Rename interpretor to interpreter.
[Faustine.git] / interpreter / lib / src / libsndfile-1.0.25 / tests / pcm_test.c
1 /*
2 ** Copyright (C) 1999-2011 Erik de Castro Lopo <erikd@mega-nerd.com>
3 **
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.
8 **
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.
13 **
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.
17 */
18
19 #include "sfconfig.h"
20
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include <string.h>
24 #include <math.h>
25
26 #if HAVE_UNISTD_H
27 #include <unistd.h>
28 #endif
29
30 #include <sndfile.h>
31
32 #include "utils.h"
33
34 #define BUFFER_SIZE (1<<12)
35
36 static void lrintf_test (void) ;
37
38 static void pcm_test_bits_8 (const char *filename, int filetype, uint64_t hash) ;
39 static void pcm_test_bits_16 (const char *filename, int filetype, uint64_t hash) ;
40 static void pcm_test_bits_24 (const char *filename, int filetype, uint64_t hash) ;
41 static void pcm_test_bits_32 (const char *filename, int filetype, uint64_t hash) ;
42
43 static void pcm_test_float (const char *filename, int filetype, uint64_t hash, int replace_float) ;
44 static void pcm_test_double (const char *filename, int filetype, uint64_t hash, int replace_float) ;
45
46 typedef union
47 { double d [BUFFER_SIZE + 1] ;
48 float f [BUFFER_SIZE + 1] ;
49 int i [BUFFER_SIZE + 1] ;
50 short s [BUFFER_SIZE + 1] ;
51 } BUFFER ;
52
53 /* Data written to the file. */
54 static BUFFER data_out ;
55
56 /* Data read back from the file. */
57 static BUFFER data_in ;
58
59 int
60 main (void)
61 {
62 lrintf_test () ;
63
64 pcm_test_bits_8 ("pcm-s8.raw", SF_FORMAT_RAW | SF_FORMAT_PCM_S8, 0x1cda335091249dbfLL) ;
65 pcm_test_bits_8 ("pcm-u8.raw", SF_FORMAT_RAW | SF_FORMAT_PCM_U8, 0x7f748c433d695f3fLL) ;
66
67 pcm_test_bits_16 ("le-pcm16.raw", SF_ENDIAN_LITTLE | SF_FORMAT_RAW | SF_FORMAT_PCM_16, 0x3a2b956c881ebf08LL) ;
68 pcm_test_bits_16 ("be-pcm16.raw", SF_ENDIAN_BIG | SF_FORMAT_RAW | SF_FORMAT_PCM_16, 0xd9e2f840c55750f8LL) ;
69
70 pcm_test_bits_24 ("le-pcm24.raw", SF_ENDIAN_LITTLE | SF_FORMAT_RAW | SF_FORMAT_PCM_24, 0x933b6a759ab496f8LL) ;
71 pcm_test_bits_24 ("be-pcm24.raw", SF_ENDIAN_BIG | SF_FORMAT_RAW | SF_FORMAT_PCM_24, 0xbb1f3eaf9c30b6f8LL) ;
72
73 pcm_test_bits_32 ("le-pcm32.raw", SF_ENDIAN_LITTLE | SF_FORMAT_RAW | SF_FORMAT_PCM_32, 0xa77aece1c1c17f08LL) ;
74 pcm_test_bits_32 ("be-pcm32.raw", SF_ENDIAN_BIG | SF_FORMAT_RAW | SF_FORMAT_PCM_32, 0x3099ddf142d0b0f8LL) ;
75
76 /* Lite remove start */
77 pcm_test_float ("le-float.raw", SF_ENDIAN_LITTLE | SF_FORMAT_RAW | SF_FORMAT_FLOAT, 0x3c2ad04f7554267aLL, SF_FALSE) ;
78 pcm_test_float ("be-float.raw", SF_ENDIAN_BIG | SF_FORMAT_RAW | SF_FORMAT_FLOAT, 0x074de3e248fa9186LL, SF_FALSE) ;
79
80 pcm_test_double ("le-double.raw", SF_ENDIAN_LITTLE | SF_FORMAT_RAW | SF_FORMAT_DOUBLE, 0xc682726f958f669cLL, SF_FALSE) ;
81 pcm_test_double ("be-double.raw", SF_ENDIAN_BIG | SF_FORMAT_RAW | SF_FORMAT_DOUBLE, 0xd9a3583f8ee51164LL, SF_FALSE) ;
82
83 pcm_test_float ("le-float.raw", SF_ENDIAN_LITTLE | SF_FORMAT_RAW | SF_FORMAT_FLOAT, 0x3c2ad04f7554267aLL, SF_TRUE) ;
84 pcm_test_float ("be-float.raw", SF_ENDIAN_BIG | SF_FORMAT_RAW | SF_FORMAT_FLOAT, 0x074de3e248fa9186LL, SF_TRUE) ;
85
86 pcm_test_double ("le-double.raw", SF_ENDIAN_LITTLE | SF_FORMAT_RAW | SF_FORMAT_DOUBLE, 0xc682726f958f669cLL, SF_TRUE) ;
87 pcm_test_double ("be-double.raw", SF_ENDIAN_BIG | SF_FORMAT_RAW | SF_FORMAT_DOUBLE, 0xd9a3583f8ee51164LL, SF_TRUE) ;
88 /* Lite remove end */
89
90 return 0 ;
91 } /* main */
92
93 /*============================================================================================
94 ** Here are the test functions.
95 */
96
97 static void
98 lrintf_test (void)
99 { int k, items ;
100 float *float_data ;
101 int *int_data ;
102
103 print_test_name ("lrintf_test", "") ;
104
105 items = 1024 ;
106
107 float_data = data_out.f ;
108 int_data = data_in.i ;
109
110 for (k = 0 ; k < items ; k++)
111 float_data [k] = (k * ((k % 2) ? 333333.0 : -333333.0)) ;
112
113 for (k = 0 ; k < items ; k++)
114 int_data [k] = lrintf (float_data [k]) ;
115
116 for (k = 0 ; k < items ; k++)
117 if (fabs (int_data [k] - float_data [k]) > 1.0)
118 { printf ("\n\nLine %d: float : Incorrect sample (#%d : %f => %d).\n", __LINE__, k, float_data [k], int_data [k]) ;
119 exit (1) ;
120 } ;
121
122 printf ("ok\n") ;
123 } /* lrintf_test */
124
125 static void
126 pcm_test_bits_8 (const char *filename, int filetype, uint64_t hash)
127 { SNDFILE *file ;
128 SF_INFO sfinfo ;
129 int k, items, zero_count ;
130 short *short_out, *short_in ;
131 int *int_out, *int_in ;
132 /* Lite remove start */
133 float *float_out, *float_in ;
134 double *double_out, *double_in ;
135 /* Lite remove end */
136
137 print_test_name ("pcm_test_bits_8", filename) ;
138
139 items = 127 ;
140
141 short_out = data_out.s ;
142 short_in = data_in.s ;
143
144 zero_count = 0 ;
145 for (k = 0 ; k < items ; k++)
146 { short_out [k] = ((k * ((k % 2) ? 1 : -1)) << 8) ;
147 zero_count = short_out [k] ? zero_count : zero_count + 1 ;
148 } ;
149
150 if (zero_count > items / 4)
151 { printf ("\n\nLine %d: too many zeros.\n", __LINE__) ;
152 exit (1) ;
153 } ;
154
155 sfinfo.samplerate = 44100 ;
156 sfinfo.frames = 123456789 ; /* Wrong length. Library should correct this on sf_close. */
157 sfinfo.channels = 1 ;
158 sfinfo.format = filetype ;
159
160 file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
161
162 test_write_short_or_die (file, 0, short_out, items, __LINE__) ;
163
164 sf_close (file) ;
165
166 memset (short_in, 0, items * sizeof (short)) ;
167
168 file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
169
170 if (sfinfo.format != filetype)
171 { printf ("\n\nLine %d: Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__, filetype, sfinfo.format) ;
172 exit (1) ;
173 } ;
174
175 if (sfinfo.frames != items)
176 { printf ("\n\nLine %d: Incorrect number of frames in file. (%d => %ld)\n", __LINE__, items, SF_COUNT_TO_LONG (sfinfo.frames)) ;
177 exit (1) ;
178 } ;
179
180 if (sfinfo.channels != 1)
181 { printf ("\n\nLine %d: Incorrect number of channels in file.\n", __LINE__) ;
182 exit (1) ;
183 } ;
184
185 check_log_buffer_or_die (file, __LINE__) ;
186
187 test_read_short_or_die (file, 0, short_in, items, __LINE__) ;
188
189 for (k = 0 ; k < items ; k++)
190 if (short_out [k] != short_in [k])
191 { printf ("\n\nLine %d: Incorrect sample (#%d : 0x%x => 0x%x).\n", __LINE__, k, short_out [k], short_in [k]) ;
192 exit (1) ;
193 } ;
194
195 sf_close (file) ;
196
197 /* Finally, check the file hash. */
198 check_file_hash_or_die (filename, hash, __LINE__) ;
199
200 /*--------------------------------------------------------------------------
201 ** Test sf_read/write_int ()
202 */
203 zero_count = 0 ;
204
205 int_out = data_out.i ;
206 int_in = data_in.i ;
207 for (k = 0 ; k < items ; k++)
208 { int_out [k] = ((k * ((k % 2) ? 1 : -1)) << 24) ;
209 zero_count = int_out [k] ? zero_count : zero_count + 1 ;
210 } ;
211
212 if (zero_count > items / 4)
213 { printf ("\n\nLine %d: too many zeros.\n", __LINE__) ;
214 exit (1) ;
215 } ;
216
217 sfinfo.samplerate = 44100 ;
218 sfinfo.frames = 123456789 ; /* Wrong length. Library should correct this on sf_close. */
219 sfinfo.channels = 1 ;
220 sfinfo.format = filetype ;
221
222 file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
223
224 test_write_int_or_die (file, 0, int_out, items, __LINE__) ;
225
226 sf_close (file) ;
227
228 memset (int_in, 0, items * sizeof (int)) ;
229
230 file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
231
232 if (sfinfo.format != filetype)
233 { printf ("\n\nLine %d: Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__, filetype, sfinfo.format) ;
234 exit (1) ;
235 } ;
236
237 if (sfinfo.frames != items)
238 { printf ("\n\nLine %d: Incorrect number of frames in file. (%d => %ld)\n", __LINE__, items, SF_COUNT_TO_LONG (sfinfo.frames)) ;
239 exit (1) ;
240 } ;
241
242 if (sfinfo.channels != 1)
243 { printf ("\n\nLine %d: Incorrect number of channels in file.\n", __LINE__) ;
244 exit (1) ;
245 } ;
246
247 check_log_buffer_or_die (file, __LINE__) ;
248
249 test_read_int_or_die (file, 0, int_in, items, __LINE__) ;
250
251 for (k = 0 ; k < items ; k++)
252 if (int_out [k] != int_in [k])
253 { printf ("\n\nLine %d: int : Incorrect sample (#%d : 0x%x => 0x%x).\n", __LINE__, k, int_out [k], int_in [k]) ;
254 exit (1) ;
255 } ;
256
257 sf_close (file) ;
258
259 /* Lite remove start */
260 /*--------------------------------------------------------------------------
261 ** Test sf_read/write_float ()
262 */
263 zero_count = 0 ;
264
265 float_out = data_out.f ;
266 float_in = data_in.f ;
267 for (k = 0 ; k < items ; k++)
268 { float_out [k] = (k * ((k % 2) ? 1 : -1)) ;
269 zero_count = (fabs (float_out [k]) > 1e-10) ? zero_count : zero_count + 1 ;
270 } ;
271
272 if (zero_count > items / 4)
273 { printf ("\n\nLine %d: too many zeros (%d/%d).\n", __LINE__, zero_count, items) ;
274 exit (1) ;
275 } ;
276
277 sfinfo.samplerate = 44100 ;
278 sfinfo.frames = 123456789 ; /* Wrong length. Library should correct this on sf_close. */
279 sfinfo.channels = 1 ;
280 sfinfo.format = filetype ;
281
282 file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
283
284 sf_command (file, SFC_SET_NORM_FLOAT, NULL, SF_FALSE) ;
285
286 test_write_float_or_die (file, 0, float_out, items, __LINE__) ;
287
288 sf_close (file) ;
289
290 memset (float_in, 0, items * sizeof (float)) ;
291
292 file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
293
294 if (sfinfo.format != filetype)
295 { printf ("\n\nLine %d: Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__, filetype, sfinfo.format) ;
296 exit (1) ;
297 } ;
298
299 if (sfinfo.frames != items)
300 { printf ("\n\nLine %d: Incorrect number of frames in file. (%d => %ld)\n", __LINE__, items, SF_COUNT_TO_LONG (sfinfo.frames)) ;
301 exit (1) ;
302 } ;
303
304 if (sfinfo.channels != 1)
305 { printf ("\n\nLine %d: Incorrect number of channels in file.\n", __LINE__) ;
306 exit (1) ;
307 } ;
308
309 check_log_buffer_or_die (file, __LINE__) ;
310
311 sf_command (file, SFC_SET_NORM_FLOAT, NULL, SF_FALSE) ;
312
313 test_read_float_or_die (file, 0, float_in, items, __LINE__) ;
314
315 for (k = 0 ; k < items ; k++)
316 if (fabs (float_out [k] - float_in [k]) > 1e-10)
317 { printf ("\n\nLine %d: float : Incorrect sample (#%d : %f => %f).\n", __LINE__, k, (double) float_out [k], (double) float_in [k]) ;
318 exit (1) ;
319 } ;
320
321 sf_close (file) ;
322
323 /*--------------------------------------------------------------------------
324 ** Test sf_read/write_double ()
325 */
326 zero_count = 0 ;
327
328 double_out = data_out.d ;
329 double_in = data_in.d ;
330 for (k = 0 ; k < items ; k++)
331 { double_out [k] = (k * ((k % 2) ? 1 : -1)) ;
332 zero_count = (fabs (double_out [k]) > 1e-10) ? zero_count : zero_count + 1 ;
333 } ;
334
335 if (zero_count > items / 4)
336 { printf ("\n\nLine %d: too many zeros (%d/%d).\n", __LINE__, zero_count, items) ;
337 exit (1) ;
338 } ;
339
340 sfinfo.samplerate = 44100 ;
341 sfinfo.frames = 123456789 ; /* Wrong length. Library should correct this on sf_close. */
342 sfinfo.channels = 1 ;
343 sfinfo.format = filetype ;
344
345 file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
346
347 sf_command (file, SFC_SET_NORM_DOUBLE, NULL, SF_FALSE) ;
348
349 test_write_double_or_die (file, 0, double_out, items, __LINE__) ;
350
351 sf_close (file) ;
352
353 memset (double_in, 0, items * sizeof (double)) ;
354
355 file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
356
357 if (sfinfo.format != filetype)
358 { printf ("\n\nLine %d: Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__, filetype, sfinfo.format) ;
359 exit (1) ;
360 } ;
361
362 if (sfinfo.frames != items)
363 { printf ("\n\nLine %d: Incorrect number of frames in file. (%d => %ld)\n", __LINE__, items, SF_COUNT_TO_LONG (sfinfo.frames)) ;
364 exit (1) ;
365 } ;
366
367 if (sfinfo.channels != 1)
368 { printf ("\n\nLine %d: Incorrect number of channels in file.\n", __LINE__) ;
369 exit (1) ;
370 } ;
371
372 check_log_buffer_or_die (file, __LINE__) ;
373
374 sf_command (file, SFC_SET_NORM_DOUBLE, NULL, SF_FALSE) ;
375
376 test_read_double_or_die (file, 0, double_in, items, __LINE__) ;
377
378 for (k = 0 ; k < items ; k++)
379 if (fabs (double_out [k] - double_in [k]) > 1e-10)
380 { printf ("\n\nLine %d: double : Incorrect sample (#%d : %f => %f).\n", __LINE__, k, double_out [k], double_in [k]) ;
381 exit (1) ;
382 } ;
383
384 sf_close (file) ;
385 /* Lite remove end */
386 unlink (filename) ;
387
388 puts ("ok") ;
389 } /* pcm_test_bits_8 */
390
391 static void
392 pcm_test_bits_16 (const char *filename, int filetype, uint64_t hash)
393 { SNDFILE *file ;
394 SF_INFO sfinfo ;
395 int k, items, zero_count ;
396 short *short_out, *short_in ;
397 int *int_out, *int_in ;
398 /* Lite remove start */
399 float *float_out, *float_in ;
400 double *double_out, *double_in ;
401 /* Lite remove end */
402
403 print_test_name ("pcm_test_bits_16", filename) ;
404
405 items = 1024 ;
406
407 short_out = data_out.s ;
408 short_in = data_in.s ;
409
410 zero_count = 0 ;
411 for (k = 0 ; k < items ; k++)
412 { short_out [k] = (k * ((k % 2) ? 3 : -3)) ;
413 zero_count = short_out [k] ? zero_count : zero_count + 1 ;
414 } ;
415
416 if (zero_count > items / 4)
417 { printf ("\n\nLine %d: too many zeros.\n", __LINE__) ;
418 exit (1) ;
419 } ;
420
421 sfinfo.samplerate = 44100 ;
422 sfinfo.frames = 123456789 ; /* Wrong length. Library should correct this on sf_close. */
423 sfinfo.channels = 1 ;
424 sfinfo.format = filetype ;
425
426 file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
427
428 test_write_short_or_die (file, 0, short_out, items, __LINE__) ;
429
430 sf_close (file) ;
431
432 memset (short_in, 0, items * sizeof (short)) ;
433
434 file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
435
436 if (sfinfo.format != filetype)
437 { printf ("\n\nLine %d: Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__, filetype, sfinfo.format) ;
438 exit (1) ;
439 } ;
440
441 if (sfinfo.frames != items)
442 { printf ("\n\nLine %d: Incorrect number of frames in file. (%d => %ld)\n", __LINE__, items, SF_COUNT_TO_LONG (sfinfo.frames)) ;
443 exit (1) ;
444 } ;
445
446 if (sfinfo.channels != 1)
447 { printf ("\n\nLine %d: Incorrect number of channels in file.\n", __LINE__) ;
448 exit (1) ;
449 } ;
450
451 check_log_buffer_or_die (file, __LINE__) ;
452
453 test_read_short_or_die (file, 0, short_in, items, __LINE__) ;
454
455 for (k = 0 ; k < items ; k++)
456 if (short_out [k] != short_in [k])
457 { printf ("\n\nLine %d: Incorrect sample (#%d : 0x%x => 0x%x).\n", __LINE__, k, short_out [k], short_in [k]) ;
458 exit (1) ;
459 } ;
460
461 sf_close (file) ;
462
463 /* Finally, check the file hash. */
464 check_file_hash_or_die (filename, hash, __LINE__) ;
465
466 /*--------------------------------------------------------------------------
467 ** Test sf_read/write_int ()
468 */
469 zero_count = 0 ;
470
471 int_out = data_out.i ;
472 int_in = data_in.i ;
473 for (k = 0 ; k < items ; k++)
474 { int_out [k] = ((k * ((k % 2) ? 3 : -3)) << 16) ;
475 zero_count = int_out [k] ? zero_count : zero_count + 1 ;
476 } ;
477
478 if (zero_count > items / 4)
479 { printf ("\n\nLine %d: too many zeros.\n", __LINE__) ;
480 exit (1) ;
481 } ;
482
483 sfinfo.samplerate = 44100 ;
484 sfinfo.frames = 123456789 ; /* Wrong length. Library should correct this on sf_close. */
485 sfinfo.channels = 1 ;
486 sfinfo.format = filetype ;
487
488 file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
489
490 test_write_int_or_die (file, 0, int_out, items, __LINE__) ;
491
492 sf_close (file) ;
493
494 memset (int_in, 0, items * sizeof (int)) ;
495
496 file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
497
498 if (sfinfo.format != filetype)
499 { printf ("\n\nLine %d: Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__, filetype, sfinfo.format) ;
500 exit (1) ;
501 } ;
502
503 if (sfinfo.frames != items)
504 { printf ("\n\nLine %d: Incorrect number of frames in file. (%d => %ld)\n", __LINE__, items, SF_COUNT_TO_LONG (sfinfo.frames)) ;
505 exit (1) ;
506 } ;
507
508 if (sfinfo.channels != 1)
509 { printf ("\n\nLine %d: Incorrect number of channels in file.\n", __LINE__) ;
510 exit (1) ;
511 } ;
512
513 check_log_buffer_or_die (file, __LINE__) ;
514
515 test_read_int_or_die (file, 0, int_in, items, __LINE__) ;
516
517 for (k = 0 ; k < items ; k++)
518 if (int_out [k] != int_in [k])
519 { printf ("\n\nLine %d: int : Incorrect sample (#%d : 0x%x => 0x%x).\n", __LINE__, k, int_out [k], int_in [k]) ;
520 exit (1) ;
521 } ;
522
523 sf_close (file) ;
524
525 /* Lite remove start */
526 /*--------------------------------------------------------------------------
527 ** Test sf_read/write_float ()
528 */
529 zero_count = 0 ;
530
531 float_out = data_out.f ;
532 float_in = data_in.f ;
533 for (k = 0 ; k < items ; k++)
534 { float_out [k] = (k * ((k % 2) ? 3 : -3)) ;
535 zero_count = (fabs (float_out [k]) > 1e-10) ? zero_count : zero_count + 1 ;
536 } ;
537
538 if (zero_count > items / 4)
539 { printf ("\n\nLine %d: too many zeros (%d/%d).\n", __LINE__, zero_count, items) ;
540 exit (1) ;
541 } ;
542
543 sfinfo.samplerate = 44100 ;
544 sfinfo.frames = 123456789 ; /* Wrong length. Library should correct this on sf_close. */
545 sfinfo.channels = 1 ;
546 sfinfo.format = filetype ;
547
548 file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
549
550 sf_command (file, SFC_SET_NORM_FLOAT, NULL, SF_FALSE) ;
551
552 test_write_float_or_die (file, 0, float_out, items, __LINE__) ;
553
554 sf_close (file) ;
555
556 memset (float_in, 0, items * sizeof (float)) ;
557
558 file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
559
560 if (sfinfo.format != filetype)
561 { printf ("\n\nLine %d: Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__, filetype, sfinfo.format) ;
562 exit (1) ;
563 } ;
564
565 if (sfinfo.frames != items)
566 { printf ("\n\nLine %d: Incorrect number of frames in file. (%d => %ld)\n", __LINE__, items, SF_COUNT_TO_LONG (sfinfo.frames)) ;
567 exit (1) ;
568 } ;
569
570 if (sfinfo.channels != 1)
571 { printf ("\n\nLine %d: Incorrect number of channels in file.\n", __LINE__) ;
572 exit (1) ;
573 } ;
574
575 check_log_buffer_or_die (file, __LINE__) ;
576
577 sf_command (file, SFC_SET_NORM_FLOAT, NULL, SF_FALSE) ;
578
579 test_read_float_or_die (file, 0, float_in, items, __LINE__) ;
580
581 for (k = 0 ; k < items ; k++)
582 if (fabs (float_out [k] - float_in [k]) > 1e-10)
583 { printf ("\n\nLine %d: float : Incorrect sample (#%d : %f => %f).\n", __LINE__, k, (double) float_out [k], (double) float_in [k]) ;
584 exit (1) ;
585 } ;
586
587 sf_close (file) ;
588
589 /*--------------------------------------------------------------------------
590 ** Test sf_read/write_double ()
591 */
592 zero_count = 0 ;
593
594 double_out = data_out.d ;
595 double_in = data_in.d ;
596 for (k = 0 ; k < items ; k++)
597 { double_out [k] = (k * ((k % 2) ? 3 : -3)) ;
598 zero_count = (fabs (double_out [k]) > 1e-10) ? zero_count : zero_count + 1 ;
599 } ;
600
601 if (zero_count > items / 4)
602 { printf ("\n\nLine %d: too many zeros (%d/%d).\n", __LINE__, zero_count, items) ;
603 exit (1) ;
604 } ;
605
606 sfinfo.samplerate = 44100 ;
607 sfinfo.frames = 123456789 ; /* Wrong length. Library should correct this on sf_close. */
608 sfinfo.channels = 1 ;
609 sfinfo.format = filetype ;
610
611 file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
612
613 sf_command (file, SFC_SET_NORM_DOUBLE, NULL, SF_FALSE) ;
614
615 test_write_double_or_die (file, 0, double_out, items, __LINE__) ;
616
617 sf_close (file) ;
618
619 memset (double_in, 0, items * sizeof (double)) ;
620
621 file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
622
623 if (sfinfo.format != filetype)
624 { printf ("\n\nLine %d: Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__, filetype, sfinfo.format) ;
625 exit (1) ;
626 } ;
627
628 if (sfinfo.frames != items)
629 { printf ("\n\nLine %d: Incorrect number of frames in file. (%d => %ld)\n", __LINE__, items, SF_COUNT_TO_LONG (sfinfo.frames)) ;
630 exit (1) ;
631 } ;
632
633 if (sfinfo.channels != 1)
634 { printf ("\n\nLine %d: Incorrect number of channels in file.\n", __LINE__) ;
635 exit (1) ;
636 } ;
637
638 check_log_buffer_or_die (file, __LINE__) ;
639
640 sf_command (file, SFC_SET_NORM_DOUBLE, NULL, SF_FALSE) ;
641
642 test_read_double_or_die (file, 0, double_in, items, __LINE__) ;
643
644 for (k = 0 ; k < items ; k++)
645 if (fabs (double_out [k] - double_in [k]) > 1e-10)
646 { printf ("\n\nLine %d: double : Incorrect sample (#%d : %f => %f).\n", __LINE__, k, double_out [k], double_in [k]) ;
647 exit (1) ;
648 } ;
649
650 sf_close (file) ;
651 /* Lite remove end */
652 unlink (filename) ;
653
654 puts ("ok") ;
655 } /* pcm_test_bits_16 */
656
657 static void
658 pcm_test_bits_24 (const char *filename, int filetype, uint64_t hash)
659 { SNDFILE *file ;
660 SF_INFO sfinfo ;
661 int k, items, zero_count ;
662 short *short_out, *short_in ;
663 int *int_out, *int_in ;
664 /* Lite remove start */
665 float *float_out, *float_in ;
666 double *double_out, *double_in ;
667 /* Lite remove end */
668
669 print_test_name ("pcm_test_bits_24", filename) ;
670
671 items = 1024 ;
672
673 short_out = data_out.s ;
674 short_in = data_in.s ;
675
676 zero_count = 0 ;
677 for (k = 0 ; k < items ; k++)
678 { short_out [k] = (k * ((k % 2) ? 3 : -3)) ;
679 zero_count = short_out [k] ? zero_count : zero_count + 1 ;
680 } ;
681
682 if (zero_count > items / 4)
683 { printf ("\n\nLine %d: too many zeros.\n", __LINE__) ;
684 exit (1) ;
685 } ;
686
687 sfinfo.samplerate = 44100 ;
688 sfinfo.frames = 123456789 ; /* Wrong length. Library should correct this on sf_close. */
689 sfinfo.channels = 1 ;
690 sfinfo.format = filetype ;
691
692 file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
693
694 test_write_short_or_die (file, 0, short_out, items, __LINE__) ;
695
696 sf_close (file) ;
697
698 memset (short_in, 0, items * sizeof (short)) ;
699
700 file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
701
702 if (sfinfo.format != filetype)
703 { printf ("\n\nLine %d: Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__, filetype, sfinfo.format) ;
704 exit (1) ;
705 } ;
706
707 if (sfinfo.frames != items)
708 { printf ("\n\nLine %d: Incorrect number of frames in file. (%d => %ld)\n", __LINE__, items, SF_COUNT_TO_LONG (sfinfo.frames)) ;
709 exit (1) ;
710 } ;
711
712 if (sfinfo.channels != 1)
713 { printf ("\n\nLine %d: Incorrect number of channels in file.\n", __LINE__) ;
714 exit (1) ;
715 } ;
716
717 check_log_buffer_or_die (file, __LINE__) ;
718
719 test_read_short_or_die (file, 0, short_in, items, __LINE__) ;
720
721 for (k = 0 ; k < items ; k++)
722 if (short_out [k] != short_in [k])
723 { printf ("\n\nLine %d: Incorrect sample (#%d : 0x%x => 0x%x).\n", __LINE__, k, short_out [k], short_in [k]) ;
724 exit (1) ;
725 } ;
726
727 sf_close (file) ;
728
729 /* Finally, check the file hash. */
730 check_file_hash_or_die (filename, hash, __LINE__) ;
731
732 /*--------------------------------------------------------------------------
733 ** Test sf_read/write_int ()
734 */
735 zero_count = 0 ;
736
737 int_out = data_out.i ;
738 int_in = data_in.i ;
739 for (k = 0 ; k < items ; k++)
740 { int_out [k] = ((k * ((k % 2) ? 3333 : -3333)) << 8) ;
741 zero_count = int_out [k] ? zero_count : zero_count + 1 ;
742 } ;
743
744 if (zero_count > items / 4)
745 { printf ("\n\nLine %d: too many zeros.\n", __LINE__) ;
746 exit (1) ;
747 } ;
748
749 sfinfo.samplerate = 44100 ;
750 sfinfo.frames = 123456789 ; /* Wrong length. Library should correct this on sf_close. */
751 sfinfo.channels = 1 ;
752 sfinfo.format = filetype ;
753
754 file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
755
756 test_write_int_or_die (file, 0, int_out, items, __LINE__) ;
757
758 sf_close (file) ;
759
760 memset (int_in, 0, items * sizeof (int)) ;
761
762 file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
763
764 if (sfinfo.format != filetype)
765 { printf ("\n\nLine %d: Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__, filetype, sfinfo.format) ;
766 exit (1) ;
767 } ;
768
769 if (sfinfo.frames != items)
770 { printf ("\n\nLine %d: Incorrect number of frames in file. (%d => %ld)\n", __LINE__, items, SF_COUNT_TO_LONG (sfinfo.frames)) ;
771 exit (1) ;
772 } ;
773
774 if (sfinfo.channels != 1)
775 { printf ("\n\nLine %d: Incorrect number of channels in file.\n", __LINE__) ;
776 exit (1) ;
777 } ;
778
779 check_log_buffer_or_die (file, __LINE__) ;
780
781 test_read_int_or_die (file, 0, int_in, items, __LINE__) ;
782
783 for (k = 0 ; k < items ; k++)
784 if (int_out [k] != int_in [k])
785 { printf ("\n\nLine %d: int : Incorrect sample (#%d : 0x%x => 0x%x).\n", __LINE__, k, int_out [k], int_in [k]) ;
786 exit (1) ;
787 } ;
788
789 sf_close (file) ;
790
791 /* Lite remove start */
792 /*--------------------------------------------------------------------------
793 ** Test sf_read/write_float ()
794 */
795 zero_count = 0 ;
796
797 float_out = data_out.f ;
798 float_in = data_in.f ;
799 for (k = 0 ; k < items ; k++)
800 { float_out [k] = (k * ((k % 2) ? 3333 : -3333)) ;
801 zero_count = (fabs (float_out [k]) > 1e-10) ? zero_count : zero_count + 1 ;
802 } ;
803
804 if (zero_count > items / 4)
805 { printf ("\n\nLine %d: too many zeros (%d/%d).\n", __LINE__, zero_count, items) ;
806 exit (1) ;
807 } ;
808
809 sfinfo.samplerate = 44100 ;
810 sfinfo.frames = 123456789 ; /* Wrong length. Library should correct this on sf_close. */
811 sfinfo.channels = 1 ;
812 sfinfo.format = filetype ;
813
814 file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
815
816 sf_command (file, SFC_SET_NORM_FLOAT, NULL, SF_FALSE) ;
817
818 test_write_float_or_die (file, 0, float_out, items, __LINE__) ;
819
820 sf_close (file) ;
821
822 memset (float_in, 0, items * sizeof (float)) ;
823
824 file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
825
826 if (sfinfo.format != filetype)
827 { printf ("\n\nLine %d: Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__, filetype, sfinfo.format) ;
828 exit (1) ;
829 } ;
830
831 if (sfinfo.frames != items)
832 { printf ("\n\nLine %d: Incorrect number of frames in file. (%d => %ld)\n", __LINE__, items, SF_COUNT_TO_LONG (sfinfo.frames)) ;
833 exit (1) ;
834 } ;
835
836 if (sfinfo.channels != 1)
837 { printf ("\n\nLine %d: Incorrect number of channels in file.\n", __LINE__) ;
838 exit (1) ;
839 } ;
840
841 check_log_buffer_or_die (file, __LINE__) ;
842
843 sf_command (file, SFC_SET_NORM_FLOAT, NULL, SF_FALSE) ;
844
845 test_read_float_or_die (file, 0, float_in, items, __LINE__) ;
846
847 for (k = 0 ; k < items ; k++)
848 if (fabs (float_out [k] - float_in [k]) > 1e-10)
849 { printf ("\n\nLine %d: float : Incorrect sample (#%d : %f => %f).\n", __LINE__, k, (double) float_out [k], (double) float_in [k]) ;
850 exit (1) ;
851 } ;
852
853 sf_close (file) ;
854
855 /*--------------------------------------------------------------------------
856 ** Test sf_read/write_double ()
857 */
858 zero_count = 0 ;
859
860 double_out = data_out.d ;
861 double_in = data_in.d ;
862 for (k = 0 ; k < items ; k++)
863 { double_out [k] = (k * ((k % 2) ? 3333 : -3333)) ;
864 zero_count = (fabs (double_out [k]) > 1e-10) ? zero_count : zero_count + 1 ;
865 } ;
866
867 if (zero_count > items / 4)
868 { printf ("\n\nLine %d: too many zeros (%d/%d).\n", __LINE__, zero_count, items) ;
869 exit (1) ;
870 } ;
871
872 sfinfo.samplerate = 44100 ;
873 sfinfo.frames = 123456789 ; /* Wrong length. Library should correct this on sf_close. */
874 sfinfo.channels = 1 ;
875 sfinfo.format = filetype ;
876
877 file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
878
879 sf_command (file, SFC_SET_NORM_DOUBLE, NULL, SF_FALSE) ;
880
881 test_write_double_or_die (file, 0, double_out, items, __LINE__) ;
882
883 sf_close (file) ;
884
885 memset (double_in, 0, items * sizeof (double)) ;
886
887 file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
888
889 if (sfinfo.format != filetype)
890 { printf ("\n\nLine %d: Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__, filetype, sfinfo.format) ;
891 exit (1) ;
892 } ;
893
894 if (sfinfo.frames != items)
895 { printf ("\n\nLine %d: Incorrect number of frames in file. (%d => %ld)\n", __LINE__, items, SF_COUNT_TO_LONG (sfinfo.frames)) ;
896 exit (1) ;
897 } ;
898
899 if (sfinfo.channels != 1)
900 { printf ("\n\nLine %d: Incorrect number of channels in file.\n", __LINE__) ;
901 exit (1) ;
902 } ;
903
904 check_log_buffer_or_die (file, __LINE__) ;
905
906 sf_command (file, SFC_SET_NORM_DOUBLE, NULL, SF_FALSE) ;
907
908 test_read_double_or_die (file, 0, double_in, items, __LINE__) ;
909
910 for (k = 0 ; k < items ; k++)
911 if (fabs (double_out [k] - double_in [k]) > 1e-10)
912 { printf ("\n\nLine %d: double : Incorrect sample (#%d : %f => %f).\n", __LINE__, k, double_out [k], double_in [k]) ;
913 exit (1) ;
914 } ;
915
916 sf_close (file) ;
917 /* Lite remove end */
918 unlink (filename) ;
919
920 puts ("ok") ;
921 } /* pcm_test_bits_24 */
922
923 static void
924 pcm_test_bits_32 (const char *filename, int filetype, uint64_t hash)
925 { SNDFILE *file ;
926 SF_INFO sfinfo ;
927 int k, items, zero_count ;
928 short *short_out, *short_in ;
929 int *int_out, *int_in ;
930 /* Lite remove start */
931 float *float_out, *float_in ;
932 double *double_out, *double_in ;
933 /* Lite remove end */
934
935 print_test_name ("pcm_test_bits_32", filename) ;
936
937 items = 1024 ;
938
939 short_out = data_out.s ;
940 short_in = data_in.s ;
941
942 zero_count = 0 ;
943 for (k = 0 ; k < items ; k++)
944 { short_out [k] = (k * ((k % 2) ? 3 : -3)) ;
945 zero_count = short_out [k] ? zero_count : zero_count + 1 ;
946 } ;
947
948 if (zero_count > items / 4)
949 { printf ("\n\nLine %d: too many zeros.\n", __LINE__) ;
950 exit (1) ;
951 } ;
952
953 sfinfo.samplerate = 44100 ;
954 sfinfo.frames = 123456789 ; /* Wrong length. Library should correct this on sf_close. */
955 sfinfo.channels = 1 ;
956 sfinfo.format = filetype ;
957
958 file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
959
960 test_write_short_or_die (file, 0, short_out, items, __LINE__) ;
961
962 sf_close (file) ;
963
964 memset (short_in, 0, items * sizeof (short)) ;
965
966 file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
967
968 if (sfinfo.format != filetype)
969 { printf ("\n\nLine %d: Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__, filetype, sfinfo.format) ;
970 exit (1) ;
971 } ;
972
973 if (sfinfo.frames != items)
974 { printf ("\n\nLine %d: Incorrect number of frames in file. (%d => %ld)\n", __LINE__, items, SF_COUNT_TO_LONG (sfinfo.frames)) ;
975 exit (1) ;
976 } ;
977
978 if (sfinfo.channels != 1)
979 { printf ("\n\nLine %d: Incorrect number of channels in file.\n", __LINE__) ;
980 exit (1) ;
981 } ;
982
983 check_log_buffer_or_die (file, __LINE__) ;
984
985 test_read_short_or_die (file, 0, short_in, items, __LINE__) ;
986
987 for (k = 0 ; k < items ; k++)
988 if (short_out [k] != short_in [k])
989 { printf ("\n\nLine %d: Incorrect sample (#%d : 0x%x => 0x%x).\n", __LINE__, k, short_out [k], short_in [k]) ;
990 exit (1) ;
991 } ;
992
993 sf_close (file) ;
994
995 /* Finally, check the file hash. */
996 check_file_hash_or_die (filename, hash, __LINE__) ;
997
998 /*--------------------------------------------------------------------------
999 ** Test sf_read/write_int ()
1000 */
1001 zero_count = 0 ;
1002
1003 int_out = data_out.i ;
1004 int_in = data_in.i ;
1005 for (k = 0 ; k < items ; k++)
1006 { int_out [k] = (k * ((k % 2) ? 333333 : -333333)) ;
1007 zero_count = int_out [k] ? zero_count : zero_count + 1 ;
1008 } ;
1009
1010 if (zero_count > items / 4)
1011 { printf ("\n\nLine %d: too many zeros.\n", __LINE__) ;
1012 exit (1) ;
1013 } ;
1014
1015 sfinfo.samplerate = 44100 ;
1016 sfinfo.frames = 123456789 ; /* Wrong length. Library should correct this on sf_close. */
1017 sfinfo.channels = 1 ;
1018 sfinfo.format = filetype ;
1019
1020 file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
1021
1022 test_write_int_or_die (file, 0, int_out, items, __LINE__) ;
1023
1024 sf_close (file) ;
1025
1026 memset (int_in, 0, items * sizeof (int)) ;
1027
1028 file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
1029
1030 if (sfinfo.format != filetype)
1031 { printf ("\n\nLine %d: Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__, filetype, sfinfo.format) ;
1032 exit (1) ;
1033 } ;
1034
1035 if (sfinfo.frames != items)
1036 { printf ("\n\nLine %d: Incorrect number of frames in file. (%d => %ld)\n", __LINE__, items, SF_COUNT_TO_LONG (sfinfo.frames)) ;
1037 exit (1) ;
1038 } ;
1039
1040 if (sfinfo.channels != 1)
1041 { printf ("\n\nLine %d: Incorrect number of channels in file.\n", __LINE__) ;
1042 exit (1) ;
1043 } ;
1044
1045 check_log_buffer_or_die (file, __LINE__) ;
1046
1047 test_read_int_or_die (file, 0, int_in, items, __LINE__) ;
1048
1049 for (k = 0 ; k < items ; k++)
1050 if (int_out [k] != int_in [k])
1051 { printf ("\n\nLine %d: int : Incorrect sample (#%d : 0x%x => 0x%x).\n", __LINE__, k, int_out [k], int_in [k]) ;
1052 exit (1) ;
1053 } ;
1054
1055 sf_close (file) ;
1056
1057 /* Lite remove start */
1058 /*--------------------------------------------------------------------------
1059 ** Test sf_read/write_float ()
1060 */
1061 zero_count = 0 ;
1062
1063 float_out = data_out.f ;
1064 float_in = data_in.f ;
1065 for (k = 0 ; k < items ; k++)
1066 { float_out [k] = (k * ((k % 2) ? 333333 : -333333)) ;
1067 zero_count = (fabs (float_out [k]) > 1e-10) ? zero_count : zero_count + 1 ;
1068 } ;
1069
1070 if (zero_count > items / 4)
1071 { printf ("\n\nLine %d: too many zeros (%d/%d).\n", __LINE__, zero_count, items) ;
1072 exit (1) ;
1073 } ;
1074
1075 sfinfo.samplerate = 44100 ;
1076 sfinfo.frames = 123456789 ; /* Wrong length. Library should correct this on sf_close. */
1077 sfinfo.channels = 1 ;
1078 sfinfo.format = filetype ;
1079
1080 file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
1081
1082 sf_command (file, SFC_SET_NORM_FLOAT, NULL, SF_FALSE) ;
1083
1084 test_write_float_or_die (file, 0, float_out, items, __LINE__) ;
1085
1086 sf_close (file) ;
1087
1088 memset (float_in, 0, items * sizeof (float)) ;
1089
1090 file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
1091
1092 if (sfinfo.format != filetype)
1093 { printf ("\n\nLine %d: Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__, filetype, sfinfo.format) ;
1094 exit (1) ;
1095 } ;
1096
1097 if (sfinfo.frames != items)
1098 { printf ("\n\nLine %d: Incorrect number of frames in file. (%d => %ld)\n", __LINE__, items, SF_COUNT_TO_LONG (sfinfo.frames)) ;
1099 exit (1) ;
1100 } ;
1101
1102 if (sfinfo.channels != 1)
1103 { printf ("\n\nLine %d: Incorrect number of channels in file.\n", __LINE__) ;
1104 exit (1) ;
1105 } ;
1106
1107 check_log_buffer_or_die (file, __LINE__) ;
1108
1109 sf_command (file, SFC_SET_NORM_FLOAT, NULL, SF_FALSE) ;
1110
1111 test_read_float_or_die (file, 0, float_in, items, __LINE__) ;
1112
1113 for (k = 0 ; k < items ; k++)
1114 if (fabs (float_out [k] - float_in [k]) > 1e-10)
1115 { printf ("\n\nLine %d: float : Incorrect sample (#%d : %f => %f).\n", __LINE__, k, (double) float_out [k], (double) float_in [k]) ;
1116 exit (1) ;
1117 } ;
1118
1119 sf_close (file) ;
1120
1121 /*--------------------------------------------------------------------------
1122 ** Test sf_read/write_double ()
1123 */
1124 zero_count = 0 ;
1125
1126 double_out = data_out.d ;
1127 double_in = data_in.d ;
1128 for (k = 0 ; k < items ; k++)
1129 { double_out [k] = (k * ((k % 2) ? 333333 : -333333)) ;
1130 zero_count = (fabs (double_out [k]) > 1e-10) ? zero_count : zero_count + 1 ;
1131 } ;
1132
1133 if (zero_count > items / 4)
1134 { printf ("\n\nLine %d: too many zeros (%d/%d).\n", __LINE__, zero_count, items) ;
1135 exit (1) ;
1136 } ;
1137
1138 sfinfo.samplerate = 44100 ;
1139 sfinfo.frames = 123456789 ; /* Wrong length. Library should correct this on sf_close. */
1140 sfinfo.channels = 1 ;
1141 sfinfo.format = filetype ;
1142
1143 file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
1144
1145 sf_command (file, SFC_SET_NORM_DOUBLE, NULL, SF_FALSE) ;
1146
1147 test_write_double_or_die (file, 0, double_out, items, __LINE__) ;
1148
1149 sf_close (file) ;
1150
1151 memset (double_in, 0, items * sizeof (double)) ;
1152
1153 file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
1154
1155 if (sfinfo.format != filetype)
1156 { printf ("\n\nLine %d: Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__, filetype, sfinfo.format) ;
1157 exit (1) ;
1158 } ;
1159
1160 if (sfinfo.frames != items)
1161 { printf ("\n\nLine %d: Incorrect number of frames in file. (%d => %ld)\n", __LINE__, items, SF_COUNT_TO_LONG (sfinfo.frames)) ;
1162 exit (1) ;
1163 } ;
1164
1165 if (sfinfo.channels != 1)
1166 { printf ("\n\nLine %d: Incorrect number of channels in file.\n", __LINE__) ;
1167 exit (1) ;
1168 } ;
1169
1170 check_log_buffer_or_die (file, __LINE__) ;
1171
1172 sf_command (file, SFC_SET_NORM_DOUBLE, NULL, SF_FALSE) ;
1173
1174 test_read_double_or_die (file, 0, double_in, items, __LINE__) ;
1175
1176 for (k = 0 ; k < items ; k++)
1177 if (fabs (double_out [k] - double_in [k]) > 1e-10)
1178 { printf ("\n\nLine %d: double : Incorrect sample (#%d : %f => %f).\n", __LINE__, k, double_out [k], double_in [k]) ;
1179 exit (1) ;
1180 } ;
1181
1182 sf_close (file) ;
1183 /* Lite remove end */
1184 unlink (filename) ;
1185
1186 puts ("ok") ;
1187 } /* pcm_test_bits_32 */
1188
1189
1190
1191 /*==============================================================================
1192 */
1193
1194 static void
1195 pcm_test_float (const char *filename, int filetype, uint64_t hash, int replace_float)
1196 { SNDFILE *file ;
1197 SF_INFO sfinfo ;
1198 int k, items, frames ;
1199 int sign ;
1200 double *data, error ;
1201
1202 print_test_name (replace_float ? "pcm_test_float (replace)" : "pcm_test_float", filename) ;
1203
1204 items = BUFFER_SIZE ;
1205
1206 data = data_out.d ;
1207 for (sign = 1, k = 0 ; k < items ; k++)
1208 { data [k] = ((double) (k * sign)) / 100.0 ;
1209 sign = (sign > 0) ? -1 : 1 ;
1210 } ;
1211
1212 sfinfo.samplerate = 44100 ;
1213 sfinfo.frames = items ;
1214 sfinfo.channels = 1 ;
1215 sfinfo.format = filetype ;
1216
1217 file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
1218 sf_command (file, SFC_TEST_IEEE_FLOAT_REPLACE, NULL, replace_float) ;
1219 if (replace_float && string_in_log_buffer (file, "Using IEEE replacement") == 0)
1220 { printf ("\n\nLine %d : Float replacement code not working.\n\n", __LINE__) ;
1221 dump_log_buffer (file) ;
1222 exit (1) ;
1223 } ;
1224
1225 test_write_double_or_die (file, 0, data, items, __LINE__) ;
1226
1227 sf_close (file) ;
1228
1229 check_file_hash_or_die (filename, hash, __LINE__) ;
1230
1231 memset (data, 0, items * sizeof (double)) ;
1232
1233 if ((filetype & SF_FORMAT_TYPEMASK) != SF_FORMAT_RAW)
1234 memset (&sfinfo, 0, sizeof (sfinfo)) ;
1235
1236 file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
1237 sf_command (file, SFC_TEST_IEEE_FLOAT_REPLACE, NULL, replace_float) ;
1238 if (replace_float && string_in_log_buffer (file, "Using IEEE replacement") == 0)
1239 { printf ("\n\nLine %d : Float replacement code not working.\n\n", __LINE__) ;
1240 dump_log_buffer (file) ;
1241 exit (1) ;
1242 } ;
1243
1244 if (sfinfo.format != filetype)
1245 { printf ("\n\nError (%s:%d) Mono : Returned format incorrect (0x%08X => 0x%08X).\n", __FILE__, __LINE__, filetype, sfinfo.format) ;
1246 exit (1) ;
1247 } ;
1248
1249 if (sfinfo.frames != items)
1250 { printf ("\n\nError (%s:%d) Mono : Incorrect number of frames in file. (%d => %ld)\n", __FILE__, __LINE__, items, SF_COUNT_TO_LONG (sfinfo.frames)) ;
1251 exit (1) ;
1252 } ;
1253
1254 if (sfinfo.channels != 1)
1255 { printf ("\n\nError (%s:%d) Mono : Incorrect number of channels in file.\n", __FILE__, __LINE__) ;
1256 exit (1) ;
1257 } ;
1258
1259 check_log_buffer_or_die (file, __LINE__) ;
1260
1261 test_read_double_or_die (file, 0, data, items, __LINE__) ;
1262
1263 for (sign = -1, k = 0 ; k < items ; k++)
1264 { error = fabs (data [k] - ((double) k) / 100.0 * (sign *= -1)) ;
1265 if (fabs (data [k]) > 1e-100 && fabs (error / data [k]) > 1e-5)
1266 { printf ("\n\nError (%s:%d) Mono : Incorrect sample (#%d : %f => %f).\n", __FILE__, __LINE__, k, ((double) k) / 100.0, data [k]) ;
1267 exit (1) ;
1268 } ;
1269 } ;
1270
1271 /* Seek to start of file. */
1272 test_seek_or_die (file, 0, SEEK_SET, 0, sfinfo.channels, __LINE__) ;
1273
1274 test_read_double_or_die (file, 0, data, 4, __LINE__) ;
1275 for (k = 0 ; k < 4 ; k++)
1276 { error = fabs (data [k] - ((double) k) / 100.0 * (sign *= -1)) ;
1277 if (fabs (data [k]) > 1e-100 && fabs (error / data [k]) > 1e-5)
1278 { printf ("\n\nError (%s:%d) Mono : Incorrect sample (#%d : %f => %f).\n", __FILE__, __LINE__, k, ((double) k) / 100.0, data [k]) ;
1279 exit (1) ;
1280 } ;
1281 } ;
1282
1283 /* Seek to offset from start of file. */
1284 test_seek_or_die (file, 10, SEEK_SET, 10, sfinfo.channels, __LINE__) ;
1285
1286 test_read_double_or_die (file, 0, data + 10, 4, __LINE__) ;
1287 for (k = 10 ; k < 14 ; k++)
1288 { error = fabs (data [k] - ((double) k) / 100.0 * (sign *= -1)) ;
1289 if (fabs (data [k]) > 1e-100 && fabs (error / data [k]) > 1e-5)
1290 { printf ("\n\nError (%s:%d) Mono : Incorrect sample (#%d : %f => %f).\n", __FILE__, __LINE__, k, ((double) k) / 100.0, data [k]) ;
1291 exit (1) ;
1292 } ;
1293 } ;
1294
1295 /* Seek to offset from current position. */
1296 test_seek_or_die (file, 6, SEEK_CUR, 20, sfinfo.channels, __LINE__) ;
1297
1298 test_read_double_or_die (file, 0, data + 20, 4, __LINE__) ;
1299 for (k = 20 ; k < 24 ; k++)
1300 { error = fabs (data [k] - ((double) k) / 100.0 * (sign *= -1)) ;
1301 if (fabs (data [k]) > 1e-100 && fabs (error / data [k]) > 1e-5)
1302 { printf ("\n\nError (%s:%d) Mono : Incorrect sample (#%d : %f => %f).\n", __FILE__, __LINE__, k, ((double) k) / 100.0, data [k]) ;
1303 exit (1) ;
1304 } ;
1305 } ;
1306
1307 /* Seek to offset from end of file. */
1308 test_seek_or_die (file, -1 * (sfinfo.frames - 10), SEEK_END, 10, sfinfo.channels, __LINE__) ;
1309
1310 test_read_double_or_die (file, 0, data + 10, 4, __LINE__) ;
1311 for (k = 10 ; k < 14 ; k++)
1312 { error = fabs (data [k] - ((double) k) / 100.0 * (sign *= -1)) ;
1313 if (fabs (data [k]) > 1e-100 && fabs (error / data [k]) > 1e-5)
1314 { printf ("\n\nError (%s:%d) Mono : Incorrect sample (#%d : %f => %f).\n", __FILE__, __LINE__, k, ((double) k) / 100.0, data [k]) ;
1315 exit (1) ;
1316 } ;
1317 } ;
1318
1319 sf_close (file) ;
1320
1321 /* Now test Stereo. */
1322
1323 if ((filetype & SF_FORMAT_TYPEMASK) == SF_FORMAT_SVX) /* SVX is mono only */
1324 { printf ("ok\n") ;
1325 return ;
1326 } ;
1327
1328 items = BUFFER_SIZE ;
1329
1330 data = data_out.d ;
1331 for (sign = -1, k = 0 ; k < items ; k++)
1332 data [k] = ((double) k) / 100.0 * (sign *= -1) ;
1333
1334 sfinfo.samplerate = 44100 ;
1335 sfinfo.frames = items ;
1336 sfinfo.channels = 2 ;
1337 sfinfo.format = filetype ;
1338
1339 frames = items / sfinfo.channels ;
1340
1341 file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
1342 sf_command (file, SFC_TEST_IEEE_FLOAT_REPLACE, NULL, replace_float) ;
1343 if (replace_float && string_in_log_buffer (file, "Using IEEE replacement") == 0)
1344 { printf ("\n\nLine %d : Float replacement code not working.\n\n", __LINE__) ;
1345 dump_log_buffer (file) ;
1346 exit (1) ;
1347 } ;
1348
1349 test_writef_double_or_die (file, 0, data, frames, __LINE__) ;
1350
1351 sf_close (file) ;
1352
1353 check_file_hash_or_die (filename, hash, __LINE__) ;
1354
1355 memset (data, 0, items * sizeof (double)) ;
1356
1357 if ((filetype & SF_FORMAT_TYPEMASK) != SF_FORMAT_RAW)
1358 memset (&sfinfo, 0, sizeof (sfinfo)) ;
1359
1360 file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
1361 sf_command (file, SFC_TEST_IEEE_FLOAT_REPLACE, NULL, replace_float) ;
1362 if (replace_float && string_in_log_buffer (file, "Using IEEE replacement") == 0)
1363 { printf ("\n\nLine %d : Float replacement code not working.\n\n", __LINE__) ;
1364 dump_log_buffer (file) ;
1365 exit (1) ;
1366 } ;
1367
1368 if (sfinfo.format != filetype)
1369 { printf ("\n\nError (%s:%d) Stereo : Returned format incorrect (0x%08X => 0x%08X).\n", __FILE__, __LINE__, filetype, sfinfo.format) ;
1370 exit (1) ;
1371 } ;
1372
1373 if (sfinfo.frames != frames)
1374 { printf ("\n\nError (%s:%d) Stereo : Incorrect number of frames in file. (%d => %ld)\n", __FILE__, __LINE__, frames, SF_COUNT_TO_LONG (sfinfo.frames)) ;
1375 exit (1) ;
1376 } ;
1377
1378 if (sfinfo.channels != 2)
1379 { printf ("\n\nError (%s:%d) Stereo : Incorrect number of channels in file.\n", __FILE__, __LINE__) ;
1380 exit (1) ;
1381 } ;
1382
1383 check_log_buffer_or_die (file, __LINE__) ;
1384
1385 test_readf_double_or_die (file, 0, data, frames, __LINE__) ;
1386 for (sign = -1, k = 0 ; k < items ; k++)
1387 { error = fabs (data [k] - ((double) k) / 100.0 * (sign *= -1)) ;
1388 if (fabs (data [k]) > 1e-100 && fabs (error / data [k]) > 1e-5)
1389 { printf ("\n\nError (%s:%d) Stereo : Incorrect sample (#%d : %f => %f).\n", __FILE__, __LINE__, k, ((double) k) / 100.0, data [k]) ;
1390 exit (1) ;
1391 } ;
1392 } ;
1393
1394 /* Seek to start of file. */
1395 test_seek_or_die (file, 0, SEEK_SET, 0, sfinfo.channels, __LINE__) ;
1396
1397 test_readf_double_or_die (file, 0, data, 4, __LINE__) ;
1398 for (k = 0 ; k < 4 ; k++)
1399 { error = fabs (data [k] - ((double) k) / 100.0 * (sign *= -1)) ;
1400 if (fabs (data [k]) > 1e-100 && fabs (error / data [k]) > 1e-5)
1401 { printf ("\n\nError (%s:%d) Stereo : Incorrect sample (#%d : %f => %f).\n", __FILE__, __LINE__, k, ((double) k) / 100.0, data [k]) ;
1402 exit (1) ;
1403 } ;
1404 } ;
1405
1406 /* Seek to offset from start of file. */
1407 test_seek_or_die (file, 10, SEEK_SET, 10, sfinfo.channels, __LINE__) ;
1408
1409 test_readf_double_or_die (file, 0, data + 20, 2, __LINE__) ;
1410 for (k = 20 ; k < 24 ; k++)
1411 { error = fabs (data [k] - ((double) k) / 100.0 * (sign *= -1)) ;
1412 if (fabs (data [k]) > 1e-100 && fabs (error / data [k]) > 1e-5)
1413 { printf ("\n\nError (%s:%d) Stereo : Incorrect sample (#%d : %f => %f).\n", __FILE__, __LINE__, k, ((double) k) / 100.0, data [k]) ;
1414 exit (1) ;
1415 } ;
1416 } ;
1417
1418 /* Seek to offset from current position. */
1419 test_seek_or_die (file, 8, SEEK_CUR, 20, sfinfo.channels, __LINE__) ;
1420
1421 test_readf_double_or_die (file, 0, data + 40, 2, __LINE__) ;
1422 for (k = 40 ; k < 44 ; k++)
1423 { error = fabs (data [k] - ((double) k) / 100.0 * (sign *= -1)) ;
1424 if (fabs (data [k]) > 1e-100 && fabs (error / data [k]) > 1e-5)
1425 { printf ("\n\nError (%s:%d) Stereo : Incorrect sample (#%d : %f => %f).\n", __FILE__, __LINE__, k, ((double) k) / 100.0, data [k]) ;
1426 exit (1) ;
1427 } ;
1428 } ;
1429
1430 /* Seek to offset from end of file. */
1431 test_seek_or_die (file, -1 * (sfinfo.frames - 10), SEEK_END, 10, sfinfo.channels, __LINE__) ;
1432
1433 test_readf_double_or_die (file, 0, data + 20, 2, __LINE__) ;
1434 for (k = 20 ; k < 24 ; k++)
1435 { error = fabs (data [k] - ((double) k) / 100.0 * (sign *= -1)) ;
1436 if (fabs (data [k]) > 1e-100 && fabs (error / data [k]) > 1e-5)
1437 { printf ("\n\nError (%s:%d) Stereo : Incorrect sample (#%d : %f => %f).\n", __FILE__, __LINE__, k, ((double) k) / 100.0, data [k]) ;
1438 exit (1) ;
1439 } ;
1440 } ;
1441
1442 sf_close (file) ;
1443
1444 printf ("ok\n") ;
1445 unlink (filename) ;
1446 } /* pcm_test_float */
1447
1448 static void
1449 pcm_test_double (const char *filename, int filetype, uint64_t hash, int replace_float)
1450 { SNDFILE *file ;
1451 SF_INFO sfinfo ;
1452 int k, items, frames ;
1453 int sign ;
1454 double *data, error ;
1455
1456 /* This is the best test routine. Other should be brought up to this standard. */
1457
1458 print_test_name (replace_float ? "pcm_test_double (replace)" : "pcm_test_double", filename) ;
1459
1460 items = BUFFER_SIZE ;
1461
1462 data = data_out.d ;
1463 for (sign = 1, k = 0 ; k < items ; k++)
1464 { data [k] = ((double) (k * sign)) / 100.0 ;
1465 sign = (sign > 0) ? -1 : 1 ;
1466 } ;
1467
1468 sfinfo.samplerate = 44100 ;
1469 sfinfo.frames = items ;
1470 sfinfo.channels = 1 ;
1471 sfinfo.format = filetype ;
1472
1473 file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
1474 sf_command (file, SFC_TEST_IEEE_FLOAT_REPLACE, NULL, replace_float) ;
1475 if (replace_float && string_in_log_buffer (file, "Using IEEE replacement") == 0)
1476 { printf ("\n\nLine %d : Float replacement code not working.\n\n", __LINE__) ;
1477 dump_log_buffer (file) ;
1478 exit (1) ;
1479 } ;
1480
1481 test_write_double_or_die (file, 0, data, items, __LINE__) ;
1482
1483 sf_close (file) ;
1484
1485 #if (defined (WIN32) || defined (_WIN32))
1486 /* File hashing on Win32 fails due to slighty different
1487 ** calculated values of the sin() function.
1488 */
1489 hash = hash ; /* Avoid compiler warning. */
1490 #else
1491 check_file_hash_or_die (filename, hash, __LINE__) ;
1492 #endif
1493
1494 memset (data, 0, items * sizeof (double)) ;
1495
1496 if ((filetype & SF_FORMAT_TYPEMASK) != SF_FORMAT_RAW)
1497 memset (&sfinfo, 0, sizeof (sfinfo)) ;
1498
1499 file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
1500 sf_command (file, SFC_TEST_IEEE_FLOAT_REPLACE, NULL, replace_float) ;
1501 if (replace_float && string_in_log_buffer (file, "Using IEEE replacement") == 0)
1502 { printf ("\n\nLine %d : Float replacement code not working.\n\n", __LINE__) ;
1503 dump_log_buffer (file) ;
1504 exit (1) ;
1505 } ;
1506
1507 if (sfinfo.format != filetype)
1508 { printf ("\n\nError (%s:%d) Mono : Returned format incorrect (0x%08X => 0x%08X).\n", __FILE__, __LINE__, filetype, sfinfo.format) ;
1509 exit (1) ;
1510 } ;
1511
1512 if (sfinfo.frames != items)
1513 { printf ("\n\nError (%s:%d) Mono : Incorrect number of frames in file. (%d => %ld)\n", __FILE__, __LINE__, items, SF_COUNT_TO_LONG (sfinfo.frames)) ;
1514 exit (1) ;
1515 } ;
1516
1517 if (sfinfo.channels != 1)
1518 { printf ("\n\nError (%s:%d) Mono : Incorrect number of channels in file.\n", __FILE__, __LINE__) ;
1519 exit (1) ;
1520 } ;
1521
1522 check_log_buffer_or_die (file, __LINE__) ;
1523
1524 test_read_double_or_die (file, 0, data, items, __LINE__) ;
1525
1526 for (sign = -1, k = 0 ; k < items ; k++)
1527 { error = fabs (data [k] - ((double) k) / 100.0 * (sign *= -1)) ;
1528 if (fabs (data [k]) > 1e-100 && fabs (error / data [k]) > 1e-5)
1529 { printf ("\n\nError (%s:%d) Mono : Incorrect sample (#%d : %f => %f).\n", __FILE__, __LINE__, k, ((double) k) / 100.0, data [k]) ;
1530 exit (1) ;
1531 } ;
1532 } ;
1533
1534 /* Seek to start of file. */
1535 test_seek_or_die (file, 0, SEEK_SET, 0, sfinfo.channels, __LINE__) ;
1536
1537 test_read_double_or_die (file, 0, data, 4, __LINE__) ;
1538 for (k = 0 ; k < 4 ; k++)
1539 { error = fabs (data [k] - ((double) k) / 100.0 * (sign *= -1)) ;
1540 if (fabs (data [k]) > 1e-100 && fabs (error / data [k]) > 1e-5)
1541 { printf ("\n\nError (%s:%d) Mono : Incorrect sample (#%d : %f => %f).\n", __FILE__, __LINE__, k, ((double) k) / 100.0, data [k]) ;
1542 exit (1) ;
1543 } ;
1544 } ;
1545
1546 /* Seek to offset from start of file. */
1547 test_seek_or_die (file, 10, SEEK_SET, 10, sfinfo.channels, __LINE__) ;
1548
1549 test_read_double_or_die (file, 0, data + 10, 4, __LINE__) ;
1550
1551 test_seek_or_die (file, 0, SEEK_CUR, 14, sfinfo.channels, __LINE__) ;
1552
1553 for (k = 10 ; k < 14 ; k++)
1554 { error = fabs (data [k] - ((double) k) / 100.0 * (sign *= -1)) ;
1555 if (fabs (data [k]) > 1e-100 && fabs (error / data [k]) > 1e-5)
1556 { printf ("\n\nError (%s:%d) Mono : Incorrect sample (#%d : %f => %f).\n", __FILE__, __LINE__, k, ((double) k) / 100.0, data [k]) ;
1557 exit (1) ;
1558 } ;
1559 } ;
1560
1561 /* Seek to offset from current position. */
1562 test_seek_or_die (file, 6, SEEK_CUR, 20, sfinfo.channels, __LINE__) ;
1563
1564 test_read_double_or_die (file, 0, data + 20, 4, __LINE__) ;
1565 for (k = 20 ; k < 24 ; k++)
1566 { error = fabs (data [k] - ((double) k) / 100.0 * (sign *= -1)) ;
1567 if (fabs (data [k]) > 1e-100 && fabs (error / data [k]) > 1e-5)
1568 { printf ("\n\nError (%s:%d) Mono : Incorrect sample (#%d : %f => %f).\n", __FILE__, __LINE__, k, ((double) k) / 100.0, data [k]) ;
1569 exit (1) ;
1570 } ;
1571 } ;
1572
1573 /* Seek to offset from end of file. */
1574 test_seek_or_die (file, -1 * (sfinfo.frames - 10), SEEK_END, 10, sfinfo.channels, __LINE__) ;
1575
1576 test_read_double_or_die (file, 0, data + 10, 4, __LINE__) ;
1577 for (k = 10 ; k < 14 ; k++)
1578 { error = fabs (data [k] - ((double) k) / 100.0 * (sign *= -1)) ;
1579 if (fabs (data [k]) > 1e-100 && fabs (error / data [k]) > 1e-5)
1580 { printf ("\n\nError (%s:%d) Mono : Incorrect sample (#%d : %f => %f).\n", __FILE__, __LINE__, k, ((double) k) / 100.0, data [k]) ;
1581 exit (1) ;
1582 } ;
1583 } ;
1584
1585 sf_close (file) ;
1586
1587 /* Now test Stereo. */
1588
1589 if ((filetype & SF_FORMAT_TYPEMASK) == SF_FORMAT_SVX) /* SVX is mono only */
1590 { printf ("ok\n") ;
1591 return ;
1592 } ;
1593
1594 items = BUFFER_SIZE ;
1595
1596 data = data_out.d ;
1597 for (sign = -1, k = 0 ; k < items ; k++)
1598 data [k] = ((double) k) / 100.0 * (sign *= -1) ;
1599
1600 sfinfo.samplerate = 44100 ;
1601 sfinfo.frames = items ;
1602 sfinfo.channels = 2 ;
1603 sfinfo.format = filetype ;
1604
1605 frames = items / sfinfo.channels ;
1606
1607 file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
1608 sf_command (file, SFC_TEST_IEEE_FLOAT_REPLACE, NULL, replace_float) ;
1609 if (replace_float && string_in_log_buffer (file, "Using IEEE replacement") == 0)
1610 { printf ("\n\nLine %d : Float replacement code not working.\n\n", __LINE__) ;
1611 dump_log_buffer (file) ;
1612 exit (1) ;
1613 } ;
1614
1615 test_writef_double_or_die (file, 0, data, frames, __LINE__) ;
1616
1617 sf_close (file) ;
1618
1619 #if (defined (WIN32) || defined (_WIN32))
1620 /* File hashing on Win32 fails due to slighty different
1621 ** calculated values.
1622 */
1623 hash = hash ; /* Avoid compiler warning. */
1624 #else
1625 check_file_hash_or_die (filename, hash, __LINE__) ;
1626 #endif
1627
1628 memset (data, 0, items * sizeof (double)) ;
1629
1630 if ((filetype & SF_FORMAT_TYPEMASK) != SF_FORMAT_RAW)
1631 memset (&sfinfo, 0, sizeof (sfinfo)) ;
1632
1633 file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
1634 sf_command (file, SFC_TEST_IEEE_FLOAT_REPLACE, NULL, replace_float) ;
1635 if (replace_float && string_in_log_buffer (file, "Using IEEE replacement") == 0)
1636 { printf ("\n\nLine %d : Float replacement code not working.\n\n", __LINE__) ;
1637 dump_log_buffer (file) ;
1638 exit (1) ;
1639 } ;
1640
1641 if (sfinfo.format != filetype)
1642 { printf ("\n\nError (%s:%d) Stereo : Returned format incorrect (0x%08X => 0x%08X).\n", __FILE__, __LINE__, filetype, sfinfo.format) ;
1643 exit (1) ;
1644 } ;
1645
1646 if (sfinfo.frames != frames)
1647 { printf ("\n\nError (%s:%d) Stereo : Incorrect number of frames in file. (%d => %ld)\n", __FILE__, __LINE__, frames, SF_COUNT_TO_LONG (sfinfo.frames)) ;
1648 exit (1) ;
1649 } ;
1650
1651 if (sfinfo.channels != 2)
1652 { printf ("\n\nError (%s:%d) Stereo : Incorrect number of channels in file.\n", __FILE__, __LINE__) ;
1653 exit (1) ;
1654 } ;
1655
1656 check_log_buffer_or_die (file, __LINE__) ;
1657
1658 test_readf_double_or_die (file, 0, data, frames, __LINE__) ;
1659
1660 for (sign = -1, k = 0 ; k < items ; k++)
1661 { error = fabs (data [k] - ((double) k) / 100.0 * (sign *= -1)) ;
1662 if (fabs (data [k]) > 1e-100 && fabs (error / data [k]) > 1e-5)
1663 { printf ("\n\nError (%s:%d) Stereo : Incorrect sample (#%d : %f => %f).\n", __FILE__, __LINE__, k, ((double) k) / 100.0, data [k]) ;
1664 exit (1) ;
1665 } ;
1666 } ;
1667
1668 /* Seek to start of file. */
1669 test_seek_or_die (file, 0, SEEK_SET, 0, sfinfo.channels, __LINE__) ;
1670
1671 test_read_double_or_die (file, 0, data, 4, __LINE__) ;
1672 for (k = 0 ; k < 4 ; k++)
1673 { error = fabs (data [k] - ((double) k) / 100.0 * (sign *= -1)) ;
1674 if (fabs (data [k]) > 1e-100 && fabs (error / data [k]) > 1e-5)
1675 { printf ("\n\nError (%s:%d) Stereo : Incorrect sample (#%d : %f => %f).\n", __FILE__, __LINE__, k, ((double) k) / 100.0, data [k]) ;
1676 exit (1) ;
1677 } ;
1678 } ;
1679
1680 /* Seek to offset from start of file. */
1681 test_seek_or_die (file, 10, SEEK_SET, 10, sfinfo.channels, __LINE__) ;
1682
1683 test_read_double_or_die (file, 0, data + 10, 4, __LINE__) ;
1684 for (k = 20 ; k < 24 ; k++)
1685 { error = fabs (data [k] - ((double) k) / 100.0 * (sign *= -1)) ;
1686 if (fabs (data [k]) > 1e-100 && fabs (error / data [k]) > 1e-5)
1687 { printf ("\n\nError (%s:%d) Stereo : Incorrect sample (#%d : %f => %f).\n", __FILE__, __LINE__, k, ((double) k) / 100.0, data [k]) ;
1688 exit (1) ;
1689 } ;
1690 } ;
1691
1692 /* Seek to offset from current position. */
1693 test_seek_or_die (file, 8, SEEK_CUR, 20, sfinfo.channels, __LINE__) ;
1694
1695 test_readf_double_or_die (file, 0, data + 40, 4, __LINE__) ;
1696 for (k = 40 ; k < 44 ; k++)
1697 { error = fabs (data [k] - ((double) k) / 100.0 * (sign *= -1)) ;
1698 if (fabs (data [k]) > 1e-100 && fabs (error / data [k]) > 1e-5)
1699 { printf ("\n\nError (%s:%d) Stereo : Incorrect sample (#%d : %f => %f).\n", __FILE__, __LINE__, k, ((double) k) / 100.0, data [k]) ;
1700 exit (1) ;
1701 } ;
1702 } ;
1703
1704 /* Seek to offset from end of file. */
1705 test_seek_or_die (file, -1 * (sfinfo.frames -10), SEEK_END, 10, sfinfo.channels, __LINE__) ;
1706
1707 test_readf_double_or_die (file, 0, data + 20, 4, __LINE__) ;
1708 for (k = 20 ; k < 24 ; k++)
1709 { error = fabs (data [k] - ((double) k) / 100.0 * (sign *= -1)) ;
1710 if (fabs (data [k]) > 1e-100 && fabs (error / data [k]) > 1e-5)
1711 { printf ("\n\nError (%s:%d) Stereo : Incorrect sample (#%d : %f => %f).\n", __FILE__, __LINE__, k, ((double) k) / 100.0, data [k]) ;
1712 exit (1) ;
1713 } ;
1714 } ;
1715
1716 sf_close (file) ;
1717
1718 printf ("ok\n") ;
1719 unlink (filename) ;
1720 } /* pcm_test_double */
1721
1722 /*==============================================================================
1723 */