test_flac.sh 52.1 KB
Newer Older
Josh Coalson's avatar
Josh Coalson committed
1
2
3
#!/bin/sh

#  FLAC - Free Lossless Audio Codec
4
5
#  Copyright (C) 2001-2009  Josh Coalson
#  Copyright (C) 2011-2013  Xiph.Org Foundation
Josh Coalson's avatar
Josh Coalson committed
6
#
Josh Coalson's avatar
Josh Coalson committed
7
#  This file is part the FLAC project.  FLAC is comprised of several
8
#  components distributed under different licenses.  The codec libraries
Josh Coalson's avatar
Josh Coalson committed
9
10
11
12
13
14
#  are distributed under Xiph.Org's BSD-like license (see the file
#  COPYING.Xiph in this distribution).  All other programs, libraries, and
#  plugins are distributed under the GPL (see COPYING.GPL).  The documentation
#  is distributed under the Gnu FDL (see COPYING.FDL).  Each file in the
#  FLAC distribution contains at the top the terms under which it may be
#  distributed.
Josh Coalson's avatar
Josh Coalson committed
15
#
Josh Coalson's avatar
Josh Coalson committed
16
17
18
19
#  Since this particular file is relevant to all components of FLAC,
#  it may be distributed under the Xiph.Org license, which is the least
#  restrictive of those mentioned above.  See the file COPYING.Xiph in this
#  distribution.
Josh Coalson's avatar
Josh Coalson committed
20

21
22
23
# we use '.' as decimal separator in --skip/--until tests
export LANG=C LC_ALL=C

24
25
26
27
28
29
die ()
{
	echo $* 1>&2
	exit 1
}

Josh Coalson's avatar
Josh Coalson committed
30
31
dddie="die ERROR: creating files with dd"

32
if [ x = x"$1" ] ; then
33
34
35
36
37
	BUILD=debug
else
	BUILD="$1"
fi

38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# change to 'false' to show flac output (useful for debugging)
if true ; then
	SILENT='--silent'
	TOTALLY_SILENT='--totally-silent'
else
	SILENT=''
	TOTALLY_SILENT=''
fi

LD_LIBRARY_PATH=`pwd`/../src/libFLAC/.libs:$LD_LIBRARY_PATH
LD_LIBRARY_PATH=`pwd`/../src/share/grabbag/.libs:$LD_LIBRARY_PATH
LD_LIBRARY_PATH=`pwd`/../src/share/getopt/.libs:$LD_LIBRARY_PATH
LD_LIBRARY_PATH=`pwd`/../src/share/replaygain_analysis/.libs:$LD_LIBRARY_PATH
LD_LIBRARY_PATH=`pwd`/../src/share/replaygain_synthesis/.libs:$LD_LIBRARY_PATH
LD_LIBRARY_PATH=`pwd`/../src/share/utf8/.libs:$LD_LIBRARY_PATH
53
LD_LIBRARY_PATH=`pwd`/../objs/$BUILD/lib:$LD_LIBRARY_PATH
Josh Coalson's avatar
Josh Coalson committed
54
export LD_LIBRARY_PATH
55
export MALLOC_CHECK_=3
56
export MALLOC_PERTURB_=$(($(date +%s) % 255 + 1))
57
58
59
PATH=`pwd`/../src/flac:$PATH
PATH=`pwd`/../src/metaflac:$PATH
PATH=`pwd`/../src/test_streams:$PATH
60
PATH=`pwd`/../objs/$BUILD/bin:$PATH
Josh Coalson's avatar
Josh Coalson committed
61

62
flac --help 1>/dev/null 2>/dev/null || die "ERROR can't find flac executable"
Josh Coalson's avatar
Josh Coalson committed
63
64
65

run_flac ()
{
66
	if [ x"$FLAC__TEST_WITH_VALGRIND" = xyes ] ; then
67
		echo "valgrind --leak-check=yes --show-reachable=yes --num-callers=50 flac $*" >>test_flac.valgrind.log
68
		valgrind --leak-check=yes --show-reachable=yes --num-callers=50 --log-fd=4 flac --no-error-on-compression-fail $* 4>>test_flac.valgrind.log
Josh Coalson's avatar
Josh Coalson committed
69
	else
70
		flac --no-error-on-compression-fail $*
Josh Coalson's avatar
Josh Coalson committed
71
72
73
	fi
}

74
75
run_metaflac ()
{
76
	if [ x"$FLAC__TEST_WITH_VALGRIND" = xyes ] ; then
77
78
		echo "valgrind --leak-check=yes --show-reachable=yes --num-callers=50 metaflac $*" >>test_flac.valgrind.log
		valgrind --leak-check=yes --show-reachable=yes --num-callers=50 --log-fd=4 metaflac $* 4>>test_flac.valgrind.log
79
80
81
82
83
	else
		metaflac $*
	fi
}

84
85
86
87
88
89
90
md5cmp ()
{
	#n=`( [ -f "$1" ] && [ -f "$2" ] && metaflac --show-md5sum --no-filename "$1" "$2" 2>/dev/null || die "ERROR: comparing FLAC files $1 and $2 by MD5 sum" ) | uniq | wc -l`
	n=`( [ -f "$1" ] && [ -f "$2" ] && metaflac --show-md5sum --no-filename "$1" "$2" 2>/dev/null || exit 1 ) | uniq | wc -l`
	[ "$n" != "" ] && [ $n = 1 ]
}

Josh Coalson's avatar
Josh Coalson committed
91
92
93
94
95
96
if [ `env | grep -ic '^comspec='` != 0 ] ; then
	is_win=yes
else
	is_win=no
fi

Josh Coalson's avatar
Josh Coalson committed
97
echo "Checking for --ogg support in flac..."
98
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
Josh Coalson's avatar
Josh Coalson committed
99
100
101
102
103
104
105
	has_ogg=yes;
	echo "flac --ogg works"
else
	has_ogg=no;
	echo "flac --ogg doesn't work"
fi

106
107
108
109
110
echo "Generating streams..."
if [ ! -f wacky1.wav ] ; then
	test_streams || die "ERROR during test_streams"
fi

111
112
113
114
115
116
117
############################################################################
# test that flac doesn't automatically overwrite files unless -f is used
############################################################################

echo "Try encoding to a file that exists; should fail"
cp wacky1.wav exist.wav
touch exist.flac
118
if run_flac $TOTALLY_SILENT -0 exist.wav ; then
119
120
121
122
123
124
	die "ERROR: it should have failed but didn't"
else
	echo "OK, it failed as it should"
fi

echo "Try encoding with -f to a file that exists; should succeed"
125
if run_flac $TOTALLY_SILENT -0 --force exist.wav ; then
126
127
128
129
130
131
	echo "OK, it succeeded as it should"
else
	die "ERROR: it should have succeeded but didn't"
fi

echo "Try decoding to a file that exists; should fail"
132
if run_flac $TOTALLY_SILENT -d exist.flac ; then
133
134
135
136
137
138
	die "ERROR: it should have failed but didn't"
else
	echo "OK, it failed as it should"
fi

echo "Try decoding with -f to a file that exists; should succeed"
139
if run_flac $TOTALLY_SILENT -d -f exist.flac ; then
140
141
142
143
144
145
146
	echo "OK, it succeeded as it should"
else
	die "ERROR: it should have succeeded but didn't"
fi

rm -f exist.wav exist.flac

Josh Coalson's avatar
Josh Coalson committed
147
148
149
150
############################################################################
# test fractional block sizes
############################################################################

151
152
153
154
test_fractional ()
{
	blocksize=$1
	samples=$2
Josh Coalson's avatar
Josh Coalson committed
155
	dd if=noise.raw ibs=4 count=$samples of=pbs.raw 2>/dev/null || $dddie
156
	echo -n "fractional block size test (blocksize=$blocksize samples=$samples) encode... "
157
	run_flac $SILENT --force --verify --force-raw-format --endian=little --sign=signed --sample-rate=44100 --bps=16 --channels=2 --blocksize=$blocksize --no-padding --lax -o pbs.flac pbs.raw || die "ERROR"
Josh Coalson's avatar
Josh Coalson committed
158
159
160
161
162
163
	echo -n "decode... "
	run_flac $SILENT --force --decode --force-raw-format --endian=little --sign=signed -o pbs.cmp pbs.flac || die "ERROR"
	echo -n "compare... "
	cmp pbs.raw pbs.cmp || die "ERROR: file mismatch"
	echo "OK"
	rm -f pbs.raw pbs.flac pbs.cmp
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
}

