xref: /illumos-gate/usr/src/man/man4i/audio.4i (revision bbf215553c7233fbab8a0afdf1fac74c44781867)
1*bbf21555SRichard Lowe.\"  Copyright (c) 2009 Sun Microsystems, Inc. All rights reserved.
2*bbf21555SRichard Lowe.\" Copyright 2018, Joyent, Inc.
3*bbf21555SRichard Lowe.\" The contents of this file are subject to the terms of the
4*bbf21555SRichard Lowe.\" Common Development and Distribution License (the "License").
5*bbf21555SRichard Lowe.\" You may not use this file except in compliance with the License.
6*bbf21555SRichard Lowe.\"
7*bbf21555SRichard Lowe.\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
8*bbf21555SRichard Lowe.\" or http://www.opensolaris.org/os/licensing.
9*bbf21555SRichard Lowe.\" See the License for the specific language governing permissions
10*bbf21555SRichard Lowe.\" and limitations under the License.
11*bbf21555SRichard Lowe.\"
12*bbf21555SRichard Lowe.\" When distributing Covered Code, include this CDDL HEADER in each
13*bbf21555SRichard Lowe.\" file and include the License file at usr/src/OPENSOLARIS.LICENSE.
14*bbf21555SRichard Lowe.\" If applicable, add the following below this CDDL HEADER, with the
15*bbf21555SRichard Lowe.\" fields enclosed by brackets "[]" replaced with your own identifying
16*bbf21555SRichard Lowe.\" information: Portions Copyright [yyyy] [name of copyright owner]
17*bbf21555SRichard Lowe.Dd July 8, 2018
18*bbf21555SRichard Lowe.Dt AUDIO 4I
19*bbf21555SRichard Lowe.Os
20*bbf21555SRichard Lowe.Sh NAME
21*bbf21555SRichard Lowe.Nm audio
22*bbf21555SRichard Lowe.Nd generic audio device interface
23*bbf21555SRichard Lowe.Sh SYNOPSIS
24*bbf21555SRichard Lowe.In sys/audio.h
25*bbf21555SRichard Lowe.Sh OVERVIEW
26*bbf21555SRichard LoweAn audio device is used to play and/or record a stream of audio data.
27*bbf21555SRichard LoweSince a
28*bbf21555SRichard Lowespecific audio device may not support all functionality described below, refer
29*bbf21555SRichard Loweto the device-specific manual pages for a complete description of each hardware
30*bbf21555SRichard Lowedevice.
31*bbf21555SRichard LoweAn application can use the
32*bbf21555SRichard Lowe.Dv AUDIO_GETDEV
33*bbf21555SRichard Lowe.Xr ioctl 2
34*bbf21555SRichard Loweto determine the current audio hardware associated with
35*bbf21555SRichard Lowe.Pa /dev/audio .
36*bbf21555SRichard Lowe.Pp
37*bbf21555SRichard LoweThe audio framework provides a software mixing engine (audio mixer) for all
38*bbf21555SRichard Loweaudio devices, allowing more than one process to play or record audio at the
39*bbf21555SRichard Lowesame time.
40*bbf21555SRichard Lowe.Ss "Backward Compatibility"
41*bbf21555SRichard LoweIt is no longer possible to disable the mixing function.
42*bbf21555SRichard LoweApplications must not
43*bbf21555SRichard Loweassume that they have exclusive access to the audio device.
44*bbf21555SRichard Lowe.Ss "Multi-Stream Codecs"
45*bbf21555SRichard LoweThe audio mixer supports multi-stream Codecs.
46*bbf21555SRichard LoweThese devices have DSP engines
47*bbf21555SRichard Lowethat provide sample rate conversion, hardware mixing, and other features.
48*bbf21555SRichard LoweThe use of such hardware features is opaque to applications.
49*bbf21555SRichard Lowe.Sh AUDIO FORMATS
50*bbf21555SRichard LoweDigital audio data represents a quantized approximation of an analog audio
51*bbf21555SRichard Lowesignal waveform.
52*bbf21555SRichard LoweIn the simplest case, these quantized numbers represent the
53*bbf21555SRichard Loweamplitude of the input waveform at particular sampling intervals.
54*bbf21555SRichard LoweTo achieve the best approximation of an input signal, the highest possible sampling
55*bbf21555SRichard Lowefrequency and precision should be used.
56*bbf21555SRichard LoweHowever, increased accuracy comes at a cost of increased data storage requirements.
57*bbf21555SRichard LoweFor instance, one minute of
58*bbf21555SRichard Lowemonaural audio recorded in \(*m-Law format (pronounced
59*bbf21555SRichard Lowe.Em mew-law )
60*bbf21555SRichard Loweat 8 KHz requires nearly 0.5 megabytes of storage, while the standard Compact Disc
61*bbf21555SRichard Loweaudio format (stereo 16-bit linear
62*bbf21555SRichard Lowe.Sy PCM
63*bbf21555SRichard Lowedata sampled at 44.1 KHz) requires approximately 10 megabytes per minute.
64*bbf21555SRichard Lowe.Pp
65*bbf21555SRichard LoweAudio data may be represented in several different formats.
66*bbf21555SRichard LoweAn audio device's
67*bbf21555SRichard Lowecurrent audio data format can be determined by using the
68*bbf21555SRichard Lowe.Dv AUDIO_GETINFO
69*bbf21555SRichard Lowe.Xr ioctl 2
70*bbf21555SRichard Lowedescribed below.
71*bbf21555SRichard Lowe.Pp
72*bbf21555SRichard LoweAn audio data format is characterized in the audio driver by four parameters:
73*bbf21555SRichard LoweSample Rate, Encoding, Precision, and Channels.
74*bbf21555SRichard LoweRefer to the device-specific
75*bbf21555SRichard Lowemanual pages for a list of the audio formats that each device supports.
76*bbf21555SRichard LoweIn addition to the formats that the audio device supports directly, other formats
77*bbf21555SRichard Loweprovide higher data compression.
78*bbf21555SRichard LoweApplications may convert audio data to and
79*bbf21555SRichard Lowefrom these formats when playing or recording.
80*bbf21555SRichard Lowe.Ss "Sample Rate"
81*bbf21555SRichard LoweSample rate is a number that represents the sampling frequency (in samples per
82*bbf21555SRichard Lowesecond) of the audio data.
83*bbf21555SRichard Lowe.Pp
84*bbf21555SRichard LoweThe audio mixer always configures the hardware for the highest possible sample
85*bbf21555SRichard Lowerate for both play and record.
86*bbf21555SRichard LoweThis ensures that none of the audio streams
87*bbf21555SRichard Lowerequire compute-intensive low pass filtering.
88*bbf21555SRichard LoweThe result is that high sample rate audio streams are not degraded by filtering.
89*bbf21555SRichard Lowe.Pp
90*bbf21555SRichard LoweSample rate conversion can be a compute-intensive operation, depending on the
91*bbf21555SRichard Lowenumber of channels and a device's sample rate.
92*bbf21555SRichard LoweFor example, an 8KHz signal can
93*bbf21555SRichard Lowebe easily converted to 48KHz, requiring a low cost up sampling by 6.
94*bbf21555SRichard LoweHowever,
95*bbf21555SRichard Loweconverting from 44.1KHz to 48KHz is compute intensive because it must be up
96*bbf21555SRichard Lowesampled by 160 and then down sampled by 147.
97*bbf21555SRichard LoweThis is only done using integer multipliers.
98*bbf21555SRichard Lowe.Pp
99*bbf21555SRichard LoweApplications can greatly reduce the impact of sample rate conversion by
100*bbf21555SRichard Lowecarefully picking the sample rate.
101*bbf21555SRichard LoweApplications should always use the highest
102*bbf21555SRichard Lowesample rate the device supports.
103*bbf21555SRichard LoweAn application can also do its own sample rate
104*bbf21555SRichard Loweconversion (to take advantage of floating point and accelerated instruction or
105*bbf21555SRichard Loweuse small integers for up and down sampling.
106*bbf21555SRichard Lowe.Pp
107*bbf21555SRichard LoweAll modern audio devices run at 48 kHz or a multiple thereof, hence just using
108*bbf21555SRichard Lowe48 kHz may be a reasonable compromise if the application is not prepared to
109*bbf21555SRichard Loweselect higher sample rates.
110*bbf21555SRichard Lowe.Ss "Encodings"
111*bbf21555SRichard LoweAn encoding parameter specifies the audio data representation.
112*bbf21555SRichard Lowe\(*m-Law
113*bbf21555SRichard Loweencoding corresponds to
114*bbf21555SRichard Lowe.Em CCITT G.711 ,
115*bbf21555SRichard Loweand is the standard for voice data
116*bbf21555SRichard Loweused by telephone companies in the United States, Canada, and Japan.
117*bbf21555SRichard LoweA-Law encoding is also part of
118*bbf21555SRichard Lowe.Em CCITT G.711
119*bbf21555SRichard Loweand is the standard encoding for telephony elsewhere in the world.
120*bbf21555SRichard LoweA-Law and \(*m-Law audio data are sampled at
121*bbf21555SRichard Lowea rate of 8000 samples per second with 12-bit precision, with the data
122*bbf21555SRichard Lowecompressed to 8-bit samples.
123*bbf21555SRichard LoweThe resulting audio data quality is equivalent to
124*bbf21555SRichard Lowethat of standard analog telephone service.
125*bbf21555SRichard Lowe.Pp
126*bbf21555SRichard LoweLinear Pulse Code Modulation (PCM) is an uncompressed, signed audio format in
127*bbf21555SRichard Lowewhich sample values are directly proportional to audio signal voltages.
128*bbf21555SRichard LoweEach sample is a 2's complement number that represents a positive or negative
129*bbf21555SRichard Loweamplitude.
130*bbf21555SRichard Lowe.Ss "Precision"
131*bbf21555SRichard LowePrecision indicates the number of bits used to store each audio sample.
132*bbf21555SRichard LoweFor instance, \(*m-Law and A-Law data are stored with 8-bit precision.
133*bbf21555SRichard Lowe.Sy PCM
134*bbf21555SRichard Lowedata may be stored at various precisions, though 16-bit is the most common.
135*bbf21555SRichard Lowe.Ss "Channels"
136*bbf21555SRichard LoweMultiple channels of audio may be interleaved at sample boundaries.
137*bbf21555SRichard LoweA sample frame consists of a single sample from each active channel.
138*bbf21555SRichard LoweFor example, a sample frame of stereo 16-bit
139*bbf21555SRichard Lowe.Sy PCM
140*bbf21555SRichard Lowedata consists of two 16-bit samples,
141*bbf21555SRichard Lowecorresponding to the left and right channel data.
142*bbf21555SRichard Lowe.Pp
143*bbf21555SRichard LoweThe audio mixer sets the hardware to the maximum number of channels supported.
144*bbf21555SRichard LoweIf a mono signal is played or recorded, it is mixed on the first two (usually
145*bbf21555SRichard Lowethe left and right) channels only.
146*bbf21555SRichard LoweSilence is mixed on the remaining channels
147*bbf21555SRichard Lowe.Ss "Supported Formats"
148*bbf21555SRichard LoweThe audio mixer supports the following audio formats:
149*bbf21555SRichard Lowe.Bl -column "Signed Linear PCM" "Precision" "Mono or Stereo" -offset 2n
150*bbf21555SRichard Lowe.It Encoding Ta Precision Ta Channels
151*bbf21555SRichard Lowe.It "Signed Linear PCM" Ta "32-bit" Ta "Mono or Stereo"
152*bbf21555SRichard Lowe.It "Signed Linear PCM" Ta "16-bit" Ta "Mono or Stereo"
153*bbf21555SRichard Lowe.It "Signed Linear PCM" Ta "8-bit" Ta "Mono or Stereo"
154*bbf21555SRichard Lowe.It "\(*m-Law" Ta "8-bit" Ta "Mono or Stereo"
155*bbf21555SRichard Lowe.It "A-Law" Ta "8-bit" Ta "Mono or Stereo"
156*bbf21555SRichard Lowe.El
157*bbf21555SRichard Lowe.Pp
158*bbf21555SRichard LoweThe audio mixer converts all audio streams to 24-bit Linear PCM before mixing.
159*bbf21555SRichard LoweAfter mixing, conversion is made to the best possible Codec format.
160*bbf21555SRichard LoweThe
161*bbf21555SRichard Loweconversion process is not compute intensive and audio applications can choose
162*bbf21555SRichard Lowethe encoding format that best meets their needs.
163*bbf21555SRichard Lowe.Pp
164*bbf21555SRichard LoweNote that the mixer discards the low order 8 bits of 32-bit Signed Linear PCM
165*bbf21555SRichard Lowein order to perform mixing.
166*bbf21555SRichard Lowe(This is done to allow for possible overflows to
167*bbf21555SRichard Lowefit into 32-bits when mixing multiple streams together.)
168*bbf21555SRichard LoweHence, the maximum effective precision is 24-bits.
169*bbf21555SRichard Lowe.Sh DESCRIPTION
170*bbf21555SRichard LoweThe device
171*bbf21555SRichard Lowe.Pa /dev/audio
172*bbf21555SRichard Loweis a device driver that dispatches audio requests
173*bbf21555SRichard Loweto the appropriate underlying audio hardware.
174*bbf21555SRichard LoweThe audio driver is implemented as a
175*bbf21555SRichard Lowe.Sy STREAMS
176*bbf21555SRichard Lowedriver.
177*bbf21555SRichard LoweIn order to record audio input, applications
178*bbf21555SRichard Lowe.Xr open 2
179*bbf21555SRichard Lowethe
180*bbf21555SRichard Lowe.Pa /dev/audio
181*bbf21555SRichard Lowedevice and read data from it using the
182*bbf21555SRichard Lowe.Xr read 2
183*bbf21555SRichard Lowesystem call.
184*bbf21555SRichard LoweSimilarly, sound data is queued to the audio output port by using the
185*bbf21555SRichard Lowe.Xr write 2
186*bbf21555SRichard Lowesystem call.
187*bbf21555SRichard LoweDevice configuration is performed using the
188*bbf21555SRichard Lowe.Xr ioctl 2
189*bbf21555SRichard Loweinterface.
190*bbf21555SRichard Lowe.Pp
191*bbf21555SRichard LoweBecause some systems may contain more than one audio device, application
192*bbf21555SRichard Lowewriters are encouraged to query the
193*bbf21555SRichard Lowe.Ev AUDIODEV
194*bbf21555SRichard Loweenvironment variable.
195*bbf21555SRichard LoweIf this variable is present in the environment, its value should identify the
196*bbf21555SRichard Lowepath name of the default audio device.
197*bbf21555SRichard Lowe.Ss "Opening the Audio Device"
198*bbf21555SRichard LoweThe audio device is not treated as an exclusive resource.
199*bbf21555SRichard LoweEach process may open the audio device once.
200*bbf21555SRichard Lowe.Pp
201*bbf21555SRichard LoweEach
202*bbf21555SRichard Lowe.Xr open 2
203*bbf21555SRichard Lowecompletes as long as there are channels available to be allocated.
204*bbf21555SRichard LoweIf no channels are available to be allocated:
205*bbf21555SRichard Lowe.Bl -bullet -offset indent
206*bbf21555SRichard Lowe.It
207*bbf21555SRichard Loweif either the
208*bbf21555SRichard Lowe.Dv O_NDELAY
209*bbf21555SRichard Loweor
210*bbf21555SRichard Lowe.Dv O_NONBLOCK
211*bbf21555SRichard Loweflags are set in the
212*bbf21555SRichard Lowe.Xr open 2
213*bbf21555SRichard Lowe.Fa oflag
214*bbf21555SRichard Loweargument, then -1 is immediately returned, with
215*bbf21555SRichard Lowe.Va errno
216*bbf21555SRichard Loweset to
217*bbf21555SRichard Lowe.Er EBUSY .
218*bbf21555SRichard Lowe.It
219*bbf21555SRichard Loweif neither the
220*bbf21555SRichard Lowe.Dv O_NDELAY
221*bbf21555SRichard Lowenor the
222*bbf21555SRichard Lowe.Dv O_NONBLOCK
223*bbf21555SRichard Loweflag are set, then
224*bbf21555SRichard Lowe.Xr open 2
225*bbf21555SRichard Lowehangs until the device is available or a signal is delivered to
226*bbf21555SRichard Lowethe process, in which case a -1 is returned with
227*bbf21555SRichard Lowe.Va errno
228*bbf21555SRichard Loweset to
229*bbf21555SRichard Lowe.Er EINTR .
230*bbf21555SRichard Lowe.El
231*bbf21555SRichard Lowe.Pp
232*bbf21555SRichard LoweUpon the initial
233*bbf21555SRichard Lowe.Xr open 2
234*bbf21555SRichard Loweof the audio channel, the audio mixer sets the data
235*bbf21555SRichard Loweformat of the audio channel to the default state of 8-bit, 8Khz, mono \(*m-Law
236*bbf21555SRichard Lowedata.
237*bbf21555SRichard Lowe.Pp
238*bbf21555SRichard LoweIf the audio device does not support this configuration, it informs the
239*bbf21555SRichard Loweaudio mixer of the initial configuration.
240*bbf21555SRichard LoweAudio applications should explicitly set the encoding characteristics to match the
241*bbf21555SRichard Loweaudio data requirements, and not depend on the default configuration.
242*bbf21555SRichard Lowe.Ss "Recording Audio Data"
243*bbf21555SRichard LoweThe
244*bbf21555SRichard Lowe.Xr read 2
245*bbf21555SRichard Lowesystem call copies data from the system's buffers to the application.
246*bbf21555SRichard LoweOrdinarily,
247*bbf21555SRichard Lowe.Xr read 2
248*bbf21555SRichard Loweblocks until the user buffer is filled.
249*bbf21555SRichard LoweThe
250*bbf21555SRichard Lowe.Dv I_NREAD
251*bbf21555SRichard Lowe.Sy ioctl
252*bbf21555SRichard Lowe(see
253*bbf21555SRichard Lowe.Xr streamio 4I )
254*bbf21555SRichard Lowemay be used to determine the amount of data that may be read without blocking.
255*bbf21555SRichard LoweThe device may alternatively be set to a non-blocking mode, in which case
256*bbf21555SRichard Lowe.Xr read 2
257*bbf21555SRichard Lowecompletes immediately, but may return fewer bytes than requested.
258*bbf21555SRichard LoweRefer to the
259*bbf21555SRichard Lowe.Xr read 2
260*bbf21555SRichard Lowemanual page for a complete description of this behavior.
261*bbf21555SRichard Lowe.Pp
262*bbf21555SRichard LoweWhen the audio device is opened with read access, the device driver immediately
263*bbf21555SRichard Lowestarts buffering audio input data.
264*bbf21555SRichard LoweSince this consumes system resources,
265*bbf21555SRichard Loweprocesses that do not record audio data should open the device write-only
266*bbf21555SRichard Lowe.Pq Dv O_WRONLY .
267*bbf21555SRichard Lowe.Pp
268*bbf21555SRichard LoweThe transfer of input data to
269*bbf21555SRichard Lowe.Sy STREAMS
270*bbf21555SRichard Lowebuffers may be paused (or resumed) by using the
271*bbf21555SRichard Lowe.Dv AUDIO_SETINFO
272*bbf21555SRichard Lowe.Sy ioctl
273*bbf21555SRichard Loweto set (or clear) the
274*bbf21555SRichard Lowe.Fa record.pause
275*bbf21555SRichard Loweflag in the audio information structure (see below).
276*bbf21555SRichard LoweAll unread input data in the
277*bbf21555SRichard Lowe.Sy STREAMS
278*bbf21555SRichard Lowequeue may be discarded by using the
279*bbf21555SRichard Lowe.Dv I_FLUSH
280*bbf21555SRichard Lowe.Sy STREAMS
281*bbf21555SRichard Loweioctl.
282*bbf21555SRichard LoweSee
283*bbf21555SRichard Lowe.Xr streamio 4I .
284*bbf21555SRichard LoweWhen changing record parameters, the input stream should be paused and flushed
285*bbf21555SRichard Lowebefore the change, and resumed afterward.
286*bbf21555SRichard LoweOtherwise, subsequent reads may return samples
287*bbf21555SRichard Lowein the old format followed by samples in the new format.
288*bbf21555SRichard LoweThis is particularly important when new parameters result in a changed sample size.
289*bbf21555SRichard Lowe.Pp
290*bbf21555SRichard LoweInput data can accumulate in
291*bbf21555SRichard Lowe.Sy STREAMS
292*bbf21555SRichard Lowebuffers very quickly.
293*bbf21555SRichard LoweAt a minimum,
294*bbf21555SRichard Loweit will accumulate at 8000 bytes per second for 8-bit, 8 KHz, mono, \(*m-Law data.
295*bbf21555SRichard LoweIf the device is configured for 16-bit linear or higher sample rates, it will
296*bbf21555SRichard Loweaccumulate even faster.
297*bbf21555SRichard LoweIf the application that consumes the data cannot keep
298*bbf21555SRichard Loweup with this data rate, the
299*bbf21555SRichard Lowe.Sy STREAMS
300*bbf21555SRichard Lowequeue may become full.
301*bbf21555SRichard LoweWhen this occurs, the
302*bbf21555SRichard Lowe.Fa record.error
303*bbf21555SRichard Loweflag is set in the audio information structure and input sampling ceases until
304*bbf21555SRichard Lowethere is room in the input queue for additional data.
305*bbf21555SRichard LoweIn such cases, the input data stream contains a discontinuity.
306*bbf21555SRichard LoweFor this reason, audio recording applications should open the audio device when
307*bbf21555SRichard Lowethey are prepared to begin reading data, rather than at the start of extensive
308*bbf21555SRichard Loweinitialization.
309*bbf21555SRichard Lowe.Ss "Playing Audio Data"
310*bbf21555SRichard LoweThe
311*bbf21555SRichard Lowe.Xr write 2
312*bbf21555SRichard Lowesystem call copies data from an application's buffer to the
313*bbf21555SRichard Lowe.Sy STREAMS
314*bbf21555SRichard Loweoutput queue.
315*bbf21555SRichard LoweOrdinarily,
316*bbf21555SRichard Lowe.Xr write 2
317*bbf21555SRichard Loweblocks until the entire user buffer is transferred.
318*bbf21555SRichard LoweThe device may alternatively be set to a non-blocking mode, in which case
319*bbf21555SRichard Lowe.Xr write 2
320*bbf21555SRichard Lowecompletes immediately, but may have transferred fewer bytes than requested.
321*bbf21555SRichard LoweSee
322*bbf21555SRichard Lowe.Xr write 2 .
323*bbf21555SRichard Lowe.Pp
324*bbf21555SRichard LoweAlthough
325*bbf21555SRichard Lowe.Xr write 2
326*bbf21555SRichard Lowereturns when the data is successfully queued, the actual
327*bbf21555SRichard Lowecompletion of audio output may take considerably longer.
328*bbf21555SRichard LoweThe
329*bbf21555SRichard Lowe.Dv AUDIO_DRAIN
330*bbf21555SRichard Loweioctl may be issued to allow an application to block until all of the
331*bbf21555SRichard Lowequeued output data has been played.
332*bbf21555SRichard LoweAlternatively, a process may request
333*bbf21555SRichard Loweasynchronous notification of output completion by writing a zero-length buffer
334*bbf21555SRichard Lowe(end-of-file record) to the output stream.
335*bbf21555SRichard LoweWhen such a buffer has been
336*bbf21555SRichard Loweprocessed, the
337*bbf21555SRichard Lowe.Fa play.eof
338*bbf21555SRichard Loweflag in the audio information structure is incremented.
339*bbf21555SRichard Lowe.Pp
340*bbf21555SRichard LoweThe final
341*bbf21555SRichard Lowe.Xr close 2
342*bbf21555SRichard Loweof the file descriptor hangs until all of the audio
343*bbf21555SRichard Loweoutput has drained.
344*bbf21555SRichard LoweIf a signal interrupts the
345*bbf21555SRichard Lowe.Xr close 2 ,
346*bbf21555SRichard Loweor if the process exits without closing the device, any remaining data queued
347*bbf21555SRichard Lowefor audio output is flushed and the device is closed immediately.
348*bbf21555SRichard Lowe.Pp
349*bbf21555SRichard LoweThe consumption of output data may be paused (or resumed) by using the
350*bbf21555SRichard Lowe.Dv AUDIO_SETINFO
351*bbf21555SRichard Loweioctl to set (or clear) the
352*bbf21555SRichard Lowe.Fa play.pause
353*bbf21555SRichard Loweflag in the audio information structure.
354*bbf21555SRichard LoweQueued output data may be discarded by using
355*bbf21555SRichard Lowethe
356*bbf21555SRichard Lowe.Dv I_FLUSH
357*bbf21555SRichard Lowe.Sy STREAMS
358*bbf21555SRichard Loweioctl.
359*bbf21555SRichard Lowe(See
360*bbf21555SRichard Lowe.Xr streamio 4I ) .
361*bbf21555SRichard Lowe.Pp
362*bbf21555SRichard LoweOutput data is played from the
363*bbf21555SRichard Lowe.Sy STREAMS
364*bbf21555SRichard Lowebuffers at a default rate of at
365*bbf21555SRichard Loweleast 8000 bytes per second for \(*m-Law, A-Law or 8-bit PCM data (faster for
366*bbf21555SRichard Lowe16-bit linear data or higher sampling rates).
367*bbf21555SRichard LoweIf the output queue becomes
368*bbf21555SRichard Loweempty, the
369*bbf21555SRichard Lowe.Fa play.error
370*bbf21555SRichard Loweflag is set in the audio information structure and
371*bbf21555SRichard Loweoutput is stopped until additional data is written.
372*bbf21555SRichard LoweIf an application attempts
373*bbf21555SRichard Loweto write a number of bytes that is not a multiple of the current sample frame
374*bbf21555SRichard Lowesize, an error is generated and the bad data is thrown away.
375*bbf21555SRichard LoweAdditional writes are allowed.
376*bbf21555SRichard Lowe.Ss "Asynchronous I/O"
377*bbf21555SRichard LoweThe
378*bbf21555SRichard Lowe.Dv I_SETSIG
379*bbf21555SRichard Lowe.Sy STREAMS
380*bbf21555SRichard Loweioctl
381*bbf21555SRichard Loweenables asynchronous notification, through the
382*bbf21555SRichard Lowe.Dv SIGPOLL
383*bbf21555SRichard Lowesignal, of input and output ready condition changes.
384*bbf21555SRichard LoweThe
385*bbf21555SRichard Lowe.Dv O_NONBLOCK
386*bbf21555SRichard Loweflag may be set using the
387*bbf21555SRichard Lowe.Dv F_SETFL
388*bbf21555SRichard Lowe.Xr fcntl 2
389*bbf21555SRichard Loweto
390*bbf21555SRichard Loweenable non-blocking
391*bbf21555SRichard Lowe.Xr read 2
392*bbf21555SRichard Loweand
393*bbf21555SRichard Lowe.Xr write 2
394*bbf21555SRichard Lowerequests.
395*bbf21555SRichard LoweThis is normally
396*bbf21555SRichard Lowesufficient for applications to maintain an audio stream in the background.
397*bbf21555SRichard Lowe.Ss "Audio Control Pseudo-Device"
398*bbf21555SRichard LoweIt is sometimes convenient to have an application, such as a volume control
399*bbf21555SRichard Lowepanel, modify certain characteristics of the audio device while it is being
400*bbf21555SRichard Loweused by an unrelated process.
401*bbf21555SRichard Lowe.Pp
402*bbf21555SRichard LoweThe
403*bbf21555SRichard Lowe.Pa /dev/audioctl
404*bbf21555SRichard Lowepseudo-device is provided for this purpose.
405*bbf21555SRichard LoweAny number of processes may open
406*bbf21555SRichard Lowe.Pa /dev/audioctl
407*bbf21555SRichard Lowesimultaneously.
408*bbf21555SRichard LoweHowever,
409*bbf21555SRichard Lowe.Xr read 2
410*bbf21555SRichard Loweand
411*bbf21555SRichard Lowe.Xr write 2
412*bbf21555SRichard Lowesystem calls are ignored by
413*bbf21555SRichard Lowe.Pa /dev/audioctl .
414*bbf21555SRichard LoweThe
415*bbf21555SRichard Lowe.Dv AUDIO_GETINFO
416*bbf21555SRichard Loweand
417*bbf21555SRichard Lowe.Dv AUDIO_SETINFO
418*bbf21555SRichard Loweioctl commands may be issued to
419*bbf21555SRichard Lowe.Pa /dev/audioctl
420*bbf21555SRichard Loweto determine the status or alter the behavior of
421*bbf21555SRichard Lowe.Pa /dev/audio .
422*bbf21555SRichard LoweNote: In general, the audio control device name is
423*bbf21555SRichard Loweconstructed by appending the letters
424*bbf21555SRichard Lowe.Qq Sy ctl
425*bbf21555SRichard Loweto the path name of the audio device.
426*bbf21555SRichard Lowe.Ss "Audio Status Change Notification"
427*bbf21555SRichard LoweApplications that open the audio control pseudo-device may request asynchronous
428*bbf21555SRichard Lowenotification of changes in the state of the audio device by setting the
429*bbf21555SRichard Lowe.Dv S_MSG
430*bbf21555SRichard Loweflag in an
431*bbf21555SRichard Lowe.Dv I_SETSIG
432*bbf21555SRichard Lowe.Sy STREAMS
433*bbf21555SRichard Loweioctl.
434*bbf21555SRichard LoweSuch processes receive a
435*bbf21555SRichard Lowe.Dv SIGPOLL
436*bbf21555SRichard Lowesignal when any of the following events occur:
437*bbf21555SRichard Lowe.Bl -bullet -offset indent
438*bbf21555SRichard Lowe.It
439*bbf21555SRichard LoweAn
440*bbf21555SRichard Lowe.Dv AUDIO_SETINFO
441*bbf21555SRichard Loweioctl has altered the device state.
442*bbf21555SRichard Lowe.It
443*bbf21555SRichard LoweAn input overflow or output underflow has occurred.
444*bbf21555SRichard Lowe.It
445*bbf21555SRichard LoweAn end-of-file record (zero-length buffer) has been processed on output.
446*bbf21555SRichard Lowe.It
447*bbf21555SRichard LoweAn
448*bbf21555SRichard Lowe.Xr open 2
449*bbf21555SRichard Loweor
450*bbf21555SRichard Lowe.Xr close 2
451*bbf21555SRichard Loweof
452*bbf21555SRichard Lowe.Pa /dev/audio
453*bbf21555SRichard Lowehas altered the device state.
454*bbf21555SRichard Lowe.It
455*bbf21555SRichard LoweAn external event (such as speakerbox's volume control) has altered the device
456*bbf21555SRichard Lowestate.
457*bbf21555SRichard Lowe.El
458*bbf21555SRichard Lowe.Sh IOCTLS
459*bbf21555SRichard Lowe.Ss "Audio Information Structure"
460*bbf21555SRichard LoweThe state of the audio device may be polled or modified using the
461*bbf21555SRichard Lowe.Dv AUDIO_GETINFO
462*bbf21555SRichard Loweand
463*bbf21555SRichard Lowe.Dv AUDIO_SETINFO
464*bbf21555SRichard Loweioctl commands.
465*bbf21555SRichard LoweThese commands operate on the
466*bbf21555SRichard Lowe.Vt audio_info
467*bbf21555SRichard Lowestructure as defined, in
468*bbf21555SRichard Lowe.In sys/audio.h ,
469*bbf21555SRichard Loweas follows:
470*bbf21555SRichard Lowe.Bd -literal -offset 2n
471*bbf21555SRichard Lowe/*
472*bbf21555SRichard Lowe * This structure contains state information for audio device
473*bbf21555SRichard Lowe * IO streams
474*bbf21555SRichard Lowe */
475*bbf21555SRichard Lowe
476*bbf21555SRichard Lowestruct audio_prinfo {
477*bbf21555SRichard Lowe     /*
478*bbf21555SRichard Lowe      * The following values describe the
479*bbf21555SRichard Lowe      * audio data encoding
480*bbf21555SRichard Lowe      */
481*bbf21555SRichard Lowe      uint_t sample_rate; /* samples per second */
482*bbf21555SRichard Lowe      uint_t channels;    /* number of interleaved channels */
483*bbf21555SRichard Lowe      uint_t precision;   /* number of bits per sample */
484*bbf21555SRichard Lowe      uint_t encoding;    /* data encoding method */
485*bbf21555SRichard Lowe
486*bbf21555SRichard Lowe      /*
487*bbf21555SRichard Lowe       * The following values control audio device
488*bbf21555SRichard Lowe       * configuration
489*bbf21555SRichard Lowe       */
490*bbf21555SRichard Lowe      uint_t gain; /* volume level */
491*bbf21555SRichard Lowe      uint_t port; /* selected I/O port */
492*bbf21555SRichard Lowe      uint_t buffer_size; /* I/O buffer size */
493*bbf21555SRichard Lowe
494*bbf21555SRichard Lowe     /*
495*bbf21555SRichard Lowe      * The following values describe the current device
496*bbf21555SRichard Lowe      * state
497*bbf21555SRichard Lowe      */
498*bbf21555SRichard Lowe     uint_t samples; /* number of samples converted */
499*bbf21555SRichard Lowe     uint_t eof;     /* End Of File counter (play only) */
500*bbf21555SRichard Lowe     uchar_t pause;  /* non-zero if paused, zero to resume */
501*bbf21555SRichard Lowe     uchar_t error;  /* non-zero if overflow/underflow */
502*bbf21555SRichard Lowe     uchar_t waiting; /* non-zero if a process wants access */
503*bbf21555SRichard Lowe     uchar_t balance; /* stereo channel balance */
504*bbf21555SRichard Lowe
505*bbf21555SRichard Lowe     /*
506*bbf21555SRichard Lowe      * The following values are read-only device state
507*bbf21555SRichard Lowe      * information
508*bbf21555SRichard Lowe      */
509*bbf21555SRichard Lowe      uchar_t open;   /* non-zero if open access granted */
510*bbf21555SRichard Lowe      uchar_t active; /* non-zero if I/O active */
511*bbf21555SRichard Lowe      uint_t avail_ports; /* available I/O ports */
512*bbf21555SRichard Lowe      uint_t mod_ports; /* modifiable I/O ports */
513*bbf21555SRichard Lowe};
514*bbf21555SRichard Lowetypedef struct audio_prinfo audio_prinfo_t;
515*bbf21555SRichard Lowe
516*bbf21555SRichard Lowe/*
517*bbf21555SRichard Lowe * This structure is used in AUDIO_GETINFO and AUDIO_SETINFO ioctl
518*bbf21555SRichard Lowe * commands
519*bbf21555SRichard Lowe */
520*bbf21555SRichard Lowestruct audio_info {
521*bbf21555SRichard Lowe    audio_prinfo_t record;/* input status info */
522*bbf21555SRichard Lowe    audio_prinfo_t play; /* output status info */
523*bbf21555SRichard Lowe    uint_t monitor_gain; /* input to output mix */
524*bbf21555SRichard Lowe    uchar_toutput_muted; /* non-zero if output muted */
525*bbf21555SRichard Lowe    uint_t hw_features;  /* supported H/W features */
526*bbf21555SRichard Lowe    uint_t sw_features;  /* supported S/W features */
527*bbf21555SRichard Lowe    uint_t sw_features_enabled;
528*bbf21555SRichard Lowe                /* supported S/W features enabled */
529*bbf21555SRichard Lowe};
530*bbf21555SRichard Lowetypedef struct audio_info audio_info_t;
531*bbf21555SRichard Lowe
532*bbf21555SRichard Lowe/* Audio encoding types */
533*bbf21555SRichard Lowe#define AUDIO_ENCODING_ULAW (1) /* u-Law encoding */
534*bbf21555SRichard Lowe#define AUDIO_ENCODING_ALAW (2) /* A-Law encoding */
535*bbf21555SRichard Lowe#define AUDIO_ENCODING_LINEAR (3) /* Signed Linear PCM encoding */
536*bbf21555SRichard Lowe
537*bbf21555SRichard Lowe/*
538*bbf21555SRichard Lowe * These ranges apply to record, play, and
539*bbf21555SRichard Lowe * monitor gain values
540*bbf21555SRichard Lowe */
541*bbf21555SRichard Lowe#define AUDIO_MIN_GAIN (0)/* minimum gain value */
542*bbf21555SRichard Lowe#define AUDIO_MAX_GAIN (255) /* maximum gain value */
543*bbf21555SRichard Lowe
544*bbf21555SRichard Lowe/*
545*bbf21555SRichard Lowe * These values apply to the balance field to adjust channel
546*bbf21555SRichard Lowe * gain values
547*bbf21555SRichard Lowe */
548*bbf21555SRichard Lowe#define AUDIO_LEFT_BALANCE   (0) /* left channel only */
549*bbf21555SRichard Lowe#define AUDIO_MID_BALANCE   (32) /* equal left/right balance */
550*bbf21555SRichard Lowe#define AUDIO_RIGHT_BALANCE (64) /* right channel only */
551*bbf21555SRichard Lowe
552*bbf21555SRichard Lowe/*
553*bbf21555SRichard Lowe * Define some convenient audio port names
554*bbf21555SRichard Lowe * (for port, avail_ports and mod_ports)
555*bbf21555SRichard Lowe */
556*bbf21555SRichard Lowe
557*bbf21555SRichard Lowe/* output ports (several might be enabled at once) */
558*bbf21555SRichard Lowe#define AUDIO_SPEAKER   (0x01) /* built-in speaker */
559*bbf21555SRichard Lowe#define AUDIO_HEADPHONE (0x02) /* headphone jack */
560*bbf21555SRichard Lowe#define AUDIO_LINE_OUT  (0x04) /* line out */
561*bbf21555SRichard Lowe#define AUDIO_SPDIF_OUT (0x08) /* SPDIF port */
562*bbf21555SRichard Lowe#define AUDIO_AUX1_OUT  (0x10) /* aux1 out */
563*bbf21555SRichard Lowe#define AUDIO_AUX2_OUT  (0x20) /* aux2 out */
564*bbf21555SRichard Lowe
565*bbf21555SRichard Lowe/*
566*bbf21555SRichard Lowe * input ports (usually only one may be enabled at a time)
567*bbf21555SRichard Lowe */
568*bbf21555SRichard Lowe#define AUDIO_MICROPHONE (0x01) /* microphone */
569*bbf21555SRichard Lowe#define AUDIO_LINE_IN  (0x02) /* line in */
570*bbf21555SRichard Lowe#define AUDIO_CD       (0x04) /* on-board CD inputs */
571*bbf21555SRichard Lowe#define AUDIO_SPDIF_IN (0x08) /* SPDIF port */
572*bbf21555SRichard Lowe#define AUDIO_AUX1_IN  (0x10) /* aux1 in */
573*bbf21555SRichard Lowe#define AUDIO_AUX2_IN  (0x20) /* aux2 in */
574*bbf21555SRichard Lowe#define AUDIO_CODEC_LOOPB_IN (0x40) /* Codec inter. loopback */
575*bbf21555SRichard Lowe
576*bbf21555SRichard Lowe/* These defines are for hardware features */
577*bbf21555SRichard Lowe#define AUDIO_HWFEATURE_DUPLEX (0x00000001u)
578*bbf21555SRichard Lowe/* simult. play & cap. supported */
579*bbf21555SRichard Lowe
580*bbf21555SRichard Lowe#define AUDIO_HWFEATURE_MSCODEC (0x00000002u)
581*bbf21555SRichard Lowe/* multi-stream Codec */
582*bbf21555SRichard Lowe
583*bbf21555SRichard Lowe/* These defines are for software features *
584*bbf21555SRichard Lowe#define AUDIO_SWFEATURE_MIXER (0x00000001u)
585*bbf21555SRichard Lowe/* audio mixer audio pers. mod. */
586*bbf21555SRichard Lowe
587*bbf21555SRichard Lowe/*
588*bbf21555SRichard Lowe * Parameter for the AUDIO_GETDEV ioctl
589*bbf21555SRichard Lowe * to determine current audio devices
590*bbf21555SRichard Lowe */
591*bbf21555SRichard Lowe#define MAX_AUDIO_DEV_LEN (16)
592*bbf21555SRichard Lowestruct audio_device {
593*bbf21555SRichard Lowe    char name[MAX_AUDIO_DEV_LEN];
594*bbf21555SRichard Lowe    char version[MAX_AUDIO_DEV_LEN];
595*bbf21555SRichard Lowe    char config[MAX_AUDIO_DEV_LEN];
596*bbf21555SRichard Lowe};
597*bbf21555SRichard Lowetypedef struct audio_device audio_device_t;
598*bbf21555SRichard Lowe.Ed
599*bbf21555SRichard Lowe.Pp
600*bbf21555SRichard LoweThe
601*bbf21555SRichard Lowe.Fa play.gain
602*bbf21555SRichard Loweand
603*bbf21555SRichard Lowe.Fa record.gain
604*bbf21555SRichard Lowefields specify the output and input volume levels.
605*bbf21555SRichard LoweA value of
606*bbf21555SRichard Lowe.Dv AUDIO_MAX_GAIN
607*bbf21555SRichard Loweindicates maximum volume.
608*bbf21555SRichard LoweAudio output may also be temporarily muted by setting a non-zero value in the
609*bbf21555SRichard Lowe.Fa output_muted
610*bbf21555SRichard Lowefield.
611*bbf21555SRichard LoweClearing this field restores audio output to the normal state.
612*bbf21555SRichard Lowe.Pp
613*bbf21555SRichard LoweThe
614*bbf21555SRichard Lowe.Va monitor_gain
615*bbf21555SRichard Lowefield is present for compatibility, and is no longer supported.
616*bbf21555SRichard LoweSee
617*bbf21555SRichard Lowe.Xr dsp 4I
618*bbf21555SRichard Lowefor more detail.
619*bbf21555SRichard Lowe.Pp
620*bbf21555SRichard LoweLikewise, the
621*bbf21555SRichard Lowe.Fa play.port ,
622*bbf21555SRichard Lowe.Fa play.ports ,
623*bbf21555SRichard Lowe.Fa play.mod_ports ,
624*bbf21555SRichard Lowe.Fa record.port ,
625*bbf21555SRichard Lowe.Fa record.ports ,
626*bbf21555SRichard Loweand
627*bbf21555SRichard Lowe.Fa record.mod_ports
628*bbf21555SRichard Loweare no longer supported.
629*bbf21555SRichard LoweSee
630*bbf21555SRichard Lowe.Xr dsp 4I
631*bbf21555SRichard Lowefor more detail.
632*bbf21555SRichard Lowe.Pp
633*bbf21555SRichard LoweThe
634*bbf21555SRichard Lowe.Fa play.balance
635*bbf21555SRichard Loweand
636*bbf21555SRichard Lowe.Fa record.balance
637*bbf21555SRichard Lowefields are fixed to
638*bbf21555SRichard Lowe.Dv AUDIO_MID_BALANCE .
639*bbf21555SRichard LoweChanges to volume levels for different channels can be
640*bbf21555SRichard Lowemade using the interfaces in
641*bbf21555SRichard Lowe.Xr dsp 4I .
642*bbf21555SRichard Lowe.Pp
643*bbf21555SRichard LoweThe
644*bbf21555SRichard Lowe.Fa play.pause
645*bbf21555SRichard Loweand
646*bbf21555SRichard Lowe.Fa record.pause
647*bbf21555SRichard Loweflags may be used to pause and
648*bbf21555SRichard Loweresume the transfer of data between the audio device and the
649*bbf21555SRichard Lowe.Sy STREAMS
650*bbf21555SRichard Lowebuffers.
651*bbf21555SRichard LoweThe
652*bbf21555SRichard Lowe.Fa play.error
653*bbf21555SRichard Loweand
654*bbf21555SRichard Lowe.Fa record.error
655*bbf21555SRichard Loweflags indicate that data underflow or overflow has occurred.
656*bbf21555SRichard LoweThe
657*bbf21555SRichard Lowe.Fa play.active
658*bbf21555SRichard Loweand
659*bbf21555SRichard Lowe.Fa record.active
660*bbf21555SRichard Loweflags indicate that data transfer is currently active in the corresponding
661*bbf21555SRichard Lowedirection.
662*bbf21555SRichard Lowe.Pp
663*bbf21555SRichard LoweThe
664*bbf21555SRichard Lowe.Fa play.open
665*bbf21555SRichard Loweand
666*bbf21555SRichard Lowe.Fa record.open
667*bbf21555SRichard Loweflags indicate that the device is
668*bbf21555SRichard Lowecurrently open with the corresponding access permission.
669*bbf21555SRichard LoweThe
670*bbf21555SRichard Lowe.Fa play.waiting
671*bbf21555SRichard Loweand
672*bbf21555SRichard Lowe.Fa record.waiting
673*bbf21555SRichard Loweflags provide an indication that a process may be waiting to access the device.
674*bbf21555SRichard LoweThese flags are set automatically when a process blocks on
675*bbf21555SRichard Lowe.Xr open 2 ,
676*bbf21555SRichard Lowethough they may also be set using the
677*bbf21555SRichard Lowe.Dv AUDIO_SETINFO
678*bbf21555SRichard Loweioctl command.
679*bbf21555SRichard LoweThey are cleared only when a process relinquishes access by closing the device.
680*bbf21555SRichard Lowe.Pp
681*bbf21555SRichard LoweThe
682*bbf21555SRichard Lowe.Fa play.samples
683*bbf21555SRichard Loweand
684*bbf21555SRichard Lowe.Fa record.samples
685*bbf21555SRichard Lowefields are zeroed at
686*bbf21555SRichard Lowe.Xr open 2
687*bbf21555SRichard Loweand are incremented each time a data sample is copied to or from
688*bbf21555SRichard Lowethe associated
689*bbf21555SRichard Lowe.Sy STREAMS
690*bbf21555SRichard Lowequeue.
691*bbf21555SRichard LoweSome audio drivers may be limited to counting
692*bbf21555SRichard Lowebuffers of samples, instead of single samples for their samples accounting.
693*bbf21555SRichard LoweFor this reason, applications should not assume that the samples fields contain a
694*bbf21555SRichard Loweperfectly accurate count.
695*bbf21555SRichard LoweThe
696*bbf21555SRichard Lowe.Fa play.eof
697*bbf21555SRichard Lowefield increments whenever a zero-length output buffer is synchronously processed.
698*bbf21555SRichard LoweApplications may use this
699*bbf21555SRichard Lowefield to detect the completion of particular segments of audio output.
700*bbf21555SRichard Lowe.Pp
701*bbf21555SRichard LoweThe
702*bbf21555SRichard Lowe.Fa record.buffer_size
703*bbf21555SRichard Lowefield controls the amount of input data that is
704*bbf21555SRichard Lowebuffered in the device driver during record operations.
705*bbf21555SRichard LoweApplications that have
706*bbf21555SRichard Loweparticular requirements for low latency should set the value appropriately.
707*bbf21555SRichard LoweNote however that smaller input buffer sizes may result in higher system
708*bbf21555SRichard Loweoverhead.
709*bbf21555SRichard LoweThe value of this field is specified in bytes and drivers will
710*bbf21555SRichard Loweconstrain it to be a multiple of the current sample frame size.
711*bbf21555SRichard LoweSome drivers may place other requirements on the value of this field.
712*bbf21555SRichard LoweRefer to the audio device-specific manual page for more details.
713*bbf21555SRichard LoweIf an application changes the
714*bbf21555SRichard Loweformat of the audio device and does not modify the
715*bbf21555SRichard Lowe.Fa record.buffer_size
716*bbf21555SRichard Lowefield, the device driver may use a default value to compensate for the new data
717*bbf21555SRichard Lowerate.
718*bbf21555SRichard LoweTherefore, if an application is going to modify this field, it should
719*bbf21555SRichard Lowemodify it during or after the format change itself, not before.
720*bbf21555SRichard LoweWhen changing
721*bbf21555SRichard Lowethe
722*bbf21555SRichard Lowe.Fa record.buffer_size
723*bbf21555SRichard Loweparameters, the input stream should be paused and
724*bbf21555SRichard Loweflushed before the change, and resumed afterward.
725*bbf21555SRichard LoweOtherwise, subsequent reads
726*bbf21555SRichard Lowemay return samples in the old format followed by samples in the new format.
727*bbf21555SRichard LoweThis is particularly important when new parameters result in a changed sample
728*bbf21555SRichard Lowesize.
729*bbf21555SRichard LoweIf you change the
730*bbf21555SRichard Lowe.Fa record.buffer_size
731*bbf21555SRichard Lowefor the first packet, this protocol must be followed or the first buffer will
732*bbf21555SRichard Lowebe the default buffer size for the device, followed by packets of the requested
733*bbf21555SRichard Lowechange size.
734*bbf21555SRichard Lowe.Pp
735*bbf21555SRichard LoweThe
736*bbf21555SRichard Lowe.Fa record.buffer_size
737*bbf21555SRichard Lowefield may be modified only on the
738*bbf21555SRichard Lowe.Pa /dev/audio
739*bbf21555SRichard Lowedevice by processes that have it opened for reading.
740*bbf21555SRichard Lowe.Pp
741*bbf21555SRichard LoweThe
742*bbf21555SRichard Lowe.Fa play.buffer_size
743*bbf21555SRichard Lowefield is currently not supported.
744*bbf21555SRichard Lowe.Pp
745*bbf21555SRichard LoweThe audio data format is indicated by the
746*bbf21555SRichard Lowe.Fa sample_rate ,
747*bbf21555SRichard Lowe.Fa channels ,
748*bbf21555SRichard Lowe.Fa precision ,
749*bbf21555SRichard Loweand
750*bbf21555SRichard Lowe.Fa encoding
751*bbf21555SRichard Lowefields.
752*bbf21555SRichard LoweThe values of these fields correspond to the
753*bbf21555SRichard Lowedescriptions in the
754*bbf21555SRichard Lowe.Sx "AUDIO FORMATS"
755*bbf21555SRichard Lowesection of this man page.
756*bbf21555SRichard LoweRefer to the
757*bbf21555SRichard Loweaudio device-specific manual pages for a list of supported data format
758*bbf21555SRichard Lowecombinations.
759*bbf21555SRichard Lowe.Pp
760*bbf21555SRichard LoweThe data format fields can be modified only on the
761*bbf21555SRichard Lowe.Pa /dev/audio
762*bbf21555SRichard Lowedevice.
763*bbf21555SRichard Lowe.Pp
764*bbf21555SRichard LoweIf the parameter changes requested by an
765*bbf21555SRichard Lowe.Dv AUDIO_SETINFO
766*bbf21555SRichard Loweioctl cannot all be accommodated,
767*bbf21555SRichard Lowe.Xr ioctl 2
768*bbf21555SRichard Lowereturns with
769*bbf21555SRichard Lowe.Va errno
770*bbf21555SRichard Loweset to
771*bbf21555SRichard Lowe.Er EINVAL
772*bbf21555SRichard Loweand no changes are made to the device state.
773*bbf21555SRichard Lowe.Ss "Streamio IOCTLS"
774*bbf21555SRichard LoweAll of the
775*bbf21555SRichard Lowe.Xr streamio 4I
776*bbf21555SRichard Lowe.Xr ioctl 2
777*bbf21555SRichard Lowecommands may be issued for the
778*bbf21555SRichard Lowe.Pa /dev/audio
779*bbf21555SRichard Lowedevice.
780*bbf21555SRichard LoweBecause the
781*bbf21555SRichard Lowe.Pa /dev/audioctl
782*bbf21555SRichard Lowedevice has its own
783*bbf21555SRichard Lowe.Sy STREAMS
784*bbf21555SRichard Lowequeues, most of these commands neither modify nor report the
785*bbf21555SRichard Lowestate of
786*bbf21555SRichard Lowe.Pa /dev/audio
787*bbf21555SRichard Loweif issued for the
788*bbf21555SRichard Lowe.Pa /dev/audioctl
789*bbf21555SRichard Lowedevice.
790*bbf21555SRichard LoweThe
791*bbf21555SRichard Lowe.Dv I_SETSIG
792*bbf21555SRichard Loweioctl may be issued for
793*bbf21555SRichard Lowe.Pa /dev/audioctl
794*bbf21555SRichard Loweto enable the notification of audio status changes, as described above.
795*bbf21555SRichard Lowe.Ss "Audio IOCTLS"
796*bbf21555SRichard LoweThe audio device additionally supports the following
797*bbf21555SRichard Lowe.Xr ioctl 2
798*bbf21555SRichard Lowecommands:
799*bbf21555SRichard Lowe.Bl -tag -width "AUDIO_GETINFO"
800*bbf21555SRichard Lowe.It Dv AUDIO_DRAIN
801*bbf21555SRichard LoweThe argument is ignored.
802*bbf21555SRichard LoweThis command suspends the calling process until the
803*bbf21555SRichard Loweoutput STREAMS queue is empty and all queued samples have been played, or until
804*bbf21555SRichard Lowea signal is delivered to the calling process.
805*bbf21555SRichard LoweIt may not be issued for the
806*bbf21555SRichard Lowe.Pa /dev/audioctl
807*bbf21555SRichard Lowedevice.
808*bbf21555SRichard LoweAn implicit
809*bbf21555SRichard Lowe.Dv AUDIO_DRAIN
810*bbf21555SRichard Loweis performed on the final
811*bbf21555SRichard Lowe.Xr close 2
812*bbf21555SRichard Loweof
813*bbf21555SRichard Lowe.Pa /dev/audio .
814*bbf21555SRichard Lowe.It Dv AUDIO_GETDEV
815*bbf21555SRichard LoweThe argument is a pointer to an
816*bbf21555SRichard Lowe.Vt audio_device_t
817*bbf21555SRichard Lowestructure.
818*bbf21555SRichard LoweThis command may be issued for either
819*bbf21555SRichard Lowe.Pa /dev/audio
820*bbf21555SRichard Loweor
821*bbf21555SRichard Lowe.Pa /dev/audioctl .
822*bbf21555SRichard LoweThe returned
823*bbf21555SRichard Lowevalue in the name field will be a string that will identify the current
824*bbf21555SRichard Lowe.Pa /dev/audio
825*bbf21555SRichard Lowehardware device, the value in version will be a string
826*bbf21555SRichard Loweindicating the current version of the hardware, and
827*bbf21555SRichard Lowe.Fa config
828*bbf21555SRichard Lowewill be a device-specific string identifying the properties of the audio stream
829*bbf21555SRichard Loweassociated with that file descriptor.
830*bbf21555SRichard LoweRefer to the audio device-specific manual
831*bbf21555SRichard Lowepages to determine the actual strings returned by the device driver.
832*bbf21555SRichard Lowe.It Dv AUDIO_GETINFO
833*bbf21555SRichard LoweThe argument is a pointer to an
834*bbf21555SRichard Lowe.Vt audio_info_t
835*bbf21555SRichard Lowestructure.
836*bbf21555SRichard LoweThis command may be issued for either
837*bbf21555SRichard Lowe.Pa /dev/audio
838*bbf21555SRichard Loweor
839*bbf21555SRichard Lowe.Pa /dev/audioctl .
840*bbf21555SRichard LoweThe current state of the
841*bbf21555SRichard Lowe.Pa /dev/audio
842*bbf21555SRichard Lowedevice is returned in the structure.
843*bbf21555SRichard LoweValues return pertain to a logical view of the device as seen by and private to
844*bbf21555SRichard Lowethe process, and do not necessarily reflect the actual hardware device itself.
845*bbf21555SRichard Lowe.It Dv AUDIO_SETINFO
846*bbf21555SRichard LoweThe argument is a pointer to an
847*bbf21555SRichard Lowe.Vt audio_info_t
848*bbf21555SRichard Lowestructure.
849*bbf21555SRichard LoweThis command may be issued for either the
850*bbf21555SRichard Lowe.Pa /dev/audio
851*bbf21555SRichard Loweor the
852*bbf21555SRichard Lowe.Pa /dev/audioctl
853*bbf21555SRichard Lowedevice with some restrictions.
854*bbf21555SRichard LoweThis command configures the audio device according to
855*bbf21555SRichard Lowethe supplied structure and overwrites the existing structure with the new state
856*bbf21555SRichard Loweof the device.
857*bbf21555SRichard LoweNote: The
858*bbf21555SRichard Lowe.Fa play.samples ,
859*bbf21555SRichard Lowe.Fa record.samples ,
860*bbf21555SRichard Lowe.Fa play.error ,
861*bbf21555SRichard Lowe.Fa record.error ,
862*bbf21555SRichard Loweand
863*bbf21555SRichard Lowe.Fa play.eof
864*bbf21555SRichard Lowefields are modified to reflect the state of the device when the
865*bbf21555SRichard Lowe.Dv AUDIO_SETINFO
866*bbf21555SRichard Loweis issued.
867*bbf21555SRichard LoweThis allows programs to automatically modify these fields while retrieving the
868*bbf21555SRichard Loweprevious value.
869*bbf21555SRichard Lowe.Pp
870*bbf21555SRichard LoweAs with
871*bbf21555SRichard Lowe.Dv AUDIO_SETINFO ,
872*bbf21555SRichard Lowethe settings managed by this ioctl deal with a
873*bbf21555SRichard Lowelogical view of the device which is private to the process, and don't
874*bbf21555SRichard Lowenecessarily have any impact on the hardware device itself.
875*bbf21555SRichard Lowe.El
876*bbf21555SRichard Lowe.Pp
877*bbf21555SRichard LoweCertain fields in the audio information structure, such as the pause flags, are
878*bbf21555SRichard Lowetreated as read-only when
879*bbf21555SRichard Lowe.Pa /dev/audio
880*bbf21555SRichard Loweis not open with the corresponding access permission.
881*bbf21555SRichard LoweOther fields, such as the gain levels and encoding
882*bbf21555SRichard Loweinformation, may have a restricted set of acceptable values.
883*bbf21555SRichard LoweApplications that
884*bbf21555SRichard Loweattempt to modify such fields should check the returned values to be sure that
885*bbf21555SRichard Lowethe corresponding change took effect.
886*bbf21555SRichard LoweThe
887*bbf21555SRichard Lowe.Fa sample_rate ,
888*bbf21555SRichard Lowe.Fa channels ,
889*bbf21555SRichard Lowe.Fa precision ,
890*bbf21555SRichard Loweand
891*bbf21555SRichard Lowe.Fa encoding
892*bbf21555SRichard Lowefields treated as read-only for
893*bbf21555SRichard Lowe.Pa /dev/audioctl ,
894*bbf21555SRichard Loweso that applications can be guaranteed that the existing
895*bbf21555SRichard Loweaudio format will stay in place until they relinquish the audio device.
896*bbf21555SRichard Lowe.Dv AUDIO_SETINFO
897*bbf21555SRichard Lowewill return
898*bbf21555SRichard Lowe.Er EINVAL
899*bbf21555SRichard Lowewhen the desired configuration is not possible, or
900*bbf21555SRichard Lowe.Er EBUSY
901*bbf21555SRichard Lowewhen another process has control of the audio device.
902*bbf21555SRichard Lowe.Pp
903*bbf21555SRichard LoweAll of the logical device state is reset when the corresponding I/O stream of
904*bbf21555SRichard Lowe.Pa /dev/audio
905*bbf21555SRichard Loweis closed.
906*bbf21555SRichard Lowe.Pp
907*bbf21555SRichard LoweThe
908*bbf21555SRichard Lowe.Vt audio_info_t
909*bbf21555SRichard Lowestructure may be initialized through the use of the
910*bbf21555SRichard Lowe.Dv AUDIO_INITINFO
911*bbf21555SRichard Lowemacro.
912*bbf21555SRichard LoweThis macro sets all fields in the structure to
913*bbf21555SRichard Lowevalues that are ignored by the
914*bbf21555SRichard Lowe.Dv AUDIO_SETINFO
915*bbf21555SRichard Lowecommand.
916*bbf21555SRichard LoweFor instance, the following code switches the output port from the built-in
917*bbf21555SRichard Lowespeaker to the headphone jack without modifying any other audio parameters:
918*bbf21555SRichard Lowe.Bd -literal -offset 2n
919*bbf21555SRichard Loweaudio_info_t info;
920*bbf21555SRichard LoweAUDIO_INITINFO();
921*bbf21555SRichard Loweinfo.play.port = AUDIO_HEADPHONE;
922*bbf21555SRichard Loweerr = ioctl(audio_fd, AUDIO_SETINFO, );
923*bbf21555SRichard Lowe.Ed
924*bbf21555SRichard Lowe.Pp
925*bbf21555SRichard LoweThis technique eliminates problems associated with using a sequence of
926*bbf21555SRichard Lowe.Dv AUDIO_GETINFO
927*bbf21555SRichard Lowefollowed by
928*bbf21555SRichard Lowe.Dv AUDIO_SETINFO .
929*bbf21555SRichard Lowe.Sh FILES
930*bbf21555SRichard LoweThe physical audio device names are system dependent and are rarely used by
931*bbf21555SRichard Loweprogrammers.
932*bbf21555SRichard LoweProgrammers should use the following generic device names:
933*bbf21555SRichard Lowe.Bl -tag -width "/usr/share/audio/samples"
934*bbf21555SRichard Lowe.It Pa /dev/audio
935*bbf21555SRichard LoweSymbolic link to the system's primary audio device
936*bbf21555SRichard Lowe.It Pa /dev/audioctl
937*bbf21555SRichard LoweSymbolic link to the control device for
938*bbf21555SRichard Lowe.Pa /dev/audio
939*bbf21555SRichard Lowe.It Pa /dev/sound/0
940*bbf21555SRichard LoweFirst audio device in the system
941*bbf21555SRichard Lowe.It Pa /dev/sound/0ctl
942*bbf21555SRichard LoweAudio control device for
943*bbf21555SRichard Lowe.Pa /dev/sound/0
944*bbf21555SRichard Lowe.It Pa /usr/share/audio/samples
945*bbf21555SRichard LoweAudio files
946*bbf21555SRichard Lowe.El
947*bbf21555SRichard Lowe.Sh ERRORS
948*bbf21555SRichard LoweAn
949*bbf21555SRichard Lowe.Xr open 2
950*bbf21555SRichard Lowecall will fail if:
951*bbf21555SRichard Lowe.Bl -tag -width "EINTR"
952*bbf21555SRichard Lowe.It Er EBUSY
953*bbf21555SRichard LoweThe requested play or record access is busy and either the
954*bbf21555SRichard Lowe.Dv O_NDELAY
955*bbf21555SRichard Loweor
956*bbf21555SRichard Lowe.Dv O_NONBLOCK
957*bbf21555SRichard Loweflag was set in the
958*bbf21555SRichard Lowe.Xr open 2
959*bbf21555SRichard Lowerequest.
960*bbf21555SRichard Lowe.It Er EINTR
961*bbf21555SRichard LoweThe requested play or record access is busy and a signal interrupted the
962*bbf21555SRichard Lowe.Xr open 2
963*bbf21555SRichard Lowerequest.
964*bbf21555SRichard Lowe.El
965*bbf21555SRichard Lowe.Pp
966*bbf21555SRichard LoweAn
967*bbf21555SRichard Lowe.Xr ioctl 2
968*bbf21555SRichard Lowecall will fail if:
969*bbf21555SRichard Lowe.Bl -tag -width "EINVAL"
970*bbf21555SRichard Lowe.It Er EINVAL
971*bbf21555SRichard LoweThe parameter changes requested in the
972*bbf21555SRichard Lowe.Dv AUDIO_SETINFO
973*bbf21555SRichard Loweioctl are invalid or are not supported by the device.
974*bbf21555SRichard Lowe.El
975*bbf21555SRichard Lowe.Sh ARCHITECTURE
976*bbf21555SRichard LoweSPARC
977*bbf21555SRichard LoweX86
978*bbf21555SRichard Lowe.Sh INTERFACE STABILITY
979*bbf21555SRichard LoweObsolete Uncommitted
980*bbf21555SRichard Lowe.Sh SEE ALSO
981*bbf21555SRichard Lowe.Xr close 2 ,
982*bbf21555SRichard Lowe.Xr fcntl 2 ,
983*bbf21555SRichard Lowe.Xr ioctl 2 ,
984*bbf21555SRichard Lowe.Xr open 2 ,
985*bbf21555SRichard Lowe.Xr poll 2 ,
986*bbf21555SRichard Lowe.Xr read 2 ,
987*bbf21555SRichard Lowe.Xr write 2 ,
988*bbf21555SRichard Lowe.Xr dsp 4I ,
989*bbf21555SRichard Lowe.Xr streamio 4I ,
990*bbf21555SRichard Lowe.Xr attributes 7
991*bbf21555SRichard Lowe.Sh BUGS
992*bbf21555SRichard LoweDue to a feature of the
993*bbf21555SRichard Lowe.Sy STREAMS
994*bbf21555SRichard Loweimplementation, programs that are terminated or
995*bbf21555SRichard Loweexit without closing the audio device may hang for a short period while audio
996*bbf21555SRichard Loweoutput drains.
997*bbf21555SRichard LoweIn general, programs that produce audio output should catch the
998*bbf21555SRichard Lowe.Dv SIGINT
999*bbf21555SRichard Lowesignal and flush the output stream before exiting.
1000