Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/audio libaudio:



details:   https://anonhg.NetBSD.org/src/rev/392e8ae21590
branches:  trunk
changeset: 500533:392e8ae21590
user:      mrg <mrg%NetBSD.org@localhost>
date:      Wed Dec 13 08:19:54 2000 +0000

description:
libaudio:
- rename audio_get_sun_encoding() to audio_sun_to_encoding()
- add audio_encoding_to_sun()
play.c:
- adapt
record.c:
- convert NetBSD encoding to sun encoding if possible, otherwise don't
output a header at all.
fixes PR#10380 from Michael Eriksson <eramore%era-t.ericsson.se@localhost>.

diffstat:

 usr.bin/audio/common/audio.c    |  21 +++++++++++++++++++--
 usr.bin/audio/common/libaudio.h |   5 +++--
 usr.bin/audio/play/play.c       |   4 ++--
 usr.bin/audio/record/record.c   |  13 +++++++++++--
 4 files changed, 35 insertions(+), 8 deletions(-)

diffs (112 lines):

diff -r eb8287258559 -r 392e8ae21590 usr.bin/audio/common/audio.c
--- a/usr.bin/audio/common/audio.c      Wed Dec 13 08:06:11 2000 +0000
+++ b/usr.bin/audio/common/audio.c      Wed Dec 13 08:19:54 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: audio.c,v 1.9 1999/09/27 05:06:10 mrg Exp $    */
+/*     $NetBSD: audio.c,v 1.10 2000/12/13 08:19:54 mrg Exp $   */
 
 /*
  * Copyright (c) 1999 Matthew R. Green
@@ -132,7 +132,7 @@
 };
 
 int
-audio_get_sun_encoding(sun_encoding, encp, precp)
+audio_sun_to_encoding(sun_encoding, encp, precp)
        int     sun_encoding;
        int     *encp;
        int     *precp;
@@ -148,6 +148,23 @@
        return (1);
 }
 
+int
+audio_encoding_to_sun(encoding, precision, sunep)
+       int     encoding;
+       int     precision;
+       int     *sunep;
+{
+       int i;
+
+       for (i = 0; file2sw_encodings[i].file_encoding != -1; i++)
+               if (file2sw_encodings[i].encoding == encoding &&
+                   file2sw_encodings[i].precision == precision) {
+                       *sunep = file2sw_encodings[i].file_encoding;
+                       return (0);
+               }
+       return (1);
+}
+
 /*
  * sample header is:
  *
diff -r eb8287258559 -r 392e8ae21590 usr.bin/audio/common/libaudio.h
--- a/usr.bin/audio/common/libaudio.h   Wed Dec 13 08:06:11 2000 +0000
+++ b/usr.bin/audio/common/libaudio.h   Wed Dec 13 08:19:54 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: libaudio.h,v 1.4 2000/06/18 07:20:15 mrg Exp $ */
+/*     $NetBSD: libaudio.h,v 1.5 2000/12/13 08:19:54 mrg Exp $ */
 
 /*
  * Copyright (c) 1999 Matthew R. Green
@@ -83,7 +83,8 @@
 char   *audio_enc_from_val __P((int));
 int    audio_enc_to_val __P((const char *));
 
-int    audio_get_sun_encoding __P((int, int *, int *));
+int    audio_sun_to_encoding __P((int, int *, int *));
+int    audio_encoding_to_sun __P((int, int, int *));
 
 /*
  * M$ WAV files, info gleamed from sox sources
diff -r eb8287258559 -r 392e8ae21590 usr.bin/audio/play/play.c
--- a/usr.bin/audio/play/play.c Wed Dec 13 08:06:11 2000 +0000
+++ b/usr.bin/audio/play/play.c Wed Dec 13 08:19:54 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: play.c,v 1.17 2000/02/27 08:20:01 mrg Exp $    */
+/*     $NetBSD: play.c,v 1.18 2000/12/13 08:19:54 mrg Exp $    */
 
 /*
  * Copyright (c) 1999 Matthew R. Green
@@ -334,7 +334,7 @@
        AUDIO_INITINFO(&info);
        sunhdr = hdr;
        if (ntohl(sunhdr->magic) == AUDIO_FILE_MAGIC) {
-               if (audio_get_sun_encoding(ntohl(sunhdr->encoding), 
+               if (audio_sun_to_encoding(ntohl(sunhdr->encoding), 
                    &info.play.encoding, &info.play.precision)) {
                        warnx("unknown unsupported Sun audio encoding format %d",
                            ntohl(sunhdr->encoding));
diff -r eb8287258559 -r 392e8ae21590 usr.bin/audio/record/record.c
--- a/usr.bin/audio/record/record.c     Wed Dec 13 08:06:11 2000 +0000
+++ b/usr.bin/audio/record/record.c     Wed Dec 13 08:19:54 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: record.c,v 1.10 2000/02/02 05:02:25 dmcmahill Exp $    */
+/*     $NetBSD: record.c,v 1.11 2000/12/13 08:19:55 mrg Exp $  */
 
 /*
  * Copyright (c) 1999 Matthew R. Green
@@ -308,13 +308,22 @@
        sun_audioheader auh;
        struct iovec iv[3];
        int veclen = 0, left, tlen = 0;
+       int sunenc;
+
+       /* if we can't express this as a Sun header, don't write any */
+       if (audio_encoding_to_sun(encoding, precision, &sunenc) != 0) {
+               if (!qflag)
+                       warnx("failed to convert to sun encoding; "
+                             "Sun audio header not written");
+               return;
+       }
 
        auh.magic = htonl(AUDIO_FILE_MAGIC);
        if (outfd == STDOUT_FILENO)
                auh.data_size = htonl(AUDIO_UNKNOWN_SIZE);
        else
                auh.data_size = htonl(total_size);
-       auh.encoding = htonl(encoding);
+       auh.encoding = htonl(sunenc);
        auh.sample_rate = htonl(sample_rate);
        auh.channels = htonl(channels);
        if (header_info) {



Home | Main Index | Thread Index | Old Index