~ubuntu-branches/ubuntu/gutsy/audacity/gutsy-backports

« back to all changes in this revision

Viewing changes to lib-src/libsndfile/tests/pcm_test.c

  • Committer: Bazaar Package Importer
  • Author(s): John Dong
  • Date: 2008-02-18 21:58:19 UTC
  • mfrom: (13.1.2 hardy)
  • Revision ID: james.westby@ubuntu.com-20080218215819-tmbcf1rx238r8gdv
Tags: 1.3.4-1.1ubuntu1~gutsy1
Automated backport upload; no source changes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
** Copyright (C) 1999-2004 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
 
 
25
 
#if HAVE_UNISTD_H
26
 
#include <unistd.h>
27
 
#endif
28
 
 
29
 
#include <sndfile.h>
30
 
 
31
 
#include "float_cast.h"
32
 
#include "utils.h"
33
 
 
34
 
#define BUFFER_SIZE             (1<<15)
35
 
 
36
 
static void     lrintf_test (void) ;
37
 
 
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) ;
42
 
 
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) ;
45
 
 
46
 
/* Data written to the file. */
47
 
static  double  data_out [(BUFFER_SIZE / sizeof (double)) + 1] ;
48
 
 
49
 
/* Data read back from the file. */
50
 
static  double  data_in [(BUFFER_SIZE / sizeof (double)) + 1] ;
51
 
 
52
 
int
53
 
main (void)
54
 
{
55
 
        lrintf_test () ;
56
 
 
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) ;
59
 
 
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) ;
62
 
 
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) ;
65
 
 
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) ;
68
 
 
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) ;
72
 
 
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) ;
75
 
 
76
 
        puts ("Test IEEE replacement code.") ;
77
 
 
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) ;
80
 
 
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) ;
83
 
        /* Lite remove end */
84
 
 
85
 
        return 0 ;
86
 
} /* main */
87
 
 
88
 
/*============================================================================================
89
 
**      Here are the test functions.
90
 
*/
91
 
 
92
 
static void
93
 
lrintf_test (void)
94
 
{       int k, items ;
95
 
        float   *float_data ;
96
 
        int             *int_data ;
97
 
 
98
 
        print_test_name ("lrintf_test", "") ;
99
 
 
100
 
        items = 1024 ;
101
 
 
102
 
        float_data = (float*) data_out ;
103
 
        int_data = (int*) data_in ;
104
 
 
105
 
        for (k = 0 ; k < items ; k++)
106
 
                float_data [k] = (k * ((k % 2) ? 333333.0 : -333333.0)) ;
107
 
 
108
 
        for (k = 0 ; k < items ; k++)
109
 
                int_data [k] = lrintf (float_data [k]) ;
110
 
 
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]) ;
114
 
                        exit (1) ;
115
 
                        } ;
116
 
 
117
 
        printf ("ok\n") ;
118
 
} /* lrintf_test */
119
 
 
120
 
static void
121
 
pcm_test_bits_8 (const char *filename, int filetype, int hash)
122
 
{       SNDFILE         *file ;
123
 
        SF_INFO         sfinfo ;
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 */
131
 
 
132
 
        print_test_name ("pcm_test_bits_8", filename) ;
133
 
 
134
 
        items = 127 ;
135
 
 
136
 
        short_out = (short*) data_out ;
137
 
        short_in = (short*) data_in ;
138
 
 
139
 
        zero_count = 0 ;
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 ;
143
 
                } ;
144
 
 
145
 
        if (zero_count > items / 4)
146
 
        {       printf ("\n\nLine %d: too many zeros.\n", __LINE__) ;
147
 
                exit (1) ;
148
 
                } ;
149
 
 
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 ;
154
 
 
155
 
        file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
156
 
 
157
 
        test_write_short_or_die (file, 0, short_out, items, __LINE__) ;
158
 
 
159
 
        sf_close (file) ;
160
 
 
161
 
        memset (short_in, 0, items * sizeof (short)) ;
162
 
 
163
 
        file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
164
 
 
165
 
        if (sfinfo.format != filetype)
166
 
        {       printf ("\n\nLine %d: Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__, filetype, sfinfo.format) ;
167
 
                exit (1) ;
168
 
                } ;
169
 
 
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)) ;
172
 
                exit (1) ;
173
 
                } ;
174
 
 
175
 
        if (sfinfo.channels != 1)
176
 
        {       printf ("\n\nLine %d: Incorrect number of channels in file.\n", __LINE__) ;
177
 
                exit (1) ;
178
 
                } ;
179
 
 
180
 
        check_log_buffer_or_die (file, __LINE__) ;
181
 
 
182
 
        test_read_short_or_die (file, 0, short_in, items, __LINE__) ;
183
 
 
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]) ;
187
 
                        exit (1) ;
188
 
                        } ;
189
 
 
190
 
        sf_close (file) ;
191
 
 
192
 
        /* Finally, check the file hash. */
193
 
        check_file_hash_or_die (filename, hash, __LINE__) ;
194
 
 
195
 
        /*--------------------------------------------------------------------------
196
 
        ** Test sf_read/write_int ()
197
 
        */
198
 
        zero_count = 0 ;
199
 
 
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 ;
205
 
                } ;
206
 
 
207
 
        if (zero_count > items / 4)
208
 
        {       printf ("\n\nLine %d: too many zeros.\n", __LINE__) ;
209
 
                exit (1) ;
210
 
                } ;
211
 
 
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 ;
216
 
 
217
 
        file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
218
 
 
219
 
        test_write_int_or_die (file, 0, int_out, items, __LINE__) ;
220
 
 
221
 
        sf_close (file) ;
222
 
 
223
 
        memset (int_in, 0, items * sizeof (int)) ;
224
 
 
225
 
        file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
226
 
 
227
 
        if (sfinfo.format != filetype)
228
 
        {       printf ("\n\nLine %d: Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__, filetype, sfinfo.format) ;
229
 
                exit (1) ;
230
 
                } ;
231
 
 
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)) ;
234
 
                exit (1) ;
235
 
                } ;
236
 
 
237
 
        if (sfinfo.channels != 1)
238
 
        {       printf ("\n\nLine %d: Incorrect number of channels in file.\n", __LINE__) ;
239
 
                exit (1) ;
240
 
                } ;
241
 
 
242
 
        check_log_buffer_or_die (file, __LINE__) ;
