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 -f (force) flag to audioplay, plus -s/-P/-...



details:   https://anonhg.NetBSD.org/src/rev/263182b903d5
branches:  trunk
changeset: 467733:263182b903d5
user:      mrg <mrg%NetBSD.org@localhost>
date:      Sun Mar 28 10:35:05 1999 +0000

description:
add -f (force) flag to audioplay, plus -s/-P/-c/-e switches for force setting sample rate, precision, channels and encoding.  fix some man pages missing .El bits (via veego)

diffstat:

 usr.bin/audio/play/audioplay.1     |    3 +-
 usr.bin/audio/play/play.c          |  122 +++++++++++++++++++++++++-----------
 usr.bin/audio/record/audiorecord.1 |    3 +-
 3 files changed, 87 insertions(+), 41 deletions(-)

diffs (263 lines):

diff -r 4765a217f178 -r 263182b903d5 usr.bin/audio/play/audioplay.1
--- a/usr.bin/audio/play/audioplay.1    Sun Mar 28 06:35:38 1999 +0000
+++ b/usr.bin/audio/play/audioplay.1    Sun Mar 28 10:35:05 1999 +0000
@@ -1,4 +1,4 @@
-.\"    $NetBSD: audioplay.1,v 1.1 1999/03/26 14:02:41 mrg Exp $
+.\"    $NetBSD: audioplay.1,v 1.2 1999/03/28 10:35:05 mrg Exp $
 .\"
 .\" Copyright (c) 1998 Matthew R. Green
 .\" All rights reserved.
@@ -86,6 +86,7 @@
 .Ar ctl .
 The default is
 .Pa /dev/audioctl0 .
+.El
 .Sh NOTES
 .Nm
 can be used to play Sun/NeXT audio files, and also RIFF WAVE audio files.
diff -r 4765a217f178 -r 263182b903d5 usr.bin/audio/play/play.c
--- a/usr.bin/audio/play/play.c Sun Mar 28 06:35:38 1999 +0000
+++ b/usr.bin/audio/play/play.c Sun Mar 28 10:35:05 1999 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: play.c,v 1.5 1999/03/27 18:16:23 mrg Exp $     */
+/*     $NetBSD: play.c,v 1.6 1999/03/28 10:35:06 mrg Exp $     */
 
 /*
  * Copyright (c) 1999 Matthew R. Green
@@ -47,12 +47,19 @@
 
 int main __P((int, char *[]));
 void usage __P((void));
-ssize_t audioctl_write_fromhdr __P((void *, size_t, int, int));
+ssize_t audioctl_write_fromhdr __P((void *, size_t, int));
 
 audio_info_t   info;
-int    volume = 0;
-int    balance = 0;
-int    port = 0;
+int    volume;
+int    balance;
+int    port;
+int    fflag;
+int    sample_rate;
+int    encoding;
+char   *encoding_str;
+int    precision;
+int    channels;
+
 char   const *play_errstring = NULL;
 
 int
@@ -70,25 +77,41 @@
        char    *device = 0;
        char    *ctldev = 0;
 
-       while ((ch = getopt(argc, argv, "b:C:d:hiqp:Vv:")) != -1) {
+       while ((ch = getopt(argc, argv, "b:C:c:d:e:fhip:P:qs:Vv:")) != -1) {
                switch (ch) {
                case 'b':
                        decode_int(optarg, &balance);
                        if (balance < 0 || balance > 64)
-                               errx(1, "balance must be between 0 and 64\n");
+                               errx(1, "balance must be between 0 and 64");
                        break;
+               case 'c':
+                       decode_int(optarg, &channels);
+                       if (channels < 0)
+                               errx(1, "channels must be positive");
                case 'C':
                        ctldev = optarg;
                        break;
                case 'd':
                        device = optarg;
                        break;
+               case 'e':
+                       encoding_str = optarg;
+                       break;
+               case 'f':
+                       fflag = 1;
+                       break;
                case 'i':
                        iflag++;
                        break;
                case 'q':
                        qflag++;
                        break;
+               case 'P':
+                       decode_int(optarg, &precision);
+                       if (precision != 8 && precision != 16 &&
+                           precision != 24 && precision != 32)
+                               errx(1, "precision must be between 8, 16, 24 or 32");
+                       break;
                case 'p':
                        len = strlen(optarg);
 
@@ -102,6 +125,11 @@
                                errx(1,
                            "port must be `speaker', `headphone', or `line'");
                        break;
+               case 's':
+                       decode_int(optarg, &sample_rate);
+                       if (sample_rate < 0 || sample_rate > 48000 * 2) /* XXX */
+                               errx(1, "sample rate must be between 0 and 96000\n");
+                       break;
                case 'V':
                        verbose++;
                        break;
@@ -119,6 +147,12 @@
        argc -= optind;
        argv += optind;
 
+       if (encoding_str) {
+               encoding = audio_enc_to_val(encoding_str);
+               if (encoding == -1)
+                       errx(1, "unknown encoding, bailing...");
+       }
+
        if (device == NULL)
                device = _PATH_AUDIO;
        if (ctldev == NULL)
