FreeBSD/Linux Kernel Cross Reference
sys/sys/audioio.h
1 /* $NetBSD: audioio.h,v 1.40 2022/04/07 19:33:38 andvar Exp $ */
2
3 /*
4 * Copyright (c) 1991-1993 Regents of the University of California.
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. All advertising materials mentioning features or use of this software
16 * must display the following acknowledgement:
17 * This product includes software developed by the Computer Systems
18 * Engineering Group at Lawrence Berkeley Laboratory.
19 * 4. Neither the name of the University nor of the Laboratory may be used
20 * to endorse or promote products derived from this software without
21 * specific prior written permission.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 * SUCH DAMAGE.
34 *
35 */
36
37 #ifndef _SYS_AUDIOIO_H_
38 #define _SYS_AUDIOIO_H_
39
40 #include <sys/types.h>
41 #include <sys/ioccom.h>
42
43 #ifndef _KERNEL
44 #include <string.h> /* Required for memset(3) prototype (AUDIO_INITINFO) */
45 #endif /* _KERNEL */
46
47 /*
48 * Audio device
49 */
50 struct audio_prinfo {
51 u_int sample_rate; /* sample rate in bit/s */
52 u_int channels; /* number of channels, usually 1 or 2 */
53 u_int precision; /* number of bits/sample */
54 u_int encoding; /* data encoding (AUDIO_ENCODING_* below) */
55 u_int gain; /* volume level */
56 u_int port; /* selected I/O port */
57 u_int seek; /* BSD extension */
58 u_int avail_ports; /* available I/O ports */
59 u_int buffer_size; /* total size audio buffer */
60 u_int _ispare[1];
61 /* Current state of device: */
62 u_int samples; /* number of samples */
63 u_int eof; /* End Of File (zero-size writes) counter */
64 u_char pause; /* non-zero if paused, zero to resume */
65 u_char error; /* non-zero if underflow/overflow occurred */
66 u_char waiting; /* non-zero if another process hangs in open */
67 u_char balance; /* stereo channel balance */
68 u_char cspare[2];
69 u_char open; /* non-zero if currently open */
70 u_char active; /* non-zero if I/O is currently active */
71 };
72 typedef struct audio_prinfo audio_prinfo_t;
73
74 struct audio_info {
75 struct audio_prinfo play; /* Info for play (output) side */
76 struct audio_prinfo record; /* Info for record (input) side */
77
78 u_int monitor_gain; /* input to output mix */
79 /* BSD extensions */
80 u_int blocksize; /* H/W read/write block size */
81 u_int hiwat; /* output high water mark */
82 u_int lowat; /* output low water mark */
83 u_int _ispare1;
84 u_int mode; /* current device mode */
85 #define AUMODE_PLAY 0x01
86 #define AUMODE_RECORD 0x02
87 #define AUMODE_PLAY_ALL 0x04 /* don't do real-time correction */
88 };
89 typedef struct audio_info audio_info_t;
90
91 #define AUDIO_INITINFO(p) \
92 (void)memset((void *)(p), 0xff, sizeof(struct audio_info))
93
94 /*
95 * Parameter for the AUDIO_GETDEV ioctl to determine current
96 * audio devices.
97 */
98 #define MAX_AUDIO_DEV_LEN 16
99 typedef struct audio_device {
100 char name[MAX_AUDIO_DEV_LEN];
101 char version[MAX_AUDIO_DEV_LEN];
102 char config[MAX_AUDIO_DEV_LEN];
103 } audio_device_t;
104
105 typedef struct audio_offset {
106 u_int samples; /* Total number of bytes transferred */
107 u_int deltablks; /* Blocks transferred since last checked */
108 u_int offset; /* Physical transfer offset in buffer */
109 } audio_offset_t;
110
111 /*
112 * Supported audio encodings
113 */
114 /* Encoding ID's */
115 #define AUDIO_ENCODING_NONE 0 /* no encoding assigned */
116 #define AUDIO_ENCODING_ULAW 1 /* ITU G.711 mu-law */
117 #define AUDIO_ENCODING_ALAW 2 /* ITU G.711 A-law */
118 #define AUDIO_ENCODING_PCM16 3 /* signed linear PCM, obsolete */
119 #define AUDIO_ENCODING_LINEAR AUDIO_ENCODING_PCM16 /* SunOS compat */
120 #define AUDIO_ENCODING_PCM8 4 /* unsigned linear PCM, obsolete */
121 #define AUDIO_ENCODING_LINEAR8 AUDIO_ENCODING_PCM8 /* SunOS compat */
122 #define AUDIO_ENCODING_ADPCM 5 /* adaptive differential PCM */
123 #define AUDIO_ENCODING_SLINEAR_LE 6
124 #define AUDIO_ENCODING_SLINEAR_BE 7
125 #define AUDIO_ENCODING_ULINEAR_LE 8
126 #define AUDIO_ENCODING_ULINEAR_BE 9
127 #define AUDIO_ENCODING_SLINEAR 10
128 #define AUDIO_ENCODING_ULINEAR 11
129 #define AUDIO_ENCODING_MPEG_L1_STREAM 12
130 #define AUDIO_ENCODING_MPEG_L1_PACKETS 13
131 #define AUDIO_ENCODING_MPEG_L1_SYSTEM 14
132 #define AUDIO_ENCODING_MPEG_L2_STREAM 15
133 #define AUDIO_ENCODING_MPEG_L2_PACKETS 16
134 #define AUDIO_ENCODING_MPEG_L2_SYSTEM 17
135 #define AUDIO_ENCODING_AC3 18
136
137 /* XXX Consider whether to export to userland? */
138 #if defined(_KERNEL)
139 #if BYTE_ORDER == LITTLE_ENDIAN
140 #define AUDIO_ENCODING_SLINEAR_NE AUDIO_ENCODING_SLINEAR_LE
141 #define AUDIO_ENCODING_ULINEAR_NE AUDIO_ENCODING_ULINEAR_LE
142 #define AUDIO_ENCODING_SLINEAR_OE AUDIO_ENCODING_SLINEAR_BE
143 #define AUDIO_ENCODING_ULINEAR_OE AUDIO_ENCODING_ULINEAR_BE
144 #else
145 #define AUDIO_ENCODING_SLINEAR_NE AUDIO_ENCODING_SLINEAR_BE
146 #define AUDIO_ENCODING_ULINEAR_NE AUDIO_ENCODING_ULINEAR_BE
147 #define AUDIO_ENCODING_SLINEAR_OE AUDIO_ENCODING_SLINEAR_LE
148 #define AUDIO_ENCODING_ULINEAR_OE AUDIO_ENCODING_ULINEAR_LE
149 #endif
150 #endif /* _KERNEL */
151
152 typedef struct audio_encoding {
153 int index;
154 char name[MAX_AUDIO_DEV_LEN];
155 int encoding;
156 int precision;
157 int flags;
158 #define AUDIO_ENCODINGFLAG_EMULATED 1 /* software emulation mode */
159 } audio_encoding_t;
160
161 struct audio_format {
162 /**
163 * Device-dependent audio drivers may use this field freely.
164 */
165 void *driver_data;
166
167 /**
168 * combination of AUMODE_PLAY and AUMODE_RECORD
169 */
170 int32_t mode;
171
172 /**
173 * Encoding type. AUDIO_ENCODING_*.
174 * Don't use AUDIO_ENCODING_SLINEAR/ULINEAR/LINEAR/LINEAR8
175 */
176 u_int encoding;
177
178 /**
179 * The size of valid bits in one sample.
180 * It must be <= precision.
181 */
182 u_int validbits;
183
184 /**
185 * The bit size of one sample.
186 * It must be >= validbits, and is usually a multiple of 8.
187 */
188 u_int precision;
189
190 /**
191 * The number of channels. >= 1
192 */
193 u_int channels;
194
195 u_int channel_mask;
196 #define AUFMT_UNKNOWN_POSITION 0U
197 #define AUFMT_FRONT_LEFT 0x00001U /* USB audio compatible */
198 #define AUFMT_FRONT_RIGHT 0x00002U /* USB audio compatible */
199 #define AUFMT_FRONT_CENTER 0x00004U /* USB audio compatible */
200 #define AUFMT_LOW_FREQUENCY 0x00008U /* USB audio compatible */
201 #define AUFMT_BACK_LEFT 0x00010U /* USB audio compatible */
202 #define AUFMT_BACK_RIGHT 0x00020U /* USB audio compatible */
203 #define AUFMT_FRONT_LEFT_OF_CENTER 0x00040U /* USB audio compatible */
204 #define AUFMT_FRONT_RIGHT_OF_CENTER 0x00080U /* USB audio compatible */
205 #define AUFMT_BACK_CENTER 0x00100U /* USB audio compatible */
206 #define AUFMT_SIDE_LEFT 0x00200U /* USB audio compatible */
207 #define AUFMT_SIDE_RIGHT 0x00400U /* USB audio compatible */
208 #define AUFMT_TOP_CENTER 0x00800U /* USB audio compatible */
209 #define AUFMT_TOP_FRONT_LEFT 0x01000U
210 #define AUFMT_TOP_FRONT_CENTER 0x02000U
211 #define AUFMT_TOP_FRONT_RIGHT 0x04000U
212 #define AUFMT_TOP_BACK_LEFT 0x08000U
213 #define AUFMT_TOP_BACK_CENTER 0x10000U
214 #define AUFMT_TOP_BACK_RIGHT 0x20000U
215
216 #define AUFMT_MONAURAL AUFMT_FRONT_CENTER
217 #define AUFMT_STEREO (AUFMT_FRONT_LEFT | AUFMT_FRONT_RIGHT)
218 #define AUFMT_SURROUND4 (AUFMT_STEREO | AUFMT_BACK_LEFT \
219 | AUFMT_BACK_RIGHT)
220 #define AUFMT_DOLBY_5_1 (AUFMT_SURROUND4 | AUFMT_FRONT_CENTER \
221 | AUFMT_LOW_FREQUENCY)
222
223 /**
224 * 0: frequency[0] is lower limit, and frequency[1] is higher limit.
225 * 1-16: frequency[0] to frequency[frequency_type-1] are valid.
226 */
227 u_int frequency_type;
228
229 #define AUFMT_MAX_FREQUENCIES 16
230 /**
231 * sampling rates
232 */
233 u_int frequency[AUFMT_MAX_FREQUENCIES];
234
235 /**
236 * 0-3: priority. 0 is the lowest.
237 * -1: hardware supports this format but driver doesn't (e.g. AC3).
238 */
239 int priority;
240 };
241
242 typedef struct audio_format_query {
243 u_int index;
244 struct audio_format fmt;
245 } audio_format_query_t;
246
247 /*
248 * Balance settings.
249 */
250 #define AUDIO_LEFT_BALANCE 0 /* left channel only */
251 #define AUDIO_MID_BALANCE 32 /* equal left/right channel */
252 #define AUDIO_RIGHT_BALANCE 64 /* right channel only */
253 #define AUDIO_BALANCE_SHIFT 3
254
255 /*
256 * Output ports
257 */
258 #define AUDIO_SPEAKER 0x01 /* built-in speaker */
259 #define AUDIO_HEADPHONE 0x02 /* headphone jack */
260 #define AUDIO_LINE_OUT 0x04 /* line out */
261 #define VC_OUT 0x08 /* virt chan out */
262
263 /*
264 * Input ports
265 */
266 #define AUDIO_MICROPHONE 0x01 /* microphone */
267 #define AUDIO_LINE_IN 0x02 /* line in */
268 #define AUDIO_CD 0x04 /* on-board CD inputs */
269 #define AUDIO_INTERNAL_CD_IN AUDIO_CD /* internal CDROM */
270 #define VC_IN 0x08 /* virt chan in */
271
272 /*
273 * Audio device operations
274 */
275 #define AUDIO_GETINFO _IOR('A', 21, struct audio_info)
276 #define AUDIO_SETINFO _IOWR('A', 22, struct audio_info)
277 #define AUDIO_DRAIN _IO('A', 23)
278 #define AUDIO_FLUSH _IO('A', 24)
279 #define AUDIO_WSEEK _IOR('A', 25, u_long)
280 #define AUDIO_RERROR _IOR('A', 26, int)
281 #define AUDIO_GETDEV _IOR('A', 27, struct audio_device)
282 #define AUDIO_GETENC _IOWR('A', 28, struct audio_encoding)
283 #define AUDIO_GETFD _IOR('A', 29, int)
284 #define AUDIO_SETFD _IOWR('A', 30, int)
285 #define AUDIO_PERROR _IOR('A', 31, int)
286 #define AUDIO_GETIOFFS _IOR('A', 32, struct audio_offset)
287 #define AUDIO_GETOOFFS _IOR('A', 33, struct audio_offset)
288 #define AUDIO_GETPROPS _IOR('A', 34, int)
289 #define AUDIO_PROP_FULLDUPLEX 0x01
290 #define AUDIO_PROP_MMAP 0x02
291 #define AUDIO_PROP_INDEPENDENT 0x04
292 #define AUDIO_PROP_PLAYBACK 0x10
293 #define AUDIO_PROP_CAPTURE 0x20
294 #define AUDIO_GETBUFINFO _IOR('A', 35, struct audio_info)
295 #define AUDIO_SETCHAN _IOW('A', 36, int)
296 #define AUDIO_GETCHAN _IOR('A', 37, int)
297 #define AUDIO_QUERYFORMAT _IOWR('A', 38, struct audio_format_query)
298 #define AUDIO_GETFORMAT _IOR('A', 39, struct audio_info)
299 #define AUDIO_SETFORMAT _IOW('A', 40, struct audio_info)
300
301 /*
302 * Mixer device
303 */
304 #define AUDIO_MIN_GAIN 0
305 #define AUDIO_MAX_GAIN 255
306
307 typedef struct mixer_level {
308 int num_channels;
309 u_char level[8]; /* [num_channels] */
310 } mixer_level_t;
311 #define AUDIO_MIXER_LEVEL_MONO 0
312 #define AUDIO_MIXER_LEVEL_LEFT 0
313 #define AUDIO_MIXER_LEVEL_RIGHT 1
314
315 /*
316 * Device operations
317 */
318
319 typedef struct audio_mixer_name {
320 char name[MAX_AUDIO_DEV_LEN];
321 int msg_id;
322 } audio_mixer_name_t;
323
324 typedef struct mixer_devinfo {
325 int index;
326 audio_mixer_name_t label;
327 int type;
328 #define AUDIO_MIXER_CLASS 0
329 #define AUDIO_MIXER_ENUM 1
330 #define AUDIO_MIXER_SET 2
331 #define AUDIO_MIXER_VALUE 3
332 int mixer_class;
333 int next, prev;
334 #define AUDIO_MIXER_LAST -1
335 union {
336 struct audio_mixer_enum {
337 int num_mem;
338 struct {
339 audio_mixer_name_t label;
340 int ord;
341 } member[32];
342 } e;
343 struct audio_mixer_set {
344 int num_mem;
345 struct {
346 audio_mixer_name_t label;
347 int mask;
348 } member[32];
349 } s;
350 struct audio_mixer_value {
351 audio_mixer_name_t units;
352 int num_channels;
353 int delta;
354 } v;
355 } un;
356 } mixer_devinfo_t;
357
358
359 typedef struct mixer_ctrl {
360 int dev;
361 int type;
362 union {
363 int ord; /* enum */
364 int mask; /* set */
365 mixer_level_t value; /* value */
366 } un;
367 } mixer_ctrl_t;
368
369 /*
370 * Mixer operations
371 */
372 #define AUDIO_MIXER_READ _IOWR('M', 0, mixer_ctrl_t)
373 #define AUDIO_MIXER_WRITE _IOWR('M', 1, mixer_ctrl_t)
374 #define AUDIO_MIXER_DEVINFO _IOWR('M', 2, mixer_devinfo_t)
375
376 /*
377 * Well known device names
378 */
379 #define AudioNmicrophone "mic"
380 #define AudioNline "line"
381 #define AudioNcd "cd"
382 #define AudioNdac "dac"
383 #define AudioNaux "aux"
384 #define AudioNrecord "record"
385 #define AudioNvolume "volume"
386 #define AudioNmonitor "monitor"
387 #define AudioNtreble "treble"
388 #define AudioNmid "mid"
389 #define AudioNbass "bass"
390 #define AudioNbassboost "bassboost"
391 #define AudioNspeaker "speaker"
392 #define AudioNheadphone "headphones"
393 #define AudioNoutput "output"
394 #define AudioNinput "input"
395 #define AudioNmaster "master"
396 #define AudioNstereo "stereo"
397 #define AudioNmono "mono"
398 #define AudioNloudness "loudness"
399 #define AudioNspatial "spatial"
400 #define AudioNsurround "surround"
401 #define AudioNpseudo "pseudo"
402 #define AudioNmute "mute"
403 #define AudioNenhanced "enhanced"
404 #define AudioNpreamp "preamp"
405 #define AudioNon "on"
406 #define AudioNoff "off"
407 #define AudioNmode "mode"
408 #define AudioNsource "source"
409 #define AudioNfmsynth "fmsynth"
410 #define AudioNwave "wave"
411 #define AudioNmidi "midi"
412 #define AudioNmixerout "mixerout"
413 #define AudioNswap "swap" /* swap left and right channels */
414 #define AudioNagc "agc"
415 #define AudioNdelay "delay"
416 #define AudioNselect "select" /* select destination */
417 #define AudioNvideo "video"
418 #define AudioNcenter "center"
419 #define AudioNdepth "depth"
420 #define AudioNlfe "lfe"
421
422 #define AudioEmulaw "mulaw"
423 #define AudioEalaw "alaw"
424 #define AudioEadpcm "adpcm"
425 #define AudioEslinear "slinear"
426 #define AudioEslinear_le "slinear_le"
427 #define AudioEslinear_be "slinear_be"
428 #define AudioEulinear "ulinear"
429 #define AudioEulinear_le "ulinear_le"
430 #define AudioEulinear_be "ulinear_be"
431 #define AudioEmpeg_l1_stream "mpeg_l1_stream"
432 #define AudioEmpeg_l1_packets "mpeg_l1_packets"
433 #define AudioEmpeg_l1_system "mpeg_l1_system"
434 #define AudioEmpeg_l2_stream "mpeg_l2_stream"
435 #define AudioEmpeg_l2_packets "mpeg_l2_packets"
436 #define AudioEmpeg_l2_system "mpeg_l2_system"
437 #define AudioEac3 "ac3"
438
439 #define AudioCinputs "inputs"
440 #define AudioCoutputs "outputs"
441 #define AudioCrecord "record"
442 #define AudioCmonitor "monitor"
443 #define AudioCequalization "equalization"
444 #define AudioCmodem "modem"
445 #define AudioCvirtchan "vchan"
446
447 #endif /* !_SYS_AUDIOIO_H_ */
Cache object: b49ea8c57e75852a3a0f9aed4bc4f95d
|