#!/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.h # # 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. PATH=$PATH:/usr/local/bin program_name=`basename $0` program_version="2.0" if [ -z "$1" ]; then echo "\ $program_name: too few arguments Try \`$program_name --help' for more information." 1>&2 exit 1 fi [ -t 1 ] || silent=1 # don't show anything if stdout isn't a tty version() { echo "$program_name (sox) $program_version" exit 0 } help() { echo "\ Usage: $program_name [OPTION]... FILE [EFFECT]... Play/record sound files to/from unix style sound devices. -c, --channels=CHANNELS specifies the number of sound channels in FILE -d, --device=DEVICE use DEVICE for input/output -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 next argument is FILE -h, --help display this help and exit --version output version information and exit --silent do not display filename of currently played file 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, resample, reverb, reverse, split, stat, vibro. See sox man page for detailed information on supported file types, data formats, and effect options." exit 0 } count=0 # loop over arguments while [ $# -ne 0 ]; do case "$1" in avg|band|chorus|copy|cut|deemph|echo|echos|flanger|highp|lowp|map|mask|phaser|pick|polyphase|rate|resample|reverb|reverse|split|stat|vibro) 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 fopts="$fopts -t $1" ;; --type=*) fopts="$fopts -t `echo $1 | sed 's/.*=//'`" ;; -v) shift volume="-v $1" ;; --volume=*) volume="-v `echo $1 | sed 's/.*=//'`" ;; -x|--xinu) fopts="$fopts -x" ;; --file) shift if [ -z "$filename_0" ]; then filename_0="$1" else echo "Filename already given. Ignoring extra name: $1" 1>&2 fi ;; -h) help ;; --help) help ;; --version) version ;; --silent) silent=1 ;; -) eval filename_$count=- count=$(($count+1)) ;; -*) fopts="$fopts $1" ;; *) eval filename_$count='"$1"' count=$(($count+1)) ;; esac shift done arch=`uname -s` case $arch in SunOS) case `arch -k` in # Use below for older Sun audio hardware sun4|sun4c|sun4d) arch_defines="-t sunau -U -c 1" ;; # Use below for newer Sun audio hardware that supports stereo linear *) arch_defines="-t sunau -w -s" ;; esac if [ -z "$device" ]; then device="/dev/audio" fi ;; Linux|FreeBSD) arch_defines="-t ossdsp" if [ -z "$device" ]; then device="/dev/dsp" fi ;; esac # If name is "rec" then record else assume user is wanting to play # a sound file. if [ "$program_name" = "rec" ]; then echo "Send break (control-c) to end recording" sox $volume $arch_defines $fopts $device "$filename_0" $effects else i=0 while test $i -lt $count; do if test -z "$silent"; then eval 'echo "playing $filename_'$i'"' fi eval 'sox $volume $fopts "$filename_'$i'" $arch_defines $device $effects' i=$(($i+1)) done fi