[SDL] audio documentation...
david at olofson.net
Wed Apr 21 05:31:20 PDT 2004
On Wednesday 21 April 2004 11.56, redman wrote:
> hi ppl.,
> i'm new to the list (and sdl) and i've got a question., :)
> does anyone have some good docs about the audio part of sdl?
> i'm having some speed issues and i'm not sure what's causing it.
> (working on windows / msdev6 / c)
> i do some calcs in the callback function but at a certain point
> (ammount of calcs) the buffer
> starts skipping., but i'm SURE i have loads of cycles left to do it
This is because you're not on a real time operating system... There is
a hard deadline for delivering the audio buffer (ie returning from
the callback), and if you miss it, audio skips. Meanwhile, a standard
OS scheduler and some background system load will cause the audio
callback to start anywhere from a few µs through tens or
(occasionally) hundreds of ms late, wasting the cycles you were going
to use for processing, or even causing audio drop-outs before you get
a chance to do anything at all. Not much you can do about that, short
of switching to Linux/lowlatency or BeOS. :-/
What you *can* do is increase the buffering (latency) so that the
scheduling jitter accounts for a smaller part of the audio buffer
period. That way, you can use more CPU power for audio with less
drop-outs, but on an OS like Windows, there is no way ever you're
going to get anywhere near 100%, and/or totally eliminate the
drop-outs when doing low latency audio. (I think you can get pretty
close with Win2k or XP, a decent proffesional sound card and running
your audio code in kernel space as Kernel Stream filters, but that's
insane for "consumer" multimedia such as games.)
> so i have basically two questions
> 1 where should i generate the data that would go into the buffer
In the callback. (Otherwise, you'll need extra buffering and thread
safe communication between the audio engine and the callback. That
can make sense in some cases, but *definitely* not when you want
interactive low latency sound effects.)
> 2 when should i call SDL_LockAudio() / SDL_UnlockAudio()
Preferably never. I would recommend using some sort of lock-free
communication between the main thread and the audio callback context
instead, to avoid increasing the callback "scheduling" jitter.
//David Olofson - Programmer, Composer, Open Source Advocate
.- Audiality -----------------------------------------------.
| Free/Open Source audio engine for games and multimedia. |
| MIDI, modular synthesis, real time effects, scripting,... |
`-----------------------------------> http://audiality.org -'
--- http://olofson.net --- http://www.reologica.se ---
More information about the SDL