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