Chris@0
|
1 /*
|
Chris@0
|
2 ** Copyright (C) 2001-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 #include <time.h>
|
Chris@0
|
25
|
Chris@0
|
26 #if HAVE_UNISTD_H
|
Chris@0
|
27 #include <unistd.h>
|
Chris@0
|
28 #endif
|
Chris@0
|
29
|
Chris@0
|
30 #include <math.h>
|
Chris@0
|
31
|
Chris@0
|
32 #include <sndfile.h>
|
Chris@0
|
33
|
Chris@0
|
34 #include "utils.h"
|
Chris@0
|
35
|
Chris@0
|
36 #define BUFFER_LEN (1<<10)
|
Chris@0
|
37 #define LOG_BUFFER_SIZE 1024
|
Chris@0
|
38
|
Chris@0
|
39 static void float_norm_test (const char *filename) ;
|
Chris@0
|
40 static void double_norm_test (const char *filename) ;
|
Chris@0
|
41 static void format_tests (void) ;
|
Chris@0
|
42 static void calc_peak_test (int filetype, const char *filename) ;
|
Chris@0
|
43 static void truncate_test (const char *filename, int filetype) ;
|
Chris@0
|
44 static void instrument_test (const char *filename, int filetype) ;
|
Chris@0
|
45 static void channel_map_test (const char *filename, int filetype) ;
|
Chris@0
|
46 static void current_sf_info_test (const char *filename) ;
|
Chris@0
|
47 static void raw_needs_endswap_test (const char *filename, int filetype) ;
|
Chris@0
|
48
|
Chris@0
|
49 static void broadcast_test (const char *filename, int filetype) ;
|
Chris@0
|
50 static void broadcast_rdwr_test (const char *filename, int filetype) ;
|
Chris@0
|
51 static void broadcast_coding_history_test (const char *filename) ;
|
Chris@0
|
52 static void broadcast_coding_history_size (const char *filename) ;
|
Chris@0
|
53
|
Chris@0
|
54 /* Force the start of this buffer to be double aligned. Sparc-solaris will
|
Chris@0
|
55 ** choke if its not.
|
Chris@0
|
56 */
|
Chris@0
|
57
|
Chris@0
|
58 static int int_data [BUFFER_LEN] ;
|
Chris@0
|
59 static float float_data [BUFFER_LEN] ;
|
Chris@0
|
60 static double double_data [BUFFER_LEN] ;
|
Chris@0
|
61
|
Chris@0
|
62 int
|
Chris@0
|
63 main (int argc, char *argv [])
|
Chris@0
|
64 { int do_all = 0 ;
|
Chris@0
|
65 int test_count = 0 ;
|
Chris@0
|
66
|
Chris@0
|
67 if (argc != 2)
|
Chris@0
|
68 { printf ("Usage : %s <test>\n", argv [0]) ;
|
Chris@0
|
69 printf (" Where <test> is one of the following:\n") ;
|
Chris@0
|
70 printf (" ver - test sf_command (SFC_GETLIB_VERSION)\n") ;
|
Chris@0
|
71 printf (" norm - test floating point normalisation\n") ;
|
Chris@0
|
72 printf (" format - test format string commands\n") ;
|
Chris@0
|
73 printf (" peak - test peak calculation\n") ;
|
Chris@0
|
74 printf (" trunc - test file truncation\n") ;
|
Chris@0
|
75 printf (" inst - test set/get of SF_INSTRUMENT.\n") ;
|
Chris@0
|
76 printf (" chanmap - test set/get of channel map data..\n") ;
|
Chris@0
|
77 printf (" bext - test set/get of SF_BROADCAST_INFO.\n") ;
|
Chris@0
|
78 printf (" bextch - test set/get of SF_BROADCAST_INFO coding_history.\n") ;
|
Chris@0
|
79 printf (" rawend - test SFC_RAW_NEEDS_ENDSWAP.\n") ;
|
Chris@0
|
80 printf (" all - perform all tests\n") ;
|
Chris@0
|
81 exit (1) ;
|
Chris@0
|
82 } ;
|
Chris@0
|
83
|
Chris@0
|
84 do_all =! strcmp (argv [1], "all") ;
|
Chris@0
|
85
|
Chris@0
|
86 if (do_all || strcmp (argv [1], "ver") == 0)
|
Chris@0
|
87 { char buffer [128] ;
|
Chris@0
|
88
|
Chris@0
|
89 print_test_name ("version_test", "(none)") ;
|
Chris@0
|
90 buffer [0] = 0 ;
|
Chris@0
|
91 sf_command (NULL, SFC_GET_LIB_VERSION, buffer, sizeof (buffer)) ;
|
Chris@0
|
92 if (strlen (buffer) < 1)
|
Chris@0
|
93 { printf ("Line %d: could not retrieve lib version.\n", __LINE__) ;
|
Chris@0
|
94 exit (1) ;
|
Chris@0
|
95 } ;
|
Chris@0
|
96 puts ("ok") ;
|
Chris@0
|
97 test_count ++ ;
|
Chris@0
|
98 } ;
|
Chris@0
|
99
|
Chris@0
|
100 if (do_all || strcmp (argv [1], "norm") == 0)
|
Chris@0
|
101 { /* Preliminary float/double normalisation tests. More testing
|
Chris@0
|
102 ** is done in the program 'floating_point_test'.
|
Chris@0
|
103 */
|
Chris@0
|
104 float_norm_test ("float.wav") ;
|
Chris@0
|
105 double_norm_test ("double.wav") ;
|
Chris@0
|
106 test_count ++ ;
|
Chris@0
|
107 } ;
|
Chris@0
|
108
|
Chris@0
|
109 if (do_all || strcmp (argv [1], "peak") == 0)
|
Chris@0
|
110 { calc_peak_test (SF_ENDIAN_BIG | SF_FORMAT_RAW, "be-peak.raw") ;
|
Chris@0
|
111 calc_peak_test (SF_ENDIAN_LITTLE | SF_FORMAT_RAW, "le-peak.raw") ;
|
Chris@0
|
112 test_count ++ ;
|
Chris@0
|
113 } ;
|
Chris@0
|
114
|
Chris@0
|
115 if (do_all || ! strcmp (argv [1], "format"))
|
Chris@0
|
116 { format_tests () ;
|
Chris@0
|
117 test_count ++ ;
|
Chris@0
|
118 } ;
|
Chris@0
|
119
|
Chris@0
|
120 if (do_all || strcmp (argv [1], "trunc") == 0)
|
Chris@0
|
121 { truncate_test ("truncate.raw", SF_FORMAT_RAW | SF_FORMAT_PCM_32) ;
|
Chris@0
|
122 truncate_test ("truncate.au" , SF_FORMAT_AU | SF_FORMAT_PCM_16) ;
|
Chris@0
|
123 test_count ++ ;
|
Chris@0
|
124 } ;
|
Chris@0
|
125
|
Chris@0
|
126 if (do_all || strcmp (argv [1], "inst") == 0)
|
Chris@0
|
127 { instrument_test ("instrument.wav", SF_FORMAT_WAV | SF_FORMAT_PCM_16) ;
|
Chris@0
|
128 instrument_test ("instrument.aiff" , SF_FORMAT_AIFF | SF_FORMAT_PCM_24) ;
|
Chris@0
|
129 /*-instrument_test ("instrument.xi", SF_FORMAT_XI | SF_FORMAT_DPCM_16) ;-*/
|
Chris@0
|
130 test_count ++ ;
|
Chris@0
|
131 } ;
|
Chris@0
|
132
|
Chris@0
|
133 if (do_all || strcmp (argv [1], "current_sf_info") == 0)
|
Chris@0
|
134 { current_sf_info_test ("current.wav") ;
|
Chris@0
|
135 test_count ++ ;
|
Chris@0
|
136 } ;
|
Chris@0
|
137
|
Chris@0
|
138 if (do_all || strcmp (argv [1], "bext") == 0)
|
Chris@0
|
139 { broadcast_test ("broadcast.wav", SF_FORMAT_WAV | SF_FORMAT_PCM_16) ;
|
Chris@0
|
140 broadcast_rdwr_test ("broadcast.wav", SF_FORMAT_WAV | SF_FORMAT_PCM_16) ;
|
Chris@0
|
141
|
Chris@0
|
142 broadcast_test ("broadcast.wavex", SF_FORMAT_WAVEX | SF_FORMAT_PCM_16) ;
|
Chris@0
|
143 broadcast_rdwr_test ("broadcast.wavex", SF_FORMAT_WAVEX | SF_FORMAT_PCM_16) ;
|
Chris@0
|
144
|
Chris@0
|
145 broadcast_test ("broadcast.rf64", SF_FORMAT_RF64 | SF_FORMAT_PCM_16) ;
|
Chris@0
|
146 broadcast_rdwr_test ("broadcast.rf64", SF_FORMAT_RF64 | SF_FORMAT_PCM_16) ;
|
Chris@0
|
147 test_count ++ ;
|
Chris@0
|
148 } ;
|
Chris@0
|
149
|
Chris@0
|
150 if (do_all || strcmp (argv [1], "bextch") == 0)
|
Chris@0
|
151 { broadcast_coding_history_test ("coding_history.wav") ;
|
Chris@0
|
152 broadcast_coding_history_size ("coding_hist_size.wav") ;
|
Chris@0
|
153 test_count ++ ;
|
Chris@0
|
154 } ;
|
Chris@0
|
155
|
Chris@0
|
156 if (do_all || strcmp (argv [1], "chanmap") == 0)
|
Chris@0
|
157 { channel_map_test ("chanmap.wavex", SF_FORMAT_WAVEX | SF_FORMAT_PCM_16) ;
|
Chris@0
|
158 channel_map_test ("chanmap.rf64", SF_FORMAT_RF64 | SF_FORMAT_PCM_16) ;
|
Chris@0
|
159 channel_map_test ("chanmap.aifc" , SF_FORMAT_AIFF | SF_FORMAT_PCM_16) ;
|
Chris@0
|
160 channel_map_test ("chanmap.caf" , SF_FORMAT_CAF | SF_FORMAT_PCM_16) ;
|
Chris@0
|
161 test_count ++ ;
|
Chris@0
|
162 } ;
|
Chris@0
|
163
|
Chris@0
|
164 if (do_all || strcmp (argv [1], "rawend") == 0)
|
Chris@0
|
165 { raw_needs_endswap_test ("raw_end.wav", SF_FORMAT_WAV) ;
|
Chris@0
|
166 raw_needs_endswap_test ("raw_end.wavex", SF_FORMAT_WAVEX) ;
|
Chris@0
|
167 raw_needs_endswap_test ("raw_end.rifx", SF_ENDIAN_BIG | SF_FORMAT_WAV) ;
|
Chris@0
|
168 raw_needs_endswap_test ("raw_end.aiff", SF_FORMAT_AIFF) ;
|
Chris@0
|
169 raw_needs_endswap_test ("raw_end.aiff_le", SF_ENDIAN_LITTLE | SF_FORMAT_AIFF) ;
|
Chris@0
|
170 test_count ++ ;
|
Chris@0
|
171 } ;
|
Chris@0
|
172
|
Chris@0
|
173 if (test_count == 0)
|
Chris@0
|
174 { printf ("Mono : ************************************\n") ;
|
Chris@0
|
175 printf ("Mono : * No '%s' test defined.\n", argv [1]) ;
|
Chris@0
|
176 printf ("Mono : ************************************\n") ;
|
Chris@0
|
177 return 1 ;
|
Chris@0
|
178 } ;
|
Chris@0
|
179
|
Chris@0
|
180 return 0 ;
|
Chris@0
|
181 } /* main */
|
Chris@0
|
182
|
Chris@0
|
183 /*============================================================================================
|
Chris@0
|
184 ** Here are the test functions.
|
Chris@0
|
185 */
|
Chris@0
|
186
|
Chris@0
|
187 static void
|
Chris@0
|
188 float_norm_test (const char *filename)
|
Chris@0
|
189 { SNDFILE *file ;
|
Chris@0
|
190 SF_INFO sfinfo ;
|
Chris@0
|
191 unsigned int k ;
|
Chris@0
|
192
|
Chris@0
|
193 print_test_name ("float_norm_test", filename) ;
|
Chris@0
|
194
|
Chris@0
|
195 sfinfo.samplerate = 44100 ;
|
Chris@0
|
196 sfinfo.format = (SF_FORMAT_RAW | SF_FORMAT_PCM_16) ;
|
Chris@0
|
197 sfinfo.channels = 1 ;
|
Chris@0
|
198 sfinfo.frames = BUFFER_LEN ;
|
Chris@0
|
199
|
Chris@0
|
200 /* Create float_data with all values being less than 1.0. */
|
Chris@0
|
201 for (k = 0 ; k < BUFFER_LEN / 2 ; k++)
|
Chris@0
|
202 float_data [k] = (k + 5) / (2.0 * BUFFER_LEN) ;
|
Chris@0
|
203 for (k = BUFFER_LEN / 2 ; k < BUFFER_LEN ; k++)
|
Chris@0
|
204 float_data [k] = (k + 5) ;
|
Chris@0
|
205
|
Chris@0
|
206 if (! (file = sf_open (filename, SFM_WRITE, &sfinfo)))
|
Chris@0
|
207 { printf ("Line %d: sf_open_write failed with error : ", __LINE__) ;
|
Chris@0
|
208 fflush (stdout) ;
|
Chris@0
|
209 puts (sf_strerror (NULL)) ;
|
Chris@0
|
210 exit (1) ;
|
Chris@0
|
211 } ;
|
Chris@0
|
212
|
Chris@0
|
213 /* Normalisation is on by default so no need to do anything here. */
|
Chris@0
|
214
|
Chris@0
|
215 if ((k = sf_write_float (file, float_data, BUFFER_LEN / 2)) != BUFFER_LEN / 2)
|
Chris@0
|
216 { printf ("Line %d: sf_write_float failed with short write (%d ->%d)\n", __LINE__, BUFFER_LEN, k) ;
|
Chris@0
|
217 exit (1) ;
|
Chris@0
|
218 } ;
|
Chris@0
|
219
|
Chris@0
|
220 /* Turn normalisation off. */
|
Chris@0
|
221 sf_command (file, SFC_SET_NORM_FLOAT, NULL, SF_FALSE) ;
|
Chris@0
|
222
|
Chris@0
|
223 if ((k = sf_write_float (file, float_data + BUFFER_LEN / 2, BUFFER_LEN / 2)) != BUFFER_LEN / 2)
|
Chris@0
|
224 { printf ("Line %d: sf_write_float failed with short write (%d ->%d)\n", __LINE__, BUFFER_LEN, k) ;
|
Chris@0
|
225 exit (1) ;
|
Chris@0
|
226 } ;
|
Chris@0
|
227
|
Chris@0
|
228 sf_close (file) ;
|
Chris@0
|
229
|
Chris@0
|
230 /* sfinfo struct should still contain correct data. */
|
Chris@0
|
231 if (! (file = sf_open (filename, SFM_READ, &sfinfo)))
|
Chris@0
|
232 { printf ("Line %d: sf_open_read failed with error : ", __LINE__) ;
|
Chris@0
|
233 fflush (stdout) ;
|
Chris@0
|
234 puts (sf_strerror (NULL)) ;
|
Chris@0
|
235 exit (1) ;
|
Chris@0
|
236 } ;
|
Chris@0
|
237
|
Chris@0
|
238 if (sfinfo.format != (SF_FORMAT_RAW | SF_FORMAT_PCM_16))
|
Chris@0
|
239 { printf ("Line %d: Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__, (SF_FORMAT_RAW | SF_FORMAT_PCM_16), sfinfo.format) ;
|
Chris@0
|
240 exit (1) ;
|
Chris@0
|
241 } ;
|
Chris@0
|
242
|
Chris@0
|
243 if (sfinfo.frames != BUFFER_LEN)
|
Chris@0
|
244 { printf ("\n\nLine %d: Incorrect number of.frames in file. (%d => %ld)\n", __LINE__, BUFFER_LEN, SF_COUNT_TO_LONG (sfinfo.frames)) ;
|
Chris@0
|
245 exit (1) ;
|
Chris@0
|
246 } ;
|
Chris@0
|
247
|
Chris@0
|
248 if (sfinfo.channels != 1)
|
Chris@0
|
249 { printf ("Line %d: Incorrect number of channels in file.\n", __LINE__) ;
|
Chris@0
|
250 exit (1) ;
|
Chris@0
|
251 } ;
|
Chris@0
|
252
|
Chris@0
|
253 /* Read float_data and check that it is normalised (ie default). */
|
Chris@0
|
254 if ((k = sf_read_float (file, float_data, BUFFER_LEN)) != BUFFER_LEN)
|
Chris@0
|
255 { printf ("\n\nLine %d: sf_read_float failed with short read (%d ->%d)\n", __LINE__, BUFFER_LEN, k) ;
|
Chris@0
|
256 exit (1) ;
|
Chris@0
|
257 } ;
|
Chris@0
|
258
|
Chris@0
|
259 for (k = 0 ; k < BUFFER_LEN ; k++)
|
Chris@0
|
260 if (float_data [k] >= 1.0)
|
Chris@0
|
261 { printf ("\n\nLine %d: float_data [%d] == %f which is greater than 1.0\n", __LINE__, k, float_data [k]) ;
|
Chris@0
|
262 exit (1) ;
|
Chris@0
|
263 } ;
|
Chris@0
|
264
|
Chris@0
|
265 /* Seek to start of file, turn normalisation off, read float_data and check again. */
|
Chris@0
|
266 sf_seek (file, 0, SEEK_SET) ;
|
Chris@0
|
267 sf_command (file, SFC_SET_NORM_FLOAT, NULL, SF_FALSE) ;
|
Chris@0
|
268
|
Chris@0
|
269 if ((k = sf_read_float (file, float_data, BUFFER_LEN)) != BUFFER_LEN)
|
Chris@0
|
270 { printf ("\n\nLine %d: sf_read_float failed with short read (%d ->%d)\n", __LINE__, BUFFER_LEN, k) ;
|
Chris@0
|
271 exit (1) ;
|
Chris@0
|
272 } ;
|
Chris@0
|
273
|
Chris@0
|
274 for (k = 0 ; k < BUFFER_LEN ; k++)
|
Chris@0
|
275 if (float_data [k] < 1.0)
|
Chris@0
|
276 { printf ("\n\nLine %d: float_data [%d] == %f which is less than 1.0\n", __LINE__, k, float_data [k]) ;
|
Chris@0
|
277 exit (1) ;
|
Chris@0
|
278 } ;
|
Chris@0
|
279
|
Chris@0
|
280 /* Seek to start of file, turn normalisation on, read float_data and do final check. */
|
Chris@0
|
281 sf_seek (file, 0, SEEK_SET) ;
|
Chris@0
|
282 sf_command (file, SFC_SET_NORM_FLOAT, NULL, SF_TRUE) ;
|
Chris@0
|
283
|
Chris@0
|
284 if ((k = sf_read_float (file, float_data, BUFFER_LEN)) != BUFFER_LEN)
|
Chris@0
|
285 { printf ("\n\nLine %d: sf_read_float failed with short read (%d ->%d)\n", __LINE__, BUFFER_LEN, k) ;
|
Chris@0
|
286 exit (1) ;
|
Chris@0
|
287 } ;
|
Chris@0
|
288
|
Chris@0
|
289 for (k = 0 ; k < BUFFER_LEN ; k++)
|
Chris@0
|
290 if (float_data [k] > 1.0)
|
Chris@0
|
291 { printf ("\n\nLine %d: float_data [%d] == %f which is greater than 1.0\n", __LINE__, k, float_data [k]) ;
|
Chris@0
|
292 exit (1) ;
|
Chris@0
|
293 } ;
|
Chris@0
|
294
|
Chris@0
|
295
|
Chris@0
|
296 sf_close (file) ;
|
Chris@0
|
297
|
Chris@0
|
298 unlink (filename) ;
|
Chris@0
|
299
|
Chris@0
|
300 printf ("ok\n") ;
|
Chris@0
|
301 } /* float_norm_test */
|
Chris@0
|
302
|
Chris@0
|
303 static void
|
Chris@0
|
304 double_norm_test (const char *filename)
|
Chris@0
|
305 { SNDFILE *file ;
|
Chris@0
|
306 SF_INFO sfinfo ;
|
Chris@0
|
307 unsigned int k ;
|
Chris@0
|
308
|
Chris@0
|
309 print_test_name ("double_norm_test", filename) ;
|
Chris@0
|
310
|
Chris@0
|
311 sfinfo.samplerate = 44100 ;
|
Chris@0
|
312 sfinfo.format = (SF_FORMAT_RAW | SF_FORMAT_PCM_16) ;
|
Chris@0
|
313 sfinfo.channels = 1 ;
|
Chris@0
|
314 sfinfo.frames = BUFFER_LEN ;
|
Chris@0
|
315
|
Chris@0
|
316 /* Create double_data with all values being less than 1.0. */
|
Chris@0
|
317 for (k = 0 ; k < BUFFER_LEN / 2 ; k++)
|
Chris@0
|
318 double_data [k] = (k + 5) / (2.0 * BUFFER_LEN) ;
|
Chris@0
|
319 for (k = BUFFER_LEN / 2 ; k < BUFFER_LEN ; k++)
|
Chris@0
|
320 double_data [k] = (k + 5) ;
|
Chris@0
|
321
|
Chris@0
|
322 if (! (file = sf_open (filename, SFM_WRITE, &sfinfo)))
|
Chris@0
|
323 { printf ("Line %d: sf_open_write failed with error : ", __LINE__) ;
|
Chris@0
|
324 fflush (stdout) ;
|
Chris@0
|
325 puts (sf_strerror (NULL)) ;
|
Chris@0
|
326 exit (1) ;
|
Chris@0
|
327 } ;
|
Chris@0
|
328
|
Chris@0
|
329 /* Normailsation is on by default so no need to do anything here. */
|
Chris@0
|
330 /*-sf_command (file, "set-norm-double", "true", 0) ;-*/
|
Chris@0
|
331
|
Chris@0
|
332 if ((k = sf_write_double (file, double_data, BUFFER_LEN / 2)) != BUFFER_LEN / 2)
|
Chris@0
|
333 { printf ("Line %d: sf_write_double failed with short write (%d ->%d)\n", __LINE__, BUFFER_LEN, k) ;
|
Chris@0
|
334 exit (1) ;
|
Chris@0
|
335 } ;
|
Chris@0
|
336
|
Chris@0
|
337 /* Turn normalisation off. */
|
Chris@0
|
338 sf_command (file, SFC_SET_NORM_DOUBLE, NULL, SF_FALSE) ;
|
Chris@0
|
339
|
Chris@0
|
340 if ((k = sf_write_double (file, double_data + BUFFER_LEN / 2, BUFFER_LEN / 2)) != BUFFER_LEN / 2)
|
Chris@0
|
341 { printf ("Line %d: sf_write_double failed with short write (%d ->%d)\n", __LINE__, BUFFER_LEN, k) ;
|
Chris@0
|
342 exit (1) ;
|
Chris@0
|
343 } ;
|
Chris@0
|
344
|
Chris@0
|
345 sf_close (file) ;
|
Chris@0
|
346
|
Chris@0
|
347 if (! (file = sf_open (filename, SFM_READ, &sfinfo)))
|
Chris@0
|
348 { printf ("Line %d: sf_open_read failed with error : ", __LINE__) ;
|
Chris@0
|
349 fflush (stdout) ;
|
Chris@0
|
350 puts (sf_strerror (NULL)) ;
|
Chris@0
|
351 exit (1) ;
|
Chris@0
|
352 } ;
|
Chris@0
|
353
|
Chris@0
|
354 if (sfinfo.format != (SF_FORMAT_RAW | SF_FORMAT_PCM_16))
|
Chris@0
|
355 { printf ("Line %d: Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__, (SF_FORMAT_RAW | SF_FORMAT_PCM_16), sfinfo.format) ;
|
Chris@0
|
356 exit (1) ;
|
Chris@0
|
357 } ;
|
Chris@0
|
358
|
Chris@0
|
359 if (sfinfo.frames != BUFFER_LEN)
|
Chris@0
|
360 { printf ("\n\nLine %d: Incorrect number of.frames in file. (%d => %ld)\n", __LINE__, BUFFER_LEN, SF_COUNT_TO_LONG (sfinfo.frames)) ;
|
Chris@0
|
361 exit (1) ;
|
Chris@0
|
362 } ;
|
Chris@0
|
363
|
Chris@0
|
364 if (sfinfo.channels != 1)
|
Chris@0
|
365 { printf ("Line %d: Incorrect number of channels in file.\n", __LINE__) ;
|
Chris@0
|
366 exit (1) ;
|
Chris@0
|
367 } ;
|
Chris@0
|
368
|
Chris@0
|
369 /* Read double_data and check that it is normalised (ie default). */
|
Chris@0
|
370 if ((k = sf_read_double (file, double_data, BUFFER_LEN)) != BUFFER_LEN)
|
Chris@0
|
371 { printf ("\n\nLine %d: sf_read_double failed with short read (%d ->%d)\n", __LINE__, BUFFER_LEN, k) ;
|
Chris@0
|
372 exit (1) ;
|
Chris@0
|
373 } ;
|
Chris@0
|
374
|
Chris@0
|
375 for (k = 0 ; k < BUFFER_LEN ; k++)
|
Chris@0
|
376 if (double_data [k] >= 1.0)
|
Chris@0
|
377 { printf ("\n\nLine %d: double_data [%d] == %f which is greater than 1.0\n", __LINE__, k, double_data [k]) ;
|
Chris@0
|
378 exit (1) ;
|
Chris@0
|
379 } ;
|
Chris@0
|
380
|
Chris@0
|
381 /* Seek to start of file, turn normalisation off, read double_data and check again. */
|
Chris@0
|
382 sf_seek (file, 0, SEEK_SET) ;
|
Chris@0
|
383 sf_command (file, SFC_SET_NORM_DOUBLE, NULL, SF_FALSE) ;
|
Chris@0
|
384
|
Chris@0
|
385 if ((k = sf_read_double (file, double_data, BUFFER_LEN)) != BUFFER_LEN)
|
Chris@0
|
386 { printf ("\n\nLine %d: sf_read_double failed with short read (%d ->%d)\n", __LINE__, BUFFER_LEN, k) ;
|
Chris@0
|
387 exit (1) ;
|
Chris@0
|
388 } ;
|
Chris@0
|
389
|
Chris@0
|
390 for (k = 0 ; k < BUFFER_LEN ; k++)
|
Chris@0
|
391 if (double_data [k] < 1.0)
|
Chris@0
|
392 { printf ("\n\nLine %d: double_data [%d] == %f which is less than 1.0\n", __LINE__, k, double_data [k]) ;
|
Chris@0
|
393 exit (1) ;
|
Chris@0
|
394 } ;
|
Chris@0
|
395
|
Chris@0
|
396 /* Seek to start of file, turn normalisation on, read double_data and do final check. */
|
Chris@0
|
397 sf_seek (file, 0, SEEK_SET) ;
|
Chris@0
|
398 sf_command (file, SFC_SET_NORM_DOUBLE, NULL, SF_TRUE) ;
|
Chris@0
|
399
|
Chris@0
|
400 if ((k = sf_read_double (file, double_data, BUFFER_LEN)) != BUFFER_LEN)
|
Chris@0
|
401 { printf ("\n\nLine %d: sf_read_double failed with short read (%d ->%d)\n", __LINE__, BUFFER_LEN, k) ;
|
Chris@0
|
402 exit (1) ;
|
Chris@0
|
403 } ;
|
Chris@0
|
404
|
Chris@0
|
405 for (k = 0 ; k < BUFFER_LEN ; k++)
|
Chris@0
|
406 if (double_data [k] > 1.0)
|
Chris@0
|
407 { printf ("\n\nLine %d: double_data [%d] == %f which is greater than 1.0\n", __LINE__, k, double_data [k]) ;
|
Chris@0
|
408 exit (1) ;
|
Chris@0
|
409 } ;
|
Chris@0
|
410
|
Chris@0
|
411
|
Chris@0
|
412 sf_close (file) ;
|
Chris@0
|
413
|
Chris@0
|
414 unlink (filename) ;
|
Chris@0
|
415
|
Chris@0
|
416 printf ("ok\n") ;
|
Chris@0
|
417 } /* double_norm_test */
|
Chris@0
|
418
|
Chris@0
|
419 static void
|
Chris@0
|
420 format_tests (void)
|
Chris@0
|
421 { SF_FORMAT_INFO format_info ;
|
Chris@0
|
422 SF_INFO sfinfo ;
|
Chris@0
|
423 const char *last_name ;
|
Chris@0
|
424 int k, count ;
|
Chris@0
|
425
|
Chris@0
|
426 print_test_name ("format_tests", "(null)") ;
|
Chris@0
|
427
|
Chris@0
|
428 /* Clear out SF_INFO struct and set channels > 0. */
|
Chris@0
|
429 memset (&sfinfo, 0, sizeof (sfinfo)) ;
|
Chris@0
|
430 sfinfo.channels = 1 ;
|
Chris@0
|
431
|
Chris@0
|
432 /* First test simple formats. */
|
Chris@0
|
433
|
Chris@0
|
434 sf_command (NULL, SFC_GET_SIMPLE_FORMAT_COUNT, &count, sizeof (int)) ;
|
Chris@0
|
435
|
Chris@0
|
436 if (count < 0 || count > 30)
|
Chris@0
|
437 { printf ("Line %d: Weird count.\n", __LINE__) ;
|
Chris@0
|
438 exit (1) ;
|
Chris@0
|
439 } ;
|
Chris@0
|
440
|
Chris@0
|
441 format_info.format = 0 ;
|
Chris@0
|
442 sf_command (NULL, SFC_GET_SIMPLE_FORMAT, &format_info, sizeof (format_info)) ;
|
Chris@0
|
443
|
Chris@0
|
444 last_name = format_info.name ;
|
Chris@0
|
445 for (k = 1 ; k < count ; k ++)
|
Chris@0
|
446 { format_info.format = k ;
|
Chris@0
|
447 sf_command (NULL, SFC_GET_SIMPLE_FORMAT, &format_info, sizeof (format_info)) ;
|
Chris@0
|
448 if (strcmp (last_name, format_info.name) >= 0)
|
Chris@0
|
449 { printf ("\n\nLine %d: format names out of sequence `%s' < `%s'.\n", __LINE__, last_name, format_info.name) ;
|
Chris@0
|
450 exit (1) ;
|
Chris@0
|
451 } ;
|
Chris@0
|
452 sfinfo.format = format_info.format ;
|
Chris@0
|
453
|
Chris@0
|
454 if (! sf_format_check (&sfinfo))
|
Chris@0
|
455 { printf ("\n\nLine %d: sf_format_check failed.\n", __LINE__) ;
|
Chris@0
|
456 printf (" Name : %s\n", format_info.name) ;
|
Chris@0
|
457 printf (" Format : 0x%X\n", sfinfo.format) ;
|
Chris@0
|
458 printf (" Channels : 0x%X\n", sfinfo.channels) ;
|
Chris@0
|
459 printf (" Sample Rate : 0x%X\n", sfinfo.samplerate) ;
|
Chris@0
|
460 exit (1) ;
|
Chris@0
|
461 } ;
|
Chris@0
|
462 last_name = format_info.name ;
|
Chris@0
|
463 } ;
|
Chris@0
|
464 format_info.format = 666 ;
|
Chris@0
|
465 sf_command (NULL, SFC_GET_SIMPLE_FORMAT, &format_info, sizeof (format_info)) ;
|
Chris@0
|
466
|
Chris@0
|
467 /* Now test major formats. */
|
Chris@0
|
468 sf_command (NULL, SFC_GET_FORMAT_MAJOR_COUNT, &count, sizeof (int)) ;
|
Chris@0
|
469
|
Chris@0
|
470 if (count < 0 || count > 30)
|
Chris@0
|
471 { printf ("Line %d: Weird count.\n", __LINE__) ;
|
Chris@0
|
472 exit (1) ;
|
Chris@0
|
473 } ;
|
Chris@0
|
474
|
Chris@0
|
475 format_info.format = 0 ;
|
Chris@0
|
476 sf_command (NULL, SFC_GET_FORMAT_MAJOR, &format_info, sizeof (format_info)) ;
|
Chris@0
|
477
|
Chris@0
|
478 last_name = format_info.name ;
|
Chris@0
|
479 for (k = 1 ; k < count ; k ++)
|
Chris@0
|
480 { format_info.format = k ;
|
Chris@0
|
481 sf_command (NULL, SFC_GET_FORMAT_MAJOR, &format_info, sizeof (format_info)) ;
|
Chris@0
|
482 if (strcmp (last_name, format_info.name) >= 0)
|
Chris@0
|
483 { printf ("\n\nLine %d: format names out of sequence (%d) `%s' < `%s'.\n", __LINE__, k, last_name, format_info.name) ;
|
Chris@0
|
484 exit (1) ;
|
Chris@0
|
485 } ;
|
Chris@0
|
486
|
Chris@0
|
487 last_name = format_info.name ;
|
Chris@0
|
488 } ;
|
Chris@0
|
489 format_info.format = 666 ;
|
Chris@0
|
490 sf_command (NULL, SFC_GET_FORMAT_MAJOR, &format_info, sizeof (format_info)) ;
|
Chris@0
|
491
|
Chris@0
|
492 /* Now test subtype formats. */
|
Chris@0
|
493 sf_command (NULL, SFC_GET_FORMAT_SUBTYPE_COUNT, &count, sizeof (int)) ;
|
Chris@0
|
494
|
Chris@0
|
495 if (count < 0 || count > 30)
|
Chris@0
|
496 { printf ("Line %d: Weird count.\n", __LINE__) ;
|
Chris@0
|
497 exit (1) ;
|
Chris@0
|
498 } ;
|
Chris@0
|
499
|
Chris@0
|
500 format_info.format = 0 ;
|
Chris@0
|
501 sf_command (NULL, SFC_GET_FORMAT_SUBTYPE, &format_info, sizeof (format_info)) ;
|
Chris@0
|
502
|
Chris@0
|
503 last_name = format_info.name ;
|
Chris@0
|
504 for (k = 1 ; k < count ; k ++)
|
Chris@0
|
505 { format_info.format = k ;
|
Chris@0
|
506 sf_command (NULL, SFC_GET_FORMAT_SUBTYPE, &format_info, sizeof (format_info)) ;
|
Chris@0
|
507 } ;
|
Chris@0
|
508 format_info.format = 666 ;
|
Chris@0
|
509 sf_command (NULL, SFC_GET_FORMAT_SUBTYPE, &format_info, sizeof (format_info)) ;
|
Chris@0
|
510
|
Chris@0
|
511
|
Chris@0
|
512 printf ("ok\n") ;
|
Chris@0
|
513 } /* format_tests */
|
Chris@0
|
514
|
Chris@0
|
515 static void
|
Chris@0
|
516 calc_peak_test (int filetype, const char *filename)
|
Chris@0
|
517 { SNDFILE *file ;
|
Chris@0
|
518 SF_INFO sfinfo ;
|
Chris@0
|
519 int k, format ;
|
Chris@0
|
520 double peak ;
|
Chris@0
|
521
|
Chris@0
|
522 print_test_name ("calc_peak_test", filename) ;
|
Chris@0
|
523
|
Chris@0
|
524 format = (filetype | SF_FORMAT_PCM_16) ;
|
Chris@0
|
525
|
Chris@0
|
526 sfinfo.samplerate = 44100 ;
|
Chris@0
|
527 sfinfo.format = format ;
|
Chris@0
|
528 sfinfo.channels = 1 ;
|
Chris@0
|
529 sfinfo.frames = BUFFER_LEN ;
|
Chris@0
|
530
|
Chris@0
|
531 /* Create double_data with max value of 0.5. */
|
Chris@0
|
532 for (k = 0 ; k < BUFFER_LEN ; k++)
|
Chris@0
|
533 double_data [k] = (k + 1) / (2.0 * BUFFER_LEN) ;
|
Chris@0
|
534
|
Chris@0
|
535 file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
|
Chris@0
|
536
|
Chris@0
|
537 test_write_double_or_die (file, 0, double_data, BUFFER_LEN, __LINE__) ;
|
Chris@0
|
538
|
Chris@0
|
539 sf_close (file) ;
|
Chris@0
|
540
|
Chris@0
|
541 file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
|
Chris@0
|
542
|
Chris@0
|
543 if (sfinfo.format != format)
|
Chris@0
|
544 { printf ("Line %d: Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__, format, sfinfo.format) ;
|
Chris@0
|
545 exit (1) ;
|
Chris@0
|
546 } ;
|
Chris@0
|
547
|
Chris@0
|
548 if (sfinfo.frames != BUFFER_LEN)
|
Chris@0
|
549 { printf ("\n\nLine %d: Incorrect number of.frames in file. (%d => %ld)\n", __LINE__, BUFFER_LEN, SF_COUNT_TO_LONG (sfinfo.frames)) ;
|
Chris@0
|
550 exit (1) ;
|
Chris@0
|
551 } ;
|
Chris@0
|
552
|
Chris@0
|
553 if (sfinfo.channels != 1)
|
Chris@0
|
554 { printf ("Line %d: Incorrect number of channels in file.\n", __LINE__) ;
|
Chris@0
|
555 exit (1) ;
|
Chris@0
|
556 } ;
|
Chris@0
|
557
|
Chris@0
|
558 sf_command (file, SFC_CALC_SIGNAL_MAX, &peak, sizeof (peak)) ;
|
Chris@0
|
559 if (fabs (peak - (1 << 14)) > 1.0)
|
Chris@0
|
560 { printf ("Line %d : Peak value should be %d (is %f).\n", __LINE__, (1 << 14), peak) ;
|
Chris@0
|
561 exit (1) ;
|
Chris@0
|
562 } ;
|
Chris@0
|
563
|
Chris@0
|
564 sf_command (file, SFC_CALC_NORM_SIGNAL_MAX, &peak, sizeof (peak)) ;
|
Chris@0
|
565 if (fabs (peak - 0.5) > 4e-5)
|
Chris@0
|
566 { printf ("Line %d : Peak value should be %f (is %f).\n", __LINE__, 0.5, peak) ;
|
Chris@0
|
567 exit (1) ;
|
Chris@0
|
568 } ;
|
Chris@0
|
569
|
Chris@0
|
570 sf_close (file) ;
|
Chris@0
|
571
|
Chris@0
|
572 format = (filetype | SF_FORMAT_FLOAT) ;
|
Chris@0
|
573 sfinfo.samplerate = 44100 ;
|
Chris@0
|
574 sfinfo.format = format ;
|
Chris@0
|
575 sfinfo.channels = 1 ;
|
Chris@0
|
576 sfinfo.frames = BUFFER_LEN ;
|
Chris@0
|
577
|
Chris@0
|
578 /* Create double_data with max value of 0.5. */
|
Chris@0
|
579 for (k = 0 ; k < BUFFER_LEN ; k++)
|
Chris@0
|
580 double_data [k] = (k + 1) / (2.0 * BUFFER_LEN) ;
|
Chris@0
|
581
|
Chris@0
|
582 file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
|
Chris@0
|
583
|
Chris@0
|
584 test_write_double_or_die (file, 0, double_data, BUFFER_LEN, __LINE__) ;
|
Chris@0
|
585
|
Chris@0
|
586 sf_close (file) ;
|
Chris@0
|
587
|
Chris@0
|
588 file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
|
Chris@0
|
589
|
Chris@0
|
590 if (sfinfo.format != format)
|
Chris@0
|
591 { printf ("Line %d: Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__, format, sfinfo.format) ;
|
Chris@0
|
592 exit (1) ;
|
Chris@0
|
593 } ;
|
Chris@0
|
594
|
Chris@0
|
595 if (sfinfo.frames != BUFFER_LEN)
|
Chris@0
|
596 { printf ("\n\nLine %d: Incorrect number of.frames in file. (%d => %ld)\n", __LINE__, BUFFER_LEN, SF_COUNT_TO_LONG (sfinfo.frames)) ;
|
Chris@0
|
597 exit (1) ;
|
Chris@0
|
598 } ;
|
Chris@0
|
599
|
Chris@0
|
600 if (sfinfo.channels != 1)
|
Chris@0
|
601 { printf ("Line %d: Incorrect number of channels in file.\n", __LINE__) ;
|
Chris@0
|
602 exit (1) ;
|
Chris@0
|
603 } ;
|
Chris@0
|
604
|
Chris@0
|
605 sf_command (file, SFC_CALC_SIGNAL_MAX, &peak, sizeof (peak)) ;
|
Chris@0
|
606 if (fabs (peak - 0.5) > 1e-5)
|
Chris@0
|
607 { printf ("Line %d : Peak value should be %f (is %f).\n", __LINE__, 0.5, peak) ;
|
Chris@0
|
608 exit (1) ;
|
Chris@0
|
609 } ;
|
Chris@0
|
610
|
Chris@0
|
611 sf_command (file, SFC_CALC_NORM_SIGNAL_MAX, &peak, sizeof (peak)) ;
|
Chris@0
|
612 if (fabs (peak - 0.5) > 1e-5)
|
Chris@0
|
613 { printf ("Line %d : Peak value should be %f (is %f).\n", __LINE__, 0.5, peak) ;
|
Chris@0
|
614 exit (1) ;
|
Chris@0
|
615 } ;
|
Chris@0
|
616
|
Chris@0
|
617 sf_close (file) ;
|
Chris@0
|
618
|
Chris@0
|
619 unlink (filename) ;
|
Chris@0
|
620
|
Chris@0
|
621 printf ("ok\n") ;
|
Chris@0
|
622 } /* calc_peak_test */
|
Chris@0
|
623
|
Chris@0
|
624 static void
|
Chris@0
|
625 truncate_test (const char *filename, int filetype)
|
Chris@0
|
626 { SNDFILE *file ;
|
Chris@0
|
627 SF_INFO sfinfo ;
|
Chris@0
|
628 sf_count_t len ;
|
Chris@0
|
629
|
Chris@0
|
630 print_test_name ("truncate_test", filename) ;
|
Chris@0
|
631
|
Chris@0
|
632 sfinfo.samplerate = 11025 ;
|
Chris@0
|
633 sfinfo.format = filetype ;
|
Chris@0
|
634 sfinfo.channels = 2 ;
|
Chris@0
|
635
|
Chris@0
|
636 file = test_open_file_or_die (filename, SFM_RDWR, &sfinfo, SF_TRUE, __LINE__) ;
|
Chris@0
|
637
|
Chris@0
|
638 test_write_int_or_die (file, 0, int_data, BUFFER_LEN, __LINE__) ;
|
Chris@0
|
639
|
Chris@0
|
640 len = 100 ;
|
Chris@0
|
641 if (sf_command (file, SFC_FILE_TRUNCATE, &len, sizeof (len)))
|
Chris@0
|
642 { printf ("Line %d: sf_command (SFC_FILE_TRUNCATE) returned error.\n", __LINE__) ;
|
Chris@0
|
643 exit (1) ;
|
Chris@0
|
644 } ;
|
Chris@0
|
645
|
Chris@0
|
646 test_seek_or_die (file, 0, SEEK_CUR, len, 2, __LINE__) ;
|
Chris@0
|
647 test_seek_or_die (file, 0, SEEK_END, len, 2, __LINE__) ;
|
Chris@0
|
648
|
Chris@0
|
649 sf_close (file) ;
|
Chris@0
|
650
|
Chris@0
|
651 unlink (filename) ;
|
Chris@0
|
652 puts ("ok") ;
|
Chris@0
|
653 } /* truncate_test */
|
Chris@0
|
654
|
Chris@0
|
655 /*------------------------------------------------------------------------------
|
Chris@0
|
656 */
|
Chris@0
|
657
|
Chris@0
|
658 static void
|
Chris@0
|
659 instrumet_rw_test (const char *filename)
|
Chris@0
|
660 { SNDFILE *sndfile ;
|
Chris@0
|
661 SF_INFO sfinfo ;
|
Chris@0
|
662 SF_INSTRUMENT inst ;
|
Chris@0
|
663 memset (&sfinfo, 0, sizeof (SF_INFO)) ;
|
Chris@0
|
664
|
Chris@0
|
665 sndfile = test_open_file_or_die (filename, SFM_RDWR, &sfinfo, SF_FALSE, __LINE__) ;
|
Chris@0
|
666
|
Chris@0
|
667 if (sf_command (sndfile, SFC_GET_INSTRUMENT, &inst, sizeof (inst)) == SF_TRUE)
|
Chris@0
|
668 { inst.basenote = 22 ;
|
Chris@0
|
669
|
Chris@0
|
670 if (sf_command (sndfile, SFC_SET_INSTRUMENT, &inst, sizeof (inst)) == SF_TRUE)
|
Chris@0
|
671 printf ("Sucess: [%s] updated\n", filename) ;
|
Chris@0
|
672 else
|
Chris@0
|
673 printf ("Error: SFC_SET_INSTRUMENT on [%s] [%s]\n", filename, sf_strerror (sndfile)) ;
|
Chris@0
|
674 }
|
Chris@0
|
675 else
|
Chris@0
|
676 printf ("Error: SFC_GET_INSTRUMENT on [%s] [%s]\n", filename, sf_strerror (sndfile)) ;
|
Chris@0
|
677
|
Chris@0
|
678
|
Chris@0
|
679 if (sf_command (sndfile, SFC_UPDATE_HEADER_NOW, NULL, 0) != 0)
|
Chris@0
|
680 printf ("Error: SFC_UPDATE_HEADER_NOW on [%s] [%s]\n", filename, sf_strerror (sndfile)) ;
|
Chris@0
|
681
|
Chris@0
|
682 sf_write_sync (sndfile) ;
|
Chris@0
|
683 sf_close (sndfile) ;
|
Chris@0
|
684
|
Chris@0
|
685 return ;
|
Chris@0
|
686 } /* instrumet_rw_test */
|
Chris@0
|
687
|
Chris@0
|
688 static void
|
Chris@0
|
689 instrument_test (const char *filename, int filetype)
|
Chris@0
|
690 { static SF_INSTRUMENT write_inst =
|
Chris@0
|
691 { 2, /* gain */
|
Chris@0
|
692 3, /* detune */
|
Chris@0
|
693 4, /* basenote */
|
Chris@0
|
694 5, 6, /* key low and high */
|
Chris@0
|
695 7, 8, /* velocity low and high */
|
Chris@0
|
696 2, /* loop_count */
|
Chris@0
|
697 { { 801, 2, 3, 0 },
|
Chris@0
|
698 { 801, 3, 4, 0 },
|
Chris@0
|
699 }
|
Chris@0
|
700 } ;
|
Chris@0
|
701 SF_INSTRUMENT read_inst ;
|
Chris@0
|
702 SNDFILE *file ;
|
Chris@0
|
703 SF_INFO sfinfo ;
|
Chris@0
|
704
|
Chris@0
|
705 print_test_name ("instrument_test", filename) ;
|
Chris@0
|
706
|
Chris@0
|
707 sfinfo.samplerate = 11025 ;
|
Chris@0
|
708 sfinfo.format = filetype ;
|
Chris@0
|
709 sfinfo.channels = 1 ;
|
Chris@0
|
710
|
Chris@0
|
711 file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
|
Chris@0
|
712 if (sf_command (file, SFC_SET_INSTRUMENT, &write_inst, sizeof (write_inst)) == SF_FALSE)
|
Chris@0
|
713 { printf ("\n\nLine %d : sf_command (SFC_SET_INSTRUMENT) failed.\n\n", __LINE__) ;
|
Chris@0
|
714 exit (1) ;
|
Chris@0
|
715 } ;
|
Chris@0
|
716 test_write_double_or_die (file, 0, double_data, BUFFER_LEN, __LINE__) ;
|
Chris@0
|
717 sf_close (file) ;
|
Chris@0
|
718
|
Chris@0
|
719 memset (&read_inst, 0, sizeof (read_inst)) ;
|
Chris@0
|
720
|
Chris@0
|
721 file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
|
Chris@0
|
722 if (sf_command (file, SFC_GET_INSTRUMENT, &read_inst, sizeof (read_inst)) == SF_FALSE)
|
Chris@0
|
723 { printf ("\n\nLine %d : sf_command (SFC_GET_INSTRUMENT) failed.\n\n", __LINE__) ;
|
Chris@0
|
724 exit (1) ;
|
Chris@0
|
725 return ;
|
Chris@0
|
726 } ;
|
Chris@0
|
727 check_log_buffer_or_die (file, __LINE__) ;
|
Chris@0
|
728 sf_close (file) ;
|
Chris@0
|
729
|
Chris@0
|
730 if ((filetype & SF_FORMAT_TYPEMASK) == SF_FORMAT_WAV)
|
Chris@0
|
731 { /*
|
Chris@0
|
732 ** For all the fields that WAV doesn't support, modify the
|
Chris@0
|
733 ** write_inst struct to hold the default value that the WAV
|
Chris@0
|
734 ** module should hold.
|
Chris@0
|
735 */
|
Chris@0
|
736 write_inst.detune = 0 ;
|
Chris@0
|
737 write_inst.key_lo = write_inst.velocity_lo = 0 ;
|
Chris@0
|
738 write_inst.key_hi = write_inst.velocity_hi = 127 ;
|
Chris@0
|
739 write_inst.gain = 1 ;
|
Chris@0
|
740 } ;
|
Chris@0
|
741
|
Chris@0
|
742 if ((filetype & SF_FORMAT_TYPEMASK) == SF_FORMAT_XI)
|
Chris@0
|
743 { /*
|
Chris@0
|
744 ** For all the fields that XI doesn't support, modify the
|
Chris@0
|
745 ** write_inst struct to hold the default value that the XI
|
Chris@0
|
746 ** module should hold.
|
Chris@0
|
747 */
|
Chris@0
|
748 write_inst.basenote = 0 ;
|
Chris@0
|
749 write_inst.detune = 0 ;
|
Chris@0
|
750 write_inst.key_lo = write_inst.velocity_lo = 0 ;
|
Chris@0
|
751 write_inst.key_hi = write_inst.velocity_hi = 127 ;
|
Chris@0
|
752 write_inst.gain = 1 ;
|
Chris@0
|
753 } ;
|
Chris@0
|
754
|
Chris@0
|
755 if (memcmp (&write_inst, &read_inst, sizeof (write_inst)) != 0)
|
Chris@0
|
756 { printf ("\n\nLine %d : instrument comparison failed.\n\n", __LINE__) ;
|
Chris@0
|
757 printf ("W Base Note : %u\n"
|
Chris@0
|
758 " Detune : %u\n"
|
Chris@0
|
759 " Low Note : %u\tHigh Note : %u\n"
|
Chris@0
|
760 " Low Vel. : %u\tHigh Vel. : %u\n"
|
Chris@0
|
761 " Gain : %d\tCount : %d\n"
|
Chris@0
|
762 " mode : %d\n"
|
Chris@0
|
763 " start : %d\tend : %d\tcount :%d\n"
|
Chris@0
|
764 " mode : %d\n"
|
Chris@0
|
765 " start : %d\tend : %d\tcount :%d\n\n",
|
Chris@0
|
766 write_inst.basenote,
|
Chris@0
|
767 write_inst.detune,
|
Chris@0
|
768 write_inst.key_lo, write_inst.key_hi,
|
Chris@0
|
769 write_inst.velocity_lo, write_inst.velocity_hi,
|
Chris@0
|
770 write_inst.gain, write_inst.loop_count,
|
Chris@0
|
771 write_inst.loops [0].mode, write_inst.loops [0].start,
|
Chris@0
|
772 write_inst.loops [0].end, write_inst.loops [0].count,
|
Chris@0
|
773 write_inst.loops [1].mode, write_inst.loops [1].start,
|
Chris@0
|
774 write_inst.loops [1].end, write_inst.loops [1].count) ;
|
Chris@0
|
775 printf ("R Base Note : %u\n"
|
Chris@0
|
776 " Detune : %u\n"
|
Chris@0
|
777 " Low Note : %u\tHigh Note : %u\n"
|
Chris@0
|
778 " Low Vel. : %u\tHigh Vel. : %u\n"
|
Chris@0
|
779 " Gain : %d\tCount : %d\n"
|
Chris@0
|
780 " mode : %d\n"
|
Chris@0
|
781 " start : %d\tend : %d\tcount :%d\n"
|
Chris@0
|
782 " mode : %d\n"
|
Chris@0
|
783 " start : %d\tend : %d\tcount :%d\n\n",
|
Chris@0
|
784 read_inst.basenote,
|
Chris@0
|
785 read_inst.detune,
|
Chris@0
|
786 read_inst.key_lo, read_inst.key_hi,
|
Chris@0
|
787 read_inst.velocity_lo, read_inst.velocity_hi,
|
Chris@0
|
788 read_inst.gain, read_inst.loop_count,
|
Chris@0
|
789 read_inst.loops [0].mode, read_inst.loops [0].start,
|
Chris@0
|
790 read_inst.loops [0].end, read_inst.loops [0].count,
|
Chris@0
|
791 read_inst.loops [1].mode, read_inst.loops [1].start,
|
Chris@0
|
792 read_inst.loops [1].end, read_inst.loops [1].count) ;
|
Chris@0
|
793
|
Chris@0
|
794 if ((filetype & SF_FORMAT_TYPEMASK) != SF_FORMAT_XI)
|
Chris@0
|
795 exit (1) ;
|
Chris@0
|
796 } ;
|
Chris@0
|
797
|
Chris@0
|
798 if (0) instrumet_rw_test (filename) ;
|
Chris@0
|
799
|
Chris@0
|
800 unlink (filename) ;
|
Chris@0
|
801 puts ("ok") ;
|
Chris@0
|
802 } /* instrument_test */
|
Chris@0
|
803
|
Chris@0
|
804 static void
|
Chris@0
|
805 current_sf_info_test (const char *filename)
|
Chris@0
|
806 { SNDFILE *outfile, *infile ;
|
Chris@0
|
807 SF_INFO outinfo, ininfo ;
|
Chris@0
|
808
|
Chris@0
|
809 print_test_name ("current_sf_info_test", filename) ;
|
Chris@0
|
810
|
Chris@0
|
811 outinfo.samplerate = 44100 ;
|
Chris@0
|
812 outinfo.format = (SF_FORMAT_WAV | SF_FORMAT_PCM_16) ;
|
Chris@0
|
813 outinfo.channels = 1 ;
|
Chris@0
|
814 outinfo.frames = 0 ;
|
Chris@0
|
815
|
Chris@0
|
816 outfile = test_open_file_or_die (filename, SFM_WRITE, &outinfo, SF_TRUE, __LINE__) ;
|
Chris@0
|
817 sf_command (outfile, SFC_SET_UPDATE_HEADER_AUTO, NULL, 0) ;
|
Chris@0
|
818
|
Chris@0
|
819 exit_if_true (outinfo.frames != 0,
|
Chris@0
|
820 "\n\nLine %d : Initial sfinfo.frames is not zero.\n\n", __LINE__
|
Chris@0
|
821 ) ;
|
Chris@0
|
822
|
Chris@0
|
823 test_write_double_or_die (outfile, 0, double_data, BUFFER_LEN, __LINE__) ;
|
Chris@0
|
824 sf_command (outfile, SFC_GET_CURRENT_SF_INFO, &outinfo, sizeof (outinfo)) ;
|
Chris@0
|
825
|
Chris@0
|
826 exit_if_true (outinfo.frames != BUFFER_LEN,
|
Chris@0
|
827 "\n\nLine %d : Initial sfinfo.frames (%ld) should be %d.\n\n", __LINE__,
|
Chris@0
|
828 SF_COUNT_TO_LONG (outinfo.frames), BUFFER_LEN
|
Chris@0
|
829 ) ;
|
Chris@0
|
830
|
Chris@0
|
831 /* Read file making sure no channel map exists. */
|
Chris@0
|
832 memset (&ininfo, 0, sizeof (ininfo)) ;
|
Chris@0
|
833 infile = test_open_file_or_die (filename, SFM_READ, &ininfo, SF_TRUE, __LINE__) ;
|
Chris@0
|
834
|
Chris@0
|
835 test_write_double_or_die (outfile, 0, double_data, BUFFER_LEN, __LINE__) ;
|
Chris@0
|
836
|
Chris@0
|
837 sf_command (infile, SFC_GET_CURRENT_SF_INFO, &ininfo, sizeof (ininfo)) ;
|
Chris@0
|
838
|
Chris@0
|
839 exit_if_true (ininfo.frames != BUFFER_LEN,
|
Chris@0
|
840 "\n\nLine %d : Initial sfinfo.frames (%ld) should be %d.\n\n", __LINE__,
|
Chris@0
|
841 SF_COUNT_TO_LONG (ininfo.frames), BUFFER_LEN
|
Chris@0
|
842 ) ;
|
Chris@0
|
843
|
Chris@0
|
844 sf_close (outfile) ;
|
Chris@0
|
845 sf_close (infile) ;
|
Chris@0
|
846
|
Chris@0
|
847 unlink (filename) ;
|
Chris@0
|
848 puts ("ok") ;
|
Chris@0
|
849 } /* current_sf_info_test */
|
Chris@0
|
850
|
Chris@0
|
851 static void
|
Chris@0
|
852 broadcast_test (const char *filename, int filetype)
|
Chris@0
|
853 { static SF_BROADCAST_INFO bc_write, bc_read ;
|
Chris@0
|
854 SNDFILE *file ;
|
Chris@0
|
855 SF_INFO sfinfo ;
|
Chris@0
|
856 int errors = 0 ;
|
Chris@0
|
857
|
Chris@0
|
858 print_test_name ("broadcast_test", filename) ;
|
Chris@0
|
859
|
Chris@0
|
860 sfinfo.samplerate = 11025 ;
|
Chris@0
|
861 sfinfo.format = filetype ;
|
Chris@0
|
862 sfinfo.channels = 1 ;
|
Chris@0
|
863
|
Chris@0
|
864 memset (&bc_write, 0, sizeof (bc_write)) ;
|
Chris@0
|
865
|
Chris@0
|
866 snprintf (bc_write.description, sizeof (bc_write.description), "Test description") ;
|
Chris@0
|
867 snprintf (bc_write.originator, sizeof (bc_write.originator), "Test originator") ;
|
Chris@0
|
868 snprintf (bc_write.originator_reference, sizeof (bc_write.originator_reference), "%08x-%08x", (unsigned int) time (NULL), (unsigned int) (~ time (NULL))) ;
|
Chris@0
|
869 snprintf (bc_write.origination_date, sizeof (bc_write.origination_date), "%d/%02d/%02d", 2006, 3, 30) ;
|
Chris@0
|
870 snprintf (bc_write.origination_time, sizeof (bc_write.origination_time), "%02d:%02d:%02d", 20, 27, 0) ;
|
Chris@0
|
871 snprintf (bc_write.umid, sizeof (bc_write.umid), "Some umid") ;
|
Chris@0
|
872 bc_write.coding_history_size = 0 ;
|
Chris@0
|
873
|
Chris@0
|
874 file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
|
Chris@0
|
875 if (sf_command (file, SFC_SET_BROADCAST_INFO, &bc_write, sizeof (bc_write)) == SF_FALSE)
|
Chris@0
|
876 { printf ("\n\nLine %d : sf_command (SFC_SET_BROADCAST_INFO) failed.\n\n", __LINE__) ;
|
Chris@0
|
877 exit (1) ;
|
Chris@0
|
878 } ;
|
Chris@0
|
879 test_write_double_or_die (file, 0, double_data, BUFFER_LEN, __LINE__) ;
|
Chris@0
|
880 sf_close (file) ;
|
Chris@0
|
881
|
Chris@0
|
882 memset (&bc_read, 0, sizeof (bc_read)) ;
|
Chris@0
|
883
|
Chris@0
|
884 file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
|
Chris@0
|
885 if (sf_command (file, SFC_GET_BROADCAST_INFO, &bc_read, sizeof (bc_read)) == SF_FALSE)
|
Chris@0
|
886 { printf ("\n\nLine %d : sf_command (SFC_GET_BROADCAST_INFO) failed.\n\n", __LINE__) ;
|
Chris@0
|
887 exit (1) ;
|
Chris@0
|
888 return ;
|
Chris@0
|
889 } ;
|
Chris@0
|
890 check_log_buffer_or_die (file, __LINE__) ;
|
Chris@0
|
891 sf_close (file) ;
|
Chris@0
|
892
|
Chris@0
|
893 if (bc_read.version != 1)
|
Chris@0
|
894 { printf ("\n\nLine %d : Read bad version number %d.\n\n", __LINE__, bc_read.version) ;
|
Chris@0
|
895 exit (1) ;
|
Chris@0
|
896 return ;
|
Chris@0
|
897 } ;
|
Chris@0
|
898
|
Chris@0
|
899 bc_read.version = bc_write.version = 0 ;
|
Chris@0
|
900
|
Chris@0
|
901 if (memcmp (bc_write.description, bc_read.description, sizeof (bc_write.description)) != 0)
|
Chris@0
|
902 { printf ("\n\nLine %d : description mismatch :\n\twrite : '%s'\n\tread : '%s'\n\n", __LINE__, bc_write.description, bc_read.description) ;
|
Chris@0
|
903 errors ++ ;
|
Chris@0
|
904 } ;
|
Chris@0
|
905
|
Chris@0
|
906 if (memcmp (bc_write.originator, bc_read.originator, sizeof (bc_write.originator)) != 0)
|
Chris@0
|
907 { printf ("\n\nLine %d : originator mismatch :\n\twrite : '%s'\n\tread : '%s'\n\n", __LINE__, bc_write.originator, bc_read.originator) ;
|
Chris@0
|
908 errors ++ ;
|
Chris@0
|
909 } ;
|
Chris@0
|
910
|
Chris@0
|
911 if (memcmp (bc_write.originator_reference, bc_read.originator_reference, sizeof (bc_write.originator_reference)) != 0)
|
Chris@0
|
912 { printf ("\n\nLine %d : originator_reference mismatch :\n\twrite : '%s'\n\tread : '%s'\n\n", __LINE__, bc_write.originator_reference, bc_read.originator_reference) ;
|
Chris@0
|
913 errors ++ ;
|
Chris@0
|
914 } ;
|
Chris@0
|
915
|
Chris@0
|
916 if (memcmp (bc_write.origination_date, bc_read.origination_date, sizeof (bc_write.origination_date)) != 0)
|
Chris@0
|
917 { printf ("\n\nLine %d : origination_date mismatch :\n\twrite : '%s'\n\tread : '%s'\n\n", __LINE__, bc_write.origination_date, bc_read.origination_date) ;
|
Chris@0
|
918 errors ++ ;
|
Chris@0
|
919 } ;
|
Chris@0
|
920
|
Chris@0
|
921 if (memcmp (bc_write.origination_time, bc_read.origination_time, sizeof (bc_write.origination_time)) != 0)
|
Chris@0
|
922 { printf ("\n\nLine %d : origination_time mismatch :\n\twrite : '%s'\n\tread : '%s'\n\n", __LINE__, bc_write.origination_time, bc_read.origination_time) ;
|
Chris@0
|
923 errors ++ ;
|
Chris@0
|
924 } ;
|
Chris@0
|
925
|
Chris@0
|
926 if (memcmp (bc_write.umid, bc_read.umid, sizeof (bc_write.umid)) != 0)
|
Chris@0
|
927 { printf ("\n\nLine %d : umid mismatch :\n\twrite : '%s'\n\tread : '%s'\n\n", __LINE__, bc_write.umid, bc_read.umid) ;
|
Chris@0
|
928 errors ++ ;
|
Chris@0
|
929 } ;
|
Chris@0
|
930
|
Chris@0
|
931 if (errors)
|
Chris@0
|
932 exit (1) ;
|
Chris@0
|
933
|
Chris@0
|
934 unlink (filename) ;
|
Chris@0
|
935 puts ("ok") ;
|
Chris@0
|
936 } /* broadcast_test */
|
Chris@0
|
937
|
Chris@0
|
938 static void
|
Chris@0
|
939 broadcast_rdwr_test (const char *filename, int filetype)
|
Chris@0
|
940 { SF_BROADCAST_INFO binfo ;
|
Chris@0
|
941 SNDFILE *file ;
|
Chris@0
|
942 SF_INFO sfinfo ;
|
Chris@0
|
943 sf_count_t frames ;
|
Chris@0
|
944
|
Chris@0
|
945 print_test_name (__func__, filename) ;
|
Chris@0
|
946
|
Chris@0
|
947 create_short_sndfile (filename, filetype, 2) ;
|
Chris@0
|
948
|
Chris@0
|
949 memset (&sfinfo, 0, sizeof (sfinfo)) ;
|
Chris@0
|
950 memset (&binfo, 0, sizeof (binfo)) ;
|
Chris@0
|
951
|
Chris@0
|
952 snprintf (binfo.description, sizeof (binfo.description), "Test description") ;
|
Chris@0
|
953 snprintf (binfo.originator, sizeof (binfo.originator), "Test originator") ;
|
Chris@0
|
954 snprintf (binfo.originator_reference, sizeof (binfo.originator_reference), "%08x-%08x", (unsigned int) time (NULL), (unsigned int) (~ time (NULL))) ;
|
Chris@0
|
955 snprintf (binfo.origination_date, sizeof (binfo.origination_date), "%d/%02d/%02d", 2006, 3, 30) ;
|
Chris@0
|
956 snprintf (binfo.origination_time, sizeof (binfo.origination_time), "%02d:%02d:%02d", 20, 27, 0) ;
|
Chris@0
|
957 snprintf (binfo.umid, sizeof (binfo.umid), "Some umid") ;
|
Chris@0
|
958 binfo.coding_history_size = 0 ;
|
Chris@0
|
959
|
Chris@0
|
960 file = test_open_file_or_die (filename, SFM_RDWR, &sfinfo, SF_TRUE, __LINE__) ;
|
Chris@0
|
961 frames = sfinfo.frames ;
|
Chris@0
|
962 if (sf_command (file, SFC_SET_BROADCAST_INFO, &binfo, sizeof (binfo)) != SF_FALSE)
|
Chris@0
|
963 { printf ("\n\nLine %d : sf_command (SFC_SET_BROADCAST_INFO) should have failed but didn't.\n\n", __LINE__) ;
|
Chris@0
|
964 exit (1) ;
|
Chris@0
|
965 } ;
|
Chris@0
|
966 sf_close (file) ;
|
Chris@0
|
967
|
Chris@0
|
968 file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
|
Chris@0
|
969 sf_close (file) ;
|
Chris@0
|
970 exit_if_true (frames != sfinfo.frames, "\n\nLine %d : Frame count %lld should be %lld.\n", __LINE__, sfinfo.frames, frames) ;
|
Chris@0
|
971
|
Chris@0
|
972 unlink (filename) ;
|
Chris@0
|
973 puts ("ok") ;
|
Chris@0
|
974 } /* broadcast_rdwr_test */
|
Chris@0
|
975
|
Chris@0
|
976 static void
|
Chris@0
|
977 check_coding_history_newlines (const char *filename)
|
Chris@0
|
978 { static SF_BROADCAST_INFO bc_write, bc_read ;
|
Chris@0
|
979 SNDFILE *file ;
|
Chris@0
|
980 SF_INFO sfinfo ;
|
Chris@0
|
981 unsigned k ;
|
Chris@0
|
982
|
Chris@0
|
983 sfinfo.samplerate = 22050 ;
|
Chris@0
|
984 sfinfo.format = SF_FORMAT_WAV | SF_FORMAT_PCM_16 ;
|
Chris@0
|
985 sfinfo.channels = 1 ;
|
Chris@0
|
986
|
Chris@0
|
987 memset (&bc_write, 0, sizeof (bc_write)) ;
|
Chris@0
|
988
|
Chris@0
|
989 snprintf (bc_write.description, sizeof (bc_write.description), "Test description") ;
|
Chris@0
|
990 snprintf (bc_write.originator, sizeof (bc_write.originator), "Test originator") ;
|
Chris@0
|
991 snprintf (bc_write.originator_reference, sizeof (bc_write.originator_reference), "%08x-%08x", (unsigned int) time (NULL), (unsigned int) (~ time (NULL))) ;
|
Chris@0
|
992 snprintf (bc_write.origination_date, sizeof (bc_write.origination_date), "%d/%02d/%02d", 2006, 3, 30) ;
|
Chris@0
|
993 snprintf (bc_write.origination_time, sizeof (bc_write.origination_time), "%02d:%02d:%02d", 20, 27, 0) ;
|
Chris@0
|
994 snprintf (bc_write.umid, sizeof (bc_write.umid), "Some umid") ;
|
Chris@0
|
995 bc_write.coding_history_size = snprintf (bc_write.coding_history, sizeof (bc_write.coding_history), "This has\nUnix\nand\rMac OS9\rline endings.\nLast line") ; ;
|
Chris@0
|
996
|
Chris@0
|
997 file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
|
Chris@0
|
998 if (sf_command (file, SFC_SET_BROADCAST_INFO, &bc_write, sizeof (bc_write)) == SF_FALSE)
|
Chris@0
|
999 { printf ("\n\nLine %d : sf_command (SFC_SET_BROADCAST_INFO) failed.\n\n", __LINE__) ;
|
Chris@0
|
1000 exit (1) ;
|
Chris@0
|
1001 } ;
|
Chris@0
|
1002
|
Chris@0
|
1003 test_write_double_or_die (file, 0, double_data, BUFFER_LEN, __LINE__) ;
|
Chris@0
|
1004 sf_close (file) ;
|
Chris@0
|
1005
|
Chris@0
|
1006 memset (&bc_read, 0, sizeof (bc_read)) ;
|
Chris@0
|
1007
|
Chris@0
|
1008 file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
|
Chris@0
|
1009 if (sf_command (file, SFC_GET_BROADCAST_INFO, &bc_read, sizeof (bc_read)) == SF_FALSE)
|
Chris@0
|
1010 { printf ("\n\nLine %d : sf_command (SFC_SET_BROADCAST_INFO) failed.\n\n", __LINE__) ;
|
Chris@0
|
1011 exit (1) ;
|
Chris@0
|
1012 } ;
|
Chris@0
|
1013 check_log_buffer_or_die (file, __LINE__) ;
|
Chris@0
|
1014 sf_close (file) ;
|
Chris@0
|
1015
|
Chris@0
|
1016 if (bc_read.coding_history_size == 0)
|
Chris@0
|
1017 { printf ("\n\nLine %d : missing coding history.\n\n", __LINE__) ;
|
Chris@0
|
1018 exit (1) ;
|
Chris@0
|
1019 } ;
|
Chris@0
|
1020
|
Chris@0
|
1021 if (strstr (bc_read.coding_history, "Last line") == NULL)
|
Chris@0
|
1022 { printf ("\n\nLine %d : coding history truncated.\n\n", __LINE__) ;
|
Chris@0
|
1023 exit (1) ;
|
Chris@0
|
1024 } ;
|
Chris@0
|
1025
|
Chris@0
|
1026 for (k = 1 ; k < bc_read.coding_history_size ; k++)
|
Chris@0
|
1027 { if (bc_read.coding_history [k] == '\n' && bc_read.coding_history [k - 1] != '\r')
|
Chris@0
|
1028 { printf ("\n\nLine %d : '\\n' without '\\r' before.\n\n", __LINE__) ;
|
Chris@0
|
1029 exit (1) ;
|
Chris@0
|
1030 } ;
|
Chris@0
|
1031
|
Chris@0
|
1032 if (bc_read.coding_history [k] == '\r' && bc_read.coding_history [k + 1] != '\n')
|
Chris@0
|
1033 { printf ("\n\nLine %d : '\\r' without '\\n' after.\n\n", __LINE__) ;
|
Chris@0
|
1034 exit (1) ;
|
Chris@0
|
1035 } ;
|
Chris@0
|
1036
|
Chris@0
|
1037 if (bc_read.coding_history [k] == 0 && k < bc_read.coding_history_size - 1)
|
Chris@0
|
1038 { printf ("\n\nLine %d : '\\0' within coding history at index %d of %d.\n\n", __LINE__, k, bc_read.coding_history_size) ;
|
Chris@0
|
1039 exit (1) ;
|
Chris@0
|
1040 } ;
|
Chris@0
|
1041 } ;
|
Chris@0
|
1042
|
Chris@0
|
1043 return ;
|
Chris@0
|
1044 } /* check_coding_history_newlines */
|
Chris@0
|
1045
|
Chris@0
|
1046 static void
|
Chris@0
|
1047 broadcast_coding_history_test (const char *filename)
|
Chris@0
|
1048 { static SF_BROADCAST_INFO bc_write, bc_read ;
|
Chris@0
|
1049 SNDFILE *file ;
|
Chris@0
|
1050 SF_INFO sfinfo ;
|
Chris@0
|
1051 const char *default_history = "A=PCM,F=22050,W=16,M=mono" ;
|
Chris@0
|
1052 const char *supplied_history =
|
Chris@0
|
1053 "A=PCM,F=44100,W=24,M=mono,T=other\r\n"
|
Chris@0
|
1054 "A=PCM,F=22050,W=16,M=mono,T=yet_another\r\n" ;
|
Chris@0
|
1055
|
Chris@0
|
1056 print_test_name ("broadcast_coding_history_test", filename) ;
|
Chris@0
|
1057
|
Chris@0
|
1058 sfinfo.samplerate = 22050 ;
|
Chris@0
|
1059 sfinfo.format = SF_FORMAT_WAV | SF_FORMAT_PCM_16 ;
|
Chris@0
|
1060 sfinfo.channels = 1 ;
|
Chris@0
|
1061
|
Chris@0
|
1062 memset (&bc_write, 0, sizeof (bc_write)) ;
|
Chris@0
|
1063
|
Chris@0
|
1064 snprintf (bc_write.description, sizeof (bc_write.description), "Test description") ;
|
Chris@0
|
1065 snprintf (bc_write.originator, sizeof (bc_write.originator), "Test originator") ;
|
Chris@0
|
1066 snprintf (bc_write.originator_reference, sizeof (bc_write.originator_reference), "%08x-%08x", (unsigned int) time (NULL), (unsigned int) (~ time (NULL))) ;
|
Chris@0
|
1067 snprintf (bc_write.origination_date, sizeof (bc_write.origination_date), "%d/%02d/%02d", 2006, 3, 30) ;
|
Chris@0
|
1068 snprintf (bc_write.origination_time, sizeof (bc_write.origination_time), "%02d:%02d:%02d", 20, 27, 0) ;
|
Chris@0
|
1069 snprintf (bc_write.umid, sizeof (bc_write.umid), "Some umid") ;
|
Chris@0
|
1070 /* Coding history will be filled in by the library. */
|
Chris@0
|
1071 bc_write.coding_history_size = 0 ;
|
Chris@0
|
1072
|
Chris@0
|
1073 file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
|
Chris@0
|
1074 if (sf_command (file, SFC_SET_BROADCAST_INFO, &bc_write, sizeof (bc_write)) == SF_FALSE)
|
Chris@0
|
1075 { printf ("\n\nLine %d : sf_command (SFC_SET_BROADCAST_INFO) failed.\n\n", __LINE__) ;
|
Chris@0
|
1076 exit (1) ;
|
Chris@0
|
1077 } ;
|
Chris@0
|
1078
|
Chris@0
|
1079 test_write_double_or_die (file, 0, double_data, BUFFER_LEN, __LINE__) ;
|
Chris@0
|
1080 sf_close (file) ;
|
Chris@0
|
1081
|
Chris@0
|
1082 memset (&bc_read, 0, sizeof (bc_read)) ;
|
Chris@0
|
1083
|
Chris@0
|
1084 file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
|
Chris@0
|
1085 if (sf_command (file, SFC_GET_BROADCAST_INFO, &bc_read, sizeof (bc_read)) == SF_FALSE)
|
Chris@0
|
1086 { printf ("\n\nLine %d : sf_command (SFC_SET_BROADCAST_INFO) failed.\n\n", __LINE__) ;
|
Chris@0
|
1087 exit (1) ;
|
Chris@0
|
1088 } ;
|
Chris@0
|
1089 check_log_buffer_or_die (file, __LINE__) ;
|
Chris@0
|
1090 sf_close (file) ;
|
Chris@0
|
1091
|
Chris@0
|
1092 if (bc_read.coding_history_size == 0)
|
Chris@0
|
1093 { printf ("\n\nLine %d : missing coding history.\n\n", __LINE__) ;
|
Chris@0
|
1094 exit (1) ;
|
Chris@0
|
1095 } ;
|
Chris@0
|
1096
|
Chris@0
|
1097 if (bc_read.coding_history_size < strlen (default_history) || memcmp (bc_read.coding_history, default_history, strlen (default_history)) != 0)
|
Chris@0
|
1098 { printf ("\n\n"
|
Chris@0
|
1099 "Line %d : unexpected coding history '%.*s',\n"
|
Chris@0
|
1100 " should be '%s'\n\n", __LINE__, bc_read.coding_history_size, bc_read.coding_history, default_history) ;
|
Chris@0
|
1101 exit (1) ;
|
Chris@0
|
1102 } ;
|
Chris@0
|
1103
|
Chris@0
|
1104 bc_write.coding_history_size = strlen (supplied_history) ;
|
Chris@0
|
1105 bc_write.coding_history_size = snprintf (bc_write.coding_history, sizeof (bc_write.coding_history), "%s", supplied_history) ;
|
Chris@0
|
1106
|
Chris@0
|
1107 file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
|
Chris@0
|
1108 if (sf_command (file, SFC_SET_BROADCAST_INFO, &bc_write, sizeof (bc_write)) == SF_FALSE)
|
Chris@0
|
1109 { printf ("\n\nLine %d : sf_command (SFC_SET_BROADCAST_INFO) failed.\n\n", __LINE__) ;
|
Chris@0
|
1110 exit (1) ;
|
Chris@0
|
1111 } ;
|
Chris@0
|
1112
|
Chris@0
|
1113 test_write_double_or_die (file, 0, double_data, BUFFER_LEN, __LINE__) ;
|
Chris@0
|
1114 sf_close (file) ;
|
Chris@0
|
1115
|
Chris@0
|
1116 memset (&bc_read, 0, sizeof (bc_read)) ;
|
Chris@0
|
1117
|
Chris@0
|
1118 file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
|
Chris@0
|
1119 if (sf_command (file, SFC_GET_BROADCAST_INFO, &bc_read, sizeof (bc_read)) == SF_FALSE)
|
Chris@0
|
1120 { printf ("\n\nLine %d : sf_command (SFC_SET_BROADCAST_INFO) failed.\n\n", __LINE__) ;
|
Chris@0
|
1121 exit (1) ;
|
Chris@0
|
1122 } ;
|
Chris@0
|
1123
|
Chris@0
|
1124 check_log_buffer_or_die (file, __LINE__) ;
|
Chris@0
|
1125 sf_close (file) ;
|
Chris@0
|
1126
|
Chris@0
|
1127 if (strstr (bc_read.coding_history, supplied_history) != bc_read.coding_history)
|
Chris@0
|
1128 { printf ("\n\nLine %d : unexpected coding history :\n"
|
Chris@0
|
1129 "----------------------------------------------------\n%s"
|
Chris@0
|
1130 "----------------------------------------------------\n"
|
Chris@0
|
1131 "should be this :\n"
|
Chris@0
|
1132 "----------------------------------------------------\n%s"
|
Chris@0
|
1133 "----------------------------------------------------\n"
|
Chris@0
|
1134 "with one more line at the end.\n\n",
|
Chris@0
|
1135 __LINE__, bc_read.coding_history, supplied_history) ;
|
Chris@0
|
1136 exit (1) ;
|
Chris@0
|
1137 } ;
|
Chris@0
|
1138
|
Chris@0
|
1139 check_coding_history_newlines (filename) ;
|
Chris@0
|
1140
|
Chris@0
|
1141 unlink (filename) ;
|
Chris@0
|
1142 puts ("ok") ;
|
Chris@0
|
1143 } /* broadcast_coding_history_test */
|
Chris@0
|
1144
|
Chris@0
|
1145 /*==============================================================================
|
Chris@0
|
1146 */
|
Chris@0
|
1147
|
Chris@0
|
1148 static void
|
Chris@0
|
1149 broadcast_coding_history_size (const char *filename)
|
Chris@0
|
1150 { /* SF_BROADCAST_INFO struct with coding_history field of 1024 bytes. */
|
Chris@0
|
1151 static SF_BROADCAST_INFO_VAR (1024) bc_write ;
|
Chris@0
|
1152 static SF_BROADCAST_INFO_VAR (1024) bc_read ;
|
Chris@0
|
1153 SNDFILE *file ;
|
Chris@0
|
1154 SF_INFO sfinfo ;
|
Chris@0
|
1155 int k ;
|
Chris@0
|
1156
|
Chris@0
|
1157 print_test_name (__func__, filename) ;
|
Chris@0
|
1158
|
Chris@0
|
1159 sfinfo.samplerate = 22050 ;
|
Chris@0
|
1160 sfinfo.format = SF_FORMAT_WAV | SF_FORMAT_PCM_16 ;
|
Chris@0
|
1161 sfinfo.channels = 1 ;
|
Chris@0
|
1162
|
Chris@0
|
1163 memset (&bc_write, 0, sizeof (bc_write)) ;
|
Chris@0
|
1164
|
Chris@0
|
1165 snprintf (bc_write.description, sizeof (bc_write.description), "Test description") ;
|
Chris@0
|
1166 snprintf (bc_write.originator, sizeof (bc_write.originator), "Test originator") ;
|
Chris@0
|
1167 snprintf (bc_write.originator_reference, sizeof (bc_write.originator_reference), "%08x-%08x", (unsigned int) time (NULL), (unsigned int) (~ time (NULL))) ;
|
Chris@0
|
1168 snprintf (bc_write.origination_date, sizeof (bc_write.origination_date), "%d/%02d/%02d", 2006, 3, 30) ;
|
Chris@0
|
1169 snprintf (bc_write.origination_time, sizeof (bc_write.origination_time), "%02d:%02d:%02d", 20, 27, 0) ;
|
Chris@0
|
1170 snprintf (bc_write.umid, sizeof (bc_write.umid), "Some umid") ;
|
Chris@0
|
1171 bc_write.coding_history_size = 0 ;
|
Chris@0
|
1172
|
Chris@0
|
1173 for (k = 0 ; bc_write.coding_history_size < 512 ; k++)
|
Chris@0
|
1174 { snprintf (bc_write.coding_history + bc_write.coding_history_size,
|
Chris@0
|
1175 sizeof (bc_write.coding_history) - bc_write.coding_history_size, "line %4d\n", k) ;
|
Chris@0
|
1176 bc_write.coding_history_size = strlen (bc_write.coding_history) ;
|
Chris@0
|
1177 } ;
|
Chris@0
|
1178
|
Chris@0
|
1179 exit_if_true (bc_write.coding_history_size < 512,
|
Chris@0
|
1180 "\n\nLine %d : bc_write.coding_history_size (%d) should be > 512.\n\n", __LINE__, bc_write.coding_history_size) ;
|
Chris@0
|
1181
|
Chris@0
|
1182 file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
|
Chris@0
|
1183 if (sf_command (file, SFC_SET_BROADCAST_INFO, &bc_write, sizeof (bc_write)) == SF_FALSE)
|
Chris@0
|
1184 { printf ("\n\nLine %d : sf_command (SFC_SET_BROADCAST_INFO) failed.\n\n", __LINE__) ;
|
Chris@0
|
1185 exit (1) ;
|
Chris@0
|
1186 } ;
|
Chris@0
|
1187
|
Chris@0
|
1188 test_write_double_or_die (file, 0, double_data, BUFFER_LEN, __LINE__) ;
|
Chris@0
|
1189 sf_close (file) ;
|
Chris@0
|
1190
|
Chris@0
|
1191 memset (&bc_read, 0, sizeof (bc_read)) ;
|
Chris@0
|
1192
|
Chris@0
|
1193 file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
|
Chris@0
|
1194 if (sf_command (file, SFC_GET_BROADCAST_INFO, &bc_read, sizeof (bc_read)) == SF_FALSE)
|
Chris@0
|
1195 { printf ("\n\nLine %d : sf_command (SFC_SET_BROADCAST_INFO) failed.\n\n", __LINE__) ;
|
Chris@0
|
1196 exit (1) ;
|
Chris@0
|
1197 } ;
|
Chris@0
|
1198 check_log_buffer_or_die (file, __LINE__) ;
|
Chris@0
|
1199 sf_close (file) ;
|
Chris@0
|
1200
|
Chris@0
|
1201 exit_if_true (bc_read.coding_history_size < 512,
|
Chris@0
|
1202 "\n\nLine %d : unexpected coding history size %d (should be > 512).\n\n", __LINE__, bc_read.coding_history_size) ;
|
Chris@0
|
1203
|
Chris@0
|
1204 exit_if_true (strstr (bc_read.coding_history, "libsndfile") == NULL,
|
Chris@0
|
1205 "\n\nLine %d : coding history incomplete (should contain 'libsndfile').\n\n", __LINE__) ;
|
Chris@0
|
1206
|
Chris@0
|
1207 unlink (filename) ;
|
Chris@0
|
1208 puts ("ok") ;
|
Chris@0
|
1209 } /* broadcast_coding_history_size */
|
Chris@0
|
1210
|
Chris@0
|
1211 /*==============================================================================
|
Chris@0
|
1212 */
|
Chris@0
|
1213
|
Chris@0
|
1214 static void
|
Chris@0
|
1215 channel_map_test (const char *filename, int filetype)
|
Chris@0
|
1216 { SNDFILE *file ;
|
Chris@0
|
1217 SF_INFO sfinfo ;
|
Chris@0
|
1218 int channel_map_read [4], channel_map_write [4] =
|
Chris@0
|
1219 { SF_CHANNEL_MAP_LEFT, SF_CHANNEL_MAP_RIGHT, SF_CHANNEL_MAP_LFE,
|
Chris@0
|
1220 SF_CHANNEL_MAP_REAR_CENTER
|
Chris@0
|
1221 } ;
|
Chris@0
|
1222
|
Chris@0
|
1223 print_test_name ("channel_map_test", filename) ;
|
Chris@0
|
1224
|
Chris@0
|
1225 memset (&sfinfo, 0, sizeof (sfinfo)) ;
|
Chris@0
|
1226 sfinfo.samplerate = 11025 ;
|
Chris@0
|
1227 sfinfo.format = filetype ;
|
Chris@0
|
1228 sfinfo.channels = ARRAY_LEN (channel_map_read) ;
|
Chris@0
|
1229
|
Chris@0
|
1230 switch (filetype & SF_FORMAT_TYPEMASK)
|
Chris@0
|
1231 { /* WAVEX and RF64 have a default channel map, even if you don't specify one. */
|
Chris@0
|
1232 case SF_FORMAT_WAVEX :
|
Chris@0
|
1233 case SF_FORMAT_RF64 :
|
Chris@0
|
1234 /* Write file without channel map. */
|
Chris@0
|
1235 file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
|
Chris@0
|
1236 test_write_double_or_die (file, 0, double_data, BUFFER_LEN, __LINE__) ;
|
Chris@0
|
1237 sf_close (file) ;
|
Chris@0
|
1238
|
Chris@0
|
1239 /* Read file making default channel map exists. */
|
Chris@0
|
1240 file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
|
Chris@0
|
1241 exit_if_true (
|
Chris@0
|
1242 sf_command (file, SFC_GET_CHANNEL_MAP_INFO, channel_map_read, sizeof (channel_map_read)) == SF_FALSE,
|
Chris@0
|
1243 "\n\nLine %d : sf_command (SFC_GET_CHANNEL_MAP_INFO) should not have failed.\n\n", __LINE__
|
Chris@0
|
1244 ) ;
|
Chris@0
|
1245 check_log_buffer_or_die (file, __LINE__) ;
|
Chris@0
|
1246 sf_close (file) ;
|
Chris@0
|
1247 break ;
|
Chris@0
|
1248
|
Chris@0
|
1249 default :
|
Chris@0
|
1250 break ;
|
Chris@0
|
1251 } ;
|
Chris@0
|
1252
|
Chris@0
|
1253 /* Write file with a channel map. */
|
Chris@0
|
1254 file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
|
Chris@0
|
1255 exit_if_true (
|
Chris@0
|
1256 sf_command (file, SFC_SET_CHANNEL_MAP_INFO, channel_map_write, sizeof (channel_map_write)) == SF_FALSE,
|
Chris@0
|
1257 "\n\nLine %d : sf_command (SFC_SET_CHANNEL_MAP_INFO) failed.\n\n", __LINE__
|
Chris@0
|
1258 ) ;
|
Chris@0
|
1259 test_write_double_or_die (file, 0, double_data, BUFFER_LEN, __LINE__) ;
|
Chris@0
|
1260 sf_close (file) ;
|
Chris@0
|
1261
|
Chris@0
|
1262 /* Read file making sure no channel map exists. */
|
Chris@0
|
1263 file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
|
Chris@0
|
1264 exit_if_true (
|
Chris@0
|
1265 sf_command (file, SFC_GET_CHANNEL_MAP_INFO, channel_map_read, sizeof (channel_map_read)) != SF_TRUE,
|
Chris@0
|
1266 "\n\nLine %d : sf_command (SFC_GET_CHANNEL_MAP_INFO) failed.\n\n", __LINE__
|
Chris@0
|
1267 ) ;
|
Chris@0
|
1268 check_log_buffer_or_die (file, __LINE__) ;
|
Chris@0
|
1269 sf_close (file) ;
|
Chris@0
|
1270
|
Chris@0
|
1271 exit_if_true (
|
Chris@0
|
1272 memcmp (channel_map_read, channel_map_write, sizeof (channel_map_read)) != 0,
|
Chris@0
|
1273 "\n\nLine %d : Channel map read does not match channel map written.\n\n", __LINE__
|
Chris@0
|
1274 ) ;
|
Chris@0
|
1275
|
Chris@0
|
1276 unlink (filename) ;
|
Chris@0
|
1277 puts ("ok") ;
|
Chris@0
|
1278 } /* channel_map_test */
|
Chris@0
|
1279
|
Chris@0
|
1280 static void
|
Chris@0
|
1281 raw_needs_endswap_test (const char *filename, int filetype)
|
Chris@0
|
1282 { static int subtypes [] =
|
Chris@0
|
1283 { SF_FORMAT_FLOAT, SF_FORMAT_DOUBLE,
|
Chris@0
|
1284 SF_FORMAT_PCM_16, SF_FORMAT_PCM_24, SF_FORMAT_PCM_32
|
Chris@0
|
1285 } ;
|
Chris@0
|
1286 SNDFILE *file ;
|
Chris@0
|
1287 SF_INFO sfinfo ;
|
Chris@0
|
1288 unsigned k ;
|
Chris@0
|
1289 int needs_endswap ;
|
Chris@0
|
1290
|
Chris@0
|
1291 print_test_name (__func__, filename) ;
|
Chris@0
|
1292
|
Chris@0
|
1293 for (k = 0 ; k < ARRAY_LEN (subtypes) ; k++)
|
Chris@0
|
1294 {
|
Chris@0
|
1295 if (filetype == (SF_ENDIAN_LITTLE | SF_FORMAT_AIFF))
|
Chris@0
|
1296 switch (subtypes [k])
|
Chris@0
|
1297 { /* Little endian AIFF does not AFAIK support fl32 and fl64. */
|
Chris@0
|
1298 case SF_FORMAT_FLOAT :
|
Chris@0
|
1299 case SF_FORMAT_DOUBLE :
|
Chris@0
|
1300 continue ;
|
Chris@0
|
1301 default :
|
Chris@0
|
1302 break ;
|
Chris@0
|
1303 } ;
|
Chris@0
|
1304
|
Chris@0
|
1305 memset (&sfinfo, 0, sizeof (sfinfo)) ;
|
Chris@0
|
1306 sfinfo.samplerate = 11025 ;
|
Chris@0
|
1307 sfinfo.format = filetype | subtypes [k] ;
|
Chris@0
|
1308 sfinfo.channels = 1 ;
|
Chris@0
|
1309
|
Chris@0
|
1310 file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
|
Chris@0
|
1311 test_write_double_or_die (file, 0, double_data, BUFFER_LEN, __LINE__) ;
|
Chris@0
|
1312 sf_close (file) ;
|
Chris@0
|
1313
|
Chris@0
|
1314 memset (&sfinfo, 0, sizeof (sfinfo)) ;
|
Chris@0
|
1315 file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
|
Chris@0
|
1316
|
Chris@0
|
1317 needs_endswap = sf_command (file, SFC_RAW_DATA_NEEDS_ENDSWAP, NULL, 0) ;
|
Chris@0
|
1318
|
Chris@0
|
1319 switch (filetype)
|
Chris@0
|
1320 { case SF_FORMAT_WAV :
|
Chris@0
|
1321 case SF_FORMAT_WAVEX :
|
Chris@0
|
1322 case SF_FORMAT_AIFF | SF_ENDIAN_LITTLE :
|
Chris@0
|
1323 exit_if_true (needs_endswap != CPU_IS_BIG_ENDIAN,
|
Chris@0
|
1324 "\n\nLine %d : SFC_RAW_DATA_NEEDS_ENDSWAP failed for (%d | %d).\n\n", __LINE__, filetype, k) ;
|
Chris@0
|
1325 break ;
|
Chris@0
|
1326
|
Chris@0
|
1327 case SF_FORMAT_AIFF :
|
Chris@0
|
1328 case SF_FORMAT_WAV | SF_ENDIAN_BIG :
|
Chris@0
|
1329 exit_if_true (needs_endswap != CPU_IS_LITTLE_ENDIAN,
|
Chris@0
|
1330 "\n\nLine %d : SFC_RAW_DATA_NEEDS_ENDSWAP failed for (%d | %d).\n\n", __LINE__, filetype, k) ;
|
Chris@0
|
1331 break ;
|
Chris@0
|
1332
|
Chris@0
|
1333 default :
|
Chris@0
|
1334 printf ("\n\nLine %d : bad format value %d.\n\n", __LINE__, filetype) ;
|
Chris@0
|
1335 exit (1) ;
|
Chris@0
|
1336 break ;
|
Chris@0
|
1337 } ;
|
Chris@0
|
1338
|
Chris@0
|
1339 sf_close (file) ;
|
Chris@0
|
1340 } ;
|
Chris@0
|
1341
|
Chris@0
|
1342 unlink (filename) ;
|
Chris@0
|
1343 puts ("ok") ;
|
Chris@0
|
1344 } /* raw_needs_endswap_test */
|