# The special significance of 2048 is it's the # of samples that flac calls
# FLAC__stream_encoder_process() on.
#
# We're trying to make sure the 1-sample overread logic in the stream encoder
# (used for last-block checking) works; these values probe around common
# multiples of the flac sample chunk size (2048) and the blocksize.
for samples in 31 32 33 34 35 2046 2047 2048 2049 2050 ; do
	test_fractional 33 $samples
done
for samples in 254 255 256 257 258 510 511 512 513 514 1022 1023 1024 1025 1026 2046 2047 2048 2049 2050 4094 4095 4096 4097 4098 ; do
	test_fractional 256 $samples
done
for samples in 1022 1023 1024 1025 1026 2046 2047 2048 2049 2050 4094 4095 4096 4097 4098 ; do
	test_fractional 2048 $samples
done
for samples in 1022 1023 1024 1025 1026 2046 2047 2048 2049 2050 4094 4095 4096 4097 4098 4606 4607 4608 4609 4610 8190 8191 8192 8193 8194 16382 16383 16384 16385 16386 ; do
	test_fractional 4608 $samples
Josh Coalson's avatar
Josh Coalson committed
183
184
done

185
186
187
188
189
190
191
############################################################################
# basic 'round-trip' tests of various kinds of streams
############################################################################

rt_test_raw ()
{
	f="$1"
Josh Coalson's avatar
Josh Coalson committed
192
	extra="$2"
193
	channels=`echo $f | awk -F- '{print $2}'`
194
	bps=`echo $f | awk -F- '{print $3}'`
195
	echo -n "round-trip test ($f) encode... "
Josh Coalson's avatar
Josh Coalson committed
196
	run_flac $SILENT --force --verify --force-raw-format --endian=little --sign=signed --sample-rate=44100 --bps=$bps --channels=$channels --no-padding --lax -o rt.flac $extra $f || die "ERROR"
197
	echo -n "decode... "
Josh Coalson's avatar
Josh Coalson committed
198
	run_flac $SILENT --force --decode --force-raw-format --endian=little --sign=signed -o rt.raw $extra rt.flac || die "ERROR"
199
200
201
202
203
204
205
206
207
	echo -n "compare... "
	cmp $f rt.raw || die "ERROR: file mismatch"
	echo "OK"
	rm -f rt.flac rt.raw
}

rt_test_wav ()
{
	f="$1"
Josh Coalson's avatar
Josh Coalson committed
208
	extra="$2"
209
	echo -n "round-trip test ($f) encode... "
Josh Coalson's avatar
Josh Coalson committed
210
	run_flac $SILENT --force --verify --channel-map=none --no-padding --lax -o rt.flac $extra $f || die "ERROR"
211
	echo -n "decode... "
Josh Coalson's avatar
Josh Coalson committed
212
	run_flac $SILENT --force --decode --channel-map=none -o rt.wav $extra rt.flac || die "ERROR"
213
214
215
216
217
218
	echo -n "compare... "
	cmp $f rt.wav || die "ERROR: file mismatch"
	echo "OK"
	rm -f rt.flac rt.wav
}

219
220
221
222
223
224
225
226
227
228
229
230
231
232
rt_test_w64 ()
{
	f="$1"
	extra="$2"
	echo -n "round-trip test ($f) encode... "
	run_flac $SILENT --force --verify --channel-map=none --no-padding --lax -o rt.flac $extra $f || die "ERROR"
	echo -n "decode... "
	run_flac $SILENT --force --decode --channel-map=none -o rt.w64 $extra rt.flac || die "ERROR"
	echo -n "compare... "
	cmp $f rt.w64 || die "ERROR: file mismatch"
	echo "OK"
	rm -f rt.flac rt.w64
}

Josh Coalson's avatar
Josh Coalson committed
233
234
235
236
237
238
239
240
241
242
243
244
245
246
rt_test_rf64 ()
{
	f="$1"
	extra="$2"
	echo -n "round-trip test ($f) encode... "
	run_flac $SILENT --force --verify --channel-map=none --no-padding --lax -o rt.flac $extra $f || die "ERROR"
	echo -n "decode... "
	run_flac $SILENT --force --decode --channel-map=none -o rt.rf64 $extra rt.flac || die "ERROR"
	echo -n "compare... "
	cmp $f rt.rf64 || die "ERROR: file mismatch"
	echo "OK"
	rm -f rt.flac rt.rf64
}

247
248
249
rt_test_aiff ()
{
	f="$1"
Josh Coalson's avatar
Josh Coalson committed
250
	extra="$2"
251
	echo -n "round-trip test ($f) encode... "
Josh Coalson's avatar
Josh Coalson committed
252
	run_flac $SILENT --force --verify --channel-map=none --no-padding --lax -o rt.flac $extra $f || die "ERROR"
253
	echo -n "decode... "
Josh Coalson's avatar
Josh Coalson committed
254
	run_flac $SILENT --force --decode --channel-map=none -o rt.aiff $extra rt.flac || die "ERROR"
255
256
257
258
259
260
	echo -n "compare... "
	cmp $f rt.aiff || die "ERROR: file mismatch"
	echo "OK"
	rm -f rt.flac rt.aiff
}

261
262
263
264
# assumes input file is WAVE; does not check the metadata-preserving features of flac-to-flac; that is checked later
rt_test_flac ()
{
	f="$1"
Josh Coalson's avatar
Josh Coalson committed
265
	extra="$2"
266
	echo -n "round-trip test ($f->flac->flac->wav) encode... "
Josh Coalson's avatar
Josh Coalson committed
267
	run_flac $SILENT --force --verify --channel-map=none --no-padding --lax -o rt.flac $extra $f || die "ERROR"
268
	echo -n "re-encode... "
269
	run_flac $SILENT --force --verify --lax -o rt2.flac rt.flac || die "ERROR"
270
	echo -n "decode... "
Josh Coalson's avatar
Josh Coalson committed
271
	run_flac $SILENT --force --decode --channel-map=none -o rt.wav $extra rt2.flac || die "ERROR"
272
273
274
275
276
277
	echo -n "compare... "
	cmp $f rt.wav || die "ERROR: file mismatch"
	echo "OK"
	rm -f rt.wav rt.flac rt2.flac
}

278
279
280
281
# assumes input file is WAVE; does not check the metadata-preserving features of flac-to-flac; that is checked later
rt_test_ogg_flac ()
{
	f="$1"
Josh Coalson's avatar
Josh Coalson committed
282
	extra="$2"
283
	echo -n "round-trip test ($f->oggflac->oggflac->wav) encode... "
Josh Coalson's avatar
Josh Coalson committed
284
	run_flac $SILENT --force --verify --channel-map=none --no-padding --lax -o rt.oga --ogg $extra $f || die "ERROR"
285
	echo -n "re-encode... "
286
	run_flac $SILENT --force --verify --lax -o rt2.oga --ogg rt.oga || die "ERROR"
287
	echo -n "decode... "
Josh Coalson's avatar
Josh Coalson committed
288
	run_flac $SILENT --force --decode --channel-map=none -o rt.wav $extra rt2.oga || die "ERROR"
289
290
291
	echo -n "compare... "
	cmp $f rt.wav || die "ERROR: file mismatch"
	echo "OK"
292
	rm -f rt.wav rt.oga rt2.oga
293
294
}

295
296
297
298
299
300
for f in rt-*.raw ; do
	rt_test_raw $f
done
for f in rt-*.wav ; do
	rt_test_wav $f
done
301
302
303
for f in rt-*.w64 ; do
	rt_test_w64 $f
done
Josh Coalson's avatar
Josh Coalson committed
304
305
306
for f in rt-*.rf64 ; do
	rt_test_rf64 $f
done
307
308
309
for f in rt-*.aiff ; do
	rt_test_aiff $f
done
310
311
312
for f in rt-*.wav ; do
	rt_test_flac $f
done
313
314
315
316
317
if [ $has_ogg = yes ] ; then
	for f in rt-*.wav ; do
		rt_test_ogg_flac $f
	done
fi
318

319
320
321
322
############################################################################
# test --skip and --until
############################################################################

