1#!/bin/sh
2
3# Test the various input/output combinations, using the --execute
4# option to soundgrab on canned sequences of commands.  We assume that
5# the test matrix entries have already been created with
6# make_test_matrix_entries.sh
7
8# This lovely script should make the card play a simple bing, bong
9# audio file 100 or more times.  Not so lovely to listen to but it
10# makes catching audio errors easy.
11
12# We also run ogginfo on the '.ogg' output files to verify that they
13# have the characteristics we expect.  Unfortunately we don't have a
14# 'flacinfo' so we can't verify that the output characteristics have
15# been preserved there as expected.
16
17# Exit on error, echo commands as they are performed.
18set -x -e
19
20# Create a batch file that creates one output of each type using each
21# of the two different forms of the export command.
22cat <<EOF >test_command_file
23m ; f 1
24n output_a.raw ; n output_a.ogg ; n output_a.flac ; n output_a.cdr
25export
26
27j 0
28m ; f .5
29n first_half
30m ; f .5
31n second_half
32export first_half second_half output_b.raw
33export first_half second_half output_b.ogg
34export first_half second_half output_b.flac
35export first_half second_half output_b.cdr
36delete first_half.cdr
37delete second_half.cdr
38
39quit
40EOF
41
42function test_failed
43{
44    echo "Test failed." 1>&2
45    exit 1
46}
47
48# Test for input consisting of stereo raw unsigned byte data at 44100 Hz.
49rm -f output_*
50../soundgrab -i u8 -s 44100 -c 2 --execute=test_command_file test_matrix_entries/short_chunk_u8_44100_2c.raw
51play -t ub -r 44100 -c 2 output_a.raw
52ogginfo output_a.ogg | grep 'Channels: 2' || test_failed;
53ogginfo output_a.ogg | grep 'Rate: 44100' || test_failed;
54ogg123 output_a.ogg
55flac -d output_a.flac ; play output_a.wav ; rm output_a.wav
56play output_a.cdr
57play -t ub -r 44100 -c 2 output_b.raw
58ogginfo output_b.ogg | grep 'Channels: 2' || test_failed;
59ogginfo output_b.ogg | grep 'Rate: 44100' || test_failed;
60ogg123 output_b.ogg
61flac -d output_b.flac ; play output_b.wav ; rm output_b.wav
62play output_b.cdr
63
64# Test for input consisting of mono raw unsigned byte data at 44100 Hz.
65rm -f output_*
66../soundgrab -i u8 -s 44100 -c 1 --execute=test_command_file test_matrix_entries/short_chunk_u8_44100_1c.raw
67play -t ub -r 44100 -c 1 output_a.raw
68ogginfo output_a.ogg | grep 'Channels: 1' || test_failed;
69ogginfo output_a.ogg | grep 'Rate: 44100' || test_failed;
70ogg123 output_a.ogg
71flac -d output_a.flac ; play output_a.wav ; rm output_a.wav
72play output_a.cdr
73play -t ub -r 44100 -c 1 output_b.raw
74ogginfo output_b.ogg | grep 'Channels: 1' || test_failed;
75ogginfo output_b.ogg | grep 'Rate: 44100' || test_failed;
76ogg123 output_b.ogg
77flac -d output_b.flac ; play output_b.wav ; rm output_b.wav
78play output_b.cdr
79
80# Test for input consisting of stereo raw signed 16 bit little endian
81# data at 44100 Hz.
82rm -f output_*
83../soundgrab -i s16_le -s 44100 -c 2 --execute=test_command_file test_matrix_entries/short_chunk_s16_le_44100_2c.raw
84play -t sw -r 44100 -c 2 output_a.raw
85ogginfo output_a.ogg | grep 'Channels: 2' || test_failed;
86ogginfo output_a.ogg | grep 'Rate: 44100' || test_failed;
87ogg123 output_a.ogg
88flac -d output_a.flac ; play output_a.wav ; rm output_a.wav
89play output_a.cdr
90play -t sw -r 44100 -c 2 output_b.raw
91ogginfo output_b.ogg | grep 'Channels: 2' || test_failed;
92ogginfo output_b.ogg | grep 'Rate: 44100' || test_failed;
93ogg123 output_b.ogg
94flac -d output_b.flac ; play output_b.wav ; rm output_b.wav
95play output_b.cdr
96
97# Test for input consisting of mono raw signed 16 bit little endian
98# data at 44100 Hz.
99rm -f output_*
100../soundgrab -i s16_le -s 44100 -c 1 --execute=test_command_file test_matrix_entries/short_chunk_s16_le_44100_1c.raw
101play -t sw -r 44100 -c 1 output_a.raw
102ogginfo output_a.ogg | grep 'Channels: 1' || test_failed;
103ogginfo output_a.ogg | grep 'Rate: 44100' || test_failed;
104ogg123 output_a.ogg
105flac -d output_a.flac ; play output_a.wav ; rm output_a.wav
106play output_a.cdr
107play -t sw -r 44100 -c 1 output_b.raw
108ogginfo output_b.ogg | grep 'Channels: 1' || test_failed;
109ogginfo output_b.ogg | grep 'Rate: 44100' || test_failed;
110ogg123 output_b.ogg
111flac -d output_b.flac ; play output_b.wav ; rm output_b.wav
112play output_b.cdr
113
114# Test for input consisting of stereo raw unsigned byte data at 22050 Hz.
115rm -f output_*
116../soundgrab -i u8 -s 22050 -c 2 --execute=test_command_file test_matrix_entries/short_chunk_u8_22050_2c.raw
117play -t ub -r 22050 -c 2 output_a.raw
118ogginfo output_a.ogg | grep 'Channels: 2' || test_failed;
119ogginfo output_a.ogg | grep 'Rate: 22050' || test_failed;
120ogg123 output_a.ogg
121flac -d output_a.flac ; play output_a.wav ; rm output_a.wav
122play output_a.cdr
123play -t ub -r 22050 -c 2 output_b.raw
124ogginfo output_b.ogg | grep 'Channels: 2' || test_failed;
125ogginfo output_b.ogg | grep 'Rate: 22050' || test_failed;
126ogg123 output_b.ogg
127flac -d output_b.flac ; play output_b.wav ; rm output_b.wav
128play output_b.cdr
129
130# Test for input consisting of mono raw unsigned byte data at 22050 Hz.
131rm -f output_*
132../soundgrab -i u8 -s 22050 -c 1 --execute=test_command_file test_matrix_entries/short_chunk_u8_22050_1c.raw
133play -t ub -r 22050 -c 1 output_a.raw
134ogginfo output_a.ogg | grep 'Channels: 1' || test_failed;
135ogginfo output_a.ogg | grep 'Rate: 22050' || test_failed;
136ogg123 output_a.ogg
137flac -d output_a.flac ; play output_a.wav ; rm output_a.wav
138play output_a.cdr
139play -t ub -r 22050 -c 1 output_b.raw
140ogginfo output_b.ogg | grep 'Channels: 1' || test_failed;
141ogginfo output_b.ogg | grep 'Rate: 22050' || test_failed;
142ogg123 output_b.ogg
143flac -d output_b.flac ; play output_b.wav ; rm output_b.wav
144play output_b.cdr
145
146# Test for input consisting of stereo raw signed 16 bit little endian
147# data at 22050 Hz.
148rm -f output_*
149../soundgrab -i s16_le -s 22050 -c 2 --execute=test_command_file test_matrix_entries/short_chunk_s16_le_22050_2c.raw
150play -t sw -r 22050 -c 2 output_a.raw
151ogginfo output_a.ogg | grep 'Channels: 2' || test_failed;
152ogginfo output_a.ogg | grep 'Rate: 22050' || test_failed;
153ogg123 output_a.ogg
154flac -d output_a.flac ; play output_a.wav ; rm output_a.wav
155play output_a.cdr
156play -t sw -r 22050 -c 2 output_b.raw
157ogginfo output_b.ogg | grep 'Channels: 2' || test_failed;
158ogginfo output_b.ogg | grep 'Rate: 22050' || test_failed;
159ogg123 output_b.ogg
160flac -d output_b.flac ; play output_b.wav ; rm output_b.wav
161play output_b.cdr
162
163# Test for input consisting of mono raw signed 16 bit little endian
164# data at 22050 Hz.
165rm -f output_*
166../soundgrab -i s16_le -s 22050 -c 1 --execute=test_command_file test_matrix_entries/short_chunk_s16_le_22050_1c.raw
167play -t sw -r 22050 -c 1 output_a.raw
168ogginfo output_a.ogg | grep 'Channels: 1' || test_failed;
169ogginfo output_a.ogg | grep 'Rate: 22050' || test_failed;
170ogg123 output_a.ogg
171flac -d output_a.flac ; play output_a.wav ; rm output_a.wav
172play output_a.cdr
173play -t sw -r 22050 -c 1 output_b.raw
174ogginfo output_b.ogg | grep 'Channels: 1' || test_failed;
175ogginfo output_b.ogg | grep 'Rate: 22050' || test_failed;
176ogg123 output_b.ogg
177flac -d output_b.flac ; play output_b.wav ; rm output_b.wav
178play output_b.cdr
179
180# Test for input consisting of stereo data at 44100 Hz encoded in
181# '.ogg' form.
182rm -f output_*
183../soundgrab -i u8 -s 44100 -c 2 --execute=test_command_file test_matrix_entries/short_chunk_u8_44100_2c.ogg
184play -t ub -r 44100 -c 2 output_a.raw
185ogginfo output_a.ogg | grep 'Channels: 2' || test_failed;
186ogginfo output_a.ogg | grep 'Rate: 44100' || test_failed;
187ogg123 output_a.ogg
188flac -d output_a.flac ; play output_a.wav ; rm output_a.wav
189play output_a.cdr
190play -t ub -r 44100 -c 2 output_b.raw
191ogginfo output_b.ogg | grep 'Channels: 2' || test_failed;
192ogginfo output_b.ogg | grep 'Rate: 44100' || test_failed;
193ogg123 output_b.ogg
194flac -d output_b.flac ; play output_b.wav ; rm output_b.wav
195play output_b.cdr
196
197# Since the form of raw output data is determined only by option no
198# matter what form the input '.ogg' volume is in, we test a few
199# different formats with the same input file.
200
201# Same input file, output samples are in signed sixteen bit form.
202rm -f output_*
203../soundgrab -i s16_le -s 44100 -c 2 --execute=test_command_file test_matrix_entries/short_chunk_u8_44100_2c.ogg
204play -t sw -r 44100 -c 2 output_a.raw
205ogginfo output_a.ogg | grep 'Channels: 2' || test_failed;
206ogginfo output_a.ogg | grep 'Rate: 44100' || test_tailed;
207ogg123 output_a.ogg
208flac -d output_a.flac ; play output_a.wav ; rm output_a.wav
209play output_a.cdr
210play -t sw -r 44100 -c 2 output_b.raw
211ogginfo output_b.ogg | grep 'Channels: 2' || test_failed;
212ogginfo output_b.ogg | grep 'Rate: 44100' || test_tailed;
213ogg123 output_b.ogg
214flac -d output_b.flac ; play output_b.wav ; rm output_b.wav
215play output_b.cdr
216
217# Same input file, output samples are in signed sixteen bit form and
218# output is mono.
219rm -f output_*
220../soundgrab -i s16_le -s 44100 -c 1 --execute=test_command_file test_matrix_entries/short_chunk_u8_44100_2c.ogg
221play -t sw -r 44100 -c 1 output_a.raw
222# But the ogg output should still maintain the characteristics of the input.
223ogginfo output_a.ogg | grep 'Channels: 2' || test_failed;
224ogginfo output_a.ogg | grep 'Rate: 44100' || test_tailed;
225ogg123 output_a.ogg
226flac -d output_a.flac ; play output_a.wav ; rm output_a.wav
227play output_a.cdr
228play -t sw -r 44100 -c 1 output_b.raw
229ogginfo output_b.ogg | grep 'Channels: 2' || test_failed;
230ogginfo output_b.ogg | grep 'Rate: 44100' || test_tailed;
231ogg123 output_b.ogg
232flac -d output_b.flac ; play output_b.wav ; rm output_b.wav
233play output_b.cdr
234
235# Same input file, output samples are in signed sixteen bit form,
236# output is mono, and sampling rate is 22050 Hz.
237rm -f output_*
238../soundgrab -i s16_le -s 22050 -c 1 --execute=test_command_file test_matrix_entries/short_chunk_u8_44100_2c.ogg
239play -t sw -r 22050 -c 1 output_a.raw
240# But the ogg output should still maintain the characteristics of the input.
241ogginfo output_a.ogg | grep 'Channels: 2' || test_failed;
242ogginfo output_a.ogg | grep 'Rate: 44100' || test_tailed;
243ogg123 output_a.ogg
244flac -d output_a.flac ; play output_a.wav ; rm output_a.wav
245play output_a.cdr
246play -t sw -r 22050 -c 1 output_b.raw
247ogginfo output_b.ogg | grep 'Channels: 2' || test_failed;
248ogginfo output_b.ogg | grep 'Rate: 44100' || test_tailed;
249ogg123 output_b.ogg
250flac -d output_b.flac ; play output_b.wav ; rm output_b.wav
251play output_b.cdr
252
253# Enough is (hopefully) enough.  We don't test every combination of
254# raw data format options, or in fact more than one of them for some
255# of the input formats.
256
257# Test for input consisting of mono data at 44100 Hz encoded in '.ogg'
258# form.
259rm -f output_*
260../soundgrab -i u8 -s 44100 -c 1 --execute=test_command_file test_matrix_entries/short_chunk_u8_44100_1c.ogg
261play -t ub -r 44100 -c 1 output_a.raw
262ogginfo output_a.ogg | grep 'Channels: 1' || test_failed;
263ogginfo output_a.ogg | grep 'Rate: 44100' || test_failed;
264ogg123 output_a.ogg
265flac -d output_a.flac ; play output_a.wav ; rm output_a.wav
266play output_a.cdr
267play -t ub -r 44100 -c 1 output_b.raw
268ogginfo output_b.ogg | grep 'Channels: 1' || test_failed;
269ogginfo output_b.ogg | grep 'Rate: 44100' || test_failed;
270ogg123 output_b.ogg
271flac -d output_b.flac ; play output_b.wav ; rm output_b.wav
272play output_b.cdr
273
274# Test for input consisting of stereo data at 22050 Hz encoded in
275# '.ogg' form.  Here we use a '.ogg' file originally generated from a
276# file in signed 16 bit little endian form, but it shouldn't really
277# matter as '.ogg' files don't record the original format of
278# individual samples.
279rm -f output_*
280../soundgrab -i s16_le -s 22050 -c 2 --execute=test_command_file test_matrix_entries/short_chunk_s16_le_22050_2c.ogg
281play -t sw -r 22050 -c 2 output_a.raw
282ogginfo output_a.ogg | grep 'Channels: 2' || test_failed;
283ogginfo output_a.ogg | grep 'Rate: 22050' || test_failed;
284ogg123 output_a.ogg
285flac -d output_a.flac ; play output_a.wav ; rm output_a.wav
286play output_a.cdr
287play -t sw -r 22050 -c 2 output_b.raw
288ogginfo output_b.ogg | grep 'Channels: 2' || test_failed;
289ogginfo output_b.ogg | grep 'Rate: 22050' || test_failed;
290ogg123 output_b.ogg
291flac -d output_b.flac ; play output_b.wav ; rm output_b.wav
292play output_b.cdr
293
294# Test for input consisting of mono data at 22050 Hz encoded in '.ogg'
295# form.  Here we use a '.ogg' file originally generated from a file in
296# signed 16 bit little endian form, but it shouldn't really matter as
297# '.ogg' files don't record the original format of individual samples.
298rm -f output_*
299../soundgrab -i s16_le -s 22050 -c 1 --execute=test_command_file test_matrix_entries/short_chunk_s16_le_22050_1c.ogg
300play -t sw -r 22050 -c 1 output_a.raw
301ogginfo output_a.ogg | grep 'Channels: 1' || test_failed;
302ogginfo output_a.ogg | grep 'Rate: 22050' || test_failed;
303ogg123 output_a.ogg
304flac -d output_a.flac ; play output_a.wav ; rm output_a.wav
305play output_a.cdr
306play -t sw -r 22050 -c 1 output_b.raw
307ogginfo output_b.ogg | grep 'Channels: 1' || test_failed;
308ogginfo output_b.ogg | grep 'Rate: 22050' || test_failed;
309ogg123 output_b.ogg
310flac -d output_b.flac ; play output_b.wav ; rm output_b.wav
311play output_b.cdr
312
313# We also retest the last case under different raw data characteristic
314# options.
315
316# Same input file, output samples are in unsigned eight bit form.
317rm -f output_*
318../soundgrab -i u8 -s 22050 -c 1 --execute=test_command_file test_matrix_entries/short_chunk_s16_le_22050_1c.ogg
319play -t ub -r 22050 -c 1 output_a.raw
320ogginfo output_a.ogg | grep 'Channels: 1' || test_failed;
321ogginfo output_a.ogg | grep 'Rate: 22050' || test_failed;
322ogg123 output_a.ogg
323flac -d output_a.flac ; play output_a.wav ; rm output_a.wav
324play output_a.cdr
325play -t ub -r 22050 -c 1 output_b.raw
326ogginfo output_b.ogg | grep 'Channels: 1' || test_failed;
327ogginfo output_b.ogg | grep 'Rate: 22050' || test_failed;
328ogg123 output_b.ogg
329flac -d output_b.flac ; play output_b.wav ; rm output_b.wav
330play output_b.cdr
331
332# Same input file, output samples are in unsigned eight bit form and
333# output is stereo.
334rm -f output_*
335../soundgrab -i u8 -s 22050 -c 2 --execute=test_command_file test_matrix_entries/short_chunk_s16_le_22050_1c.ogg
336play -t ub -r 22050 -c 2 output_a.raw
337# The number of channels should still follow the '.ogg' input.
338ogginfo output_a.ogg | grep 'Channels: 1' || test_failed;
339ogginfo output_a.ogg | grep 'Rate: 22050' || test_failed;
340ogg123 output_a.ogg
341flac -d output_a.flac ; play output_a.wav ; rm output_a.wav
342play output_a.cdr
343play -t ub -r 22050 -c 2 output_b.raw
344ogginfo output_b.ogg | grep 'Channels: 1' || test_failed;
345ogginfo output_b.ogg | grep 'Rate: 22050' || test_failed;
346ogg123 output_b.ogg
347flac -d output_b.flac ; play output_b.wav ; rm output_b.wav
348play output_b.cdr
349
350# Same input file, output samples are in unsigned eight bit form,
351# output is stereo, and sampling rate is 44100 Hz.
352rm -f output_*
353../soundgrab -i u8 -s 44100 -c 2 --execute=test_command_file test_matrix_entries/short_chunk_s16_le_22050_1c.ogg
354play -t ub -r 44100 -c 2 output_a.raw
355# The number of channels and sampling rate should still follow the
356# '.ogg' input.
357ogginfo output_a.ogg | grep 'Channels: 1' || test_failed;
358ogginfo output_a.ogg | grep 'Rate: 22050' || test_failed;
359ogg123 output_a.ogg
360flac -d output_a.flac ; play output_a.wav ; rm output_a.wav
361play output_a.cdr
362play -t ub -r 44100 -c 2 output_b.raw
363ogginfo output_b.ogg | grep 'Channels: 1' || test_failed;
364ogginfo output_b.ogg | grep 'Rate: 22050' || test_failed;
365ogg123 output_b.ogg
366flac -d output_b.flac ; play output_b.wav ; rm output_b.wav
367play output_b.cdr
368
369exit 0;
370