1#!/bin/sh 2# 3# SoX Regression Test script: Lossless file conversion 4 5bindir="." 6builddir="." 7srcdir="." 8 9if [ -f ./sox.exe ] ; then 10 EXEEXT=".exe" 11else 12 EXEEXT="" 13fi 14 15# Set options & allow user to override paths. Useful for testing an 16# installed sox. 17while [ $# -ne 0 ]; do 18 case "$1" in 19 -e) 20 echo=$1 21 ;; 22 23 -V) 24 verbose=$1 25 echo=$1 26 ;; 27 28 -a) # Perform each test up to 3 times with different #s of 29 all=all # channels; probably enough coverage without this though. 30 ;; 31 32 --bindir=*) 33 bindir=`echo $1 | sed 's/.*=//'` 34 ;; 35 36 -i) 37 shift 38 bindir=$1 39 ;; 40 41 --builddir=*) 42 builddir=`echo $1 | sed 's/.*=//'` 43 ;; 44 45 -b) 46 shift 47 builddir=$1 48 ;; 49 50 --srcdir=*) 51 srcdir=`echo $1 | sed 's/.*=//'` 52 ;; 53 54 -c) 55 shift 56 srcdir=$1 57 ;; 58 59 *) 60 echo "Unknown option" 61 exit 1 62 esac 63 shift 64done 65 66getFormat () { 67 formatExt=$1; formatText=$1; formatFlags="" 68 case $1 in 69 al ) formatText="alaw" ;; 70 ul ) formatText="ulaw" ;; 71 wavu8)formatText="u8 in wav"; formatFlags="-e unsigned -b 8"; formatExt="wav" ;; 72 s1X ) formatText="s8 (swap bits)"; formatExt="s8"; formatFlags="-X" ;; 73 s1N ) formatText="s8 (swap nibbles)"; formatExt="s8"; formatFlags="-N" ;; 74 s1XN) formatText="s8 (swap nibbles & bits)"; formatExt="s8"; formatFlags="-X -N" ;; 75 esac 76} 77 78execute() { 79 if [ "${echo}x" != "x" ] ; then 80 echo $* 81 fi 82 cmd=$1 83 shift 84 echo $* | xargs $cmd 85} 86 87convertToAndFrom () { 88 while [ $# != 0 ]; do 89 if [ "${skip}x" != "x" ] ; then 90 format1_skip=`echo ${skip} | grep ${format1}` 91 from_skip=`echo ${skip} | grep ${1}` 92 fi 93 if [ "${format1_skip}x" = "x" -a "${from_skip}x" = "x" ] ; then 94 getFormat ${format1}; format1Ext=$formatExt; format1Text=$formatText; format1Flags=$formatFlags 95 getFormat $1; format2Ext=$formatExt; format2Text=$formatText; format2Flags=$formatFlags 96 execute ${bindir}/sox${EXEEXT} $verbose -RD -r $rate -c $channels -n $format1Flags input.$format1Ext synth $samples's' sin 300-3300 noise trapezium 97 execute ${bindir}/sox${EXEEXT} $verbose -RD -r $rate -c $channels $format1Flags input.$format1Ext $format2Flags intermediate.$format2Ext 98 execute ${bindir}/sox${EXEEXT} $verbose -RD -r $rate -c $channels $format2Flags intermediate.$format2Ext $format1Flags output.$format1Ext 99 intermediateReference=vectors/intermediate`echo "$channels $rate $format1Flags $format1Ext $format2Flags"|tr " " "_"`.$format2Ext 100 101 # Uncomment to generate new reference files 102 # N.B. new reference files must be manually checked for correctness 103 #cp -i intermediate.$format2Ext $intermediateReference 104 105 if test -f $intermediateReference 106 then 107 cmp -s $intermediateReference intermediate.$format2Ext 108 if [ "$?" != "0" ] 109 then 110 echo "*FAIL vector* channels=$channels \"$format1Text\" ---> \"$format2Text\"." 111 exit 1 # This allows failure inspection. 112 fi 113 vectors=`expr $vectors + 1` 114 fi 115 116 if cmp -s input.$format1Ext output.$format1Ext 117 then 118 echo "ok channels=$channels \"$format1Text\" <--> \"$format2Text\"." 119 else 120 echo "*FAIL* channels=$channels \"$format1Text\" <--> \"$format2Text\"." 121 exit 1 # This allows failure inspection. 122 fi 123 rm -f input.$format1Ext intermediate.$format2Ext output.$format1Ext 124 fi 125 shift 126 done 127} 128 129do_multichannel_formats () { 130 format1=u8 131 convertToAndFrom s8 u8 s16 u16 s24 u24 s32 u32 f32 f64 dat au wav aiff aifc flac caf sph wv sox 132 133 format1=s16 134 convertToAndFrom s16 u16 s24 u24 s32 u32 f32 f64 dat au wav aiff aifc flac caf sph wv sox 135 136 format1=u24 137 convertToAndFrom s24 u24 s32 u32 f32 f64 wav aiff aifc flac sph wv sox 138 (samples=23500; convertToAndFrom paf) || exit 1 139 140 format1=s32 141 convertToAndFrom s32 u32 f64 wav aiff aifc caf sph wv mat4 mat5 sox 142 143 format1=al 144 convertToAndFrom al s16 u16 s32 f32 f64 dat aiff aifc flac caf w64 145 146 format1=ul 147 convertToAndFrom ul s16 u16 s32 f32 f64 dat aiff aifc flac caf sph 148 149 format1=wavu8 150 convertToAndFrom wavu8 aiff aifc au dat sf flac caf sph 151} 152 153do_twochannel_formats () { 154 format1=wavu8 155 convertToAndFrom avr maud 156 (rate=8000; convertToAndFrom voc) || exit 1 # Fixed rate 157 (samples=23492; convertToAndFrom 8svx) || exit 1 # Even number of samples only 158} 159 160do_singlechannel_formats () { 161 format1=vox 162 convertToAndFrom vox s16 u16 s24 u24 s32 u32 f32 f64 dat au wav aiff aifc flac caf sox 163 164 format1=ima 165 convertToAndFrom ima s16 u16 s24 u24 s32 u32 f32 f64 dat au aiff aifc flac caf # FIXME: wav 166 167 format1=wavu8 168 convertToAndFrom smp s8 s1X s1N s1XN sndt sndr 169 #(rate=50000; convertToAndFrom txw) || exit 1 # FIXME 170 (rate=11025; convertToAndFrom hcom) || exit 1 # Fixed rates 171 172 format1=wve 173 (rate=8000; convertToAndFrom al s16 u16 s32 f32 f64 dat) || exit 1 # Fixed rate 174 175 format1=prc 176 (rate=8000; convertToAndFrom al s16 u16 s32 f32 f64 dat) || exit 1 # Fixed rate 177} 178 179stderr_time () { 180 egrep -v "^real |^user |^sys " $1 1>&2 181 grep "^user " $1 | sed "s/^user //" 182} 183 184# Reading and writing performance test 185time="/usr/bin/time -p" 186timeIO () { 187 $time ${bindir}/sox${EXEEXT} -c $channels -r $rate -n tmp.sox synth $samples's' saw 0:`expr $rate / 2` noise brown vol .9 2> tmp.write 188 echo TIME synth channels=$channels samples=$samples `stderr_time tmp.write`s 189 if [ `uname` != SunOS ]; then 190 while [ $# != 0 ]; do 191 if [ "${skip}x" != "x" ] ; then 192 from_skip=`echo ${skip} | grep ${1}` 193 fi 194 if [ "${from_skip}x" = "x" ] ; then 195 getFormat $1; 196 ($time ${bindir}/sox${EXEEXT} $verbose -D tmp.sox $formatFlags -t $1 - 2> tmp.read) | \ 197 ($time ${bindir}/sox${EXEEXT} $verbose -t $1 -c $channels -r $rate - -t sox /dev/null 2> tmp.write) 198 echo "TIME `printf %4s $formatText` write=`stderr_time tmp.write`s read=`stderr_time tmp.read`s" 199 fi 200 shift 201 done 202 fi 203 rm -f tmp.sox tmp.write tmp.read 204} 205 206# Don't try to test un-built formats 207skip_check () { 208 while [ $# -ne 0 ]; do 209 ${bindir}/sox${EXEEXT} --help|grep "^AUDIO FILE.*\<$1\>">/dev/null || skip="$1 $skip" 210 shift 211 done 212} 213 214 215# Run tests 216 217${builddir}/sox_sample_test${EXEEXT} || exit 1 218 219skip_check caf flac mat4 mat5 paf w64 wv 220 221vectors=0 222 223rate=44100 224samples=23493 225 226channels=3 227do_multichannel_formats 228 229channels=2 230if [ "$all" = "all" ]; then 231 do_multichannel_formats 232fi 233do_twochannel_formats 234format1=cdda # 2-channel only 235convertToAndFrom s16 u24 aiff 236 237channels=1 238if [ "$all" = "all" ]; then 239 do_multichannel_formats 240 do_twochannel_formats 241fi 242do_singlechannel_formats 243 244if false; then # needs skip & dir work for general use 245${srcdir}/test-comments 246if [ $? -eq 0 ]; then 247 echo "ok comments" 248else 249 echo "*FAIL* comments" 250 exit 1 251fi 252fi 253 254${bindir}/sox${EXEEXT} -c 1 -r 44100 -n output.u8 synth .01 vol .5 255if [ `wc -c <output.u8` = 441 ]; then 256 echo "ok synth size" 257else 258 echo "*FAIL* synth size" 259fi 260rm output.u8 261 262echo "Checked $vectors vectors" 263 264channels=2 265samples=1e7 266timeIO s8 u8 s16 u16 s24 u24 s32 u32 f32 f64 au wav aiff aifc sph # FIXME?: caf flac dat 267 268test -n "$skip" && echo "Skipped: $skip" 269 270# Run one last command so return code is not error 271# when $skip is empty. 272echo "done." 273