Sun Aug 28 01:17:48 2011 UTC ()
ANSIfy. Add static. Add __dead.


(joerg)
diff -r1.19 -r1.20 src/usr.bin/audio/common/audio.c
diff -r1.16 -r1.17 src/usr.bin/audio/common/libaudio.h
diff -r1.6 -r1.7 src/usr.bin/audio/common/sun.c
diff -r1.9 -r1.10 src/usr.bin/audio/common/wav.c
diff -r1.38 -r1.39 src/usr.bin/audio/ctl/ctl.c
diff -r1.53 -r1.54 src/usr.bin/audio/play/play.c
diff -r1.50 -r1.51 src/usr.bin/audio/record/record.c

cvs diff -r1.19 -r1.20 src/usr.bin/audio/common/audio.c (expand / switch to unified diff)

--- src/usr.bin/audio/common/audio.c 2008/05/29 14:51:27 1.19
+++ src/usr.bin/audio/common/audio.c 2011/08/28 01:17:47 1.20
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: audio.c,v 1.19 2008/05/29 14:51:27 mrg Exp $ */ 1/* $NetBSD: audio.c,v 1.20 2011/08/28 01:17:47 joerg Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1999 Matthew R. Green 4 * Copyright (c) 1999 Matthew R. Green
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
@@ -22,76 +22,75 @@ @@ -22,76 +22,75 @@
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
23 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 23 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE. 26 * SUCH DAMAGE.
27 */ 27 */
28 28
29/* 29/*
30 * XXX this is slightly icky in places... 30 * XXX this is slightly icky in places...
31 */ 31 */
32#include <sys/cdefs.h> 32#include <sys/cdefs.h>
33 33
34#ifndef lint 34#ifndef lint
35__RCSID("$NetBSD: audio.c,v 1.19 2008/05/29 14:51:27 mrg Exp $"); 35__RCSID("$NetBSD: audio.c,v 1.20 2011/08/28 01:17:47 joerg Exp $");
36#endif 36#endif
37 37
38 38
39#include <sys/types.h> 39#include <sys/types.h>
40#include <sys/audioio.h> 40#include <sys/audioio.h>
41#include <sys/ioctl.h> 41#include <sys/ioctl.h>
42#include <sys/time.h> 42#include <sys/time.h>
43 43
44#include <ctype.h> 44#include <ctype.h>
45#include <err.h> 45#include <err.h>
46#include <stdio.h> 46#include <stdio.h>
47#include <stdlib.h> 47#include <stdlib.h>
48#include <string.h> 48#include <string.h>
49 49
50#include "libaudio.h" 50#include "libaudio.h"
51 51
52/* what format am i? */ 52/* what format am i? */
53 53
54struct { 54static const struct {
55 const char *fname; 55 const char *fname;
56 int fno; 56 int fno;
57} formats[] = { 57} formats[] = {
58 { "sunau", AUDIO_FORMAT_SUN }, 58 { "sunau", AUDIO_FORMAT_SUN },
59 { "au", AUDIO_FORMAT_SUN }, 59 { "au", AUDIO_FORMAT_SUN },
60 { "sun", AUDIO_FORMAT_SUN }, 60 { "sun", AUDIO_FORMAT_SUN },
61 { "wav", AUDIO_FORMAT_WAV }, 61 { "wav", AUDIO_FORMAT_WAV },
62 { "wave", AUDIO_FORMAT_WAV }, 62 { "wave", AUDIO_FORMAT_WAV },
63 { "riff", AUDIO_FORMAT_WAV }, 63 { "riff", AUDIO_FORMAT_WAV },
64 { "no", AUDIO_FORMAT_NONE }, 64 { "no", AUDIO_FORMAT_NONE },
65 { "none", AUDIO_FORMAT_NONE }, 65 { "none", AUDIO_FORMAT_NONE },
66 { NULL, -1 } 66 { NULL, -1 }
67}; 67};
68 68
69int 69int
70audio_format_from_str(str) 70audio_format_from_str(char *str)
71 char *str; 
72{ 71{
73 int i; 72 int i;
74 73
75 for (i = 0; formats[i].fname; i++) 74 for (i = 0; formats[i].fname; i++)
76 if (strcasecmp(formats[i].fname, str) == 0) 75 if (strcasecmp(formats[i].fname, str) == 0)
77 break; 76 break;
78 return (formats[i].fno); 77 return (formats[i].fno);
79} 78}
80 79
81 80
82 81
83/* back and forth between encodings */ 82/* back and forth between encodings */
84struct { 83static const struct {
85 const char *ename; 84 const char *ename;
86 int eno; 85 int eno;
87} encs[] = { 86} encs[] = {
88 { AudioEmulaw, AUDIO_ENCODING_ULAW }, 87 { AudioEmulaw, AUDIO_ENCODING_ULAW },
89 { "ulaw", AUDIO_ENCODING_ULAW }, 88 { "ulaw", AUDIO_ENCODING_ULAW },
90 { AudioEalaw, AUDIO_ENCODING_ALAW }, 89 { AudioEalaw, AUDIO_ENCODING_ALAW },
91 { AudioEslinear, AUDIO_ENCODING_SLINEAR }, 90 { AudioEslinear, AUDIO_ENCODING_SLINEAR },
92 { "linear", AUDIO_ENCODING_SLINEAR }, 91 { "linear", AUDIO_ENCODING_SLINEAR },
93 { AudioEulinear, AUDIO_ENCODING_ULINEAR }, 92 { AudioEulinear, AUDIO_ENCODING_ULINEAR },
94 { AudioEadpcm, AUDIO_ENCODING_ADPCM }, 93 { AudioEadpcm, AUDIO_ENCODING_ADPCM },
95 { "ADPCM", AUDIO_ENCODING_ADPCM }, 94 { "ADPCM", AUDIO_ENCODING_ADPCM },
96 { AudioEslinear_le, AUDIO_ENCODING_SLINEAR_LE }, 95 { AudioEslinear_le, AUDIO_ENCODING_SLINEAR_LE },
97 { "linear_le", AUDIO_ENCODING_SLINEAR_LE }, 96 { "linear_le", AUDIO_ENCODING_SLINEAR_LE },
@@ -100,73 +99,67 @@ struct { @@ -100,73 +99,67 @@ struct {
100 { "linear_be", AUDIO_ENCODING_SLINEAR_BE }, 99 { "linear_be", AUDIO_ENCODING_SLINEAR_BE },
101 { AudioEulinear_be, AUDIO_ENCODING_ULINEAR_BE }, 100 { AudioEulinear_be, AUDIO_ENCODING_ULINEAR_BE },
102 { AudioEmpeg_l1_stream, AUDIO_ENCODING_MPEG_L1_STREAM }, 101 { AudioEmpeg_l1_stream, AUDIO_ENCODING_MPEG_L1_STREAM },
103 { AudioEmpeg_l1_packets,AUDIO_ENCODING_MPEG_L1_PACKETS }, 102 { AudioEmpeg_l1_packets,AUDIO_ENCODING_MPEG_L1_PACKETS },
104 { AudioEmpeg_l1_system, AUDIO_ENCODING_MPEG_L1_SYSTEM }, 103 { AudioEmpeg_l1_system, AUDIO_ENCODING_MPEG_L1_SYSTEM },
105 { AudioEmpeg_l2_stream, AUDIO_ENCODING_MPEG_L2_STREAM }, 104 { AudioEmpeg_l2_stream, AUDIO_ENCODING_MPEG_L2_STREAM },
106 { AudioEmpeg_l2_packets,AUDIO_ENCODING_MPEG_L2_PACKETS }, 105 { AudioEmpeg_l2_packets,AUDIO_ENCODING_MPEG_L2_PACKETS },
107 { AudioEmpeg_l2_system, AUDIO_ENCODING_MPEG_L2_SYSTEM }, 106 { AudioEmpeg_l2_system, AUDIO_ENCODING_MPEG_L2_SYSTEM },
108 { NULL, -1 } 107 { NULL, -1 }
109}; 108};
110 109
111 110
112const char * 111const char *
113audio_enc_from_val(val) 112audio_enc_from_val(int val)
114 int val; 
115{ 113{
116 int i; 114 int i;
117 115
118 for (i = 0; encs[i].ename; i++) 116 for (i = 0; encs[i].ename; i++)
119 if (encs[i].eno == val) 117 if (encs[i].eno == val)
120 break; 118 break;
121 return (encs[i].ename); 119 return (encs[i].ename);
122} 120}
123 121
124int 122int
125audio_enc_to_val(enc) 123audio_enc_to_val(const char *enc)
126 const char *enc; 
127{ 124{
128 int i; 125 int i;
129 126
130 for (i = 0; encs[i].ename; i++) 127 for (i = 0; encs[i].ename; i++)
131 if (strcmp(encs[i].ename, enc) == 0) 128 if (strcmp(encs[i].ename, enc) == 0)
132 break; 129 break;
133 if (encs[i].ename) 130 if (encs[i].ename)
134 return (encs[i].eno); 131 return (encs[i].eno);
135 else 132 else
136 return (AUDIO_ENOENT); 133 return (AUDIO_ENOENT);
137} 134}
138 135
139void 136void
140decode_int(arg, intp) 137decode_int(const char *arg, int *intp)
141 const char *arg; 
142 int *intp; 
143{ 138{
144 char *ep; 139 char *ep;
145 int ret; 140 int ret;
146 141
147 ret = (int)strtoul(arg, &ep, 10); 142 ret = (int)strtoul(arg, &ep, 10);
148 143
149 if (ep[0] == '\0') { 144 if (ep[0] == '\0') {
150 *intp = ret; 145 *intp = ret;
151 return; 146 return;
152 } 147 }
153 errx(1, "argument `%s' not a valid integer", arg); 148 errx(1, "argument `%s' not a valid integer", arg);
154} 149}
155 150
156void 151void
157decode_time(arg, tvp) 152decode_time(const char *arg, struct timeval *tvp)
158 const char *arg; 
159 struct timeval *tvp; 
160{ 153{
161 char *s, *colon, *dot; 154 char *s, *colon, *dot;
162 char *copy = strdup(arg); 155 char *copy = strdup(arg);
163 int first; 156 int first;
164 157
165 if (copy == NULL) 158 if (copy == NULL)
166 err(1, "could not allocate a copy of %s", arg); 159 err(1, "could not allocate a copy of %s", arg);
167 160
168 tvp->tv_sec = tvp->tv_usec = 0; 161 tvp->tv_sec = tvp->tv_usec = 0;
169 s = copy; 162 s = copy;
170  163
171 /* handle [hh:]mm:ss.dd */ 164 /* handle [hh:]mm:ss.dd */
172 if ((colon = strchr(s, ':')) != NULL) { 165 if ((colon = strchr(s, ':')) != NULL) {
@@ -196,49 +189,46 @@ decode_time(arg, tvp) @@ -196,49 +189,46 @@ decode_time(arg, tvp)
196 tvp->tv_usec += base * (dot[i] - '0'); 189 tvp->tv_usec += base * (dot[i] - '0');
197 } 190 }
198 } 191 }
199 decode_int(s, &first); 192 decode_int(s, &first);
200 tvp->tv_sec += first; 193 tvp->tv_sec += first;
201 194
202 free(copy); 195 free(copy);
203} 196}
204 197
205/* 198/*
206 * decode a string into an encoding value. 199 * decode a string into an encoding value.
207 */ 200 */
208void 201void
209decode_encoding(arg, encp) 202decode_encoding(const char *arg, int *encp)
210 const char *arg; 
211 int *encp; 
212{ 203{
213 size_t len; 204 size_t len;
214 int i; 205 int i;
215 206
216 len = strlen(arg); 207 len = strlen(arg);
217 for (i = 0; encs[i].ename; i++) 208 for (i = 0; encs[i].ename; i++)
218 if (strncmp(encs[i].ename, arg, len) == 0) { 209 if (strncmp(encs[i].ename, arg, len) == 0) {
219 *encp = encs[i].eno; 210 *encp = encs[i].eno;
220 return; 211 return;
221 } 212 }
222 errx(1, "unknown encoding `%s'", arg); 213 errx(1, "unknown encoding `%s'", arg);
223} 214}
224 215
225const char *const audio_errlist[] = { 216static const char *const audio_errlist[] = {
226 "error zero", /* nothing? */ 217 "error zero", /* nothing? */
227 "no audio entry", /* AUDIO_ENOENT */ 218 "no audio entry", /* AUDIO_ENOENT */
228 "short header", /* AUDIO_ESHORTHDR */ 219 "short header", /* AUDIO_ESHORTHDR */
229 "unsupported WAV format", /* AUDIO_EWAVUNSUPP */ 220 "unsupported WAV format", /* AUDIO_EWAVUNSUPP */
230 "bad (unsupported) WAV PCM format", /* AUDIO_EWAVBADPCM */ 221 "bad (unsupported) WAV PCM format", /* AUDIO_EWAVBADPCM */
231 "no WAV audio data", /* AUDIO_EWAVNODATA */ 222 "no WAV audio data", /* AUDIO_EWAVNODATA */
232 "internal error", /* AUDIO_EINTERNAL */ 223 "internal error", /* AUDIO_EINTERNAL */
233}; 224};
234 225
235const char * 226const char *
236audio_errstring(errval) 227audio_errstring(int errval)
237 int errval; 
238{ 228{
239 229
240 errval = -errval; 230 errval = -errval;
241 if (errval < 1 || errval > AUDIO_MAXERRNO) 231 if (errval < 1 || errval > AUDIO_MAXERRNO)
242 return "Invalid error"; 232 return "Invalid error";
243 return audio_errlist[errval]; 233 return audio_errlist[errval];
244} 234}