243
 
 
244
 
        test_read_int_or_die (file, 0, int_in, items, __LINE__) ;
245
 
 
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]) ;
249
 
                        exit (1) ;
250
 
                        } ;
251
 
 
252
 
        sf_close (file) ;
253
 
 
254
 
        /* Lite remove start */
255
 
        /*--------------------------------------------------------------------------
256
 
        ** Test sf_read/write_float ()
257
 
        */
258
 
        zero_count = 0 ;
259
 
 
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 ;
265
 
                } ;
266
 
 
267
 
        if (zero_count > items / 4)
268
 
        {       printf ("\n\nLine %d: too many zeros (%d/%d).\n", __LINE__, zero_count, items) ;
269
 
                exit (1) ;
270
 
                } ;
271
 
 
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 ;
276
 
 
277
 
        file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
278
 
 
279
 
        sf_command (file, SFC_SET_NORM_FLOAT, NULL, SF_FALSE) ;
280
 
 
281
 
        test_write_float_or_die (file, 0, float_out, items, __LINE__) ;
282
 
 
283
 
        sf_close (file) ;
284
 
 
285
 
        memset (float_in, 0, items * sizeof (float)) ;
286
 
 
287
 
        file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
288
 
 
289
 
        if (sfinfo.format != filetype)
290
 
        {       printf ("\n\nLine %d: Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__, filetype, sfinfo.format) ;
291
 
                exit (1) ;
292
 
                } ;
293
 
 
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)) ;
296
 
                exit (1) ;
297
 
                } ;
298
 
 
299
 
        if (sfinfo.channels != 1)
300
 
        {       printf ("\n\nLine %d: Incorrect number of channels in file.\n", __LINE__) ;
301
 
                exit (1) ;
302
 
                } ;
303
 
 
304
 
        check_log_buffer_or_die (file, __LINE__) ;
305
 
 
306
 
        sf_command (file, SFC_SET_NORM_FLOAT, NULL, SF_FALSE) ;
307
 
 
308
 
        test_read_float_or_die (file, 0, float_in, items, __LINE__) ;
309
 
 
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]) ;
313
 
                        exit (1) ;
314
 
                        break ;
315
 
                        } ;
316
 
 
317
 
        sf_close (file) ;
318
 
 
319
 
        /*--------------------------------------------------------------------------
320
 
        ** Test sf_read/write_double ()
321
 
        */
322
 
        zero_count = 0 ;
323
 
 
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 ;
329
 
                } ;
330
 
 
331
 
        if (zero_count > items / 4)
332
 
        {       printf ("\n\nLine %d: too many zeros (%d/%d).\n", __LINE__, zero_count, items) ;
333
 
                exit (1) ;
334
 
                } ;
335
 
 
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 ;
340
 
 
341
 
        file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
342
 
 
343
 
        sf_command (file, SFC_SET_NORM_DOUBLE, NULL, SF_FALSE) ;
344
 
 
345
 
        test_write_double_or_die (file, 0, double_out, items, __LINE__) ;
346
 
 
347
 
        sf_close (file) ;
348
 
 
349
 
        memset (double_in, 0, items * sizeof (double)) ;
350
 
 
351
 
        file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
352
 
 
353
 
        if (sfinfo.format != filetype)
354
 
        {       printf ("\n\nLine %d: Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__, filetype, sfinfo.format) ;
355
 
                exit (1) ;
356
 
                } ;
357
 
 
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)) ;
360
 
                exit (1) ;
361
 
                } ;
362
 
 
363
 
        if (sfinfo.channels != 1)
364
 
        {       printf ("\n\nLine %d: Incorrect number of channels in file.\n", __LINE__) ;
365
 
                exit (1) ;
366
 
                } ;
367
 
 
368
 
        check_log_buffer_or_die (file, __LINE__) ;
369
 
 
370
 
        sf_command (file, SFC_SET_NORM_DOUBLE, NULL, SF_FALSE) ;
371
 
 
372
 
        test_read_double_or_die (file, 0, double_in, items, __LINE__) ;
373
 
 
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]) ;
377
 
                        exit (1) ;
378
 
                        } ;
379
 
 
380
 
        sf_close (file) ;
381
 
        /* Lite remove end */
382
 
        unlink (filename) ;
383
 
 
384
 
        puts ("ok") ;
385
 
} /* pcm_test_bits_8 */
386
 
 
387
 
static void
388
 
pcm_test_bits_16 (const char *filename, int filetype, int hash)
389
 
{       SNDFILE         *file ;
390
 
        SF_INFO         sfinfo ;
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 */
398
 
 
399
 
        print_test_name ("pcm_test_bits_16", filename) ;
400
 
 
401
 
        items = 1024 ;
402
 
 
403
 
        short_out = (short*) data_out ;
404
 
        short_in = (short*) data_in ;
405
 
 
406
 
        zero_count = 0 ;
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 ;
410
 
                } ;
411
 
 
412
 
        if (zero_count > items / 4)
413
 
        {       printf ("\n\nLine %d: too many zeros.\n", __LINE__) ;
414
 
                exit (1) ;
415
 
                } ;
416
 
 
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 ;
421
 
 
422
 
        file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
423
 
 
424
 
        test_write_short_or_die (file, 0, short_out, items, __LINE__) ;
425
 
 
426
 
        sf_close (file) ;
427
 
 
428
 
        memset (short_in, 0, items * sizeof (short)) ;
429
 
 
430
 
        file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
431
 
 
432
 
        if (sfinfo.format != filetype)
433
 
        {       printf ("\n\nLine %d: Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__, filetype, sfinfo.format) ;
434
 
                exit (1) ;
435
 
                } ;
436
 
 
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)) ;
439
 
                exit (1) ;
440
 
                } ;
441
 
 
442
 
        if (sfinfo.channels != 1)
443
 
        {       printf ("\n\nLine %d: Incorrect number of channels in file.\n", __LINE__) ;
444
 
                exit (1) ;
445
 
                } ;
446
 
 
447
 
        check_log_buffer_or_die (file, __LINE__) ;
448
 
 
449
 
        test_read_short_or_die (file, 0, short_in, items, __LINE__) ;
450
 
 
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]) ;
454
 
                        exit (1) ;
455
 
                        } ;
456
 
 
457
 
        sf_close (file) ;
458
 
 
459
 
        /* Finally, check the file hash. */
