update to match new getopt-based options
[platform/upstream/flac.git] / test / test_streams.sh
1 #!/bin/sh
2
3 #  FLAC - Free Lossless Audio Codec
4 #  Copyright (C) 2001,2002  Josh Coalson
5 #
6 #  This program is part of FLAC; you can redistribute it and/or
7 #  modify it under the terms of the GNU General Public License
8 #  as published by the Free Software Foundation; either version 2
9 #  of the License, or (at your option) any later version.
10 #
11 #  This program is distributed in the hope that it will be useful,
12 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 #  GNU General Public License for more details.
15 #
16 #  You should have received a copy of the GNU General Public License
17 #  along with this program; if not, write to the Free Software
18 #  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
19
20 LD_LIBRARY_PATH=../src/libFLAC/.libs:../obj/lib:$LD_LIBRARY_PATH
21 export LD_LIBRARY_PATH
22 PATH=../src/flac:../src/test_streams:../obj/bin:$PATH
23
24 flac --help 1>/dev/null 2>/dev/null || (echo "ERROR can't find flac executable" 1>&2 && exit 1)
25 if [ $? != 0 ] ; then exit 1 ; fi
26
27 echo "Generating streams..."
28 if test_streams ; then : ; else
29         echo "ERROR during test_streams" 1>&2
30         exit 1
31 fi
32
33 echo "Checking for --ogg support in flac..."
34 if flac --ogg wacky1.wav 1>/dev/null 2>&1 ; then
35         has_ogg=yes;
36         echo "flac --ogg works"
37 else
38         has_ogg=no;
39         echo "flac --ogg doesn't work"
40 fi
41
42 #
43 # multi-file tests
44 #
45 echo "Generating multiple input files from noise..."
46 if flac --verify --silent --force-raw-input --endian=big --sample-rate=44100 --bps=16 --channels=2 noise.raw ; then : ; else
47         echo "ERROR generating FLAC file" 1>&2
48         exit 1
49 fi
50 if flac --decode --silent noise.flac ; then : ; else
51         echo "ERROR generating WAVE file" 1>&2
52         exit 1
53 fi
54 rm -f noise.flac
55 mv noise.wav file0.wav
56 cp file0.wav file1.wav
57 cp file1.wav file2.wav
58
59 test_multifile ()
60 {
61         streamtype=$1
62         encode_options="$2"
63
64         if [ $streamtype = ogg ] ; then
65                 suffix=ogg
66                 encode_options="$encode_options --ogg"
67         else
68                 suffix=flac
69         fi
70
71         if flac $encode_options file0.wav file1.wav file2.wav ; then : ; else
72                 echo "ERROR" 1>&2
73                 exit 1
74         fi
75         for n in 0 1 2 ; do
76                 mv file$n.$suffix file${n}x.$suffix
77         done
78         if flac --decode file0x.$suffix file1x.$suffix file2x.$suffix ; then : ; else
79                 echo "ERROR" 1>&2
80                 exit 1
81         fi
82         for n in 0 1 2 ; do
83                 if cmp file$n.wav file${n}x.wav ; then : ; else
84                         echo "ERROR: file mismatch on file #$n" 1>&2
85                         exit 1
86                 fi
87         done
88         for n in 0 1 2 ; do
89                 rm -f file${n}x.$suffix file${n}x.wav
90         done
91 }
92
93 echo "Testing multiple files without verify..."
94 test_multifile flac ""
95
96 echo "Testing multiple files with verify..."
97 test_multifile flac "--verify"
98
99 #@@@@echo "Testing multiple files with --sector-align, without verify..."
100 #@@@@test_multifile flac "--sector-align"
101
102 #@@@@echo "Testing multiple files with --sector-align, with verify..."
103 #@@@@test_multifile flac "--sector-align --verify"
104
105 if [ $has_ogg = "yes" ] ; then
106         echo "Testing multiple files with --ogg, without verify..."
107         test_multifile ogg ""
108
109         echo "Testing multiple files with --ogg, with verify..."
110         test_multifile ogg "--verify"
111
112         #@@@@echo "Testing multiple files with --ogg and --sector-align, without verify..."
113         #@@@@test_multifile ogg "--sector-align"
114
115         #@@@@echo "Testing multiple files with --ogg and --sector-align, with verify..."
116         #@@@@test_multifile ogg "--sector-align --verify"
117 fi
118
119 #
120 # single-file tests
121 #
122
123 test_file ()
124 {
125         name=$1
126         channels=$2
127         bps=$3
128         encode_options="$4"
129
130         echo -n "$name: encode..."
131         cmd="flac --verify --silent --force-raw-input --endian=big --sample-rate=44100 --bps=$bps --channels=$channels $encode_options $name.raw"
132         echo "### ENCODE $name #######################################################" >> ./streams.log
133         echo "###    cmd=$cmd" >> ./streams.log
134         if $cmd 2>>./streams.log ; then : ; else
135                 echo "ERROR during encode of $name" 1>&2
136                 exit 1
137         fi
138         echo -n "decode..."
139         cmd="flac --silent --endian=big --decode --force-raw-input --output-name=$name.cmp $name.flac"
140         echo "### DECODE $name #######################################################" >> ./streams.log
141         echo "###    cmd=$cmd" >> ./streams.log
142         if $cmd 2>>./streams.log ; then : ; else
143                 echo "ERROR during decode of $name" 1>&2
144                 exit 1
145         fi
146         ls -1l $name.raw >> ./streams.log
147         ls -1l $name.flac >> ./streams.log
148         ls -1l $name.cmp >> ./streams.log
149         echo -n "compare..."
150         if cmp $name.raw $name.cmp ; then : ; else
151                 echo "ERROR during compare of $name" 1>&2
152                 exit 1
153         fi
154         echo OK
155 }
156
157 test_file_piped ()
158 {
159         name=$1
160         channels=$2
161         bps=$3
162         encode_options="$4"
163
164         if [ `env | grep -ic '^comspec='` != 0 ] ; then
165                 is_win=yes
166         else
167                 is_win=no
168         fi
169
170         echo -n "$name: encode via pipes..."
171         if [ $is_win = yes ] ; then
172                 cmd="flac --verify --silent --force-raw-input --endian=big --sample-rate=44100 --bps=$bps --channels=$channels $encode_options --stdout $name.raw"
173                 echo "### ENCODE $name #######################################################" >> ./streams.log
174                 echo "###    cmd=$cmd" >> ./streams.log
175                 if $cmd 1>$name.flac 2>>./streams.log ; then : ; else
176                         echo "ERROR during encode of $name" 1>&2
177                         exit 1
178                 fi
179         else
180                 cmd="flac --verify --silent --force-raw-input --endian=big --sample-rate=44100 --bps=$bps --channels=$channels $encode_options --stdout -"
181                 echo "### ENCODE $name #######################################################" >> ./streams.log
182                 echo "###    cmd=$cmd" >> ./streams.log
183                 if cat $name.raw | $cmd 1>$name.flac 2>>./streams.log ; then : ; else
184                         echo "ERROR during encode of $name" 1>&2
185                         exit 1
186                 fi
187         fi
188         echo -n "decode via pipes..."
189         if [ $is_win = yes ] ; then
190                 cmd="flac --silent --endian=big --decode --force-raw-input --stdout $name.flac"
191                 echo "### DECODE $name #######################################################" >> ./streams.log
192                 echo "###    cmd=$cmd" >> ./streams.log
193                 if $cmd 1>$name.cmp 2>>./streams.log ; then : ; else
194                         echo "ERROR during decode of $name" 1>&2
195                         exit 1
196                 fi
197         else
198                 cmd="flac --silent --endian=big --decode --force-raw-input --stdout -"
199                 echo "### DECODE $name #######################################################" >> ./streams.log
200                 echo "###    cmd=$cmd" >> ./streams.log
201                 if cat $name.flac | $cmd 1>$name.cmp 2>>./streams.log ; then : ; else
202                         echo "ERROR during decode of $name" 1>&2
203                         exit 1
204                 fi
205         fi
206         ls -1l $name.raw >> ./streams.log
207         ls -1l $name.flac >> ./streams.log
208         ls -1l $name.cmp >> ./streams.log
209         echo -n "compare..."
210         if cmp $name.raw $name.cmp ; then : ; else
211                 echo "ERROR during compare of $name" 1>&2
212                 exit 1
213         fi
214         echo OK
215 }
216
217 echo "Testing noise through pipes..."
218 test_file_piped noise 1 8 "-0"
219
220 echo "Testing small files..."
221 test_file test01 1 16 "-0 --max-lpc-order=16 --mid-side --exhaustive-model-search --qlp-coeff-precision-search"
222 test_file test02 2 16 "-0 --max-lpc-order=16 --mid-side --exhaustive-model-search --qlp-coeff-precision-search"
223 test_file test03 1 16 "-0 --max-lpc-order=16 --mid-side --exhaustive-model-search --qlp-coeff-precision-search"
224 test_file test04 2 16 "-0 --max-lpc-order=16 --mid-side --exhaustive-model-search --qlp-coeff-precision-search"
225
226 echo "Testing 8-bit full-scale deflection streams..."
227 for b in 01 02 03 04 05 06 07 ; do
228         test_file fsd8-$b 1 8 "-0 --max-lpc-order=16 --mid-side --exhaustive-model-search --qlp-coeff-precision-search"
229 done
230
231 echo "Testing 16-bit full-scale deflection streams..."
232 for b in 01 02 03 04 05 06 07 ; do
233         test_file fsd16-$b 1 16 "-0 --max-lpc-order=16 --mid-side --exhaustive-model-search --qlp-coeff-precision-search"
234 done
235
236 echo "Testing 24-bit full-scale deflection streams..."
237 for b in 01 02 03 04 05 06 07 ; do
238         test_file fsd24-$b 1 24 "-0 --max-lpc-order=16 --mid-side --exhaustive-model-search --qlp-coeff-precision-search"
239 done
240
241 echo "Testing 16-bit wasted-bits-per-sample streams..."
242 for b in 01 ; do
243         test_file wbps16-$b 1 16 "-0 --max-lpc-order=16 --mid-side --exhaustive-model-search --qlp-coeff-precision-search"
244 done
245
246 for bps in 16 24 ; do
247         echo "Testing $bps-bit sine wave streams..."
248         for b in 00 01 02 03 04 ; do
249                 test_file sine${bps}-$b 1 $bps "-0 --max-lpc-order=16 --mid-side --exhaustive-model-search"
250         done
251         for b in 10 11 12 13 14 15 16 17 18 19 ; do
252                 test_file sine${bps}-$b 2 $bps "-0 --max-lpc-order=16 --mid-side --exhaustive-model-search"
253         done
254 done
255
256 echo "Testing some frame header variations..."
257 test_file sine16-01 1 16 "-0 --max-lpc-order=8 --mid-side --exhaustive-model-search --qlp-coeff-precision-search --lax --blocksize=16"
258 test_file sine16-01 1 16 "-0 --max-lpc-order=8 --mid-side --exhaustive-model-search --qlp-coeff-precision-search --lax --blocksize=65535"
259 test_file sine16-01 1 16 "-0 --max-lpc-order=8 --mid-side --exhaustive-model-search --qlp-coeff-precision-search --blocksize=16"
260 test_file sine16-01 1 16 "-0 --max-lpc-order=8 --mid-side --exhaustive-model-search --qlp-coeff-precision-search --blocksize=65535"
261 test_file sine16-01 1 16 "-0 --max-lpc-order=8 --mid-side --exhaustive-model-search --qlp-coeff-precision-search --lax --sample-rate=9"
262 test_file sine16-01 1 16 "-0 --max-lpc-order=8 --mid-side --exhaustive-model-search --qlp-coeff-precision-search --lax --sample-rate=90"
263 test_file sine16-01 1 16 "-0 --max-lpc-order=8 --mid-side --exhaustive-model-search --qlp-coeff-precision-search --lax --sample-rate=90000"
264 test_file sine16-01 1 16 "-0 --max-lpc-order=8 --mid-side --exhaustive-model-search --qlp-coeff-precision-search --sample-rate=9"
265 test_file sine16-01 1 16 "-0 --max-lpc-order=8 --mid-side --exhaustive-model-search --qlp-coeff-precision-search --sample-rate=90"
266 test_file sine16-01 1 16 "-0 --max-lpc-order=8 --mid-side --exhaustive-model-search --qlp-coeff-precision-search --sample-rate=90000"
267
268 echo "Testing option variations..."
269 for f in 00 01 02 03 04 ; do
270         for opt in 0 1 2 4 5 6 8 ; do
271                 for extras in '' '--qlp-coeff-precision-search' '--exhaustive-model-search' ; do
272                         test_file sine16-$f 1 16 "-$opt $extras"
273                 done
274         done
275 done
276 for f in 10 11 12 13 14 15 16 17 18 19 ; do
277         for opt in 0 1 2 4 5 6 8 ; do
278                 for extras in '' '--qlp-coeff-precision-search' '--exhaustive-model-search' ; do
279                         test_file sine16-$f 2 16 "-$opt $extras"
280                 done
281         done
282 done
283
284 echo "Testing noise..."
285 for opt in 0 1 2 3 4 5 6 7 8 ; do
286         for extras in '' '--qlp-coeff-precision-search' '--exhaustive-model-search' ; do
287                 for blocksize in '' '--blocksize=32' '--blocksize=32768' '--blocksize=65535' ; do
288                         for channels in 1 2 4 8 ; do
289                                 for bps in 8 16 24 ; do
290                                         test_file noise $channels $bps "-$opt $extras $blocksize"
291                                 done
292                         done
293                 done
294         done
295 done