[SDL] Re: Converting push sound model to SDL

Stephen Anthony stephena at users.sourceforge.net
Thu Jun 23 17:43:29 PDT 2005


On June 23, 2005 08:38 pm, Leo Broukhis wrote:
> Drake Wilson <drake <at> libcom.com> writes:
> > > I would like to convert the audio systel to SDL.  What is the
> > > right way to go?  Is there a code that wraps the SDL audio
> > > callback API into a "push model" a la write syscall that blocks
> > > if the buffer is full?
> >
> > Perhaps have the callback read from a circular buffer?  I believe
> > the Simple FIFO library <http://olofson.net/mixed.html> might be
> > beneficial here.
>
> Thanks, but unlikely (for one, it does not have locking). My attempts
> to use SDL audio and mutexes resulted either in underflows or in too
> much lag between a keypress and a keyclick. It seems that except the
> sound buffer size there is no way to control the playback parameters
> (namely, the number of yet unplayed fragments downstream from the
> callback).
>
> Moreover, what are the constraints on the callback function? How long
> can it run before returning to avoid underflows?
> May it use SDL video calls and have the event loop inside of it?
>
> A possible solution would be to embed all of the emulator inside of
> the callback function and return from it every time an audio buffer
> is full, but this is too drastic and/or will not work if the audio
> system only calls the callback fn when the audio has almost drained.

If I'm understanding you correctly, you want to move from a "push the 
sound bytes down the pipe" model to a callback model?  If so, I 
encountered and eventually solved (with a great amount of misery) the 
exact same problems with Stella, the Atari 2600 emulator.

Originally, the sound processing was done in a separate sound server, 
where updates were simply done with 'write' and using OSS.  Later, the 
code was converted to use SDL.

Have a look at the web repository on stella.sf.net.  Specifically, look 
for the old OSS sound code in 'src/ui/sound/Attic/OSS.c' and the new 
code in 'src/common/SoundSDL.cxx'.  To be sure, there are some things 
there that you can ignore, but it might give you some ideas on how to 
proceed.

Steve




More information about the SDL mailing list