460
 
        check_file_hash_or_die (filename, hash, __LINE__) ;
461
 
 
462
 
        /*--------------------------------------------------------------------------
463
 
        ** Test sf_read/write_int ()
464
 
        */
465
 
        zero_count = 0 ;
466
 
 
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 ;
472
 
                } ;
473
 
 
474
 
        if (zero_count > items / 4)
475
 
        {       printf ("\n\nLine %d: too many zeros.\n", __LINE__) ;
476
 
                exit (1) ;
477
 
                } ;
478
 
 
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 ;
483
 
 
484
 
        file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
485
 
 
486
 
        test_write_int_or_die (file, 0, int_out, items, __LINE__) ;
487
 
 
488
 
        sf_close (file) ;
489
 
 
490
 
        memset (int_in, 0, items * sizeof (int)) ;
491
 
 
492
 
        file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
493
 
 
494
 
        if (sfinfo.format != filetype)
495
 
        {       printf ("\n\nLine %d: Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__, filetype, sfinfo.format) ;
496
 
                exit (1) ;
497
 
                } ;
498
 
 
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)) ;
501
 
                exit (1) ;
502
 
                } ;
503
 
 
504
 
        if (sfinfo.channels != 1)
505
 
        {       printf ("\n\nLine %d: Incorrect number of channels in file.\n", __LINE__) ;
506
 
                exit (1) ;
507
 
                } ;
508
 
 
509
 
        check_log_buffer_or_die (file, __LINE__) ;
510
 
 
511
 
        test_read_int_or_die (file, 0, int_in, items, __LINE__) ;
512
 
 
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]) ;
516
 
                        exit (1) ;
517
 
                        } ;
518
 
 
519
 
        sf_close (file) ;
520
 
 
521
 
        /* Lite remove start */
522
 
        /*--------------------------------------------------------------------------
523
 
        ** Test sf_read/write_float ()
524
 
        */
525
 
        zero_count = 0 ;
526
 
 
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 ;
532
 
                } ;
533
 
 
534
 
        if (zero_count > items / 4)
535
 
        {       printf ("\n\nLine %d: too many zeros (%d/%d).\n", __LINE__, zero_count, items) ;
536
 
                exit (1) ;
537
 
                } ;
538
 
 
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 ;
543
 
 
544
 
        file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
545
 
 
546
 
        sf_command (file, SFC_SET_NORM_FLOAT, NULL, SF_FALSE) ;
547
 
 
548
 
        test_write_float_or_die (file, 0, float_out, items, __LINE__) ;
549
 
 
550
 
        sf_close (file) ;
551
 
 
552
 
        memset (float_in, 0, items * sizeof (float)) ;
553
 
 
554
 
        file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
555
 
 
556
 
        if (sfinfo.format != filetype)
557
 
        {       printf ("\n\nLine %d: Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__, filetype, sfinfo.format) ;
558
 
                exit (1) ;
559
 
                } ;
560
 
 
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)) ;
563
 
                exit (1) ;
564
 
                } ;
565
 
 
566
 
        if (sfinfo.channels != 1)
567
 
        {       printf ("\n\nLine %d: Incorrect number of channels in file.\n", __LINE__) ;
568
 
                exit (1) ;
569
 
                } ;
570
 
 
571
 
        check_log_buffer_or_die (file, __LINE__) ;
572
 
 
573
 
        sf_command (file, SFC_SET_NORM_FLOAT, NULL, SF_FALSE) ;
574
 
 
575
 
        test_read_float_or_die (file, 0, float_in, items, __LINE__) ;
576
 
 
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]) ;
580
 
                        exit (1) ;
581
 
                        break ;
582
 
                        } ;
583
 
 
584
 
        sf_close (file) ;
585
 
 
586
 
        /*--------------------------------------------------------------------------
587
 
        ** Test sf_read/write_double ()
588
 
        */
589
 
        zero_count = 0 ;
590
 
 
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 ;
596
 
                } ;
597
 
 
598
 
        if (zero_count > items / 4)
599
 
        {       printf ("\n\nLine %d: too many zeros (%d/%d).\n", __LINE__, zero_count, items) ;
600
 
                exit (1) ;
601
 
                } ;
602
 
 
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 ;
607
 
 
608
 
        file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
609
 
 
610
 
        sf_command (file, SFC_SET_NORM_DOUBLE, NULL, SF_FALSE) ;
611
 
 
612
 
        test_write_double_or_die (file, 0, double_out, items, __LINE__) ;
613
 
 
614
 
        sf_close (file) ;
615
 
 
616
 
        memset (double_in, 0, items * sizeof (double)) ;
617
 
 
618
 
        file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
619
 
 
620
 
        if (sfinfo.format != filetype)
621
 
        {       printf ("\n\nLine %d: Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__, filetype, sfinfo.format) ;
622
 
                exit (1) ;
623
 
                } ;
624
 
 
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)) ;
627
 
                exit (1) ;
628
 
                } ;
629
 
 
630
 
        if (sfinfo.channels != 1)
631
 
        {       printf ("\n\nLine %d: Incorrect number of channels in file.\n", __LINE__) ;
632
 
                exit (1) ;
633
 
                } ;
634
 
 
635
 
        check_log_buffer_or_die (file, __LINE__) ;
636
 
 
637
 
        sf_command (file, SFC_SET_NORM_DOUBLE, NULL, SF_FALSE) ;
638
 
 
639
 
        test_read_double_or_die (file, 0, double_in, items, __LINE__) ;
640
 
 
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]) ;
644
 
                        exit (1) ;
645
 
                        } ;
646
 
 
647
 
        sf_close (file) ;
648
 
        /* Lite remove end */
649
 
        unlink (filename) ;
650
 
 
651
 
        puts ("ok") ;
652
 
} /* pcm_test_bits_16 */
653
 
 
654
 
static void
655
 
pcm_test_bits_24 (const char *filename, int filetype, int hash)
656
 
{       SNDFILE         *file ;
657
 
        SF_INFO         sfinfo ;
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 */
665
 
 
666
 
        print_test_name ("pcm_test_bits_24", filename) ;
667
 
 
668
 
        items = 1024 ;
669
 
 
670
 
        short_out = (short*) data_out ;
671
 
        short_in = (short*) data_in ;
672
 
 
673
 
        zero_count = 0 ;
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 ;
677
 
                } ;
