Technical data

SunOS 5.5 Ioctl Requests audio(7I)
Precision Precision indicates the number of bits used to store each audio sample. For instance, µ-
law and A-law data are stored with 8-bit precision. PCM data may be stored at various
precisions, though 16-bitPCM is most common.
Channels Multiple channels of audio may be interleaved at sample boundaries. A sample frame
consists of a single sample from each active channel. For example, a sample frame of
stereo 16-bit PCM data consists of 2 16-bit samples, corresponding to the left and right
channel data.
DESCRIPTION The device /dev/audio is a device driver that dispatches audio requests to the appropriate
underlying audio device driver. The audio driver is implementedas a STREAMS driver.
In order to record audio input, applications open(2) the /dev/audio device and read data
from it using the read(2) system call. Similarly, sound data is queued to the audio output
port by using the write(2) system call. Device configuration is performed using the
ioctl(2) interface.
As some systems may contain more than one audio device, application writers are
encouraged to query theAUDIODEV environment variable. If this variable is present in
the environment, its value should identify the path name of the default audio device.
Opening the Audio
Device
The audio device is treated as an exclusive resource only one process can open the dev-
ice at a time. However, two processes may simultaneously access the device: if one opens
it read-only, then another may open it write-only.
When a process cannot open /dev/audio because the requested access mode is busy:
if either theO_NDELAY or O_NONBLOCK flag are set in the open() oflag argu-
ment, then 1 is immediately returned, with errno set toEBUSY.
if neither theO_NDELAY nor the O_NONBLOCK flag are set, then open()
hangs until the device is available or a signal is delivered to the process, in
which case a 1 is returned with errno set to EINTR. This allows a process to
block in the open call, while waiting for the audio device to become available.
Upon the initialopen() of the audio device, the driver will reset the data format of the
device to the default state of 8-bit, 8Khz, mono µ-law data. If the device is already open
and a different audio format has been set, this will not be possible. Audio applications
should explicitly set the encoding characteristics to match the audio data requirements,
rather than depend on the default configuration.
Since the audio device grants exclusive read or write access to a single process at a time,
long-lived audio applications may choose to close the device when they enter an idle
state and reopen it when required. The play.waiting and record.waiting flags in the audio
information structure (see below) provide an indication that another process has
requested access to the device. For instance, a background audio output process may
choose to relinquish the audio device whenever another process requests write access.
Recording Audio
Data
The read() system call copies data from the system buffers to the application. Ordinarily,
read() blocks until the user buffer is filled. TheI_NREAD ioctl (see streamio(7I)) may be
used to determine the amount of data that may be read without blocking. The device
may alternatively be set to a non-blocking mode, in which case read() completes
modified 21 Mar 1995 7I-25