(SDL) How to play sound at a different speed?
I'm in the process of porting my DirectSound audio engine to SDL. In DirectSound, I have the ability to change the frequency at which individual sound buffers are playing, thus allowing me to speed up / slow down (obviously changing pitch) sounds dynamically at run time.
AFAIK, SDL doesn't have such an ability since all sounds must be mixed together at one particular frequency in the mixer callback.
As with most SDL applications, I open sound with a particular frequency (in my case, 22050) and then convert each WAV on load to that frequency.
What I'd like to do is (if a sound is playing at something other than 1.0x speed) dynamically convert the sound to a different speed (frequency) in my mixer callback so that it can then be mixed in with the main audio buffer. For example, if I wanted to play a sound at half the speed, I could convert it to a stream that was twice the frequency and then play that stream at the normal frequency, thus slowing the sound down by a half.
Is there an algorithm I can use to do this? A link to an algorithm or tutorial would suffice.
Thanks!
I think that feature was supposed to be added to the next version of SDL_mixer for SDL 1.3. It's called resampling or something like that. I've done an experiment with soft synths on SDL_mixer that played different frequency sine waves into a MIX_chunk and then played it back but changing the sampling rate of a sample is best accomplished by hardware in the sound card.
If you're on a deadline, you might consider using OpenAL Soft instead of SDL_mixer. I think it can do that for you.
If you're on a deadline, you might consider using OpenAL Soft instead of SDL_mixer. I think it can do that for you.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement