2
** Copyright (C) 1999-2004 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.
31
#include "float_cast.h"
34
#define BUFFER_SIZE (1<<15)
36
static void lrintf_test (void) ;
38
static void pcm_test_bits_8 (const char *filename, int filetype, int hash) ;
39
static void pcm_test_bits_16 (const char *filename, int filetype, int hash) ;
40
static void pcm_test_bits_24 (const char *filename, int filetype, int hash) ;
41
static void pcm_test_bits_32 (const char *filename, int filetype, int hash) ;
43
static void pcm_test_float (const char *filename, int filetype, int hash, int replace_float) ;
44
static void pcm_test_double (const char *filename, int filetype, int hash, int replace_float) ;
46
/* Data written to the file. */
47
static double data_out [(BUFFER_SIZE / sizeof (double)) + 1] ;
49
/* Data read back from the file. */
50
static double data_in [(BUFFER_SIZE / sizeof (double)) + 1] ;
57
pcm_test_bits_8 ("pcm-s8.raw", SF_FORMAT_RAW | SF_FORMAT_PCM_S8, 0x9ae33814) ;
58
pcm_test_bits_8 ("pcm-u8.raw", SF_FORMAT_RAW | SF_FORMAT_PCM_U8, 0x651d4694) ;
60
pcm_test_bits_16 ("le-pcm16.raw", SF_ENDIAN_LITTLE | SF_FORMAT_RAW | SF_FORMAT_PCM_16, 0x16866fa0) ;
61
pcm_test_bits_16 ("be-pcm16.raw", SF_ENDIAN_BIG | SF_FORMAT_RAW | SF_FORMAT_PCM_16, 0xc571826c) ;
63
pcm_test_bits_24 ("le-pcm24.raw", SF_ENDIAN_LITTLE | SF_FORMAT_RAW | SF_FORMAT_PCM_24, 0x658e4bb6) ;
64
pcm_test_bits_24 ("be-pcm24.raw", SF_ENDIAN_BIG | SF_FORMAT_RAW | SF_FORMAT_PCM_24, 0xbf8cde4a) ;
66
pcm_test_bits_32 ("le-pcm32.raw", SF_ENDIAN_LITTLE | SF_FORMAT_RAW | SF_FORMAT_PCM_32, 0x04c84a70) ;
67
pcm_test_bits_32 ("be-pcm32.raw", SF_ENDIAN_BIG | SF_FORMAT_RAW | SF_FORMAT_PCM_32, 0x069c84f6) ;
69
/* Lite remove start */
70
pcm_test_float ("le-float.raw", SF_ENDIAN_LITTLE | SF_FORMAT_RAW | SF_FORMAT_FLOAT, 0xbb836603, SF_FALSE) ;
71
pcm_test_float ("be-float.raw", SF_ENDIAN_BIG | SF_FORMAT_RAW | SF_FORMAT_FLOAT, 0x903cd8fc, SF_FALSE) ;
73
pcm_test_double ("le-double.raw", SF_ENDIAN_LITTLE | SF_FORMAT_RAW | SF_FORMAT_DOUBLE, 0xbf84448e, SF_FALSE) ;
74
pcm_test_double ("be-double.raw", SF_ENDIAN_BIG | SF_FORMAT_RAW | SF_FORMAT_DOUBLE, 0xaf3d9fb5, SF_FALSE) ;
76
puts ("Test IEEE replacement code.") ;
78
pcm_test_float ("le-float.raw", SF_ENDIAN_LITTLE | SF_FORMAT_RAW | SF_FORMAT_FLOAT, 0xbb836603, SF_TRUE) ;
79
pcm_test_float ("be-float.raw", SF_ENDIAN_BIG | SF_FORMAT_RAW | SF_FORMAT_FLOAT, 0x903cd8fc, SF_TRUE) ;
81
pcm_test_double ("le-double.raw", SF_ENDIAN_LITTLE | SF_FORMAT_RAW | SF_FORMAT_DOUBLE, 0xbf84448e, SF_TRUE) ;
82
pcm_test_double ("be-double.raw", SF_ENDIAN_BIG | SF_FORMAT_RAW | SF_FORMAT_DOUBLE, 0xaf3d9fb5, SF_TRUE) ;
88
/*============================================================================================
89
** Here are the test functions.
98
print_test_name ("lrintf_test", "") ;
102
float_data = (float*) data_out ;
103
int_data = (int*) data_in ;
105
for (k = 0 ; k < items ; k++)
106
float_data [k] = (k * ((k % 2) ? 333333.0 : -333333.0)) ;
108
for (k = 0 ; k < items ; k++)
109
int_data [k] = lrintf (float_data [k]) ;
111
for (k = 0 ; k < items ; k++)
112
if (fabs (int_data [k] - float_data [k]) > 1.0)
113
{ printf ("\n\nLine %d: float : Incorrect sample (#%d : %f => %d).\n", __LINE__, k, float_data [k], int_data [k]) ;
121
pcm_test_bits_8 (const char *filename, int filetype, int hash)
124
int k, items, zero_count ;
125
short *short_out, *short_in ;
126
int *int_out, *int_in ;
127
/* Lite remove start */
128
float *float_out, *float_in ;
129
double *double_out, *double_in ;
130
/* Lite remove end */
132
print_test_name ("pcm_test_bits_8", filename) ;
136
short_out = (short*) data_out ;
137
short_in = (short*) data_in ;
140
for (k = 0 ; k < items ; k++)
141
{ short_out [k] = ((k * ((k % 2) ? 1 : -1)) << 8) ;
142
zero_count = short_out [k] ? zero_count : zero_count + 1 ;
145
if (zero_count > items / 4)
146
{ printf ("\n\nLine %d: too many zeros.\n", __LINE__) ;
150
sfinfo.samplerate = 44100 ;
151
sfinfo.frames = 123456789 ; /* Wrong length. Library should correct this on sf_close. */
152
sfinfo.channels = 1 ;
153
sfinfo.format = filetype ;
155
file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
157
test_write_short_or_die (file, 0, short_out, items, __LINE__) ;
161
memset (short_in, 0, items * sizeof (short)) ;
163
file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
165
if (sfinfo.format != filetype)
166
{ printf ("\n\nLine %d: Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__, filetype, sfinfo.format) ;
170
if (sfinfo.frames != items)
171
{ printf ("\n\nLine %d: Incorrect number of frames in file. (%d => %ld)\n", __LINE__, items, SF_COUNT_TO_LONG (sfinfo.frames)) ;
175
if (sfinfo.channels != 1)
176
{ printf ("\n\nLine %d: Incorrect number of channels in file.\n", __LINE__) ;
180
check_log_buffer_or_die (file, __LINE__) ;
182
test_read_short_or_die (file, 0, short_in, items, __LINE__) ;
184
for (k = 0 ; k < items ; k++)
185
if (short_out [k] != short_in [k])
186
{ printf ("\n\nLine %d: Incorrect sample (#%d : 0x%x => 0x%x).\n", __LINE__, k, short_out [k], short_in [k]) ;
192
/* Finally, check the file hash. */
193
check_file_hash_or_die (filename, hash, __LINE__) ;
195
/*--------------------------------------------------------------------------
196
** Test sf_read/write_int ()
200
int_out = (int*) data_out ;
201
int_in = (int*) data_in ;
202
for (k = 0 ; k < items ; k++)
203
{ int_out [k] = ((k * ((k % 2) ? 1 : -1)) << 24) ;
204
zero_count = int_out [k] ? zero_count : zero_count + 1 ;
207
if (zero_count > items / 4)
208
{ printf ("\n\nLine %d: too many zeros.\n", __LINE__) ;
212
sfinfo.samplerate = 44100 ;
213
sfinfo.frames = 123456789 ; /* Wrong length. Library should correct this on sf_close. */
214
sfinfo.channels = 1 ;
215
sfinfo.format = filetype ;
217
file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
219
test_write_int_or_die (file, 0, int_out, items, __LINE__) ;
223
memset (int_in, 0, items * sizeof (int)) ;
225
file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
227
if (sfinfo.format != filetype)
228
{ printf ("\n\nLine %d: Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__, filetype, sfinfo.format) ;
232
if (sfinfo.frames != items)
233
{ printf ("\n\nLine %d: Incorrect number of frames in file. (%d => %ld)\n", __LINE__, items, SF_COUNT_TO_LONG (sfinfo.frames)) ;
237
if (sfinfo.channels != 1)
238
{ printf ("\n\nLine %d: Incorrect number of channels in file.\n", __LINE__) ;
242
check_log_buffer_or_die (file, __LINE__) ;
244
test_read_int_or_die (file, 0, int_in, items, __LINE__) ;
246
for (k = 0 ; k < items ; k++)
247
if (int_out [k] != int_in [k])
248
{ printf ("\n\nLine %d: int : Incorrect sample (#%d : 0x%x => 0x%x).\n", __LINE__, k, int_out [k], int_in [k]) ;
254
/* Lite remove start */
255
/*--------------------------------------------------------------------------
256
** Test sf_read/write_float ()
260
float_out = (float*) data_out ;
261
float_in = (float*) data_in ;
262
for (k = 0 ; k < items ; k++)
263
{ float_out [k] = (k * ((k % 2) ? 1 : -1)) ;
264
zero_count = (fabs (float_out [k]) > 1e-10) ? zero_count : zero_count + 1 ;
267
if (zero_count > items / 4)
268
{ printf ("\n\nLine %d: too many zeros (%d/%d).\n", __LINE__, zero_count, items) ;
272
sfinfo.samplerate = 44100 ;
273
sfinfo.frames = 123456789 ; /* Wrong length. Library should correct this on sf_close. */
274
sfinfo.channels = 1 ;
275
sfinfo.format = filetype ;
277
file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
279
sf_command (file, SFC_SET_NORM_FLOAT, NULL, SF_FALSE) ;
281
test_write_float_or_die (file, 0, float_out, items, __LINE__) ;
285
memset (float_in, 0, items * sizeof (float)) ;
287
file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
289
if (sfinfo.format != filetype)
290
{ printf ("\n\nLine %d: Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__, filetype, sfinfo.format) ;
294
if (sfinfo.frames != items)
295
{ printf ("\n\nLine %d: Incorrect number of frames in file. (%d => %ld)\n", __LINE__, items, SF_COUNT_TO_LONG (sfinfo.frames)) ;
299
if (sfinfo.channels != 1)
300
{ printf ("\n\nLine %d: Incorrect number of channels in file.\n", __LINE__) ;
304
check_log_buffer_or_die (file, __LINE__) ;
306
sf_command (file, SFC_SET_NORM_FLOAT, NULL, SF_FALSE) ;
308
test_read_float_or_die (file, 0, float_in, items, __LINE__) ;
310
for (k = 0 ; k < items ; k++)
311
if (fabs (float_out [k] - float_in [k]) > 1e-10)
312
{ printf ("\n\nLine %d: float : Incorrect sample (#%d : %f => %f).\n", __LINE__, k, (double) float_out [k], (double) float_in [k]) ;
319
/*--------------------------------------------------------------------------
320
** Test sf_read/write_double ()
324
double_out = (double*) data_out ;
325
double_in = (double*) data_in ;
326
for (k = 0 ; k < items ; k++)
327
{ double_out [k] = (k * ((k % 2) ? 1 : -1)) ;
328
zero_count = (fabs (double_out [k]) > 1e-10) ? zero_count : zero_count + 1 ;
331
if (zero_count > items / 4)
332
{ printf ("\n\nLine %d: too many zeros (%d/%d).\n", __LINE__, zero_count, items) ;
336
sfinfo.samplerate = 44100 ;
337
sfinfo.frames = 123456789 ; /* Wrong length. Library should correct this on sf_close. */
338
sfinfo.channels = 1 ;
339
sfinfo.format = filetype ;
341
file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
343
sf_command (file, SFC_SET_NORM_DOUBLE, NULL, SF_FALSE) ;
345
test_write_double_or_die (file, 0, double_out, items, __LINE__) ;
349
memset (double_in, 0, items * sizeof (double)) ;
351
file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
353
if (sfinfo.format != filetype)
354
{ printf ("\n\nLine %d: Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__, filetype, sfinfo.format) ;
358
if (sfinfo.frames != items)
359
{ printf ("\n\nLine %d: Incorrect number of frames in file. (%d => %ld)\n", __LINE__, items, SF_COUNT_TO_LONG (sfinfo.frames)) ;
363
if (sfinfo.channels != 1)
364
{ printf ("\n\nLine %d: Incorrect number of channels in file.\n", __LINE__) ;
368
check_log_buffer_or_die (file, __LINE__) ;
370
sf_command (file, SFC_SET_NORM_DOUBLE, NULL, SF_FALSE) ;
372
test_read_double_or_die (file, 0, double_in, items, __LINE__) ;
374
for (k = 0 ; k < items ; k++)
375
if (fabs (double_out [k] - double_in [k]) > 1e-10)
376
{ printf ("\n\nLine %d: double : Incorrect sample (#%d : %f => %f).\n", __LINE__, k, double_out [k], double_in [k]) ;
381
/* Lite remove end */
385
} /* pcm_test_bits_8 */
388
pcm_test_bits_16 (const char *filename, int filetype, int hash)
391
int k, items, zero_count ;
392
short *short_out, *short_in ;
393
int *int_out, *int_in ;
394
/* Lite remove start */
395
float *float_out, *float_in ;
396
double *double_out, *double_in ;
397
/* Lite remove end */
399
print_test_name ("pcm_test_bits_16", filename) ;
403
short_out = (short*) data_out ;
404
short_in = (short*) data_in ;
407
for (k = 0 ; k < items ; k++)
408
{ short_out [k] = (k * ((k % 2) ? 3 : -3)) ;
409
zero_count = short_out [k] ? zero_count : zero_count + 1 ;
412
if (zero_count > items / 4)
413
{ printf ("\n\nLine %d: too many zeros.\n", __LINE__) ;
417
sfinfo.samplerate = 44100 ;
418
sfinfo.frames = 123456789 ; /* Wrong length. Library should correct this on sf_close. */
419
sfinfo.channels = 1 ;
420
sfinfo.format = filetype ;
422
file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
424
test_write_short_or_die (file, 0, short_out, items, __LINE__) ;
428
memset (short_in, 0, items * sizeof (short)) ;
430
file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
432
if (sfinfo.format != filetype)
433
{ printf ("\n\nLine %d: Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__, filetype, sfinfo.format) ;
437
if (sfinfo.frames != items)
438
{ printf ("\n\nLine %d: Incorrect number of frames in file. (%d => %ld)\n", __LINE__, items, SF_COUNT_TO_LONG (sfinfo.frames)) ;
442
if (sfinfo.channels != 1)
443
{ printf ("\n\nLine %d: Incorrect number of channels in file.\n", __LINE__) ;
447
check_log_buffer_or_die (file, __LINE__) ;
449
test_read_short_or_die (file, 0, short_in, items, __LINE__) ;
451
for (k = 0 ; k < items ; k++)
452
if (short_out [k] != short_in [k])
453
{ printf ("\n\nLine %d: Incorrect sample (#%d : 0x%x => 0x%x).\n", __LINE__, k, short_out [k], short_in [k]) ;
459
/* Finally, check the file hash. */
460
check_file_hash_or_die (filename, hash, __LINE__) ;
462
/*--------------------------------------------------------------------------
463
** Test sf_read/write_int ()
467
int_out = (int*) data_out ;
468
int_in = (int*) data_in ;
469
for (k = 0 ; k < items ; k++)
470
{ int_out [k] = ((k * ((k % 2) ? 3 : -3)) << 16) ;
471
zero_count = int_out [k] ? zero_count : zero_count + 1 ;
474
if (zero_count > items / 4)
475
{ printf ("\n\nLine %d: too many zeros.\n", __LINE__) ;
479
sfinfo.samplerate = 44100 ;
480
sfinfo.frames = 123456789 ; /* Wrong length. Library should correct this on sf_close. */
481
sfinfo.channels = 1 ;
482
sfinfo.format = filetype ;
484
file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
486
test_write_int_or_die (file, 0, int_out, items, __LINE__) ;
490
memset (int_in, 0, items * sizeof (int)) ;
492
file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
494
if (sfinfo.format != filetype)
495
{ printf ("\n\nLine %d: Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__, filetype, sfinfo.format) ;
499
if (sfinfo.frames != items)
500
{ printf ("\n\nLine %d: Incorrect number of frames in file. (%d => %ld)\n", __LINE__, items, SF_COUNT_TO_LONG (sfinfo.frames)) ;
504
if (sfinfo.channels != 1)
505
{ printf ("\n\nLine %d: Incorrect number of channels in file.\n", __LINE__) ;
509
check_log_buffer_or_die (file, __LINE__) ;
511
test_read_int_or_die (file, 0, int_in, items, __LINE__) ;
513
for (k = 0 ; k < items ; k++)
514
if (int_out [k] != int_in [k])
515
{ printf ("\n\nLine %d: int : Incorrect sample (#%d : 0x%x => 0x%x).\n", __LINE__, k, int_out [k], int_in [k]) ;
521
/* Lite remove start */
522
/*--------------------------------------------------------------------------
523
** Test sf_read/write_float ()
527
float_out = (float*) data_out ;
528
float_in = (float*) data_in ;
529
for (k = 0 ; k < items ; k++)
530
{ float_out [k] = (k * ((k % 2) ? 3 : -3)) ;
531
zero_count = (fabs (float_out [k]) > 1e-10) ? zero_count : zero_count + 1 ;
534
if (zero_count > items / 4)
535
{ printf ("\n\nLine %d: too many zeros (%d/%d).\n", __LINE__, zero_count, items) ;
539
sfinfo.samplerate = 44100 ;
540
sfinfo.frames = 123456789 ; /* Wrong length. Library should correct this on sf_close. */
541
sfinfo.channels = 1 ;
542
sfinfo.format = filetype ;
544
file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
546
sf_command (file, SFC_SET_NORM_FLOAT, NULL, SF_FALSE) ;
548
test_write_float_or_die (file, 0, float_out, items, __LINE__) ;
552
memset (float_in, 0, items * sizeof (float)) ;
554
file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
556
if (sfinfo.format != filetype)
557
{ printf ("\n\nLine %d: Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__, filetype, sfinfo.format) ;
561
if (sfinfo.frames != items)
562
{ printf ("\n\nLine %d: Incorrect number of frames in file. (%d => %ld)\n", __LINE__, items, SF_COUNT_TO_LONG (sfinfo.frames)) ;
566
if (sfinfo.channels != 1)
567
{ printf ("\n\nLine %d: Incorrect number of channels in file.\n", __LINE__) ;
571
check_log_buffer_or_die (file, __LINE__) ;
573
sf_command (file, SFC_SET_NORM_FLOAT, NULL, SF_FALSE) ;
575
test_read_float_or_die (file, 0, float_in, items, __LINE__) ;
577
for (k = 0 ; k < items ; k++)
578
if (fabs (float_out [k] - float_in [k]) > 1e-10)
579
{ printf ("\n\nLine %d: float : Incorrect sample (#%d : %f => %f).\n", __LINE__, k, (double) float_out [k], (double) float_in [k]) ;
586
/*--------------------------------------------------------------------------
587
** Test sf_read/write_double ()
591
double_out = (double*) data_out ;
592
double_in = (double*) data_in ;
593
for (k = 0 ; k < items ; k++)
594
{ double_out [k] = (k * ((k % 2) ? 3 : -3)) ;
595
zero_count = (fabs (double_out [k]) > 1e-10) ? zero_count : zero_count + 1 ;
598
if (zero_count > items / 4)
599
{ printf ("\n\nLine %d: too many zeros (%d/%d).\n", __LINE__, zero_count, items) ;
603
sfinfo.samplerate = 44100 ;
604
sfinfo.frames = 123456789 ; /* Wrong length. Library should correct this on sf_close. */
605
sfinfo.channels = 1 ;
606
sfinfo.format = filetype ;
608
file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
610
sf_command (file, SFC_SET_NORM_DOUBLE, NULL, SF_FALSE) ;
612
test_write_double_or_die (file, 0, double_out, items, __LINE__) ;
616
memset (double_in, 0, items * sizeof (double)) ;
618
file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
620
if (sfinfo.format != filetype)
621
{ printf ("\n\nLine %d: Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__, filetype, sfinfo.format) ;
625
if (sfinfo.frames != items)
626
{ printf ("\n\nLine %d: Incorrect number of frames in file. (%d => %ld)\n", __LINE__, items, SF_COUNT_TO_LONG (sfinfo.frames)) ;
630
if (sfinfo.channels != 1)
631
{ printf ("\n\nLine %d: Incorrect number of channels in file.\n", __LINE__) ;
635
check_log_buffer_or_die (file, __LINE__) ;
637
sf_command (file, SFC_SET_NORM_DOUBLE, NULL, SF_FALSE) ;
639
test_read_double_or_die (file, 0, double_in, items, __LINE__) ;
641
for (k = 0 ; k < items ; k++)
642
if (fabs (double_out [k] - double_in [k]) > 1e-10)
643
{ printf ("\n\nLine %d: double : Incorrect sample (#%d : %f => %f).\n", __LINE__, k, double_out [k], double_in [k]) ;
648
/* Lite remove end */
652
} /* pcm_test_bits_16 */
655
pcm_test_bits_24 (const char *filename, int filetype, int hash)
658
int k, items, zero_count ;
659
short *short_out, *short_in ;
660
int *int_out, *int_in ;
661
/* Lite remove start */
662
float *float_out, *float_in ;
663
double *double_out, *double_in ;
664
/* Lite remove end */
666
print_test_name ("pcm_test_bits_24", filename) ;
670
short_out = (short*) data_out ;
671
short_in = (short*) data_in ;
674
for (k = 0 ; k < items ; k++)
675
{ short_out [k] = (k * ((k % 2) ? 3 : -3)) ;
676
zero_count = short_out [k] ? zero_count : zero_count + 1 ;
679
if (zero_count > items / 4)
680
{ printf ("\n\nLine %d: too many zeros.\n", __LINE__) ;
684
sfinfo.samplerate = 44100 ;
685
sfinfo.frames = 123456789 ; /* Wrong length. Library should correct this on sf_close. */
686
sfinfo.channels = 1 ;
687
sfinfo.format = filetype ;
689
file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
691
test_write_short_or_die (file, 0, short_out, items, __LINE__) ;
695
memset (short_in, 0, items * sizeof (short)) ;
697
file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
699
if (sfinfo.format != filetype)
700
{ printf ("\n\nLine %d: Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__, filetype, sfinfo.format) ;
704
if (sfinfo.frames != items)
705
{ printf ("\n\nLine %d: Incorrect number of frames in file. (%d => %ld)\n", __LINE__, items, SF_COUNT_TO_LONG (sfinfo.frames)) ;
709
if (sfinfo.channels != 1)
710
{ printf ("\n\nLine %d: Incorrect number of channels in file.\n", __LINE__) ;
714
check_log_buffer_or_die (file, __LINE__) ;
716
test_read_short_or_die (file, 0, short_in, items, __LINE__) ;
718
for (k = 0 ; k < items ; k++)
719
if (short_out [k] != short_in [k])
720
{ printf ("\n\nLine %d: Incorrect sample (#%d : 0x%x => 0x%x).\n", __LINE__, k, short_out [k], short_in [k]) ;
726
/* Finally, check the file hash. */
727
check_file_hash_or_die (filename, hash, __LINE__) ;
729
/*--------------------------------------------------------------------------
730
** Test sf_read/write_int ()
734
int_out = (int*) data_out ;
735
int_in = (int*) data_in ;
736
for (k = 0 ; k < items ; k++)
737
{ int_out [k] = ((k * ((k % 2) ? 3333 : -3333)) << 8) ;
738
zero_count = int_out [k] ? zero_count : zero_count + 1 ;
741
if (zero_count > items / 4)
742
{ printf ("\n\nLine %d: too many zeros.\n", __LINE__) ;
746
sfinfo.samplerate = 44100 ;
747
sfinfo.frames = 123456789 ; /* Wrong length. Library should correct this on sf_close. */
748
sfinfo.channels = 1 ;
749
sfinfo.format = filetype ;
751
file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
753
test_write_int_or_die (file, 0, int_out, items, __LINE__) ;
757
memset (int_in, 0, items * sizeof (int)) ;
759
file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
761
if (sfinfo.format != filetype)
762
{ printf ("\n\nLine %d: Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__, filetype, sfinfo.format) ;
766
if (sfinfo.frames != items)
767
{ printf ("\n\nLine %d: Incorrect number of frames in file. (%d => %ld)\n", __LINE__, items, SF_COUNT_TO_LONG (sfinfo.frames)) ;
771
if (sfinfo.channels != 1)
772
{ printf ("\n\nLine %d: Incorrect number of channels in file.\n", __LINE__) ;
776
check_log_buffer_or_die (file, __LINE__) ;
778
test_read_int_or_die (file, 0, int_in, items, __LINE__) ;
780
for (k = 0 ; k < items ; k++)
781
if (int_out [k] != int_in [k])
782
{ printf ("\n\nLine %d: int : Incorrect sample (#%d : 0x%x => 0x%x).\n", __LINE__, k, int_out [k], int_in [k]) ;
788
/* Lite remove start */
789
/*--------------------------------------------------------------------------
790
** Test sf_read/write_float ()
794
float_out = (float*) data_out ;
795
float_in = (float*) data_in ;
796
for (k = 0 ; k < items ; k++)
797
{ float_out [k] = (k * ((k % 2) ? 3333 : -3333)) ;
798
zero_count = (fabs (float_out [k]) > 1e-10) ? zero_count : zero_count + 1 ;
801
if (zero_count > items / 4)
802
{ printf ("\n\nLine %d: too many zeros (%d/%d).\n", __LINE__, zero_count, items) ;
806
sfinfo.samplerate = 44100 ;
807
sfinfo.frames = 123456789 ; /* Wrong length. Library should correct this on sf_close. */
808
sfinfo.channels = 1 ;
809
sfinfo.format = filetype ;
811
file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
813
sf_command (file, SFC_SET_NORM_FLOAT, NULL, SF_FALSE) ;
815
test_write_float_or_die (file, 0, float_out, items, __LINE__) ;
819
memset (float_in, 0, items * sizeof (float)) ;
821
file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
823
if (sfinfo.format != filetype)
824
{ printf ("\n\nLine %d: Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__, filetype, sfinfo.format) ;
828
if (sfinfo.frames != items)
829
{ printf ("\n\nLine %d: Incorrect number of frames in file. (%d => %ld)\n", __LINE__, items, SF_COUNT_TO_LONG (sfinfo.frames)) ;
833
if (sfinfo.channels != 1)
834
{ printf ("\n\nLine %d: Incorrect number of channels in file.\n", __LINE__) ;
838
check_log_buffer_or_die (file, __LINE__) ;
840
sf_command (file, SFC_SET_NORM_FLOAT, NULL, SF_FALSE) ;
842
test_read_float_or_die (file, 0, float_in, items, __LINE__) ;
844
for (k = 0 ; k < items ; k++)
845
if (fabs (float_out [k] - float_in [k]) > 1e-10)
846
{ printf ("\n\nLine %d: float : Incorrect sample (#%d : %f => %f).\n", __LINE__, k, (double) float_out [k], (double) float_in [k]) ;
853
/*--------------------------------------------------------------------------
854
** Test sf_read/write_double ()
858
double_out = (double*) data_out ;
859
double_in = (double*) data_in ;
860
for (k = 0 ; k < items ; k++)
861
{ double_out [k] = (k * ((k % 2) ? 3333 : -3333)) ;
862
zero_count = (fabs (double_out [k]) > 1e-10) ? zero_count : zero_count + 1 ;
865
if (zero_count > items / 4)
866
{ printf ("\n\nLine %d: too many zeros (%d/%d).\n", __LINE__, zero_count, items) ;
870
sfinfo.samplerate = 44100 ;
871
sfinfo.frames = 123456789 ; /* Wrong length. Library should correct this on sf_close. */
872
sfinfo.channels = 1 ;
873
sfinfo.format = filetype ;
875
file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
877
sf_command (file, SFC_SET_NORM_DOUBLE, NULL, SF_FALSE) ;
879
test_write_double_or_die (file, 0, double_out, items, __LINE__) ;
883
memset (double_in, 0, items * sizeof (double)) ;
885
file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
887
if (sfinfo.format != filetype)
888
{ printf ("\n\nLine %d: Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__, filetype, sfinfo.format) ;
892
if (sfinfo.frames != items)
893
{ printf ("\n\nLine %d: Incorrect number of frames in file. (%d => %ld)\n", __LINE__, items, SF_COUNT_TO_LONG (sfinfo.frames)) ;
897
if (sfinfo.channels != 1)
898
{ printf ("\n\nLine %d: Incorrect number of channels in file.\n", __LINE__) ;
902
check_log_buffer_or_die (file, __LINE__) ;
904
sf_command (file, SFC_SET_NORM_DOUBLE, NULL, SF_FALSE) ;
906
test_read_double_or_die (file, 0, double_in, items, __LINE__) ;
908
for (k = 0 ; k < items ; k++)
909
if (fabs (double_out [k] - double_in [k]) > 1e-10)
910
{ printf ("\n\nLine %d: double : Incorrect sample (#%d : %f => %f).\n", __LINE__, k, double_out [k], double_in [k]) ;
915
/* Lite remove end */
919
} /* pcm_test_bits_24 */
922
pcm_test_bits_32 (const char *filename, int filetype, int hash)
925
int k, items, zero_count ;
926
short *short_out, *short_in ;
927
int *int_out, *int_in ;
928
/* Lite remove start */
929
float *float_out, *float_in ;
930
double *double_out, *double_in ;
931
/* Lite remove end */
933
print_test_name ("pcm_test_bits_32", filename) ;
937
short_out = (short*) data_out ;
938
short_in = (short*) data_in ;
941
for (k = 0 ; k < items ; k++)
942
{ short_out [k] = (k * ((k % 2) ? 3 : -3)) ;
943
zero_count = short_out [k] ? zero_count : zero_count + 1 ;
946
if (zero_count > items / 4)
947
{ printf ("\n\nLine %d: too many zeros.\n", __LINE__) ;
951
sfinfo.samplerate = 44100 ;
952
sfinfo.frames = 123456789 ; /* Wrong length. Library should correct this on sf_close. */
953
sfinfo.channels = 1 ;
954
sfinfo.format = filetype ;
956
file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
958
test_write_short_or_die (file, 0, short_out, items, __LINE__) ;
962
memset (short_in, 0, items * sizeof (short)) ;
964
file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
966
if (sfinfo.format != filetype)
967
{ printf ("\n\nLine %d: Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__, filetype, sfinfo.format) ;
971
if (sfinfo.frames != items)
972
{ printf ("\n\nLine %d: Incorrect number of frames in file. (%d => %ld)\n", __LINE__, items, SF_COUNT_TO_LONG (sfinfo.frames)) ;
976
if (sfinfo.channels != 1)
977
{ printf ("\n\nLine %d: Incorrect number of channels in file.\n", __LINE__) ;
981
check_log_buffer_or_die (file, __LINE__) ;
983
test_read_short_or_die (file, 0, short_in, items, __LINE__) ;
985
for (k = 0 ; k < items ; k++)
986
if (short_out [k] != short_in [k])
987
{ printf ("\n\nLine %d: Incorrect sample (#%d : 0x%x => 0x%x).\n", __LINE__, k, short_out [k], short_in [k]) ;
993
/* Finally, check the file hash. */
994
check_file_hash_or_die (filename, hash, __LINE__) ;
996
/*--------------------------------------------------------------------------
997
** Test sf_read/write_int ()
1001
int_out = (int*) data_out ;
1002
int_in = (int*) data_in ;
1003
for (k = 0 ; k < items ; k++)
1004
{ int_out [k] = (k * ((k % 2) ? 333333 : -333333)) ;
1005
zero_count = int_out [k] ? zero_count : zero_count + 1 ;
1008
if (zero_count > items / 4)
1009
{ printf ("\n\nLine %d: too many zeros.\n", __LINE__) ;
1013
sfinfo.samplerate = 44100 ;
1014
sfinfo.frames = 123456789 ; /* Wrong length. Library should correct this on sf_close. */
1015
sfinfo.channels = 1 ;
1016
sfinfo.format = filetype ;
1018
file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
1020
test_write_int_or_die (file, 0, int_out, items, __LINE__) ;
1024
memset (int_in, 0, items * sizeof (int)) ;
1026
file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
1028
if (sfinfo.format != filetype)
1029
{ printf ("\n\nLine %d: Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__, filetype, sfinfo.format) ;
1033
if (sfinfo.frames != items)
1034
{ printf ("\n\nLine %d: Incorrect number of frames in file. (%d => %ld)\n", __LINE__, items, SF_COUNT_TO_LONG (sfinfo.frames)) ;
1038
if (sfinfo.channels != 1)
1039
{ printf ("\n\nLine %d: Incorrect number of channels in file.\n", __LINE__) ;
1043
check_log_buffer_or_die (file, __LINE__) ;
1045
test_read_int_or_die (file, 0, int_in, items, __LINE__) ;
1047
for (k = 0 ; k < items ; k++)
1048
if (int_out [k] != int_in [k])
1049
{ printf ("\n\nLine %d: int : Incorrect sample (#%d : 0x%x => 0x%x).\n", __LINE__, k, int_out [k], int_in [k]) ;
1055
/* Lite remove start */
1056
/*--------------------------------------------------------------------------
1057
** Test sf_read/write_float ()
1061
float_out = (float*) data_out ;
1062
float_in = (float*) data_in ;
1063
for (k = 0 ; k < items ; k++)
1064
{ float_out [k] = (k * ((k % 2) ? 333333 : -333333)) ;
1065
zero_count = (fabs (float_out [k]) > 1e-10) ? zero_count : zero_count + 1 ;
1068
if (zero_count > items / 4)
1069
{ printf ("\n\nLine %d: too many zeros (%d/%d).\n", __LINE__, zero_count, items) ;
1073
sfinfo.samplerate = 44100 ;
1074
sfinfo.frames = 123456789 ; /* Wrong length. Library should correct this on sf_close. */
1075
sfinfo.channels = 1 ;
1076
sfinfo.format = filetype ;
1078
file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
1080
sf_command (file, SFC_SET_NORM_FLOAT, NULL, SF_FALSE) ;
1082
test_write_float_or_die (file, 0, float_out, items, __LINE__) ;
1086
memset (float_in, 0, items * sizeof (float)) ;
1088
file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
1090
if (sfinfo.format != filetype)
1091
{ printf ("\n\nLine %d: Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__, filetype, sfinfo.format) ;
1095
if (sfinfo.frames != items)
1096
{ printf ("\n\nLine %d: Incorrect number of frames in file. (%d => %ld)\n", __LINE__, items, SF_COUNT_TO_LONG (sfinfo.frames)) ;
1100
if (sfinfo.channels != 1)
1101
{ printf ("\n\nLine %d: Incorrect number of channels in file.\n", __LINE__) ;
1105
check_log_buffer_or_die (file, __LINE__) ;
1107
sf_command (file, SFC_SET_NORM_FLOAT, NULL, SF_FALSE) ;
1109
test_read_float_or_die (file, 0, float_in, items, __LINE__) ;
1111
for (k = 0 ; k < items ; k++)
1112
if (fabs (float_out [k] - float_in [k]) > 1e-10)
1113
{ printf ("\n\nLine %d: float : Incorrect sample (#%d : %f => %f).\n", __LINE__, k, (double) float_out [k], (double) float_in [k]) ;
1120
/*--------------------------------------------------------------------------
1121
** Test sf_read/write_double ()
1125
double_out = (double*) data_out ;
1126
double_in = (double*) data_in ;
1127
for (k = 0 ; k < items ; k++)
1128
{ double_out [k] = (k * ((k % 2) ? 333333 : -333333)) ;
1129
zero_count = (fabs (double_out [k]) > 1e-10) ? zero_count : zero_count + 1 ;
1132
if (zero_count > items / 4)
1133
{ printf ("\n\nLine %d: too many zeros (%d/%d).\n", __LINE__, zero_count, items) ;
1137
sfinfo.samplerate = 44100 ;
1138
sfinfo.frames = 123456789 ; /* Wrong length. Library should correct this on sf_close. */
1139
sfinfo.channels = 1 ;
1140
sfinfo.format = filetype ;
1142
file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
1144
sf_command (file, SFC_SET_NORM_DOUBLE, NULL, SF_FALSE) ;
1146
test_write_double_or_die (file, 0, double_out, items, __LINE__) ;
1150
memset (double_in, 0, items * sizeof (double)) ;
1152
file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
1154
if (sfinfo.format != filetype)
1155
{ printf ("\n\nLine %d: Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__, filetype, sfinfo.format) ;
1159
if (sfinfo.frames != items)
1160
{ printf ("\n\nLine %d: Incorrect number of frames in file. (%d => %ld)\n", __LINE__, items, SF_COUNT_TO_LONG (sfinfo.frames)) ;
1164
if (sfinfo.channels != 1)
1165
{ printf ("\n\nLine %d: Incorrect number of channels in file.\n", __LINE__) ;
1169
check_log_buffer_or_die (file, __LINE__) ;
1171
sf_command (file, SFC_SET_NORM_DOUBLE, NULL, SF_FALSE) ;
1173
test_read_double_or_die (file, 0, double_in, items, __LINE__) ;
1175
for (k = 0 ; k < items ; k++)
1176
if (fabs (double_out [k] - double_in [k]) > 1e-10)
1177
{ printf ("\n\nLine %d: double : Incorrect sample (#%d : %f => %f).\n", __LINE__, k, double_out [k], double_in [k]) ;
1182
/* Lite remove end */
1186
} /* pcm_test_bits_32 */
1190
/*==============================================================================
1194
pcm_test_float (const char *filename, int filetype, int hash, int replace_float)
1197
int k, items, frames ;
1199
double *data, error ;
1201
print_test_name ("pcm_test_float", filename) ;
1203
items = BUFFER_SIZE / sizeof (double) ;
1205
data = (double*) data_out ;
1206
for (sign = 1, k = 0 ; k < items ; k++)
1207
{ data [k] = ((double) (k * sign)) / 100.0 ;
1208
sign = (sign > 0) ? -1 : 1 ;
1211
sfinfo.samplerate = 44100 ;
1212
sfinfo.frames = items ;
1213
sfinfo.channels = 1 ;
1214
sfinfo.format = filetype ;
1216
file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
1217
sf_command (file, SFC_TEST_IEEE_FLOAT_REPLACE, NULL, replace_float) ;
1218
if (replace_float && string_in_log_buffer (file, "Using IEEE replacement") == 0)
1219
{ printf ("\n\nLine %d : Float replacement code not working.\n\n", __LINE__) ;
1220
dump_log_buffer (file) ;
1224
test_write_double_or_die (file, 0, data, items, __LINE__) ;
1228
check_file_hash_or_die (filename, hash, __LINE__) ;
1230
memset (data, 0, items * sizeof (double)) ;
1232
if ((filetype & SF_FORMAT_TYPEMASK) != SF_FORMAT_RAW)
1233
memset (&sfinfo, 0, sizeof (sfinfo)) ;
1235
file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
1236
sf_command (file, SFC_TEST_IEEE_FLOAT_REPLACE, NULL, replace_float) ;
1237
if (replace_float && string_in_log_buffer (file, "Using IEEE replacement") == 0)
1238
{ printf ("\n\nLine %d : Float replacement code not working.\n\n", __LINE__) ;
1239
dump_log_buffer (file) ;
1243
if (sfinfo.format != filetype)
1244
{ printf ("\n\nError (%s:%d) Mono : Returned format incorrect (0x%08X => 0x%08X).\n", __FILE__, __LINE__, filetype, sfinfo.format) ;
1248
if (sfinfo.frames != items)
1249
{ printf ("\n\nError (%s:%d) Mono : Incorrect number of frames in file. (%d => %ld)\n", __FILE__, __LINE__, items, SF_COUNT_TO_LONG (sfinfo.frames)) ;
1253
if (sfinfo.channels != 1)
1254
{ printf ("\n\nError (%s:%d) Mono : Incorrect number of channels in file.\n", __FILE__, __LINE__) ;
1258
check_log_buffer_or_die (file, __LINE__) ;
1260
test_read_double_or_die (file, 0, data, items, __LINE__) ;
1262
for (sign = -1, k = 0 ; k < items ; k++)
1263
{ error = fabs (data [k] - ((double) k) / 100.0 * (sign *= -1)) ;
1264
if (fabs (data [k]) > 1e-100 && fabs (error / data [k]) > 1e-5)
1265
{ printf ("\n\nError (%s:%d) Mono : Incorrect sample (#%d : %f => %f).\n", __FILE__, __LINE__, k, ((double) k) / 100.0, data [k]) ;
1270
/* Seek to start of file. */
1271
test_seek_or_die (file, 0, SEEK_SET, 0, sfinfo.channels, __LINE__) ;
1273
test_read_double_or_die (file, 0, data, 4, __LINE__) ;
1274
for (k = 0 ; k < 4 ; k++)
1275
{ error = fabs (data [k] - ((double) k) / 100.0 * (sign *= -1)) ;
1276
if (fabs (data [k]) > 1e-100 && fabs (error / data [k]) > 1e-5)
1277
{ printf ("\n\nError (%s:%d) Mono : Incorrect sample (#%d : %f => %f).\n", __FILE__, __LINE__, k, ((double) k) / 100.0, data [k]) ;
1282
/* Seek to offset from start of file. */
1283
test_seek_or_die (file, 10, SEEK_SET, 10, sfinfo.channels, __LINE__) ;
1285
test_read_double_or_die (file, 0, data + 10, 4, __LINE__) ;
1286
for (k = 10 ; k < 14 ; k++)
1287
{ error = fabs (data [k] - ((double) k) / 100.0 * (sign *= -1)) ;
1288
if (fabs (data [k]) > 1e-100 && fabs (error / data [k]) > 1e-5)
1289
{ printf ("\n\nError (%s:%d) Mono : Incorrect sample (#%d : %f => %f).\n", __FILE__, __LINE__, k, ((double) k) / 100.0, data [k]) ;
1294
/* Seek to offset from current position. */
1295
test_seek_or_die (file, 6, SEEK_CUR, 20, sfinfo.channels, __LINE__) ;
1297
test_read_double_or_die (file, 0, data + 20, 4, __LINE__) ;
1298
for (k = 20 ; k < 24 ; k++)
1299
{ error = fabs (data [k] - ((double) k) / 100.0 * (sign *= -1)) ;
1300
if (fabs (data [k]) > 1e-100 && fabs (error / data [k]) > 1e-5)
1301
{ printf ("\n\nError (%s:%d) Mono : Incorrect sample (#%d : %f => %f).\n", __FILE__, __LINE__, k, ((double) k) / 100.0, data [k]) ;
1306
/* Seek to offset from end of file. */
1307
test_seek_or_die (file, -1 * (sfinfo.frames - 10), SEEK_END, 10, sfinfo.channels, __LINE__) ;
1309
test_read_double_or_die (file, 0, data + 10, 4, __LINE__) ;
1310
for (k = 10 ; k < 14 ; k++)
1311
{ error = fabs (data [k] - ((double) k) / 100.0 * (sign *= -1)) ;
1312
if (fabs (data [k]) > 1e-100 && fabs (error / data [k]) > 1e-5)
1313
{ printf ("\n\nError (%s:%d) Mono : Incorrect sample (#%d : %f => %f).\n", __FILE__, __LINE__, k, ((double) k) / 100.0, data [k]) ;
1320
/* Now test Stereo. */
1322
if ((filetype & SF_FORMAT_TYPEMASK) == SF_FORMAT_SVX) /* SVX is mono only */
1327
items = BUFFER_SIZE / sizeof (double) ;
1329
data = (double*) data_out ;
1330
for (sign = -1, k = 0 ; k < items ; k++)
1331
data [k] = ((double) k) / 100.0 * (sign *= -1) ;
1333
sfinfo.samplerate = 44100 ;
1334
sfinfo.frames = items ;
1335
sfinfo.channels = 2 ;
1336
sfinfo.format = filetype ;
1338
frames = items / sfinfo.channels ;
1340
file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
1341
sf_command (file, SFC_TEST_IEEE_FLOAT_REPLACE, NULL, replace_float) ;
1342
if (replace_float && string_in_log_buffer (file, "Using IEEE replacement") == 0)
1343
{ printf ("\n\nLine %d : Float replacement code not working.\n\n", __LINE__) ;
1344
dump_log_buffer (file) ;
1348
test_writef_double_or_die (file, 0, data, frames, __LINE__) ;
1352
check_file_hash_or_die (filename, hash, __LINE__) ;
1354
memset (data, 0, items * sizeof (double)) ;
1356
if ((filetype & SF_FORMAT_TYPEMASK) != SF_FORMAT_RAW)
1357
memset (&sfinfo, 0, sizeof (sfinfo)) ;
1359
file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
1360
sf_command (file, SFC_TEST_IEEE_FLOAT_REPLACE, NULL, replace_float) ;
1361
if (replace_float && string_in_log_buffer (file, "Using IEEE replacement") == 0)
1362
{ printf ("\n\nLine %d : Float replacement code not working.\n\n", __LINE__) ;
1363
dump_log_buffer (file) ;
1367
if (sfinfo.format != filetype)
1368
{ printf ("\n\nError (%s:%d) Stereo : Returned format incorrect (0x%08X => 0x%08X).\n", __FILE__, __LINE__, filetype, sfinfo.format) ;
1372
if (sfinfo.frames != frames)
1373
{ printf ("\n\nError (%s:%d) Stereo : Incorrect number of frames in file. (%d => %ld)\n", __FILE__, __LINE__, frames, SF_COUNT_TO_LONG (sfinfo.frames)) ;
1377
if (sfinfo.channels != 2)
1378
{ printf ("\n\nError (%s:%d) Stereo : Incorrect number of channels in file.\n", __FILE__, __LINE__) ;
1382
check_log_buffer_or_die (file, __LINE__) ;
1384
test_readf_double_or_die (file, 0, data, frames, __LINE__) ;
1385
for (sign = -1, k = 0 ; k < items ; k++)
1386
{ error = fabs (data [k] - ((double) k) / 100.0 * (sign *= -1)) ;
1387
if (fabs (data [k]) > 1e-100 && fabs (error / data [k]) > 1e-5)
1388
{ printf ("\n\nError (%s:%d) Stereo : Incorrect sample (#%d : %f => %f).\n", __FILE__, __LINE__, k, ((double) k) / 100.0, data [k]) ;
1393
/* Seek to start of file. */
1394
test_seek_or_die (file, 0, SEEK_SET, 0, sfinfo.channels, __LINE__) ;
1396
test_readf_double_or_die (file, 0, data, 4, __LINE__) ;
1397
for (k = 0 ; k < 4 ; k++)
1398
{ error = fabs (data [k] - ((double) k) / 100.0 * (sign *= -1)) ;
1399
if (fabs (data [k]) > 1e-100 && fabs (error / data [k]) > 1e-5)
1400
{ printf ("\n\nError (%s:%d) Stereo : Incorrect sample (#%d : %f => %f).\n", __FILE__, __LINE__, k, ((double) k) / 100.0, data [k]) ;
1405
/* Seek to offset from start of file. */
1406
test_seek_or_die (file, 10, SEEK_SET, 10, sfinfo.channels, __LINE__) ;
1408
test_readf_double_or_die (file, 0, data + 20, 2, __LINE__) ;
1409
for (k = 20 ; k < 24 ; k++)
1410
{ error = fabs (data [k] - ((double) k) / 100.0 * (sign *= -1)) ;
1411
if (fabs (data [k]) > 1e-100 && fabs (error / data [k]) > 1e-5)
1412
{ printf ("\n\nError (%s:%d) Stereo : Incorrect sample (#%d : %f => %f).\n", __FILE__, __LINE__, k, ((double) k) / 100.0, data [k]) ;
1417
/* Seek to offset from current position. */
1418
test_seek_or_die (file, 8, SEEK_CUR, 20, sfinfo.channels, __LINE__) ;
1420
test_readf_double_or_die (file, 0, data + 40, 2, __LINE__) ;
1421
for (k = 40 ; k < 44 ; k++)
1422
{ error = fabs (data [k] - ((double) k) / 100.0 * (sign *= -1)) ;
1423
if (fabs (data [k]) > 1e-100 && fabs (error / data [k]) > 1e-5)
1424
{ printf ("\n\nError (%s:%d) Stereo : Incorrect sample (#%d : %f => %f).\n", __FILE__, __LINE__, k, ((double) k) / 100.0, data [k]) ;
1429
/* Seek to offset from end of file. */
1430
test_seek_or_die (file, -1 * (sfinfo.frames - 10), SEEK_END, 10, sfinfo.channels, __LINE__) ;
1432
test_readf_double_or_die (file, 0, data + 20, 2, __LINE__) ;
1433
for (k = 20 ; k < 24 ; k++)
1434
{ error = fabs (data [k] - ((double) k) / 100.0 * (sign *= -1)) ;
1435
if (fabs (data [k]) > 1e-100 && fabs (error / data [k]) > 1e-5)
1436
{ printf ("\n\nError (%s:%d) Stereo : Incorrect sample (#%d : %f => %f).\n", __FILE__, __LINE__, k, ((double) k) / 100.0, data [k]) ;
1445
} /* pcm_test_float */
1448
pcm_test_double (const char *filename, int filetype, int hash, int replace_float)
1451
int k, items, frames ;
1453
double *data, error ;
1455
/* This is the best test routine. Other should be brought up to this standard. */
1457
print_test_name ("pcm_test_double", filename) ;
1459
items = BUFFER_SIZE / sizeof (double) ;
1461
data = (double*) data_out ;
1462
for (sign = 1, k = 0 ; k < items ; k++)
1463
{ data [k] = ((double) (k * sign)) / 100.0 ;
1464
sign = (sign > 0) ? -1 : 1 ;
1467
sfinfo.samplerate = 44100 ;
1468
sfinfo.frames = items ;
1469
sfinfo.channels = 1 ;
1470
sfinfo.format = filetype ;
1472
file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
1473
sf_command (file, SFC_TEST_IEEE_FLOAT_REPLACE, NULL, replace_float) ;
1474
if (replace_float && string_in_log_buffer (file, "Using IEEE replacement") == 0)
1475
{ printf ("\n\nLine %d : Float replacement code not working.\n\n", __LINE__) ;
1476
dump_log_buffer (file) ;
1480
test_write_double_or_die (file, 0, data, items, __LINE__) ;
1484
#if (defined (WIN32) || defined (_WIN32))
1485
/* File hashing on Win32 fails due to slighty different
1486
** calculated values of the sin() function.
1488
hash = hash ; /* Avoid compiler warning. */
1490
check_file_hash_or_die (filename, hash, __LINE__) ;
1493
memset (data, 0, items * sizeof (double)) ;
1495
if ((filetype & SF_FORMAT_TYPEMASK) != SF_FORMAT_RAW)
1496
memset (&sfinfo, 0, sizeof (sfinfo)) ;
1498
file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
1499
sf_command (file, SFC_TEST_IEEE_FLOAT_REPLACE, NULL, replace_float) ;
1500
if (replace_float && string_in_log_buffer (file, "Using IEEE replacement") == 0)
1501
{ printf ("\n\nLine %d : Float replacement code not working.\n\n", __LINE__) ;
1502
dump_log_buffer (file) ;
1506
if (sfinfo.format != filetype)
1507
{ printf ("\n\nError (%s:%d) Mono : Returned format incorrect (0x%08X => 0x%08X).\n", __FILE__, __LINE__, filetype, sfinfo.format) ;
1511
if (sfinfo.frames != items)
1512
{ printf ("\n\nError (%s:%d) Mono : Incorrect number of frames in file. (%d => %ld)\n", __FILE__, __LINE__, items, SF_COUNT_TO_LONG (sfinfo.frames)) ;
1516
if (sfinfo.channels != 1)
1517
{ printf ("\n\nError (%s:%d) Mono : Incorrect number of channels in file.\n", __FILE__, __LINE__) ;
1521
check_log_buffer_or_die (file, __LINE__) ;
1523
test_read_double_or_die (file, 0, data, items, __LINE__) ;
1525
for (sign = -1, k = 0 ; k < items ; k++)
1526
{ error = fabs (data [k] - ((double) k) / 100.0 * (sign *= -1)) ;
1527
if (fabs (data [k]) > 1e-100 && fabs (error / data [k]) > 1e-5)
1528
{ printf ("\n\nError (%s:%d) Mono : Incorrect sample (#%d : %f => %f).\n", __FILE__, __LINE__, k, ((double) k) / 100.0, data [k]) ;
1533
/* Seek to start of file. */
1534
test_seek_or_die (file, 0, SEEK_SET, 0, sfinfo.channels, __LINE__) ;
1536
test_read_double_or_die (file, 0, data, 4, __LINE__) ;
1537
for (k = 0 ; k < 4 ; k++)
1538
{ error = fabs (data [k] - ((double) k) / 100.0 * (sign *= -1)) ;
1539
if (fabs (data [k]) > 1e-100 && fabs (error / data [k]) > 1e-5)
1540
{ printf ("\n\nError (%s:%d) Mono : Incorrect sample (#%d : %f => %f).\n", __FILE__, __LINE__, k, ((double) k) / 100.0, data [k]) ;
1545
/* Seek to offset from start of file. */
1546
test_seek_or_die (file, 10, SEEK_SET, 10, sfinfo.channels, __LINE__) ;
1548
test_read_double_or_die (file, 0, data + 10, 4, __LINE__) ;
1550
test_seek_or_die (file, 0, SEEK_CUR, 14, sfinfo.channels, __LINE__) ;
1552
for (k = 10 ; k < 14 ; k++)
1553
{ error = fabs (data [k] - ((double) k) / 100.0 * (sign *= -1)) ;
1554
if (fabs (data [k]) > 1e-100 && fabs (error / data [k]) > 1e-5)
1555
{ printf ("\n\nError (%s:%d) Mono : Incorrect sample (#%d : %f => %f).\n", __FILE__, __LINE__, k, ((double) k) / 100.0, data [k]) ;
1560
/* Seek to offset from current position. */
1561
test_seek_or_die (file, 6, SEEK_CUR, 20, sfinfo.channels, __LINE__) ;
1563
test_read_double_or_die (file, 0, data + 20, 4, __LINE__) ;
1564
for (k = 20 ; k < 24 ; k++)
1565
{ error = fabs (data [k] - ((double) k) / 100.0 * (sign *= -1)) ;
1566
if (fabs (data [k]) > 1e-100 && fabs (error / data [k]) > 1e-5)
1567
{ printf ("\n\nError (%s:%d) Mono : Incorrect sample (#%d : %f => %f).\n", __FILE__, __LINE__, k, ((double) k) / 100.0, data [k]) ;
1572
/* Seek to offset from end of file. */
1573
test_seek_or_die (file, -1 * (sfinfo.frames - 10), SEEK_END, 10, sfinfo.channels, __LINE__) ;
1575
test_read_double_or_die (file, 0, data + 10, 4, __LINE__) ;
1576
for (k = 10 ; k < 14 ; k++)
1577
{ error = fabs (data [k] - ((double) k) / 100.0 * (sign *= -1)) ;
1578
if (fabs (data [k]) > 1e-100 && fabs (error / data [k]) > 1e-5)
1579
{ printf ("\n\nError (%s:%d) Mono : Incorrect sample (#%d : %f => %f).\n", __FILE__, __LINE__, k, ((double) k) / 100.0, data [k]) ;
1586
/* Now test Stereo. */
1588
if ((filetype & SF_FORMAT_TYPEMASK) == SF_FORMAT_SVX) /* SVX is mono only */
1593
items = BUFFER_SIZE / sizeof (double) ;
1595
data = (double*) data_out ;
1596
for (sign = -1, k = 0 ; k < items ; k++)
1597
data [k] = ((double) k) / 100.0 * (sign *= -1) ;
1599
sfinfo.samplerate = 44100 ;
1600
sfinfo.frames = items ;
1601
sfinfo.channels = 2 ;
1602
sfinfo.format = filetype ;
1604
frames = items / sfinfo.channels ;
1606
file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
1607
sf_command (file, SFC_TEST_IEEE_FLOAT_REPLACE, NULL, replace_float) ;
1608
if (replace_float && string_in_log_buffer (file, "Using IEEE replacement") == 0)
1609
{ printf ("\n\nLine %d : Float replacement code not working.\n\n", __LINE__) ;
1610
dump_log_buffer (file) ;
1614
test_writef_double_or_die (file, 0, data, frames, __LINE__) ;
1618
#if (defined (WIN32) || defined (_WIN32))
1619
/* File hashing on Win32 fails due to slighty different
1620
** calculated values.
1622
hash = hash ; /* Avoid compiler warning. */
1624
check_file_hash_or_die (filename, hash, __LINE__) ;
1627
memset (data, 0, items * sizeof (double)) ;
1629
if ((filetype & SF_FORMAT_TYPEMASK) != SF_FORMAT_RAW)
1630
memset (&sfinfo, 0, sizeof (sfinfo)) ;
1632
file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
1633
sf_command (file, SFC_TEST_IEEE_FLOAT_REPLACE, NULL, replace_float) ;
1634
if (replace_float && string_in_log_buffer (file, "Using IEEE replacement") == 0)
1635
{ printf ("\n\nLine %d : Float replacement code not working.\n\n", __LINE__) ;
1636
dump_log_buffer (file) ;
1640
if (sfinfo.format != filetype)
1641
{ printf ("\n\nError (%s:%d) Stereo : Returned format incorrect (0x%08X => 0x%08X).\n", __FILE__, __LINE__, filetype, sfinfo.format) ;
1645
if (sfinfo.frames != frames)
1646
{ printf ("\n\nError (%s:%d) Stereo : Incorrect number of frames in file. (%d => %ld)\n", __FILE__, __LINE__, frames, SF_COUNT_TO_LONG (sfinfo.frames)) ;
1650
if (sfinfo.channels != 2)
1651
{ printf ("\n\nError (%s:%d) Stereo : Incorrect number of channels in file.\n", __FILE__, __LINE__) ;
1655
check_log_buffer_or_die (file, __LINE__) ;
1657
test_readf_double_or_die (file, 0, data, frames, __LINE__) ;
1659
for (sign = -1, k = 0 ; k < items ; k++)
1660
{ error = fabs (data [k] - ((double) k) / 100.0 * (sign *= -1)) ;
1661
if (fabs (data [k]) > 1e-100 && fabs (error / data [k]) > 1e-5)
1662
{ printf ("\n\nError (%s:%d) Stereo : Incorrect sample (#%d : %f => %f).\n", __FILE__, __LINE__, k, ((double) k) / 100.0, data [k]) ;
1667
/* Seek to start of file. */
1668
test_seek_or_die (file, 0, SEEK_SET, 0, sfinfo.channels, __LINE__) ;
1670
test_read_double_or_die (file, 0, data, 4, __LINE__) ;
1671
for (k = 0 ; k < 4 ; k++)
1672
{ error = fabs (data [k] - ((double) k) / 100.0 * (sign *= -1)) ;
1673
if (fabs (data [k]) > 1e-100 && fabs (error / data [k]) > 1e-5)
1674
{ printf ("\n\nError (%s:%d) Stereo : Incorrect sample (#%d : %f => %f).\n", __FILE__, __LINE__, k, ((double) k) / 100.0, data [k]) ;
1679
/* Seek to offset from start of file. */
1680
test_seek_or_die (file, 10, SEEK_SET, 10, sfinfo.channels, __LINE__) ;
1682
test_read_double_or_die (file, 0, data + 10, 4, __LINE__) ;
1683
for (k = 20 ; k < 24 ; k++)
1684
{ error = fabs (data [k] - ((double) k) / 100.0 * (sign *= -1)) ;
1685
if (fabs (data [k]) > 1e-100 && fabs (error / data [k]) > 1e-5)
1686
{ printf ("\n\nError (%s:%d) Stereo : Incorrect sample (#%d : %f => %f).\n", __FILE__, __LINE__, k, ((double) k) / 100.0, data [k]) ;
1691
/* Seek to offset from current position. */
1692
test_seek_or_die (file, 8, SEEK_CUR, 20, sfinfo.channels, __LINE__) ;
1694
test_readf_double_or_die (file, 0, data + 40, 4, __LINE__) ;
1695
for (k = 40 ; k < 44 ; k++)
1696
{ error = fabs (data [k] - ((double) k) / 100.0 * (sign *= -1)) ;
1697
if (fabs (data [k]) > 1e-100 && fabs (error / data [k]) > 1e-5)
1698
{ printf ("\n\nError (%s:%d) Stereo : Incorrect sample (#%d : %f => %f).\n", __FILE__, __LINE__, k, ((double) k) / 100.0, data [k]) ;
1703
/* Seek to offset from end of file. */
1704
test_seek_or_die (file, -1 * (sfinfo.frames -10), SEEK_END, 10, sfinfo.channels, __LINE__) ;
1706
test_readf_double_or_die (file, 0, data + 20, 4, __LINE__) ;
1707
for (k = 20 ; k < 24 ; k++)
1708
{ error = fabs (data [k] - ((double) k) / 100.0 * (sign *= -1)) ;
1709
if (fabs (data [k]) > 1e-100 && fabs (error / data [k]) > 1e-5)
1710
{ printf ("\n\nError (%s:%d) Stereo : Incorrect sample (#%d : %f => %f).\n", __FILE__, __LINE__, k, ((double) k) / 100.0, data [k]) ;
1719
} /* pcm_test_double */
1721
/*==============================================================================