e871760e0dd5c8bd3e89b1c95186da9171002fa3
2 ** Copyright (C) 1999-2011 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 #define LCT_MAX(x,y) ((x) > (y) ? (x) : (y))
43 static void lcomp_test_short (const char *filename
, int filetype
, int chan
, double margin
) ;
44 static void lcomp_test_int (const char *filename
, int filetype
, int chan
, double margin
) ;
45 static void lcomp_test_float (const char *filename
, int filetype
, int chan
, double margin
) ;
46 static void lcomp_test_double (const char *filename
, int filetype
, int chan
, double margin
) ;
48 static void sdlcomp_test_short (const char *filename
, int filetype
, int chan
, double margin
) ;
49 static void sdlcomp_test_int (const char *filename
, int filetype
, int chan
, double margin
) ;
50 static void sdlcomp_test_float (const char *filename
, int filetype
, int chan
, double margin
) ;
51 static void sdlcomp_test_double (const char *filename
, int filetype
, int chan
, double margin
) ;
53 static void read_raw_test (const char *filename
, int filetype
, int chan
) ;
55 static int error_function (double data
, double orig
, double margin
) ;
56 static int decay_response (int k
) ;
58 static void gen_signal_double (double *data
, double scale
, int channels
, int datalen
) ;
60 static void smoothed_diff_short (short *data
, unsigned int datalen
) ;
61 static void smoothed_diff_int (int *data
, unsigned int datalen
) ;
62 static void smoothed_diff_float (float *data
, unsigned int datalen
) ;
63 static void smoothed_diff_double (double *data
, unsigned int datalen
) ;
65 static void check_comment (SNDFILE
* file
, int format
, int lineno
) ;
67 static int is_lossy (int filetype
) ;
70 ** Force the start of these buffers to be double aligned. Sparc-solaris will
71 ** choke if they are not.
74 { double d
[BUFFER_SIZE
+ 1] ;
75 float f
[BUFFER_SIZE
+ 1] ;
76 int i
[BUFFER_SIZE
+ 1] ;
77 short s
[BUFFER_SIZE
+ 1] ;
78 char c
[BUFFER_SIZE
+ 1] ;
81 static BUFFER data_buffer
;
82 static BUFFER orig_buffer
;
83 static BUFFER smooth_buffer
;
85 static const char *long_comment
=
86 "This is really quite a long comment. It is designed to be long enough "
87 "to screw up the encoders and decoders if the file container format does "
88 "not handle things correctly. If everything is working correctly, the "
89 "decoder will only decode the actual audio data, and not this string at "
90 "the end of the file." ;
93 main (int argc
, char *argv
[])
98 { printf ("Usage : %s <test>\n", argv
[0]) ;
99 printf (" Where <test> is one of the following:\n") ;
100 printf (" wav_ima - test IMA ADPCM WAV file functions\n") ;
101 printf (" wav_msadpcm - test MS ADPCM WAV file functions\n") ;
102 printf (" wav_gsm610 - test GSM 6.10 WAV file functions\n") ;
103 printf (" wav_ulaw - test u-law WAV file functions\n") ;
104 printf (" wav_alaw - test A-law WAV file functions\n") ;
105 printf (" wve - test Psion WVE file functions\n") ;
106 printf (" all - perform all tests\n") ;
110 do_all
= ! strcmp (argv
[1], "all") ;
112 if (do_all
|| strcmp (argv
[1], "wav_pcm") == 0)
113 { /* This is just a sanity test for PCM encoding. */
114 lcomp_test_short ("pcm.wav", SF_FORMAT_WAV
| SF_FORMAT_PCM_16
, 2, 1e-50) ;
115 lcomp_test_int ("pcm.wav", SF_FORMAT_WAV
| SF_FORMAT_PCM_32
, 2, 1e-50) ;
116 lcomp_test_short ("pcm.rifx", SF_ENDIAN_BIG
| SF_FORMAT_WAV
| SF_FORMAT_PCM_16
, 2, 1e-50) ;
117 lcomp_test_int ("pcm.rifx", SF_ENDIAN_BIG
| SF_FORMAT_WAV
| SF_FORMAT_PCM_32
, 2, 1e-50) ;
118 /* Lite remove start */
119 lcomp_test_float ("pcm.wav", SF_FORMAT_WAV
| SF_FORMAT_FLOAT
, 2, 1e-50) ;
120 lcomp_test_double ("pcm.wav", SF_FORMAT_WAV
| SF_FORMAT_DOUBLE
, 2, 1e-50) ;
121 /* Lite remove end */
123 read_raw_test ("pcm.wav", SF_FORMAT_WAV
| SF_FORMAT_PCM_U8
, 2) ;
127 /* For all the rest, if the file format supports more than 1 channel, use stereo. */
128 /* Lite remove start */
129 if (do_all
|| strcmp (argv
[1], "wav_ima") == 0)
130 { lcomp_test_short ("ima.wav", SF_FORMAT_WAV
| SF_FORMAT_IMA_ADPCM
, 2, 0.18) ;
131 lcomp_test_int ("ima.wav", SF_FORMAT_WAV
| SF_FORMAT_IMA_ADPCM
, 2, 0.65) ;
132 lcomp_test_float ("ima.wav", SF_FORMAT_WAV
| SF_FORMAT_IMA_ADPCM
, 2, 0.18) ;
133 lcomp_test_double ("ima.wav", SF_FORMAT_WAV
| SF_FORMAT_IMA_ADPCM
, 2, 0.18) ;
135 lcomp_test_short ("ima.rifx", SF_ENDIAN_BIG
| SF_FORMAT_WAV
| SF_FORMAT_IMA_ADPCM
, 2, 0.18) ;
136 lcomp_test_int ("ima.rifx", SF_ENDIAN_BIG
| SF_FORMAT_WAV
| SF_FORMAT_IMA_ADPCM
, 2, 0.18) ;
137 lcomp_test_float ("ima.rifx", SF_ENDIAN_BIG
| SF_FORMAT_WAV
| SF_FORMAT_IMA_ADPCM
, 2, 0.18) ;
138 lcomp_test_double ("ima.rifx", SF_ENDIAN_BIG
| SF_FORMAT_WAV
| SF_FORMAT_IMA_ADPCM
, 2, 0.18) ;
140 sdlcomp_test_short ("ima.wav", SF_FORMAT_WAV
| SF_FORMAT_IMA_ADPCM
, 2, 0.18) ;
141 sdlcomp_test_int ("ima.wav", SF_FORMAT_WAV
| SF_FORMAT_IMA_ADPCM
, 2, 0.18) ;
142 sdlcomp_test_float ("ima.wav", SF_FORMAT_WAV
| SF_FORMAT_IMA_ADPCM
, 2, 0.18) ;
143 sdlcomp_test_double ("ima.wav", SF_FORMAT_WAV
| SF_FORMAT_IMA_ADPCM
, 2, 0.18) ;
147 if (do_all
|| strcmp (argv
[1], "wav_msadpcm") == 0)
148 { lcomp_test_short ("msadpcm.wav", SF_FORMAT_WAV
| SF_FORMAT_MS_ADPCM
, 2, 0.36) ;
149 lcomp_test_int ("msadpcm.wav", SF_FORMAT_WAV
| SF_FORMAT_MS_ADPCM
, 2, 0.36) ;
150 lcomp_test_float ("msadpcm.wav", SF_FORMAT_WAV
| SF_FORMAT_MS_ADPCM
, 2, 0.36) ;
151 lcomp_test_double ("msadpcm.wav", SF_FORMAT_WAV
| SF_FORMAT_MS_ADPCM
, 2, 0.36) ;
153 lcomp_test_short ("msadpcm.rifx", SF_ENDIAN_BIG
| SF_FORMAT_WAV
| SF_FORMAT_MS_ADPCM
, 2, 0.36) ;
154 lcomp_test_int ("msadpcm.rifx", SF_ENDIAN_BIG
| SF_FORMAT_WAV
| SF_FORMAT_MS_ADPCM
, 2, 0.36) ;
155 lcomp_test_float ("msadpcm.rifx", SF_ENDIAN_BIG
| SF_FORMAT_WAV
| SF_FORMAT_MS_ADPCM
, 2, 0.36) ;
156 lcomp_test_double ("msadpcm.rifx", SF_ENDIAN_BIG
| SF_FORMAT_WAV
| SF_FORMAT_MS_ADPCM
, 2, 0.36) ;
158 sdlcomp_test_short ("msadpcm.wav", SF_FORMAT_WAV
| SF_FORMAT_MS_ADPCM
, 2, 0.36) ;
159 sdlcomp_test_int ("msadpcm.wav", SF_FORMAT_WAV
| SF_FORMAT_MS_ADPCM
, 2, 0.36) ;
160 sdlcomp_test_float ("msadpcm.wav", SF_FORMAT_WAV
| SF_FORMAT_MS_ADPCM
, 2, 0.36) ;
161 sdlcomp_test_double ("msadpcm.wav", SF_FORMAT_WAV
| SF_FORMAT_MS_ADPCM
, 2, 0.36) ;
166 if (do_all
|| strcmp (argv
[1], "wav_g721") == 0)
167 { printf ("**** Fix this later : error bound should be 0.06 ****\n") ;
168 lcomp_test_short ("g721.wav", SF_FORMAT_WAV
| SF_FORMAT_G721_32
, 1, 0.7) ;
169 lcomp_test_int ("g721.wav", SF_FORMAT_WAV
| SF_FORMAT_G721_32
, 1, 0.7) ;
171 lcomp_test_short ("g721.rifx", SF_ENDIAN_BIG
| SF_FORMAT_WAV
| SF_FORMAT_G721_32
, 1, 0.7) ;
172 lcomp_test_int ("g721.rifx", SF_ENDIAN_BIG
| SF_FORMAT_WAV
| SF_FORMAT_G721_32
, 1, 0.7) ;
176 /* Lite remove end */
178 if (do_all
|| strcmp (argv
[1], "wav_ulaw") == 0)
179 { lcomp_test_short ("ulaw.wav", SF_FORMAT_WAV
| SF_FORMAT_ULAW
, 2, 0.04) ;
180 lcomp_test_int ("ulaw.wav", SF_FORMAT_WAV
| SF_FORMAT_ULAW
, 2, 0.04) ;
182 lcomp_test_short ("ulaw.rifx", SF_ENDIAN_BIG
| SF_FORMAT_WAV
| SF_FORMAT_ULAW
, 2, 0.04) ;
183 lcomp_test_int ("ulaw.rifx", SF_ENDIAN_BIG
| SF_FORMAT_WAV
| SF_FORMAT_ULAW
, 2, 0.04) ;
185 /* Lite remove start */
186 lcomp_test_float ("ulaw.wav", SF_FORMAT_WAV
| SF_FORMAT_ULAW
, 2, 0.04) ;
187 lcomp_test_double ("ulaw.wav", SF_FORMAT_WAV
| SF_FORMAT_ULAW
, 2, 0.04) ;
188 /* Lite remove end */
190 read_raw_test ("ulaw.wav", SF_FORMAT_WAV
| SF_FORMAT_ULAW
, 2) ;
194 if (do_all
|| strcmp (argv
[1], "wav_alaw") == 0)
195 { lcomp_test_short ("alaw.wav", SF_FORMAT_WAV
| SF_FORMAT_ALAW
, 2, 0.04) ;
196 lcomp_test_int ("alaw.wav", SF_FORMAT_WAV
| SF_FORMAT_ALAW
, 2, 0.04) ;
197 /* Lite remove start */
198 lcomp_test_float ("alaw.wav", SF_FORMAT_WAV
| SF_FORMAT_ALAW
, 2, 0.04) ;
199 lcomp_test_double ("alaw.wav", SF_FORMAT_WAV
| SF_FORMAT_ALAW
, 2, 0.04) ;
200 /* Lite remove end */
202 read_raw_test ("alaw.wav", SF_FORMAT_WAV
| SF_FORMAT_ALAW
, 2) ;
206 if (do_all
|| strcmp (argv
[1], "wav_gsm610") == 0)
207 { /* Don't do lcomp_test_XXX as the errors are too big. */
208 sdlcomp_test_short ("gsm610.wav", SF_FORMAT_WAV
| SF_FORMAT_GSM610
, 1, 0.24) ;
209 sdlcomp_test_int ("gsm610.wav", SF_FORMAT_WAV
| SF_FORMAT_GSM610
, 1, 0.24) ;
211 sdlcomp_test_short ("gsm610.rifx", SF_ENDIAN_BIG
| SF_FORMAT_WAV
| SF_FORMAT_GSM610
, 1, 0.24) ;
212 sdlcomp_test_int ("gsm610.rifx", SF_ENDIAN_BIG
| SF_FORMAT_WAV
| SF_FORMAT_GSM610
, 1, 0.24) ;
214 /* Lite remove start */
215 sdlcomp_test_float ("gsm610.wav", SF_FORMAT_WAV
| SF_FORMAT_GSM610
, 1, 0.24) ;
216 sdlcomp_test_double ("gsm610.wav", SF_FORMAT_WAV
| SF_FORMAT_GSM610
, 1, 0.24) ;
217 /* Lite remove end */
221 if (do_all
|| strcmp (argv
[1], "aiff_ulaw") == 0)
222 { lcomp_test_short ("ulaw.aiff", SF_FORMAT_AIFF
| SF_FORMAT_ULAW
, 2, 0.04) ;
223 lcomp_test_int ("ulaw.aiff", SF_FORMAT_AIFF
| SF_FORMAT_ULAW
, 2, 0.04) ;
224 /* Lite remove start */
225 lcomp_test_float ("ulaw.aiff", SF_FORMAT_AIFF
| SF_FORMAT_ULAW
, 2, 0.04) ;
226 lcomp_test_double ("ulaw.aiff", SF_FORMAT_AIFF
| SF_FORMAT_ULAW
, 2, 0.04) ;
227 /* Lite remove end */
229 read_raw_test ("ulaw.aiff", SF_FORMAT_AIFF
| SF_FORMAT_ULAW
, 2) ;
233 if (do_all
|| strcmp (argv
[1], "aiff_alaw") == 0)
234 { lcomp_test_short ("alaw.aiff", SF_FORMAT_AIFF
| SF_FORMAT_ALAW
, 2, 0.04) ;
235 lcomp_test_int ("alaw.aiff", SF_FORMAT_AIFF
| SF_FORMAT_ALAW
, 2, 0.04) ;
236 /* Lite remove start */
237 lcomp_test_float ("alaw.aiff", SF_FORMAT_AIFF
| SF_FORMAT_ALAW
, 2, 0.04) ;
238 lcomp_test_double ("alaw.aiff", SF_FORMAT_AIFF
| SF_FORMAT_ALAW
, 2, 0.04) ;
239 /* Lite remove end */
241 read_raw_test ("alaw.aiff", SF_FORMAT_AIFF
| SF_FORMAT_ALAW
, 2) ;
245 if (do_all
|| strcmp (argv
[1], "aiff_gsm610") == 0)
246 { /* Don't do lcomp_test_XXX as the errors are too big. */
247 sdlcomp_test_short ("gsm610.aiff", SF_FORMAT_AIFF
| SF_FORMAT_GSM610
, 1, 0.24) ;
248 sdlcomp_test_int ("gsm610.aiff", SF_FORMAT_AIFF
| SF_FORMAT_GSM610
, 1, 0.24) ;
249 /* Lite remove start */
250 sdlcomp_test_float ("gsm610.aiff", SF_FORMAT_AIFF
| SF_FORMAT_GSM610
, 1, 0.24) ;
251 sdlcomp_test_double ("gsm610.aiff", SF_FORMAT_AIFF
| SF_FORMAT_GSM610
, 1, 0.24) ;
252 /* Lite remove end */
256 if (strcmp (argv
[1], "aiff_ima") == 0)
257 { lcomp_test_short ("ima.aiff", SF_FORMAT_AIFF
| SF_FORMAT_IMA_ADPCM
, 2, 0.18) ;
258 lcomp_test_int ("ima.aiff", SF_FORMAT_AIFF
| SF_FORMAT_IMA_ADPCM
, 2, 0.18) ;
259 /* Lite remove start */
260 lcomp_test_float ("ima.aiff", SF_FORMAT_AIFF
| SF_FORMAT_IMA_ADPCM
, 2, 0.18) ;
261 lcomp_test_double ("ima.aiff", SF_FORMAT_AIFF
| SF_FORMAT_IMA_ADPCM
, 2, 0.18) ;
262 /* Lite remove end */
265 if (do_all
|| strcmp (argv
[1], "au_ulaw") == 0)
266 { lcomp_test_short ("ulaw.au", SF_ENDIAN_BIG
| SF_FORMAT_AU
| SF_FORMAT_ULAW
, 2, 0.04) ;
267 lcomp_test_int ("ulaw.au", SF_ENDIAN_LITTLE
| SF_FORMAT_AU
| SF_FORMAT_ULAW
, 2, 0.04) ;
268 /* Lite remove start */
269 lcomp_test_float ("ulaw.au", SF_ENDIAN_LITTLE
| SF_FORMAT_AU
| SF_FORMAT_ULAW
, 2, 0.04) ;
270 lcomp_test_double ("ulaw.au", SF_ENDIAN_BIG
| SF_FORMAT_AU
| SF_FORMAT_ULAW
, 2, 0.04) ;
271 /* Lite remove end */
275 if (do_all
|| strcmp (argv
[1], "au_alaw") == 0)
276 { lcomp_test_short ("alaw.au", SF_ENDIAN_LITTLE
| SF_FORMAT_AU
| SF_FORMAT_ALAW
, 2, 0.04) ;
277 lcomp_test_int ("alaw.au", SF_ENDIAN_BIG
| SF_FORMAT_AU
| SF_FORMAT_ALAW
, 2, 0.04) ;
278 /* Lite remove start */
279 lcomp_test_float ("alaw.au", SF_ENDIAN_BIG
| SF_FORMAT_AU
| SF_FORMAT_ALAW
, 2, 0.04) ;
280 lcomp_test_double ("alaw.au", SF_ENDIAN_LITTLE
| SF_FORMAT_AU
| SF_FORMAT_ALAW
, 2, 0.04) ;
281 /* Lite remove end */
285 /* Lite remove start */
286 if (do_all
|| strcmp (argv
[1], "au_g721") == 0)
287 { printf ("**** Fix this later : error bound should be 0.06 ****\n") ;
288 lcomp_test_short ("g721.au", SF_ENDIAN_LITTLE
| SF_FORMAT_AU
| SF_FORMAT_G721_32
, 1, 0.7) ;
289 lcomp_test_int ("g721.au", SF_ENDIAN_BIG
| SF_FORMAT_AU
| SF_FORMAT_G721_32
, 1, 0.7) ;
290 lcomp_test_float ("g721.au", SF_ENDIAN_LITTLE
| SF_FORMAT_AU
| SF_FORMAT_G721_32
, 1, 0.7) ;
291 lcomp_test_double ("g721.au", SF_ENDIAN_BIG
| SF_FORMAT_AU
| SF_FORMAT_G721_32
, 1, 0.7) ;
293 /*- sdlcomp_test_short ("g721.au", SF_ENDIAN_BIG | SF_FORMAT_AU | SF_FORMAT_G721_32, 1, 0.07) ;
294 sdlcomp_test_int ("g721.au", SF_ENDIAN_LITTLE | SF_FORMAT_AU | SF_FORMAT_G721_32, 1, 0.07) ;
295 sdlcomp_test_float ("g721.au", SF_ENDIAN_BIG | SF_FORMAT_AU | SF_FORMAT_G721_32, 1, 0.07) ;
296 sdlcomp_test_double ("g721.au", SF_ENDIAN_LITTLE | SF_FORMAT_AU | SF_FORMAT_G721_32, 1, 0.12) ;
301 if (do_all
|| strcmp (argv
[1], "au_g723") == 0)
302 { printf ("**** Fix this later : error bound should be 0.16 ****\n") ;
303 lcomp_test_short ("g723_24.au", SF_ENDIAN_LITTLE
| SF_FORMAT_AU
| SF_FORMAT_G723_24
, 1, 0.7) ;
304 lcomp_test_int ("g723_24.au", SF_ENDIAN_BIG
| SF_FORMAT_AU
| SF_FORMAT_G723_24
, 1, 0.7) ;
305 lcomp_test_float ("g723_24.au", SF_ENDIAN_LITTLE
| SF_FORMAT_AU
| SF_FORMAT_G723_24
, 1, 0.7) ;
306 lcomp_test_double ("g723_24.au", SF_ENDIAN_BIG
| SF_FORMAT_AU
| SF_FORMAT_G723_24
, 1, 0.7) ;
308 lcomp_test_short ("g723_40.au", SF_ENDIAN_LITTLE
| SF_FORMAT_AU
| SF_FORMAT_G723_40
, 1, 0.85) ;
309 lcomp_test_int ("g723_40.au", SF_ENDIAN_BIG
| SF_FORMAT_AU
| SF_FORMAT_G723_40
, 1, 0.84) ;
310 lcomp_test_float ("g723_40.au", SF_ENDIAN_LITTLE
| SF_FORMAT_AU
| SF_FORMAT_G723_40
, 1, 0.86) ;
311 lcomp_test_double ("g723_40.au", SF_ENDIAN_BIG
| SF_FORMAT_AU
| SF_FORMAT_G723_40
, 1, 0.86) ;
313 /*- sdlcomp_test_short ("g723.au", SF_ENDIAN_BIG | SF_FORMAT_AU | SF_FORMAT_G723_24, 1, 0.15) ;
314 sdlcomp_test_int ("g723.au", SF_ENDIAN_LITTLE | SF_FORMAT_AU | SF_FORMAT_G723_24, 1, 0.15) ;
315 sdlcomp_test_float ("g723.au", SF_ENDIAN_BIG | SF_FORMAT_AU | SF_FORMAT_G723_24, 1, 0.15) ;
316 sdlcomp_test_double ("g723.au", SF_ENDIAN_LITTLE | SF_FORMAT_AU | SF_FORMAT_G723_24, 1, 0.15) ;
320 /* Lite remove end */
322 if (do_all
|| strcmp (argv
[1], "caf_ulaw") == 0)
323 { lcomp_test_short ("ulaw.caf", SF_FORMAT_CAF
| SF_FORMAT_ULAW
, 2, 0.04) ;
324 lcomp_test_int ("ulaw.caf", SF_FORMAT_CAF
| SF_FORMAT_ULAW
, 2, 0.04) ;
325 /* Lite remove start */
326 lcomp_test_float ("ulaw.caf", SF_FORMAT_CAF
| SF_FORMAT_ULAW
, 2, 0.04) ;
327 lcomp_test_double ("ulaw.caf", SF_FORMAT_CAF
| SF_FORMAT_ULAW
, 2, 0.04) ;
328 /* Lite remove end */
330 read_raw_test ("ulaw.caf", SF_FORMAT_CAF
| SF_FORMAT_ULAW
, 2) ;
334 if (do_all
|| strcmp (argv
[1], "caf_alaw") == 0)
335 { lcomp_test_short ("alaw.caf", SF_FORMAT_CAF
| SF_FORMAT_ALAW
, 2, 0.04) ;
336 lcomp_test_int ("alaw.caf", SF_FORMAT_CAF
| SF_FORMAT_ALAW
, 2, 0.04) ;
337 /* Lite remove start */
338 lcomp_test_float ("alaw.caf", SF_FORMAT_CAF
| SF_FORMAT_ALAW
, 2, 0.04) ;
339 lcomp_test_double ("alaw.caf", SF_FORMAT_CAF
| SF_FORMAT_ALAW
, 2, 0.04) ;
340 /* Lite remove end */
342 read_raw_test ("alaw.caf", SF_FORMAT_CAF
| SF_FORMAT_ALAW
, 2) ;
347 if (do_all
|| strcmp (argv
[1], "raw_ulaw") == 0)
348 { lcomp_test_short ("ulaw.raw", SF_ENDIAN_LITTLE
| SF_FORMAT_RAW
| SF_FORMAT_ULAW
, 2, 0.04) ;
349 lcomp_test_int ("ulaw.raw", SF_ENDIAN_BIG
| SF_FORMAT_RAW
| SF_FORMAT_ULAW
, 2, 0.04) ;
350 /* Lite remove start */
351 lcomp_test_float ("ulaw.raw", SF_ENDIAN_LITTLE
| SF_FORMAT_RAW
| SF_FORMAT_ULAW
, 2, 0.04) ;
352 lcomp_test_double ("ulaw.raw", SF_ENDIAN_BIG
| SF_FORMAT_RAW
| SF_FORMAT_ULAW
, 2, 0.04) ;
353 /* Lite remove end */
357 if (do_all
|| strcmp (argv
[1], "raw_alaw") == 0)
358 { lcomp_test_short ("alaw.raw", SF_ENDIAN_LITTLE
| SF_FORMAT_RAW
| SF_FORMAT_ALAW
, 2, 0.04) ;
359 lcomp_test_int ("alaw.raw", SF_ENDIAN_BIG
| SF_FORMAT_RAW
| SF_FORMAT_ALAW
, 2, 0.04) ;
360 /* Lite remove start */
361 lcomp_test_float ("alaw.raw", SF_ENDIAN_LITTLE
| SF_FORMAT_RAW
| SF_FORMAT_ALAW
, 2, 0.04) ;
362 lcomp_test_double ("alaw.raw", SF_ENDIAN_BIG
| SF_FORMAT_RAW
| SF_FORMAT_ALAW
, 2, 0.04) ;
363 /* Lite remove end */
367 if (do_all
|| strcmp (argv
[1], "raw_gsm610") == 0)
368 { /* Don't do lcomp_test_XXX as the errors are too big. */
369 sdlcomp_test_short ("raw.gsm", SF_FORMAT_RAW
| SF_FORMAT_GSM610
, 1, 0.24) ;
370 sdlcomp_test_int ("raw.gsm", SF_FORMAT_RAW
| SF_FORMAT_GSM610
, 1, 0.24) ;
371 sdlcomp_test_float ("raw.gsm", SF_FORMAT_RAW
| SF_FORMAT_GSM610
, 1, 0.24) ;
372 sdlcomp_test_double ("raw.gsm", SF_FORMAT_RAW
| SF_FORMAT_GSM610
, 1, 0.24) ;
376 if (do_all
|| strcmp (argv
[1], "ogg_vorbis") == 0)
377 { if (HAVE_EXTERNAL_LIBS
)
378 { /* Don't do lcomp_test_XXX as the errors are too big. */
379 sdlcomp_test_short ("vorbis.oga", SF_FORMAT_OGG
| SF_FORMAT_VORBIS
, 1, 0.30) ;
380 sdlcomp_test_int ("vorbis.oga", SF_FORMAT_OGG
| SF_FORMAT_VORBIS
, 1, 0.30) ;
381 sdlcomp_test_float ("vorbis.oga", SF_FORMAT_OGG
| SF_FORMAT_VORBIS
, 1, 0.30) ;
382 sdlcomp_test_double ("vorbis.oga", SF_FORMAT_OGG
| SF_FORMAT_VORBIS
, 1, 0.30) ;
385 puts (" No Ogg/Vorbis tests because Ogg/Vorbis support was not compiled in.") ;
390 /* Lite remove start */
391 if (do_all
|| strcmp (argv
[1], "ircam_ulaw") == 0)
392 { lcomp_test_short ("ulaw.ircam", SF_ENDIAN_LITTLE
| SF_FORMAT_IRCAM
| SF_FORMAT_ULAW
, 2, 0.04) ;
393 lcomp_test_int ("ulaw.ircam", SF_ENDIAN_BIG
| SF_FORMAT_IRCAM
| SF_FORMAT_ULAW
, 2, 0.04) ;
394 lcomp_test_float ("ulaw.ircam", SF_ENDIAN_LITTLE
| SF_FORMAT_IRCAM
| SF_FORMAT_ULAW
, 2, 0.04) ;
395 lcomp_test_double ("ulaw.ircam", SF_ENDIAN_BIG
| SF_FORMAT_IRCAM
| SF_FORMAT_ULAW
, 2, 0.04) ;
399 if (do_all
|| strcmp (argv
[1], "ircam_alaw") == 0)
400 { lcomp_test_short ("alaw.ircam", SF_ENDIAN_LITTLE
| SF_FORMAT_IRCAM
| SF_FORMAT_ALAW
, 2, 0.04) ;
401 lcomp_test_int ("alaw.ircam", SF_ENDIAN_BIG
| SF_FORMAT_IRCAM
| SF_FORMAT_ALAW
, 2, 0.04) ;
402 lcomp_test_float ("alaw.ircam", SF_ENDIAN_LITTLE
| SF_FORMAT_IRCAM
| SF_FORMAT_ALAW
, 2, 0.04) ;
403 lcomp_test_double ("alaw.ircam", SF_ENDIAN_BIG
| SF_FORMAT_IRCAM
| SF_FORMAT_ALAW
, 2, 0.04) ;
407 if (do_all
|| strcmp (argv
[1], "nist_ulaw") == 0)
408 { lcomp_test_short ("ulaw.nist", SF_ENDIAN_LITTLE
| SF_FORMAT_NIST
| SF_FORMAT_ULAW
, 2, 0.04) ;
409 lcomp_test_int ("ulaw.nist", SF_ENDIAN_BIG
| SF_FORMAT_NIST
| SF_FORMAT_ULAW
, 2, 0.04) ;
410 lcomp_test_float ("ulaw.nist", SF_ENDIAN_LITTLE
| SF_FORMAT_NIST
| SF_FORMAT_ULAW
, 2, 0.04) ;
411 lcomp_test_double ("ulaw.nist", SF_ENDIAN_BIG
| SF_FORMAT_NIST
| SF_FORMAT_ULAW
, 2, 0.04) ;
415 if (do_all
|| strcmp (argv
[1], "nist_alaw") == 0)
416 { lcomp_test_short ("alaw.nist", SF_ENDIAN_LITTLE
| SF_FORMAT_NIST
| SF_FORMAT_ALAW
, 2, 0.04) ;
417 lcomp_test_int ("alaw.nist", SF_ENDIAN_BIG
| SF_FORMAT_NIST
| SF_FORMAT_ALAW
, 2, 0.04) ;
418 lcomp_test_float ("alaw.nist", SF_ENDIAN_LITTLE
| SF_FORMAT_NIST
| SF_FORMAT_ALAW
, 2, 0.04) ;
419 lcomp_test_double ("alaw.nist", SF_ENDIAN_BIG
| SF_FORMAT_NIST
| SF_FORMAT_ALAW
, 2, 0.04) ;
423 if (do_all
|| strcmp (argv
[1], "voc_ulaw") == 0)
424 { lcomp_test_short ("ulaw.voc", SF_FORMAT_VOC
| SF_FORMAT_ULAW
, 2, 0.04) ;
425 lcomp_test_int ("ulaw.voc", SF_FORMAT_VOC
| SF_FORMAT_ULAW
, 2, 0.04) ;
426 lcomp_test_float ("ulaw.voc", SF_FORMAT_VOC
| SF_FORMAT_ULAW
, 2, 0.04) ;
427 lcomp_test_double ("ulaw.voc", SF_FORMAT_VOC
| SF_FORMAT_ULAW
, 2, 0.04) ;
431 if (do_all
|| strcmp (argv
[1], "voc_alaw") == 0)
432 { lcomp_test_short ("alaw.voc", SF_FORMAT_VOC
| SF_FORMAT_ALAW
, 2, 0.04) ;
433 lcomp_test_int ("alaw.voc", SF_FORMAT_VOC
| SF_FORMAT_ALAW
, 2, 0.04) ;
434 lcomp_test_float ("alaw.voc", SF_FORMAT_VOC
| SF_FORMAT_ALAW
, 2, 0.04) ;
435 lcomp_test_double ("alaw.voc", SF_FORMAT_VOC
| SF_FORMAT_ALAW
, 2, 0.04) ;
438 /* Lite remove end */
440 if (do_all
|| strcmp (argv
[1], "w64_ulaw") == 0)
441 { lcomp_test_short ("ulaw.w64", SF_FORMAT_W64
| SF_FORMAT_ULAW
, 2, 0.04) ;
442 lcomp_test_int ("ulaw.w64", SF_FORMAT_W64
| SF_FORMAT_ULAW
, 2, 0.04) ;
443 /* Lite remove start */
444 lcomp_test_float ("ulaw.w64", SF_FORMAT_W64
| SF_FORMAT_ULAW
, 2, 0.04) ;
445 lcomp_test_double ("ulaw.w64", SF_FORMAT_W64
| SF_FORMAT_ULAW
, 2, 0.04) ;
446 /* Lite remove end */
448 read_raw_test ("ulaw.w64", SF_FORMAT_W64
| SF_FORMAT_ULAW
, 2) ;
452 if (do_all
|| strcmp (argv
[1], "w64_alaw") == 0)
453 { lcomp_test_short ("alaw.w64", SF_FORMAT_W64
| SF_FORMAT_ALAW
, 2, 0.04) ;
454 lcomp_test_int ("alaw.w64", SF_FORMAT_W64
| SF_FORMAT_ALAW
, 2, 0.04) ;
455 /* Lite remove start */
456 lcomp_test_float ("alaw.w64", SF_FORMAT_W64
| SF_FORMAT_ALAW
, 2, 0.04) ;
457 lcomp_test_double ("alaw.w64", SF_FORMAT_W64
| SF_FORMAT_ALAW
, 2, 0.04) ;
458 /* Lite remove end */
460 read_raw_test ("alaw.w64", SF_FORMAT_W64
| SF_FORMAT_ALAW
, 2) ;
464 /* Lite remove start */
465 if (do_all
|| strcmp (argv
[1], "w64_ima") == 0)
466 { lcomp_test_short ("ima.w64", SF_FORMAT_W64
| SF_FORMAT_IMA_ADPCM
, 2, 0.18) ;
467 lcomp_test_int ("ima.w64", SF_FORMAT_W64
| SF_FORMAT_IMA_ADPCM
, 2, 0.18) ;
468 lcomp_test_float ("ima.w64", SF_FORMAT_W64
| SF_FORMAT_IMA_ADPCM
, 2, 0.18) ;
469 lcomp_test_double ("ima.w64", SF_FORMAT_W64
| SF_FORMAT_IMA_ADPCM
, 2, 0.18) ;
471 sdlcomp_test_short ("ima.w64", SF_FORMAT_W64
| SF_FORMAT_IMA_ADPCM
, 2, 0.18) ;
472 sdlcomp_test_int ("ima.w64", SF_FORMAT_W64
| SF_FORMAT_IMA_ADPCM
, 2, 0.18) ;
473 sdlcomp_test_float ("ima.w64", SF_FORMAT_W64
| SF_FORMAT_IMA_ADPCM
, 2, 0.18) ;
474 sdlcomp_test_double ("ima.w64", SF_FORMAT_W64
| SF_FORMAT_IMA_ADPCM
, 2, 0.18) ;
478 if (do_all
|| strcmp (argv
[1], "w64_msadpcm") == 0)
479 { lcomp_test_short ("msadpcm.w64", SF_FORMAT_W64
| SF_FORMAT_MS_ADPCM
, 2, 0.36) ;
480 lcomp_test_int ("msadpcm.w64", SF_FORMAT_W64
| SF_FORMAT_MS_ADPCM
, 2, 0.36) ;
481 lcomp_test_float ("msadpcm.w64", SF_FORMAT_W64
| SF_FORMAT_MS_ADPCM
, 2, 0.36) ;
482 lcomp_test_double ("msadpcm.w64", SF_FORMAT_W64
| SF_FORMAT_MS_ADPCM
, 2, 0.36) ;
484 sdlcomp_test_short ("msadpcm.w64", SF_FORMAT_W64
| SF_FORMAT_MS_ADPCM
, 2, 0.36) ;
485 sdlcomp_test_int ("msadpcm.w64", SF_FORMAT_W64
| SF_FORMAT_MS_ADPCM
, 2, 0.36) ;
486 sdlcomp_test_float ("msadpcm.w64", SF_FORMAT_W64
| SF_FORMAT_MS_ADPCM
, 2, 0.36) ;
487 sdlcomp_test_double ("msadpcm.w64", SF_FORMAT_W64
| SF_FORMAT_MS_ADPCM
, 2, 0.36) ;
491 if (do_all
|| strcmp (argv
[1], "wve") == 0)
492 { lcomp_test_short ("psion.wve", SF_FORMAT_WVE
| SF_FORMAT_ALAW
, 1, 0.04) ;
493 lcomp_test_int ("psion.wve", SF_FORMAT_WVE
| SF_FORMAT_ALAW
, 1, 0.04) ;
494 /* Lite remove start */
495 lcomp_test_float ("psion.wve", SF_FORMAT_WVE
| SF_FORMAT_ALAW
, 1, 0.04) ;
496 lcomp_test_double ("psion.wve", SF_FORMAT_WVE
| SF_FORMAT_ALAW
, 1, 0.04) ;
497 /* Lite remove end */
501 /* Lite remove end */
503 if (do_all
|| strcmp (argv
[1], "w64_gsm610") == 0)
504 { /* Don't do lcomp_test_XXX as the errors are too big. */
505 sdlcomp_test_short ("gsm610.w64", SF_FORMAT_W64
| SF_FORMAT_GSM610
, 1, 0.2) ;
506 sdlcomp_test_int ("gsm610.w64", SF_FORMAT_W64
| SF_FORMAT_GSM610
, 1, 0.2) ;
507 /* Lite remove start */
508 sdlcomp_test_float ("gsm610.w64", SF_FORMAT_W64
| SF_FORMAT_GSM610
, 1, 0.2) ;
509 sdlcomp_test_double ("gsm610.w64", SF_FORMAT_W64
| SF_FORMAT_GSM610
, 1, 0.2) ;
510 /* Lite remove end */
514 /* Lite remove start */
515 if (do_all
|| strcmp (argv
[1], "vox_adpcm") == 0)
516 { lcomp_test_short ("adpcm.vox", SF_FORMAT_RAW
| SF_FORMAT_VOX_ADPCM
, 1, 0.17) ;
517 lcomp_test_int ("adpcm.vox", SF_FORMAT_RAW
| SF_FORMAT_VOX_ADPCM
, 1, 0.17) ;
518 lcomp_test_float ("adpcm.vox", SF_FORMAT_RAW
| SF_FORMAT_VOX_ADPCM
, 1, 0.17) ;
519 lcomp_test_double ("adpcm.vox", SF_FORMAT_RAW
| SF_FORMAT_VOX_ADPCM
, 1, 0.17) ;
521 sdlcomp_test_short ("adpcm.vox", SF_FORMAT_RAW
| SF_FORMAT_VOX_ADPCM
, 1, 0.072) ;
522 sdlcomp_test_int ("adpcm.vox", SF_FORMAT_RAW
| SF_FORMAT_VOX_ADPCM
, 1, 0.072) ;
523 sdlcomp_test_float ("adpcm.vox", SF_FORMAT_RAW
| SF_FORMAT_VOX_ADPCM
, 1, 0.072) ;
524 sdlcomp_test_double ("adpcm.vox", SF_FORMAT_RAW
| SF_FORMAT_VOX_ADPCM
, 1, 0.072) ;
528 if (do_all
|| strcmp (argv
[1], "xi_dpcm") == 0)
529 { lcomp_test_short ("8bit.xi", SF_FORMAT_XI
| SF_FORMAT_DPCM_8
, 1, 0.25) ;
530 lcomp_test_int ("8bit.xi", SF_FORMAT_XI
| SF_FORMAT_DPCM_8
, 1, 0.25) ;
532 lcomp_test_short ("16bit.xi", SF_FORMAT_XI
| SF_FORMAT_DPCM_16
, 1, 0.002) ;
533 lcomp_test_int ("16bit.xi", SF_FORMAT_XI
| SF_FORMAT_DPCM_16
, 1, 0.002) ;
534 lcomp_test_float ("16bit.xi", SF_FORMAT_XI
| SF_FORMAT_DPCM_16
, 1, 0.002) ;
535 lcomp_test_double ("16bit.xi", SF_FORMAT_XI
| SF_FORMAT_DPCM_16
, 1, 0.002) ;
538 /* Lite remove end */
541 { printf ("************************************\n") ;
542 printf ("* No '%s' test defined.\n", argv
[1]) ;
543 printf ("************************************\n") ;
550 /*============================================================================================
551 ** Here are the test functions.
555 lcomp_test_short (const char *filename
, int filetype
, int channels
, double margin
)
558 int k
, m
, seekpos
, half_max_abs
;
562 print_test_name ("lcomp_test_short", filename
) ;
564 datalen
= BUFFER_SIZE
/ channels
;
566 data
= data_buffer
.s
;
567 orig
= orig_buffer
.s
;
569 gen_signal_double (orig_buffer
.d
, 32000.0, channels
, datalen
) ;
570 for (k
= 0 ; k
< channels
* datalen
; k
++)
571 orig
[k
] = (short) (orig_buffer
.d
[k
]) ;
573 sfinfo
.samplerate
= SAMPLE_RATE
;
574 sfinfo
.frames
= 123456789 ; /* Ridiculous value. */
575 sfinfo
.channels
= channels
;
576 sfinfo
.format
= filetype
;
578 file
= test_open_file_or_die (filename
, SFM_WRITE
, &sfinfo
, SF_FALSE
, __LINE__
) ;
579 test_writef_short_or_die (file
, 0, orig
, datalen
, __LINE__
) ;
580 sf_set_string (file
, SF_STR_COMMENT
, long_comment
) ;
583 memset (data
, 0, datalen
* sizeof (short)) ;
585 if ((filetype
& SF_FORMAT_TYPEMASK
) != SF_FORMAT_RAW
)
586 memset (&sfinfo
, 0, sizeof (sfinfo
)) ;
588 file
= test_open_file_or_die (filename
, SFM_READ
, &sfinfo
, SF_FALSE
, __LINE__
) ;
590 if ((sfinfo
.format
& (SF_FORMAT_TYPEMASK
| SF_FORMAT_SUBMASK
)) != (filetype
& (SF_FORMAT_TYPEMASK
| SF_FORMAT_SUBMASK
)))
591 { printf ("\n\nLine %d: Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__
, filetype
, sfinfo
.format
) ;
595 if (sfinfo
.frames
< datalen
/ channels
)
596 { printf ("Too few frames in file. (%ld should be a little more than %ld)\n", SF_COUNT_TO_LONG (sfinfo
.frames
), datalen
) ;
600 if (sfinfo
.frames
> (datalen
+ datalen
/ 20))
601 { printf ("Too many frames in file. (%ld should be a little more than %ld)\n", SF_COUNT_TO_LONG (sfinfo
.frames
), datalen
) ;
605 if (sfinfo
.channels
!= channels
)
606 { printf ("Incorrect number of channels in file.\n") ;
610 check_log_buffer_or_die (file
, __LINE__
) ;
612 check_comment (file
, filetype
, __LINE__
) ;
614 test_readf_short_or_die (file
, 0, data
, datalen
, __LINE__
) ;
617 for (k
= 0 ; k
< datalen
; k
++)
618 { if (error_function (data
[k
], orig
[k
], margin
))
619 { printf ("\n\nLine %d: Incorrect sample A (#%d : %d should be %d).\n", __LINE__
, k
, data
[k
], orig
[k
]) ;
620 oct_save_short (orig
, data
, datalen
) ;
623 half_max_abs
= LCT_MAX (half_max_abs
, abs (data
[k
] / 2)) ;
626 if (half_max_abs
< 1.0)
627 { printf ("\n\nLine %d: Signal is all zeros.\n", __LINE__
) ;
631 if ((k
= sf_readf_short (file
, data
, datalen
)) != sfinfo
.frames
- datalen
)
632 { printf ("\n\nLine %d: Incorrect read length (%ld should be %d).\n", __LINE__
,
633 SF_COUNT_TO_LONG (channels
* sfinfo
.frames
- datalen
), k
) ;
637 /* This check is only for block based encoders which must append silence
638 ** to the end of a file so as to fill out a block.
640 for (k
= 0 ; k
< sfinfo
.frames
- datalen
; k
++)
641 if (abs (data
[channels
* k
]) > decay_response (channels
* k
))
642 { printf ("\n\nLine %d : Incorrect sample B (#%d : abs (%d) should be < %d).\n", __LINE__
, channels
* k
, data
[channels
* k
], decay_response (channels
* k
)) ;
646 if (! sfinfo
.seekable
)
653 /* Now test sf_seek function. */
655 if ((k
= sf_seek (file
, 0, SEEK_SET
)) != 0)
656 { printf ("\n\nLine %d: Seek to start of file failed (%d).\n", __LINE__
, k
) ;
660 for (m
= 0 ; m
< 3 ; m
++)
661 { test_readf_short_or_die (file
, m
, data
, 11, __LINE__
) ;
663 for (k
= 0 ; k
< channels
* 11 ; k
++)
664 if (error_function (1.0 * data
[k
], 1.0 * orig
[k
+ channels
* m
* 11], margin
))
665 { 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
]) ;
666 for (m
= 0 ; m
< channels
; m
++)
667 printf ("%d ", data
[m
]) ;
673 seekpos
= BUFFER_SIZE
/ 10 ;
675 /* Check seek from start of file. */
676 if ((k
= sf_seek (file
, seekpos
, SEEK_SET
)) != seekpos
)
677 { printf ("Seek to start of file + %d failed (%d).\n", seekpos
, k
) ;
681 test_readf_short_or_die (file
, 0, data
, 1, __LINE__
) ;
683 if (error_function (1.0 * data
[0], 1.0 * orig
[seekpos
* channels
], margin
))
684 { printf ("\n\nLine %d: sf_seek (SEEK_SET) followed by sf_readf_short failed (%d, %d).\n", __LINE__
, orig
[1], data
[0]) ;
688 if ((k
= sf_seek (file
, 0, SEEK_CUR
)) != seekpos
+ 1)
689 { printf ("\n\nLine %d: sf_seek (SEEK_CUR) with 0 offset failed (%d should be %d)\n", __LINE__
, k
, seekpos
+ 1) ;
693 seekpos
= sf_seek (file
, 0, SEEK_CUR
) + BUFFER_SIZE
/ 5 ;
694 k
= sf_seek (file
, BUFFER_SIZE
/ 5, SEEK_CUR
) ;
695 test_readf_short_or_die (file
, 0, data
, 1, __LINE__
) ;
696 if (error_function (1.0 * data
[0], 1.0 * orig
[seekpos
* channels
], margin
) || k
!= seekpos
)
697 { 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) ;
698 oct_save_short (orig
, data
, datalen
) ;
702 seekpos
= sf_seek (file
, 0, SEEK_CUR
) - 20 ;
703 /* Check seek backward from current position. */
704 k
= sf_seek (file
, -20, SEEK_CUR
) ;
705 test_readf_short_or_die (file
, 0, data
, 1, __LINE__
) ;
706 if (error_function (1.0 * data
[0], 1.0 * orig
[seekpos
* channels
], margin
) || k
!= seekpos
)
707 { printf ("\nLine %d: sf_seek (backwards, SEEK_CUR) followed by sf_readf_short failed (%d, %d) (%d, %d).\n", __LINE__
, data
[0], orig
[seekpos
* channels
], k
, seekpos
) ;
711 /* Check that read past end of file returns number of items. */
712 sf_seek (file
, sfinfo
.frames
, SEEK_SET
) ;
714 if ((k
= sf_readf_short (file
, data
, datalen
)) != 0)
715 { printf ("\n\nLine %d: Return value from sf_readf_short past end of file incorrect (%d).\n", __LINE__
, k
) ;
719 /* Check seek backward from end. */
720 if ((k
= sf_seek (file
, 5 - sfinfo
.frames
, SEEK_END
)) != 5)
721 { printf ("\n\nLine %d: sf_seek (SEEK_END) returned %d instead of %d.\n", __LINE__
, k
, 5) ;
725 test_readf_short_or_die (file
, 0, data
, 1, __LINE__
) ;
726 if (error_function (1.0 * data
[0], 1.0 * orig
[5 * channels
], margin
))
727 { printf ("\nLine %d: sf_seek (SEEK_END) followed by sf_readf_short failed (%d should be %d).\n", __LINE__
, data
[0], orig
[5 * channels
]) ;
735 } /* lcomp_test_short */
737 /*--------------------------------------------------------------------------------------------
741 lcomp_test_int (const char *filename
, int filetype
, int channels
, double margin
)
744 int k
, m
, half_max_abs
;
745 long datalen
, seekpos
;
746 double scale
, max_val
;
749 print_test_name ("lcomp_test_int", filename
) ;
751 datalen
= BUFFER_SIZE
/ channels
;
753 if (is_lossy (filetype
))
754 { scale
= 1.0 * 0x10000 ;
755 max_val
= 32000.0 * scale
;
759 max_val
= 0x7fffffff * scale
;
762 data
= data_buffer
.i
;
763 orig
= orig_buffer
.i
;
765 gen_signal_double (orig_buffer
.d
, max_val
, channels
, datalen
) ;
767 for (k
= 0 ; k
< channels
* datalen
; k
++)
768 orig
[k
] = lrint (orig_buffer
.d
[k
]) ;
770 sfinfo
.samplerate
= SAMPLE_RATE
;
771 sfinfo
.frames
= 123456789 ; /* Ridiculous value. */
772 sfinfo
.channels
= channels
;
773 sfinfo
.format
= filetype
;
775 file
= test_open_file_or_die (filename
, SFM_WRITE
, &sfinfo
, SF_FALSE
, __LINE__
) ;
776 test_writef_int_or_die (file
, 0, orig
, datalen
, __LINE__
) ;
777 sf_set_string (file
, SF_STR_COMMENT
, long_comment
) ;
780 memset (data
, 0, datalen
* sizeof (int)) ;
782 if ((filetype
& SF_FORMAT_TYPEMASK
) != SF_FORMAT_RAW
)
783 memset (&sfinfo
, 0, sizeof (sfinfo
)) ;
785 file
= test_open_file_or_die (filename
, SFM_READ
, &sfinfo
, SF_FALSE
, __LINE__
) ;
787 if ((sfinfo
.format
& (SF_FORMAT_TYPEMASK
| SF_FORMAT_SUBMASK
)) != (filetype
& (SF_FORMAT_TYPEMASK
| SF_FORMAT_SUBMASK
)))
788 { printf ("\n\nLine %d: Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__
, filetype
, sfinfo
.format
) ;
792 if (sfinfo
.frames
< datalen
/ channels
)
793 { printf ("Too few.frames in file. (%ld should be a little more than %ld)\n", datalen
, SF_COUNT_TO_LONG (sfinfo
.frames
)) ;
797 if (sfinfo
.frames
> (datalen
+ datalen
/ 20))
798 { printf ("Too many.frames in file. (%ld should be a little more than %ld)\n", datalen
, SF_COUNT_TO_LONG (sfinfo
.frames
)) ;
802 if (sfinfo
.channels
!= channels
)
803 { printf ("Incorrect number of channels in file.\n") ;
807 check_log_buffer_or_die (file
, __LINE__
) ;
809 check_comment (file
, filetype
, __LINE__
) ;
811 test_readf_int_or_die (file
, 0, data
, datalen
, __LINE__
) ;
814 for (k
= 0 ; k
< datalen
; k
++)
815 { if (error_function (data
[k
] / scale
, orig
[k
] / scale
, margin
))
816 { printf ("\nLine %d: Incorrect sample (#%d : %f should be %f).\n", __LINE__
, k
, data
[k
] / scale
, orig
[k
] / scale
) ;
817 oct_save_int (orig
, data
, datalen
) ;
820 half_max_abs
= LCT_MAX (half_max_abs
, abs (data
[k
] / 2)) ;
823 if (half_max_abs
< 1.0)
824 { printf ("\n\nLine %d: Signal is all zeros (%d, 0x%X).\n", __LINE__
, half_max_abs
, half_max_abs
) ;
828 if ((k
= sf_readf_int (file
, data
, datalen
)) != sfinfo
.frames
- datalen
)
829 { printf ("\n\nLine %d: Incorrect read length (%ld should be %d).\n", __LINE__
,
830 SF_COUNT_TO_LONG (channels
* sfinfo
.frames
- datalen
), k
) ;
834 /* This check is only for block based encoders which must append silence
835 ** to the end of a file so as to fill out a block.
837 if ((sfinfo
.format
& SF_FORMAT_SUBMASK
) != SF_FORMAT_MS_ADPCM
)
838 for (k
= 0 ; k
< sfinfo
.frames
- datalen
; k
++)
839 if (abs (data
[channels
* k
] / scale
) > decay_response (channels
* k
))
840 { printf ("\n\nLine %d : Incorrect sample B (#%d : abs (%d) should be < %d).\n", __LINE__
, channels
* k
, data
[channels
* k
], decay_response (channels
* k
)) ;
844 if (! sfinfo
.seekable
)
851 /* Now test sf_seek function. */
853 if ((k
= sf_seek (file
, 0, SEEK_SET
)) != 0)
854 { printf ("\n\nLine %d: Seek to start of file failed (%d).\n", __LINE__
, k
) ;
858 for (m
= 0 ; m
< 3 ; m
++)
859 { test_readf_int_or_die (file
, m
, data
, 11, __LINE__
) ;
861 for (k
= 0 ; k
< channels
* 11 ; k
++)
862 if (error_function (data
[k
] / scale
, orig
[k
+ channels
* m
* 11] / scale
, margin
))
863 { printf ("\nLine %d: Incorrect sample (m = %d) (#%d : %d => %d).\n", __LINE__
, m
, k
+ channels
* m
* 11, orig
[k
+ channels
* m
* 11], data
[k
]) ;
864 for (m
= 0 ; m
< channels
; m
++)
865 printf ("%d ", data
[m
]) ;
871 seekpos
= BUFFER_SIZE
/ 10 ;
873 /* Check seek from start of file. */
874 if ((k
= sf_seek (file
, seekpos
, SEEK_SET
)) != seekpos
)
875 { printf ("Seek to start of file + %ld failed (%d).\n", seekpos
, k
) ;
879 test_readf_int_or_die (file
, 0, data
, 1, __LINE__
) ;
881 if (error_function (1.0 * data
[0], 1.0 * orig
[seekpos
* channels
], margin
))
882 { printf ("\nLine %d: sf_seek (SEEK_SET) followed by sf_readf_int failed (%d, %d).\n", __LINE__
, orig
[1], data
[0]) ;
886 if ((k
= sf_seek (file
, 0, SEEK_CUR
)) != seekpos
+ 1)
887 { printf ("\n\nLine %d: sf_seek (SEEK_CUR) with 0 offset failed (%d should be %ld)\n", __LINE__
, k
, seekpos
+ 1) ;
891 seekpos
= sf_seek (file
, 0, SEEK_CUR
) + BUFFER_SIZE
/ 5 ;
892 k
= sf_seek (file
, BUFFER_SIZE
/ 5, SEEK_CUR
) ;
893 test_readf_int_or_die (file
, 0, data
, 1, __LINE__
) ;
894 if (error_function (1.0 * data
[0], 1.0 * orig
[seekpos
* channels
], margin
) || k
!= seekpos
)
895 { printf ("\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) ;
899 seekpos
= sf_seek (file
, 0, SEEK_CUR
) - 20 ;
900 /* Check seek backward from current position. */
901 k
= sf_seek (file
, -20, SEEK_CUR
) ;
902 test_readf_int_or_die (file
, 0, data
, 1, __LINE__
) ;
903 if (error_function (1.0 * data
[0], 1.0 * orig
[seekpos
* channels
], margin
) || k
!= seekpos
)
904 { printf ("\nLine %d: sf_seek (backwards, SEEK_CUR) followed by sf_readf_int failed (%d, %d) (%d, %ld).\n", __LINE__
, data
[0], orig
[seekpos
* channels
], k
, seekpos
) ;
908 /* Check that read past end of file returns number of items. */
909 sf_seek (file
, sfinfo
.frames
, SEEK_SET
) ;
911 if ((k
= sf_readf_int (file
, data
, datalen
)) != 0)
912 { printf ("\n\nLine %d: Return value from sf_readf_int past end of file incorrect (%d).\n", __LINE__
, k
) ;
916 /* Check seek backward from end. */
917 if ((k
= sf_seek (file
, 5 - sfinfo
.frames
, SEEK_END
)) != 5)
918 { printf ("\n\nLine %d: sf_seek (SEEK_END) returned %d instead of %d.\n", __LINE__
, k
, 5) ;
922 test_readf_int_or_die (file
, 0, data
, 1, __LINE__
) ;
923 if (error_function (data
[0] / scale
, orig
[5 * channels
] / scale
, margin
))
924 { printf ("\nLine %d: sf_seek (SEEK_END) followed by sf_readf_short failed (%d should be %d).\n", __LINE__
, data
[0], orig
[5]) ;
932 } /* lcomp_test_int */
934 /*--------------------------------------------------------------------------------------------
938 lcomp_test_float (const char *filename
, int filetype
, int channels
, double margin
)
944 double half_max_abs
;
946 print_test_name ("lcomp_test_float", filename
) ;
948 datalen
= BUFFER_SIZE
/ channels
;
950 data
= data_buffer
.f
;
951 orig
= orig_buffer
.f
;
953 gen_signal_double (orig_buffer
.d
, 32000.0, channels
, datalen
) ;
954 for (k
= 0 ; k
< channels
* datalen
; k
++)
955 orig
[k
] = orig_buffer
.d
[k
] ;
957 sfinfo
.samplerate
= SAMPLE_RATE
;
958 sfinfo
.frames
= 123456789 ; /* Ridiculous value. */
959 sfinfo
.channels
= channels
;
960 sfinfo
.format
= filetype
;
962 file
= test_open_file_or_die (filename
, SFM_WRITE
, &sfinfo
, SF_FALSE
, __LINE__
) ;
963 sf_command (file
, SFC_SET_NORM_FLOAT
, NULL
, SF_FALSE
) ;
964 test_writef_float_or_die (file
, 0, orig
, datalen
, __LINE__
) ;
965 sf_set_string (file
, SF_STR_COMMENT
, long_comment
) ;
968 memset (data
, 0, datalen
* sizeof (float)) ;
970 if ((filetype
& SF_FORMAT_TYPEMASK
) != SF_FORMAT_RAW
)
971 memset (&sfinfo
, 0, sizeof (sfinfo
)) ;
973 file
= test_open_file_or_die (filename
, SFM_READ
, &sfinfo
, SF_FALSE
, __LINE__
) ;
975 if ((sfinfo
.format
& (SF_FORMAT_TYPEMASK
| SF_FORMAT_SUBMASK
)) != (filetype
& (SF_FORMAT_TYPEMASK
| SF_FORMAT_SUBMASK
)))
976 { printf ("\n\nLine %d: Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__
, filetype
, sfinfo
.format
) ;
980 if (sfinfo
.frames
< datalen
/ channels
)
981 { printf ("Too few.frames in file. (%ld should be a little more than %ld)\n", datalen
, SF_COUNT_TO_LONG (sfinfo
.frames
)) ;
985 if (sfinfo
.frames
> (datalen
+ datalen
/ 20))
986 { printf ("Too many.frames in file. (%ld should be a little more than %ld)\n", datalen
, SF_COUNT_TO_LONG (sfinfo
.frames
)) ;
990 if (sfinfo
.channels
!= channels
)
991 { printf ("Incorrect number of channels in file.\n") ;
995 check_comment (file
, filetype
, __LINE__
) ;
997 sf_command (file
, SFC_SET_NORM_FLOAT
, NULL
, SF_FALSE
) ;
999 check_log_buffer_or_die (file
, __LINE__
) ;
1001 check_comment (file
, filetype
, __LINE__
) ;
1003 sf_command (file
, SFC_SET_NORM_FLOAT
, NULL
, SF_FALSE
) ;
1005 test_readf_float_or_die (file
, 0, data
, datalen
, __LINE__
) ;
1007 half_max_abs
= 0.0 ;
1008 for (k
= 0 ; k
< datalen
; k
++)
1009 { if (error_function (data
[k
], orig
[k
], margin
))
1010 { printf ("\nLine %d: Incorrect sample A (#%d : %f should be %f).\n", __LINE__
, k
, data
[k
], orig
[k
]) ;
1011 oct_save_float (orig
, data
, datalen
) ;
1014 half_max_abs
= LCT_MAX (half_max_abs
, fabs (0.5 * data
[k
])) ;
1017 if (half_max_abs
< 1.0)
1018 { printf ("\n\nLine %d: Signal is all zeros.\n", __LINE__
) ;
1022 if ((k
= sf_readf_float (file
, data
, datalen
)) != sfinfo
.frames
- datalen
)
1023 { printf ("\n\nLine %d: Incorrect read length (%ld should be %d).\n", __LINE__
,
1024 SF_COUNT_TO_LONG (channels
* sfinfo
.frames
- datalen
), k
) ;
1028 /* This check is only for block based encoders which must append silence
1029 ** to the end of a file so as to fill out a block.
1031 if ((sfinfo
.format
& SF_FORMAT_SUBMASK
) != SF_FORMAT_MS_ADPCM
)
1032 for (k
= 0 ; k
< sfinfo
.frames
- datalen
; k
++)
1033 if (abs (data
[channels
* k
]) > decay_response (channels
* k
))
1034 { printf ("\n\nLine %d : Incorrect sample B (#%d : abs (%f) should be < %d).\n", __LINE__
, channels
* k
, data
[channels
* k
], decay_response (channels
* k
)) ;
1038 if (! sfinfo
.seekable
)
1045 /* Now test sf_seek function. */
1047 if ((k
= sf_seek (file
, 0, SEEK_SET
)) != 0)
1048 { printf ("\n\nLine %d: Seek to start of file failed (%d).\n", __LINE__
, k
) ;
1052 for (m
= 0 ; m
< 3 ; m
++)
1053 { test_readf_float_or_die (file
, 0, data
, 11, __LINE__
) ;
1055 for (k
= 0 ; k
< channels
* 11 ; k
++)
1056 if (error_function (data
[k
], orig
[k
+ channels
* m
* 11], margin
))
1057 { printf ("\nLine %d: Incorrect sample (m = %d) (#%d : %f => %f).\n", __LINE__
, m
, k
+ channels
* m
* 11, orig
[k
+ channels
* m
* 11], data
[k
]) ;
1058 for (m
= 0 ; m
< channels
; m
++)
1059 printf ("%f ", data
[m
]) ;
1065 seekpos
= BUFFER_SIZE
/ 10 ;
1067 /* Check seek from start of file. */
1068 if ((k
= sf_seek (file
, seekpos
, SEEK_SET
)) != seekpos
)
1069 { printf ("Seek to start of file + %d failed (%d).\n", seekpos
, k
) ;
1073 test_readf_float_or_die (file
, 0, data
, 1, __LINE__
) ;
1075 if (error_function (data
[0], orig
[seekpos
* channels
], margin
))
1076 { printf ("\nLine %d: sf_seek (SEEK_SET) followed by sf_readf_float failed (%f, %f).\n", __LINE__
, orig
[1], data
[0]) ;
1080 if ((k
= sf_seek (file
, 0, SEEK_CUR
)) != seekpos
+ 1)
1081 { printf ("\n\nLine %d: sf_seek (SEEK_CUR) with 0 offset failed (%d should be %d)\n", __LINE__
, k
, seekpos
+ 1) ;
1085 seekpos
= sf_seek (file
, 0, SEEK_CUR
) + BUFFER_SIZE
/ 5 ;
1086 k
= sf_seek (file
, BUFFER_SIZE
/ 5, SEEK_CUR
) ;
1087 test_readf_float_or_die (file
, 0, data
, 1, __LINE__
) ;
1088 if (error_function (data
[0], orig
[seekpos
* channels
], margin
) || k
!= seekpos
)
1089 { printf ("\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) ;
1093 seekpos
= sf_seek (file
, 0, SEEK_CUR
) - 20 ;
1094 /* Check seek backward from current position. */
1095 k
= sf_seek (file
, -20, SEEK_CUR
) ;
1096 test_readf_float_or_die (file
, 0, data
, 1, __LINE__
) ;
1097 if (error_function (data
[0], orig
[seekpos
* channels
], margin
) || k
!= seekpos
)
1098 { printf ("\nLine %d: sf_seek (backwards, SEEK_CUR) followed by sf_readf_float failed (%f, %f) (%d, %d).\n", __LINE__
, data
[0], orig
[seekpos
* channels
], k
, seekpos
) ;
1102 /* Check that read past end of file returns number of items. */
1103 sf_seek (file
, sfinfo
.frames
, SEEK_SET
) ;
1105 if ((k
= sf_readf_float (file
, data
, datalen
)) != 0)
1106 { printf ("\n\nLine %d: Return value from sf_readf_float past end of file incorrect (%d).\n", __LINE__
, k
) ;
1110 /* Check seek backward from end. */
1111 if ((k
= sf_seek (file
, 5 - sfinfo
.frames
, SEEK_END
)) != 5)
1112 { printf ("\n\nLine %d: sf_seek (SEEK_END) returned %d instead of %d.\n", __LINE__
, k
, 5) ;
1116 test_readf_float_or_die (file
, 0, data
, 1, __LINE__
) ;
1117 if (error_function (data
[0], orig
[5 * channels
], margin
))
1118 { printf ("\nLine %d: sf_seek (SEEK_END) followed by sf_readf_short failed (%f should be %f).\n", __LINE__
, data
[0], orig
[5 * channels
]) ;
1126 } /* lcomp_test_float */
1128 /*--------------------------------------------------------------------------------------------
1132 lcomp_test_double (const char *filename
, int filetype
, int channels
, double margin
)
1137 double *orig
, *data
;
1138 double half_max_abs
;
1140 print_test_name ("lcomp_test_double", filename
) ;
1142 datalen
= BUFFER_SIZE
/ channels
;
1144 data
= data_buffer
.d
;
1145 orig
= orig_buffer
.d
;
1147 gen_signal_double (orig_buffer
.d
, 32000.0, channels
, datalen
) ;
1148 for (k
= 0 ; k
< channels
* datalen
; k
++)
1149 orig
[k
] = orig_buffer
.d
[k
] ;
1151 sfinfo
.samplerate
= SAMPLE_RATE
;
1152 sfinfo
.frames
= 123456789 ; /* Ridiculous value. */
1153 sfinfo
.channels
= channels
;
1154 sfinfo
.format
= filetype
;
1156 file
= test_open_file_or_die (filename
, SFM_WRITE
, &sfinfo
, SF_FALSE
, __LINE__
) ;
1157 sf_command (file
, SFC_SET_NORM_DOUBLE
, NULL
, SF_FALSE
) ;
1158 test_writef_double_or_die (file
, 0, orig
, datalen
, __LINE__
) ;
1159 sf_set_string (file
, SF_STR_COMMENT
, long_comment
) ;
1162 memset (data
, 0, datalen
* sizeof (double)) ;
1164 if ((filetype
& SF_FORMAT_TYPEMASK
) != SF_FORMAT_RAW
)
1165 memset (&sfinfo
, 0, sizeof (sfinfo
)) ;
1167 file
= test_open_file_or_die (filename
, SFM_READ
, &sfinfo
, SF_FALSE
, __LINE__
) ;
1169 if ((sfinfo
.format
& (SF_FORMAT_TYPEMASK
| SF_FORMAT_SUBMASK
)) != (filetype
& (SF_FORMAT_TYPEMASK
| SF_FORMAT_SUBMASK
)))
1170 { printf ("\n\nLine %d: Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__
, filetype
, sfinfo
.format
) ;
1174 if (sfinfo
.frames
< datalen
/ channels
)
1175 { printf ("Too few.frames in file. (%ld should be a little more than %ld)\n", datalen
, SF_COUNT_TO_LONG (sfinfo
.frames
)) ;
1179 if (sfinfo
.frames
> (datalen
+ datalen
/ 20))
1180 { printf ("Too many.frames in file. (%ld should be a little more than %ld)\n", datalen
, SF_COUNT_TO_LONG (sfinfo
.frames
)) ;
1184 if (sfinfo
.channels
!= channels
)
1185 { printf ("Incorrect number of channels in file.\n") ;
1189 check_comment (file
, filetype
, __LINE__
) ;
1191 sf_command (file
, SFC_SET_NORM_DOUBLE
, NULL
, SF_FALSE
) ;
1193 check_log_buffer_or_die (file
, __LINE__
) ;
1195 check_comment (file
, filetype
, __LINE__
) ;
1197 sf_command (file
, SFC_SET_NORM_DOUBLE
, NULL
, SF_FALSE
) ;
1199 test_readf_double_or_die (file
, 0, data
, datalen
, __LINE__
) ;
1201 half_max_abs
= 0.0 ;
1202 for (k
= 0 ; k
< datalen
; k
++)
1203 { if (error_function (data
[k
], orig
[k
], margin
))
1204 { printf ("\nLine %d: Incorrect sample A (#%d : %f should be %f).\n", __LINE__
, k
, data
[k
], orig
[k
]) ;
1205 oct_save_double (orig
, data
, datalen
) ;
1208 half_max_abs
= LCT_MAX (half_max_abs
, abs (0.5 * data
[k
])) ;
1211 if (half_max_abs
< 1.0)
1212 { printf ("\n\nLine %d: Signal is all zeros.\n", __LINE__
) ;
1216 if ((k
= sf_readf_double (file
, data
, datalen
)) != sfinfo
.frames
- datalen
)
1217 { printf ("\n\nLine %d: Incorrect read length (%ld should be %d).\n", __LINE__
,
1218 SF_COUNT_TO_LONG (channels
* sfinfo
.frames
- datalen
), k
) ;
1222 /* This check is only for block based encoders which must append silence
1223 ** to the end of a file so as to fill out a block.
1225 if ((sfinfo
.format
& SF_FORMAT_SUBMASK
) != SF_FORMAT_MS_ADPCM
)
1226 for (k
= 0 ; k
< sfinfo
.frames
- datalen
; k
++)
1227 if (abs (data
[channels
* k
]) > decay_response (channels
* k
))
1228 { printf ("\n\nLine %d : Incorrect sample B (#%d : abs (%f) should be < %d).\n", __LINE__
, channels
* k
, data
[channels
* k
], decay_response (channels
* k
)) ;
1232 if (! sfinfo
.seekable
)
1239 /* Now test sf_seek function. */
1241 if ((k
= sf_seek (file
, 0, SEEK_SET
)) != 0)
1242 { printf ("\n\nLine %d: Seek to start of file failed (%d).\n", __LINE__
, k
) ;
1246 for (m
= 0 ; m
< 3 ; m
++)
1247 { test_readf_double_or_die (file
, m
, data
, 11, __LINE__
) ;
1249 for (k
= 0 ; k
< channels
* 11 ; k
++)
1250 if (error_function (data
[k
], orig
[k
+ channels
* m
* 11], margin
))
1251 { printf ("\nLine %d: Incorrect sample (m = %d) (#%d : %f => %f).\n", __LINE__
, m
, k
+ channels
* m
* 11, orig
[k
+ channels
* m
* 11], data
[k
]) ;
1252 for (m
= 0 ; m
< channels
; m
++)
1253 printf ("%f ", data
[m
]) ;
1259 seekpos
= BUFFER_SIZE
/ 10 ;
1261 /* Check seek from start of file. */
1262 if ((k
= sf_seek (file
, seekpos
, SEEK_SET
)) != seekpos
)
1263 { printf ("Seek to start of file + %d failed (%d).\n", seekpos
, k
) ;
1267 test_readf_double_or_die (file
, 0, data
, 1, __LINE__
) ;
1269 if (error_function (data
[0], orig
[seekpos
* channels
], margin
))
1270 { printf ("\nLine %d: sf_seek (SEEK_SET) followed by sf_readf_double failed (%f, %f).\n", __LINE__
, orig
[1], data
[0]) ;
1274 if ((k
= sf_seek (file
, 0, SEEK_CUR
)) != seekpos
+ 1)
1275 { printf ("\n\nLine %d: sf_seek (SEEK_CUR) with 0 offset failed (%d should be %d)\n", __LINE__
, k
, seekpos
+ 1) ;
1279 seekpos
= sf_seek (file
, 0, SEEK_CUR
) + BUFFER_SIZE
/ 5 ;
1280 k
= sf_seek (file
, BUFFER_SIZE
/ 5, SEEK_CUR
) ;
1281 test_readf_double_or_die (file
, 0, data
, 1, __LINE__
) ;
1282 if (error_function (data
[0], orig
[seekpos
* channels
], margin
) || k
!= seekpos
)
1283 { printf ("\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) ;
1287 seekpos
= sf_seek (file
, 0, SEEK_CUR
) - 20 ;
1288 /* Check seek backward from current position. */
1289 k
= sf_seek (file
, -20, SEEK_CUR
) ;
1290 test_readf_double_or_die (file
, 0, data
, 1, __LINE__
) ;
1291 if (error_function (data
[0], orig
[seekpos
* channels
], margin
) || k
!= seekpos
)
1292 { printf ("\nLine %d: sf_seek (backwards, SEEK_CUR) followed by sf_readf_double failed (%f, %f) (%d, %d).\n", __LINE__
, data
[0], orig
[seekpos
* channels
], k
, seekpos
) ;
1296 /* Check that read past end of file returns number of items. */
1297 sf_seek (file
, sfinfo
.frames
, SEEK_SET
) ;
1299 if ((k
= sf_readf_double (file
, data
, datalen
)) != 0)
1300 { printf ("\n\nLine %d: Return value from sf_readf_double past end of file incorrect (%d).\n", __LINE__
, k
) ;
1304 /* Check seek backward from end. */
1305 if ((k
= sf_seek (file
, 5 - sfinfo
.frames
, SEEK_END
)) != 5)
1306 { printf ("\n\nLine %d: sf_seek (SEEK_END) returned %d instead of %d.\n", __LINE__
, k
, 5) ;
1310 test_readf_double_or_die (file
, 0, data
, 1, __LINE__
) ;
1311 if (error_function (data
[0], orig
[5 * channels
], margin
))
1312 { printf ("\nLine %d: sf_seek (SEEK_END) followed by sf_readf_short failed (%f should be %f).\n", __LINE__
, data
[0], orig
[5 * channels
]) ;
1320 } /* lcomp_test_double */
1322 /*========================================================================================
1323 ** Smoothed differential loss compression tests.
1327 sdlcomp_test_short (const char *filename
, int filetype
, int channels
, double margin
)
1330 int k
, m
, seekpos
, half_max_abs
;
1332 short *orig
, *data
, *smooth
;
1335 print_test_name ("sdlcomp_test_short", filename
) ;
1337 datalen
= BUFFER_SIZE
;
1339 orig
= orig_buffer
.s
;
1340 data
= data_buffer
.s
;
1341 smooth
= smooth_buffer
.s
;
1343 gen_signal_double (orig_buffer
.d
, 32000.0, channels
, datalen
) ;
1344 for (k
= 0 ; k
< datalen
; k
++)
1345 orig
[k
] = lrint (orig_buffer
.d
[k
]) ;
1347 sfinfo
.samplerate
= SAMPLE_RATE
;
1348 sfinfo
.frames
= 123456789 ; /* Ridiculous value. */
1349 sfinfo
.channels
= channels
;
1350 sfinfo
.format
= filetype
;
1352 /* The Vorbis encoder has a bug on PowerPC and X86-64 with sample rates
1353 ** <= 22050. Increasing the sample rate to 32000 avoids triggering it.
1354 ** See https://trac.xiph.org/ticket/1229
1356 if ((file
= sf_open (filename
, SFM_WRITE
, &sfinfo
)) == NULL
)
1357 { const char * errstr
;
1359 errstr
= sf_strerror (NULL
) ;
1360 if (strstr (errstr
, "Sample rate chosen is known to trigger a Vorbis") == NULL
)
1361 { printf ("Line %d: sf_open_fd (SFM_WRITE) failed : %s\n", __LINE__
, errstr
) ;
1362 dump_log_buffer (NULL
) ;
1366 printf ("\n Sample rate -> 32kHz ") ;
1367 sfinfo
.samplerate
= 32000 ;
1369 file
= test_open_file_or_die (filename
, SFM_WRITE
, &sfinfo
, SF_TRUE
, __LINE__
) ;
1372 test_write_short_or_die (file
, 0, orig
, datalen
, __LINE__
) ;
1373 sf_set_string (file
, SF_STR_COMMENT
, long_comment
) ;
1376 memset (data
, 0, datalen
* sizeof (short)) ;
1378 if ((filetype
& SF_FORMAT_TYPEMASK
) != SF_FORMAT_RAW
)
1379 memset (&sfinfo
, 0, sizeof (sfinfo
)) ;
1381 file
= test_open_file_or_die (filename
, SFM_READ
, &sfinfo
, SF_FALSE
, __LINE__
) ;
1383 if (sfinfo
.format
!= filetype
)
1384 { printf ("\n\nLine %d: Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__
, filetype
, sfinfo
.format
) ;
1388 if (sfinfo
.frames
< datalen
/ channels
)
1389 { printf ("Too few.frames in file. (%ld should be a little more than %ld)\n", datalen
, SF_COUNT_TO_LONG (sfinfo
.frames
)) ;
1393 if (sfinfo
.frames
> (datalen
+ 400))
1394 { printf ("Too many.frames in file. (%ld should be a little more than %ld)\n", SF_COUNT_TO_LONG (sfinfo
.frames
), datalen
) ;
1398 if (sfinfo
.channels
!= channels
)
1399 { printf ("Incorrect number of channels in file.\n") ;
1403 check_comment (file
, filetype
, __LINE__
) ;
1405 sf_command (file
, SFC_SET_NORM_FLOAT
, NULL
, SF_FALSE
) ;
1407 check_log_buffer_or_die (file
, __LINE__
) ;
1409 test_readf_short_or_die (file
, 0, data
, datalen
, __LINE__
) ;
1411 memcpy (smooth
, orig
, datalen
* sizeof (short)) ;
1412 smoothed_diff_short (data
, datalen
) ;
1413 smoothed_diff_short (smooth
, datalen
) ;
1415 half_max_abs
= 0.0 ;
1416 for (k
= 0 ; k
< datalen
; k
++)
1417 { if (error_function (1.0 * data
[k
], 1.0 * smooth
[k
], margin
))
1418 { printf ("\nLine %d: Incorrect sample (#%d : %d should be %d).\n", __LINE__
, k
, data
[k
], smooth
[k
]) ;
1419 oct_save_short (orig
, smooth
, datalen
) ;
1422 half_max_abs
= LCT_MAX (half_max_abs
, abs (0.5 * data
[k
])) ;
1425 if (half_max_abs
< 1)
1426 { printf ("\n\nLine %d: Signal is all zeros.\n", __LINE__
) ;
1430 if ((k
= sf_read_short (file
, data
, datalen
)) != sfinfo
.frames
- datalen
)
1431 { printf ("\n\nLine %d: Incorrect read length (%d should be %ld).\n", __LINE__
, k
, SF_COUNT_TO_LONG (sfinfo
.frames
- datalen
)) ;
1435 if ((sfinfo
.format
& SF_FORMAT_SUBMASK
) != SF_FORMAT_MS_ADPCM
&&
1436 (sfinfo
.format
& SF_FORMAT_SUBMASK
) != SF_FORMAT_GSM610
)
1437 for (k
= 0 ; k
< sfinfo
.frames
- datalen
; k
++)
1438 if (abs (data
[k
]) > decay_response (k
))
1439 { printf ("\n\nLine %d: Incorrect sample (#%ld : abs (%d) should be < %d).\n", __LINE__
, datalen
+ k
, data
[k
], decay_response (k
)) ;
1443 /* Now test sf_seek function. */
1444 if (sfinfo
.seekable
)
1445 { if ((k
= sf_seek (file
, 0, SEEK_SET
)) != 0)
1446 { printf ("\n\nLine %d: Seek to start of file failed (%d).\n", __LINE__
, k
) ;
1450 for (m
= 0 ; m
< 3 ; m
++)
1451 { test_readf_short_or_die (file
, m
, data
, datalen
/ 7, __LINE__
) ;
1453 smoothed_diff_short (data
, datalen
/ 7) ;
1454 memcpy (smooth
, orig
+ m
* datalen
/ 7, datalen
/ 7 * sizeof (short)) ;
1455 smoothed_diff_short (smooth
, datalen
/ 7) ;
1457 for (k
= 0 ; k
< datalen
/ 7 ; k
++)
1458 if (error_function (1.0 * data
[k
], 1.0 * smooth
[k
], margin
))
1459 { printf ("\nLine %d: Incorrect sample C (#%d (%ld) : %d => %d).\n", __LINE__
, k
, k
+ m
* (datalen
/ 7), smooth
[k
], data
[k
]) ;
1460 for (m
= 0 ; m
< 10 ; m
++)
1461 printf ("%d ", data
[k
]) ;
1465 } ; /* for (m = 0 ; m < 3 ; m++) */
1467 seekpos
= BUFFER_SIZE
/ 10 ;
1469 /* Check seek from start of file. */
1470 if ((k
= sf_seek (file
, seekpos
, SEEK_SET
)) != seekpos
)
1471 { printf ("Seek to start of file + %d failed (%d).\n", seekpos
, k
) ;
1474 test_readf_short_or_die (file
, 0, data
, 1, __LINE__
) ;
1476 if (error_function (1.0 * data
[0], 1.0 * orig
[seekpos
* channels
], margin
))
1477 { printf ("\nLine %d: sf_seek (SEEK_SET) followed by sf_read_short failed (%d, %d).\n", __LINE__
, orig
[1], data
[0]) ;
1481 if ((k
= sf_seek (file
, 0, SEEK_CUR
)) != seekpos
+ 1)
1482 { printf ("\n\nLine %d: sf_seek (SEEK_CUR) with 0 offset failed (%d should be %d)\n", __LINE__
, k
, seekpos
+ 1) ;
1486 seekpos
= sf_seek (file
, 0, SEEK_CUR
) + BUFFER_SIZE
/ 5 ;
1487 k
= sf_seek (file
, BUFFER_SIZE
/ 5, SEEK_CUR
) ;
1488 test_readf_short_or_die (file
, 0, data
, 1, __LINE__
) ;
1489 if (error_function (1.0 * data
[0], 1.0 * orig
[seekpos
* channels
], margin
) || k
!= seekpos
)
1490 { printf ("\nLine %d: sf_seek (forwards, SEEK_CUR) followed by sf_read_short failed (%d, %d) (%d, %d).\n", __LINE__
, data
[0], orig
[seekpos
* channels
], k
, seekpos
+ 1) ;
1494 seekpos
= sf_seek (file
, 0, SEEK_CUR
) - 20 ;
1495 /* Check seek backward from current position. */
1496 k
= sf_seek (file
, -20, SEEK_CUR
) ;
1497 test_readf_short_or_die (file
, 0, data
, 1, __LINE__
) ;
1498 if (error_function (1.0 * data
[0], 1.0 * orig
[seekpos
* channels
], margin
) || k
!= seekpos
)
1499 { printf ("\nLine %d: sf_seek (backwards, SEEK_CUR) followed by sf_read_short failed (%d, %d) (%d, %d).\n", __LINE__
, data
[0], orig
[seekpos
* channels
], k
, seekpos
) ;
1503 /* Check that read past end of file returns number of items. */
1504 sf_seek (file
, sfinfo
.frames
, SEEK_SET
) ;
1506 if ((k
= sf_read_short (file
, data
, datalen
)) != 0)
1507 { printf ("\n\nLine %d: Return value from sf_read_short past end of file incorrect (%d).\n", __LINE__
, k
) ;
1511 /* Check seek backward from end. */
1513 if ((k
= sf_seek (file
, 5 - sfinfo
.frames
, SEEK_END
)) != 5)
1514 { printf ("\n\nLine %d: sf_seek (SEEK_END) returned %d instead of %d.\n", __LINE__
, k
, 5) ;
1518 test_read_short_or_die (file
, 0, data
, channels
, __LINE__
) ;
1519 if (error_function (1.0 * data
[0], 1.0 * orig
[5 * channels
], margin
))
1520 { printf ("\nLine %d: sf_seek (SEEK_END) followed by sf_read_short failed (%d should be %d).\n", __LINE__
, data
[0], orig
[5 * channels
]) ;
1523 } /* if (sfinfo.seekable) */
1529 } /* sdlcomp_test_short */
1532 sdlcomp_test_int (const char *filename
, int filetype
, int channels
, double margin
)
1535 int k
, m
, seekpos
, half_max_abs
;
1537 int *orig
, *data
, *smooth
;
1542 print_test_name ("sdlcomp_test_int", filename
) ;
1544 datalen
= BUFFER_SIZE
;
1545 scale
= 1.0 * 0x10000 ;
1547 orig
= orig_buffer
.i
;
1548 data
= data_buffer
.i
;
1549 smooth
= smooth_buffer
.i
;
1551 gen_signal_double (orig_buffer
.d
, 32000.0 * scale
, channels
, datalen
) ;
1552 for (k
= 0 ; k
< datalen
; k
++)
1553 orig
[k
] = lrint (orig_buffer
.d
[k
]) ;
1555 sfinfo
.samplerate
= SAMPLE_RATE
;
1556 sfinfo
.frames
= 123456789 ; /* Ridiculous value. */
1557 sfinfo
.channels
= channels
;
1558 sfinfo
.format
= filetype
;
1560 /* The Vorbis encoder has a bug on PowerPC and X86-64 with sample rates
1561 ** <= 22050. Increasing the sample rate to 32000 avoids triggering it.
1562 ** See https://trac.xiph.org/ticket/1229
1564 if ((file
= sf_open (filename
, SFM_WRITE
, &sfinfo
)) == NULL
)
1565 { const char * errstr
;
1567 errstr
= sf_strerror (NULL
) ;
1568 if (strstr (errstr
, "Sample rate chosen is known to trigger a Vorbis") == NULL
)
1569 { printf ("Line %d: sf_open_fd (SFM_WRITE) failed : %s\n", __LINE__
, errstr
) ;
1570 dump_log_buffer (NULL
) ;
1574 printf ("\n Sample rate -> 32kHz ") ;
1575 sfinfo
.samplerate
= 32000 ;
1577 file
= test_open_file_or_die (filename
, SFM_WRITE
, &sfinfo
, SF_TRUE
, __LINE__
) ;
1580 test_writef_int_or_die (file
, 0, orig
, datalen
, __LINE__
) ;
1581 sf_set_string (file
, SF_STR_COMMENT
, long_comment
) ;
1584 memset (data
, 0, datalen
* sizeof (int)) ;
1586 if ((filetype
& SF_FORMAT_TYPEMASK
) != SF_FORMAT_RAW
)
1587 memset (&sfinfo
, 0, sizeof (sfinfo
)) ;
1589 file
= test_open_file_or_die (filename
, SFM_READ
, &sfinfo
, SF_FALSE
, __LINE__
) ;
1591 if (sfinfo
.format
!= filetype
)
1592 { printf ("Returned format incorrect (0x%08X => 0x%08X).\n", filetype
, sfinfo
.format
) ;
1596 if (sfinfo
.frames
< datalen
/ channels
)
1597 { printf ("Too few.frames in file. (%ld should be a little more than %ld)\n", datalen
, SF_COUNT_TO_LONG (sfinfo
.frames
)) ;
1601 if (sfinfo
.frames
> (datalen
+ 400))
1602 { printf ("Too many.frames in file. (%ld should be a little more than %ld)\n", SF_COUNT_TO_LONG (sfinfo
.frames
), datalen
) ;
1606 if (sfinfo
.channels
!= channels
)
1607 { printf ("Incorrect number of channels in file.\n") ;
1611 check_log_buffer_or_die (file
, __LINE__
) ;
1613 test_readf_int_or_die (file
, 0, data
, datalen
, __LINE__
) ;
1615 memcpy (smooth
, orig
, datalen
* sizeof (int)) ;
1616 smoothed_diff_int (data
, datalen
) ;
1617 smoothed_diff_int (smooth
, datalen
) ;
1619 half_max_abs
= abs (data
[0] >> 16) ;
1620 for (k
= 1 ; k
< datalen
; k
++)
1621 { if (error_function (data
[k
] / scale
, smooth
[k
] / scale
, margin
))
1622 { printf ("\nLine %d: Incorrect sample (#%d : %d should be %d).\n", __LINE__
, k
, data
[k
], smooth
[k
]) ;
1623 oct_save_int (orig
, smooth
, datalen
) ;
1626 half_max_abs
= LCT_MAX (half_max_abs
, abs (data
[k
] / 2)) ;
1629 if (half_max_abs
< 1)
1630 { printf ("\n\nLine %d: Signal is all zeros.\n", __LINE__
) ;
1634 if ((k
= sf_readf_int (file
, data
, datalen
)) != sfinfo
.frames
- datalen
)
1635 { printf ("\n\nLine %d: Incorrect read length (%d should be %ld).\n", __LINE__
, k
, SF_COUNT_TO_LONG (sfinfo
.frames
- datalen
)) ;
1639 if ((sfinfo
.format
& SF_FORMAT_SUBMASK
) != SF_FORMAT_IMA_ADPCM
&&
1640 (sfinfo
.format
& SF_FORMAT_SUBMASK
) != SF_FORMAT_MS_ADPCM
&&
1641 (sfinfo
.format
& SF_FORMAT_SUBMASK
) != SF_FORMAT_GSM610
&&
1642 (sfinfo
.format
& SF_FORMAT_SUBMASK
) != SF_FORMAT_G721_32
&&
1643 (sfinfo
.format
& SF_FORMAT_SUBMASK
) != SF_FORMAT_G723_24
)
1644 for (k
= 0 ; k
< sfinfo
.frames
- datalen
; k
++)
1645 if (abs (data
[k
]) > decay_response (k
))
1646 { printf ("\n\nLine %d: Incorrect sample (#%ld : abs (%d) should be < %d).\n", __LINE__
, datalen
+ k
, data
[k
], decay_response (k
)) ;
1650 /* Now test sf_seek function. */
1651 if (sfinfo
.seekable
)
1652 { if ((k
= sf_seek (file
, 0, SEEK_SET
)) != 0)
1653 { printf ("\n\nLine %d: Seek to start of file failed (%d).\n", __LINE__
, k
) ;
1657 for (m
= 0 ; m
< 3 ; m
++)
1658 { test_readf_int_or_die (file
, m
, data
, datalen
/ 7, __LINE__
) ;
1660 smoothed_diff_int (data
, datalen
/ 7) ;
1661 memcpy (smooth
, orig
+ m
* datalen
/ 7, datalen
/ 7 * sizeof (int)) ;
1662 smoothed_diff_int (smooth
, datalen
/ 7) ;
1664 for (k
= 0 ; k
< datalen
/ 7 ; k
++)
1665 if (error_function (data
[k
] / scale
, smooth
[k
] / scale
, margin
))
1666 { printf ("\nLine %d: Incorrect sample (#%d (%ld) : %d => %d).\n", __LINE__
, k
, k
+ m
* (datalen
/ 7), smooth
[k
], data
[k
]) ;
1667 for (m
= 0 ; m
< 10 ; m
++)
1668 printf ("%d ", data
[k
]) ;
1672 } ; /* for (m = 0 ; m < 3 ; m++) */
1674 seekpos
= BUFFER_SIZE
/ 10 ;
1676 /* Check seek from start of file. */
1677 if ((k
= sf_seek (file
, seekpos
, SEEK_SET
)) != seekpos
)
1678 { printf ("Seek to start of file + %d failed (%d).\n", seekpos
, k
) ;
1681 test_readf_int_or_die (file
, 0, data
, 1, __LINE__
) ;
1683 if (error_function (1.0 * data
[0], 1.0 * orig
[seekpos
* channels
], margin
))
1684 { printf ("\nLine %d: sf_seek (SEEK_SET) followed by sf_readf_int failed (%d, %d).\n", __LINE__
, orig
[1], data
[0]) ;
1688 if ((k
= sf_seek (file
, 0, SEEK_CUR
)) != seekpos
+ 1)
1689 { printf ("\n\nLine %d: sf_seek (SEEK_CUR) with 0 offset failed (%d should be %d)\n", __LINE__
, k
, seekpos
+ 1) ;
1693 seekpos
= sf_seek (file
, 0, SEEK_CUR
) + BUFFER_SIZE
/ 5 ;
1694 k
= sf_seek (file
, BUFFER_SIZE
/ 5, SEEK_CUR
) ;
1695 test_readf_int_or_die (file
, 0, data
, 1, __LINE__
) ;
1696 if (error_function (1.0 * data
[0], 1.0 * orig
[seekpos
* channels
], margin
) || k
!= seekpos
)
1697 { printf ("\nLine %d: sf_seek (forwards, SEEK_CUR) followed by sf_readf_int failed (%d, %d) (%d, %d).\n", __LINE__
, data
[0], orig
[seekpos
* channels
], k
, seekpos
+ 1) ;
1701 seekpos
= sf_seek (file
, 0, SEEK_CUR
) - 20 ;
1702 /* Check seek backward from current position. */
1703 k
= sf_seek (file
, -20, SEEK_CUR
) ;
1704 test_readf_int_or_die (file
, 0, data
, 1, __LINE__
) ;
1705 if (error_function (1.0 * data
[0], 1.0 * orig
[seekpos
* channels
], margin
) || k
!= seekpos
)
1706 { printf ("\nLine %d: sf_seek (backwards, SEEK_CUR) followed by sf_readf_int failed (%d, %d) (%d, %d).\n", __LINE__
, data
[0], orig
[seekpos
* channels
], k
, seekpos
) ;
1710 /* Check that read past end of file returns number of items. */
1711 sf_seek (file
, sfinfo
.frames
, SEEK_SET
) ;
1713 if ((k
= sf_readf_int (file
, data
, datalen
)) != 0)
1714 { printf ("\n\nLine %d: Return value from sf_readf_int past end of file incorrect (%d).\n", __LINE__
, k
) ;
1718 /* Check seek backward from end. */
1720 if ((k
= sf_seek (file
, 5 - sfinfo
.frames
, SEEK_END
)) != 5)
1721 { printf ("\n\nLine %d: sf_seek (SEEK_END) returned %d instead of %d.\n", __LINE__
, k
, 5) ;
1725 test_readf_int_or_die (file
, 0, data
, 1, __LINE__
) ;
1726 if (error_function (data
[0] / scale
, orig
[5] / scale
, margin
))
1727 { printf ("\nLine %d: sf_seek (SEEK_END) followed by sf_readf_int failed (%d should be %d).\n", __LINE__
, data
[0], orig
[5]) ;
1730 } /* if (sfinfo.seekable) */
1736 } /* sdlcomp_test_int */
1739 sdlcomp_test_float (const char *filename
, int filetype
, int channels
, double margin
)
1744 float *orig
, *data
, *smooth
;
1745 double half_max_abs
;
1749 print_test_name ("sdlcomp_test_float", filename
) ;
1751 if ((filetype
& SF_FORMAT_SUBMASK
) == SF_FORMAT_VORBIS
)
1752 { puts ("Not working for this format.") ;
1756 printf ("** fix this ** ") ;
1758 datalen
= BUFFER_SIZE
;
1760 orig
= orig_buffer
.f
;
1761 data
= data_buffer
.f
;
1762 smooth
= smooth_buffer
.f
;
1764 gen_signal_double (orig_buffer
.d
, 32000.0, channels
, datalen
) ;
1765 for (k
= 0 ; k
< datalen
; k
++)
1766 orig
[k
] = lrint (orig_buffer
.d
[k
]) ;
1768 sfinfo
.samplerate
= SAMPLE_RATE
;
1769 sfinfo
.frames
= 123456789 ; /* Ridiculous value. */
1770 sfinfo
.channels
= channels
;
1771 sfinfo
.format
= filetype
;
1773 file
= test_open_file_or_die (filename
, SFM_WRITE
, &sfinfo
, SF_FALSE
, __LINE__
) ;
1774 sf_command (file
, SFC_SET_NORM_FLOAT
, NULL
, SF_FALSE
) ;
1775 test_write_float_or_die (file
, 0, orig
, datalen
, __LINE__
) ;
1776 sf_set_string (file
, SF_STR_COMMENT
, long_comment
) ;
1779 memset (data
, 0, datalen
* sizeof (float)) ;
1781 if ((filetype
& SF_FORMAT_TYPEMASK
) != SF_FORMAT_RAW
)
1782 memset (&sfinfo
, 0, sizeof (sfinfo
)) ;
1784 file
= test_open_file_or_die (filename
, SFM_READ
, &sfinfo
, SF_FALSE
, __LINE__
) ;
1786 if ((sfinfo
.format
& (SF_FORMAT_TYPEMASK
| SF_FORMAT_SUBMASK
)) != (filetype
& (SF_FORMAT_TYPEMASK
| SF_FORMAT_SUBMASK
)))
1787 { printf ("\n\nLine %d: Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__
, filetype
, sfinfo
.format
) ;
1791 if (sfinfo
.frames
< datalen
/ channels
)
1792 { printf ("Too few.frames in file. (%ld should be a little more than %ld)\n", datalen
, SF_COUNT_TO_LONG (sfinfo
.frames
)) ;
1796 if (sfinfo
.frames
> (datalen
+ 400))
1797 { printf ("Too many.frames in file. (%ld should be a little more than %ld)\n", SF_COUNT_TO_LONG (sfinfo
.frames
), datalen
) ;
1801 if (sfinfo
.channels
!= channels
)
1802 { printf ("Incorrect number of channels in file.\n") ;
1806 check_comment (file
, filetype
, __LINE__
) ;
1808 sf_command (file
, SFC_SET_NORM_FLOAT
, NULL
, SF_FALSE
) ;
1810 check_log_buffer_or_die (file
, __LINE__
) ;
1812 test_read_float_or_die (file
, 0, data
, datalen
, __LINE__
) ;
1814 memcpy (smooth
, orig
, datalen
* sizeof (float)) ;
1815 smoothed_diff_float (data
, datalen
) ;
1816 smoothed_diff_float (smooth
, datalen
) ;
1818 half_max_abs
= fabs (data
[0]) ;
1819 for (k
= 1 ; k
< datalen
; k
++)
1820 { if (error_function (data
[k
], smooth
[k
], margin
))
1821 { printf ("\nLine %d: Incorrect sample (#%d : %d should be %d).\n", __LINE__
, k
, (int) data
[k
], (int) smooth
[k
]) ;
1822 oct_save_float (orig
, smooth
, datalen
) ;
1825 half_max_abs
= LCT_MAX (half_max_abs
, abs (0.5 * data
[k
])) ;
1828 if (half_max_abs
<= 0.0)
1829 { printf ("\n\nLine %d: Signal is all zeros.\n", __LINE__
) ;
1830 printf ("half_max_abs : % 10.6f\n", half_max_abs
) ;
1834 if ((k
= sf_read_float (file
, data
, datalen
)) != sfinfo
.frames
- datalen
)
1835 { printf ("\n\nLine %d: Incorrect read length (%d should be %ld).\n", __LINE__
, k
, SF_COUNT_TO_LONG (sfinfo
.frames
- datalen
)) ;
1839 if ((sfinfo
.format
& SF_FORMAT_SUBMASK
) != SF_FORMAT_MS_ADPCM
&&
1840 (sfinfo
.format
& SF_FORMAT_SUBMASK
) != SF_FORMAT_GSM610
)
1841 for (k
= 0 ; k
< sfinfo
.frames
- datalen
; k
++)
1842 if (abs (data
[k
]) > decay_response (k
))
1843 { printf ("\n\nLine %d: Incorrect sample (#%ld : abs (%d) should be < %d).\n", __LINE__
, datalen
+ k
, (int) data
[k
], (int) decay_response (k
)) ;
1847 /* Now test sf_seek function. */
1848 if (sfinfo
.seekable
)
1849 { if ((k
= sf_seek (file
, 0, SEEK_SET
)) != 0)
1850 { printf ("\n\nLine %d: Seek to start of file failed (%d).\n", __LINE__
, k
) ;
1854 for (m
= 0 ; m
< 3 ; m
++)
1855 { test_read_float_or_die (file
, 0, data
, datalen
/ 7, __LINE__
) ;
1857 smoothed_diff_float (data
, datalen
/ 7) ;
1858 memcpy (smooth
, orig
+ m
* datalen
/ 7, datalen
/ 7 * sizeof (float)) ;
1859 smoothed_diff_float (smooth
, datalen
/ 7) ;
1861 for (k
= 0 ; k
< datalen
/ 7 ; k
++)
1862 if (error_function (data
[k
], smooth
[k
], margin
))
1863 { printf ("\nLine %d: Incorrect sample C (#%d (%ld) : %d => %d).\n", __LINE__
, k
, k
+ m
* (datalen
/ 7), (int) smooth
[k
], (int) data
[k
]) ;
1864 for (m
= 0 ; m
< 10 ; m
++)
1865 printf ("%d ", (int) data
[k
]) ;
1869 } ; /* for (m = 0 ; m < 3 ; m++) */
1871 seekpos
= BUFFER_SIZE
/ 10 ;
1873 /* Check seek from start of file. */
1874 if ((k
= sf_seek (file
, seekpos
, SEEK_SET
)) != seekpos
)
1875 { printf ("Seek to start of file + %d failed (%d).\n", seekpos
, k
) ;
1878 test_read_float_or_die (file
, 0, data
, channels
, __LINE__
) ;
1880 if (error_function (data
[0], orig
[seekpos
* channels
], margin
))
1881 { printf ("\nLine %d: sf_seek (SEEK_SET) followed by sf_read_float failed (%d, %d).\n", __LINE__
, (int) orig
[1], (int) data
[0]) ;
1885 if ((k
= sf_seek (file
, 0, SEEK_CUR
)) != seekpos
+ 1)
1886 { printf ("\n\nLine %d: sf_seek (SEEK_CUR) with 0 offset failed (%d should be %d)\n", __LINE__
, k
, seekpos
+ 1) ;
1890 seekpos
= sf_seek (file
, 0, SEEK_CUR
) + BUFFER_SIZE
/ 5 ;
1891 k
= sf_seek (file
, BUFFER_SIZE
/ 5, SEEK_CUR
) ;
1892 test_read_float_or_die (file
, 0, data
, channels
, __LINE__
) ;
1893 if (error_function (data
[0], orig
[seekpos
* channels
], margin
) || k
!= seekpos
)
1894 { printf ("\nLine %d: sf_seek (forwards, SEEK_CUR) followed by sf_read_float failed (%d, %d) (%d, %d).\n", __LINE__
, (int) data
[0], (int) orig
[seekpos
* channels
], k
, seekpos
+ 1) ;
1898 seekpos
= sf_seek (file
, 0, SEEK_CUR
) - 20 ;
1899 /* Check seek backward from current position. */
1900 k
= sf_seek (file
, -20, SEEK_CUR
) ;
1901 test_read_float_or_die (file
, 0, data
, channels
, __LINE__
) ;
1902 if (error_function (data
[0], orig
[seekpos
* channels
], margin
) || k
!= seekpos
)
1903 { printf ("\nLine %d: sf_seek (backwards, SEEK_CUR) followed by sf_read_float failed (%d, %d) (%d, %d).\n", __LINE__
, (int) data
[0], (int) orig
[seekpos
* channels
], k
, seekpos
) ;
1907 /* Check that read past end of file returns number of items. */
1908 sf_seek (file
, sfinfo
.frames
, SEEK_SET
) ;
1910 if ((k
= sf_read_float (file
, data
, datalen
)) != 0)
1911 { printf ("\n\nLine %d: Return value from sf_read_float past end of file incorrect (%d).\n", __LINE__
, k
) ;
1915 /* Check seek backward from end. */
1917 if ((k
= sf_seek (file
, 5 - sfinfo
.frames
, SEEK_END
)) != 5)
1918 { printf ("\n\nLine %d: sf_seek (SEEK_END) returned %d instead of %d.\n", __LINE__
, k
, 5) ;
1922 test_read_float_or_die (file
, 0, data
, channels
, __LINE__
) ;
1923 if (error_function (data
[0], orig
[5 * channels
], margin
))
1924 { printf ("\nLine %d: sf_seek (SEEK_END) followed by sf_read_float failed (%f should be %f).\n", __LINE__
, data
[0], orig
[5 * channels
]) ;
1927 } /* if (sfinfo.seekable) */
1933 } /* sdlcomp_test_float */
1936 sdlcomp_test_double (const char *filename
, int filetype
, int channels
, double margin
)
1941 double *orig
, *data
, *smooth
, half_max_abs
;
1944 print_test_name ("sdlcomp_test_double", filename
) ;
1946 if ((filetype
& SF_FORMAT_SUBMASK
) == SF_FORMAT_VORBIS
)
1947 { puts ("Not working for this format.") ;
1951 datalen
= BUFFER_SIZE
;
1953 orig
= orig_buffer
.d
;
1954 data
= data_buffer
.d
;
1955 smooth
= smooth_buffer
.d
;
1957 gen_signal_double (orig_buffer
.d
, 32000.0, channels
, datalen
) ;
1959 sfinfo
.samplerate
= SAMPLE_RATE
;
1960 sfinfo
.frames
= 123456789 ; /* Ridiculous value. */
1961 sfinfo
.channels
= channels
;
1962 sfinfo
.format
= filetype
;
1964 file
= test_open_file_or_die (filename
, SFM_WRITE
, &sfinfo
, SF_FALSE
, __LINE__
) ;
1965 sf_command (file
, SFC_SET_NORM_DOUBLE
, NULL
, SF_FALSE
) ;
1966 test_write_double_or_die (file
, 0, orig
, datalen
, __LINE__
) ;
1967 sf_set_string (file
, SF_STR_COMMENT
, long_comment
) ;
1970 memset (data
, 0, datalen
* sizeof (double)) ;
1972 if ((filetype
& SF_FORMAT_TYPEMASK
) != SF_FORMAT_RAW
)
1973 memset (&sfinfo
, 0, sizeof (sfinfo
)) ;
1975 file
= test_open_file_or_die (filename
, SFM_READ
, &sfinfo
, SF_FALSE
, __LINE__
) ;
1977 if (sfinfo
.format
!= filetype
)
1978 { printf ("Returned format incorrect (0x%08X => 0x%08X).\n", filetype
, sfinfo
.format
) ;
1982 if (sfinfo
.frames
< datalen
/ channels
)
1983 { printf ("Too few.frames in file. (%ld should be a little more than %ld)\n", datalen
, SF_COUNT_TO_LONG (sfinfo
.frames
)) ;
1987 if (sfinfo
.frames
> (datalen
+ 400))
1988 { printf ("Too many.frames in file. (%ld should be a little more than %ld)\n", SF_COUNT_TO_LONG (sfinfo
.frames
), datalen
) ;
1992 if (sfinfo
.channels
!= channels
)
1993 { printf ("Incorrect number of channels in file.\n") ;
1997 check_comment (file
, filetype
, __LINE__
) ;
1999 check_comment (file
, filetype
, __LINE__
) ;
2001 sf_command (file
, SFC_SET_NORM_DOUBLE
, NULL
, SF_FALSE
) ;
2003 check_log_buffer_or_die (file
, __LINE__
) ;
2005 test_read_double_or_die (file
, 0, data
, datalen
, __LINE__
) ;
2007 memcpy (smooth
, orig
, datalen
* sizeof (double)) ;
2008 smoothed_diff_double (data
, datalen
) ;
2009 smoothed_diff_double (smooth
, datalen
) ;
2011 half_max_abs
= 0.0 ;
2012 for (k
= 0 ; k
< datalen
; k
++)
2013 { if (error_function (data
[k
], smooth
[k
], margin
))
2014 { printf ("\n\nLine %d: Incorrect sample (#%d : %d should be %d).\n", __LINE__
, k
, (int) data
[k
], (int) smooth
[k
]) ;
2015 oct_save_double (orig
, smooth
, datalen
) ;
2018 half_max_abs
= LCT_MAX (half_max_abs
, 0.5 * fabs (data
[k
])) ;
2021 if (half_max_abs
< 1.0)
2022 { printf ("\n\nLine %d: Signal is all zeros.\n", __LINE__
) ;
2026 if ((k
= sf_read_double (file
, data
, datalen
)) != sfinfo
.frames
- datalen
)
2027 { printf ("\n\nLine %d: Incorrect read length (%d should be %ld).\n", __LINE__
, k
, SF_COUNT_TO_LONG (sfinfo
.frames
- datalen
)) ;
2031 if ((sfinfo
.format
& SF_FORMAT_SUBMASK
) != SF_FORMAT_MS_ADPCM
&&
2032 (sfinfo
.format
& SF_FORMAT_SUBMASK
) != SF_FORMAT_GSM610
)
2033 for (k
= 0 ; k
< sfinfo
.frames
- datalen
; k
++)
2034 if (abs (data
[k
]) > decay_response (k
))
2035 { printf ("\n\nLine %d: Incorrect sample (#%ld : abs (%d) should be < %d).\n", __LINE__
, datalen
+ k
, (int) data
[k
], (int) decay_response (k
)) ;
2039 /* Now test sf_seek function. */
2040 if (sfinfo
.seekable
)
2041 { if ((k
= sf_seek (file
, 0, SEEK_SET
)) != 0)
2042 { printf ("\n\nLine %d: Seek to start of file failed (%d).\n", __LINE__
, k
) ;
2046 for (m
= 0 ; m
< 3 ; m
++)
2047 { test_read_double_or_die (file
, m
, data
, datalen
/ 7, __LINE__
) ;
2049 smoothed_diff_double (data
, datalen
/ 7) ;
2050 memcpy (smooth
, orig
+ m
* datalen
/ 7, datalen
/ 7 * sizeof (double)) ;
2051 smoothed_diff_double (smooth
, datalen
/ 7) ;
2053 for (k
= 0 ; k
< datalen
/ 7 ; k
++)
2054 if (error_function (data
[k
], smooth
[k
], margin
))
2055 { printf ("\nLine %d: Incorrect sample C (#%d (%ld) : %d => %d).\n", __LINE__
, k
, k
+ m
* (datalen
/ 7), (int) smooth
[k
], (int) data
[k
]) ;
2056 for (m
= 0 ; m
< 10 ; m
++)
2057 printf ("%d ", (int) data
[k
]) ;
2061 } ; /* for (m = 0 ; m < 3 ; m++) */
2063 seekpos
= BUFFER_SIZE
/ 10 ;
2065 /* Check seek from start of file. */
2066 if ((k
= sf_seek (file
, seekpos
, SEEK_SET
)) != seekpos
)
2067 { printf ("Seek to start of file + %d failed (%d).\n", seekpos
, k
) ;
2070 test_read_double_or_die (file
, 0, data
, channels
, __LINE__
) ;
2072 if (error_function (data
[0], orig
[seekpos
* channels
], margin
))
2073 { printf ("\nLine %d: sf_seek (SEEK_SET) followed by sf_read_double failed (%d, %d).\n", __LINE__
, (int) orig
[1], (int) data
[0]) ;
2077 if ((k
= sf_seek (file
, 0, SEEK_CUR
)) != seekpos
+ 1)
2078 { printf ("\n\nLine %d: sf_seek (SEEK_CUR) with 0 offset failed (%d should be %d)\n", __LINE__
, k
, seekpos
+ 1) ;
2082 seekpos
= sf_seek (file
, 0, SEEK_CUR
) + BUFFER_SIZE
/ 5 ;
2083 k
= sf_seek (file
, BUFFER_SIZE
/ 5, SEEK_CUR
) ;
2084 test_read_double_or_die (file
, 0, data
, channels
, __LINE__
) ;
2085 if (error_function (data
[0], orig
[seekpos
* channels
], margin
) || k
!= seekpos
)
2086 { printf ("\nLine %d: sf_seek (forwards, SEEK_CUR) followed by sf_read_double failed (%d, %d) (%d, %d).\n", __LINE__
, (int) data
[0], (int) orig
[seekpos
* channels
], k
, seekpos
+ 1) ;
2090 seekpos
= sf_seek (file
, 0, SEEK_CUR
) - 20 ;
2091 /* Check seek backward from current position. */
2092 k
= sf_seek (file
, -20, SEEK_CUR
) ;
2093 test_read_double_or_die (file
, 0, data
, channels
, __LINE__
) ;
2094 if (error_function (data
[0], orig
[seekpos
* channels
], margin
) || k
!= seekpos
)
2095 { printf ("\nLine %d: sf_seek (backwards, SEEK_CUR) followed by sf_read_double failed (%d, %d) (%d, %d).\n", __LINE__
, (int) data
[0], (int) orig
[seekpos
* channels
], k
, seekpos
) ;
2099 /* Check that read past end of file returns number of items. */
2100 sf_seek (file
, sfinfo
.frames
, SEEK_SET
) ;
2102 if ((k
= sf_read_double (file
, data
, datalen
)) != 0)
2103 { printf ("\n\nLine %d: Return value from sf_read_double past end of file incorrect (%d).\n", __LINE__
, k
) ;
2107 /* Check seek backward from end. */
2109 if ((k
= sf_seek (file
, 5 - sfinfo
.frames
, SEEK_END
)) != 5)
2110 { printf ("\n\nLine %d: sf_seek (SEEK_END) returned %d instead of %d.\n", __LINE__
, k
, 5) ;
2114 test_read_double_or_die (file
, 0, data
, channels
, __LINE__
) ;
2115 if (error_function (data
[0], orig
[5 * channels
], margin
))
2116 { printf ("\nLine %d: sf_seek (SEEK_END) followed by sf_read_double failed (%f should be %f).\n", __LINE__
, data
[0], orig
[5 * channels
]) ;
2119 } /* if (sfinfo.seekable) */
2125 } /* sdlcomp_test_double */
2128 read_raw_test (const char *filename
, int filetype
, int channels
)
2133 short *orig
, *data
;
2136 print_test_name ("read_raw_test", filename
) ;
2138 datalen
= ARRAY_LEN (orig_buffer
.s
) / 2 ;
2140 orig
= orig_buffer
.s
;
2141 data
= data_buffer
.s
;
2143 gen_signal_double (orig_buffer
.d
, 32000.0, channels
, datalen
) ;
2144 for (k
= 0 ; k
< datalen
; k
++)
2145 orig
[k
] = lrint (orig_buffer
.d
[k
]) ;
2147 sfinfo
.samplerate
= SAMPLE_RATE
;
2148 sfinfo
.frames
= 123456789 ; /* Ridiculous value. */
2149 sfinfo
.channels
= channels
;
2150 sfinfo
.format
= filetype
;
2152 file
= test_open_file_or_die (filename
, SFM_WRITE
, &sfinfo
, SF_FALSE
, __LINE__
) ;
2153 test_write_short_or_die (file
, 0, orig
, datalen
, __LINE__
) ;
2154 sf_set_string (file
, SF_STR_COMMENT
, long_comment
) ;
2157 memset (data
, 0, datalen
* sizeof (double)) ;
2159 if ((filetype
& SF_FORMAT_TYPEMASK
) != SF_FORMAT_RAW
)
2160 memset (&sfinfo
, 0, sizeof (sfinfo
)) ;
2162 file
= test_open_file_or_die (filename
, SFM_READ
, &sfinfo
, SF_FALSE
, __LINE__
) ;
2164 if (sfinfo
.format
!= filetype
)
2165 { printf ("Returned format incorrect (0x%08X => 0x%08X).\n", filetype
, sfinfo
.format
) ;
2169 if (sfinfo
.frames
< datalen
/ channels
)
2170 { printf ("Too few.frames in file. (%ld should be a little more than %ld)\n", datalen
, SF_COUNT_TO_LONG (sfinfo
.frames
)) ;
2174 if (sfinfo
.frames
> (datalen
+ 400))
2175 { printf ("Too many.frames in file. (%ld should be a little more than %ld)\n", SF_COUNT_TO_LONG (sfinfo
.frames
), datalen
) ;
2179 if (sfinfo
.channels
!= channels
)
2180 { printf ("Incorrect number of channels in file.\n") ;
2184 check_comment (file
, filetype
, __LINE__
) ;
2186 count
= sf_read_raw (file
, orig_buffer
.c
, datalen
+ 5 * channels
) ;
2187 if (count
!= sfinfo
.channels
* sfinfo
.frames
)
2188 { printf ("\nLine %d : sf_read_raw returned %ld should be %ld\n", __LINE__
, SF_COUNT_TO_LONG (count
), sfinfo
.channels
* SF_COUNT_TO_LONG (sfinfo
.frames
)) ;
2196 } /* read_raw_test */
2198 /*========================================================================================
2199 ** Auxiliary functions
2202 #define SIGNAL_MAXVAL 30000.0
2203 #define DECAY_COUNT 1000
2206 decay_response (int k
)
2208 return (int) (1.2 * SIGNAL_MAXVAL
) ;
2209 if (k
> DECAY_COUNT
)
2211 return (int) (1.2 * SIGNAL_MAXVAL
* (DECAY_COUNT
- k
) / (1.0 * DECAY_COUNT
)) ;
2212 } /* decay_response */
2215 gen_signal_double (double *data
, double scale
, int channels
, int datalen
)
2219 ramplen
= DECAY_COUNT
;
2222 { for (k
= 0 ; k
< datalen
; k
++)
2224 amp
= scale
* k
/ ((double) ramplen
) ;
2225 else if (k
> datalen
- ramplen
)
2226 amp
= scale
* (datalen
- k
) / ((double) ramplen
) ;
2228 /*-printf ("%3d : %g\n", k, amp) ;-*/
2230 data
[k
] = amp
* (0.4 * sin (33.3 * 2.0 * M_PI
* ((double) (k
+1)) / ((double) SAMPLE_RATE
))
2231 + 0.3 * cos (201.1 * 2.0 * M_PI
* ((double) (k
+1)) / ((double) SAMPLE_RATE
))) ;
2235 { for (k
= 0 ; k
< datalen
; k
++)
2237 amp
= scale
* k
/ ((double) ramplen
) ;
2238 else if (k
> datalen
- ramplen
)
2239 amp
= scale
* (datalen
- k
) / ((double) ramplen
) ;
2241 data
[2 * k
] = amp
* (0.4 * sin (33.3 * 2.0 * M_PI
* ((double) (k
+1)) / ((double) SAMPLE_RATE
))
2242 + 0.3 * cos (201.1 * 2.0 * M_PI
* ((double) (k
+1)) / ((double) SAMPLE_RATE
))) ;
2243 data
[2 * k
+ 1] = amp
* (0.4 * sin (55.5 * 2.0 * M_PI
* ((double) (k
+1)) / ((double) SAMPLE_RATE
))
2244 + 0.3 * cos (201.1 * 2.0 * M_PI
* ((double) (k
+1)) / ((double) SAMPLE_RATE
))) ;
2249 } /* gen_signal_double */
2252 error_function (double data
, double orig
, double margin
)
2255 if (fabs (orig
) <= 500.0)
2256 error
= fabs (fabs (data
) - fabs (orig
)) / 2000.0 ;
2257 else if (fabs (orig
) <= 1000.0)
2258 error
= fabs (data
- orig
) / 3000.0 ;
2260 error
= fabs (data
- orig
) / fabs (orig
) ;
2263 { printf ("\n\nerror_function (data = %f, orig = %f, margin = %f) -> %f\n", data
, orig
, margin
, error
) ;
2267 } /* error_function */
2270 smoothed_diff_short (short *data
, unsigned int datalen
)
2272 double memory
= 0.0 ;
2274 /* Calculate the smoothed sample-to-sample difference. */
2275 for (k
= 0 ; k
< datalen
- 1 ; k
++)
2276 { memory
= 0.7 * memory
+ (1 - 0.7) * (double) (data
[k
+1] - data
[k
]) ;
2277 data
[k
] = (short) memory
;
2279 data
[datalen
-1] = data
[datalen
-2] ;
2281 } /* smoothed_diff_short */
2284 smoothed_diff_int (int *data
, unsigned int datalen
)
2286 double memory
= 0.0 ;
2288 /* Calculate the smoothed sample-to-sample difference. */
2289 for (k
= 0 ; k
< datalen
- 1 ; k
++)
2290 { memory
= 0.7 * memory
+ (1 - 0.7) * (double) (data
[k
+1] - data
[k
]) ;
2291 data
[k
] = (int) memory
;
2293 data
[datalen
-1] = data
[datalen
-2] ;
2295 } /* smoothed_diff_int */
2298 smoothed_diff_float (float *data
, unsigned int datalen
)
2300 float memory
= 0.0 ;
2302 /* Calculate the smoothed sample-to-sample difference. */
2303 for (k
= 0 ; k
< datalen
- 1 ; k
++)
2304 { memory
= 0.7 * memory
+ (1 - 0.7) * (data
[k
+1] - data
[k
]) ;
2307 data
[datalen
-1] = data
[datalen
-2] ;
2309 } /* smoothed_diff_float */
2312 smoothed_diff_double (double *data
, unsigned int datalen
)
2314 double memory
= 0.0 ;
2316 /* Calculate the smoothed sample-to-sample difference. */
2317 for (k
= 0 ; k
< datalen
- 1 ; k
++)
2318 { memory
= 0.7 * memory
+ (1 - 0.7) * (data
[k
+1] - data
[k
]) ;
2321 data
[datalen
-1] = data
[datalen
-2] ;
2323 } /* smoothed_diff_double */
2326 check_comment (SNDFILE
* file
, int format
, int lineno
)
2327 { const char *comment
;
2329 switch (format
& SF_FORMAT_TYPEMASK
)
2330 { case SF_FORMAT_AIFF
:
2331 case SF_FORMAT_WAV
:
2332 case SF_FORMAT_WAVEX
:
2338 comment
= sf_get_string (file
, SF_STR_COMMENT
) ;
2339 if (comment
== NULL
)
2340 { printf ("\n\nLine %d : File does not contain a comment string.\n\n", lineno
) ;
2344 if (strcmp (comment
, long_comment
) != 0)
2345 { printf ("\n\nLine %d : File comment does not match comment written.\n\n", lineno
) ;
2350 } /* check_comment */
2353 is_lossy (int filetype
)
2355 switch (SF_FORMAT_SUBMASK
& filetype
)
2356 { case SF_FORMAT_PCM_U8
:
2357 case SF_FORMAT_PCM_S8
:
2358 case SF_FORMAT_PCM_16
:
2359 case SF_FORMAT_PCM_24
:
2360 case SF_FORMAT_PCM_32
:
2361 case SF_FORMAT_FLOAT
:
2362 case SF_FORMAT_DOUBLE
: