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