2 ** Copyright (C) 1999-2013 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.
35 #define BUFFER_SIZE (1 << 12)
37 static void lrintf_test (void) ;
39 static void pcm_test_bits_8 (const char *filename, int filetype, uint64_t hash) ;
40 static void pcm_test_bits_16 (const char *filename, int filetype, uint64_t hash) ;
41 static void pcm_test_bits_24 (const char *filename, int filetype, uint64_t hash) ;
42 static void pcm_test_bits_32 (const char *filename, int filetype, uint64_t hash) ;
44 static void pcm_test_float (const char *filename, int filetype, uint64_t hash, int replace_float) ;
45 static void pcm_test_double (const char *filename, int filetype, uint64_t hash, int replace_float) ;
48 { double d [BUFFER_SIZE + 1] ;
49 float f [BUFFER_SIZE + 1] ;
50 int i [BUFFER_SIZE + 1] ;
51 short s [BUFFER_SIZE + 1] ;
54 /* Data written to the file. */
55 static BUFFER data_out ;
57 /* Data read back from the file. */
58 static BUFFER data_in ;
65 pcm_test_bits_8 ("pcm-s8.raw", SF_FORMAT_RAW | SF_FORMAT_PCM_S8, 0xa335091249dbfLL) ;
66 pcm_test_bits_8 ("pcm-u8.raw", SF_FORMAT_RAW | SF_FORMAT_PCM_U8, 0x48c433d695f3fLL) ;
68 pcm_test_bits_16 ("le-pcm16.raw", SF_ENDIAN_LITTLE | SF_FORMAT_RAW | SF_FORMAT_PCM_16, 0xb956c881ebf08LL) ;
69 pcm_test_bits_16 ("be-pcm16.raw", SF_ENDIAN_BIG | SF_FORMAT_RAW | SF_FORMAT_PCM_16, 0x2f840c55750f8LL) ;
71 pcm_test_bits_24 ("le-pcm24.raw", SF_ENDIAN_LITTLE | SF_FORMAT_RAW | SF_FORMAT_PCM_24, 0xb6a759ab496f8LL) ;
72 pcm_test_bits_24 ("be-pcm24.raw", SF_ENDIAN_BIG | SF_FORMAT_RAW | SF_FORMAT_PCM_24, 0xf3eaf9c30b6f8LL) ;
74 pcm_test_bits_32 ("le-pcm32.raw", SF_ENDIAN_LITTLE | SF_FORMAT_RAW | SF_FORMAT_PCM_32, 0xaece1c1c17f08LL) ;
75 pcm_test_bits_32 ("be-pcm32.raw", SF_ENDIAN_BIG | SF_FORMAT_RAW | SF_FORMAT_PCM_32, 0x9ddf142d0b0f8LL) ;
77 /* Lite remove start */
78 pcm_test_float ("le-float.raw", SF_ENDIAN_LITTLE | SF_FORMAT_RAW | SF_FORMAT_FLOAT, 0xad04f7554267aLL, SF_FALSE) ;
79 pcm_test_float ("be-float.raw", SF_ENDIAN_BIG | SF_FORMAT_RAW | SF_FORMAT_FLOAT, 0xde3e248fa9186LL, SF_FALSE) ;
81 pcm_test_double ("le-double.raw", SF_ENDIAN_LITTLE | SF_FORMAT_RAW | SF_FORMAT_DOUBLE, 0x2726f958f669cLL, SF_FALSE) ;
82 pcm_test_double ("be-double.raw", SF_ENDIAN_BIG | SF_FORMAT_RAW | SF_FORMAT_DOUBLE, 0x3583f8ee51164LL, SF_FALSE) ;
84 pcm_test_float ("le-float.raw", SF_ENDIAN_LITTLE | SF_FORMAT_RAW | SF_FORMAT_FLOAT, 0xad04f7554267aLL, SF_TRUE) ;
85 pcm_test_float ("be-float.raw", SF_ENDIAN_BIG | SF_FORMAT_RAW | SF_FORMAT_FLOAT, 0xde3e248fa9186LL, SF_TRUE) ;
87 pcm_test_double ("le-double.raw", SF_ENDIAN_LITTLE | SF_FORMAT_RAW | SF_FORMAT_DOUBLE, 0x2726f958f669cLL, SF_TRUE) ;
88 pcm_test_double ("be-double.raw", SF_ENDIAN_BIG | SF_FORMAT_RAW | SF_FORMAT_DOUBLE, 0x3583f8ee51164LL, SF_TRUE) ;
94 /*============================================================================================
95 ** Here are the test functions.
104 print_test_name ("lrintf_test", "") ;
108 float_data = data_out.f ;
109 int_data = data_in.i ;
111 for (k = 0 ; k < items ; k++)
112 float_data [k] = (k * ((k % 2) ? 333333.0 : -333333.0)) ;
114 for (k = 0 ; k < items ; k++)
115 int_data [k] = lrintf (float_data [k]) ;
117 for (k = 0 ; k < items ; k++)
118 if (fabs (int_data [k] - float_data [k]) > 1.0)
119 { printf ("\n\nLine %d: float : Incorrect sample (#%d : %f => %d).\n", __LINE__, k, float_data [k], int_data [k]) ;
127 pcm_test_bits_8 (const char *filename, int filetype, uint64_t hash)
130 int k, items, zero_count ;
131 short *short_out, *short_in ;
132 int *int_out, *int_in ;
133 /* Lite remove start */
134 float *float_out, *float_in ;
135 double *double_out, *double_in ;
136 /* Lite remove end */
138 print_test_name ("pcm_test_bits_8", filename) ;
142 short_out = data_out.s ;
143 short_in = data_in.s ;
146 for (k = 0 ; k < items ; k++)
147 { short_out [k] = arith_shift_left (k * ((k % 2) ? 1 : -1), 8) ;
148 zero_count = short_out [k] ? zero_count : zero_count + 1 ;
151 if (zero_count > items / 4)
152 { printf ("\n\nLine %d: too many zeros.\n", __LINE__) ;
156 sfinfo.samplerate = 44100 ;
157 sfinfo.frames = 123456789 ; /* Wrong length. Library should correct this on sf_close. */
158 sfinfo.channels = 1 ;
159 sfinfo.format = filetype ;
161 file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
163 test_write_short_or_die (file, 0, short_out, items, __LINE__) ;
167 memset (short_in, 0, items * sizeof (short)) ;
169 file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
171 if (sfinfo.format != filetype)
172 { printf ("\n\nLine %d: Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__, filetype, sfinfo.format) ;
176 if (sfinfo.frames != items)
177 { printf ("\n\nLine %d: Incorrect number of frames in file. (%d => %" PRId64 ")\n", __LINE__, items, sfinfo.frames) ;
181 if (sfinfo.channels != 1)
182 { printf ("\n\nLine %d: Incorrect number of channels in file.\n", __LINE__) ;
186 check_log_buffer_or_die (file, __LINE__) ;
188 test_read_short_or_die (file, 0, short_in, items, __LINE__) ;
190 for (k = 0 ; k < items ; k++)
191 if (short_out [k] != short_in [k])
192 { printf ("\n\nLine %d: Incorrect sample (#%d : 0x%x => 0x%x).\n", __LINE__, k, short_out [k], short_in [k]) ;
198 /* Finally, check the file hash. */
199 check_file_hash_or_die (filename, hash, __LINE__) ;
201 /*--------------------------------------------------------------------------
202 ** Test sf_read/write_int ()
206 int_out = data_out.i ;
208 for (k = 0 ; k < items ; k++)
209 { int_out [k] = arith_shift_left (k * ((k % 2) ? 1 : -1), 24) ;
210 zero_count = int_out [k] ? zero_count : zero_count + 1 ;
213 if (zero_count > items / 4)
214 { printf ("\n\nLine %d: too many zeros.\n", __LINE__) ;
218 sfinfo.samplerate = 44100 ;
219 sfinfo.frames = 123456789 ; /* Wrong length. Library should correct this on sf_close. */
220 sfinfo.channels = 1 ;
221 sfinfo.format = filetype ;
223 file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
225 test_write_int_or_die (file, 0, int_out, items, __LINE__) ;
229 memset (int_in, 0, items * sizeof (int)) ;
231 file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
233 if (sfinfo.format != filetype)
234 { printf ("\n\nLine %d: Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__, filetype, sfinfo.format) ;
238 if (sfinfo.frames != items)
239 { printf ("\n\nLine %d: Incorrect number of frames in file. (%d => %" PRId64 ")\n", __LINE__, items, sfinfo.frames) ;
243 if (sfinfo.channels != 1)
244 { printf ("\n\nLine %d: Incorrect number of channels in file.\n", __LINE__) ;
248 check_log_buffer_or_die (file, __LINE__) ;
250 test_read_int_or_die (file, 0, int_in, items, __LINE__) ;
252 for (k = 0 ; k < items ; k++)
253 if (int_out [k] != int_in [k])
254 { printf ("\n\nLine %d: int : Incorrect sample (#%d : 0x%x => 0x%x).\n", __LINE__, k, int_out [k], int_in [k]) ;
260 /* Lite remove start */
261 /*--------------------------------------------------------------------------
262 ** Test sf_read/write_float ()
266 float_out = data_out.f ;
267 float_in = data_in.f ;
268 for (k = 0 ; k < items ; k++)
269 { float_out [k] = (k * ((k % 2) ? 1 : -1)) ;
270 zero_count = (fabs (float_out [k]) > 1e-10) ? zero_count : zero_count + 1 ;
273 if (zero_count > items / 4)
274 { printf ("\n\nLine %d: too many zeros (%d/%d).\n", __LINE__, zero_count, items) ;
278 sfinfo.samplerate = 44100 ;
279 sfinfo.frames = 123456789 ; /* Wrong length. Library should correct this on sf_close. */
280 sfinfo.channels = 1 ;
281 sfinfo.format = filetype ;
283 file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
285 sf_command (file, SFC_SET_NORM_FLOAT, NULL, SF_FALSE) ;
287 test_write_float_or_die (file, 0, float_out, items, __LINE__) ;
291 memset (float_in, 0, items * sizeof (float)) ;
293 file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
295 if (sfinfo.format != filetype)
296 { printf ("\n\nLine %d: Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__, filetype, sfinfo.format) ;
300 if (sfinfo.frames != items)
301 { printf ("\n\nLine %d: Incorrect number of frames in file. (%d => %" PRId64 ")\n", __LINE__, items, sfinfo.frames) ;
305 if (sfinfo.channels != 1)
306 { printf ("\n\nLine %d: Incorrect number of channels in file.\n", __LINE__) ;
310 check_log_buffer_or_die (file, __LINE__) ;
312 sf_command (file, SFC_SET_NORM_FLOAT, NULL, SF_FALSE) ;
314 test_read_float_or_die (file, 0, float_in, items, __LINE__) ;
316 for (k = 0 ; k < items ; k++)
317 if (fabs (float_out [k] - float_in [k]) > 1e-10)
318 { printf ("\n\nLine %d: float : Incorrect sample (#%d : %f => %f).\n", __LINE__, k, (double) float_out [k], (double) float_in [k]) ;
324 /*--------------------------------------------------------------------------
325 ** Test sf_read/write_double ()
329 double_out = data_out.d ;
330 double_in = data_in.d ;
331 for (k = 0 ; k < items ; k++)
332 { double_out [k] = (k * ((k % 2) ? 1 : -1)) ;
333 zero_count = (fabs (double_out [k]) > 1e-10) ? zero_count : zero_count + 1 ;
336 if (zero_count > items / 4)
337 { printf ("\n\nLine %d: too many zeros (%d/%d).\n", __LINE__, zero_count, items) ;
341 sfinfo.samplerate = 44100 ;
342 sfinfo.frames = 123456789 ; /* Wrong length. Library should correct this on sf_close. */
343 sfinfo.channels = 1 ;
344 sfinfo.format = filetype ;
346 file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
348 sf_command (file, SFC_SET_NORM_DOUBLE, NULL, SF_FALSE) ;
350 test_write_double_or_die (file, 0, double_out, items, __LINE__) ;
354 memset (double_in, 0, items * sizeof (double)) ;
356 file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
358 if (sfinfo.format != filetype)
359 { printf ("\n\nLine %d: Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__, filetype, sfinfo.format) ;
363 if (sfinfo.frames != items)
364 { printf ("\n\nLine %d: Incorrect number of frames in file. (%d => %" PRId64 ")\n", __LINE__, items, sfinfo.frames) ;
368 if (sfinfo.channels != 1)
369 { printf ("\n\nLine %d: Incorrect number of channels in file.\n", __LINE__) ;
373 check_log_buffer_or_die (file, __LINE__) ;
375 sf_command (file, SFC_SET_NORM_DOUBLE, NULL, SF_FALSE) ;
377 test_read_double_or_die (file, 0, double_in, items, __LINE__) ;
379 for (k = 0 ; k < items ; k++)
380 if (fabs (double_out [k] - double_in [k]) > 1e-10)
381 { printf ("\n\nLine %d: double : Incorrect sample (#%d : %f => %f).\n", __LINE__, k, double_out [k], double_in [k]) ;
386 /* Lite remove end */
390 } /* pcm_test_bits_8 */
393 pcm_test_bits_16 (const char *filename, int filetype, uint64_t hash)
396 int k, items, zero_count ;
397 short *short_out, *short_in ;
398 int *int_out, *int_in ;
399 /* Lite remove start */
400 float *float_out, *float_in ;
401 double *double_out, *double_in ;
402 /* Lite remove end */
404 print_test_name ("pcm_test_bits_16", filename) ;
408 short_out = data_out.s ;
409 short_in = data_in.s ;
412 for (k = 0 ; k < items ; k++)
413 { short_out [k] = (k * ((k % 2) ? 3 : -3)) ;
414 zero_count = short_out [k] ? zero_count : zero_count + 1 ;
417 if (zero_count > items / 4)
418 { printf ("\n\nLine %d: too many zeros.\n", __LINE__) ;
422 sfinfo.samplerate = 44100 ;
423 sfinfo.frames = 123456789 ; /* Wrong length. Library should correct this on sf_close. */
424 sfinfo.channels = 1 ;
425 sfinfo.format = filetype ;
427 file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
429 test_write_short_or_die (file, 0, short_out, items, __LINE__) ;
433 memset (short_in, 0, items * sizeof (short)) ;
435 file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
437 if (sfinfo.format != filetype)
438 { printf ("\n\nLine %d: Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__, filetype, sfinfo.format) ;
442 if (sfinfo.frames != items)
443 { printf ("\n\nLine %d: Incorrect number of frames in file. (%d => %" PRId64 ")\n", __LINE__, items, sfinfo.frames) ;
447 if (sfinfo.channels != 1)
448 { printf ("\n\nLine %d: Incorrect number of channels in file.\n", __LINE__) ;
452 check_log_buffer_or_die (file, __LINE__) ;
454 test_read_short_or_die (file, 0, short_in, items, __LINE__) ;
456 for (k = 0 ; k < items ; k++)
457 if (short_out [k] != short_in [k])
458 { printf ("\n\nLine %d: Incorrect sample (#%d : 0x%x => 0x%x).\n", __LINE__, k, short_out [k], short_in [k]) ;
464 /* Finally, check the file hash. */
465 check_file_hash_or_die (filename, hash, __LINE__) ;
467 /*--------------------------------------------------------------------------
468 ** Test sf_read/write_int ()
472 int_out = data_out.i ;
474 for (k = 0 ; k < items ; k++)
475 { int_out [k] = arith_shift_left (k * ((k % 2) ? 3 : -3), 16) ;
476 zero_count = int_out [k] ? zero_count : zero_count + 1 ;
479 if (zero_count > items / 4)
480 { printf ("\n\nLine %d: too many zeros.\n", __LINE__) ;
484 sfinfo.samplerate = 44100 ;
485 sfinfo.frames = 123456789 ; /* Wrong length. Library should correct this on sf_close. */
486 sfinfo.channels = 1 ;
487 sfinfo.format = filetype ;
489 file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
491 test_write_int_or_die (file, 0, int_out, items, __LINE__) ;
495 memset (int_in, 0, items * sizeof (int)) ;
497 file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
499 if (sfinfo.format != filetype)
500 { printf ("\n\nLine %d: Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__, filetype, sfinfo.format) ;
504 if (sfinfo.frames != items)
505 { printf ("\n\nLine %d: Incorrect number of frames in file. (%d => %" PRId64 ")\n", __LINE__, items, sfinfo.frames) ;
509 if (sfinfo.channels != 1)
510 { printf ("\n\nLine %d: Incorrect number of channels in file.\n", __LINE__) ;
514 check_log_buffer_or_die (file, __LINE__) ;
516 test_read_int_or_die (file, 0, int_in, items, __LINE__) ;
518 for (k = 0 ; k < items ; k++)
519 if (int_out [k] != int_in [k])
520 { printf ("\n\nLine %d: int : Incorrect sample (#%d : 0x%x => 0x%x).\n", __LINE__, k, int_out [k], int_in [k]) ;
526 /* Lite remove start */
527 /*--------------------------------------------------------------------------
528 ** Test sf_read/write_float ()
532 float_out = data_out.f ;
533 float_in = data_in.f ;
534 for (k = 0 ; k < items ; k++)
535 { float_out [k] = (k * ((k % 2) ? 3 : -3)) ;
536 zero_count = (fabs (float_out [k]) > 1e-10) ? zero_count : zero_count + 1 ;
539 if (zero_count > items / 4)
540 { printf ("\n\nLine %d: too many zeros (%d/%d).\n", __LINE__, zero_count, items) ;
544 sfinfo.samplerate = 44100 ;
545 sfinfo.frames = 123456789 ; /* Wrong length. Library should correct this on sf_close. */
546 sfinfo.channels = 1 ;
547 sfinfo.format = filetype ;
549 file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
551 sf_command (file, SFC_SET_NORM_FLOAT, NULL, SF_FALSE) ;
553 test_write_float_or_die (file, 0, float_out, items, __LINE__) ;
557 memset (float_in, 0, items * sizeof (float)) ;
559 file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
561 if (sfinfo.format != filetype)
562 { printf ("\n\nLine %d: Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__, filetype, sfinfo.format) ;
566 if (sfinfo.frames != items)
567 { printf ("\n\nLine %d: Incorrect number of frames in file. (%d => %" PRId64 ")\n", __LINE__, items, sfinfo.frames) ;
571 if (sfinfo.channels != 1)
572 { printf ("\n\nLine %d: Incorrect number of channels in file.\n", __LINE__) ;
576 check_log_buffer_or_die (file, __LINE__) ;
578 sf_command (file, SFC_SET_NORM_FLOAT, NULL, SF_FALSE) ;
580 test_read_float_or_die (file, 0, float_in, items, __LINE__) ;
582 for (k = 0 ; k < items ; k++)
583 if (fabs (float_out [k] - float_in [k]) > 1e-10)
584 { printf ("\n\nLine %d: float : Incorrect sample (#%d : %f => %f).\n", __LINE__, k, (double) float_out [k], (double) float_in [k]) ;
590 /*--------------------------------------------------------------------------
591 ** Test sf_read/write_double ()
595 double_out = data_out.d ;
596 double_in = data_in.d ;
597 for (k = 0 ; k < items ; k++)
598 { double_out [k] = (k * ((k % 2) ? 3 : -3)) ;
599 zero_count = (fabs (double_out [k]) > 1e-10) ? zero_count : zero_count + 1 ;
602 if (zero_count > items / 4)
603 { printf ("\n\nLine %d: too many zeros (%d/%d).\n", __LINE__, zero_count, items) ;
607 sfinfo.samplerate = 44100 ;
608 sfinfo.frames = 123456789 ; /* Wrong length. Library should correct this on sf_close. */
609 sfinfo.channels = 1 ;
610 sfinfo.format = filetype ;
612 file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
614 sf_command (file, SFC_SET_NORM_DOUBLE, NULL, SF_FALSE) ;
616 test_write_double_or_die (file, 0, double_out, items, __LINE__) ;
620 memset (double_in, 0, items * sizeof (double)) ;
622 file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
624 if (sfinfo.format != filetype)
625 { printf ("\n\nLine %d: Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__, filetype, sfinfo.format) ;
629 if (sfinfo.frames != items)
630 { printf ("\n\nLine %d: Incorrect number of frames in file. (%d => %" PRId64 ")\n", __LINE__, items, sfinfo.frames) ;
634 if (sfinfo.channels != 1)
635 { printf ("\n\nLine %d: Incorrect number of channels in file.\n", __LINE__) ;
639 check_log_buffer_or_die (file, __LINE__) ;
641 sf_command (file, SFC_SET_NORM_DOUBLE, NULL, SF_FALSE) ;
643 test_read_double_or_die (file, 0, double_in, items, __LINE__) ;
645 for (k = 0 ; k < items ; k++)
646 if (fabs (double_out [k] - double_in [k]) > 1e-10)
647 { printf ("\n\nLine %d: double : Incorrect sample (#%d : %f => %f).\n", __LINE__, k, double_out [k], double_in [k]) ;
652 /* Lite remove end */
656 } /* pcm_test_bits_16 */
659 pcm_test_bits_24 (const char *filename, int filetype, uint64_t hash)
662 int k, items, zero_count ;
663 short *short_out, *short_in ;
664 int *int_out, *int_in ;
665 /* Lite remove start */
666 float *float_out, *float_in ;
667 double *double_out, *double_in ;
668 /* Lite remove end */
670 print_test_name ("pcm_test_bits_24", filename) ;
674 short_out = data_out.s ;
675 short_in = data_in.s ;
678 for (k = 0 ; k < items ; k++)
679 { short_out [k] = (k * ((k % 2) ? 3 : -3)) ;
680 zero_count = short_out [k] ? zero_count : zero_count + 1 ;
683 if (zero_count > items / 4)
684 { printf ("\n\nLine %d: too many zeros.\n", __LINE__) ;
688 sfinfo.samplerate = 44100 ;
689 sfinfo.frames = 123456789 ; /* Wrong length. Library should correct this on sf_close. */
690 sfinfo.channels = 1 ;
691 sfinfo.format = filetype ;
693 file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
695 test_write_short_or_die (file, 0, short_out, items, __LINE__) ;
699 memset (short_in, 0, items * sizeof (short)) ;
701 file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
703 if (sfinfo.format != filetype)
704 { printf ("\n\nLine %d: Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__, filetype, sfinfo.format) ;
708 if (sfinfo.frames != items)
709 { printf ("\n\nLine %d: Incorrect number of frames in file. (%d => %" PRId64 ")\n", __LINE__, items, sfinfo.frames) ;
713 if (sfinfo.channels != 1)
714 { printf ("\n\nLine %d: Incorrect number of channels in file.\n", __LINE__) ;
718 check_log_buffer_or_die (file, __LINE__) ;
720 test_read_short_or_die (file, 0, short_in, items, __LINE__) ;
722 for (k = 0 ; k < items ; k++)
723 if (short_out [k] != short_in [k])
724 { printf ("\n\nLine %d: Incorrect sample (#%d : 0x%x => 0x%x).\n", __LINE__, k, short_out [k], short_in [k]) ;
730 /* Finally, check the file hash. */
731 check_file_hash_or_die (filename, hash, __LINE__) ;
733 /*--------------------------------------------------------------------------
734 ** Test sf_read/write_int ()
738 int_out = data_out.i ;
740 for (k = 0 ; k < items ; k++)
741 { int_out [k] = arith_shift_left (k * ((k % 2) ? 3333 : -3333), 8) ;
742 zero_count = int_out [k] ? zero_count : zero_count + 1 ;
745 if (zero_count > items / 4)
746 { printf ("\n\nLine %d: too many zeros.\n", __LINE__) ;
750 sfinfo.samplerate = 44100 ;
751 sfinfo.frames = 123456789 ; /* Wrong length. Library should correct this on sf_close. */
752 sfinfo.channels = 1 ;
753 sfinfo.format = filetype ;
755 file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
757 test_write_int_or_die (file, 0, int_out, items, __LINE__) ;
761 memset (int_in, 0, items * sizeof (int)) ;
763 file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
765 if (sfinfo.format != filetype)
766 { printf ("\n\nLine %d: Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__, filetype, sfinfo.format) ;
770 if (sfinfo.frames != items)
771 { printf ("\n\nLine %d: Incorrect number of frames in file. (%d => %" PRId64 ")\n", __LINE__, items, sfinfo.frames) ;
775 if (sfinfo.channels != 1)
776 { printf ("\n\nLine %d: Incorrect number of channels in file.\n", __LINE__) ;
780 check_log_buffer_or_die (file, __LINE__) ;
782 test_read_int_or_die (file, 0, int_in, items, __LINE__) ;
784 for (k = 0 ; k < items ; k++)
785 if (int_out [k] != int_in [k])
786 { printf ("\n\nLine %d: int : Incorrect sample (#%d : 0x%x => 0x%x).\n", __LINE__, k, int_out [k], int_in [k]) ;
792 /* Lite remove start */
793 /*--------------------------------------------------------------------------
794 ** Test sf_read/write_float ()
798 float_out = data_out.f ;
799 float_in = data_in.f ;
800 for (k = 0 ; k < items ; k++)
801 { float_out [k] = (k * ((k % 2) ? 3333 : -3333)) ;
802 zero_count = (fabs (float_out [k]) > 1e-10) ? zero_count : zero_count + 1 ;
805 if (zero_count > items / 4)
806 { printf ("\n\nLine %d: too many zeros (%d/%d).\n", __LINE__, zero_count, items) ;
810 sfinfo.samplerate = 44100 ;
811 sfinfo.frames = 123456789 ; /* Wrong length. Library should correct this on sf_close. */
812 sfinfo.channels = 1 ;
813 sfinfo.format = filetype ;
815 file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
817 sf_command (file, SFC_SET_NORM_FLOAT, NULL, SF_FALSE) ;
819 test_write_float_or_die (file, 0, float_out, items, __LINE__) ;
823 memset (float_in, 0, items * sizeof (float)) ;
825 file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
827 if (sfinfo.format != filetype)
828 { printf ("\n\nLine %d: Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__, filetype, sfinfo.format) ;
832 if (sfinfo.frames != items)
833 { printf ("\n\nLine %d: Incorrect number of frames in file. (%d => %" PRId64 ")\n", __LINE__, items, sfinfo.frames) ;
837 if (sfinfo.channels != 1)
838 { printf ("\n\nLine %d: Incorrect number of channels in file.\n", __LINE__) ;
842 check_log_buffer_or_die (file, __LINE__) ;
844 sf_command (file, SFC_SET_NORM_FLOAT, NULL, SF_FALSE) ;
846 test_read_float_or_die (file, 0, float_in, items, __LINE__) ;
848 for (k = 0 ; k < items ; k++)
849 if (fabs (float_out [k] - float_in [k]) > 1e-10)
850 { printf ("\n\nLine %d: float : Incorrect sample (#%d : %f => %f).\n", __LINE__, k, (double) float_out [k], (double) float_in [k]) ;
856 /*--------------------------------------------------------------------------
857 ** Test sf_read/write_double ()
861 double_out = data_out.d ;
862 double_in = data_in.d ;
863 for (k = 0 ; k < items ; k++)
864 { double_out [k] = (k * ((k % 2) ? 3333 : -3333)) ;
865 zero_count = (fabs (double_out [k]) > 1e-10) ? zero_count : zero_count + 1 ;
868 if (zero_count > items / 4)
869 { printf ("\n\nLine %d: too many zeros (%d/%d).\n", __LINE__, zero_count, items) ;
873 sfinfo.samplerate = 44100 ;
874 sfinfo.frames = 123456789 ; /* Wrong length. Library should correct this on sf_close. */
875 sfinfo.channels = 1 ;
876 sfinfo.format = filetype ;
878 file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
880 sf_command (file, SFC_SET_NORM_DOUBLE, NULL, SF_FALSE) ;
882 test_write_double_or_die (file, 0, double_out, items, __LINE__) ;
886 memset (double_in, 0, items * sizeof (double)) ;
888 file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
890 if (sfinfo.format != filetype)
891 { printf ("\n\nLine %d: Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__, filetype, sfinfo.format) ;
895 if (sfinfo.frames != items)
896 { printf ("\n\nLine %d: Incorrect number of frames in file. (%d => %" PRId64 ")\n", __LINE__, items, sfinfo.frames) ;
900 if (sfinfo.channels != 1)
901 { printf ("\n\nLine %d: Incorrect number of channels in file.\n", __LINE__) ;
905 check_log_buffer_or_die (file, __LINE__) ;
907 sf_command (file, SFC_SET_NORM_DOUBLE, NULL, SF_FALSE) ;
909 test_read_double_or_die (file, 0, double_in, items, __LINE__) ;
911 for (k = 0 ; k < items ; k++)
912 if (fabs (double_out [k] - double_in [k]) > 1e-10)
913 { printf ("\n\nLine %d: double : Incorrect sample (#%d : %f => %f).\n", __LINE__, k, double_out [k], double_in [k]) ;
918 /* Lite remove end */
922 } /* pcm_test_bits_24 */
925 pcm_test_bits_32 (const char *filename, int filetype, uint64_t hash)
928 int k, items, zero_count ;
929 short *short_out, *short_in ;
930 int *int_out, *int_in ;
931 /* Lite remove start */
932 float *float_out, *float_in ;
933 double *double_out, *double_in ;
934 /* Lite remove end */
936 print_test_name ("pcm_test_bits_32", filename) ;
940 short_out = data_out.s ;
941 short_in = data_in.s ;
944 for (k = 0 ; k < items ; k++)
945 { short_out [k] = (k * ((k % 2) ? 3 : -3)) ;
946 zero_count = short_out [k] ? zero_count : zero_count + 1 ;
949 if (zero_count > items / 4)
950 { printf ("\n\nLine %d: too many zeros.\n", __LINE__) ;
954 sfinfo.samplerate = 44100 ;
955 sfinfo.frames = 123456789 ; /* Wrong length. Library should correct this on sf_close. */
956 sfinfo.channels = 1 ;
957 sfinfo.format = filetype ;
959 file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
961 test_write_short_or_die (file, 0, short_out, items, __LINE__) ;
965 memset (short_in, 0, items * sizeof (short)) ;
967 file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
969 if (sfinfo.format != filetype)
970 { printf ("\n\nLine %d: Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__, filetype, sfinfo.format) ;
974 if (sfinfo.frames != items)
975 { printf ("\n\nLine %d: Incorrect number of frames in file. (%d => %" PRId64 ")\n", __LINE__, items, sfinfo.frames) ;
979 if (sfinfo.channels != 1)
980 { printf ("\n\nLine %d: Incorrect number of channels in file.\n", __LINE__) ;
984 check_log_buffer_or_die (file, __LINE__) ;
986 test_read_short_or_die (file, 0, short_in, items, __LINE__) ;
988 for (k = 0 ; k < items ; k++)
989 if (short_out [k] != short_in [k])
990 { printf ("\n\nLine %d: Incorrect sample (#%d : 0x%x => 0x%x).\n", __LINE__, k, short_out [k], short_in [k]) ;
996 /* Finally, check the file hash. */
997 check_file_hash_or_die (filename, hash, __LINE__) ;
999 /*--------------------------------------------------------------------------
1000 ** Test sf_read/write_int ()
1004 int_out = data_out.i ;
1005 int_in = data_in.i ;
1006 for (k = 0 ; k < items ; k++)
1007 { int_out [k] = (k * ((k % 2) ? 333333 : -333333)) ;
1008 zero_count = int_out [k] ? zero_count : zero_count + 1 ;
1011 if (zero_count > items / 4)
1012 { printf ("\n\nLine %d: too many zeros.\n", __LINE__) ;
1016 sfinfo.samplerate = 44100 ;
1017 sfinfo.frames = 123456789 ; /* Wrong length. Library should correct this on sf_close. */
1018 sfinfo.channels = 1 ;
1019 sfinfo.format = filetype ;
1021 file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
1023 test_write_int_or_die (file, 0, int_out, items, __LINE__) ;
1027 memset (int_in, 0, items * sizeof (int)) ;
1029 file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
1031 if (sfinfo.format != filetype)
1032 { printf ("\n\nLine %d: Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__, filetype, sfinfo.format) ;
1036 if (sfinfo.frames != items)
1037 { printf ("\n\nLine %d: Incorrect number of frames in file. (%d => %" PRId64 ")\n", __LINE__, items, sfinfo.frames) ;
1041 if (sfinfo.channels != 1)
1042 { printf ("\n\nLine %d: Incorrect number of channels in file.\n", __LINE__) ;
1046 check_log_buffer_or_die (file, __LINE__) ;
1048 test_read_int_or_die (file, 0, int_in, items, __LINE__) ;
1050 for (k = 0 ; k < items ; k++)
1051 if (int_out [k] != int_in [k])
1052 { printf ("\n\nLine %d: int : Incorrect sample (#%d : 0x%x => 0x%x).\n", __LINE__, k, int_out [k], int_in [k]) ;
1058 /* Lite remove start */
1059 /*--------------------------------------------------------------------------
1060 ** Test sf_read/write_float ()
1064 float_out = data_out.f ;
1065 float_in = data_in.f ;
1066 for (k = 0 ; k < items ; k++)
1067 { float_out [k] = (k * ((k % 2) ? 333333 : -333333)) ;
1068 zero_count = (fabs (float_out [k]) > 1e-10) ? zero_count : zero_count + 1 ;
1071 if (zero_count > items / 4)
1072 { printf ("\n\nLine %d: too many zeros (%d/%d).\n", __LINE__, zero_count, items) ;
1076 sfinfo.samplerate = 44100 ;
1077 sfinfo.frames = 123456789 ; /* Wrong length. Library should correct this on sf_close. */
1078 sfinfo.channels = 1 ;
1079 sfinfo.format = filetype ;
1081 file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
1083 sf_command (file, SFC_SET_NORM_FLOAT, NULL, SF_FALSE) ;
1085 test_write_float_or_die (file, 0, float_out, items, __LINE__) ;
1089 memset (float_in, 0, items * sizeof (float)) ;
1091 file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
1093 if (sfinfo.format != filetype)
1094 { printf ("\n\nLine %d: Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__, filetype, sfinfo.format) ;
1098 if (sfinfo.frames != items)
1099 { printf ("\n\nLine %d: Incorrect number of frames in file. (%d => %" PRId64 ")\n", __LINE__, items, sfinfo.frames) ;
1103 if (sfinfo.channels != 1)
1104 { printf ("\n\nLine %d: Incorrect number of channels in file.\n", __LINE__) ;
1108 check_log_buffer_or_die (file, __LINE__) ;
1110 sf_command (file, SFC_SET_NORM_FLOAT, NULL, SF_FALSE) ;
1112 test_read_float_or_die (file, 0, float_in, items, __LINE__) ;
1114 for (k = 0 ; k < items ; k++)
1115 if (fabs (float_out [k] - float_in [k]) > 1e-10)
1116 { printf ("\n\nLine %d: float : Incorrect sample (#%d : %f => %f).\n", __LINE__, k, (double) float_out [k], (double) float_in [k]) ;
1122 /*--------------------------------------------------------------------------
1123 ** Test sf_read/write_double ()
1127 double_out = data_out.d ;
1128 double_in = data_in.d ;
1129 for (k = 0 ; k < items ; k++)
1130 { double_out [k] = (k * ((k % 2) ? 333333 : -333333)) ;
1131 zero_count = (fabs (double_out [k]) > 1e-10) ? zero_count : zero_count + 1 ;
1134 if (zero_count > items / 4)
1135 { printf ("\n\nLine %d: too many zeros (%d/%d).\n", __LINE__, zero_count, items) ;
1139 sfinfo.samplerate = 44100 ;
1140 sfinfo.frames = 123456789 ; /* Wrong length. Library should correct this on sf_close. */
1141 sfinfo.channels = 1 ;
1142 sfinfo.format = filetype ;
1144 file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
1146 sf_command (file, SFC_SET_NORM_DOUBLE, NULL, SF_FALSE) ;
1148 test_write_double_or_die (file, 0, double_out, items, __LINE__) ;
1152 memset (double_in, 0, items * sizeof (double)) ;
1154 file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
1156 if (sfinfo.format != filetype)
1157 { printf ("\n\nLine %d: Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__, filetype, sfinfo.format) ;
1161 if (sfinfo.frames != items)
1162 { printf ("\n\nLine %d: Incorrect number of frames in file. (%d => %" PRId64 ")\n", __LINE__, items, sfinfo.frames) ;
1166 if (sfinfo.channels != 1)
1167 { printf ("\n\nLine %d: Incorrect number of channels in file.\n", __LINE__) ;
1171 check_log_buffer_or_die (file, __LINE__) ;
1173 sf_command (file, SFC_SET_NORM_DOUBLE, NULL, SF_FALSE) ;
1175 test_read_double_or_die (file, 0, double_in, items, __LINE__) ;
1177 for (k = 0 ; k < items ; k++)
1178 if (fabs (double_out [k] - double_in [k]) > 1e-10)
1179 { printf ("\n\nLine %d: double : Incorrect sample (#%d : %f => %f).\n", __LINE__, k, double_out [k], double_in [k]) ;
1184 /* Lite remove end */
1188 } /* pcm_test_bits_32 */
1192 /*==============================================================================
1196 pcm_test_float (const char *filename, int filetype, uint64_t hash, int replace_float)
1199 int k, items, frames ;
1201 double *data, error ;
1203 print_test_name (replace_float ? "pcm_test_float (replace)" : "pcm_test_float", filename) ;
1205 items = BUFFER_SIZE ;
1208 for (sign = 1, k = 0 ; k < items ; k++)
1209 { data [k] = ((double) (k * sign)) / 100.0 ;
1210 sign = (sign > 0) ? -1 : 1 ;
1213 sfinfo.samplerate = 44100 ;
1214 sfinfo.frames = items ;
1215 sfinfo.channels = 1 ;
1216 sfinfo.format = filetype ;
1218 file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
1219 sf_command (file, SFC_TEST_IEEE_FLOAT_REPLACE, NULL, replace_float) ;
1220 if (replace_float && string_in_log_buffer (file, "Using IEEE replacement") == 0)
1221 { printf ("\n\nLine %d : Float replacement code not working.\n\n", __LINE__) ;
1222 dump_log_buffer (file) ;
1226 test_write_double_or_die (file, 0, data, items, __LINE__) ;
1230 check_file_hash_or_die (filename, hash, __LINE__) ;
1232 memset (data, 0, items * sizeof (double)) ;
1234 if ((filetype & SF_FORMAT_TYPEMASK) != SF_FORMAT_RAW)
1235 memset (&sfinfo, 0, sizeof (sfinfo)) ;
1237 file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
1238 sf_command (file, SFC_TEST_IEEE_FLOAT_REPLACE, NULL, replace_float) ;
1239 if (replace_float && string_in_log_buffer (file, "Using IEEE replacement") == 0)
1240 { printf ("\n\nLine %d : Float replacement code not working.\n\n", __LINE__) ;
1241 dump_log_buffer (file) ;
1245 if (sfinfo.format != filetype)
1246 { printf ("\n\nError (%s:%d) Mono : Returned format incorrect (0x%08X => 0x%08X).\n", __FILE__, __LINE__, filetype, sfinfo.format) ;
1250 if (sfinfo.frames != items)
1251 { printf ("\n\nError (%s:%d) Mono : Incorrect number of frames in file. (%d => %" PRId64 ")\n", __FILE__, __LINE__, items, sfinfo.frames) ;
1255 if (sfinfo.channels != 1)
1256 { printf ("\n\nError (%s:%d) Mono : Incorrect number of channels in file.\n", __FILE__, __LINE__) ;
1260 check_log_buffer_or_die (file, __LINE__) ;
1262 test_read_double_or_die (file, 0, data, items, __LINE__) ;
1264 for (sign = -1, k = 0 ; k < items ; k++)
1265 { error = fabs (data [k] - ((double) k) / 100.0 * (sign *= -1)) ;
1266 if (fabs (data [k]) > 1e-100 && fabs (error / data [k]) > 1e-5)
1267 { printf ("\n\nError (%s:%d) Mono : Incorrect sample (#%d : %f => %f).\n", __FILE__, __LINE__, k, ((double) k) / 100.0, data [k]) ;
1272 /* Seek to end of file. */
1273 test_seek_or_die (file, 0, SEEK_END, sfinfo.frames, sfinfo.channels, __LINE__) ;
1275 /* Seek to start of file. */
1276 test_seek_or_die (file, 0, SEEK_SET, 0, sfinfo.channels, __LINE__) ;
1278 test_read_double_or_die (file, 0, data, 4, __LINE__) ;
1279 for (k = 0 ; k < 4 ; k++)
1280 { error = fabs (data [k] - ((double) k) / 100.0 * (sign *= -1)) ;
1281 if (fabs (data [k]) > 1e-100 && fabs (error / data [k]) > 1e-5)
1282 { printf ("\n\nError (%s:%d) Mono : Incorrect sample (#%d : %f => %f).\n", __FILE__, __LINE__, k, ((double) k) / 100.0, data [k]) ;
1287 /* Seek to offset from start of file. */
1288 test_seek_or_die (file, 10, SEEK_SET, 10, sfinfo.channels, __LINE__) ;
1290 test_read_double_or_die (file, 0, data + 10, 4, __LINE__) ;
1291 for (k = 10 ; k < 14 ; k++)
1292 { error = fabs (data [k] - ((double) k) / 100.0 * (sign *= -1)) ;
1293 if (fabs (data [k]) > 1e-100 && fabs (error / data [k]) > 1e-5)
1294 { printf ("\n\nError (%s:%d) Mono : Incorrect sample (#%d : %f => %f).\n", __FILE__, __LINE__, k, ((double) k) / 100.0, data [k]) ;
1299 /* Seek to offset from current position. */
1300 test_seek_or_die (file, 6, SEEK_CUR, 20, sfinfo.channels, __LINE__) ;
1302 test_read_double_or_die (file, 0, data + 20, 4, __LINE__) ;
1303 for (k = 20 ; k < 24 ; k++)
1304 { error = fabs (data [k] - ((double) k) / 100.0 * (sign *= -1)) ;
1305 if (fabs (data [k]) > 1e-100 && fabs (error / data [k]) > 1e-5)
1306 { printf ("\n\nError (%s:%d) Mono : Incorrect sample (#%d : %f => %f).\n", __FILE__, __LINE__, k, ((double) k) / 100.0, data [k]) ;
1311 /* Seek to offset from end of file. */
1312 test_seek_or_die (file, -1 * (sfinfo.frames - 10), SEEK_END, 10, sfinfo.channels, __LINE__) ;
1314 test_read_double_or_die (file, 0, data + 10, 4, __LINE__) ;
1315 for (k = 10 ; k < 14 ; k++)
1316 { error = fabs (data [k] - ((double) k) / 100.0 * (sign *= -1)) ;
1317 if (fabs (data [k]) > 1e-100 && fabs (error / data [k]) > 1e-5)
1318 { printf ("\n\nError (%s:%d) Mono : Incorrect sample (#%d : %f => %f).\n", __FILE__, __LINE__, k, ((double) k) / 100.0, data [k]) ;
1325 /* Now test Stereo. */
1327 if ((filetype & SF_FORMAT_TYPEMASK) == SF_FORMAT_SVX) /* SVX is mono only */
1332 items = BUFFER_SIZE ;
1335 for (sign = -1, k = 0 ; k < items ; k++)
1336 data [k] = ((double) k) / 100.0 * (sign *= -1) ;
1338 sfinfo.samplerate = 44100 ;
1339 sfinfo.frames = items ;
1340 sfinfo.channels = 2 ;
1341 sfinfo.format = filetype ;
1343 frames = items / sfinfo.channels ;
1345 file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
1346 sf_command (file, SFC_TEST_IEEE_FLOAT_REPLACE, NULL, replace_float) ;
1347 if (replace_float && string_in_log_buffer (file, "Using IEEE replacement") == 0)
1348 { printf ("\n\nLine %d : Float replacement code not working.\n\n", __LINE__) ;
1349 dump_log_buffer (file) ;
1353 test_writef_double_or_die (file, 0, data, frames, __LINE__) ;
1357 check_file_hash_or_die (filename, hash, __LINE__) ;
1359 memset (data, 0, items * sizeof (double)) ;
1361 if ((filetype & SF_FORMAT_TYPEMASK) != SF_FORMAT_RAW)
1362 memset (&sfinfo, 0, sizeof (sfinfo)) ;
1364 file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
1365 sf_command (file, SFC_TEST_IEEE_FLOAT_REPLACE, NULL, replace_float) ;
1366 if (replace_float && string_in_log_buffer (file, "Using IEEE replacement") == 0)
1367 { printf ("\n\nLine %d : Float replacement code not working.\n\n", __LINE__) ;
1368 dump_log_buffer (file) ;
1372 if (sfinfo.format != filetype)
1373 { printf ("\n\nError (%s:%d) Stereo : Returned format incorrect (0x%08X => 0x%08X).\n", __FILE__, __LINE__, filetype, sfinfo.format) ;
1377 if (sfinfo.frames != frames)
1378 { printf ("\n\nError (%s:%d) Stereo : Incorrect number of frames in file. (%d => %" PRId64 ")\n", __FILE__, __LINE__, frames, sfinfo.frames) ;
1382 if (sfinfo.channels != 2)
1383 { printf ("\n\nError (%s:%d) Stereo : Incorrect number of channels in file.\n", __FILE__, __LINE__) ;
1387 check_log_buffer_or_die (file, __LINE__) ;
1389 test_readf_double_or_die (file, 0, data, frames, __LINE__) ;
1390 for (sign = -1, k = 0 ; k < items ; k++)
1391 { error = fabs (data [k] - ((double) k) / 100.0 * (sign *= -1)) ;
1392 if (fabs (data [k]) > 1e-100 && fabs (error / data [k]) > 1e-5)
1393 { printf ("\n\nError (%s:%d) Stereo : Incorrect sample (#%d : %f => %f).\n", __FILE__, __LINE__, k, ((double) k) / 100.0, data [k]) ;
1398 /* Seek to start of file. */
1399 test_seek_or_die (file, 0, SEEK_SET, 0, sfinfo.channels, __LINE__) ;
1401 test_readf_double_or_die (file, 0, data, 4, __LINE__) ;
1402 for (k = 0 ; k < 4 ; k++)
1403 { error = fabs (data [k] - ((double) k) / 100.0 * (sign *= -1)) ;
1404 if (fabs (data [k]) > 1e-100 && fabs (error / data [k]) > 1e-5)
1405 { printf ("\n\nError (%s:%d) Stereo : Incorrect sample (#%d : %f => %f).\n", __FILE__, __LINE__, k, ((double) k) / 100.0, data [k]) ;
1410 /* Seek to offset from start of file. */
1411 test_seek_or_die (file, 10, SEEK_SET, 10, sfinfo.channels, __LINE__) ;
1413 test_readf_double_or_die (file, 0, data + 20, 2, __LINE__) ;
1414 for (k = 20 ; k < 24 ; k++)
1415 { error = fabs (data [k] - ((double) k) / 100.0 * (sign *= -1)) ;
1416 if (fabs (data [k]) > 1e-100 && fabs (error / data [k]) > 1e-5)
1417 { printf ("\n\nError (%s:%d) Stereo : Incorrect sample (#%d : %f => %f).\n", __FILE__, __LINE__, k, ((double) k) / 100.0, data [k]) ;
1422 /* Seek to offset from current position. */
1423 test_seek_or_die (file, 8, SEEK_CUR, 20, sfinfo.channels, __LINE__) ;
1425 test_readf_double_or_die (file, 0, data + 40, 2, __LINE__) ;
1426 for (k = 40 ; k < 44 ; k++)
1427 { error = fabs (data [k] - ((double) k) / 100.0 * (sign *= -1)) ;
1428 if (fabs (data [k]) > 1e-100 && fabs (error / data [k]) > 1e-5)
1429 { printf ("\n\nError (%s:%d) Stereo : Incorrect sample (#%d : %f => %f).\n", __FILE__, __LINE__, k, ((double) k) / 100.0, data [k]) ;
1434 /* Seek to offset from end of file. */
1435 test_seek_or_die (file, -1 * (sfinfo.frames - 10), SEEK_END, 10, sfinfo.channels, __LINE__) ;
1437 test_readf_double_or_die (file, 0, data + 20, 2, __LINE__) ;
1438 for (k = 20 ; k < 24 ; k++)
1439 { error = fabs (data [k] - ((double) k) / 100.0 * (sign *= -1)) ;
1440 if (fabs (data [k]) > 1e-100 && fabs (error / data [k]) > 1e-5)
1441 { printf ("\n\nError (%s:%d) Stereo : Incorrect sample (#%d : %f => %f).\n", __FILE__, __LINE__, k, ((double) k) / 100.0, data [k]) ;
1450 } /* pcm_test_float */
1453 pcm_test_double (const char *filename, int filetype, uint64_t hash, int replace_float)
1456 int k, items, frames ;
1458 double *data, error ;
1460 /* This is the best test routine. Other should be brought up to this standard. */
1462 print_test_name (replace_float ? "pcm_test_double (replace)" : "pcm_test_double", filename) ;
1464 items = BUFFER_SIZE ;
1467 for (sign = 1, k = 0 ; k < items ; k++)
1468 { data [k] = ((double) (k * sign)) / 100.0 ;
1469 sign = (sign > 0) ? -1 : 1 ;
1472 sfinfo.samplerate = 44100 ;
1473 sfinfo.frames = items ;
1474 sfinfo.channels = 1 ;
1475 sfinfo.format = filetype ;
1477 file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
1478 sf_command (file, SFC_TEST_IEEE_FLOAT_REPLACE, NULL, replace_float) ;
1479 if (replace_float && string_in_log_buffer (file, "Using IEEE replacement") == 0)
1480 { printf ("\n\nLine %d : Float replacement code not working.\n\n", __LINE__) ;
1481 dump_log_buffer (file) ;
1485 test_write_double_or_die (file, 0, data, items, __LINE__) ;
1489 #if (defined (WIN32) || defined (_WIN32))
1490 /* File hashing on Win32 fails due to slighty different
1491 ** calculated values of the sin() function.
1493 hash = hash ; /* Avoid compiler warning. */
1495 check_file_hash_or_die (filename, hash, __LINE__) ;
1498 memset (data, 0, items * sizeof (double)) ;
1500 if ((filetype & SF_FORMAT_TYPEMASK) != SF_FORMAT_RAW)
1501 memset (&sfinfo, 0, sizeof (sfinfo)) ;
1503 file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
1504 sf_command (file, SFC_TEST_IEEE_FLOAT_REPLACE, NULL, replace_float) ;
1505 if (replace_float && string_in_log_buffer (file, "Using IEEE replacement") == 0)
1506 { printf ("\n\nLine %d : Float replacement code not working.\n\n", __LINE__) ;
1507 dump_log_buffer (file) ;
1511 if (sfinfo.format != filetype)
1512 { printf ("\n\nError (%s:%d) Mono : Returned format incorrect (0x%08X => 0x%08X).\n", __FILE__, __LINE__, filetype, sfinfo.format) ;
1516 if (sfinfo.frames != items)
1517 { printf ("\n\nError (%s:%d) Mono : Incorrect number of frames in file. (%d => %" PRId64 ")\n", __FILE__, __LINE__, items, sfinfo.frames) ;
1521 if (sfinfo.channels != 1)
1522 { printf ("\n\nError (%s:%d) Mono : Incorrect number of channels in file.\n", __FILE__, __LINE__) ;
1526 check_log_buffer_or_die (file, __LINE__) ;
1528 test_read_double_or_die (file, 0, data, items, __LINE__) ;
1530 for (sign = -1, k = 0 ; k < items ; k++)
1531 { error = fabs (data [k] - ((double) k) / 100.0 * (sign *= -1)) ;
1532 if (fabs (data [k]) > 1e-100 && fabs (error / data [k]) > 1e-5)
1533 { printf ("\n\nError (%s:%d) Mono : Incorrect sample (#%d : %f => %f).\n", __FILE__, __LINE__, k, ((double) k) / 100.0, data [k]) ;
1538 /* Seek to start of file. */
1539 test_seek_or_die (file, 0, SEEK_SET, 0, sfinfo.channels, __LINE__) ;
1541 test_read_double_or_die (file, 0, data, 4, __LINE__) ;
1542 for (k = 0 ; k < 4 ; k++)
1543 { error = fabs (data [k] - ((double) k) / 100.0 * (sign *= -1)) ;
1544 if (fabs (data [k]) > 1e-100 && fabs (error / data [k]) > 1e-5)
1545 { printf ("\n\nError (%s:%d) Mono : Incorrect sample (#%d : %f => %f).\n", __FILE__, __LINE__, k, ((double) k) / 100.0, data [k]) ;
1550 /* Seek to offset from start of file. */
1551 test_seek_or_die (file, 10, SEEK_SET, 10, sfinfo.channels, __LINE__) ;
1553 test_read_double_or_die (file, 0, data + 10, 4, __LINE__) ;
1555 test_seek_or_die (file, 0, SEEK_CUR, 14, sfinfo.channels, __LINE__) ;
1557 for (k = 10 ; k < 14 ; k++)
1558 { error = fabs (data [k] - ((double) k) / 100.0 * (sign *= -1)) ;
1559 if (fabs (data [k]) > 1e-100 && fabs (error / data [k]) > 1e-5)
1560 { printf ("\n\nError (%s:%d) Mono : Incorrect sample (#%d : %f => %f).\n", __FILE__, __LINE__, k, ((double) k) / 100.0, data [k]) ;
1565 /* Seek to offset from current position. */
1566 test_seek_or_die (file, 6, SEEK_CUR, 20, sfinfo.channels, __LINE__) ;
1568 test_read_double_or_die (file, 0, data + 20, 4, __LINE__) ;
1569 for (k = 20 ; k < 24 ; k++)
1570 { error = fabs (data [k] - ((double) k) / 100.0 * (sign *= -1)) ;
1571 if (fabs (data [k]) > 1e-100 && fabs (error / data [k]) > 1e-5)
1572 { printf ("\n\nError (%s:%d) Mono : Incorrect sample (#%d : %f => %f).\n", __FILE__, __LINE__, k, ((double) k) / 100.0, data [k]) ;
1577 /* Seek to offset from end of file. */
1578 test_seek_or_die (file, -1 * (sfinfo.frames - 10), SEEK_END, 10, sfinfo.channels, __LINE__) ;
1580 test_read_double_or_die (file, 0, data + 10, 4, __LINE__) ;
1581 for (k = 10 ; k < 14 ; k++)
1582 { error = fabs (data [k] - ((double) k) / 100.0 * (sign *= -1)) ;
1583 if (fabs (data [k]) > 1e-100 && fabs (error / data [k]) > 1e-5)
1584 { printf ("\n\nError (%s:%d) Mono : Incorrect sample (#%d : %f => %f).\n", __FILE__, __LINE__, k, ((double) k) / 100.0, data [k]) ;
1591 /* Now test Stereo. */
1593 if ((filetype & SF_FORMAT_TYPEMASK) == SF_FORMAT_SVX) /* SVX is mono only */
1598 items = BUFFER_SIZE ;
1601 for (sign = -1, k = 0 ; k < items ; k++)
1602 data [k] = ((double) k) / 100.0 * (sign *= -1) ;
1604 sfinfo.samplerate = 44100 ;
1605 sfinfo.frames = items ;
1606 sfinfo.channels = 2 ;
1607 sfinfo.format = filetype ;
1609 frames = items / sfinfo.channels ;
1611 file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
1612 sf_command (file, SFC_TEST_IEEE_FLOAT_REPLACE, NULL, replace_float) ;
1613 if (replace_float && string_in_log_buffer (file, "Using IEEE replacement") == 0)
1614 { printf ("\n\nLine %d : Float replacement code not working.\n\n", __LINE__) ;
1615 dump_log_buffer (file) ;
1619 test_writef_double_or_die (file, 0, data, frames, __LINE__) ;
1623 #if (defined (WIN32) || defined (_WIN32))
1624 /* File hashing on Win32 fails due to slighty different
1625 ** calculated values.
1627 hash = hash ; /* Avoid compiler warning. */
1629 check_file_hash_or_die (filename, hash, __LINE__) ;
1632 memset (data, 0, items * sizeof (double)) ;
1634 if ((filetype & SF_FORMAT_TYPEMASK) != SF_FORMAT_RAW)
1635 memset (&sfinfo, 0, sizeof (sfinfo)) ;
1637 file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
1638 sf_command (file, SFC_TEST_IEEE_FLOAT_REPLACE, NULL, replace_float) ;
1639 if (replace_float && string_in_log_buffer (file, "Using IEEE replacement") == 0)
1640 { printf ("\n\nLine %d : Float replacement code not working.\n\n", __LINE__) ;
1641 dump_log_buffer (file) ;
1645 if (sfinfo.format != filetype)
1646 { printf ("\n\nError (%s:%d) Stereo : Returned format incorrect (0x%08X => 0x%08X).\n", __FILE__, __LINE__, filetype, sfinfo.format) ;
1650 if (sfinfo.frames != frames)
1651 { printf ("\n\nError (%s:%d) Stereo : Incorrect number of frames in file. (%d => %" PRId64 ")\n", __FILE__, __LINE__, frames, sfinfo.frames) ;
1655 if (sfinfo.channels != 2)
1656 { printf ("\n\nError (%s:%d) Stereo : Incorrect number of channels in file.\n", __FILE__, __LINE__) ;
1660 check_log_buffer_or_die (file, __LINE__) ;
1662 test_readf_double_or_die (file, 0, data, frames, __LINE__) ;
1664 for (sign = -1, k = 0 ; k < items ; k++)
1665 { error = fabs (data [k] - ((double) k) / 100.0 * (sign *= -1)) ;
1666 if (fabs (data [k]) > 1e-100 && fabs (error / data [k]) > 1e-5)
1667 { printf ("\n\nError (%s:%d) Stereo : Incorrect sample (#%d : %f => %f).\n", __FILE__, __LINE__, k, ((double) k) / 100.0, data [k]) ;
1672 /* Seek to start of file. */
1673 test_seek_or_die (file, 0, SEEK_SET, 0, sfinfo.channels, __LINE__) ;
1675 test_read_double_or_die (file, 0, data, 4, __LINE__) ;
1676 for (k = 0 ; k < 4 ; k++)
1677 { error = fabs (data [k] - ((double) k) / 100.0 * (sign *= -1)) ;
1678 if (fabs (data [k]) > 1e-100 && fabs (error / data [k]) > 1e-5)
1679 { printf ("\n\nError (%s:%d) Stereo : Incorrect sample (#%d : %f => %f).\n", __FILE__, __LINE__, k, ((double) k) / 100.0, data [k]) ;
1684 /* Seek to offset from start of file. */
1685 test_seek_or_die (file, 10, SEEK_SET, 10, sfinfo.channels, __LINE__) ;
1687 test_read_double_or_die (file, 0, data + 10, 4, __LINE__) ;
1688 for (k = 20 ; k < 24 ; k++)
1689 { error = fabs (data [k] - ((double) k) / 100.0 * (sign *= -1)) ;
1690 if (fabs (data [k]) > 1e-100 && fabs (error / data [k]) > 1e-5)
1691 { printf ("\n\nError (%s:%d) Stereo : Incorrect sample (#%d : %f => %f).\n", __FILE__, __LINE__, k, ((double) k) / 100.0, data [k]) ;
1696 /* Seek to offset from current position. */
1697 test_seek_or_die (file, 8, SEEK_CUR, 20, sfinfo.channels, __LINE__) ;
1699 test_readf_double_or_die (file, 0, data + 40, 4, __LINE__) ;
1700 for (k = 40 ; k < 44 ; k++)
1701 { error = fabs (data [k] - ((double) k) / 100.0 * (sign *= -1)) ;
1702 if (fabs (data [k]) > 1e-100 && fabs (error / data [k]) > 1e-5)
1703 { printf ("\n\nError (%s:%d) Stereo : Incorrect sample (#%d : %f => %f).\n", __FILE__, __LINE__, k, ((double) k) / 100.0, data [k]) ;
1708 /* Seek to offset from end of file. */
1709 test_seek_or_die (file, -1 * (sfinfo.frames -10), SEEK_END, 10, sfinfo.channels, __LINE__) ;
1711 test_readf_double_or_die (file, 0, data + 20, 4, __LINE__) ;
1712 for (k = 20 ; k < 24 ; k++)
1713 { error = fabs (data [k] - ((double) k) / 100.0 * (sign *= -1)) ;
1714 if (fabs (data [k]) > 1e-100 && fabs (error / data [k]) > 1e-5)
1715 { printf ("\n\nError (%s:%d) Stereo : Incorrect sample (#%d : %f => %f).\n", __FILE__, __LINE__, k, ((double) k) / 100.0, data [k]) ;
1724 } /* pcm_test_double */
1726 /*==============================================================================