cvs diff -r1.16 -r1.17 src/usr.bin/audio/common/libaudio.h (expand / switch to unified diff)

--- src/usr.bin/audio/common/libaudio.h 2009/06/18 02:37:27 1.16
+++ src/usr.bin/audio/common/libaudio.h 2011/08/28 01:17:47 1.17
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: libaudio.h,v 1.16 2009/06/18 02:37:27 mrg Exp $ */ 1/* $NetBSD: libaudio.h,v 1.17 2011/08/28 01:17:47 joerg Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1999, 2009 Matthew R. Green 4 * Copyright (c) 1999, 2009 Matthew R. Green
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
@@ -149,26 +149,28 @@ typedef struct { @@ -149,26 +149,28 @@ typedef struct {
149} __packed wav_audioheaderfmt; 149} __packed wav_audioheaderfmt;
150 150
151typedef struct { 151typedef struct {
152 u_int16_t len; 152 u_int16_t len;
153 u_int16_t valid_bits; 153 u_int16_t valid_bits;
154 u_int32_t speaker_pos_mask; 154 u_int32_t speaker_pos_mask;
155 u_int16_t sub_tag; 155 u_int16_t sub_tag;
156 u_int8_t dummy[14]; 156 u_int8_t dummy[14];
157} __packed wav_audiohdrextensible; 157} __packed wav_audiohdrextensible;
158 158
159/* returns size of header, or -ve for failure */ 159/* returns size of header, or -ve for failure */
160ssize_t audio_wav_parse_hdr (void *, size_t, u_int *, u_int *, u_int *, u_int *, size_t *); 160ssize_t audio_wav_parse_hdr (void *, size_t, u_int *, u_int *, u_int *, u_int *, size_t *);
161 161
 162extern int verbose;
 163
162/* 164/*
163 * audio routine error codes 165 * audio routine error codes
164 */ 166 */
165#define AUDIO_ENOENT -1 /* no such audio format */ 167#define AUDIO_ENOENT -1 /* no such audio format */
166#define AUDIO_ESHORTHDR -2 /* short header */ 168#define AUDIO_ESHORTHDR -2 /* short header */
167#define AUDIO_EWAVUNSUPP -3 /* WAV: unsupported file */ 169#define AUDIO_EWAVUNSUPP -3 /* WAV: unsupported file */
168#define AUDIO_EWAVBADPCM -4 /* WAV: bad PCM bps */ 170#define AUDIO_EWAVBADPCM -4 /* WAV: bad PCM bps */
169#define AUDIO_EWAVNODATA -5 /* WAV: missing data */ 171#define AUDIO_EWAVNODATA -5 /* WAV: missing data */
170#define AUDIO_EINTERNAL -6 /* internal error */ 172#define AUDIO_EINTERNAL -6 /* internal error */
171 173
172#define AUDIO_MAXERRNO 5 174#define AUDIO_MAXERRNO 5
173 175
174/* and something to get a string associated with this error */ 176/* and something to get a string associated with this error */

cvs diff -r1.6 -r1.7 src/usr.bin/audio/common/sun.c (expand / switch to unified diff)

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

cvs diff -r1.9 -r1.10 src/usr.bin/audio/common/wav.c (expand / switch to unified diff)