Josh Coalson's avatar
Josh Coalson committed
323
#
324
# first make some chopped-up raw files
Josh Coalson's avatar
Josh Coalson committed
325
#
326
327
328
329
echo "abcdefghijklmnopqrstuvwxyz1234567890ABCDEFGHIJKLMN" > master.raw
dd if=master.raw ibs=1 count=50 of=50c.raw 2>/dev/null || $dddie
dd if=master.raw ibs=1 skip=10 count=40 of=50c.skip10.raw 2>/dev/null || $dddie
dd if=master.raw ibs=1 skip=11 count=39 of=50c.skip11.raw 2>/dev/null || $dddie
330
331
332
333
334
335
dd if=master.raw ibs=1 skip=20 count=30 of=50c.skip20.raw 2>/dev/null || $dddie
dd if=master.raw ibs=1 skip=30 count=20 of=50c.skip30.raw 2>/dev/null || $dddie
dd if=master.raw ibs=1 skip=40 count=10 of=50c.skip40.raw 2>/dev/null || $dddie
dd if=master.raw ibs=1 count=10 of=50c.until10.raw 2>/dev/null || $dddie
dd if=master.raw ibs=1 count=20 of=50c.until20.raw 2>/dev/null || $dddie
dd if=master.raw ibs=1 count=30 of=50c.until30.raw 2>/dev/null || $dddie
336
dd if=master.raw ibs=1 count=39 of=50c.until39.raw 2>/dev/null || $dddie
337
338
dd if=master.raw ibs=1 count=40 of=50c.until40.raw 2>/dev/null || $dddie
dd if=master.raw ibs=1 skip=10 count=20 of=50c.skip10.until30.raw 2>/dev/null || $dddie
339
dd if=master.raw ibs=1 skip=10 count=29 of=50c.skip10.until39.raw 2>/dev/null || $dddie
340
341
342
dd if=master.raw ibs=1 skip=10 count=30 of=50c.skip10.until40.raw 2>/dev/null || $dddie
dd if=master.raw ibs=1 skip=20 count=10 of=50c.skip20.until30.raw 2>/dev/null || $dddie
dd if=master.raw ibs=1 skip=20 count=20 of=50c.skip20.until40.raw 2>/dev/null || $dddie
Josh Coalson's avatar
Josh Coalson committed
343

344
wav_eopt="$SILENT --force --verify --no-padding --lax"
345
wav_dopt="$SILENT --force --decode"
346

Josh Coalson's avatar
Josh Coalson committed
347
raw_eopt="$wav_eopt --force-raw-format --endian=big --sign=signed --sample-rate=10 --bps=8 --channels=1"
348
raw_dopt="$wav_dopt --force-raw-format --endian=big --sign=signed"
349
350

#
351
# convert them to WAVE/AIFF/Ogg FLAC files
352
#
353
354
convert_to_wav ()
{
355
356
	run_flac "$2" $1.raw || die "ERROR converting $1.raw to WAVE"
	run_flac "$3" $1.flac || die "ERROR converting $1.raw to WAVE"
357
}
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
convert_to_wav 50c "$raw_eopt" "$wav_dopt"
convert_to_wav 50c.skip10 "$raw_eopt" "$wav_dopt"
convert_to_wav 50c.skip11 "$raw_eopt" "$wav_dopt"
convert_to_wav 50c.skip20 "$raw_eopt" "$wav_dopt"
convert_to_wav 50c.skip30 "$raw_eopt" "$wav_dopt"
convert_to_wav 50c.skip40 "$raw_eopt" "$wav_dopt"
convert_to_wav 50c.until10 "$raw_eopt" "$wav_dopt"
convert_to_wav 50c.until20 "$raw_eopt" "$wav_dopt"
convert_to_wav 50c.until30 "$raw_eopt" "$wav_dopt"
convert_to_wav 50c.until39 "$raw_eopt" "$wav_dopt"
convert_to_wav 50c.until40 "$raw_eopt" "$wav_dopt"
convert_to_wav 50c.skip10.until30 "$raw_eopt" "$wav_dopt"
convert_to_wav 50c.skip10.until39 "$raw_eopt" "$wav_dopt"
convert_to_wav 50c.skip10.until40 "$raw_eopt" "$wav_dopt"
convert_to_wav 50c.skip20.until30 "$raw_eopt" "$wav_dopt"
convert_to_wav 50c.skip20.until40 "$raw_eopt" "$wav_dopt"
374

375
376
convert_to_aiff ()
{
377
378
	run_flac "$2" $1.raw || die "ERROR converting $1.raw to AIFF"
	run_flac "$3" $1.flac -o $1.aiff || die "ERROR converting $1.raw to AIFF"
379
}
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
convert_to_aiff 50c "$raw_eopt" "$wav_dopt"
convert_to_aiff 50c.skip10 "$raw_eopt" "$wav_dopt"
convert_to_aiff 50c.skip11 "$raw_eopt" "$wav_dopt"
convert_to_aiff 50c.skip20 "$raw_eopt" "$wav_dopt"
convert_to_aiff 50c.skip30 "$raw_eopt" "$wav_dopt"
convert_to_aiff 50c.skip40 "$raw_eopt" "$wav_dopt"
convert_to_aiff 50c.until10 "$raw_eopt" "$wav_dopt"
convert_to_aiff 50c.until20 "$raw_eopt" "$wav_dopt"
convert_to_aiff 50c.until30 "$raw_eopt" "$wav_dopt"
convert_to_aiff 50c.until39 "$raw_eopt" "$wav_dopt"
convert_to_aiff 50c.until40 "$raw_eopt" "$wav_dopt"
convert_to_aiff 50c.skip10.until30 "$raw_eopt" "$wav_dopt"
convert_to_aiff 50c.skip10.until39 "$raw_eopt" "$wav_dopt"
convert_to_aiff 50c.skip10.until40 "$raw_eopt" "$wav_dopt"
convert_to_aiff 50c.skip20.until30 "$raw_eopt" "$wav_dopt"
convert_to_aiff 50c.skip20.until40 "$raw_eopt" "$wav_dopt"
396

397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
convert_to_ogg ()
{
	run_flac "$wav_eopt" --ogg $1.wav || die "ERROR converting $1.raw to Ogg FLAC"
}
if [ $has_ogg = yes ] ; then
	convert_to_ogg 50c
	convert_to_ogg 50c.skip10
	convert_to_ogg 50c.skip11
	convert_to_ogg 50c.skip20
	convert_to_ogg 50c.skip30
	convert_to_ogg 50c.skip40
	convert_to_ogg 50c.until10
	convert_to_ogg 50c.until20
	convert_to_ogg 50c.until30
	convert_to_ogg 50c.until39
	convert_to_ogg 50c.until40
	convert_to_ogg 50c.skip10.until30
	convert_to_ogg 50c.skip10.until39
	convert_to_ogg 50c.skip10.until40
	convert_to_ogg 50c.skip20.until30
	convert_to_ogg 50c.skip20.until40
fi

