Imported Upstream version 1.0.26
[platform/upstream/libsndfile.git] / tests / pcm_test.c
1 /*
2 ** Copyright (C) 1999-2013 Erik de Castro Lopo <erikd@mega-nerd.com>
3 **
4 ** This program is free software; you can redistribute it and/or modify
5 ** it under the terms of the GNU General Public License as published by
6 ** the Free Software Foundation; either version 2 of the License, or
7 ** (at your option) any later version.
8 **
9 ** This program is distributed in the hope that it will be useful,
10 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
11 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 ** GNU General Public License for more details.
13 **
14 ** You should have received a copy of the GNU General Public License
15 ** along with this program; if not, write to the Free Software
16 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 */
18
19 #include "sfconfig.h"
20
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include <string.h>
24 #include <math.h>
25 #include <inttypes.h>
26
27 #if HAVE_UNISTD_H
28 #include <unistd.h>
29 #endif
30
31 #include <sndfile.h>
32
33 #include "utils.h"
34
35 #define BUFFER_SIZE             (1 << 12)
36
37 static void     lrintf_test (void) ;
38
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) ;
43
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) ;
46
47 typedef union
48 {       double  d [BUFFER_SIZE + 1] ;
49         float   f [BUFFER_SIZE + 1] ;
50         int             i [BUFFER_SIZE + 1] ;
51         short   s [BUFFER_SIZE + 1] ;
52 } BUFFER ;
53
54 /* Data written to the file. */
55 static  BUFFER  data_out ;
56
57 /* Data read back from the file. */
58 static  BUFFER  data_in ;
59
60 int
61 main (void)
62 {
63         lrintf_test () ;
64
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) ;
67
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) ;
70
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) ;
73
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) ;
76
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) ;
80
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) ;
83
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) ;
86
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) ;
89         /* Lite remove end */
90
91         return 0 ;
92 } /* main */
93
94 /*============================================================================================
95 **      Here are the test functions.
96 */
97
98 static void
99 lrintf_test (void)
100 {       int k, items ;
101         float   *float_data ;
102         int             *int_data ;
103
104         print_test_name ("lrintf_test", "") ;
105
106         items = 1024 ;
107
108         float_data = data_out.f ;
109         int_data = data_in.i ;
110
111         for (k = 0 ; k < items ; k++)
112                 float_data [k] = (k * ((k % 2) ? 333333.0 : -333333.0)) ;
113
114         for (k = 0 ; k < items ; k++)
115                 int_data [k] = lrintf (float_data [k]) ;
116
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]) ;
120                         exit (1) ;
121                         } ;
122
123         printf ("ok\n") ;
124 } /* lrintf_test */
125
126 static void
127 pcm_test_bits_8 (const char *filename, int filetype, uint64_t hash)
128 {       SNDFILE         *file ;
129         SF_INFO         sfinfo ;
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 */
137
138         print_test_name ("pcm_test_bits_8", filename) ;
139
140         items = 127 ;
141
142         short_out = data_out.s ;
143         short_in = data_in.s ;
144
145         zero_count = 0 ;
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 ;
149                 } ;
150
151         if (zero_count > items / 4)
152         {       printf ("\n\nLine %d: too many zeros.\n", __LINE__) ;
153                 exit (1) ;
154                 } ;
155
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 ;
160
161         file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
162
163         test_write_short_or_die (file, 0, short_out, items, __LINE__) ;
164
165         sf_close (file) ;
166
167         memset (short_in, 0, items * sizeof (short)) ;
168
169         file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
170
171         if (sfinfo.format != filetype)
172         {       printf ("\n\nLine %d: Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__, filetype, sfinfo.format) ;
173                 exit (1) ;
174                 } ;
175
176         if (sfinfo.frames != items)
177         {       printf ("\n\nLine %d: Incorrect number of frames in file. (%d => %" PRId64 ")\n", __LINE__, items, sfinfo.frames) ;
178                 exit (1) ;
179                 } ;
180
181         if (sfinfo.channels != 1)
182         {       printf ("\n\nLine %d: Incorrect number of channels in file.\n", __LINE__) ;
183                 exit (1) ;
184                 } ;
185
186         check_log_buffer_or_die (file, __LINE__) ;
187
188         test_read_short_or_die (file, 0, short_in, items, __LINE__) ;
189
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]) ;
193                         exit (1) ;
194                         } ;
195
196         sf_close (file) ;
197
198         /* Finally, check the file hash. */
199         check_file_hash_or_die (filename, hash, __LINE__) ;
200
201         /*--------------------------------------------------------------------------
202         ** Test sf_read/write_int ()
203         */
204         zero_count = 0 ;
205
206         int_out = data_out.i ;
207         int_in = data_in.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 ;
211                 } ;
212
213         if (zero_count > items / 4)
214         {       printf ("\n\nLine %d: too many zeros.\n", __LINE__) ;
215                 exit (1) ;
216                 } ;
217
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 ;
222
223         file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
224
225         test_write_int_or_die (file, 0, int_out, items, __LINE__) ;
226
227         sf_close (file) ;
228
229         memset (int_in, 0, items * sizeof (int)) ;
230
231         file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
232
233         if (sfinfo.format != filetype)
234         {       printf ("\n\nLine %d: Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__, filetype, sfinfo.format) ;
235                 exit (1) ;
236                 } ;
237
238         if (sfinfo.frames != items)
239         {       printf ("\n\nLine %d: Incorrect number of frames in file. (%d => %" PRId64 ")\n", __LINE__, items, sfinfo.frames) ;
240                 exit (1) ;
241                 } ;
242
243         if (sfinfo.channels != 1)
244         {       printf ("\n\nLine %d: Incorrect number of channels in file.\n", __LINE__) ;
245                 exit (1) ;
246                 } ;
247
248         check_log_buffer_or_die (file, __LINE__) ;
249
250         test_read_int_or_die (file, 0, int_in, items, __LINE__) ;
251
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]) ;
255                         exit (1) ;
256                         } ;
257
258         sf_close (file) ;
259
260         /* Lite remove start */
261         /*--------------------------------------------------------------------------
262         ** Test sf_read/write_float ()
263         */
264         zero_count = 0 ;
265
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 ;
271                 } ;
272
273         if (zero_count > items / 4)
274         {       printf ("\n\nLine %d: too many zeros (%d/%d).\n", __LINE__, zero_count, items) ;
275                 exit (1) ;
276                 } ;
277
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 ;
282
283         file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
284
285         sf_command (file, SFC_SET_NORM_FLOAT, NULL, SF_FALSE) ;
286
287         test_write_float_or_die (file, 0, float_out, items, __LINE__) ;
288
289         sf_close (file) ;
290
291         memset (float_in, 0, items * sizeof (float)) ;
292
293         file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
294
295         if (sfinfo.format != filetype)
296         {       printf ("\n\nLine %d: Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__, filetype, sfinfo.format) ;
297                 exit (1) ;
298                 } ;
299
300         if (sfinfo.frames != items)
301         {       printf ("\n\nLine %d: Incorrect number of frames in file. (%d => %" PRId64 ")\n", __LINE__, items, sfinfo.frames) ;
302                 exit (1) ;
303                 } ;
304
305         if (sfinfo.channels != 1)
306         {       printf ("\n\nLine %d: Incorrect number of channels in file.\n", __LINE__) ;
307                 exit (1) ;
308                 } ;
309
310         check_log_buffer_or_die (file, __LINE__) ;
311
312         sf_command (file, SFC_SET_NORM_FLOAT, NULL, SF_FALSE) ;
313
314         test_read_float_or_die (file, 0, float_in, items, __LINE__) ;
315
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]) ;
319                         exit (1) ;
320                         } ;
321
322         sf_close (file) ;
323
324         /*--------------------------------------------------------------------------
325         ** Test sf_read/write_double ()
326         */
327         zero_count = 0 ;
328
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 ;
334                 } ;
335
336         if (zero_count > items / 4)
337         {       printf ("\n\nLine %d: too many zeros (%d/%d).\n", __LINE__, zero_count, items) ;
338                 exit (1) ;
339                 } ;
340
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 ;
345
346         file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
347
348         sf_command (file, SFC_SET_NORM_DOUBLE, NULL, SF_FALSE) ;
349
350         test_write_double_or_die (file, 0, double_out, items, __LINE__) ;
351
352         sf_close (file) ;
353
354         memset (double_in, 0, items * sizeof (double)) ;
355
356         file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
357
358         if (sfinfo.format != filetype)
359         {       printf ("\n\nLine %d: Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__, filetype, sfinfo.format) ;
360                 exit (1) ;
361                 } ;
362
363         if (sfinfo.frames != items)
364         {       printf ("\n\nLine %d: Incorrect number of frames in file. (%d => %" PRId64 ")\n", __LINE__, items, sfinfo.frames) ;
365                 exit (1) ;
366                 } ;
367
368         if (sfinfo.channels != 1)
369         {       printf ("\n\nLine %d: Incorrect number of channels in file.\n", __LINE__) ;
370                 exit (1) ;
371                 } ;
372
373         check_log_buffer_or_die (file, __LINE__) ;
374
375         sf_command (file, SFC_SET_NORM_DOUBLE, NULL, SF_FALSE) ;
376
377         test_read_double_or_die (file, 0, double_in, items, __LINE__) ;
378
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]) ;
382                         exit (1) ;
383                         } ;
384
385         sf_close (file) ;
386         /* Lite remove end */
387         unlink (filename) ;
388
389         puts ("ok") ;
390 } /* pcm_test_bits_8 */
391
392 static void
393 pcm_test_bits_16 (const char *filename, int filetype, uint64_t hash)
394 {       SNDFILE         *file ;
395         SF_INFO         sfinfo ;
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 */
403
404         print_test_name ("pcm_test_bits_16", filename) ;
405
406         items = 1024 ;
407
408         short_out = data_out.s ;
409         short_in = data_in.s ;
410
411         zero_count = 0 ;
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 ;
415                 } ;
416
417         if (zero_count > items / 4)
418         {       printf ("\n\nLine %d: too many zeros.\n", __LINE__) ;
419                 exit (1) ;
420                 } ;
421
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 ;
426
427         file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
428
429         test_write_short_or_die (file, 0, short_out, items, __LINE__) ;
430
431         sf_close (file) ;
432
433         memset (short_in, 0, items * sizeof (short)) ;
434
435         file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
436
437         if (sfinfo.format != filetype)
438         {       printf ("\n\nLine %d: Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__, filetype, sfinfo.format) ;
439                 exit (1) ;
440                 } ;
441
442         if (sfinfo.frames != items)
443         {       printf ("\n\nLine %d: Incorrect number of frames in file. (%d => %" PRId64 ")\n", __LINE__, items, sfinfo.frames) ;
444                 exit (1) ;
445                 } ;
446
447         if (sfinfo.channels != 1)
448         {       printf ("\n\nLine %d: Incorrect number of channels in file.\n", __LINE__) ;
449                 exit (1) ;
450                 } ;
451
452         check_log_buffer_or_die (file, __LINE__) ;
453
454         test_read_short_or_die (file, 0, short_in, items, __LINE__) ;
455
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]) ;
459                         exit (1) ;
460                         } ;
461
462         sf_close (file) ;
463
464         /* Finally, check the file hash. */
465         check_file_hash_or_die (filename, hash, __LINE__) ;
466
467         /*--------------------------------------------------------------------------
468         ** Test sf_read/write_int ()
469         */
470         zero_count = 0 ;
471
472         int_out = data_out.i ;
473         int_in = data_in.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 ;
477                 } ;
478
479         if (zero_count > items / 4)
480         {       printf ("\n\nLine %d: too many zeros.\n", __LINE__) ;
481                 exit (1) ;
482                 } ;
483
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 ;
488
489         file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
490
491         test_write_int_or_die (file, 0, int_out, items, __LINE__) ;
492
493         sf_close (file) ;
494
495         memset (int_in, 0, items * sizeof (int)) ;
496
497         file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
498
499         if (sfinfo.format != filetype)
500         {       printf ("\n\nLine %d: Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__, filetype, sfinfo.format) ;
501                 exit (1) ;
502                 } ;
503
504         if (sfinfo.frames != items)
505         {       printf ("\n\nLine %d: Incorrect number of frames in file. (%d => %" PRId64 ")\n", __LINE__, items, sfinfo.frames) ;
506                 exit (1) ;
507                 } ;
508
509         if (sfinfo.channels != 1)
510         {       printf ("\n\nLine %d: Incorrect number of channels in file.\n", __LINE__) ;
511                 exit (1) ;
512                 } ;
513
514         check_log_buffer_or_die (file, __LINE__) ;
515
516         test_read_int_or_die (file, 0, int_in, items, __LINE__) ;
517
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]) ;
521                         exit (1) ;
522                         } ;
523
524         sf_close (file) ;
525
526         /* Lite remove start */
527         /*--------------------------------------------------------------------------
528         ** Test sf_read/write_float ()
529         */
530         zero_count = 0 ;
531
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 ;
537                 } ;
538
539         if (zero_count > items / 4)
540         {       printf ("\n\nLine %d: too many zeros (%d/%d).\n", __LINE__, zero_count, items) ;
541                 exit (1) ;
542                 } ;
543
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 ;
548
549         file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
550
551         sf_command (file, SFC_SET_NORM_FLOAT, NULL, SF_FALSE) ;
552
553         test_write_float_or_die (file, 0, float_out, items, __LINE__) ;
554
555         sf_close (file) ;
556
557         memset (float_in, 0, items * sizeof (float)) ;
558
559         file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
560
561         if (sfinfo.format != filetype)
562         {       printf ("\n\nLine %d: Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__, filetype, sfinfo.format) ;
563                 exit (1) ;
564                 } ;
565
566         if (sfinfo.frames != items)
567         {       printf ("\n\nLine %d: Incorrect number of frames in file. (%d => %" PRId64 ")\n", __LINE__, items, sfinfo.frames) ;
568                 exit (1) ;
569                 } ;
570
571         if (sfinfo.channels != 1)
572         {       printf ("\n\nLine %d: Incorrect number of channels in file.\n", __LINE__) ;
573                 exit (1) ;
574                 } ;
575
576         check_log_buffer_or_die (file, __LINE__) ;
577
578         sf_command (file, SFC_SET_NORM_FLOAT, NULL, SF_FALSE) ;
579
580         test_read_float_or_die (file, 0, float_in, items, __LINE__) ;
581
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]) ;
585                         exit (1) ;
586                         } ;
587
588         sf_close (file) ;
589
590         /*--------------------------------------------------------------------------
591         ** Test sf_read/write_double ()
592         */
593         zero_count = 0 ;
594
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 ;
600                 } ;
601
602         if (zero_count > items / 4)
603         {       printf ("\n\nLine %d: too many zeros (%d/%d).\n", __LINE__, zero_count, items) ;
604                 exit (1) ;
605                 } ;
606
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 ;
611
612         file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
613
614         sf_command (file, SFC_SET_NORM_DOUBLE, NULL, SF_FALSE) ;
615
616         test_write_double_or_die (file, 0, double_out, items, __LINE__) ;
617
618         sf_close (file) ;
619
620         memset (double_in, 0, items * sizeof (double)) ;
621
622         file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
623
624         if (sfinfo.format != filetype)
625         {       printf ("\n\nLine %d: Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__, filetype, sfinfo.format) ;
626                 exit (1) ;
627                 } ;
628
629         if (sfinfo.frames != items)
630         {       printf ("\n\nLine %d: Incorrect number of frames in file. (%d => %" PRId64 ")\n", __LINE__, items, sfinfo.frames) ;
631                 exit (1) ;
632                 } ;
633
634         if (sfinfo.channels != 1)
635         {       printf ("\n\nLine %d: Incorrect number of channels in file.\n", __LINE__) ;
636                 exit (1) ;
637                 } ;
638
639         check_log_buffer_or_die (file, __LINE__) ;
640
641         sf_command (file, SFC_SET_NORM_DOUBLE, NULL, SF_FALSE) ;
642
643         test_read_double_or_die (file, 0, double_in, items, __LINE__) ;
644
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]) ;
648                         exit (1) ;
649                         } ;
650
651         sf_close (file) ;
652         /* Lite remove end */
653         unlink (filename) ;
654
655         puts ("ok") ;
656 } /* pcm_test_bits_16 */
657
658 static void
659 pcm_test_bits_24 (const char *filename, int filetype, uint64_t hash)
660 {       SNDFILE         *file ;
661         SF_INFO         sfinfo ;
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 */
669
670         print_test_name ("pcm_test_bits_24", filename) ;
671
672         items = 1024 ;
673
674         short_out = data_out.s ;
675         short_in = data_in.s ;
676
677         zero_count = 0 ;
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 ;
681                 } ;
682
683         if (zero_count > items / 4)
684         {       printf ("\n\nLine %d: too many zeros.\n", __LINE__) ;
685                 exit (1) ;
686                 } ;
687
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 ;
692
693         file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
694
695         test_write_short_or_die (file, 0, short_out, items, __LINE__) ;
696
697         sf_close (file) ;
698
699         memset (short_in, 0, items * sizeof (short)) ;
700
701         file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
702
703         if (sfinfo.format != filetype)
704         {       printf ("\n\nLine %d: Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__, filetype, sfinfo.format) ;
705                 exit (1) ;
706                 } ;
707
708         if (sfinfo.frames != items)
709         {       printf ("\n\nLine %d: Incorrect number of frames in file. (%d => %" PRId64 ")\n", __LINE__, items, sfinfo.frames) ;
710                 exit (1) ;
711                 } ;
712
713         if (sfinfo.channels != 1)
714         {       printf ("\n\nLine %d: Incorrect number of channels in file.\n", __LINE__) ;
715                 exit (1) ;
716                 } ;
717
718         check_log_buffer_or_die (file, __LINE__) ;
719
720         test_read_short_or_die (file, 0, short_in, items, __LINE__) ;
721
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]) ;
725                         exit (1) ;
726                         } ;
727
728         sf_close (file) ;
729
730         /* Finally, check the file hash. */
731         check_file_hash_or_die (filename, hash, __LINE__) ;
732
733         /*--------------------------------------------------------------------------
734         ** Test sf_read/write_int ()
735         */
736         zero_count = 0 ;
737
738         int_out = data_out.i ;
739         int_in = data_in.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 ;
743                 } ;
744
745         if (zero_count > items / 4)
746         {       printf ("\n\nLine %d: too many zeros.\n", __LINE__) ;
747                 exit (1) ;
748                 } ;
749
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 ;
754
755         file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
756
757         test_write_int_or_die (file, 0, int_out, items, __LINE__) ;
758
759         sf_close (file) ;
760
761         memset (int_in, 0, items * sizeof (int)) ;
762
763         file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
764
765         if (sfinfo.format != filetype)
766         {       printf ("\n\nLine %d: Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__, filetype, sfinfo.format) ;
767                 exit (1) ;
768                 } ;
769
770         if (sfinfo.frames != items)
771         {       printf ("\n\nLine %d: Incorrect number of frames in file. (%d => %" PRId64 ")\n", __LINE__, items, sfinfo.frames) ;
772                 exit (1) ;
773                 } ;
774
775         if (sfinfo.channels != 1)
776         {       printf ("\n\nLine %d: Incorrect number of channels in file.\n", __LINE__) ;
777                 exit (1) ;
778                 } ;
779
780         check_log_buffer_or_die (file, __LINE__) ;
781
782         test_read_int_or_die (file, 0, int_in, items, __LINE__) ;
783
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]) ;
787                         exit (1) ;
788                         } ;
789
790         sf_close (file) ;
791
792         /* Lite remove start */
793         /*--------------------------------------------------------------------------
794         ** Test sf_read/write_float ()
795         */
796         zero_count = 0 ;
797
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 ;
803                 } ;
804
805         if (zero_count > items / 4)
806         {       printf ("\n\nLine %d: too many zeros (%d/%d).\n", __LINE__, zero_count, items) ;
807                 exit (1) ;
808                 } ;
809
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 ;
814
815         file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
816
817         sf_command (file, SFC_SET_NORM_FLOAT, NULL, SF_FALSE) ;
818
819         test_write_float_or_die (file, 0, float_out, items, __LINE__) ;
820
821         sf_close (file) ;
822
823         memset (float_in, 0, items * sizeof (float)) ;
824
825         file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
826
827         if (sfinfo.format != filetype)
828         {       printf ("\n\nLine %d: Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__, filetype, sfinfo.format) ;
829                 exit (1) ;
830                 } ;
831
832         if (sfinfo.frames != items)
833         {       printf ("\n\nLine %d: Incorrect number of frames in file. (%d => %" PRId64 ")\n", __LINE__, items, sfinfo.frames) ;
834                 exit (1) ;
835                 } ;
836
837         if (sfinfo.channels != 1)
838         {       printf ("\n\nLine %d: Incorrect number of channels in file.\n", __LINE__) ;
839                 exit (1) ;
840                 } ;
841
842         check_log_buffer_or_die (file, __LINE__) ;
843
844         sf_command (file, SFC_SET_NORM_FLOAT, NULL, SF_FALSE) ;
845
846         test_read_float_or_die (file, 0, float_in, items, __LINE__) ;
847
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]) ;
851                         exit (1) ;
852                         } ;
853
854         sf_close (file) ;
855
856         /*--------------------------------------------------------------------------
857         ** Test sf_read/write_double ()
858         */
859         zero_count = 0 ;
860
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 ;
866                 } ;
867
868         if (zero_count > items / 4)
869         {       printf ("\n\nLine %d: too many zeros (%d/%d).\n", __LINE__, zero_count, items) ;
870                 exit (1) ;
871                 } ;
872
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 ;
877
878         file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
879
880         sf_command (file, SFC_SET_NORM_DOUBLE, NULL, SF_FALSE) ;
881
882         test_write_double_or_die (file, 0, double_out, items, __LINE__) ;
883
884         sf_close (file) ;
885
886         memset (double_in, 0, items * sizeof (double)) ;
887
888         file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
889
890         if (sfinfo.format != filetype)
891         {       printf ("\n\nLine %d: Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__, filetype, sfinfo.format) ;
892                 exit (1) ;
893                 } ;
894
895         if (sfinfo.frames != items)
896         {       printf ("\n\nLine %d: Incorrect number of frames in file. (%d => %" PRId64 ")\n", __LINE__, items, sfinfo.frames) ;
897                 exit (1) ;
898                 } ;
899
900         if (sfinfo.channels != 1)
901         {       printf ("\n\nLine %d: Incorrect number of channels in file.\n", __LINE__) ;
902                 exit (1) ;
903                 } ;
904
905         check_log_buffer_or_die (file, __LINE__) ;
906
907         sf_command (file, SFC_SET_NORM_DOUBLE, NULL, SF_FALSE) ;
908
909         test_read_double_or_die (file, 0, double_in, items, __LINE__) ;
910
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]) ;
914                         exit (1) ;
915                         } ;
916
917         sf_close (file) ;
918         /* Lite remove end */
919         unlink (filename) ;
920
921         puts ("ok") ;
922 } /* pcm_test_bits_24 */
923
924 static void
925 pcm_test_bits_32 (const char *filename, int filetype, uint64_t hash)
926 {       SNDFILE         *file ;
927         SF_INFO         sfinfo ;
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 */
935
936         print_test_name ("pcm_test_bits_32", filename) ;
937
938         items = 1024 ;
939
940         short_out = data_out.s ;
941         short_in = data_in.s ;
942
943         zero_count = 0 ;
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 ;
947                 } ;
948
949         if (zero_count > items / 4)
950         {       printf ("\n\nLine %d: too many zeros.\n", __LINE__) ;
951                 exit (1) ;
952                 } ;
953
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 ;
958
959         file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
960
961         test_write_short_or_die (file, 0, short_out, items, __LINE__) ;
962
963         sf_close (file) ;
964
965         memset (short_in, 0, items * sizeof (short)) ;
966
967         file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
968
969         if (sfinfo.format != filetype)
970         {       printf ("\n\nLine %d: Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__, filetype, sfinfo.format) ;
971                 exit (1) ;
972                 } ;
973
974         if (sfinfo.frames != items)
975         {       printf ("\n\nLine %d: Incorrect number of frames in file. (%d => %" PRId64 ")\n", __LINE__, items, sfinfo.frames) ;
976                 exit (1) ;
977                 } ;
978
979         if (sfinfo.channels != 1)
980         {       printf ("\n\nLine %d: Incorrect number of channels in file.\n", __LINE__) ;
981                 exit (1) ;
982                 } ;
983
984         check_log_buffer_or_die (file, __LINE__) ;
985
986         test_read_short_or_die (file, 0, short_in, items, __LINE__) ;
987
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]) ;
991                         exit (1) ;
992                         } ;
993
994         sf_close (file) ;
995
996         /* Finally, check the file hash. */
997         check_file_hash_or_die (filename, hash, __LINE__) ;
998
999         /*--------------------------------------------------------------------------
1000         ** Test sf_read/write_int ()
1001         */
1002         zero_count = 0 ;
1003
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 ;
1009                 } ;
1010
1011         if (zero_count > items / 4)
1012         {       printf ("\n\nLine %d: too many zeros.\n", __LINE__) ;
1013                 exit (1) ;
1014                 } ;
1015
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 ;
1020
1021         file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
1022
1023         test_write_int_or_die (file, 0, int_out, items, __LINE__) ;
1024
1025         sf_close (file) ;
1026
1027         memset (int_in, 0, items * sizeof (int)) ;
1028
1029         file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
1030
1031         if (sfinfo.format != filetype)
1032         {       printf ("\n\nLine %d: Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__, filetype, sfinfo.format) ;
1033                 exit (1) ;
1034                 } ;
1035
1036         if (sfinfo.frames != items)
1037         {       printf ("\n\nLine %d: Incorrect number of frames in file. (%d => %" PRId64 ")\n", __LINE__, items, sfinfo.frames) ;
1038                 exit (1) ;
1039                 } ;
1040
1041         if (sfinfo.channels != 1)
1042         {       printf ("\n\nLine %d: Incorrect number of channels in file.\n", __LINE__) ;
1043                 exit (1) ;
1044                 } ;
1045
1046         check_log_buffer_or_die (file, __LINE__) ;
1047
1048         test_read_int_or_die (file, 0, int_in, items, __LINE__) ;
1049
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]) ;
1053                         exit (1) ;
1054                         } ;
1055
1056         sf_close (file) ;
1057
1058         /* Lite remove start */
1059         /*--------------------------------------------------------------------------
1060         ** Test sf_read/write_float ()
1061         */
1062         zero_count = 0 ;
1063
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 ;
1069                 } ;
1070
1071         if (zero_count > items / 4)
1072         {       printf ("\n\nLine %d: too many zeros (%d/%d).\n", __LINE__, zero_count, items) ;
1073                 exit (1) ;
1074                 } ;
1075
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 ;
1080
1081         file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
1082
1083         sf_command (file, SFC_SET_NORM_FLOAT, NULL, SF_FALSE) ;
1084
1085         test_write_float_or_die (file, 0, float_out, items, __LINE__) ;
1086
1087         sf_close (file) ;
1088
1089         memset (float_in, 0, items * sizeof (float)) ;
1090
1091         file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
1092
1093         if (sfinfo.format != filetype)
1094         {       printf ("\n\nLine %d: Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__, filetype, sfinfo.format) ;
1095                 exit (1) ;
1096                 } ;
1097
1098         if (sfinfo.frames != items)
1099         {       printf ("\n\nLine %d: Incorrect number of frames in file. (%d => %" PRId64 ")\n", __LINE__, items, sfinfo.frames) ;
1100                 exit (1) ;
1101                 } ;
1102
1103         if (sfinfo.channels != 1)
1104         {       printf ("\n\nLine %d: Incorrect number of channels in file.\n", __LINE__) ;
1105                 exit (1) ;
1106                 } ;
1107
1108         check_log_buffer_or_die (file, __LINE__) ;
1109
1110         sf_command (file, SFC_SET_NORM_FLOAT, NULL, SF_FALSE) ;
1111
1112         test_read_float_or_die (file, 0, float_in, items, __LINE__) ;
1113
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]) ;
1117                         exit (1) ;
1118                         } ;
1119
1120         sf_close (file) ;
1121
1122         /*--------------------------------------------------------------------------
1123         ** Test sf_read/write_double ()
1124         */
1125         zero_count = 0 ;
1126
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 ;
1132                 } ;
1133
1134         if (zero_count > items / 4)
1135         {       printf ("\n\nLine %d: too many zeros (%d/%d).\n", __LINE__, zero_count, items) ;
1136                 exit (1) ;
1137                 } ;
1138
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 ;
1143
1144         file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
1145
1146         sf_command (file, SFC_SET_NORM_DOUBLE, NULL, SF_FALSE) ;
1147
1148         test_write_double_or_die (file, 0, double_out, items, __LINE__) ;
1149
1150         sf_close (file) ;
1151
1152         memset (double_in, 0, items * sizeof (double)) ;
1153
1154         file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
1155
1156         if (sfinfo.format != filetype)
1157         {       printf ("\n\nLine %d: Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__, filetype, sfinfo.format) ;
1158                 exit (1) ;
1159                 } ;
1160
1161         if (sfinfo.frames != items)
1162         {       printf ("\n\nLine %d: Incorrect number of frames in file. (%d => %" PRId64 ")\n", __LINE__, items, sfinfo.frames) ;
1163                 exit (1) ;
1164                 } ;
1165
1166         if (sfinfo.channels != 1)
1167         {       printf ("\n\nLine %d: Incorrect number of channels in file.\n", __LINE__) ;
1168                 exit (1) ;
1169                 } ;
1170
1171         check_log_buffer_or_die (file, __LINE__) ;
1172
1173         sf_command (file, SFC_SET_NORM_DOUBLE, NULL, SF_FALSE) ;
1174
1175         test_read_double_or_die (file, 0, double_in, items, __LINE__) ;
1176
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]) ;
1180                         exit (1) ;
1181                         } ;
1182
1183         sf_close (file) ;
1184         /* Lite remove end */
1185         unlink (filename) ;
1186
1187         puts ("ok") ;
1188 } /* pcm_test_bits_32 */
1189
1190
1191
1192 /*==============================================================================
1193 */
1194
1195 static void
1196 pcm_test_float (const char *filename, int filetype, uint64_t hash, int replace_float)
1197 {       SNDFILE                 *file ;
1198         SF_INFO                 sfinfo ;
1199         int                             k, items, frames ;
1200         int                             sign ;
1201         double                  *data, error ;
1202
1203         print_test_name (replace_float ? "pcm_test_float (replace)" : "pcm_test_float", filename) ;
1204
1205         items = BUFFER_SIZE ;
1206
1207         data = data_out.d ;
1208         for (sign = 1, k = 0 ; k < items ; k++)
1209         {       data [k] = ((double) (k * sign)) / 100.0 ;
1210                 sign = (sign > 0) ? -1 : 1 ;
1211                 } ;
1212
1213         sfinfo.samplerate       = 44100 ;
1214         sfinfo.frames           = items ;
1215         sfinfo.channels         = 1 ;
1216         sfinfo.format           = filetype ;
1217
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) ;
1223                 exit (1) ;
1224                 } ;
1225
1226         test_write_double_or_die (file, 0, data, items, __LINE__) ;
1227
1228         sf_close (file) ;
1229
1230         check_file_hash_or_die (filename, hash, __LINE__) ;
1231
1232         memset (data, 0, items * sizeof (double)) ;
1233
1234         if ((filetype & SF_FORMAT_TYPEMASK) != SF_FORMAT_RAW)
1235                 memset (&sfinfo, 0, sizeof (sfinfo)) ;
1236
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) ;
1242                 exit (1) ;
1243                 } ;
1244
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) ;
1247                 exit (1) ;
1248                 } ;
1249
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) ;
1252                 exit (1) ;
1253                 } ;
1254
1255         if (sfinfo.channels != 1)
1256         {       printf ("\n\nError (%s:%d) Mono : Incorrect number of channels in file.\n", __FILE__, __LINE__) ;
1257                 exit (1) ;
1258                 } ;
1259
1260         check_log_buffer_or_die (file, __LINE__) ;
1261
1262         test_read_double_or_die (file, 0, data, items, __LINE__) ;
1263
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]) ;
1268                         exit (1) ;
1269                         } ;
1270                 } ;
1271
1272         /* Seek to end of file. */
1273         test_seek_or_die (file, 0, SEEK_END, sfinfo.frames, sfinfo.channels, __LINE__) ;
1274
1275         /* Seek to start of file. */
1276         test_seek_or_die (file, 0, SEEK_SET, 0, sfinfo.channels, __LINE__) ;
1277
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]) ;
1283                         exit (1) ;
1284                         } ;
1285                 } ;
1286
1287         /* Seek to offset from start of file. */
1288         test_seek_or_die (file, 10, SEEK_SET, 10, sfinfo.channels, __LINE__) ;
1289
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]) ;
1295                         exit (1) ;
1296                         } ;
1297                 } ;
1298
1299         /* Seek to offset from current position. */
1300         test_seek_or_die (file, 6, SEEK_CUR, 20, sfinfo.channels, __LINE__) ;
1301
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]) ;
1307                         exit (1) ;
1308                         } ;
1309                 } ;
1310
1311         /* Seek to offset from end of file. */
1312         test_seek_or_die (file, -1 * (sfinfo.frames - 10), SEEK_END, 10, sfinfo.channels, __LINE__) ;
1313
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]) ;
1319                         exit (1) ;
1320                         } ;
1321                 } ;
1322
1323         sf_close (file) ;
1324
1325         /* Now test Stereo. */
1326
1327         if ((filetype & SF_FORMAT_TYPEMASK) == SF_FORMAT_SVX) /* SVX is mono only */
1328         {       printf ("ok\n") ;
1329                 return ;
1330                 } ;
1331
1332         items = BUFFER_SIZE ;
1333
1334         data = data_out.d ;
1335         for (sign = -1, k = 0 ; k < items ; k++)
1336                 data [k] = ((double) k) / 100.0 * (sign *= -1) ;
1337
1338         sfinfo.samplerate       = 44100 ;
1339         sfinfo.frames           = items ;
1340         sfinfo.channels         = 2 ;
1341         sfinfo.format           = filetype ;
1342
1343         frames = items / sfinfo.channels ;
1344
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) ;
1350                 exit (1) ;
1351                 } ;
1352
1353         test_writef_double_or_die (file, 0, data, frames, __LINE__) ;
1354
1355         sf_close (file) ;
1356
1357         check_file_hash_or_die (filename, hash, __LINE__) ;
1358
1359         memset (data, 0, items * sizeof (double)) ;
1360
1361         if ((filetype & SF_FORMAT_TYPEMASK) != SF_FORMAT_RAW)
1362                 memset (&sfinfo, 0, sizeof (sfinfo)) ;
1363
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) ;
1369                 exit (1) ;
1370                 } ;
1371
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) ;
1374                 exit (1) ;
1375                 } ;
1376
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) ;
1379                 exit (1) ;
1380                 } ;
1381
1382         if (sfinfo.channels != 2)
1383         {       printf ("\n\nError (%s:%d) Stereo : Incorrect number of channels in file.\n", __FILE__, __LINE__) ;
1384                 exit (1) ;
1385                 } ;
1386
1387         check_log_buffer_or_die (file, __LINE__) ;
1388
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]) ;
1394                         exit (1) ;
1395                         } ;
1396                 } ;
1397
1398         /* Seek to start of file. */
1399         test_seek_or_die (file, 0, SEEK_SET, 0, sfinfo.channels, __LINE__) ;
1400
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]) ;
1406                         exit (1) ;
1407                         } ;
1408                 } ;
1409
1410         /* Seek to offset from start of file. */
1411         test_seek_or_die (file, 10, SEEK_SET, 10, sfinfo.channels, __LINE__) ;
1412
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]) ;
1418                         exit (1) ;
1419                         } ;
1420                 } ;
1421
1422         /* Seek to offset from current position. */
1423         test_seek_or_die (file, 8, SEEK_CUR, 20, sfinfo.channels, __LINE__) ;
1424
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]) ;
1430                         exit (1) ;
1431                         } ;
1432                 } ;
1433
1434         /* Seek to offset from end of file. */
1435         test_seek_or_die (file, -1 * (sfinfo.frames - 10), SEEK_END, 10, sfinfo.channels, __LINE__) ;
1436
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]) ;
1442                         exit (1) ;
1443                         } ;
1444                 } ;
1445
1446         sf_close (file) ;
1447
1448         printf ("ok\n") ;
1449         unlink (filename) ;
1450 } /* pcm_test_float */
1451
1452 static void
1453 pcm_test_double (const char *filename, int      filetype, uint64_t hash, int replace_float)
1454 {       SNDFILE                 *file ;
1455         SF_INFO                 sfinfo ;
1456         int                             k, items, frames ;
1457         int                             sign ;
1458         double                  *data, error ;
1459
1460         /* This is the best test routine. Other should be brought up to this standard. */
1461
1462         print_test_name (replace_float ? "pcm_test_double (replace)" : "pcm_test_double", filename) ;
1463
1464         items = BUFFER_SIZE ;
1465
1466         data = data_out.d ;
1467         for (sign = 1, k = 0 ; k < items ; k++)
1468         {       data [k] = ((double) (k * sign)) / 100.0 ;
1469                 sign = (sign > 0) ? -1 : 1 ;
1470                 } ;
1471
1472         sfinfo.samplerate       = 44100 ;
1473         sfinfo.frames           = items ;
1474         sfinfo.channels         = 1 ;
1475         sfinfo.format           = filetype ;
1476
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) ;
1482                 exit (1) ;
1483                 } ;
1484
1485         test_write_double_or_die (file, 0, data, items, __LINE__) ;
1486
1487         sf_close (file) ;
1488
1489 #if (defined (WIN32) || defined (_WIN32))
1490         /* File hashing on Win32 fails due to slighty different
1491         ** calculated values of the sin() function.
1492         */
1493         hash = hash ; /* Avoid compiler warning. */
1494 #else
1495         check_file_hash_or_die (filename, hash, __LINE__) ;
1496 #endif
1497
1498         memset (data, 0, items * sizeof (double)) ;
1499
1500         if ((filetype & SF_FORMAT_TYPEMASK) != SF_FORMAT_RAW)
1501                 memset (&sfinfo, 0, sizeof (sfinfo)) ;
1502
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) ;
1508                 exit (1) ;
1509                 } ;
1510
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) ;
1513                 exit (1) ;
1514                 } ;
1515
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) ;
1518                 exit (1) ;
1519                 } ;
1520
1521         if (sfinfo.channels != 1)
1522         {       printf ("\n\nError (%s:%d) Mono : Incorrect number of channels in file.\n", __FILE__, __LINE__) ;
1523                 exit (1) ;
1524                 } ;
1525
1526         check_log_buffer_or_die (file, __LINE__) ;
1527
1528         test_read_double_or_die (file, 0, data, items, __LINE__) ;
1529
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]) ;
1534                         exit (1) ;
1535                         } ;
1536                 } ;
1537
1538         /* Seek to start of file. */
1539         test_seek_or_die (file, 0, SEEK_SET, 0, sfinfo.channels, __LINE__) ;
1540
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]) ;
1546                         exit (1) ;
1547                         } ;
1548                 } ;
1549
1550         /* Seek to offset from start of file. */
1551         test_seek_or_die (file, 10, SEEK_SET, 10, sfinfo.channels, __LINE__) ;
1552
1553         test_read_double_or_die (file, 0, data + 10, 4, __LINE__) ;
1554
1555         test_seek_or_die (file, 0, SEEK_CUR, 14, sfinfo.channels, __LINE__) ;
1556
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]) ;
1561                         exit (1) ;
1562                         } ;
1563                 } ;
1564
1565         /* Seek to offset from current position. */
1566         test_seek_or_die (file, 6, SEEK_CUR, 20, sfinfo.channels, __LINE__) ;
1567
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]) ;
1573                         exit (1) ;
1574                         } ;
1575                 } ;
1576
1577         /* Seek to offset from end of file. */
1578         test_seek_or_die (file, -1 * (sfinfo.frames - 10), SEEK_END, 10, sfinfo.channels, __LINE__) ;
1579
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]) ;
1585                         exit (1) ;
1586                         } ;
1587                 } ;
1588
1589         sf_close (file) ;
1590
1591         /* Now test Stereo. */
1592
1593         if ((filetype & SF_FORMAT_TYPEMASK) == SF_FORMAT_SVX) /* SVX is mono only */
1594         {       printf ("ok\n") ;
1595                 return ;
1596                 } ;
1597
1598         items = BUFFER_SIZE ;
1599
1600         data = data_out.d ;
1601         for (sign = -1, k = 0 ; k < items ; k++)
1602                 data [k] = ((double) k) / 100.0 * (sign *= -1) ;
1603
1604         sfinfo.samplerate       = 44100 ;
1605         sfinfo.frames           = items ;
1606         sfinfo.channels         = 2 ;
1607         sfinfo.format           = filetype ;
1608
1609         frames = items / sfinfo.channels ;
1610
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) ;
1616                 exit (1) ;
1617                 } ;
1618
1619         test_writef_double_or_die (file, 0, data, frames, __LINE__) ;
1620
1621         sf_close (file) ;
1622
1623 #if (defined (WIN32) || defined (_WIN32))
1624         /* File hashing on Win32 fails due to slighty different
1625         ** calculated values.
1626         */
1627         hash = hash ; /* Avoid compiler warning. */
1628 #else
1629         check_file_hash_or_die (filename, hash, __LINE__) ;
1630 #endif
1631
1632         memset (data, 0, items * sizeof (double)) ;
1633
1634         if ((filetype & SF_FORMAT_TYPEMASK) != SF_FORMAT_RAW)
1635                 memset (&sfinfo, 0, sizeof (sfinfo)) ;
1636
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) ;
1642                 exit (1) ;
1643                 } ;
1644
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) ;
1647                 exit (1) ;
1648                 } ;
1649
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) ;
1652                 exit (1) ;
1653                 } ;
1654
1655         if (sfinfo.channels != 2)
1656         {       printf ("\n\nError (%s:%d) Stereo : Incorrect number of channels in file.\n", __FILE__, __LINE__) ;
1657                 exit (1) ;
1658                 } ;
1659
1660         check_log_buffer_or_die (file, __LINE__) ;
1661
1662         test_readf_double_or_die (file, 0, data, frames, __LINE__) ;
1663
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]) ;
1668                         exit (1) ;
1669                         } ;
1670                 } ;
1671
1672         /* Seek to start of file. */
1673         test_seek_or_die (file, 0, SEEK_SET, 0, sfinfo.channels, __LINE__) ;
1674
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]) ;
1680                         exit (1) ;
1681                         } ;
1682                 } ;
1683
1684         /* Seek to offset from start of file. */
1685         test_seek_or_die (file, 10, SEEK_SET, 10, sfinfo.channels, __LINE__) ;
1686
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]) ;
1692                         exit (1) ;
1693                         } ;
1694                 } ;
1695
1696         /* Seek to offset from current position. */
1697         test_seek_or_die (file, 8, SEEK_CUR, 20, sfinfo.channels, __LINE__) ;
1698
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]) ;
1704                         exit (1) ;
1705                         } ;
1706                 } ;
1707
1708         /* Seek to offset from end of file. */
1709         test_seek_or_die (file, -1 * (sfinfo.frames -10), SEEK_END, 10, sfinfo.channels, __LINE__) ;
1710
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]) ;
1716                         exit (1) ;
1717                         } ;
1718                 } ;
1719
1720         sf_close (file) ;
1721
1722         printf ("ok\n") ;
1723         unlink (filename) ;
1724 } /* pcm_test_double */
1725
1726 /*==============================================================================
1727 */