678
 
 
679
 
        if (zero_count > items / 4)
680
 
        {       printf ("\n\nLine %d: too many zeros.\n", __LINE__) ;
681
 
                exit (1) ;
682
 
                } ;
683
 
 
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 ;
688
 
 
689
 
        file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
690
 
 
691
 
        test_write_short_or_die (file, 0, short_out, items, __LINE__) ;
692
 
 
693
 
        sf_close (file) ;
694
 
 
695
 
        memset (short_in, 0, items * sizeof (short)) ;
696
 
 
697
 
        file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
698
 
 
699
 
        if (sfinfo.format != filetype)
700
 
        {       printf ("\n\nLine %d: Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__, filetype, sfinfo.format) ;
701
 
                exit (1) ;
702
 
                } ;
703
 
 
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)) ;
706
 
                exit (1) ;
707
 
                } ;
708
 
 
709
 
        if (sfinfo.channels != 1)
710
 
        {       printf ("\n\nLine %d: Incorrect number of channels in file.\n", __LINE__) ;
711
 
                exit (1) ;
712
 
                } ;
713
 
 
714
 
        check_log_buffer_or_die (file, __LINE__) ;
715
 
 
716
 
        test_read_short_or_die (file, 0, short_in, items, __LINE__) ;
717
 
 
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]) ;
721
 
                        exit (1) ;
722
 
                        } ;
723
 
 
724
 
        sf_close (file) ;
725
 
 
726
 
        /* Finally, check the file hash. */
727
 
        check_file_hash_or_die (filename, hash, __LINE__) ;
728
 
 
729
 
        /*--------------------------------------------------------------------------
730
 
        ** Test sf_read/write_int ()
731
 
        */
732
 
        zero_count = 0 ;
733
 
 
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 ;
739
 
                } ;
740
 
 
741
 
        if (zero_count > items / 4)
742
 
        {       printf ("\n\nLine %d: too many zeros.\n", __LINE__) ;
743
 
                exit (1) ;
744
 
                } ;
745
 
 
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 ;
750
 
 
751
 
        file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
752
 
 
753
 
        test_write_int_or_die (file, 0, int_out, items, __LINE__) ;
754
 
 
755
 
        sf_close (file) ;
756
 
 
757
 
        memset (int_in, 0, items * sizeof (int)) ;
758
 
 
759
 
        file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
760
 
 
761
 
        if (sfinfo.format != filetype)
762
 
        {       printf ("\n\nLine %d: Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__, filetype, sfinfo.format) ;
763
 
                exit (1) ;
764
 
                } ;
765
 
 
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)) ;
768
 
                exit (1) ;
769
 
                } ;
770
 
 
771
 
        if (sfinfo.channels != 1)
772
 
        {       printf ("\n\nLine %d: Incorrect number of channels in file.\n", __LINE__) ;
773
 
                exit (1) ;
774
 
                } ;
775
 
 
776
 
        check_log_buffer_or_die (file, __LINE__) ;
777
 
 
778
 
        test_read_int_or_die (file, 0, int_in, items, __LINE__) ;
779
 
 
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]) ;
783
 
                        exit (1) ;
784
 
                        } ;
785
 
 
786
 
        sf_close (file) ;
787
 
 
788
 
        /* Lite remove start */
789
 
        /*--------------------------------------------------------------------------
790
 
        ** Test sf_read/write_float ()
791
 
        */
792
 
        zero_count = 0 ;
793
 
 
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 ;
799
 
                } ;
800
 
 
801
 
        if (zero_count > items / 4)
802
 
        {       printf ("\n\nLine %d: too many zeros (%d/%d).\n", __LINE__, zero_count, items) ;
803
 
                exit (1) ;
804
 
                } ;
805
 
 
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 ;
810
 
 
811
 
        file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
812
 
 
813
 
        sf_command (file, SFC_SET_NORM_FLOAT, NULL, SF_FALSE) ;
814
 
 
815
 
        test_write_float_or_die (file, 0, float_out, items, __LINE__) ;
816
 
 
817
 
        sf_close (file) ;
818
 
 
819
 
        memset (float_in, 0, items * sizeof (float)) ;
820
 
 
821
 
        file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
822
 
 
823
 
        if (sfinfo.format != filetype)
824
 
        {       printf ("\n\nLine %d: Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__, filetype, sfinfo.format) ;
825
 
                exit (1) ;
826
 
                } ;
827
 
 
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)) ;
830
 
                exit (1) ;
831
 
                } ;
832
 
 
833
 
        if (sfinfo.channels != 1)
834
 
        {       printf ("\n\nLine %d: Incorrect number of channels in file.\n", __LINE__) ;
835
 
                exit (1) ;
836
 
                } ;
837
 
 
838
 
        check_log_buffer_or_die (file, __LINE__) ;
839
 
 
840
 
        sf_command (file, SFC_SET_NORM_FLOAT, NULL, SF_FALSE) ;
841
 
 
842
 
        test_read_float_or_die (file, 0, float_in, items, __LINE__) ;
843
 
 
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]) ;
847
 
                        exit (1) ;
848
 
                        break ;
849
 
                        } ;
850
 
 
851
 
        sf_close (file) ;
852
 
 
853
 
        /*--------------------------------------------------------------------------
854
 
        ** Test sf_read/write_double ()
855
 
        */
856
 
        zero_count = 0 ;
857
 
 
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 ;
863
 
                } ;
864
 
 
865
 
        if (zero_count > items / 4)
866
 
        {       printf ("\n\nLine %d: too many zeros (%d/%d).\n", __LINE__, zero_count, items) ;
867
 
                exit (1) ;
868
 
                } ;
869
 
 
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 ;
874
 
 
875
 
        file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
876
 
 
877
 
        sf_command (file, SFC_SET_NORM_DOUBLE, NULL, SF_FALSE) ;
878
 
 
879
 
        test_write_double_or_die (file, 0, double_out, items, __LINE__) ;
880
 
 
881
 
        sf_close (file) ;
882
 
 
883
 
        memset (double_in, 0, items * sizeof (double)) ;
884
 
 
885
 
        file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
886
 
 
887
 
        if (sfinfo.format != filetype)
888
 
        {       printf ("\n\nLine %d: Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__, filetype, sfinfo.format) ;
889
 
                exit (1) ;
890
 
                } ;
891
 
 
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)) ;
894
 
                exit (1) ;
