File: play

package info (click to toggle)
sox 12.16-6
  • links: PTS
  • area: main
  • in suites: potato
  • size: 1,180 kB
  • ctags: 1,466
  • sloc: ansic: 16,658; sh: 2,071; makefile: 126
file content (203 lines) | stat: -rwxr-xr-x 4,804 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
#!/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