Deleted Added
full compact
sound.h (169319) sound.h (170161)
1/*-
2 * Copyright (c) 1999 Cameron Grant <cg@freebsd.org>
3 * Copyright by Hannu Savolainen 1995
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 * SUCH DAMAGE.
26 *
1/*-
2 * Copyright (c) 1999 Cameron Grant <cg@freebsd.org>
3 * Copyright by Hannu Savolainen 1995
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 * SUCH DAMAGE.
26 *
27 * $FreeBSD: head/sys/dev/sound/pcm/sound.h 169319 2007-05-06 16:46:23Z ariff $
27 * $FreeBSD: head/sys/dev/sound/pcm/sound.h 170161 2007-05-31 18:43:33Z ariff $
28 */
29
30/*
31 * first, include kernel header files.
32 */
33
34#ifndef _OS_H_
35#define _OS_H_
36
37#ifdef _KERNEL
38#include <sys/param.h>
39#include <sys/systm.h>
40#include <sys/ioccom.h>
41#include <sys/filio.h>
42#include <sys/sockio.h>
43#include <sys/fcntl.h>
44#include <sys/tty.h>
45#include <sys/proc.h>
46#include <sys/kernel.h> /* for DATA_SET */
47#include <sys/module.h>
48#include <sys/conf.h>
49#include <sys/file.h>
50#include <sys/uio.h>
51#include <sys/syslog.h>
52#include <sys/errno.h>
53#include <sys/malloc.h>
54#include <sys/bus.h>
55#if __FreeBSD_version < 500000
56#include <sys/buf.h>
57#endif
58#include <machine/resource.h>
59#include <machine/bus.h>
60#include <sys/rman.h>
61#include <sys/limits.h>
62#include <sys/mman.h>
63#include <sys/poll.h>
64#include <sys/sbuf.h>
65#include <sys/soundcard.h>
66#include <sys/sysctl.h>
67#include <sys/kobj.h>
68#include <vm/vm.h>
69#include <vm/pmap.h>
70
71#undef USING_MUTEX
72#undef USING_DEVFS
73
74#if __FreeBSD_version > 500000
75#include <sys/lock.h>
76#include <sys/mutex.h>
77#include <sys/condvar.h>
78
79#define USING_MUTEX
80#define USING_DEVFS
81#else
82#define INTR_TYPE_AV INTR_TYPE_TTY
83#define INTR_MPSAFE 0
84#endif
85
86#define SND_DYNSYSCTL
87
88struct pcm_channel;
89struct pcm_feeder;
90struct snd_dbuf;
91struct snd_mixer;
92
93#include <dev/sound/pcm/buffer.h>
94#include <dev/sound/pcm/channel.h>
95#include <dev/sound/pcm/feeder.h>
96#include <dev/sound/pcm/mixer.h>
97#include <dev/sound/pcm/dsp.h>
28 */
29
30/*
31 * first, include kernel header files.
32 */
33
34#ifndef _OS_H_
35#define _OS_H_
36
37#ifdef _KERNEL
38#include <sys/param.h>
39#include <sys/systm.h>
40#include <sys/ioccom.h>
41#include <sys/filio.h>
42#include <sys/sockio.h>
43#include <sys/fcntl.h>
44#include <sys/tty.h>
45#include <sys/proc.h>
46#include <sys/kernel.h> /* for DATA_SET */
47#include <sys/module.h>
48#include <sys/conf.h>
49#include <sys/file.h>
50#include <sys/uio.h>
51#include <sys/syslog.h>
52#include <sys/errno.h>
53#include <sys/malloc.h>
54#include <sys/bus.h>
55#if __FreeBSD_version < 500000
56#include <sys/buf.h>
57#endif
58#include <machine/resource.h>
59#include <machine/bus.h>
60#include <sys/rman.h>
61#include <sys/limits.h>
62#include <sys/mman.h>
63#include <sys/poll.h>
64#include <sys/sbuf.h>
65#include <sys/soundcard.h>
66#include <sys/sysctl.h>
67#include <sys/kobj.h>
68#include <vm/vm.h>
69#include <vm/pmap.h>
70
71#undef USING_MUTEX
72#undef USING_DEVFS
73
74#if __FreeBSD_version > 500000
75#include <sys/lock.h>
76#include <sys/mutex.h>
77#include <sys/condvar.h>
78
79#define USING_MUTEX
80#define USING_DEVFS
81#else
82#define INTR_TYPE_AV INTR_TYPE_TTY
83#define INTR_MPSAFE 0
84#endif
85
86#define SND_DYNSYSCTL
87
88struct pcm_channel;
89struct pcm_feeder;
90struct snd_dbuf;
91struct snd_mixer;
92
93#include <dev/sound/pcm/buffer.h>
94#include <dev/sound/pcm/channel.h>
95#include <dev/sound/pcm/feeder.h>
96#include <dev/sound/pcm/mixer.h>
97#include <dev/sound/pcm/dsp.h>
98#include <dev/sound/clone.h>
99#include <dev/sound/unit.h>
98
99#define PCM_SOFTC_SIZE 512
100
101#define SND_STATUSLEN 64
102
103#define SOUND_MODVER 2
104
105#define SOUND_MINVER SOUND_MODVER
106#define SOUND_PREFVER SOUND_MODVER
107#define SOUND_MAXVER SOUND_MODVER
108
109/*
110 * We're abusing the fact that MAXMINOR still have enough room
100
101#define PCM_SOFTC_SIZE 512
102
103#define SND_STATUSLEN 64
104
105#define SOUND_MODVER 2
106
107#define SOUND_MINVER SOUND_MODVER
108#define SOUND_PREFVER SOUND_MODVER
109#define SOUND_MAXVER SOUND_MODVER
110
111/*
112 * We're abusing the fact that MAXMINOR still have enough room
111 * for our bit twiddling and nobody ever need 2048 unique soundcards,
112 * 32 unique device types and 256 unique cloneable devices for the
113 * next 100 years... or until the NextPCM.
114 *
115 * MAXMINOR 0xffff00ff
116 * | |
117 * | +--- PCMMAXCHAN
118 * |
119 * +-------- ((PCMMAXUNIT << 5) | PCMMAXDEV) << 16
113 * for our bit twiddling and nobody ever need 512 unique soundcards,
114 * 32 unique device types and 1024 unique cloneable devices for the
115 * next 100 years...
120 */
121
116 */
117
122#define PCMMAXCHAN 0xff
123#define PCMMAXDEV 0x1f
124#define PCMMAXUNIT 0x7ff
125#define PCMMINOR(x) minor(x)
126#define PCMCHAN(x) (PCMMINOR(x) & PCMMAXCHAN)
127#define PCMUNIT(x) ((PCMMINOR(x) >> 21) & PCMMAXUNIT)
128#define PCMDEV(x) ((PCMMINOR(x) >> 16) & PCMMAXDEV)
129#define PCMMKMINOR(u, d, c) ((((u) & PCMMAXUNIT) << 21) | \
130 (((d) & PCMMAXDEV) << 16) | ((c) & PCMMAXCHAN))
118#define PCMMAXUNIT (snd_max_u())
119#define PCMMAXDEV (snd_max_d())
120#define PCMMAXCHAN (snd_max_c())
131
121
122#define PCMMAXCLONE PCMMAXCHAN
123
124#define PCMUNIT(x) (snd_unit2u(dev2unit(x)))
125#define PCMDEV(x) (snd_unit2d(dev2unit(x)))
126#define PCMCHAN(x) (snd_unit2c(dev2unit(x)))
127
128/*
129 * By design, limit possible channels for each direction.
130 */
131#define SND_MAXHWCHAN 256
132#define SND_MAXVCHANS SND_MAXHWCHAN
133
132#define SD_F_SIMPLEX 0x00000001
133#define SD_F_AUTOVCHAN 0x00000002
134#define SD_F_SOFTPCMVOL 0x00000004
135#define SD_F_PSWAPLR 0x00000008
136#define SD_F_RSWAPLR 0x00000010
134#define SD_F_SIMPLEX 0x00000001
135#define SD_F_AUTOVCHAN 0x00000002
136#define SD_F_SOFTPCMVOL 0x00000004
137#define SD_F_PSWAPLR 0x00000008
138#define SD_F_RSWAPLR 0x00000010
139#define SD_F_DYING 0x00000020
140#define SD_F_SUICIDE 0x00000040
137#define SD_F_PRIO_RD 0x10000000
138#define SD_F_PRIO_WR 0x20000000
139#define SD_F_PRIO_SET (SD_F_PRIO_RD | SD_F_PRIO_WR)
140#define SD_F_DIR_SET 0x40000000
141#define SD_F_TRANSIENT 0xf0000000
142
143/* many variables should be reduced to a range. Here define a macro */
144#define RANGE(var, low, high) (var) = \
145 (((var)<(low))? (low) : ((var)>(high))? (high) : (var))
146#define DSP_BUFFSIZE (8192)
147
148/*
149 * Macros for reading/writing PCM sample / int values from bytes array.
150 * Since every process is done using signed integer (and to make our life
151 * less miserable), unsigned sample will be converted to its signed
152 * counterpart and restored during writing back. To avoid overflow,
153 * we truncate 32bit (and only 32bit) samples down to 24bit (see below
154 * for the reason), unless PCM_USE_64BIT_ARITH is defined.
155 */
156
157/*
158 * Automatically turn on 64bit arithmetic on suitable archs
159 * (amd64 64bit, ia64, etc..) for wider 32bit samples / integer processing.
160 */
161#if LONG_BIT >= 64
162#undef PCM_USE_64BIT_ARITH
163#define PCM_USE_64BIT_ARITH 1
164#else
165#if 0
166#undef PCM_USE_64BIT_ARITH
167#define PCM_USE_64BIT_ARITH 1
168#endif
169#endif
170
171#ifdef PCM_USE_64BIT_ARITH
172typedef int64_t intpcm_t;
173#else
174typedef int32_t intpcm_t;
175#endif
176
177/* 32bit fixed point shift */
178#define PCM_FXSHIFT 8
179
180#define PCM_S8_MAX 0x7f
181#define PCM_S8_MIN -0x80
182#define PCM_S16_MAX 0x7fff
183#define PCM_S16_MIN -0x8000
184#define PCM_S24_MAX 0x7fffff
185#define PCM_S24_MIN -0x800000
186#ifdef PCM_USE_64BIT_ARITH
187#if LONG_BIT >= 64
188#define PCM_S32_MAX 0x7fffffffL
189#define PCM_S32_MIN -0x80000000L
190#else
191#define PCM_S32_MAX 0x7fffffffLL
192#define PCM_S32_MIN -0x80000000LL
193#endif
194#else
195#define PCM_S32_MAX 0x7fffffff
196#define PCM_S32_MIN (-0x7fffffff - 1)
197#endif
198
199/* Bytes-per-sample definition */
200#define PCM_8_BPS 1
201#define PCM_16_BPS 2
202#define PCM_24_BPS 3
203#define PCM_32_BPS 4
204
205#if BYTE_ORDER == LITTLE_ENDIAN
206#define PCM_READ_S16_LE(b8) *((int16_t *)(b8))
207#define _PCM_READ_S32_LE(b8) *((int32_t *)(b8))
208#define PCM_READ_S16_BE(b8) \
209 ((int32_t)((b8)[1] | ((int8_t)((b8)[0])) << 8))
210#define _PCM_READ_S32_BE(b8) \
211 ((int32_t)((b8)[3] | (b8)[2] << 8 | (b8)[1] << 16 | \
212 ((int8_t)((b8)[0])) << 24))
213
214#define PCM_WRITE_S16_LE(b8, val) *((int16_t *)(b8)) = (val)
215#define _PCM_WRITE_S32_LE(b8, val) *((int32_t *)(b8)) = (val)
216#define PCM_WRITE_S16_BE(bb8, vval) do { \
217 int32_t val = (vval); \
218 uint8_t *b8 = (bb8); \
219 b8[1] = val; \
220 b8[0] = val >> 8; \
221 } while(0)
222#define _PCM_WRITE_S32_BE(bb8, vval) do { \
223 int32_t val = (vval); \
224 uint8_t *b8 = (bb8); \
225 b8[3] = val; \
226 b8[2] = val >> 8; \
227 b8[1] = val >> 16; \
228 b8[0] = val >> 24; \
229 } while(0)
230
231#define PCM_READ_U16_LE(b8) ((int16_t)(*((uint16_t *)(b8)) ^ 0x8000))
232#define _PCM_READ_U32_LE(b8) ((int32_t)(*((uint32_t *)(b8)) ^ 0x80000000))
233#define PCM_READ_U16_BE(b8) \
234 ((int32_t)((b8)[1] | ((int8_t)((b8)[0] ^ 0x80)) << 8))
235#define _PCM_READ_U32_BE(b8) \
236 ((int32_t)((b8)[3] | (b8)[2] << 8 | (b8)[1] << 16 | \
237 ((int8_t)((b8)[0] ^ 0x80)) << 24))
238
239#define PCM_WRITE_U16_LE(b8, val) *((uint16_t *)(b8)) = (val) ^ 0x8000
240#define _PCM_WRITE_U32_LE(b8, val) *((uint32_t *)(b8)) = (val) ^ 0x80000000
241#define PCM_WRITE_U16_BE(bb8, vval) do { \
242 int32_t val = (vval); \
243 uint8_t *b8 = (bb8); \
244 b8[1] = val; \
245 b8[0] = (val >> 8) ^ 0x80; \
246 } while(0)
247#define _PCM_WRITE_U32_BE(bb8, vval) do { \
248 int32_t val = (vval); \
249 uint8_t *b8 = (bb8); \
250 b8[3] = val; \
251 b8[2] = val >> 8; \
252 b8[1] = val >> 16; \
253 b8[0] = (val >> 24) ^ 0x80; \
254 } while(0)
255#else /* !LITTLE_ENDIAN */
256#define PCM_READ_S16_LE(b8) \
257 ((int32_t)((b8)[0] | ((int8_t)((b8)[1])) << 8))
258#define _PCM_READ_S32_LE(b8) \
259 ((int32_t)((b8)[0] | (b8)[1] << 8 | (b8)[2] << 16 | \
260 ((int8_t)((b8)[3])) << 24))
261#define PCM_READ_S16_BE(b8) *((int16_t *)(b8))
262#define _PCM_READ_S32_BE(b8) *((int32_t *)(b8))
263
264#define PCM_WRITE_S16_LE(bb8, vval) do { \
265 int32_t val = (vval); \
266 uint8_t *b8 = (bb8); \
267 b8[0] = val; \
268 b8[1] = val >> 8; \
269 } while(0)
270#define _PCM_WRITE_S32_LE(bb8, vval) do { \
271 int32_t val = (vval); \
272 uint8_t *b8 = (bb8); \
273 b8[0] = val; \
274 b8[1] = val >> 8; \
275 b8[2] = val >> 16; \
276 b8[3] = val >> 24; \
277 } while(0)
278#define PCM_WRITE_S16_BE(b8, val) *((int16_t *)(b8)) = (val)
279#define _PCM_WRITE_S32_BE(b8, val) *((int32_t *)(b8)) = (val)
280
281#define PCM_READ_U16_LE(b8) \
282 ((int32_t)((b8)[0] | ((int8_t)((b8)[1] ^ 0x80)) << 8))
283#define _PCM_READ_U32_LE(b8) \
284 ((int32_t)((b8)[0] | (b8)[1] << 8 | (b8)[2] << 16 | \
285 ((int8_t)((b8)[3] ^ 0x80)) << 24))
286#define PCM_READ_U16_BE(b8) ((int16_t)(*((uint16_t *)(b8)) ^ 0x8000))
287#define _PCM_READ_U32_BE(b8) ((int32_t)(*((uint32_t *)(b8)) ^ 0x80000000))
288
289#define PCM_WRITE_U16_LE(bb8, vval) do { \
290 int32_t val = (vval); \
291 uint8_t *b8 = (bb8); \
292 b8[0] = val; \
293 b8[1] = (val >> 8) ^ 0x80; \
294 } while(0)
295#define _PCM_WRITE_U32_LE(bb8, vval) do { \
296 int32_t val = (vval); \
297 uint8_t *b8 = (bb8); \
298 b8[0] = val; \
299 b8[1] = val >> 8; \
300 b8[2] = val >> 16; \
301 b8[3] = (val >> 24) ^ 0x80; \
302 } while(0)
303#define PCM_WRITE_U16_BE(b8, val) *((uint16_t *)(b8)) = (val) ^ 0x8000
304#define _PCM_WRITE_U32_BE(b8, val) *((uint32_t *)(b8)) = (val) ^ 0x80000000
305#endif
306
307#define PCM_READ_S24_LE(b8) \
308 ((int32_t)((b8)[0] | (b8)[1] << 8 | ((int8_t)((b8)[2])) << 16))
309#define PCM_READ_S24_BE(b8) \
310 ((int32_t)((b8)[2] | (b8)[1] << 8 | ((int8_t)((b8)[0])) << 16))
311
312#define PCM_WRITE_S24_LE(bb8, vval) do { \
313 int32_t val = (vval); \
314 uint8_t *b8 = (bb8); \
315 b8[0] = val; \
316 b8[1] = val >> 8; \
317 b8[2] = val >> 16; \
318 } while(0)
319#define PCM_WRITE_S24_BE(bb8, vval) do { \
320 int32_t val = (vval); \
321 uint8_t *b8 = (bb8); \
322 b8[2] = val; \
323 b8[1] = val >> 8; \
324 b8[0] = val >> 16; \
325 } while(0)
326
327#define PCM_READ_U24_LE(b8) \
328 ((int32_t)((b8)[0] | (b8)[1] << 8 | \
329 ((int8_t)((b8)[2] ^ 0x80)) << 16))
330#define PCM_READ_U24_BE(b8) \
331 ((int32_t)((b8)[2] | (b8)[1] << 8 | \
332 ((int8_t)((b8)[0] ^ 0x80)) << 16))
333
334#define PCM_WRITE_U24_LE(bb8, vval) do { \
335 int32_t val = (vval); \
336 uint8_t *b8 = (bb8); \
337 b8[0] = val; \
338 b8[1] = val >> 8; \
339 b8[2] = (val >> 16) ^ 0x80; \
340 } while(0)
341#define PCM_WRITE_U24_BE(bb8, vval) do { \
342 int32_t val = (vval); \
343 uint8_t *b8 = (bb8); \
344 b8[2] = val; \
345 b8[1] = val >> 8; \
346 b8[0] = (val >> 16) ^ 0x80; \
347 } while(0)
348
349#ifdef PCM_USE_64BIT_ARITH
350#define PCM_READ_S32_LE(b8) _PCM_READ_S32_LE(b8)
351#define PCM_READ_S32_BE(b8) _PCM_READ_S32_BE(b8)
352#define PCM_WRITE_S32_LE(b8, val) _PCM_WRITE_S32_LE(b8, val)
353#define PCM_WRITE_S32_BE(b8, val) _PCM_WRITE_S32_BE(b8, val)
354
355#define PCM_READ_U32_LE(b8) _PCM_READ_U32_LE(b8)
356#define PCM_READ_U32_BE(b8) _PCM_READ_U32_BE(b8)
357#define PCM_WRITE_U32_LE(b8, val) _PCM_WRITE_U32_LE(b8, val)
358#define PCM_WRITE_U32_BE(b8, val) _PCM_WRITE_U32_BE(b8, val)
359#else /* !PCM_USE_64BIT_ARITH */
360/*
361 * 24bit integer ?!? This is quite unfortunate, eh? Get the fact straight:
362 * Dynamic range for:
363 * 1) Human =~ 140db
364 * 2) 16bit = 96db (close enough)
365 * 3) 24bit = 144db (perfect)
366 * 4) 32bit = 196db (way too much)
367 * 5) Bugs Bunny = Gazillion!@%$Erbzzztt-EINVAL db
368 * Since we're not Bugs Bunny ..uh..err.. avoiding 64bit arithmetic, 24bit
369 * is pretty much sufficient for our signed integer processing.
370 */
371#define PCM_READ_S32_LE(b8) (_PCM_READ_S32_LE(b8) >> PCM_FXSHIFT)
372#define PCM_READ_S32_BE(b8) (_PCM_READ_S32_BE(b8) >> PCM_FXSHIFT)
373#define PCM_WRITE_S32_LE(b8, val) _PCM_WRITE_S32_LE(b8, (val) << PCM_FXSHIFT)
374#define PCM_WRITE_S32_BE(b8, val) _PCM_WRITE_S32_BE(b8, (val) << PCM_FXSHIFT)
375
376#define PCM_READ_U32_LE(b8) (_PCM_READ_U32_LE(b8) >> PCM_FXSHIFT)
377#define PCM_READ_U32_BE(b8) (_PCM_READ_U32_BE(b8) >> PCM_FXSHIFT)
378#define PCM_WRITE_U32_LE(b8, val) _PCM_WRITE_U32_LE(b8, (val) << PCM_FXSHIFT)
379#define PCM_WRITE_U32_BE(b8, val) _PCM_WRITE_U32_BE(b8, (val) << PCM_FXSHIFT)
380#endif
381
382/*
383 * 8bit sample is pretty much useless since it doesn't provide
384 * sufficient dynamic range throughout our filtering process.
385 * For the sake of completeness, declare it anyway.
386 */
387#define PCM_READ_S8(b8) *((int8_t *)(b8))
388#define PCM_READ_S8_NE(b8) PCM_READ_S8(b8)
389#define PCM_READ_U8(b8) ((int8_t)(*((uint8_t *)(b8)) ^ 0x80))
390#define PCM_READ_U8_NE(b8) PCM_READ_U8(b8)
391
392#define PCM_WRITE_S8(b8, val) *((int8_t *)(b8)) = (val)
393#define PCM_WRITE_S8_NE(b8, val) PCM_WRITE_S8(b8, val)
394#define PCM_WRITE_U8(b8, val) *((uint8_t *)(b8)) = (val) ^ 0x80
395#define PCM_WRITE_U8_NE(b8, val) PCM_WRITE_U8(b8, val)
396
397#define PCM_CLAMP_S8(val) \
398 (((val) > PCM_S8_MAX) ? PCM_S8_MAX : \
399 (((val) < PCM_S8_MIN) ? PCM_S8_MIN : (val)))
400#define PCM_CLAMP_S16(val) \
401 (((val) > PCM_S16_MAX) ? PCM_S16_MAX : \
402 (((val) < PCM_S16_MIN) ? PCM_S16_MIN : (val)))
403#define PCM_CLAMP_S24(val) \
404 (((val) > PCM_S24_MAX) ? PCM_S24_MAX : \
405 (((val) < PCM_S24_MIN) ? PCM_S24_MIN : (val)))
406
407#ifdef PCM_USE_64BIT_ARITH
408#define PCM_CLAMP_S32(val) \
409 (((val) > PCM_S32_MAX) ? PCM_S32_MAX : \
410 (((val) < PCM_S32_MIN) ? PCM_S32_MIN : (val)))
411#else
412#define PCM_CLAMP_S32(val) \
413 (((val) > PCM_S24_MAX) ? PCM_S32_MAX : \
414 (((val) < PCM_S24_MIN) ? PCM_S32_MIN : \
415 ((val) << PCM_FXSHIFT)))
416#endif
417
418#define PCM_CLAMP_U8(val) PCM_CLAMP_S8(val)
419#define PCM_CLAMP_U16(val) PCM_CLAMP_S16(val)
420#define PCM_CLAMP_U24(val) PCM_CLAMP_S24(val)
421#define PCM_CLAMP_U32(val) PCM_CLAMP_S32(val)
422
423/* make figuring out what a format is easier. got AFMT_STEREO already */
424#define AFMT_32BIT (AFMT_S32_LE | AFMT_S32_BE | AFMT_U32_LE | AFMT_U32_BE)
425#define AFMT_24BIT (AFMT_S24_LE | AFMT_S24_BE | AFMT_U24_LE | AFMT_U24_BE)
426#define AFMT_16BIT (AFMT_S16_LE | AFMT_S16_BE | AFMT_U16_LE | AFMT_U16_BE)
427#define AFMT_8BIT (AFMT_MU_LAW | AFMT_A_LAW | AFMT_U8 | AFMT_S8)
428#define AFMT_SIGNED (AFMT_S32_LE | AFMT_S32_BE | AFMT_S24_LE | AFMT_S24_BE | \
429 AFMT_S16_LE | AFMT_S16_BE | AFMT_S8)
430#define AFMT_BIGENDIAN (AFMT_S32_BE | AFMT_U32_BE | AFMT_S24_BE | AFMT_U24_BE | \
431 AFMT_S16_BE | AFMT_U16_BE)
432
433struct pcm_channel *fkchan_setup(device_t dev);
434int fkchan_kill(struct pcm_channel *c);
435
141#define SD_F_PRIO_RD 0x10000000
142#define SD_F_PRIO_WR 0x20000000
143#define SD_F_PRIO_SET (SD_F_PRIO_RD | SD_F_PRIO_WR)
144#define SD_F_DIR_SET 0x40000000
145#define SD_F_TRANSIENT 0xf0000000
146
147/* many variables should be reduced to a range. Here define a macro */
148#define RANGE(var, low, high) (var) = \
149 (((var)<(low))? (low) : ((var)>(high))? (high) : (var))
150#define DSP_BUFFSIZE (8192)
151
152/*
153 * Macros for reading/writing PCM sample / int values from bytes array.
154 * Since every process is done using signed integer (and to make our life
155 * less miserable), unsigned sample will be converted to its signed
156 * counterpart and restored during writing back. To avoid overflow,
157 * we truncate 32bit (and only 32bit) samples down to 24bit (see below
158 * for the reason), unless PCM_USE_64BIT_ARITH is defined.
159 */
160
161/*
162 * Automatically turn on 64bit arithmetic on suitable archs
163 * (amd64 64bit, ia64, etc..) for wider 32bit samples / integer processing.
164 */
165#if LONG_BIT >= 64
166#undef PCM_USE_64BIT_ARITH
167#define PCM_USE_64BIT_ARITH 1
168#else
169#if 0
170#undef PCM_USE_64BIT_ARITH
171#define PCM_USE_64BIT_ARITH 1
172#endif
173#endif
174
175#ifdef PCM_USE_64BIT_ARITH
176typedef int64_t intpcm_t;
177#else
178typedef int32_t intpcm_t;
179#endif
180
181/* 32bit fixed point shift */
182#define PCM_FXSHIFT 8
183
184#define PCM_S8_MAX 0x7f
185#define PCM_S8_MIN -0x80
186#define PCM_S16_MAX 0x7fff
187#define PCM_S16_MIN -0x8000
188#define PCM_S24_MAX 0x7fffff
189#define PCM_S24_MIN -0x800000
190#ifdef PCM_USE_64BIT_ARITH
191#if LONG_BIT >= 64
192#define PCM_S32_MAX 0x7fffffffL
193#define PCM_S32_MIN -0x80000000L
194#else
195#define PCM_S32_MAX 0x7fffffffLL
196#define PCM_S32_MIN -0x80000000LL
197#endif
198#else
199#define PCM_S32_MAX 0x7fffffff
200#define PCM_S32_MIN (-0x7fffffff - 1)
201#endif
202
203/* Bytes-per-sample definition */
204#define PCM_8_BPS 1
205#define PCM_16_BPS 2
206#define PCM_24_BPS 3
207#define PCM_32_BPS 4
208
209#if BYTE_ORDER == LITTLE_ENDIAN
210#define PCM_READ_S16_LE(b8) *((int16_t *)(b8))
211#define _PCM_READ_S32_LE(b8) *((int32_t *)(b8))
212#define PCM_READ_S16_BE(b8) \
213 ((int32_t)((b8)[1] | ((int8_t)((b8)[0])) << 8))
214#define _PCM_READ_S32_BE(b8) \
215 ((int32_t)((b8)[3] | (b8)[2] << 8 | (b8)[1] << 16 | \
216 ((int8_t)((b8)[0])) << 24))
217
218#define PCM_WRITE_S16_LE(b8, val) *((int16_t *)(b8)) = (val)
219#define _PCM_WRITE_S32_LE(b8, val) *((int32_t *)(b8)) = (val)
220#define PCM_WRITE_S16_BE(bb8, vval) do { \
221 int32_t val = (vval); \
222 uint8_t *b8 = (bb8); \
223 b8[1] = val; \
224 b8[0] = val >> 8; \
225 } while(0)
226#define _PCM_WRITE_S32_BE(bb8, vval) do { \
227 int32_t val = (vval); \
228 uint8_t *b8 = (bb8); \
229 b8[3] = val; \
230 b8[2] = val >> 8; \
231 b8[1] = val >> 16; \
232 b8[0] = val >> 24; \
233 } while(0)
234
235#define PCM_READ_U16_LE(b8) ((int16_t)(*((uint16_t *)(b8)) ^ 0x8000))
236#define _PCM_READ_U32_LE(b8) ((int32_t)(*((uint32_t *)(b8)) ^ 0x80000000))
237#define PCM_READ_U16_BE(b8) \
238 ((int32_t)((b8)[1] | ((int8_t)((b8)[0] ^ 0x80)) << 8))
239#define _PCM_READ_U32_BE(b8) \
240 ((int32_t)((b8)[3] | (b8)[2] << 8 | (b8)[1] << 16 | \
241 ((int8_t)((b8)[0] ^ 0x80)) << 24))
242
243#define PCM_WRITE_U16_LE(b8, val) *((uint16_t *)(b8)) = (val) ^ 0x8000
244#define _PCM_WRITE_U32_LE(b8, val) *((uint32_t *)(b8)) = (val) ^ 0x80000000
245#define PCM_WRITE_U16_BE(bb8, vval) do { \
246 int32_t val = (vval); \
247 uint8_t *b8 = (bb8); \
248 b8[1] = val; \
249 b8[0] = (val >> 8) ^ 0x80; \
250 } while(0)
251#define _PCM_WRITE_U32_BE(bb8, vval) do { \
252 int32_t val = (vval); \
253 uint8_t *b8 = (bb8); \
254 b8[3] = val; \
255 b8[2] = val >> 8; \
256 b8[1] = val >> 16; \
257 b8[0] = (val >> 24) ^ 0x80; \
258 } while(0)
259#else /* !LITTLE_ENDIAN */
260#define PCM_READ_S16_LE(b8) \
261 ((int32_t)((b8)[0] | ((int8_t)((b8)[1])) << 8))
262#define _PCM_READ_S32_LE(b8) \
263 ((int32_t)((b8)[0] | (b8)[1] << 8 | (b8)[2] << 16 | \
264 ((int8_t)((b8)[3])) << 24))
265#define PCM_READ_S16_BE(b8) *((int16_t *)(b8))
266#define _PCM_READ_S32_BE(b8) *((int32_t *)(b8))
267
268#define PCM_WRITE_S16_LE(bb8, vval) do { \
269 int32_t val = (vval); \
270 uint8_t *b8 = (bb8); \
271 b8[0] = val; \
272 b8[1] = val >> 8; \
273 } while(0)
274#define _PCM_WRITE_S32_LE(bb8, vval) do { \
275 int32_t val = (vval); \
276 uint8_t *b8 = (bb8); \
277 b8[0] = val; \
278 b8[1] = val >> 8; \
279 b8[2] = val >> 16; \
280 b8[3] = val >> 24; \
281 } while(0)
282#define PCM_WRITE_S16_BE(b8, val) *((int16_t *)(b8)) = (val)
283#define _PCM_WRITE_S32_BE(b8, val) *((int32_t *)(b8)) = (val)
284
285#define PCM_READ_U16_LE(b8) \
286 ((int32_t)((b8)[0] | ((int8_t)((b8)[1] ^ 0x80)) << 8))
287#define _PCM_READ_U32_LE(b8) \
288 ((int32_t)((b8)[0] | (b8)[1] << 8 | (b8)[2] << 16 | \
289 ((int8_t)((b8)[3] ^ 0x80)) << 24))
290#define PCM_READ_U16_BE(b8) ((int16_t)(*((uint16_t *)(b8)) ^ 0x8000))
291#define _PCM_READ_U32_BE(b8) ((int32_t)(*((uint32_t *)(b8)) ^ 0x80000000))
292
293#define PCM_WRITE_U16_LE(bb8, vval) do { \
294 int32_t val = (vval); \
295 uint8_t *b8 = (bb8); \
296 b8[0] = val; \
297 b8[1] = (val >> 8) ^ 0x80; \
298 } while(0)
299#define _PCM_WRITE_U32_LE(bb8, vval) do { \
300 int32_t val = (vval); \
301 uint8_t *b8 = (bb8); \
302 b8[0] = val; \
303 b8[1] = val >> 8; \
304 b8[2] = val >> 16; \
305 b8[3] = (val >> 24) ^ 0x80; \
306 } while(0)
307#define PCM_WRITE_U16_BE(b8, val) *((uint16_t *)(b8)) = (val) ^ 0x8000
308#define _PCM_WRITE_U32_BE(b8, val) *((uint32_t *)(b8)) = (val) ^ 0x80000000
309#endif
310
311#define PCM_READ_S24_LE(b8) \
312 ((int32_t)((b8)[0] | (b8)[1] << 8 | ((int8_t)((b8)[2])) << 16))
313#define PCM_READ_S24_BE(b8) \
314 ((int32_t)((b8)[2] | (b8)[1] << 8 | ((int8_t)((b8)[0])) << 16))
315
316#define PCM_WRITE_S24_LE(bb8, vval) do { \
317 int32_t val = (vval); \
318 uint8_t *b8 = (bb8); \
319 b8[0] = val; \
320 b8[1] = val >> 8; \
321 b8[2] = val >> 16; \
322 } while(0)
323#define PCM_WRITE_S24_BE(bb8, vval) do { \
324 int32_t val = (vval); \
325 uint8_t *b8 = (bb8); \
326 b8[2] = val; \
327 b8[1] = val >> 8; \
328 b8[0] = val >> 16; \
329 } while(0)
330
331#define PCM_READ_U24_LE(b8) \
332 ((int32_t)((b8)[0] | (b8)[1] << 8 | \
333 ((int8_t)((b8)[2] ^ 0x80)) << 16))
334#define PCM_READ_U24_BE(b8) \
335 ((int32_t)((b8)[2] | (b8)[1] << 8 | \
336 ((int8_t)((b8)[0] ^ 0x80)) << 16))
337
338#define PCM_WRITE_U24_LE(bb8, vval) do { \
339 int32_t val = (vval); \
340 uint8_t *b8 = (bb8); \
341 b8[0] = val; \
342 b8[1] = val >> 8; \
343 b8[2] = (val >> 16) ^ 0x80; \
344 } while(0)
345#define PCM_WRITE_U24_BE(bb8, vval) do { \
346 int32_t val = (vval); \
347 uint8_t *b8 = (bb8); \
348 b8[2] = val; \
349 b8[1] = val >> 8; \
350 b8[0] = (val >> 16) ^ 0x80; \
351 } while(0)
352
353#ifdef PCM_USE_64BIT_ARITH
354#define PCM_READ_S32_LE(b8) _PCM_READ_S32_LE(b8)
355#define PCM_READ_S32_BE(b8) _PCM_READ_S32_BE(b8)
356#define PCM_WRITE_S32_LE(b8, val) _PCM_WRITE_S32_LE(b8, val)
357#define PCM_WRITE_S32_BE(b8, val) _PCM_WRITE_S32_BE(b8, val)
358
359#define PCM_READ_U32_LE(b8) _PCM_READ_U32_LE(b8)
360#define PCM_READ_U32_BE(b8) _PCM_READ_U32_BE(b8)
361#define PCM_WRITE_U32_LE(b8, val) _PCM_WRITE_U32_LE(b8, val)
362#define PCM_WRITE_U32_BE(b8, val) _PCM_WRITE_U32_BE(b8, val)
363#else /* !PCM_USE_64BIT_ARITH */
364/*
365 * 24bit integer ?!? This is quite unfortunate, eh? Get the fact straight:
366 * Dynamic range for:
367 * 1) Human =~ 140db
368 * 2) 16bit = 96db (close enough)
369 * 3) 24bit = 144db (perfect)
370 * 4) 32bit = 196db (way too much)
371 * 5) Bugs Bunny = Gazillion!@%$Erbzzztt-EINVAL db
372 * Since we're not Bugs Bunny ..uh..err.. avoiding 64bit arithmetic, 24bit
373 * is pretty much sufficient for our signed integer processing.
374 */
375#define PCM_READ_S32_LE(b8) (_PCM_READ_S32_LE(b8) >> PCM_FXSHIFT)
376#define PCM_READ_S32_BE(b8) (_PCM_READ_S32_BE(b8) >> PCM_FXSHIFT)
377#define PCM_WRITE_S32_LE(b8, val) _PCM_WRITE_S32_LE(b8, (val) << PCM_FXSHIFT)
378#define PCM_WRITE_S32_BE(b8, val) _PCM_WRITE_S32_BE(b8, (val) << PCM_FXSHIFT)
379
380#define PCM_READ_U32_LE(b8) (_PCM_READ_U32_LE(b8) >> PCM_FXSHIFT)
381#define PCM_READ_U32_BE(b8) (_PCM_READ_U32_BE(b8) >> PCM_FXSHIFT)
382#define PCM_WRITE_U32_LE(b8, val) _PCM_WRITE_U32_LE(b8, (val) << PCM_FXSHIFT)
383#define PCM_WRITE_U32_BE(b8, val) _PCM_WRITE_U32_BE(b8, (val) << PCM_FXSHIFT)
384#endif
385
386/*
387 * 8bit sample is pretty much useless since it doesn't provide
388 * sufficient dynamic range throughout our filtering process.
389 * For the sake of completeness, declare it anyway.
390 */
391#define PCM_READ_S8(b8) *((int8_t *)(b8))
392#define PCM_READ_S8_NE(b8) PCM_READ_S8(b8)
393#define PCM_READ_U8(b8) ((int8_t)(*((uint8_t *)(b8)) ^ 0x80))
394#define PCM_READ_U8_NE(b8) PCM_READ_U8(b8)
395
396#define PCM_WRITE_S8(b8, val) *((int8_t *)(b8)) = (val)
397#define PCM_WRITE_S8_NE(b8, val) PCM_WRITE_S8(b8, val)
398#define PCM_WRITE_U8(b8, val) *((uint8_t *)(b8)) = (val) ^ 0x80
399#define PCM_WRITE_U8_NE(b8, val) PCM_WRITE_U8(b8, val)
400
401#define PCM_CLAMP_S8(val) \
402 (((val) > PCM_S8_MAX) ? PCM_S8_MAX : \
403 (((val) < PCM_S8_MIN) ? PCM_S8_MIN : (val)))
404#define PCM_CLAMP_S16(val) \
405 (((val) > PCM_S16_MAX) ? PCM_S16_MAX : \
406 (((val) < PCM_S16_MIN) ? PCM_S16_MIN : (val)))
407#define PCM_CLAMP_S24(val) \
408 (((val) > PCM_S24_MAX) ? PCM_S24_MAX : \
409 (((val) < PCM_S24_MIN) ? PCM_S24_MIN : (val)))
410
411#ifdef PCM_USE_64BIT_ARITH
412#define PCM_CLAMP_S32(val) \
413 (((val) > PCM_S32_MAX) ? PCM_S32_MAX : \
414 (((val) < PCM_S32_MIN) ? PCM_S32_MIN : (val)))
415#else
416#define PCM_CLAMP_S32(val) \
417 (((val) > PCM_S24_MAX) ? PCM_S32_MAX : \
418 (((val) < PCM_S24_MIN) ? PCM_S32_MIN : \
419 ((val) << PCM_FXSHIFT)))
420#endif
421
422#define PCM_CLAMP_U8(val) PCM_CLAMP_S8(val)
423#define PCM_CLAMP_U16(val) PCM_CLAMP_S16(val)
424#define PCM_CLAMP_U24(val) PCM_CLAMP_S24(val)
425#define PCM_CLAMP_U32(val) PCM_CLAMP_S32(val)
426
427/* make figuring out what a format is easier. got AFMT_STEREO already */
428#define AFMT_32BIT (AFMT_S32_LE | AFMT_S32_BE | AFMT_U32_LE | AFMT_U32_BE)
429#define AFMT_24BIT (AFMT_S24_LE | AFMT_S24_BE | AFMT_U24_LE | AFMT_U24_BE)
430#define AFMT_16BIT (AFMT_S16_LE | AFMT_S16_BE | AFMT_U16_LE | AFMT_U16_BE)
431#define AFMT_8BIT (AFMT_MU_LAW | AFMT_A_LAW | AFMT_U8 | AFMT_S8)
432#define AFMT_SIGNED (AFMT_S32_LE | AFMT_S32_BE | AFMT_S24_LE | AFMT_S24_BE | \
433 AFMT_S16_LE | AFMT_S16_BE | AFMT_S8)
434#define AFMT_BIGENDIAN (AFMT_S32_BE | AFMT_U32_BE | AFMT_S24_BE | AFMT_U24_BE | \
435 AFMT_S16_BE | AFMT_U16_BE)
436
437struct pcm_channel *fkchan_setup(device_t dev);
438int fkchan_kill(struct pcm_channel *c);
439
436/* XXX Flawed definition. I'll fix it someday. */
437#define SND_MAXVCHANS PCMMAXCHAN
438
439/*
440 * Minor numbers for the sound driver.
441 *
442 * Unfortunately Creative called the codec chip of SB as a DSP. For this
443 * reason the /dev/dsp is reserved for digitized audio use. There is a
444 * device for true DSP processors but it will be called something else.
445 * In v3.0 it's /dev/sndproc but this could be a temporary solution.
446 */
447
448#define SND_DEV_CTL 0 /* Control port /dev/mixer */
449#define SND_DEV_SEQ 1 /* Sequencer /dev/sequencer */
450#define SND_DEV_MIDIN 2 /* Raw midi access */
451#define SND_DEV_DSP 3 /* Digitized voice /dev/dsp */
452#define SND_DEV_AUDIO 4 /* Sparc compatible /dev/audio */
453#define SND_DEV_DSP16 5 /* Like /dev/dsp but 16 bits/sample */
454#define SND_DEV_STATUS 6 /* /dev/sndstat */
455 /* #7 not in use now. */
456#define SND_DEV_SEQ2 8 /* /dev/sequencer, level 2 interface */
457#define SND_DEV_SNDPROC 9 /* /dev/sndproc for programmable devices */
458#define SND_DEV_PSS SND_DEV_SNDPROC /* ? */
459#define SND_DEV_NORESET 10
440/*
441 * Minor numbers for the sound driver.
442 *
443 * Unfortunately Creative called the codec chip of SB as a DSP. For this
444 * reason the /dev/dsp is reserved for digitized audio use. There is a
445 * device for true DSP processors but it will be called something else.
446 * In v3.0 it's /dev/sndproc but this could be a temporary solution.
447 */
448
449#define SND_DEV_CTL 0 /* Control port /dev/mixer */
450#define SND_DEV_SEQ 1 /* Sequencer /dev/sequencer */
451#define SND_DEV_MIDIN 2 /* Raw midi access */
452#define SND_DEV_DSP 3 /* Digitized voice /dev/dsp */
453#define SND_DEV_AUDIO 4 /* Sparc compatible /dev/audio */
454#define SND_DEV_DSP16 5 /* Like /dev/dsp but 16 bits/sample */
455#define SND_DEV_STATUS 6 /* /dev/sndstat */
456 /* #7 not in use now. */
457#define SND_DEV_SEQ2 8 /* /dev/sequencer, level 2 interface */
458#define SND_DEV_SNDPROC 9 /* /dev/sndproc for programmable devices */
459#define SND_DEV_PSS SND_DEV_SNDPROC /* ? */
460#define SND_DEV_NORESET 10
460#define SND_DEV_DSPHW 11 /* specific channel request */
461
461
462#define SND_DEV_DSPHW_PLAY 11 /* specific playback channel */
463#define SND_DEV_DSPHW_VPLAY 12 /* specific virtual playback channel */
464#define SND_DEV_DSPHW_REC 13 /* specific record channel */
465#define SND_DEV_DSPHW_VREC 14 /* specific virtual record channel */
466
462#define DSP_DEFAULT_SPEED 8000
463
464#define ON 1
465#define OFF 0
466
467extern int pcm_veto_load;
468extern int snd_unit;
469extern int snd_maxautovchans;
470extern int snd_verbose;
471extern devclass_t pcm_devclass;
472extern struct unrhdr *pcmsg_unrhdr;
473
474/*
475 * some macros for debugging purposes
476 * DDB/DEB to enable/disable debugging stuff
477 * BVDDB to enable debugging when bootverbose
478 */
479#define BVDDB(x) if (bootverbose) x
480
481#ifndef DEB
482#define DEB(x)
483#endif
484
485SYSCTL_DECL(_hw_snd);
486
487struct pcm_channel *pcm_getfakechan(struct snddev_info *d);
467#define DSP_DEFAULT_SPEED 8000
468
469#define ON 1
470#define OFF 0
471
472extern int pcm_veto_load;
473extern int snd_unit;
474extern int snd_maxautovchans;
475extern int snd_verbose;
476extern devclass_t pcm_devclass;
477extern struct unrhdr *pcmsg_unrhdr;
478
479/*
480 * some macros for debugging purposes
481 * DDB/DEB to enable/disable debugging stuff
482 * BVDDB to enable debugging when bootverbose
483 */
484#define BVDDB(x) if (bootverbose) x
485
486#ifndef DEB
487#define DEB(x)
488#endif
489
490SYSCTL_DECL(_hw_snd);
491
492struct pcm_channel *pcm_getfakechan(struct snddev_info *d);
488int pcm_chnalloc(struct snddev_info *d, struct pcm_channel **ch, int direction, pid_t pid, int chnum);
493int pcm_chnalloc(struct snddev_info *d, struct pcm_channel **ch, int direction, pid_t pid, int devunit);
489int pcm_chnrelease(struct pcm_channel *c);
490int pcm_chnref(struct pcm_channel *c, int ref);
491int pcm_inprog(struct snddev_info *d, int delta);
492
494int pcm_chnrelease(struct pcm_channel *c);
495int pcm_chnref(struct pcm_channel *c, int ref);
496int pcm_inprog(struct snddev_info *d, int delta);
497
493struct pcm_channel *pcm_chn_create(struct snddev_info *d, struct pcm_channel *parent, kobj_class_t cls, int dir, void *devinfo);
498struct pcm_channel *pcm_chn_create(struct snddev_info *d, struct pcm_channel *parent, kobj_class_t cls, int dir, int num, void *devinfo);
494int pcm_chn_destroy(struct pcm_channel *ch);
495int pcm_chn_add(struct snddev_info *d, struct pcm_channel *ch);
496int pcm_chn_remove(struct snddev_info *d, struct pcm_channel *ch);
497
498int pcm_addchan(device_t dev, int dir, kobj_class_t cls, void *devinfo);
499unsigned int pcm_getbuffersize(device_t dev, unsigned int minbufsz, unsigned int deflt, unsigned int maxbufsz);
500int pcm_register(device_t dev, void *devinfo, int numplay, int numrec);
501int pcm_unregister(device_t dev);
502int pcm_setstatus(device_t dev, char *str);
503u_int32_t pcm_getflags(device_t dev);
504void pcm_setflags(device_t dev, u_int32_t val);
505void *pcm_getdevinfo(device_t dev);
506
507
508int snd_setup_intr(device_t dev, struct resource *res, int flags,
509 driver_intr_t hand, void *param, void **cookiep);
510
511void *snd_mtxcreate(const char *desc, const char *type);
512void snd_mtxfree(void *m);
513void snd_mtxassert(void *m);
514#define snd_mtxlock(m) mtx_lock(m)
515#define snd_mtxunlock(m) mtx_unlock(m)
516
517int sysctl_hw_snd_vchans(SYSCTL_HANDLER_ARGS);
518
519typedef int (*sndstat_handler)(struct sbuf *s, device_t dev, int verbose);
499int pcm_chn_destroy(struct pcm_channel *ch);
500int pcm_chn_add(struct snddev_info *d, struct pcm_channel *ch);
501int pcm_chn_remove(struct snddev_info *d, struct pcm_channel *ch);
502
503int pcm_addchan(device_t dev, int dir, kobj_class_t cls, void *devinfo);
504unsigned int pcm_getbuffersize(device_t dev, unsigned int minbufsz, unsigned int deflt, unsigned int maxbufsz);
505int pcm_register(device_t dev, void *devinfo, int numplay, int numrec);
506int pcm_unregister(device_t dev);
507int pcm_setstatus(device_t dev, char *str);
508u_int32_t pcm_getflags(device_t dev);
509void pcm_setflags(device_t dev, u_int32_t val);
510void *pcm_getdevinfo(device_t dev);
511
512
513int snd_setup_intr(device_t dev, struct resource *res, int flags,
514 driver_intr_t hand, void *param, void **cookiep);
515
516void *snd_mtxcreate(const char *desc, const char *type);
517void snd_mtxfree(void *m);
518void snd_mtxassert(void *m);
519#define snd_mtxlock(m) mtx_lock(m)
520#define snd_mtxunlock(m) mtx_unlock(m)
521
522int sysctl_hw_snd_vchans(SYSCTL_HANDLER_ARGS);
523
524typedef int (*sndstat_handler)(struct sbuf *s, device_t dev, int verbose);
520int sndstat_acquire(void);
521int sndstat_release(void);
525int sndstat_acquire(struct thread *td);
526int sndstat_release(struct thread *td);
522int sndstat_register(device_t dev, char *str, sndstat_handler handler);
523int sndstat_registerfile(char *str);
524int sndstat_unregister(device_t dev);
525int sndstat_unregisterfile(char *str);
526
527#define SND_DECLARE_FILE(version) \
528 _SND_DECLARE_FILE(__LINE__, version)
529
530#define _SND_DECLARE_FILE(uniq, version) \
531 __SND_DECLARE_FILE(uniq, version)
532
533#define __SND_DECLARE_FILE(uniq, version) \
534 static char sndstat_vinfo[] = version; \
535 SYSINIT(sdf_ ## uniq, SI_SUB_DRIVERS, SI_ORDER_MIDDLE, sndstat_registerfile, sndstat_vinfo); \
536 SYSUNINIT(sdf_ ## uniq, SI_SUB_DRIVERS, SI_ORDER_MIDDLE, sndstat_unregisterfile, sndstat_vinfo);
537
538/* usage of flags in device config entry (config file) */
539#define DV_F_DRQ_MASK 0x00000007 /* mask for secondary drq */
540#define DV_F_DUAL_DMA 0x00000010 /* set to use secondary dma channel */
541
542/* ought to be made obsolete but still used by mss */
543#define DV_F_DEV_MASK 0x0000ff00 /* force device type/class */
544#define DV_F_DEV_SHIFT 8 /* force device type/class */
545
546#define PCM_DEBUG_MTX
547
548/*
549 * this is rather kludgey- we need to duplicate these struct def'ns from sound.c
550 * so that the macro versions of pcm_{,un}lock can dereference them.
551 * we also have to do this now makedev() has gone away.
552 */
553
527int sndstat_register(device_t dev, char *str, sndstat_handler handler);
528int sndstat_registerfile(char *str);
529int sndstat_unregister(device_t dev);
530int sndstat_unregisterfile(char *str);
531
532#define SND_DECLARE_FILE(version) \
533 _SND_DECLARE_FILE(__LINE__, version)
534
535#define _SND_DECLARE_FILE(uniq, version) \
536 __SND_DECLARE_FILE(uniq, version)
537
538#define __SND_DECLARE_FILE(uniq, version) \
539 static char sndstat_vinfo[] = version; \
540 SYSINIT(sdf_ ## uniq, SI_SUB_DRIVERS, SI_ORDER_MIDDLE, sndstat_registerfile, sndstat_vinfo); \
541 SYSUNINIT(sdf_ ## uniq, SI_SUB_DRIVERS, SI_ORDER_MIDDLE, sndstat_unregisterfile, sndstat_vinfo);
542
543/* usage of flags in device config entry (config file) */
544#define DV_F_DRQ_MASK 0x00000007 /* mask for secondary drq */
545#define DV_F_DUAL_DMA 0x00000010 /* set to use secondary dma channel */
546
547/* ought to be made obsolete but still used by mss */
548#define DV_F_DEV_MASK 0x0000ff00 /* force device type/class */
549#define DV_F_DEV_SHIFT 8 /* force device type/class */
550
551#define PCM_DEBUG_MTX
552
553/*
554 * this is rather kludgey- we need to duplicate these struct def'ns from sound.c
555 * so that the macro versions of pcm_{,un}lock can dereference them.
556 * we also have to do this now makedev() has gone away.
557 */
558
554struct snddev_channel {
555 SLIST_ENTRY(snddev_channel) link;
556 struct pcm_channel *channel;
557 int chan_num;
558 struct cdev *dsp_devt;
559 struct cdev *dspW_devt;
560 struct cdev *audio_devt;
561 struct cdev *dspHW_devt;
562};
563
564struct snddev_info {
559struct snddev_info {
565 SLIST_HEAD(, snddev_channel) channels;
560 struct {
561 struct {
562 SLIST_HEAD(, pcm_channel) head;
563 struct {
564 SLIST_HEAD(, pcm_channel) head;
565 } busy;
566 } pcm;
567 } channels;
568 struct snd_clone *clones;
566 struct pcm_channel *fakechan;
569 struct pcm_channel *fakechan;
567 unsigned devcount, playcount, reccount, vchancount;
570 unsigned devcount, playcount, reccount, pvchancount, rvchancount ;
568 unsigned flags;
569 int inprog;
570 unsigned int bufsz;
571 void *devinfo;
572 device_t dev;
573 char status[SND_STATUSLEN];
574 struct mtx *lock;
575 struct cdev *mixer_dev;
571 unsigned flags;
572 int inprog;
573 unsigned int bufsz;
574 void *devinfo;
575 device_t dev;
576 char status[SND_STATUSLEN];
577 struct mtx *lock;
578 struct cdev *mixer_dev;
576
579 uint32_t pvchanrate, pvchanformat;
580 uint32_t rvchanrate, rvchanformat;
581 struct sysctl_ctx_list play_sysctl_ctx, rec_sysctl_ctx;
582 struct sysctl_oid *play_sysctl_tree, *rec_sysctl_tree;
577};
578
579void sound_oss_sysinfo(oss_sysinfo *);
580
581#ifdef PCM_DEBUG_MTX
582#define pcm_lock(d) mtx_lock(((struct snddev_info *)(d))->lock)
583#define pcm_unlock(d) mtx_unlock(((struct snddev_info *)(d))->lock)
584#else
585void pcm_lock(struct snddev_info *d);
586void pcm_unlock(struct snddev_info *d);
587#endif
588
589#ifdef KLD_MODULE
590#define PCM_KLDSTRING(a) ("kld " # a)
591#else
592#define PCM_KLDSTRING(a) ""
593#endif
594
595#endif /* _KERNEL */
596
597#endif /* _OS_H_ */
583};
584
585void sound_oss_sysinfo(oss_sysinfo *);
586
587#ifdef PCM_DEBUG_MTX
588#define pcm_lock(d) mtx_lock(((struct snddev_info *)(d))->lock)
589#define pcm_unlock(d) mtx_unlock(((struct snddev_info *)(d))->lock)
590#else
591void pcm_lock(struct snddev_info *d);
592void pcm_unlock(struct snddev_info *d);
593#endif
594
595#ifdef KLD_MODULE
596#define PCM_KLDSTRING(a) ("kld " # a)
597#else
598#define PCM_KLDSTRING(a) ""
599#endif
600
601#endif /* _KERNEL */
602
603#endif /* _OS_H_ */