aucc.c revision 1.26 1 1.26 mhitch /* $NetBSD: aucc.c,v 1.26 2000/09/03 02:04:53 mhitch Exp $ */
2 1.20 augustss
3 1.1 is /*
4 1.24 is * Copyright (c) 1999 Bernardo Innocenti
5 1.24 is * All rights reserved.
6 1.24 is *
7 1.1 is * Copyright (c) 1997 Stephan Thesing
8 1.1 is * All rights reserved.
9 1.1 is *
10 1.1 is * Redistribution and use in source and binary forms, with or without
11 1.1 is * modification, are permitted provided that the following conditions
12 1.1 is * are met:
13 1.1 is * 1. Redistributions of source code must retain the above copyright
14 1.1 is * notice, this list of conditions and the following disclaimer.
15 1.1 is * 2. Redistributions in binary form must reproduce the above copyright
16 1.1 is * notice, this list of conditions and the following disclaimer in the
17 1.1 is * documentation and/or other materials provided with the distribution.
18 1.1 is * 3. All advertising materials mentioning features or use of this software
19 1.1 is * must display the following acknowledgement:
20 1.1 is * This product includes software developed by Stephan Thesing.
21 1.1 is * 4. The name of the author may not be used to endorse or promote products
22 1.1 is * derived from this software without specific prior written permission
23 1.1 is *
24 1.1 is * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
25 1.1 is * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
26 1.1 is * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
27 1.1 is * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
28 1.1 is * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
29 1.1 is * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30 1.1 is * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31 1.1 is * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32 1.1 is * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
33 1.1 is * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 1.1 is */
35 1.1 is
36 1.24 is /* TODO:
37 1.24 is *
38 1.24 is * - ulaw -> 14bit conversion
39 1.24 is * - channel allocation is wrong for 14bit mono
40 1.24 is * - convert the... err... conversion routines to 68k asm for best performance
41 1.24 is * XXX: NO. aucc audio is limited by chipmem speed, anyway. You dont
42 1.24 is * want to make life difficult for amigappc work.
43 1.24 is * -is
44 1.24 is *
45 1.24 is * - rely on auconv.c routines for ulaw/alaw conversions
46 1.24 is * - perhaps use a calibration table for better 14bit output
47 1.24 is * - set 31KHz AGA video mode to allow 44.1KHz even if grfcc is missing
48 1.24 is * in the kernel
49 1.24 is * - 14bit output requires maximum volume
50 1.24 is */
51 1.24 is
52 1.1 is #include "aucc.h"
53 1.1 is #if NAUCC > 0
54 1.5 is
55 1.1 is #include <sys/param.h>
56 1.1 is #include <sys/systm.h>
57 1.1 is #include <sys/errno.h>
58 1.1 is #include <sys/ioctl.h>
59 1.1 is #include <sys/device.h>
60 1.1 is #include <sys/proc.h>
61 1.1 is #include <machine/cpu.h>
62 1.1 is
63 1.1 is #include <sys/audioio.h>
64 1.1 is #include <dev/audio_if.h>
65 1.1 is #include <amiga/amiga/cc.h>
66 1.1 is #include <amiga/amiga/custom.h>
67 1.1 is #include <amiga/amiga/device.h>
68 1.1 is #include <amiga/dev/auccvar.h>
69 1.1 is
70 1.7 is
71 1.7 is #ifdef LEV6_DEFER
72 1.7 is #define AUCC_MAXINT 3
73 1.7 is #define AUCC_ALLINTF (INTF_AUD0|INTF_AUD1|INTF_AUD2)
74 1.7 is #else
75 1.7 is #define AUCC_MAXINT 4
76 1.7 is #define AUCC_ALLINTF (INTF_AUD0|INTF_AUD1|INTF_AUD2|INTF_AUD3)
77 1.7 is #endif
78 1.7 is /* this unconditionally; we may use AUD3 as slave channel with LEV6_DEFER */
79 1.7 is #define AUCC_ALLDMAF (DMAF_AUD0|DMAF_AUD1|DMAF_AUD2|DMAF_AUD3)
80 1.7 is
81 1.1 is #ifdef AUDIO_DEBUG
82 1.1 is /*extern printf __P((const char *,...));*/
83 1.1 is int auccdebug = 1;
84 1.1 is #define DPRINTF(x) if (auccdebug) printf x
85 1.1 is #else
86 1.1 is #define DPRINTF(x)
87 1.1 is #endif
88 1.1 is
89 1.1 is #ifdef splaudio
90 1.1 is #undef splaudio
91 1.1 is #endif
92 1.1 is
93 1.1 is #define splaudio() spl4();
94 1.1 is
95 1.1 is /* clock frequency.. */
96 1.1 is extern int eclockfreq;
97 1.1 is
98 1.1 is
99 1.1 is /* hw audio ch */
100 1.1 is extern struct audio_channel channel[4];
101 1.1 is
102 1.1 is
103 1.1 is /*
104 1.1 is * Software state.
105 1.1 is */
106 1.1 is struct aucc_softc {
107 1.1 is struct device sc_dev; /* base device */
108 1.1 is
109 1.1 is int sc_open; /* single use device */
110 1.1 is aucc_data_t sc_channel[4]; /* per channel freq, ... */
111 1.1 is u_int sc_encoding; /* encoding AUDIO_ENCODING_.*/
112 1.1 is int sc_channels; /* # of channels used */
113 1.24 is int sc_precision; /* 8 or 16 bits */
114 1.24 is int sc_14bit; /* 14bit output enabled */
115 1.1 is
116 1.1 is int sc_intrcnt; /* interrupt count */
117 1.1 is int sc_channelmask; /* which channels are used ? */
118 1.24 is void (*sc_decodefunc) __P((u_char **, u_char *, int));
119 1.24 is /* pointer to format conversion routine */
120 1.1 is };
121 1.1 is
122 1.1 is /* interrupt interfaces */
123 1.1 is void aucc_inthdl __P((int));
124 1.1 is
125 1.1 is /* forward declarations */
126 1.1 is static int init_aucc __P((struct aucc_softc *));
127 1.1 is static u_int freqtoper __P((u_int));
128 1.1 is static u_int pertofreq __P((u_int));
129 1.1 is
130 1.1 is /* autoconfiguration driver */
131 1.1 is void auccattach __P((struct device *, struct device *, void *));
132 1.1 is int auccmatch __P((struct device *, struct cfdata *, void *));
133 1.1 is
134 1.1 is struct cfattach aucc_ca = {
135 1.1 is sizeof(struct aucc_softc),
136 1.1 is auccmatch,
137 1.1 is auccattach
138 1.1 is };
139 1.1 is
140 1.1 is struct audio_device aucc_device = {
141 1.1 is "Amiga-audio",
142 1.24 is "2.0",
143 1.1 is "aucc"
144 1.1 is };
145 1.1 is
146 1.1 is
147 1.1 is struct aucc_softc *aucc=NULL;
148 1.1 is
149 1.1 is
150 1.1 is unsigned char ulaw_to_lin[] = {
151 1.2 is 0x82, 0x86, 0x8a, 0x8e, 0x92, 0x96, 0x9a, 0x9e,
152 1.2 is 0xa2, 0xa6, 0xaa, 0xae, 0xb2, 0xb6, 0xba, 0xbe,
153 1.2 is 0xc1, 0xc3, 0xc5, 0xc7, 0xc9, 0xcb, 0xcd, 0xcf,
154 1.2 is 0xd1, 0xd3, 0xd5, 0xd7, 0xd9, 0xdb, 0xdd, 0xdf,
155 1.2 is 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8,
156 1.2 is 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef, 0xf0,
157 1.2 is 0xf0, 0xf1, 0xf1, 0xf2, 0xf2, 0xf3, 0xf3, 0xf4,
158 1.2 is 0xf4, 0xf5, 0xf5, 0xf6, 0xf6, 0xf7, 0xf7, 0xf8,
159 1.2 is 0xf8, 0xf8, 0xf9, 0xf9, 0xf9, 0xf9, 0xfa, 0xfa,
160 1.2 is 0xfa, 0xfa, 0xfb, 0xfb, 0xfb, 0xfb, 0xfc, 0xfc,
161 1.2 is 0xfc, 0xfc, 0xfc, 0xfc, 0xfd, 0xfd, 0xfd, 0xfd,
162 1.2 is 0xfd, 0xfd, 0xfd, 0xfd, 0xfe, 0xfe, 0xfe, 0xfe,
163 1.2 is 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe,
164 1.2 is 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
165 1.2 is 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
166 1.2 is 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00,
167 1.2 is 0x7d, 0x79, 0x75, 0x71, 0x6d, 0x69, 0x65, 0x61,
168 1.2 is 0x5d, 0x59, 0x55, 0x51, 0x4d, 0x49, 0x45, 0x41,
169 1.2 is 0x3e, 0x3c, 0x3a, 0x38, 0x36, 0x34, 0x32, 0x30,
170 1.2 is 0x2e, 0x2c, 0x2a, 0x28, 0x26, 0x24, 0x22, 0x20,
171 1.2 is 0x1e, 0x1d, 0x1c, 0x1b, 0x1a, 0x19, 0x18, 0x17,
172 1.2 is 0x16, 0x15, 0x14, 0x13, 0x12, 0x11, 0x10, 0x0f,
173 1.2 is 0x0f, 0x0e, 0x0e, 0x0d, 0x0d, 0x0c, 0x0c, 0x0b,
174 1.2 is 0x0b, 0x0a, 0x0a, 0x09, 0x09, 0x08, 0x08, 0x07,
175 1.2 is 0x07, 0x07, 0x06, 0x06, 0x06, 0x06, 0x05, 0x05,
176 1.2 is 0x05, 0x05, 0x04, 0x04, 0x04, 0x04, 0x03, 0x03,
177 1.2 is 0x03, 0x03, 0x03, 0x03, 0x02, 0x02, 0x02, 0x02,
178 1.2 is 0x02, 0x02, 0x02, 0x02, 0x01, 0x01, 0x01, 0x01,
179 1.2 is 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
180 1.2 is 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
181 1.2 is 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
182 1.2 is 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
183 1.1 is };
184 1.1 is
185 1.1 is /*
186 1.1 is * Define our interface to the higher level audio driver.
187 1.1 is */
188 1.16 augustss int aucc_open __P((void *, int));
189 1.1 is void aucc_close __P((void *));
190 1.1 is int aucc_set_out_sr __P((void *, u_long));
191 1.1 is int aucc_query_encoding __P((void *, struct audio_encoding *));
192 1.1 is int aucc_round_blocksize __P((void *, int));
193 1.1 is int aucc_commit_settings __P((void *));
194 1.1 is int aucc_start_output __P((void *, void *, int, void (*)(void *),
195 1.1 is void *));
196 1.1 is int aucc_start_input __P((void *, void *, int, void (*)(void *),
197 1.1 is void *));
198 1.1 is int aucc_halt_output __P((void *));
199 1.1 is int aucc_halt_input __P((void *));
200 1.1 is int aucc_getdev __P((void *, struct audio_device *));
201 1.1 is int aucc_set_port __P((void *, mixer_ctrl_t *));
202 1.1 is int aucc_get_port __P((void *, mixer_ctrl_t *));
203 1.1 is int aucc_query_devinfo __P((void *, mixer_devinfo_t *));
204 1.24 is void aucc_encode __P((int, int, int, int, u_char *, u_short **));
205 1.18 augustss int aucc_set_params __P((void *, int, int,
206 1.18 augustss struct audio_params *, struct audio_params *));
207 1.16 augustss int aucc_get_props __P((void *));
208 1.1 is
209 1.24 is
210 1.24 is static void aucc_decode_slinear8_1ch __P((u_char **, u_char *, int));
211 1.24 is static void aucc_decode_slinear8_2ch __P((u_char **, u_char *, int));
212 1.24 is static void aucc_decode_slinear8_3ch __P((u_char **, u_char *, int));
213 1.24 is static void aucc_decode_slinear8_4ch __P((u_char **, u_char *, int));
214 1.24 is
215 1.24 is static void aucc_decode_ulinear8_1ch __P((u_char **, u_char *, int));
216 1.24 is static void aucc_decode_ulinear8_2ch __P((u_char **, u_char *, int));
217 1.24 is static void aucc_decode_ulinear8_3ch __P((u_char **, u_char *, int));
218 1.24 is static void aucc_decode_ulinear8_4ch __P((u_char **, u_char *, int));
219 1.24 is
220 1.24 is static void aucc_decode_ulaw_1ch __P((u_char **, u_char *, int));
221 1.24 is static void aucc_decode_ulaw_2ch __P((u_char **, u_char *, int));
222 1.24 is static void aucc_decode_ulaw_3ch __P((u_char **, u_char *, int));
223 1.24 is static void aucc_decode_ulaw_4ch __P((u_char **, u_char *, int));
224 1.24 is
225 1.24 is static void aucc_decode_slinear16_1ch __P((u_char **, u_char *, int));
226 1.24 is static void aucc_decode_slinear16_2ch __P((u_char **, u_char *, int));
227 1.24 is static void aucc_decode_slinear16_3ch __P((u_char **, u_char *, int));
228 1.24 is static void aucc_decode_slinear16_4ch __P((u_char **, u_char *, int));
229 1.24 is
230 1.24 is static void aucc_decode_slinear16sw_1ch __P((u_char **, u_char *, int));
231 1.24 is static void aucc_decode_slinear16sw_2ch __P((u_char **, u_char *, int));
232 1.24 is static void aucc_decode_slinear16sw_3ch __P((u_char **, u_char *, int));
233 1.24 is static void aucc_decode_slinear16sw_4ch __P((u_char **, u_char *, int));
234 1.24 is
235 1.24 is
236 1.24 is
237 1.1 is struct audio_hw_if sa_hw_if = {
238 1.1 is aucc_open,
239 1.1 is aucc_close,
240 1.1 is NULL,
241 1.1 is aucc_query_encoding,
242 1.1 is aucc_set_params,
243 1.1 is aucc_round_blocksize,
244 1.1 is aucc_commit_settings,
245 1.14 augustss NULL,
246 1.14 augustss NULL,
247 1.1 is aucc_start_output,
248 1.1 is aucc_start_input,
249 1.1 is aucc_halt_output,
250 1.1 is aucc_halt_input,
251 1.1 is NULL,
252 1.1 is aucc_getdev,
253 1.13 augustss NULL,
254 1.1 is aucc_set_port,
255 1.1 is aucc_get_port,
256 1.1 is aucc_query_devinfo,
257 1.14 augustss NULL,
258 1.14 augustss NULL,
259 1.14 augustss NULL,
260 1.15 augustss NULL,
261 1.16 augustss aucc_get_props,
262 1.1 is };
263 1.1 is
264 1.1 is /* autoconfig routines */
265 1.1 is
266 1.1 is int
267 1.1 is auccmatch(pdp, cfp, aux)
268 1.1 is struct device *pdp;
269 1.1 is struct cfdata *cfp;
270 1.1 is void *aux;
271 1.1 is {
272 1.25 kleink static int aucc_matched = 0;
273 1.25 kleink
274 1.25 kleink if (!matchname((char *)aux, "aucc") ||
275 1.1 is #ifdef DRACO
276 1.25 kleink is_draco() ||
277 1.1 is #endif
278 1.25 kleink aucc_matched)
279 1.25 kleink return 0;
280 1.1 is
281 1.25 kleink aucc_matched = 1;
282 1.25 kleink return 1;
283 1.1 is }
284 1.1 is
285 1.1 is /*
286 1.1 is * Audio chip found.
287 1.1 is */
288 1.1 is void
289 1.1 is auccattach(parent, self, args)
290 1.1 is struct device *parent, *self;
291 1.1 is void *args;
292 1.1 is {
293 1.1 is register struct aucc_softc *sc = (struct aucc_softc *)self;
294 1.1 is register int i;
295 1.1 is
296 1.1 is printf("\n");
297 1.1 is
298 1.1 is if((i=init_aucc(sc))) {
299 1.1 is printf("audio: no chipmem\n");
300 1.1 is return;
301 1.1 is }
302 1.1 is
303 1.23 augustss audio_attach_mi(&sa_hw_if, sc, &sc->sc_dev);
304 1.1 is }
305 1.1 is
306 1.1 is
307 1.1 is static int
308 1.1 is init_aucc(sc)
309 1.1 is struct aucc_softc *sc;
310 1.1 is {
311 1.1 is register int i, err=0;
312 1.1 is
313 1.1 is /* init values per channel */
314 1.1 is for (i=0;i<4;i++) {
315 1.1 is sc->sc_channel[i].nd_freq=8000;
316 1.1 is sc->sc_channel[i].nd_per=freqtoper(8000);
317 1.1 is sc->sc_channel[i].nd_busy=0;
318 1.1 is sc->sc_channel[i].nd_dma=alloc_chipmem(AUDIO_BUF_SIZE*2);
319 1.1 is if (sc->sc_channel[i].nd_dma==NULL)
320 1.1 is err=1;
321 1.1 is sc->sc_channel[i].nd_dmalength=0;
322 1.1 is sc->sc_channel[i].nd_volume=64;
323 1.1 is sc->sc_channel[i].nd_intr=NULL;
324 1.1 is sc->sc_channel[i].nd_intrdata=NULL;
325 1.8 is sc->sc_channel[i].nd_doublebuf=0;
326 1.1 is DPRINTF(("dma buffer for channel %d is %p\n", i,
327 1.1 is sc->sc_channel[i].nd_dma));
328 1.1 is }
329 1.1 is
330 1.1 is if (err) {
331 1.1 is for(i=0;i<4;i++)
332 1.1 is if (sc->sc_channel[i].nd_dma)
333 1.1 is free_chipmem(sc->sc_channel[i].nd_dma);
334 1.1 is }
335 1.1 is
336 1.8 is sc->sc_channels=1;
337 1.1 is sc->sc_channelmask=0xf;
338 1.24 is sc->sc_precision=8;
339 1.24 is sc->sc_14bit = 0;
340 1.24 is sc->sc_encoding=AUDIO_ENCODING_ULAW;
341 1.24 is sc->sc_decodefunc = aucc_decode_ulaw_1ch;
342 1.1 is
343 1.2 is /* clear interrupts and dma: */
344 1.7 is custom.intena = AUCC_ALLINTF;
345 1.24 is custom.dmacon = AUCC_ALLDMAF;
346 1.1 is
347 1.1 is return err;
348 1.1 is }
349 1.1 is
350 1.1 is int
351 1.16 augustss aucc_open(addr, flags)
352 1.16 augustss void *addr;
353 1.1 is int flags;
354 1.1 is {
355 1.16 augustss struct aucc_softc *sc = addr;
356 1.16 augustss int i;
357 1.1 is
358 1.16 augustss DPRINTF(("sa_open: unit %p\n",sc));
359 1.1 is
360 1.1 is if (sc->sc_open)
361 1.1 is return (EBUSY);
362 1.1 is sc->sc_open = 1;
363 1.7 is for (i=0;i<AUCC_MAXINT;i++) {
364 1.1 is sc->sc_channel[i].nd_intr=NULL;
365 1.1 is sc->sc_channel[i].nd_intrdata=NULL;
366 1.1 is }
367 1.1 is aucc=sc;
368 1.1 is sc->sc_channelmask=0xf;
369 1.1 is
370 1.1 is DPRINTF(("saopen: ok -> sc=0x%p\n",sc));
371 1.1 is
372 1.1 is return (0);
373 1.1 is }
374 1.1 is
375 1.1 is void
376 1.1 is aucc_close(addr)
377 1.1 is void *addr;
378 1.1 is {
379 1.1 is register struct aucc_softc *sc = addr;
380 1.1 is
381 1.1 is DPRINTF(("sa_close: sc=0x%p\n", sc));
382 1.1 is /*
383 1.1 is * halt i/o, clear open flag, and done.
384 1.1 is */
385 1.1 is aucc_halt_output(sc);
386 1.1 is sc->sc_open = 0;
387 1.1 is
388 1.1 is DPRINTF(("sa_close: closed.\n"));
389 1.1 is }
390 1.1 is
391 1.1 is int
392 1.1 is aucc_set_out_sr(addr, sr)
393 1.1 is void *addr;
394 1.1 is u_long sr;
395 1.1 is {
396 1.1 is struct aucc_softc *sc=addr;
397 1.1 is u_long per;
398 1.1 is register int i;
399 1.1 is
400 1.1 is per=freqtoper(sr);
401 1.1 is if (per>0xffff)
402 1.1 is return EINVAL;
403 1.1 is sr=pertofreq(per);
404 1.1 is
405 1.1 is for (i=0;i<4;i++) {
406 1.1 is sc->sc_channel[i].nd_freq=sr;
407 1.1 is sc->sc_channel[i].nd_per=per;
408 1.1 is }
409 1.1 is
410 1.1 is return(0);
411 1.1 is }
412 1.1 is
413 1.1 is int
414 1.1 is aucc_query_encoding(addr, fp)
415 1.1 is void *addr;
416 1.1 is struct audio_encoding *fp;
417 1.1 is {
418 1.24 is switch (fp->index) {
419 1.24 is case 0:
420 1.24 is strcpy(fp->name, AudioEslinear);
421 1.24 is fp->encoding = AUDIO_ENCODING_SLINEAR;
422 1.24 is fp->precision = 8;
423 1.24 is fp->flags = 0;
424 1.24 is break;
425 1.24 is case 1:
426 1.24 is strcpy(fp->name, AudioEmulaw);
427 1.24 is fp->encoding = AUDIO_ENCODING_ULAW;
428 1.24 is fp->precision = 8;
429 1.24 is fp->flags = AUDIO_ENCODINGFLAG_EMULATED;
430 1.24 is break;
431 1.1 is
432 1.24 is case 2:
433 1.24 is strcpy(fp->name, AudioEulinear);
434 1.24 is fp->encoding = AUDIO_ENCODING_ULINEAR;
435 1.24 is fp->precision = 8;
436 1.24 is fp->flags = AUDIO_ENCODINGFLAG_EMULATED;
437 1.24 is break;
438 1.24 is
439 1.24 is case 3:
440 1.24 is strcpy(fp->name, AudioEslinear);
441 1.24 is fp->encoding = AUDIO_ENCODING_SLINEAR;
442 1.24 is fp->precision = 16;
443 1.24 is fp->flags = AUDIO_ENCODINGFLAG_EMULATED;
444 1.24 is break;
445 1.24 is
446 1.24 is case 4:
447 1.24 is strcpy(fp->name, AudioEslinear_be);
448 1.24 is fp->encoding = AUDIO_ENCODING_SLINEAR_BE;
449 1.24 is fp->precision = 16;
450 1.24 is fp->flags = AUDIO_ENCODINGFLAG_EMULATED;
451 1.24 is break;
452 1.24 is
453 1.24 is case 5:
454 1.24 is strcpy(fp->name, AudioEslinear_le);
455 1.24 is fp->encoding = AUDIO_ENCODING_SLINEAR_LE;
456 1.24 is fp->precision = 16;
457 1.24 is fp->flags = AUDIO_ENCODINGFLAG_EMULATED;
458 1.24 is break;
459 1.3 is
460 1.24 is default:
461 1.24 is return(EINVAL);
462 1.24 is /*NOTREACHED*/
463 1.1 is }
464 1.1 is return(0);
465 1.1 is }
466 1.1 is
467 1.1 is int
468 1.18 augustss aucc_set_params(addr, setmode, usemode, p, r)
469 1.1 is void *addr;
470 1.18 augustss int setmode, usemode;
471 1.18 augustss struct audio_params *p, *r;
472 1.1 is {
473 1.18 augustss struct aucc_softc *sc = addr;
474 1.8 is
475 1.18 augustss /* if (setmode & AUMODE_RECORD)
476 1.8 is return 0 ENXIO*/;
477 1.8 is
478 1.9 is #ifdef AUCCDEBUG
479 1.24 is printf("aucc_set_params(setmode 0x%x, usemode 0x%x, "
480 1.24 is "enc %d, bits %d, chn %d, sr %ld)\n", setmode, usemode,
481 1.24 is p->encoding, p->precision, p->channels, p->sample_rate);
482 1.24 is #endif
483 1.24 is
484 1.24 is switch (p->precision) {
485 1.24 is case 8:
486 1.24 is switch (p->encoding) {
487 1.24 is case AUDIO_ENCODING_ULAW:
488 1.24 is switch (p->channels) {
489 1.24 is case 1:
490 1.24 is sc->sc_decodefunc = aucc_decode_ulaw_1ch;
491 1.24 is break;
492 1.24 is case 2:
493 1.24 is sc->sc_decodefunc = aucc_decode_ulaw_2ch;
494 1.24 is break;
495 1.24 is case 3:
496 1.24 is sc->sc_decodefunc = aucc_decode_ulaw_3ch;
497 1.24 is break;
498 1.24 is case 4:
499 1.24 is sc->sc_decodefunc = aucc_decode_ulaw_4ch;
500 1.24 is break;
501 1.24 is default:
502 1.24 is return EINVAL;
503 1.24 is }
504 1.24 is break;
505 1.24 is
506 1.24 is case AUDIO_ENCODING_SLINEAR:
507 1.24 is case AUDIO_ENCODING_SLINEAR_BE:
508 1.24 is case AUDIO_ENCODING_SLINEAR_LE:
509 1.24 is switch (p->channels) {
510 1.24 is case 1:
511 1.24 is sc->sc_decodefunc = aucc_decode_slinear8_1ch;
512 1.24 is break;
513 1.24 is case 2:
514 1.24 is sc->sc_decodefunc = aucc_decode_slinear8_2ch;
515 1.24 is break;
516 1.24 is case 3:
517 1.24 is sc->sc_decodefunc = aucc_decode_slinear8_3ch;
518 1.24 is break;
519 1.24 is case 4:
520 1.24 is sc->sc_decodefunc = aucc_decode_slinear8_4ch;
521 1.24 is break;
522 1.24 is default:
523 1.24 is return EINVAL;
524 1.24 is }
525 1.24 is break;
526 1.24 is
527 1.24 is case AUDIO_ENCODING_ULINEAR:
528 1.24 is case AUDIO_ENCODING_ULINEAR_BE:
529 1.24 is case AUDIO_ENCODING_ULINEAR_LE:
530 1.24 is switch (p->channels) {
531 1.24 is case 1:
532 1.24 is sc->sc_decodefunc = aucc_decode_ulinear8_1ch;
533 1.24 is break;
534 1.24 is case 2:
535 1.24 is sc->sc_decodefunc = aucc_decode_ulinear8_2ch;
536 1.24 is break;
537 1.24 is case 3:
538 1.24 is sc->sc_decodefunc = aucc_decode_ulinear8_3ch;
539 1.24 is break;
540 1.24 is case 4:
541 1.24 is sc->sc_decodefunc = aucc_decode_ulinear8_4ch;
542 1.24 is break;
543 1.24 is default:
544 1.24 is return EINVAL;
545 1.24 is }
546 1.24 is break;
547 1.24 is
548 1.24 is default:
549 1.24 is return EINVAL;
550 1.24 is }
551 1.24 is break;
552 1.24 is
553 1.24 is case 16:
554 1.24 is switch (p->encoding) {
555 1.24 is #if BYTE_ORDER == BIG_ENDIAN
556 1.24 is case AUDIO_ENCODING_SLINEAR:
557 1.24 is #endif
558 1.24 is case AUDIO_ENCODING_SLINEAR_BE:
559 1.24 is switch (p->channels) {
560 1.24 is case 1:
561 1.24 is sc->sc_decodefunc = aucc_decode_slinear16_1ch;
562 1.24 is break;
563 1.24 is
564 1.24 is case 2:
565 1.24 is sc->sc_decodefunc = aucc_decode_slinear16_2ch;
566 1.24 is break;
567 1.24 is case 3:
568 1.24 is sc->sc_decodefunc = aucc_decode_slinear16_3ch;
569 1.24 is break;
570 1.24 is case 4:
571 1.24 is sc->sc_decodefunc = aucc_decode_slinear16_4ch;
572 1.24 is break;
573 1.24 is default:
574 1.24 is return EINVAL;
575 1.24 is }
576 1.24 is break;
577 1.24 is
578 1.24 is #if BYTE_ORDER == LITTLE_ENDIAN
579 1.24 is case AUDIO_ENCODING_SLINEAR:
580 1.9 is #endif
581 1.24 is case AUDIO_ENCODING_SLINEAR_LE:
582 1.24 is switch (p->channels) {
583 1.24 is case 1:
584 1.24 is sc->sc_decodefunc = aucc_decode_slinear16sw_1ch;
585 1.24 is break;
586 1.24 is case 2:
587 1.24 is sc->sc_decodefunc = aucc_decode_slinear16sw_2ch;
588 1.24 is break;
589 1.24 is case 3:
590 1.24 is sc->sc_decodefunc = aucc_decode_slinear16sw_3ch;
591 1.24 is break;
592 1.24 is case 4:
593 1.24 is sc->sc_decodefunc = aucc_decode_slinear16sw_4ch;
594 1.24 is break;
595 1.24 is default:
596 1.24 is return EINVAL;
597 1.24 is }
598 1.24 is break;
599 1.4 is
600 1.24 is default:
601 1.24 is return EINVAL;
602 1.24 is }
603 1.24 is break;
604 1.8 is
605 1.1 is default:
606 1.1 is return EINVAL;
607 1.1 is }
608 1.1 is
609 1.8 is sc->sc_encoding = p->encoding;
610 1.24 is sc->sc_precision = p->precision;
611 1.24 is sc->sc_14bit = ((p->precision == 16) && (p->channels <= 2));
612 1.24 is sc->sc_channels = sc->sc_14bit ? (p->channels * 2) : p->channels;
613 1.8 is
614 1.8 is return aucc_set_out_sr(addr, p->sample_rate);
615 1.1 is }
616 1.1 is
617 1.1 is int
618 1.1 is aucc_round_blocksize(addr, blk)
619 1.1 is void *addr;
620 1.1 is int blk;
621 1.1 is {
622 1.24 is /* round up to even size */
623 1.24 is return blk > AUDIO_BUF_SIZE ? AUDIO_BUF_SIZE : blk;
624 1.1 is }
625 1.1 is
626 1.1 is int
627 1.1 is aucc_commit_settings(addr)
628 1.1 is void *addr;
629 1.1 is {
630 1.1 is register struct aucc_softc *sc = addr;
631 1.1 is register int i;
632 1.1 is
633 1.1 is DPRINTF(("sa_commit.\n"));
634 1.1 is
635 1.1 is for (i=0;i<4;i++) {
636 1.1 is custom.aud[i].vol=sc->sc_channel[i].nd_volume;
637 1.1 is custom.aud[i].per=sc->sc_channel[i].nd_per;
638 1.1 is }
639 1.1 is
640 1.1 is DPRINTF(("commit done\n"));
641 1.1 is
642 1.1 is return(0);
643 1.1 is }
644 1.1 is
645 1.1 is static int masks[4] = {1,3,7,15}; /* masks for n first channels */
646 1.1 is static int masks2[4] = {1,2,4,8};
647 1.1 is
648 1.1 is int
649 1.1 is aucc_start_output(addr, p, cc, intr, arg)
650 1.1 is void *addr;
651 1.1 is void *p;
652 1.1 is int cc;
653 1.1 is void (*intr) __P((void *));
654 1.1 is void *arg;
655 1.1 is {
656 1.8 is struct aucc_softc *sc;
657 1.8 is int mask;
658 1.24 is int i, j, k, len;
659 1.24 is u_char *dmap[4];
660 1.8 is
661 1.1 is
662 1.8 is sc = addr;
663 1.8 is mask = sc->sc_channelmask;
664 1.1 is
665 1.8 is dmap[0] = dmap[1] = dmap[2] = dmap[3] = NULL;
666 1.1 is
667 1.1 is DPRINTF(("sa_start_output: cc=%d %p (%p)\n", cc, intr, arg));
668 1.1 is
669 1.10 is if (sc->sc_channels > 1)
670 1.24 is mask &= masks[sc->sc_channels - 1];
671 1.10 is /* we use first sc_channels channels */
672 1.24 is if (mask == 0) /* active and used channels are disjoint */
673 1.1 is return EINVAL;
674 1.1 is
675 1.24 is for (i=0;i<4;i++) {
676 1.24 is /* channels available ? */
677 1.24 is if ((masks2[i] & mask) && (sc->sc_channel[i].nd_busy))
678 1.1 is return EBUSY; /* channel is busy */
679 1.24 is if (channel[i].isaudio == -1)
680 1.1 is return EBUSY; /* system uses them */
681 1.1 is }
682 1.1 is
683 1.1 is /* enable interrupt on 1st channel */
684 1.24 is for (i = j = 0; i < AUCC_MAXINT; i++) {
685 1.24 is if (masks2[i] & mask) {
686 1.1 is DPRINTF(("first channel is %d\n",i));
687 1.1 is j=i;
688 1.1 is sc->sc_channel[i].nd_intr=intr;
689 1.1 is sc->sc_channel[i].nd_intrdata=arg;
690 1.1 is break;
691 1.1 is }
692 1.1 is }
693 1.1 is
694 1.8 is DPRINTF(("dmap is %p %p %p %p, mask=0x%x\n", dmap[0], dmap[1],
695 1.8 is dmap[2], dmap[3], mask));
696 1.8 is
697 1.8 is /* disable ints, dma for channels, until all parameters set */
698 1.8 is /* XXX dont disable DMA! custom.dmacon=mask;*/
699 1.24 is custom.intreq = mask << INTB_AUD0;
700 1.24 is custom.intena = mask << INTB_AUD0;
701 1.1 is
702 1.1 is /* copy data to dma buffer */
703 1.1 is
704 1.8 is if (sc->sc_channels == 1) {
705 1.8 is dmap[0] =
706 1.8 is dmap[1] =
707 1.8 is dmap[2] =
708 1.24 is dmap[3] = (u_char *)sc->sc_channel[j].nd_dma;
709 1.24 is }
710 1.24 is else {
711 1.8 is for (k=0; k<4; k++) {
712 1.24 is if (masks2[k+j] & mask)
713 1.24 is dmap[k] = (u_char *)sc->sc_channel[k+j].nd_dma;
714 1.8 is }
715 1.8 is }
716 1.8 is
717 1.8 is sc->sc_channel[j].nd_doublebuf ^= 1;
718 1.8 is if (sc->sc_channel[j].nd_doublebuf) {
719 1.24 is dmap[0] += AUDIO_BUF_SIZE;
720 1.24 is dmap[1] += AUDIO_BUF_SIZE;
721 1.24 is dmap[2] += AUDIO_BUF_SIZE;
722 1.24 is dmap[3] += AUDIO_BUF_SIZE;
723 1.8 is }
724 1.1 is
725 1.24 is /* compute output length in bytes per channel.
726 1.24 is * divide by two only for 16bit->8bit conversion.
727 1.24 is */
728 1.24 is len = cc / sc->sc_channels;
729 1.24 is if (!sc->sc_14bit && (sc->sc_precision == 16))
730 1.24 is len /= 2;
731 1.24 is
732 1.24 is /* call audio decoding routine */
733 1.24 is sc->sc_decodefunc (dmap, (u_char *)p, len);
734 1.1 is
735 1.24 is /* dma buffers: we use same buffer 4 all channels
736 1.24 is * write dma location and length
737 1.24 is */
738 1.24 is for (i = k = 0; i < 4; i++) {
739 1.8 is if (masks2[i] & mask) {
740 1.1 is DPRINTF(("turning channel %d on\n",i));
741 1.24 is /* sc->sc_channel[i].nd_busy=1; */
742 1.24 is channel[i].isaudio = 1;
743 1.24 is channel[i].play_count = 1;
744 1.24 is channel[i].handler = NULL;
745 1.24 is custom.aud[i].per = sc->sc_channel[i].nd_per;
746 1.24 is if (sc->sc_14bit && (i > 1))
747 1.24 is custom.aud[i].vol = 1;
748 1.24 is else
749 1.24 is custom.aud[i].vol = sc->sc_channel[i].nd_volume;
750 1.8 is custom.aud[i].lc = PREP_DMA_MEM(dmap[k++]);
751 1.24 is custom.aud[i].len = len / 2;
752 1.24 is sc->sc_channel[i].nd_mask = mask;
753 1.1 is DPRINTF(("per is %d, vol is %d, len is %d\n",\
754 1.8 is sc->sc_channel[i].nd_per,
755 1.24 is sc->sc_channel[i].nd_volume, len));
756 1.1 is }
757 1.1 is }
758 1.1 is
759 1.1 is channel[j].handler=aucc_inthdl;
760 1.1 is
761 1.1 is /* enable ints */
762 1.24 is custom.intena = INTF_SETCLR | INTF_INTEN | (masks2[j] << INTB_AUD0);
763 1.1 is
764 1.24 is DPRINTF(("enabled ints: 0x%x\n", (masks2[j] << INTB_AUD0)));
765 1.1 is
766 1.1 is /* enable dma */
767 1.24 is custom.dmacon = DMAF_SETCLR | DMAF_MASTER | mask;
768 1.1 is
769 1.1 is DPRINTF(("enabled dma, mask=0x%x\n",mask));
770 1.1 is
771 1.1 is return(0);
772 1.1 is }
773 1.1 is
774 1.1 is /* ARGSUSED */
775 1.1 is int
776 1.1 is aucc_start_input(addr, p, cc, intr, arg)
777 1.1 is void *addr;
778 1.1 is void *p;
779 1.1 is int cc;
780 1.1 is void (*intr) __P((void *));
781 1.1 is void *arg;
782 1.1 is {
783 1.1 is
784 1.1 is return ENXIO; /* no input */
785 1.1 is }
786 1.1 is
787 1.1 is int
788 1.1 is aucc_halt_output(addr)
789 1.1 is void *addr;
790 1.1 is {
791 1.1 is register struct aucc_softc *sc = addr;
792 1.1 is register int i;
793 1.1 is
794 1.1 is /* XXX only halt, if input is also halted ?? */
795 1.1 is /* stop dma, etc */
796 1.7 is custom.intena = AUCC_ALLINTF;
797 1.7 is custom.dmacon = AUCC_ALLDMAF;
798 1.1 is /* mark every busy unit idle */
799 1.1 is for (i=0;i<4;i++) {
800 1.1 is sc->sc_channel[i].nd_busy=sc->sc_channel[i].nd_mask=0;
801 1.1 is channel[i].isaudio=0;
802 1.1 is channel[i].play_count=0;
803 1.1 is }
804 1.1 is
805 1.1 is return(0);
806 1.1 is }
807 1.1 is
808 1.1 is int
809 1.1 is aucc_halt_input(addr)
810 1.1 is void *addr;
811 1.1 is {
812 1.1 is /* no input */
813 1.1 is
814 1.1 is return ENXIO;
815 1.1 is }
816 1.1 is
817 1.1 is int
818 1.1 is aucc_getdev(addr, retp)
819 1.1 is void *addr;
820 1.1 is struct audio_device *retp;
821 1.1 is {
822 1.1 is *retp = aucc_device;
823 1.1 is return 0;
824 1.1 is }
825 1.1 is
826 1.1 is int
827 1.1 is aucc_set_port(addr, cp)
828 1.1 is void *addr;
829 1.1 is mixer_ctrl_t *cp;
830 1.1 is {
831 1.1 is register struct aucc_softc *sc = addr;
832 1.1 is register int i,j;
833 1.1 is
834 1.1 is DPRINTF(("aucc_set_port: port=%d", cp->dev));
835 1.1 is
836 1.1 is switch (cp->type) {
837 1.1 is case AUDIO_MIXER_SET:
838 1.1 is if (cp->dev!=AUCC_CHANNELS)
839 1.1 is return EINVAL;
840 1.1 is i=cp->un.mask;
841 1.24 is if ((i<1) || (i>15))
842 1.1 is return EINVAL;
843 1.24 is
844 1.1 is sc->sc_channelmask=i;
845 1.1 is break;
846 1.1 is
847 1.1 is case AUDIO_MIXER_VALUE:
848 1.1 is i=cp->un.value.num_channels;
849 1.24 is if ((i<1) || (i>4))
850 1.1 is return EINVAL;
851 1.1 is
852 1.10 is #ifdef __XXXwhatsthat
853 1.1 is if (cp->dev!=AUCC_VOLUME)
854 1.1 is return EINVAL;
855 1.10 is #endif
856 1.1 is
857 1.1 is /* set volume for channel 0..i-1 */
858 1.21 is
859 1.21 is /* evil workaround for xanim bug, IMO */
860 1.21 is if ((sc->sc_channels == 1) && (i == 2)) {
861 1.21 is sc->sc_channel[0].nd_volume =
862 1.21 is sc->sc_channel[3].nd_volume =
863 1.21 is cp->un.value.level[0]>>2;
864 1.21 is sc->sc_channel[1].nd_volume =
865 1.21 is sc->sc_channel[2].nd_volume =
866 1.21 is cp->un.value.level[1]>>2;
867 1.21 is } else if (i>1) {
868 1.10 is for (j=0;j<i;j++)
869 1.10 is sc->sc_channel[j].nd_volume =
870 1.10 is cp->un.value.level[j]>>2;
871 1.21 is } else if (sc->sc_channels > 1)
872 1.10 is for (j=0; j<sc->sc_channels; j++)
873 1.10 is sc->sc_channel[j].nd_volume =
874 1.10 is cp->un.value.level[0]>>2;
875 1.10 is else
876 1.10 is for (j=0; j<4; j++)
877 1.10 is sc->sc_channel[j].nd_volume =
878 1.10 is cp->un.value.level[0]>>2;
879 1.10 is break;
880 1.1 is
881 1.1 is default:
882 1.1 is return EINVAL;
883 1.1 is break;
884 1.1 is }
885 1.1 is return 0;
886 1.1 is }
887 1.1 is
888 1.1 is
889 1.1 is int
890 1.1 is aucc_get_port(addr, cp)
891 1.1 is void *addr;
892 1.1 is mixer_ctrl_t *cp;
893 1.1 is {
894 1.1 is register struct aucc_softc *sc = addr;
895 1.1 is register int i,j;
896 1.1 is
897 1.1 is DPRINTF(("aucc_get_port: port=%d", cp->dev));
898 1.1 is
899 1.1 is switch (cp->type) {
900 1.1 is case AUDIO_MIXER_SET:
901 1.1 is if (cp->dev!=AUCC_CHANNELS)
902 1.1 is return EINVAL;
903 1.1 is cp->un.mask=sc->sc_channelmask;
904 1.1 is break;
905 1.1 is
906 1.1 is case AUDIO_MIXER_VALUE:
907 1.1 is i = cp->un.value.num_channels;
908 1.1 is if ((i<1)||(i>4))
909 1.1 is return EINVAL;
910 1.1 is
911 1.1 is for (j=0;j<i;j++)
912 1.10 is cp->un.value.level[j] =
913 1.10 is (sc->sc_channel[j].nd_volume<<2) +
914 1.10 is (sc->sc_channel[j].nd_volume>>4);
915 1.1 is break;
916 1.1 is
917 1.1 is default:
918 1.1 is return EINVAL;
919 1.1 is }
920 1.1 is return 0;
921 1.1 is }
922 1.1 is
923 1.16 augustss
924 1.16 augustss int
925 1.16 augustss aucc_get_props(addr)
926 1.16 augustss void *addr;
927 1.16 augustss {
928 1.16 augustss return 0;
929 1.16 augustss }
930 1.1 is
931 1.1 is int
932 1.1 is aucc_query_devinfo(addr, dip)
933 1.1 is void *addr;
934 1.1 is register mixer_devinfo_t *dip;
935 1.1 is {
936 1.1 is register int i;
937 1.1 is
938 1.1 is switch(dip->index) {
939 1.1 is case AUCC_CHANNELS:
940 1.1 is dip->type = AUDIO_MIXER_SET;
941 1.1 is dip->mixer_class = AUCC_OUTPUT_CLASS;
942 1.1 is dip->prev = dip->next = AUDIO_MIXER_LAST;
943 1.1 is strcpy(dip->label.name, AudioNspeaker);
944 1.1 is for (i=0;i<16;i++) {
945 1.1 is sprintf(dip->un.s.member[i].label.name,
946 1.1 is "channelmask%d", i);
947 1.1 is dip->un.s.member[i].mask = i;
948 1.1 is }
949 1.1 is dip->un.s.num_mem = 16;
950 1.1 is break;
951 1.1 is
952 1.1 is case AUCC_VOLUME:
953 1.1 is dip->type = AUDIO_MIXER_VALUE;
954 1.1 is dip->mixer_class = AUCC_OUTPUT_CLASS;
955 1.1 is dip->prev = dip->next = AUDIO_MIXER_LAST;
956 1.20 augustss strcpy(dip->label.name, AudioNmaster);
957 1.1 is dip->un.v.num_channels = 4;
958 1.1 is strcpy(dip->un.v.units.name, AudioNvolume);
959 1.1 is break;
960 1.1 is
961 1.1 is case AUCC_OUTPUT_CLASS:
962 1.1 is dip->type = AUDIO_MIXER_CLASS;
963 1.1 is dip->mixer_class = AUCC_OUTPUT_CLASS;
964 1.1 is dip->next = dip->prev = AUDIO_MIXER_LAST;
965 1.19 mycroft strcpy(dip->label.name, AudioCoutputs);
966 1.1 is break;
967 1.20 augustss
968 1.1 is default:
969 1.1 is return ENXIO;
970 1.1 is }
971 1.1 is
972 1.1 is DPRINTF(("AUDIO_MIXER_DEVINFO: name=%s\n", dip->label.name));
973 1.1 is
974 1.1 is return(0);
975 1.1 is }
976 1.1 is
977 1.1 is
978 1.1 is /* audio int handler */
979 1.1 is void
980 1.1 is aucc_inthdl(int ch)
981 1.1 is {
982 1.1 is register int i;
983 1.1 is register int mask=aucc->sc_channel[ch].nd_mask;
984 1.1 is
985 1.1 is /* for all channels in this maskgroup:
986 1.1 is disable dma, int
987 1.1 is mark idle */
988 1.1 is DPRINTF(("inthandler called, channel %d, mask 0x%x\n",ch,mask));
989 1.1 is
990 1.7 is custom.intreq=mask<<INTB_AUD0; /* clear request */
991 1.24 is /*
992 1.24 is * XXX: maybe we can leave ints and/or DMA on,
993 1.24 is * if another sample has to be played?
994 1.24 is */
995 1.7 is custom.intena=mask<<INTB_AUD0;
996 1.1 is /*
997 1.1 is * XXX custom.dmacon=mask; NO!!!
998 1.1 is */
999 1.24 is for (i=0; i<4; i++) {
1000 1.1 is if (masks2[i]&&mask) {
1001 1.1 is DPRINTF(("marking channel %d idle\n",i));
1002 1.1 is aucc->sc_channel[i].nd_busy=0;
1003 1.1 is aucc->sc_channel[i].nd_mask=0;
1004 1.1 is channel[i].isaudio=channel[i].play_count=0;
1005 1.1 is }
1006 1.1 is }
1007 1.1 is
1008 1.1 is /* call handler */
1009 1.1 is if (aucc->sc_channel[ch].nd_intr) {
1010 1.1 is DPRINTF(("calling %p\n",aucc->sc_channel[ch].nd_intr));
1011 1.24 is (*(aucc->sc_channel[ch].nd_intr))
1012 1.24 is (aucc->sc_channel[ch].nd_intrdata);
1013 1.1 is }
1014 1.24 is else
1015 1.24 is DPRINTF(("zero int handler\n"));
1016 1.1 is DPRINTF(("ints done\n"));
1017 1.1 is }
1018 1.1 is
1019 1.1 is
1020 1.1 is
1021 1.1 is
1022 1.1 is /* transform frequency to period, adjust bounds */
1023 1.1 is static u_int
1024 1.24 is freqtoper(u_int freq) {
1025 1.1 is u_int per=eclockfreq*5/freq;
1026 1.1 is
1027 1.1 is if (per<124)
1028 1.1 is per=124; /* must have at least 124 ticks between samples */
1029 1.1 is
1030 1.1 is return per;
1031 1.1 is }
1032 1.1 is
1033 1.1 is /* transform period to frequency */
1034 1.1 is static u_int
1035 1.24 is pertofreq(u_int per) {
1036 1.24 is u_int freq=eclockfreq*5/per;
1037 1.24 is
1038 1.24 is return freq;
1039 1.24 is }
1040 1.24 is
1041 1.24 is static void aucc_decode_slinear8_1ch (u_char **dmap, u_char *p, int i) {
1042 1.24 is memcpy (dmap[0], p, i);
1043 1.24 is }
1044 1.24 is
1045 1.24 is static void aucc_decode_slinear8_2ch (u_char **dmap, u_char *p, int i) {
1046 1.24 is u_char *ch0 = dmap[0];
1047 1.24 is u_char *ch1 = dmap[1];
1048 1.24 is
1049 1.24 is while (i--) {
1050 1.24 is *ch0++ = *p++;
1051 1.24 is *ch1++ = *p++;
1052 1.24 is }
1053 1.24 is }
1054 1.24 is
1055 1.24 is static void aucc_decode_slinear8_3ch (u_char **dmap, u_char *p, int i) {
1056 1.24 is u_char *ch0 = dmap[0];
1057 1.24 is u_char *ch1 = dmap[1];
1058 1.24 is u_char *ch2 = dmap[2];
1059 1.24 is
1060 1.24 is while (i--) {
1061 1.24 is *ch0++ = *p++;
1062 1.24 is *ch1++ = *p++;
1063 1.24 is *ch2++ = *p++;
1064 1.24 is }
1065 1.24 is }
1066 1.24 is
1067 1.24 is static void aucc_decode_slinear8_4ch (u_char **dmap, u_char *p, int i) {
1068 1.24 is u_char *ch0 = dmap[0];
1069 1.24 is u_char *ch1 = dmap[1];
1070 1.24 is u_char *ch2 = dmap[2];
1071 1.24 is u_char *ch3 = dmap[3];
1072 1.24 is
1073 1.24 is while (i--) {
1074 1.24 is *ch0++ = *p++;
1075 1.24 is *ch1++ = *p++;
1076 1.24 is *ch2++ = *p++;
1077 1.24 is *ch3++ = *p++;
1078 1.24 is }
1079 1.24 is }
1080 1.24 is
1081 1.24 is static void
1082 1.24 is aucc_decode_ulinear8_1ch (dmap, p, i)
1083 1.24 is u_char **dmap;
1084 1.24 is u_char *p;
1085 1.24 is int i;
1086 1.24 is {
1087 1.24 is u_char *ch0 = dmap[0];
1088 1.24 is
1089 1.24 is while (i--)
1090 1.24 is *ch0++ = *p++ - 128;
1091 1.24 is }
1092 1.24 is
1093 1.24 is static void
1094 1.24 is aucc_decode_ulinear8_2ch(dmap, p, i)
1095 1.24 is u_char **dmap;
1096 1.24 is u_char *p;
1097 1.24 is int i;
1098 1.1 is {
1099 1.24 is u_char *ch0 = dmap[0];
1100 1.24 is u_char *ch1 = dmap[1];
1101 1.24 is
1102 1.24 is while (i--) {
1103 1.24 is *ch0++ = *p++ - 128;
1104 1.24 is *ch1++ = *p++ - 128;
1105 1.24 is }
1106 1.24 is }
1107 1.24 is
1108 1.24 is static void
1109 1.24 is aucc_decode_ulinear8_3ch(dmap, p, i)
1110 1.24 is u_char **dmap;
1111 1.24 is u_char *p;
1112 1.24 is int i;
1113 1.24 is {
1114 1.24 is u_char *ch0 = dmap[0];
1115 1.24 is u_char *ch1 = dmap[1];
1116 1.24 is u_char *ch2 = dmap[2];
1117 1.24 is
1118 1.24 is while (i--) {
1119 1.24 is *ch0++ = *p++ - 128;
1120 1.24 is *ch1++ = *p++ - 128;
1121 1.24 is *ch2++ = *p++ - 128;
1122 1.24 is }
1123 1.24 is }
1124 1.24 is
1125 1.24 is static void
1126 1.24 is aucc_decode_ulinear8_4ch(dmap, p, i)
1127 1.24 is u_char **dmap;
1128 1.24 is u_char *p;
1129 1.24 is int i;
1130 1.24 is {
1131 1.24 is u_char *ch0 = dmap[0];
1132 1.24 is u_char *ch1 = dmap[1];
1133 1.24 is u_char *ch2 = dmap[2];
1134 1.24 is u_char *ch3 = dmap[3];
1135 1.24 is
1136 1.24 is while (i--) {
1137 1.24 is *ch0++ = *p++ - 128;
1138 1.24 is *ch1++ = *p++ - 128;
1139 1.24 is *ch2++ = *p++ - 128;
1140 1.24 is *ch3++ = *p++ - 128;
1141 1.24 is }
1142 1.24 is }
1143 1.24 is
1144 1.24 is
1145 1.24 is static void
1146 1.24 is aucc_decode_ulaw_1ch (dmap, p, i)
1147 1.24 is u_char **dmap;
1148 1.24 is u_char *p;
1149 1.24 is int i;
1150 1.24 is {
1151 1.24 is u_char *ch0 = dmap[0];
1152 1.24 is
1153 1.24 is while (i--)
1154 1.24 is *ch0++ = ulaw_to_lin[*p++];
1155 1.24 is }
1156 1.24 is
1157 1.24 is static void
1158 1.24 is aucc_decode_ulaw_2ch(dmap, p, i)
1159 1.24 is u_char **dmap;
1160 1.24 is u_char *p;
1161 1.24 is int i;
1162 1.24 is {
1163 1.24 is u_char *ch0 = dmap[0];
1164 1.24 is u_char *ch1 = dmap[1];
1165 1.24 is
1166 1.24 is while (i--) {
1167 1.24 is *ch0++ = ulaw_to_lin[*p++];
1168 1.24 is *ch1++ = ulaw_to_lin[*p++];
1169 1.24 is }
1170 1.24 is }
1171 1.1 is
1172 1.24 is static void
1173 1.24 is aucc_decode_ulaw_3ch(dmap, p, i)
1174 1.24 is u_char **dmap;
1175 1.24 is u_char *p;
1176 1.24 is int i;
1177 1.24 is {
1178 1.24 is u_char *ch0 = dmap[0];
1179 1.24 is u_char *ch1 = dmap[1];
1180 1.24 is u_char *ch2 = dmap[2];
1181 1.24 is
1182 1.24 is while (i--) {
1183 1.24 is *ch0++ = ulaw_to_lin[*p++];
1184 1.24 is *ch1++ = ulaw_to_lin[*p++];
1185 1.24 is *ch2++ = ulaw_to_lin[*p++];
1186 1.24 is }
1187 1.24 is }
1188 1.1 is
1189 1.24 is static void
1190 1.24 is aucc_decode_ulaw_4ch(dmap, p, i)
1191 1.24 is u_char **dmap;
1192 1.24 is u_char *p;
1193 1.24 is int i;
1194 1.24 is {
1195 1.24 is u_char *ch0 = dmap[0];
1196 1.24 is u_char *ch1 = dmap[1];
1197 1.24 is u_char *ch2 = dmap[2];
1198 1.24 is u_char *ch3 = dmap[3];
1199 1.24 is
1200 1.24 is while (i--) {
1201 1.24 is *ch0++ = ulaw_to_lin[*p++];
1202 1.24 is *ch1++ = ulaw_to_lin[*p++];
1203 1.24 is *ch2++ = ulaw_to_lin[*p++];
1204 1.24 is *ch3++ = ulaw_to_lin[*p++];
1205 1.24 is }
1206 1.1 is }
1207 1.1 is
1208 1.1 is
1209 1.24 is /* 14bit output */
1210 1.24 is static void
1211 1.24 is aucc_decode_slinear16_1ch(dmap, p, i)
1212 1.24 is u_char **dmap;
1213 1.24 is u_char *p;
1214 1.24 is int i;
1215 1.24 is {
1216 1.24 is u_char *ch0 = dmap[0];
1217 1.24 is u_char *ch3 = dmap[1]; /* XXX should be 3 */
1218 1.24 is
1219 1.24 is while (i--) {
1220 1.24 is *ch0++ = *p++;
1221 1.24 is *ch3++ = *p++ >> 2;
1222 1.24 is }
1223 1.24 is }
1224 1.1 is
1225 1.24 is /* 14bit stereo output */
1226 1.24 is static void
1227 1.24 is aucc_decode_slinear16_2ch(dmap, p, i)
1228 1.24 is u_char **dmap;
1229 1.24 is u_char *p;
1230 1.24 is int i;
1231 1.24 is {
1232 1.24 is u_char *ch0 = dmap[0];
1233 1.24 is u_char *ch1 = dmap[1];
1234 1.24 is u_char *ch2 = dmap[2];
1235 1.24 is u_char *ch3 = dmap[3];
1236 1.24 is
1237 1.24 is while (i--) {
1238 1.24 is *ch0++ = *p++;
1239 1.24 is *ch3++ = *p++ >> 2;
1240 1.24 is *ch1++ = *p++;
1241 1.24 is *ch2++ = *p++ >> 2;
1242 1.24 is }
1243 1.24 is }
1244 1.24 is
1245 1.24 is static void
1246 1.24 is aucc_decode_slinear16_3ch(dmap, p, i)
1247 1.24 is u_char **dmap;
1248 1.24 is u_char *p;
1249 1.24 is int i;
1250 1.24 is {
1251 1.24 is u_char *ch0 = dmap[0];
1252 1.24 is u_char *ch1 = dmap[1];
1253 1.24 is u_char *ch2 = dmap[2];
1254 1.24 is
1255 1.24 is while (i--) {
1256 1.24 is *ch0++ = *p++; p++;
1257 1.24 is *ch1++ = *p++; p++;
1258 1.24 is *ch2++ = *p++; p++;
1259 1.24 is }
1260 1.24 is }
1261 1.24 is
1262 1.24 is static void
1263 1.24 is aucc_decode_slinear16_4ch (dmap, p, i)
1264 1.24 is u_char **dmap;
1265 1.1 is u_char *p;
1266 1.24 is int i;
1267 1.1 is {
1268 1.24 is u_char *ch0 = dmap[0];
1269 1.24 is u_char *ch1 = dmap[1];
1270 1.24 is u_char *ch2 = dmap[2];
1271 1.24 is u_char *ch3 = dmap[3];
1272 1.24 is
1273 1.24 is while (i--) {
1274 1.24 is *ch0++ = *p++; p++;
1275 1.24 is *ch1++ = *p++; p++;
1276 1.24 is *ch2++ = *p++; p++;
1277 1.24 is *ch3++ = *p++; p++;
1278 1.24 is }
1279 1.24 is }
1280 1.8 is
1281 1.24 is /* 14bit output, swap bytes */
1282 1.24 is static void
1283 1.24 is aucc_decode_slinear16sw_1ch(dmap, p, i)
1284 1.24 is u_char **dmap;
1285 1.24 is u_char *p;
1286 1.24 is int i;
1287 1.24 is {
1288 1.24 is u_char *ch0 = dmap[0];
1289 1.26 mhitch u_char *ch3 = dmap[1]; /* XXX should be 3 */
1290 1.1 is
1291 1.24 is while (i--) {
1292 1.24 is *ch3++ = *p++ >> 2;
1293 1.24 is *ch0++ = *p++;
1294 1.24 is }
1295 1.24 is }
1296 1.1 is
1297 1.24 is static void
1298 1.24 is aucc_decode_slinear16sw_2ch(dmap, p, i)
1299 1.24 is u_char **dmap;
1300 1.24 is u_char *p;
1301 1.24 is int i;
1302 1.24 is {
1303 1.24 is u_char *ch0 = dmap[0];
1304 1.24 is u_char *ch1 = dmap[1];
1305 1.24 is u_char *ch2 = dmap[2];
1306 1.24 is u_char *ch3 = dmap[3];
1307 1.24 is
1308 1.24 is while (i--) {
1309 1.24 is *ch3++ = *p++ >> 2;
1310 1.24 is *ch0++ = *p++;
1311 1.24 is *ch2++ = *p++ >> 2;
1312 1.24 is *ch1++ = *p++;
1313 1.24 is }
1314 1.24 is }
1315 1.1 is
1316 1.24 is static void
1317 1.24 is aucc_decode_slinear16sw_3ch(dmap, p, i)
1318 1.24 is u_char **dmap;
1319 1.24 is u_char *p;
1320 1.24 is int i;
1321 1.24 is {
1322 1.24 is u_char *ch0 = dmap[0];
1323 1.24 is u_char *ch1 = dmap[1];
1324 1.24 is u_char *ch2 = dmap[2];
1325 1.24 is
1326 1.24 is while (i--) {
1327 1.24 is p++; *ch0++ = *p++;
1328 1.24 is p++; *ch1++ = *p++;
1329 1.24 is p++; *ch2++ = *p++;
1330 1.1 is }
1331 1.24 is }
1332 1.1 is
1333 1.24 is static void
1334 1.24 is aucc_decode_slinear16sw_4ch(dmap, p, i)
1335 1.24 is u_char **dmap;
1336 1.24 is u_char *p;
1337 1.24 is int i;
1338 1.24 is {
1339 1.24 is u_char *ch0 = dmap[0];
1340 1.24 is u_char *ch1 = dmap[1];
1341 1.24 is u_char *ch2 = dmap[2];
1342 1.24 is u_char *ch3 = dmap[3];
1343 1.24 is
1344 1.24 is while (i--) {
1345 1.24 is p++; *ch0++ = *p++;
1346 1.24 is p++; *ch1++ = *p++;
1347 1.24 is p++; *ch2++ = *p++;
1348 1.24 is p++; *ch3++ = *p++;
1349 1.24 is }
1350 1.1 is }
1351 1.24 is
1352 1.1 is
1353 1.1 is #endif /* NAUCC > 0 */
1354