Chris@0
|
1 [+ AutoGen5 template c +]
|
Chris@0
|
2 /*
|
Chris@0
|
3 ** Copyright (C) 1999-2011 Erik de Castro Lopo <erikd@mega-nerd.com>
|
Chris@0
|
4 **
|
Chris@0
|
5 ** This program is free software; you can redistribute it and/or modify
|
Chris@0
|
6 ** it under the terms of the GNU General Public License as published by
|
Chris@0
|
7 ** the Free Software Foundation; either version 2 of the License, or
|
Chris@0
|
8 ** (at your option) any later version.
|
Chris@0
|
9 **
|
Chris@0
|
10 ** This program is distributed in the hope that it will be useful,
|
Chris@0
|
11 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
Chris@0
|
12 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
Chris@0
|
13 ** GNU General Public License for more details.
|
Chris@0
|
14 **
|
Chris@0
|
15 ** You should have received a copy of the GNU General Public License
|
Chris@0
|
16 ** along with this program; if not, write to the Free Software
|
Chris@0
|
17 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
Chris@0
|
18 */
|
Chris@0
|
19
|
Chris@0
|
20 #include "sfconfig.h"
|
Chris@0
|
21
|
Chris@0
|
22 #include <stdio.h>
|
Chris@0
|
23 #include <stdlib.h>
|
Chris@0
|
24 #include <string.h>
|
Chris@0
|
25 #include <math.h>
|
Chris@0
|
26
|
Chris@0
|
27 #if HAVE_UNISTD_H
|
Chris@0
|
28 #include <unistd.h>
|
Chris@0
|
29 #endif
|
Chris@0
|
30
|
Chris@0
|
31 #include <sndfile.h>
|
Chris@0
|
32
|
Chris@0
|
33 #include "utils.h"
|
Chris@0
|
34
|
Chris@0
|
35 #define BUFFER_SIZE (1<<12)
|
Chris@0
|
36
|
Chris@0
|
37 static void lrintf_test (void) ;
|
Chris@0
|
38
|
Chris@0
|
39 [+ FOR data_type
|
Chris@0
|
40 +]static void pcm_test_[+ (get "name") +] (const char *filename, int filetype, uint64_t hash) ;
|
Chris@0
|
41 [+ ENDFOR data_type
|
Chris@0
|
42 +]
|
Chris@0
|
43 static void pcm_test_float (const char *filename, int filetype, uint64_t hash, int replace_float) ;
|
Chris@0
|
44 static void pcm_test_double (const char *filename, int filetype, uint64_t hash, int replace_float) ;
|
Chris@0
|
45
|
Chris@0
|
46 typedef union
|
Chris@0
|
47 { double d [BUFFER_SIZE + 1] ;
|
Chris@0
|
48 float f [BUFFER_SIZE + 1] ;
|
Chris@0
|
49 int i [BUFFER_SIZE + 1] ;
|
Chris@0
|
50 short s [BUFFER_SIZE + 1] ;
|
Chris@0
|
51 } BUFFER ;
|
Chris@0
|
52
|
Chris@0
|
53 /* Data written to the file. */
|
Chris@0
|
54 static BUFFER data_out ;
|
Chris@0
|
55
|
Chris@0
|
56 /* Data read back from the file. */
|
Chris@0
|
57 static BUFFER data_in ;
|
Chris@0
|
58
|
Chris@0
|
59 int
|
Chris@0
|
60 main (void)
|
Chris@0
|
61 {
|
Chris@0
|
62 lrintf_test () ;
|
Chris@0
|
63
|
Chris@0
|
64 pcm_test_bits_8 ("pcm-s8.raw", SF_FORMAT_RAW | SF_FORMAT_PCM_S8, 0x1cda335091249dbfLL) ;
|
Chris@0
|
65 pcm_test_bits_8 ("pcm-u8.raw", SF_FORMAT_RAW | SF_FORMAT_PCM_U8, 0x7f748c433d695f3fLL) ;
|
Chris@0
|
66
|
Chris@0
|
67 pcm_test_bits_16 ("le-pcm16.raw", SF_ENDIAN_LITTLE | SF_FORMAT_RAW | SF_FORMAT_PCM_16, 0x3a2b956c881ebf08LL) ;
|
Chris@0
|
68 pcm_test_bits_16 ("be-pcm16.raw", SF_ENDIAN_BIG | SF_FORMAT_RAW | SF_FORMAT_PCM_16, 0xd9e2f840c55750f8LL) ;
|
Chris@0
|
69
|
Chris@0
|
70 pcm_test_bits_24 ("le-pcm24.raw", SF_ENDIAN_LITTLE | SF_FORMAT_RAW | SF_FORMAT_PCM_24, 0x933b6a759ab496f8LL) ;
|
Chris@0
|
71 pcm_test_bits_24 ("be-pcm24.raw", SF_ENDIAN_BIG | SF_FORMAT_RAW | SF_FORMAT_PCM_24, 0xbb1f3eaf9c30b6f8LL) ;
|
Chris@0
|
72
|
Chris@0
|
73 pcm_test_bits_32 ("le-pcm32.raw", SF_ENDIAN_LITTLE | SF_FORMAT_RAW | SF_FORMAT_PCM_32, 0xa77aece1c1c17f08LL) ;
|
Chris@0
|
74 pcm_test_bits_32 ("be-pcm32.raw", SF_ENDIAN_BIG | SF_FORMAT_RAW | SF_FORMAT_PCM_32, 0x3099ddf142d0b0f8LL) ;
|
Chris@0
|
75
|
Chris@0
|
76 /* Lite remove start */
|
Chris@0
|
77 pcm_test_float ("le-float.raw", SF_ENDIAN_LITTLE | SF_FORMAT_RAW | SF_FORMAT_FLOAT, 0x3c2ad04f7554267aLL, SF_FALSE) ;
|
Chris@0
|
78 pcm_test_float ("be-float.raw", SF_ENDIAN_BIG | SF_FORMAT_RAW | SF_FORMAT_FLOAT, 0x074de3e248fa9186LL, SF_FALSE) ;
|
Chris@0
|
79
|
Chris@0
|
80 pcm_test_double ("le-double.raw", SF_ENDIAN_LITTLE | SF_FORMAT_RAW | SF_FORMAT_DOUBLE, 0xc682726f958f669cLL, SF_FALSE) ;
|
Chris@0
|
81 pcm_test_double ("be-double.raw", SF_ENDIAN_BIG | SF_FORMAT_RAW | SF_FORMAT_DOUBLE, 0xd9a3583f8ee51164LL, SF_FALSE) ;
|
Chris@0
|
82
|
Chris@0
|
83 pcm_test_float ("le-float.raw", SF_ENDIAN_LITTLE | SF_FORMAT_RAW | SF_FORMAT_FLOAT, 0x3c2ad04f7554267aLL, SF_TRUE) ;
|
Chris@0
|
84 pcm_test_float ("be-float.raw", SF_ENDIAN_BIG | SF_FORMAT_RAW | SF_FORMAT_FLOAT, 0x074de3e248fa9186LL, SF_TRUE) ;
|
Chris@0
|
85
|
Chris@0
|
86 pcm_test_double ("le-double.raw", SF_ENDIAN_LITTLE | SF_FORMAT_RAW | SF_FORMAT_DOUBLE, 0xc682726f958f669cLL, SF_TRUE) ;
|
Chris@0
|
87 pcm_test_double ("be-double.raw", SF_ENDIAN_BIG | SF_FORMAT_RAW | SF_FORMAT_DOUBLE, 0xd9a3583f8ee51164LL, SF_TRUE) ;
|
Chris@0
|
88 /* Lite remove end */
|
Chris@0
|
89
|
Chris@0
|
90 return 0 ;
|
Chris@0
|
91 } /* main */
|
Chris@0
|
92
|
Chris@0
|
93 /*============================================================================================
|
Chris@0
|
94 ** Here are the test functions.
|
Chris@0
|
95 */
|
Chris@0
|
96
|
Chris@0
|
97 static void
|
Chris@0
|
98 lrintf_test (void)
|
Chris@0
|
99 { int k, items ;
|
Chris@0
|
100 float *float_data ;
|
Chris@0
|
101 int *int_data ;
|
Chris@0
|
102
|
Chris@0
|
103 print_test_name ("lrintf_test", "") ;
|
Chris@0
|
104
|
Chris@0
|
105 items = 1024 ;
|
Chris@0
|
106
|
Chris@0
|
107 float_data = data_out.f ;
|
Chris@0
|
108 int_data = data_in.i ;
|
Chris@0
|
109
|
Chris@0
|
110 for (k = 0 ; k < items ; k++)
|
Chris@0
|
111 float_data [k] = (k * ((k % 2) ? 333333.0 : -333333.0)) ;
|
Chris@0
|
112
|
Chris@0
|
113 for (k = 0 ; k < items ; k++)
|
Chris@0
|
114 int_data [k] = lrintf (float_data [k]) ;
|
Chris@0
|
115
|
Chris@0
|
116 for (k = 0 ; k < items ; k++)
|
Chris@0
|
117 if (fabs (int_data [k] - float_data [k]) > 1.0)
|
Chris@0
|
118 { printf ("\n\nLine %d: float : Incorrect sample (#%d : %f => %d).\n", __LINE__, k, float_data [k], int_data [k]) ;
|
Chris@0
|
119 exit (1) ;
|
Chris@0
|
120 } ;
|
Chris@0
|
121
|
Chris@0
|
122 printf ("ok\n") ;
|
Chris@0
|
123 } /* lrintf_test */
|
Chris@0
|
124
|
Chris@0
|
125 [+ FOR data_type
|
Chris@0
|
126 +]static void
|
Chris@0
|
127 pcm_test_[+ (get "name") +] (const char *filename, int filetype, uint64_t hash)
|
Chris@0
|
128 { SNDFILE *file ;
|
Chris@0
|
129 SF_INFO sfinfo ;
|
Chris@0
|
130 int k, items, zero_count ;
|
Chris@0
|
131 short *short_out, *short_in ;
|
Chris@0
|
132 int *int_out, *int_in ;
|
Chris@0
|
133 /* Lite remove start */
|
Chris@0
|
134 float *float_out, *float_in ;
|
Chris@0
|
135 double *double_out, *double_in ;
|
Chris@0
|
136 /* Lite remove end */
|
Chris@0
|
137
|
Chris@0
|
138 print_test_name ("pcm_test_[+ (get "name") +]", filename) ;
|
Chris@0
|
139
|
Chris@0
|
140 items = [+ (get "item_count") +] ;
|
Chris@0
|
141
|
Chris@0
|
142 short_out = data_out.s ;
|
Chris@0
|
143 short_in = data_in.s ;
|
Chris@0
|
144
|
Chris@0
|
145 zero_count = 0 ;
|
Chris@0
|
146 for (k = 0 ; k < items ; k++)
|
Chris@0
|
147 { short_out [k] = [+ (get "short_func") +] ;
|
Chris@0
|
148 zero_count = short_out [k] ? zero_count : zero_count + 1 ;
|
Chris@0
|
149 } ;
|
Chris@0
|
150
|
Chris@0
|
151 if (zero_count > items / 4)
|
Chris@0
|
152 { printf ("\n\nLine %d: too many zeros.\n", __LINE__) ;
|
Chris@0
|
153 exit (1) ;
|
Chris@0
|
154 } ;
|
Chris@0
|
155
|
Chris@0
|
156 sfinfo.samplerate = 44100 ;
|
Chris@0
|
157 sfinfo.frames = 123456789 ; /* Wrong length. Library should correct this on sf_close. */
|
Chris@0
|
158 sfinfo.channels = 1 ;
|
Chris@0
|
159 sfinfo.format = filetype ;
|
Chris@0
|
160
|
Chris@0
|
161 file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
|
Chris@0
|
162
|
Chris@0
|
163 test_write_short_or_die (file, 0, short_out, items, __LINE__) ;
|
Chris@0
|
164
|
Chris@0
|
165 sf_close (file) ;
|
Chris@0
|
166
|
Chris@0
|
167 memset (short_in, 0, items * sizeof (short)) ;
|
Chris@0
|
168
|
Chris@0
|
169 file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
|
Chris@0
|
170
|
Chris@0
|
171 if (sfinfo.format != filetype)
|
Chris@0
|
172 { printf ("\n\nLine %d: Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__, filetype, sfinfo.format) ;
|
Chris@0
|
173 exit (1) ;
|
Chris@0
|
174 } ;
|
Chris@0
|
175
|
Chris@0
|
176 if (sfinfo.frames != items)
|
Chris@0
|
177 { printf ("\n\nLine %d: Incorrect number of frames in file. (%d => %ld)\n", __LINE__, items, SF_COUNT_TO_LONG (sfinfo.frames)) ;
|
Chris@0
|
178 exit (1) ;
|
Chris@0
|
179 } ;
|
Chris@0
|
180
|
Chris@0
|
181 if (sfinfo.channels != 1)
|
Chris@0
|
182 { printf ("\n\nLine %d: Incorrect number of channels in file.\n", __LINE__) ;
|
Chris@0
|
183 exit (1) ;
|
Chris@0
|
184 } ;
|
Chris@0
|
185
|
Chris@0
|
186 check_log_buffer_or_die (file, __LINE__) ;
|
Chris@0
|
187
|
Chris@0
|
188 test_read_short_or_die (file, 0, short_in, items, __LINE__) ;
|
Chris@0
|
189
|
Chris@0
|
190 for (k = 0 ; k < items ; k++)
|
Chris@0
|
191 if (short_out [k] != short_in [k])
|
Chris@0
|
192 { printf ("\n\nLine %d: Incorrect sample (#%d : 0x%x => 0x%x).\n", __LINE__, k, short_out [k], short_in [k]) ;
|
Chris@0
|
193 exit (1) ;
|
Chris@0
|
194 } ;
|
Chris@0
|
195
|
Chris@0
|
196 sf_close (file) ;
|
Chris@0
|
197
|
Chris@0
|
198 /* Finally, check the file hash. */
|
Chris@0
|
199 check_file_hash_or_die (filename, hash, __LINE__) ;
|
Chris@0
|
200
|
Chris@0
|
201 /*--------------------------------------------------------------------------
|
Chris@0
|
202 ** Test sf_read/write_int ()
|
Chris@0
|
203 */
|
Chris@0
|
204 zero_count = 0 ;
|
Chris@0
|
205
|
Chris@0
|
206 int_out = data_out.i ;
|
Chris@0
|
207 int_in = data_in.i ;
|
Chris@0
|
208 for (k = 0 ; k < items ; k++)
|
Chris@0
|
209 { int_out [k] = [+ (get "int_func") +] ;
|
Chris@0
|
210 zero_count = int_out [k] ? zero_count : zero_count + 1 ;
|
Chris@0
|
211 } ;
|
Chris@0
|
212
|
Chris@0
|
213 if (zero_count > items / 4)
|
Chris@0
|
214 { printf ("\n\nLine %d: too many zeros.\n", __LINE__) ;
|
Chris@0
|
215 exit (1) ;
|
Chris@0
|
216 } ;
|
Chris@0
|
217
|
Chris@0
|
218 sfinfo.samplerate = 44100 ;
|
Chris@0
|
219 sfinfo.frames = 123456789 ; /* Wrong length. Library should correct this on sf_close. */
|
Chris@0
|
220 sfinfo.channels = 1 ;
|
Chris@0
|
221 sfinfo.format = filetype ;
|
Chris@0
|
222
|
Chris@0
|
223 file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
|
Chris@0
|
224
|
Chris@0
|
225 test_write_int_or_die (file, 0, int_out, items, __LINE__) ;
|
Chris@0
|
226
|
Chris@0
|
227 sf_close (file) ;
|
Chris@0
|
228
|
Chris@0
|
229 memset (int_in, 0, items * sizeof (int)) ;
|
Chris@0
|
230
|
Chris@0
|
231 file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
|
Chris@0
|
232
|
Chris@0
|
233 if (sfinfo.format != filetype)
|
Chris@0
|
234 { printf ("\n\nLine %d: Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__, filetype, sfinfo.format) ;
|
Chris@0
|
235 exit (1) ;
|
Chris@0
|
236 } ;
|
Chris@0
|
237
|
Chris@0
|
238 if (sfinfo.frames != items)
|
Chris@0
|
239 { printf ("\n\nLine %d: Incorrect number of frames in file. (%d => %ld)\n", __LINE__, items, SF_COUNT_TO_LONG (sfinfo.frames)) ;
|
Chris@0
|
240 exit (1) ;
|
Chris@0
|
241 } ;
|
Chris@0
|
242
|
Chris@0
|
243 if (sfinfo.channels != 1)
|
Chris@0
|
244 { printf ("\n\nLine %d: Incorrect number of channels in file.\n", __LINE__) ;
|
Chris@0
|
245 exit (1) ;
|
Chris@0
|
246 } ;
|
Chris@0
|
247
|
Chris@0
|
248 check_log_buffer_or_die (file, __LINE__) ;
|
Chris@0
|
249
|
Chris@0
|
250 test_read_int_or_die (file, 0, int_in, items, __LINE__) ;
|
Chris@0
|
251
|
Chris@0
|
252 for (k = 0 ; k < items ; k++)
|
Chris@0
|
253 if (int_out [k] != int_in [k])
|
Chris@0
|
254 { printf ("\n\nLine %d: int : Incorrect sample (#%d : 0x%x => 0x%x).\n", __LINE__, k, int_out [k], int_in [k]) ;
|
Chris@0
|
255 exit (1) ;
|
Chris@0
|
256 } ;
|
Chris@0
|
257
|
Chris@0
|
258 sf_close (file) ;
|
Chris@0
|
259
|
Chris@0
|
260 /* Lite remove start */
|
Chris@0
|
261 /*--------------------------------------------------------------------------
|
Chris@0
|
262 ** Test sf_read/write_float ()
|
Chris@0
|
263 */
|
Chris@0
|
264 zero_count = 0 ;
|
Chris@0
|
265
|
Chris@0
|
266 float_out = data_out.f ;
|
Chris@0
|
267 float_in = data_in.f ;
|
Chris@0
|
268 for (k = 0 ; k < items ; k++)
|
Chris@0
|
269 { float_out [k] = [+ (get "float_func") +] ;
|
Chris@0
|
270 zero_count = (fabs (float_out [k]) > 1e-10) ? zero_count : zero_count + 1 ;
|
Chris@0
|
271 } ;
|
Chris@0
|
272
|
Chris@0
|
273 if (zero_count > items / 4)
|
Chris@0
|
274 { printf ("\n\nLine %d: too many zeros (%d/%d).\n", __LINE__, zero_count, items) ;
|
Chris@0
|
275 exit (1) ;
|
Chris@0
|
276 } ;
|
Chris@0
|
277
|
Chris@0
|
278 sfinfo.samplerate = 44100 ;
|
Chris@0
|
279 sfinfo.frames = 123456789 ; /* Wrong length. Library should correct this on sf_close. */
|
Chris@0
|
280 sfinfo.channels = 1 ;
|
Chris@0
|
281 sfinfo.format = filetype ;
|
Chris@0
|
282
|
Chris@0
|
283 file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
|
Chris@0
|
284
|
Chris@0
|
285 sf_command (file, SFC_SET_NORM_FLOAT, NULL, SF_FALSE) ;
|
Chris@0
|
286
|
Chris@0
|
287 test_write_float_or_die (file, 0, float_out, items, __LINE__) ;
|
Chris@0
|
288
|
Chris@0
|
289 sf_close (file) ;
|
Chris@0
|
290
|
Chris@0
|
291 memset (float_in, 0, items * sizeof (float)) ;
|
Chris@0
|
292
|
Chris@0
|
293 file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
|
Chris@0
|
294
|
Chris@0
|
295 if (sfinfo.format != filetype)
|
Chris@0
|
296 { printf ("\n\nLine %d: Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__, filetype, sfinfo.format) ;
|
Chris@0
|
297 exit (1) ;
|
Chris@0
|
298 } ;
|
Chris@0
|
299
|
Chris@0
|
300 if (sfinfo.frames != items)
|
Chris@0
|
301 { printf ("\n\nLine %d: Incorrect number of frames in file. (%d => %ld)\n", __LINE__, items, SF_COUNT_TO_LONG (sfinfo.frames)) ;
|
Chris@0
|
302 exit (1) ;
|
Chris@0
|
303 } ;
|
Chris@0
|
304
|
Chris@0
|
305 if (sfinfo.channels != 1)
|
Chris@0
|
306 { printf ("\n\nLine %d: Incorrect number of channels in file.\n", __LINE__) ;
|
Chris@0
|
307 exit (1) ;
|
Chris@0
|
308 } ;
|
Chris@0
|
309
|
Chris@0
|
310 check_log_buffer_or_die (file, __LINE__) ;
|
Chris@0
|
311
|
Chris@0
|
312 sf_command (file, SFC_SET_NORM_FLOAT, NULL, SF_FALSE) ;
|
Chris@0
|
313
|
Chris@0
|
314 test_read_float_or_die (file, 0, float_in, items, __LINE__) ;
|
Chris@0
|
315
|
Chris@0
|
316 for (k = 0 ; k < items ; k++)
|
Chris@0
|
317 if (fabs (float_out [k] - float_in [k]) > 1e-10)
|
Chris@0
|
318 { printf ("\n\nLine %d: float : Incorrect sample (#%d : %f => %f).\n", __LINE__, k, (double) float_out [k], (double) float_in [k]) ;
|
Chris@0
|
319 exit (1) ;
|
Chris@0
|
320 } ;
|
Chris@0
|
321
|
Chris@0
|
322 sf_close (file) ;
|
Chris@0
|
323
|
Chris@0
|
324 /*--------------------------------------------------------------------------
|
Chris@0
|
325 ** Test sf_read/write_double ()
|
Chris@0
|
326 */
|
Chris@0
|
327 zero_count = 0 ;
|
Chris@0
|
328
|
Chris@0
|
329 double_out = data_out.d ;
|
Chris@0
|
330 double_in = data_in.d ;
|
Chris@0
|
331 for (k = 0 ; k < items ; k++)
|
Chris@0
|
332 { double_out [k] = [+ (get "float_func") +] ;
|
Chris@0
|
333 zero_count = (fabs (double_out [k]) > 1e-10) ? zero_count : zero_count + 1 ;
|
Chris@0
|
334 } ;
|
Chris@0
|
335
|
Chris@0
|
336 if (zero_count > items / 4)
|
Chris@0
|
337 { printf ("\n\nLine %d: too many zeros (%d/%d).\n", __LINE__, zero_count, items) ;
|
Chris@0
|
338 exit (1) ;
|
Chris@0
|
339 } ;
|
Chris@0
|
340
|
Chris@0
|
341 sfinfo.samplerate = 44100 ;
|
Chris@0
|
342 sfinfo.frames = 123456789 ; /* Wrong length. Library should correct this on sf_close. */
|
Chris@0
|
343 sfinfo.channels = 1 ;
|
Chris@0
|
344 sfinfo.format = filetype ;
|
Chris@0
|
345
|
Chris@0
|
346 file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
|
Chris@0
|
347
|
Chris@0
|
348 sf_command (file, SFC_SET_NORM_DOUBLE, NULL, SF_FALSE) ;
|
Chris@0
|
349
|
Chris@0
|
350 test_write_double_or_die (file, 0, double_out, items, __LINE__) ;
|
Chris@0
|
351
|
Chris@0
|
352 sf_close (file) ;
|
Chris@0
|
353
|
Chris@0
|
354 memset (double_in, 0, items * sizeof (double)) ;
|
Chris@0
|
355
|
Chris@0
|
356 file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
|
Chris@0
|
357
|
Chris@0
|
358 if (sfinfo.format != filetype)
|
Chris@0
|
359 { printf ("\n\nLine %d: Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__, filetype, sfinfo.format) ;
|
Chris@0
|
360 exit (1) ;
|
Chris@0
|
361 } ;
|
Chris@0
|
362
|
Chris@0
|
363 if (sfinfo.frames != items)
|
Chris@0
|
364 { printf ("\n\nLine %d: Incorrect number of frames in file. (%d => %ld)\n", __LINE__, items, SF_COUNT_TO_LONG (sfinfo.frames)) ;
|
Chris@0
|
365 exit (1) ;
|
Chris@0
|
366 } ;
|
Chris@0
|
367
|
Chris@0
|
368 if (sfinfo.channels != 1)
|
Chris@0
|
369 { printf ("\n\nLine %d: Incorrect number of channels in file.\n", __LINE__) ;
|
Chris@0
|
370 exit (1) ;
|
Chris@0
|
371 } ;
|
Chris@0
|
372
|
Chris@0
|
373 check_log_buffer_or_die (file, __LINE__) ;
|
Chris@0
|
374
|
Chris@0
|
375 sf_command (file, SFC_SET_NORM_DOUBLE, NULL, SF_FALSE) ;
|
Chris@0
|
376
|
Chris@0
|
377 test_read_double_or_die (file, 0, double_in, items, __LINE__) ;
|
Chris@0
|
378
|
Chris@0
|
379 for (k = 0 ; k < items ; k++)
|
Chris@0
|
380 if (fabs (double_out [k] - double_in [k]) > 1e-10)
|
Chris@0
|
381 { printf ("\n\nLine %d: double : Incorrect sample (#%d : %f => %f).\n", __LINE__, k, double_out [k], double_in [k]) ;
|
Chris@0
|
382 exit (1) ;
|
Chris@0
|
383 } ;
|
Chris@0
|
384
|
Chris@0
|
385 sf_close (file) ;
|
Chris@0
|
386 /* Lite remove end */
|
Chris@0
|
387 unlink (filename) ;
|
Chris@0
|
388
|
Chris@0
|
389 puts ("ok") ;
|
Chris@0
|
390 } /* pcm_test_[+ (get "name") +] */
|
Chris@0
|
391
|
Chris@0
|
392 [+ ENDFOR data_type
|
Chris@0
|
393 +]
|
Chris@0
|
394
|
Chris@0
|
395 /*==============================================================================
|
Chris@0
|
396 */
|
Chris@0
|
397
|
Chris@0
|
398 static void
|
Chris@0
|
399 pcm_test_float (const char *filename, int filetype, uint64_t hash, int replace_float)
|
Chris@0
|
400 { SNDFILE *file ;
|
Chris@0
|
401 SF_INFO sfinfo ;
|
Chris@0
|
402 int k, items, frames ;
|
Chris@0
|
403 int sign ;
|
Chris@0
|
404 double *data, error ;
|
Chris@0
|
405
|
Chris@0
|
406 print_test_name (replace_float ? "pcm_test_float (replace)" : "pcm_test_float", filename) ;
|
Chris@0
|
407
|
Chris@0
|
408 items = BUFFER_SIZE ;
|
Chris@0
|
409
|
Chris@0
|
410 data = data_out.d ;
|
Chris@0
|
411 for (sign = 1, k = 0 ; k < items ; k++)
|
Chris@0
|
412 { data [k] = ((double) (k * sign)) / 100.0 ;
|
Chris@0
|
413 sign = (sign > 0) ? -1 : 1 ;
|
Chris@0
|
414 } ;
|
Chris@0
|
415
|
Chris@0
|
416 sfinfo.samplerate = 44100 ;
|
Chris@0
|
417 sfinfo.frames = items ;
|
Chris@0
|
418 sfinfo.channels = 1 ;
|
Chris@0
|
419 sfinfo.format = filetype ;
|
Chris@0
|
420
|
Chris@0
|
421 file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
|
Chris@0
|
422 sf_command (file, SFC_TEST_IEEE_FLOAT_REPLACE, NULL, replace_float) ;
|
Chris@0
|
423 if (replace_float && string_in_log_buffer (file, "Using IEEE replacement") == 0)
|
Chris@0
|
424 { printf ("\n\nLine %d : Float replacement code not working.\n\n", __LINE__) ;
|
Chris@0
|
425 dump_log_buffer (file) ;
|
Chris@0
|
426 exit (1) ;
|
Chris@0
|
427 } ;
|
Chris@0
|
428
|
Chris@0
|
429 test_write_double_or_die (file, 0, data, items, __LINE__) ;
|
Chris@0
|
430
|
Chris@0
|
431 sf_close (file) ;
|
Chris@0
|
432
|
Chris@0
|
433 check_file_hash_or_die (filename, hash, __LINE__) ;
|
Chris@0
|
434
|
Chris@0
|
435 memset (data, 0, items * sizeof (double)) ;
|
Chris@0
|
436
|
Chris@0
|
437 if ((filetype & SF_FORMAT_TYPEMASK) != SF_FORMAT_RAW)
|
Chris@0
|
438 memset (&sfinfo, 0, sizeof (sfinfo)) ;
|
Chris@0
|
439
|
Chris@0
|
440 file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
|
Chris@0
|
441 sf_command (file, SFC_TEST_IEEE_FLOAT_REPLACE, NULL, replace_float) ;
|
Chris@0
|
442 if (replace_float && string_in_log_buffer (file, "Using IEEE replacement") == 0)
|
Chris@0
|
443 { printf ("\n\nLine %d : Float replacement code not working.\n\n", __LINE__) ;
|
Chris@0
|
444 dump_log_buffer (file) ;
|
Chris@0
|
445 exit (1) ;
|
Chris@0
|
446 } ;
|
Chris@0
|
447
|
Chris@0
|
448 if (sfinfo.format != filetype)
|
Chris@0
|
449 { printf ("\n\nError (%s:%d) Mono : Returned format incorrect (0x%08X => 0x%08X).\n", __FILE__, __LINE__, filetype, sfinfo.format) ;
|
Chris@0
|
450 exit (1) ;
|
Chris@0
|
451 } ;
|
Chris@0
|
452
|
Chris@0
|
453 if (sfinfo.frames != items)
|
Chris@0
|
454 { printf ("\n\nError (%s:%d) Mono : Incorrect number of frames in file. (%d => %ld)\n", __FILE__, __LINE__, items, SF_COUNT_TO_LONG (sfinfo.frames)) ;
|
Chris@0
|
455 exit (1) ;
|
Chris@0
|
456 } ;
|
Chris@0
|
457
|
Chris@0
|
458 if (sfinfo.channels != 1)
|
Chris@0
|
459 { printf ("\n\nError (%s:%d) Mono : Incorrect number of channels in file.\n", __FILE__, __LINE__) ;
|
Chris@0
|
460 exit (1) ;
|
Chris@0
|
461 } ;
|
Chris@0
|
462
|
Chris@0
|
463 check_log_buffer_or_die (file, __LINE__) ;
|
Chris@0
|
464
|
Chris@0
|
465 test_read_double_or_die (file, 0, data, items, __LINE__) ;
|
Chris@0
|
466
|
Chris@0
|
467 for (sign = -1, k = 0 ; k < items ; k++)
|
Chris@0
|
468 { error = fabs (data [k] - ((double) k) / 100.0 * (sign *= -1)) ;
|
Chris@0
|
469 if (fabs (data [k]) > 1e-100 && fabs (error / data [k]) > 1e-5)
|
Chris@0
|
470 { printf ("\n\nError (%s:%d) Mono : Incorrect sample (#%d : %f => %f).\n", __FILE__, __LINE__, k, ((double) k) / 100.0, data [k]) ;
|
Chris@0
|
471 exit (1) ;
|
Chris@0
|
472 } ;
|
Chris@0
|
473 } ;
|
Chris@0
|
474
|
Chris@0
|
475 /* Seek to start of file. */
|
Chris@0
|
476 test_seek_or_die (file, 0, SEEK_SET, 0, sfinfo.channels, __LINE__) ;
|
Chris@0
|
477
|
Chris@0
|
478 test_read_double_or_die (file, 0, data, 4, __LINE__) ;
|
Chris@0
|
479 for (k = 0 ; k < 4 ; k++)
|
Chris@0
|
480 { error = fabs (data [k] - ((double) k) / 100.0 * (sign *= -1)) ;
|
Chris@0
|
481 if (fabs (data [k]) > 1e-100 && fabs (error / data [k]) > 1e-5)
|
Chris@0
|
482 { printf ("\n\nError (%s:%d) Mono : Incorrect sample (#%d : %f => %f).\n", __FILE__, __LINE__, k, ((double) k) / 100.0, data [k]) ;
|
Chris@0
|
483 exit (1) ;
|
Chris@0
|
484 } ;
|
Chris@0
|
485 } ;
|
Chris@0
|
486
|
Chris@0
|
487 /* Seek to offset from start of file. */
|
Chris@0
|
488 test_seek_or_die (file, 10, SEEK_SET, 10, sfinfo.channels, __LINE__) ;
|
Chris@0
|
489
|
Chris@0
|
490 test_read_double_or_die (file, 0, data + 10, 4, __LINE__) ;
|
Chris@0
|
491 for (k = 10 ; k < 14 ; k++)
|
Chris@0
|
492 { error = fabs (data [k] - ((double) k) / 100.0 * (sign *= -1)) ;
|
Chris@0
|
493 if (fabs (data [k]) > 1e-100 && fabs (error / data [k]) > 1e-5)
|
Chris@0
|
494 { printf ("\n\nError (%s:%d) Mono : Incorrect sample (#%d : %f => %f).\n", __FILE__, __LINE__, k, ((double) k) / 100.0, data [k]) ;
|
Chris@0
|
495 exit (1) ;
|
Chris@0
|
496 } ;
|
Chris@0
|
497 } ;
|
Chris@0
|
498
|
Chris@0
|
499 /* Seek to offset from current position. */
|
Chris@0
|
500 test_seek_or_die (file, 6, SEEK_CUR, 20, sfinfo.channels, __LINE__) ;
|
Chris@0
|
501
|
Chris@0
|
502 test_read_double_or_die (file, 0, data + 20, 4, __LINE__) ;
|
Chris@0
|
503 for (k = 20 ; k < 24 ; k++)
|
Chris@0
|
504 { error = fabs (data [k] - ((double) k) / 100.0 * (sign *= -1)) ;
|
Chris@0
|
505 if (fabs (data [k]) > 1e-100 && fabs (error / data [k]) > 1e-5)
|
Chris@0
|
506 { printf ("\n\nError (%s:%d) Mono : Incorrect sample (#%d : %f => %f).\n", __FILE__, __LINE__, k, ((double) k) / 100.0, data [k]) ;
|
Chris@0
|
507 exit (1) ;
|
Chris@0
|
508 } ;
|
Chris@0
|
509 } ;
|
Chris@0
|
510
|
Chris@0
|
511 /* Seek to offset from end of file. */
|
Chris@0
|
512 test_seek_or_die (file, -1 * (sfinfo.frames - 10), SEEK_END, 10, sfinfo.channels, __LINE__) ;
|
Chris@0
|
513
|
Chris@0
|
514 test_read_double_or_die (file, 0, data + 10, 4, __LINE__) ;
|
Chris@0
|
515 for (k = 10 ; k < 14 ; k++)
|
Chris@0
|
516 { error = fabs (data [k] - ((double) k) / 100.0 * (sign *= -1)) ;
|
Chris@0
|
517 if (fabs (data [k]) > 1e-100 && fabs (error / data [k]) > 1e-5)
|
Chris@0
|
518 { printf ("\n\nError (%s:%d) Mono : Incorrect sample (#%d : %f => %f).\n", __FILE__, __LINE__, k, ((double) k) / 100.0, data [k]) ;
|
Chris@0
|
519 exit (1) ;
|
Chris@0
|
520 } ;
|
Chris@0
|
521 } ;
|
Chris@0
|
522
|
Chris@0
|
523 sf_close (file) ;
|
Chris@0
|
524
|
Chris@0
|
525 /* Now test Stereo. */
|
Chris@0
|
526
|
Chris@0
|
527 if ((filetype & SF_FORMAT_TYPEMASK) == SF_FORMAT_SVX) /* SVX is mono only */
|
Chris@0
|
528 { printf ("ok\n") ;
|
Chris@0
|
529 return ;
|
Chris@0
|
530 } ;
|
Chris@0
|
531
|
Chris@0
|
532 items = BUFFER_SIZE ;
|
Chris@0
|
533
|
Chris@0
|
534 data = data_out.d ;
|
Chris@0
|
535 for (sign = -1, k = 0 ; k < items ; k++)
|
Chris@0
|
536 data [k] = ((double) k) / 100.0 * (sign *= -1) ;
|
Chris@0
|
537
|
Chris@0
|
538 sfinfo.samplerate = 44100 ;
|
Chris@0
|
539 sfinfo.frames = items ;
|
Chris@0
|
540 sfinfo.channels = 2 ;
|
Chris@0
|
541 sfinfo.format = filetype ;
|
Chris@0
|
542
|
Chris@0
|
543 frames = items / sfinfo.channels ;
|
Chris@0
|
544
|
Chris@0
|
545 file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
|
Chris@0
|
546 sf_command (file, SFC_TEST_IEEE_FLOAT_REPLACE, NULL, replace_float) ;
|
Chris@0
|
547 if (replace_float && string_in_log_buffer (file, "Using IEEE replacement") == 0)
|
Chris@0
|
548 { printf ("\n\nLine %d : Float replacement code not working.\n\n", __LINE__) ;
|
Chris@0
|
549 dump_log_buffer (file) ;
|
Chris@0
|
550 exit (1) ;
|
Chris@0
|
551 } ;
|
Chris@0
|
552
|
Chris@0
|
553 test_writef_double_or_die (file, 0, data, frames, __LINE__) ;
|
Chris@0
|
554
|
Chris@0
|
555 sf_close (file) ;
|
Chris@0
|
556
|
Chris@0
|
557 check_file_hash_or_die (filename, hash, __LINE__) ;
|
Chris@0
|
558
|
Chris@0
|
559 memset (data, 0, items * sizeof (double)) ;
|
Chris@0
|
560
|
Chris@0
|
561 if ((filetype & SF_FORMAT_TYPEMASK) != SF_FORMAT_RAW)
|
Chris@0
|
562 memset (&sfinfo, 0, sizeof (sfinfo)) ;
|
Chris@0
|
563
|
Chris@0
|
564 file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
|
Chris@0
|
565 sf_command (file, SFC_TEST_IEEE_FLOAT_REPLACE, NULL, replace_float) ;
|
Chris@0
|
566 if (replace_float && string_in_log_buffer (file, "Using IEEE replacement") == 0)
|
Chris@0
|
567 { printf ("\n\nLine %d : Float replacement code not working.\n\n", __LINE__) ;
|
Chris@0
|
568 dump_log_buffer (file) ;
|
Chris@0
|
569 exit (1) ;
|
Chris@0
|
570 } ;
|
Chris@0
|
571
|
Chris@0
|
572 if (sfinfo.format != filetype)
|
Chris@0
|
573 { printf ("\n\nError (%s:%d) Stereo : Returned format incorrect (0x%08X => 0x%08X).\n", __FILE__, __LINE__, filetype, sfinfo.format) ;
|
Chris@0
|
574 exit (1) ;
|
Chris@0
|
575 } ;
|
Chris@0
|
576
|
Chris@0
|
577 if (sfinfo.frames != frames)
|
Chris@0
|
578 { printf ("\n\nError (%s:%d) Stereo : Incorrect number of frames in file. (%d => %ld)\n", __FILE__, __LINE__, frames, SF_COUNT_TO_LONG (sfinfo.frames)) ;
|
Chris@0
|
579 exit (1) ;
|
Chris@0
|
580 } ;
|
Chris@0
|
581
|
Chris@0
|
582 if (sfinfo.channels != 2)
|
Chris@0
|
583 { printf ("\n\nError (%s:%d) Stereo : Incorrect number of channels in file.\n", __FILE__, __LINE__) ;
|
Chris@0
|
584 exit (1) ;
|
Chris@0
|
585 } ;
|
Chris@0
|
586
|
Chris@0
|
587 check_log_buffer_or_die (file, __LINE__) ;
|
Chris@0
|
588
|
Chris@0
|
589 test_readf_double_or_die (file, 0, data, frames, __LINE__) ;
|
Chris@0
|
590 for (sign = -1, k = 0 ; k < items ; k++)
|
Chris@0
|
591 { error = fabs (data [k] - ((double) k) / 100.0 * (sign *= -1)) ;
|
Chris@0
|
592 if (fabs (data [k]) > 1e-100 && fabs (error / data [k]) > 1e-5)
|
Chris@0
|
593 { printf ("\n\nError (%s:%d) Stereo : Incorrect sample (#%d : %f => %f).\n", __FILE__, __LINE__, k, ((double) k) / 100.0, data [k]) ;
|
Chris@0
|
594 exit (1) ;
|
Chris@0
|
595 } ;
|
Chris@0
|
596 } ;
|
Chris@0
|
597
|
Chris@0
|
598 /* Seek to start of file. */
|
Chris@0
|
599 test_seek_or_die (file, 0, SEEK_SET, 0, sfinfo.channels, __LINE__) ;
|
Chris@0
|
600
|
Chris@0
|
601 test_readf_double_or_die (file, 0, data, 4, __LINE__) ;
|
Chris@0
|
602 for (k = 0 ; k < 4 ; k++)
|
Chris@0
|
603 { error = fabs (data [k] - ((double) k) / 100.0 * (sign *= -1)) ;
|
Chris@0
|
604 if (fabs (data [k]) > 1e-100 && fabs (error / data [k]) > 1e-5)
|
Chris@0
|
605 { printf ("\n\nError (%s:%d) Stereo : Incorrect sample (#%d : %f => %f).\n", __FILE__, __LINE__, k, ((double) k) / 100.0, data [k]) ;
|
Chris@0
|
606 exit (1) ;
|
Chris@0
|
607 } ;
|
Chris@0
|
608 } ;
|
Chris@0
|
609
|
Chris@0
|
610 /* Seek to offset from start of file. */
|
Chris@0
|
611 test_seek_or_die (file, 10, SEEK_SET, 10, sfinfo.channels, __LINE__) ;
|
Chris@0
|
612
|
Chris@0
|
613 test_readf_double_or_die (file, 0, data + 20, 2, __LINE__) ;
|
Chris@0
|
614 for (k = 20 ; k < 24 ; k++)
|
Chris@0
|
615 { error = fabs (data [k] - ((double) k) / 100.0 * (sign *= -1)) ;
|
Chris@0
|
616 if (fabs (data [k]) > 1e-100 && fabs (error / data [k]) > 1e-5)
|
Chris@0
|
617 { printf ("\n\nError (%s:%d) Stereo : Incorrect sample (#%d : %f => %f).\n", __FILE__, __LINE__, k, ((double) k) / 100.0, data [k]) ;
|
Chris@0
|
618 exit (1) ;
|
Chris@0
|
619 } ;
|
Chris@0
|
620 } ;
|
Chris@0
|
621
|
Chris@0
|
622 /* Seek to offset from current position. */
|
Chris@0
|
623 test_seek_or_die (file, 8, SEEK_CUR, 20, sfinfo.channels, __LINE__) ;
|
Chris@0
|
624
|
Chris@0
|
625 test_readf_double_or_die (file, 0, data + 40, 2, __LINE__) ;
|
Chris@0
|
626 for (k = 40 ; k < 44 ; k++)
|
Chris@0
|
627 { error = fabs (data [k] - ((double) k) / 100.0 * (sign *= -1)) ;
|
Chris@0
|
628 if (fabs (data [k]) > 1e-100 && fabs (error / data [k]) > 1e-5)
|
Chris@0
|
629 { printf ("\n\nError (%s:%d) Stereo : Incorrect sample (#%d : %f => %f).\n", __FILE__, __LINE__, k, ((double) k) / 100.0, data [k]) ;
|
Chris@0
|
630 exit (1) ;
|
Chris@0
|
631 } ;
|
Chris@0
|
632 } ;
|
Chris@0
|
633
|
Chris@0
|
634 /* Seek to offset from end of file. */
|
Chris@0
|
635 test_seek_or_die (file, -1 * (sfinfo.frames - 10), SEEK_END, 10, sfinfo.channels, __LINE__) ;
|
Chris@0
|
636
|
Chris@0
|
637 test_readf_double_or_die (file, 0, data + 20, 2, __LINE__) ;
|
Chris@0
|
638 for (k = 20 ; k < 24 ; k++)
|
Chris@0
|
639 { error = fabs (data [k] - ((double) k) / 100.0 * (sign *= -1)) ;
|
Chris@0
|
640 if (fabs (data [k]) > 1e-100 && fabs (error / data [k]) > 1e-5)
|
Chris@0
|
641 { printf ("\n\nError (%s:%d) Stereo : Incorrect sample (#%d : %f => %f).\n", __FILE__, __LINE__, k, ((double) k) / 100.0, data [k]) ;
|
Chris@0
|
642 exit (1) ;
|
Chris@0
|
643 } ;
|
Chris@0
|
644 } ;
|
Chris@0
|
645
|
Chris@0
|
646 sf_close (file) ;
|
Chris@0
|
647
|
Chris@0
|
648 printf ("ok\n") ;
|
Chris@0
|
649 unlink (filename) ;
|
Chris@0
|
650 } /* pcm_test_float */
|
Chris@0
|
651
|
Chris@0
|
652 static void
|
Chris@0
|
653 pcm_test_double (const char *filename, int filetype, uint64_t hash, int replace_float)
|
Chris@0
|
654 { SNDFILE *file ;
|
Chris@0
|
655 SF_INFO sfinfo ;
|
Chris@0
|
656 int k, items, frames ;
|
Chris@0
|
657 int sign ;
|
Chris@0
|
658 double *data, error ;
|
Chris@0
|
659
|
Chris@0
|
660 /* This is the best test routine. Other should be brought up to this standard. */
|
Chris@0
|
661
|
Chris@0
|
662 print_test_name (replace_float ? "pcm_test_double (replace)" : "pcm_test_double", filename) ;
|
Chris@0
|
663
|
Chris@0
|
664 items = BUFFER_SIZE ;
|
Chris@0
|
665
|
Chris@0
|
666 data = data_out.d ;
|
Chris@0
|
667 for (sign = 1, k = 0 ; k < items ; k++)
|
Chris@0
|
668 { data [k] = ((double) (k * sign)) / 100.0 ;
|
Chris@0
|
669 sign = (sign > 0) ? -1 : 1 ;
|
Chris@0
|
670 } ;
|
Chris@0
|
671
|
Chris@0
|
672 sfinfo.samplerate = 44100 ;
|
Chris@0
|
673 sfinfo.frames = items ;
|
Chris@0
|
674 sfinfo.channels = 1 ;
|
Chris@0
|
675 sfinfo.format = filetype ;
|
Chris@0
|
676
|
Chris@0
|
677 file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
|
Chris@0
|
678 sf_command (file, SFC_TEST_IEEE_FLOAT_REPLACE, NULL, replace_float) ;
|
Chris@0
|
679 if (replace_float && string_in_log_buffer (file, "Using IEEE replacement") == 0)
|
Chris@0
|
680 { printf ("\n\nLine %d : Float replacement code not working.\n\n", __LINE__) ;
|
Chris@0
|
681 dump_log_buffer (file) ;
|
Chris@0
|
682 exit (1) ;
|
Chris@0
|
683 } ;
|
Chris@0
|
684
|
Chris@0
|
685 test_write_double_or_die (file, 0, data, items, __LINE__) ;
|
Chris@0
|
686
|
Chris@0
|
687 sf_close (file) ;
|
Chris@0
|
688
|
Chris@0
|
689 #if (defined (WIN32) || defined (_WIN32))
|
Chris@0
|
690 /* File hashing on Win32 fails due to slighty different
|
Chris@0
|
691 ** calculated values of the sin() function.
|
Chris@0
|
692 */
|
Chris@0
|
693 hash = hash ; /* Avoid compiler warning. */
|
Chris@0
|
694 #else
|
Chris@0
|
695 check_file_hash_or_die (filename, hash, __LINE__) ;
|
Chris@0
|
696 #endif
|
Chris@0
|
697
|
Chris@0
|
698 memset (data, 0, items * sizeof (double)) ;
|
Chris@0
|
699
|
Chris@0
|
700 if ((filetype & SF_FORMAT_TYPEMASK) != SF_FORMAT_RAW)
|
Chris@0
|
701 memset (&sfinfo, 0, sizeof (sfinfo)) ;
|
Chris@0
|
702
|
Chris@0
|
703 file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
|
Chris@0
|
704 sf_command (file, SFC_TEST_IEEE_FLOAT_REPLACE, NULL, replace_float) ;
|
Chris@0
|
705 if (replace_float && string_in_log_buffer (file, "Using IEEE replacement") == 0)
|
Chris@0
|
706 { printf ("\n\nLine %d : Float replacement code not working.\n\n", __LINE__) ;
|
Chris@0
|
707 dump_log_buffer (file) ;
|
Chris@0
|
708 exit (1) ;
|
Chris@0
|
709 } ;
|
Chris@0
|
710
|
Chris@0
|
711 if (sfinfo.format != filetype)
|
Chris@0
|
712 { printf ("\n\nError (%s:%d) Mono : Returned format incorrect (0x%08X => 0x%08X).\n", __FILE__, __LINE__, filetype, sfinfo.format) ;
|
Chris@0
|
713 exit (1) ;
|
Chris@0
|
714 } ;
|
Chris@0
|
715
|
Chris@0
|
716 if (sfinfo.frames != items)
|
Chris@0
|
717 { printf ("\n\nError (%s:%d) Mono : Incorrect number of frames in file. (%d => %ld)\n", __FILE__, __LINE__, items, SF_COUNT_TO_LONG (sfinfo.frames)) ;
|
Chris@0
|
718 exit (1) ;
|
Chris@0
|
719 } ;
|
Chris@0
|
720
|
Chris@0
|
721 if (sfinfo.channels != 1)
|
Chris@0
|
722 { printf ("\n\nError (%s:%d) Mono : Incorrect number of channels in file.\n", __FILE__, __LINE__) ;
|
Chris@0
|
723 exit (1) ;
|
Chris@0
|
724 } ;
|
Chris@0
|
725
|
Chris@0
|
726 check_log_buffer_or_die (file, __LINE__) ;
|
Chris@0
|
727
|
Chris@0
|
728 test_read_double_or_die (file, 0, data, items, __LINE__) ;
|
Chris@0
|
729
|
Chris@0
|
730 for (sign = -1, k = 0 ; k < items ; k++)
|
Chris@0
|
731 { error = fabs (data [k] - ((double) k) / 100.0 * (sign *= -1)) ;
|
Chris@0
|
732 if (fabs (data [k]) > 1e-100 && fabs (error / data [k]) > 1e-5)
|
Chris@0
|
733 { printf ("\n\nError (%s:%d) Mono : Incorrect sample (#%d : %f => %f).\n", __FILE__, __LINE__, k, ((double) k) / 100.0, data [k]) ;
|
Chris@0
|
734 exit (1) ;
|
Chris@0
|
735 } ;
|
Chris@0
|
736 } ;
|
Chris@0
|
737
|
Chris@0
|
738 /* Seek to start of file. */
|
Chris@0
|
739 test_seek_or_die (file, 0, SEEK_SET, 0, sfinfo.channels, __LINE__) ;
|
Chris@0
|
740
|
Chris@0
|
741 test_read_double_or_die (file, 0, data, 4, __LINE__) ;
|
Chris@0
|
742 for (k = 0 ; k < 4 ; k++)
|
Chris@0
|
743 { error = fabs (data [k] - ((double) k) / 100.0 * (sign *= -1)) ;
|
Chris@0
|
744 if (fabs (data [k]) > 1e-100 && fabs (error / data [k]) > 1e-5)
|
Chris@0
|
745 { printf ("\n\nError (%s:%d) Mono : Incorrect sample (#%d : %f => %f).\n", __FILE__, __LINE__, k, ((double) k) / 100.0, data [k]) ;
|
Chris@0
|
746 exit (1) ;
|
Chris@0
|
747 } ;
|
Chris@0
|
748 } ;
|
Chris@0
|
749
|
Chris@0
|
750 /* Seek to offset from start of file. */
|
Chris@0
|
751 test_seek_or_die (file, 10, SEEK_SET, 10, sfinfo.channels, __LINE__) ;
|
Chris@0
|
752
|
Chris@0
|
753 test_read_double_or_die (file, 0, data + 10, 4, __LINE__) ;
|
Chris@0
|
754
|
Chris@0
|
755 test_seek_or_die (file, 0, SEEK_CUR, 14, sfinfo.channels, __LINE__) ;
|
Chris@0
|
756
|
Chris@0
|
757 for (k = 10 ; k < 14 ; k++)
|
Chris@0
|
758 { error = fabs (data [k] - ((double) k) / 100.0 * (sign *= -1)) ;
|
Chris@0
|
759 if (fabs (data [k]) > 1e-100 && fabs (error / data [k]) > 1e-5)
|
Chris@0
|
760 { printf ("\n\nError (%s:%d) Mono : Incorrect sample (#%d : %f => %f).\n", __FILE__, __LINE__, k, ((double) k) / 100.0, data [k]) ;
|
Chris@0
|
761 exit (1) ;
|
Chris@0
|
762 } ;
|
Chris@0
|
763 } ;
|
Chris@0
|
764
|
Chris@0
|
765 /* Seek to offset from current position. */
|
Chris@0
|
766 test_seek_or_die (file, 6, SEEK_CUR, 20, sfinfo.channels, __LINE__) ;
|
Chris@0
|
767
|
Chris@0
|
768 test_read_double_or_die (file, 0, data + 20, 4, __LINE__) ;
|
Chris@0
|
769 for (k = 20 ; k < 24 ; k++)
|
Chris@0
|
770 { error = fabs (data [k] - ((double) k) / 100.0 * (sign *= -1)) ;
|
Chris@0
|
771 if (fabs (data [k]) > 1e-100 && fabs (error / data [k]) > 1e-5)
|
Chris@0
|
772 { printf ("\n\nError (%s:%d) Mono : Incorrect sample (#%d : %f => %f).\n", __FILE__, __LINE__, k, ((double) k) / 100.0, data [k]) ;
|
Chris@0
|
773 exit (1) ;
|
Chris@0
|
774 } ;
|
Chris@0
|
775 } ;
|
Chris@0
|
776
|
Chris@0
|
777 /* Seek to offset from end of file. */
|
Chris@0
|
778 test_seek_or_die (file, -1 * (sfinfo.frames - 10), SEEK_END, 10, sfinfo.channels, __LINE__) ;
|
Chris@0
|
779
|
Chris@0
|
780 test_read_double_or_die (file, 0, data + 10, 4, __LINE__) ;
|
Chris@0
|
781 for (k = 10 ; k < 14 ; k++)
|
Chris@0
|
782 { error = fabs (data [k] - ((double) k) / 100.0 * (sign *= -1)) ;
|
Chris@0
|
783 if (fabs (data [k]) > 1e-100 && fabs (error / data [k]) > 1e-5)
|
Chris@0
|
784 { printf ("\n\nError (%s:%d) Mono : Incorrect sample (#%d : %f => %f).\n", __FILE__, __LINE__, k, ((double) k) / 100.0, data [k]) ;
|
Chris@0
|
785 exit (1) ;
|
Chris@0
|
786 } ;
|
Chris@0
|
787 } ;
|
Chris@0
|
788
|
Chris@0
|
789 sf_close (file) ;
|
Chris@0
|
790
|
Chris@0
|
791 /* Now test Stereo. */
|
Chris@0
|
792
|
Chris@0
|
793 if ((filetype & SF_FORMAT_TYPEMASK) == SF_FORMAT_SVX) /* SVX is mono only */
|
Chris@0
|
794 { printf ("ok\n") ;
|
Chris@0
|
795 return ;
|
Chris@0
|
796 } ;
|
Chris@0
|
797
|
Chris@0
|
798 items = BUFFER_SIZE ;
|
Chris@0
|
799
|
Chris@0
|
800 data = data_out.d ;
|
Chris@0
|
801 for (sign = -1, k = 0 ; k < items ; k++)
|
Chris@0
|
802 data [k] = ((double) k) / 100.0 * (sign *= -1) ;
|
Chris@0
|
803
|
Chris@0
|
804 sfinfo.samplerate = 44100 ;
|
Chris@0
|
805 sfinfo.frames = items ;
|
Chris@0
|
806 sfinfo.channels = 2 ;
|
Chris@0
|
807 sfinfo.format = filetype ;
|
Chris@0
|
808
|
Chris@0
|
809 frames = items / sfinfo.channels ;
|
Chris@0
|
810
|
Chris@0
|
811 file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
|
Chris@0
|
812 sf_command (file, SFC_TEST_IEEE_FLOAT_REPLACE, NULL, replace_float) ;
|
Chris@0
|
813 if (replace_float && string_in_log_buffer (file, "Using IEEE replacement") == 0)
|
Chris@0
|
814 { printf ("\n\nLine %d : Float replacement code not working.\n\n", __LINE__) ;
|
Chris@0
|
815 dump_log_buffer (file) ;
|
Chris@0
|
816 exit (1) ;
|
Chris@0
|
817 } ;
|
Chris@0
|
818
|
Chris@0
|
819 test_writef_double_or_die (file, 0, data, frames, __LINE__) ;
|
Chris@0
|
820
|
Chris@0
|
821 sf_close (file) ;
|
Chris@0
|
822
|
Chris@0
|
823 #if (defined (WIN32) || defined (_WIN32))
|
Chris@0
|
824 /* File hashing on Win32 fails due to slighty different
|
Chris@0
|
825 ** calculated values.
|
Chris@0
|
826 */
|
Chris@0
|
827 hash = hash ; /* Avoid compiler warning. */
|
Chris@0
|
828 #else
|
Chris@0
|
829 check_file_hash_or_die (filename, hash, __LINE__) ;
|
Chris@0
|
830 #endif
|
Chris@0
|
831
|
Chris@0
|
832 memset (data, 0, items * sizeof (double)) ;
|
Chris@0
|
833
|
Chris@0
|
834 if ((filetype & SF_FORMAT_TYPEMASK) != SF_FORMAT_RAW)
|
Chris@0
|
835 memset (&sfinfo, 0, sizeof (sfinfo)) ;
|
Chris@0
|
836
|
Chris@0
|
837 file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
|
Chris@0
|
838 sf_command (file, SFC_TEST_IEEE_FLOAT_REPLACE, NULL, replace_float) ;
|
Chris@0
|
839 if (replace_float && string_in_log_buffer (file, "Using IEEE replacement") == 0)
|
Chris@0
|
840 { printf ("\n\nLine %d : Float replacement code not working.\n\n", __LINE__) ;
|
Chris@0
|
841 dump_log_buffer (file) ;
|
Chris@0
|
842 exit (1) ;
|
Chris@0
|
843 } ;
|
Chris@0
|
844
|
Chris@0
|
845 if (sfinfo.format != filetype)
|
Chris@0
|
846 { printf ("\n\nError (%s:%d) Stereo : Returned format incorrect (0x%08X => 0x%08X).\n", __FILE__, __LINE__, filetype, sfinfo.format) ;
|
Chris@0
|
847 exit (1) ;
|
Chris@0
|
848 } ;
|
Chris@0
|
849
|
Chris@0
|
850 if (sfinfo.frames != frames)
|
Chris@0
|
851 { printf ("\n\nError (%s:%d) Stereo : Incorrect number of frames in file. (%d => %ld)\n", __FILE__, __LINE__, frames, SF_COUNT_TO_LONG (sfinfo.frames)) ;
|
Chris@0
|
852 exit (1) ;
|
Chris@0
|
853 } ;
|
Chris@0
|
854
|
Chris@0
|
855 if (sfinfo.channels != 2)
|
Chris@0
|
856 { printf ("\n\nError (%s:%d) Stereo : Incorrect number of channels in file.\n", __FILE__, __LINE__) ;
|
Chris@0
|
857 exit (1) ;
|
Chris@0
|
858 } ;
|
Chris@0
|
859
|
Chris@0
|
860 check_log_buffer_or_die (file, __LINE__) ;
|
Chris@0
|
861
|
Chris@0
|
862 test_readf_double_or_die (file, 0, data, frames, __LINE__) ;
|
Chris@0
|
863
|
Chris@0
|
864 for (sign = -1, k = 0 ; k < items ; k++)
|
Chris@0
|
865 { error = fabs (data [k] - ((double) k) / 100.0 * (sign *= -1)) ;
|
Chris@0
|
866 if (fabs (data [k]) > 1e-100 && fabs (error / data [k]) > 1e-5)
|
Chris@0
|
867 { printf ("\n\nError (%s:%d) Stereo : Incorrect sample (#%d : %f => %f).\n", __FILE__, __LINE__, k, ((double) k) / 100.0, data [k]) ;
|
Chris@0
|
868 exit (1) ;
|
Chris@0
|
869 } ;
|
Chris@0
|
870 } ;
|
Chris@0
|
871
|
Chris@0
|
872 /* Seek to start of file. */
|
Chris@0
|
873 test_seek_or_die (file, 0, SEEK_SET, 0, sfinfo.channels, __LINE__) ;
|
Chris@0
|
874
|
Chris@0
|
875 test_read_double_or_die (file, 0, data, 4, __LINE__) ;
|
Chris@0
|
876 for (k = 0 ; k < 4 ; k++)
|
Chris@0
|
877 { error = fabs (data [k] - ((double) k) / 100.0 * (sign *= -1)) ;
|
Chris@0
|
878 if (fabs (data [k]) > 1e-100 && fabs (error / data [k]) > 1e-5)
|
Chris@0
|
879 { printf ("\n\nError (%s:%d) Stereo : Incorrect sample (#%d : %f => %f).\n", __FILE__, __LINE__, k, ((double) k) / 100.0, data [k]) ;
|
Chris@0
|
880 exit (1) ;
|
Chris@0
|
881 } ;
|
Chris@0
|
882 } ;
|
Chris@0
|
883
|
Chris@0
|
884 /* Seek to offset from start of file. */
|
Chris@0
|
885 test_seek_or_die (file, 10, SEEK_SET, 10, sfinfo.channels, __LINE__) ;
|
Chris@0
|
886
|
Chris@0
|
887 test_read_double_or_die (file, 0, data + 10, 4, __LINE__) ;
|
Chris@0
|
888 for (k = 20 ; k < 24 ; k++)
|
Chris@0
|
889 { error = fabs (data [k] - ((double) k) / 100.0 * (sign *= -1)) ;
|
Chris@0
|
890 if (fabs (data [k]) > 1e-100 && fabs (error / data [k]) > 1e-5)
|
Chris@0
|
891 { printf ("\n\nError (%s:%d) Stereo : Incorrect sample (#%d : %f => %f).\n", __FILE__, __LINE__, k, ((double) k) / 100.0, data [k]) ;
|
Chris@0
|
892 exit (1) ;
|
Chris@0
|
893 } ;
|
Chris@0
|
894 } ;
|
Chris@0
|
895
|
Chris@0
|
896 /* Seek to offset from current position. */
|
Chris@0
|
897 test_seek_or_die (file, 8, SEEK_CUR, 20, sfinfo.channels, __LINE__) ;
|
Chris@0
|
898
|
Chris@0
|
899 test_readf_double_or_die (file, 0, data + 40, 4, __LINE__) ;
|
Chris@0
|
900 for (k = 40 ; k < 44 ; k++)
|
Chris@0
|
901 { error = fabs (data [k] - ((double) k) / 100.0 * (sign *= -1)) ;
|
Chris@0
|
902 if (fabs (data [k]) > 1e-100 && fabs (error / data [k]) > 1e-5)
|
Chris@0
|
903 { printf ("\n\nError (%s:%d) Stereo : Incorrect sample (#%d : %f => %f).\n", __FILE__, __LINE__, k, ((double) k) / 100.0, data [k]) ;
|
Chris@0
|
904 exit (1) ;
|
Chris@0
|
905 } ;
|
Chris@0
|
906 } ;
|
Chris@0
|
907
|
Chris@0
|
908 /* Seek to offset from end of file. */
|
Chris@0
|
909 test_seek_or_die (file, -1 * (sfinfo.frames -10), SEEK_END, 10, sfinfo.channels, __LINE__) ;
|
Chris@0
|
910
|
Chris@0
|
911 test_readf_double_or_die (file, 0, data + 20, 4, __LINE__) ;
|
Chris@0
|
912 for (k = 20 ; k < 24 ; k++)
|
Chris@0
|
913 { error = fabs (data [k] - ((double) k) / 100.0 * (sign *= -1)) ;
|
Chris@0
|
914 if (fabs (data [k]) > 1e-100 && fabs (error / data [k]) > 1e-5)
|
Chris@0
|
915 { printf ("\n\nError (%s:%d) Stereo : Incorrect sample (#%d : %f => %f).\n", __FILE__, __LINE__, k, ((double) k) / 100.0, data [k]) ;
|
Chris@0
|
916 exit (1) ;
|
Chris@0
|
917 } ;
|
Chris@0
|
918 } ;
|
Chris@0
|
919
|
Chris@0
|
920 sf_close (file) ;
|
Chris@0
|
921
|
Chris@0
|
922 printf ("ok\n") ;
|
Chris@0
|
923 unlink (filename) ;
|
Chris@0
|
924 } /* pcm_test_double */
|
Chris@0
|
925
|
Chris@0
|
926 /*==============================================================================
|
Chris@0
|
927 */
|