sun.c revision 1.7 1 1.7 joerg /* $NetBSD: sun.c,v 1.7 2011/08/28 01:17:47 joerg Exp $ */
2 1.1 mrg
3 1.1 mrg /*
4 1.1 mrg * Copyright (c) 2002 Matthew R. Green
5 1.1 mrg * All rights reserved.
6 1.1 mrg *
7 1.1 mrg * Redistribution and use in source and binary forms, with or without
8 1.1 mrg * modification, are permitted provided that the following conditions
9 1.1 mrg * are met:
10 1.1 mrg * 1. Redistributions of source code must retain the above copyright
11 1.1 mrg * notice, this list of conditions and the following disclaimer.
12 1.1 mrg * 2. Redistributions in binary form must reproduce the above copyright
13 1.1 mrg * notice, this list of conditions and the following disclaimer in the
14 1.1 mrg * documentation and/or other materials provided with the distribution.
15 1.1 mrg *
16 1.1 mrg * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 1.1 mrg * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 1.1 mrg * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 1.1 mrg * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 1.1 mrg * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
21 1.1 mrg * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 1.1 mrg * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
23 1.1 mrg * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24 1.1 mrg * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 1.1 mrg * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 1.1 mrg * SUCH DAMAGE.
27 1.1 mrg */
28 1.1 mrg
29 1.1 mrg /*
30 1.1 mrg * XXX this is slightly icky in places...
31 1.1 mrg */
32 1.3 agc #include <sys/cdefs.h>
33 1.3 agc
34 1.3 agc #ifndef lint
35 1.7 joerg __RCSID("$NetBSD: sun.c,v 1.7 2011/08/28 01:17:47 joerg Exp $");
36 1.3 agc #endif
37 1.3 agc
38 1.1 mrg
39 1.1 mrg #include <sys/types.h>
40 1.1 mrg #include <sys/audioio.h>
41 1.1 mrg #include <sys/ioctl.h>
42 1.1 mrg #include <sys/time.h>
43 1.1 mrg
44 1.1 mrg #include <ctype.h>
45 1.1 mrg #include <err.h>
46 1.1 mrg #include <stdio.h>
47 1.1 mrg #include <stdlib.h>
48 1.1 mrg #include <string.h>
49 1.1 mrg
50 1.1 mrg #include "libaudio.h"
51 1.1 mrg
52 1.1 mrg /*
53 1.1 mrg * SunOS/NeXT .au format helpers
54 1.1 mrg */
55 1.7 joerg static const struct {
56 1.1 mrg int file_encoding;
57 1.1 mrg int encoding;
58 1.1 mrg int precision;
59 1.1 mrg } file2sw_encodings[] = {
60 1.1 mrg { AUDIO_FILE_ENCODING_MULAW_8, AUDIO_ENCODING_ULAW, 8 },
61 1.2 mrg { AUDIO_FILE_ENCODING_LINEAR_8, AUDIO_ENCODING_SLINEAR_BE, 8 },
62 1.2 mrg { AUDIO_FILE_ENCODING_LINEAR_16, AUDIO_ENCODING_SLINEAR_BE, 16 },
63 1.2 mrg { AUDIO_FILE_ENCODING_LINEAR_24, AUDIO_ENCODING_SLINEAR_BE, 24 },
64 1.2 mrg { AUDIO_FILE_ENCODING_LINEAR_32, AUDIO_ENCODING_SLINEAR_BE, 32 },
65 1.1 mrg #if 0
66 1.1 mrg /*
67 1.1 mrg * we should make some of these available. the, eg ultrasparc, port
68 1.1 mrg * can use the VIS instructions (if available) do do some of these
69 1.1 mrg * mpeg ones.
70 1.1 mrg */
71 1.1 mrg { AUDIO_FILE_ENCODING_FLOAT, AUDIO_ENCODING_ULAW, 32 },
72 1.1 mrg { AUDIO_FILE_ENCODING_DOUBLE, AUDIO_ENCODING_ULAW, 64 },
73 1.1 mrg { AUDIO_FILE_ENCODING_ADPCM_G721, AUDIO_ENCODING_ULAW, 4 },
74 1.1 mrg { AUDIO_FILE_ENCODING_ADPCM_G722, AUDIO_ENCODING_ULAW, 0 },
75 1.1 mrg { AUDIO_FILE_ENCODING_ADPCM_G723_3, AUDIO_ENCODING_ULAW, 3 },
76 1.1 mrg { AUDIO_FILE_ENCODING_ADPCM_G723_5, AUDIO_ENCODING_ULAW, 5 },
77 1.1 mrg #endif
78 1.1 mrg { AUDIO_FILE_ENCODING_ALAW_8, AUDIO_ENCODING_ALAW, 8 },
79 1.5 christos { -1, -1, -1 }
80 1.1 mrg };
81 1.1 mrg
82 1.1 mrg int
83 1.7 joerg audio_sun_to_encoding(int sun_encoding, u_int *encp, u_int *precp)
84 1.1 mrg {
85 1.1 mrg int i;
86 1.1 mrg
87 1.1 mrg for (i = 0; file2sw_encodings[i].file_encoding != -1; i++)
88 1.1 mrg if (file2sw_encodings[i].file_encoding == sun_encoding) {
89 1.1 mrg *precp = file2sw_encodings[i].precision;
90 1.1 mrg *encp = file2sw_encodings[i].encoding;
91 1.1 mrg return (0);
92 1.1 mrg }
93 1.1 mrg return (1);
94 1.1 mrg }
95 1.1 mrg
96 1.1 mrg int
97 1.7 joerg audio_encoding_to_sun(int encoding, int precision, int *sunep)
98 1.1 mrg {
99 1.1 mrg int i;
100 1.1 mrg
101 1.1 mrg for (i = 0; file2sw_encodings[i].file_encoding != -1; i++)
102 1.1 mrg if (file2sw_encodings[i].encoding == encoding &&
103 1.1 mrg file2sw_encodings[i].precision == precision) {
104 1.1 mrg *sunep = file2sw_encodings[i].file_encoding;
105 1.1 mrg return (0);
106 1.1 mrg }
107 1.1 mrg return (1);
108 1.1 mrg }
109