audiovar.h revision 1.2 1 1.2 isaki /* $NetBSD: audiovar.h,v 1.2 2019/05/08 13:40:17 isaki Exp $ */
2 1.2 isaki
3 1.2 isaki /*-
4 1.2 isaki * Copyright (c) 2002 The NetBSD Foundation, Inc.
5 1.2 isaki * All rights reserved.
6 1.2 isaki *
7 1.2 isaki * This code is derived from software contributed to The NetBSD Foundation
8 1.2 isaki * by TAMURA Kent
9 1.2 isaki *
10 1.2 isaki * Redistribution and use in source and binary forms, with or without
11 1.2 isaki * modification, are permitted provided that the following conditions
12 1.2 isaki * are met:
13 1.2 isaki * 1. Redistributions of source code must retain the above copyright
14 1.2 isaki * notice, this list of conditions and the following disclaimer.
15 1.2 isaki * 2. Redistributions in binary form must reproduce the above copyright
16 1.2 isaki * notice, this list of conditions and the following disclaimer in the
17 1.2 isaki * documentation and/or other materials provided with the distribution.
18 1.2 isaki *
19 1.2 isaki * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 1.2 isaki * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 1.2 isaki * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 1.2 isaki * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 1.2 isaki * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 1.2 isaki * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 1.2 isaki * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 1.2 isaki * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 1.2 isaki * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 1.2 isaki * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 1.2 isaki * POSSIBILITY OF SUCH DAMAGE.
30 1.2 isaki */
31 1.2 isaki
32 1.2 isaki /*
33 1.2 isaki * Copyright (c) 1991-1993 Regents of the University of California.
34 1.2 isaki * All rights reserved.
35 1.2 isaki *
36 1.2 isaki * Redistribution and use in source and binary forms, with or without
37 1.2 isaki * modification, are permitted provided that the following conditions
38 1.2 isaki * are met:
39 1.2 isaki * 1. Redistributions of source code must retain the above copyright
40 1.2 isaki * notice, this list of conditions and the following disclaimer.
41 1.2 isaki * 2. Redistributions in binary form must reproduce the above copyright
42 1.2 isaki * notice, this list of conditions and the following disclaimer in the
43 1.2 isaki * documentation and/or other materials provided with the distribution.
44 1.2 isaki * 3. All advertising materials mentioning features or use of this software
45 1.2 isaki * must display the following acknowledgement:
46 1.2 isaki * This product includes software developed by the Computer Systems
47 1.2 isaki * Engineering Group at Lawrence Berkeley Laboratory.
48 1.2 isaki * 4. Neither the name of the University nor of the Laboratory may be used
49 1.2 isaki * to endorse or promote products derived from this software without
50 1.2 isaki * specific prior written permission.
51 1.2 isaki *
52 1.2 isaki * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
53 1.2 isaki * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
54 1.2 isaki * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
55 1.2 isaki * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
56 1.2 isaki * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
57 1.2 isaki * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
58 1.2 isaki * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
59 1.2 isaki * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
60 1.2 isaki * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
61 1.2 isaki * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
62 1.2 isaki * SUCH DAMAGE.
63 1.2 isaki *
64 1.2 isaki * From: Header: audiovar.h,v 1.3 93/07/18 14:07:25 mccanne Exp (LBL)
65 1.2 isaki */
66 1.2 isaki
67 1.2 isaki #ifndef _SYS_DEV_AUDIO_AUDIOVAR_H_
68 1.2 isaki #define _SYS_DEV_AUDIO_AUDIOVAR_H_
69 1.2 isaki
70 1.2 isaki #if defined(_KERNEL)
71 1.2 isaki #include <sys/condvar.h>
72 1.2 isaki #include <sys/proc.h>
73 1.2 isaki #include <sys/queue.h>
74 1.2 isaki
75 1.2 isaki #include <dev/audio/audio_if.h>
76 1.2 isaki #include <dev/audio/audiofil.h>
77 1.2 isaki #else
78 1.2 isaki #include <stdint.h>
79 1.2 isaki #include <stdbool.h>
80 1.2 isaki #include "compat.h"
81 1.2 isaki #include "userland.h"
82 1.2 isaki #include "audiofil.h"
83 1.2 isaki #endif /* _KERNEL */
84 1.2 isaki
85 1.2 isaki /*
86 1.2 isaki * Whether supports [US]LINEAR24/24 as userland format.
87 1.2 isaki */
88 1.2 isaki /* #define AUDIO_SUPPORT_LINEAR24 */
89 1.2 isaki
90 1.2 isaki /*
91 1.2 isaki * Frequency range.
92 1.2 isaki * For lower limit, there are some antique machines who supports under
93 1.2 isaki * 4000Hz, so that we accept 1000Hz as lower limit, regardless of
94 1.2 isaki * practicality(?).
95 1.2 isaki * For upper limit, there are some devices who supports 384000Hz, but
96 1.2 isaki * I don't have them. :-)
97 1.2 isaki */
98 1.2 isaki #define AUDIO_MIN_FREQUENCY (1000)
99 1.2 isaki #define AUDIO_MAX_FREQUENCY (192000)
100 1.2 isaki
101 1.2 isaki typedef struct audio_file audio_file_t;
102 1.2 isaki typedef struct audio_trackmixer audio_trackmixer_t;
103 1.2 isaki
104 1.2 isaki /* ring buffer */
105 1.2 isaki typedef struct {
106 1.2 isaki audio_format2_t fmt; /* format */
107 1.2 isaki int capacity; /* capacity by frame */
108 1.2 isaki int head; /* head position in frame */
109 1.2 isaki int used; /* used frame count */
110 1.2 isaki void *mem; /* sample ptr */
111 1.2 isaki } audio_ring_t;
112 1.2 isaki
113 1.2 isaki #define AUDIO_N_PORTS 4
114 1.2 isaki
115 1.2 isaki struct au_mixer_ports {
116 1.2 isaki int index; /* index of port-selector mixerctl */
117 1.2 isaki int master; /* index of master mixerctl */
118 1.2 isaki int nports; /* number of selectable ports */
119 1.2 isaki bool isenum; /* selector is enum type */
120 1.2 isaki u_int allports; /* all aumasks or'd */
121 1.2 isaki u_int aumask[AUDIO_N_PORTS]; /* exposed value of "ports" */
122 1.2 isaki int misel [AUDIO_N_PORTS]; /* ord of port, for selector */
123 1.2 isaki int miport[AUDIO_N_PORTS]; /* index of port's mixerctl */
124 1.2 isaki bool isdual; /* has working mixerout */
125 1.2 isaki int mixerout; /* ord of mixerout, for dual case */
126 1.2 isaki int cur_port; /* the port that gain actually controls when
127 1.2 isaki mixerout is selected, for dual case */
128 1.2 isaki };
129 1.2 isaki
130 1.2 isaki struct audio_softc {
131 1.2 isaki /* Myself (e.g.; audio0, audio1, ...) */
132 1.2 isaki device_t sc_dev;
133 1.2 isaki
134 1.2 isaki /* Hardware device struct (e.g.; sb0, hdafg0, ...) */
135 1.2 isaki device_t hw_dev;
136 1.2 isaki
137 1.2 isaki /*
138 1.2 isaki * Hardware interface and driver handle.
139 1.2 isaki * hw_if == NULL means that the device is (attached but) disabled.
140 1.2 isaki */
141 1.2 isaki const struct audio_hw_if *hw_if;
142 1.2 isaki void *hw_hdl;
143 1.2 isaki
144 1.2 isaki /*
145 1.2 isaki * List of opened descriptors.
146 1.2 isaki * Must be protected by sc_intr_lock.
147 1.2 isaki */
148 1.2 isaki SLIST_HEAD(, audio_file) sc_files;
149 1.2 isaki
150 1.2 isaki /*
151 1.2 isaki * Blocksize in msec.
152 1.2 isaki * Must be protected by sc_lock.
153 1.2 isaki */
154 1.2 isaki int sc_blk_ms;
155 1.2 isaki
156 1.2 isaki /*
157 1.2 isaki * Track mixer for playback and recording.
158 1.2 isaki * If null, the mixer is disabled.
159 1.2 isaki */
160 1.2 isaki audio_trackmixer_t *sc_pmixer;
161 1.2 isaki audio_trackmixer_t *sc_rmixer;
162 1.2 isaki
163 1.2 isaki /*
164 1.2 isaki * Opening track counter.
165 1.2 isaki * Must be protected by sc_lock.
166 1.2 isaki */
167 1.2 isaki int sc_popens;
168 1.2 isaki int sc_ropens;
169 1.2 isaki
170 1.2 isaki /*
171 1.2 isaki * true if the track mixer is running.
172 1.2 isaki * Must be protected by sc_lock.
173 1.2 isaki */
174 1.2 isaki bool sc_pbusy;
175 1.2 isaki bool sc_rbusy;
176 1.2 isaki
177 1.2 isaki /*
178 1.2 isaki * These four are the parameters sustained with /dev/sound.
179 1.2 isaki * Must be protected by sc_lock.
180 1.2 isaki */
181 1.2 isaki audio_format2_t sc_sound_pparams;
182 1.2 isaki audio_format2_t sc_sound_rparams;
183 1.2 isaki bool sc_sound_ppause;
184 1.2 isaki bool sc_sound_rpause;
185 1.2 isaki
186 1.2 isaki /* recent info for /dev/sound */
187 1.2 isaki /* XXX TODO */
188 1.2 isaki struct audio_info sc_ai;
189 1.2 isaki
190 1.2 isaki /*
191 1.2 isaki * Playback(write)/Recording(read) selector.
192 1.2 isaki * Must be protected by sc_lock.
193 1.2 isaki */
194 1.2 isaki struct selinfo sc_wsel;
195 1.2 isaki struct selinfo sc_rsel;
196 1.2 isaki
197 1.2 isaki /*
198 1.2 isaki * processes who want mixer SIGIO.
199 1.2 isaki * Must be protected by sc_lock.
200 1.2 isaki */
201 1.2 isaki struct mixer_asyncs {
202 1.2 isaki struct mixer_asyncs *next;
203 1.2 isaki pid_t pid;
204 1.2 isaki } *sc_async_mixer;
205 1.2 isaki
206 1.2 isaki /*
207 1.2 isaki * Thread lock and interrupt lock obtained by get_locks().
208 1.2 isaki */
209 1.2 isaki kmutex_t *sc_lock;
210 1.2 isaki kmutex_t *sc_intr_lock;
211 1.2 isaki
212 1.2 isaki /*
213 1.2 isaki * Critical section.
214 1.2 isaki * Must be protected by sc_lock.
215 1.2 isaki */
216 1.2 isaki int sc_exlock;
217 1.2 isaki kcondvar_t sc_exlockcv;
218 1.2 isaki
219 1.2 isaki /*
220 1.2 isaki * Must be protected by sc_lock (?)
221 1.2 isaki */
222 1.2 isaki bool sc_dying;
223 1.2 isaki
224 1.2 isaki /*
225 1.2 isaki * If multiuser is false, other users who have different euid
226 1.2 isaki * than the first user cannot open this device.
227 1.2 isaki * Must be protected by sc_lock.
228 1.2 isaki */
229 1.2 isaki bool sc_multiuser;
230 1.2 isaki kauth_cred_t sc_cred;
231 1.2 isaki
232 1.2 isaki struct sysctllog *sc_log;
233 1.2 isaki
234 1.2 isaki mixer_ctrl_t *sc_mixer_state;
235 1.2 isaki int sc_nmixer_states;
236 1.2 isaki struct au_mixer_ports sc_inports;
237 1.2 isaki struct au_mixer_ports sc_outports;
238 1.2 isaki int sc_monitor_port;
239 1.2 isaki u_int sc_lastgain;
240 1.2 isaki };
241 1.2 isaki
242 1.2 isaki #ifdef DIAGNOSTIC
243 1.2 isaki #define DIAGNOSTIC_filter_arg(arg) audio_diagnostic_filter_arg(__func__, (arg))
244 1.2 isaki #define DIAGNOSTIC_format2(fmt) audio_diagnostic_format2(__func__, (fmt))
245 1.2 isaki extern void audio_diagnostic_filter_arg(const char *,
246 1.2 isaki const audio_filter_arg_t *);
247 1.2 isaki extern void audio_diagnostic_format2(const char *, const audio_format2_t *);
248 1.2 isaki #else
249 1.2 isaki #define DIAGNOSTIC_filter_arg(arg)
250 1.2 isaki #define DIAGNOSTIC_format2(fmt)
251 1.2 isaki #endif
252 1.2 isaki
253 1.2 isaki /*
254 1.2 isaki * Return true if 'fmt' is the internal format.
255 1.2 isaki * It does not check for frequency and number of channels.
256 1.2 isaki */
257 1.2 isaki static __inline bool
258 1.2 isaki audio_format2_is_internal(const audio_format2_t *fmt)
259 1.2 isaki {
260 1.2 isaki
261 1.2 isaki if (fmt->encoding != AUDIO_ENCODING_SLINEAR_NE)
262 1.2 isaki return false;
263 1.2 isaki if (fmt->precision != AUDIO_INTERNAL_BITS)
264 1.2 isaki return false;
265 1.2 isaki if (fmt->stride != AUDIO_INTERNAL_BITS)
266 1.2 isaki return false;
267 1.2 isaki return true;
268 1.2 isaki }
269 1.2 isaki
270 1.2 isaki /*
271 1.2 isaki * Return true if fmt's encoding is one of LINEAR.
272 1.2 isaki */
273 1.2 isaki static __inline bool
274 1.2 isaki audio_format2_is_linear(const audio_format2_t *fmt)
275 1.2 isaki {
276 1.2 isaki return (fmt->encoding == AUDIO_ENCODING_SLINEAR_LE)
277 1.2 isaki || (fmt->encoding == AUDIO_ENCODING_SLINEAR_BE)
278 1.2 isaki || (fmt->encoding == AUDIO_ENCODING_ULINEAR_LE)
279 1.2 isaki || (fmt->encoding == AUDIO_ENCODING_ULINEAR_BE);
280 1.2 isaki }
281 1.2 isaki
282 1.2 isaki /*
283 1.2 isaki * Return true if fmt's encoding is one of SLINEAR.
284 1.2 isaki */
285 1.2 isaki static __inline bool
286 1.2 isaki audio_format2_is_signed(const audio_format2_t *fmt)
287 1.2 isaki {
288 1.2 isaki return (fmt->encoding == AUDIO_ENCODING_SLINEAR_LE)
289 1.2 isaki || (fmt->encoding == AUDIO_ENCODING_SLINEAR_BE);
290 1.2 isaki }
291 1.2 isaki
292 1.2 isaki /*
293 1.2 isaki * Return fmt's endian as LITTLE_ENDIAN or BIG_ENDIAN.
294 1.2 isaki */
295 1.2 isaki static __inline int
296 1.2 isaki audio_format2_endian(const audio_format2_t *fmt)
297 1.2 isaki {
298 1.2 isaki if (fmt->stride == 8) {
299 1.2 isaki /* HOST ENDIAN */
300 1.2 isaki return BYTE_ORDER;
301 1.2 isaki }
302 1.2 isaki
303 1.2 isaki if (fmt->encoding == AUDIO_ENCODING_SLINEAR_LE ||
304 1.2 isaki fmt->encoding == AUDIO_ENCODING_ULINEAR_LE) {
305 1.2 isaki return LITTLE_ENDIAN;
306 1.2 isaki }
307 1.2 isaki if (fmt->encoding == AUDIO_ENCODING_SLINEAR_BE ||
308 1.2 isaki fmt->encoding == AUDIO_ENCODING_ULINEAR_BE) {
309 1.2 isaki return BIG_ENDIAN;
310 1.2 isaki }
311 1.2 isaki return BYTE_ORDER;
312 1.2 isaki }
313 1.2 isaki
314 1.2 isaki /* Interfaces for audiobell. */
315 1.2 isaki struct audiobell_arg {
316 1.2 isaki u_int sample_rate; /* IN */
317 1.2 isaki u_int encoding; /* IN */
318 1.2 isaki u_int channels; /* IN */
319 1.2 isaki u_int precision; /* IN */
320 1.2 isaki u_int blocksize; /* OUT */
321 1.2 isaki audio_file_t *file; /* OUT */
322 1.2 isaki };
323 1.2 isaki int audiobellopen(dev_t, struct audiobell_arg *);
324 1.2 isaki int audiobellclose(audio_file_t *);
325 1.2 isaki int audiobellwrite(audio_file_t *, struct uio *);
326 1.2 isaki
327 1.2 isaki #endif /* !_SYS_DEV_AUDIO_AUDIOVAR_H_ */
328