AUDIO(4) | Device Drivers Manual | AUDIO(4) |
audio
, mixer
— device-independent audio driver layer
audio* at ...
#include <sys/types.h>
#include <sys/ioctl.h>
#include <sys/audioio.h>
#include <string.h>
The audio
driver provides support for
various audio peripherals. It provides a uniform programming interface layer
above different underlying audio hardware drivers. The audio layer provides
full-duplex operation if the underlying hardware configuration supports
it.
There are three device files available for audio operation:
/dev/audio, /dev/audioctl,
and /dev/mixer. /dev/audio
is used for recording or playback of digital samples.
/dev/mixer is used to manipulate volume, recording
source, or other audio mixer functions.
/dev/audioctl accepts the same
ioctl(2) operations as
/dev/audio, but no other operations. In contrast to
/dev/audio, which has the exclusive open property,
/dev/audioctl can be opened at any time and can be
used to read the audio
device variables while it is
in use.
When /dev/audio is opened, it attempts to maintain the previous audio sample format and record/playback mode. In addition, if it is opened read-only (write-only) the device is set to half-duplex record (play) mode with recording (playing) unpaused.
Only one process may hold open a sampling device at a given time (although file descriptors may be shared between processes once the first open completes).
On a half-duplex device, either reads or writes are allowed, but not both. On a full-duplex device, reads and writes may operate concurrently without interference.
If a writing process does not call write(2) frequently enough to provide samples at the pace the hardware consumes them silence is inserted. If a reading process does not call read(2) frequently enough, it will simply miss samples.
The audio
device is accessed with
read(2) or
write(2).
The audio
device, like most devices, can
be used in poll(2),
The following ioctl(2) commands are supported on the sample devices:
AUDIO_GETDEV
audio_device_t *typedef struct audio_device { char name[MAX_AUDIO_DEV_LEN]; char version[MAX_AUDIO_DEV_LEN]; char config[MAX_AUDIO_DEV_LEN]; } audio_device_t;
AUDIO_SETPAR
struct audio_swpar *AUDIO_GETPAR
struct audio_swpar *struct audio_swpar { unsigned int sig; /* if 1, encoding is signed */ unsigned int le; /* if 1, encoding is little-endian */ unsigned int bits; /* bits per sample */ unsigned int bps; /* bytes per sample */ unsigned int msb; /* if 1, bits are msb-aligned */ unsigned int rate; /* common play & rec sample rate */ unsigned int pchan; /* play channels */ unsigned int rchan; /* rec channels */ unsigned int nblks; /* number of blocks in play buffer */ unsigned int round; /* common frames per block */ };
When setting the device parameters with
AUDIO_SETPAR
, the
audio_swpar structure should first be initialized
with
struct audio_swpar ap; AUDIO_INITPAR(&ap);
and then only the values to be changed should be set. This
ensures that the software will work with future versions of the driver.
The driver will attempt to set the given parameters; if the device
doesn't support them, it will choose other parameters. Then the software
must call AUDIO_GETPAR
to obtain the parameters
in use.
The parameters are as follows:
AUDIO_START
AUDIO_GETPAR
.
AUDIO_STOP
AUDIO_GETPOS
struct audio_pos *struct audio_pos { unsigned int play_pos; /* total bytes played */ unsigned int play_xrun; /* bytes of silence inserted */ unsigned int rec_pos; /* total bytes recorded */ unsigned int rec_xrun; /* bytes dropped */ };
The properties have the following meaning:
AUDIO_GETSTATUS
struct audio_status *struct audio_status { #define AUMODE_PLAY 0x01 #define AUMODE_RECORD 0x02 int mode; /* current mode */ int pause; /* not started yet */ int active; /* playing/recording in progress */ };
The properties have the following meaning:
AUDIO_STOP
was called,
and the device is not attempting to start.The mixer
device,
/dev/mixer, may be manipulated with
ioctl(2) but does not support
read(2) or
write(2). It supports the
following ioctl(2)
commands:
AUDIO_GETDEV
audio_device_t *AUDIO_MIXER_READ
mixer_ctrl_t *AUDIO_MIXER_WRITE
mixer_ctrl_t *#define AUDIO_MIXER_CLASS 0 #define AUDIO_MIXER_ENUM 1 #define AUDIO_MIXER_SET 2 #define AUDIO_MIXER_VALUE 3 typedef struct mixer_ctrl { int dev; /* input: nth device */ int type; union { int ord; /* enum */ int mask; /* set */ mixer_level_t value; /* value */ } un; } mixer_ctrl_t; #define AUDIO_MIN_GAIN 0 #define AUDIO_MAX_GAIN 255 typedef struct mixer_level { int num_channels; u_char level[8]; /* [num_channels] */ } mixer_level_t; #define AUDIO_MIXER_LEVEL_MONO 0 #define AUDIO_MIXER_LEVEL_LEFT 0 #define AUDIO_MIXER_LEVEL_RIGHT 1
For a mixer value, the value field
specifies both the number of channels and the values for each channel.
If the channel count does not match the current channel count, the
attempt to change the setting may fail (depending on the hardware device
driver implementation). For an enumeration value, the
ord field should be set to one of the possible
values as returned by a prior
AUDIO_MIXER_DEVINFO
command. The type
AUDIO_MIXER_CLASS
is only used for classifying
particular mixer
device types and is not used
for AUDIO_MIXER_READ
or
AUDIO_MIXER_WRITE
.
AUDIO_MIXER_DEVINFO
mixer_devinfo_t *mixer
device information into the input/output
mixer_devinfo_t * argument. To query all the
supported devices, start with an index field of 0 and continue with
successive devices (1, 2, ...) until the command returns an error.
typedef struct mixer_devinfo { int index; /* input: nth mixer device */ audio_mixer_name_t label; int type; int mixer_class; int next, prev; #define AUDIO_MIXER_LAST -1 union { struct audio_mixer_enum { int num_mem; struct { audio_mixer_name_t label; int ord; } member[32]; } e; struct audio_mixer_set { int num_mem; struct { audio_mixer_name_t label; int mask; } member[32]; } s; struct audio_mixer_value { audio_mixer_name_t units; int num_channels; int delta; } v; } un; } mixer_devinfo_t;
The label field identifies the name of
this particular mixer control. The index field may
be used as the dev field in
AUDIO_MIXER_READ
and
AUDIO_MIXER_WRITE
commands. The
type field identifies the type of this mixer
control. Enumeration types are typically used for on/off style controls
(e.g., a mute control) or for input/output device selection (e.g.,
select recording input source from CD, line in, or microphone). Set
types are similar to enumeration types but any combination of the mask
bits can be used.
The mixer_class field identifies what
class of control this is. This value is set to the index value used to
query the class itself. The (arbitrary) value set by the hardware driver
may be determined by examining the mixer_class
field of the class itself, a mixer of type
AUDIO_MIXER_CLASS
. For example, a mixer level
controlling the input gain on the “line in” circuit would
have a mixer_class that matches an input class
device with the name “inputs”
(AudioCinputs
) and would have a
label of “line”
(AudioNline
). Mixer controls which control audio
circuitry for a particular audio source (e.g., line-in, CD in, DAC
output) are collected under the input class, while those which control
all audio sources (e.g., master volume, equalization controls) are under
the output class. Hardware devices capable of recording typically also
have a record class, for controls that only affect recording, and also a
monitor class.
The next and prev
may be used by the hardware device driver to provide hints for the next
and previous devices in a related set (for example, the line in level
control would have the line in mute as its “next” value).
If there is no relevant next or previous value,
AUDIO_MIXER_LAST
is specified.
For AUDIO_MIXER_ENUM
mixer control
types, the enumeration values and their corresponding names are filled
in. For example, a mute control would return appropriate values paired
with AudioNon
and
AudioNoff
. For the
AUDIO_MIXER_VALUE
and
AUDIO_MIXER_SET
mixer control types, the channel
count is returned; the units name specifies what the level controls
(typical values are AudioNvolume
,
AudioNtreble
, and
AudioNbass
).
By convention, all the mixer devices can be distinguished from
other mixer controls because they use a name from one of the
AudioC*
string values.
aucat(1), audioctl(1), cdio(1), mixerctl(1), ioctl(2), sio_open(3), ac97(4), uaudio(4), audio(9)
September 8, 2016 | OpenBSD-6.2 |