420
421
test_skip_until ()
{
422
423
	in_fmt=$1
	out_fmt=$2
424

425
	[ "$in_fmt" = wav ] || [ "$in_fmt" = aiff ] || [ "$in_fmt" = raw ] || [ "$in_fmt" = flac ] || [ "$in_fmt" = ogg ] || die "ERROR: internal error, bad 'in' format '$in_fmt'"
426

427
428
429
	[ "$out_fmt" = flac ] || [ "$out_fmt" = ogg ] || die "ERROR: internal error, bad 'out' format '$out_fmt'"

	if [ $in_fmt = raw ] ; then
430
431
432
433
434
435
		eopt="$raw_eopt"
		dopt="$raw_dopt"
	else
		eopt="$wav_eopt"
		dopt="$wav_dopt"
	fi
436

437
	if ( [ $in_fmt = flac ] || [ $in_fmt = ogg ] ) && ( [ $out_fmt = flac ] || [ $out_fmt = ogg ] ) ; then
438
439
440
441
442
		CMP=md5cmp
	else
		CMP=cmp
	fi

443
444
445
446
	if [ $out_fmt = ogg ] ; then
		eopt="--ogg $eopt"
	fi

447
448
449
450
	#
	# test --skip when encoding
	#

451
452
453
454
	desc="($in_fmt<->$out_fmt)"

	echo -n "testing --skip=# (encode) $desc... "
	run_flac $eopt --skip=10 -o z50c.skip10.$out_fmt 50c.$in_fmt || die "ERROR generating FLAC file $desc"
455
456
	[ $in_fmt = $out_fmt ] || run_flac $dopt -o z50c.skip10.$in_fmt z50c.skip10.$out_fmt || die "ERROR decoding FLAC file $desc"
	$CMP 50c.skip10.$in_fmt z50c.skip10.$in_fmt || die "ERROR: file mismatch for --skip=10 (encode) $desc"
457
	rm -f z50c.skip10.$out_fmt z50c.skip10.$in_fmt
458
459
	echo OK

460
	echo -n "testing --skip=mm:ss (encode) $desc... "
461
462
463
464
	run_flac $eopt --skip=0:01 -o z50c.skip0_01.$out_fmt 50c.$in_fmt || die "ERROR generating FLAC file $desc"
	[ $in_fmt = $out_fmt ] || run_flac $dopt -o z50c.skip0_01.$in_fmt z50c.skip0_01.$out_fmt || die "ERROR decoding FLAC file $desc"
	$CMP 50c.skip10.$in_fmt z50c.skip0_01.$in_fmt || die "ERROR: file mismatch for --skip=0:01 (encode) $desc"
	rm -f z50c.skip0_01.$out_fmt z50c.skip0_01.$in_fmt
465
466
	echo OK

467
	echo -n "testing --skip=mm:ss.sss (encode) $desc... "
468
469
470
471
	run_flac $eopt --skip=0:01.1001 -o z50c.skip0_01.1001.$out_fmt 50c.$in_fmt || die "ERROR generating FLAC file $desc"
	[ $in_fmt = $out_fmt ] || run_flac $dopt -o z50c.skip0_01.1001.$in_fmt z50c.skip0_01.1001.$out_fmt || die "ERROR decoding FLAC file $desc"
	$CMP 50c.skip11.$in_fmt z50c.skip0_01.1001.$in_fmt || die "ERROR: file mismatch for --skip=0:01.1001 (encode) $desc"
	rm -f z50c.skip0_01.1001.$out_fmt z50c.skip0_01.1001.$in_fmt
472
473
474
475
476
477
	echo OK

	#
	# test --skip when decoding
	#

478
479
	if [ $in_fmt != $out_fmt ] ; then run_flac $eopt -o z50c.$out_fmt 50c.$in_fmt ; else cp -f 50c.$in_fmt z50c.$out_fmt ; fi || die "ERROR generating FLAC file $desc"

480
481
	echo -n "testing --skip=# (decode) $desc... "
	run_flac $dopt --skip=10 -o z50c.skip10.$in_fmt z50c.$out_fmt || die "ERROR decoding FLAC file $desc"
482
	$CMP 50c.skip10.$in_fmt z50c.skip10.$in_fmt || die "ERROR: file mismatch for --skip=10 (decode) $desc"
483
	rm -f z50c.skip10.$in_fmt
484
485
	echo OK

486
	echo -n "testing --skip=mm:ss (decode) $desc... "
487
488
489
	run_flac $dopt --skip=0:01 -o z50c.skip0_01.$in_fmt z50c.$out_fmt || die "ERROR decoding FLAC file $desc"
	$CMP 50c.skip10.$in_fmt z50c.skip0_01.$in_fmt || die "ERROR: file mismatch for --skip=0:01 (decode) $desc"
	rm -f z50c.skip0_01.$in_fmt
490
491
	echo OK

492
	echo -n "testing --skip=mm:ss.sss (decode) $desc... "
493
494
495
	run_flac $dopt --skip=0:01.1001 -o z50c.skip0_01.1001.$in_fmt z50c.$out_fmt || die "ERROR decoding FLAC file $desc"
	$CMP 50c.skip11.$in_fmt z50c.skip0_01.1001.$in_fmt || die "ERROR: file mismatch for --skip=0:01.1001 (decode) $desc"
	rm -f z50c.skip0_01.1001.$in_fmt
496
497
	echo OK

498
	rm -f z50c.$out_fmt
499
500
501
502
503

	#
	# test --until when encoding
	#

504
505
	echo -n "testing --until=# (encode) $desc... "
	run_flac $eopt --until=40 -o z50c.until40.$out_fmt 50c.$in_fmt || die "ERROR generating FLAC file $desc"
506
507
	[ $in_fmt = $out_fmt ] || run_flac $dopt -o z50c.until40.$in_fmt z50c.until40.$out_fmt || die "ERROR decoding FLAC file $desc"
	$CMP 50c.until40.$in_fmt z50c.until40.$in_fmt || die "ERROR: file mismatch for --until=40 (encode) $desc"
508
	rm -f z50c.until40.$out_fmt z50c.until40.$in_fmt
509
510
	echo OK

511
	echo -n "testing --until=mm:ss (encode) $desc... "
512
513
514
515
	run_flac $eopt --until=0:04 -o z50c.until0_04.$out_fmt 50c.$in_fmt || die "ERROR generating FLAC file $desc"
	[ $in_fmt = $out_fmt ] || run_flac $dopt -o z50c.until0_04.$in_fmt z50c.until0_04.$out_fmt || die "ERROR decoding FLAC file $desc"
	$CMP 50c.until40.$in_fmt z50c.until0_04.$in_fmt || die "ERROR: file mismatch for --until=0:04 (encode) $desc"
	rm -f z50c.until0_04.$out_fmt z50c.until0_04.$in_fmt
516
517
	echo OK

518
	echo -n "testing --until=mm:ss.sss (encode) $desc... "
519
520
521
522
	run_flac $eopt --until=0:03.9001 -o z50c.until0_03.9001.$out_fmt 50c.$in_fmt || die "ERROR generating FLAC file $desc"
	[ $in_fmt = $out_fmt ] || run_flac $dopt -o z50c.until0_03.9001.$in_fmt z50c.until0_03.9001.$out_fmt || die "ERROR decoding FLAC file $desc"
	$CMP 50c.until39.$in_fmt z50c.until0_03.9001.$in_fmt || die "ERROR: file mismatch for --until=0:03.9001 (encode) $desc"
	rm -f z50c.until0_03.9001.$out_fmt z50c.until0_03.9001.$in_fmt
523
524
	echo OK

525
526
	echo -n "testing --until=-# (encode) $desc... "
	run_flac $eopt --until=-10 -o z50c.until-10.$out_fmt 50c.$in_fmt || die "ERROR generating FLAC file $desc"
527
528
	[ $in_fmt = $out_fmt ] || run_flac $dopt -o z50c.until-10.$in_fmt z50c.until-10.$out_fmt || die "ERROR decoding FLAC file $desc"
	$CMP 50c.until40.$in_fmt z50c.until-10.$in_fmt || die "ERROR: file mismatch for --until=-10 (encode) $desc"
529
	rm -f z50c.until-10.$out_fmt z50c.until-10.$in_fmt
530
531
	echo OK

532
	echo -n "testing --until=-mm:ss (encode) $desc... "
533
534
535
536
	run_flac $eopt --until=-0:01 -o z50c.until-0_01.$out_fmt 50c.$in_fmt || die "ERROR generating FLAC file $desc"
	[ $in_fmt = $out_fmt ] || run_flac $dopt -o z50c.until-0_01.$in_fmt z50c.until-0_01.$out_fmt || die "ERROR decoding FLAC file $desc"
	$CMP 50c.until40.$in_fmt z50c.until-0_01.$in_fmt || die "ERROR: file mismatch for --until=-0:01 (encode) $desc"
	rm -f z50c.until-0_01.$out_fmt z50c.until-0_01.$in_fmt
537
538
	echo OK

539
	echo -n "testing --until=-mm:ss.sss (encode) $desc... "
540
541
542
543
	run_flac $eopt --until=-0:01.1001 -o z50c.until-0_01.1001.$out_fmt 50c.$in_fmt || die "ERROR generating FLAC file $desc"
	[ $in_fmt = $out_fmt ] || run_flac $dopt -o z50c.until-0_01.1001.$in_fmt z50c.until-0_01.1001.$out_fmt || die "ERROR decoding FLAC file $desc"
	$CMP 50c.until39.$in_fmt z50c.until-0_01.1001.$in_fmt || die "ERROR: file mismatch for --until=-0:01.1001 (encode) $desc"
	rm -f z50c.until-0_01.1001.$out_fmt z50c.until-0_01.1001.$in_fmt
544
545
546
547
548
549
	echo OK

	#
	# test --until when decoding
	#

550
	if [ $in_fmt != $out_fmt ] ; then run_flac $eopt -o z50c.$out_fmt 50c.$in_fmt ; else cp -f 50c.$in_fmt z50c.$out_fmt ; fi || die "ERROR generating FLAC file $desc"
551

552
553
	echo -n "testing --until=# (decode) $desc... "
	run_flac $dopt --until=40 -o z50c.until40.$in_fmt z50c.$out_fmt || die "ERROR decoding FLAC file $desc"
554
	$CMP 50c.until40.$in_fmt z50c.until40.$in_fmt || die "ERROR: file mismatch for --until=40 (decode) $desc"
555
	rm -f z50c.until40.$in_fmt
556
557
	echo OK

558
	echo -n "testing --until=mm:ss (decode) $desc... "
559
560
561
	run_flac $dopt --until=0:04 -o z50c.until0_04.$in_fmt z50c.$out_fmt || die "ERROR decoding FLAC file $desc"
	$CMP 50c.until40.$in_fmt z50c.until0_04.$in_fmt || die "ERROR: file mismatch for --until=0:04 (decode) $desc"
	rm -f z50c.until0_04.$in_fmt
562
563
	echo OK

564
	echo -n "testing --until=mm:ss.sss (decode) $desc... "
565
566
567
	run_flac $dopt --until=0:03.9001 -o z50c.until0_03.9001.$in_fmt z50c.$out_fmt || die "ERROR decoding FLAC file $desc"
	$CMP 50c.until39.$in_fmt z50c.until0_03.9001.$in_fmt || die "ERROR: file mismatch for --until=0:03.9001 (decode) $desc"
	rm -f z50c.until0_03.9001.$in_fmt
568
569
	echo OK

570
571
	echo -n "testing --until=-# (decode) $desc... "
	run_flac $dopt --until=-10 -o z50c.until-10.$in_fmt z50c.$out_fmt || die "ERROR decoding FLAC file $desc"
572
	$CMP 50c.until40.$in_fmt z50c.until-10.$in_fmt || die "ERROR: file mismatch for --until=-10 (decode) $desc"
573
	rm -f z50c.until-10.$in_fmt
574
575
	echo OK

576
	echo -n "testing --until=-mm:ss (decode) $desc... "
577
578
579
	run_flac $dopt --until=-0:01 -o z50c.until-0_01.$in_fmt z50c.$out_fmt || die "ERROR decoding FLAC file $desc"
	$CMP 50c.until40.$in_fmt z50c.until-0_01.$in_fmt || die "ERROR: file mismatch for --until=-0:01 (decode) $desc"
	rm -f z50c.until-0_01.$in_fmt
580
581
	echo OK

582
	echo -n "testing --until=-mm:ss.sss (decode) $desc... "
583
584
585
	run_flac $dopt --until=-0:01.1001 -o z50c.until-0_01.1001.$in_fmt z50c.$out_fmt || die "ERROR decoding FLAC file $desc"
	$CMP 50c.until39.$in_fmt z50c.until-0_01.1001.$in_fmt || die "ERROR: file mismatch for --until=-0:01.1001 (decode) $desc"
	rm -f z50c.until-0_01.1001.$in_fmt
586
587
	echo OK

588
	rm -f z50c.$out_fmt
589
590
591
592
593

	#
	# test --skip and --until when encoding
	#

594
595
	echo -n "testing --skip=10 --until=# (encode) $desc... "
	run_flac $eopt --skip=10 --until=40 -o z50c.skip10.until40.$out_fmt 50c.$in_fmt || die "ERROR generating FLAC file $desc"
596
597
	[ $in_fmt = $out_fmt ] || run_flac $dopt -o z50c.skip10.until40.$in_fmt z50c.skip10.until40.$out_fmt || die "ERROR decoding FLAC file $desc"
	$CMP 50c.skip10.until40.$in_fmt z50c.skip10.until40.$in_fmt || die "ERROR: file mismatch for --skip=10 --until=40 (encode) $desc"
598
	rm -f z50c.skip10.until40.$out_fmt z50c.skip10.until40.$in_fmt
599
600
	echo OK

601
	echo -n "testing --skip=10 --until=mm:ss (encode) $desc... "
602
603
604
605
	run_flac $eopt --skip=10 --until=0:04 -o z50c.skip10.until0_04.$out_fmt 50c.$in_fmt || die "ERROR generating FLAC file $desc"
	[ $in_fmt = $out_fmt ] || run_flac $dopt -o z50c.skip10.until0_04.$in_fmt z50c.skip10.until0_04.$out_fmt || die "ERROR decoding FLAC file $desc"
	$CMP 50c.skip10.until40.$in_fmt z50c.skip10.until0_04.$in_fmt || die "ERROR: file mismatch for --skip=10 --until=0:04 (encode) $desc"
	rm -f z50c.skip10.until0_04.$out_fmt z50c.skip10.until0_04.$in_fmt
606
607
	echo OK

608
	echo -n "testing --skip=10 --until=mm:ss.sss (encode) $desc... "
609
610
611
612
	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"
	[ $in_fmt = $out_fmt ] || run_flac $dopt -o z50c.skip10.until0_03.9001.$in_fmt z50c.skip10.until0_03.9001.$out_fmt || die "ERROR decoding FLAC file $desc"
	$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"
	rm -f z50c.skip10.until0_03.9001.$out_fmt z50c.skip10.until0_03.9001.$in_fmt
613
614
	echo OK

615
616
	echo -n "testing --skip=10 --until=+# (encode) $desc... "
	run_flac $eopt --skip=10 --until=+30 -o z50c.skip10.until+30.$out_fmt 50c.$in_fmt || die "ERROR generating FLAC file $desc"
617
618
	[ $in_fmt = $out_fmt ] || run_flac $dopt -o z50c.skip10.until+30.$in_fmt z50c.skip10.until+30.$out_fmt || die "ERROR decoding FLAC file $desc"
	$CMP 50c.skip10.until40.$in_fmt z50c.skip10.until+30.$in_fmt || die "ERROR: file mismatch for --skip=10 --until=+30 (encode) $desc"
619
	rm -f z50c.skip10.until+30.$out_fmt z50c.skip10.until+30.$in_fmt
620
621
	echo OK

622
	echo -n "testing --skip=10 --until=+mm:ss (encode) $desc... "
623
624
625
626
	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"
	[ $in_fmt = $out_fmt ] || run_flac $dopt -o z50c.skip10.until+0_03.$in_fmt z50c.skip10.until+0_03.$out_fmt || die "ERROR decoding FLAC file $desc"
	$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"
	rm -f z50c.skip10.until+0_03.$out_fmt z50c.skip10.until+0_03.$in_fmt
627
628
	echo OK

629
	echo -n "testing --skip=10 --until=+mm:ss.sss (encode) $desc... "
630
631
632
633
	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"
	[ $in_fmt = $out_fmt ] || 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"
	$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"
	rm -f z50c.skip10.until+0_02.9001.$out_fmt z50c.skip10.until+0_02.9001.$in_fmt
634
635
	echo OK

636
637
	echo -n "testing --skip=10 --until=-# (encode) $desc... "
	run_flac $eopt --skip=10 --until=-10 -o z50c.skip10.until-10.$out_fmt 50c.$in_fmt || die "ERROR generating FLAC file $desc"
638
639
	[ $in_fmt = $out_fmt ] || run_flac $dopt -o z50c.skip10.until-10.$in_fmt z50c.skip10.until-10.$out_fmt || die "ERROR decoding FLAC file $desc"
	$CMP 50c.skip10.until40.$in_fmt z50c.skip10.until-10.$in_fmt || die "ERROR: file mismatch for --skip=10 --until=-10 (encode) $desc"
640
	rm -f z50c.skip10.until-10.$out_fmt z50c.skip10.until-10.$in_fmt
641
642
	echo OK

643
	echo -n "testing --skip=10 --until=-mm:ss (encode) $desc... "
644
645
646
647
	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"
	[ $in_fmt = $out_fmt ] || run_flac $dopt -o z50c.skip10.until-0_01.$in_fmt z50c.skip10.until-0_01.$out_fmt || die "ERROR decoding FLAC file $desc"
	$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"
	rm -f z50c.skip10.until-0_01.$out_fmt z50c.skip10.until-0_01.$in_fmt
648
649
	echo OK

650
	echo -n "testing --skip=10 --until=-mm:ss.sss (encode) $desc... "
651
652
653
654
	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"
	[ $in_fmt = $out_fmt ] || 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"
	$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"
	rm -f z50c.skip10.until-0_01.1001.$out_fmt z50c.skip10.until-0_01.1001.$in_fmt
655
656
657
658
659
660
	echo OK

	#
	# test --skip and --until when decoding
	#

661
662
	if [ $in_fmt != $out_fmt ] ; then run_flac $eopt -o z50c.$out_fmt 50c.$in_fmt ; else cp -f 50c.$in_fmt z50c.$out_fmt ; fi || die "ERROR generating FLAC file $desc"

663

664
665
	echo -n "testing --skip=10 --until=# (decode) $desc... "
	run_flac $dopt --skip=10 --until=40 -o z50c.skip10.until40.$in_fmt z50c.$out_fmt || die "ERROR decoding FLAC file $desc"
666
	$CMP 50c.skip10.until40.$in_fmt z50c.skip10.until40.$in_fmt || die "ERROR: file mismatch for --skip=10 --until=40 (decode) $desc"
667
	rm -f z50c.skip10.until40.$in_fmt
668
669
	echo OK

670
	echo -n "testing --skip=10 --until=mm:ss (decode) $desc... "
671
672
673
	run_flac $dopt --skip=10 --until=0:04 -o z50c.skip10.until0_04.$in_fmt z50c.$out_fmt || die "ERROR decoding FLAC file $desc"
	$CMP 50c.skip10.until40.$in_fmt z50c.skip10.until0_04.$in_fmt || die "ERROR: file mismatch for --skip=10 --until=0:04 (decode) $desc"
	rm -f z50c.skip10.until0_04.$in_fmt
674
675
	echo OK

676
	echo -n "testing --skip=10 --until=mm:ss.sss (decode) $desc... "
677
678
679
	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"
	$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"
	rm -f z50c.skip10.until0_03.9001.$in_fmt
680
681
	echo OK

682
683
	echo -n "testing --skip=10 --until=-# (decode) $desc... "
	run_flac $dopt --skip=10 --until=-10 -o z50c.skip10.until-10.$in_fmt z50c.$out_fmt || die "ERROR decoding FLAC file $desc"
684
	$CMP 50c.skip10.until40.$in_fmt z50c.skip10.until-10.$in_fmt || die "ERROR: file mismatch for --skip=10 --until=-10 (decode) $desc"
685
	rm -f z50c.skip10.until-10.$in_fmt
686
687
	echo OK

688
	echo -n "testing --skip=10 --until=-mm:ss (decode) $desc... "
689
690
691
	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"
	$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"
	rm -f z50c.skip10.until-0_01.$in_fmt
692
693
	echo OK

694
	echo -n "testing --skip=10 --until=-mm:ss.sss (decode) $desc... "
695
696
697
	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"
	$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"
	rm -f z50c.skip10.until-0_01.1001.$in_fmt
698
699
	echo OK

700
	rm -f z50c.$out_fmt
701
}
702

