0713e06d4b2c3d3593c05b0bb4ba20e5868d989c
[platform/upstream/flac.git] / test / test_flac.sh
1 #!/bin/sh
2
3 #  FLAC - Free Lossless Audio Codec
4 #  Copyright (C) 2001,2002,2003,2004,2005  Josh Coalson
5 #
6 #  This file is part the FLAC project.  FLAC is comprised of several
7 #  components distributed under difference licenses.  The codec libraries
8 #  are distributed under Xiph.Org's BSD-like license (see the file
9 #  COPYING.Xiph in this distribution).  All other programs, libraries, and
10 #  plugins are distributed under the GPL (see COPYING.GPL).  The documentation
11 #  is distributed under the Gnu FDL (see COPYING.FDL).  Each file in the
12 #  FLAC distribution contains at the top the terms under which it may be
13 #  distributed.
14 #
15 #  Since this particular file is relevant to all components of FLAC,
16 #  it may be distributed under the Xiph.Org license, which is the least
17 #  restrictive of those mentioned above.  See the file COPYING.Xiph in this
18 #  distribution.
19
20 die ()
21 {
22         echo $* 1>&2
23         exit 1
24 }
25
26 if [ x = x"$1" ] ; then 
27         BUILD=debug
28 else
29         BUILD="$1"
30 fi
31
32 LD_LIBRARY_PATH=../src/libFLAC/.libs:$LD_LIBRARY_PATH
33 LD_LIBRARY_PATH=../src/libOggFLAC/.libs:$LD_LIBRARY_PATH
34 LD_LIBRARY_PATH=../src/share/grabbag/.libs:$LD_LIBRARY_PATH
35 LD_LIBRARY_PATH=../src/share/getopt/.libs:$LD_LIBRARY_PATH
36 LD_LIBRARY_PATH=../src/share/replaygain_analysis/.libs:$LD_LIBRARY_PATH
37 LD_LIBRARY_PATH=../src/share/replaygain_synthesis/.libs:$LD_LIBRARY_PATH
38 LD_LIBRARY_PATH=../src/share/utf8/.libs:$LD_LIBRARY_PATH
39 LD_LIBRARY_PATH=../obj/$BUILD/lib:$LD_LIBRARY_PATH
40 export LD_LIBRARY_PATH
41 PATH=../src/flac:$PATH
42 PATH=../src/metaflac:$PATH
43 PATH=../src/test_streams:$PATH
44 PATH=../obj/$BUILD/bin:$PATH
45
46 flac --help 1>/dev/null 2>/dev/null || die "ERROR can't find flac executable"
47
48 run_flac ()
49 {
50         if [ x"$FLAC__VALGRIND" = xyes ] ; then
51                 valgrind --leak-check=yes --show-reachable=yes --num-callers=100 --logfile-fd=4 flac $* 4>>test_flac.valgrind.log
52         else
53                 flac $*
54         fi
55 }
56
57 run_metaflac ()
58 {
59         if [ x"$FLAC__VALGRIND" = xyes ] ; then
60                 valgrind --leak-check=yes --show-reachable=yes --num-callers=100 --logfile-fd=4 metaflac $* 4>>test_flac.valgrind.log
61         else
62                 metaflac $*
63         fi
64 }
65
66 if [ `env | grep -ic '^comspec='` != 0 ] ; then
67         is_win=yes
68 else
69         is_win=no
70 fi
71
72 echo "Checking for --ogg support in flac..."
73 if flac --ogg --silent --force-raw-format --endian=little --sign=signed --channels=1 --bps=8 --sample-rate=44100 -c $0 1>/dev/null 2>&1 ; then
74         has_ogg=yes;
75         echo "flac --ogg works"
76 else
77         has_ogg=no;
78         echo "flac --ogg doesn't work"
79 fi
80
81
82 echo "Generating streams..."
83 if [ ! -f wacky1.wav ] ; then
84         test_streams || die "ERROR during test_streams"
85 fi
86
87 ############################################################################
88 # test that flac doesn't automatically overwrite files unless -f is used
89 ############################################################################
90
91 echo "Try encoding to a file that exists; should fail"
92 cp wacky1.wav exist.wav
93 touch exist.flac
94 if run_flac --totally-silent -0 exist.wav ; then
95         die "ERROR: it should have failed but didn't"
96 else
97         echo "OK, it failed as it should"
98 fi
99
100 echo "Try encoding with -f to a file that exists; should succeed"
101 if run_flac --totally-silent -0 --force exist.wav ; then
102         echo "OK, it succeeded as it should"
103 else
104         die "ERROR: it should have succeeded but didn't"
105 fi
106
107 echo "Try decoding to a file that exists; should fail"
108 if run_flac --totally-silent -d exist.flac ; then
109         die "ERROR: it should have failed but didn't"
110 else
111         echo "OK, it failed as it should"
112 fi
113
114 echo "Try decoding with -f to a file that exists; should succeed"
115 if run_flac --totally-silent -d -f exist.flac ; then
116         echo "OK, it succeeded as it should"
117 else
118         die "ERROR: it should have succeeded but didn't"
119 fi
120
121 rm -f exist.wav exist.flac
122
123 ############################################################################
124 # basic 'round-trip' tests of various kinds of streams
125 ############################################################################
126
127 rt_test_raw ()
128 {
129         f="$1"
130         channels=`echo $f | awk -F- '{print $2}'`
131         bytes_per_sample=`echo $f | awk -F- '{print $3}'`
132         bps=`expr $bytes_per_sample '*' 8`
133         echo -n "round-trip test ($f) encode... "
134         run_flac --silent --force --verify --force-raw-format --endian=little --sign=signed --sample-rate=44100 --bps=$bps --channels=$channels $f -o rt.flac || die "ERROR"
135         echo -n "decode... "
136         run_flac --silent --force --decode --force-raw-format --endian=little --sign=signed -o rt.raw rt.flac || die "ERROR"
137         echo -n "compare... "
138         cmp $f rt.raw || die "ERROR: file mismatch"
139         echo "OK"
140         rm -f rt.flac rt.raw
141 }
142
143 rt_test_wav ()
144 {
145         f="$1"
146         echo -n "round-trip test ($f) encode... "
147         run_flac --silent --force --verify $f -o rt.flac || die "ERROR"
148         echo -n "decode... "
149         run_flac --silent --force --decode -o rt.wav rt.flac || die "ERROR"
150         echo -n "compare... "
151         cmp $f rt.wav || die "ERROR: file mismatch"
152         echo "OK"
153         rm -f rt.flac rt.wav
154 }
155
156 rt_test_aiff ()
157 {
158         f="$1"
159         echo -n "round-trip test ($f) encode... "
160         run_flac --silent --force --verify $f -o rt.flac || die "ERROR"
161         echo -n "decode... "
162         run_flac --silent --force --decode -o rt.aiff rt.flac || die "ERROR"
163         echo -n "compare... "
164         cmp $f rt.aiff || die "ERROR: file mismatch"
165         echo "OK"
166         rm -f rt.flac rt.aiff
167 }
168
169 for f in rt-*.raw ; do
170         rt_test_raw $f
171 done
172 for f in rt-*.wav ; do
173         rt_test_wav $f
174 done
175 for f in rt-*.aiff ; do
176         rt_test_aiff $f
177 done
178
179 ############################################################################
180 # test --skip and --until
181 ############################################################################
182
183 #
184 # first make some chopped-up raw files
185 #
186 echo "abcdefghijklmnopqrstuvwxyz1234567890ABCDEFGHIJKLMN" > master.raw
187 dddie="die ERROR: creating files with dd"
188 dd if=master.raw ibs=1 count=50 of=50c.raw 2>/dev/null || $dddie
189 dd if=master.raw ibs=1 skip=10 count=40 of=50c.skip10.raw 2>/dev/null || $dddie
190 dd if=master.raw ibs=1 skip=11 count=39 of=50c.skip11.raw 2>/dev/null || $dddie
191 dd if=master.raw ibs=1 skip=20 count=30 of=50c.skip20.raw 2>/dev/null || $dddie
192 dd if=master.raw ibs=1 skip=30 count=20 of=50c.skip30.raw 2>/dev/null || $dddie
193 dd if=master.raw ibs=1 skip=40 count=10 of=50c.skip40.raw 2>/dev/null || $dddie
194 dd if=master.raw ibs=1 count=10 of=50c.until10.raw 2>/dev/null || $dddie
195 dd if=master.raw ibs=1 count=20 of=50c.until20.raw 2>/dev/null || $dddie
196 dd if=master.raw ibs=1 count=30 of=50c.until30.raw 2>/dev/null || $dddie
197 dd if=master.raw ibs=1 count=39 of=50c.until39.raw 2>/dev/null || $dddie
198 dd if=master.raw ibs=1 count=40 of=50c.until40.raw 2>/dev/null || $dddie
199 dd if=master.raw ibs=1 skip=10 count=20 of=50c.skip10.until30.raw 2>/dev/null || $dddie
200 dd if=master.raw ibs=1 skip=10 count=29 of=50c.skip10.until39.raw 2>/dev/null || $dddie
201 dd if=master.raw ibs=1 skip=10 count=30 of=50c.skip10.until40.raw 2>/dev/null || $dddie
202 dd if=master.raw ibs=1 skip=20 count=10 of=50c.skip20.until30.raw 2>/dev/null || $dddie
203 dd if=master.raw ibs=1 skip=20 count=20 of=50c.skip20.until40.raw 2>/dev/null || $dddie
204
205 wav_eopt="--silent --force --verify --lax"
206 wav_dopt="--silent --force --decode"
207
208 raw_eopt="$wav_eopt --force-raw-format --endian=big --sign=signed --sample-rate=10 --bps=8 --channels=1"
209 raw_dopt="$wav_dopt --force-raw-format --endian=big --sign=signed"
210
211 #
212 # convert them to WAVE and AIFF files
213 #
214 convert_to_wav ()
215 {
216         run_flac "$2" $1.raw || die "ERROR converting $1.raw to WAVE"
217         run_flac "$3" $1.flac || die "ERROR converting $1.raw to WAVE"
218 }
219 convert_to_wav 50c "$raw_eopt" "$wav_dopt"
220 convert_to_wav 50c.skip10 "$raw_eopt" "$wav_dopt"
221 convert_to_wav 50c.skip11 "$raw_eopt" "$wav_dopt"
222 convert_to_wav 50c.skip20 "$raw_eopt" "$wav_dopt"
223 convert_to_wav 50c.skip30 "$raw_eopt" "$wav_dopt"
224 convert_to_wav 50c.skip40 "$raw_eopt" "$wav_dopt"
225 convert_to_wav 50c.until10 "$raw_eopt" "$wav_dopt"
226 convert_to_wav 50c.until20 "$raw_eopt" "$wav_dopt"
227 convert_to_wav 50c.until30 "$raw_eopt" "$wav_dopt"
228 convert_to_wav 50c.until39 "$raw_eopt" "$wav_dopt"
229 convert_to_wav 50c.until40 "$raw_eopt" "$wav_dopt"
230 convert_to_wav 50c.skip10.until30 "$raw_eopt" "$wav_dopt"
231 convert_to_wav 50c.skip10.until39 "$raw_eopt" "$wav_dopt"
232 convert_to_wav 50c.skip10.until40 "$raw_eopt" "$wav_dopt"
233 convert_to_wav 50c.skip20.until30 "$raw_eopt" "$wav_dopt"
234 convert_to_wav 50c.skip20.until40 "$raw_eopt" "$wav_dopt"
235
236 convert_to_aiff ()
237 {
238         run_flac "$2" $1.raw || die "ERROR converting $1.raw to AIFF"
239         run_flac "$3" $1.flac -o $1.aiff || die "ERROR converting $1.raw to AIFF"
240 }
241 convert_to_aiff 50c "$raw_eopt" "$wav_dopt"
242 convert_to_aiff 50c.skip10 "$raw_eopt" "$wav_dopt"
243 convert_to_aiff 50c.skip11 "$raw_eopt" "$wav_dopt"
244 convert_to_aiff 50c.skip20 "$raw_eopt" "$wav_dopt"
245 convert_to_aiff 50c.skip30 "$raw_eopt" "$wav_dopt"
246 convert_to_aiff 50c.skip40 "$raw_eopt" "$wav_dopt"
247 convert_to_aiff 50c.until10 "$raw_eopt" "$wav_dopt"
248 convert_to_aiff 50c.until20 "$raw_eopt" "$wav_dopt"
249 convert_to_aiff 50c.until30 "$raw_eopt" "$wav_dopt"
250 convert_to_aiff 50c.until39 "$raw_eopt" "$wav_dopt"
251 convert_to_aiff 50c.until40 "$raw_eopt" "$wav_dopt"
252 convert_to_aiff 50c.skip10.until30 "$raw_eopt" "$wav_dopt"
253 convert_to_aiff 50c.skip10.until39 "$raw_eopt" "$wav_dopt"
254 convert_to_aiff 50c.skip10.until40 "$raw_eopt" "$wav_dopt"
255 convert_to_aiff 50c.skip20.until30 "$raw_eopt" "$wav_dopt"
256 convert_to_aiff 50c.skip20.until40 "$raw_eopt" "$wav_dopt"
257
258 test_skip_until ()
259 {
260         in_fmt=$1
261         out_fmt=$2
262
263         [ "$in_fmt" = wav ] || [ "$in_fmt" = aiff ] || [ "$in_fmt" = raw ] || die "ERROR: internal error, bad 'in' format '$in_fmt'"
264
265         [ "$out_fmt" = flac ] || [ "$out_fmt" = ogg ] || die "ERROR: internal error, bad 'out' format '$out_fmt'"
266
267         if [ $in_fmt = raw ] ; then
268                 eopt="$raw_eopt"
269                 dopt="$raw_dopt"
270         else
271                 eopt="$wav_eopt"
272                 dopt="$wav_dopt"
273         fi
274
275         if [ $out_fmt = ogg ] ; then
276                 eopt="--ogg $eopt"
277         fi
278
279         #
280         # test --skip when encoding
281         #
282
283         desc="($in_fmt<->$out_fmt)"
284
285         echo -n "testing --skip=# (encode) $desc... "
286         run_flac $eopt --skip=10 -o z50c.skip10.$out_fmt 50c.$in_fmt || die "ERROR generating FLAC file $desc"
287         run_flac $dopt -o z50c.skip10.$in_fmt z50c.skip10.$out_fmt || die "ERROR decoding FLAC file $desc"
288         cmp 50c.skip10.$in_fmt z50c.skip10.$in_fmt || die "ERROR: file mismatch for --skip=10 (encode) $desc"
289         rm -f z50c.skip10.$out_fmt z50c.skip10.$in_fmt
290         echo OK
291
292         echo -n "testing --skip=mm:ss (encode) $desc... "
293         run_flac $eopt --skip=0:01 -o z50c.skip0:01.$out_fmt 50c.$in_fmt || die "ERROR generating FLAC file $desc"
294         run_flac $dopt -o z50c.skip0:01.$in_fmt z50c.skip0:01.$out_fmt || die "ERROR decoding FLAC file $desc"
295         cmp 50c.skip10.$in_fmt z50c.skip0:01.$in_fmt || die "ERROR: file mismatch for --skip=0:01 (encode) $desc"
296         rm -f z50c.skip0:01.$out_fmt z50c.skip0:01.$in_fmt
297         echo OK
298
299         echo -n "testing --skip=mm:ss.sss (encode) $desc... "
300         run_flac $eopt --skip=0:01.1001 -o z50c.skip0:01.1001.$out_fmt 50c.$in_fmt || die "ERROR generating FLAC file $desc"
301         run_flac $dopt -o z50c.skip0:01.1001.$in_fmt z50c.skip0:01.1001.$out_fmt || die "ERROR decoding FLAC file $desc"
302         cmp 50c.skip11.$in_fmt z50c.skip0:01.1001.$in_fmt || die "ERROR: file mismatch for --skip=0:01.1001 (encode) $desc"
303         rm -f z50c.skip0:01.1001.$out_fmt z50c.skip0:01.1001.$in_fmt
304         echo OK
305
306         #
307         # test --skip when decoding
308         #
309
310         echo -n "testing --skip=# (decode) $desc... "
311         run_flac $eopt -o z50c.$out_fmt 50c.$in_fmt || die "ERROR generating FLAC file $desc"
312         run_flac $dopt --skip=10 -o z50c.skip10.$in_fmt z50c.$out_fmt || die "ERROR decoding FLAC file $desc"
313         cmp 50c.skip10.$in_fmt z50c.skip10.$in_fmt || die "ERROR: file mismatch for --skip=10 (decode) $desc"
314         rm -f z50c.skip10.$in_fmt
315         echo OK
316
317         echo -n "testing --skip=mm:ss (decode) $desc... "
318         run_flac $dopt --skip=0:01 -o z50c.skip0:01.$in_fmt z50c.$out_fmt || die "ERROR decoding FLAC file $desc"
319         cmp 50c.skip10.$in_fmt z50c.skip0:01.$in_fmt || die "ERROR: file mismatch for --skip=0:01 (decode) $desc"
320         rm -f z50c.skip0:01.$in_fmt
321         echo OK
322
323         echo -n "testing --skip=mm:ss.sss (decode) $desc... "
324         run_flac $dopt --skip=0:01.1001 -o z50c.skip0:01.1001.$in_fmt z50c.$out_fmt || die "ERROR decoding FLAC file $desc"
325         cmp 50c.skip11.$in_fmt z50c.skip0:01.1001.$in_fmt || die "ERROR: file mismatch for --skip=0:01.1001 (decode) $desc"
326         rm -f z50c.skip0:01.1001.$in_fmt
327         echo OK
328
329         rm -f z50c.$out_fmt
330
331         #
332         # test --until when encoding
333         #
334
335         echo -n "testing --until=# (encode) $desc... "
336         run_flac $eopt --until=40 -o z50c.until40.$out_fmt 50c.$in_fmt || die "ERROR generating FLAC file $desc"
337         run_flac $dopt -o z50c.until40.$in_fmt z50c.until40.$out_fmt || die "ERROR decoding FLAC file $desc"
338         cmp 50c.until40.$in_fmt z50c.until40.$in_fmt || die "ERROR: file mismatch for --until=40 (encode) $desc"
339         rm -f z50c.until40.$out_fmt z50c.until40.$in_fmt
340         echo OK
341
342         echo -n "testing --until=mm:ss (encode) $desc... "
343         run_flac $eopt --until=0:04 -o z50c.until0:04.$out_fmt 50c.$in_fmt || die "ERROR generating FLAC file $desc"
344         run_flac $dopt -o z50c.until0:04.$in_fmt z50c.until0:04.$out_fmt || die "ERROR decoding FLAC file $desc"
345         cmp 50c.until40.$in_fmt z50c.until0:04.$in_fmt || die "ERROR: file mismatch for --until=0:04 (encode) $desc"
346         rm -f z50c.until0:04.$out_fmt z50c.until0:04.$in_fmt
347         echo OK
348
349         echo -n "testing --until=mm:ss.sss (encode) $desc... "
350         run_flac $eopt --until=0:03.9001 -o z50c.until0:03.9001.$out_fmt 50c.$in_fmt || die "ERROR generating FLAC file $desc"
351         run_flac $dopt -o z50c.until0:03.9001.$in_fmt z50c.until0:03.9001.$out_fmt || die "ERROR decoding FLAC file $desc"
352         cmp 50c.until39.$in_fmt z50c.until0:03.9001.$in_fmt || die "ERROR: file mismatch for --until=0:03.9001 (encode) $desc"
353         rm -f z50c.until0:03.9001.$out_fmt z50c.until0:03.9001.$in_fmt
354         echo OK
355
356         echo -n "testing --until=-# (encode) $desc... "
357         run_flac $eopt --until=-10 -o z50c.until-10.$out_fmt 50c.$in_fmt || die "ERROR generating FLAC file $desc"
358         run_flac $dopt -o z50c.until-10.$in_fmt z50c.until-10.$out_fmt || die "ERROR decoding FLAC file $desc"
359         cmp 50c.until40.$in_fmt z50c.until-10.$in_fmt || die "ERROR: file mismatch for --until=-10 (encode) $desc"
360         rm -f z50c.until-10.$out_fmt z50c.until-10.$in_fmt
361         echo OK
362
363         echo -n "testing --until=-mm:ss (encode) $desc... "
364         run_flac $eopt --until=-0:01 -o z50c.until-0:01.$out_fmt 50c.$in_fmt || die "ERROR generating FLAC file $desc"
365         run_flac $dopt -o z50c.until-0:01.$in_fmt z50c.until-0:01.$out_fmt || die "ERROR decoding FLAC file $desc"
366         cmp 50c.until40.$in_fmt z50c.until-0:01.$in_fmt || die "ERROR: file mismatch for --until=-0:01 (encode) $desc"
367         rm -f z50c.until-0:01.$out_fmt z50c.until-0:01.$in_fmt
368         echo OK
369
370         echo -n "testing --until=-mm:ss.sss (encode) $desc... "
371         run_flac $eopt --until=-0:01.1001 -o z50c.until-0:01.1001.$out_fmt 50c.$in_fmt || die "ERROR generating FLAC file $desc"
372         run_flac $dopt -o z50c.until-0:01.1001.$in_fmt z50c.until-0:01.1001.$out_fmt || die "ERROR decoding FLAC file $desc"
373         cmp 50c.until39.$in_fmt z50c.until-0:01.1001.$in_fmt || die "ERROR: file mismatch for --until=-0:01.1001 (encode) $desc"
374         rm -f z50c.until-0:01.1001.$out_fmt z50c.until-0:01.1001.$in_fmt
375         echo OK
376
377         #
378         # test --until when decoding
379         #
380
381         run_flac $eopt -o z50c.$out_fmt 50c.$in_fmt || die "ERROR generating FLAC file $desc"
382
383         echo -n "testing --until=# (decode) $desc... "
384         run_flac $dopt --until=40 -o z50c.until40.$in_fmt z50c.$out_fmt || die "ERROR decoding FLAC file $desc"
385         cmp 50c.until40.$in_fmt z50c.until40.$in_fmt || die "ERROR: file mismatch for --until=40 (decode) $desc"
386         rm -f z50c.until40.$in_fmt
387         echo OK
388
389         echo -n "testing --until=mm:ss (decode) $desc... "
390         run_flac $dopt --until=0:04 -o z50c.until0:04.$in_fmt z50c.$out_fmt || die "ERROR decoding FLAC file $desc"
391         cmp 50c.until40.$in_fmt z50c.until0:04.$in_fmt || die "ERROR: file mismatch for --until=0:04 (decode) $desc"
392         rm -f z50c.until0:04.$in_fmt
393         echo OK
394
395         echo -n "testing --until=mm:ss.sss (decode) $desc... "
396         run_flac $dopt --until=0:03.9001 -o z50c.until0:03.9001.$in_fmt z50c.$out_fmt || die "ERROR decoding FLAC file $desc"
397         cmp 50c.until39.$in_fmt z50c.until0:03.9001.$in_fmt || die "ERROR: file mismatch for --until=0:03.9001 (decode) $desc"
398         rm -f z50c.until0:03.9001.$in_fmt
399         echo OK
400
401         echo -n "testing --until=-# (decode) $desc... "
402         run_flac $dopt --until=-10 -o z50c.until-10.$in_fmt z50c.$out_fmt || die "ERROR decoding FLAC file $desc"
403         cmp 50c.until40.$in_fmt z50c.until-10.$in_fmt || die "ERROR: file mismatch for --until=-10 (decode) $desc"
404         rm -f z50c.until-10.$in_fmt
405         echo OK
406
407         echo -n "testing --until=-mm:ss (decode) $desc... "
408         run_flac $dopt --until=-0:01 -o z50c.until-0:01.$in_fmt z50c.$out_fmt || die "ERROR decoding FLAC file $desc"
409         cmp 50c.until40.$in_fmt z50c.until-0:01.$in_fmt || die "ERROR: file mismatch for --until=-0:01 (decode) $desc"
410         rm -f z50c.until-0:01.$in_fmt
411         echo OK
412
413         echo -n "testing --until=-mm:ss.sss (decode) $desc... "
414         run_flac $dopt --until=-0:01.1001 -o z50c.until-0:01.1001.$in_fmt z50c.$out_fmt || die "ERROR decoding FLAC file $desc"
415         cmp 50c.until39.$in_fmt z50c.until-0:01.1001.$in_fmt || die "ERROR: file mismatch for --until=-0:01.1001 (decode) $desc"
416         rm -f z50c.until-0:01.1001.$in_fmt
417         echo OK
418
419         rm -f z50c.$out_fmt
420
421         #
422         # test --skip and --until when encoding
423         #
424
425         echo -n "testing --skip=10 --until=# (encode) $desc... "
426         run_flac $eopt --skip=10 --until=40 -o z50c.skip10.until40.$out_fmt 50c.$in_fmt || die "ERROR generating FLAC file $desc"
427         run_flac $dopt -o z50c.skip10.until40.$in_fmt z50c.skip10.until40.$out_fmt || die "ERROR decoding FLAC file $desc"
428         cmp 50c.skip10.until40.$in_fmt z50c.skip10.until40.$in_fmt || die "ERROR: file mismatch for --skip=10 --until=40 (encode) $desc"
429         rm -f z50c.skip10.until40.$out_fmt z50c.skip10.until40.$in_fmt
430         echo OK
431
432         echo -n "testing --skip=10 --until=mm:ss (encode) $desc... "
433         run_flac $eopt --skip=10 --until=0:04 -o z50c.skip10.until0:04.$out_fmt 50c.$in_fmt || die "ERROR generating FLAC file $desc"
434         run_flac $dopt -o z50c.skip10.until0:04.$in_fmt z50c.skip10.until0:04.$out_fmt || die "ERROR decoding FLAC file $desc"
435         cmp 50c.skip10.until40.$in_fmt z50c.skip10.until0:04.$in_fmt || die "ERROR: file mismatch for --skip=10 --until=0:04 (encode) $desc"
436         rm -f z50c.skip10.until0:04.$out_fmt z50c.skip10.until0:04.$in_fmt
437         echo OK
438
439         echo -n "testing --skip=10 --until=mm:ss.sss (encode) $desc... "
440         run_flac $eopt --skip=10 --until=0:03.9001 -o z50c.skip10.until0:03.9001.$out_fmt 50c.$in_fmt || die "ERROR generating FLAC file $desc"
441         run_flac $dopt -o z50c.skip10.until0:03.9001.$in_fmt z50c.skip10.until0:03.9001.$out_fmt || die "ERROR decoding FLAC file $desc"
442         cmp 50c.skip10.until39.$in_fmt z50c.skip10.until0:03.9001.$in_fmt || die "ERROR: file mismatch for --skip=10 --until=0:03.9001 (encode) $desc"
443         rm -f z50c.skip10.until0:03.9001.$out_fmt z50c.skip10.until0:03.9001.$in_fmt
444         echo OK
445
446         echo -n "testing --skip=10 --until=+# (encode) $desc... "
447         run_flac $eopt --skip=10 --until=+30 -o z50c.skip10.until+30.$out_fmt 50c.$in_fmt || die "ERROR generating FLAC file $desc"
448         run_flac $dopt -o z50c.skip10.until+30.$in_fmt z50c.skip10.until+30.$out_fmt || die "ERROR decoding FLAC file $desc"
449         cmp 50c.skip10.until40.$in_fmt z50c.skip10.until+30.$in_fmt || die "ERROR: file mismatch for --skip=10 --until=+30 (encode) $desc"
450         rm -f z50c.skip10.until+30.$out_fmt z50c.skip10.until+30.$in_fmt
451         echo OK
452
453         echo -n "testing --skip=10 --until=+mm:ss (encode) $desc... "
454         run_flac $eopt --skip=10 --until=+0:03 -o z50c.skip10.until+0:03.$out_fmt 50c.$in_fmt || die "ERROR generating FLAC file $desc"
455         run_flac $dopt -o z50c.skip10.until+0:03.$in_fmt z50c.skip10.until+0:03.$out_fmt || die "ERROR decoding FLAC file $desc"
456         cmp 50c.skip10.until40.$in_fmt z50c.skip10.until+0:03.$in_fmt || die "ERROR: file mismatch for --skip=10 --until=+0:03 (encode) $desc"
457         rm -f z50c.skip10.until+0:03.$out_fmt z50c.skip10.until+0:03.$in_fmt
458         echo OK
459
460         echo -n "testing --skip=10 --until=+mm:ss.sss (encode) $desc... "
461         run_flac $eopt --skip=10 --until=+0:02.9001 -o z50c.skip10.until+0:02.9001.$out_fmt 50c.$in_fmt || die "ERROR generating FLAC file $desc"
462         run_flac $dopt -o z50c.skip10.until+0:02.9001.$in_fmt z50c.skip10.until+0:02.9001.$out_fmt || die "ERROR decoding FLAC file $desc"
463         cmp 50c.skip10.until39.$in_fmt z50c.skip10.until+0:02.9001.$in_fmt || die "ERROR: file mismatch for --skip=10 --until=+0:02.9001 (encode) $desc"
464         rm -f z50c.skip10.until+0:02.9001.$out_fmt z50c.skip10.until+0:02.9001.$in_fmt
465         echo OK
466
467         echo -n "testing --skip=10 --until=-# (encode) $desc... "
468         run_flac $eopt --skip=10 --until=-10 -o z50c.skip10.until-10.$out_fmt 50c.$in_fmt || die "ERROR generating FLAC file $desc"
469         run_flac $dopt -o z50c.skip10.until-10.$in_fmt z50c.skip10.until-10.$out_fmt || die "ERROR decoding FLAC file $desc"
470         cmp 50c.skip10.until40.$in_fmt z50c.skip10.until-10.$in_fmt || die "ERROR: file mismatch for --skip=10 --until=-10 (encode) $desc"
471         rm -f z50c.skip10.until-10.$out_fmt z50c.skip10.until-10.$in_fmt
472         echo OK
473
474         echo -n "testing --skip=10 --until=-mm:ss (encode) $desc... "
475         run_flac $eopt --skip=10 --until=-0:01 -o z50c.skip10.until-0:01.$out_fmt 50c.$in_fmt || die "ERROR generating FLAC file $desc"
476         run_flac $dopt -o z50c.skip10.until-0:01.$in_fmt z50c.skip10.until-0:01.$out_fmt || die "ERROR decoding FLAC file $desc"
477         cmp 50c.skip10.until40.$in_fmt z50c.skip10.until-0:01.$in_fmt || die "ERROR: file mismatch for --skip=10 --until=-0:01 (encode) $desc"
478         rm -f z50c.skip10.until-0:01.$out_fmt z50c.skip10.until-0:01.$in_fmt
479         echo OK
480
481         echo -n "testing --skip=10 --until=-mm:ss.sss (encode) $desc... "
482         run_flac $eopt --skip=10 --until=-0:01.1001 -o z50c.skip10.until-0:01.1001.$out_fmt 50c.$in_fmt || die "ERROR generating FLAC file $desc"
483         run_flac $dopt -o z50c.skip10.until-0:01.1001.$in_fmt z50c.skip10.until-0:01.1001.$out_fmt || die "ERROR decoding FLAC file $desc"
484         cmp 50c.skip10.until39.$in_fmt z50c.skip10.until-0:01.1001.$in_fmt || die "ERROR: file mismatch for --skip=10 --until=-0:01.1001 (encode) $desc"
485         rm -f z50c.skip10.until-0:01.1001.$out_fmt z50c.skip10.until-0:01.1001.$in_fmt
486         echo OK
487
488         #
489         # test --skip and --until when decoding
490         #
491
492         run_flac $eopt -o z50c.$out_fmt 50c.$in_fmt || die "ERROR generating FLAC file $desc"
493
494         echo -n "testing --skip=10 --until=# (decode) $desc... "
495         run_flac $dopt --skip=10 --until=40 -o z50c.skip10.until40.$in_fmt z50c.$out_fmt || die "ERROR decoding FLAC file $desc"
496         cmp 50c.skip10.until40.$in_fmt z50c.skip10.until40.$in_fmt || die "ERROR: file mismatch for --skip=10 --until=40 (decode) $desc"
497         rm -f z50c.skip10.until40.$in_fmt
498         echo OK
499
500         echo -n "testing --skip=10 --until=mm:ss (decode) $desc... "
501         run_flac $dopt --skip=10 --until=0:04 -o z50c.skip10.until0:04.$in_fmt z50c.$out_fmt || die "ERROR decoding FLAC file $desc"
502         cmp 50c.skip10.until40.$in_fmt z50c.skip10.until0:04.$in_fmt || die "ERROR: file mismatch for --skip=10 --until=0:04 (decode) $desc"
503         rm -f z50c.skip10.until0:04.$in_fmt
504         echo OK
505
506         echo -n "testing --skip=10 --until=mm:ss.sss (decode) $desc... "
507         run_flac $dopt --skip=10 --until=0:03.9001 -o z50c.skip10.until0:03.9001.$in_fmt z50c.$out_fmt || die "ERROR decoding FLAC file $desc"
508         cmp 50c.skip10.until39.$in_fmt z50c.skip10.until0:03.9001.$in_fmt || die "ERROR: file mismatch for --skip=10 --until=0:03.9001 (decode) $desc"
509         rm -f z50c.skip10.until0:03.9001.$in_fmt
510         echo OK
511
512         echo -n "testing --skip=10 --until=-# (decode) $desc... "
513         run_flac $dopt --skip=10 --until=-10 -o z50c.skip10.until-10.$in_fmt z50c.$out_fmt || die "ERROR decoding FLAC file $desc"
514         cmp 50c.skip10.until40.$in_fmt z50c.skip10.until-10.$in_fmt || die "ERROR: file mismatch for --skip=10 --until=-10 (decode) $desc"
515         rm -f z50c.skip10.until-10.$in_fmt
516         echo OK
517
518         echo -n "testing --skip=10 --until=-mm:ss (decode) $desc... "
519         run_flac $dopt --skip=10 --until=-0:01 -o z50c.skip10.until-0:01.$in_fmt z50c.$out_fmt || die "ERROR decoding FLAC file $desc"
520         cmp 50c.skip10.until40.$in_fmt z50c.skip10.until-0:01.$in_fmt || die "ERROR: file mismatch for --skip=10 --until=-0:01 (decode) $desc"
521         rm -f z50c.skip10.until-0:01.$in_fmt
522         echo OK
523
524         echo -n "testing --skip=10 --until=-mm:ss.sss (decode) $desc... "
525         run_flac $dopt --skip=10 --until=-0:01.1001 -o z50c.skip10.until-0:01.1001.$in_fmt z50c.$out_fmt || die "ERROR decoding FLAC file $desc"
526         cmp 50c.skip10.until39.$in_fmt z50c.skip10.until-0:01.1001.$in_fmt || die "ERROR: file mismatch for --skip=10 --until=-0:01.1001 (decode) $desc"
527         rm -f z50c.skip10.until-0:01.1001.$in_fmt
528         echo OK
529
530         rm -f z50c.$out_fmt
531 }
532
533 test_skip_until raw flac
534 test_skip_until wav flac
535 test_skip_until aiff flac
536
537 if [ $has_ogg = "yes" ] ; then
538         test_skip_until raw ogg
539         test_skip_until wav ogg
540         test_skip_until aiff ogg
541 fi
542
543 echo "testing seek extremes:"
544
545 run_flac --verify --force --silent --force-raw-format --endian=big --sign=signed --sample-rate=44100 --bps=16 --channels=2 --blocksize=576 noise.raw || die "ERROR generating FLAC file"
546
547 if [ $is_win = no ] ; then
548         total_noise_cdda_samples=`run_metaflac --show-total-samples noise.flac`
549         [ $? = 0 ] || die "ERROR getting total sample count from noise.flac"
550 else
551         # some flavors of cygwin don't seem to treat the \x0d as a word
552         # separator, so we hard code it.  we'll just have to fix it later
553         # if we change the way noise.flac is made.
554         total_noise_cdda_samples=393216
555 fi
556
557 echo -n "testing --skip=0... "
558 run_flac $wav_dopt --skip=0 -o z.wav noise.flac || die "ERROR decoding FLAC file noise.flac"
559 echo OK
560
561 for delta in 2 1 ; do
562         n=`expr $total_noise_cdda_samples - $delta`
563         echo -n "testing --skip=$n... "
564         run_flac $wav_dopt --skip=$n -o z.wav noise.flac || die "ERROR decoding FLAC file noise.flac"
565         echo OK
566 done
567
568 rm noise.flac z.wav
569
570
571 ############################################################################
572 # test --input-size
573 ############################################################################
574
575 #@@@@@@ cat will not work on old cygwin, need to fix
576 if [ $is_win = no ] ; then
577         echo -n "testing --input-size=50 --skip=10... "
578         cat 50c.raw | run_flac $raw_eopt --input-size=50 --skip=10 -o z50c.skip10.flac - || die "ERROR generating FLAC file"
579         run_flac $raw_dopt -o z50c.skip10.raw z50c.skip10.flac || die "ERROR decoding FLAC file"
580         cmp 50c.skip10.raw z50c.skip10.raw || die "ERROR: file mismatch for --input-size=50 --skip=10"
581         rm -f z50c.skip10.raw z50c.skip10.flac
582         echo OK
583 fi
584
585
586 ############################################################################
587 # test --skip and --until
588 ############################################################################
589
590 ############################################################################
591 # test --cue
592 ############################################################################
593
594 #
595 # create the cue sheet
596 #
597 cuesheet=cuetest.cue
598 cat > $cuesheet << EOF
599 CATALOG 1234567890123
600 FILE "blah" WAVE
601   TRACK 01 AUDIO
602     INDEX 01 0
603     INDEX 02 10
604     INDEX 03 20
605   TRACK 02 AUDIO
606     INDEX 01 30
607   TRACK 04 AUDIO
608     INDEX 01 40
609 EOF
610
611 test_cue ()
612 {
613         in_fmt=$1
614         out_fmt=$2
615
616         [ "$in_fmt" = wav ] || [ "$in_fmt" = aiff ] || [ "$in_fmt" = raw ] || die "ERROR: internal error, bad 'in' format '$in_fmt'"
617
618         [ "$out_fmt" = flac ] || [ "$out_fmt" = ogg ] || die "ERROR: internal error, bad 'out' format '$out_fmt'"
619
620         if [ $in_fmt = raw ] ; then
621                 eopt="$raw_eopt"
622                 dopt="$raw_dopt"
623         else
624                 eopt="$wav_eopt"
625                 dopt="$wav_dopt"
626         fi
627
628         if [ $out_fmt = ogg ] ; then
629                 eopt="--ogg $eopt"
630         fi
631
632         desc="($in_fmt<->$out_fmt)"
633
634         #
635         # for this we need just need just one FLAC file; --cue only works while decoding
636         #
637         run_flac $eopt --cuesheet=$cuesheet -o z50c.cue.$out_fmt 50c.$in_fmt || die "ERROR generating FLAC file $desc"
638
639         # To make it easy to translate from cue point to sample numbers, the
640         # file has a sample rate of 10 Hz and a cuesheet like so:
641         #
642         # TRACK 01, INDEX 01 : 0:00.00 -> sample 0
643         # TRACK 01, INDEX 02 : 0:01.00 -> sample 10
644         # TRACK 01, INDEX 03 : 0:02.00 -> sample 20
645         # TRACK 02, INDEX 01 : 0:03.00 -> sample 30
646         # TRACK 04, INDEX 01 : 0:04.00 -> sample 40
647         #
648         echo -n "testing --cue=- $desc... "
649         run_flac $dopt -o z50c.cue.$in_fmt --cue=- z50c.cue.$out_fmt || die "ERROR decoding FLAC file $desc"
650         cmp 50c.$in_fmt z50c.cue.$in_fmt || die "ERROR: file mismatch for --cue=- $desc"
651         rm -f z50c.cue.$in_fmt
652         echo OK
653
654         echo -n "testing --cue=1.0 $desc... "
655         run_flac $dopt -o z50c.cue.$in_fmt --cue=1.0 z50c.cue.$out_fmt || die "ERROR decoding FLAC file $desc"
656         cmp 50c.$in_fmt z50c.cue.$in_fmt || die "ERROR: file mismatch for --cue=1.0 $desc"
657         rm -f z50c.cue.$in_fmt
658         echo OK
659
660         echo -n "testing --cue=1.0- $desc... "
661         run_flac $dopt -o z50c.cue.$in_fmt --cue=1.0- z50c.cue.$out_fmt || die "ERROR decoding FLAC file $desc"
662         cmp 50c.$in_fmt z50c.cue.$in_fmt || die "ERROR: file mismatch for --cue=1.0- $desc"
663         rm -f z50c.cue.$in_fmt
664         echo OK
665
666         echo -n "testing --cue=1.1 $desc... "
667         run_flac $dopt -o z50c.cue.$in_fmt --cue=1.1 z50c.cue.$out_fmt || die "ERROR decoding FLAC file $desc"
668         cmp 50c.$in_fmt z50c.cue.$in_fmt || die "ERROR: file mismatch for --cue=1.1 $desc"
669         rm -f z50c.cue.$in_fmt
670         echo OK
671
672         echo -n "testing --cue=1.1- $desc... "
673         run_flac $dopt -o z50c.cue.$in_fmt --cue=1.1- z50c.cue.$out_fmt || die "ERROR decoding FLAC file $desc"
674         cmp 50c.$in_fmt z50c.cue.$in_fmt || die "ERROR: file mismatch for --cue=1.1- $desc"
675         rm -f z50c.cue.$in_fmt
676         echo OK
677
678         echo -n "testing --cue=1.2 $desc... "
679         run_flac $dopt -o z50c.cue.$in_fmt --cue=1.2 z50c.cue.$out_fmt || die "ERROR decoding FLAC file $desc"
680         cmp 50c.skip10.$in_fmt z50c.cue.$in_fmt || die "ERROR: file mismatch for --cue=1.2 $desc"
681         rm -f z50c.cue.$in_fmt
682         echo OK
683
684         echo -n "testing --cue=1.2- $desc... "
685         run_flac $dopt -o z50c.cue.$in_fmt --cue=1.2- z50c.cue.$out_fmt || die "ERROR decoding FLAC file $desc"
686         cmp 50c.skip10.$in_fmt z50c.cue.$in_fmt || die "ERROR: file mismatch for --cue=1.2- $desc"
687         rm -f z50c.cue.$in_fmt
688         echo OK
689
690         echo -n "testing --cue=1.4 $desc... "
691         run_flac $dopt -o z50c.cue.$in_fmt --cue=1.4 z50c.cue.$out_fmt || die "ERROR decoding FLAC file $desc"
692         cmp 50c.skip20.$in_fmt z50c.cue.$in_fmt || die "ERROR: file mismatch for --cue=1.4 $desc"
693         rm -f z50c.cue.$in_fmt
694         echo OK
695
696         echo -n "testing --cue=1.4- $desc... "
697         run_flac $dopt -o z50c.cue.$in_fmt --cue=1.4- z50c.cue.$out_fmt || die "ERROR decoding FLAC file $desc"
698         cmp 50c.skip20.$in_fmt z50c.cue.$in_fmt || die "ERROR: file mismatch for --cue=1.4- $desc"
699         rm -f z50c.cue.$in_fmt
700         echo OK
701
702         echo -n "testing --cue=-5.0 $desc... "
703         run_flac $dopt -o z50c.cue.$in_fmt --cue=-5.0 z50c.cue.$out_fmt || die "ERROR decoding FLAC file $desc"
704         cmp 50c.$in_fmt z50c.cue.$in_fmt || die "ERROR: file mismatch for --cue=-5.0 $desc"
705         rm -f z50c.cue.$in_fmt
706         echo OK
707
708         echo -n "testing --cue=-4.1 $desc... "
709         run_flac $dopt -o z50c.cue.$in_fmt --cue=-4.1 z50c.cue.$out_fmt || die "ERROR decoding FLAC file $desc"
710         cmp 50c.until40.$in_fmt z50c.cue.$in_fmt || die "ERROR: file mismatch for --cue=-4.1 $desc"
711         rm -f z50c.cue.$in_fmt
712         echo OK
713
714         echo -n "testing --cue=-3.1 $desc... "
715         run_flac $dopt -o z50c.cue.$in_fmt --cue=-3.1 z50c.cue.$out_fmt || die "ERROR decoding FLAC file $desc"
716         cmp 50c.until40.$in_fmt z50c.cue.$in_fmt || die "ERROR: file mismatch for --cue=-3.1 $desc"
717         rm -f z50c.cue.$in_fmt
718         echo OK
719
720         echo -n "testing --cue=-1.4 $desc... "
721         run_flac $dopt -o z50c.cue.$in_fmt --cue=-1.4 z50c.cue.$out_fmt || die "ERROR decoding FLAC file $desc"
722         cmp 50c.until30.$in_fmt z50c.cue.$in_fmt || die "ERROR: file mismatch for --cue=-1.4 $desc"
723         rm -f z50c.cue.$in_fmt
724         echo OK
725
726         echo -n "testing --cue=1.0-5.0 $desc... "
727         run_flac $dopt -o z50c.cue.$in_fmt --cue=1.0-5.0 z50c.cue.$out_fmt || die "ERROR decoding FLAC file $desc"
728         cmp 50c.$in_fmt z50c.cue.$in_fmt || die "ERROR: file mismatch for --cue=1.0-5.0 $desc"
729         rm -f z50c.cue.$in_fmt
730         echo OK
731
732         echo -n "testing --cue=1.1-5.0 $desc... "
733         run_flac $dopt -o z50c.cue.$in_fmt --cue=1.1-5.0 z50c.cue.$out_fmt || die "ERROR decoding FLAC file $desc"
734         cmp 50c.$in_fmt z50c.cue.$in_fmt || die "ERROR: file mismatch for --cue=1.1-5.0 $desc"
735         rm -f z50c.cue.$in_fmt
736         echo OK
737
738         echo -n "testing --cue=1.2-4.1 $desc... "
739         run_flac $dopt -o z50c.cue.$in_fmt --cue=1.2-4.1 z50c.cue.$out_fmt || die "ERROR decoding FLAC file $desc"
740         cmp 50c.skip10.until40.$in_fmt z50c.cue.$in_fmt || die "ERROR: file mismatch for --cue=1.2-4.1 $desc"
741         rm -f z50c.cue.$in_fmt
742         echo OK
743
744         echo -n "testing --cue=1.4-2.0 $desc... "
745         run_flac $dopt -o z50c.cue.$in_fmt --cue=1.4-2.0 z50c.cue.$out_fmt || die "ERROR decoding FLAC file $desc"
746         cmp 50c.skip20.until30.$in_fmt z50c.cue.$in_fmt || die "ERROR: file mismatch for --cue=1.4-2.0 $desc"
747         rm -f z50c.cue.$in_fmt
748         echo OK
749
750         rm -f z50c.cue.$out_fmt
751 }
752
753 test_cue raw flac
754 test_cue wav flac
755 test_cue aiff flac
756
757 if [ $has_ogg = "yes" ] ; then
758         test_cue raw ogg
759         test_cue wav ogg
760         test_cue aiff ogg
761 fi
762
763 ############################################################################
764 # test 'fixup' code that happens when a FLAC file with total_samples == 0
765 # in the STREAMINFO block is converted to WAVE or AIFF, requiring the
766 # decoder go back and fix up the chunk headers
767 ############################################################################
768
769 echo -n "WAVE fixup test... "
770
771 echo -n "prepare... "
772 convert_to_wav noise "$raw_eopt" "$wav_dopt" || die "ERROR creating reference WAVE"
773
774 echo -n "encode... "
775 # the pipe from 'cat' to 'flac' does not work on cygwin because of the EOF/
776 # binary-mode stdin problem, so we use an undocumented option to metaflac to
777 # set the total sample count to 0
778 if [ $is_win = yes ] ; then
779         run_flac $raw_eopt noise.raw -o fixup.flac || die "ERROR generating FLAC file"
780         run_metaflac --set-total-samples=0 fixup.flac 2> /dev/null
781 else
782         cat noise.raw | run_flac $raw_eopt - -c > fixup.flac || die "ERROR generating FLAC file"
783 fi
784
785 echo -n "decode... "
786 run_flac $wav_dopt fixup.flac -o fixup.wav || die "ERROR decoding FLAC file"
787
788 echo -n "compare... "
789 cmp noise.wav fixup.wav || die "ERROR: file mismatch"
790
791 echo OK
792 rm -f noise.wav fixup.wav fixup.flac
793
794 echo -n "AIFF fixup test... "
795
796 echo -n "prepare... "
797 convert_to_aiff noise "$raw_eopt" "$wav_dopt" || die "ERROR creating reference AIFF"
798
799 echo -n "encode... "
800 # the pipe from 'cat' to 'flac' does not work on cygwin because of the EOF/
801 # binary-mode stdin problem, so we use an undocumented option to metaflac to
802 # set the total sample count to 0
803 if [ $is_win = yes ] ; then
804         run_flac $raw_eopt noise.raw -o fixup.flac || die "ERROR generating FLAC file"
805         run_metaflac --set-total-samples=0 fixup.flac 2> /dev/null
806 else
807         cat noise.raw | run_flac $raw_eopt - -c > fixup.flac || die "ERROR generating FLAC file"
808 fi
809
810 echo -n "decode... "
811 run_flac $wav_dopt fixup.flac -o fixup.aiff || die "ERROR decoding FLAC file"
812
813 echo -n "compare... "
814 cmp noise.aiff fixup.aiff || die "ERROR: file mismatch"
815
816 echo OK
817 rm -f noise.aiff fixup.aiff fixup.flac
818
819
820 ############################################################################
821 # multi-file tests
822 ############################################################################
823
824 echo "Generating multiple input files from noise..."
825 multifile_format_decode="--endian=big --sign=signed"
826 multifile_format_encode="$multifile_format_decode --sample-rate=44100 --bps=16 --channels=2"
827 run_flac --verify --force --silent --force-raw-format $multifile_format_encode noise.raw || die "ERROR generating FLAC file"
828 run_flac --decode --force --silent noise.flac || die "ERROR generating WAVE file"
829 run_flac --decode --force --silent noise.flac -o noise.aiff || die "ERROR generating AIFF file"
830 rm -f noise.flac
831 cp noise.wav file0.wav
832 cp noise.wav file1.wav
833 cp noise.wav file2.wav
834 rm -f noise.wav
835 cp noise.aiff file0.aiff
836 cp noise.aiff file1.aiff
837 cp noise.aiff file2.aiff
838 rm -f noise.aiff
839 cp noise.raw file0.raw
840 cp noise.raw file1.raw
841 cp noise.raw file2.raw
842 # create authoritative sector-aligned files for comparison
843 file0_samples=`expr \( $total_noise_cdda_samples / 588 \) \* 588`
844 file0_remainder=`expr $total_noise_cdda_samples - $file0_samples`
845 file1_samples=`expr \( \( $file0_remainder + $total_noise_cdda_samples \) / 588 \) \* 588`
846 file1_remainder=`expr $file0_remainder + $total_noise_cdda_samples - $file1_samples`
847 file1_samples=`expr $file1_samples - $file0_remainder`
848 file2_samples=`expr \( \( $file1_remainder + $total_noise_cdda_samples \) / 588 \) \* 588`
849 file2_remainder=`expr $file1_remainder + $total_noise_cdda_samples - $file2_samples`
850 file2_samples=`expr $file2_samples - $file1_remainder`
851 if [ $file2_remainder != '0' ] ; then
852         file2_samples=`expr $file2_samples + $file2_remainder`
853         file2_remainder=`expr 588 - $file2_remainder`
854 fi
855
856 dd if=file0.raw ibs=4 count=$file0_samples of=file0s.raw 2>/dev/null || $dddie
857 dd if=file0.raw ibs=4 count=$file0_remainder of=file1s.raw skip=$file0_samples 2>/dev/null || $dddie
858 dd if=file1.raw ibs=4 count=$file1_samples of=z.raw 2>/dev/null || $dddie
859 cat z.raw >> file1s.raw || die "ERROR: cat-ing sector-aligned files"
860 dd if=file1.raw ibs=4 count=$file1_remainder of=file2s.raw skip=$file1_samples 2>/dev/null || $dddie
861 dd if=file2.raw ibs=4 count=$file2_samples of=z.raw 2>/dev/null || $dddie
862 cat z.raw >> file2s.raw || die "ERROR: cat-ing sector-aligned files"
863 dd if=/dev/zero ibs=4 count=$file2_remainder of=z.raw 2>/dev/null || $dddie
864 cat z.raw >> file2s.raw || die "ERROR: cat-ing sector-aligned files"
865 rm -f z.raw
866
867 convert_to_wav file0s "$multifile_format_encode --force" "--silent --force --decode" || die "ERROR creating authoritative sector-aligned WAVE"
868 convert_to_wav file1s "$multifile_format_encode --force" "--silent --force --decode" || die "ERROR creating authoritative sector-aligned WAVE"
869 convert_to_wav file2s "$multifile_format_encode --force" "--silent --force --decode" || die "ERROR creating authoritative sector-aligned WAVE"
870
871 convert_to_aiff file0s "$multifile_format_encode --force" "--silent --force --decode" || die "ERROR creating authoritative sector-aligned AIFF"
872 convert_to_aiff file1s "$multifile_format_encode --force" "--silent --force --decode" || die "ERROR creating authoritative sector-aligned AIFF"
873 convert_to_aiff file2s "$multifile_format_encode --force" "--silent --force --decode" || die "ERROR creating authoritative sector-aligned AIFF"
874
875 test_multifile ()
876 {
877         input_type=$1
878         streamtype=$2
879         sector_align=$3
880         encode_options="$4"
881
882         extra_encode_options=""
883         extra_decode_options=""
884         if [ $input_type = "raw" ] ; then
885                 extra_encode_options="--force-raw-format $multifile_format_encode"
886                 extra_decode_options="--force-raw-format $multifile_format_decode"
887         else
888                 if [ $input_type = "aiff" ] ; then
889                         extra_decode_options="--force-aiff-format"
890                 fi
891         fi
892
893         if [ $streamtype = ogg ] ; then
894                 suffix=ogg
895                 encode_options="$encode_options --ogg"
896         else
897                 suffix=flac
898         fi
899
900         if [ $sector_align = sector_align ] ; then
901                 encode_options="$encode_options --sector-align"
902         fi
903
904         run_flac --force $encode_options $extra_encode_options file0.$input_type file1.$input_type file2.$input_type || die "ERROR"
905         for n in 0 1 2 ; do
906                 mv file$n.$suffix file${n}x.$suffix
907         done
908         run_flac --force --decode $extra_decode_options file0x.$suffix file1x.$suffix file2x.$suffix || die "ERROR"
909         if [ $sector_align != sector_align ] ; then
910                 for n in 0 1 2 ; do
911                         cmp file$n.$input_type file${n}x.$input_type || die "ERROR: file mismatch on file #$n"
912                 done
913         else
914                 for n in 0 1 2 ; do
915                         cmp file${n}s.$input_type file${n}x.$input_type || die "ERROR: file mismatch on file #$n"
916                 done
917         fi
918         for n in 0 1 2 ; do
919                 rm -f file${n}x.$suffix file${n}x.$input_type
920         done
921 }
922
923 for input_type in raw wav aiff ; do
924         echo "Testing multiple $input_type files without verify..."
925         test_multifile $input_type flac no_sector_align ""
926
927         echo "Testing multiple $input_type files with verify..."
928         test_multifile $input_type flac no_sector_align "--verify"
929
930         echo "Testing multiple $input_type files with --sector-align, without verify..."
931         test_multifile $input_type flac sector_align ""
932
933         echo "Testing multiple $input_type files with --sector-align, with verify..."
934         test_multifile $input_type flac sector_align "--verify"
935
936         if [ $has_ogg = "yes" ] ; then
937                 echo "Testing multiple $input_type files with --ogg, without verify..."
938                 test_multifile $input_type ogg no_sector_align ""
939
940                 echo "Testing multiple $input_type files with --ogg, with verify..."
941                 test_multifile $input_type ogg no_sector_align "--verify"
942
943                 echo "Testing multiple $input_type files with --ogg and --sector-align, without verify..."
944                 test_multifile $input_type ogg sector_align ""
945
946                 echo "Testing multiple $input_type files with --ogg and --sector-align, with verify..."
947                 test_multifile $input_type ogg sector_align "--verify"
948
949                 echo "Testing multiple $input_type files with --ogg and --serial-number, with verify..."
950                 test_multifile $input_type ogg no_sector_align "--serial-number=321 --verify"
951         fi
952 done