xref: /illumos-gate/usr/src/cmd/audio/include/audio_device.h (revision 2a8bcb4efb45d99ac41c94a75c396b362c414f7f)
1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate  * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate  *
4*7c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate  * with the License.
8*7c478bd9Sstevel@tonic-gate  *
9*7c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate  * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate  *
14*7c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate  *
20*7c478bd9Sstevel@tonic-gate  * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate  */
22*7c478bd9Sstevel@tonic-gate /*
23*7c478bd9Sstevel@tonic-gate  * Copyright (c) 1992-2001 by Sun Microsystems, Inc.
24*7c478bd9Sstevel@tonic-gate  * All rights reserved.
25*7c478bd9Sstevel@tonic-gate  */
26*7c478bd9Sstevel@tonic-gate 
27*7c478bd9Sstevel@tonic-gate #ifndef _MULTIMEDIA_AUDIO_DEVICE_H
28*7c478bd9Sstevel@tonic-gate #define	_MULTIMEDIA_AUDIO_DEVICE_H
29*7c478bd9Sstevel@tonic-gate 
30*7c478bd9Sstevel@tonic-gate #ifdef __cplusplus
31*7c478bd9Sstevel@tonic-gate extern "C" {
32*7c478bd9Sstevel@tonic-gate #endif
33*7c478bd9Sstevel@tonic-gate 
34*7c478bd9Sstevel@tonic-gate #include <sys/types.h>
35*7c478bd9Sstevel@tonic-gate #include <sys/ioccom.h>
36*7c478bd9Sstevel@tonic-gate #include <sys/audioio.h>
37*7c478bd9Sstevel@tonic-gate 
38*7c478bd9Sstevel@tonic-gate typedef audio_info_t	Audio_info;
39*7c478bd9Sstevel@tonic-gate 
40*7c478bd9Sstevel@tonic-gate /*
41*7c478bd9Sstevel@tonic-gate  * The following macros read the current audio device configuration
42*7c478bd9Sstevel@tonic-gate  * and convert the data encoding format into an Audio_hdr.
43*7c478bd9Sstevel@tonic-gate  * 'F' is an open audio file descriptor.
44*7c478bd9Sstevel@tonic-gate  * 'H' is a pointer to an Audio_hdr.
45*7c478bd9Sstevel@tonic-gate  * The structure '*H' is updated after the device state has been read.
46*7c478bd9Sstevel@tonic-gate  */
47*7c478bd9Sstevel@tonic-gate #define	audio_get_play_config(F, H)					\
48*7c478bd9Sstevel@tonic-gate 		audio__setplayhdr((F), (H), AUDIO__PLAY)
49*7c478bd9Sstevel@tonic-gate #define	audio_get_record_config(F, H)					\
50*7c478bd9Sstevel@tonic-gate 		audio__setplayhdr((F), (H), AUDIO__RECORD)
51*7c478bd9Sstevel@tonic-gate 
52*7c478bd9Sstevel@tonic-gate /*
53*7c478bd9Sstevel@tonic-gate  * The following macros attempt to reconfigure the audio device so that
54*7c478bd9Sstevel@tonic-gate  * it operates on data encoded according to a given Audio_hdr.
55*7c478bd9Sstevel@tonic-gate  * 'F' is an open audio file descriptor.
56*7c478bd9Sstevel@tonic-gate  * 'H' is a pointer to an Audio_hdr describing the desired encoding.
57*7c478bd9Sstevel@tonic-gate  * The structure '*H' is updated after the device state has been read
58*7c478bd9Sstevel@tonic-gate  * to reflect the actual state of the device.
59*7c478bd9Sstevel@tonic-gate  *
60*7c478bd9Sstevel@tonic-gate  * AUDIO_SUCCESS is returned if the device configuration matches the
61*7c478bd9Sstevel@tonic-gate  * requested encoding.  AUDIO_ERR_NOEFFECT is returned if it does not.
62*7c478bd9Sstevel@tonic-gate  */
63*7c478bd9Sstevel@tonic-gate #define	audio_set_play_config(F, H)					\
64*7c478bd9Sstevel@tonic-gate 		audio__setplayhdr((F), (H), AUDIO__SET|AUDIO__PLAY)
65*7c478bd9Sstevel@tonic-gate #define	audio_set_record_config(F, H)					\
66*7c478bd9Sstevel@tonic-gate 		audio__setplayhdr((F), (H), AUDIO__SET|AUDIO__RECORD)
67*7c478bd9Sstevel@tonic-gate 
68*7c478bd9Sstevel@tonic-gate 
69*7c478bd9Sstevel@tonic-gate /*
70*7c478bd9Sstevel@tonic-gate  * The following macros pause or resume the audio play and/or record channels.
71*7c478bd9Sstevel@tonic-gate  * Note that requests to pause a channel that is not open will have no effect.
72*7c478bd9Sstevel@tonic-gate  * In such cases, AUDIO_ERR_NOEFFECT is returned.
73*7c478bd9Sstevel@tonic-gate  */
74*7c478bd9Sstevel@tonic-gate #define	audio_pause(F)							\
75*7c478bd9Sstevel@tonic-gate 		audio__setpause((F), AUDIO__PLAYREC|AUDIO__PAUSE)
76*7c478bd9Sstevel@tonic-gate #define	audio_pause_play(F)						\
77*7c478bd9Sstevel@tonic-gate 		audio__setpause((F), AUDIO__PLAY|AUDIO__PAUSE)
78*7c478bd9Sstevel@tonic-gate #define	audio_pause_record(F)						\
79*7c478bd9Sstevel@tonic-gate 		audio__setpause((F), AUDIO__RECORD|AUDIO__PAUSE)
80*7c478bd9Sstevel@tonic-gate 
81*7c478bd9Sstevel@tonic-gate #define	audio_resume(F)							\
82*7c478bd9Sstevel@tonic-gate 		audio__setpause((F), AUDIO__PLAYREC|AUDIO__RESUME)
83*7c478bd9Sstevel@tonic-gate #define	audio_resume_play(F)						\
84*7c478bd9Sstevel@tonic-gate 		audio__setpause((F), AUDIO__PLAY|AUDIO__RESUME)
85*7c478bd9Sstevel@tonic-gate #define	audio_resume_record(F)						\
86*7c478bd9Sstevel@tonic-gate 		audio__setpause((F), AUDIO__RECORD|AUDIO__RESUME)
87*7c478bd9Sstevel@tonic-gate 
88*7c478bd9Sstevel@tonic-gate 
89*7c478bd9Sstevel@tonic-gate /*
90*7c478bd9Sstevel@tonic-gate  * The following macros get individual state values.
91*7c478bd9Sstevel@tonic-gate  * 'F' is an open audio file descriptor.
92*7c478bd9Sstevel@tonic-gate  * 'V' is a pointer to an unsigned int.
93*7c478bd9Sstevel@tonic-gate  * The value '*V' is updated after the device state has been read.
94*7c478bd9Sstevel@tonic-gate  */
95*7c478bd9Sstevel@tonic-gate #define	audio_get_play_port(F, V)					\
96*7c478bd9Sstevel@tonic-gate 		audio__setval((F), (V), AUDIO__PLAY|AUDIO__PORT)
97*7c478bd9Sstevel@tonic-gate #define	audio_get_record_port(F, V)					\
98*7c478bd9Sstevel@tonic-gate 		audio__setval((F), (V), AUDIO__RECORD|AUDIO__PORT)
99*7c478bd9Sstevel@tonic-gate #define	audio_get_play_balance(F, V)					\
100*7c478bd9Sstevel@tonic-gate 		audio__setval((F), (V), AUDIO__PLAY|AUDIO__BALANCE)
101*7c478bd9Sstevel@tonic-gate #define	audio_get_record_balance(F, V)					\
102*7c478bd9Sstevel@tonic-gate 		audio__setval((F), (V), AUDIO__RECORD|AUDIO__BALANCE)
103*7c478bd9Sstevel@tonic-gate #define	audio_get_play_samples(F, V)					\
104*7c478bd9Sstevel@tonic-gate 		audio__setval((F), (V), AUDIO__PLAY|AUDIO__SAMPLES)
105*7c478bd9Sstevel@tonic-gate #define	audio_get_record_samples(F, V)					\
106*7c478bd9Sstevel@tonic-gate 		audio__setval((F), (V), AUDIO__RECORD|AUDIO__SAMPLES)
107*7c478bd9Sstevel@tonic-gate #define	audio_get_play_error(F, V)					\
108*7c478bd9Sstevel@tonic-gate 		audio__setval((F), (V), AUDIO__PLAY|AUDIO__ERROR)
109*7c478bd9Sstevel@tonic-gate #define	audio_get_record_error(F, V)					\
110*7c478bd9Sstevel@tonic-gate 		audio__setval((F), (V), AUDIO__RECORD|AUDIO__ERROR)
111*7c478bd9Sstevel@tonic-gate #define	audio_get_play_eof(F, V)					\
112*7c478bd9Sstevel@tonic-gate 		audio__setval((F), (V), AUDIO__PLAY|AUDIO__EOF)
113*7c478bd9Sstevel@tonic-gate 
114*7c478bd9Sstevel@tonic-gate #define	audio_get_play_open(F, V)					\
115*7c478bd9Sstevel@tonic-gate 		audio__setval((F), (V), AUDIO__PLAY|AUDIO__OPEN)
116*7c478bd9Sstevel@tonic-gate #define	audio_get_record_open(F, V)					\
117*7c478bd9Sstevel@tonic-gate 		audio__setval((F), (V), AUDIO__RECORD|AUDIO__OPEN)
118*7c478bd9Sstevel@tonic-gate #define	audio_get_play_active(F, V)					\
119*7c478bd9Sstevel@tonic-gate 		audio__setval((F), (V), AUDIO__PLAY|AUDIO__ACTIVE)
120*7c478bd9Sstevel@tonic-gate #define	audio_get_record_active(F, V)					\
121*7c478bd9Sstevel@tonic-gate 		audio__setval((F), (V), AUDIO__RECORD|AUDIO__ACTIVE)
122*7c478bd9Sstevel@tonic-gate #define	audio_get_play_waiting(F, V)					\
123*7c478bd9Sstevel@tonic-gate 		audio__setval((F), (V), AUDIO__PLAY|AUDIO__WAITING)
124*7c478bd9Sstevel@tonic-gate #define	audio_get_record_waiting(F, V)					\
125*7c478bd9Sstevel@tonic-gate 		audio__setval((F), (V), AUDIO__RECORD|AUDIO__WAITING)
126*7c478bd9Sstevel@tonic-gate 
127*7c478bd9Sstevel@tonic-gate /*
128*7c478bd9Sstevel@tonic-gate  * The following macros set individual state values.
129*7c478bd9Sstevel@tonic-gate  * 'F' is an open audio file descriptor.
130*7c478bd9Sstevel@tonic-gate  * 'V' is a pointer to an unsigned int.
131*7c478bd9Sstevel@tonic-gate  * The value '*V' is updated after the device state has been read.
132*7c478bd9Sstevel@tonic-gate  */
133*7c478bd9Sstevel@tonic-gate #define	audio_set_play_port(F, V)					\
134*7c478bd9Sstevel@tonic-gate 		audio__setval((F), (V), AUDIO__SET|AUDIO__PLAY|AUDIO__PORT)
135*7c478bd9Sstevel@tonic-gate #define	audio_set_record_port(F, V)					\
136*7c478bd9Sstevel@tonic-gate 		audio__setval((F), (V), AUDIO__SET|AUDIO__RECORD|AUDIO__PORT)
137*7c478bd9Sstevel@tonic-gate 
138*7c478bd9Sstevel@tonic-gate /*
139*7c478bd9Sstevel@tonic-gate  * The value returned for these is the value *before* the state was changed.
140*7c478bd9Sstevel@tonic-gate  * This allows you to atomically read and reset their values.
141*7c478bd9Sstevel@tonic-gate  */
142*7c478bd9Sstevel@tonic-gate #define	audio_set_play_balance(F, V)					\
143*7c478bd9Sstevel@tonic-gate 		audio__setval((F), (V), AUDIO__SET|AUDIO__PLAY|AUDIO__BALANCE)
144*7c478bd9Sstevel@tonic-gate #define	audio_set_record_balance(F, V)					\
145*7c478bd9Sstevel@tonic-gate 		audio__setval((F), (V), AUDIO__SET|AUDIO__RECORD|AUDIO__BALANCE)
146*7c478bd9Sstevel@tonic-gate #define	audio_set_play_samples(F, V)					\
147*7c478bd9Sstevel@tonic-gate 		audio__setval((F), (V), AUDIO__SET|AUDIO__PLAY|AUDIO__SAMPLES)
148*7c478bd9Sstevel@tonic-gate #define	audio_set_record_samples(F, V)					\
149*7c478bd9Sstevel@tonic-gate 		audio__setval((F), (V), AUDIO__SET|AUDIO__RECORD|AUDIO__SAMPLES)
150*7c478bd9Sstevel@tonic-gate #define	audio_set_play_error(F, V)					\
151*7c478bd9Sstevel@tonic-gate 		audio__setval((F), (V), AUDIO__SET|AUDIO__PLAY|AUDIO__ERROR)
152*7c478bd9Sstevel@tonic-gate #define	audio_set_record_error(F, V)					\
153*7c478bd9Sstevel@tonic-gate 		audio__setval((F), (V), AUDIO__SET|AUDIO__RECORD|AUDIO__ERROR)
154*7c478bd9Sstevel@tonic-gate #define	audio_set_play_eof(F, V)					\
155*7c478bd9Sstevel@tonic-gate 		audio__setval((F), (V), AUDIO__SET|AUDIO__PLAY|AUDIO__EOF)
156*7c478bd9Sstevel@tonic-gate 
157*7c478bd9Sstevel@tonic-gate /* The value can only be set to one.  It is reset to zero on close(). */
158*7c478bd9Sstevel@tonic-gate #define	audio_set_play_waiting(F, V)					\
159*7c478bd9Sstevel@tonic-gate 		audio__setval((F), (V), AUDIO__SET|AUDIO__PLAY|AUDIO__WAITING)
160*7c478bd9Sstevel@tonic-gate #define	audio_set_record_waiting(F, V)					\
161*7c478bd9Sstevel@tonic-gate 		audio__setval((F), (V), AUDIO__SET|AUDIO__RECORD|AUDIO__WAITING)
162*7c478bd9Sstevel@tonic-gate 
163*7c478bd9Sstevel@tonic-gate /*
164*7c478bd9Sstevel@tonic-gate  * Gain routines take double values, mapping the valid range of gains
165*7c478bd9Sstevel@tonic-gate  * to a floating-point value between zero and one, inclusive.
166*7c478bd9Sstevel@tonic-gate  * The value returned will likely be slightly different than the value set.
167*7c478bd9Sstevel@tonic-gate  * This is because the value is quantized by the device.
168*7c478bd9Sstevel@tonic-gate  *
169*7c478bd9Sstevel@tonic-gate  * Make sure that 'V' is a (double *)!
170*7c478bd9Sstevel@tonic-gate  */
171*7c478bd9Sstevel@tonic-gate #define	audio_get_play_gain(F, V)					\
172*7c478bd9Sstevel@tonic-gate 		audio__setgain((F), (V), AUDIO__PLAY|AUDIO__GAIN)
173*7c478bd9Sstevel@tonic-gate #define	audio_get_record_gain(F, V)					\
174*7c478bd9Sstevel@tonic-gate 		audio__setgain((F), (V), AUDIO__RECORD|AUDIO__GAIN)
175*7c478bd9Sstevel@tonic-gate #define	audio_get_monitor_gain(F, V)					\
176*7c478bd9Sstevel@tonic-gate 		audio__setgain((F), (V), AUDIO__MONGAIN)
177*7c478bd9Sstevel@tonic-gate 
178*7c478bd9Sstevel@tonic-gate #define	audio_set_play_gain(F, V)					\
179*7c478bd9Sstevel@tonic-gate 		audio__setgain((F), (V), AUDIO__SET|AUDIO__PLAY|AUDIO__GAIN)
180*7c478bd9Sstevel@tonic-gate #define	audio_set_record_gain(F, V)					\
181*7c478bd9Sstevel@tonic-gate 		audio__setgain((F), (V), AUDIO__SET|AUDIO__RECORD|AUDIO__GAIN)
182*7c478bd9Sstevel@tonic-gate #define	audio_set_monitor_gain(F, V)					\
183*7c478bd9Sstevel@tonic-gate 		audio__setgain((F), (V), AUDIO__SET|AUDIO__MONGAIN)
184*7c478bd9Sstevel@tonic-gate 
185*7c478bd9Sstevel@tonic-gate /*
186*7c478bd9Sstevel@tonic-gate  * The following macros flush the audio play and/or record queues.
187*7c478bd9Sstevel@tonic-gate  * Note that requests to flush a channel that is not open will have no effect.
188*7c478bd9Sstevel@tonic-gate  */
189*7c478bd9Sstevel@tonic-gate #define	audio_flush(F)							\
190*7c478bd9Sstevel@tonic-gate 		audio__flush((F), AUDIO__PLAYREC)
191*7c478bd9Sstevel@tonic-gate #define	audio_flush_play(F)						\
192*7c478bd9Sstevel@tonic-gate 		audio__flush((F), AUDIO__PLAY)
193*7c478bd9Sstevel@tonic-gate #define	audio_flush_record(F)						\
194*7c478bd9Sstevel@tonic-gate 		audio__flush((F), AUDIO__RECORD)
195*7c478bd9Sstevel@tonic-gate 
196*7c478bd9Sstevel@tonic-gate 
197*7c478bd9Sstevel@tonic-gate /* The following is used for 'which' arguments to get/set info routines */
198*7c478bd9Sstevel@tonic-gate #define	AUDIO__PLAY		(0x10000)
199*7c478bd9Sstevel@tonic-gate #define	AUDIO__RECORD		(0x20000)
200*7c478bd9Sstevel@tonic-gate #define	AUDIO__PLAYREC		(AUDIO__PLAY | AUDIO__RECORD)
201*7c478bd9Sstevel@tonic-gate 
202*7c478bd9Sstevel@tonic-gate #define	AUDIO__PORT		(1)
203*7c478bd9Sstevel@tonic-gate #define	AUDIO__SAMPLES		(2)
204*7c478bd9Sstevel@tonic-gate #define	AUDIO__ERROR		(3)
205*7c478bd9Sstevel@tonic-gate #define	AUDIO__EOF		(4)
206*7c478bd9Sstevel@tonic-gate #define	AUDIO__OPEN		(5)
207*7c478bd9Sstevel@tonic-gate #define	AUDIO__ACTIVE		(6)
208*7c478bd9Sstevel@tonic-gate #define	AUDIO__WAITING		(7)
209*7c478bd9Sstevel@tonic-gate #define	AUDIO__GAIN		(8)
210*7c478bd9Sstevel@tonic-gate #define	AUDIO__MONGAIN		(9)
211*7c478bd9Sstevel@tonic-gate #define	AUDIO__PAUSE		(10)
212*7c478bd9Sstevel@tonic-gate #define	AUDIO__RESUME		(11)
213*7c478bd9Sstevel@tonic-gate #define	AUDIO__BALANCE		(12)
214*7c478bd9Sstevel@tonic-gate 
215*7c478bd9Sstevel@tonic-gate #define	AUDIO__SET		(0x80000000)
216*7c478bd9Sstevel@tonic-gate #define	AUDIO__SETVAL_MASK	(0xff)
217*7c478bd9Sstevel@tonic-gate 
218*7c478bd9Sstevel@tonic-gate #ifdef __cplusplus
219*7c478bd9Sstevel@tonic-gate }
220*7c478bd9Sstevel@tonic-gate #endif
221*7c478bd9Sstevel@tonic-gate 
222*7c478bd9Sstevel@tonic-gate #endif /* !_MULTIMEDIA_AUDIO_DEVICE_H */
223