shithub: sox

Download patch

ref: 49be44ccb713c2a5373751861efcf2adc0958c5d
parent: faabf4330b3983cc36908b906f2e1f4af1b810d2
author: cbagwell <cbagwell>
date: Sun Nov 6 18:36:54 EST 2005

Update play script to support multiple files.

--- a/play.1
+++ b/play.1
@@ -5,26 +5,42 @@
 play, rec \- play and record sound files
 .SH SYNOPSIS
 .B play
-.I "[fopts] infile [effect]"
+.I "[ general options ] [ format options ] infile1 [ [ format options ] infile2 ... ] [effect]"
 .P
 .B rec
-.I "[fopts] outfile [effect]"
+.I "[ general options ] [format options ] outfile [effect]"
 .SH "DESCRIPTION"
-This manual page briefly documents the
-.B play and rec
-commands.
-.PP
 .B play
 and
 .B rec
-are programs that allow you to play and record different types of sound files 
-from the command line.  They are front ends to the more general 
+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) 
-package.  Normally, the play command will automatically detect the 
-type and other parameters of the soundfile. If it can't do 
-so, the parameters can be changed through options.
-.SH OPTIONS
-A summary of common options are included below.
+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 preceed.
 For a complete description of options and their values, see 
 the 
 .B sox(1) 
@@ -33,12 +49,9 @@
 .B \-c [channels], \-\-channels=[channels]
 Define the number of channels in the file.
 .TP
-.B \-d [device], \-\-device=[device]
-Specify a different device to play the sound file to.
+.B \-\-file=[filename]
+Specify the filename.
 .TP
-.B \-\-file
-Next specified option is FILENAME.
-.TP
 .B \-f [format], \-\-format=[format]
 Specify bit format of the sample. One of s, u, U, A, a, or g.
 .TP
@@ -55,23 +68,17 @@
 .B \-v [volume], \-\-volume=[volume]
 Change the audio volume
 .TP
-.B \-V, \-\-verbose
-Print verbose information during processing
-.TP
 .B \-x , \-\-xinu
 Reverse the byte order of the sample (only works with 16 and 32-bit data).
 .TP
-.B \-h, \-\-help
-Show summary of options.
-.TP
-.B \-\-version
-Show version of play/rec.
-
-.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)
--- a/sox.txt
+++ b/sox.txt
@@ -90,7 +90,7 @@
        audio  sample data type and apply one or more sound effects to the file
        during this translation.
 
-       If more then one input file is specified	 then  they  are  concatenated
+       If more than one input file is specified	 then  they  are  concatenated
        into  the  output  file.	  In  this case, it has a restriction that all
        input files must be of the same data type and sample rates.
 
--- a/src/play.in
+++ b/src/play.in
@@ -5,7 +5,9 @@
 # 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.h
+#          play each filename back with the given effect. This
+#          would allow the files to be of different data types
+#          and sample rates.
 #
 # Change History:
 #
@@ -27,7 +29,11 @@
 PATH="$bindir:.:$PATH"
 
 program_name=`basename $0`
-program_version="2.0"
+rec_mode="no"
+if [ "$program_name" = "rec" ]; then
+    rec_mode="yes"
+fi
+program_version="3.0"
 
 if [ -z "$1" ]; then
     echo "\
@@ -45,11 +51,25 @@
 help()
 {
     echo "\
-Usage: $program_name [OPTION]... FILE [EFFECT]...
+Usage: $program_name [GENERAL OPTIONS] [FORMAT OPTIONS] FILE [EFFECT]...
 Play/record sound files to/from unix style sound devices.
 
-  -c, --channels=CHANNELS      specifies the number of sound channels in FILE
+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
@@ -57,16 +77,13 @@
                                SIZE is either b, w, l, f, d, or D
   -t, --type=TYPE              specifies file format of FILE
   -v, --volume=VOLUME          change amplitude
-  -V, --verbose                print verbose information
   -x, --xinu                   reverse bit order of sample
                                (only works with 16-bit and 32-bit integer data)
-      --file                   next argument is FILE
-  -h, --help                   display this help and exit
-      --version                output version information and exit
+      --file=FILENAME          specify filename
 
 EFFECTs are one or more of the following:  avg, band, chorus, copy, cut, 
-deemph, echo, echos, flanger, highp, lowp, map, mask, phaser, pick, polyphase
-rate, repeat, resample, reverb, reverse, split, stat, vibro.
+deemph, echo, echos, flanger, highp, lowp, map, mask, phaser, pick,
+polyphase, rate, repeat, resample, reverb, reverse, split, stat, vibro.
 
 See sox man page for detailed information on supported file types, data
 formats, and effect options."
@@ -73,7 +90,6 @@
     exit 0
 }
 
-
 # loop over arguments
 while [ $# -ne 0 ]; do
     case "$1" in
@@ -125,24 +141,30 @@
 	    ;;
 	-v)
 	    shift
-	    volume="-v $1"
+	    fopts2="$fopts2 -v $1"
 	    ;;
 	--volume=*)
-	    volume="-v `echo $1 | sed 's/.*=//'`"
+	    fopts2="$fopts2 -v `echo $1 | sed 's/.*=//'`"
 	    ;;
         -V|--verbose)
-            fopts="$fopts -V"
+            gopts="$gopts -V"
             ;;
 	-x|--xinu)
 	    fopts="$fopts -x"
 	    ;;
-	--file)
-	    shift
-	    if [ -z "$filename" ]; then
-		filename="$1"
-	    else
-		echo "Filename already given.  Ignoring extra name: $1" 1>&2
-	    fi
+	--file=*)
+            if [ $rec_mode == "yes" ]; then
+	        if [ -z "$filename" ]; then
+                    filename=`echo $1 | sed 's/.*=//'`
+                else
+                    echo "Filename already given.  Ignoring extra name: $1" 1>&2
+	        fi
+            else
+                filename=`echo $1 | sed 's/.*=//'`
+                play_opts="$play_opts $fopts $fopts2 \"$filename\""
+                fopts=""
+                fopts2=""
+            fi
 	    ;;
 	-h)
 	    help
@@ -154,18 +176,34 @@
 	    version
 	    ;;
 	-)
-	    filename="-"
+            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
 	    ;;
-	-*)
-	    fopts="$fopts $1"
-	    ;;
 	*)
-	    if [ -z "$filename" ]; then
-		filename="$1"
-	    else
-		echo "Filename already given.  Ignoring extra name: $1" 1>&2
-	    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
+                echo $filename
+                play_opts="$play_opts $fopts $fopts2 \"$filename\""
+                fopts=""
+                fopts2=""
+            fi
 	    ;;
     esac
     shift
@@ -219,7 +257,7 @@
 
 # If name is "rec" then record else assume user is wanting to play
 # a sound file.
-if [ "$program_name" = "rec" ]; then
+if [ "$rec_mode" = "yes" ]; then
 
     # Don't send data to stdout if they are reading from it.
     if [ "$filename" = "-" ]; then
@@ -227,8 +265,15 @@
     else
       echo "Send break (control-c) to end recording"
     fi
-    sox $volume $arch_defines $fopts $device $fopts2 "$filename" $effects 
-
+    # $fopts are specified on both sides because audio driver
+    # may not support the given format and might pick
+    # something close to it.  Asume 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
-    sox $volume $fopts $fopts2 "$filename" $arch_defines $device $effects
+    # Eval is needed to recongnize 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