[linux-audio-dev] Behaviour of write() in blocking/non-blocking mode

Greg Ward gward at python.net
Wed Nov 27 21:18:01 UTC 2002

Hi all --

I'm making my first forays into OSS DSP programming with an eye to
improving the standard linuxaudiodev module included with Python.  (And,
of course, to using that module for my own ends!)

I'm rather confused by the semantics of write() in blocking and
non-blocking mode.  Specifically, in the default mode (blocking, no
SNDCTL_DSP_NONBLOCK ioctl() call), it appears that write() will happily
write the entire buffer passed to it, and not return until almost all of
the data has been played.  (I assume the last dribble is in a
lower-level [hardware?] buffer, so when write() returns there's still a
little bit of sound to be heard.)

However, in non-blocking mode, write() plays roughly 64k or 128k
(depending on the hardware device used) and returns immediately.  This
is more like what I was expecting -- I guess the behaviour in blocking
mode is a bit surprising.  Is it supposed to be like this?  More
importantly, can I *rely* on write() in blocking mode always consuming
the entire buffer passed to it?

BTW, this is with Linux 2.4.20-rc1; the two audio devices are a
SoundBlaster Live using the OSS emu10k1 driver, and a Stereo-Link
external USB audio device using, you guessed it, the USB audio driver.

Thanks --

Greg Ward <gward at python.net>                         http://www.gerg.ca/
I hope something GOOD came in the mail today so I have a REASON to live!!

More information about the Linux-audio-dev mailing list