[SDL] Loading data as background process
Stephane Marchesin
stephane.marchesin at wanadoo.fr
Mon May 31 15:17:54 PDT 2004
David Olofson wrote:
>>I'll
>>probably have to implement a separate thread for Ogg music
>>streaming as well though.
>>
>
>That won't be much of a problem, I think, as the decoding doesn't have
>anything to do with SDL directly. I'd suggest using a lock-free FIFO
>or buffer ring between the decoder thread and the audio callback.
>
Here's my 2 cents worth of music streaming with SDL :
I have done mp3 music streaming for a game. Contrary to all sane advice,
I do decoding directly inside the callback function :)
I use an optimized mmx mp3 decoder (mpglib, to which I backported mmx
optimizations from mpg123) and a 4096 samples buffer (this is with 44Khz
16 bit stereo sound, I found 4096 was the minimum on windows to avoid
sound skips with that quality, whatever I do). I know that's quite
unreasonable but it happens to works fine on windows and linux.
The trick in all this is that the mp3 decoding time is not that big if
you compare it to the time it takes to do a memory copy in the threaded
decoding approach. In fact, a big part of the computation time is spent
waiting for cache misses in both cases. It'll probably work with ogg
too, although I couldn't find any ogg decoder that I could drop in in my
code that was as easy to integrate as mpglib (I wanted to integrate it
in my code to be able to add in my optimizations).
Stephane
More information about the SDL
mailing list