895
 
                } ;
896
 
 
897
 
        if (sfinfo.channels != 1)
898
 
        {       printf ("\n\nLine %d: Incorrect number of channels in file.\n", __LINE__) ;
899
 
                exit (1) ;
900
 
                } ;
901
 
 
902
 
        check_log_buffer_or_die (file, __LINE__) ;
903
 
 
904
 
        sf_command (file, SFC_SET_NORM_DOUBLE, NULL, SF_FALSE) ;
905
 
 
906
 
        test_read_double_or_die (file, 0, double_in, items, __LINE__) ;
907
 
 
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]) ;
911
 
                        exit (1) ;
912
 
                        } ;
913
 
 
914
 
        sf_close (file) ;
915
 
        /* Lite remove end */
916
 
        unlink (filename) ;
917
 
 
918
 
        puts ("ok") ;
919
 
} /* pcm_test_bits_24 */
920
 
 
921
 
static void
922
 
pcm_test_bits_32 (const char *filename, int filetype, int hash)
923
 
{       SNDFILE         *file ;
924
 
        SF_INFO         sfinfo ;
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 */
932
 
 
933
 
        print_test_name ("pcm_test_bits_32", filename) ;
934
 
 
935
 
        items = 1024 ;
936
 
 
937
 
        short_out = (short*) data_out ;
938
 
        short_in = (short*) data_in ;
939
 
 
940
 
        zero_count = 0 ;
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 ;
944
 
                } ;
945
 
 
946
 
        if (zero_count > items / 4)
947
 
        {       printf ("\n\nLine %d: too many zeros.\n", __LINE__) ;
948
 
                exit (1) ;
949
 
                } ;
950
 
 
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 ;
955
 
 
956
 
        file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
957
 
 
958
 
        test_write_short_or_die (file, 0, short_out, items, __LINE__) ;
959
 
 
960
 
        sf_close (file) ;
961
 
 
962
 
        memset (short_in, 0, items * sizeof (short)) ;
963
 
 
964
 
        file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
965
 
 
966
 
        if (sfinfo.format != filetype)
967
 
        {       printf ("\n\nLine %d: Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__, filetype, sfinfo.format) ;
968
 
                exit (1) ;
969
 
                } ;
970
 
 
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)) ;
973
 
                exit (1) ;
974
 
                } ;
975
 
 
976
 
        if (sfinfo.channels != 1)
977
 
        {       printf ("\n\nLine %d: Incorrect number of channels in file.\n", __LINE__) ;
978
 
                exit (1) ;
979
 
                } ;
980
 
 
981
 
        check_log_buffer_or_die (file, __LINE__) ;
982
 
 
983
 
        test_read_short_or_die (file, 0, short_in, items, __LINE__) ;
984
 
 
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]) ;
988
 
                        exit (1) ;
989
 
                        } ;
990
 
 
991
 
        sf_close (file) ;
992
 
 
993
 
        /* Finally, check the file hash. */
994
 
        check_file_hash_or_die (filename, hash, __LINE__) ;
995
 
 
996
 
        /*--------------------------------------------------------------------------
997
 
        ** Test sf_read/write_int ()
998
 
        */
999
 
        zero_count = 0 ;
1000
 
 
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 ;
1006
 
                } ;
1007
 
 
1008
 
        if (zero_count > items / 4)
1009
 
        {       printf ("\n\nLine %d: too many zeros.\n", __LINE__) ;
1010
 
                exit (1) ;
1011
 
                } ;
1012
 
 
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 ;
1017
 
 
1018
 
        file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
1019
 
 
1020
 
        test_write_int_or_die (file, 0, int_out, items, __LINE__) ;
1021
 
 
1022
 
        sf_close (file) ;
1023
 
 
1024
 
        memset (int_in, 0, items * sizeof (int)) ;
1025
 
 
1026
 
        file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
1027
 
 
1028
 
        if (sfinfo.format != filetype)
1029
 
        {       printf ("\n\nLine %d: Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__, filetype, sfinfo.format) ;
1030
 
                exit (1) ;
1031
 
                } ;
1032
 
 
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)) ;
1035
 
                exit (1) ;
1036
 
                } ;
1037
 
 
1038
 
        if (sfinfo.channels != 1)
1039
 
        {       printf ("\n\nLine %d: Incorrect number of channels in file.\n", __LINE__) ;
1040
 
                exit (1) ;
1041
 
                } ;
1042
 
 
1043
 
        check_log_buffer_or_die (file, __LINE__) ;
1044
 
 
1045
 
        test_read_int_or_die (file, 0, int_in, items, __LINE__) ;
1046
 
 
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]) ;
1050
 
                        exit (1) ;
1051
 
                        } ;
1052
 
 
1053
 
        sf_close (file) ;
1054
 
 
1055
 
        /* Lite remove start */
1056
 
        /*--------------------------------------------------------------------------
1057
 
        ** Test sf_read/write_float ()
1058
 
        */
1059
 
        zero_count = 0 ;
1060
 
 
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 ;
1066
 
                } ;
1067
 
 
1068
 
        if (zero_count > items / 4)
1069
 
        {       printf ("\n\nLine %d: too many zeros (%d/%d).\n", __LINE__, zero_count, items) ;
1070
 
                exit (1) ;
1071
 
                } ;
1072
 
 
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 ;
1077
 
 
1078
 
        file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
1079
 
 
1080
 
        sf_command (file, SFC_SET_NORM_FLOAT, NULL, SF_FALSE) ;
1081
 
 
1082
 
        test_write_float_or_die (file, 0, float_out, items, __LINE__) ;
1083
 
 
1084
 
        sf_close (file) ;
1085
 
 
1086
 
        memset (float_in, 0, items * sizeof (float)) ;
1087
 
 
1088
 
        file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
1089
 
 
1090
 
        if (sfinfo.format != filetype)
1091
 
        {       printf ("\n\nLine %d: Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__, filetype, sfinfo.format) ;
1092
 
                exit (1) ;
1093
 
                } ;
1094
 
 
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)) ;
1097
 
                exit (1) ;
1098
 
                } ;
1099
 
 
1100
 
        if (sfinfo.channels != 1)
1101
 
        {       printf ("\n\nLine %d: Incorrect number of channels in file.\n", __LINE__) ;
1102
 
                exit (1) ;
1103
 
                } ;
