[SDL] sdl audio jittering

Florian Hufsky fhufsky at phorus.at
Sat Nov 12 13:13:30 PST 2005


Hi,

Due to the lack of an easy to use compressed audio capable sdl audio 
library (ever tried sdl_mixer with mp3/ogg sounds?) I'm working on an 
Audiere version that solely uses SDL.

Everything's fine until now, as Audiere does everything to load and mix 
the music. It gives me a steady stream of 16Bit PCM samples that only 
need to be shoved into the sdl audio buffer.

The whole thing works great already. Unless the CPU gets a bit busy. 
Then things start to jitter. However running Audiere with the Windows 
backend works still fine, so it's not a performance Problem of audiere.

Ok, my question is if you could help me get rid of that jittering at 
higher CPU loads. I guess someone with a more decent knowledge of SDL 
audio internals might instantly know the answer.


How the thing works:

I have a

freq        = 44100;
channels    = 2;            //stereo
format        = AUDIO_S16;
samples        = 2048;   
SDL_AudioSpec (verified after initalizin, and it's the same format that 
audiere gives us)

In the audio callback I do the following:
1. let audiere mix the next streamlen bytes of audio data
2. put it in the sdl audio stream

That's exactly the same thing audiere does in the windows backend.

I guess the jittering is because of audiere taking too much time to mix 
data (for sdl). However I'm worried because with the windows backend 
everything works fine.
But maybe the windows backend is written a way so that the audio 
callback can run multiple times at once.


Do you have any idea what could be the problem? Or what causes audio 
jittering under SDL in general.

If you want I can publish a patch to the audiere source to make it SDLified.

Huge thanks in advance,
Florian Hufsky





More information about the SDL mailing list