703
704
705
test_skip_until raw flac
test_skip_until wav flac
test_skip_until aiff flac
706
test_skip_until flac flac
707
708
709
710
#@@@if [ $has_ogg = yes ] ; then
#@@@	#@@@ doesn't work yet because md5cmp doesn't work because metaflac doesn't work on ogg flac yet
#@@@	test_skip_until ogg flac
#@@@fi
Josh Coalson's avatar
Josh Coalson committed
711

712
if [ $has_ogg = yes ] ; then
713
714
715
	test_skip_until raw ogg
	test_skip_until wav ogg
	test_skip_until aiff ogg
716
	#@@@ doesn't work yet because md5cmp doesn't work because metaflac doesn't work on ogg flac yet
717
	#@@@test_skip_until flac ogg
718
	#@@@test_skip_until ogg ogg
719
fi
Josh Coalson's avatar
Josh Coalson committed
720

Josh Coalson's avatar
Josh Coalson committed
721
echo "testing seek extremes:"
722

723
run_flac --verify --force $SILENT --no-padding --force-raw-format --endian=big --sign=signed --sample-rate=44100 --bps=16 --channels=2 --blocksize=576 noise.raw || die "ERROR generating FLAC file"
724

Josh Coalson's avatar
Josh Coalson committed
725
if [ $is_win = no ] ; then
726
	total_noise_cdda_samples=`run_metaflac --show-total-samples noise.flac`
