1fa0e2c523dca32be92a715fca99ae1c8095e1dd
[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 -V -s -fr -fb -fs 44100 -fp 16 -fc 2 noise.raw ; then : ; else
47         echo "ERROR generating FLAC file" 1>&2
48         exit 1
49 fi
50 if flac -d -s 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 f0.wav
56 cp f0.wav f1.wav
57 cp f1.wav f2.wav
58
59 test_multifile ()
60 {
61         streamtype=$1
62         encode_options="$2"
63
64         if [ $streamtype = ogg ] ; then
65                 suffix=ogg
66                 encode_options="$encode_options --ogg"
67         else
68                 suffix=flac
69         fi
70
71         if flac $encode_options f0.wav f1.wav f2.wav ; then : ; else
72                 echo "ERROR" 1>&2
73                 exit 1
74         fi
75         for n in 0 1 2 ; do
76                 mv f$n.$suffix f${n}x.$suffix
77         done
78         if flac -d f0x.$suffix f1x.$suffix f2x.$suffix ; then : ; else
79                 echo "ERROR" 1>&2
80                 exit 1
81         fi
82         for n in 0 1 2 ; do
83                 if cmp f$n.wav f${n}x.wav ; then : ; else
84                         echo "ERROR: file mismatch on file #$n" 1>&2
85                         exit 1
86                 fi
87         done
88         for n in 0 1 2 ; do
89                 rm -f f${n}x.$suffix f${n}x.wav
90         done
91 }
92
93 echo "Testing multiple files without verify..."
94 test_multifile flac ""
95
96 echo "Testing multiple files with verify..."
97 test_multifile flac "-V"
98
99 echo "Testing multiple files with --sector-align, without verify..."
100 test_multifile flac "--sector-align"
101
102 echo "Testing multiple files with --sector-align, with verify..."
103 test_multifile flac "--sector-align -V"
104
105 if [ $has_ogg = "yes" ] ; then
106         echo "Testing multiple files with --ogg, without verify..."
107         test_multifile ogg ""
108
109         echo "Testing multiple files with --ogg, with verify..."
110         test_multifile ogg "-V"
111
112         echo "Testing multiple files with --ogg and --sector-align, without verify..."
113         test_multifile flac "--ogg --sector-align"
114
115         echo "Testing multiple files with --ogg and --sector-align, with verify..."
116         test_multifile flac "--ogg --sector-align -V"
117 fi
118
119 exit 0
120
121 #
122 # single-file tests
123 #
124
125 test_file ()
126 {
127         name=$1
128         channels=$2
129         bps=$3
130         encode_options="$4"
131
132         echo -n "$name: encode..."
133         cmd="flac -V -s -fr -fb -fs 44100 -fp $bps -fc $channels $encode_options $name.raw"
134         echo "### ENCODE $name #######################################################" >> ./streams.log
135         echo "###    cmd=$cmd" >> ./streams.log
136         if $cmd 2>>./streams.log ; then : ; else
137                 echo "ERROR during encode of $name" 1>&2
138                 exit 1
139         fi
140         echo -n "decode..."
141         cmd="flac -s -fb -d -fr -o $name.cmp $name.flac"
142         echo "### DECODE $name #######################################################" >> ./streams.log
143         echo "###    cmd=$cmd" >> ./streams.log
144         if $cmd 2>>./streams.log ; then : ; else
145                 echo "ERROR during decode of $name" 1>&2
146                 exit 1
147         fi
148         ls -1l $name.raw >> ./streams.log
149         ls -1l $name.flac >> ./streams.log
150         ls -1l $name.cmp >> ./streams.log
151         echo -n "compare..."
152         if cmp $name.raw $name.cmp ; then : ; else
153                 echo "ERROR during compare of $name" 1>&2
154                 exit 1
155         fi
156         echo OK
157 }
158
159 test_file_piped ()
160 {
161         name=$1
162         channels=$2
163         bps=$3
164         encode_options="$4"
165
166         if [ `env | grep -ic '^comspec='` != 0 ] ; then
167                 is_win=yes
168         else
169                 is_win=no
170         fi
171
172         echo -n "$name: encode via pipes..."
173         if [ $is_win = yes ] ; then
174                 cmd="flac -V -s -fr -fb -fs 44100 -fp $bps -fc $channels $encode_options -c $name.raw"
175                 echo "### ENCODE $name #######################################################" >> ./streams.log
176                 echo "###    cmd=$cmd" >> ./streams.log
177                 if $cmd 1>$name.flac 2>>./streams.log ; then : ; else
178                         echo "ERROR during encode of $name" 1>&2
179                         exit 1
180                 fi
181         else
182                 cmd="flac -V -s -fr -fb -fs 44100 -fp $bps -fc $channels $encode_options -c -"
183                 echo "### ENCODE $name #######################################################" >> ./streams.log
184                 echo "###    cmd=$cmd" >> ./streams.log
185                 if cat $name.raw | $cmd 1>$name.flac 2>>./streams.log ; then : ; else
186                         echo "ERROR during encode of $name" 1>&2
187                         exit 1
188                 fi
189         fi
190         echo -n "decode via pipes..."
191         if [ $is_win = yes ] ; then
192                 cmd="flac -s -fb -d -fr -c $name.flac"
193                 echo "### DECODE $name #######################################################" >> ./streams.log
194                 echo "###    cmd=$cmd" >> ./streams.log
195                 if $cmd 1>$name.cmp 2>>./streams.log ; then : ; else
196                         echo "ERROR during decode of $name" 1>&2
197                         exit 1
198                 fi
199         else
200                 cmd="flac -s -fb -d -fr -c -"
201                 echo "### DECODE $name #######################################################" >> ./streams.log
202                 echo "###    cmd=$cmd" >> ./streams.log
203                 if cat $name.flac | $cmd 1>$name.cmp 2>>./streams.log ; then : ; else
204                         echo "ERROR during decode of $name" 1>&2
205                         exit 1
206                 fi
207         fi
208         ls -1l $name.raw >> ./streams.log
209         ls -1l $name.flac >> ./streams.log
210         ls -1l $name.cmp >> ./streams.log
211         echo -n "compare..."
212         if cmp $name.raw $name.cmp ; then : ; else
213                 echo "ERROR during compare of $name" 1>&2
214                 exit 1
215         fi
216         echo OK
217 }
218
219 echo "Testing noise through pipes..."
220 test_file_piped noise 1 8 "-0"
221
222 echo "Testing small files..."
223 test_file test01 1 16 "-0 -l 16 -m -e -p"
224 test_file test02 2 16 "-0 -l 16 -m -e -p"
225 test_file test03 1 16 "-0 -l 16 -m -e -p"
226 test_file test04 2 16 "-0 -l 16 -m -e -p"
227
228 echo "Testing 8-bit full-scale deflection streams..."
229 for b in 01 02 03 04 05 06 07 ; do
230         test_file fsd8-$b 1 8 "-0 -l 16 -m -e -p"
231 done
232
233 echo "Testing 16-bit full-scale deflection streams..."
234 for b in 01 02 03 04 05 06 07 ; do
235         test_file fsd16-$b 1 16 "-0 -l 16 -m -e -p"
236 done
237
238 echo "Testing 24-bit full-scale deflection streams..."
239 for b in 01 02 03 04 05 06 07 ; do
240         test_file fsd24-$b 1 24 "-0 -l 16 -m -e -p"
241 done
242
243 echo "Testing 16-bit wasted-bits-per-sample streams..."
244 for b in 01 ; do
245         test_file wbps16-$b 1 16 "-0 -l 16 -m -e -p"
246 done
247
248 for bps in 16 24 ; do
249         echo "Testing $bps-bit sine wave streams..."
250         for b in 00 01 02 03 04 ; do
251                 test_file sine${bps}-$b 1 $bps "-0 -l 16 -m -e"
252         done
253         for b in 10 11 12 13 14 15 16 17 18 19 ; do
254                 test_file sine${bps}-$b 2 $bps "-0 -l 16 -m -e"
255         done
256 done
257
258 echo "Testing some frame header variations..."
259 test_file sine16-01 1 16 "-0 -l 8 -m -e -p --lax -b 16"
260 test_file sine16-01 1 16 "-0 -l 8 -m -e -p --lax -b 65535"
261 test_file sine16-01 1 16 "-0 -l 8 -m -e -p -b 16"
262 test_file sine16-01 1 16 "-0 -l 8 -m -e -p -b 65535"
263 test_file sine16-01 1 16 "-0 -l 8 -m -e -p --lax -fs 9"
264 test_file sine16-01 1 16 "-0 -l 8 -m -e -p --lax -fs 90"
265 test_file sine16-01 1 16 "-0 -l 8 -m -e -p --lax -fs 90000"
266 test_file sine16-01 1 16 "-0 -l 8 -m -e -p -fs 9"
267 test_file sine16-01 1 16 "-0 -l 8 -m -e -p -fs 90"
268 test_file sine16-01 1 16 "-0 -l 8 -m -e -p -fs 90000"
269
270 echo "Testing option variations..."
271 for f in 00 01 02 03 04 ; do
272         for opt in 0 1 2 4 5 6 8 ; do
273                 for extras in '' '-p' '-e' ; do
274                         test_file sine16-$f 1 16 "-$opt $extras"
275                 done
276         done
277 done
278 for f in 10 11 12 13 14 15 16 17 18 19 ; do
279         for opt in 0 1 2 4 5 6 8 ; do
280                 for extras in '' '-p' '-e' ; do
281                         test_file sine16-$f 2 16 "-$opt $extras"
282                 done
283         done
284 done
285
286 echo "Testing noise..."
287 for opt in 0 1 2 3 4 5 6 7 8 ; do
288         for extras in '' '-p' '-e' ; do
289                 for blocksize in '' '-b 32' '-b 32768' '-b 65535' ; do
290                         for channels in 1 2 4 8 ; do
291                                 for bps in 8 16 24 ; do
292                                         test_file noise $channels $bps "-$opt $extras $blocksize"
293                                 done
294                         done
295                 done
296         done
297 done