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