Chris@0
|
1 /*
|
Chris@0
|
2 ** Copyright (C) 1999-2011 Erik de Castro Lopo <erikd@mega-nerd.com>
|
Chris@0
|
3 **
|
Chris@0
|
4 ** This program is free software; you can redistribute it and/or modify
|
Chris@0
|
5 ** it under the terms of the GNU General Public License as published by
|
Chris@0
|
6 ** the Free Software Foundation; either version 2 of the License, or
|
Chris@0
|
7 ** (at your option) any later version.
|
Chris@0
|
8 **
|
Chris@0
|
9 ** This program is distributed in the hope that it will be useful,
|
Chris@0
|
10 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
Chris@0
|
11 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
Chris@0
|
12 ** GNU General Public License for more details.
|
Chris@0
|
13 **
|
Chris@0
|
14 ** You should have received a copy of the GNU General Public License
|
Chris@0
|
15 ** along with this program; if not, write to the Free Software
|
Chris@0
|
16 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
Chris@0
|
17 */
|
Chris@0
|
18
|
Chris@0
|
19 #include "sfconfig.h"
|
Chris@0
|
20
|
Chris@0
|
21 #include <stdio.h>
|
Chris@0
|
22 #include <stdlib.h>
|
Chris@0
|
23 #include <string.h>
|
Chris@0
|
24
|
Chris@0
|
25 #if HAVE_UNISTD_H
|
Chris@0
|
26 #include <unistd.h>
|
Chris@0
|
27 #endif
|
Chris@0
|
28
|
Chris@0
|
29 #include <math.h>
|
Chris@0
|
30
|
Chris@0
|
31 #include <sndfile.h>
|
Chris@0
|
32
|
Chris@0
|
33 #include "utils.h"
|
Chris@0
|
34
|
Chris@0
|
35 #ifndef M_PI
|
Chris@0
|
36 #define M_PI 3.14159265358979323846264338
|
Chris@0
|
37 #endif
|
Chris@0
|
38
|
Chris@0
|
39 #define HALF_BUFFER_SIZE (1 << 12)
|
Chris@0
|
40 #define BUFFER_SIZE (2 * HALF_BUFFER_SIZE)
|
Chris@0
|
41
|
Chris@0
|
42 #define SINE_AMP 1.1
|
Chris@0
|
43 #define MAX_ERROR 0.0202
|
Chris@0
|
44
|
Chris@0
|
45
|
Chris@0
|
46 static void flt_scale_clip_test_16 (const char *filename, int filetype, float maxval) ;
|
Chris@0
|
47 static void flt_scale_clip_test_24 (const char *filename, int filetype, float maxval) ;
|
Chris@0
|
48 static void flt_scale_clip_test_32 (const char *filename, int filetype, float maxval) ;
|
Chris@0
|
49 static void flt_scale_clip_test_08 (const char *filename, int filetype, float maxval) ;
|
Chris@0
|
50
|
Chris@0
|
51 static void dbl_scale_clip_test_16 (const char *filename, int filetype, float maxval) ;
|
Chris@0
|
52 static void dbl_scale_clip_test_24 (const char *filename, int filetype, float maxval) ;
|
Chris@0
|
53 static void dbl_scale_clip_test_32 (const char *filename, int filetype, float maxval) ;
|
Chris@0
|
54 static void dbl_scale_clip_test_08 (const char *filename, int filetype, float maxval) ;
|
Chris@0
|
55
|
Chris@0
|
56
|
Chris@0
|
57
|
Chris@0
|
58 static void flt_short_clip_read_test (const char *filename, int filetype) ;
|
Chris@0
|
59 static void flt_int_clip_read_test (const char *filename, int filetype) ;
|
Chris@0
|
60
|
Chris@0
|
61 static void dbl_short_clip_read_test (const char *filename, int filetype) ;
|
Chris@0
|
62 static void dbl_int_clip_read_test (const char *filename, int filetype) ;
|
Chris@0
|
63
|
Chris@0
|
64
|
Chris@0
|
65
|
Chris@0
|
66 static void short_flt_scale_write_test (const char *filename, int filetype) ;
|
Chris@0
|
67 static void short_dbl_scale_write_test (const char *filename, int filetype) ;
|
Chris@0
|
68
|
Chris@0
|
69 static void int_flt_scale_write_test (const char *filename, int filetype) ;
|
Chris@0
|
70 static void int_dbl_scale_write_test (const char *filename, int filetype) ;
|
Chris@0
|
71
|
Chris@0
|
72
|
Chris@0
|
73 typedef union
|
Chris@0
|
74 { double dbl [BUFFER_SIZE] ;
|
Chris@0
|
75 float flt [BUFFER_SIZE] ;
|
Chris@0
|
76 int i [BUFFER_SIZE] ;
|
Chris@0
|
77 short s [BUFFER_SIZE] ;
|
Chris@0
|
78 } BUFFER ;
|
Chris@0
|
79
|
Chris@0
|
80 /* Data buffer. */
|
Chris@0
|
81 static BUFFER buffer_out ;
|
Chris@0
|
82 static BUFFER buffer_in ;
|
Chris@0
|
83
|
Chris@0
|
84 int
|
Chris@0
|
85 main (void)
|
Chris@0
|
86 {
|
Chris@0
|
87 flt_scale_clip_test_08 ("scale_clip_s8.au", SF_FORMAT_AU | SF_FORMAT_PCM_S8, 1.0 * 0x80) ;
|
Chris@0
|
88 flt_scale_clip_test_08 ("scale_clip_u8.wav", SF_FORMAT_WAV | SF_FORMAT_PCM_U8, 1.0 * 0x80) ;
|
Chris@0
|
89
|
Chris@0
|
90 dbl_scale_clip_test_08 ("scale_clip_s8.au", SF_FORMAT_AU | SF_FORMAT_PCM_S8, 1.0 * 0x80) ;
|
Chris@0
|
91 dbl_scale_clip_test_08 ("scale_clip_u8.wav", SF_FORMAT_WAV | SF_FORMAT_PCM_U8, 1.0 * 0x80) ;
|
Chris@0
|
92
|
Chris@0
|
93 /*
|
Chris@0
|
94 ** Now use SF_FORMAT_AU where possible because it allows both
|
Chris@0
|
95 ** big and little endian files.
|
Chris@0
|
96 */
|
Chris@0
|
97
|
Chris@0
|
98 flt_scale_clip_test_16 ("scale_clip_be16.au", SF_ENDIAN_BIG | SF_FORMAT_AU | SF_FORMAT_PCM_16, 1.0 * 0x8000) ;
|
Chris@0
|
99 flt_scale_clip_test_16 ("scale_clip_le16.au", SF_ENDIAN_LITTLE | SF_FORMAT_AU | SF_FORMAT_PCM_16, 1.0 * 0x8000) ;
|
Chris@0
|
100 flt_scale_clip_test_24 ("scale_clip_be24.au", SF_ENDIAN_BIG | SF_FORMAT_AU | SF_FORMAT_PCM_24, 1.0 * 0x800000) ;
|
Chris@0
|
101 flt_scale_clip_test_24 ("scale_clip_le24.au", SF_ENDIAN_LITTLE | SF_FORMAT_AU | SF_FORMAT_PCM_24, 1.0 * 0x800000) ;
|
Chris@0
|
102 flt_scale_clip_test_32 ("scale_clip_be32.au", SF_ENDIAN_BIG | SF_FORMAT_AU | SF_FORMAT_PCM_32, 1.0 * 0x80000000) ;
|
Chris@0
|
103 flt_scale_clip_test_32 ("scale_clip_le32.au", SF_ENDIAN_LITTLE | SF_FORMAT_AU | SF_FORMAT_PCM_32, 1.0 * 0x80000000) ;
|
Chris@0
|
104
|
Chris@0
|
105 dbl_scale_clip_test_16 ("scale_clip_be16.au", SF_ENDIAN_BIG | SF_FORMAT_AU | SF_FORMAT_PCM_16, 1.0 * 0x8000) ;
|
Chris@0
|
106 dbl_scale_clip_test_16 ("scale_clip_le16.au", SF_ENDIAN_LITTLE | SF_FORMAT_AU | SF_FORMAT_PCM_16, 1.0 * 0x8000) ;
|
Chris@0
|
107 dbl_scale_clip_test_24 ("scale_clip_be24.au", SF_ENDIAN_BIG | SF_FORMAT_AU | SF_FORMAT_PCM_24, 1.0 * 0x800000) ;
|
Chris@0
|
108 dbl_scale_clip_test_24 ("scale_clip_le24.au", SF_ENDIAN_LITTLE | SF_FORMAT_AU | SF_FORMAT_PCM_24, 1.0 * 0x800000) ;
|
Chris@0
|
109 dbl_scale_clip_test_32 ("scale_clip_be32.au", SF_ENDIAN_BIG | SF_FORMAT_AU | SF_FORMAT_PCM_32, 1.0 * 0x80000000) ;
|
Chris@0
|
110 dbl_scale_clip_test_32 ("scale_clip_le32.au", SF_ENDIAN_LITTLE | SF_FORMAT_AU | SF_FORMAT_PCM_32, 1.0 * 0x80000000) ;
|
Chris@0
|
111
|
Chris@0
|
112 flt_short_clip_read_test ("flt_short.au" , SF_ENDIAN_BIG | SF_FORMAT_AU | SF_FORMAT_FLOAT) ;
|
Chris@0
|
113 flt_int_clip_read_test ("flt_int.au" , SF_ENDIAN_LITTLE | SF_FORMAT_AU | SF_FORMAT_FLOAT) ;
|
Chris@0
|
114 dbl_short_clip_read_test ("dbl_short.au" , SF_ENDIAN_BIG | SF_FORMAT_AU | SF_FORMAT_DOUBLE) ;
|
Chris@0
|
115 dbl_int_clip_read_test ("dbl_int.au" , SF_ENDIAN_LITTLE | SF_FORMAT_AU | SF_FORMAT_DOUBLE) ;
|
Chris@0
|
116
|
Chris@0
|
117 short_flt_scale_write_test ("short_flt.au" , SF_ENDIAN_BIG | SF_FORMAT_AU | SF_FORMAT_FLOAT) ;
|
Chris@0
|
118 int_flt_scale_write_test ("int_flt.au" , SF_ENDIAN_LITTLE | SF_FORMAT_AU | SF_FORMAT_FLOAT) ;
|
Chris@0
|
119 short_dbl_scale_write_test ("short_dbl.au" , SF_ENDIAN_BIG | SF_FORMAT_AU | SF_FORMAT_DOUBLE) ;
|
Chris@0
|
120 int_dbl_scale_write_test ("int_dbl.au" , SF_ENDIAN_LITTLE | SF_FORMAT_AU | SF_FORMAT_DOUBLE) ;
|
Chris@0
|
121
|
Chris@0
|
122 return 0 ;
|
Chris@0
|
123 } /* main */
|
Chris@0
|
124
|
Chris@0
|
125 /*============================================================================================
|
Chris@0
|
126 ** Here are the test functions.
|
Chris@0
|
127 */
|
Chris@0
|
128
|
Chris@0
|
129
|
Chris@0
|
130 static void
|
Chris@0
|
131 flt_scale_clip_test_16 (const char *filename, int filetype, float maxval)
|
Chris@0
|
132 { SNDFILE *file ;
|
Chris@0
|
133 SF_INFO sfinfo ;
|
Chris@0
|
134 int k ;
|
Chris@0
|
135 float *data_out, *data_in ;
|
Chris@0
|
136 double diff, clip_max_diff ;
|
Chris@0
|
137
|
Chris@0
|
138 print_test_name ("flt_scale_clip_test_16", filename) ;
|
Chris@0
|
139
|
Chris@0
|
140 data_out = buffer_out.flt ;
|
Chris@0
|
141 data_in = buffer_in.flt ;
|
Chris@0
|
142
|
Chris@0
|
143 for (k = 0 ; k < HALF_BUFFER_SIZE ; k++)
|
Chris@0
|
144 { data_out [k] = 1.2 * sin (2 * M_PI * k / HALF_BUFFER_SIZE) ;
|
Chris@0
|
145 data_out [k + HALF_BUFFER_SIZE] = data_out [k] * maxval ;
|
Chris@0
|
146 } ;
|
Chris@0
|
147
|
Chris@0
|
148 sfinfo.samplerate = 44100 ;
|
Chris@0
|
149 sfinfo.frames = 123456789 ; /* Wrong length. Library should correct this on sf_close. */
|
Chris@0
|
150 sfinfo.channels = 1 ;
|
Chris@0
|
151 sfinfo.format = filetype ;
|
Chris@0
|
152
|
Chris@0
|
153 /*
|
Chris@0
|
154 ** Write two versions of the data:
|
Chris@0
|
155 ** normalized and clipped
|
Chris@0
|
156 ** un-normalized and clipped.
|
Chris@0
|
157 */
|
Chris@0
|
158
|
Chris@0
|
159 file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
|
Chris@0
|
160 sf_command (file, SFC_SET_CLIPPING, NULL, SF_TRUE) ;
|
Chris@0
|
161 test_write_float_or_die (file, 0, data_out, HALF_BUFFER_SIZE, __LINE__) ;
|
Chris@0
|
162 sf_command (file, SFC_SET_NORM_FLOAT, NULL, SF_FALSE) ;
|
Chris@0
|
163 test_write_float_or_die (file, 0, data_out + HALF_BUFFER_SIZE, HALF_BUFFER_SIZE, __LINE__) ;
|
Chris@0
|
164 sf_close (file) ;
|
Chris@0
|
165
|
Chris@0
|
166 memset (&buffer_in, 0, sizeof (buffer_in)) ;
|
Chris@0
|
167
|
Chris@0
|
168 file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
|
Chris@0
|
169
|
Chris@0
|
170 sfinfo.format &= (SF_FORMAT_TYPEMASK | SF_FORMAT_SUBMASK) ;
|
Chris@0
|
171
|
Chris@0
|
172 if (sfinfo.format != (filetype & (SF_FORMAT_TYPEMASK | SF_FORMAT_SUBMASK)))
|
Chris@0
|
173 { printf ("\n\nLine %d: Returned format incorrect (0x%08X => 0x%08X).\n\n", __LINE__, filetype, sfinfo.format) ;
|
Chris@0
|
174 exit (1) ;
|
Chris@0
|
175 } ;
|
Chris@0
|
176
|
Chris@0
|
177 if (sfinfo.frames != BUFFER_SIZE)
|
Chris@0
|
178 { printf ("\n\nLine %d: Incorrect number of frames in file (%d => %ld).\n\n", __LINE__, BUFFER_SIZE, SF_COUNT_TO_LONG (sfinfo.frames)) ;
|
Chris@0
|
179 exit (1) ;
|
Chris@0
|
180 } ;
|
Chris@0
|
181
|
Chris@0
|
182 if (sfinfo.channels != 1)
|
Chris@0
|
183 { printf ("\n\nLine %d: Incorrect number of channels in file.\n\n", __LINE__) ;
|
Chris@0
|
184 exit (1) ;
|
Chris@0
|
185 } ;
|
Chris@0
|
186
|
Chris@0
|
187 check_log_buffer_or_die (file, __LINE__) ;
|
Chris@0
|
188
|
Chris@0
|
189 test_read_float_or_die (file, 0, data_in, HALF_BUFFER_SIZE, __LINE__) ;
|
Chris@0
|
190 sf_command (file, SFC_SET_NORM_FLOAT, NULL, SF_FALSE) ;
|
Chris@0
|
191 test_read_float_or_die (file, 0, data_in + HALF_BUFFER_SIZE, HALF_BUFFER_SIZE, __LINE__) ;
|
Chris@0
|
192 sf_close (file) ;
|
Chris@0
|
193
|
Chris@0
|
194 /* Check normalized version. */
|
Chris@0
|
195 clip_max_diff = 0.0 ;
|
Chris@0
|
196 for (k = 0 ; k < HALF_BUFFER_SIZE ; k++)
|
Chris@0
|
197 { if (fabs (data_in [k]) > 1.0)
|
Chris@0
|
198 { printf ("\n\nLine %d: Input sample %d/%d (%f) has not been clipped.\n\n", __LINE__, k, BUFFER_SIZE, data_in [k]) ;
|
Chris@0
|
199 exit (1) ;
|
Chris@0
|
200 } ;
|
Chris@0
|
201
|
Chris@0
|
202 if (data_out [k] * data_in [k] < 0.0)
|
Chris@0
|
203 { printf ("\n\nLine %d: Data wrap around at index %d/%d.\n\n", __LINE__, k, BUFFER_SIZE) ;
|
Chris@0
|
204 exit (1) ;
|
Chris@0
|
205 } ;
|
Chris@0
|
206
|
Chris@0
|
207 if (fabs (data_out [k]) > 1.0)
|
Chris@0
|
208 continue ;
|
Chris@0
|
209
|
Chris@0
|
210 diff = fabs (data_out [k] - data_in [k]) ;
|
Chris@0
|
211 if (diff > clip_max_diff)
|
Chris@0
|
212 clip_max_diff = diff ;
|
Chris@0
|
213 } ;
|
Chris@0
|
214
|
Chris@0
|
215 if (clip_max_diff < 1e-20)
|
Chris@0
|
216 { printf ("\n\nLine %d: Clipping difference (%e) too small (normalized).\n\n", __LINE__, clip_max_diff) ;
|
Chris@0
|
217 exit (1) ;
|
Chris@0
|
218 } ;
|
Chris@0
|
219
|
Chris@0
|
220 if (clip_max_diff > 1.0 / 0x8000)
|
Chris@0
|
221 { printf ("\n\nLine %d: Clipping difference (%e) too large (normalized).\n\n", __LINE__, clip_max_diff) ;
|
Chris@0
|
222 exit (1) ;
|
Chris@0
|
223 } ;
|
Chris@0
|
224
|
Chris@0
|
225 /* Check the un-normalized data. */
|
Chris@0
|
226 clip_max_diff = 0.0 ;
|
Chris@0
|
227 for (k = HALF_BUFFER_SIZE ; k < BUFFER_SIZE ; k++)
|
Chris@0
|
228 { if (fabs (data_in [k]) > maxval)
|
Chris@0
|
229 { printf ("\n\nLine %d: Input sample %d/%d (%f) has not been clipped.\n\n", __LINE__, k, BUFFER_SIZE, data_in [k]) ;
|
Chris@0
|
230 exit (1) ;
|
Chris@0
|
231 } ;
|
Chris@0
|
232
|
Chris@0
|
233 if (data_out [k] * data_in [k] < 0.0)
|
Chris@0
|
234 { printf ("\n\nLine %d: Data wrap around at index %d/%d.\n\n", __LINE__, k, BUFFER_SIZE) ;
|
Chris@0
|
235 exit (1) ;
|
Chris@0
|
236 } ;
|
Chris@0
|
237
|
Chris@0
|
238 if (fabs (data_out [k]) > maxval)
|
Chris@0
|
239 continue ;
|
Chris@0
|
240
|
Chris@0
|
241 diff = fabs (data_out [k] - data_in [k]) ;
|
Chris@0
|
242 if (diff > clip_max_diff)
|
Chris@0
|
243 clip_max_diff = diff ;
|
Chris@0
|
244 } ;
|
Chris@0
|
245
|
Chris@0
|
246 if (clip_max_diff < 1e-20)
|
Chris@0
|
247 { printf ("\n\nLine %d: Clipping difference (%e) too small (un-normalized).\n\n", __LINE__, clip_max_diff) ;
|
Chris@0
|
248 exit (1) ;
|
Chris@0
|
249 } ;
|
Chris@0
|
250
|
Chris@0
|
251 if (clip_max_diff > 1.0)
|
Chris@0
|
252 { printf ("\n\nLine %d: Clipping difference (%e) too large (un-normalised).\n\n", __LINE__, clip_max_diff) ;
|
Chris@0
|
253 exit (1) ;
|
Chris@0
|
254 } ;
|
Chris@0
|
255
|
Chris@0
|
256 printf ("ok\n") ;
|
Chris@0
|
257 unlink (filename) ;
|
Chris@0
|
258 } /* flt_scale_clip_test_16 */
|
Chris@0
|
259
|
Chris@0
|
260 static void
|
Chris@0
|
261 flt_scale_clip_test_24 (const char *filename, int filetype, float maxval)
|
Chris@0
|
262 { SNDFILE *file ;
|
Chris@0
|
263 SF_INFO sfinfo ;
|
Chris@0
|
264 int k ;
|
Chris@0
|
265 float *data_out, *data_in ;
|
Chris@0
|
266 double diff, clip_max_diff ;
|
Chris@0
|
267
|
Chris@0
|
268 print_test_name ("flt_scale_clip_test_24", filename) ;
|
Chris@0
|
269
|
Chris@0
|
270 data_out = buffer_out.flt ;
|
Chris@0
|
271 data_in = buffer_in.flt ;
|
Chris@0
|
272
|
Chris@0
|
273 for (k = 0 ; k < HALF_BUFFER_SIZE ; k++)
|
Chris@0
|
274 { data_out [k] = 1.2 * sin (2 * M_PI * k / HALF_BUFFER_SIZE) ;
|
Chris@0
|
275 data_out [k + HALF_BUFFER_SIZE] = data_out [k] * maxval ;
|
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 /*
|
Chris@0
|
284 ** Write two versions of the data:
|
Chris@0
|
285 ** normalized and clipped
|
Chris@0
|
286 ** un-normalized and clipped.
|
Chris@0
|
287 */
|
Chris@0
|
288
|
Chris@0
|
289 file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
|
Chris@0
|
290 sf_command (file, SFC_SET_CLIPPING, NULL, SF_TRUE) ;
|
Chris@0
|
291 test_write_float_or_die (file, 0, data_out, HALF_BUFFER_SIZE, __LINE__) ;
|
Chris@0
|
292 sf_command (file, SFC_SET_NORM_FLOAT, NULL, SF_FALSE) ;
|
Chris@0
|
293 test_write_float_or_die (file, 0, data_out + HALF_BUFFER_SIZE, HALF_BUFFER_SIZE, __LINE__) ;
|
Chris@0
|
294 sf_close (file) ;
|
Chris@0
|
295
|
Chris@0
|
296 memset (&buffer_in, 0, sizeof (buffer_in)) ;
|
Chris@0
|
297
|
Chris@0
|
298 file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
|
Chris@0
|
299
|
Chris@0
|
300 sfinfo.format &= (SF_FORMAT_TYPEMASK | SF_FORMAT_SUBMASK) ;
|
Chris@0
|
301
|
Chris@0
|
302 if (sfinfo.format != (filetype & (SF_FORMAT_TYPEMASK | SF_FORMAT_SUBMASK)))
|
Chris@0
|
303 { printf ("\n\nLine %d: Returned format incorrect (0x%08X => 0x%08X).\n\n", __LINE__, filetype, sfinfo.format) ;
|
Chris@0
|
304 exit (1) ;
|
Chris@0
|
305 } ;
|
Chris@0
|
306
|
Chris@0
|
307 if (sfinfo.frames != BUFFER_SIZE)
|
Chris@0
|
308 { printf ("\n\nLine %d: Incorrect number of frames in file (%d => %ld).\n\n", __LINE__, BUFFER_SIZE, SF_COUNT_TO_LONG (sfinfo.frames)) ;
|
Chris@0
|
309 exit (1) ;
|
Chris@0
|
310 } ;
|
Chris@0
|
311
|
Chris@0
|
312 if (sfinfo.channels != 1)
|
Chris@0
|
313 { printf ("\n\nLine %d: Incorrect number of channels in file.\n\n", __LINE__) ;
|
Chris@0
|
314 exit (1) ;
|
Chris@0
|
315 } ;
|
Chris@0
|
316
|
Chris@0
|
317 check_log_buffer_or_die (file, __LINE__) ;
|
Chris@0
|
318
|
Chris@0
|
319 test_read_float_or_die (file, 0, data_in, HALF_BUFFER_SIZE, __LINE__) ;
|
Chris@0
|
320 sf_command (file, SFC_SET_NORM_FLOAT, NULL, SF_FALSE) ;
|
Chris@0
|
321 test_read_float_or_die (file, 0, data_in + HALF_BUFFER_SIZE, HALF_BUFFER_SIZE, __LINE__) ;
|
Chris@0
|
322 sf_close (file) ;
|
Chris@0
|
323
|
Chris@0
|
324 /* Check normalized version. */
|
Chris@0
|
325 clip_max_diff = 0.0 ;
|
Chris@0
|
326 for (k = 0 ; k < HALF_BUFFER_SIZE ; k++)
|
Chris@0
|
327 { if (fabs (data_in [k]) > 1.0)
|
Chris@0
|
328 { printf ("\n\nLine %d: Input sample %d/%d (%f) has not been clipped.\n\n", __LINE__, k, BUFFER_SIZE, data_in [k]) ;
|
Chris@0
|
329 exit (1) ;
|
Chris@0
|
330 } ;
|
Chris@0
|
331
|
Chris@0
|
332 if (data_out [k] * data_in [k] < 0.0)
|
Chris@0
|
333 { printf ("\n\nLine %d: Data wrap around at index %d/%d.\n\n", __LINE__, k, BUFFER_SIZE) ;
|
Chris@0
|
334 exit (1) ;
|
Chris@0
|
335 } ;
|
Chris@0
|
336
|
Chris@0
|
337 if (fabs (data_out [k]) > 1.0)
|
Chris@0
|
338 continue ;
|
Chris@0
|
339
|
Chris@0
|
340 diff = fabs (data_out [k] - data_in [k]) ;
|
Chris@0
|
341 if (diff > clip_max_diff)
|
Chris@0
|
342 clip_max_diff = diff ;
|
Chris@0
|
343 } ;
|
Chris@0
|
344
|
Chris@0
|
345 if (clip_max_diff < 1e-20)
|
Chris@0
|
346 { printf ("\n\nLine %d: Clipping difference (%e) too small (normalized).\n\n", __LINE__, clip_max_diff) ;
|
Chris@0
|
347 exit (1) ;
|
Chris@0
|
348 } ;
|
Chris@0
|
349
|
Chris@0
|
350 if (clip_max_diff > 1.0 / 0x800000)
|
Chris@0
|
351 { printf ("\n\nLine %d: Clipping difference (%e) too large (normalized).\n\n", __LINE__, clip_max_diff) ;
|
Chris@0
|
352 exit (1) ;
|
Chris@0
|
353 } ;
|
Chris@0
|
354
|
Chris@0
|
355 /* Check the un-normalized data. */
|
Chris@0
|
356 clip_max_diff = 0.0 ;
|
Chris@0
|
357 for (k = HALF_BUFFER_SIZE ; k < BUFFER_SIZE ; k++)
|
Chris@0
|
358 { if (fabs (data_in [k]) > maxval)
|
Chris@0
|
359 { printf ("\n\nLine %d: Input sample %d/%d (%f) has not been clipped.\n\n", __LINE__, k, BUFFER_SIZE, data_in [k]) ;
|
Chris@0
|
360 exit (1) ;
|
Chris@0
|
361 } ;
|
Chris@0
|
362
|
Chris@0
|
363 if (data_out [k] * data_in [k] < 0.0)
|
Chris@0
|
364 { printf ("\n\nLine %d: Data wrap around at index %d/%d.\n\n", __LINE__, k, BUFFER_SIZE) ;
|
Chris@0
|
365 exit (1) ;
|
Chris@0
|
366 } ;
|
Chris@0
|
367
|
Chris@0
|
368 if (fabs (data_out [k]) > maxval)
|
Chris@0
|
369 continue ;
|
Chris@0
|
370
|
Chris@0
|
371 diff = fabs (data_out [k] - data_in [k]) ;
|
Chris@0
|
372 if (diff > clip_max_diff)
|
Chris@0
|
373 clip_max_diff = diff ;
|
Chris@0
|
374 } ;
|
Chris@0
|
375
|
Chris@0
|
376 if (clip_max_diff < 1e-20)
|
Chris@0
|
377 { printf ("\n\nLine %d: Clipping difference (%e) too small (un-normalized).\n\n", __LINE__, clip_max_diff) ;
|
Chris@0
|
378 exit (1) ;
|
Chris@0
|
379 } ;
|
Chris@0
|
380
|
Chris@0
|
381 if (clip_max_diff > 1.0)
|
Chris@0
|
382 { printf ("\n\nLine %d: Clipping difference (%e) too large (un-normalised).\n\n", __LINE__, clip_max_diff) ;
|
Chris@0
|
383 exit (1) ;
|
Chris@0
|
384 } ;
|
Chris@0
|
385
|
Chris@0
|
386 printf ("ok\n") ;
|
Chris@0
|
387 unlink (filename) ;
|
Chris@0
|
388 } /* flt_scale_clip_test_24 */
|
Chris@0
|
389
|
Chris@0
|
390 static void
|
Chris@0
|
391 flt_scale_clip_test_32 (const char *filename, int filetype, float maxval)
|
Chris@0
|
392 { SNDFILE *file ;
|
Chris@0
|
393 SF_INFO sfinfo ;
|
Chris@0
|
394 int k ;
|
Chris@0
|
395 float *data_out, *data_in ;
|
Chris@0
|
396 double diff, clip_max_diff ;
|
Chris@0
|
397
|
Chris@0
|
398 print_test_name ("flt_scale_clip_test_32", filename) ;
|
Chris@0
|
399
|
Chris@0
|
400 data_out = buffer_out.flt ;
|
Chris@0
|
401 data_in = buffer_in.flt ;
|
Chris@0
|
402
|
Chris@0
|
403 for (k = 0 ; k < HALF_BUFFER_SIZE ; k++)
|
Chris@0
|
404 { data_out [k] = 1.2 * sin (2 * M_PI * k / HALF_BUFFER_SIZE) ;
|
Chris@0
|
405 data_out [k + HALF_BUFFER_SIZE] = data_out [k] * maxval ;
|
Chris@0
|
406 } ;
|
Chris@0
|
407
|
Chris@0
|
408 sfinfo.samplerate = 44100 ;
|
Chris@0
|
409 sfinfo.frames = 123456789 ; /* Wrong length. Library should correct this on sf_close. */
|
Chris@0
|
410 sfinfo.channels = 1 ;
|
Chris@0
|
411 sfinfo.format = filetype ;
|
Chris@0
|
412
|
Chris@0
|
413 /*
|
Chris@0
|
414 ** Write two versions of the data:
|
Chris@0
|
415 ** normalized and clipped
|
Chris@0
|
416 ** un-normalized and clipped.
|
Chris@0
|
417 */
|
Chris@0
|
418
|
Chris@0
|
419 file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
|
Chris@0
|
420 sf_command (file, SFC_SET_CLIPPING, NULL, SF_TRUE) ;
|
Chris@0
|
421 test_write_float_or_die (file, 0, data_out, HALF_BUFFER_SIZE, __LINE__) ;
|
Chris@0
|
422 sf_command (file, SFC_SET_NORM_FLOAT, NULL, SF_FALSE) ;
|
Chris@0
|
423 test_write_float_or_die (file, 0, data_out + HALF_BUFFER_SIZE, HALF_BUFFER_SIZE, __LINE__) ;
|
Chris@0
|
424 sf_close (file) ;
|
Chris@0
|
425
|
Chris@0
|
426 memset (&buffer_in, 0, sizeof (buffer_in)) ;
|
Chris@0
|
427
|
Chris@0
|
428 file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
|
Chris@0
|
429
|
Chris@0
|
430 sfinfo.format &= (SF_FORMAT_TYPEMASK | SF_FORMAT_SUBMASK) ;
|
Chris@0
|
431
|
Chris@0
|
432 if (sfinfo.format != (filetype & (SF_FORMAT_TYPEMASK | SF_FORMAT_SUBMASK)))
|
Chris@0
|
433 { printf ("\n\nLine %d: Returned format incorrect (0x%08X => 0x%08X).\n\n", __LINE__, filetype, sfinfo.format) ;
|
Chris@0
|
434 exit (1) ;
|
Chris@0
|
435 } ;
|
Chris@0
|
436
|
Chris@0
|
437 if (sfinfo.frames != BUFFER_SIZE)
|
Chris@0
|
438 { printf ("\n\nLine %d: Incorrect number of frames in file (%d => %ld).\n\n", __LINE__, BUFFER_SIZE, SF_COUNT_TO_LONG (sfinfo.frames)) ;
|
Chris@0
|
439 exit (1) ;
|
Chris@0
|
440 } ;
|
Chris@0
|
441
|
Chris@0
|
442 if (sfinfo.channels != 1)
|
Chris@0
|
443 { printf ("\n\nLine %d: Incorrect number of channels in file.\n\n", __LINE__) ;
|
Chris@0
|
444 exit (1) ;
|
Chris@0
|
445 } ;
|
Chris@0
|
446
|
Chris@0
|
447 check_log_buffer_or_die (file, __LINE__) ;
|
Chris@0
|
448
|
Chris@0
|
449 test_read_float_or_die (file, 0, data_in, HALF_BUFFER_SIZE, __LINE__) ;
|
Chris@0
|
450 sf_command (file, SFC_SET_NORM_FLOAT, NULL, SF_FALSE) ;
|
Chris@0
|
451 test_read_float_or_die (file, 0, data_in + HALF_BUFFER_SIZE, HALF_BUFFER_SIZE, __LINE__) ;
|
Chris@0
|
452 sf_close (file) ;
|
Chris@0
|
453
|
Chris@0
|
454 /* Check normalized version. */
|
Chris@0
|
455 clip_max_diff = 0.0 ;
|
Chris@0
|
456 for (k = 0 ; k < HALF_BUFFER_SIZE ; k++)
|
Chris@0
|
457 { if (fabs (data_in [k]) > 1.0)
|
Chris@0
|
458 { printf ("\n\nLine %d: Input sample %d/%d (%f) has not been clipped.\n\n", __LINE__, k, BUFFER_SIZE, data_in [k]) ;
|
Chris@0
|
459 exit (1) ;
|
Chris@0
|
460 } ;
|
Chris@0
|
461
|
Chris@0
|
462 if (data_out [k] * data_in [k] < 0.0)
|
Chris@0
|
463 { printf ("\n\nLine %d: Data wrap around at index %d/%d.\n\n", __LINE__, k, BUFFER_SIZE) ;
|
Chris@0
|
464 exit (1) ;
|
Chris@0
|
465 } ;
|
Chris@0
|
466
|
Chris@0
|
467 if (fabs (data_out [k]) > 1.0)
|
Chris@0
|
468 continue ;
|
Chris@0
|
469
|
Chris@0
|
470 diff = fabs (data_out [k] - data_in [k]) ;
|
Chris@0
|
471 if (diff > clip_max_diff)
|
Chris@0
|
472 clip_max_diff = diff ;
|
Chris@0
|
473 } ;
|
Chris@0
|
474
|
Chris@0
|
475 if (clip_max_diff < 1e-20)
|
Chris@0
|
476 { printf ("\n\nLine %d: Clipping difference (%e) too small (normalized).\n\n", __LINE__, clip_max_diff) ;
|
Chris@0
|
477 exit (1) ;
|
Chris@0
|
478 } ;
|
Chris@0
|
479
|
Chris@0
|
480 if (clip_max_diff > 1.0 / 0x80000000)
|
Chris@0
|
481 { printf ("\n\nLine %d: Clipping difference (%e) too large (normalized).\n\n", __LINE__, clip_max_diff) ;
|
Chris@0
|
482 exit (1) ;
|
Chris@0
|
483 } ;
|
Chris@0
|
484
|
Chris@0
|
485 /* Check the un-normalized data. */
|
Chris@0
|
486 clip_max_diff = 0.0 ;
|
Chris@0
|
487 for (k = HALF_BUFFER_SIZE ; k < BUFFER_SIZE ; k++)
|
Chris@0
|
488 { if (fabs (data_in [k]) > maxval)
|
Chris@0
|
489 { printf ("\n\nLine %d: Input sample %d/%d (%f) has not been clipped.\n\n", __LINE__, k, BUFFER_SIZE, data_in [k]) ;
|
Chris@0
|
490 exit (1) ;
|
Chris@0
|
491 } ;
|
Chris@0
|
492
|
Chris@0
|
493 if (data_out [k] * data_in [k] < 0.0)
|
Chris@0
|
494 { printf ("\n\nLine %d: Data wrap around at index %d/%d.\n\n", __LINE__, k, BUFFER_SIZE) ;
|
Chris@0
|
495 exit (1) ;
|
Chris@0
|
496 } ;
|
Chris@0
|
497
|
Chris@0
|
498 if (fabs (data_out [k]) > maxval)
|
Chris@0
|
499 continue ;
|
Chris@0
|
500
|
Chris@0
|
501 diff = fabs (data_out [k] - data_in [k]) ;
|
Chris@0
|
502 if (diff > clip_max_diff)
|
Chris@0
|
503 clip_max_diff = diff ;
|
Chris@0
|
504 } ;
|
Chris@0
|
505
|
Chris@0
|
506 if (clip_max_diff < 1e-20)
|
Chris@0
|
507 { printf ("\n\nLine %d: Clipping difference (%e) too small (un-normalized).\n\n", __LINE__, clip_max_diff) ;
|
Chris@0
|
508 exit (1) ;
|
Chris@0
|
509 } ;
|
Chris@0
|
510
|
Chris@0
|
511 if (clip_max_diff > 1.0)
|
Chris@0
|
512 { printf ("\n\nLine %d: Clipping difference (%e) too large (un-normalised).\n\n", __LINE__, clip_max_diff) ;
|
Chris@0
|
513 exit (1) ;
|
Chris@0
|
514 } ;
|
Chris@0
|
515
|
Chris@0
|
516 printf ("ok\n") ;
|
Chris@0
|
517 unlink (filename) ;
|
Chris@0
|
518 } /* flt_scale_clip_test_32 */
|
Chris@0
|
519
|
Chris@0
|
520 static void
|
Chris@0
|
521 flt_scale_clip_test_08 (const char *filename, int filetype, float maxval)
|
Chris@0
|
522 { SNDFILE *file ;
|
Chris@0
|
523 SF_INFO sfinfo ;
|
Chris@0
|
524 int k ;
|
Chris@0
|
525 float *data_out, *data_in ;
|
Chris@0
|
526 double diff, clip_max_diff ;
|
Chris@0
|
527
|
Chris@0
|
528 print_test_name ("flt_scale_clip_test_08", filename) ;
|
Chris@0
|
529
|
Chris@0
|
530 data_out = buffer_out.flt ;
|
Chris@0
|
531 data_in = buffer_in.flt ;
|
Chris@0
|
532
|
Chris@0
|
533 for (k = 0 ; k < HALF_BUFFER_SIZE ; k++)
|
Chris@0
|
534 { data_out [k] = 1.2 * sin (2 * M_PI * k / HALF_BUFFER_SIZE) ;
|
Chris@0
|
535 data_out [k + HALF_BUFFER_SIZE] = data_out [k] * maxval ;
|
Chris@0
|
536 } ;
|
Chris@0
|
537
|
Chris@0
|
538 sfinfo.samplerate = 44100 ;
|
Chris@0
|
539 sfinfo.frames = 123456789 ; /* Wrong length. Library should correct this on sf_close. */
|
Chris@0
|
540 sfinfo.channels = 1 ;
|
Chris@0
|
541 sfinfo.format = filetype ;
|
Chris@0
|
542
|
Chris@0
|
543 /*
|
Chris@0
|
544 ** Write two versions of the data:
|
Chris@0
|
545 ** normalized and clipped
|
Chris@0
|
546 ** un-normalized and clipped.
|
Chris@0
|
547 */
|
Chris@0
|
548
|
Chris@0
|
549 file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
|
Chris@0
|
550 sf_command (file, SFC_SET_CLIPPING, NULL, SF_TRUE) ;
|
Chris@0
|
551 test_write_float_or_die (file, 0, data_out, HALF_BUFFER_SIZE, __LINE__) ;
|
Chris@0
|
552 sf_command (file, SFC_SET_NORM_FLOAT, NULL, SF_FALSE) ;
|
Chris@0
|
553 test_write_float_or_die (file, 0, data_out + HALF_BUFFER_SIZE, HALF_BUFFER_SIZE, __LINE__) ;
|
Chris@0
|
554 sf_close (file) ;
|
Chris@0
|
555
|
Chris@0
|
556 memset (&buffer_in, 0, sizeof (buffer_in)) ;
|
Chris@0
|
557
|
Chris@0
|
558 file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
|
Chris@0
|
559
|
Chris@0
|
560 sfinfo.format &= (SF_FORMAT_TYPEMASK | SF_FORMAT_SUBMASK) ;
|
Chris@0
|
561
|
Chris@0
|
562 if (sfinfo.format != (filetype & (SF_FORMAT_TYPEMASK | SF_FORMAT_SUBMASK)))
|
Chris@0
|
563 { printf ("\n\nLine %d: Returned format incorrect (0x%08X => 0x%08X).\n\n", __LINE__, filetype, sfinfo.format) ;
|
Chris@0
|
564 exit (1) ;
|
Chris@0
|
565 } ;
|
Chris@0
|
566
|
Chris@0
|
567 if (sfinfo.frames != BUFFER_SIZE)
|
Chris@0
|
568 { printf ("\n\nLine %d: Incorrect number of frames in file (%d => %ld).\n\n", __LINE__, BUFFER_SIZE, SF_COUNT_TO_LONG (sfinfo.frames)) ;
|
Chris@0
|
569 exit (1) ;
|
Chris@0
|
570 } ;
|
Chris@0
|
571
|
Chris@0
|
572 if (sfinfo.channels != 1)
|
Chris@0
|
573 { printf ("\n\nLine %d: Incorrect number of channels in file.\n\n", __LINE__) ;
|
Chris@0
|
574 exit (1) ;
|
Chris@0
|
575 } ;
|
Chris@0
|
576
|
Chris@0
|
577 check_log_buffer_or_die (file, __LINE__) ;
|
Chris@0
|
578
|
Chris@0
|
579 test_read_float_or_die (file, 0, data_in, HALF_BUFFER_SIZE, __LINE__) ;
|
Chris@0
|
580 sf_command (file, SFC_SET_NORM_FLOAT, NULL, SF_FALSE) ;
|
Chris@0
|
581 test_read_float_or_die (file, 0, data_in + HALF_BUFFER_SIZE, HALF_BUFFER_SIZE, __LINE__) ;
|
Chris@0
|
582 sf_close (file) ;
|
Chris@0
|
583
|
Chris@0
|
584 /* Check normalized version. */
|
Chris@0
|
585 clip_max_diff = 0.0 ;
|
Chris@0
|
586 for (k = 0 ; k < HALF_BUFFER_SIZE ; k++)
|
Chris@0
|
587 { if (fabs (data_in [k]) > 1.0)
|
Chris@0
|
588 { printf ("\n\nLine %d: Input sample %d/%d (%f) has not been clipped.\n\n", __LINE__, k, BUFFER_SIZE, data_in [k]) ;
|
Chris@0
|
589 exit (1) ;
|
Chris@0
|
590 } ;
|
Chris@0
|
591
|
Chris@0
|
592 if (data_out [k] * data_in [k] < 0.0)
|
Chris@0
|
593 { printf ("\n\nLine %d: Data wrap around at index %d/%d.\n\n", __LINE__, k, BUFFER_SIZE) ;
|
Chris@0
|
594 exit (1) ;
|
Chris@0
|
595 } ;
|
Chris@0
|
596
|
Chris@0
|
597 if (fabs (data_out [k]) > 1.0)
|
Chris@0
|
598 continue ;
|
Chris@0
|
599
|
Chris@0
|
600 diff = fabs (data_out [k] - data_in [k]) ;
|
Chris@0
|
601 if (diff > clip_max_diff)
|
Chris@0
|
602 clip_max_diff = diff ;
|
Chris@0
|
603 } ;
|
Chris@0
|
604
|
Chris@0
|
605 if (clip_max_diff < 1e-20)
|
Chris@0
|
606 { printf ("\n\nLine %d: Clipping difference (%e) too small (normalized).\n\n", __LINE__, clip_max_diff) ;
|
Chris@0
|
607 exit (1) ;
|
Chris@0
|
608 } ;
|
Chris@0
|
609
|
Chris@0
|
610 if (clip_max_diff > 1.0 / 0x80)
|
Chris@0
|
611 { printf ("\n\nLine %d: Clipping difference (%e) too large (normalized).\n\n", __LINE__, clip_max_diff) ;
|
Chris@0
|
612 exit (1) ;
|
Chris@0
|
613 } ;
|
Chris@0
|
614
|
Chris@0
|
615 /* Check the un-normalized data. */
|
Chris@0
|
616 clip_max_diff = 0.0 ;
|
Chris@0
|
617 for (k = HALF_BUFFER_SIZE ; k < BUFFER_SIZE ; k++)
|
Chris@0
|
618 { if (fabs (data_in [k]) > maxval)
|
Chris@0
|
619 { printf ("\n\nLine %d: Input sample %d/%d (%f) has not been clipped.\n\n", __LINE__, k, BUFFER_SIZE, data_in [k]) ;
|
Chris@0
|
620 exit (1) ;
|
Chris@0
|
621 } ;
|
Chris@0
|
622
|
Chris@0
|
623 if (data_out [k] * data_in [k] < 0.0)
|
Chris@0
|
624 { printf ("\n\nLine %d: Data wrap around at index %d/%d.\n\n", __LINE__, k, BUFFER_SIZE) ;
|
Chris@0
|
625 exit (1) ;
|
Chris@0
|
626 } ;
|
Chris@0
|
627
|
Chris@0
|
628 if (fabs (data_out [k]) > maxval)
|
Chris@0
|
629 continue ;
|
Chris@0
|
630
|
Chris@0
|
631 diff = fabs (data_out [k] - data_in [k]) ;
|
Chris@0
|
632 if (diff > clip_max_diff)
|
Chris@0
|
633 clip_max_diff = diff ;
|
Chris@0
|
634 } ;
|
Chris@0
|
635
|
Chris@0
|
636 if (clip_max_diff < 1e-20)
|
Chris@0
|
637 { printf ("\n\nLine %d: Clipping difference (%e) too small (un-normalized).\n\n", __LINE__, clip_max_diff) ;
|
Chris@0
|
638 exit (1) ;
|
Chris@0
|
639 } ;
|
Chris@0
|
640
|
Chris@0
|
641 if (clip_max_diff > 1.0)
|
Chris@0
|
642 { printf ("\n\nLine %d: Clipping difference (%e) too large (un-normalised).\n\n", __LINE__, clip_max_diff) ;
|
Chris@0
|
643 exit (1) ;
|
Chris@0
|
644 } ;
|
Chris@0
|
645
|
Chris@0
|
646 printf ("ok\n") ;
|
Chris@0
|
647 unlink (filename) ;
|
Chris@0
|
648 } /* flt_scale_clip_test_08 */
|
Chris@0
|
649
|
Chris@0
|
650
|
Chris@0
|
651
|
Chris@0
|
652 static void
|
Chris@0
|
653 dbl_scale_clip_test_16 (const char *filename, int filetype, float maxval)
|
Chris@0
|
654 { SNDFILE *file ;
|
Chris@0
|
655 SF_INFO sfinfo ;
|
Chris@0
|
656 int k ;
|
Chris@0
|
657 double *data_out, *data_in ;
|
Chris@0
|
658 double diff, clip_max_diff ;
|
Chris@0
|
659
|
Chris@0
|
660 print_test_name ("dbl_scale_clip_test_16", filename) ;
|
Chris@0
|
661
|
Chris@0
|
662 data_out = buffer_out.dbl ;
|
Chris@0
|
663 data_in = buffer_in.dbl ;
|
Chris@0
|
664
|
Chris@0
|
665 for (k = 0 ; k < HALF_BUFFER_SIZE ; k++)
|
Chris@0
|
666 { data_out [k] = 1.2 * sin (2 * M_PI * k / HALF_BUFFER_SIZE) ;
|
Chris@0
|
667 data_out [k + HALF_BUFFER_SIZE] = data_out [k] * maxval ;
|
Chris@0
|
668 } ;
|
Chris@0
|
669
|
Chris@0
|
670 sfinfo.samplerate = 44100 ;
|
Chris@0
|
671 sfinfo.frames = 123456789 ; /* Wrong length. Library should correct this on sf_close. */
|
Chris@0
|
672 sfinfo.channels = 1 ;
|
Chris@0
|
673 sfinfo.format = filetype ;
|
Chris@0
|
674
|
Chris@0
|
675 /*
|
Chris@0
|
676 ** Write two versions of the data:
|
Chris@0
|
677 ** normalized and clipped
|
Chris@0
|
678 ** un-normalized and clipped.
|
Chris@0
|
679 */
|
Chris@0
|
680
|
Chris@0
|
681 file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
|
Chris@0
|
682 sf_command (file, SFC_SET_CLIPPING, NULL, SF_TRUE) ;
|
Chris@0
|
683 test_write_double_or_die (file, 0, data_out, HALF_BUFFER_SIZE, __LINE__) ;
|
Chris@0
|
684 sf_command (file, SFC_SET_NORM_DOUBLE, NULL, SF_FALSE) ;
|
Chris@0
|
685 test_write_double_or_die (file, 0, data_out + HALF_BUFFER_SIZE, HALF_BUFFER_SIZE, __LINE__) ;
|
Chris@0
|
686 sf_close (file) ;
|
Chris@0
|
687
|
Chris@0
|
688 memset (&buffer_in, 0, sizeof (buffer_in)) ;
|
Chris@0
|
689
|
Chris@0
|
690 file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
|
Chris@0
|
691
|
Chris@0
|
692 sfinfo.format &= (SF_FORMAT_TYPEMASK | SF_FORMAT_SUBMASK) ;
|
Chris@0
|
693
|
Chris@0
|
694 if (sfinfo.format != (filetype & (SF_FORMAT_TYPEMASK | SF_FORMAT_SUBMASK)))
|
Chris@0
|
695 { printf ("\n\nLine %d: Returned format incorrect (0x%08X => 0x%08X).\n\n", __LINE__, filetype, sfinfo.format) ;
|
Chris@0
|
696 exit (1) ;
|
Chris@0
|
697 } ;
|
Chris@0
|
698
|
Chris@0
|
699 if (sfinfo.frames != BUFFER_SIZE)
|
Chris@0
|
700 { printf ("\n\nLine %d: Incorrect number of frames in file (%d => %ld).\n\n", __LINE__, BUFFER_SIZE, SF_COUNT_TO_LONG (sfinfo.frames)) ;
|
Chris@0
|
701 exit (1) ;
|
Chris@0
|
702 } ;
|
Chris@0
|
703
|
Chris@0
|
704 if (sfinfo.channels != 1)
|
Chris@0
|
705 { printf ("\n\nLine %d: Incorrect number of channels in file.\n\n", __LINE__) ;
|
Chris@0
|
706 exit (1) ;
|
Chris@0
|
707 } ;
|
Chris@0
|
708
|
Chris@0
|
709 check_log_buffer_or_die (file, __LINE__) ;
|
Chris@0
|
710
|
Chris@0
|
711 test_read_double_or_die (file, 0, data_in, HALF_BUFFER_SIZE, __LINE__) ;
|
Chris@0
|
712 sf_command (file, SFC_SET_NORM_DOUBLE, NULL, SF_FALSE) ;
|
Chris@0
|
713 test_read_double_or_die (file, 0, data_in + HALF_BUFFER_SIZE, HALF_BUFFER_SIZE, __LINE__) ;
|
Chris@0
|
714 sf_close (file) ;
|
Chris@0
|
715
|
Chris@0
|
716 /* Check normalized version. */
|
Chris@0
|
717 clip_max_diff = 0.0 ;
|
Chris@0
|
718 for (k = 0 ; k < HALF_BUFFER_SIZE ; k++)
|
Chris@0
|
719 { if (fabs (data_in [k]) > 1.0)
|
Chris@0
|
720 { printf ("\n\nLine %d: Input sample %d/%d (%f) has not been clipped.\n\n", __LINE__, k, BUFFER_SIZE, data_in [k]) ;
|
Chris@0
|
721 exit (1) ;
|
Chris@0
|
722 } ;
|
Chris@0
|
723
|
Chris@0
|
724 if (data_out [k] * data_in [k] < 0.0)
|
Chris@0
|
725 { printf ("\n\nLine %d: Data wrap around at index %d/%d.\n\n", __LINE__, k, BUFFER_SIZE) ;
|
Chris@0
|
726 exit (1) ;
|
Chris@0
|
727 } ;
|
Chris@0
|
728
|
Chris@0
|
729 if (fabs (data_out [k]) > 1.0)
|
Chris@0
|
730 continue ;
|
Chris@0
|
731
|
Chris@0
|
732 diff = fabs (data_out [k] - data_in [k]) ;
|
Chris@0
|
733 if (diff > clip_max_diff)
|
Chris@0
|
734 clip_max_diff = diff ;
|
Chris@0
|
735 } ;
|
Chris@0
|
736
|
Chris@0
|
737 if (clip_max_diff < 1e-20)
|
Chris@0
|
738 { printf ("\n\nLine %d: Clipping difference (%e) too small (normalized).\n\n", __LINE__, clip_max_diff) ;
|
Chris@0
|
739 exit (1) ;
|
Chris@0
|
740 } ;
|
Chris@0
|
741
|
Chris@0
|
742 if (clip_max_diff > 1.0 / 0x8000)
|
Chris@0
|
743 { printf ("\n\nLine %d: Clipping difference (%e) too large (normalized).\n\n", __LINE__, clip_max_diff) ;
|
Chris@0
|
744 exit (1) ;
|
Chris@0
|
745 } ;
|
Chris@0
|
746
|
Chris@0
|
747 /* Check the un-normalized data. */
|
Chris@0
|
748 clip_max_diff = 0.0 ;
|
Chris@0
|
749 for (k = HALF_BUFFER_SIZE ; k < BUFFER_SIZE ; k++)
|
Chris@0
|
750 { if (fabs (data_in [k]) > maxval)
|
Chris@0
|
751 { printf ("\n\nLine %d: Input sample %d/%d (%f) has not been clipped.\n\n", __LINE__, k, BUFFER_SIZE, data_in [k]) ;
|
Chris@0
|
752 exit (1) ;
|
Chris@0
|
753 } ;
|
Chris@0
|
754
|
Chris@0
|
755 if (data_out [k] * data_in [k] < 0.0)
|
Chris@0
|
756 { printf ("\n\nLine %d: Data wrap around at index %d/%d.\n\n", __LINE__, k, BUFFER_SIZE) ;
|
Chris@0
|
757 exit (1) ;
|
Chris@0
|
758 } ;
|
Chris@0
|
759
|
Chris@0
|
760 if (fabs (data_out [k]) > maxval)
|
Chris@0
|
761 continue ;
|
Chris@0
|
762
|
Chris@0
|
763 diff = fabs (data_out [k] - data_in [k]) ;
|
Chris@0
|
764 if (diff > clip_max_diff)
|
Chris@0
|
765 clip_max_diff = diff ;
|
Chris@0
|
766 } ;
|
Chris@0
|
767
|
Chris@0
|
768 if (clip_max_diff < 1e-20)
|
Chris@0
|
769 { printf ("\n\nLine %d: Clipping difference (%e) too small (un-normalized).\n\n", __LINE__, clip_max_diff) ;
|
Chris@0
|
770 exit (1) ;
|
Chris@0
|
771 } ;
|
Chris@0
|
772
|
Chris@0
|
773 if (clip_max_diff > 1.0)
|
Chris@0
|
774 { printf ("\n\nLine %d: Clipping difference (%e) too large (un-normalised).\n\n", __LINE__, clip_max_diff) ;
|
Chris@0
|
775 exit (1) ;
|
Chris@0
|
776 } ;
|
Chris@0
|
777
|
Chris@0
|
778 printf ("ok\n") ;
|
Chris@0
|
779 unlink (filename) ;
|
Chris@0
|
780 } /* dbl_scale_clip_test_16 */
|
Chris@0
|
781
|
Chris@0
|
782 static void
|
Chris@0
|
783 dbl_scale_clip_test_24 (const char *filename, int filetype, float maxval)
|
Chris@0
|
784 { SNDFILE *file ;
|
Chris@0
|
785 SF_INFO sfinfo ;
|
Chris@0
|
786 int k ;
|
Chris@0
|
787 double *data_out, *data_in ;
|
Chris@0
|
788 double diff, clip_max_diff ;
|
Chris@0
|
789
|
Chris@0
|
790 print_test_name ("dbl_scale_clip_test_24", filename) ;
|
Chris@0
|
791
|
Chris@0
|
792 data_out = buffer_out.dbl ;
|
Chris@0
|
793 data_in = buffer_in.dbl ;
|
Chris@0
|
794
|
Chris@0
|
795 for (k = 0 ; k < HALF_BUFFER_SIZE ; k++)
|
Chris@0
|
796 { data_out [k] = 1.2 * sin (2 * M_PI * k / HALF_BUFFER_SIZE) ;
|
Chris@0
|
797 data_out [k + HALF_BUFFER_SIZE] = data_out [k] * maxval ;
|
Chris@0
|
798 } ;
|
Chris@0
|
799
|
Chris@0
|
800 sfinfo.samplerate = 44100 ;
|
Chris@0
|
801 sfinfo.frames = 123456789 ; /* Wrong length. Library should correct this on sf_close. */
|
Chris@0
|
802 sfinfo.channels = 1 ;
|
Chris@0
|
803 sfinfo.format = filetype ;
|
Chris@0
|
804
|
Chris@0
|
805 /*
|
Chris@0
|
806 ** Write two versions of the data:
|
Chris@0
|
807 ** normalized and clipped
|
Chris@0
|
808 ** un-normalized and clipped.
|
Chris@0
|
809 */
|
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_SET_CLIPPING, NULL, SF_TRUE) ;
|
Chris@0
|
813 test_write_double_or_die (file, 0, data_out, HALF_BUFFER_SIZE, __LINE__) ;
|
Chris@0
|
814 sf_command (file, SFC_SET_NORM_DOUBLE, NULL, SF_FALSE) ;
|
Chris@0
|
815 test_write_double_or_die (file, 0, data_out + HALF_BUFFER_SIZE, HALF_BUFFER_SIZE, __LINE__) ;
|
Chris@0
|
816 sf_close (file) ;
|
Chris@0
|
817
|
Chris@0
|
818 memset (&buffer_in, 0, sizeof (buffer_in)) ;
|
Chris@0
|
819
|
Chris@0
|
820 file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
|
Chris@0
|
821
|
Chris@0
|
822 sfinfo.format &= (SF_FORMAT_TYPEMASK | SF_FORMAT_SUBMASK) ;
|
Chris@0
|
823
|
Chris@0
|
824 if (sfinfo.format != (filetype & (SF_FORMAT_TYPEMASK | SF_FORMAT_SUBMASK)))
|
Chris@0
|
825 { printf ("\n\nLine %d: Returned format incorrect (0x%08X => 0x%08X).\n\n", __LINE__, filetype, sfinfo.format) ;
|
Chris@0
|
826 exit (1) ;
|
Chris@0
|
827 } ;
|
Chris@0
|
828
|
Chris@0
|
829 if (sfinfo.frames != BUFFER_SIZE)
|
Chris@0
|
830 { printf ("\n\nLine %d: Incorrect number of frames in file (%d => %ld).\n\n", __LINE__, BUFFER_SIZE, SF_COUNT_TO_LONG (sfinfo.frames)) ;
|
Chris@0
|
831 exit (1) ;
|
Chris@0
|
832 } ;
|
Chris@0
|
833
|
Chris@0
|
834 if (sfinfo.channels != 1)
|
Chris@0
|
835 { printf ("\n\nLine %d: Incorrect number of channels in file.\n\n", __LINE__) ;
|
Chris@0
|
836 exit (1) ;
|
Chris@0
|
837 } ;
|
Chris@0
|
838
|
Chris@0
|
839 check_log_buffer_or_die (file, __LINE__) ;
|
Chris@0
|
840
|
Chris@0
|
841 test_read_double_or_die (file, 0, data_in, HALF_BUFFER_SIZE, __LINE__) ;
|
Chris@0
|
842 sf_command (file, SFC_SET_NORM_DOUBLE, NULL, SF_FALSE) ;
|
Chris@0
|
843 test_read_double_or_die (file, 0, data_in + HALF_BUFFER_SIZE, HALF_BUFFER_SIZE, __LINE__) ;
|
Chris@0
|
844 sf_close (file) ;
|
Chris@0
|
845
|
Chris@0
|
846 /* Check normalized version. */
|
Chris@0
|
847 clip_max_diff = 0.0 ;
|
Chris@0
|
848 for (k = 0 ; k < HALF_BUFFER_SIZE ; k++)
|
Chris@0
|
849 { if (fabs (data_in [k]) > 1.0)
|
Chris@0
|
850 { printf ("\n\nLine %d: Input sample %d/%d (%f) has not been clipped.\n\n", __LINE__, k, BUFFER_SIZE, data_in [k]) ;
|
Chris@0
|
851 exit (1) ;
|
Chris@0
|
852 } ;
|
Chris@0
|
853
|
Chris@0
|
854 if (data_out [k] * data_in [k] < 0.0)
|
Chris@0
|
855 { printf ("\n\nLine %d: Data wrap around at index %d/%d.\n\n", __LINE__, k, BUFFER_SIZE) ;
|
Chris@0
|
856 exit (1) ;
|
Chris@0
|
857 } ;
|
Chris@0
|
858
|
Chris@0
|
859 if (fabs (data_out [k]) > 1.0)
|
Chris@0
|
860 continue ;
|
Chris@0
|
861
|
Chris@0
|
862 diff = fabs (data_out [k] - data_in [k]) ;
|
Chris@0
|
863 if (diff > clip_max_diff)
|
Chris@0
|
864 clip_max_diff = diff ;
|
Chris@0
|
865 } ;
|
Chris@0
|
866
|
Chris@0
|
867 if (clip_max_diff < 1e-20)
|
Chris@0
|
868 { printf ("\n\nLine %d: Clipping difference (%e) too small (normalized).\n\n", __LINE__, clip_max_diff) ;
|
Chris@0
|
869 exit (1) ;
|
Chris@0
|
870 } ;
|
Chris@0
|
871
|
Chris@0
|
872 if (clip_max_diff > 1.0 / 0x800000)
|
Chris@0
|
873 { printf ("\n\nLine %d: Clipping difference (%e) too large (normalized).\n\n", __LINE__, clip_max_diff) ;
|
Chris@0
|
874 exit (1) ;
|
Chris@0
|
875 } ;
|
Chris@0
|
876
|
Chris@0
|
877 /* Check the un-normalized data. */
|
Chris@0
|
878 clip_max_diff = 0.0 ;
|
Chris@0
|
879 for (k = HALF_BUFFER_SIZE ; k < BUFFER_SIZE ; k++)
|
Chris@0
|
880 { if (fabs (data_in [k]) > maxval)
|
Chris@0
|
881 { printf ("\n\nLine %d: Input sample %d/%d (%f) has not been clipped.\n\n", __LINE__, k, BUFFER_SIZE, data_in [k]) ;
|
Chris@0
|
882 exit (1) ;
|
Chris@0
|
883 } ;
|
Chris@0
|
884
|
Chris@0
|
885 if (data_out [k] * data_in [k] < 0.0)
|
Chris@0
|
886 { printf ("\n\nLine %d: Data wrap around at index %d/%d.\n\n", __LINE__, k, BUFFER_SIZE) ;
|
Chris@0
|
887 exit (1) ;
|
Chris@0
|
888 } ;
|
Chris@0
|
889
|
Chris@0
|
890 if (fabs (data_out [k]) > maxval)
|
Chris@0
|
891 continue ;
|
Chris@0
|
892
|
Chris@0
|
893 diff = fabs (data_out [k] - data_in [k]) ;
|
Chris@0
|
894 if (diff > clip_max_diff)
|
Chris@0
|
895 clip_max_diff = diff ;
|
Chris@0
|
896 } ;
|
Chris@0
|
897
|
Chris@0
|
898 if (clip_max_diff < 1e-20)
|
Chris@0
|
899 { printf ("\n\nLine %d: Clipping difference (%e) too small (un-normalized).\n\n", __LINE__, clip_max_diff) ;
|
Chris@0
|
900 exit (1) ;
|
Chris@0
|
901 } ;
|
Chris@0
|
902
|
Chris@0
|
903 if (clip_max_diff > 1.0)
|
Chris@0
|
904 { printf ("\n\nLine %d: Clipping difference (%e) too large (un-normalised).\n\n", __LINE__, clip_max_diff) ;
|
Chris@0
|
905 exit (1) ;
|
Chris@0
|
906 } ;
|
Chris@0
|
907
|
Chris@0
|
908 printf ("ok\n") ;
|
Chris@0
|
909 unlink (filename) ;
|
Chris@0
|
910 } /* dbl_scale_clip_test_24 */
|
Chris@0
|
911
|
Chris@0
|
912 static void
|
Chris@0
|
913 dbl_scale_clip_test_32 (const char *filename, int filetype, float maxval)
|
Chris@0
|
914 { SNDFILE *file ;
|
Chris@0
|
915 SF_INFO sfinfo ;
|
Chris@0
|
916 int k ;
|
Chris@0
|
917 double *data_out, *data_in ;
|
Chris@0
|
918 double diff, clip_max_diff ;
|
Chris@0
|
919
|
Chris@0
|
920 print_test_name ("dbl_scale_clip_test_32", filename) ;
|
Chris@0
|
921
|
Chris@0
|
922 data_out = buffer_out.dbl ;
|
Chris@0
|
923 data_in = buffer_in.dbl ;
|
Chris@0
|
924
|
Chris@0
|
925 for (k = 0 ; k < HALF_BUFFER_SIZE ; k++)
|
Chris@0
|
926 { data_out [k] = 1.2 * sin (2 * M_PI * k / HALF_BUFFER_SIZE) ;
|
Chris@0
|
927 data_out [k + HALF_BUFFER_SIZE] = data_out [k] * maxval ;
|
Chris@0
|
928 } ;
|
Chris@0
|
929
|
Chris@0
|
930 sfinfo.samplerate = 44100 ;
|
Chris@0
|
931 sfinfo.frames = 123456789 ; /* Wrong length. Library should correct this on sf_close. */
|
Chris@0
|
932 sfinfo.channels = 1 ;
|
Chris@0
|
933 sfinfo.format = filetype ;
|
Chris@0
|
934
|
Chris@0
|
935 /*
|
Chris@0
|
936 ** Write two versions of the data:
|
Chris@0
|
937 ** normalized and clipped
|
Chris@0
|
938 ** un-normalized and clipped.
|
Chris@0
|
939 */
|
Chris@0
|
940
|
Chris@0
|
941 file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
|
Chris@0
|
942 sf_command (file, SFC_SET_CLIPPING, NULL, SF_TRUE) ;
|
Chris@0
|
943 test_write_double_or_die (file, 0, data_out, HALF_BUFFER_SIZE, __LINE__) ;
|
Chris@0
|
944 sf_command (file, SFC_SET_NORM_DOUBLE, NULL, SF_FALSE) ;
|
Chris@0
|
945 test_write_double_or_die (file, 0, data_out + HALF_BUFFER_SIZE, HALF_BUFFER_SIZE, __LINE__) ;
|
Chris@0
|
946 sf_close (file) ;
|
Chris@0
|
947
|
Chris@0
|
948 memset (&buffer_in, 0, sizeof (buffer_in)) ;
|
Chris@0
|
949
|
Chris@0
|
950 file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
|
Chris@0
|
951
|
Chris@0
|
952 sfinfo.format &= (SF_FORMAT_TYPEMASK | SF_FORMAT_SUBMASK) ;
|
Chris@0
|
953
|
Chris@0
|
954 if (sfinfo.format != (filetype & (SF_FORMAT_TYPEMASK | SF_FORMAT_SUBMASK)))
|
Chris@0
|
955 { printf ("\n\nLine %d: Returned format incorrect (0x%08X => 0x%08X).\n\n", __LINE__, filetype, sfinfo.format) ;
|
Chris@0
|
956 exit (1) ;
|
Chris@0
|
957 } ;
|
Chris@0
|
958
|
Chris@0
|
959 if (sfinfo.frames != BUFFER_SIZE)
|
Chris@0
|
960 { printf ("\n\nLine %d: Incorrect number of frames in file (%d => %ld).\n\n", __LINE__, BUFFER_SIZE, SF_COUNT_TO_LONG (sfinfo.frames)) ;
|
Chris@0
|
961 exit (1) ;
|
Chris@0
|
962 } ;
|
Chris@0
|
963
|
Chris@0
|
964 if (sfinfo.channels != 1)
|
Chris@0
|
965 { printf ("\n\nLine %d: Incorrect number of channels in file.\n\n", __LINE__) ;
|
Chris@0
|
966 exit (1) ;
|
Chris@0
|
967 } ;
|
Chris@0
|
968
|
Chris@0
|
969 check_log_buffer_or_die (file, __LINE__) ;
|
Chris@0
|
970
|
Chris@0
|
971 test_read_double_or_die (file, 0, data_in, HALF_BUFFER_SIZE, __LINE__) ;
|
Chris@0
|
972 sf_command (file, SFC_SET_NORM_DOUBLE, NULL, SF_FALSE) ;
|
Chris@0
|
973 test_read_double_or_die (file, 0, data_in + HALF_BUFFER_SIZE, HALF_BUFFER_SIZE, __LINE__) ;
|
Chris@0
|
974 sf_close (file) ;
|
Chris@0
|
975
|
Chris@0
|
976 /* Check normalized version. */
|
Chris@0
|
977 clip_max_diff = 0.0 ;
|
Chris@0
|
978 for (k = 0 ; k < HALF_BUFFER_SIZE ; k++)
|
Chris@0
|
979 { if (fabs (data_in [k]) > 1.0)
|
Chris@0
|
980 { printf ("\n\nLine %d: Input sample %d/%d (%f) has not been clipped.\n\n", __LINE__, k, BUFFER_SIZE, data_in [k]) ;
|
Chris@0
|
981 exit (1) ;
|
Chris@0
|
982 } ;
|
Chris@0
|
983
|
Chris@0
|
984 if (data_out [k] * data_in [k] < 0.0)
|
Chris@0
|
985 { printf ("\n\nLine %d: Data wrap around at index %d/%d.\n\n", __LINE__, k, BUFFER_SIZE) ;
|
Chris@0
|
986 exit (1) ;
|
Chris@0
|
987 } ;
|
Chris@0
|
988
|
Chris@0
|
989 if (fabs (data_out [k]) > 1.0)
|
Chris@0
|
990 continue ;
|
Chris@0
|
991
|
Chris@0
|
992 diff = fabs (data_out [k] - data_in [k]) ;
|
Chris@0
|
993 if (diff > clip_max_diff)
|
Chris@0
|
994 clip_max_diff = diff ;
|
Chris@0
|
995 } ;
|
Chris@0
|
996
|
Chris@0
|
997 if (clip_max_diff < 1e-20)
|
Chris@0
|
998 { printf ("\n\nLine %d: Clipping difference (%e) too small (normalized).\n\n", __LINE__, clip_max_diff) ;
|
Chris@0
|
999 exit (1) ;
|
Chris@0
|
1000 } ;
|
Chris@0
|
1001
|
Chris@0
|
1002 if (clip_max_diff > 1.0 / 0x80000000)
|
Chris@0
|
1003 { printf ("\n\nLine %d: Clipping difference (%e) too large (normalized).\n\n", __LINE__, clip_max_diff) ;
|
Chris@0
|
1004 exit (1) ;
|
Chris@0
|
1005 } ;
|
Chris@0
|
1006
|
Chris@0
|
1007 /* Check the un-normalized data. */
|
Chris@0
|
1008 clip_max_diff = 0.0 ;
|
Chris@0
|
1009 for (k = HALF_BUFFER_SIZE ; k < BUFFER_SIZE ; k++)
|
Chris@0
|
1010 { if (fabs (data_in [k]) > maxval)
|
Chris@0
|
1011 { printf ("\n\nLine %d: Input sample %d/%d (%f) has not been clipped.\n\n", __LINE__, k, BUFFER_SIZE, data_in [k]) ;
|
Chris@0
|
1012 exit (1) ;
|
Chris@0
|
1013 } ;
|
Chris@0
|
1014
|
Chris@0
|
1015 if (data_out [k] * data_in [k] < 0.0)
|
Chris@0
|
1016 { printf ("\n\nLine %d: Data wrap around at index %d/%d.\n\n", __LINE__, k, BUFFER_SIZE) ;
|
Chris@0
|
1017 exit (1) ;
|
Chris@0
|
1018 } ;
|
Chris@0
|
1019
|
Chris@0
|
1020 if (fabs (data_out [k]) > maxval)
|
Chris@0
|
1021 continue ;
|
Chris@0
|
1022
|
Chris@0
|
1023 diff = fabs (data_out [k] - data_in [k]) ;
|
Chris@0
|
1024 if (diff > clip_max_diff)
|
Chris@0
|
1025 clip_max_diff = diff ;
|
Chris@0
|
1026 } ;
|
Chris@0
|
1027
|
Chris@0
|
1028 if (clip_max_diff < 1e-20)
|
Chris@0
|
1029 { printf ("\n\nLine %d: Clipping difference (%e) too small (un-normalized).\n\n", __LINE__, clip_max_diff) ;
|
Chris@0
|
1030 exit (1) ;
|
Chris@0
|
1031 } ;
|
Chris@0
|
1032
|
Chris@0
|
1033 if (clip_max_diff > 1.0)
|
Chris@0
|
1034 { printf ("\n\nLine %d: Clipping difference (%e) too large (un-normalised).\n\n", __LINE__, clip_max_diff) ;
|
Chris@0
|
1035 exit (1) ;
|
Chris@0
|
1036 } ;
|
Chris@0
|
1037
|
Chris@0
|
1038 printf ("ok\n") ;
|
Chris@0
|
1039 unlink (filename) ;
|
Chris@0
|
1040 } /* dbl_scale_clip_test_32 */
|
Chris@0
|
1041
|
Chris@0
|
1042 static void
|
Chris@0
|
1043 dbl_scale_clip_test_08 (const char *filename, int filetype, float maxval)
|
Chris@0
|
1044 { SNDFILE *file ;
|
Chris@0
|
1045 SF_INFO sfinfo ;
|
Chris@0
|
1046 int k ;
|
Chris@0
|
1047 double *data_out, *data_in ;
|
Chris@0
|
1048 double diff, clip_max_diff ;
|
Chris@0
|
1049
|
Chris@0
|
1050 print_test_name ("dbl_scale_clip_test_08", filename) ;
|
Chris@0
|
1051
|
Chris@0
|
1052 data_out = buffer_out.dbl ;
|
Chris@0
|
1053 data_in = buffer_in.dbl ;
|
Chris@0
|
1054
|
Chris@0
|
1055 for (k = 0 ; k < HALF_BUFFER_SIZE ; k++)
|
Chris@0
|
1056 { data_out [k] = 1.2 * sin (2 * M_PI * k / HALF_BUFFER_SIZE) ;
|
Chris@0
|
1057 data_out [k + HALF_BUFFER_SIZE] = data_out [k] * maxval ;
|
Chris@0
|
1058 } ;
|
Chris@0
|
1059
|
Chris@0
|
1060 sfinfo.samplerate = 44100 ;
|
Chris@0
|
1061 sfinfo.frames = 123456789 ; /* Wrong length. Library should correct this on sf_close. */
|
Chris@0
|
1062 sfinfo.channels = 1 ;
|
Chris@0
|
1063 sfinfo.format = filetype ;
|
Chris@0
|
1064
|
Chris@0
|
1065 /*
|
Chris@0
|
1066 ** Write two versions of the data:
|
Chris@0
|
1067 ** normalized and clipped
|
Chris@0
|
1068 ** un-normalized and clipped.
|
Chris@0
|
1069 */
|
Chris@0
|
1070
|
Chris@0
|
1071 file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
|
Chris@0
|
1072 sf_command (file, SFC_SET_CLIPPING, NULL, SF_TRUE) ;
|
Chris@0
|
1073 test_write_double_or_die (file, 0, data_out, HALF_BUFFER_SIZE, __LINE__) ;
|
Chris@0
|
1074 sf_command (file, SFC_SET_NORM_DOUBLE, NULL, SF_FALSE) ;
|
Chris@0
|
1075 test_write_double_or_die (file, 0, data_out + HALF_BUFFER_SIZE, HALF_BUFFER_SIZE, __LINE__) ;
|
Chris@0
|
1076 sf_close (file) ;
|
Chris@0
|
1077
|
Chris@0
|
1078 memset (&buffer_in, 0, sizeof (buffer_in)) ;
|
Chris@0
|
1079
|
Chris@0
|
1080 file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
|
Chris@0
|
1081
|
Chris@0
|
1082 sfinfo.format &= (SF_FORMAT_TYPEMASK | SF_FORMAT_SUBMASK) ;
|
Chris@0
|
1083
|
Chris@0
|
1084 if (sfinfo.format != (filetype & (SF_FORMAT_TYPEMASK | SF_FORMAT_SUBMASK)))
|
Chris@0
|
1085 { printf ("\n\nLine %d: Returned format incorrect (0x%08X => 0x%08X).\n\n", __LINE__, filetype, sfinfo.format) ;
|
Chris@0
|
1086 exit (1) ;
|
Chris@0
|
1087 } ;
|
Chris@0
|
1088
|
Chris@0
|
1089 if (sfinfo.frames != BUFFER_SIZE)
|
Chris@0
|
1090 { printf ("\n\nLine %d: Incorrect number of frames in file (%d => %ld).\n\n", __LINE__, BUFFER_SIZE, SF_COUNT_TO_LONG (sfinfo.frames)) ;
|
Chris@0
|
1091 exit (1) ;
|
Chris@0
|
1092 } ;
|
Chris@0
|
1093
|
Chris@0
|
1094 if (sfinfo.channels != 1)
|
Chris@0
|
1095 { printf ("\n\nLine %d: Incorrect number of channels in file.\n\n", __LINE__) ;
|
Chris@0
|
1096 exit (1) ;
|
Chris@0
|
1097 } ;
|
Chris@0
|
1098
|
Chris@0
|
1099 check_log_buffer_or_die (file, __LINE__) ;
|
Chris@0
|
1100
|
Chris@0
|
1101 test_read_double_or_die (file, 0, data_in, HALF_BUFFER_SIZE, __LINE__) ;
|
Chris@0
|
1102 sf_command (file, SFC_SET_NORM_DOUBLE, NULL, SF_FALSE) ;
|
Chris@0
|
1103 test_read_double_or_die (file, 0, data_in + HALF_BUFFER_SIZE, HALF_BUFFER_SIZE, __LINE__) ;
|
Chris@0
|
1104 sf_close (file) ;
|
Chris@0
|
1105
|
Chris@0
|
1106 /* Check normalized version. */
|
Chris@0
|
1107 clip_max_diff = 0.0 ;
|
Chris@0
|
1108 for (k = 0 ; k < HALF_BUFFER_SIZE ; k++)
|
Chris@0
|
1109 { if (fabs (data_in [k]) > 1.0)
|
Chris@0
|
1110 { printf ("\n\nLine %d: Input sample %d/%d (%f) has not been clipped.\n\n", __LINE__, k, BUFFER_SIZE, data_in [k]) ;
|
Chris@0
|
1111 exit (1) ;
|
Chris@0
|
1112 } ;
|
Chris@0
|
1113
|
Chris@0
|
1114 if (data_out [k] * data_in [k] < 0.0)
|
Chris@0
|
1115 { printf ("\n\nLine %d: Data wrap around at index %d/%d.\n\n", __LINE__, k, BUFFER_SIZE) ;
|
Chris@0
|
1116 exit (1) ;
|
Chris@0
|
1117 } ;
|
Chris@0
|
1118
|
Chris@0
|
1119 if (fabs (data_out [k]) > 1.0)
|
Chris@0
|
1120 continue ;
|
Chris@0
|
1121
|
Chris@0
|
1122 diff = fabs (data_out [k] - data_in [k]) ;
|
Chris@0
|
1123 if (diff > clip_max_diff)
|
Chris@0
|
1124 clip_max_diff = diff ;
|
Chris@0
|
1125 } ;
|
Chris@0
|
1126
|
Chris@0
|
1127 if (clip_max_diff < 1e-20)
|
Chris@0
|
1128 { printf ("\n\nLine %d: Clipping difference (%e) too small (normalized).\n\n", __LINE__, clip_max_diff) ;
|
Chris@0
|
1129 exit (1) ;
|
Chris@0
|
1130 } ;
|
Chris@0
|
1131
|
Chris@0
|
1132 if (clip_max_diff > 1.0 / 0x80)
|
Chris@0
|
1133 { printf ("\n\nLine %d: Clipping difference (%e) too large (normalized).\n\n", __LINE__, clip_max_diff) ;
|
Chris@0
|
1134 exit (1) ;
|
Chris@0
|
1135 } ;
|
Chris@0
|
1136
|
Chris@0
|
1137 /* Check the un-normalized data. */
|
Chris@0
|
1138 clip_max_diff = 0.0 ;
|
Chris@0
|
1139 for (k = HALF_BUFFER_SIZE ; k < BUFFER_SIZE ; k++)
|
Chris@0
|
1140 { if (fabs (data_in [k]) > maxval)
|
Chris@0
|
1141 { printf ("\n\nLine %d: Input sample %d/%d (%f) has not been clipped.\n\n", __LINE__, k, BUFFER_SIZE, data_in [k]) ;
|
Chris@0
|
1142 exit (1) ;
|
Chris@0
|
1143 } ;
|
Chris@0
|
1144
|
Chris@0
|
1145 if (data_out [k] * data_in [k] < 0.0)
|
Chris@0
|
1146 { printf ("\n\nLine %d: Data wrap around at index %d/%d.\n\n", __LINE__, k, BUFFER_SIZE) ;
|
Chris@0
|
1147 exit (1) ;
|
Chris@0
|
1148 } ;
|
Chris@0
|
1149
|
Chris@0
|
1150 if (fabs (data_out [k]) > maxval)
|
Chris@0
|
1151 continue ;
|
Chris@0
|
1152
|
Chris@0
|
1153 diff = fabs (data_out [k] - data_in [k]) ;
|
Chris@0
|
1154 if (diff > clip_max_diff)
|
Chris@0
|
1155 clip_max_diff = diff ;
|
Chris@0
|
1156 } ;
|
Chris@0
|
1157
|
Chris@0
|
1158 if (clip_max_diff < 1e-20)
|
Chris@0
|
1159 { printf ("\n\nLine %d: Clipping difference (%e) too small (un-normalized).\n\n", __LINE__, clip_max_diff) ;
|
Chris@0
|
1160 exit (1) ;
|
Chris@0
|
1161 } ;
|
Chris@0
|
1162
|
Chris@0
|
1163 if (clip_max_diff > 1.0)
|
Chris@0
|
1164 { printf ("\n\nLine %d: Clipping difference (%e) too large (un-normalised).\n\n", __LINE__, clip_max_diff) ;
|
Chris@0
|
1165 exit (1) ;
|
Chris@0
|
1166 } ;
|
Chris@0
|
1167
|
Chris@0
|
1168 printf ("ok\n") ;
|
Chris@0
|
1169 unlink (filename) ;
|
Chris@0
|
1170 } /* dbl_scale_clip_test_08 */
|
Chris@0
|
1171
|
Chris@0
|
1172
|
Chris@0
|
1173
|
Chris@0
|
1174
|
Chris@0
|
1175 /*==============================================================================
|
Chris@0
|
1176 */
|
Chris@0
|
1177
|
Chris@0
|
1178
|
Chris@0
|
1179 static void flt_short_clip_read_test (const char *filename, int filetype)
|
Chris@0
|
1180 { SNDFILE *file ;
|
Chris@0
|
1181 SF_INFO sfinfo ;
|
Chris@0
|
1182 float *data_out ;
|
Chris@0
|
1183 short *data_in, max_value ;
|
Chris@0
|
1184 int k ;
|
Chris@0
|
1185
|
Chris@0
|
1186 print_test_name ("flt_short_clip_read_test", filename) ;
|
Chris@0
|
1187
|
Chris@0
|
1188 data_out = buffer_out.flt ;
|
Chris@0
|
1189 data_in = buffer_in.s ;
|
Chris@0
|
1190
|
Chris@0
|
1191 for (k = 0 ; k < BUFFER_SIZE ; k++)
|
Chris@0
|
1192 data_out [k] = 0.995 * sin (4 * M_PI * k / BUFFER_SIZE) ;
|
Chris@0
|
1193 data_out [BUFFER_SIZE / 8] = 1.0 ;
|
Chris@0
|
1194 data_out [3 * BUFFER_SIZE / 8] = -1.000000001 ;
|
Chris@0
|
1195 data_out [5 * BUFFER_SIZE / 8] = 1.0 ;
|
Chris@0
|
1196 data_out [7 * BUFFER_SIZE / 8] = -1.000000001 ;
|
Chris@0
|
1197
|
Chris@0
|
1198 memset (&sfinfo, 0, sizeof (sfinfo)) ;
|
Chris@0
|
1199 sfinfo.samplerate = 44100 ;
|
Chris@0
|
1200 sfinfo.frames = 123456789 ; /* Wrong length. Library should correct this on sf_close. */
|
Chris@0
|
1201 sfinfo.channels = 1 ;
|
Chris@0
|
1202 sfinfo.format = filetype ;
|
Chris@0
|
1203
|
Chris@0
|
1204 /* Save unclipped data to the file. */
|
Chris@0
|
1205 file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
|
Chris@0
|
1206 test_write_float_or_die (file, 0, data_out, BUFFER_SIZE, __LINE__) ;
|
Chris@0
|
1207 sf_close (file) ;
|
Chris@0
|
1208
|
Chris@0
|
1209 memset (&sfinfo, 0, sizeof (sfinfo)) ;
|
Chris@0
|
1210
|
Chris@0
|
1211 file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
|
Chris@0
|
1212 sf_command (file, SFC_SET_SCALE_FLOAT_INT_READ, NULL, SF_TRUE) ;
|
Chris@0
|
1213
|
Chris@0
|
1214 sfinfo.format &= (SF_FORMAT_TYPEMASK | SF_FORMAT_SUBMASK) ;
|
Chris@0
|
1215
|
Chris@0
|
1216 if (sfinfo.format != (filetype & (SF_FORMAT_TYPEMASK | SF_FORMAT_SUBMASK)))
|
Chris@0
|
1217 { printf ("\n\nLine %d: Returned format incorrect (0x%08X => 0x%08X).\n\n", __LINE__, filetype, sfinfo.format) ;
|
Chris@0
|
1218 exit (1) ;
|
Chris@0
|
1219 } ;
|
Chris@0
|
1220
|
Chris@0
|
1221 if (sfinfo.frames != BUFFER_SIZE)
|
Chris@0
|
1222 { printf ("\n\nLine %d: Incorrect number of frames in file (%d => %ld).\n\n", __LINE__, BUFFER_SIZE, SF_COUNT_TO_LONG (sfinfo.frames)) ;
|
Chris@0
|
1223 exit (1) ;
|
Chris@0
|
1224 } ;
|
Chris@0
|
1225
|
Chris@0
|
1226 if (sfinfo.channels != 1)
|
Chris@0
|
1227 { printf ("\n\nLine %d: Incorrect number of channels in file.\n\n", __LINE__) ;
|
Chris@0
|
1228 exit (1) ;
|
Chris@0
|
1229 } ;
|
Chris@0
|
1230
|
Chris@0
|
1231 check_log_buffer_or_die (file, __LINE__) ;
|
Chris@0
|
1232
|
Chris@0
|
1233 sf_command (file, SFC_SET_CLIPPING, NULL, SF_TRUE) ;
|
Chris@0
|
1234 test_read_short_or_die (file, 0, data_in, BUFFER_SIZE, __LINE__) ;
|
Chris@0
|
1235 /*-sf_command (file, SFC_SET_NORM_FLOAT, NULL, SF_FALSE) ;-*/
|
Chris@0
|
1236 sf_close (file) ;
|
Chris@0
|
1237
|
Chris@0
|
1238 /* Check the first half. */
|
Chris@0
|
1239 max_value = 0 ;
|
Chris@0
|
1240 for (k = 0 ; k < sfinfo.frames ; k++)
|
Chris@0
|
1241 { /* Check if data_out has different sign from data_in. */
|
Chris@0
|
1242 if ((data_out [k] < 0.0 && data_in [k] > 0) || (data_out [k] > 0.0 && data_in [k] < 0))
|
Chris@0
|
1243 { printf ("\n\nLine %d: Data wrap around at index %d/%d (%f -> %d).\n\n", __LINE__, k, BUFFER_SIZE, data_out [k], data_in [k]) ;
|
Chris@0
|
1244 exit (1) ;
|
Chris@0
|
1245 } ;
|
Chris@0
|
1246 max_value = (max_value > abs (data_in [k])) ? max_value : abs (data_in [k]) ;
|
Chris@0
|
1247 } ;
|
Chris@0
|
1248
|
Chris@0
|
1249 unlink (filename) ;
|
Chris@0
|
1250 puts ("ok") ;
|
Chris@0
|
1251 } /* flt_short_clip_read_test */
|
Chris@0
|
1252 static void flt_int_clip_read_test (const char *filename, int filetype)
|
Chris@0
|
1253 { SNDFILE *file ;
|
Chris@0
|
1254 SF_INFO sfinfo ;
|
Chris@0
|
1255 float *data_out ;
|
Chris@0
|
1256 int *data_in, max_value ;
|
Chris@0
|
1257 int k ;
|
Chris@0
|
1258
|
Chris@0
|
1259 print_test_name ("flt_int_clip_read_test", filename) ;
|
Chris@0
|
1260
|
Chris@0
|
1261 data_out = buffer_out.flt ;
|
Chris@0
|
1262 data_in = buffer_in.i ;
|
Chris@0
|
1263
|
Chris@0
|
1264 for (k = 0 ; k < BUFFER_SIZE ; k++)
|
Chris@0
|
1265 data_out [k] = 0.995 * sin (4 * M_PI * k / BUFFER_SIZE) ;
|
Chris@0
|
1266 data_out [BUFFER_SIZE / 8] = 1.0 ;
|
Chris@0
|
1267 data_out [3 * BUFFER_SIZE / 8] = -1.000000001 ;
|
Chris@0
|
1268 data_out [5 * BUFFER_SIZE / 8] = 1.0 ;
|
Chris@0
|
1269 data_out [7 * BUFFER_SIZE / 8] = -1.000000001 ;
|
Chris@0
|
1270
|
Chris@0
|
1271 memset (&sfinfo, 0, sizeof (sfinfo)) ;
|
Chris@0
|
1272 sfinfo.samplerate = 44100 ;
|
Chris@0
|
1273 sfinfo.frames = 123456789 ; /* Wrong length. Library should correct this on sf_close. */
|
Chris@0
|
1274 sfinfo.channels = 1 ;
|
Chris@0
|
1275 sfinfo.format = filetype ;
|
Chris@0
|
1276
|
Chris@0
|
1277 /* Save unclipped data to the file. */
|
Chris@0
|
1278 file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
|
Chris@0
|
1279 test_write_float_or_die (file, 0, data_out, BUFFER_SIZE, __LINE__) ;
|
Chris@0
|
1280 sf_close (file) ;
|
Chris@0
|
1281
|
Chris@0
|
1282 memset (&sfinfo, 0, sizeof (sfinfo)) ;
|
Chris@0
|
1283
|
Chris@0
|
1284 file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
|
Chris@0
|
1285 sf_command (file, SFC_SET_SCALE_FLOAT_INT_READ, NULL, SF_TRUE) ;
|
Chris@0
|
1286
|
Chris@0
|
1287 sfinfo.format &= (SF_FORMAT_TYPEMASK | SF_FORMAT_SUBMASK) ;
|
Chris@0
|
1288
|
Chris@0
|
1289 if (sfinfo.format != (filetype & (SF_FORMAT_TYPEMASK | SF_FORMAT_SUBMASK)))
|
Chris@0
|
1290 { printf ("\n\nLine %d: Returned format incorrect (0x%08X => 0x%08X).\n\n", __LINE__, filetype, sfinfo.format) ;
|
Chris@0
|
1291 exit (1) ;
|
Chris@0
|
1292 } ;
|
Chris@0
|
1293
|
Chris@0
|
1294 if (sfinfo.frames != BUFFER_SIZE)
|
Chris@0
|
1295 { printf ("\n\nLine %d: Incorrect number of frames in file (%d => %ld).\n\n", __LINE__, BUFFER_SIZE, SF_COUNT_TO_LONG (sfinfo.frames)) ;
|
Chris@0
|
1296 exit (1) ;
|
Chris@0
|
1297 } ;
|
Chris@0
|
1298
|
Chris@0
|
1299 if (sfinfo.channels != 1)
|
Chris@0
|
1300 { printf ("\n\nLine %d: Incorrect number of channels in file.\n\n", __LINE__) ;
|
Chris@0
|
1301 exit (1) ;
|
Chris@0
|
1302 } ;
|
Chris@0
|
1303
|
Chris@0
|
1304 check_log_buffer_or_die (file, __LINE__) ;
|
Chris@0
|
1305
|
Chris@0
|
1306 sf_command (file, SFC_SET_CLIPPING, NULL, SF_TRUE) ;
|
Chris@0
|
1307 test_read_int_or_die (file, 0, data_in, BUFFER_SIZE, __LINE__) ;
|
Chris@0
|
1308 /*-sf_command (file, SFC_SET_NORM_FLOAT, NULL, SF_FALSE) ;-*/
|
Chris@0
|
1309 sf_close (file) ;
|
Chris@0
|
1310
|
Chris@0
|
1311 /* Check the first half. */
|
Chris@0
|
1312 max_value = 0 ;
|
Chris@0
|
1313 for (k = 0 ; k < sfinfo.frames ; k++)
|
Chris@0
|
1314 { /* Check if data_out has different sign from data_in. */
|
Chris@0
|
1315 if ((data_out [k] < 0.0 && data_in [k] > 0) || (data_out [k] > 0.0 && data_in [k] < 0))
|
Chris@0
|
1316 { printf ("\n\nLine %d: Data wrap around at index %d/%d (%f -> %d).\n\n", __LINE__, k, BUFFER_SIZE, data_out [k], data_in [k]) ;
|
Chris@0
|
1317 exit (1) ;
|
Chris@0
|
1318 } ;
|
Chris@0
|
1319 max_value = (max_value > abs (data_in [k])) ? max_value : abs (data_in [k]) ;
|
Chris@0
|
1320 } ;
|
Chris@0
|
1321
|
Chris@0
|
1322 unlink (filename) ;
|
Chris@0
|
1323 puts ("ok") ;
|
Chris@0
|
1324 } /* flt_int_clip_read_test */
|
Chris@0
|
1325
|
Chris@0
|
1326 static void dbl_short_clip_read_test (const char *filename, int filetype)
|
Chris@0
|
1327 { SNDFILE *file ;
|
Chris@0
|
1328 SF_INFO sfinfo ;
|
Chris@0
|
1329 double *data_out ;
|
Chris@0
|
1330 short *data_in, max_value ;
|
Chris@0
|
1331 int k ;
|
Chris@0
|
1332
|
Chris@0
|
1333 print_test_name ("dbl_short_clip_read_test", filename) ;
|
Chris@0
|
1334
|
Chris@0
|
1335 data_out = buffer_out.dbl ;
|
Chris@0
|
1336 data_in = buffer_in.s ;
|
Chris@0
|
1337
|
Chris@0
|
1338 for (k = 0 ; k < BUFFER_SIZE ; k++)
|
Chris@0
|
1339 data_out [k] = 0.995 * sin (4 * M_PI * k / BUFFER_SIZE) ;
|
Chris@0
|
1340 data_out [BUFFER_SIZE / 8] = 1.0 ;
|
Chris@0
|
1341 data_out [3 * BUFFER_SIZE / 8] = -1.000000001 ;
|
Chris@0
|
1342 data_out [5 * BUFFER_SIZE / 8] = 1.0 ;
|
Chris@0
|
1343 data_out [7 * BUFFER_SIZE / 8] = -1.000000001 ;
|
Chris@0
|
1344
|
Chris@0
|
1345 memset (&sfinfo, 0, sizeof (sfinfo)) ;
|
Chris@0
|
1346 sfinfo.samplerate = 44100 ;
|
Chris@0
|
1347 sfinfo.frames = 123456789 ; /* Wrong length. Library should correct this on sf_close. */
|
Chris@0
|
1348 sfinfo.channels = 1 ;
|
Chris@0
|
1349 sfinfo.format = filetype ;
|
Chris@0
|
1350
|
Chris@0
|
1351 /* Save unclipped data to the file. */
|
Chris@0
|
1352 file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
|
Chris@0
|
1353 test_write_double_or_die (file, 0, data_out, BUFFER_SIZE, __LINE__) ;
|
Chris@0
|
1354 sf_close (file) ;
|
Chris@0
|
1355
|
Chris@0
|
1356 memset (&sfinfo, 0, sizeof (sfinfo)) ;
|
Chris@0
|
1357
|
Chris@0
|
1358 file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
|
Chris@0
|
1359 sf_command (file, SFC_SET_SCALE_FLOAT_INT_READ, NULL, SF_TRUE) ;
|
Chris@0
|
1360
|
Chris@0
|
1361 sfinfo.format &= (SF_FORMAT_TYPEMASK | SF_FORMAT_SUBMASK) ;
|
Chris@0
|
1362
|
Chris@0
|
1363 if (sfinfo.format != (filetype & (SF_FORMAT_TYPEMASK | SF_FORMAT_SUBMASK)))
|
Chris@0
|
1364 { printf ("\n\nLine %d: Returned format incorrect (0x%08X => 0x%08X).\n\n", __LINE__, filetype, sfinfo.format) ;
|
Chris@0
|
1365 exit (1) ;
|
Chris@0
|
1366 } ;
|
Chris@0
|
1367
|
Chris@0
|
1368 if (sfinfo.frames != BUFFER_SIZE)
|
Chris@0
|
1369 { printf ("\n\nLine %d: Incorrect number of frames in file (%d => %ld).\n\n", __LINE__, BUFFER_SIZE, SF_COUNT_TO_LONG (sfinfo.frames)) ;
|
Chris@0
|
1370 exit (1) ;
|
Chris@0
|
1371 } ;
|
Chris@0
|
1372
|
Chris@0
|
1373 if (sfinfo.channels != 1)
|
Chris@0
|
1374 { printf ("\n\nLine %d: Incorrect number of channels in file.\n\n", __LINE__) ;
|
Chris@0
|
1375 exit (1) ;
|
Chris@0
|
1376 } ;
|
Chris@0
|
1377
|
Chris@0
|
1378 check_log_buffer_or_die (file, __LINE__) ;
|
Chris@0
|
1379
|
Chris@0
|
1380 sf_command (file, SFC_SET_CLIPPING, NULL, SF_TRUE) ;
|
Chris@0
|
1381 test_read_short_or_die (file, 0, data_in, BUFFER_SIZE, __LINE__) ;
|
Chris@0
|
1382 /*-sf_command (file, SFC_SET_NORM_DOUBLE, NULL, SF_FALSE) ;-*/
|
Chris@0
|
1383 sf_close (file) ;
|
Chris@0
|
1384
|
Chris@0
|
1385 /* Check the first half. */
|
Chris@0
|
1386 max_value = 0 ;
|
Chris@0
|
1387 for (k = 0 ; k < sfinfo.frames ; k++)
|
Chris@0
|
1388 { /* Check if data_out has different sign from data_in. */
|
Chris@0
|
1389 if ((data_out [k] < 0.0 && data_in [k] > 0) || (data_out [k] > 0.0 && data_in [k] < 0))
|
Chris@0
|
1390 { printf ("\n\nLine %d: Data wrap around at index %d/%d (%f -> %d).\n\n", __LINE__, k, BUFFER_SIZE, data_out [k], data_in [k]) ;
|
Chris@0
|
1391 exit (1) ;
|
Chris@0
|
1392 } ;
|
Chris@0
|
1393 max_value = (max_value > abs (data_in [k])) ? max_value : abs (data_in [k]) ;
|
Chris@0
|
1394 } ;
|
Chris@0
|
1395
|
Chris@0
|
1396 unlink (filename) ;
|
Chris@0
|
1397 puts ("ok") ;
|
Chris@0
|
1398 } /* dbl_short_clip_read_test */
|
Chris@0
|
1399 static void dbl_int_clip_read_test (const char *filename, int filetype)
|
Chris@0
|
1400 { SNDFILE *file ;
|
Chris@0
|
1401 SF_INFO sfinfo ;
|
Chris@0
|
1402 double *data_out ;
|
Chris@0
|
1403 int *data_in, max_value ;
|
Chris@0
|
1404 int k ;
|
Chris@0
|
1405
|
Chris@0
|
1406 print_test_name ("dbl_int_clip_read_test", filename) ;
|
Chris@0
|
1407
|
Chris@0
|
1408 data_out = buffer_out.dbl ;
|
Chris@0
|
1409 data_in = buffer_in.i ;
|
Chris@0
|
1410
|
Chris@0
|
1411 for (k = 0 ; k < BUFFER_SIZE ; k++)
|
Chris@0
|
1412 data_out [k] = 0.995 * sin (4 * M_PI * k / BUFFER_SIZE) ;
|
Chris@0
|
1413 data_out [BUFFER_SIZE / 8] = 1.0 ;
|
Chris@0
|
1414 data_out [3 * BUFFER_SIZE / 8] = -1.000000001 ;
|
Chris@0
|
1415 data_out [5 * BUFFER_SIZE / 8] = 1.0 ;
|
Chris@0
|
1416 data_out [7 * BUFFER_SIZE / 8] = -1.000000001 ;
|
Chris@0
|
1417
|
Chris@0
|
1418 memset (&sfinfo, 0, sizeof (sfinfo)) ;
|
Chris@0
|
1419 sfinfo.samplerate = 44100 ;
|
Chris@0
|
1420 sfinfo.frames = 123456789 ; /* Wrong length. Library should correct this on sf_close. */
|
Chris@0
|
1421 sfinfo.channels = 1 ;
|
Chris@0
|
1422 sfinfo.format = filetype ;
|
Chris@0
|
1423
|
Chris@0
|
1424 /* Save unclipped data to the file. */
|
Chris@0
|
1425 file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
|
Chris@0
|
1426 test_write_double_or_die (file, 0, data_out, BUFFER_SIZE, __LINE__) ;
|
Chris@0
|
1427 sf_close (file) ;
|
Chris@0
|
1428
|
Chris@0
|
1429 memset (&sfinfo, 0, sizeof (sfinfo)) ;
|
Chris@0
|
1430
|
Chris@0
|
1431 file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
|
Chris@0
|
1432 sf_command (file, SFC_SET_SCALE_FLOAT_INT_READ, NULL, SF_TRUE) ;
|
Chris@0
|
1433
|
Chris@0
|
1434 sfinfo.format &= (SF_FORMAT_TYPEMASK | SF_FORMAT_SUBMASK) ;
|
Chris@0
|
1435
|
Chris@0
|
1436 if (sfinfo.format != (filetype & (SF_FORMAT_TYPEMASK | SF_FORMAT_SUBMASK)))
|
Chris@0
|
1437 { printf ("\n\nLine %d: Returned format incorrect (0x%08X => 0x%08X).\n\n", __LINE__, filetype, sfinfo.format) ;
|
Chris@0
|
1438 exit (1) ;
|
Chris@0
|
1439 } ;
|
Chris@0
|
1440
|
Chris@0
|
1441 if (sfinfo.frames != BUFFER_SIZE)
|
Chris@0
|
1442 { printf ("\n\nLine %d: Incorrect number of frames in file (%d => %ld).\n\n", __LINE__, BUFFER_SIZE, SF_COUNT_TO_LONG (sfinfo.frames)) ;
|
Chris@0
|
1443 exit (1) ;
|
Chris@0
|
1444 } ;
|
Chris@0
|
1445
|
Chris@0
|
1446 if (sfinfo.channels != 1)
|
Chris@0
|
1447 { printf ("\n\nLine %d: Incorrect number of channels in file.\n\n", __LINE__) ;
|
Chris@0
|
1448 exit (1) ;
|
Chris@0
|
1449 } ;
|
Chris@0
|
1450
|
Chris@0
|
1451 check_log_buffer_or_die (file, __LINE__) ;
|
Chris@0
|
1452
|
Chris@0
|
1453 sf_command (file, SFC_SET_CLIPPING, NULL, SF_TRUE) ;
|
Chris@0
|
1454 test_read_int_or_die (file, 0, data_in, BUFFER_SIZE, __LINE__) ;
|
Chris@0
|
1455 /*-sf_command (file, SFC_SET_NORM_DOUBLE, NULL, SF_FALSE) ;-*/
|
Chris@0
|
1456 sf_close (file) ;
|
Chris@0
|
1457
|
Chris@0
|
1458 /* Check the first half. */
|
Chris@0
|
1459 max_value = 0 ;
|
Chris@0
|
1460 for (k = 0 ; k < sfinfo.frames ; k++)
|
Chris@0
|
1461 { /* Check if data_out has different sign from data_in. */
|
Chris@0
|
1462 if ((data_out [k] < 0.0 && data_in [k] > 0) || (data_out [k] > 0.0 && data_in [k] < 0))
|
Chris@0
|
1463 { printf ("\n\nLine %d: Data wrap around at index %d/%d (%f -> %d).\n\n", __LINE__, k, BUFFER_SIZE, data_out [k], data_in [k]) ;
|
Chris@0
|
1464 exit (1) ;
|
Chris@0
|
1465 } ;
|
Chris@0
|
1466 max_value = (max_value > abs (data_in [k])) ? max_value : abs (data_in [k]) ;
|
Chris@0
|
1467 } ;
|
Chris@0
|
1468
|
Chris@0
|
1469 unlink (filename) ;
|
Chris@0
|
1470 puts ("ok") ;
|
Chris@0
|
1471 } /* dbl_int_clip_read_test */
|
Chris@0
|
1472
|
Chris@0
|
1473
|
Chris@0
|
1474 /*==============================================================================
|
Chris@0
|
1475 */
|
Chris@0
|
1476
|
Chris@0
|
1477
|
Chris@0
|
1478 static void short_flt_scale_write_test (const char *filename, int filetype)
|
Chris@0
|
1479 { SNDFILE *file ;
|
Chris@0
|
1480 SF_INFO sfinfo ;
|
Chris@0
|
1481 short *data_out ;
|
Chris@0
|
1482 float *data_in, max_value ;
|
Chris@0
|
1483 int k ;
|
Chris@0
|
1484
|
Chris@0
|
1485 print_test_name ("short_flt_clip_write_test", filename) ;
|
Chris@0
|
1486
|
Chris@0
|
1487 data_out = buffer_out.s ;
|
Chris@0
|
1488 data_in = buffer_in.flt ;
|
Chris@0
|
1489
|
Chris@0
|
1490 for (k = 0 ; k < BUFFER_SIZE ; k++)
|
Chris@0
|
1491 data_out [k] = lrintf (0x7FFFF * 0.995 * sin (4 * M_PI * k / BUFFER_SIZE)) ;
|
Chris@0
|
1492
|
Chris@0
|
1493 memset (&sfinfo, 0, sizeof (sfinfo)) ;
|
Chris@0
|
1494 sfinfo.samplerate = 44100 ;
|
Chris@0
|
1495 sfinfo.frames = 123456789 ; /* Wrong length. Library should correct this on sf_close. */
|
Chris@0
|
1496 sfinfo.channels = 1 ;
|
Chris@0
|
1497 sfinfo.format = filetype ;
|
Chris@0
|
1498
|
Chris@0
|
1499 file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
|
Chris@0
|
1500 test_write_short_or_die (file, 0, data_out, BUFFER_SIZE, __LINE__) ;
|
Chris@0
|
1501 sf_command (file, SFC_SET_SCALE_INT_FLOAT_WRITE, NULL, SF_TRUE) ;
|
Chris@0
|
1502 test_write_short_or_die (file, 0, data_out, BUFFER_SIZE, __LINE__) ;
|
Chris@0
|
1503 sf_command (file, SFC_SET_SCALE_INT_FLOAT_WRITE, NULL, SF_FALSE) ;
|
Chris@0
|
1504 test_write_short_or_die (file, 0, data_out, BUFFER_SIZE, __LINE__) ;
|
Chris@0
|
1505 sf_close (file) ;
|
Chris@0
|
1506
|
Chris@0
|
1507 memset (&sfinfo, 0, sizeof (sfinfo)) ;
|
Chris@0
|
1508
|
Chris@0
|
1509 file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
|
Chris@0
|
1510
|
Chris@0
|
1511 sfinfo.format &= (SF_FORMAT_TYPEMASK | SF_FORMAT_SUBMASK) ;
|
Chris@0
|
1512
|
Chris@0
|
1513 if (sfinfo.format != (filetype & (SF_FORMAT_TYPEMASK | SF_FORMAT_SUBMASK)))
|
Chris@0
|
1514 { printf ("\n\nLine %d: Returned format incorrect (0x%08X => 0x%08X).\n\n", __LINE__, filetype, sfinfo.format) ;
|
Chris@0
|
1515 exit (1) ;
|
Chris@0
|
1516 } ;
|
Chris@0
|
1517
|
Chris@0
|
1518 if (sfinfo.frames != 3 * BUFFER_SIZE)
|
Chris@0
|
1519 { printf ("\n\nLine %d: Incorrect number of frames in file (%d => %ld).\n\n", __LINE__, 3 * BUFFER_SIZE, SF_COUNT_TO_LONG (sfinfo.frames)) ;
|
Chris@0
|
1520 exit (1) ;
|
Chris@0
|
1521 } ;
|
Chris@0
|
1522
|
Chris@0
|
1523 if (sfinfo.channels != 1)
|
Chris@0
|
1524 { printf ("\n\nLine %d: Incorrect number of channels in file.\n\n", __LINE__) ;
|
Chris@0
|
1525 exit (1) ;
|
Chris@0
|
1526 } ;
|
Chris@0
|
1527
|
Chris@0
|
1528 check_log_buffer_or_die (file, __LINE__) ;
|
Chris@0
|
1529
|
Chris@0
|
1530 /* Check the first section. */
|
Chris@0
|
1531 test_read_float_or_die (file, 0, data_in, BUFFER_SIZE, __LINE__) ;
|
Chris@0
|
1532
|
Chris@0
|
1533 max_value = 0.0 ;
|
Chris@0
|
1534 for (k = 0 ; k < BUFFER_SIZE ; k++)
|
Chris@0
|
1535 max_value = (max_value > fabs (data_in [k])) ? max_value : fabs (data_in [k]) ;
|
Chris@0
|
1536
|
Chris@0
|
1537 if (max_value < 1000.0)
|
Chris@0
|
1538 { printf ("\n\nLine %d: Max value (%f) < 1000.0.\n\n", __LINE__, max_value) ;
|
Chris@0
|
1539 exit (1) ;
|
Chris@0
|
1540 } ;
|
Chris@0
|
1541
|
Chris@0
|
1542 /* Check the second section. */
|
Chris@0
|
1543 test_read_float_or_die (file, 0, data_in, BUFFER_SIZE, __LINE__) ;
|
Chris@0
|
1544
|
Chris@0
|
1545 max_value = 0.0 ;
|
Chris@0
|
1546 for (k = 0 ; k < BUFFER_SIZE ; k++)
|
Chris@0
|
1547 max_value = (max_value > fabs (data_in [k])) ? max_value : fabs (data_in [k]) ;
|
Chris@0
|
1548
|
Chris@0
|
1549 if (max_value > 1.0)
|
Chris@0
|
1550 { printf ("\n\nLine %d: Max value (%f) > 1.0.\n\n", __LINE__, max_value) ;
|
Chris@0
|
1551 exit (1) ;
|
Chris@0
|
1552 } ;
|
Chris@0
|
1553
|
Chris@0
|
1554 /* Check the third section. */
|
Chris@0
|
1555 test_read_float_or_die (file, 0, data_in, BUFFER_SIZE, __LINE__) ;
|
Chris@0
|
1556
|
Chris@0
|
1557 max_value = 0.0 ;
|
Chris@0
|
1558 for (k = 0 ; k < BUFFER_SIZE ; k++)
|
Chris@0
|
1559 max_value = (max_value > fabs (data_in [k])) ? max_value : fabs (data_in [k]) ;
|
Chris@0
|
1560
|
Chris@0
|
1561 if (max_value < 1000.0)
|
Chris@0
|
1562 { printf ("\n\nLine %d: Max value (%f) < 1000.0.\n\n", __LINE__, max_value) ;
|
Chris@0
|
1563 exit (1) ;
|
Chris@0
|
1564 } ;
|
Chris@0
|
1565
|
Chris@0
|
1566 sf_close (file) ;
|
Chris@0
|
1567
|
Chris@0
|
1568 unlink (filename) ;
|
Chris@0
|
1569 puts ("ok") ;
|
Chris@0
|
1570 } /* short_flt_scale_write_test */
|
Chris@0
|
1571 static void short_dbl_scale_write_test (const char *filename, int filetype)
|
Chris@0
|
1572 { SNDFILE *file ;
|
Chris@0
|
1573 SF_INFO sfinfo ;
|
Chris@0
|
1574 short *data_out ;
|
Chris@0
|
1575 double *data_in, max_value ;
|
Chris@0
|
1576 int k ;
|
Chris@0
|
1577
|
Chris@0
|
1578 print_test_name ("short_dbl_clip_write_test", filename) ;
|
Chris@0
|
1579
|
Chris@0
|
1580 data_out = buffer_out.s ;
|
Chris@0
|
1581 data_in = buffer_in.dbl ;
|
Chris@0
|
1582
|
Chris@0
|
1583 for (k = 0 ; k < BUFFER_SIZE ; k++)
|
Chris@0
|
1584 data_out [k] = lrint (0x7FFFF * 0.995 * sin (4 * M_PI * k / BUFFER_SIZE)) ;
|
Chris@0
|
1585
|
Chris@0
|
1586 memset (&sfinfo, 0, sizeof (sfinfo)) ;
|
Chris@0
|
1587 sfinfo.samplerate = 44100 ;
|
Chris@0
|
1588 sfinfo.frames = 123456789 ; /* Wrong length. Library should correct this on sf_close. */
|
Chris@0
|
1589 sfinfo.channels = 1 ;
|
Chris@0
|
1590 sfinfo.format = filetype ;
|
Chris@0
|
1591
|
Chris@0
|
1592 file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
|
Chris@0
|
1593 test_write_short_or_die (file, 0, data_out, BUFFER_SIZE, __LINE__) ;
|
Chris@0
|
1594 sf_command (file, SFC_SET_SCALE_INT_FLOAT_WRITE, NULL, SF_TRUE) ;
|
Chris@0
|
1595 test_write_short_or_die (file, 0, data_out, BUFFER_SIZE, __LINE__) ;
|
Chris@0
|
1596 sf_command (file, SFC_SET_SCALE_INT_FLOAT_WRITE, NULL, SF_FALSE) ;
|
Chris@0
|
1597 test_write_short_or_die (file, 0, data_out, BUFFER_SIZE, __LINE__) ;
|
Chris@0
|
1598 sf_close (file) ;
|
Chris@0
|
1599
|
Chris@0
|
1600 memset (&sfinfo, 0, sizeof (sfinfo)) ;
|
Chris@0
|
1601
|
Chris@0
|
1602 file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
|
Chris@0
|
1603
|
Chris@0
|
1604 sfinfo.format &= (SF_FORMAT_TYPEMASK | SF_FORMAT_SUBMASK) ;
|
Chris@0
|
1605
|
Chris@0
|
1606 if (sfinfo.format != (filetype & (SF_FORMAT_TYPEMASK | SF_FORMAT_SUBMASK)))
|
Chris@0
|
1607 { printf ("\n\nLine %d: Returned format incorrect (0x%08X => 0x%08X).\n\n", __LINE__, filetype, sfinfo.format) ;
|
Chris@0
|
1608 exit (1) ;
|
Chris@0
|
1609 } ;
|
Chris@0
|
1610
|
Chris@0
|
1611 if (sfinfo.frames != 3 * BUFFER_SIZE)
|
Chris@0
|
1612 { printf ("\n\nLine %d: Incorrect number of frames in file (%d => %ld).\n\n", __LINE__, 3 * BUFFER_SIZE, SF_COUNT_TO_LONG (sfinfo.frames)) ;
|
Chris@0
|
1613 exit (1) ;
|
Chris@0
|
1614 } ;
|
Chris@0
|
1615
|
Chris@0
|
1616 if (sfinfo.channels != 1)
|
Chris@0
|
1617 { printf ("\n\nLine %d: Incorrect number of channels in file.\n\n", __LINE__) ;
|
Chris@0
|
1618 exit (1) ;
|
Chris@0
|
1619 } ;
|
Chris@0
|
1620
|
Chris@0
|
1621 check_log_buffer_or_die (file, __LINE__) ;
|
Chris@0
|
1622
|
Chris@0
|
1623 /* Check the first section. */
|
Chris@0
|
1624 test_read_double_or_die (file, 0, data_in, BUFFER_SIZE, __LINE__) ;
|
Chris@0
|
1625
|
Chris@0
|
1626 max_value = 0.0 ;
|
Chris@0
|
1627 for (k = 0 ; k < BUFFER_SIZE ; k++)
|
Chris@0
|
1628 max_value = (max_value > fabs (data_in [k])) ? max_value : fabs (data_in [k]) ;
|
Chris@0
|
1629
|
Chris@0
|
1630 if (max_value < 1000.0)
|
Chris@0
|
1631 { printf ("\n\nLine %d: Max value (%f) < 1000.0.\n\n", __LINE__, max_value) ;
|
Chris@0
|
1632 exit (1) ;
|
Chris@0
|
1633 } ;
|
Chris@0
|
1634
|
Chris@0
|
1635 /* Check the second section. */
|
Chris@0
|
1636 test_read_double_or_die (file, 0, data_in, BUFFER_SIZE, __LINE__) ;
|
Chris@0
|
1637
|
Chris@0
|
1638 max_value = 0.0 ;
|
Chris@0
|
1639 for (k = 0 ; k < BUFFER_SIZE ; k++)
|
Chris@0
|
1640 max_value = (max_value > fabs (data_in [k])) ? max_value : fabs (data_in [k]) ;
|
Chris@0
|
1641
|
Chris@0
|
1642 if (max_value > 1.0)
|
Chris@0
|
1643 { printf ("\n\nLine %d: Max value (%f) > 1.0.\n\n", __LINE__, max_value) ;
|
Chris@0
|
1644 exit (1) ;
|
Chris@0
|
1645 } ;
|
Chris@0
|
1646
|
Chris@0
|
1647 /* Check the third section. */
|
Chris@0
|
1648 test_read_double_or_die (file, 0, data_in, BUFFER_SIZE, __LINE__) ;
|
Chris@0
|
1649
|
Chris@0
|
1650 max_value = 0.0 ;
|
Chris@0
|
1651 for (k = 0 ; k < BUFFER_SIZE ; k++)
|
Chris@0
|
1652 max_value = (max_value > fabs (data_in [k])) ? max_value : fabs (data_in [k]) ;
|
Chris@0
|
1653
|
Chris@0
|
1654 if (max_value < 1000.0)
|
Chris@0
|
1655 { printf ("\n\nLine %d: Max value (%f) < 1000.0.\n\n", __LINE__, max_value) ;
|
Chris@0
|
1656 exit (1) ;
|
Chris@0
|
1657 } ;
|
Chris@0
|
1658
|
Chris@0
|
1659 sf_close (file) ;
|
Chris@0
|
1660
|
Chris@0
|
1661 unlink (filename) ;
|
Chris@0
|
1662 puts ("ok") ;
|
Chris@0
|
1663 } /* short_dbl_scale_write_test */
|
Chris@0
|
1664
|
Chris@0
|
1665 static void int_flt_scale_write_test (const char *filename, int filetype)
|
Chris@0
|
1666 { SNDFILE *file ;
|
Chris@0
|
1667 SF_INFO sfinfo ;
|
Chris@0
|
1668 int *data_out ;
|
Chris@0
|
1669 float *data_in, max_value ;
|
Chris@0
|
1670 int k ;
|
Chris@0
|
1671
|
Chris@0
|
1672 print_test_name ("int_flt_clip_write_test", filename) ;
|
Chris@0
|
1673
|
Chris@0
|
1674 data_out = buffer_out.i ;
|
Chris@0
|
1675 data_in = buffer_in.flt ;
|
Chris@0
|
1676
|
Chris@0
|
1677 for (k = 0 ; k < BUFFER_SIZE ; k++)
|
Chris@0
|
1678 data_out [k] = lrintf (0x7FFFFFFF * 0.995 * sin (4 * M_PI * k / BUFFER_SIZE)) ;
|
Chris@0
|
1679
|
Chris@0
|
1680 memset (&sfinfo, 0, sizeof (sfinfo)) ;
|
Chris@0
|
1681 sfinfo.samplerate = 44100 ;
|
Chris@0
|
1682 sfinfo.frames = 123456789 ; /* Wrong length. Library should correct this on sf_close. */
|
Chris@0
|
1683 sfinfo.channels = 1 ;
|
Chris@0
|
1684 sfinfo.format = filetype ;
|
Chris@0
|
1685
|
Chris@0
|
1686 file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
|
Chris@0
|
1687 test_write_int_or_die (file, 0, data_out, BUFFER_SIZE, __LINE__) ;
|
Chris@0
|
1688 sf_command (file, SFC_SET_SCALE_INT_FLOAT_WRITE, NULL, SF_TRUE) ;
|
Chris@0
|
1689 test_write_int_or_die (file, 0, data_out, BUFFER_SIZE, __LINE__) ;
|
Chris@0
|
1690 sf_command (file, SFC_SET_SCALE_INT_FLOAT_WRITE, NULL, SF_FALSE) ;
|
Chris@0
|
1691 test_write_int_or_die (file, 0, data_out, BUFFER_SIZE, __LINE__) ;
|
Chris@0
|
1692 sf_close (file) ;
|
Chris@0
|
1693
|
Chris@0
|
1694 memset (&sfinfo, 0, sizeof (sfinfo)) ;
|
Chris@0
|
1695
|
Chris@0
|
1696 file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
|
Chris@0
|
1697
|
Chris@0
|
1698 sfinfo.format &= (SF_FORMAT_TYPEMASK | SF_FORMAT_SUBMASK) ;
|
Chris@0
|
1699
|
Chris@0
|
1700 if (sfinfo.format != (filetype & (SF_FORMAT_TYPEMASK | SF_FORMAT_SUBMASK)))
|
Chris@0
|
1701 { printf ("\n\nLine %d: Returned format incorrect (0x%08X => 0x%08X).\n\n", __LINE__, filetype, sfinfo.format) ;
|
Chris@0
|
1702 exit (1) ;
|
Chris@0
|
1703 } ;
|
Chris@0
|
1704
|
Chris@0
|
1705 if (sfinfo.frames != 3 * BUFFER_SIZE)
|
Chris@0
|
1706 { printf ("\n\nLine %d: Incorrect number of frames in file (%d => %ld).\n\n", __LINE__, 3 * BUFFER_SIZE, SF_COUNT_TO_LONG (sfinfo.frames)) ;
|
Chris@0
|
1707 exit (1) ;
|
Chris@0
|
1708 } ;
|
Chris@0
|
1709
|
Chris@0
|
1710 if (sfinfo.channels != 1)
|
Chris@0
|
1711 { printf ("\n\nLine %d: Incorrect number of channels in file.\n\n", __LINE__) ;
|
Chris@0
|
1712 exit (1) ;
|
Chris@0
|
1713 } ;
|
Chris@0
|
1714
|
Chris@0
|
1715 check_log_buffer_or_die (file, __LINE__) ;
|
Chris@0
|
1716
|
Chris@0
|
1717 /* Check the first section. */
|
Chris@0
|
1718 test_read_float_or_die (file, 0, data_in, BUFFER_SIZE, __LINE__) ;
|
Chris@0
|
1719
|
Chris@0
|
1720 max_value = 0.0 ;
|
Chris@0
|
1721 for (k = 0 ; k < BUFFER_SIZE ; k++)
|
Chris@0
|
1722 max_value = (max_value > fabs (data_in [k])) ? max_value : fabs (data_in [k]) ;
|
Chris@0
|
1723
|
Chris@0
|
1724 if (max_value < 1000.0)
|
Chris@0
|
1725 { printf ("\n\nLine %d: Max value (%f) < 1000.0.\n\n", __LINE__, max_value) ;
|
Chris@0
|
1726 exit (1) ;
|
Chris@0
|
1727 } ;
|
Chris@0
|
1728
|
Chris@0
|
1729 /* Check the second section. */
|
Chris@0
|
1730 test_read_float_or_die (file, 0, data_in, BUFFER_SIZE, __LINE__) ;
|
Chris@0
|
1731
|
Chris@0
|
1732 max_value = 0.0 ;
|
Chris@0
|
1733 for (k = 0 ; k < BUFFER_SIZE ; k++)
|
Chris@0
|
1734 max_value = (max_value > fabs (data_in [k])) ? max_value : fabs (data_in [k]) ;
|
Chris@0
|
1735
|
Chris@0
|
1736 if (max_value > 1.0)
|
Chris@0
|
1737 { printf ("\n\nLine %d: Max value (%f) > 1.0.\n\n", __LINE__, max_value) ;
|
Chris@0
|
1738 exit (1) ;
|
Chris@0
|
1739 } ;
|
Chris@0
|
1740
|
Chris@0
|
1741 /* Check the third section. */
|
Chris@0
|
1742 test_read_float_or_die (file, 0, data_in, BUFFER_SIZE, __LINE__) ;
|
Chris@0
|
1743
|
Chris@0
|
1744 max_value = 0.0 ;
|
Chris@0
|
1745 for (k = 0 ; k < BUFFER_SIZE ; k++)
|
Chris@0
|
1746 max_value = (max_value > fabs (data_in [k])) ? max_value : fabs (data_in [k]) ;
|
Chris@0
|
1747
|
Chris@0
|
1748 if (max_value < 1000.0)
|
Chris@0
|
1749 { printf ("\n\nLine %d: Max value (%f) < 1000.0.\n\n", __LINE__, max_value) ;
|
Chris@0
|
1750 exit (1) ;
|
Chris@0
|
1751 } ;
|
Chris@0
|
1752
|
Chris@0
|
1753 sf_close (file) ;
|
Chris@0
|
1754
|
Chris@0
|
1755 unlink (filename) ;
|
Chris@0
|
1756 puts ("ok") ;
|
Chris@0
|
1757 } /* int_flt_scale_write_test */
|
Chris@0
|
1758 static void int_dbl_scale_write_test (const char *filename, int filetype)
|
Chris@0
|
1759 { SNDFILE *file ;
|
Chris@0
|
1760 SF_INFO sfinfo ;
|
Chris@0
|
1761 int *data_out ;
|
Chris@0
|
1762 double *data_in, max_value ;
|
Chris@0
|
1763 int k ;
|
Chris@0
|
1764
|
Chris@0
|
1765 print_test_name ("int_dbl_clip_write_test", filename) ;
|
Chris@0
|
1766
|
Chris@0
|
1767 data_out = buffer_out.i ;
|
Chris@0
|
1768 data_in = buffer_in.dbl ;
|
Chris@0
|
1769
|
Chris@0
|
1770 for (k = 0 ; k < BUFFER_SIZE ; k++)
|
Chris@0
|
1771 data_out [k] = lrint (0x7FFFFFFF * 0.995 * sin (4 * M_PI * k / BUFFER_SIZE)) ;
|
Chris@0
|
1772
|
Chris@0
|
1773 memset (&sfinfo, 0, sizeof (sfinfo)) ;
|
Chris@0
|
1774 sfinfo.samplerate = 44100 ;
|
Chris@0
|
1775 sfinfo.frames = 123456789 ; /* Wrong length. Library should correct this on sf_close. */
|
Chris@0
|
1776 sfinfo.channels = 1 ;
|
Chris@0
|
1777 sfinfo.format = filetype ;
|
Chris@0
|
1778
|
Chris@0
|
1779 file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
|
Chris@0
|
1780 test_write_int_or_die (file, 0, data_out, BUFFER_SIZE, __LINE__) ;
|
Chris@0
|
1781 sf_command (file, SFC_SET_SCALE_INT_FLOAT_WRITE, NULL, SF_TRUE) ;
|
Chris@0
|
1782 test_write_int_or_die (file, 0, data_out, BUFFER_SIZE, __LINE__) ;
|
Chris@0
|
1783 sf_command (file, SFC_SET_SCALE_INT_FLOAT_WRITE, NULL, SF_FALSE) ;
|
Chris@0
|
1784 test_write_int_or_die (file, 0, data_out, BUFFER_SIZE, __LINE__) ;
|
Chris@0
|
1785 sf_close (file) ;
|
Chris@0
|
1786
|
Chris@0
|
1787 memset (&sfinfo, 0, sizeof (sfinfo)) ;
|
Chris@0
|
1788
|
Chris@0
|
1789 file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
|
Chris@0
|
1790
|
Chris@0
|
1791 sfinfo.format &= (SF_FORMAT_TYPEMASK | SF_FORMAT_SUBMASK) ;
|
Chris@0
|
1792
|
Chris@0
|
1793 if (sfinfo.format != (filetype & (SF_FORMAT_TYPEMASK | SF_FORMAT_SUBMASK)))
|
Chris@0
|
1794 { printf ("\n\nLine %d: Returned format incorrect (0x%08X => 0x%08X).\n\n", __LINE__, filetype, sfinfo.format) ;
|
Chris@0
|
1795 exit (1) ;
|
Chris@0
|
1796 } ;
|
Chris@0
|
1797
|
Chris@0
|
1798 if (sfinfo.frames != 3 * BUFFER_SIZE)
|
Chris@0
|
1799 { printf ("\n\nLine %d: Incorrect number of frames in file (%d => %ld).\n\n", __LINE__, 3 * BUFFER_SIZE, SF_COUNT_TO_LONG (sfinfo.frames)) ;
|
Chris@0
|
1800 exit (1) ;
|
Chris@0
|
1801 } ;
|
Chris@0
|
1802
|
Chris@0
|
1803 if (sfinfo.channels != 1)
|
Chris@0
|
1804 { printf ("\n\nLine %d: Incorrect number of channels in file.\n\n", __LINE__) ;
|
Chris@0
|
1805 exit (1) ;
|
Chris@0
|
1806 } ;
|
Chris@0
|
1807
|
Chris@0
|
1808 check_log_buffer_or_die (file, __LINE__) ;
|
Chris@0
|
1809
|
Chris@0
|
1810 /* Check the first section. */
|
Chris@0
|
1811 test_read_double_or_die (file, 0, data_in, BUFFER_SIZE, __LINE__) ;
|
Chris@0
|
1812
|
Chris@0
|
1813 max_value = 0.0 ;
|
Chris@0
|
1814 for (k = 0 ; k < BUFFER_SIZE ; k++)
|
Chris@0
|
1815 max_value = (max_value > fabs (data_in [k])) ? max_value : fabs (data_in [k]) ;
|
Chris@0
|
1816
|
Chris@0
|
1817 if (max_value < 1000.0)
|
Chris@0
|
1818 { printf ("\n\nLine %d: Max value (%f) < 1000.0.\n\n", __LINE__, max_value) ;
|
Chris@0
|
1819 exit (1) ;
|
Chris@0
|
1820 } ;
|
Chris@0
|
1821
|
Chris@0
|
1822 /* Check the second section. */
|
Chris@0
|
1823 test_read_double_or_die (file, 0, data_in, BUFFER_SIZE, __LINE__) ;
|
Chris@0
|
1824
|
Chris@0
|
1825 max_value = 0.0 ;
|
Chris@0
|
1826 for (k = 0 ; k < BUFFER_SIZE ; k++)
|
Chris@0
|
1827 max_value = (max_value > fabs (data_in [k])) ? max_value : fabs (data_in [k]) ;
|
Chris@0
|
1828
|
Chris@0
|
1829 if (max_value > 1.0)
|
Chris@0
|
1830 { printf ("\n\nLine %d: Max value (%f) > 1.0.\n\n", __LINE__, max_value) ;
|
Chris@0
|
1831 exit (1) ;
|
Chris@0
|
1832 } ;
|
Chris@0
|
1833
|
Chris@0
|
1834 /* Check the third section. */
|
Chris@0
|
1835 test_read_double_or_die (file, 0, data_in, BUFFER_SIZE, __LINE__) ;
|
Chris@0
|
1836
|
Chris@0
|
1837 max_value = 0.0 ;
|
Chris@0
|
1838 for (k = 0 ; k < BUFFER_SIZE ; k++)
|
Chris@0
|
1839 max_value = (max_value > fabs (data_in [k])) ? max_value : fabs (data_in [k]) ;
|
Chris@0
|
1840
|
Chris@0
|
1841 if (max_value < 1000.0)
|
Chris@0
|
1842 { printf ("\n\nLine %d: Max value (%f) < 1000.0.\n\n", __LINE__, max_value) ;
|
Chris@0
|
1843 exit (1) ;
|
Chris@0
|
1844 } ;
|
Chris@0
|
1845
|
Chris@0
|
1846 sf_close (file) ;
|
Chris@0
|
1847
|
Chris@0
|
1848 unlink (filename) ;
|
Chris@0
|
1849 puts ("ok") ;
|
Chris@0
|
1850 } /* int_dbl_scale_write_test */
|
Chris@0
|
1851
|
Chris@0
|
1852
|
Chris@0
|
1853
|