--- src/usr.bin/audio/common/wav.c 2009/06/18 02:37:27 1.9
+++ src/usr.bin/audio/common/wav.c 2011/08/28 01:17:47 1.10
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: wav.c,v 1.9 2009/06/18 02:37:27 mrg Exp $ */ 1/* $NetBSD: wav.c,v 1.10 2011/08/28 01:17:47 joerg Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 2002, 2009 Matthew R. Green 4 * Copyright (c) 2002, 2009 Matthew R. Green
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
@@ -23,93 +23,85 @@ @@ -23,93 +23,85 @@
23 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 23 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE. 26 * SUCH DAMAGE.
27 */ 27 */
28 28
29/* 29/*
30 * WAV support for the audio tools; thanks go to the sox utility for 30 * WAV support for the audio tools; thanks go to the sox utility for
31 * clearing up issues with WAV files. 31 * clearing up issues with WAV files.
32 */ 32 */
33#include <sys/cdefs.h> 33#include <sys/cdefs.h>
34 34
35#ifndef lint 35#ifndef lint
36__RCSID("$NetBSD: wav.c,v 1.9 2009/06/18 02:37:27 mrg Exp $"); 36__RCSID("$NetBSD: wav.c,v 1.10 2011/08/28 01:17:47 joerg Exp $");
37#endif 37#endif
38 38
39 39
40#include <sys/types.h> 40#include <sys/types.h>
41#include <sys/audioio.h> 41#include <sys/audioio.h>
42#include <sys/ioctl.h> 42#include <sys/ioctl.h>
43#include <sys/time.h> 43#include <sys/time.h>
44 44
45#include <ctype.h> 45#include <ctype.h>
46#include <err.h> 46#include <err.h>
47#include <stdio.h> 47#include <stdio.h>
48#include <stdlib.h> 48#include <stdlib.h>
49#include <string.h> 49#include <string.h>
50#include <stdint.h> 50#include <stdint.h>
51 51
52#include "libaudio.h" 52#include "libaudio.h"
53 53
54struct { 54static const struct {
55 int wenc; 55 int wenc;
56 const char *wname; 56 const char *wname;
57} wavencs[] = { 57} wavencs[] = {
58 { WAVE_FORMAT_UNKNOWN, "Microsoft Official Unknown" }, 58 { WAVE_FORMAT_UNKNOWN, "Microsoft Official Unknown" },
59 { WAVE_FORMAT_PCM, "Microsoft PCM" }, 59 { WAVE_FORMAT_PCM, "Microsoft PCM" },
60 { WAVE_FORMAT_ADPCM, "Microsoft ADPCM" }, 60 { WAVE_FORMAT_ADPCM, "Microsoft ADPCM" },
61 { WAVE_FORMAT_ALAW, "Microsoft A-law" }, 61 { WAVE_FORMAT_ALAW, "Microsoft A-law" },
62 { WAVE_FORMAT_MULAW, "Microsoft mu-law" }, 62 { WAVE_FORMAT_MULAW, "Microsoft mu-law" },
63 { WAVE_FORMAT_OKI_ADPCM,"OKI ADPCM" }, 63 { WAVE_FORMAT_OKI_ADPCM,"OKI ADPCM" },
64 { WAVE_FORMAT_DIGISTD, "Digistd format" }, 64 { WAVE_FORMAT_DIGISTD, "Digistd format" },
65 { WAVE_FORMAT_DIGIFIX, "Digifix format" }, 65 { WAVE_FORMAT_DIGIFIX, "Digifix format" },
66 { -1, "?Unknown?" }, 66 { -1, "?Unknown?" },
67}; 67};
68 68
69const char * 69const char *
70wav_enc_from_val(int encoding) 70wav_enc_from_val(int encoding)
71{ 71{
72 int i; 72 int i;
73 73
74 for (i = 0; wavencs[i].wenc != -1; i++) 74 for (i = 0; wavencs[i].wenc != -1; i++)
75 if (wavencs[i].wenc == encoding) 75 if (wavencs[i].wenc == encoding)
76 break; 76 break;
77 return (wavencs[i].wname); 77 return (wavencs[i].wname);
78} 78}
79 79
80extern int verbose; 
81 
82/* 80/*
83 * sample header is: 81 * sample header is:
84 * 82 *
85 * RIFF\^@^C^@WAVEfmt ^P^@^@^@^A^@^B^@D<AC>^@^@^P<B1>^B^@^D^@^P^@data^@^@^C^@^@^@^@^@^@^@^@^@^@ 83 * RIFF\^@^C^@WAVEfmt ^P^@^@^@^A^@^B^@D<AC>^@^@^P<B1>^B^@^D^@^P^@data^@^@^C^@^@^@^@^@^@^@^@^@^@
86 * 84 *
87 */ 85 */
88/* 86/*
89 * WAV format helpers 87 * WAV format helpers
90 */ 88 */
91/* 89/*
92 * find a .wav header, etc. returns header length on success 90 * find a .wav header, etc. returns header length on success
93 */ 91 */
94ssize_t 92ssize_t
95audio_wav_parse_hdr(hdr, sz, enc, prec, sample, channels, datasize) 93audio_wav_parse_hdr(void *hdr, size_t sz, u_int *enc, u_int *prec,
96 void *hdr; 94 u_int *sample, u_int *channels, size_t *datasize)
97 size_t sz; 
98 u_int *enc; 
99 u_int *prec; 
100 u_int *sample; 
101 u_int *channels; 
102 size_t *datasize; 
103{ 95{
104 char *where = hdr, *owhere; 96 char *where = hdr, *owhere;
105 wav_audioheaderpart part; 97 wav_audioheaderpart part;
106 wav_audioheaderfmt fmt; 98 wav_audioheaderfmt fmt;
107 wav_audiohdrextensible ext; 99 wav_audiohdrextensible ext;
108 char *end = (((char *)hdr) + sz); 100 char *end = (((char *)hdr) + sz);
109 u_int newenc, newprec; 101 u_int newenc, newprec;
110 u_int16_t fmttag; 102 u_int16_t fmttag;
111 static const char 103 static const char
112 strfmt[4] = "fmt ", 104 strfmt[4] = "fmt ",
113 strRIFF[4] = "RIFF", 105 strRIFF[4] = "RIFF",
114 strWAVE[4] = "WAVE", 106 strWAVE[4] = "WAVE",
115 strdata[4] = "data"; 107 strdata[4] = "data";

cvs diff -r1.38 -r1.39 src/usr.bin/audio/ctl/ctl.c (expand / switch to unified diff)

--- src/usr.bin/audio/ctl/ctl.c 2009/04/11 10:43:09 1.38
+++ src/usr.bin/audio/ctl/ctl.c 2011/08/28 01:17:48 1.39
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: ctl.c,v 1.38 2009/04/11 10:43:09 lukem Exp $ */ 1/* $NetBSD: ctl.c,v 1.39 2011/08/28 01:17:48 joerg Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1997 The NetBSD Foundation, Inc. 4 * Copyright (c) 1997 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Lennart Augustsson (augustss@NetBSD.org). 8 * by Lennart Augustsson (augustss@NetBSD.org).
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -21,63 +21,62 @@ @@ -21,63 +21,62 @@
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE. 29 * POSSIBILITY OF SUCH DAMAGE.
30 */ 30 */
31#include <sys/cdefs.h> 31#include <sys/cdefs.h>
32 32
33#ifndef lint 33#ifndef lint
34__RCSID("$NetBSD: ctl.c,v 1.38 2009/04/11 10:43:09 lukem Exp $"); 34__RCSID("$NetBSD: ctl.c,v 1.39 2011/08/28 01:17:48 joerg Exp $");
35#endif 35#endif
36 36
37 37
38#include <sys/types.h> 38#include <sys/types.h>
39#include <sys/stat.h> 39#include <sys/stat.h>
40#include <sys/ioctl.h> 40#include <sys/ioctl.h>
41#include <sys/audioio.h> 41#include <sys/audioio.h>
42 42
43#include <err.h> 43#include <err.h>
44#include <fcntl.h> 44#include <fcntl.h>
45#include <stdio.h> 45#include <stdio.h>
46#include <stdlib.h> 46#include <stdlib.h>
47#include <string.h> 47#include <string.h>
48#include <unistd.h> 48#include <unistd.h>
49 49
50#include <paths.h> 50#include <paths.h>
51 51
52#include "libaudio.h" 52#include "libaudio.h"
53 53
54struct field *findfield (const char *name); 54static struct field *findfield(const char *name);
55void prfield (struct field *p, const char *sep); 55static void prfield(const struct field *p, const char *sep);
56void rdfield (struct field *p, char *q); 56static void rdfield(struct field *p, char *q);
57void getinfo (int fd); 57static void getinfo(int fd);
58void audioctl_write (int, int, char *[]); 58static void audioctl_write(int, int, char *[]);
59void usage (void); 59__dead static void usage(void);
60int main (int argc, char **argv); 
61 60
62audio_device_t adev; 61static audio_device_t adev;
63 62
64audio_info_t info; 63static audio_info_t info;
65 64
66char encbuf[1000]; 65static char encbuf[1000];
67 66
68int properties, fullduplex, rerror; 67static int properties, fullduplex, rerror;
69 68
70struct field { 69static struct field {
71 const char *name; 70 const char *name;
72 void *valp; 71 void *valp;
73 int format; 72 int format;
74#define STRING 1 73#define STRING 1
75#define INT 2 74#define INT 2
76#define UINT 3 75#define UINT 3
77#define P_R 4 76#define P_R 4
78#define ULONG 5 /* XXX obsolete now */ 77#define ULONG 5 /* XXX obsolete now */
79#define UCHAR 6 78#define UCHAR 6
80#define ENC 7 79#define ENC 7
81#define PROPS 8 80#define PROPS 8
82#define XINT 9 81#define XINT 9
83#define FORMAT 10 82#define FORMAT 10
@@ -130,79 +129,76 @@ struct field { @@ -130,79 +129,76 @@ struct field {
130 { "record.seek", &info.record.seek, UINT, READONLY }, 129 { "record.seek", &info.record.seek, UINT, READONLY },
131 { "record.samples", &info.record.samples, UINT, READONLY }, 130 { "record.samples", &info.record.samples, UINT, READONLY },
132 { "record.eof", &info.record.eof, UINT, READONLY }, 131 { "record.eof", &info.record.eof, UINT, READONLY },
133 { "record.pause", &info.record.pause, UCHAR, 0 }, 132 { "record.pause", &info.record.pause, UCHAR, 0 },
134 { "record.error", &info.record.error, UCHAR, READONLY }, 133 { "record.error", &info.record.error, UCHAR, READONLY },
135 { "record.waiting", &info.record.waiting, UCHAR, READONLY }, 134 { "record.waiting", &info.record.waiting, UCHAR, READONLY },
136 { "record.open", &info.record.open, UCHAR, READONLY }, 135 { "record.open", &info.record.open, UCHAR, READONLY },
137 { "record.active", &info.record.active, UCHAR, READONLY }, 136 { "record.active", &info.record.active, UCHAR, READONLY },
138 { "record.buffer_size", &info.record.buffer_size,UINT, 0 }, 137 { "record.buffer_size", &info.record.buffer_size,UINT, 0 },
139 { "record.errors", &rerror, INT, READONLY }, 138 { "record.errors", &rerror, INT, READONLY },
140 { .name = NULL }, 139 { .name = NULL },
141}; 140};
142 141
143static struct { 142static const struct {
144 const char *name; 143 const char *name;
145 u_int prop; 144 u_int prop;
146} props[] = { 145} props[] = {
147 { "full_duplex", AUDIO_PROP_FULLDUPLEX }, 146 { "full_duplex", AUDIO_PROP_FULLDUPLEX },
148 { "mmap", AUDIO_PROP_MMAP }, 147 { "mmap", AUDIO_PROP_MMAP },
149 { "independent", AUDIO_PROP_INDEPENDENT }, 148 { "independent", AUDIO_PROP_INDEPENDENT },
150 { .name = NULL }, 149 { .name = NULL },
151}; 150};
152 151
153struct field * 152static struct field *
154findfield(name) 153findfield(const char *name)
155 const char *name; 
156{ 154{
157 int i; 155 int i;
158 for (i = 0; fields[i].name; i++) 156 for (i = 0; fields[i].name; i++)
159 if (strcmp(fields[i].name, name) == 0) 157 if (strcmp(fields[i].name, name) == 0)
160 return &fields[i]; 158 return &fields[i];
161 return 0; 159 return 0;
162} 160}
163 161
164void 162static void
165prfield(p, sep) 163prfield(const struct field *p, const char *sep)
166 struct field *p; 
167 const char *sep; 
168{ 164{
169 u_int v; 165 u_int v;
170 const char *cm, *encstr; 166 const char *cm, *encstr;
171 int i; 167 int i;
172 168
173 if (sep) 169 if (sep)
174 printf("%s%s", p->name, sep); 170 printf("%s%s", p->name, sep);
175 switch(p->format) { 171 switch(p->format) {
176 case STRING: 172 case STRING:
177 printf("%s", (char*)p->valp); 173 printf("%s", (const char*)p->valp);
178 break; 174 break;
179 case INT: 175 case INT:
180 printf("%d", *(int*)p->valp); 176 printf("%d", *(const int*)p->valp);
181 break; 177 break;
182 case UINT: 178 case UINT:
183 printf("%u", *(u_int*)p->valp); 179 printf("%u", *(const u_int*)p->valp);
184 break; 180 break;
185 case XINT: 181 case XINT:
186 printf("0x%x", *(u_int*)p->valp); 182 printf("0x%x", *(const u_int*)p->valp);
187 break; 183 break;
188 case UCHAR: 184 case UCHAR:
189 printf("%u", *(u_char*)p->valp); 185 printf("%u", *(const u_char*)p->valp);
190 break; 186 break;
191 case ULONG: 187 case ULONG:
192 printf("%lu", *(u_long*)p->valp); 188 printf("%lu", *(const u_long*)p->valp);
193 break; 189 break;
194 case P_R: 190 case P_R:
195 v = *(u_int*)p->valp; 191 v = *(const u_int*)p->valp;
196 cm = ""; 192 cm = "";
197 if (v & AUMODE_PLAY) { 193 if (v & AUMODE_PLAY) {
198 if (v & AUMODE_PLAY_ALL) 194 if (v & AUMODE_PLAY_ALL)
199 printf("play"); 195 printf("play");
200 else 196 else
201 printf("playsync"); 197 printf("playsync");
202 cm = ","; 198 cm = ",";
203 } 199 }
204 if (v & AUMODE_RECORD) 200 if (v & AUMODE_RECORD)
205 printf("%srecord", cm); 201 printf("%srecord", cm);
206 break; 202 break;
207 case ENC: 203 case ENC:
208 v = *(u_int*)p->valp; 204 v = *(u_int*)p->valp;
@@ -225,30 +221,28 @@ prfield(p, sep) @@ -225,30 +221,28 @@ prfield(p, sep)
225 prfield(p + 1, 0); 221 prfield(p + 1, 0);
226 printf(","); 222 printf(",");
227 prfield(p + 3, 0); 223 prfield(p + 3, 0);
228 printf(","); 224 printf(",");
229 prfield(p + 4, 0); 225 prfield(p + 4, 0);
230 printf(","); 226 printf(",");
231 prfield(p + 5, 0); 227 prfield(p + 5, 0);
232 break; 228 break;
233 default: 229 default:
234 errx(1, "Invalid print format."); 230 errx(1, "Invalid print format.");
235 } 231 }
236} 232}
237 233
238void 234static void
239rdfield(p, q) 235rdfield(struct field *p, char *q)
240 struct field *p; 
241 char *q; 
242{ 236{
243 int enc; 237 int enc;
244 u_int u; 238 u_int u;
245 char *s; 239 char *s;
246 240
247 switch(p->format) { 241 switch(p->format) {
248 case UINT: 242 case UINT:
249 if (sscanf(q, "%u", (unsigned int *)p->valp) != 1) 243 if (sscanf(q, "%u", (unsigned int *)p->valp) != 1)
250 errx(1, "Bad number: %s", q); 244 errx(1, "Bad number: %s", q);
251 break; 245 break;
252 case UCHAR: 246 case UCHAR:
253 if (sscanf(q, "%u", &u) != 1) 247 if (sscanf(q, "%u", &u) != 1)
254 errx(1, "Bad number: %s", q); 248 errx(1, "Bad number: %s", q);
@@ -279,29 +273,28 @@ rdfield(p, q) @@ -279,29 +273,28 @@ rdfield(p, q)
279 rdfield(p + 4, s); 273 rdfield(p + 4, s);
280 s = strsep(&q, ","); 274 s = strsep(&q, ",");
281 if (s) 275 if (s)
282 rdfield(p + 5, s); 276 rdfield(p + 5, s);
283 if (!s || q) 277 if (!s || q)
284 errx(1, "Bad format"); 278 errx(1, "Bad format");
285 break; 279 break;
286 default: 280 default:
287 errx(1, "Invalid read format."); 281 errx(1, "Invalid read format.");
288 } 282 }
289 p->flags |= SET; 283 p->flags |= SET;
290} 284}
291 285
292void 286static void
293getinfo(fd) 287getinfo(int fd)
294 int fd; 
295{ 288{
296 int pos, i; 289 int pos, i;
297 290
298 if (ioctl(fd, AUDIO_GETDEV, &adev) < 0) 291 if (ioctl(fd, AUDIO_GETDEV, &adev) < 0)
299 err(1, "AUDIO_GETDEV"); 292 err(1, "AUDIO_GETDEV");
300 for (pos = 0, i = 0; ; i++) { 293 for (pos = 0, i = 0; ; i++) {
301 audio_encoding_t enc; 294 audio_encoding_t enc;
302 enc.index = i; 295 enc.index = i;
303 if (ioctl(fd, AUDIO_GETENC, &enc) < 0) 296 if (ioctl(fd, AUDIO_GETENC, &enc) < 0)
304 break; 297 break;
305 if (pos >= (int)sizeof(encbuf)-1) 298 if (pos >= (int)sizeof(encbuf)-1)
306 break; 299 break;
307 if (pos) 300 if (pos)
@@ -312,41 +305,39 @@ getinfo(fd) @@ -312,41 +305,39 @@ getinfo(fd)
312 enc.name, enc.precision, 305 enc.name, enc.precision,
313 enc.flags & AUDIO_ENCODINGFLAG_EMULATED ? "*" : ""); 306 enc.flags & AUDIO_ENCODINGFLAG_EMULATED ? "*" : "");
314 } 307 }
315 if (ioctl(fd, AUDIO_GETFD, &fullduplex) < 0) 308 if (ioctl(fd, AUDIO_GETFD, &fullduplex) < 0)
316 err(1, "AUDIO_GETFD"); 309 err(1, "AUDIO_GETFD");
317 if (ioctl(fd, AUDIO_GETPROPS, &properties) < 0) 310 if (ioctl(fd, AUDIO_GETPROPS, &properties) < 0)
318 err(1, "AUDIO_GETPROPS"); 311 err(1, "AUDIO_GETPROPS");
319 if (ioctl(fd, AUDIO_RERROR, &rerror) < 0) 312 if (ioctl(fd, AUDIO_RERROR, &rerror) < 0)
320 err(1, "AUDIO_RERROR"); 313 err(1, "AUDIO_RERROR");
321 if (ioctl(fd, AUDIO_GETINFO, &info) < 0) 314 if (ioctl(fd, AUDIO_GETINFO, &info) < 0)
322 err(1, "AUDIO_GETINFO"); 315 err(1, "AUDIO_GETINFO");
323} 316}
324 317
325void 318static void
326usage() 319usage(void)
327{ 320{
328 const char *prog = getprogname(); 321 const char *prog = getprogname();
329 322
330 fprintf(stderr, "Usage: %s [-d file] [-n] name ...\n", prog); 323 fprintf(stderr, "Usage: %s [-d file] [-n] name ...\n", prog);
331 fprintf(stderr, "Usage: %s [-d file] [-n] -w name=value ...\n", prog); 324 fprintf(stderr, "Usage: %s [-d file] [-n] -w name=value ...\n", prog);
332 fprintf(stderr, "Usage: %s [-d file] [-n] -a\n", prog); 325 fprintf(stderr, "Usage: %s [-d file] [-n] -a\n", prog);
333 exit(1); 326 exit(1);
334} 327}
335 328
336int 329int
337main(argc, argv) 330main(int argc, char *argv[])
338 int argc; 
339 char **argv; 
340{ 331{
341 int fd, i, ch; 332 int fd, i, ch;
342 int aflag = 0, wflag = 0; 333 int aflag = 0, wflag = 0;
343 const char *deffile = _PATH_AUDIOCTL; 334 const char *deffile = _PATH_AUDIOCTL;
344 const char *file; 335 const char *file;
345 const char *sep = "="; 336 const char *sep = "=";
346 337
347 file = getenv("AUDIOCTLDEVICE"); 338 file = getenv("AUDIOCTLDEVICE");
348 if (file == NULL) 339 if (file == NULL)
349 file = deffile; 340 file = deffile;
350 341
351 while ((ch = getopt(argc, argv, "ad:f:nw")) != -1) { 342 while ((ch = getopt(argc, argv, "ad:f:nw")) != -1) {
352 switch(ch) { 343 switch(ch) {
@@ -418,31 +409,28 @@ main(argc, argv) @@ -418,31 +409,28 @@ main(argc, argv)
418 warnx("field %s does not exist", *argv); 409 warnx("field %s does not exist", *argv);
419 } else { 410 } else {
420 prfield(p, sep); 411 prfield(p, sep);
421 printf("\n"); 412 printf("\n");
422 } 413 }
423 argv++; 414 argv++;
424 } 415 }
425 } 416 }
426 } else 417 } else
427 usage(); 418 usage();
428 exit(0); 419 exit(0);
429} 420}
430 421
431void 422static void
432audioctl_write(fd, argc, argv) 423audioctl_write(int fd, int argc, char *argv[])
433 int fd; 
434 int argc; 
435 char *argv[]; 
436{ 424{
437 struct field *p; 425 struct field *p;
438 426
439 AUDIO_INITINFO(&info); 427 AUDIO_INITINFO(&info);
440 while (argc--) { 428 while (argc--) {
441 char *q; 429 char *q;
442 430
443 q = strchr(*argv, '='); 431 q = strchr(*argv, '=');
444 if (q) { 432 if (q) {
445 *q++ = 0; 433 *q++ = 0;
446 p = findfield(*argv); 434 p = findfield(*argv);
447 if (p == 0) 435 if (p == 0)
448 warnx("field `%s' does not exist", *argv); 436 warnx("field `%s' does not exist", *argv);

cvs diff -r1.53 -r1.54 src/usr.bin/audio/play/play.c (expand / switch to unified diff)

--- src/usr.bin/audio/play/play.c 2010/12/29 18:48:40 1.53
+++ src/usr.bin/audio/play/play.c 2011/08/28 01:17:48 1.54
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: play.c,v 1.53 2010/12/29 18:48:40 wiz Exp $ */ 1/* $NetBSD: play.c,v 1.54 2011/08/28 01:17:48 joerg Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1999, 2000, 2001, 2002, 2010 Matthew R. Green 4 * Copyright (c) 1999, 2000, 2001, 2002, 2010 Matthew R. Green
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
@@ -18,78 +18,75 @@ @@ -18,78 +18,75 @@
18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
21 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 21 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
23 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 23 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE. 26 * SUCH DAMAGE.
27 */ 27 */
28#include <sys/cdefs.h> 28#include <sys/cdefs.h>
29 29
30#ifndef lint 30#ifndef lint
31__RCSID("$NetBSD: play.c,v 1.53 2010/12/29 18:48:40 wiz Exp $"); 31__RCSID("$NetBSD: play.c,v 1.54 2011/08/28 01:17:48 joerg Exp $");
32#endif 32#endif
33 33
34 34
35#include <sys/param.h> 35#include <sys/param.h>
36#include <sys/audioio.h> 36#include <sys/audioio.h>
37#include <sys/ioctl.h> 37#include <sys/ioctl.h>
38#include <sys/mman.h> 38#include <sys/mman.h>
39#include <sys/stat.h> 39#include <sys/stat.h>
40 40
41#include <err.h> 41#include <err.h>
42#include <fcntl.h> 42#include <fcntl.h>
43#include <signal.h> 43#include <signal.h>
44#include <stdio.h> 44#include <stdio.h>
45#include <stdlib.h> 45#include <stdlib.h>
46#include <string.h> 46#include <string.h>
47#include <unistd.h> 47#include <unistd.h>
48#include <util.h> 48#include <util.h>
49 49
50#include <paths.h> 50#include <paths.h>
51 51
52#include "libaudio.h" 52#include "libaudio.h"
53 53
54int main(int, char *[]); 54static void usage(void) __dead;
55void usage(void); 55static void play(char *);
56void play(char *); 56static void play_fd(const char *, int);
57void play_fd(const char *, int); 57static ssize_t audioctl_write_fromhdr(void *, size_t, int, size_t *, const char *);
58ssize_t audioctl_write_fromhdr(void *, size_t, int, size_t *, const char *); 58static void cleanup(int) __dead;
59void cleanup(int) __dead; 59
60 60static audio_info_t info;
61audio_info_t info; 61static int volume;
62int volume; 62static int balance;
63int balance; 63static int port;
64int port; 64static int fflag;
65int fflag; 65static int qflag;
66int qflag; 
67int verbose; 66int verbose;
68int sample_rate; 67static int sample_rate;
69int encoding; 68static int encoding;
70char *encoding_str; 69static char *encoding_str;
71int precision; 70static int precision;
72int channels; 71static int channels;
73 72
74char const *play_errstring = NULL; 73static char const *play_errstring = NULL;
75size_t bufsize; 74static size_t bufsize;
76int audiofd; 75static int audiofd;
77int exitstatus = EXIT_SUCCESS; 76static int exitstatus = EXIT_SUCCESS;
78 77
79int 78int
80main(argc, argv) 79main(int argc, char *argv[])
81 int argc; 
82 char *argv[]; 
83{ 80{
84 size_t len; 81 size_t len;
85 int ch; 82 int ch;
86 int iflag = 0; 83 int iflag = 0;
87 const char *defdevice = _PATH_SOUND; 84 const char *defdevice = _PATH_SOUND;
88 const char *device = NULL; 85 const char *device = NULL;
89 86
90 while ((ch = getopt(argc, argv, "b:B:C:c:d:e:fhip:P:qs:Vv:")) != -1) { 87 while ((ch = getopt(argc, argv, "b:B:C:c:d:e:fhip:P:qs:Vv:")) != -1) {
91 switch (ch) { 88 switch (ch) {
92 case 'b': 89 case 'b':
93 decode_int(optarg, &balance); 90 decode_int(optarg, &balance);
94 if (balance < 0 || balance > 64) 91 if (balance < 0 || balance > 64)
95 errx(1, "balance must be between 0 and 63"); 92 errx(1, "balance must be between 0 and 63");
@@ -194,43 +191,41 @@ main(argc, argv) @@ -194,43 +191,41 @@ main(argc, argv)
194 signal(SIGTERM, cleanup); 191 signal(SIGTERM, cleanup);
195 signal(SIGHUP, cleanup); 192 signal(SIGHUP, cleanup);
196 193
197 if (*argv) 194 if (*argv)
198 do 195 do
199 play(*argv++); 196 play(*argv++);
200 while (*argv); 197 while (*argv);
201 else 198 else
202 play_fd("standard input", STDIN_FILENO); 199 play_fd("standard input", STDIN_FILENO);
203 200
204 cleanup(0); 201 cleanup(0);
205} 202}
206 203
207void 204static void
208cleanup(signo) 205cleanup(int signo)
209 int signo; 
210{ 206{
211 207
212 (void)ioctl(audiofd, AUDIO_FLUSH, NULL); 208 (void)ioctl(audiofd, AUDIO_FLUSH, NULL);
213 (void)ioctl(audiofd, AUDIO_SETINFO, &info); 209 (void)ioctl(audiofd, AUDIO_SETINFO, &info);
214 close(audiofd); 210 close(audiofd);
215 if (signo != 0) { 211 if (signo != 0) {
216 (void)raise_default_signal(signo); 212 (void)raise_default_signal(signo);
217 } 213 }
218 exit(exitstatus); 214 exit(exitstatus);
219} 215}
220 216
221void 217static void
222play(file) 218play(char *file)
223 char *file; 
224{ 219{
225 struct stat sb; 220 struct stat sb;
226 void *addr, *oaddr; 221 void *addr, *oaddr;
227 off_t filesize; 222 off_t filesize;
228 size_t sizet_filesize; 223 size_t sizet_filesize;
229 size_t datasize = 0; 224 size_t datasize = 0;
230 ssize_t hdrlen; 225 ssize_t hdrlen;
231 int fd; 226 int fd;
232 227
233 if (file[0] == '-' && file[1] == 0) { 228 if (file[0] == '-' && file[1] == 0) {
234 play_fd("standard input", STDIN_FILENO); 229 play_fd("standard input", STDIN_FILENO);
235 return; 230 return;
236 } 231 }
@@ -297,30 +292,28 @@ play(file) @@ -297,30 +292,28 @@ play(file)
297 err(1, "final write failed"); 292 err(1, "final write failed");
298 293
299 if (ioctl(audiofd, AUDIO_DRAIN) < 0 && !qflag) 294 if (ioctl(audiofd, AUDIO_DRAIN) < 0 && !qflag)
300 warn("audio drain ioctl failed"); 295 warn("audio drain ioctl failed");
301 if (munmap(oaddr, sizet_filesize) < 0) 296 if (munmap(oaddr, sizet_filesize) < 0)
302 err(1, "munmap failed"); 297 err(1, "munmap failed");
303 298
304 close(fd); 299 close(fd);
305} 300}
306 301
307/* 302/*
308 * play the file on the file descriptor fd 303 * play the file on the file descriptor fd
309 */ 304 */
310void 305static void
311play_fd(file, fd) 306play_fd(const char *file, int fd)
312 const char *file; 
313 int fd; 
314{ 307{
315 char *buffer = malloc(bufsize); 308 char *buffer = malloc(bufsize);
316 ssize_t hdrlen; 309 ssize_t hdrlen;
317 int nr, nw; 310 int nr, nw;
318 size_t datasize = 0; 311 size_t datasize = 0;
319 size_t dataout = 0; 312 size_t dataout = 0;
320 313
321 if (buffer == NULL) 314 if (buffer == NULL)
322 err(1, "malloc of read buffer failed"); 315 err(1, "malloc of read buffer failed");
323 316
324 nr = read(fd, buffer, bufsize); 317 nr = read(fd, buffer, bufsize);
325 if (nr < 0) 318 if (nr < 0)
326 goto read_error; 319 goto read_error;
@@ -363,33 +356,28 @@ play_fd(file, fd) @@ -363,33 +356,28 @@ play_fd(file, fd)
363 return; 356 return;
364read_error: 357read_error:
365 err(1, "read of standard input failed"); 358 err(1, "read of standard input failed");
366write_error: 359write_error:
367 err(1, "audio device write failed"); 360 err(1, "audio device write failed");
368} 361}
369 362
370/* 363/*
371 * only support sun and wav audio files so far ... 364 * only support sun and wav audio files so far ...
372 * 365 *
373 * XXX this should probably be mostly part of libaudio, but it 366 * XXX this should probably be mostly part of libaudio, but it
374 * uses the local "info" variable. blah... fix me! 367 * uses the local "info" variable. blah... fix me!
375 */ 368 */
376ssize_t 369static ssize_t
377audioctl_write_fromhdr(hdr, fsz, fd, datasize, file) 370audioctl_write_fromhdr(void *hdr, size_t fsz, int fd, size_t *datasize, const char *file)
378 void *hdr; 
379 size_t fsz; 
380 int fd; 
381 size_t *datasize; 
382 const char *file; 
383{ 371{
384 sun_audioheader *sunhdr; 372 sun_audioheader *sunhdr;
385 ssize_t hdr_len = 0; 373 ssize_t hdr_len = 0;
386 374
387 AUDIO_INITINFO(&info); 375 AUDIO_INITINFO(&info);
388 sunhdr = hdr; 376 sunhdr = hdr;
389 if (ntohl(sunhdr->magic) == AUDIO_FILE_MAGIC) { 377 if (ntohl(sunhdr->magic) == AUDIO_FILE_MAGIC) {
390 if (audio_sun_to_encoding(ntohl(sunhdr->encoding), 378 if (audio_sun_to_encoding(ntohl(sunhdr->encoding),
391 &info.play.encoding, &info.play.precision)) { 379 &info.play.encoding, &info.play.precision)) {
392 if (!qflag) 380 if (!qflag)
393 warnx("unknown unsupported Sun audio encoding" 381 warnx("unknown unsupported Sun audio encoding"
394 " format %d", ntohl(sunhdr->encoding)); 382 " format %d", ntohl(sunhdr->encoding));
395 if (fflag) 383 if (fflag)
@@ -458,28 +446,28 @@ set_audio_mode: @@ -458,28 +446,28 @@ set_audio_mode:
458 info.play.channels, 446 info.play.channels,
459 (long long)*datasize, 447 (long long)*datasize,
460 info.play.precision, 448 info.play.precision,
461 enc ? " encoding=" : "",  449 enc ? " encoding=" : "",
462 enc ? enc : ""); 450 enc ? enc : "");
463 } 451 }
464 452
465 if (ioctl(fd, AUDIO_SETINFO, &info) < 0) 453 if (ioctl(fd, AUDIO_SETINFO, &info) < 0)
466 err(1, "failed to set audio info"); 454 err(1, "failed to set audio info");
467 455
468 return (hdr_len); 456 return (hdr_len);
469} 457}
470 458
471void 459static void
472usage() 460usage(void)
473{ 461{
474 462
475 fprintf(stderr, "Usage: %s [-hiqV] [options] files\n", getprogname()); 463 fprintf(stderr, "Usage: %s [-hiqV] [options] files\n", getprogname());
476 fprintf(stderr, "Options:\n\t" 464 fprintf(stderr, "Options:\n\t"
477 "-B buffer size\n\t" 465 "-B buffer size\n\t"
478 "-b balance (0-63)\n\t" 466 "-b balance (0-63)\n\t"
479 "-d audio device\n\t" 467 "-d audio device\n\t"
480 "-f force settings\n\t" 468 "-f force settings\n\t"
481 "\t-c forced channels\n\t" 469 "\t-c forced channels\n\t"
482 "\t-e forced encoding\n\t" 470 "\t-e forced encoding\n\t"
483 "\t-P forced precision\n\t" 471 "\t-P forced precision\n\t"
484 "\t-s forced sample rate\n\t" 472 "\t-s forced sample rate\n\t"
485 "-i header information\n\t" 473 "-i header information\n\t"

cvs diff -r1.50 -r1.51 src/usr.bin/audio/record/record.c (expand / switch to unified diff)

--- src/usr.bin/audio/record/record.c 2010/12/29 18:49:41 1.50
+++ src/usr.bin/audio/record/record.c 2011/08/28 01:17:48 1.51
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: record.c,v 1.50 2010/12/29 18:49:41 wiz Exp $ */ 1/* $NetBSD: record.c,v 1.51 2011/08/28 01:17:48 joerg Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1999, 2002, 2003, 2005, 2010 Matthew R. Green 4 * Copyright (c) 1999, 2002, 2003, 2005, 2010 Matthew R. Green
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
@@ -22,85 +22,82 @@ @@ -22,85 +22,82 @@
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
23 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 23 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE. 26 * SUCH DAMAGE.
27 */ 27 */
28 28
29/* 29/*
30 * SunOS compatible audiorecord(1) 30 * SunOS compatible audiorecord(1)
31 */ 31 */
32#include <sys/cdefs.h> 32#include <sys/cdefs.h>
33 33
34#ifndef lint 34#ifndef lint
35__RCSID("$NetBSD: record.c,v 1.50 2010/12/29 18:49:41 wiz Exp $"); 35__RCSID("$NetBSD: record.c,v 1.51 2011/08/28 01:17:48 joerg Exp $");
36#endif 36#endif
37 37
38 38
39#include <sys/param.h> 39#include <sys/param.h>
40#include <sys/audioio.h> 40#include <sys/audioio.h>
41#include <sys/ioctl.h> 41#include <sys/ioctl.h>
42#include <sys/time.h> 42#include <sys/time.h>
43#include <sys/uio.h> 43#include <sys/uio.h>
44 44
45#include <err.h> 45#include <err.h>
46#include <fcntl.h> 46#include <fcntl.h>
47#include <paths.h> 47#include <paths.h>
48#include <signal.h> 48#include <signal.h>
49#include <stdio.h> 49#include <stdio.h>
50#include <stdlib.h> 50#include <stdlib.h>
51#include <string.h> 51#include <string.h>
52#include <unistd.h> 52#include <unistd.h>
53#include <util.h> 53#include <util.h>
54 54
55#include "libaudio.h" 55#include "libaudio.h"
56#include "auconv.h" 56#include "auconv.h"
57 57
58audio_info_t info, oinfo; 58static audio_info_t info, oinfo;
59ssize_t total_size = -1; 59static ssize_t total_size = -1;
60const char *device; 60static const char *device;
61int format = AUDIO_FORMAT_DEFAULT; 61static int format = AUDIO_FORMAT_DEFAULT;
62char *header_info; 62static char *header_info;
63char default_info[8] = { '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0' }; 63static char default_info[8] = { '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0' };
64int audiofd, outfd; 64static int audiofd, outfd;
65int qflag, aflag, fflag; 65static int qflag, aflag, fflag;
66int verbose; 66int verbose;
67int monitor_gain, omonitor_gain; 67static int monitor_gain, omonitor_gain;
68int gain; 68static int gain;
69int balance; 69static int balance;
70int port; 70static int port;
71int encoding; 71static int encoding;
72char *encoding_str; 72static char *encoding_str;
73int precision; 73static int precision;
74int sample_rate; 74static int sample_rate;
75int channels; 75static int channels;
76struct timeval record_time; 76static struct timeval record_time;
77struct timeval start_time; 77static struct timeval start_time;
78 78
79void (*conv_func) (u_char *, int); 79static void (*conv_func) (u_char *, int);
80 80
81void usage (void); 81static void usage (void) __dead;
82int main (int, char *[]); 82static int timeleft (struct timeval *, struct timeval *);
83int timeleft (struct timeval *, struct timeval *); 83static void cleanup (int) __dead;
84void cleanup (int) __dead; 84static int write_header_sun (void **, size_t *, int *);
85int write_header_sun (void **, size_t *, int *); 85static int write_header_wav (void **, size_t *, int *);
86int write_header_wav (void **, size_t *, int *); 86static void write_header (void);
87void write_header (void); 87static void rewrite_header (void);
88void rewrite_header (void); 
89 88
90int 89int
91main(argc, argv) 90main(int argc, char *argv[])
92 int argc; 
93 char *argv[]; 
94{ 91{
95 u_char *buffer; 92 u_char *buffer;
96 size_t len, bufsize = 0; 93 size_t len, bufsize = 0;
97 int ch, no_time_limit = 1; 94 int ch, no_time_limit = 1;
98 const char *defdevice = _PATH_SOUND; 95 const char *defdevice = _PATH_SOUND;
99 96
100 while ((ch = getopt(argc, argv, "ab:B:C:F:c:d:e:fhi:m:P:p:qt:s:Vv:")) != -1) { 97 while ((ch = getopt(argc, argv, "ab:B:C:F:c:d:e:fhi:m:P:p:qt:s:Vv:")) != -1) {
101 switch (ch) { 98 switch (ch) {
102 case 'a': 99 case 'a':
103 aflag++; 100 aflag++;
104 break; 101 break;
105 case 'b': 102 case 'b':
106 decode_int(optarg, &balance); 103 decode_int(optarg, &balance);
@@ -338,64 +335,58 @@ main(argc, argv) @@ -338,64 +335,58 @@ main(argc, argv)
338 while (no_time_limit || timeleft(&start_time, &record_time)) { 335 while (no_time_limit || timeleft(&start_time, &record_time)) {
339 if ((size_t)read(audiofd, buffer, bufsize) != bufsize) 336 if ((size_t)read(audiofd, buffer, bufsize) != bufsize)
340 err(1, "read failed"); 337 err(1, "read failed");
341 if (conv_func) 338 if (conv_func)
342 (*conv_func)(buffer, bufsize); 339 (*conv_func)(buffer, bufsize);
343 if ((size_t)write(outfd, buffer, bufsize) != bufsize) 340 if ((size_t)write(outfd, buffer, bufsize) != bufsize)
344 err(1, "write failed"); 341 err(1, "write failed");
345 total_size += bufsize; 342 total_size += bufsize;
346 } 343 }
347 cleanup(0); 344 cleanup(0);
348} 345}
349 346
350int 347int
351timeleft(start_tvp, record_tvp) 348timeleft(struct timeval *start_tvp, struct timeval *record_tvp)
352 struct timeval *start_tvp; 
353 struct timeval *record_tvp; 
354{ 349{
355 struct timeval now, diff; 350 struct timeval now, diff;
356 351
357 (void)gettimeofday(&now, NULL); 352 (void)gettimeofday(&now, NULL);
358 timersub(&now, start_tvp, &diff); 353 timersub(&now, start_tvp, &diff);
359 timersub(record_tvp, &diff, &now); 354 timersub(record_tvp, &diff, &now);
360 355
361 return (now.tv_sec > 0 || (now.tv_sec == 0 && now.tv_usec > 0)); 356 return (now.tv_sec > 0 || (now.tv_sec == 0 && now.tv_usec > 0));
362} 357}
363 358
364void 359void
365cleanup(signo) 360cleanup(int signo)
366 int signo; 
367{ 361{
368 362
369 rewrite_header(); 363 rewrite_header();
370 close(outfd); 364 close(outfd);
371 if (omonitor_gain) { 365 if (omonitor_gain) {
372 AUDIO_INITINFO(&info); 366 AUDIO_INITINFO(&info);
373 info.monitor_gain = omonitor_gain; 367 info.monitor_gain = omonitor_gain;
374 if (ioctl(audiofd, AUDIO_SETINFO, &info) < 0) 368 if (ioctl(audiofd, AUDIO_SETINFO, &info) < 0)
375 err(1, "failed to reset audio info"); 369 err(1, "failed to reset audio info");
376 } 370 }
377 close(audiofd); 371 close(audiofd);
378 if (signo != 0) { 372 if (signo != 0) {
379 (void)raise_default_signal(signo); 373 (void)raise_default_signal(signo);
380 } 374 }
381 exit(0); 375 exit(0);
382} 376}
383 377
384int 378static int
385write_header_sun(hdrp, lenp, leftp) 379write_header_sun(void **hdrp, size_t *lenp, int *leftp)
386 void **hdrp; 
387 size_t *lenp; 
388 int *leftp; 
389{ 380{
390 static int warned = 0; 381 static int warned = 0;
391 static sun_audioheader auh; 382 static sun_audioheader auh;
392 int sunenc, oencoding = encoding; 383 int sunenc, oencoding = encoding;
393 384
394 /* only perform conversions if we don't specify the encoding */ 385 /* only perform conversions if we don't specify the encoding */
395 switch (encoding) { 386 switch (encoding) {
396 case AUDIO_ENCODING_ULINEAR_LE: 387 case AUDIO_ENCODING_ULINEAR_LE:
397#if BYTE_ORDER == LITTLE_ENDIAN 388#if BYTE_ORDER == LITTLE_ENDIAN
398 case AUDIO_ENCODING_ULINEAR: 389 case AUDIO_ENCODING_ULINEAR:
399#endif 390#endif
400 if (precision == 16) 391 if (precision == 16)
401 conv_func = change_sign16_swap_bytes_le; 392 conv_func = change_sign16_swap_bytes_le;
@@ -468,31 +459,28 @@ write_header_sun(hdrp, lenp, leftp) @@ -468,31 +459,28 @@ write_header_sun(hdrp, lenp, leftp)
468 459
469 infolen = ((len = strlen(header_info)) + 7) & 0xfffffff8; 460 infolen = ((len = strlen(header_info)) + 7) & 0xfffffff8;
470 *leftp = infolen - len; 461 *leftp = infolen - len;
471 auh.hdr_size = htonl(sizeof(auh) + infolen); 462 auh.hdr_size = htonl(sizeof(auh) + infolen);
472 } else { 463 } else {
473 *leftp = sizeof(default_info); 464 *leftp = sizeof(default_info);
474 auh.hdr_size = htonl(sizeof(auh) + *leftp); 465 auh.hdr_size = htonl(sizeof(auh) + *leftp);
475 } 466 }
476 *(sun_audioheader **)hdrp = &auh; 467 *(sun_audioheader **)hdrp = &auh;
477 *lenp = sizeof auh; 468 *lenp = sizeof auh;
478 return 0; 469 return 0;
479} 470}
480 471
481int 472static int
482write_header_wav(hdrp, lenp, leftp) 473write_header_wav(void **hdrp, size_t *lenp, int *leftp)
483 void **hdrp; 
484 size_t *lenp; 
485 int *leftp; 
486{ 474{
487 /* 475 /*
488 * WAV header we write looks like this: 476 * WAV header we write looks like this:
489 * 477 *
490 * bytes purpose 478 * bytes purpose
491 * 0-3 "RIFF" 479 * 0-3 "RIFF"
492 * 4-7 file length (minus 8) 480 * 4-7 file length (minus 8)
493 * 8-15 "WAVEfmt " 481 * 8-15 "WAVEfmt "
494 * 16-19 format size 482 * 16-19 format size
495 * 20-21 format tag 483 * 20-21 format tag
496 * 22-23 number of channels 484 * 22-23 number of channels
497 * 24-27 sample rate 485 * 24-27 sample rate
498 * 28-31 average bytes per second 486 * 28-31 average bytes per second
@@ -699,28 +687,28 @@ fmt_pcm: @@ -699,28 +687,28 @@ fmt_pcm:
699 memcpy(p, data, 4); 687 memcpy(p, data, 4);
700 p += 4; /* 40/54 */ 688 p += 4; /* 40/54 */
701 put32(datalen); 689 put32(datalen);
702 p += 4; /* 44/58 */ 690 p += 4; /* 44/58 */
703#undef put32 691#undef put32
704#undef put16 692#undef put16
705 693
706 *hdrp = wavheaderbuf; 694 *hdrp = wavheaderbuf;
707 *lenp = (p - wavheaderbuf); 695 *lenp = (p - wavheaderbuf);
708 696
709 return 0; 697 return 0;
710} 698}
711 699
712void 700static void
713write_header() 701write_header(void)
714{ 702{
715 struct iovec iv[3]; 703 struct iovec iv[3];
716 int veclen, left, tlen; 704 int veclen, left, tlen;
717 void *hdr; 705 void *hdr;
718 size_t hdrlen; 706 size_t hdrlen;
719 707
720 switch (format) { 708 switch (format) {
721 case AUDIO_FORMAT_DEFAULT: 709 case AUDIO_FORMAT_DEFAULT:
722 case AUDIO_FORMAT_SUN: 710 case AUDIO_FORMAT_SUN:
723 if (write_header_sun(&hdr, &hdrlen, &left) != 0) 711 if (write_header_sun(&hdr, &hdrlen, &left) != 0)
724 return; 712 return;
725 break; 713 break;
726 case AUDIO_FORMAT_WAV: 714 case AUDIO_FORMAT_WAV:
@@ -749,41 +737,41 @@ write_header() @@ -749,41 +737,41 @@ write_header()
749 if (left) { 737 if (left) {
750 iv[veclen].iov_base = default_info; 738 iv[veclen].iov_base = default_info;
751 iv[veclen].iov_len = left; 739 iv[veclen].iov_len = left;
752 tlen += iv[veclen++].iov_len; 740 tlen += iv[veclen++].iov_len;
753 } 741 }
754 742
755 if (tlen == 0) 743 if (tlen == 0)
756 return; 744 return;
757 745
758 if (writev(outfd, iv, veclen) != tlen) 746 if (writev(outfd, iv, veclen) != tlen)
759 err(1, "could not write audio header"); 747 err(1, "could not write audio header");
760} 748}
761 749
762void 750static void
763rewrite_header() 751rewrite_header(void)
764{ 752{
765 753
766 /* can't do this here! */ 754 /* can't do this here! */
767 if (outfd == STDOUT_FILENO) 755 if (outfd == STDOUT_FILENO)
768 return; 756 return;
769 757
770 if (lseek(outfd, SEEK_SET, 0) < 0) 758 if (lseek(outfd, SEEK_SET, 0) < 0)
771 err(1, "could not seek to start of file for header rewrite"); 759 err(1, "could not seek to start of file for header rewrite");
772 write_header(); 760 write_header();
773} 761}
774 762
775void 763static void
776usage() 764usage(void)
777{ 765{
778 766
779 fprintf(stderr, "Usage: %s [-afhqV] [options] {files ...|-}\n", 767 fprintf(stderr, "Usage: %s [-afhqV] [options] {files ...|-}\n",
780 getprogname()); 768 getprogname());
781 fprintf(stderr, "Options:\n\t" 769 fprintf(stderr, "Options:\n\t"
782 "-B buffer size\n\t" 770 "-B buffer size\n\t"
783 "-b balance (0-63)\n\t" 771 "-b balance (0-63)\n\t"
784 "-c channels\n\t" 772 "-c channels\n\t"
785 "-d audio device\n\t" 773 "-d audio device\n\t"
786 "-e encoding\n\t" 774 "-e encoding\n\t"
787 "-F format\n\t" 775 "-F format\n\t"
788 "-i header information\n\t" 776 "-i header information\n\t"
789 "-m monitor volume\n\t" 777 "-m monitor volume\n\t"