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