Josh Coalson's avatar
Josh Coalson committed
727
728
729
730
731
	[ $? = 0 ] || die "ERROR getting total sample count from noise.flac"
else
	# some flavors of cygwin don't seem to treat the \x0d as a word
	# separator, so we hard code it.  we'll just have to fix it later
	# if we change the way noise.flac is made.
732
	total_noise_cdda_samples=393216
Josh Coalson's avatar
Josh Coalson committed
733
fi
734

Josh Coalson's avatar
Josh Coalson committed
735
echo -n "testing --skip=0... "
Josh Coalson's avatar
Josh Coalson committed
736
run_flac $wav_dopt --skip=0 -o z.wav noise.flac || die "ERROR decoding FLAC file noise.flac"
737
738
739
echo OK

for delta in 2 1 ; do
740
	n=`expr $total_noise_cdda_samples - $delta`
Josh Coalson's avatar
Josh Coalson committed
741
	echo -n "testing --skip=$n... "
Josh Coalson's avatar
Josh Coalson committed
742
	run_flac $wav_dopt --skip=$n -o z.wav noise.flac || die "ERROR decoding FLAC file noise.flac"
743
744
745
746
747
748
	echo OK
done

rm noise.flac z.wav


749
750
751
752
############################################################################
# test --input-size
############################################################################

Josh Coalson's avatar
Josh Coalson committed
753
#@@@ cat will not work on old cygwin, need to fix
754
755
756
757
758
759
760
761
if [ $is_win = no ] ; then
	echo -n "testing --input-size=50 --skip=10... "
	cat 50c.raw | run_flac $raw_eopt --input-size=50 --skip=10 -o z50c.skip10.flac - || die "ERROR generating FLAC file"
	run_flac $raw_dopt -o z50c.skip10.raw z50c.skip10.flac || die "ERROR decoding FLAC file"
	cmp 50c.skip10.raw z50c.skip10.raw || die "ERROR: file mismatch for --input-size=50 --skip=10"
	rm -f z50c.skip10.raw z50c.skip10.flac
	echo OK
fi
762
763


764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
############################################################################
# test --cue
############################################################################

#
# create the cue sheet
#
cuesheet=cuetest.cue
cat > $cuesheet << EOF
CATALOG 1234567890123
FILE "blah" WAVE
  TRACK 01 AUDIO
    INDEX 01 0
    INDEX 02 10
    INDEX 03 20
  TRACK 02 AUDIO
    INDEX 01 30
  TRACK 04 AUDIO
    INDEX 01 40
EOF

