Open Sound System
OSS 4.x Programmer's Guide

Do you have problems with sound/audio application development? Don't panic! Click here for help!

The select() and poll() system calls

All OSS system calls follow the familiar Posix/Unix semantics. Please look at the standard manual page (man select or man poll) for more informtion. This section will only explain some OSS related details. The error codes returned by OSS as well as their meaning will be described in the Possible error codes (errno) returned by OSS calls section.

The select and poll calls can be used when non blocking operation is needed with OSS or if the application needs to be able to respond to events from multiple sources at the same time (for example audio, MIDI, keyboard/mouse and some network sockets).

Many applications we have examined uses select/poll with no good reason. I think this is caused by some kind of misunderstanding. Majority of applications will work better if it uses normal blocking reads and writes.

By default select and poll will report a read event when it's possible to write at least one byte to the device. In this mode the application must check how much space there is available in the buffer and fill it before calling select again. In read direction the application should read all bytes available in the device. Otherwise the CPU consumption of the application may become unbearably hight.

An alternative approach with audio devices is setting the low water limit with SNDCTL_DSP_LOW_WATER. In this way the select will report an event when the available read/write size is greater or equal to the low water limit.

One special case is applications that do full duplex filtering (record data from the device, process it and play it back). Such applications will work better if they use select/poll only for checking if recorded data is available. Write calls will not block if the application keeps writing at the same rate with recording.

A very common error with select is that the application doesn't start recording before calling select. recording can be started by calling SNDCTL_DSP_SETTRIGGER.

Sample programs

fulldup.cFull duplex sample program using the single device approach.
mmap_duplex.cA simple sample program for doing dull duplex using mmap
morse3.cYet another morse code program that uses select
morse2.cAnother morse code program that uses select
seltest2.cThis program has been used to verify that the select() call works
iosync.cMeasuring the hardware level latencies.
ioctl_test.cThis program has been used to verify that some of the ioctl calls work
softsynth_gtk.cA simple software MIDI synthesizer program with GTK GUI.
softsynth.cA simple software MIDI synthesizer program.

Copyright (C) 4Front Technologies, 2007. All rights reserved.
Back to index OSS web site