2
** Copyright (C) 1999-2005 Erik de Castro Lopo <erikd@mega-nerd.com>
4
** This program is free software; you can redistribute it and/or modify
5
** it under the terms of the GNU General Public License as published by
6
** the Free Software Foundation; either version 2 of the License, or
7
** (at your option) any later version.
9
** This program is distributed in the hope that it will be useful,
10
** but WITHOUT ANY WARRANTY; without even the implied warranty of
11
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
** GNU General Public License for more details.
14
** You should have received a copy of the GNU General Public License
15
** along with this program; if not, write to the Free Software
16
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
34
#define BUFFER_SIZE (1<<14) /* Should be (1<<14) */
35
#define SAMPLE_RATE 11025
38
#define M_PI 3.14159265358979323846264338
41
static void lcomp_test_short (const char *filename, int filetype, int chan, double margin) ;
42
static void lcomp_test_int (const char *filename, int filetype, int chan, double margin) ;
43
static void lcomp_test_float (const char *filename, int filetype, int chan, double margin) ;
44
static void lcomp_test_double (const char *filename, int filetype, int chan, double margin) ;
46
static void sdlcomp_test_short (const char *filename, int filetype, int chan, double margin) ;
47
static void sdlcomp_test_int (const char *filename, int filetype, int chan, double margin) ;
48
static void sdlcomp_test_float (const char *filename, int filetype, int chan, double margin) ;
49
static void sdlcomp_test_double (const char *filename, int filetype, int chan, double margin) ;
51
static int error_function (double data, double orig, double margin) ;
52
static int decay_response (int k) ;
54
static void gen_signal_double (double *data, double scale, int channels, int datalen) ;
56
static void smoothed_diff_short (short *data, unsigned int datalen) ;
57
static void smoothed_diff_int (int *data, unsigned int datalen) ;
58
static void smoothed_diff_float (float *data, unsigned int datalen) ;
59
static void smoothed_diff_double (double *data, unsigned int datalen) ;
61
static void check_comment (SNDFILE * file, int format, int lineno) ;
64
** Force the start of these buffers to be double aligned. Sparc-solaris will
65
** choke if they are not.
67
static double data_buffer [BUFFER_SIZE + 1] ;
68
static double orig_buffer [BUFFER_SIZE + 1] ;
69
static double smooth_buffer [BUFFER_SIZE + 1] ;
71
static const char *long_comment =
72
"This is really quite a long comment. It is designed to be long enough "
73
"to screw up the encoders and decoders if the file container format does "
74
"not handle things correctly. If everything is working correctly, the "
75
"decoder will only decode the actual audio data, and not this string at "
76
"the end of the file." ;
79
main (int argc, char *argv [])
84
{ printf ("Usage : %s <test>\n", argv [0]) ;
85
printf (" Where <test> is one of the following:\n") ;
86
printf (" wav_ima - test IMA ADPCM WAV file functions\n") ;
87
printf (" wav_msadpcm - test MS ADPCM WAV file functions\n") ;
88
printf (" wav_gsm610 - test GSM 6.10 WAV file functions\n") ;
89
printf (" wav_ulaw - test u-law WAV file functions\n") ;
90
printf (" wav_alaw - test A-law WAV file functions\n") ;
91
printf (" all - perform all tests\n") ;
95
do_all = ! strcmp (argv [1], "all") ;
97
if (strcmp (argv [1], "wav_pcm") == 0)
98
{ /* This is just a sanity test for PCM encoding. */
99
lcomp_test_short ("pcm.wav", SF_FORMAT_WAV | SF_FORMAT_PCM_16, 2, 0.00001) ;
100
lcomp_test_int ("pcm.wav", SF_FORMAT_WAV | SF_FORMAT_PCM_16, 2, 0.00001) ;
101
lcomp_test_short ("pcm.rifx", SF_ENDIAN_BIG | SF_FORMAT_WAV | SF_FORMAT_PCM_16, 2, 0.00001) ;
102
lcomp_test_int ("pcm.rifx", SF_ENDIAN_BIG | SF_FORMAT_WAV | SF_FORMAT_PCM_16, 2, 0.00001) ;
103
/* Lite remove start */
104
lcomp_test_float ("pcm.wav", SF_FORMAT_WAV | SF_FORMAT_PCM_16, 2, 0.005) ;
105
lcomp_test_double ("pcm.wav", SF_FORMAT_WAV | SF_FORMAT_PCM_16, 2, 0.005) ;
106
/* Lite remove end */
110
/* For all the rest, if the file format supports more than 1 channel, use stereo. */
111
/* Lite remove start */
112
if (do_all || strcmp (argv [1], "wav_ima") == 0)
113
{ lcomp_test_short ("ima.wav", SF_FORMAT_WAV | SF_FORMAT_IMA_ADPCM, 2, 0.18) ;
114
lcomp_test_int ("ima.wav", SF_FORMAT_WAV | SF_FORMAT_IMA_ADPCM, 2, 0.18) ;
115
lcomp_test_float ("ima.wav", SF_FORMAT_WAV | SF_FORMAT_IMA_ADPCM, 2, 0.18) ;
116
lcomp_test_double ("ima.wav", SF_FORMAT_WAV | SF_FORMAT_IMA_ADPCM, 2, 0.18) ;
118
lcomp_test_short ("ima.rifx", SF_ENDIAN_BIG | SF_FORMAT_WAV | SF_FORMAT_IMA_ADPCM, 2, 0.18) ;
119
lcomp_test_int ("ima.rifx", SF_ENDIAN_BIG | SF_FORMAT_WAV | SF_FORMAT_IMA_ADPCM, 2, 0.18) ;
120
lcomp_test_float ("ima.rifx", SF_ENDIAN_BIG | SF_FORMAT_WAV | SF_FORMAT_IMA_ADPCM, 2, 0.18) ;
121
lcomp_test_double ("ima.rifx", SF_ENDIAN_BIG | SF_FORMAT_WAV | SF_FORMAT_IMA_ADPCM, 2, 0.18) ;
123
sdlcomp_test_short ("ima.wav", SF_FORMAT_WAV | SF_FORMAT_IMA_ADPCM, 2, 0.18) ;
124
sdlcomp_test_int ("ima.wav", SF_FORMAT_WAV | SF_FORMAT_IMA_ADPCM, 2, 0.18) ;
125
sdlcomp_test_float ("ima.wav", SF_FORMAT_WAV | SF_FORMAT_IMA_ADPCM, 2, 0.18) ;
126
sdlcomp_test_double ("ima.wav", SF_FORMAT_WAV | SF_FORMAT_IMA_ADPCM, 2, 0.18) ;
130
if (do_all || strcmp (argv [1], "wav_msadpcm") == 0)
131
{ lcomp_test_short ("msadpcm.wav", SF_FORMAT_WAV | SF_FORMAT_MS_ADPCM, 2, 0.36) ;
132
lcomp_test_int ("msadpcm.wav", SF_FORMAT_WAV | SF_FORMAT_MS_ADPCM, 2, 0.36) ;
133
lcomp_test_float ("msadpcm.wav", SF_FORMAT_WAV | SF_FORMAT_MS_ADPCM, 2, 0.36) ;
134
lcomp_test_double ("msadpcm.wav", SF_FORMAT_WAV | SF_FORMAT_MS_ADPCM, 2, 0.36) ;
136
lcomp_test_short ("msadpcm.rifx", SF_ENDIAN_BIG | SF_FORMAT_WAV | SF_FORMAT_MS_ADPCM, 2, 0.36) ;
137
lcomp_test_int ("msadpcm.rifx", SF_ENDIAN_BIG | SF_FORMAT_WAV | SF_FORMAT_MS_ADPCM, 2, 0.36) ;
138
lcomp_test_float ("msadpcm.rifx", SF_ENDIAN_BIG | SF_FORMAT_WAV | SF_FORMAT_MS_ADPCM, 2, 0.36) ;
139
lcomp_test_double ("msadpcm.rifx", SF_ENDIAN_BIG | SF_FORMAT_WAV | SF_FORMAT_MS_ADPCM, 2, 0.36) ;
141
sdlcomp_test_short ("msadpcm.wav", SF_FORMAT_WAV | SF_FORMAT_MS_ADPCM, 2, 0.36) ;
142
sdlcomp_test_int ("msadpcm.wav", SF_FORMAT_WAV | SF_FORMAT_MS_ADPCM, 2, 0.36) ;
143
sdlcomp_test_float ("msadpcm.wav", SF_FORMAT_WAV | SF_FORMAT_MS_ADPCM, 2, 0.36) ;
144
sdlcomp_test_double ("msadpcm.wav", SF_FORMAT_WAV | SF_FORMAT_MS_ADPCM, 2, 0.36) ;
149
if (do_all || strcmp (argv [1], "wav_g721") == 0)
150
{ printf ("**** Fix this later : error bound should be 0.06 ****\n") ;
151
lcomp_test_short ("g721.wav", SF_FORMAT_WAV | SF_FORMAT_G721_32, 1, 0.7) ;
152
lcomp_test_int ("g721.wav", SF_FORMAT_WAV | SF_FORMAT_G721_32, 1, 0.7) ;
154
lcomp_test_short ("g721.rifx", SF_ENDIAN_BIG | SF_FORMAT_WAV | SF_FORMAT_G721_32, 1, 0.7) ;
155
lcomp_test_int ("g721.rifx", SF_ENDIAN_BIG | SF_FORMAT_WAV | SF_FORMAT_G721_32, 1, 0.7) ;
159
/* Lite remove end */
161
if (do_all || strcmp (argv [1], "wav_ulaw") == 0)
162
{ lcomp_test_short ("ulaw.wav", SF_FORMAT_WAV | SF_FORMAT_ULAW, 2, 0.04) ;
163
lcomp_test_int ("ulaw.wav", SF_FORMAT_WAV | SF_FORMAT_ULAW, 2, 0.04) ;
165
lcomp_test_short ("ulaw.rifx", SF_ENDIAN_BIG | SF_FORMAT_WAV | SF_FORMAT_ULAW, 2, 0.04) ;
166
lcomp_test_int ("ulaw.rifx", SF_ENDIAN_BIG | SF_FORMAT_WAV | SF_FORMAT_ULAW, 2, 0.04) ;
168
/* Lite remove start */
169
lcomp_test_float ("ulaw.wav", SF_FORMAT_WAV | SF_FORMAT_ULAW, 2, 0.04) ;
170
lcomp_test_double ("ulaw.wav", SF_FORMAT_WAV | SF_FORMAT_ULAW, 2, 0.04) ;
171
/* Lite remove end */
175
if (do_all || strcmp (argv [1], "wav_alaw") == 0)
176
{ lcomp_test_short ("alaw.wav", SF_FORMAT_WAV | SF_FORMAT_ALAW, 2, 0.04) ;
177
lcomp_test_int ("alaw.wav", SF_FORMAT_WAV | SF_FORMAT_ALAW, 2, 0.04) ;
178
/* Lite remove start */
179
lcomp_test_float ("alaw.wav", SF_FORMAT_WAV | SF_FORMAT_ALAW, 2, 0.04) ;
180
lcomp_test_double ("alaw.wav", SF_FORMAT_WAV | SF_FORMAT_ALAW, 2, 0.04) ;
181
/* Lite remove end */
185
if (do_all || strcmp (argv [1], "wav_gsm610") == 0)
186
{ /* Don't do lcomp_test_XXX as the errors are too big. */
187
sdlcomp_test_short ("gsm610.wav", SF_FORMAT_WAV | SF_FORMAT_GSM610, 1, 0.24) ;
188
sdlcomp_test_int ("gsm610.wav", SF_FORMAT_WAV | SF_FORMAT_GSM610, 1, 0.24) ;
190
sdlcomp_test_short ("gsm610.rifx", SF_ENDIAN_BIG | SF_FORMAT_WAV | SF_FORMAT_GSM610, 1, 0.24) ;
191
sdlcomp_test_int ("gsm610.rifx", SF_ENDIAN_BIG | SF_FORMAT_WAV | SF_FORMAT_GSM610, 1, 0.24) ;
193
/* Lite remove start */
194
sdlcomp_test_float ("gsm610.wav", SF_FORMAT_WAV | SF_FORMAT_GSM610, 1, 0.24) ;
195
sdlcomp_test_double ("gsm610.wav", SF_FORMAT_WAV | SF_FORMAT_GSM610, 1, 0.24) ;
196
/* Lite remove end */
200
if (do_all || strcmp (argv [1], "aiff_ulaw") == 0)
201
{ lcomp_test_short ("ulaw.aiff", SF_FORMAT_AIFF | SF_FORMAT_ULAW, 2, 0.04) ;
202
lcomp_test_int ("ulaw.aiff", SF_FORMAT_AIFF | SF_FORMAT_ULAW, 2, 0.04) ;
203
/* Lite remove start */
204
lcomp_test_float ("ulaw.aiff", SF_FORMAT_AIFF | SF_FORMAT_ULAW, 2, 0.04) ;
205
lcomp_test_double ("ulaw.aiff", SF_FORMAT_AIFF | SF_FORMAT_ULAW, 2, 0.04) ;
206
/* Lite remove end */
210
if (do_all || strcmp (argv [1], "aiff_alaw") == 0)
211
{ lcomp_test_short ("alaw.aiff", SF_FORMAT_AIFF | SF_FORMAT_ALAW, 2, 0.04) ;
212
lcomp_test_int ("alaw.aiff", SF_FORMAT_AIFF | SF_FORMAT_ALAW, 2, 0.04) ;
213
/* Lite remove start */
214
lcomp_test_float ("alaw.aiff", SF_FORMAT_AIFF | SF_FORMAT_ALAW, 2, 0.04) ;
215
lcomp_test_double ("alaw.aiff", SF_FORMAT_AIFF | SF_FORMAT_ALAW, 2, 0.04) ;
216
/* Lite remove end */
220
if (do_all || strcmp (argv [1], "aiff_gsm610") == 0)
221
{ /* Don't do lcomp_test_XXX as the errors are too big. */
222
sdlcomp_test_short ("gsm610.aiff", SF_FORMAT_AIFF | SF_FORMAT_GSM610, 1, 0.24) ;
223
sdlcomp_test_int ("gsm610.aiff", SF_FORMAT_AIFF | SF_FORMAT_GSM610, 1, 0.24) ;
224
/* Lite remove start */
225
sdlcomp_test_float ("gsm610.aiff", SF_FORMAT_AIFF | SF_FORMAT_GSM610, 1, 0.24) ;
226
sdlcomp_test_double ("gsm610.aiff", SF_FORMAT_AIFF | SF_FORMAT_GSM610, 1, 0.24) ;
227
/* Lite remove end */
231
if (strcmp (argv [1], "aiff_ima") == 0)
232
{ lcomp_test_short ("ima.aiff", SF_FORMAT_AIFF | SF_FORMAT_IMA_ADPCM, 2, 0.18) ;
233
lcomp_test_int ("ima.aiff", SF_FORMAT_AIFF | SF_FORMAT_IMA_ADPCM, 2, 0.18) ;
234
/* Lite remove start */
235
lcomp_test_float ("ima.aiff", SF_FORMAT_AIFF | SF_FORMAT_IMA_ADPCM, 2, 0.18) ;
236
lcomp_test_double ("ima.aiff", SF_FORMAT_AIFF | SF_FORMAT_IMA_ADPCM, 2, 0.18) ;
237
/* Lite remove end */
240
if (do_all || strcmp (argv [1], "au_ulaw") == 0)
241
{ lcomp_test_short ("ulaw.au", SF_ENDIAN_BIG | SF_FORMAT_AU | SF_FORMAT_ULAW, 2, 0.04) ;
242
lcomp_test_int ("ulaw.au", SF_ENDIAN_LITTLE | SF_FORMAT_AU | SF_FORMAT_ULAW, 2, 0.04) ;
243
/* Lite remove start */
244
lcomp_test_float ("ulaw.au", SF_ENDIAN_LITTLE | SF_FORMAT_AU | SF_FORMAT_ULAW, 2, 0.04) ;
245
lcomp_test_double ("ulaw.au", SF_ENDIAN_BIG | SF_FORMAT_AU | SF_FORMAT_ULAW, 2, 0.04) ;
246
/* Lite remove end */
250
if (do_all || strcmp (argv [1], "au_alaw") == 0)
251
{ lcomp_test_short ("alaw.au", SF_ENDIAN_LITTLE | SF_FORMAT_AU | SF_FORMAT_ALAW, 2, 0.04) ;
252
lcomp_test_int ("alaw.au", SF_ENDIAN_BIG | SF_FORMAT_AU | SF_FORMAT_ALAW, 2, 0.04) ;
253
/* Lite remove start */
254
lcomp_test_float ("alaw.au", SF_ENDIAN_BIG | SF_FORMAT_AU | SF_FORMAT_ALAW, 2, 0.04) ;
255
lcomp_test_double ("alaw.au", SF_ENDIAN_LITTLE | SF_FORMAT_AU | SF_FORMAT_ALAW, 2, 0.04) ;
256
/* Lite remove end */
260
/* Lite remove start */
261
if (do_all || strcmp (argv [1], "au_g721") == 0)
262
{ printf ("**** Fix this later : error bound should be 0.06 ****\n") ;
263
lcomp_test_short ("g721.au", SF_ENDIAN_LITTLE | SF_FORMAT_AU | SF_FORMAT_G721_32, 1, 0.7) ;
264
lcomp_test_int ("g721.au", SF_ENDIAN_BIG | SF_FORMAT_AU | SF_FORMAT_G721_32, 1, 0.7) ;
265
lcomp_test_float ("g721.au", SF_ENDIAN_LITTLE | SF_FORMAT_AU | SF_FORMAT_G721_32, 1, 0.7) ;
266
lcomp_test_double ("g721.au", SF_ENDIAN_BIG | SF_FORMAT_AU | SF_FORMAT_G721_32, 1, 0.7) ;
268
/*- sdlcomp_test_short ("g721.au", SF_ENDIAN_BIG | SF_FORMAT_AU | SF_FORMAT_G721_32, 1, 0.07) ;
269
sdlcomp_test_int ("g721.au", SF_ENDIAN_LITTLE | SF_FORMAT_AU | SF_FORMAT_G721_32, 1, 0.07) ;
270
sdlcomp_test_float ("g721.au", SF_ENDIAN_BIG | SF_FORMAT_AU | SF_FORMAT_G721_32, 1, 0.07) ;
271
sdlcomp_test_double ("g721.au", SF_ENDIAN_LITTLE | SF_FORMAT_AU | SF_FORMAT_G721_32, 1, 0.12) ;
276
if (do_all || strcmp (argv [1], "au_g723") == 0)
277
{ printf ("**** Fix this later : error bound should be 0.16 ****\n") ;
278
lcomp_test_short ("g723_24.au", SF_ENDIAN_LITTLE | SF_FORMAT_AU | SF_FORMAT_G723_24, 1, 0.7) ;
279
lcomp_test_int ("g723_24.au", SF_ENDIAN_BIG | SF_FORMAT_AU | SF_FORMAT_G723_24, 1, 0.7) ;
280
lcomp_test_float ("g723_24.au", SF_ENDIAN_LITTLE | SF_FORMAT_AU | SF_FORMAT_G723_24, 1, 0.7) ;
281
lcomp_test_double ("g723_24.au", SF_ENDIAN_BIG | SF_FORMAT_AU | SF_FORMAT_G723_24, 1, 0.7) ;
283
lcomp_test_short ("g723_40.au", SF_ENDIAN_LITTLE | SF_FORMAT_AU | SF_FORMAT_G723_40, 1, 0.21) ;
284
lcomp_test_int ("g723_40.au", SF_ENDIAN_BIG | SF_FORMAT_AU | SF_FORMAT_G723_40, 1, 0.21) ;
285
lcomp_test_float ("g723_40.au", SF_ENDIAN_LITTLE | SF_FORMAT_AU | SF_FORMAT_G723_40, 1, 0.21) ;
286
lcomp_test_double ("g723_40.au", SF_ENDIAN_BIG | SF_FORMAT_AU | SF_FORMAT_G723_40, 1, 0.21) ;
288
/*- sdlcomp_test_short ("g723.au", SF_ENDIAN_BIG | SF_FORMAT_AU | SF_FORMAT_G723_24, 1, 0.15) ;
289
sdlcomp_test_int ("g723.au", SF_ENDIAN_LITTLE | SF_FORMAT_AU | SF_FORMAT_G723_24, 1, 0.15) ;
290
sdlcomp_test_float ("g723.au", SF_ENDIAN_BIG | SF_FORMAT_AU | SF_FORMAT_G723_24, 1, 0.15) ;
291
sdlcomp_test_double ("g723.au", SF_ENDIAN_LITTLE | SF_FORMAT_AU | SF_FORMAT_G723_24, 1, 0.15) ;
295
/* Lite remove end */
297
if (do_all || strcmp (argv [1], "caf_ulaw") == 0)
298
{ lcomp_test_short ("ulaw.caf", SF_FORMAT_CAF | SF_FORMAT_ULAW, 2, 0.04) ;
299
lcomp_test_int ("ulaw.caf", SF_FORMAT_CAF | SF_FORMAT_ULAW, 2, 0.04) ;
300
/* Lite remove start */
301
lcomp_test_float ("ulaw.caf", SF_FORMAT_CAF | SF_FORMAT_ULAW, 2, 0.04) ;
302
lcomp_test_double ("ulaw.caf", SF_FORMAT_CAF | SF_FORMAT_ULAW, 2, 0.04) ;
303
/* Lite remove end */
307
if (do_all || strcmp (argv [1], "caf_alaw") == 0)
308
{ lcomp_test_short ("alaw.caf", SF_FORMAT_CAF | SF_FORMAT_ALAW, 2, 0.04) ;
309
lcomp_test_int ("alaw.caf", SF_FORMAT_CAF | SF_FORMAT_ALAW, 2, 0.04) ;
310
/* Lite remove start */
311
lcomp_test_float ("alaw.caf", SF_FORMAT_CAF | SF_FORMAT_ALAW, 2, 0.04) ;
312
lcomp_test_double ("alaw.caf", SF_FORMAT_CAF | SF_FORMAT_ALAW, 2, 0.04) ;
313
/* Lite remove end */
318
if (do_all || strcmp (argv [1], "raw_ulaw") == 0)
319
{ lcomp_test_short ("ulaw.raw", SF_ENDIAN_LITTLE | SF_FORMAT_RAW | SF_FORMAT_ULAW, 2, 0.04) ;
320
lcomp_test_int ("ulaw.raw", SF_ENDIAN_BIG | SF_FORMAT_RAW | SF_FORMAT_ULAW, 2, 0.04) ;
321
/* Lite remove start */
322
lcomp_test_float ("ulaw.raw", SF_ENDIAN_LITTLE | SF_FORMAT_RAW | SF_FORMAT_ULAW, 2, 0.04) ;
323
lcomp_test_double ("ulaw.raw", SF_ENDIAN_BIG | SF_FORMAT_RAW | SF_FORMAT_ULAW, 2, 0.04) ;
324
/* Lite remove end */
328
if (do_all || strcmp (argv [1], "raw_alaw") == 0)
329
{ lcomp_test_short ("alaw.raw", SF_ENDIAN_LITTLE | SF_FORMAT_RAW | SF_FORMAT_ALAW, 2, 0.04) ;
330
lcomp_test_int ("alaw.raw", SF_ENDIAN_BIG | SF_FORMAT_RAW | SF_FORMAT_ALAW, 2, 0.04) ;
331
/* Lite remove start */
332
lcomp_test_float ("alaw.raw", SF_ENDIAN_LITTLE | SF_FORMAT_RAW | SF_FORMAT_ALAW, 2, 0.04) ;
333
lcomp_test_double ("alaw.raw", SF_ENDIAN_BIG | SF_FORMAT_RAW | SF_FORMAT_ALAW, 2, 0.04) ;
334
/* Lite remove end */
338
if (do_all || strcmp (argv [1], "raw_gsm610") == 0)
339
{ /* Don't do lcomp_test_XXX as the errors are too big. */
340
sdlcomp_test_short ("raw.gsm", SF_FORMAT_RAW | SF_FORMAT_GSM610, 1, 0.24) ;
341
sdlcomp_test_int ("raw.gsm", SF_FORMAT_RAW | SF_FORMAT_GSM610, 1, 0.24) ;
342
sdlcomp_test_float ("raw.gsm", SF_FORMAT_RAW | SF_FORMAT_GSM610, 1, 0.24) ;
343
sdlcomp_test_double ("raw.gsm", SF_FORMAT_RAW | SF_FORMAT_GSM610, 1, 0.24) ;
347
/* Lite remove start */
348
if (do_all || strcmp (argv [1], "ircam_ulaw") == 0)
349
{ lcomp_test_short ("ulaw.ircam", SF_ENDIAN_LITTLE | SF_FORMAT_IRCAM | SF_FORMAT_ULAW, 2, 0.04) ;
350
lcomp_test_int ("ulaw.ircam", SF_ENDIAN_BIG | SF_FORMAT_IRCAM | SF_FORMAT_ULAW, 2, 0.04) ;
351
lcomp_test_float ("ulaw.ircam", SF_ENDIAN_LITTLE | SF_FORMAT_IRCAM | SF_FORMAT_ULAW, 2, 0.04) ;
352
lcomp_test_double ("ulaw.ircam", SF_ENDIAN_BIG | SF_FORMAT_IRCAM | SF_FORMAT_ULAW, 2, 0.04) ;
356
if (do_all || strcmp (argv [1], "ircam_alaw") == 0)
357
{ lcomp_test_short ("alaw.ircam", SF_ENDIAN_LITTLE | SF_FORMAT_IRCAM | SF_FORMAT_ALAW, 2, 0.04) ;
358
lcomp_test_int ("alaw.ircam", SF_ENDIAN_BIG | SF_FORMAT_IRCAM | SF_FORMAT_ALAW, 2, 0.04) ;
359
lcomp_test_float ("alaw.ircam", SF_ENDIAN_LITTLE | SF_FORMAT_IRCAM | SF_FORMAT_ALAW, 2, 0.04) ;
360
lcomp_test_double ("alaw.ircam", SF_ENDIAN_BIG | SF_FORMAT_IRCAM | SF_FORMAT_ALAW, 2, 0.04) ;
364
if (do_all || strcmp (argv [1], "nist_ulaw") == 0)
365
{ lcomp_test_short ("ulaw.nist", SF_ENDIAN_LITTLE | SF_FORMAT_NIST | SF_FORMAT_ULAW, 2, 0.04) ;
366
lcomp_test_int ("ulaw.nist", SF_ENDIAN_BIG | SF_FORMAT_NIST | SF_FORMAT_ULAW, 2, 0.04) ;
367
lcomp_test_float ("ulaw.nist", SF_ENDIAN_LITTLE | SF_FORMAT_NIST | SF_FORMAT_ULAW, 2, 0.04) ;
368
lcomp_test_double ("ulaw.nist", SF_ENDIAN_BIG | SF_FORMAT_NIST | SF_FORMAT_ULAW, 2, 0.04) ;
372
if (do_all || strcmp (argv [1], "nist_alaw") == 0)
373
{ lcomp_test_short ("alaw.nist", SF_ENDIAN_LITTLE | SF_FORMAT_NIST | SF_FORMAT_ALAW, 2, 0.04) ;
374
lcomp_test_int ("alaw.nist", SF_ENDIAN_BIG | SF_FORMAT_NIST | SF_FORMAT_ALAW, 2, 0.04) ;
375
lcomp_test_float ("alaw.nist", SF_ENDIAN_LITTLE | SF_FORMAT_NIST | SF_FORMAT_ALAW, 2, 0.04) ;
376
lcomp_test_double ("alaw.nist", SF_ENDIAN_BIG | SF_FORMAT_NIST | SF_FORMAT_ALAW, 2, 0.04) ;
380
if (do_all || strcmp (argv [1], "voc_ulaw") == 0)
381
{ lcomp_test_short ("ulaw.voc", SF_FORMAT_VOC | SF_FORMAT_ULAW, 2, 0.04) ;
382
lcomp_test_int ("ulaw.voc", SF_FORMAT_VOC | SF_FORMAT_ULAW, 2, 0.04) ;
383
lcomp_test_float ("ulaw.voc", SF_FORMAT_VOC | SF_FORMAT_ULAW, 2, 0.04) ;
384
lcomp_test_double ("ulaw.voc", SF_FORMAT_VOC | SF_FORMAT_ULAW, 2, 0.04) ;
388
if (do_all || strcmp (argv [1], "voc_alaw") == 0)
389
{ lcomp_test_short ("alaw.voc", SF_FORMAT_VOC | SF_FORMAT_ALAW, 2, 0.04) ;
390
lcomp_test_int ("alaw.voc", SF_FORMAT_VOC | SF_FORMAT_ALAW, 2, 0.04) ;
391
lcomp_test_float ("alaw.voc", SF_FORMAT_VOC | SF_FORMAT_ALAW, 2, 0.04) ;
392
lcomp_test_double ("alaw.voc", SF_FORMAT_VOC | SF_FORMAT_ALAW, 2, 0.04) ;
395
/* Lite remove end */
397
if (do_all || strcmp (argv [1], "w64_ulaw") == 0)
398
{ lcomp_test_short ("ulaw.w64", SF_FORMAT_W64 | SF_FORMAT_ULAW, 2, 0.04) ;
399
lcomp_test_int ("ulaw.w64", SF_FORMAT_W64 | SF_FORMAT_ULAW, 2, 0.04) ;
400
/* Lite remove start */
401
lcomp_test_float ("ulaw.w64", SF_FORMAT_W64 | SF_FORMAT_ULAW, 2, 0.04) ;
402
lcomp_test_double ("ulaw.w64", SF_FORMAT_W64 | SF_FORMAT_ULAW, 2, 0.04) ;
403
/* Lite remove end */
407
if (do_all || strcmp (argv [1], "w64_alaw") == 0)
408
{ lcomp_test_short ("alaw.w64", SF_FORMAT_W64 | SF_FORMAT_ALAW, 2, 0.04) ;
409
lcomp_test_int ("alaw.w64", SF_FORMAT_W64 | SF_FORMAT_ALAW, 2, 0.04) ;
410
/* Lite remove start */
411
lcomp_test_float ("alaw.w64", SF_FORMAT_W64 | SF_FORMAT_ALAW, 2, 0.04) ;
412
lcomp_test_double ("alaw.w64", SF_FORMAT_W64 | SF_FORMAT_ALAW, 2, 0.04) ;
413
/* Lite remove end */
417
/* Lite remove start */
418
if (do_all || strcmp (argv [1], "w64_ima") == 0)
419
{ lcomp_test_short ("ima.w64", SF_FORMAT_W64 | SF_FORMAT_IMA_ADPCM, 2, 0.18) ;
420
lcomp_test_int ("ima.w64", SF_FORMAT_W64 | SF_FORMAT_IMA_ADPCM, 2, 0.18) ;
421
lcomp_test_float ("ima.w64", SF_FORMAT_W64 | SF_FORMAT_IMA_ADPCM, 2, 0.18) ;
422
lcomp_test_double ("ima.w64", SF_FORMAT_W64 | SF_FORMAT_IMA_ADPCM, 2, 0.18) ;
424
sdlcomp_test_short ("ima.w64", SF_FORMAT_W64 | SF_FORMAT_IMA_ADPCM, 2, 0.18) ;
425
sdlcomp_test_int ("ima.w64", SF_FORMAT_W64 | SF_FORMAT_IMA_ADPCM, 2, 0.18) ;
426
sdlcomp_test_float ("ima.w64", SF_FORMAT_W64 | SF_FORMAT_IMA_ADPCM, 2, 0.18) ;
427
sdlcomp_test_double ("ima.w64", SF_FORMAT_W64 | SF_FORMAT_IMA_ADPCM, 2, 0.18) ;
431
if (do_all || strcmp (argv [1], "w64_msadpcm") == 0)
432
{ lcomp_test_short ("msadpcm.w64", SF_FORMAT_W64 | SF_FORMAT_MS_ADPCM, 2, 0.36) ;
433
lcomp_test_int ("msadpcm.w64", SF_FORMAT_W64 | SF_FORMAT_MS_ADPCM, 2, 0.36) ;
434
lcomp_test_float ("msadpcm.w64", SF_FORMAT_W64 | SF_FORMAT_MS_ADPCM, 2, 0.36) ;
435
lcomp_test_double ("msadpcm.w64", SF_FORMAT_W64 | SF_FORMAT_MS_ADPCM, 2, 0.36) ;
437
sdlcomp_test_short ("msadpcm.w64", SF_FORMAT_W64 | SF_FORMAT_MS_ADPCM, 2, 0.36) ;
438
sdlcomp_test_int ("msadpcm.w64", SF_FORMAT_W64 | SF_FORMAT_MS_ADPCM, 2, 0.36) ;
439
sdlcomp_test_float ("msadpcm.w64", SF_FORMAT_W64 | SF_FORMAT_MS_ADPCM, 2, 0.36) ;
440
sdlcomp_test_double ("msadpcm.w64", SF_FORMAT_W64 | SF_FORMAT_MS_ADPCM, 2, 0.36) ;
443
/* Lite remove end */
445
if (do_all || strcmp (argv [1], "w64_gsm610") == 0)
446
{ /* Don't do lcomp_test_XXX as the errors are too big. */
447
sdlcomp_test_short ("gsm610.w64", SF_FORMAT_W64 | SF_FORMAT_GSM610, 1, 0.2) ;
448
sdlcomp_test_int ("gsm610.w64", SF_FORMAT_W64 | SF_FORMAT_GSM610, 1, 0.2) ;
449
/* Lite remove start */
450
sdlcomp_test_float ("gsm610.w64", SF_FORMAT_W64 | SF_FORMAT_GSM610, 1, 0.2) ;
451
sdlcomp_test_double ("gsm610.w64", SF_FORMAT_W64 | SF_FORMAT_GSM610, 1, 0.2) ;
452
/* Lite remove end */
456
/* Lite remove start */
457
if (do_all || strcmp (argv [1], "vox_adpcm") == 0)
458
{ lcomp_test_short ("adpcm.vox", SF_FORMAT_RAW | SF_FORMAT_VOX_ADPCM, 1, 0.17) ;
459
lcomp_test_int ("adpcm.vox", SF_FORMAT_RAW | SF_FORMAT_VOX_ADPCM, 1, 0.17) ;
460
lcomp_test_float ("adpcm.vox", SF_FORMAT_RAW | SF_FORMAT_VOX_ADPCM, 1, 0.17) ;
461
lcomp_test_double ("adpcm.vox", SF_FORMAT_RAW | SF_FORMAT_VOX_ADPCM, 1, 0.17) ;
463
sdlcomp_test_short ("adpcm.vox", SF_FORMAT_RAW | SF_FORMAT_VOX_ADPCM, 1, 0.072) ;
464
sdlcomp_test_int ("adpcm.vox", SF_FORMAT_RAW | SF_FORMAT_VOX_ADPCM, 1, 0.072) ;
465
sdlcomp_test_float ("adpcm.vox", SF_FORMAT_RAW | SF_FORMAT_VOX_ADPCM, 1, 0.072) ;
466
sdlcomp_test_double ("adpcm.vox", SF_FORMAT_RAW | SF_FORMAT_VOX_ADPCM, 1, 0.072) ;
470
if (do_all || strcmp (argv [1], "xi_dpcm") == 0)
471
{ lcomp_test_short ("8bit.xi", SF_FORMAT_XI | SF_FORMAT_DPCM_8, 1, 0.25) ;
472
lcomp_test_int ("8bit.xi", SF_FORMAT_XI | SF_FORMAT_DPCM_8, 1, 0.25) ;
474
lcomp_test_short ("16bit.xi", SF_FORMAT_XI | SF_FORMAT_DPCM_16, 1, 0.002) ;
475
lcomp_test_int ("16bit.xi", SF_FORMAT_XI | SF_FORMAT_DPCM_16, 1, 0.002) ;
476
lcomp_test_float ("16bit.xi", SF_FORMAT_XI | SF_FORMAT_DPCM_16, 1, 0.002) ;
477
lcomp_test_double ("16bit.xi", SF_FORMAT_XI | SF_FORMAT_DPCM_16, 1, 0.002) ;
480
/* Lite remove end */
483
{ printf ("************************************\n") ;
484
printf ("* No '%s' test defined.\n", argv [1]) ;
485
printf ("************************************\n") ;
492
/*============================================================================================
493
** Here are the test functions.
497
lcomp_test_short (const char *filename, int filetype, int channels, double margin)
500
int k, m, seekpos, sum_abs ;
504
print_test_name ("lcomp_test_short", filename) ;
506
datalen = BUFFER_SIZE / channels ;
508
data = (short*) data_buffer ;
509
orig = (short*) orig_buffer ;
511
gen_signal_double (orig_buffer, 32000.0, channels, datalen) ;
512
for (k = 0 ; k < channels * datalen ; k++)
513
orig [k] = (short) (orig_buffer [k]) ;
515
sfinfo.samplerate = SAMPLE_RATE ;
516
sfinfo.frames = 123456789 ; /* Ridiculous value. */
517
sfinfo.channels = channels ;
518
sfinfo.format = filetype ;
520
file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_FALSE, __LINE__) ;
521
test_writef_short_or_die (file, 0, orig, datalen, __LINE__) ;
522
sf_set_string (file, SF_STR_COMMENT, long_comment) ;
525
memset (data, 0, datalen * sizeof (short)) ;
527
if ((filetype & SF_FORMAT_TYPEMASK) != SF_FORMAT_RAW)
528
memset (&sfinfo, 0, sizeof (sfinfo)) ;
530
file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_FALSE, __LINE__) ;
532
if ((sfinfo.format & (SF_FORMAT_TYPEMASK | SF_FORMAT_SUBMASK)) != (filetype & (SF_FORMAT_TYPEMASK | SF_FORMAT_SUBMASK)))
533
{ printf ("\n\nLine %d: Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__, filetype, sfinfo.format) ;
537
if (sfinfo.frames < datalen / channels)
538
{ printf ("Too few frames in file. (%ld should be a little more than %ld)\n", SF_COUNT_TO_LONG (sfinfo.frames), datalen) ;
542
if (sfinfo.frames > (datalen + datalen / 20))
543
{ printf ("Too many frames in file. (%ld should be a little more than %ld)\n", SF_COUNT_TO_LONG (sfinfo.frames), datalen) ;
547
if (sfinfo.channels != channels)
548
{ printf ("Incorrect number of channels in file.\n") ;
552
check_log_buffer_or_die (file, __LINE__) ;
554
check_comment (file, filetype, __LINE__) ;
556
test_readf_short_or_die (file, 0, data, datalen, __LINE__) ;
559
for (k = 0 ; k < datalen ; k++)
560
{ if (error_function (data [k], orig [k], margin))
561
{ printf ("\n\nLine %d: Incorrect sample A (#%d : %d should be %d).\n", __LINE__, k, data [k], orig [k]) ;
562
oct_save_short (orig, data, datalen) ;
565
sum_abs = abs (sum_abs + abs (data [k])) ;
569
{ printf ("\n\nLine %d: Signal is all zeros.\n", __LINE__) ;
573
if ((k = sf_readf_short (file, data, datalen)) != sfinfo.frames - datalen)
574
{ printf ("\n\nLine %d: Incorrect read length (%ld should be %d).\n", __LINE__,
575
SF_COUNT_TO_LONG (channels * sfinfo.frames - datalen), k) ;
579
/* This check is only for block based encoders which must append silence
580
** to the end of a file so as to fill out a block.
582
for (k = 0 ; k < sfinfo.frames - datalen ; k++)
583
if (abs (data [channels * k]) > decay_response (channels * k))
584
{ printf ("\n\nLine %d : Incorrect sample B (#%d : abs (%d) should be < %d).\n", __LINE__, channels * k, data [channels * k], decay_response (channels * k)) ;
588
if (! sfinfo.seekable)
595
/* Now test sf_seek function. */
597
if ((k = sf_seek (file, 0, SEEK_SET)) != 0)
598
{ printf ("\n\nLine %d: Seek to start of file failed (%d).\n", __LINE__, k) ;
602
for (m = 0 ; m < 3 ; m++)
603
{ test_readf_short_or_die (file, m, data, 11, __LINE__) ;
605
for (k = 0 ; k < channels * 11 ; k++)
606
if (error_function ((double) data [k], (double) orig [k + channels * m * 11], margin))
607
{ printf ("\n\nLine %d: Incorrect sample (m = %d) (#%d : %d => %d).\n", __LINE__, m, k + channels * m * 11, orig [k + channels * m * 11], data [k]) ;
608
for (m = 0 ; m < channels ; m++)
609
printf ("%d ", data [m]) ;
615
seekpos = BUFFER_SIZE / 10 ;
617
/* Check seek from start of file. */
618
if ((k = sf_seek (file, seekpos, SEEK_SET)) != seekpos)
619
{ printf ("Seek to start of file + %d failed (%d).\n", seekpos, k) ;
623
test_readf_short_or_die (file, 0, data, 1, __LINE__) ;
625
if (error_function ((double) data [0], (double) orig [seekpos * channels], margin))
626
{ printf ("\n\nLine %d: sf_seek (SEEK_SET) followed by sf_readf_short failed (%d, %d).\n", __LINE__, orig [1], data [0]) ;
630
if ((k = sf_seek (file, 0, SEEK_CUR)) != seekpos + 1)
631
{ printf ("\n\nLine %d: sf_seek (SEEK_CUR) with 0 offset failed (%d should be %d)\n", __LINE__, k, seekpos + 1) ;
635
seekpos = sf_seek (file, 0, SEEK_CUR) + BUFFER_SIZE / 5 ;
636
k = sf_seek (file, BUFFER_SIZE / 5, SEEK_CUR) ;
637
test_readf_short_or_die (file, 0, data, 1, __LINE__) ;
638
if (error_function ((double) data [0], (double) orig [seekpos * channels], margin) || k != seekpos)
639
{ printf ("\n\nLine %d: sf_seek (forwards, SEEK_CUR) followed by sf_readf_short failed (%d, %d) (%d, %d).\n", __LINE__, data [0], orig [seekpos * channels], k, seekpos + 1) ;
640
oct_save_short (orig, data, datalen) ;
644
seekpos = sf_seek (file, 0, SEEK_CUR) - 20 ;
645
/* Check seek backward from current position. */
646
k = sf_seek (file, -20, SEEK_CUR) ;
647
test_readf_short_or_die (file, 0, data, 1, __LINE__) ;
648
if (error_function ((double) data [0], (double) orig [seekpos * channels], margin) || k != seekpos)
649
{ printf ("sf_seek (backwards, SEEK_CUR) followed by sf_readf_short failed (%d, %d) (%d, %d).\n", data [0], orig [seekpos * channels], k, seekpos) ;
653
/* Check that read past end of file returns number of items. */
654
sf_seek (file, (short) sfinfo.frames, SEEK_SET) ;
656
if ((k = sf_readf_short (file, data, datalen)) != 0)
657
{ printf ("\n\nLine %d: Return value from sf_readf_short past end of file incorrect (%d).\n", __LINE__, k) ;
661
/* Check seek backward from end. */
662
if ((k = sf_seek (file, 5 - (short) sfinfo.frames, SEEK_END)) != 5)
663
{ printf ("sf_seek (SEEK_END) returned %d instead of %d.\n", k, 5) ;
667
test_readf_short_or_die (file, 0, data, channels, __LINE__) ;
668
if (error_function ((double) data [0], (double) orig [5], margin))
669
{ printf ("\n\nLine %d: sf_seek (SEEK_END) followed by sf_readf_short failed (%d should be %d).\n", __LINE__, data [0], orig [5]) ;
677
} /* lcomp_test_short */
679
/*--------------------------------------------------------------------------------------------
683
lcomp_test_int (const char *filename, int filetype, int channels, double margin)
686
int k, m, *orig, *data, sum_abs ;
687
long datalen, seekpos ;
690
print_test_name ("lcomp_test_int", filename) ;
692
datalen = BUFFER_SIZE / channels ;
694
scale = 1.0 * 0x10000 ;
696
data = (int*) data_buffer ;
697
orig = (int*) orig_buffer ;
699
gen_signal_double (orig_buffer, 32000.0 * scale, channels, datalen) ;
700
for (k = 0 ; k < channels * datalen ; k++)
701
orig [k] = orig_buffer [k] ;
703
sfinfo.samplerate = SAMPLE_RATE ;
704
sfinfo.frames = 123456789 ; /* Ridiculous value. */
705
sfinfo.channels = channels ;
706
sfinfo.format = filetype ;
708
file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_FALSE, __LINE__) ;
709
test_writef_int_or_die (file, 0, orig, datalen, __LINE__) ;
710
sf_set_string (file, SF_STR_COMMENT, long_comment) ;
713
memset (data, 0, datalen * sizeof (int)) ;
715
if ((filetype & SF_FORMAT_TYPEMASK) != SF_FORMAT_RAW)
716
memset (&sfinfo, 0, sizeof (sfinfo)) ;
718
file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_FALSE, __LINE__) ;
720
if ((sfinfo.format & (SF_FORMAT_TYPEMASK | SF_FORMAT_SUBMASK)) != (filetype & (SF_FORMAT_TYPEMASK | SF_FORMAT_SUBMASK)))
721
{ printf ("\n\nLine %d: Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__, filetype, sfinfo.format) ;
725
if (sfinfo.frames < datalen / channels)
726
{ printf ("Too few.frames in file. (%ld should be a little more than %ld)\n", datalen, SF_COUNT_TO_LONG (sfinfo.frames)) ;
730
if (sfinfo.frames > (datalen + datalen / 20))
731
{ printf ("Too many.frames in file. (%ld should be a little more than %ld)\n", datalen, SF_COUNT_TO_LONG (sfinfo.frames)) ;
735
if (sfinfo.channels != channels)
736
{ printf ("Incorrect number of channels in file.\n") ;
740
check_log_buffer_or_die (file, __LINE__) ;
742
check_comment (file, filetype, __LINE__) ;
744
test_readf_int_or_die (file, 0, data, datalen, __LINE__) ;
747
for (k = 0 ; k < datalen ; k++)
748
{ if (error_function (data [k] / scale, orig [k] / scale, margin))
749
{ printf ("\n\nLine %d: Incorrect sample (#%d : %f should be %f).\n", __LINE__, k, data [k] / scale, orig [k] / scale) ;
750
oct_save_int (orig, data, datalen) ;
753
sum_abs = abs (sum_abs + abs (abs (data [k]) - 256)) ;
757
{ printf ("\n\nLine %d: Signal is all zeros (%d, 0x%X).\n", __LINE__, sum_abs, sum_abs) ;
761
if ((k = sf_readf_int (file, data, datalen)) != sfinfo.frames - datalen)
762
{ printf ("\n\nLine %d: Incorrect read length (%ld should be %d).\n", __LINE__,
763
SF_COUNT_TO_LONG (channels * sfinfo.frames - datalen), k) ;
767
/* This check is only for block based encoders which must append silence
768
** to the end of a file so as to fill out a block.
770
if ((sfinfo.format & SF_FORMAT_SUBMASK) != SF_FORMAT_MS_ADPCM)
771
for (k = 0 ; k < sfinfo.frames - datalen ; k++)
772
if (abs (data [channels * k] / scale) > decay_response (channels * k))
773
{ printf ("\n\nLine %d : Incorrect sample B (#%d : abs (%d) should be < %d).\n", __LINE__, channels * k, data [channels * k], decay_response (channels * k)) ;
777
if (! sfinfo.seekable)
784
/* Now test sf_seek function. */
786
if ((k = sf_seek (file, 0, SEEK_SET)) != 0)
787
{ printf ("\n\nLine %d: Seek to start of file failed (%d).\n", __LINE__, k) ;
791
for (m = 0 ; m < 3 ; m++)
792
{ test_readf_int_or_die (file, m, data, 11, __LINE__) ;
794
for (k = 0 ; k < channels * 11 ; k++)
795
if (error_function (data [k] / scale, orig [k + channels * m * 11] / scale, margin))
796
{ printf ("\n\nLine %d: Incorrect sample (m = %d) (#%d : %d => %d).\n", __LINE__, m, k + channels * m * 11, orig [k + channels * m * 11], data [k]) ;
797
for (m = 0 ; m < channels ; m++)
798
printf ("%d ", data [m]) ;
804
seekpos = BUFFER_SIZE / 10 ;
806
/* Check seek from start of file. */
807
if ((k = sf_seek (file, seekpos, SEEK_SET)) != seekpos)
808
{ printf ("Seek to start of file + %ld failed (%d).\n", seekpos, k) ;
812
test_readf_int_or_die (file, 0, data, 1, __LINE__) ;
814
if (error_function ((double) data [0], (double) orig [seekpos * channels], margin))
815
{ printf ("\n\nLine %d: sf_seek (SEEK_SET) followed by sf_readf_int failed (%d, %d).\n", __LINE__, orig [1], data [0]) ;
819
if ((k = sf_seek (file, 0, SEEK_CUR)) != seekpos + 1)
820
{ printf ("\n\nLine %d: sf_seek (SEEK_CUR) with 0 offset failed (%d should be %ld)\n", __LINE__, k, seekpos + 1) ;
824
seekpos = sf_seek (file, 0, SEEK_CUR) + BUFFER_SIZE / 5 ;
825
k = sf_seek (file, BUFFER_SIZE / 5, SEEK_CUR) ;
826
test_readf_int_or_die (file, 0, data, 1, __LINE__) ;
827
if (error_function ((double) data [0], (double) orig [seekpos * channels], margin) || k != seekpos)
828
{ printf ("\n\nLine %d: sf_seek (forwards, SEEK_CUR) followed by sf_readf_int failed (%d, %d) (%d, %ld).\n", __LINE__, data [0], orig [seekpos * channels], k, seekpos + 1) ;
832
seekpos = sf_seek (file, 0, SEEK_CUR) - 20 ;
833
/* Check seek backward from current position. */
834
k = sf_seek (file, -20, SEEK_CUR) ;
835
test_readf_int_or_die (file, 0, data, 1, __LINE__) ;
836
if (error_function ((double) data [0], (double) orig [seekpos * channels], margin) || k != seekpos)
837
{ printf ("sf_seek (backwards, SEEK_CUR) followed by sf_readf_int failed (%d, %d) (%d, %ld).\n", data [0], orig [seekpos * channels], k, seekpos) ;
841
/* Check that read past end of file returns number of items. */
842
sf_seek (file, (int) sfinfo.frames, SEEK_SET) ;
844
if ((k = sf_readf_int (file, data, datalen)) != 0)
845
{ printf ("\n\nLine %d: Return value from sf_readf_int past end of file incorrect (%d).\n", __LINE__, k) ;
849
/* Check seek backward from end. */
850
if ((k = sf_seek (file, 5 - (int) sfinfo.frames, SEEK_END)) != 5)
851
{ printf ("sf_seek (SEEK_END) returned %d instead of %d.\n", k, 5) ;
855
test_readf_int_or_die (file, 0, data, channels, __LINE__) ;
856
if (error_function (data [0] / scale, orig [5] / scale, margin))
857
{ printf ("\n\nLine %d: sf_seek (SEEK_END) followed by sf_readf_short failed (%d should be %d).\n", __LINE__, data [0], orig [5]) ;
865
} /* lcomp_test_int */
867
/*--------------------------------------------------------------------------------------------
871
lcomp_test_float (const char *filename, int filetype, int channels, double margin)
874
int k, m, seekpos, sum_abs ;
878
print_test_name ("lcomp_test_float", filename) ;
880
datalen = BUFFER_SIZE / channels ;
882
data = (float*) data_buffer ;
883
orig = (float*) orig_buffer ;
885
gen_signal_double (orig_buffer, 32000.0, channels, datalen) ;
886
for (k = 0 ; k < channels * datalen ; k++)
887
orig [k] = (float) (orig_buffer [k]) ;
889
sfinfo.samplerate = SAMPLE_RATE ;
890
sfinfo.frames = 123456789 ; /* Ridiculous value. */
891
sfinfo.channels = channels ;
892
sfinfo.format = filetype ;
894
file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_FALSE, __LINE__) ;
895
sf_command (file, SFC_SET_NORM_FLOAT, NULL, SF_FALSE) ;
896
test_writef_float_or_die (file, 0, orig, datalen, __LINE__) ;
897
sf_set_string (file, SF_STR_COMMENT, long_comment) ;
900
memset (data, 0, datalen * sizeof (float)) ;
902
if ((filetype & SF_FORMAT_TYPEMASK) != SF_FORMAT_RAW)
903
memset (&sfinfo, 0, sizeof (sfinfo)) ;
905
file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_FALSE, __LINE__) ;
907
if ((sfinfo.format & (SF_FORMAT_TYPEMASK | SF_FORMAT_SUBMASK)) != (filetype & (SF_FORMAT_TYPEMASK | SF_FORMAT_SUBMASK)))
908
{ printf ("\n\nLine %d: Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__, filetype, sfinfo.format) ;
912
if (sfinfo.frames < datalen / channels)
913
{ printf ("Too few.frames in file. (%ld should be a little more than %ld)\n", datalen, SF_COUNT_TO_LONG (sfinfo.frames)) ;
917
if (sfinfo.frames > (datalen + datalen / 20))
918
{ printf ("Too many.frames in file. (%ld should be a little more than %ld)\n", datalen, SF_COUNT_TO_LONG (sfinfo.frames)) ;
922
if (sfinfo.channels != channels)
923
{ printf ("Incorrect number of channels in file.\n") ;
927
check_comment (file, filetype, __LINE__) ;
929
sf_command (file, SFC_SET_NORM_FLOAT, NULL, SF_FALSE) ;
931
check_log_buffer_or_die (file, __LINE__) ;
933
check_comment (file, filetype, __LINE__) ;
935
sf_command (file, SFC_SET_NORM_FLOAT, NULL, SF_FALSE) ;
937
test_readf_float_or_die (file, 0, data, datalen, __LINE__) ;
940
for (k = 0 ; k < datalen ; k++)
941
{ if (error_function ((double) data [k], (double) orig [k], margin))
942
{ printf ("\n\nLine %d: Incorrect sample A (#%d : %f should be %f).\n", __LINE__, k, data [k], orig [k]) ;
943
oct_save_float (orig, data, datalen) ;
946
sum_abs += fabs (data [k]) ;
950
{ printf ("\n\nLine %d: Signal is all zeros.\n", __LINE__) ;
954
if ((k = sf_readf_float (file, data, datalen)) != sfinfo.frames - datalen)
955
{ printf ("\n\nLine %d: Incorrect read length (%ld should be %d).\n", __LINE__,
956
SF_COUNT_TO_LONG (channels * sfinfo.frames - datalen), k) ;
960
/* This check is only for block based encoders which must append silence
961
** to the end of a file so as to fill out a block.
963
if ((sfinfo.format & SF_FORMAT_SUBMASK) != SF_FORMAT_MS_ADPCM)
964
for (k = 0 ; k < sfinfo.frames - datalen ; k++)
965
if (abs (data [channels * k]) > decay_response (channels * k))
966
{ printf ("\n\nLine %d : Incorrect sample B (#%d : abs (%f) should be < %d).\n", __LINE__, channels * k, data [channels * k], decay_response (channels * k)) ;
970
if (! sfinfo.seekable)
977
/* Now test sf_seek function. */
979
if ((k = sf_seek (file, 0, SEEK_SET)) != 0)
980
{ printf ("\n\nLine %d: Seek to start of file failed (%d).\n", __LINE__, k) ;
984
for (m = 0 ; m < 3 ; m++)
985
{ test_readf_float_or_die (file, 0, data, 11, __LINE__) ;
987
for (k = 0 ; k < channels * 11 ; k++)
988
if (error_function ((double) data [k], (double) orig [k + channels * m * 11], margin))
989
{ printf ("\n\nLine %d: Incorrect sample (m = %d) (#%d : %f => %f).\n", __LINE__, m, k + channels * m * 11, orig [k + channels * m * 11], data [k]) ;
990
for (m = 0 ; m < channels ; m++)
991
printf ("%f ", data [m]) ;
997
seekpos = BUFFER_SIZE / 10 ;
999
/* Check seek from start of file. */
1000
if ((k = sf_seek (file, seekpos, SEEK_SET)) != seekpos)
1001
{ printf ("Seek to start of file + %d failed (%d).\n", seekpos, k) ;
1005
test_readf_float_or_die (file, 0, data, 1, __LINE__) ;
1007
if (error_function ((double) data [0], (double) orig [seekpos * channels], margin))
1008
{ printf ("\n\nLine %d: sf_seek (SEEK_SET) followed by sf_readf_float failed (%f, %f).\n", __LINE__, orig [1], data [0]) ;
1012
if ((k = sf_seek (file, 0, SEEK_CUR)) != seekpos + 1)
1013
{ printf ("\n\nLine %d: sf_seek (SEEK_CUR) with 0 offset failed (%d should be %d)\n", __LINE__, k, seekpos + 1) ;
1017
seekpos = sf_seek (file, 0, SEEK_CUR) + BUFFER_SIZE / 5 ;
1018
k = sf_seek (file, BUFFER_SIZE / 5, SEEK_CUR) ;
1019
test_readf_float_or_die (file, 0, data, 1, __LINE__) ;
1020
if (error_function ((double) data [0], (double) orig [seekpos * channels], margin) || k != seekpos)
1021
{ printf ("\n\nLine %d: sf_seek (forwards, SEEK_CUR) followed by sf_readf_float failed (%f, %f) (%d, %d).\n", __LINE__, data [0], orig [seekpos * channels], k, seekpos + 1) ;
1025
seekpos = sf_seek (file, 0, SEEK_CUR) - 20 ;
1026
/* Check seek backward from current position. */
1027
k = sf_seek (file, -20, SEEK_CUR) ;
1028
test_readf_float_or_die (file, 0, data, 1, __LINE__) ;
1029
if (error_function ((double) data [0], (double) orig [seekpos * channels], margin) || k != seekpos)
1030
{ printf ("sf_seek (backwards, SEEK_CUR) followed by sf_readf_float failed (%f, %f) (%d, %d).\n", data [0], orig [seekpos * channels], k, seekpos) ;
1034
/* Check that read past end of file returns number of items. */
1035
sf_seek (file, (float) sfinfo.frames, SEEK_SET) ;
1037
if ((k = sf_readf_float (file, data, datalen)) != 0)
1038
{ printf ("\n\nLine %d: Return value from sf_readf_float past end of file incorrect (%d).\n", __LINE__, k) ;
1042
/* Check seek backward from end. */
1043
if ((k = sf_seek (file, 5 - (float) sfinfo.frames, SEEK_END)) != 5)
1044
{ printf ("sf_seek (SEEK_END) returned %d instead of %d.\n", k, 5) ;
1048
test_readf_float_or_die (file, 0, data, channels, __LINE__) ;
1049
if (error_function ((double) data [0], (double) orig [5], margin))
1050
{ printf ("\n\nLine %d: sf_seek (SEEK_END) followed by sf_readf_short failed (%f should be %f).\n", __LINE__, data [0], orig [5]) ;
1058
} /* lcomp_test_float */
1060
/*--------------------------------------------------------------------------------------------
1064
lcomp_test_double (const char *filename, int filetype, int channels, double margin)
1067
int k, m, seekpos, sum_abs ;
1069
double *orig, *data ;
1071
print_test_name ("lcomp_test_double", filename) ;
1073
datalen = BUFFER_SIZE / channels ;
1075
data = (double*) data_buffer ;
1076
orig = (double*) orig_buffer ;
1078
gen_signal_double (orig_buffer, 32000.0, channels, datalen) ;
1079
for (k = 0 ; k < channels * datalen ; k++)
1080
orig [k] = (double) (orig_buffer [k]) ;
1082
sfinfo.samplerate = SAMPLE_RATE ;
1083
sfinfo.frames = 123456789 ; /* Ridiculous value. */
1084
sfinfo.channels = channels ;
1085
sfinfo.format = filetype ;
1087
file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_FALSE, __LINE__) ;
1088
sf_command (file, SFC_SET_NORM_DOUBLE, NULL, SF_FALSE) ;
1089
test_writef_double_or_die (file, 0, orig, datalen, __LINE__) ;
1090
sf_set_string (file, SF_STR_COMMENT, long_comment) ;
1093
memset (data, 0, datalen * sizeof (double)) ;
1095
if ((filetype & SF_FORMAT_TYPEMASK) != SF_FORMAT_RAW)
1096
memset (&sfinfo, 0, sizeof (sfinfo)) ;
1098
file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_FALSE, __LINE__) ;
1100
if ((sfinfo.format & (SF_FORMAT_TYPEMASK | SF_FORMAT_SUBMASK)) != (filetype & (SF_FORMAT_TYPEMASK | SF_FORMAT_SUBMASK)))
1101
{ printf ("\n\nLine %d: Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__, filetype, sfinfo.format) ;
1105
if (sfinfo.frames < datalen / channels)
1106
{ printf ("Too few.frames in file. (%ld should be a little more than %ld)\n", datalen, SF_COUNT_TO_LONG (sfinfo.frames)) ;
1110
if (sfinfo.frames > (datalen + datalen / 20))
1111
{ printf ("Too many.frames in file. (%ld should be a little more than %ld)\n", datalen, SF_COUNT_TO_LONG (sfinfo.frames)) ;
1115
if (sfinfo.channels != channels)
1116
{ printf ("Incorrect number of channels in file.\n") ;
1120
check_comment (file, filetype, __LINE__) ;
1122
sf_command (file, SFC_SET_NORM_DOUBLE, NULL, SF_FALSE) ;
1124
check_log_buffer_or_die (file, __LINE__) ;
1126
check_comment (file, filetype, __LINE__) ;
1128
sf_command (file, SFC_SET_NORM_DOUBLE, NULL, SF_FALSE) ;
1130
test_readf_double_or_die (file, 0, data, datalen, __LINE__) ;
1133
for (k = 0 ; k < datalen ; k++)
1134
{ if (error_function ((double) data [k], (double) orig [k], margin))
1135
{ printf ("\n\nLine %d: Incorrect sample A (#%d : %f should be %f).\n", __LINE__, k, data [k], orig [k]) ;
1136
oct_save_double (orig, data, datalen) ;
1139
sum_abs += fabs (data [k]) ;
1143
{ printf ("\n\nLine %d: Signal is all zeros.\n", __LINE__) ;
1147
if ((k = sf_readf_double (file, data, datalen)) != sfinfo.frames - datalen)
1148
{ printf ("\n\nLine %d: Incorrect read length (%ld should be %d).\n", __LINE__,
1149
SF_COUNT_TO_LONG (channels * sfinfo.frames - datalen), k) ;
1153
/* This check is only for block based encoders which must append silence
1154
** to the end of a file so as to fill out a block.
1156
if ((sfinfo.format & SF_FORMAT_SUBMASK) != SF_FORMAT_MS_ADPCM)
1157
for (k = 0 ; k < sfinfo.frames - datalen ; k++)
1158
if (abs (data [channels * k]) > decay_response (channels * k))
1159
{ printf ("\n\nLine %d : Incorrect sample B (#%d : abs (%f) should be < %d).\n", __LINE__, channels * k, data [channels * k], decay_response (channels * k)) ;
1163
if (! sfinfo.seekable)
1170
/* Now test sf_seek function. */
1172
if ((k = sf_seek (file, 0, SEEK_SET)) != 0)
1173
{ printf ("\n\nLine %d: Seek to start of file failed (%d).\n", __LINE__, k) ;
1177
for (m = 0 ; m < 3 ; m++)
1178
{ test_readf_double_or_die (file, m, data, 11, __LINE__) ;
1180
for (k = 0 ; k < channels * 11 ; k++)
1181
if (error_function ((double) data [k], (double) orig [k + channels * m * 11], margin))
1182
{ printf ("\n\nLine %d: Incorrect sample (m = %d) (#%d : %f => %f).\n", __LINE__, m, k + channels * m * 11, orig [k + channels * m * 11], data [k]) ;
1183
for (m = 0 ; m < channels ; m++)
1184
printf ("%f ", data [m]) ;
1190
seekpos = BUFFER_SIZE / 10 ;
1192
/* Check seek from start of file. */
1193
if ((k = sf_seek (file, seekpos, SEEK_SET)) != seekpos)
1194
{ printf ("Seek to start of file + %d failed (%d).\n", seekpos, k) ;
1198
test_readf_double_or_die (file, 0, data, 1, __LINE__) ;
1200
if (error_function ((double) data [0], (double) orig [seekpos * channels], margin))
1201
{ printf ("\n\nLine %d: sf_seek (SEEK_SET) followed by sf_readf_double failed (%f, %f).\n", __LINE__, orig [1], data [0]) ;
1205
if ((k = sf_seek (file, 0, SEEK_CUR)) != seekpos + 1)
1206
{ printf ("\n\nLine %d: sf_seek (SEEK_CUR) with 0 offset failed (%d should be %d)\n", __LINE__, k, seekpos + 1) ;
1210
seekpos = sf_seek (file, 0, SEEK_CUR) + BUFFER_SIZE / 5 ;
1211
k = sf_seek (file, BUFFER_SIZE / 5, SEEK_CUR) ;
1212
test_readf_double_or_die (file, 0, data, 1, __LINE__) ;
1213
if (error_function ((double) data [0], (double) orig [seekpos * channels], margin) || k != seekpos)
1214
{ printf ("\n\nLine %d: sf_seek (forwards, SEEK_CUR) followed by sf_readf_double failed (%f, %f) (%d, %d).\n", __LINE__, data [0], orig [seekpos * channels], k, seekpos + 1) ;
1218
seekpos = sf_seek (file, 0, SEEK_CUR) - 20 ;
1219
/* Check seek backward from current position. */
1220
k = sf_seek (file, -20, SEEK_CUR) ;
1221
test_readf_double_or_die (file, 0, data, 1, __LINE__) ;
1222
if (error_function ((double) data [0], (double) orig [seekpos * channels], margin) || k != seekpos)
1223
{ printf ("sf_seek (backwards, SEEK_CUR) followed by sf_readf_double failed (%f, %f) (%d, %d).\n", data [0], orig [seekpos * channels], k, seekpos) ;
1227
/* Check that read past end of file returns number of items. */
1228
sf_seek (file, (double) sfinfo.frames, SEEK_SET) ;
1230
if ((k = sf_readf_double (file, data, datalen)) != 0)
1231
{ printf ("\n\nLine %d: Return value from sf_readf_double past end of file incorrect (%d).\n", __LINE__, k) ;
1235
/* Check seek backward from end. */
1236
if ((k = sf_seek (file, 5 - (double) sfinfo.frames, SEEK_END)) != 5)
1237
{ printf ("sf_seek (SEEK_END) returned %d instead of %d.\n", k, 5) ;
1241
test_readf_double_or_die (file, 0, data, channels, __LINE__) ;
1242
if (error_function ((double) data [0], (double) orig [5], margin))
1243
{ printf ("\n\nLine %d: sf_seek (SEEK_END) followed by sf_readf_short failed (%f should be %f).\n", __LINE__, data [0], orig [5]) ;
1251
} /* lcomp_test_double */
1253
/*========================================================================================
1254
** Smoothed differential loss compression tests.
1258
sdlcomp_test_short (const char *filename, int filetype, int channels, double margin)
1261
int k, m, seekpos, sum_abs ;
1263
short *orig, *data, *smooth ;
1266
print_test_name ("sdlcomp_test_short", filename) ;
1268
datalen = BUFFER_SIZE ;
1270
orig = (short*) orig_buffer ;
1271
data = (short*) data_buffer ;
1272
smooth = (short*) smooth_buffer ;
1274
gen_signal_double (orig_buffer, 32000.0, channels, datalen) ;
1275
for (k = 0 ; k < datalen ; k++)
1276
orig [k] = (short) (orig_buffer [k]) ;
1278
sfinfo.samplerate = SAMPLE_RATE ;
1279
sfinfo.frames = 123456789 ; /* Ridiculous value. */
1280
sfinfo.channels = channels ;
1281
sfinfo.format = filetype ;
1283
file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_FALSE, __LINE__) ;
1284
test_write_short_or_die (file, 0, orig, datalen, __LINE__) ;
1285
sf_set_string (file, SF_STR_COMMENT, long_comment) ;
1288
memset (data, 0, datalen * sizeof (short)) ;
1290
if ((filetype & SF_FORMAT_TYPEMASK) != SF_FORMAT_RAW)
1291
memset (&sfinfo, 0, sizeof (sfinfo)) ;
1293
file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_FALSE, __LINE__) ;
1295
if (sfinfo.format != filetype)
1296
{ printf ("\n\nLine %d: Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__, filetype, sfinfo.format) ;
1300
if (sfinfo.frames < datalen / channels)
1301
{ printf ("Too few.frames in file. (%ld should be a little more than %ld)\n", datalen, SF_COUNT_TO_LONG (sfinfo.frames)) ;
1305
if (sfinfo.frames > (datalen + 400))
1306
{ printf ("Too many.frames in file. (%ld should be a little more than %ld)\n", SF_COUNT_TO_LONG (sfinfo.frames), datalen) ;
1310
if (sfinfo.channels != channels)
1311
{ printf ("Incorrect number of channels in file.\n") ;
1315
check_comment (file, filetype, __LINE__) ;
1317
sf_command (file, SFC_SET_NORM_FLOAT, NULL, SF_FALSE) ;
1319
check_log_buffer_or_die (file, __LINE__) ;
1321
test_readf_short_or_die (file, 0, data, datalen, __LINE__) ;
1323
memcpy (smooth, orig, datalen * sizeof (short)) ;
1324
smoothed_diff_short (data, datalen) ;
1325
smoothed_diff_short (smooth, datalen) ;
1327
sum_abs = abs (data [0]) ;
1328
for (k = 1 ; k < datalen ; k++)
1329
{ if (error_function ((double) data [k], (double) smooth [k], margin))
1330
{ printf ("\n\nLine %d: Incorrect sample (#%d : %d should be %d).\n", __LINE__, k, data [k], smooth [k]) ;
1331
oct_save_short (orig, smooth, datalen) ;
1334
sum_abs = abs (sum_abs + abs (data [k])) ;
1338
{ printf ("\n\nLine %d: Signal is all zeros.\n", __LINE__) ;
1342
if ((k = sf_read_short (file, data, datalen)) != sfinfo.frames - datalen)
1343
{ printf ("\n\nLine %d: Incorrect read length (%d should be %ld).\n", __LINE__, k, SF_COUNT_TO_LONG (sfinfo.frames - datalen)) ;
1347
if ((sfinfo.format & SF_FORMAT_SUBMASK) != SF_FORMAT_MS_ADPCM &&
1348
(sfinfo.format & SF_FORMAT_SUBMASK) != SF_FORMAT_GSM610)
1349
for (k = 0 ; k < sfinfo.frames - datalen ; k++)
1350
if (abs (data [k]) > decay_response (k))
1351
{ printf ("\n\nLine %d: Incorrect sample (#%ld : abs (%d) should be < %d).\n", __LINE__, datalen + k, data [k], decay_response (k)) ;
1355
/* Now test sf_seek function. */
1356
if (sfinfo.seekable)
1357
{ if ((k = sf_seek (file, 0, SEEK_SET)) != 0)
1358
{ printf ("\n\nLine %d: Seek to start of file failed (%d).\n", __LINE__, k) ;
1362
for (m = 0 ; m < 3 ; m++)
1363
{ test_readf_short_or_die (file, m, data, datalen / 7, __LINE__) ;
1365
smoothed_diff_short (data, datalen / 7) ;
1366
memcpy (smooth, orig + m * datalen / 7, datalen / 7 * sizeof (short)) ;
1367
smoothed_diff_short (smooth, datalen / 7) ;
1369
for (k = 0 ; k < datalen / 7 ; k++)
1370
if (error_function ((double) data [k], (double) smooth [k], margin))
1371
{ printf ("Incorrect sample C (#%d (%ld) : %d => %d).\n", k, k + m * (datalen / 7), smooth [k], data [k]) ;
1372
for (m = 0 ; m < 10 ; m++)
1373
printf ("%d ", data [k]) ;
1377
} ; /* for (m = 0 ; m < 3 ; m++) */
1379
seekpos = BUFFER_SIZE / 10 ;
1381
/* Check seek from start of file. */
1382
if ((k = sf_seek (file, seekpos, SEEK_SET)) != seekpos)
1383
{ printf ("Seek to start of file + %d failed (%d).\n", seekpos, k) ;
1386
test_readf_short_or_die (file, 0, data, 1, __LINE__) ;
1388
if (error_function ((double) data [0], (double) orig [seekpos * channels], margin))
1389
{ printf ("sf_seek (SEEK_SET) followed by sf_read_short failed (%d, %d).\n", orig [1], data [0]) ;
1393
if ((k = sf_seek (file, 0, SEEK_CUR)) != seekpos + 1)
1394
{ printf ("sf_seek (SEEK_CUR) with 0 offset failed (%d should be %d)\n", k, seekpos + 1) ;
1398
seekpos = sf_seek (file, 0, SEEK_CUR) + BUFFER_SIZE / 5 ;
1399
k = sf_seek (file, BUFFER_SIZE / 5, SEEK_CUR) ;
1400
test_readf_short_or_die (file, 0, data, channels, __LINE__) ;
1401
if (error_function ((double) data [0], (double) orig [seekpos * channels], margin) || k != seekpos)
1402
{ printf ("sf_seek (forwards, SEEK_CUR) followed by sf_read_short failed (%d, %d) (%d, %d).\n", data [0], orig [seekpos * channels], k, seekpos + 1) ;
1406
seekpos = sf_seek (file, 0, SEEK_CUR) - 20 ;
1407
/* Check seek backward from current position. */
1408
k = sf_seek (file, -20, SEEK_CUR) ;
1409
test_readf_short_or_die (file, 0, data, channels, __LINE__) ;
1410
if (error_function ((double) data [0], (double) orig [seekpos * channels], margin) || k != seekpos)
1411
{ printf ("sf_seek (backwards, SEEK_CUR) followed by sf_read_short failed (%d, %d) (%d, %d).\n", data [0], orig [seekpos * channels], k, seekpos) ;
1415
/* Check that read past end of file returns number of items. */
1416
sf_seek (file, (int) sfinfo.frames, SEEK_SET) ;
1418
if ((k = sf_read_short (file, data, datalen)) != 0)
1419
{ printf ("\n\nLine %d: Return value from sf_read_short past end of file incorrect (%d).\n", __LINE__, k) ;
1423
/* Check seek backward from end. */
1425
if ((k = sf_seek (file, 5 - (int) sfinfo.frames, SEEK_END)) != 5)
1426
{ printf ("sf_seek (SEEK_END) returned %d instead of %d.\n", k, 5) ;
1430
test_read_short_or_die (file, 0, data, channels, __LINE__) ;
1431
if (error_function ((double) data [0], (double) orig [5], margin))
1432
{ printf ("sf_seek (SEEK_END) followed by sf_read_short failed (%d should be %d).\n", data [0], orig [5]) ;
1435
} /* if (sfinfo.seekable) */
1441
} /* sdlcomp_test_short */
1444
sdlcomp_test_int (const char *filename, int filetype, int channels, double margin)
1447
int k, m, seekpos, sum_abs ;
1449
int *orig, *data, *smooth ;
1454
print_test_name ("sdlcomp_test_int", filename) ;
1456
datalen = BUFFER_SIZE ;
1457
scale = 1.0 * 0x10000 ;
1459
orig = (int*) orig_buffer ;
1460
data = (int*) data_buffer ;
1461
smooth = (int*) smooth_buffer ;
1463
gen_signal_double (orig_buffer, 32000.0 * scale, channels, datalen) ;
1464
for (k = 0 ; k < datalen ; k++)
1465
orig [k] = (int) (orig_buffer [k]) ;
1467
sfinfo.samplerate = SAMPLE_RATE ;
1468
sfinfo.frames = 123456789 ; /* Ridiculous value. */
1469
sfinfo.channels = channels ;
1470
sfinfo.format = filetype ;
1472
file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_FALSE, __LINE__) ;
1473
test_writef_int_or_die (file, 0, orig, datalen, __LINE__) ;
1474
sf_set_string (file, SF_STR_COMMENT, long_comment) ;
1477
memset (data, 0, datalen * sizeof (int)) ;
1479
if ((filetype & SF_FORMAT_TYPEMASK) != SF_FORMAT_RAW)
1480
memset (&sfinfo, 0, sizeof (sfinfo)) ;
1482
file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_FALSE, __LINE__) ;
1484
if (sfinfo.format != filetype)
1485
{ printf ("Returned format incorrect (0x%08X => 0x%08X).\n", filetype, sfinfo.format) ;
1489
if (sfinfo.frames < datalen / channels)
1490
{ printf ("Too few.frames in file. (%ld should be a little more than %ld)\n", datalen, SF_COUNT_TO_LONG (sfinfo.frames)) ;
1494
if (sfinfo.frames > (datalen + 400))
1495
{ printf ("Too many.frames in file. (%ld should be a little more than %ld)\n", SF_COUNT_TO_LONG (sfinfo.frames), datalen) ;
1499
if (sfinfo.channels != channels)
1500
{ printf ("Incorrect number of channels in file.\n") ;
1504
check_log_buffer_or_die (file, __LINE__) ;
1506
test_readf_int_or_die (file, 0, data, datalen, __LINE__) ;
1508
memcpy (smooth, orig, datalen * sizeof (int)) ;
1509
smoothed_diff_int (data, datalen) ;
1510
smoothed_diff_int (smooth, datalen) ;
1512
sum_abs = abs (data [0] >> 16) ;
1513
for (k = 1 ; k < datalen ; k++)
1514
{ if (error_function (data [k] / scale, smooth [k] / scale, margin))
1515
{ printf ("\n\nLine %d: Incorrect sample (#%d : %d should be %d).\n", __LINE__, k, data [k], smooth [k]) ;
1516
oct_save_int (orig, smooth, datalen) ;
1519
sum_abs = abs (sum_abs + abs (data [k] >> 16)) ;
1523
{ printf ("\n\nLine %d: Signal is all zeros.\n", __LINE__) ;
1527
if ((k = sf_readf_int (file, data, datalen)) != sfinfo.frames - datalen)
1528
{ printf ("\n\nLine %d: Incorrect read length (%d should be %ld).\n", __LINE__, k, SF_COUNT_TO_LONG (sfinfo.frames - datalen)) ;
1532
if ((sfinfo.format & SF_FORMAT_SUBMASK) != SF_FORMAT_IMA_ADPCM &&
1533
(sfinfo.format & SF_FORMAT_SUBMASK) != SF_FORMAT_MS_ADPCM &&
1534
(sfinfo.format & SF_FORMAT_SUBMASK) != SF_FORMAT_GSM610 &&
1535
(sfinfo.format & SF_FORMAT_SUBMASK) != SF_FORMAT_G721_32 &&
1536
(sfinfo.format & SF_FORMAT_SUBMASK) != SF_FORMAT_G723_24)
1537
for (k = 0 ; k < sfinfo.frames - datalen ; k++)
1538
if (abs (data [k]) > decay_response (k))
1539
{ printf ("\n\nLine %d: Incorrect sample (#%ld : abs (%d) should be < %d).\n", __LINE__, datalen + k, data [k], decay_response (k)) ;
1543
/* Now test sf_seek function. */
1544
if (sfinfo.seekable)
1545
{ if ((k = sf_seek (file, 0, SEEK_SET)) != 0)
1546
{ printf ("\n\nLine %d: Seek to start of file failed (%d).\n", __LINE__, k) ;
1550
for (m = 0 ; m < 3 ; m++)
1551
{ test_readf_int_or_die (file, m, data, datalen / 7, __LINE__) ;
1553
smoothed_diff_int (data, datalen / 7) ;
1554
memcpy (smooth, orig + m * datalen / 7, datalen / 7 * sizeof (int)) ;
1555
smoothed_diff_int (smooth, datalen / 7) ;
1557
for (k = 0 ; k < datalen / 7 ; k++)
1558
if (error_function (data [k] / scale, smooth [k] / scale, margin))
1559
{ printf ("\n\nLine %d: Incorrect sample (#%d (%ld) : %d => %d).\n", __LINE__, k, k + m * (datalen / 7), smooth [k], data [k]) ;
1560
for (m = 0 ; m < 10 ; m++)
1561
printf ("%d ", data [k]) ;
1565
} ; /* for (m = 0 ; m < 3 ; m++) */
1567
seekpos = BUFFER_SIZE / 10 ;
1569
/* Check seek from start of file. */
1570
if ((k = sf_seek (file, seekpos, SEEK_SET)) != seekpos)
1571
{ printf ("Seek to start of file + %d failed (%d).\n", seekpos, k) ;
1574
test_readf_int_or_die (file, 0, data, 1, __LINE__) ;
1576
if (error_function ((double) data [0], (double) orig [seekpos * channels], margin))
1577
{ printf ("sf_seek (SEEK_SET) followed by sf_readf_int failed (%d, %d).\n", orig [1], data [0]) ;
1581
if ((k = sf_seek (file, 0, SEEK_CUR)) != seekpos + 1)
1582
{ printf ("sf_seek (SEEK_CUR) with 0 offset failed (%d should be %d)\n", k, seekpos + 1) ;
1586
seekpos = sf_seek (file, 0, SEEK_CUR) + BUFFER_SIZE / 5 ;
1587
k = sf_seek (file, BUFFER_SIZE / 5, SEEK_CUR) ;
1588
test_readf_int_or_die (file, 0, data, 1, __LINE__) ;
1589
if (error_function ((double) data [0], (double) orig [seekpos * channels], margin) || k != seekpos)
1590
{ printf ("sf_seek (forwards, SEEK_CUR) followed by sf_readf_int failed (%d, %d) (%d, %d).\n", data [0], orig [seekpos * channels], k, seekpos + 1) ;
1594
seekpos = sf_seek (file, 0, SEEK_CUR) - 20 ;
1595
/* Check seek backward from current position. */
1596
k = sf_seek (file, -20, SEEK_CUR) ;
1597
test_readf_int_or_die (file, 0, data, 1, __LINE__) ;
1598
if (error_function ((double) data [0], (double) orig [seekpos * channels], margin) || k != seekpos)
1599
{ printf ("sf_seek (backwards, SEEK_CUR) followed by sf_readf_int failed (%d, %d) (%d, %d).\n", data [0], orig [seekpos * channels], k, seekpos) ;
1603
/* Check that read past end of file returns number of items. */
1604
sf_seek (file, (int) sfinfo.frames, SEEK_SET) ;
1606
if ((k = sf_readf_int (file, data, datalen)) != 0)
1607
{ printf ("\n\nLine %d: Return value from sf_readf_int past end of file incorrect (%d).\n", __LINE__, k) ;
1611
/* Check seek backward from end. */
1613
if ((k = sf_seek (file, 5 - (int) sfinfo.frames, SEEK_END)) != 5)
1614
{ printf ("sf_seek (SEEK_END) returned %d instead of %d.\n", k, 5) ;
1618
test_readf_int_or_die (file, 0, data, 1, __LINE__) ;
1619
if (error_function (data [0] / scale, orig [5] / scale, margin))
1620
{ printf ("\n\nLine %d: sf_seek (SEEK_END) followed by sf_readf_int failed (%d should be %d).\n", __LINE__, data [0], orig [5]) ;
1623
} /* if (sfinfo.seekable) */
1629
} /* sdlcomp_test_int */
1632
sdlcomp_test_float (const char *filename, int filetype, int channels, double margin)
1637
float *orig, *data, *smooth ;
1642
print_test_name ("sdlcomp_test_float", filename) ;
1644
printf ("** fix this ** ") ;
1646
datalen = BUFFER_SIZE ;
1648
orig = (float*) orig_buffer ;
1649
data = (float*) data_buffer ;
1650
smooth = (float*) smooth_buffer ;
1652
gen_signal_double (orig_buffer, 32000.0, channels, datalen) ;
1653
for (k = 0 ; k < datalen ; k++)
1654
orig [k] = (int) (orig_buffer [k]) ;
1656
sfinfo.samplerate = SAMPLE_RATE ;
1657
sfinfo.frames = 123456789 ; /* Ridiculous value. */
1658
sfinfo.channels = channels ;
1659
sfinfo.format = filetype ;
1661
file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_FALSE, __LINE__) ;
1662
sf_command (file, SFC_SET_NORM_FLOAT, NULL, SF_FALSE) ;
1663
test_write_float_or_die (file, 0, orig, datalen, __LINE__) ;
1664
sf_set_string (file, SF_STR_COMMENT, long_comment) ;
1667
memset (data, 0, datalen * sizeof (float)) ;
1669
if ((filetype & SF_FORMAT_TYPEMASK) != SF_FORMAT_RAW)
1670
memset (&sfinfo, 0, sizeof (sfinfo)) ;
1672
file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_FALSE, __LINE__) ;
1674
if ((sfinfo.format & (SF_FORMAT_TYPEMASK | SF_FORMAT_SUBMASK)) != (filetype & (SF_FORMAT_TYPEMASK | SF_FORMAT_SUBMASK)))
1675
{ printf ("\n\nLine %d: Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__, filetype, sfinfo.format) ;
1679
if (sfinfo.frames < datalen / channels)
1680
{ printf ("Too few.frames in file. (%ld should be a little more than %ld)\n", datalen, SF_COUNT_TO_LONG (sfinfo.frames)) ;
1684
if (sfinfo.frames > (datalen + 400))
1685
{ printf ("Too many.frames in file. (%ld should be a little more than %ld)\n", SF_COUNT_TO_LONG (sfinfo.frames), datalen) ;
1689
if (sfinfo.channels != channels)
1690
{ printf ("Incorrect number of channels in file.\n") ;
1694
check_comment (file, filetype, __LINE__) ;
1696
sf_command (file, SFC_SET_NORM_FLOAT, NULL, SF_FALSE) ;
1698
check_log_buffer_or_die (file, __LINE__) ;
1700
test_read_float_or_die (file, 0, data, datalen, __LINE__) ;
1702
memcpy (smooth, orig, datalen * sizeof (float)) ;
1703
smoothed_diff_float (data, datalen) ;
1704
smoothed_diff_float (smooth, datalen) ;
1706
sum_abs = fabs (data [0]) ;
1707
for (k = 1 ; k < datalen ; k++)
1708
{ if (error_function (data [k], smooth [k], margin))
1709
{ printf ("\n\nLine %d: Incorrect sample (#%d : %d should be %d).\n", __LINE__, k, (int) data [k], (int) smooth [k]) ;
1710
oct_save_float (orig, smooth, datalen) ;
1713
sum_abs += fabs (data [k]) ;
1717
{ printf ("\n\nLine %d: Signal is all zeros.\n", __LINE__) ;
1718
printf ("sum_abs : % 10.6f\n", sum_abs) ;
1722
if ((k = sf_read_float (file, data, datalen)) != sfinfo.frames - datalen)
1723
{ printf ("\n\nLine %d: Incorrect read length (%d should be %ld).\n", __LINE__, k, SF_COUNT_TO_LONG (sfinfo.frames - datalen)) ;
1727
if ((sfinfo.format & SF_FORMAT_SUBMASK) != SF_FORMAT_MS_ADPCM &&
1728
(sfinfo.format & SF_FORMAT_SUBMASK) != SF_FORMAT_GSM610)
1729
for (k = 0 ; k < sfinfo.frames - datalen ; k++)
1730
if (abs (data [k]) > decay_response (k))
1731
{ printf ("\n\nLine %d: Incorrect sample (#%ld : abs (%d) should be < %d).\n", __LINE__, datalen + k, (int) data [k], (int) decay_response (k)) ;
1735
/* Now test sf_seek function. */
1736
if (sfinfo.seekable)
1737
{ if ((k = sf_seek (file, 0, SEEK_SET)) != 0)
1738
{ printf ("\n\nLine %d: Seek to start of file failed (%d).\n", __LINE__, k) ;
1742
for (m = 0 ; m < 3 ; m++)
1743
{ test_read_float_or_die (file, 0, data, datalen / 7, __LINE__) ;
1745
smoothed_diff_float (data, datalen / 7) ;
1746
memcpy (smooth, orig + m * datalen / 7, datalen / 7 * sizeof (float)) ;
1747
smoothed_diff_float (smooth, datalen / 7) ;
1749
for (k = 0 ; k < datalen / 7 ; k++)
1750
if (error_function ((float) data [k], (float) smooth [k], margin))
1751
{ printf ("Incorrect sample C (#%d (%ld) : %d => %d).\n", k, k + m * (datalen / 7), (int) smooth [k], (int) data [k]) ;
1752
for (m = 0 ; m < 10 ; m++)
1753
printf ("%d ", (int) data [k]) ;
1757
} ; /* for (m = 0 ; m < 3 ; m++) */
1759
seekpos = BUFFER_SIZE / 10 ;
1761
/* Check seek from start of file. */
1762
if ((k = sf_seek (file, seekpos, SEEK_SET)) != seekpos)
1763
{ printf ("Seek to start of file + %d failed (%d).\n", seekpos, k) ;
1766
test_read_float_or_die (file, 0, data, 1, __LINE__) ;
1768
if (error_function ((float) data [0], (float) orig [seekpos * channels], margin))
1769
{ printf ("sf_seek (SEEK_SET) followed by sf_read_float failed (%d, %d).\n", (int) orig [1], (int) data [0]) ;
1773
if ((k = sf_seek (file, 0, SEEK_CUR)) != seekpos + 1)
1774
{ printf ("sf_seek (SEEK_CUR) with 0 offset failed (%d should be %d)\n", k, seekpos + 1) ;
1778
seekpos = sf_seek (file, 0, SEEK_CUR) + BUFFER_SIZE / 5 ;
1779
k = sf_seek (file, BUFFER_SIZE / 5, SEEK_CUR) ;
1780
test_read_float_or_die (file, 0, data, channels, __LINE__) ;
1781
if (error_function ((float) data [0], (float) orig [seekpos * channels], margin) || k != seekpos)
1782
{ printf ("sf_seek (forwards, SEEK_CUR) followed by sf_read_float failed (%d, %d) (%d, %d).\n", (int) data [0], (int) orig [seekpos * channels], k, seekpos + 1) ;
1786
seekpos = sf_seek (file, 0, SEEK_CUR) - 20 ;
1787
/* Check seek backward from current position. */
1788
k = sf_seek (file, -20, SEEK_CUR) ;
1789
test_read_float_or_die (file, 0, data, channels, __LINE__) ;
1790
if (error_function ((float) data [0], (float) orig [seekpos * channels], margin) || k != seekpos)
1791
{ printf ("sf_seek (backwards, SEEK_CUR) followed by sf_read_float failed (%d, %d) (%d, %d).\n", (int) data [0], (int) orig [seekpos * channels], k, seekpos) ;
1795
/* Check that read past end of file returns number of items. */
1796
sf_seek (file, (int) sfinfo.frames, SEEK_SET) ;
1798
if ((k = sf_read_float (file, data, datalen)) != 0)
1799
{ printf ("\n\nLine %d: Return value from sf_read_float past end of file incorrect (%d).\n", __LINE__, k) ;
1803
/* Check seek backward from end. */
1805
if ((k = sf_seek (file, 5 - (int) sfinfo.frames, SEEK_END)) != 5)
1806
{ printf ("sf_seek (SEEK_END) returned %d instead of %d.\n", k, 5) ;
1810
test_read_float_or_die (file, 0, data, channels, __LINE__) ;
1811
if (error_function ((float) data [0], (float) orig [5], margin))
1812
{ printf ("sf_seek (SEEK_END) followed by sf_read_float failed (%d should be %d).\n", (int) data [0], (int) orig [5]) ;
1815
} /* if (sfinfo.seekable) */
1821
} /* sdlcomp_test_float */
1824
sdlcomp_test_double (const char *filename, int filetype, int channels, double margin)
1829
double *orig, *data, *smooth, sum_abs ;
1832
print_test_name ("sdlcomp_test_double", filename) ;
1834
datalen = BUFFER_SIZE ;
1836
orig = orig_buffer ;
1837
data = data_buffer ;
1838
smooth = smooth_buffer ;
1840
gen_signal_double (orig_buffer, 32000.0, channels, datalen) ;
1842
sfinfo.samplerate = SAMPLE_RATE ;
1843
sfinfo.frames = 123456789 ; /* Ridiculous value. */
1844
sfinfo.channels = channels ;
1845
sfinfo.format = filetype ;
1847
file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_FALSE, __LINE__) ;
1848
sf_command (file, SFC_SET_NORM_DOUBLE, NULL, SF_FALSE) ;
1849
test_write_double_or_die (file, 0, orig, datalen, __LINE__) ;
1850
sf_set_string (file, SF_STR_COMMENT, long_comment) ;
1853
memset (data, 0, datalen * sizeof (double)) ;
1855
if ((filetype & SF_FORMAT_TYPEMASK) != SF_FORMAT_RAW)
1856
memset (&sfinfo, 0, sizeof (sfinfo)) ;
1858
file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_FALSE, __LINE__) ;
1860
if (sfinfo.format != filetype)
1861
{ printf ("Returned format incorrect (0x%08X => 0x%08X).\n", filetype, sfinfo.format) ;
1865
if (sfinfo.frames < datalen / channels)
1866
{ printf ("Too few.frames in file. (%ld should be a little more than %ld)\n", datalen, SF_COUNT_TO_LONG (sfinfo.frames)) ;
1870
if (sfinfo.frames > (datalen + 400))
1871
{ printf ("Too many.frames in file. (%ld should be a little more than %ld)\n", SF_COUNT_TO_LONG (sfinfo.frames), datalen) ;
1875
if (sfinfo.channels != channels)
1876
{ printf ("Incorrect number of channels in file.\n") ;
1880
check_comment (file, filetype, __LINE__) ;
1882
check_comment (file, filetype, __LINE__) ;
1884
sf_command (file, SFC_SET_NORM_DOUBLE, NULL, SF_FALSE) ;
1886
check_log_buffer_or_die (file, __LINE__) ;
1888
test_read_double_or_die (file, 0, data, datalen, __LINE__) ;
1890
memcpy (smooth, orig, datalen * sizeof (double)) ;
1891
smoothed_diff_double (data, datalen) ;
1892
smoothed_diff_double (smooth, datalen) ;
1894
sum_abs = fabs (data [0]) ;
1895
for (k = 1 ; k < datalen ; k++)
1896
{ if (error_function (data [k], smooth [k], margin))
1897
{ printf ("\n\nLine %d: Incorrect sample (#%d : %d should be %d).\n", __LINE__, k, (int) data [k], (int) smooth [k]) ;
1898
oct_save_double (orig, smooth, datalen) ;
1901
sum_abs += fabs (data [k]) ;
1905
{ printf ("\n\nLine %d: Signal is all zeros.\n", __LINE__) ;
1909
if ((k = sf_read_double (file, data, datalen)) != sfinfo.frames - datalen)
1910
{ printf ("\n\nLine %d: Incorrect read length (%d should be %ld).\n", __LINE__, k, SF_COUNT_TO_LONG (sfinfo.frames - datalen)) ;
1914
if ((sfinfo.format & SF_FORMAT_SUBMASK) != SF_FORMAT_MS_ADPCM &&
1915
(sfinfo.format & SF_FORMAT_SUBMASK) != SF_FORMAT_GSM610)
1916
for (k = 0 ; k < sfinfo.frames - datalen ; k++)
1917
if (abs (data [k]) > decay_response (k))
1918
{ printf ("\n\nLine %d: Incorrect sample (#%ld : abs (%d) should be < %d).\n", __LINE__, datalen + k, (int) data [k], (int) decay_response (k)) ;
1922
/* Now test sf_seek function. */
1923
if (sfinfo.seekable)
1924
{ if ((k = sf_seek (file, 0, SEEK_SET)) != 0)
1925
{ printf ("\n\nLine %d: Seek to start of file failed (%d).\n", __LINE__, k) ;
1929
for (m = 0 ; m < 3 ; m++)
1930
{ test_read_double_or_die (file, m, data, datalen / 7, __LINE__) ;
1932
smoothed_diff_double (data, datalen / 7) ;
1933
memcpy (smooth, orig + m * datalen / 7, datalen / 7 * sizeof (double)) ;
1934
smoothed_diff_double (smooth, datalen / 7) ;
1936
for (k = 0 ; k < datalen / 7 ; k++)
1937
if (error_function ((double) data [k], (double) smooth [k], margin))
1938
{ printf ("Incorrect sample C (#%d (%ld) : %d => %d).\n", k, k + m * (datalen / 7), (int) smooth [k], (int) data [k]) ;
1939
for (m = 0 ; m < 10 ; m++)
1940
printf ("%d ", (int) data [k]) ;
1944
} ; /* for (m = 0 ; m < 3 ; m++) */
1946
seekpos = BUFFER_SIZE / 10 ;
1948
/* Check seek from start of file. */
1949
if ((k = sf_seek (file, seekpos, SEEK_SET)) != seekpos)
1950
{ printf ("Seek to start of file + %d failed (%d).\n", seekpos, k) ;
1953
test_read_double_or_die (file, 0, data, 1, __LINE__) ;
1955
if (error_function ((double) data [0], (double) orig [seekpos * channels], margin))
1956
{ printf ("sf_seek (SEEK_SET) followed by sf_read_double failed (%d, %d).\n", (int) orig [1], (int) data [0]) ;
1960
if ((k = sf_seek (file, 0, SEEK_CUR)) != seekpos + 1)
1961
{ printf ("sf_seek (SEEK_CUR) with 0 offset failed (%d should be %d)\n", k, seekpos + 1) ;
1965
seekpos = sf_seek (file, 0, SEEK_CUR) + BUFFER_SIZE / 5 ;
1966
k = sf_seek (file, BUFFER_SIZE / 5, SEEK_CUR) ;
1967
test_read_double_or_die (file, 0, data, 1, __LINE__) ;
1968
if (error_function ((double) data [0], (double) orig [seekpos * channels], margin) || k != seekpos)
1969
{ printf ("sf_seek (forwards, SEEK_CUR) followed by sf_read_double failed (%d, %d) (%d, %d).\n", (int) data [0], (int) orig [seekpos * channels], k, seekpos + 1) ;
1973
seekpos = sf_seek (file, 0, SEEK_CUR) - 20 ;
1974
/* Check seek backward from current position. */
1975
k = sf_seek (file, -20, SEEK_CUR) ;
1976
test_read_double_or_die (file, 0, data, 1, __LINE__) ;
1977
if (error_function ((double) data [0], (double) orig [seekpos * channels], margin) || k != seekpos)
1978
{ printf ("sf_seek (backwards, SEEK_CUR) followed by sf_read_double failed (%d, %d) (%d, %d).\n", (int) data [0], (int) orig [seekpos * channels], k, seekpos) ;
1982
/* Check that read past end of file returns number of items. */
1983
sf_seek (file, (int) sfinfo.frames, SEEK_SET) ;
1985
if ((k = sf_read_double (file, data, datalen)) != 0)
1986
{ printf ("\n\nLine %d: Return value from sf_read_double past end of file incorrect (%d).\n", __LINE__, k) ;
1990
/* Check seek backward from end. */
1992
if ((k = sf_seek (file, 5 - (int) sfinfo.frames, SEEK_END)) != 5)
1993
{ printf ("sf_seek (SEEK_END) returned %d instead of %d.\n", k, 5) ;
1997
test_read_double_or_die (file, 0, data, 1, __LINE__) ;
1998
if (error_function ((double) data [0], (double) orig [5], margin))
1999
{ printf ("sf_seek (SEEK_END) followed by sf_read_double failed (%d should be %d).\n", (int) data [0], (int) orig [5]) ;
2002
} /* if (sfinfo.seekable) */
2008
} /* sdlcomp_test_double */
2010
/*========================================================================================
2011
** Auxiliary functions
2014
#define SIGNAL_MAXVAL 30000.0
2015
#define DECAY_COUNT 1000
2018
decay_response (int k)
2020
return (int) (1.2 * SIGNAL_MAXVAL) ;
2021
if (k > DECAY_COUNT)
2023
return (int) (1.2 * SIGNAL_MAXVAL * (DECAY_COUNT - k) / (1.0 * DECAY_COUNT)) ;
2024
} /* decay_response */
2027
gen_signal_double (double *data, double scale, int channels, int datalen)
2031
ramplen = DECAY_COUNT ;
2034
{ for (k = 0 ; k < datalen ; k++)
2036
amp = scale * k / ((double) ramplen) ;
2037
else if (k > datalen - ramplen)
2038
amp = scale * (datalen - k) / ((double) ramplen) ;
2040
/*-printf ("%3d : %g\n", k, amp) ;-*/
2042
data [k] = amp * (0.4 * sin (33.3 * 2.0 * M_PI * ((double) (k+1)) / ((double) SAMPLE_RATE))
2043
+ 0.3 * cos (201.1 * 2.0 * M_PI * ((double) (k+1)) / ((double) SAMPLE_RATE))) ;
2047
{ for (k = 0 ; k < datalen ; k ++)
2049
amp = scale * k / ((double) ramplen) ;
2050
else if (k > datalen - ramplen)
2051
amp = scale * (datalen - k) / ((double) ramplen) ;
2053
data [2 * k] = amp * (0.4 * sin (33.3 * 2.0 * M_PI * ((double) (k+1)) / ((double) SAMPLE_RATE))
2054
+ 0.3 * cos (201.1 * 2.0 * M_PI * ((double) (k+1)) / ((double) SAMPLE_RATE))) ;
2055
data [2 * k + 1] = amp * (0.4 * sin (55.5 * 2.0 * M_PI * ((double) (k+1)) / ((double) SAMPLE_RATE))
2056
+ 0.3 * cos (201.1 * 2.0 * M_PI * ((double) (k+1)) / ((double) SAMPLE_RATE))) ;
2061
} /* gen_signal_double */
2064
error_function (double data, double orig, double margin)
2067
if (fabs (orig) <= 500.0)
2068
error = fabs (fabs (data) - fabs (orig)) / 2000.0 ;
2069
else if (fabs (orig) <= 1000.0)
2070
error = fabs (data - orig) / 3000.0 ;
2072
error = fabs (data - orig) / fabs (orig) ;
2075
{ printf ("\n\n*******************\nError : %f\n", error) ;
2079
} /* error_function */
2082
smoothed_diff_short (short *data, unsigned int datalen)
2084
double memory = 0.0 ;
2086
/* Calculate the smoothed sample-to-sample difference. */
2087
for (k = 0 ; k < datalen - 1 ; k++)
2088
{ memory = 0.7 * memory + (1 - 0.7) * (double) (data [k+1] - data [k]) ;
2089
data [k] = (short) memory ;
2091
data [datalen-1] = data [datalen-2] ;
2093
} /* smoothed_diff_short */
2096
smoothed_diff_int (int *data, unsigned int datalen)
2098
double memory = 0.0 ;
2100
/* Calculate the smoothed sample-to-sample difference. */
2101
for (k = 0 ; k < datalen - 1 ; k++)
2102
{ memory = 0.7 * memory + (1 - 0.7) * (double) (data [k+1] - data [k]) ;
2103
data [k] = (int) memory ;
2105
data [datalen-1] = data [datalen-2] ;
2107
} /* smoothed_diff_int */
2110
smoothed_diff_float (float *data, unsigned int datalen)
2112
float memory = 0.0 ;
2114
/* Calculate the smoothed sample-to-sample difference. */
2115
for (k = 0 ; k < datalen - 1 ; k++)
2116
{ memory = 0.7 * memory + (1 - 0.7) * (data [k+1] - data [k]) ;
2119
data [datalen-1] = data [datalen-2] ;
2121
} /* smoothed_diff_float */
2124
smoothed_diff_double (double *data, unsigned int datalen)
2126
double memory = 0.0 ;
2128
/* Calculate the smoothed sample-to-sample difference. */
2129
for (k = 0 ; k < datalen - 1 ; k++)
2130
{ memory = 0.7 * memory + (1 - 0.7) * (data [k+1] - data [k]) ;
2133
data [datalen-1] = data [datalen-2] ;
2135
} /* smoothed_diff_double */
2138
check_comment (SNDFILE * file, int format, int lineno)
2139
{ const char *comment ;
2141
switch (format & SF_FORMAT_TYPEMASK)
2142
{ case SF_FORMAT_AIFF :
2143
case SF_FORMAT_WAV :
2144
case SF_FORMAT_WAVEX :
2150
comment = sf_get_string (file, SF_STR_COMMENT) ;
2151
if (comment == NULL)
2152
{ printf ("\n\nLine %d : File does not contain a comment string.\n\n", lineno) ;
2156
if (strcmp (comment, long_comment) != 0)
2157
{ printf ("\n\nLine %d : File comment does not match comment written.\n\n", lineno) ;
2162
} /* check_comment */
2165
** Do not edit or modify anything in this comment block.
2166
** The arch-tag line is a file identity tag for the GNU Arch
2167
** revision control system.
2169
** arch-tag: 5eb86888-3311-48b8-920e-c2a0393b7ad2