1104
 
 
1105
 
        check_log_buffer_or_die (file, __LINE__) ;
1106
 
 
1107
 
        sf_command (file, SFC_SET_NORM_FLOAT, NULL, SF_FALSE) ;
1108
 
 
1109
 
        test_read_float_or_die (file, 0, float_in, items, __LINE__) ;
1110
 
 
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]) ;
1114
 
                        exit (1) ;
1115
 
                        break ;
1116
 
                        } ;
1117
 
 
1118
 
        sf_close (file) ;
1119
 
 
1120
 
        /*--------------------------------------------------------------------------
1121
 
        ** Test sf_read/write_double ()
1122
 
        */
1123
 
        zero_count = 0 ;
1124
 
 
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 ;
1130
 
                } ;
1131
 
 
1132
 
        if (zero_count > items / 4)
1133
 
        {       printf ("\n\nLine %d: too many zeros (%d/%d).\n", __LINE__, zero_count, items) ;
1134
 
                exit (1) ;
1135
 
                } ;
1136
 
 
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 ;
1141
 
 
1142
 
        file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
1143
 
 
1144
 
        sf_command (file, SFC_SET_NORM_DOUBLE, NULL, SF_FALSE) ;
1145
 
 
1146
 
        test_write_double_or_die (file, 0, double_out, items, __LINE__) ;
1147
 
 
1148
 
        sf_close (file) ;
1149
 
 
1150
 
        memset (double_in, 0, items * sizeof (double)) ;
1151
 
 
1152
 
        file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
1153
 
 
1154
 
        if (sfinfo.format != filetype)
1155
 
        {       printf ("\n\nLine %d: Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__, filetype, sfinfo.format) ;
1156
 
                exit (1) ;
1157
 
                } ;
1158
 
 
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)) ;
1161
 
                exit (1) ;
1162
 
                } ;
1163
 
 
1164
 
        if (sfinfo.channels != 1)
1165
 
        {       printf ("\n\nLine %d: Incorrect number of channels in file.\n", __LINE__) ;
1166
 
                exit (1) ;
1167
 
                } ;
1168
 
 
1169
 
        check_log_buffer_or_die (file, __LINE__) ;
1170
 
 
1171
 
        sf_command (file, SFC_SET_NORM_DOUBLE, NULL, SF_FALSE) ;
1172
 
 
1173
 
        test_read_double_or_die (file, 0, double_in, items, __LINE__) ;
1174
 
 
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]) ;
1178
 
                        exit (1) ;
1179
 
                        } ;
1180
 
 
1181
 
        sf_close (file) ;
1182
 
        /* Lite remove end */
1183
 
        unlink (filename) ;
1184
 
 
1185
 
        puts ("ok") ;
1186
 
} /* pcm_test_bits_32 */
1187
 
 
1188
 
 
1189
 
 
1190
 
/*==============================================================================
1191
 
*/
1192
 
 
1193
 
static void
1194
 
pcm_test_float (const char *filename, int filetype, int hash, int replace_float)
1195
 
{       SNDFILE                 *file ;
1196
 
        SF_INFO                 sfinfo ;
1197
 
        int                             k, items, frames ;
1198
 
        int                             sign ;
1199
 
        double                  *data, error ;
1200
 
 
1201
 
        print_test_name ("pcm_test_float", filename) ;
1202
 
 
1203
 
        items = BUFFER_SIZE / sizeof (double) ;
1204
 
 
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 ;
1209
 
                } ;
1210
 
 
1211
 
        sfinfo.samplerate       = 44100 ;
1212
 
        sfinfo.frames           = items ;
1213
 
        sfinfo.channels         = 1 ;
1214
 
        sfinfo.format           = filetype ;
1215
 
 
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) ;
1221
 
                exit (1) ;
1222
 
                } ;
1223
 
 
1224
 
        test_write_double_or_die (file, 0, data, items, __LINE__) ;
1225
 
 
1226
 
        sf_close (file) ;
1227
 
 
1228
 
        check_file_hash_or_die (filename, hash, __LINE__) ;
1229
 
 
1230
 
        memset (data, 0, items * sizeof (double)) ;
1231
 
 
1232
 
        if ((filetype & SF_FORMAT_TYPEMASK) != SF_FORMAT_RAW)
1233
 
                memset (&sfinfo, 0, sizeof (sfinfo)) ;
1234
 
 
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) ;
1240
 
                exit (1) ;
1241
 
                } ;
1242
 
 
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) ;
1245
 
                exit (1) ;
1246
 
                } ;
1247
 
 
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)) ;
1250
 
                exit (1) ;
1251
 
                } ;
1252
 
 
1253
 
        if (sfinfo.channels != 1)
1254
 
        {       printf ("\n\nError (%s:%d) Mono : Incorrect number of channels in file.\n", __FILE__, __LINE__) ;
1255
 
                exit (1) ;
1256
 
                } ;
1257
 
 
1258
 
        check_log_buffer_or_die (file, __LINE__) ;
1259
 
 
1260
 
        test_read_double_or_die (file, 0, data, items, __LINE__) ;
1261
 
 
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]) ;
1266
 
                        exit (1) ;
1267
 
                        } ;
1268
 
                } ;
1269
 
 
1270
 
        /* Seek to start of file. */
1271
 
        test_seek_or_die (file, 0, SEEK_SET, 0, sfinfo.channels, __LINE__) ;
1272
 
 
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]) ;
1278
 
                        exit (1) ;
1279
 
                        } ;
1280
 
                } ;
1281
 
 
1282
 
        /* Seek to offset from start of file. */
1283
 
        test_seek_or_die (file, 10, SEEK_SET, 10, sfinfo.channels, __LINE__) ;
1284
 
 
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]) ;
1290
 
                        exit (1) ;
1291
 
                        } ;
1292
 
                } ;
1293
 
 
1294
 
        /* Seek to offset from current position. */
1295
 
        test_seek_or_die (file, 6, SEEK_CUR, 20, sfinfo.channels, __LINE__) ;
1296
 
 
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]) ;
1302
 
                        exit (1) ;
1303
 
                        } ;
1304
 
                } ;
1305
 
 
1306
 
        /* Seek to offset from end of file. */
1307
 
        test_seek_or_die (file, -1 * (sfinfo.frames - 10), SEEK_END, 10, sfinfo.channels, __LINE__) ;
