Sound speed
-
Can you change the speed of audio while it’s playing?
-
//global
speed = 1
loop
clear()
playAudio( channel, handle, volume, pan, speed, loops )if c.a then
speed+= 1
endif -
If you are talking about playing asset sounds with playAudio(), I'm pretty sure that you cannot change the speed while the audio is already playing. I tried this in my entry for the Speed themed game jam, but couldn't find a way to do it...
Running waldron's code above restarts the audio for each loop, which you probably do not want.
One idea I had at the time was to have the same audio playing on different channels, but at slightly different speed, and then slowly cross fade from one to the other by changing the volume of both channels (volume can be changed while its playing with setVolume()).
I guess it depends on the audio, if it would be possible to make that sound OK...
-
This post is deleted! -
@waldron No, I just tested it. The audio definitely restarts every time you call playAudio().
-
This post is deleted! -
This post is deleted! -
What happens if you setfrequency the channel the audio’s playing on?
-
@toxibunny I just tested it, and it actually works!
Now I feel stupid.I just kept looking for a setSpeed() command, since the parameter to playAudio() is called speed!
-
You can use setFrequency with a frequency parameter that goes from 0 (the sounds then stops playing) and upwards. Setting it to 1 means playing at normal speed. So the parameter isn't really a frequency, but seems to correspond to the speed parameter from playAudio()!
I tested this:
music = loadAudio("...") playAudio(0, music, 1, .5, 1, -1) freq = 1 loop clear() c = controls(0) freq += c.ly / 100 print(freq) setFrequency(0, freq) update() repeat
...and then you can control the speed of the music with the left stick while it is playing!
-
maybe i need my weetabix haha glad you found a solution
-
Thanks I’ll try it out