ref: 9343c9427158a36841cbece5baff21bd26505c7d
parent: f0983536cf684f309aa689a3a4b3b168f115bbec
author: rrt <rrt>
date: Tue Jan 9 11:51:55 EST 2007
Allow sox to be run as "play" and "rec". Add support for AUDIODEV to --rec. Document --play, --rec, play and rec. Remove "-o" short form for "--octave", it's not worth a single-letter option, and "-o" often means "output file", so probably just confusing.
--- a/Makefile.am
+++ b/Makefile.am
@@ -10,8 +10,8 @@
# man pages are not considered to be sources, so need to add "dist_"
# prefix to ensure they are added to the distribution.
-dist_man_MANS = sox.1 soxexam.1 play.1 libst.3
-dist_pkgdata_DATA = sox.txt soxexam.txt
+dist_man_MANS = sox.1 soxexam.1 libst.3
+dist_pkgdata_DATA = sox.txt soxexam.txt libst.txt
# Rule for making plain text man pages
%.txt: %.1
--- a/configure.ac
+++ b/configure.ac
@@ -263,9 +263,7 @@
dnl Generate output files.
AX_CREATE_STDINT_H(src/ststdint.h)
-AC_SUBST(with_alsa) dnl for play.in
-AC_SUBST(with_oss) dnl for play.in
-AC_CONFIG_FILES(Makefile src/Makefile src/libgsm/Makefile src/libst-config src/play)
+AC_CONFIG_FILES(Makefile src/Makefile src/libgsm/Makefile src/libst-config)
AC_CONFIG_SUBDIRS([lua])
AC_OUTPUT
--- a/play.1
+++ /dev/null
@@ -1,90 +1,0 @@
-.TH play 1 "December 11, 2001"
-.\" NAME should be all caps, SECTION should be 1-8, maybe w/ subsection
-.\" other parms are allowed: see man(7), man(1)
-.SH NAME
-play, rec \- play and record sound files
-.SH SYNOPSIS
-.B play
-.I "[ general options ] [ format options ] infile1 [ [ format options ] infile2 ... ] [effect]"
-.P
-.B rec
-.I "[ general options ] [format options ] outfile [effect]"
-.SH "DESCRIPTION"
-.B play
-and
-.B rec
-is a command line front end to the
-.B sox(1)
-program. It will play/record audio files to/from unix-style audio devices. It can optionally apply audio effects to the file.
-.PP
-When playing audio files, more then one input file can be specified. If more than one is specified then they are concatenated together while playing. In this case, it has a restriction that all input files must be of the same data type and sample rates.
-
-When playing audio files without headers, format options may be specified to inform sox of the files sample rate, data size and encoding, and number of channels. When recording audio data, this same information needs to be presented so that the audio device can be placed into the proper mode.
-
-.SH GENERAL OPTIONS
-A summary of general options are included below. They should only be specified once on the command line.
-For a complete description of options and their values, see
-the
-.B sox(1)
-man page.
-.TP
-.B \-d [device], \-\-device=[device]
-Specify a different device to play/record the sound file to/from.
-.TP
-.B \-h, \-\-help
-Show summary of options.
-.TP
-.B \-V, \-\-verbose
-Print verbose information during processing
-.TP
-.B \-\-version
-Show version of play/rec.
-.SH FORMAT OPTIONS
-A summary of format options are included below. These options apply to the filename they immediately precede.
-For a complete description of options and their values, see the
-.B sox(1)
-man page.
-.TP
-.B \-c [channels], \-\-channels=[channels]
-Define the number of channels in the file.
-.TP
-.B \-\-file=[filename]
-Specify the filename.
-.TP
-.B \-f [format], \-\-format=[format]
-Specify bit format of the sample. One of s, u, U, A, a, or g.
-.TP
-.B \-r [rate], \-\-rate=[rate]
-Specify the sample rate of the audio data (samples per second).
-.TP
-.B \-s [size], \-\-size=[size]
-Specify the width of each sample. One of b, w, l, f, d, or D.
-.TP
-.B \-t [type], \-\-type=[type]
-Specify audio file format to use. Useful if it can not be
-automatically determined.
-.TP
-.B \-v [volume], \-\-volume=[volume]
-Change the audio volume
-.TP
-.B \-x , \-\-xinu
-Reverse the byte order of the sample (only works with 16 and 32-bit data).
-.TP
-Description of effects are described in the
-.B sox(1)
-man page.
-.SH EFFECTS
-For a complete description of effects and their values, see
-the
-.B sox(1)
-man page.
-.SH "SEE ALSO"
-
-sox(1)
-soxexam(1)
-
-.SH AUTHOR
-This manual page was written by Guenter Geiger <geiger@iem.mhsg.ac.at>,
-for the Debian GNU/Linux system.
-.P
-Updates by Anonymous.
--- a/sox.1
+++ b/sox.1
@@ -23,8 +23,13 @@
.SH SYNOPSIS
.nf
\fBsox\fR [\fIglobal-options\fR] [\fIformat-options\fR] \fIinfile1\fR
- [ [\fIformat-options\fR] \fIinfile2\fR ] ... [\fIformat-options\fR] \fIoutfile\fR
- [\fIeffect\fR [\fIeffect-options\fR] ] ...
+ [[\fIformat-options\fR] \fIinfile2\fR] ... [\fIformat-options\fR] \fIoutfile\fR
+ [\fIeffect\fR [\fIeffect-options\fR]] ...
+\fBplay\fR [\fIglobal-options\fR] [\fIformat-options\fR] \fIinfile1\fR
+ [[\fIformat-options\fR] \fIinfile2\fR] ... [\fIformat-options\fR]
+ [\fIeffect\fR [\fIeffect-options\fR]] ...
+\fBrec\fR [\fIglobal-options\fR] [\fIformat-options\fR] \fIoutfile\fR
+ [\fIeffect\fR [\fIeffect-options\fR]] ...
.fi
.SH DESCRIPTION
SoX reads and writes audio files in most popular formats and can
@@ -35,6 +40,9 @@
number of channels) to form one output file using one of three methods:
`concatenate' (the default), `mix', or `merge'.
.SP
+If invoked as `play', the output file is the default sound device. If
+invoked as `rec', the input device is the default sound device.
+.SP
The overall SoX processing chain can be summarised as follows:
.SP
.ce
@@ -53,8 +61,7 @@
sample rate
The sample rate in samples per second (`Hertz' or `Hz'). For
example, digital telephony traditionally uses a sample rate of 8000Hz
-(8kHz);
-audio Compact Discs use 44100Hz (44\*d1kHz).
+(8kHz); audio Compact Discs use 44100Hz (44\*d1kHz).
.TP
sample size
The number of bits (or bytes) used to store each sample. Most popular are
@@ -66,8 +73,8 @@
some `compress' the audio data, i.e. the stored audio data takes up less
space (i.e. disk-space or transmission band-width) than the other format
parameters and the number of samples would imply. Commonly-used
-encoding types include: floating-point, \(*m-law, ADPCM, signed linear,
-FLAC, etc.
+encoding types include floating-point, \(*m-law, ADPCM, signed linear,
+and FLAC.
.TP
channels
The number of audio channels contained in the file. One (`mono') and two
@@ -329,7 +336,7 @@
stereo file; the first and second mono files would become
the left and right channels of the stereo file.
.TP
-\fB\-o\fR, \fB\-\-octave\fR
+\fB\-\-octave\fR
Run in a mode that can be used, in conjunction with the GNU
Octave program, to assist with the selection and configuration
of many of the filtering effects. For the first given effect
@@ -341,10 +348,16 @@
.br
octave plot.m
.TP
+\fB\-\-play\fR
+The same as invoking SoX as `play'.
+.TP
\fB\-q\fR, \fB\-\-no\-show\-progress\fR
Run in quiet mode when SoX wouldn't otherwise do so;
this is the converse of the \fB\-S\fR option.
.TP
+\fB\-\-rec\fR
+The same as invoking SoX as `rec'.
+.TP
\fB\-S\fR, \fB\-\-show\-progress\fR
Display input file format/header information and input file(s)
processing progress in terms of elapsed/remaining time and percentage.
@@ -881,7 +894,7 @@
options will cause a format conversion, and the \fB.wav\fR
will written appropriately.
.SP
-SoX currently can read PCM, ULAW, ALAW, MS ADPCM, and IMA (or DVI) ADPCM.
+SoX currently can read PCM, \(*m-law, A-law, MS ADPCM, and IMA (or DVI) ADPCM.
It can write all of these formats including the ADPCM encoding.
Big endian versions of RIFF files, called RIFX, can also be read
and written. To write a RIFX file, use the
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -9,7 +9,7 @@
LIBTOOL = @LIBTOOL@ @LIBTOOLFLAGS@
bin_PROGRAMS = sox
-bin_SCRIPTS = play libst-config
+bin_SCRIPTS = libst-config
lib_LTLIBRARIES = libst.la
include_HEADERS = st.h stconfig.h ststdint.h
@@ -40,12 +40,12 @@
libgsm/libgsm.la:
$(MAKE) -C libgsm
-rec: play
- $(RM) rec && $(LN_S) play rec
+play rec: sox
+ $(RM) $@ && $(LN_S) sox $@
install-exec-hook:
- cd $(DESTDIR)$(bindir) && \
- $(RM) rec && $(LN_S) play rec
+ cd $(DESTDIR)$(bindir) && $(RM) play && $(LN_S) sox play
+ cd $(DESTDIR)$(bindir) && $(RM) rec && $(LN_S) sox rec
distclean-local:
$(RM) *.raw *.sf ststdint.h
--- a/src/play.in
+++ /dev/null
@@ -1,270 +1,0 @@
-#!/bin/sh
-# Shell script to play/record sound files to/from unix style sound devices.
-# Should auto detect most supported systems.
-#
-# Originally developed by Chris Bagwell (cbagwell@sprynet.com)
-#
-# TODO: Put each set of fopts and filenames on an array and then
-# play each filename back with the given effect. This
-# would allow the files to be of different data types
-# and sample rates.
-#
-# Change History:
-#
-# Major updates have been supplied by Kjetil Torgrim Homme and
-# Kirk Goff.
-
-# Set up path so that it can find Sox if user's path doesn't already
-# include it.
-prefix=@prefix@
-exec_prefix=@exec_prefix@
-bindir=@bindir@
-
-HAVE_ALSA=@with_alsa@
-HAVE_OSS=@with_oss@
-
-# Look for sox in install directory first and then in current directory.
-PATH="$bindir:.:$PATH"
-
-program_name=`basename $0`
-rec_mode="no"
-if [ "$program_name" = "rec" ]; then
- rec_mode="yes"
-fi
-program_version="3.0"
-
-if [ -z "$1" ]; then
- echo "\
-$program_name: too few arguments
-Try \`$program_name --help' for more information." 1>&2
- exit 1
-fi
-
-version()
-{
- echo "$program_name (sox) $program_version"
- exit 0
-}
-
-help()
-{
- echo "\
-Usage: $program_name [GENERAL OPTIONS] [FORMAT OPTIONS] FILE [EFFECT]...
-Play/record sound files to/from unix style sound devices.
-
-GENERAL OPTIONS:
-
-General options should only be specified one.
-
- -d, --device=DEVICE use DEVICE for input/output
- -V, --verbose print verbose information
- -h, --help display this help and exit
- --version output version information and exit
-
-FORMAT OPTIONS:
-
-File options can be specified for each filename. Multiple filenames can
-be specified when playing audio files but they must all be of
-the data type and sample rates.
-
- -c, --channels=CHANNELS specifies the number of sound channels in FILE
- -f, --format=FORMAT specifies bit format of sample
- FORMAT is either s, u, U, A, a, or g
- -r, --rate=RATE sample rate in hertz of FILE
- -s, --size=SIZE interpret size of sample
- SIZE is either b, w, l, f, d, or D
- -t, --type=TYPE specifies file format of FILE
- -v, --volume=VOLUME change amplitude
- -x, --xinu reverse bit order of sample
- (only works with 16-bit and 32-bit integer data)
- --file=FILENAME specify filename
-
-EFFECTs are one or more of the following: avg, band, bandpass, bandreject,
-bass, chorus, compand, dcshift, deemph, dither, earwax, echo, echos,
-equalizer, fade, filter, flanger, highpass, highp, lowpass, lowp, mask,
-mcompand, noiseprof, noisered, pad, pan, phaser, pick, pitch, polyphase,
-rabbit, rate, repeat, resample, reverb, reverse, silence, speed, stat,
-stretch, swap, synth, treble, trim, vibro, vol.
-
-See sox man page for detailed information on supported file types, data
-formats, and effect options."
- exit 0
-}
-
-# loop over arguments
-while [ $# -ne 0 ]; do
- case "$1" in
- avg|band|bandpass|bandreject|bass|chorus|compand|dcshift|deemph|dither|earwax|echo|echos|equalizer|fade|filter|flanger|highpass|highp|lowpass|lowp|mask|mcompand|noiseprof|noisered|pad|pan|phaser|pick|pitch|polyphase|rabbit|rate|repeat|resample|reverb|reverse|silence|speed|stat|stretch|swap|synth|treble|trim|vibro|vol)
- effects="$@"
- break
- ;;
- -c)
- shift
- fopts="$fopts -c $1"
- ;;
- --channels=*)
- fopts="$fopts -c `echo $1 | sed 's/.*=//'`"
- ;;
- -d)
- shift
- device="$1"
- ;;
- --device=*)
- device=`echo $1 | sed 's/.*=//'`
- ;;
- -f)
- shift
- fopts="$fopts -$1"
- ;;
- --format=*)
- fopts="$fopts -`echo $1 | sed 's/.*=//'`"
- ;;
- -r)
- shift
- fopts="$fopts -r $1"
- ;;
- --rate=*)
- fopts="$fopts -r `echo $1 | sed 's/.*=//'`"
- ;;
- -s)
- shift
- fopts="$fopts -$1"
- ;;
- --size=*)
- fopts="$fopts -`echo $1 | sed 's/.*=//'`"
- ;;
- -t)
- shift
- fopts2="$fopts -t $1"
- ;;
- --type=*)
- fopts2="$fopts -t `echo $1 | sed 's/.*=//'`"
- ;;
- -v)
- shift
- fopts2="$fopts2 -v $1"
- ;;
- --volume=*)
- fopts2="$fopts2 -v `echo $1 | sed 's/.*=//'`"
- ;;
- -V|--verbose)
- gopts="$gopts -V"
- ;;
- -x|--xinu)
- fopts="$fopts -x"
- ;;
- --file=*)
- if [ $rec_mode = "yes" ]; then
- filename=`echo $1 | sed 's/.*=//'`
- else
- filename=`echo $1 | sed 's/.*=//'`
- play_opts="$play_opts $fopts $fopts2 \"$filename\""
- fopts=""
- fopts2=""
- fi
- ;;
- -h)
- help
- ;;
- --help)
- help
- ;;
- --version)
- version
- ;;
- -)
- if [ $rec_mode = "yes" ]; then
- if [ -z "$filename" ]; then
- filename="-"
- else
- echo "Filename already given. Ignoring extra name: $1" 1>&2
- fi
- else
- filename="-"
- play_opts="$play_opts $fopts $fopts2 \"$filename\""
- fopts=""
- fopts2=""
- fi
- ;;
- *)
- if [ $rec_mode = "yes" ]; then
- if [ -z "$filename" ]; then
- filename="$1"
- else
- echo "Filename already given. Ignoring extra name: $1" 1>&2
- fi
- else
- filename=`echo $1 | sed 's/\ /\\\ /g'`
- filename=$1
- play_opts="$play_opts $fopts $fopts2 \"$filename\""
- fopts=""
- fopts2=""
- fi
- ;;
- esac
- shift
-done
-
-# If user sets AUDIODEV environment variable then force output device
-# to be that. Solaris SunRays make use of this for sure.
-if [ -n "$AUDIODEV" ]; then
- device="$AUDIODEV"
-fi
-
-if [ "$HAVE_ALSA" = "yes" ]; then
- arch_defines="-t alsa"
- if [ -z "$device" ]; then
- device="default"
- fi
-else
- if [ "$HAVE_OSS" = "yes" ]; then
- arch_defines="-t ossdsp"
- if [ -z "$device" ]; then
- device="/dev/dsp"
- fi
- else
- arch=`uname -s`
- case $arch in
- SunOS)
- case `uname -r` in
- # Solaris software can auto-detect hardware capabilities.
- 5.*)
- arch_defines="-t sunau"
- ;;
- # For SunOS default to signed words. Some hardware can only play u-law and would need
- # to be changed here.
- *)
- arch_defines="-t sunau -w -s"
- ;;
- esac
- if [ -z "$device" ]; then
- device="/dev/audio"
- fi
- ;;
- NetBSD|OpenBSD)
- arch_defines="-t sunau"
- if [ -z "$device" ]; then
- device="/dev/audio"
- fi
- ;;
-
- esac
- fi
-fi
-
-# If name is "rec" then record else assume user is wanting to play
-# a sound file.
-if [ "$rec_mode" = "yes" ]; then
- echo "Send break (control-c) to end recording" 1>&2
- # $fopts are specified on both sides because audio driver
- # may not support the given format and might pick
- # something close to it. Assume user really wants the
- # file to be in the specified format and so request
- # sox to do any conversions.
- sox $gopts $arch_defines $fopts $device $fopts $fopts2 "$filename" $effects
-else
- # Eval is needed to recognize the quotes around filename
- # and let them be passed to program as 1 option (in case
- # filename has spaces).
- eval sox $gopts $play_opts $arch_defines $device $effects
-fi
--- a/src/sox.c
+++ b/src/sox.c
@@ -86,7 +86,7 @@
} *file_info_t;
/* local forward declarations */
-static bool doopts(file_info_t fo, int, char **, bool *play, bool *record);
+static bool doopts(file_info_t fo, int, char **, bool *play, bool *rec);
static void usage(char const *) NORET;
static void usage_effect(char *) NORET;
static void process(void);
@@ -223,14 +223,15 @@
static void set_device(file_info_t fo)
{
#if defined(HAVE_ALSA)
- fo->filetype = "alsa";
- fo->filename = xstrdup("default");
+ fo->filetype = "alsa";
+ fo->filename = xstrdup("default");
#elif defined(HAVE_OSS)
- fo->filetype = "ossdsp";
- fo->filename = xstrdup("/dev/dsp");
+ fo->filetype = "ossdsp";
+ fo->filename = xstrdup("/dev/dsp");
#elif defined (HAVE_SUN_AUDIO)
- fo->filetype = "sunau";
- fo->filename = xstrdup("/dev/audio");
+ char *device = getenv("AUDIODEV");
+ fo->filetype = "sunau";
+ fo->filename = xstrdup(device ? device : "/dev/audio");
#endif
}
@@ -237,7 +238,7 @@
int main(int argc, char **argv)
{
size_t i;
- bool play = false, record = false;
+ bool play = false, rec = false;
myname = argv[0];
atexit(cleanup);
@@ -248,8 +249,8 @@
strcmp(myname + i - (sizeof("play") - 1), "play") == 0) {
play = true;
} else if (i >= sizeof("rec") - 1 &&
- strcmp(myname + i - (sizeof("record") - 1), "record") == 0) {
- record = true;
+ strcmp(myname + i - (sizeof("rec") - 1), "rec") == 0) {
+ rec = true;
}
/* Loop over arguments and filenames, stop when an effect name is
@@ -265,7 +266,7 @@
fo_none = *fo;
- if (doopts(fo, argc, argv, &play, &record)) { /* is null file? */
+ if (doopts(fo, argc, argv, &play, &rec)) { /* is null file? */
if (fo->filetype != NULL && strcmp(fo->filetype, "null") != 0)
st_warn("Ignoring \"-t %s\".", fo->filetype);
fo->filetype = "null";
@@ -282,7 +283,7 @@
file_opts[file_count++] = fo;
}
- if (record) {
+ if (rec) {
file_info_t fo = make_file_info();
st_size_t i;
@@ -421,8 +422,9 @@
{"endian" , required_argument, NULL, 0},
{"interactive" , no_argument, NULL, 0},
{"help-effect" , required_argument, NULL, 0},
+ {"octave" , no_argument, NULL, 0},
{"play" , no_argument, NULL, 0},
- {"record" , no_argument, NULL, 0},
+ {"rec" , no_argument, NULL, 0},
{"version" , no_argument, NULL, 0},
{"channels" , required_argument, NULL, 'c'},
@@ -431,7 +433,6 @@
{"merge" , no_argument, NULL, 'M'},
{"mix" , no_argument, NULL, 'm'},
{"no-show-progress", no_argument, NULL, 'q'},
- {"octave" , no_argument, NULL, 'o'},
{"rate" , required_argument, NULL, 'r'},
{"reverse-bits" , no_argument, NULL, 'X'},
{"show-progress" , no_argument, NULL, 'S'},
@@ -441,7 +442,7 @@
{NULL, 0, NULL, 0}
};
-static bool doopts(file_info_t fo, int argc, char **argv, bool *play, bool *record)
+static bool doopts(file_info_t fo, int argc, char **argv, bool *play, bool *rec)
{
bool isnull = false;
int option_index, c;
@@ -479,14 +480,18 @@
break;
case 5:
- *play = true;
+ globalinfo.octave_plot_effect = true;
break;
case 6:
- *record = true;
+ *play = true;
break;
-
+
case 7:
+ *rec = true;
+ break;
+
+ case 8:
printf("%s: v%s\n", myname, st_version());
exit(0);
break;
@@ -509,10 +514,6 @@
isnull = true; /* Is null file. */
break;
- case 'o':
- globalinfo.octave_plot_effect = true;
- break;
-
case 'h': case '?':
usage(NULL); /* No return */
break;
@@ -1628,7 +1629,7 @@
"-o generate Octave commands to plot response of filter effect\n"
"--play output to the default sound device; set if SoX run as `play'\n"
"-q run in quiet mode; opposite of -S\n"
- "--record input from the default sound device; set if SoX run as `rec'\n"
+ "--rec input from the default sound device; set if SoX run as `rec'\n"
"-S display status while processing audio data\n"
"--version display version number of SoX and exit\n"
"-V[level] increment or set verbosity level (default 2); levels are:\n"