[SDL] Converting OSS sound code to SDL ...

Loren Osborn linux_dr at yahoo.com
Wed Aug 14 11:58:01 PDT 2002


--- Stephen Anthony <stephena at roadrunner.nf.net>
wrote:
> On August 14, 2002 03:18 pm, Loren Osborn wrote:
> 
> > For me anyway, it is much easier to to think of
> the
> > mutex being "locked" or "unlocked" rather than 1
> or
> > 0...
> 
> That's why I called it a mutex of sorts.  It isn't
> really a mutex at all.
> 
> > The point is the callback isn't called in sync
> with
> > any part of your program, so you should probably
> make
> > a mutex-protected ring buffer... The callback can
> read
> > out of it, and the rest of your sound code can
> feed
> > it... When it becomes empty, the callback should
> send
> > the silence value.
> 
> Yes, this is what Sam mentioned, but I wasn't sure
> what he meant.  Now I 
> know :)  Quite a bit more complicated than an
> ordinary write().  I was 
> still thinking in terms of one write for one sound. 
> I forgot about the 
> threading part, where the sound thread isn't
> necessarily in sync with the 
> other code.  Going from single-threaded to
> multi-threaded can be 
> difficult sometimes.
> 
> BTW, how do you know how much data you can write on
> each call to the 
> callback?

The callback prototype looks like:

void (*callback)(void *userdata, Uint8 *stream, int
len);

so, the buffer length is passed in to you, you
probably need to divide it by the number of channels
(1 or 2) and the number of bytes per sample (1 or
2)...

Best of luck,

-Loren

__________________________________________________
Do You Yahoo!?
HotJobs - Search Thousands of New Jobs
http://www.hotjobs.com




More information about the SDL mailing list