test_cue ()
{
	in_fmt=$1
	out_fmt=$2

790
	[ "$in_fmt" = wav ] || [ "$in_fmt" = aiff ] || [ "$in_fmt" = raw ] || [ "$in_fmt" = flac ] || [ "$in_fmt" = ogg ] || die "ERROR: internal error, bad 'in' format '$in_fmt'"
791
792
793
794
795
796
797
798
799
800
801

	[ "$out_fmt" = flac ] || [ "$out_fmt" = ogg ] || die "ERROR: internal error, bad 'out' format '$out_fmt'"

	if [ $in_fmt = raw ] ; then
		eopt="$raw_eopt"
		dopt="$raw_dopt"
	else
		eopt="$wav_eopt"
		dopt="$wav_dopt"
	fi

802
	if ( [ $in_fmt = flac ] || [ $in_fmt = ogg ] ) && ( [ $out_fmt = flac ] || [ $out_fmt = ogg ] ) ; then
803
804
805
806
807
		CMP=md5cmp
	else
		CMP=cmp
	fi

808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
	if [ $out_fmt = ogg ] ; then
		eopt="--ogg $eopt"
	fi

	desc="($in_fmt<->$out_fmt)"

	#
	# for this we need just need just one FLAC file; --cue only works while decoding
	#
	run_flac $eopt --cuesheet=$cuesheet -o z50c.cue.$out_fmt 50c.$in_fmt || die "ERROR generating FLAC file $desc"

	# To make it easy to translate from cue point to sample numbers, the
	# file has a sample rate of 10 Hz and a cuesheet like so:
	#
	# TRACK 01, INDEX 01 : 0:00.00 -> sample 0
	# TRACK 01, INDEX 02 : 0:01.00 -> sample 10
	# TRACK 01, INDEX 03 : 0:02.00 -> sample 20
	# TRACK 02, INDEX 01 : 0:03.00 -> sample 30
	# TRACK 04, INDEX 01 : 0:04.00 -> sample 40
	#
	echo -n "testing --cue=- $desc... "
829
830
831
	run_flac $dopt -o z50c.cued.$in_fmt --cue=- z50c.cue.$out_fmt || die "ERROR decoding FLAC file $desc"
	$CMP 50c.$in_fmt z50c.cued.$in_fmt || die "ERROR: file mismatch for --cue=- $desc"
	rm -f z50c.cued.$in_fmt
832
833
834
	echo OK

	echo -n "testing --cue=1.0 $desc... "
835
836
837
	run_flac $dopt -o z50c.cued.$in_fmt --cue=1.0 z50c.cue.$out_fmt || die "ERROR decoding FLAC file $desc"
	$CMP 50c.$in_fmt z50c.cued.$in_fmt || die "ERROR: file mismatch for --cue=1.0 $desc"
	rm -f z50c.cued.$in_fmt
838
839
840
	echo OK

	echo -n "testing --cue=1.0- $desc... "
841
842
843
	run_flac $dopt -o z50c.cued.$in_fmt --cue=1.0- z50c.cue.$out_fmt || die "ERROR decoding FLAC file $desc"
	$CMP 50c.$in_fmt z50c.cued.$in_fmt || die "ERROR: file mismatch for --cue=1.0- $desc"
	rm -f z50c.cued.$in_fmt
844
845
846
	echo OK

	echo -n "testing --cue=1.1 $desc... "
847
848
849
	run_flac $dopt -o z50c.cued.$in_fmt --cue=1.1 z50c.cue.$out_fmt || die "ERROR decoding FLAC file $desc"
	$CMP 50c.$in_fmt z50c.cued.$in_fmt || die "ERROR: file mismatch for --cue=1.1 $desc"
	rm -f z50c.cued.$in_fmt
850
851
852
	echo OK

	echo -n "testing --cue=1.1- $desc... "
853
854
855
	run_flac $dopt -o z50c.cued.$in_fmt --cue=1.1- z50c.cue.$out_fmt || die "ERROR decoding FLAC file $desc"
	$CMP 50c.$in_fmt z50c.cued.$in_fmt || die "ERROR: file mismatch for --cue=1.1- $desc"
	rm -f z50c.cued.$in_fmt
856
857
858
	echo OK

	echo -n "testing --cue=1.2 $desc... "
859
860
861
	run_flac $dopt -o z50c.cued.$in_fmt --cue=1.2 z50c.cue.$out_fmt || die "ERROR decoding FLAC file $desc"
	$CMP 50c.skip10.$in_fmt z50c.cued.$in_fmt || die "ERROR: file mismatch for --cue=1.2 $desc"
	rm -f z50c.cued.$in_fmt
862
863
864
	echo OK

	echo -n "testing --cue=1.2- $desc... "
865
866
867
	run_flac $dopt -o z50c.cued.$in_fmt --cue=1.2- z50c.cue.$out_fmt || die "ERROR decoding FLAC file $desc"
	$CMP 50c.skip10.$in_fmt z50c.cued.$in_fmt || die "ERROR: file mismatch for --cue=1.2- $desc"
	rm -f z50c.cued.$in_fmt
868
869
870
	echo OK

	echo -n "testing --cue=1.4 $desc... "
871
872
873
	run_flac $dopt -o z50c.cued.$in_fmt --cue=1.4 z50c.cue.$out_fmt || die "ERROR decoding FLAC file $desc"
	$CMP 50c.skip20.$in_fmt z50c.cued.$in_fmt || die "ERROR: file mismatch for --cue=1.4 $desc"
	rm -f z50c.cued.$in_fmt
874
875
876
	echo OK

	echo -n "testing --cue=1.4- $desc... "
877
878
879
	run_flac $dopt -o z50c.cued.$in_fmt --cue=1.4- z50c.cue.$out_fmt || die "ERROR decoding FLAC file $desc"
	$CMP 50c.skip20.$in_fmt z50c.cued.$in_fmt || die "ERROR: file mismatch for --cue=1.4- $desc"
	rm -f z50c.cued.$in_fmt
880
881
882
	echo OK

	echo -n "testing --cue=-5.0 $desc... "
883
884
885
	run_flac $dopt -o z50c.cued.$in_fmt --cue=-5.0 z50c.cue.$out_fmt || die "ERROR decoding FLAC file $desc"
	$CMP 50c.$in_fmt z50c.cued.$in_fmt || die "ERROR: file mismatch for --cue=-5.0 $desc"
	rm -f z50c.cued.$in_fmt
886
887
888
	echo OK

	echo -n "testing --cue=-4.1 $desc... "
889
890
891
	run_flac $dopt -o z50c.cued.$in_fmt --cue=-4.1 z50c.cue.$out_fmt || die "ERROR decoding FLAC file $desc"
	$CMP 50c.until40.$in_fmt z50c.cued.$in_fmt || die "ERROR: file mismatch for --cue=-4.1 $desc"
	rm -f z50c.cued.$in_fmt
892
893
894
	echo OK

	echo -n "testing --cue=-3.1 $desc... "
895
896
897
	run_flac $dopt -o z50c.cued.$in_fmt --cue=-3.1 z50c.cue.$out_fmt || die "ERROR decoding FLAC file $desc"
	$CMP 50c.until40.$in_fmt z50c.cued.$in_fmt || die "ERROR: file mismatch for --cue=-3.1 $desc"
	rm -f z50c.cued.$in_fmt
898
899
900
	echo OK

	echo -n "testing --cue=-1.4 $desc... "
901
902
903
	run_flac $dopt -o z50c.cued.$in_fmt --cue=-1.4 z50c.cue.$out_fmt || die "ERROR decoding FLAC file $desc"
	$CMP 50c.until30.$in_fmt z50c.cued.$in_fmt || die "ERROR: file mismatch for --cue=-1.4 $desc"
	rm -f z50c.cued.$in_fmt
904
905
906
	echo OK

	echo -n "testing --cue=1.0-5.0 $desc... "
907
908
909
	run_flac $dopt -o z50c.cued.$in_fmt --cue=1.0-5.0 z50c.cue.$out_fmt || die "ERROR decoding FLAC file $desc"
	$CMP 50c.$in_fmt z50c.cued.$in_fmt || die "ERROR: file mismatch for --cue=1.0-5.0 $desc"
	rm -f z50c.cued.$in_fmt
910
911
912
	echo OK

	echo -n "testing --cue=1.1-5.0 $desc... "
913
914
915
	run_flac $dopt -o z50c.cued.$in_fmt --cue=1.1-5.0 z50c.cue.$out_fmt || die "ERROR decoding FLAC file $desc"
	$CMP 50c.$in_fmt z50c.cued.$in_fmt || die "ERROR: file mismatch for --cue=1.1-5.0 $desc"
	rm -f z50c.cued.$in_fmt
916
917
918
	echo OK

	echo -n "testing --cue=1.2-4.1 $desc... "
919
920
921
	run_flac $dopt -o z50c.cued.$in_fmt --cue=1.2-4.1 z50c.cue.$out_fmt || die "ERROR decoding FLAC file $desc"
	$CMP 50c.skip10.until40.$in_fmt z50c.cued.$in_fmt || die "ERROR: file mismatch for --cue=1.2-4.1 $desc"
	rm -f z50c.cued.$in_fmt
922
923
924
	echo OK

	echo -n "testing --cue=1.4-2.0 $desc... "
925
926
927
	run_flac $dopt -o z50c.cued.$in_fmt --cue=1.4-2.0 z50c.cue.$out_fmt || die "ERROR decoding FLAC file $desc"
	$CMP 50c.skip20.until30.$in_fmt z50c.cued.$in_fmt || die "ERROR: file mismatch for --cue=1.4-2.0 $desc"
	rm -f z50c.cued.$in_fmt
928
929
930
931
932
933
934
935
	echo OK

	rm -f z50c.cue.$out_fmt
}

test_cue raw flac
test_cue wav flac
test_cue aiff flac
936
test_cue flac flac
937
938
939
940
#@@@if [ $has_ogg = yes ] ; then
#@@@	#@@@ doesn't work yet because md5cmp doesn't work because metaflac doesn't work on ogg flac yet
#@@@	test_cue ogg flac
#@@@fi
941

942
if [ $has_ogg = yes ] ; then
943
944
945
	test_cue raw ogg
	test_cue wav ogg
	test_cue aiff ogg
946
	#@@@ doesn't work yet because md5cmp doesn't work because metaflac doesn't work on ogg flac yet
947
	#@@@test_cue flac ogg
948
	#@@@test_cue ogg ogg
949
950
fi

Josh Coalson's avatar
Josh Coalson committed
951
952
953
954
955
956
957
############################################################################
# test 'fixup' code that happens when a FLAC file with total_samples == 0
# in the STREAMINFO block is converted to WAVE or AIFF, requiring the
# decoder go back and fix up the chunk headers
############################################################################

echo -n "WAVE fixup test... "
Josh Coalson's avatar
Josh Coalson committed
958

Josh Coalson's avatar
Josh Coalson committed
959
echo -n "prepare... "
960
convert_to_wav noise "$raw_eopt" "$wav_dopt" || die "ERROR creating reference WAVE"
Josh Coalson's avatar
Josh Coalson committed
961

Josh Coalson's avatar
Josh Coalson committed
962
echo -n "encode... "
Josh Coalson's avatar
Josh Coalson committed
963
964
965
966
967
# the pipe from 'cat' to 'flac' does not work on cygwin because of the EOF/
# binary-mode stdin problem, so we use an undocumented option to metaflac to
# set the total sample count to 0
if [ $is_win = yes ] ; then
	run_flac $raw_eopt noise.raw -o fixup.flac || die "ERROR generating FLAC file"
968
	run_metaflac --set-total-samples=0 fixup.flac 2> /dev/null
