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