minor changes in anticipation of release
[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
26 echo "Generating streams..."
27 if test_streams ; then : ; else
28         echo "ERROR during test_streams" 1>&2
29         exit 1
30 fi
31
32 test_file ()
33 {
34         name=$1
35         channels=$2
36         bps=$3
37         encode_options="$4"
38
39         echo -n "$name: encode..."
40         cmd="flac -V -s -fr -fb -fs 44100 -fp $bps -fc $channels $encode_options $name.raw"
41         echo "### ENCODE $name #######################################################" >> ./streams.log
42         echo "###    cmd=$cmd" >> ./streams.log
43         if $cmd 2>>./streams.log ; then : ; else
44                 echo "ERROR during encode of $name" 1>&2
45                 exit 1
46         fi
47         echo -n "decode..."
48         cmd="flac -s -fb -d -fr -o $name.cmp $name.flac"
49         echo "### DECODE $name #######################################################" >> ./streams.log
50         echo "###    cmd=$cmd" >> ./streams.log
51         if $cmd 2>>./streams.log ; then : ; else
52                 echo "ERROR during decode of $name" 1>&2
53                 exit 1
54         fi
55         ls -1l $name.raw >> ./streams.log
56         ls -1l $name.flac >> ./streams.log
57         ls -1l $name.cmp >> ./streams.log
58         echo -n "compare..."
59         if cmp $name.raw $name.cmp ; then : ; else
60                 echo "ERROR during compare of $name" 1>&2
61                 exit 1
62         fi
63         echo OK
64 }
65
66 test_file_piped ()
67 {
68         name=$1
69         channels=$2
70         bps=$3
71         encode_options="$4"
72
73         if [ `env | grep -ic '^comspec='` != 0 ] ; then
74                 is_win=yes
75         else
76                 is_win=no
77         fi
78
79         echo -n "$name: encode via pipes..."
80         if [ $is_win = yes ] ; then
81                 cmd="flac -V -s -fr -fb -fs 44100 -fp $bps -fc $channels $encode_options -c $name.raw"
82                 echo "### ENCODE $name #######################################################" >> ./streams.log
83                 echo "###    cmd=$cmd" >> ./streams.log
84                 if $cmd 1>$name.flac 2>>./streams.log ; then : ; else
85                         echo "ERROR during encode of $name" 1>&2
86                         exit 1
87                 fi
88         else
89                 cmd="flac -V -s -fr -fb -fs 44100 -fp $bps -fc $channels $encode_options -c -"
90                 echo "### ENCODE $name #######################################################" >> ./streams.log
91                 echo "###    cmd=$cmd" >> ./streams.log
92                 if cat $name.raw | $cmd 1>$name.flac 2>>./streams.log ; then : ; else
93                         echo "ERROR during encode of $name" 1>&2
94                         exit 1
95                 fi
96         fi
97         echo -n "decode via pipes..."
98         if [ $is_win = yes ] ; then
99                 cmd="flac -s -fb -d -fr -c $name.flac"
100                 echo "### DECODE $name #######################################################" >> ./streams.log
101                 echo "###    cmd=$cmd" >> ./streams.log
102                 if $cmd 1>$name.cmp 2>>./streams.log ; then : ; else
103                         echo "ERROR during decode of $name" 1>&2
104                         exit 1
105                 fi
106         else
107                 cmd="flac -s -fb -d -fr -c -"
108                 echo "### DECODE $name #######################################################" >> ./streams.log
109                 echo "###    cmd=$cmd" >> ./streams.log
110                 if cat $name.flac | $cmd 1>$name.cmp 2>>./streams.log ; then : ; else
111                         echo "ERROR during decode of $name" 1>&2
112                         exit 1
113                 fi
114         fi
115         ls -1l $name.raw >> ./streams.log
116         ls -1l $name.flac >> ./streams.log
117         ls -1l $name.cmp >> ./streams.log
118         echo -n "compare..."
119         if cmp $name.raw $name.cmp ; then : ; else
120                 echo "ERROR during compare of $name" 1>&2
121                 exit 1
122         fi
123         echo OK
124 }
125
126 echo "Testing noise through pipes..."
127 test_file_piped noise 1 8 "-0"
128
129 echo "Testing small files..."
130 test_file test01 1 16 "-0 -l 16 -m -e -p"
131 test_file test02 2 16 "-0 -l 16 -m -e -p"
132 test_file test03 1 16 "-0 -l 16 -m -e -p"
133 test_file test04 2 16 "-0 -l 16 -m -e -p"
134
135 echo "Testing 8-bit full-scale deflection streams..."
136 for b in 01 02 03 04 05 06 07 ; do
137         test_file fsd8-$b 1 8 "-0 -l 16 -m -e -p"
138 done
139
140 echo "Testing 16-bit full-scale deflection streams..."
141 for b in 01 02 03 04 05 06 07 ; do
142         test_file fsd16-$b 1 16 "-0 -l 16 -m -e -p"
143 done
144
145 echo "Testing 24-bit full-scale deflection streams..."
146 for b in 01 02 03 04 05 06 07 ; do
147         test_file fsd24-$b 1 24 "-0 -l 16 -m -e -p"
148 done
149
150 echo "Testing 16-bit wasted-bits-per-sample streams..."
151 for b in 01 ; do
152         test_file wbps16-$b 1 16 "-0 -l 16 -m -e -p"
153 done
154
155 for bps in 16 24 ; do
156         echo "Testing $bps-bit sine wave streams..."
157         for b in 00 01 02 03 04 ; do
158                 test_file sine${bps}-$b 1 $bps "-0 -l 16 -m -e"
159         done
160         for b in 10 11 12 13 14 15 16 17 18 19 ; do
161                 test_file sine${bps}-$b 2 $bps "-0 -l 16 -m -e"
162         done
163 done
164
165 echo "Testing some frame header variations..."
166 test_file sine16-01 1 16 "-0 -l 8 -m -e -p --lax -b 16"
167 test_file sine16-01 1 16 "-0 -l 8 -m -e -p --lax -b 65535"
168 test_file sine16-01 1 16 "-0 -l 8 -m -e -p -b 16"
169 test_file sine16-01 1 16 "-0 -l 8 -m -e -p -b 65535"
170 test_file sine16-01 1 16 "-0 -l 8 -m -e -p --lax -fs 9"
171 test_file sine16-01 1 16 "-0 -l 8 -m -e -p --lax -fs 90"
172 test_file sine16-01 1 16 "-0 -l 8 -m -e -p --lax -fs 90000"
173 test_file sine16-01 1 16 "-0 -l 8 -m -e -p -fs 9"
174 test_file sine16-01 1 16 "-0 -l 8 -m -e -p -fs 90"
175 test_file sine16-01 1 16 "-0 -l 8 -m -e -p -fs 90000"
176
177 echo "Testing option variations..."
178 for f in 00 01 02 03 04 ; do
179         for opt in 0 1 2 4 5 6 8 ; do
180                 for extras in '' '-p' '-e' ; do
181                         test_file sine16-$f 1 16 "-$opt $extras"
182                 done
183         done
184 done
185 for f in 10 11 12 13 14 15 16 17 18 19 ; do
186         for opt in 0 1 2 4 5 6 8 ; do
187                 for extras in '' '-p' '-e' ; do
188                         test_file sine16-$f 2 16 "-$opt $extras"
189                 done
190         done
191 done
192
193 echo "Testing noise..."
194 for opt in 0 1 2 3 4 5 6 7 8 ; do
195         for extras in '' '-p' '-e' ; do
196                 for blocksize in '' '-b 32' '-b 32768' '-b 65535' ; do
197                         for channels in 1 2 4 8 ; do
198                                 for bps in 8 16 24 ; do
199                                         test_file noise $channels $bps "-$opt $extras $blocksize"
200                                 done
201                         done
202                 done
203         done
204 done