rename the top-level Makefile.cfgparam to cfgparam.mk
[unleashed.git] / share / man / man7i / audio.7i
blob6c6126abf24e0f7816f41747fc4bd8411445d239
1 '\" te
2 .\"  Copyright (c) 2009 Sun Microsystems, Inc. All rights reserved.
3 .\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License"). You may not use this file except in compliance with the License. You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing.
4 .\"  See the License for the specific language governing permissions and limitations under the License. When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE. If applicable, add the following below this CDDL HEADER, with the
5 .\" fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
6 .TH AUDIO 7I "May 6, 2009"
7 .SH NAME
8 audio \- generic audio device interface
9 .SH SYNOPSIS
10 .LP
11 .nf
12 \fB#include\fR \fB<sys/audio.h>\fR
13 .fi
15 .SH OVERVIEW
16 .sp
17 .LP
18 An audio device is used to play and/or record a stream of audio data. Since a
19 specific audio device may not support all functionality described below, refer
20 to the device-specific manual pages for a complete description of each hardware
21 device. An application can use the \fBAUDIO_GETDEV\fR \fBioctl\fR(2) to
22 determine the current audio hardware associated with \fB/dev/audio\fR.
23 .sp
24 .LP
25 The audio framework provides a software mixing engine (audio mixer) for all
26 audio devices, allowing more than one process to play or record audio at the
27 same time.
28 .SS "Backward Compatibility"
29 .sp
30 .LP
31 It is no longer possible to disable the mixing function. Applications must not
32 assume that they have exclusive access to the audio device.
33 .SS "Multi-Stream Codecs"
34 .sp
35 .LP
36 The audio mixer supports multi-stream Codecs. These devices have DSP engines
37 that provide sample rate conversion, hardware mixing, and other features. The
38 use of such hardware features is opaque to applications.
39 .SH AUDIO FORMATS
40 .sp
41 .LP
42 Digital audio data represents a quantized approximation of an analog audio
43 signal waveform. In the simplest case, these quantized numbers represent the
44 amplitude of the input waveform at particular sampling intervals. To achieve
45 the best approximation of an input signal, the highest possible sampling
46 frequency and precision should be used. However, increased accuracy comes at a
47 cost of increased data storage requirements. For instance, one minute of
48 monaural audio recorded in \(*m-Law format (pronounced \fBmew-law\fR) at 8 KHz
49 requires nearly 0.5 megabytes of storage, while the standard Compact Disc audio
50 format (stereo 16-bit linear \fBPCM\fR data sampled at 44.1 KHz) requires
51 approximately 10 megabytes per minute.
52 .sp
53 .LP
54 Audio data may be represented in several different formats. An audio device's
55 current audio data format can be determined by using the \fBAUDIO_GETINFO\fR
56 \fBioctl\fR(2) described below.
57 .sp
58 .LP
59 An audio data format is characterized in the audio driver by four parameters:
60 Sample Rate, Encoding, Precision, and Channels. Refer to the device-specific
61 manual pages for a list of the audio formats that each device supports. In
62 addition to the formats that the audio device supports directly, other formats
63 provide higher data compression. Applications may convert audio data to and
64 from these formats when playing or recording.
65 .SS "Sample Rate"
66 .sp
67 .LP
68 Sample rate is a number that represents the sampling frequency (in samples per
69 second) of the audio data.
70 .sp
71 .LP
72 The audio mixer always configures the hardware for the highest possible sample
73 rate for both play and record. This ensures that none of the audio streams
74 require compute-intensive low pass filtering. The result is that high sample
75 rate audio streams are not degraded by filter ing.
76 .sp
77 .LP
78 Sample rate conversion can be a compute-intensive operation, depending on the
79 number of channels and a device's sample rate. For example, an 8KHz signal can
80 be easily converted to 48KHz, requiring a low cost up sampling by 6. However,
81 converting from 44.1KHz to 48KHz is compute  intensive because it must be up
82 sampled by 160 and then down sampled by 147. This is only done using integer
83 multipliers.
84 .sp
85 .LP
86 Applications can greatly reduce the impact of sample rate conversion by
87 carefully picking the sample rate. Applications should always use the highest
88 sample rate the device supports. An application can also do its own sample rate
89 conversion (to take advantage of floating  point and accelerated instruction or
90 use small integers for up and down sampling.
91 .sp
92 .LP
93 All modern audio devices run at 48 kHz or a multiple thereof, hence just using
94 48 kHz may be a reasonable compromise if the application is not prepared to
95 select higher sample rates.
96 .SS "Encodings"
97 .sp
98 .LP
99 An encoding parameter specifies the audio data representation. \(*m-Law
100 encoding corresponds to \fICCITT G.711\fR, and is the standard for voice data
101 used by telephone companies in the United States, Canada, and Japan. A-Law
102 encoding is also part of \fICCITT G.711\fR and is the standard encoding for
103 telephony elsewhere in the world. A-Law and \(*m-Law audio data are sampled at
104 a rate of 8000 samples per second with 12-bit precision, with the data
105 compressed to 8-bit samples. The resulting audio data quality is equivalent to
106 that of standard analog telephone service.
109 Linear Pulse Code Modulation (PCM) is an uncompressed, signed audio format in
110 which sample values are directly proportional to audio signal voltages. Each
111 sample is a 2's complement number that represents a positive or negative
112 amplitude.
113 .SS "Precision"
116 Precision indicates the number of bits used to store each audio sample. For
117 instance, u-Law and A-Law data are stored with 8-bit precision. \fBPCM\fR data
118 may be stored at various precisions, though 16-bit is the most common.
119 .SS "Channels"
122 Multiple channels of audio may be interleaved at sample boundaries. A sample
123 frame consists of a single sample from each active channel. For example, a
124 sample frame of stereo 16-bit \fBPCM\fR data consists of two 16-bit samples,
125 corresponding to the left and right channel data.
128 The audio mixer sets the hardware to the maximum number of channels supported.
129 If a mono signal is played or recorded, it is mixed on the first two (usually
130 the left and right) channels only. Silence is mixed on the remaining channels
131 .SS "Supported Formats"
134 The audio mixer supports the following audio formats:
136 .in +2
138 Encoding           Precision   Channels
139 Signed Linear PCM  32-bit      Mono or Stereo
140 Signed Linear PCM  16-bit      Mono or Stereo
141 Signed Linear PCM   8-bit      Mono or Stereo
142 u-Law               8-bit      Mono or Stereo
143 A-Law               8-bit      Mono or Stereo
145 .in -2
150 The audio mixer converts all audio streams to 24-bit Linear PCM before mixing.
151 After mixing, conversion is made to the best possible Codec format. The
152 conversion process is not compute intensive and audio applications can choose
153 the encoding format that best meets their needs.
156 Note that the mixer discards the low order 8 bits of 32-bit Signed Linear PCM
157 in order to perform mixing. (This is done to allow for possible overflows to
158 fit into 32-bits when mixing multiple streams together.) Hence, the maximum
159 effective precision is 24-bits.
160 .SH DESCRIPTION
163 The device \fB/dev/audio\fR is a device driver that dispatches audio requests
164 to the appropriate underlying audio hardware. The audio driver is implemented
165 as a \fBSTREAMS\fR driver. In order to record audio input, applications
166 \fBopen\fR(2) the \fB/dev/audio\fR device and read data from it using the
167 \fBread\fR(2) system call. Similarly, sound data is queued to the audio output
168 port by using the \fBwrite\fR(2) system call. Device configuration is performed
169 using the \fBioctl\fR(2) interface.
172 Because some systems may contain more than one audio device, application
173 writers are encouraged to query the \fBAUDIODEV\fR environment variable. If
174 this variable is present in the environment, its value should identify the path
175 name of the default audio device.
176 .SS "Opening the Audio Device"
179 The audio device is not treated as an exclusive resource. Each process may open
180 the audio device once.
183 Each \fBopen()\fR completes as long as there are channels available to be
184 allocated. If no channels are available to be allocated:
185 .RS +4
187 .ie t \(bu
188 .el o
189 if either the \fBO_NDELAY\fR or \fBO_NONBLOCK\fR flags are set in the
190 \fBopen()\fR \fIoflag\fR argument, then -1 is immediately returned, with
191 \fIerrno\fR set to \fBEBUSY.\fR
193 .RS +4
195 .ie t \(bu
196 .el o
197 if neither the \fBO_NDELAY\fR nor the \fBO_NONBLOCK\fR flag are set, then
198 \fBopen()\fR hangs until the device is available or a signal is delivered to
199 the process, in which case a -1 is returned with \fIerrno\fR set to
200 \fBEINTR.\fR
204 Upon the initial open() of the audio channel, the audio mixer sets the data
205 format of the audio channel to the default state of 8-bit, 8Khz, mono u-Law
206 data. If the audio device does not support this configuration, it informs the
207 audio mixer of the initial configuration. Audio applications should explicitly
208 set the encoding characteristics to match the audio data requirements, and not
209 depend on the default configuration.
210 .SS "Recording Audio Data"
213 The \fBread()\fR system call copies data from the system's buffers to the
214 application. Ordinarily, \fBread()\fR blocks until the user buffer is filled.
215 The \fBI_NREAD\fR \fBioctl\fR (see \fBstreamio\fR(7I)) may be used to determine
216 the amount of data that may be read without blocking. The device may
217 alternatively be set to a non-blocking mode, in which case \fBread()\fR
218 completes immediately, but may return fewer bytes than requested. Refer to the
219 \fBread\fR(2) manual page for a complete description of this behavior.
222 When the audio device is opened with read access, the device driver immediately
223 starts buffering audio input data. Since this consumes system resources,
224 processes that do not record audio data should open the device write-only
225 (\fBO_WRONLY\fR).
228 The transfer of input data to \fBSTREAMS\fR buffers may be paused (or resumed)
229 by using the \fBAUDIO_SETINFO\fR \fBioctl\fR to set (or clear) the
230 \fIrecord.pause\fR flag in the audio information structure (see below). All
231 unread input data in the \fBSTREAMS\fR queue may be discarded by using the
232 \fBI_FLUSH\fR \fBSTREAMS\fR \fBioctl\fR. See \fBstreamio\fR(7I). When changing
233 record parameters, the input stream should be paused and flushed before the
234 change, and resumed afterward. Otherwise, subsequent reads may return samples
235 in the old format followed by samples in the new format. This is particularly
236 important when new parameters result in a changed sample size.
239 Input data can accumulate in \fBSTREAMS\fR buffers very quickly. At a minimum,
240 it will accumulate at 8000 bytes per second for 8-bit, 8 KHz, mono, u-Law data.
241 If the device is configured for 16-bit linear or higher sample rates, it will
242 accumulate even faster. If the application that consumes the data cannot keep
243 up with this data rate, the \fBSTREAMS\fR queue may become full. When this
244 occurs, the \fIrecord.error\fR flag is set in the audio information structure
245 and input sampling ceases until there is room in the input queue for additional
246 data. In such cases, the input data stream contains a discontinuity. For this
247 reason, audio recording applications should open the audio device when they are
248 prepared to begin reading data, rather than at the start of extensive
249 initialization.
250 .SS "Playing Audio Data"
253 The \fBwrite()\fR system call copies data from an application's buffer to the
254 \fBSTREAMS\fR output queue. Ordinarily, \fBwrite()\fR blocks until the entire
255 user buffer is transferred. The device may alternatively be set to a
256 non-blocking mode, in which case \fBwrite()\fR completes immediately, but may
257 have transferred fewer bytes than requested. See \fBwrite\fR(2).
260 Although \fBwrite()\fR returns when the data is successfully queued, the actual
261 completion of audio output may take considerably longer. The \fBAUDIO_DRAIN\fR
262 \fBioctl\fR may be issued to allow an application to block until all of the
263 queued output data has been played. Alternatively, a process may request
264 asynchronous notification of output completion by writing a zero-length buffer
265 (end-of-file record) to the output stream. When such a buffer has been
266 processed, the \fIplay.eof\fR flag in the audio information structure is
267 incremented.
270 The final \fBclose\fR(2) of the file descriptor hangs until all of the audio
271 output has drained. If a signal interrupts the \fBclose()\fR, or if the process
272 exits without closing the device, any remaining data queued for audio output is
273 flushed and the device is closed immediately.
276 The consumption of output data may be paused (or resumed) by using the
277 \fBAUDIO_SETINFO\fR \fBioctl\fR to set (or clear) the \fIplay.pause\fR flag in
278 the audio information structure. Queued output data may be discarded by using
279 the \fBI_FLUSH\fR \fBSTREAMS\fR \fBioctl\fR. (See \fBstreamio\fR(7I)).
282 Output data is played from the \fBSTREAMS\fR buffers at a default rate of at
283 least 8000 bytes per second for \(*m-Law, A-Law or 8-bit PCM data (faster for
284 16-bit linear data or higher sampling rates). If the output queue becomes
285 empty, the \fIplay.error\fR flag is set in the audio information structure and
286 output is stopped until additional data is written. If an application attempts
287 to write a number of bytes that is not a multiple of the current sample frame
288 size, an error is generated and the bad data is thrown away. Additional writes
289 are allowed.
290 .SS "Asynchronous I/O"
293 The \fBI_SETSIG\fR \fBSTREAMS\fR \fBioctl\fR enables asynchronous notification,
294 through the \fBSIGPOLL\fR signal, of input and output ready condition changes.
295 The \fBO_NONBLOCK\fR flag may be set using the \fBF_SETFL\fR \fBfcntl\fR(2) to
296 enable non-blocking \fBread()\fR and \fBwrite()\fR requests. This is normally
297 sufficient for applications to maintain an audio stream in the background.
298 .SS "Audio Control Pseudo-Device"
301 It is sometimes convenient to have an application, such as a volume control
302 panel, modify certain characteristics of the audio device while it is being
303 used by an unrelated process.
306 The \fB/dev/audioctl\fR pseudo-device is provided for this purpose. Any number
307 of processes may open \fB/dev/audioctl\fR simultaneously. However, \fBread()\fR
308 and \fBwrite()\fR system calls are ignored by \fB/dev/audioctl\fR. The
309 \fBAUDIO_GETINFO\fR and \fBAUDIO_SETINFO\fR \fBioctl\fR commands may be issued
310 to \fB/dev/audioctl\fR to determine the status or alter the behavior of
311 \fB/dev/audio\fR. Note: In general, the audio control device name is
312 constructed by appending the letters \fB"ctl"\fR to the path name of the audio
313 device.
314 .SS "Audio Status Change Notification"
317 Applications that open the audio control pseudo-device may request asynchronous
318 notification of changes in the state of the audio device by setting the
319 \fBS_MSG\fR flag in an \fBI_SETSIG\fR \fBSTREAMS\fR \fBioctl\fR. Such processes
320 receive a \fBSIGPOLL\fR signal when any of the following events occur:
321 .RS +4
323 .ie t \(bu
324 .el o
325 An \fBAUDIO_SETINFO\fR \fBioctl\fR has altered the device state.
327 .RS +4
329 .ie t \(bu
330 .el o
331 An input overflow or output underflow has occurred.
333 .RS +4
335 .ie t \(bu
336 .el o
337 An end-of-file record (zero-length buffer) has been processed on output.
339 .RS +4
341 .ie t \(bu
342 .el o
343 An \fBopen()\fR or \fBclose()\fR of \fB/dev/audio\fR has altered the device
344 state.
346 .RS +4
348 .ie t \(bu
349 .el o
350 An external event (such as speakerbox's volume control) has altered the device
351 state.
353 .SH IOCTLS
354 .SS "Audio Information Structure"
357 The state of the audio device may be polled or modified using the
358 \fBAUDIO_GETINFO\fR and \fBAUDIO_SETINFO\fR \fBioctl\fR commands. These
359 commands operate on the \fBaudio_info\fR structure as defined, in
360 \fB<sys/audio.h>\fR, as follows:
362 .in +2
365 * This structure contains state information for audio device
366 * IO streams
369 struct audio_prinfo {
370   /*
371   * The following values describe the
372   * audio data encoding
373   */
374  uint_t sample_rate; /* samples per second */
375  uint_t channels;  /* number of interleaved channels */
376  uint_t precision; /* number of bits per sample */
377  uint_t encoding;  /* data encoding method */
380   /*
381   * The following values control audio device
382   * configuration
383   */
384  uint_t gain; /* volume level */
385  uint_t port; /* selected I/O port */
386  uint_t buffer_size; /* I/O buffer size */
388   /*
389   * The following values describe the current device
390   * state
391   */
392  uint_t samples; /* number of samples converted */
393  uint_t eof;  /* End Of File counter (play only) */
394  uchar_t pause;  /* non-zero if paused, zero to resume */
395  uchar_t error; /* non-zero if overflow/underflow */
396  uchar_t waiting; /* non-zero if a process wants access */
397  uchar_t balance; /* stereo channel balance */
398    /*
399    * The following values are read-only device state
400    * information
401    */
402  uchar_t open;/* non-zero if open access granted */
403  uchar_t active; /* non-zero if I/O active */
404  uint_t avail_ports; /* available I/O ports */
405  uint_t mod_ports; /* modifiable I/O ports */
407 typedef struct audio_prinfo audio_prinfo_t;
409   /*
410   * This structure is used in AUDIO_GETINFO and AUDIO_SETINFO ioctl
411   * commands
412   */
413 struct audio_info {
414  audio_prinfo_t record;/* input status info */
415  audio_prinfo_t play;/* output status info */
416  uint_t monitor_gain; /* input to output mix */
417  uchar_toutput_muted; /* non-zero if output muted */
418  uint_t hw_features; /* supported H/W features */
419  uint_t sw_features;/* supported S/W features */
420  uint_t sw_features_enabled;
421                 /* supported S/W features enabled */
423 typedef struct audio_info audio_info_t;
425 /* Audio encoding types */
426 #define AUDIO_ENCODING_ULAW (1) /* u-Law encoding */
427 #define AUDIO_ENCODING_ALAW (2) /* A-Law encoding */
428 #define AUDIO_ENCODING_LINEAR (3) /* Signed Linear PCM encoding */
430 * These ranges apply to record, play, and
431 * monitor gain values
432  */
433 #define AUDIO_MIN_GAIN (0)/* minimum gain value */
434 #define AUDIO_MAX_GAIN (255) /* maximum gain value */
437 * These values apply to the balance field to adjust channel
438 * gain values
439  */
440 #define AUDIO_LEFT_BALANCE(0) /* left channel only */
441 #define AUDIO_MID_BALANCE (32) /* equal left/right balance */
442 #define AUDIO_RIGHT_BALANCE (64) /* right channel only */
445 * Define some convenient audio port names
446 * (for port, avail_ports and mod_ports)
447  */
449 /* output ports (several might be enabled at once) */
450 #define AUDIO_SPEAKER (0x01)/* built-in speaker */
451 #define AUDIO_HEADPHONE (0x02)/* headphone jack */
452 #define AUDIO_LINE_OUT (0x04)/* line out */
453 #define AUDIO_SPDIF_OUT (0x08)/* SPDIF port */
454 #define AUDIO_AUX1_OUT (0x10)/* aux1 out */
455 #define AUDIO_AUX2_OUT (0x20)/* aux2 out */
457 /* input ports (usually only one may be
458 * enabled at a time)
459  */
460 #define AUDIO_MICROPHONE (0x01) /* microphone */
461 #define AUDIO_LINE_IN (0x02) /* line in */
462 #define AUDIO_CD(0x04) /* on-board CD inputs */
463 #define AUDIO_SPDIF_IN (0x08) /* SPDIF port */
464 #define AUDIO_AUX1_IN (0x10) /* aux1 in */
465 #define AUDIO_AUX2_IN (0x20) /* aux2 in */
466 #define AUDIO_CODEC_LOOPB_IN (0x40) /* Codec inter.loopback */
468 /* These defines are for hardware features */
469 #define AUDIO_HWFEATURE_DUPLEX (0x00000001u)
470 /*simult. play & cap. supported */
472 #define AUDIO_HWFEATURE_MSCODEC (0x00000002u)
473 /* multi-stream Codec */
475 /* These defines are for software features *
476 #define AUDIO_SWFEATURE_MIXER (0x00000001u)
477  /* audio mixer audio pers. mod. */
480 * Parameter for the AUDIO_GETDEV ioctl
481 * to determine current audio devices
482 */#define MAX_AUDIO_DEV_LEN(16)
483 struct audio_device {
484  char name[MAX_AUDIO_DEV_LEN];
485  char version[MAX_AUDIO_DEV_LEN];
486  char config[MAX_AUDIO_DEV_LEN];
488 typedef struct audio_device audio_device_t;
490 .in -2
494 The \fIplay.gain\fR and \fIrecord.gain\fR fields specify the output and input
495 volume levels. A value of \fBAUDIO_MAX_GAIN\fR indicates maximum volume. Audio
496 output may also be temporarily muted by setting a non-zero value in the
497 \fIoutput_muted\fR field. Clearing this field restores audio output  to the
498 normal state.
501 The \fImonitor_gain\fR field is present for compatibility, and is no longer
502 supported. See \fBdsp\fR(7I) for more detail.
505 Likewise, the \fIplay.port\fR, \fIplay.ports\fR, \fIplay.mod_ports\fR,
506 \fIrecord.port\fR, \fIrecord.ports\fR, and \fIrecord.mod_ports\fR are no longer
507 supported. See \fBdsp\fR(7I) for more detail.
510 The \fIplay.balance\fR and \fIrecord.balance\fR fields are fixed to
511 \fBAUDIO_MID_BALANCE\fR. Changes to volume levels for different channels can be
512 made using the interfaces in \fBdsp\fR(7I).
515 The \fIplay.pause\fR and \fIrecord.pause\fR flags may be used to pause and
516 resume the transfer of data between the audio device and the STREAMS buffers.
517 The \fIplay.error\fR and \fIrecord.error\fR flags indicate that data underflow
518 or overflow has occurred. The \fIplay.active\fR and \fIrecord.active\fR flags
519 indicate  that data transfer is currently active in the corresponding
520 direction.
523 The \fIplay.open\fR and \fIrecord.open\fR flags indicate that the device is
524 currently open with the corresponding access permission. The \fIplay.waiting\fR
525 and \fIrecord.waiting\fR flags provide an indication that a process may be
526 waiting to access the device. These flags are set automatically when a process
527 blocks on \fBopen()\fR, though they may also be set using the
528 \fBAUDIO_SETINFO\fR ioctl command. They are cleared only when a process
529 relinquishes access by closing the device.
532 The \fIplay.samples\fR and \fIrecord.samples\fR fields are zeroed at
533 \fBopen()\fR and are incremented each time a data sample is copied to or from
534 the associated STREAMS queue. Some audio drivers may be limited to counting
535 buffers of samples, instead of single samples for their samples accounting. For
536 this reason, applications should not assume that the samples fields contain a
537 perfectly accurate count. The \fIplay.eof\fR field increments whenever a
538 zero-length output buffer is synchronously processed. Applications may use this
539 field to detect  the completion of particular segments of audio output.
542 The \fIrecord.buffer_size\fR field controls the amount of input data that is
543 buffered in the device driver during record operations. Applications that have
544 particular requirements for low latency should set the value appropriately.
545 Note however that smaller input buffer sizes may result in higher system
546 overhead. The value of this field is specified in bytes and drivers will
547 constrain it to be a multiple of the current sample frame size. Some drivers
548 may place other requirements on the value of this field. Refer to the audio
549 device-specific manual page for more details. If an application changes the
550 format of the audio device and does not modify the \fIrecord.buffer_size\fR
551 field, the device driver may use a default value to compensate for the new data
552 rate. Therefore, if an application is going to modify this field, it should
553 modify it during or after the format change itself, not before. When changing
554 the \fIrecord.buffer_size\fR parameters, the input stream should be paused and
555 flushed before the change, and resumed afterward. Otherwise,  subsequent reads
556 may return samples in the old format followed by samples in the new format.
557 This is particularly important when new parameters result in a changed sample
558 size. If you change the \fIrecord.buffer_size\fR for the first packet, this
559 protocol must be followed or the first buffer will be the default buffer size
560 for the device, followed by packets of the requested change size.
563 The \fIrecord.buffer_size\fR field may be modified only on the \fB/dev/audio\fR
564 device by processes that have it opened for reading.
567 The \fIplay.buffer_size\fR field is currently not supported.
570 The audio data format is indicated by the \fIsample_rate, channels,
571 precision\fR and encoding fields. The values of these fields correspond to the
572 descriptions in the \fBAUDIO FORMATS\fR section of this man page. Refer to the
573 audio device-specific manual pages for a list of supported data format
574 combinations.
577 The data format fields can be modified only on the \fB/dev/audio\fR device.
580 If the parameter changes requested by an \fBAUDIO_SETINFO\fR ioctl cannot all
581 be accommodated, \fBioctl()\fR returns with \fBerrno\fR set to \fBEINVAL\fR and
582 no changes are made to the device state.
583 .SS "Streamio IOCTLS"
586 All of the \fBstreamio\fR(7I) \fBioctl\fR commands may be issued for the
587 \fB/dev/audio\fR device. Because the \fB/dev/audioctl\fR device has its own
588 \fBSTREAMS\fR queues, most of these commands neither modify nor report the
589 state of \fB/dev/audio\fR if issued for the \fB/dev/audioctl\fR device. The
590 \fBI_SETSIG\fR \fBioctl\fR may be issued for \fB/dev/audioctl\fR to enable the
591 notification of audio status changes, as described above.
592 .SS "Audio IOCTLS"
595 The audio device additionally supports the following \fBioctl\fR commands:
597 .ne 2
599 \fB\fBAUDIO_DRAIN\fR\fR
601 .RS 17n
602 The argument is ignored. This command suspends the calling process until the
603 output STREAMS queue is empty and all queued samples have been played, or until
604 a signal is delivered to the calling process. It may not be issued for the
605 \fB/dev/audioctldevice\fR.  An implicit \fBAUDIO_DRAIN\fR is performed on the
606 final \fBclose()\fR of \fB/dev/audio\fR.
610 .ne 2
612 \fB\fBAUDIO_GETDEV\fR\fR
614 .RS 17n
615 The argument is a pointer to an \fBaudio_device_t\fR structure. This command
616 may be issued for either \fB/dev/audio\fR or \fB/dev/audioctl\fR. The returned
617 value in the name field will be a string that will identify the current
618 \fB/dev/audio\fR hardware device, the value in version will be a string
619 indicating the current version of the hardware, and \fBconfig\fR will be a
620 device-specific string identifying the properties of the audio stream
621 associated with that file descriptor. Refer to the audio device-specific manual
622 pages to determine the actual strings returned by the device driver.
626 .ne 2
628 \fB\fBAUDIO_GETINFO\fR\fR
630 .RS 17n
631 The argument is a pointer to an \fBaudio_info_t\fR structure. This command may
632 be issued for either \fB/dev/audio\fR or \fB/dev/audioctl\fR. The current state
633 of the \fB/dev/audio\fR device is returned in the structure.
635 Values return pertain to a logical view of the device as seen by and private to
636 the process, and do not necessarily reflect the actual hardware device itself.
640 .ne 2
642 \fB\fBAUDIO_SETINFO\fR\fR
644 .RS 17n
645 The argument is a pointer to an \fBaudio_info_t\fR structure. This command may
646 be issued for either the \fB/dev/audio\fR or the \fB/dev/audioctl\fR device
647 with some restrictions. This command configures the audio device according to
648 the supplied structure and overwrites the existing structure with the new state
649 of the device. Note: The \fIplay.samples\fR, \fIrecord.samples\fR,
650 \fIplay.error\fR, \fIrecord.error\fR, and \fIplay.eof\fR fields are modified to
651 reflect the state of the device when the \fBAUDIO_SETINFO\fR is issued. This
652 allows programs to automatically modify  these fields while retrieving the
653 previous value.
655 As with \fBAUDIO_SETINFO\fR, the settings managed by this ioctl deal with a
656 logical view of the device which is private to the process, and don't
657 necessarily have any impact on the hardware device itself.
662 Certain fields in the audio information structure, such as the pause flags, are
663 treated as read-only when \fB/dev/audio\fR is not open with the corresponding
664 access permission. Other fields, such as the gain levels and encoding
665 information, may have a restricted set of acceptable values. Applications that
666 attempt to modify such fields should check the returned values to be sure that
667 the corresponding change took effect. The \fIsample_rate\fR, \fIchannels\fR,
668 \fIprecision\fR, and \fIencoding\fR fields treated as read-only for
669 \fB/dev/audioctl\fR, so that applications  can be guaranteed that the existing
670 audio format will stay in place until they relinquish the audio device.
671 \fBAUDIO_SETINFO\fR will return \fBEINVAL\fR when the desired configuration is
672 not possible, or \fBEBUSY\fR when another process has control of the audio
673 device.
676 All of the logical device state is reset when the corresponding I/O stream of
677 \fB/dev/audio\fR is closed.
680 The \fBaudio_info_t\fR structure may be initialized through the use of the
681 \fBAUDIO_INITINFO\fR macro. This macro sets all fields in the structure to
682 values that are ignored by the \fBAUDIO_SETINFO\fR command. For instance, the
683 following code switches the output port from the built-in speaker to the
684 headphone jack without modifying any other audio parameters:
686 .in +2
688 audio_info_t info;
689 AUDIO_INITINFO();
690 info.play.port = AUDIO_HEADPHONE;
691 err = ioctl(audio_fd, AUDIO_SETINFO, );
693 .in -2
698 This technique eliminates problems associated with using a sequence of
699 \fBAUDIO_GETINFO\fR followed by \fBAUDIO_SETINFO\fR.
700 .SH ERRORS
703 An \fBopen()\fR will fail if:
705 .ne 2
707 \fB\fBEBUSY\fR\fR
709 .RS 9n
710 The requested play or record access is busy and either the \fBO_NDELAY\fR or
711 \fBO_NONBLOCK\fR flag was set in the \fBopen()\fR request.
715 .ne 2
717 \fB\fBEINTR\fR\fR
719 .RS 9n
720 The requested play or record access is busy and a signal interrupted the
721 \fBopen()\fR request.
726 An \fBioctl()\fR will fail if:
728 .ne 2
730 \fB\fBEINVAL\fR\fR
732 .RS 10n
733 The parameter changes requested in the \fBAUDIO_SETINFO()\fR ioctl are invalid
734 or are not supported by the device.
737 .SH FILES
740 The physical audio device names are system dependent and are rarely used by
741 programmers. Programmers should use the following generic device names:
743 .ne 2
745 \fB\fB/dev/audio\fR\fR
747 .RS 28n
748 Symbolic link to the system's primary audio device
752 .ne 2
754 \fB\fB/dev/audioctl\fR\fR
756 .RS 28n
757 Symbolic link to the control device for \fB/dev/audio\fR
761 .ne 2
763 \fB\fB/dev/sound/0\fR\fR
765 .RS 28n
766 First audio device in the system
770 .ne 2
772 \fB\fB/dev/sound/0ctl\fR\fR
774 .RS 28n
775 Audio control device for \fB/dev/sound/0\fR
778 .SH ATTRIBUTES
781 See \fBattributes\fR(5) for a description of the following attributes:
786 box;
787 c | c
788 l | l .
789 ATTRIBUTE TYPE  ATTRIBUTE VALUE
791 Architecture    SPARC, x86
793 Stability Level Obsolete Uncommitted
796 .SH SEE ALSO
799 \fBclose\fR(2), \fBfcntl\fR(2), \fBioctl\fR(2), \fBopen\fR(2), \fBpoll\fR(2),
800 \fBread\fR(2), \fBwrite\fR(2), \fBattributes\fR(5), \fBdsp\fR(7I),
801 \fBstreamio\fR(7I)
802 .SH BUGS
805 Due to a feature of the STREAMS implementation, programs that are terminated or
806 exit without closing the audio device may hang for a short period while audio
807 output drains. In general, programs that produce audio output should catch the
808 \fBSIGINT\fR signal and flush the output stream before exiting.