1308
 
 
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]) ;
1314
 
                        exit (1) ;
1315
 
                        } ;
1316
 
                } ;
1317
 
 
1318
 
        sf_close (file) ;
1319
 
 
1320
 
        /* Now test Stereo. */
1321
 
 
1322
 
        if ((filetype & SF_FORMAT_TYPEMASK) == SF_FORMAT_SVX) /* SVX is mono only */
1323
 
        {       printf ("ok\n") ;
1324
 
                return ;
1325
 
                } ;
1326
 
 
1327
 
        items = BUFFER_SIZE / sizeof (double) ;
1328
 
 
1329
 
        data = (double*) data_out ;
1330
 
        for (sign = -1, k = 0 ; k < items ; k++)
1331
 
                data [k] = ((double) k) / 100.0 * (sign *= -1) ;
1332
 
 
1333
 
        sfinfo.samplerate       = 44100 ;
1334
 
        sfinfo.frames           = items ;
1335
 
        sfinfo.channels         = 2 ;
1336
 
        sfinfo.format           = filetype ;
1337
 
 
1338
 
        frames = items / sfinfo.channels ;
1339
 
 
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) ;
1345
 
                exit (1) ;
1346
 
                } ;
1347
 
 
1348
 
        test_writef_double_or_die (file, 0, data, frames, __LINE__) ;
1349
 
 
1350
 
        sf_close (file) ;
1351
 
 
1352
 
        check_file_hash_or_die (filename, hash, __LINE__) ;
1353
 
 
1354
 
        memset (data, 0, items * sizeof (double)) ;
1355
 
 
1356
 
        if ((filetype & SF_FORMAT_TYPEMASK) != SF_FORMAT_RAW)
1357
 
                memset (&sfinfo, 0, sizeof (sfinfo)) ;
1358
 
 
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) ;
1364
 
                exit (1) ;
1365
 
                } ;
1366
 
 
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) ;
1369
 
                exit (1) ;
1370
 
                } ;
1371
 
 
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)) ;
1374
 
                exit (1) ;
1375
 
                } ;
1376
 
 
1377
 
        if (sfinfo.channels != 2)
1378
 
        {       printf ("\n\nError (%s:%d) Stereo : Incorrect number of channels in file.\n", __FILE__, __LINE__) ;
1379
 
                exit (1) ;
1380
 
                } ;
1381
 
 
1382
 
        check_log_buffer_or_die (file, __LINE__) ;
1383
 
 
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]) ;
1389
 
                        exit (1) ;
1390
 
                        } ;
1391
 
                } ;
1392
 
 
1393
 
        /* Seek to start of file. */
1394
 
        test_seek_or_die (file, 0, SEEK_SET, 0, sfinfo.channels, __LINE__) ;
1395
 
 
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]) ;
1401
 
                        exit (1) ;
1402
 
                        } ;
1403
 
                } ;
1404
 
 
1405
 
        /* Seek to offset from start of file. */
1406
 
        test_seek_or_die (file, 10, SEEK_SET, 10, sfinfo.channels, __LINE__) ;
1407
 
 
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]) ;
1413
 
                        exit (1) ;
1414
 
                        } ;
1415
 
                } ;
1416
 
 
1417
 
        /* Seek to offset from current position. */
1418
 
        test_seek_or_die (file, 8, SEEK_CUR, 20, sfinfo.channels, __LINE__) ;
1419
 
 
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]) ;
1425
 
                        exit (1) ;
1426
 
                        } ;
1427
 
                } ;
1428
 
 
1429
 
        /* Seek to offset from end of file. */
1430
 
        test_seek_or_die (file, -1 * (sfinfo.frames - 10), SEEK_END, 10, sfinfo.channels, __LINE__) ;
1431
 
 
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]) ;
1437
 
                        exit (1) ;
1438
 
                        } ;
1439
 
                } ;
1440
 
 
1441
 
        sf_close (file) ;
1442
 
 
1443
 
        printf ("ok\n") ;
1444
 
        unlink (filename) ;
1445
 
} /* pcm_test_float */
1446
 
 
1447
 
static void
1448
 
pcm_test_double (const char *filename, int      filetype, int hash, int replace_float)
1449
 
{       SNDFILE                 *file ;
1450
 
        SF_INFO                 sfinfo ;
1451
 
        int                             k, items, frames ;
1452
 
        int                             sign ;
1453
 
        double                  *data, error ;
1454
 
 
1455
 
        /* This is the best test routine. Other should be brought up to this standard. */
1456
 
 
1457
 
        print_test_name ("pcm_test_double", filename) ;
1458
 
 
1459
 
        items = BUFFER_SIZE / sizeof (double) ;
1460
 
 
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 ;
1465
 
                } ;
1466
 
 
1467
 
        sfinfo.samplerate       = 44100 ;
1468
 
        sfinfo.frames           = items ;
1469
 
        sfinfo.channels         = 1 ;
1470
 
        sfinfo.format           = filetype ;
1471
 
 
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) ;
1477
 
                exit (1) ;
1478
 
                } ;
1479
 
 
1480
 
        test_write_double_or_die (file, 0, data, items, __LINE__) ;
1481
 
 
1482
 
        sf_close (file) ;
1483
 
 
1484
 
#if (defined (WIN32) || defined (_WIN32))
1485
 
        /* File hashing on Win32 fails due to slighty different
1486
 
        ** calculated values of the sin() function.
1487
 
        */
1488
 
        hash = hash ; /* Avoid compiler warning. */
1489
 
#else
1490
 
        check_file_hash_or_die (filename, hash, __LINE__) ;
1491
 
#endif
1492
 
 
1493
 
        memset (data, 0, items * sizeof (double)) ;
1494
 
 
1495
 
        if ((filetype & SF_FORMAT_TYPEMASK) != SF_FORMAT_RAW)
1496
 
                memset (&sfinfo, 0, sizeof (sfinfo)) ;
1497
 
 
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) ;
1503
 
                exit (1) ;
1504
 
                } ;
1505
 
 
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) ;
1508
 
                exit (1) ;
1509
 
                } ;
1510
 
 
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)) ;
1513
 
                exit (1) ;
1514
 
                } ;
1515
 
 
1516
 
        if (sfinfo.channels != 1)
1517
 
        {       printf ("\n\nError (%s:%d) Mono : Incorrect number of channels in file.\n", __FILE__, __LINE__) ;
1518
 
                exit (1) ;
1519
 
                } ;
