[SDL] SDL_LockAudio and MacOS

Darrell Walisser dwaliss1 at purdue.edu
Sat Apr 21 10:14:24 PDT 2001


On Sat, 21 Apr 2001, David Olofson wrote:

> On Thursday 19 April 2001 23:36, Darrell Walisser wrote:
> > > And result in clicks/blank spaces. Unacceptable.  I'm talking about
> > > blocking the audio interrupt for microseconds at a time, while, for
> > > example, a link list operation is completed.
> >
> > Unfortunately I don't think there is any way to implement it.
>
> Why not? There are lock-free solutions for most kind of sync constructs,
> although most of them are rather messy, uggly and/or awkward to code. Single
> reader-single writer constructs are rather simple, though, as long as you
> have atomic reads and/or atomic writes for some usable word size, which is
> the case with most architectures, even on SMP machines.

I've thought about this problem a bit, and I think I have a solution:

Modify the Carbon sound driver as follows:

make SDL_LockAudio set a flag audio_locked to true.

in the callback, if the audio is locked, don't send any new data to the
chip, and stop the callback cycle. In other words, do nothing in this
case.

make SDL_UnlockAudio send data to the chip and also send the interrupt
command to start the callback cycle over again.


As long as you can process all of your data between

SDL_LockAudio() and SDL_UnLockAudio() faster than the current sound
buffer takes to play, you shouldn't get any clicks or have synchronization
problems.


What do you think?

Regards,
Darrell







More information about the SDL mailing list