[SDL] Converting OSS sound code to SDL ...
Ryan C. Gordon
icculus at clutteredmind.org
Mon Aug 12 13:19:01 PDT 2002
> I have another question wrt. this. When using OSS, you open /dev/dsp and
> write to the soundcard directly (using write(...)). When that write is
> finished, does the sound keep playing? That is, when you write data to the
> sound card, does it keep using that data until something else is written to
> it?
Depends on the driver, I think.
> That's what seems to be happening in the OSS code I have now. If SDL doesn't
> do this, that *could* explain why the SDL version is choppy. It only plays
> what data is written to it, then stops. These 'stops' could be interpreted
> as choppiness in the playback.
>
> Is this how it works? Or is this theory useless.
SDL writes to /dev/dsp (or whatnot) and then calls your callback when it
needs more data. If you don't feed it as much data as it wants when your
callback gets called, you'll probably get choppiness or maybe repeats if
you happen to get the same memory buffer and it hasn't been reinitialized
(depends on the SDL target and hardware driver). But that memory buffer in
your callback is going to the audio device, ready or not.
> Is this somehow related to blocking vs. non-blocking mode? I'm still not
> sure what the difference is between these.
Blocking says "write to the audio device, and don't return from the
write() call until all the data is written (or a fatal error occurs)". Non
blocking says "write to the audio device and return immediately, telling
me how much you managed to write".
SDL writes to the audio device in a separate thread, so blocking is more
or less irrelevant, since all this thread does is write to the audio
device, get more data from your callback as needed, and write to the audio
device again.
--ryan.
More information about the SDL
mailing list