1520
 
 
1521
 
        check_log_buffer_or_die (file, __LINE__) ;
1522
 
 
1523
 
        test_read_double_or_die (file, 0, data, items, __LINE__) ;
1524
 
 
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]) ;
1529
 
                        exit (1) ;
1530
 
                        } ;
1531
 
                } ;
1532
 
 
1533
 
        /* Seek to start of file. */
1534
 
        test_seek_or_die (file, 0, SEEK_SET, 0, sfinfo.channels, __LINE__) ;
1535
 
 
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]) ;
1541
 
                        exit (1) ;
1542
 
                        } ;
1543
 
                } ;
1544
 
 
1545
 
        /* Seek to offset from start of file. */
1546
 
        test_seek_or_die (file, 10, SEEK_SET, 10, sfinfo.channels, __LINE__) ;
1547
 
 
1548
 
        test_read_double_or_die (file, 0, data + 10, 4, __LINE__) ;
1549
 
 
1550
 
        test_seek_or_die (file, 0, SEEK_CUR, 14, sfinfo.channels, __LINE__) ;
1551
 
 
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]) ;
1556
 
                        exit (1) ;
1557
 
                        } ;
1558
 
                } ;
1559
 
 
1560
 
        /* Seek to offset from current position. */
1561
 
        test_seek_or_die (file, 6, SEEK_CUR, 20, sfinfo.channels, __LINE__) ;
1562
 
 
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]) ;
1568
 
                        exit (1) ;
1569
 
                        } ;
1570
 
                } ;
1571
 
 
1572
 
        /* Seek to offset from end of file. */
1573
 
        test_seek_or_die (file, -1 * (sfinfo.frames - 10), SEEK_END, 10, sfinfo.channels, __LINE__) ;
1574
 
 
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]) ;
1580
 
                        exit (1) ;
1581
 
                        } ;
1582
 
                } ;
1583
 
 
1584
 
        sf_close (file) ;
1585
 
 
1586
 
        /* Now test Stereo. */
1587
 
 
1588
 
        if ((filetype & SF_FORMAT_TYPEMASK) == SF_FORMAT_SVX) /* SVX is mono only */
1589
 
        {       printf ("ok\n") ;
1590
 
                return ;
1591
 
                } ;
1592
 
 
1593
 
        items = BUFFER_SIZE / sizeof (double) ;
1594
 
 
1595
 
        data = (double*) data_out ;
1596
 
        for (sign = -1, k = 0 ; k < items ; k++)
1597
 
                data [k] = ((double) k) / 100.0 * (sign *= -1) ;
1598
 
 
1599
 
        sfinfo.samplerate       = 44100 ;
1600
 
        sfinfo.frames           = items ;
1601
 
        sfinfo.channels         = 2 ;
1602
 
        sfinfo.format           = filetype ;
1603
 
 
1604
 
        frames = items / sfinfo.channels ;
1605
 
 
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) ;
1611
 
                exit (1) ;
1612
 
                } ;
1613
 
 
1614
 
        test_writef_double_or_die (file, 0, data, frames, __LINE__) ;
1615
 
 
1616
 
        sf_close (file) ;
1617
 
 
1618
 
#if (defined (WIN32) || defined (_WIN32))
1619
 
        /* File hashing on Win32 fails due to slighty different
1620
 
        ** calculated values.
1621
 
        */
1622
 
        hash = hash ; /* Avoid compiler warning. */
1623
 
#else
1624
 
        check_file_hash_or_die (filename, hash, __LINE__) ;
1625
 
#endif
1626
 
 
1627
 
        memset (data, 0, items * sizeof (double)) ;
1628
 
 
1629
 
        if ((filetype & SF_FORMAT_TYPEMASK) != SF_FORMAT_RAW)
1630
 
                memset (&sfinfo, 0, sizeof (sfinfo)) ;
1631
 
 
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) ;
1637
 
                exit (1) ;
1638
 
                } ;
1639
 
 
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) ;
1642
 
                exit (1) ;
1643
 
                } ;
1644
 
 
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)) ;
1647
 
                exit (1) ;
1648
 
                } ;
1649
 
 
1650
 
        if (sfinfo.channels != 2)
1651
 
        {       printf ("\n\nError (%s:%d) Stereo : Incorrect number of channels in file.\n", __FILE__, __LINE__) ;
1652
 
                exit (1) ;
1653
 
                } ;
1654
 
 
1655
 
        check_log_buffer_or_die (file, __LINE__) ;
1656
 
 
1657
 
        test_readf_double_or_die (file, 0, data, frames, __LINE__) ;
1658
 
 
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]) ;
1663
 
                        exit (1) ;
1664
 
                        } ;
1665
 
                } ;
1666
 
 
1667
 
        /* Seek to start of file. */
1668
 
        test_seek_or_die (file, 0, SEEK_SET, 0, sfinfo.channels, __LINE__) ;
1669
 
 
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]) ;
1675
 
                        exit (1) ;
1676
 
                        } ;
1677
 
                } ;
1678
 
 
1679
 
        /* Seek to offset from start of file. */
1680
 
        test_seek_or_die (file, 10, SEEK_SET, 10, sfinfo.channels, __LINE__) ;
1681
 
 
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]) ;
1687
 
                        exit (1) ;
1688
 
                        } ;
1689
 
                } ;
1690
 
 
1691
 
        /* Seek to offset from current position. */
1692
 
        test_seek_or_die (file, 8, SEEK_CUR, 20, sfinfo.channels, __LINE__) ;
1693
 
 
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]) ;
1699
 
                        exit (1) ;
1700
 
                        } ;
1701
 
                } ;
1702
 
 
1703
 
        /* Seek to offset from end of file. */
1704
 
        test_seek_or_die (file, -1 * (sfinfo.frames -10), SEEK_END, 10, sfinfo.channels, __LINE__) ;
1705
 
 
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]) ;
1711
 
                        exit (1) ;
1712
 
                        } ;
1713
 
                } ;
1714
 
 
1715
 
        sf_close (file) ;
1716
 
 
1717
 
        printf ("ok\n") ;
1718
 
        unlink (filename) ;
1719
 
} /* pcm_test_double */
1720
 
 
1721
 
/*==============================================================================
1722
 
*/
1723
 
 
1724