• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/sh -e
2
3#  FLAC - Free Lossless Audio Codec
4#  Copyright (C) 2001-2009  Josh Coalson
5#  Copyright (C) 2011-2016  Xiph.Org Foundation
6#
7#  This file is part the FLAC project.  FLAC is comprised of several
8#  components distributed under different licenses.  The codec libraries
9#  are distributed under Xiph.Org's BSD-like license (see the file
10#  COPYING.Xiph in this distribution).  All other programs, libraries, and
11#  plugins are distributed under the GPL (see COPYING.GPL).  The documentation
12#  is distributed under the Gnu FDL (see COPYING.FDL).  Each file in the
13#  FLAC distribution contains at the top the terms under which it may be
14#  distributed.
15#
16#  Since this particular file is relevant to all components of FLAC,
17#  it may be distributed under the Xiph.Org license, which is the least
18#  restrictive of those mentioned above.  See the file COPYING.Xiph in this
19#  distribution.
20
21. ./common.sh
22
23PATH=../src/flac:$PATH
24PATH=../src/test_streams:$PATH
25PATH=../objs/$BUILD/bin:$PATH
26
27if [ x"$FLAC__TEST_LEVEL" = x ] ; then
28	FLAC__TEST_LEVEL=1
29fi
30
31flac${EXE} --help 1>/dev/null 2>/dev/null || die "ERROR can't find flac executable"
32
33run_flac ()
34{
35	if [ x"$FLAC__TEST_WITH_VALGRIND" = xyes ] ; then
36		echo "valgrind --leak-check=yes --show-reachable=yes --num-callers=50 flac $*" >>test_streams.valgrind.log
37		valgrind --leak-check=yes --show-reachable=yes --num-callers=50 --log-fd=4 flac --no-error-on-compression-fail $* 4>>test_streams.valgrind.log
38	else
39		flac${EXE} --no-error-on-compression-fail $*
40	fi
41}
42
43echo "Generating streams..."
44if [ ! -f wacky1.wav ] ; then
45	test_streams || die "ERROR: missing files"
46fi
47
48#
49# single-file test routines
50#
51
52test_file ()
53{
54	name=$1
55	channels=$2
56	bps=$3
57	encode_options="$4"
58
59	echo $ECHO_N "$name (--channels=$channels --bps=$bps $encode_options): encode..." $ECHO_C
60	cmd="run_flac --verify --silent --force --force-raw-format --endian=little --sign=signed --sample-rate=44100 --bps=$bps --channels=$channels $encode_options --no-padding $name.raw"
61	echo "### ENCODE $name #######################################################" >> ./streams.log
62	echo "###    cmd=$cmd" >> ./streams.log
63	$cmd 2>>./streams.log || die "ERROR during encode of $name"
64
65	echo $ECHO_N "decode..." $ECHO_C
66	cmd="run_flac --silent --force --endian=little --sign=signed --decode --force-raw-format --output-name=$name.cmp $name.flac"
67	echo "### DECODE $name #######################################################" >> ./streams.log
68	echo "###    cmd=$cmd" >> ./streams.log
69	$cmd 2>>./streams.log || die "ERROR during decode of $name"
70
71	ls -1l $name.raw >> ./streams.log
72	ls -1l $name.flac >> ./streams.log
73	ls -1l $name.cmp >> ./streams.log
74
75	echo $ECHO_N "compare..." $ECHO_C
76	cmp $name.raw $name.cmp || die "ERROR during compare of $name"
77
78	echo OK
79}
80
81test_file_piped ()
82{
83	name=$1
84	channels=$2
85	bps=$3
86	encode_options="$4"
87
88	if [ `env | grep -ic '^comspec='` != 0 ] ; then
89		is_win=yes
90	else
91		is_win=no
92	fi
93
94	echo $ECHO_N "$name: encode via pipes..." $ECHO_C
95	if [ $is_win = yes ] ; then
96		cmd="run_flac --verify --silent --force --force-raw-format --endian=little --sign=signed --sample-rate=44100 --bps=$bps --channels=$channels $encode_options --no-padding --stdout $name.raw"
97		echo "### ENCODE $name #######################################################" >> ./streams.log
98		echo "###    cmd=$cmd" >> ./streams.log
99		$cmd 1>$name.flac 2>>./streams.log || die "ERROR during encode of $name"
100	else
101		cmd="run_flac --verify --silent --force --force-raw-format --endian=little --sign=signed --sample-rate=44100 --bps=$bps --channels=$channels $encode_options --no-padding --stdout -"
102		echo "### ENCODE $name #######################################################" >> ./streams.log
103		echo "###    cmd=$cmd" >> ./streams.log
104		cat $name.raw | $cmd 1>$name.flac 2>>./streams.log || die "ERROR during encode of $name"
105	fi
106	echo $ECHO_N "decode via pipes..." $ECHO_C
107	if [ $is_win = yes ] ; then
108		cmd="run_flac --silent --force --endian=little --sign=signed --decode --force-raw-format --stdout $name.flac"
109		echo "### DECODE $name #######################################################" >> ./streams.log
110		echo "###    cmd=$cmd" >> ./streams.log
111		$cmd 1>$name.cmp 2>>./streams.log || die "ERROR during decode of $name"
112	else
113		cmd="run_flac --silent --force --endian=little --sign=signed --decode --force-raw-format --stdout -"
114		echo "### DECODE $name #######################################################" >> ./streams.log
115		echo "###    cmd=$cmd" >> ./streams.log
116		cat $name.flac | $cmd 1>$name.cmp 2>>./streams.log || die "ERROR during decode of $name"
117	fi
118	ls -1l $name.raw >> ./streams.log
119	ls -1l $name.flac >> ./streams.log
120	ls -1l $name.cmp >> ./streams.log
121
122	echo $ECHO_N "compare..." $ECHO_C
123	cmp $name.raw $name.cmp || die "ERROR during compare of $name"
124
125	echo OK
126}
127
128if [ "$FLAC__TEST_LEVEL" -gt 1 ] ; then
129	max_lpc_order=32
130else
131	max_lpc_order=16
132fi
133
134echo "Testing noise through pipes..."
135test_file_piped noise 1 8 "-0"
136
137echo "Testing small files..."
138test_file test01 1 16 "-0 -l $max_lpc_order --lax -m -e -p"
139test_file test02 2 16 "-0 -l $max_lpc_order --lax -m -e -p"
140test_file test03 1 16 "-0 -l $max_lpc_order --lax -m -e -p"
141test_file test04 2 16 "-0 -l $max_lpc_order --lax -m -e -p"
142
143for bps in 8 16 24 ; do
144	echo "Testing $bps-bit full-scale deflection streams..."
145	for b in 01 02 03 04 05 06 07 ; do
146		test_file fsd$bps-$b 1 $bps "-0 -l $max_lpc_order --lax -m -e -p"
147	done
148done
149
150echo "Testing 16-bit wasted-bits-per-sample streams..."
151for b in 01 ; do
152	test_file wbps16-$b 1 16 "-0 -l $max_lpc_order --lax -m -e -p"
153done
154
155for bps in 8 16 24 ; do
156	echo "Testing $bps-bit sine wave streams..."
157	for b in 00 ; do
158		test_file sine${bps}-$b 1 $bps "-0 -l $max_lpc_order --lax -m -e --sample-rate=48000"
159	done
160	for b in 01 ; do
161		test_file sine${bps}-$b 1 $bps "-0 -l $max_lpc_order --lax -m -e --sample-rate=96000"
162	done
163	for b in 02 03 04 ; do
164		test_file sine${bps}-$b 1 $bps "-0 -l $max_lpc_order --lax -m -e"
165	done
166	for b in 10 11 ; do
167		test_file sine${bps}-$b 2 $bps "-0 -l $max_lpc_order --lax -m -e --sample-rate=48000"
168	done
169	for b in 12 ; do
170		test_file sine${bps}-$b 2 $bps "-0 -l $max_lpc_order --lax -m -e --sample-rate=96000"
171	done
172	for b in 13 14 15 16 17 18 19 ; do
173		test_file sine${bps}-$b 2 $bps "-0 -l $max_lpc_order --lax -m -e"
174	done
175done
176
177echo "Testing blocksize variations..."
178for disable in '' '--disable-verbatim-subframes --disable-constant-subframes' '--disable-verbatim-subframes --disable-constant-subframes --disable-fixed-subframes' ; do
179	for blocksize in 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 ; do
180		for lpc_order in 0 1 2 3 4 5 7 8 9 15 16 17 31 32 ; do
181			if [ $lpc_order = 0 ] || [ $lpc_order -le $blocksize ] ; then
182				test_file noise8m32 1 8 "-8 -p -e -l $lpc_order --lax --blocksize=$blocksize $disable"
183			fi
184		done
185	done
186done
187
188echo "Testing some frame header variations..."
189test_file sine16-01 1 16 "-0 -l $max_lpc_order -m -e -p --lax -b $max_lpc_order"
190test_file sine16-01 1 16 "-0 -l $max_lpc_order -m -e -p --lax -b 65535"
191test_file sine16-01 1 16 "-0 -l $max_lpc_order -m -e -p --lax --sample-rate=9"
192test_file sine16-01 1 16 "-0 -l $max_lpc_order -m -e -p --lax --sample-rate=90"
193test_file sine16-01 1 16 "-0 -l $max_lpc_order -m -e -p --lax --sample-rate=90000"
194test_file sine16-01 1 16 "-0 -l $max_lpc_order -m -e -p --lax --sample-rate=9"
195test_file sine16-01 1 16 "-0 -l $max_lpc_order -m -e -p --lax --sample-rate=90"
196test_file sine16-01 1 16 "-0 -l $max_lpc_order -m -e -p --lax --sample-rate=90000"
197
198echo "Testing option variations..."
199for f in 00 01 02 03 04 ; do
200	for disable in '' '--disable-verbatim-subframes --disable-constant-subframes' '--disable-verbatim-subframes --disable-constant-subframes --disable-fixed-subframes' ; do
201		if [ -z "$disable" ] || [ "$FLAC__TEST_LEVEL" -gt 0 ] ; then
202			for opt in 0 1 2 4 5 6 8 ; do
203				for extras in '' '-p' '-e' ; do
204					if [ -z "$extras" ] || [ "$FLAC__TEST_LEVEL" -gt 0 ] ; then
205						test_file sine16-$f 1 16 "-$opt $extras $disable"
206					fi
207				done
208			done
209			if [ "$FLAC__TEST_LEVEL" -gt 1 ] ; then
210				test_file sine16-$f 1 16 "-b 16384 -m -r 8 -l $max_lpc_order --lax -e -p $disable"
211			fi
212		fi
213	done
214done
215
216for f in 10 11 12 13 14 15 16 17 18 19 ; do
217	for disable in '' '--disable-verbatim-subframes --disable-constant-subframes' '--disable-verbatim-subframes --disable-constant-subframes --disable-fixed-subframes' ; do
218		if [ -z "$disable" ] || [ "$FLAC__TEST_LEVEL" -gt 0 ] ; then
219			for opt in 0 1 2 4 5 6 8 ; do
220				for extras in '' '-p' '-e' ; do
221					if [ -z "$extras" ] || [ "$FLAC__TEST_LEVEL" -gt 0 ] ; then
222						test_file sine16-$f 2 16 "-$opt $extras $disable"
223					fi
224				done
225			done
226			if [ "$FLAC__TEST_LEVEL" -gt 1 ] ; then
227				test_file sine16-$f 2 16 "-b 16384 -m -r 8 -l $max_lpc_order --lax -e -p $disable"
228			fi
229		fi
230	done
231done
232
233echo "Testing noise..."
234for disable in '' '--disable-verbatim-subframes --disable-constant-subframes' '--disable-verbatim-subframes --disable-constant-subframes --disable-fixed-subframes' ; do
235	if [ -z "$disable" ] || [ "$FLAC__TEST_LEVEL" -gt 0 ] ; then
236		for channels in 1 2 4 8 ; do
237			if [ $channels -le 2 ] || [ "$FLAC__TEST_LEVEL" -gt 0 ] ; then
238				for bps in 8 16 24 ; do
239					for opt in 0 1 2 3 4 5 6 7 8 ; do
240						for extras in '' '-p' '-e' ; do
241							if [ -z "$extras" ] || [ "$FLAC__TEST_LEVEL" -gt 0 ] ; then
242								for blocksize in '' '--lax -b 32' '--lax -b 32768' '--lax -b 65535' ; do
243									if [ -z "$blocksize" ] || [ "$FLAC__TEST_LEVEL" -gt 0 ] ; then
244										test_file noise $channels $bps "-$opt $extras $blocksize $disable"
245									fi
246								done
247							fi
248						done
249					done
250					if [ "$FLAC__TEST_LEVEL" -gt 1 ] ; then
251						test_file noise $channels $bps "-b 16384 -m -r 8 -l $max_lpc_order --lax -e -p $disable"
252					fi
253				done
254			fi
255		done
256	fi
257done
258