Source-Changes-HG archive

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

[src/trunk]: src/usr.bin add audiorecord and audioplay tools. audioplay does...



details:   https://anonhg.NetBSD.org/src/rev/308dd156a924
branches:  trunk
changeset: 467615:308dd156a924
user:      mrg <mrg%NetBSD.org@localhost>
date:      Fri Mar 26 14:02:39 1999 +0000

description:
add audiorecord and audioplay tools.  audioplay does .au and .wav files.  audiorecord makes .au files only.  uses parts of audioctl..

diffstat:

 usr.bin/audio/Makefile             |    5 +
 usr.bin/audio/Makefile.inc         |   13 +
 usr.bin/audio/common/Makefile      |   12 +
 usr.bin/audio/common/audio.c       |  368 +++++++++++++++++++++++++++
 usr.bin/audio/common/libaudio.h    |  158 +++++++++++
 usr.bin/audio/ctl/Makefile         |    6 +
 usr.bin/audio/ctl/audioctl.h       |    6 +
 usr.bin/audio/ctl/ctl.c            |  167 +++++------
 usr.bin/audio/play/Makefile        |    6 +
 usr.bin/audio/play/audioplay.1     |  107 +++++++
 usr.bin/audio/play/play.c          |  257 +++++++++++++++++++
 usr.bin/audio/record/Makefile      |    6 +
 usr.bin/audio/record/audiorecord.1 |  145 ++++++++++
 usr.bin/audio/record/record.c      |  340 +++++++++++++++++++++++++
 usr.bin/audioctl/Makefile          |    6 -
 usr.bin/audioctl/audioctl.1        |  115 --------
 usr.bin/audioctl/audioctl.c        |  499 -------------------------------------
 17 files changed, 1508 insertions(+), 708 deletions(-)

diffs (truncated from 2406 to 300 lines):

