How to change the octave of an audio more than 2x

If you have ever tried making a synthesizer in ROBLOX, you might have realized that the “PitchShiftSoundEffect” instance is limited to the range of (0.5,2) octaves. It is possible to change the playback speed of the audio, but it distorts the time scale and compresses everything together.

The solution:
Create multiple sounds of varying pitches. Since the “PitchShiftSoundEffect” can double or halve the octave, you want to account for that in the sound frequencies.

For example, if I want to play a sound on the range of (25,400) hertz, I would create 2 sound files. One sound would be at 50hz and the other would be at 200hz. When I halve the 50hz, I can get my lower limit of 25 hz. When i double the 50hz to 100hz, it reaches the bottom limit of the 200hz sound. Then lastly, I can double the 200hz sound to reach 400hz.

Using some simple code, you can loop through the sound instances to pick the one closest to the target pitch but not below 2x the max hertz.

Example:
Here’s a little test I made using the mouse position and 4 audio files of various sine waves.

(HEADPHONE WARNING)


In this example, the audio plays from 25hz all the way to 6400hz. The various hertz audio I used are {50hz, 200hz, 800hz, 3200hz}. There is a noticeable sound when quickly switching audios, but you could have the audio hertz overlap and lerp the volume to mitigate it.

Thank you for reading, please create some cool music games.

3 Likes