Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.bin/audio - add a AUDIO_FORMAT_DEFAULT. use it. don't ...
details: https://anonhg.NetBSD.org/src/rev/938423ae9067
branches: trunk
changeset: 522026:938423ae9067
user: mrg <mrg%NetBSD.org@localhost>
date: Sun Feb 10 15:30:53 2002 +0000
description:
- add a AUDIO_FORMAT_DEFAULT. use it. don't change functionity.
- fix the function selection in sunau conversions.
- be more verbose when given -V. (hi lennart! :)
diffstat:
usr.bin/audio/common/libaudio.h | 3 +-
usr.bin/audio/record/record.c | 59 +++++++++++++++++++++++++++++++++++-----
2 files changed, 53 insertions(+), 9 deletions(-)
diffs (147 lines):
diff -r a96090840674 -r 938423ae9067 usr.bin/audio/common/libaudio.h
--- a/usr.bin/audio/common/libaudio.h Sun Feb 10 15:29:58 2002 +0000
+++ b/usr.bin/audio/common/libaudio.h Sun Feb 10 15:30:53 2002 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: libaudio.h,v 1.10 2002/01/15 23:48:52 mrg Exp $ */
+/* $NetBSD: libaudio.h,v 1.11 2002/02/10 15:30:53 mrg Exp $ */
/*
* Copyright (c) 1999 Matthew R. Green
@@ -31,6 +31,7 @@
/*
* audio formats
*/
+#define AUDIO_FORMAT_DEFAULT -1
#define AUDIO_FORMAT_NONE 1
#define AUDIO_FORMAT_SUN 2
#define AUDIO_FORMAT_WAV 3
diff -r a96090840674 -r 938423ae9067 usr.bin/audio/record/record.c
--- a/usr.bin/audio/record/record.c Sun Feb 10 15:29:58 2002 +0000
+++ b/usr.bin/audio/record/record.c Sun Feb 10 15:30:53 2002 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: record.c,v 1.26 2002/02/10 13:23:27 mrg Exp $ */
+/* $NetBSD: record.c,v 1.27 2002/02/10 15:30:55 mrg Exp $ */
/*
* Copyright (c) 1999 Matthew R. Green
@@ -53,7 +53,7 @@
audio_info_t info, oinfo;
ssize_t total_size = -1;
const char *device;
-int format = AUDIO_FORMAT_SUN;
+int format = AUDIO_FORMAT_DEFAULT;
char *header_info;
char default_info[8] = { '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0' };
int audiofd, outfd;
@@ -108,8 +108,8 @@
case 'F':
format = audio_format_from_str(optarg);
if (format < 0)
- errx(1, "Unknown audio format; "
- "supported formats: \"sun\" and \"wav\"");
+ errx(1, "Unknown audio format; supported "
+ "formats: \"sun\", \"wav\", and \"none\"");
break;
case 'c':
decode_int(optarg, &channels);
@@ -267,6 +267,45 @@
write_header();
total_size = 0;
+ if (verbose && conv_func) {
+ const char *s = NULL;
+
+ if (conv_func == swap_bytes)
+ s = "swap bytes (16 bit)";
+ else if (conv_func == swap_bytes32)
+ s = "swap bytes (32 bit)";
+ else if (conv_func == change_sign16_be)
+ s = "change sign (big-endian, 16 bit)";
+ else if (conv_func == change_sign16_le)
+ s = "change sign (little-endian, 16 bit)";
+ else if (conv_func == change_sign32_be)
+ s = "change sign (big-endian, 32 bit)";
+ else if (conv_func == change_sign32_le)
+ s = "change sign (little-endian, 32 bit)";
+ else if (conv_func == change_sign16_swap_bytes_be)
+ s = "change sign & swap bytes (big-endian, 16 bit)";
+ else if (conv_func == change_sign16_swap_bytes_le)
+ s = "change sign & swap bytes (little-endian, 16 bit)";
+ else if (conv_func == change_sign32_swap_bytes_be)
+ s = "change sign (big-endian, 32 bit)";
+ else if (conv_func == change_sign32_swap_bytes_le)
+ s = "change sign & swap bytes (little-endian, 32 bit)";
+
+ if (s)
+ fprintf(stderr, "%s: converting, using function: %s\n",
+ getprogname(), s);
+ else
+ fprintf(stderr, "%s: using unnamed conversion "
+ "function\n", getprogname());
+ }
+
+ if (verbose)
+ fprintf(stderr,
+ "sample_rate=%d channels=%d precision=%d encoding=%s\n",
+ info.record.sample_rate, info.record.channels,
+ info.record.precision,
+ audio_enc_from_val(info.record.encoding));
+
(void)gettimeofday(&start_time, NULL);
while (no_time_limit || timeleft(&start_time, &record_time)) {
if (read(audiofd, buffer, bufsize) != bufsize)
@@ -321,15 +360,16 @@
static sun_audioheader auh;
int sunenc, oencoding = encoding;
+ /* only perform conversions if we don't specify the encoding */
switch (encoding) {
case AUDIO_ENCODING_ULINEAR_LE:
#if BYTE_ORDER == LITTLE_ENDIAN
case AUDIO_ENCODING_ULINEAR:
#endif
if (precision == 16)
- conv_func = swap_bytes;
+ conv_func = change_sign16_swap_bytes_le;
else if (precision == 32)
- conv_func = swap_bytes32;
+ conv_func = change_sign32_swap_bytes_le;
if (conv_func)
encoding = AUDIO_ENCODING_SLINEAR_BE;
break;
@@ -351,9 +391,9 @@
case AUDIO_ENCODING_SLINEAR:
#endif
if (precision == 16)
- conv_func = change_sign16_swap_bytes_le;
+ conv_func = swap_bytes;
else if (precision == 32)
- conv_func = change_sign32_swap_bytes_le;
+ conv_func = swap_bytes32;
if (conv_func)
encoding = AUDIO_ENCODING_SLINEAR_BE;
break;
@@ -376,6 +416,7 @@
"(precision %d);\nSun audio header not written",
s, precision);
}
+ format = AUDIO_FORMAT_NONE;
conv_func = 0;
warned = 1;
return -1;
@@ -550,6 +591,7 @@
warned = 1;
}
}
+ format = AUDIO_FORMAT_NONE;
return (-1);
}
@@ -637,6 +679,7 @@
size_t hdrlen;
switch (format) {
+ case AUDIO_FORMAT_DEFAULT:
case AUDIO_FORMAT_SUN:
if (write_header_sun(&hdr, &hdrlen, &left) != 0)
return;
Home |
Main Index |
Thread Index |
Old Index