Josh Coalson's avatar
Josh Coalson committed
969
970
971
972
else
	cat noise.raw | run_flac $raw_eopt - -c > fixup.flac || die "ERROR generating FLAC file"
fi

Josh Coalson's avatar
Josh Coalson committed
973
974
echo -n "decode... "
run_flac $wav_dopt fixup.flac -o fixup.wav || die "ERROR decoding FLAC file"
Josh Coalson's avatar
Josh Coalson committed
975

Josh Coalson's avatar
Josh Coalson committed
976
977
echo -n "compare... "
cmp noise.wav fixup.wav || die "ERROR: file mismatch"
Josh Coalson's avatar
Josh Coalson committed
978

Josh Coalson's avatar
Josh Coalson committed
979
980
981
982
echo OK
rm -f noise.wav fixup.wav fixup.flac

echo -n "AIFF fixup test... "
Josh Coalson's avatar
Josh Coalson committed
983

Josh Coalson's avatar
Josh Coalson committed
984
echo -n "prepare... "
985
convert_to_aiff noise "$raw_eopt" "$wav_dopt" || die "ERROR creating reference AIFF"
Josh Coalson's avatar
Josh Coalson committed
986

Josh Coalson's avatar
Josh Coalson committed
987
echo -n "encode... "
Josh Coalson's avatar
Josh Coalson committed
988
989
990
991
992
# the pipe from 'cat' to 'flac' does not work on cygwin because of the EOF/
# binary-mode stdin problem, so we use an undocumented option to metaflac to
# set the total sample count to 0
if [ $is_win = yes ] ; then
	run_flac $raw_eopt noise.raw -o fixup.flac || die "ERROR generating FLAC file"
993
	run_metaflac --set-total-samples=0 fixup.flac 2> /dev/null
Josh Coalson's avatar
Josh Coalson committed
994
995
996
997
else
	cat noise.raw | run_flac $raw_eopt - -c > fixup.flac || die "ERROR generating FLAC file"
fi

Josh Coalson's avatar
Josh Coalson committed
998
999
echo -n "decode... "
run_flac $wav_dopt fixup.flac -o fixup.aiff || die "ERROR decoding FLAC file"
Josh Coalson's avatar
Josh Coalson committed
1000

Josh Coalson's avatar
Josh Coalson committed
1001
1002
echo -n "compare... "
cmp noise.aiff fixup.aiff || die "ERROR: file mismatch"
Josh Coalson's avatar
Josh Coalson committed
1003

Josh Coalson's avatar
Josh Coalson committed
1004
1005
1006
1007
1008
echo OK
rm -f noise.aiff fixup.aiff fixup.flac


############################################################################
Josh Coalson's avatar
Josh Coalson committed
1009
# multi-file tests
Josh Coalson's avatar
Josh Coalson committed
1010
############################################################################
Josh Coalson's avatar
Josh Coalson committed
1011
1012

echo "Generating multiple input files from noise..."
1013
multifile_format_decode="--endian=big --sign=signed"
1014
multifile_format_encode="$multifile_format_decode --sample-rate=44100 --bps=16 --channels=2 --no-padding"
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
short_noise_cdda_samples=`expr $total_noise_cdda_samples / 8`
run_flac --verify --force $SILENT --force-raw-format $multifile_format_encode --until=$short_noise_cdda_samples -o shortnoise.flac noise.raw || die "ERROR generating FLAC file"
run_flac --decode --force $SILENT shortnoise.flac -o shortnoise.raw --force-raw-format $multifile_format_decode || die "ERROR generating RAW file"
run_flac --decode --force $SILENT shortnoise.flac || die "ERROR generating WAVE file"
run_flac --decode --force $SILENT shortnoise.flac -o shortnoise.aiff || die "ERROR generating AIFF file"
cp shortnoise.flac file0.flac
cp shortnoise.flac file1.flac
cp shortnoise.flac file2.flac
rm -f shortnoise.flac
cp shortnoise.wav file0.wav
cp shortnoise.wav file1.wav
cp shortnoise.wav file2.wav
rm -f shortnoise.wav
cp shortnoise.aiff file0.aiff
cp shortnoise.aiff file1.aiff
cp shortnoise.aiff file2.aiff
rm -f shortnoise.aiff
cp shortnoise.raw file0.raw
cp shortnoise.raw file1.raw
cp shortnoise.raw file2.raw
rm -f shortnoise.raw
1036
# create authoritative sector-aligned files for comparison
1037
1038
1039
1040
file0_samples=`expr \( $short_noise_cdda_samples / 588 \) \* 588`
file0_remainder=`expr $short_noise_cdda_samples - $file0_samples`
file1_samples=`expr \( \( $file0_remainder + $short_noise_cdda_samples \) / 588 \) \* 588`
file1_remainder=`expr $file0_remainder + $short_noise_cdda_samples - $file1_samples`
1041
file1_samples=`expr $file1_samples - $file0_remainder`
1042
1043
file2_samples=`expr \( \( $file1_remainder + $short_noise_cdda_samples \) / 588 \) \* 588`
file2_remainder=`expr $file1_remainder + $short_noise_cdda_samples - $file2_samples`
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
file2_samples=`expr $file2_samples - $file1_remainder`
if [ $file2_remainder != '0' ] ; then
	file2_samples=`expr $file2_samples + $file2_remainder`
	file2_remainder=`expr 588 - $file2_remainder`
fi

dd if=file0.raw ibs=4 count=$file0_samples of=file0s.raw 2>/dev/null || $dddie
dd if=file0.raw ibs=4 count=$file0_remainder of=file1s.raw skip=$file0_samples 2>/dev/null || $dddie
dd if=file1.raw ibs=4 count=$file1_samples of=z.raw 2>/dev/null || $dddie
cat z.raw >> file1s.raw || die "ERROR: cat-ing sector-aligned files"
dd if=file1.raw ibs=4 count=$file1_remainder of=file2s.raw skip=$file1_samples 2>/dev/null || $dddie
dd if=file2.raw ibs=4 count=$file2_samples of=z.raw 2>/dev/null || $dddie
cat z.raw >> file2s.raw || die "ERROR: cat-ing sector-aligned files"
dd if=/dev/zero ibs=4 count=$file2_remainder of=z.raw 2>/dev/null || $dddie
cat z.raw >> file2s.raw || die "ERROR: cat-ing sector-aligned files"
rm -f z.raw

1061
1062
1063
convert_to_wav file0s "$multifile_format_encode --force" "$SILENT --force --decode" || die "ERROR creating authoritative sector-aligned WAVE"
convert_to_wav file1s "$multifile_format_encode --force" "$SILENT --force --decode" || die "ERROR creating authoritative sector-aligned WAVE"
convert_to_wav file2s "$multifile_format_encode --force" "$SILENT --force --decode" || die "ERROR creating authoritative sector-aligned WAVE"
1064

1065
1066
1067
convert_to_aiff file0s "$multifile_format_encode --force" "$SILENT --force --decode" || die "ERROR creating authoritative sector-aligned AIFF"
convert_to_aiff file1s "$multifile_format_encode --force" "$SILENT --force --decode" || die "ERROR creating authoritative sector-aligned AIFF"
convert_to_aiff file2s "$multifile_format_encode --force" "$SILENT --force --decode" || die "ERROR creating authoritative sector-aligned AIFF"
Josh Coalson's avatar
Josh Coalson committed
1068
1069
1070

test_multifile ()
{
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
	input_type=$1
	streamtype=$2
	sector_align=$3
	encode_options="$4"

	extra_encode_options=""
	extra_decode_options=""
	if [ $input_type = "raw" ] ; then
		extra_encode_options="--force-raw-format $multifile_format_encode"
		extra_decode_options="--force-raw-format $multifile_format_decode"
	else
		if [ $input_type = "aiff" ] ; then
			extra_decode_options="--force-aiff-format"
		fi
	fi
Josh Coalson's avatar
Josh Coalson committed
1086
1087

	if [ $streamtype = ogg ] ; then
1088
		suffix=oga
Josh Coalson's avatar
Josh Coalson committed
1089
1090
1091
1092
1093
1094
1095
1096
1097
		encode_options="$encode_options --ogg"
	else
		suffix=flac
	fi

	if [ $sector_align = sector_align ] ; then
		encode_options="$encode_options --sector-align"
	fi

1098
	if [ $input_type = flac ] || [ $input_type = ogg ] ; then
1099
1100
1101
1102
1103
		CMP=md5cmp
	else
		CMP=cmp
	fi

Josh Coalson's avatar
Josh Coalson committed
1104
	for n in 0 1 2 ; do