@@ -165,7 +199,7 @@
                                err(1, "could not mmap %s", *argv);
 
                        if ((hdrlen = audioctl_write_fromhdr(addr,
-                           (size_t)filesize, ctlfd, 1)) < 0) {
+                           (size_t)filesize, ctlfd)) < 0) {
 play_error:
                                if (play_errstring)
                                        errx(1, "%s: %s", play_errstring, *argv);
@@ -205,7 +239,7 @@
                if (n == 0)
                        errx(1, "EOF on standard input");
 
-               hdrlen = audioctl_write_fromhdr(buffer, n, ctlfd, 1);
+               hdrlen = audioctl_write_fromhdr(buffer, n, ctlfd);
                if (hdrlen < 0)
                        goto play_error;
 
@@ -239,11 +273,10 @@
  * uses the local "info" variable. blah... fix me!
  */
 ssize_t
-audioctl_write_fromhdr(hdr, fsz, fd, unknown_ok)
+audioctl_write_fromhdr(hdr, fsz, fd)
        void    *hdr;
        size_t  fsz;
        int     fd;
-       int     unknown_ok;
 {
        sun_audioheader *sunhdr;
        ssize_t hdr_len;
@@ -258,20 +291,11 @@
                        return (-1);
                }
 
-               info.play.sample_rate = ntohl(sunhdr->sample_rate);
-               info.play.channels = ntohl(sunhdr->channels);
-               if (port)
-                       info.play.port = port;
-               if (volume)
-                       info.play.gain = volume;
-               if (balance)
-                       info.play.balance = balance;
-               info.mode = AUMODE_PLAY_ALL;
+               sample_rate = ntohl(sunhdr->sample_rate);
+               channels = ntohl(sunhdr->channels);
+               hdr_len = ntohl(sunhdr->hdr_size); 
 
-               if (ioctl(fd, AUDIO_SETINFO, &info) < 0)
-                       err(1, "failed to set audio info");
-
-               return (ntohl(sunhdr->hdr_size));
+               goto set_audio_mode;
        }
 
        hdr_len = audio_parse_wav_hdr(hdr, fsz, &info.play.encoding,
@@ -282,28 +306,43 @@
        case AUDIO_EWAVUNSUPP:
        case AUDIO_EWAVBADPCM:
        case AUDIO_EWAVNODATA:
-               if (unknown_ok == 0)
-                       play_errstring = audio_errstring(hdr_len);
+               play_errstring = audio_errstring(hdr_len);
                /* FALL THROUGH */
        case AUDIO_ENOENT:
                break;
        default:
                if (hdr_len < 1)
                        break;
-               if (port)
-                       info.play.port = port;
-               if (volume)
-                       info.play.gain = volume;
-               if (balance)
-                       info.play.balance = balance;
-               info.mode = AUMODE_PLAY_ALL;
+               goto set_audio_mode;
+       }
+       /*
+        * if we don't know it, bail unless we are forcing.
+        */
+       if (fflag == 0)
+               return (-1);
+set_audio_mode:
+       if (port)
+               info.play.port = port;
+       if (volume)
+               info.play.gain = volume;
+       if (balance)
+               info.play.balance = balance;
+       if (fflag) {
+               if (sample_rate)
+                       info.play.gain = sample_rate;
+               if (channels)
+                       info.play.gain = channels;
+               if (encoding)
+                       info.play.encoding = encoding;
+               if (precision)
+                       info.play.encoding = precision;
+       }
+       info.mode = AUMODE_PLAY_ALL;
 
-               if (ioctl(fd, AUDIO_SETINFO, &info) < 0)
-                       err(1, "failed to set audio info");
-
-               return (hdr_len);
-       }
-       return (unknown_ok ? 0 : -1);
+       if (ioctl(fd, AUDIO_SETINFO, &info) < 0)
+               err(1, "failed to set audio info");
+       
+       return (hdr_len);
 }
 
 void
@@ -316,6 +355,11 @@
            "-C audio control device\n\t"
            "-b balance (0-63)\n\t"
            "-d audio device\n\t"
+           "-f force settings\n\t"
+           "\t-c forced channels\n\t"
+           "\t-e forced encoding\n\t"
+           "\t-P forced precision\n\t"
+           "\t-s forced sample rate\n\t"
            "-i header information\n\t"
            "-m monitor volume\n\t"
            "-p output port\n\t"
diff -r 4765a217f178 -r 263182b903d5 usr.bin/audio/record/audiorecord.1
--- a/usr.bin/audio/record/audiorecord.1        Sun Mar 28 06:35:38 1999 +0000
+++ b/usr.bin/audio/record/audiorecord.1        Sun Mar 28 10:35:05 1999 +0000
@@ -1,4 +1,4 @@
-.\"    $NetBSD: audiorecord.1,v 1.2 1999/03/26 15:46:22 mrg Exp $
+.\"    $NetBSD: audiorecord.1,v 1.3 1999/03/28 10:35:06 mrg Exp $
 .\"
 .\" Copyright (c) 1998 Matthew R. Green
 .\" All rights reserved.
@@ -123,6 +123,7 @@
 Set the volume (gain) to
 .Ar volume .
 This value must be between 0 and 255.
+.El
 .Sh BUGS
 Many audio device hardware is limited in capabilities.  Any attempt
 to use an audio device beyond it's capabilities will result in an



Home | Main Index | Thread Index | Old Index