diff -r 8ec42950d1a6 -r 308dd156a924 usr.bin/audio/Makefile
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/usr.bin/audio/Makefile    Fri Mar 26 14:02:39 1999 +0000
@@ -0,0 +1,5 @@
+#      $NetBSD: Makefile,v 1.1 1999/03/26 14:02:39 mrg Exp $
+
+SUBDIR=        common ctl play record
+
+.include <bsd.subdir.mk>
diff -r 8ec42950d1a6 -r 308dd156a924 usr.bin/audio/Makefile.inc
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/usr.bin/audio/Makefile.inc        Fri Mar 26 14:02:39 1999 +0000
@@ -0,0 +1,13 @@
+#      $NetBSD: Makefile.inc,v 1.1 1999/03/26 14:02:39 mrg Exp $
+
+LIBAUDIO != cd ${.CURDIR}/../common;\
+    printf "xxx: .MAKE\n\t@echo \$${.OBJDIR}\n" | ${MAKE} -s -f-
+CPPFLAGS+=-I${.CURDIR}/../common
+DPADD+=        ${LIBAUDIO}/libaudio.a
+LDADD+=        -L${LIBAUDIO} -laudio
+
+.if exists(${.CURDIR}/../../Makefile.inc)
+.include "${.CURDIR}/../../Makefile.inc"
+.endif
+
+COPTS+= -g
diff -r 8ec42950d1a6 -r 308dd156a924 usr.bin/audio/common/Makefile
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/usr.bin/audio/common/Makefile     Fri Mar 26 14:02:39 1999 +0000
@@ -0,0 +1,12 @@
+#      $NetBSD: Makefile,v 1.1 1999/03/26 14:02:40 mrg Exp $
+
+LIB=   audio
+SRCS=  audio.c
+
+NOPROFILE=      noprofile
+NOPIC=          nopic
+
+# only needed during build
+libinstall::
+
+.include <bsd.lib.mk>
diff -r 8ec42950d1a6 -r 308dd156a924 usr.bin/audio/common/audio.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/usr.bin/audio/common/audio.c      Fri Mar 26 14:02:39 1999 +0000
@@ -0,0 +1,368 @@
+#include <sys/types.h>
+#include <sys/audioio.h>
+#include <sys/ioctl.h>
+#include <sys/time.h>
+
+#include <ctype.h>
+#include <err.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "libaudio.h"
+
+/* back and forth between encodings */
+struct {
+       char *ename;
+       int eno;
+} encs[] = {
+       { AudioEmulaw,          AUDIO_ENCODING_ULAW },
+       { "ulaw",               AUDIO_ENCODING_ULAW },
+       { AudioEalaw,           AUDIO_ENCODING_ALAW },
+       { AudioEslinear,        AUDIO_ENCODING_SLINEAR },
+       { "linear",             AUDIO_ENCODING_SLINEAR },
+       { AudioEulinear,        AUDIO_ENCODING_ULINEAR },
+       { AudioEadpcm,          AUDIO_ENCODING_ADPCM },
+       { "ADPCM",              AUDIO_ENCODING_ADPCM },
+       { AudioEslinear_le,     AUDIO_ENCODING_SLINEAR_LE },
+       { "linear_le",          AUDIO_ENCODING_SLINEAR_LE },
+       { AudioEulinear_le,     AUDIO_ENCODING_ULINEAR_LE },
+       { AudioEslinear_be,     AUDIO_ENCODING_SLINEAR_BE },
+       { "linear_be",          AUDIO_ENCODING_SLINEAR_BE },
+       { AudioEulinear_be,     AUDIO_ENCODING_ULINEAR_BE },
+       { AudioEmpeg_l1_stream, AUDIO_ENCODING_MPEG_L1_STREAM },
+       { AudioEmpeg_l1_packets,AUDIO_ENCODING_MPEG_L1_PACKETS },
+       { AudioEmpeg_l1_system, AUDIO_ENCODING_MPEG_L1_SYSTEM },
+       { AudioEmpeg_l2_stream, AUDIO_ENCODING_MPEG_L2_STREAM },
+       { AudioEmpeg_l2_packets,AUDIO_ENCODING_MPEG_L2_PACKETS },
+       { AudioEmpeg_l2_system, AUDIO_ENCODING_MPEG_L2_SYSTEM },
+       { 0, -1 }
+};
+
+
+char *
+audio_enc_from_val(val)
+       int     val;
+{
+       int     i;
+
+       for (i = 0; encs[i].ename; i++)
+               if (encs[i].eno == val)
+                       break;
+       return (encs[i].ename);
+}
+
+int
+audio_enc_to_val(enc)
+       const   char *enc;
+{
+       int     i;
+
+       for (i = 0; encs[i].ename; i++)
+               if (strcmp(encs[i].ename, enc) == 0)
+                       break;
+       if (encs[i].ename)
+               return (encs[i].eno);
+       else
+               return (-1);
+}
+
+int
+audio_parse_encoding(encoding_str, fd, encp, precp)
+       char    *encoding_str;
+       int     fd;
+       int     *encp;
+       int     *precp;
+{
+       int     i, prec = 0;
+       char    *colon, *star;
+
+       colon = strchr(encoding_str, ':');
+       if (colon) {
+               *colon++ = '\0';
+               if (*colon)
+                       prec = atoi(colon);
+       }
+       star = strrchr(encoding_str, '*');
+       if (star)
+               *star = '\0';
+       for (i = 0; ; i++) {
+               audio_encoding_t enc;
+
+               enc.index = i;
+               if (ioctl(fd, AUDIO_GETENC, &enc) < 0)
+                       break;
+
+               if (strcasecmp(enc.name, encoding_str) == 0 &&
+                  (prec == 0 || prec == enc.precision)) {
+                       *encp = enc.encoding;
+                       *precp = enc.precision;
+                       return (0);
+               }
+               
+       }
+       return (1);
+}
+
+/*
+ * SunOS/NeXT .au format helpers
+ */
+struct {
+       int     file_encoding;
+       int     encoding;
+       int     precision;
+} file2sw_encodings[] = {
+       { AUDIO_FILE_ENCODING_MULAW_8,          AUDIO_ENCODING_ULAW,    8 },
+       { AUDIO_FILE_ENCODING_LINEAR_8,         AUDIO_ENCODING_ULINEAR_BE, 8 },
+       { AUDIO_FILE_ENCODING_LINEAR_16,        AUDIO_ENCODING_ULINEAR_BE, 16 },
+       { AUDIO_FILE_ENCODING_LINEAR_24,        AUDIO_ENCODING_ULINEAR_BE, 24 },
+       { AUDIO_FILE_ENCODING_LINEAR_32,        AUDIO_ENCODING_ULINEAR_BE, 32 },
+#if 0
+       { AUDIO_FILE_ENCODING_FLOAT,            AUDIO_ENCODING_ULAW,    32 },
+       { AUDIO_FILE_ENCODING_DOUBLE,           AUDIO_ENCODING_ULAW,    64 },
+       { AUDIO_FILE_ENCODING_ADPCM_G721,       AUDIO_ENCODING_ULAW,    4 },
+       { AUDIO_FILE_ENCODING_ADPCM_G722,       AUDIO_ENCODING_ULAW,    0 },
+       { AUDIO_FILE_ENCODING_ADPCM_G723_3,     AUDIO_ENCODING_ULAW,    3 },
+       { AUDIO_FILE_ENCODING_ADPCM_G723_5,     AUDIO_ENCODING_ULAW,    5 },
+#endif
+       { AUDIO_FILE_ENCODING_ALAW_8,           AUDIO_ENCODING_ALAW,    8 },
+       { -1, -1 }
+};
+
+int
+audio_get_sun_encoding(sun_encoding, encp, precp)
+       int     sun_encoding;
+       int     *encp;
+       int     *precp;
+{
+       int i;
+
+       for (i = 0; file2sw_encodings[i].file_encoding != -1; i++)
+               if (file2sw_encodings[i].file_encoding == sun_encoding) {
+                       *precp = file2sw_encodings[i].precision;
+                       *encp = file2sw_encodings[i].encoding;
+                       return (0);
+               }
+       return (1);
+}
+
+/*
+ * sample header is:
+ *
+ *   RIFF\^@^C^@WAVEfmt ^P^@^@^@^A^@^B^@D<AC>^@^@^P<B1>^B^@^D^@^P^@data^@^@^C^@^@^@^@^@^@^@^@^@^@
+ *
+ */
+/*
+ * WAV format helpers
+ */
+/*
+ * find a .wav header, etc. returns header length on success
+ */
+size_t
+audio_parse_wav_hdr(hdr, sz, enc, prec, sample, channels)
+       void    *hdr;
+       size_t  sz;
+       int     *enc;
+       int     *prec;
+       int     *sample;
+       int     *channels;
+{
+       char    *where = hdr;
+       wav_audioheaderpart *part;
+       wav_audioheaderfmt *fmt;
+       char    *end = (((char *)hdr) + sz);
+       int     newenc, newprec;
+
+       if (sz < 32)
+               return (AUDIO_ENOENT);
+
+       if (strncmp(where, "RIFF", 4))
+               return (AUDIO_ENOENT);
+       where += 8;
+       if (strncmp(where,  "WAVE", 4))
+               return (AUDIO_ENOENT);
+       where += 4;
+
+       do {
+               part = (wav_audioheaderpart *)where;
+               where += getle32(part->len) + 8;
+       } while (where < end && strncmp(part->name, "fmt ", 4));
+
+       /* too short ? */
+       if (where + 16 > end)
+               return (AUDIO_ESHORTHDR);
+
+       fmt = (wav_audioheaderfmt *)(part + 1);
+
+#if 0
+printf("fmt header is:\n\t%d\ttag\n\t%d\tchannels\n\t%d\tsample rate\n\t%d\tavg_bps\n\t%d\talignment\n\t%d\tbits per sample\n", getle16(fmt->tag), getle16(fmt->channels), getle32(fmt->sample_rate), 
getle32(fmt->avg_bps), getle16(fmt->alignment), getle16(fmt->bits_per_sample));
+#endif
+
+       switch (getle16(fmt->tag)) {
+       case WAVE_FORMAT_UNKNOWN:
+       case WAVE_FORMAT_ADPCM:
+       case WAVE_FORMAT_OKI_ADPCM:
+       case WAVE_FORMAT_DIGISTD:
+       case WAVE_FORMAT_DIGIFIX:
+       case IBM_FORMAT_MULAW:
+       case IBM_FORMAT_ALAW:
+       case IBM_FORMAT_ADPCM:
+       default:
+               return (AUDIO_EWAVUNSUPP);
+
+       case WAVE_FORMAT_PCM:
+               switch (getle16(fmt->bits_per_sample)) {
+               case 8:
+                       newprec = 8;
+                       break;
+               case 16:
+                       newprec = 16;
+                       break;
+               case 24:
+                       newprec = 24;
+                       break;
+               case 32:
+                       newprec = 32;
+                       break;
+               default:
+                       return (AUDIO_EWAVBADPCM);
+               }
+               newenc = AUDIO_ENCODING_ULINEAR;;
+               break;
+       case WAVE_FORMAT_ALAW:
+               newenc = AUDIO_ENCODING_ALAW;
+               newprec = 8;
+               break;
+       case WAVE_FORMAT_MULAW:
+               newenc = AUDIO_ENCODING_ULAW;
+               newprec = 8;
+               break;
+       }
+
+       do {
+               part = (wav_audioheaderpart *)where;
+               where += (getle32(part->len) + 8);
+       } while ((char *)where < end && strncmp(part->name, "data", 4));
+
+       if (where <= end) {
+               *channels = getle16(fmt->channels);
+               *sample = getle32(fmt->sample_rate);
+               *enc = newenc;
+               *prec = newprec;
+               part++;
+               return ((char *)part - (char *)hdr);
+       }



Home | Main Index | Thread Index | Old Index