Mercurial > hg > sv-dependency-builds
comparison src/libsndfile-1.0.27/tests/command_test.c @ 40:1df64224f5ac
Current libsndfile source
author | Chris Cannam |
---|---|
date | Tue, 18 Oct 2016 13:22:47 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
39:7ddb4fc30dac | 40:1df64224f5ac |
---|---|
1 /* | |
2 ** Copyright (C) 2001-2016 Erik de Castro Lopo <erikd@mega-nerd.com> | |
3 ** | |
4 ** This program is free software; you can redistribute it and/or modify | |
5 ** it under the terms of the GNU General Public License as published by | |
6 ** the Free Software Foundation; either version 2 of the License, or | |
7 ** (at your option) any later version. | |
8 ** | |
9 ** This program is distributed in the hope that it will be useful, | |
10 ** but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 ** GNU General Public License for more details. | |
13 ** | |
14 ** You should have received a copy of the GNU General Public License | |
15 ** along with this program; if not, write to the Free Software | |
16 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | |
17 */ | |
18 | |
19 #include "sfconfig.h" | |
20 | |
21 #include <stdio.h> | |
22 #include <stdlib.h> | |
23 #include <stdint.h> | |
24 #include <inttypes.h> | |
25 #include <string.h> | |
26 #include <time.h> | |
27 | |
28 #if HAVE_UNISTD_H | |
29 #include <unistd.h> | |
30 #endif | |
31 | |
32 #include <math.h> | |
33 | |
34 #include <sndfile.h> | |
35 | |
36 #include "sfendian.h" | |
37 #include "utils.h" | |
38 | |
39 #define BUFFER_LEN (1 << 10) | |
40 #define LOG_BUFFER_SIZE 1024 | |
41 #define data_MARKER MAKE_MARKER ('d', 'a', 't', 'a') | |
42 | |
43 static void float_norm_test (const char *filename) ; | |
44 static void double_norm_test (const char *filename) ; | |
45 static void format_tests (void) ; | |
46 static void calc_peak_test (int filetype, const char *filename, int channels) ; | |
47 static void truncate_test (const char *filename, int filetype) ; | |
48 static void instrument_test (const char *filename, int filetype) ; | |
49 static void cue_test (const char *filename, int filetype) ; | |
50 static void channel_map_test (const char *filename, int filetype) ; | |
51 static void current_sf_info_test (const char *filename) ; | |
52 static void raw_needs_endswap_test (const char *filename, int filetype) ; | |
53 | |
54 static void broadcast_test (const char *filename, int filetype) ; | |
55 static void broadcast_rdwr_test (const char *filename, int filetype) ; | |
56 static void broadcast_coding_history_test (const char *filename) ; | |
57 static void broadcast_coding_history_size (const char *filename) ; | |
58 | |
59 /* Cart Chunk tests */ | |
60 static void cart_test (const char *filename, int filetype) ; | |
61 static void cart_rdwr_test (const char *filename, int filetype) ; | |
62 | |
63 /* Force the start of this buffer to be double aligned. Sparc-solaris will | |
64 ** choke if its not. | |
65 */ | |
66 | |
67 static int int_data [BUFFER_LEN] ; | |
68 static float float_data [BUFFER_LEN] ; | |
69 static double double_data [BUFFER_LEN] ; | |
70 | |
71 int | |
72 main (int argc, char *argv []) | |
73 { int do_all = 0 ; | |
74 int test_count = 0 ; | |
75 | |
76 if (argc != 2) | |
77 { printf ("Usage : %s <test>\n", argv [0]) ; | |
78 printf (" Where <test> is one of the following:\n") ; | |
79 printf (" ver - test sf_command (SFC_GETLIB_VERSION)\n") ; | |
80 printf (" norm - test floating point normalisation\n") ; | |
81 printf (" format - test format string commands\n") ; | |
82 printf (" peak - test peak calculation\n") ; | |
83 printf (" trunc - test file truncation\n") ; | |
84 printf (" inst - test set/get of SF_INSTRUMENT.\n") ; | |
85 printf (" cue - test set/get of SF_CUES.\n") ; | |
86 printf (" chanmap - test set/get of channel map data..\n") ; | |
87 printf (" bext - test set/get of SF_BROADCAST_INFO.\n") ; | |
88 printf (" bextch - test set/get of SF_BROADCAST_INFO coding_history.\n") ; | |
89 printf (" cart - test set/get of SF_CART_INFO.\n") ; | |
90 printf (" rawend - test SFC_RAW_NEEDS_ENDSWAP.\n") ; | |
91 printf (" all - perform all tests\n") ; | |
92 exit (1) ; | |
93 } ; | |
94 | |
95 do_all = ! strcmp (argv [1], "all") ; | |
96 | |
97 if (do_all || strcmp (argv [1], "ver") == 0) | |
98 { char buffer [128] ; | |
99 | |
100 print_test_name ("version_test", "(none)") ; | |
101 buffer [0] = 0 ; | |
102 sf_command (NULL, SFC_GET_LIB_VERSION, buffer, sizeof (buffer)) ; | |
103 if (strlen (buffer) < 1) | |
104 { printf ("Line %d: could not retrieve lib version.\n", __LINE__) ; | |
105 exit (1) ; | |
106 } ; | |
107 puts ("ok") ; | |
108 test_count ++ ; | |
109 } ; | |
110 | |
111 if (do_all || strcmp (argv [1], "norm") == 0) | |
112 { /* Preliminary float/double normalisation tests. More testing | |
113 ** is done in the program 'floating_point_test'. | |
114 */ | |
115 float_norm_test ("float.wav") ; | |
116 double_norm_test ("double.wav") ; | |
117 test_count ++ ; | |
118 } ; | |
119 | |
120 if (do_all || strcmp (argv [1], "peak") == 0) | |
121 { calc_peak_test (SF_ENDIAN_BIG | SF_FORMAT_RAW, "be-peak.raw", 1) ; | |
122 calc_peak_test (SF_ENDIAN_LITTLE | SF_FORMAT_RAW, "le-peak.raw", 1) ; | |
123 calc_peak_test (SF_ENDIAN_BIG | SF_FORMAT_RAW, "be-peak.raw", 7) ; | |
124 calc_peak_test (SF_ENDIAN_LITTLE | SF_FORMAT_RAW, "le-peak.raw", 7) ; | |
125 test_count ++ ; | |
126 } ; | |
127 | |
128 if (do_all || ! strcmp (argv [1], "format")) | |
129 { format_tests () ; | |
130 test_count ++ ; | |
131 } ; | |
132 | |
133 if (do_all || strcmp (argv [1], "trunc") == 0) | |
134 { truncate_test ("truncate.raw", SF_FORMAT_RAW | SF_FORMAT_PCM_32) ; | |
135 truncate_test ("truncate.au" , SF_FORMAT_AU | SF_FORMAT_PCM_16) ; | |
136 test_count ++ ; | |
137 } ; | |
138 | |
139 if (do_all || strcmp (argv [1], "inst") == 0) | |
140 { instrument_test ("instrument.wav", SF_FORMAT_WAV | SF_FORMAT_PCM_16) ; | |
141 instrument_test ("instrument.aiff" , SF_FORMAT_AIFF | SF_FORMAT_PCM_24) ; | |
142 /*-instrument_test ("instrument.xi", SF_FORMAT_XI | SF_FORMAT_DPCM_16) ;-*/ | |
143 test_count ++ ; | |
144 } ; | |
145 | |
146 if (do_all || strcmp (argv [1], "cue") == 0) | |
147 { cue_test ("cue.wav", SF_FORMAT_WAV | SF_FORMAT_PCM_16) ; | |
148 cue_test ("cue.aiff" , SF_FORMAT_AIFF | SF_FORMAT_PCM_24) ; | |
149 test_count ++ ; | |
150 } ; | |
151 | |
152 if (do_all || strcmp (argv [1], "current_sf_info") == 0) | |
153 { current_sf_info_test ("current.wav") ; | |
154 test_count ++ ; | |
155 } ; | |
156 | |
157 if (do_all || strcmp (argv [1], "bext") == 0) | |
158 { broadcast_test ("broadcast.wav", SF_FORMAT_WAV | SF_FORMAT_PCM_16) ; | |
159 broadcast_rdwr_test ("broadcast.wav", SF_FORMAT_WAV | SF_FORMAT_PCM_16) ; | |
160 | |
161 broadcast_test ("broadcast.wavex", SF_FORMAT_WAVEX | SF_FORMAT_PCM_16) ; | |
162 broadcast_rdwr_test ("broadcast.wavex", SF_FORMAT_WAVEX | SF_FORMAT_PCM_16) ; | |
163 | |
164 broadcast_test ("broadcast.rf64", SF_FORMAT_RF64 | SF_FORMAT_PCM_16) ; | |
165 broadcast_rdwr_test ("broadcast.rf64", SF_FORMAT_RF64 | SF_FORMAT_PCM_16) ; | |
166 test_count ++ ; | |
167 } ; | |
168 | |
169 if (do_all || strcmp (argv [1], "cart") == 0) | |
170 { cart_test ("cart.wav", SF_FORMAT_WAV | SF_FORMAT_PCM_16) ; | |
171 cart_rdwr_test ("cart.wav", SF_FORMAT_WAV | SF_FORMAT_PCM_16) ; | |
172 cart_test ("cart.rf64", SF_FORMAT_RF64 | SF_FORMAT_PCM_16) ; | |
173 cart_rdwr_test ("cart.rf64", SF_FORMAT_RF64 | SF_FORMAT_PCM_16) ; | |
174 test_count ++ ; | |
175 } ; | |
176 | |
177 if (do_all || strcmp (argv [1], "bextch") == 0) | |
178 { broadcast_coding_history_test ("coding_history.wav") ; | |
179 broadcast_coding_history_size ("coding_hist_size.wav") ; | |
180 test_count ++ ; | |
181 } ; | |
182 | |
183 if (do_all || strcmp (argv [1], "chanmap") == 0) | |
184 { channel_map_test ("chanmap.wavex", SF_FORMAT_WAVEX | SF_FORMAT_PCM_16) ; | |
185 channel_map_test ("chanmap.rf64", SF_FORMAT_RF64 | SF_FORMAT_PCM_16) ; | |
186 channel_map_test ("chanmap.aifc" , SF_FORMAT_AIFF | SF_FORMAT_PCM_16) ; | |
187 channel_map_test ("chanmap.caf" , SF_FORMAT_CAF | SF_FORMAT_PCM_16) ; | |
188 test_count ++ ; | |
189 } ; | |
190 | |
191 if (do_all || strcmp (argv [1], "rawend") == 0) | |
192 { raw_needs_endswap_test ("raw_end.wav", SF_FORMAT_WAV) ; | |
193 raw_needs_endswap_test ("raw_end.wavex", SF_FORMAT_WAVEX) ; | |
194 raw_needs_endswap_test ("raw_end.rifx", SF_ENDIAN_BIG | SF_FORMAT_WAV) ; | |
195 raw_needs_endswap_test ("raw_end.aiff", SF_FORMAT_AIFF) ; | |
196 raw_needs_endswap_test ("raw_end.aiff_le", SF_ENDIAN_LITTLE | SF_FORMAT_AIFF) ; | |
197 test_count ++ ; | |
198 } ; | |
199 | |
200 if (test_count == 0) | |
201 { printf ("Mono : ************************************\n") ; | |
202 printf ("Mono : * No '%s' test defined.\n", argv [1]) ; | |
203 printf ("Mono : ************************************\n") ; | |
204 return 1 ; | |
205 } ; | |
206 | |
207 return 0 ; | |
208 } /* main */ | |
209 | |
210 /*============================================================================================ | |
211 ** Here are the test functions. | |
212 */ | |
213 | |
214 static void | |
215 float_norm_test (const char *filename) | |
216 { SNDFILE *file ; | |
217 SF_INFO sfinfo ; | |
218 unsigned int k ; | |
219 | |
220 print_test_name ("float_norm_test", filename) ; | |
221 | |
222 sfinfo.samplerate = 44100 ; | |
223 sfinfo.format = (SF_FORMAT_RAW | SF_FORMAT_PCM_16) ; | |
224 sfinfo.channels = 1 ; | |
225 sfinfo.frames = BUFFER_LEN ; | |
226 | |
227 /* Create float_data with all values being less than 1.0. */ | |
228 for (k = 0 ; k < BUFFER_LEN / 2 ; k++) | |
229 float_data [k] = (k + 5) / (2.0 * BUFFER_LEN) ; | |
230 for (k = BUFFER_LEN / 2 ; k < BUFFER_LEN ; k++) | |
231 float_data [k] = (k + 5) ; | |
232 | |
233 if (! (file = sf_open (filename, SFM_WRITE, &sfinfo))) | |
234 { printf ("Line %d: sf_open_write failed with error : ", __LINE__) ; | |
235 fflush (stdout) ; | |
236 puts (sf_strerror (NULL)) ; | |
237 exit (1) ; | |
238 } ; | |
239 | |
240 /* Normalisation is on by default so no need to do anything here. */ | |
241 | |
242 if ((k = sf_write_float (file, float_data, BUFFER_LEN / 2)) != BUFFER_LEN / 2) | |
243 { printf ("Line %d: sf_write_float failed with short write (%d ->%d)\n", __LINE__, BUFFER_LEN, k) ; | |
244 exit (1) ; | |
245 } ; | |
246 | |
247 /* Turn normalisation off. */ | |
248 sf_command (file, SFC_SET_NORM_FLOAT, NULL, SF_FALSE) ; | |
249 | |
250 if ((k = sf_write_float (file, float_data + BUFFER_LEN / 2, BUFFER_LEN / 2)) != BUFFER_LEN / 2) | |
251 { printf ("Line %d: sf_write_float failed with short write (%d ->%d)\n", __LINE__, BUFFER_LEN, k) ; | |
252 exit (1) ; | |
253 } ; | |
254 | |
255 sf_close (file) ; | |
256 | |
257 /* sfinfo struct should still contain correct data. */ | |
258 if (! (file = sf_open (filename, SFM_READ, &sfinfo))) | |
259 { printf ("Line %d: sf_open_read failed with error : ", __LINE__) ; | |
260 fflush (stdout) ; | |
261 puts (sf_strerror (NULL)) ; | |
262 exit (1) ; | |
263 } ; | |
264 | |
265 if (sfinfo.format != (SF_FORMAT_RAW | SF_FORMAT_PCM_16)) | |
266 { printf ("Line %d: Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__, (SF_FORMAT_RAW | SF_FORMAT_PCM_16), sfinfo.format) ; | |
267 exit (1) ; | |
268 } ; | |
269 | |
270 if (sfinfo.frames != BUFFER_LEN) | |
271 { printf ("\n\nLine %d: Incorrect number of.frames in file. (%d => %" PRId64 ")\n", __LINE__, BUFFER_LEN, sfinfo.frames) ; | |
272 exit (1) ; | |
273 } ; | |
274 | |
275 if (sfinfo.channels != 1) | |
276 { printf ("Line %d: Incorrect number of channels in file.\n", __LINE__) ; | |
277 exit (1) ; | |
278 } ; | |
279 | |
280 /* Read float_data and check that it is normalised (ie default). */ | |
281 if ((k = sf_read_float (file, float_data, BUFFER_LEN)) != BUFFER_LEN) | |
282 { printf ("\n\nLine %d: sf_read_float failed with short read (%d ->%d)\n", __LINE__, BUFFER_LEN, k) ; | |
283 exit (1) ; | |
284 } ; | |
285 | |
286 for (k = 0 ; k < BUFFER_LEN ; k++) | |
287 if (float_data [k] >= 1.0) | |
288 { printf ("\n\nLine %d: float_data [%d] == %f which is greater than 1.0\n", __LINE__, k, float_data [k]) ; | |
289 exit (1) ; | |
290 } ; | |
291 | |
292 /* Seek to start of file, turn normalisation off, read float_data and check again. */ | |
293 sf_seek (file, 0, SEEK_SET) ; | |
294 sf_command (file, SFC_SET_NORM_FLOAT, NULL, SF_FALSE) ; | |
295 | |
296 if ((k = sf_read_float (file, float_data, BUFFER_LEN)) != BUFFER_LEN) | |
297 { printf ("\n\nLine %d: sf_read_float failed with short read (%d ->%d)\n", __LINE__, BUFFER_LEN, k) ; | |
298 exit (1) ; | |
299 } ; | |
300 | |
301 for (k = 0 ; k < BUFFER_LEN ; k++) | |
302 if (float_data [k] < 1.0) | |
303 { printf ("\n\nLine %d: float_data [%d] == %f which is less than 1.0\n", __LINE__, k, float_data [k]) ; | |
304 exit (1) ; | |
305 } ; | |
306 | |
307 /* Seek to start of file, turn normalisation on, read float_data and do final check. */ | |
308 sf_seek (file, 0, SEEK_SET) ; | |
309 sf_command (file, SFC_SET_NORM_FLOAT, NULL, SF_TRUE) ; | |
310 | |
311 if ((k = sf_read_float (file, float_data, BUFFER_LEN)) != BUFFER_LEN) | |
312 { printf ("\n\nLine %d: sf_read_float failed with short read (%d ->%d)\n", __LINE__, BUFFER_LEN, k) ; | |
313 exit (1) ; | |
314 } ; | |
315 | |
316 for (k = 0 ; k < BUFFER_LEN ; k++) | |
317 if (float_data [k] > 1.0) | |
318 { printf ("\n\nLine %d: float_data [%d] == %f which is greater than 1.0\n", __LINE__, k, float_data [k]) ; | |
319 exit (1) ; | |
320 } ; | |
321 | |
322 | |
323 sf_close (file) ; | |
324 | |
325 unlink (filename) ; | |
326 | |
327 printf ("ok\n") ; | |
328 } /* float_norm_test */ | |
329 | |
330 static void | |
331 double_norm_test (const char *filename) | |
332 { SNDFILE *file ; | |
333 SF_INFO sfinfo ; | |
334 unsigned int k ; | |
335 | |
336 print_test_name ("double_norm_test", filename) ; | |
337 | |
338 sfinfo.samplerate = 44100 ; | |
339 sfinfo.format = (SF_FORMAT_RAW | SF_FORMAT_PCM_16) ; | |
340 sfinfo.channels = 1 ; | |
341 sfinfo.frames = BUFFER_LEN ; | |
342 | |
343 /* Create double_data with all values being less than 1.0. */ | |
344 for (k = 0 ; k < BUFFER_LEN / 2 ; k++) | |
345 double_data [k] = (k + 5) / (2.0 * BUFFER_LEN) ; | |
346 for (k = BUFFER_LEN / 2 ; k < BUFFER_LEN ; k++) | |
347 double_data [k] = (k + 5) ; | |
348 | |
349 if (! (file = sf_open (filename, SFM_WRITE, &sfinfo))) | |
350 { printf ("Line %d: sf_open_write failed with error : ", __LINE__) ; | |
351 fflush (stdout) ; | |
352 puts (sf_strerror (NULL)) ; | |
353 exit (1) ; | |
354 } ; | |
355 | |
356 /* Normailsation is on by default so no need to do anything here. */ | |
357 /*-sf_command (file, "set-norm-double", "true", 0) ;-*/ | |
358 | |
359 if ((k = sf_write_double (file, double_data, BUFFER_LEN / 2)) != BUFFER_LEN / 2) | |
360 { printf ("Line %d: sf_write_double failed with short write (%d ->%d)\n", __LINE__, BUFFER_LEN, k) ; | |
361 exit (1) ; | |
362 } ; | |
363 | |
364 /* Turn normalisation off. */ | |
365 sf_command (file, SFC_SET_NORM_DOUBLE, NULL, SF_FALSE) ; | |
366 | |
367 if ((k = sf_write_double (file, double_data + BUFFER_LEN / 2, BUFFER_LEN / 2)) != BUFFER_LEN / 2) | |
368 { printf ("Line %d: sf_write_double failed with short write (%d ->%d)\n", __LINE__, BUFFER_LEN, k) ; | |
369 exit (1) ; | |
370 } ; | |
371 | |
372 sf_close (file) ; | |
373 | |
374 if (! (file = sf_open (filename, SFM_READ, &sfinfo))) | |
375 { printf ("Line %d: sf_open_read failed with error : ", __LINE__) ; | |
376 fflush (stdout) ; | |
377 puts (sf_strerror (NULL)) ; | |
378 exit (1) ; | |
379 } ; | |
380 | |
381 if (sfinfo.format != (SF_FORMAT_RAW | SF_FORMAT_PCM_16)) | |
382 { printf ("Line %d: Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__, (SF_FORMAT_RAW | SF_FORMAT_PCM_16), sfinfo.format) ; | |
383 exit (1) ; | |
384 } ; | |
385 | |
386 if (sfinfo.frames != BUFFER_LEN) | |
387 { printf ("\n\nLine %d: Incorrect number of.frames in file. (%d => %" PRId64 ")\n", __LINE__, BUFFER_LEN, sfinfo.frames) ; | |
388 exit (1) ; | |
389 } ; | |
390 | |
391 if (sfinfo.channels != 1) | |
392 { printf ("Line %d: Incorrect number of channels in file.\n", __LINE__) ; | |
393 exit (1) ; | |
394 } ; | |
395 | |
396 /* Read double_data and check that it is normalised (ie default). */ | |
397 if ((k = sf_read_double (file, double_data, BUFFER_LEN)) != BUFFER_LEN) | |
398 { printf ("\n\nLine %d: sf_read_double failed with short read (%d ->%d)\n", __LINE__, BUFFER_LEN, k) ; | |
399 exit (1) ; | |
400 } ; | |
401 | |
402 for (k = 0 ; k < BUFFER_LEN ; k++) | |
403 if (double_data [k] >= 1.0) | |
404 { printf ("\n\nLine %d: double_data [%d] == %f which is greater than 1.0\n", __LINE__, k, double_data [k]) ; | |
405 exit (1) ; | |
406 } ; | |
407 | |
408 /* Seek to start of file, turn normalisation off, read double_data and check again. */ | |
409 sf_seek (file, 0, SEEK_SET) ; | |
410 sf_command (file, SFC_SET_NORM_DOUBLE, NULL, SF_FALSE) ; | |
411 | |
412 if ((k = sf_read_double (file, double_data, BUFFER_LEN)) != BUFFER_LEN) | |
413 { printf ("\n\nLine %d: sf_read_double failed with short read (%d ->%d)\n", __LINE__, BUFFER_LEN, k) ; | |
414 exit (1) ; | |
415 } ; | |
416 | |
417 for (k = 0 ; k < BUFFER_LEN ; k++) | |
418 if (double_data [k] < 1.0) | |
419 { printf ("\n\nLine %d: double_data [%d] == %f which is less than 1.0\n", __LINE__, k, double_data [k]) ; | |
420 exit (1) ; | |
421 } ; | |
422 | |
423 /* Seek to start of file, turn normalisation on, read double_data and do final check. */ | |
424 sf_seek (file, 0, SEEK_SET) ; | |
425 sf_command (file, SFC_SET_NORM_DOUBLE, NULL, SF_TRUE) ; | |
426 | |
427 if ((k = sf_read_double (file, double_data, BUFFER_LEN)) != BUFFER_LEN) | |
428 { printf ("\n\nLine %d: sf_read_double failed with short read (%d ->%d)\n", __LINE__, BUFFER_LEN, k) ; | |
429 exit (1) ; | |
430 } ; | |
431 | |
432 for (k = 0 ; k < BUFFER_LEN ; k++) | |
433 if (double_data [k] > 1.0) | |
434 { printf ("\n\nLine %d: double_data [%d] == %f which is greater than 1.0\n", __LINE__, k, double_data [k]) ; | |
435 exit (1) ; | |
436 } ; | |
437 | |
438 | |
439 sf_close (file) ; | |
440 | |
441 unlink (filename) ; | |
442 | |
443 printf ("ok\n") ; | |
444 } /* double_norm_test */ | |
445 | |
446 static void | |
447 format_tests (void) | |
448 { SF_FORMAT_INFO format_info ; | |
449 SF_INFO sfinfo ; | |
450 const char *last_name ; | |
451 int k, count ; | |
452 | |
453 print_test_name ("format_tests", "(null)") ; | |
454 | |
455 /* Clear out SF_INFO struct and set channels > 0. */ | |
456 memset (&sfinfo, 0, sizeof (sfinfo)) ; | |
457 sfinfo.channels = 1 ; | |
458 | |
459 /* First test simple formats. */ | |
460 | |
461 sf_command (NULL, SFC_GET_SIMPLE_FORMAT_COUNT, &count, sizeof (int)) ; | |
462 | |
463 if (count < 0 || count > 30) | |
464 { printf ("Line %d: Weird count.\n", __LINE__) ; | |
465 exit (1) ; | |
466 } ; | |
467 | |
468 format_info.format = 0 ; | |
469 sf_command (NULL, SFC_GET_SIMPLE_FORMAT, &format_info, sizeof (format_info)) ; | |
470 | |
471 last_name = format_info.name ; | |
472 for (k = 1 ; k < count ; k ++) | |
473 { format_info.format = k ; | |
474 sf_command (NULL, SFC_GET_SIMPLE_FORMAT, &format_info, sizeof (format_info)) ; | |
475 if (strcmp (last_name, format_info.name) >= 0) | |
476 { printf ("\n\nLine %d: format names out of sequence `%s' < `%s'.\n", __LINE__, last_name, format_info.name) ; | |
477 exit (1) ; | |
478 } ; | |
479 sfinfo.format = format_info.format ; | |
480 | |
481 if (! sf_format_check (&sfinfo)) | |
482 { printf ("\n\nLine %d: sf_format_check failed.\n", __LINE__) ; | |
483 printf (" Name : %s\n", format_info.name) ; | |
484 printf (" Format : 0x%X\n", sfinfo.format) ; | |
485 printf (" Channels : 0x%X\n", sfinfo.channels) ; | |
486 printf (" Sample Rate : 0x%X\n", sfinfo.samplerate) ; | |
487 exit (1) ; | |
488 } ; | |
489 last_name = format_info.name ; | |
490 } ; | |
491 format_info.format = 666 ; | |
492 sf_command (NULL, SFC_GET_SIMPLE_FORMAT, &format_info, sizeof (format_info)) ; | |
493 | |
494 /* Now test major formats. */ | |
495 sf_command (NULL, SFC_GET_FORMAT_MAJOR_COUNT, &count, sizeof (int)) ; | |
496 | |
497 if (count < 0 || count > 30) | |
498 { printf ("Line %d: Weird count.\n", __LINE__) ; | |
499 exit (1) ; | |
500 } ; | |
501 | |
502 format_info.format = 0 ; | |
503 sf_command (NULL, SFC_GET_FORMAT_MAJOR, &format_info, sizeof (format_info)) ; | |
504 | |
505 last_name = format_info.name ; | |
506 for (k = 1 ; k < count ; k ++) | |
507 { format_info.format = k ; | |
508 sf_command (NULL, SFC_GET_FORMAT_MAJOR, &format_info, sizeof (format_info)) ; | |
509 if (strcmp (last_name, format_info.name) >= 0) | |
510 { printf ("\n\nLine %d: format names out of sequence (%d) `%s' < `%s'.\n", __LINE__, k, last_name, format_info.name) ; | |
511 exit (1) ; | |
512 } ; | |
513 | |
514 last_name = format_info.name ; | |
515 } ; | |
516 format_info.format = 666 ; | |
517 sf_command (NULL, SFC_GET_FORMAT_MAJOR, &format_info, sizeof (format_info)) ; | |
518 | |
519 /* Now test subtype formats. */ | |
520 sf_command (NULL, SFC_GET_FORMAT_SUBTYPE_COUNT, &count, sizeof (int)) ; | |
521 | |
522 if (count < 0 || count > 30) | |
523 { printf ("Line %d: Weird count.\n", __LINE__) ; | |
524 exit (1) ; | |
525 } ; | |
526 | |
527 format_info.format = 0 ; | |
528 sf_command (NULL, SFC_GET_FORMAT_SUBTYPE, &format_info, sizeof (format_info)) ; | |
529 | |
530 last_name = format_info.name ; | |
531 for (k = 1 ; k < count ; k ++) | |
532 { format_info.format = k ; | |
533 sf_command (NULL, SFC_GET_FORMAT_SUBTYPE, &format_info, sizeof (format_info)) ; | |
534 } ; | |
535 format_info.format = 666 ; | |
536 sf_command (NULL, SFC_GET_FORMAT_SUBTYPE, &format_info, sizeof (format_info)) ; | |
537 | |
538 | |
539 printf ("ok\n") ; | |
540 } /* format_tests */ | |
541 | |
542 static void | |
543 calc_peak_test (int filetype, const char *filename, int channels) | |
544 { SNDFILE *file ; | |
545 SF_INFO sfinfo ; | |
546 char label [128] ; | |
547 int k, format ; | |
548 sf_count_t buffer_len, frame_count ; | |
549 double peak ; | |
550 | |
551 snprintf (label, sizeof (label), "calc_peak_test (%d channels)", channels) ; | |
552 print_test_name (label, filename) ; | |
553 | |
554 format = filetype | SF_FORMAT_PCM_16 ; | |
555 | |
556 buffer_len = BUFFER_LEN - (BUFFER_LEN % channels) ; | |
557 frame_count = buffer_len / channels ; | |
558 | |
559 sfinfo.samplerate = 44100 ; | |
560 sfinfo.format = format ; | |
561 sfinfo.channels = channels ; | |
562 sfinfo.frames = frame_count ; | |
563 | |
564 /* Create double_data with max value of 0.5. */ | |
565 for (k = 0 ; k < buffer_len ; k++) | |
566 double_data [k] = (k + 1) / (2.0 * buffer_len) ; | |
567 | |
568 file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ; | |
569 | |
570 test_writef_double_or_die (file, 0, double_data, frame_count, __LINE__) ; | |
571 | |
572 sf_close (file) ; | |
573 | |
574 file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ; | |
575 | |
576 if (sfinfo.format != format) | |
577 { printf ("Line %d: Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__, format, sfinfo.format) ; | |
578 exit (1) ; | |
579 } ; | |
580 | |
581 if (sfinfo.frames != frame_count) | |
582 { printf ("\n\nLine %d: Incorrect number of frames in file. (%" PRId64 " => %" PRId64 ")\n", __LINE__, frame_count, sfinfo.frames) ; | |
583 exit (1) ; | |
584 } ; | |
585 | |
586 if (sfinfo.channels != channels) | |
587 { printf ("Line %d: Incorrect number of channels in file.\n", __LINE__) ; | |
588 exit (1) ; | |
589 } ; | |
590 | |
591 sf_command (file, SFC_CALC_SIGNAL_MAX, &peak, sizeof (peak)) ; | |
592 if (fabs (peak - (1 << 14)) > 1.0) | |
593 { printf ("Line %d : Peak value should be %d (is %f).\n", __LINE__, (1 << 14), peak) ; | |
594 exit (1) ; | |
595 } ; | |
596 | |
597 sf_command (file, SFC_CALC_NORM_SIGNAL_MAX, &peak, sizeof (peak)) ; | |
598 if (fabs (peak - 0.5) > 4e-5) | |
599 { printf ("Line %d : Peak value should be %f (is %f).\n", __LINE__, 0.5, peak) ; | |
600 exit (1) ; | |
601 } ; | |
602 | |
603 sf_close (file) ; | |
604 | |
605 format = (filetype | SF_FORMAT_FLOAT) ; | |
606 sfinfo.samplerate = 44100 ; | |
607 sfinfo.format = format ; | |
608 sfinfo.channels = channels ; | |
609 sfinfo.frames = frame_count ; | |
610 | |
611 /* Create double_data with max value of 0.5. */ | |
612 for (k = 0 ; k < buffer_len ; k++) | |
613 double_data [k] = (k + 1) / (2.0 * buffer_len) ; | |
614 | |
615 file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ; | |
616 | |
617 test_writef_double_or_die (file, 0, double_data, frame_count, __LINE__) ; | |
618 | |
619 sf_close (file) ; | |
620 | |
621 file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ; | |
622 | |
623 if (sfinfo.format != format) | |
624 { printf ("Line %d: Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__, format, sfinfo.format) ; | |
625 exit (1) ; | |
626 } ; | |
627 | |
628 if (sfinfo.frames != frame_count) | |
629 { printf ("\n\nLine %d: Incorrect number of.frames in file. (%" PRId64 " => %" PRId64 ")\n", __LINE__, frame_count, sfinfo.frames) ; | |
630 exit (1) ; | |
631 } ; | |
632 | |
633 if (sfinfo.channels != channels) | |
634 { printf ("Line %d: Incorrect number of channels in file.\n", __LINE__) ; | |
635 exit (1) ; | |
636 } ; | |
637 | |
638 sf_command (file, SFC_CALC_SIGNAL_MAX, &peak, sizeof (peak)) ; | |
639 if (fabs (peak - 0.5) > 1e-5) | |
640 { printf ("Line %d : Peak value should be %f (is %f).\n", __LINE__, 0.5, peak) ; | |
641 exit (1) ; | |
642 } ; | |
643 | |
644 sf_command (file, SFC_CALC_NORM_SIGNAL_MAX, &peak, sizeof (peak)) ; | |
645 if (fabs (peak - 0.5) > 1e-5) | |
646 { printf ("Line %d : Peak value should be %f (is %f).\n", __LINE__, 0.5, peak) ; | |
647 exit (1) ; | |
648 } ; | |
649 | |
650 sf_close (file) ; | |
651 | |
652 unlink (filename) ; | |
653 | |
654 printf ("ok\n") ; | |
655 } /* calc_peak_test */ | |
656 | |
657 static void | |
658 truncate_test (const char *filename, int filetype) | |
659 { SNDFILE *file ; | |
660 SF_INFO sfinfo ; | |
661 sf_count_t len ; | |
662 | |
663 print_test_name ("truncate_test", filename) ; | |
664 | |
665 sfinfo.samplerate = 11025 ; | |
666 sfinfo.format = filetype ; | |
667 sfinfo.channels = 2 ; | |
668 | |
669 file = test_open_file_or_die (filename, SFM_RDWR, &sfinfo, SF_TRUE, __LINE__) ; | |
670 | |
671 test_write_int_or_die (file, 0, int_data, BUFFER_LEN, __LINE__) ; | |
672 | |
673 len = 100 ; | |
674 if (sf_command (file, SFC_FILE_TRUNCATE, &len, sizeof (len))) | |
675 { printf ("Line %d: sf_command (SFC_FILE_TRUNCATE) returned error.\n", __LINE__) ; | |
676 exit (1) ; | |
677 } ; | |
678 | |
679 test_seek_or_die (file, 0, SEEK_CUR, len, 2, __LINE__) ; | |
680 test_seek_or_die (file, 0, SEEK_END, len, 2, __LINE__) ; | |
681 | |
682 sf_close (file) ; | |
683 | |
684 unlink (filename) ; | |
685 puts ("ok") ; | |
686 } /* truncate_test */ | |
687 | |
688 /*------------------------------------------------------------------------------ | |
689 */ | |
690 | |
691 static void | |
692 instrumet_rw_test (const char *filename) | |
693 { SNDFILE *sndfile ; | |
694 SF_INFO sfinfo ; | |
695 SF_INSTRUMENT inst ; | |
696 memset (&sfinfo, 0, sizeof (SF_INFO)) ; | |
697 | |
698 sndfile = test_open_file_or_die (filename, SFM_RDWR, &sfinfo, SF_FALSE, __LINE__) ; | |
699 | |
700 if (sf_command (sndfile, SFC_GET_INSTRUMENT, &inst, sizeof (inst)) == SF_TRUE) | |
701 { inst.basenote = 22 ; | |
702 | |
703 if (sf_command (sndfile, SFC_SET_INSTRUMENT, &inst, sizeof (inst)) == SF_TRUE) | |
704 printf ("Sucess: [%s] updated\n", filename) ; | |
705 else | |
706 printf ("Error: SFC_SET_INSTRUMENT on [%s] [%s]\n", filename, sf_strerror (sndfile)) ; | |
707 } | |
708 else | |
709 printf ("Error: SFC_GET_INSTRUMENT on [%s] [%s]\n", filename, sf_strerror (sndfile)) ; | |
710 | |
711 | |
712 if (sf_command (sndfile, SFC_UPDATE_HEADER_NOW, NULL, 0) != 0) | |
713 printf ("Error: SFC_UPDATE_HEADER_NOW on [%s] [%s]\n", filename, sf_strerror (sndfile)) ; | |
714 | |
715 sf_write_sync (sndfile) ; | |
716 sf_close (sndfile) ; | |
717 | |
718 return ; | |
719 } /* instrumet_rw_test */ | |
720 | |
721 static void | |
722 instrument_test (const char *filename, int filetype) | |
723 { static SF_INSTRUMENT write_inst = | |
724 { 2, /* gain */ | |
725 3, /* detune */ | |
726 4, /* basenote */ | |
727 5, 6, /* key low and high */ | |
728 7, 8, /* velocity low and high */ | |
729 2, /* loop_count */ | |
730 { { 801, 2, 3, 0 }, | |
731 { 801, 3, 4, 0 }, | |
732 } | |
733 } ; | |
734 SF_INSTRUMENT read_inst ; | |
735 SNDFILE *file ; | |
736 SF_INFO sfinfo ; | |
737 | |
738 print_test_name ("instrument_test", filename) ; | |
739 | |
740 sfinfo.samplerate = 11025 ; | |
741 sfinfo.format = filetype ; | |
742 sfinfo.channels = 1 ; | |
743 | |
744 file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ; | |
745 if (sf_command (file, SFC_SET_INSTRUMENT, &write_inst, sizeof (write_inst)) == SF_FALSE) | |
746 { printf ("\n\nLine %d : sf_command (SFC_SET_INSTRUMENT) failed.\n\n", __LINE__) ; | |
747 exit (1) ; | |
748 } ; | |
749 test_write_double_or_die (file, 0, double_data, BUFFER_LEN, __LINE__) ; | |
750 sf_close (file) ; | |
751 | |
752 memset (&read_inst, 0, sizeof (read_inst)) ; | |
753 | |
754 file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ; | |
755 if (sf_command (file, SFC_GET_INSTRUMENT, &read_inst, sizeof (read_inst)) == SF_FALSE) | |
756 { printf ("\n\nLine %d : sf_command (SFC_GET_INSTRUMENT) failed.\n\n", __LINE__) ; | |
757 exit (1) ; | |
758 return ; | |
759 } ; | |
760 check_log_buffer_or_die (file, __LINE__) ; | |
761 sf_close (file) ; | |
762 | |
763 if ((filetype & SF_FORMAT_TYPEMASK) == SF_FORMAT_WAV) | |
764 { /* | |
765 ** For all the fields that WAV doesn't support, modify the | |
766 ** write_inst struct to hold the default value that the WAV | |
767 ** module should hold. | |
768 */ | |
769 write_inst.detune = 0 ; | |
770 write_inst.key_lo = write_inst.velocity_lo = 0 ; | |
771 write_inst.key_hi = write_inst.velocity_hi = 127 ; | |
772 write_inst.gain = 1 ; | |
773 } ; | |
774 | |
775 if ((filetype & SF_FORMAT_TYPEMASK) == SF_FORMAT_XI) | |
776 { /* | |
777 ** For all the fields that XI doesn't support, modify the | |
778 ** write_inst struct to hold the default value that the XI | |
779 ** module should hold. | |
780 */ | |
781 write_inst.basenote = 0 ; | |
782 write_inst.detune = 0 ; | |
783 write_inst.key_lo = write_inst.velocity_lo = 0 ; | |
784 write_inst.key_hi = write_inst.velocity_hi = 127 ; | |
785 write_inst.gain = 1 ; | |
786 } ; | |
787 | |
788 if (memcmp (&write_inst, &read_inst, sizeof (write_inst)) != 0) | |
789 { printf ("\n\nLine %d : instrument comparison failed.\n\n", __LINE__) ; | |
790 printf ("W Base Note : %u\n" | |
791 " Detune : %u\n" | |
792 " Low Note : %u\tHigh Note : %u\n" | |
793 " Low Vel. : %u\tHigh Vel. : %u\n" | |
794 " Gain : %d\tCount : %d\n" | |
795 " mode : %d\n" | |
796 " start : %d\tend : %d\tcount :%d\n" | |
797 " mode : %d\n" | |
798 " start : %d\tend : %d\tcount :%d\n\n", | |
799 write_inst.basenote, | |
800 write_inst.detune, | |
801 write_inst.key_lo, write_inst.key_hi, | |
802 write_inst.velocity_lo, write_inst.velocity_hi, | |
803 write_inst.gain, write_inst.loop_count, | |
804 write_inst.loops [0].mode, write_inst.loops [0].start, | |
805 write_inst.loops [0].end, write_inst.loops [0].count, | |
806 write_inst.loops [1].mode, write_inst.loops [1].start, | |
807 write_inst.loops [1].end, write_inst.loops [1].count) ; | |
808 printf ("R Base Note : %u\n" | |
809 " Detune : %u\n" | |
810 " Low Note : %u\tHigh Note : %u\n" | |
811 " Low Vel. : %u\tHigh Vel. : %u\n" | |
812 " Gain : %d\tCount : %d\n" | |
813 " mode : %d\n" | |
814 " start : %d\tend : %d\tcount :%d\n" | |
815 " mode : %d\n" | |
816 " start : %d\tend : %d\tcount :%d\n\n", | |
817 read_inst.basenote, | |
818 read_inst.detune, | |
819 read_inst.key_lo, read_inst.key_hi, | |
820 read_inst.velocity_lo, read_inst.velocity_hi, | |
821 read_inst.gain, read_inst.loop_count, | |
822 read_inst.loops [0].mode, read_inst.loops [0].start, | |
823 read_inst.loops [0].end, read_inst.loops [0].count, | |
824 read_inst.loops [1].mode, read_inst.loops [1].start, | |
825 read_inst.loops [1].end, read_inst.loops [1].count) ; | |
826 | |
827 if ((filetype & SF_FORMAT_TYPEMASK) != SF_FORMAT_XI) | |
828 exit (1) ; | |
829 } ; | |
830 | |
831 if (0) instrumet_rw_test (filename) ; | |
832 | |
833 unlink (filename) ; | |
834 puts ("ok") ; | |
835 } /* instrument_test */ | |
836 | |
837 static void | |
838 cue_rw_test (const char *filename) | |
839 { SNDFILE *sndfile ; | |
840 SF_INFO sfinfo ; | |
841 SF_CUES cues ; | |
842 memset (&sfinfo, 0, sizeof (SF_INFO)) ; | |
843 | |
844 sndfile = test_open_file_or_die (filename, SFM_RDWR, &sfinfo, SF_FALSE, __LINE__) ; | |
845 | |
846 exit_if_true ( | |
847 sf_command (sndfile, SFC_GET_CUE_COUNT, &cues.cue_count, sizeof (cues.cue_count)) != SF_TRUE, | |
848 "\nLine %d: SFC_GET_CUE_COUNT command failed.\n\n", __LINE__ | |
849 ) ; | |
850 | |
851 exit_if_true ( | |
852 cues.cue_count != 3, | |
853 "\nLine %d: Expected cue_count (%u) to be 3.\n\n", __LINE__, cues.cue_count | |
854 ) ; | |
855 | |
856 if (sf_command (sndfile, SFC_GET_CUE, &cues, sizeof (cues)) == SF_TRUE) | |
857 { cues.cue_points [1].sample_offset = 3 ; | |
858 | |
859 if (sf_command (sndfile, SFC_SET_CUE, &cues, sizeof (cues)) == SF_TRUE) | |
860 printf ("Sucess: [%s] updated\n", filename) ; | |
861 else | |
862 printf ("Error: SFC_SET_CUE on [%s] [%s]\n", filename, sf_strerror (sndfile)) ; | |
863 } | |
864 else | |
865 printf ("Error: SFC_GET_CUE on [%s] [%s]\n", filename, sf_strerror (sndfile)) ; | |
866 | |
867 | |
868 if (sf_command (sndfile, SFC_UPDATE_HEADER_NOW, NULL, 0) != 0) | |
869 printf ("Error: SFC_UPDATE_HEADER_NOW on [%s] [%s]\n", filename, sf_strerror (sndfile)) ; | |
870 | |
871 sf_write_sync (sndfile) ; | |
872 sf_close (sndfile) ; | |
873 | |
874 return ; | |
875 } /* cue_rw_test */ | |
876 | |
877 static void | |
878 cue_test (const char *filename, int filetype) | |
879 { SF_CUES write_cue ; | |
880 SF_CUES read_cue ; | |
881 SNDFILE *file ; | |
882 SF_INFO sfinfo ; | |
883 | |
884 if (filetype == (SF_FORMAT_WAV | SF_FORMAT_PCM_16)) | |
885 { write_cue = (SF_CUES) | |
886 { 2, /* cue_count */ | |
887 { { 1, 0, data_MARKER, 0, 0, 1, "" }, | |
888 { 2, 0, data_MARKER, 0, 0, 2, "" }, | |
889 } | |
890 } ; | |
891 } | |
892 else | |
893 { write_cue = (SF_CUES) | |
894 { 2, /* cue_count */ | |
895 { { 1, 0, data_MARKER, 0, 0, 1, "Cue1" }, | |
896 { 2, 0, data_MARKER, 0, 0, 2, "Cue2" }, | |
897 } | |
898 } ; | |
899 } | |
900 | |
901 print_test_name ("cue_test", filename) ; | |
902 | |
903 sfinfo.samplerate = 11025 ; | |
904 sfinfo.format = filetype ; | |
905 sfinfo.channels = 1 ; | |
906 | |
907 file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ; | |
908 if (sf_command (file, SFC_SET_CUE, &write_cue, sizeof (write_cue)) == SF_FALSE) | |
909 { printf ("\n\nLine %d : sf_command (SFC_SET_CUE) failed.\n\n", __LINE__) ; | |
910 exit (1) ; | |
911 } ; | |
912 test_write_double_or_die (file, 0, double_data, BUFFER_LEN, __LINE__) ; | |
913 sf_close (file) ; | |
914 | |
915 memset (&read_cue, 0, sizeof (read_cue)) ; | |
916 | |
917 file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ; | |
918 if (sf_command (file, SFC_GET_CUE, &read_cue, sizeof (read_cue)) == SF_FALSE) | |
919 { printf ("\n\nLine %d : sf_command (SFC_GET_CUE) failed.\n\n", __LINE__) ; | |
920 exit (1) ; | |
921 return ; | |
922 } ; | |
923 check_log_buffer_or_die (file, __LINE__) ; | |
924 sf_close (file) ; | |
925 | |
926 if (memcmp (&write_cue, &read_cue, sizeof (write_cue)) != 0) | |
927 { printf ("\n\nLine %d : cue comparison failed.\n\n", __LINE__) ; | |
928 printf ("W Cue count : %d\n" | |
929 " indx : %d\n" | |
930 " position : %u\n" | |
931 " fcc_chunk : %x\n" | |
932 " chunk_start : %d\n" | |
933 " block_start : %d\n" | |
934 " sample_offset : %u\n" | |
935 " name : %s\n" | |
936 " indx : %d\n" | |
937 " position : %u\n" | |
938 " fcc_chunk : %x\n" | |
939 " chunk_start : %d\n" | |
940 " block_start : %d\n" | |
941 " sample_offset : %u\n" | |
942 " name : %s\n", | |
943 write_cue.cue_count, | |
944 write_cue.cue_points [0].indx, | |
945 write_cue.cue_points [0].position, | |
946 write_cue.cue_points [0].fcc_chunk, | |
947 write_cue.cue_points [0].chunk_start, | |
948 write_cue.cue_points [0].block_start, | |
949 write_cue.cue_points [0].sample_offset, | |
950 write_cue.cue_points [0].name, | |
951 write_cue.cue_points [1].indx, | |
952 write_cue.cue_points [1].position, | |
953 write_cue.cue_points [1].fcc_chunk, | |
954 write_cue.cue_points [1].chunk_start, | |
955 write_cue.cue_points [1].block_start, | |
956 write_cue.cue_points [1].sample_offset, | |
957 write_cue.cue_points [1].name) ; | |
958 printf ("R Cue count : %d\n" | |
959 " indx : %d\n" | |
960 " position : %u\n" | |
961 " fcc_chunk : %x\n" | |
962 " chunk_start : %d\n" | |
963 " block_start : %d\n" | |
964 " sample_offset : %u\n" | |
965 " name : %s\n" | |
966 " indx : %d\n" | |
967 " position : %u\n" | |
968 " fcc_chunk : %x\n" | |
969 " chunk_start : %d\n" | |
970 " block_start : %d\n" | |
971 " sample_offset : %u\n" | |
972 " name : %s\n", | |
973 read_cue.cue_count, | |
974 read_cue.cue_points [0].indx, | |
975 read_cue.cue_points [0].position, | |
976 read_cue.cue_points [0].fcc_chunk, | |
977 read_cue.cue_points [0].chunk_start, | |
978 read_cue.cue_points [0].block_start, | |
979 read_cue.cue_points [0].sample_offset, | |
980 read_cue.cue_points [0].name, | |
981 read_cue.cue_points [1].indx, | |
982 read_cue.cue_points [1].position, | |
983 read_cue.cue_points [1].fcc_chunk, | |
984 read_cue.cue_points [1].chunk_start, | |
985 read_cue.cue_points [1].block_start, | |
986 read_cue.cue_points [1].sample_offset, | |
987 read_cue.cue_points [1].name) ; | |
988 | |
989 exit (1) ; | |
990 } ; | |
991 | |
992 if (0) cue_rw_test (filename) ; | |
993 | |
994 unlink (filename) ; | |
995 puts ("ok") ; | |
996 } /* cue_test */ | |
997 | |
998 static void | |
999 current_sf_info_test (const char *filename) | |
1000 { SNDFILE *outfile, *infile ; | |
1001 SF_INFO outinfo, ininfo ; | |
1002 | |
1003 print_test_name ("current_sf_info_test", filename) ; | |
1004 | |
1005 outinfo.samplerate = 44100 ; | |
1006 outinfo.format = (SF_FORMAT_WAV | SF_FORMAT_PCM_16) ; | |
1007 outinfo.channels = 1 ; | |
1008 outinfo.frames = 0 ; | |
1009 | |
1010 outfile = test_open_file_or_die (filename, SFM_WRITE, &outinfo, SF_TRUE, __LINE__) ; | |
1011 sf_command (outfile, SFC_SET_UPDATE_HEADER_AUTO, NULL, 0) ; | |
1012 | |
1013 exit_if_true (outinfo.frames != 0, | |
1014 "\n\nLine %d : Initial sfinfo.frames is not zero.\n\n", __LINE__ | |
1015 ) ; | |
1016 | |
1017 test_write_double_or_die (outfile, 0, double_data, BUFFER_LEN, __LINE__) ; | |
1018 sf_command (outfile, SFC_GET_CURRENT_SF_INFO, &outinfo, sizeof (outinfo)) ; | |
1019 | |
1020 exit_if_true (outinfo.frames != BUFFER_LEN, | |
1021 "\n\nLine %d : Initial sfinfo.frames (%" PRId64 ") should be %d.\n\n", __LINE__, | |
1022 outinfo.frames, BUFFER_LEN | |
1023 ) ; | |
1024 | |
1025 /* Read file making sure no channel map exists. */ | |
1026 memset (&ininfo, 0, sizeof (ininfo)) ; | |
1027 infile = test_open_file_or_die (filename, SFM_READ, &ininfo, SF_TRUE, __LINE__) ; | |
1028 | |
1029 test_write_double_or_die (outfile, 0, double_data, BUFFER_LEN, __LINE__) ; | |
1030 | |
1031 sf_command (infile, SFC_GET_CURRENT_SF_INFO, &ininfo, sizeof (ininfo)) ; | |
1032 | |
1033 exit_if_true (ininfo.frames != BUFFER_LEN, | |
1034 "\n\nLine %d : Initial sfinfo.frames (%" PRId64 ") should be %d.\n\n", __LINE__, | |
1035 ininfo.frames, BUFFER_LEN | |
1036 ) ; | |
1037 | |
1038 sf_close (outfile) ; | |
1039 sf_close (infile) ; | |
1040 | |
1041 unlink (filename) ; | |
1042 puts ("ok") ; | |
1043 } /* current_sf_info_test */ | |
1044 | |
1045 static void | |
1046 broadcast_test (const char *filename, int filetype) | |
1047 { static SF_BROADCAST_INFO bc_write, bc_read ; | |
1048 SNDFILE *file ; | |
1049 SF_INFO sfinfo ; | |
1050 int errors = 0 ; | |
1051 | |
1052 print_test_name ("broadcast_test", filename) ; | |
1053 | |
1054 sfinfo.samplerate = 11025 ; | |
1055 sfinfo.format = filetype ; | |
1056 sfinfo.channels = 1 ; | |
1057 | |
1058 memset (&bc_write, 0, sizeof (bc_write)) ; | |
1059 | |
1060 snprintf (bc_write.description, sizeof (bc_write.description), "Test description") ; | |
1061 snprintf (bc_write.originator, sizeof (bc_write.originator), "Test originator") ; | |
1062 snprintf (bc_write.originator_reference, sizeof (bc_write.originator_reference), "%08x-%08x", (unsigned int) time (NULL), (unsigned int) (~ time (NULL))) ; | |
1063 snprintf (bc_write.origination_date, sizeof (bc_write.origination_date), "%d/%02d/%02d", 2006, 3, 30) ; | |
1064 snprintf (bc_write.origination_time, sizeof (bc_write.origination_time), "%02d:%02d:%02d", 20, 27, 0) ; | |
1065 snprintf (bc_write.umid, sizeof (bc_write.umid), "Some umid") ; | |
1066 bc_write.coding_history_size = 0 ; | |
1067 | |
1068 file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ; | |
1069 if (sf_command (file, SFC_SET_BROADCAST_INFO, &bc_write, sizeof (bc_write)) == SF_FALSE) | |
1070 { printf ("\n\nLine %d : sf_command (SFC_SET_BROADCAST_INFO) failed.\n\n", __LINE__) ; | |
1071 exit (1) ; | |
1072 } ; | |
1073 test_write_double_or_die (file, 0, double_data, BUFFER_LEN, __LINE__) ; | |
1074 sf_close (file) ; | |
1075 | |
1076 memset (&bc_read, 0, sizeof (bc_read)) ; | |
1077 | |
1078 file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ; | |
1079 if (sf_command (file, SFC_GET_BROADCAST_INFO, &bc_read, sizeof (bc_read)) == SF_FALSE) | |
1080 { printf ("\n\nLine %d : sf_command (SFC_GET_BROADCAST_INFO) failed.\n\n", __LINE__) ; | |
1081 exit (1) ; | |
1082 return ; | |
1083 } ; | |
1084 check_log_buffer_or_die (file, __LINE__) ; | |
1085 sf_close (file) ; | |
1086 | |
1087 if (bc_read.version != 1) | |
1088 { printf ("\n\nLine %d : Read bad version number %d.\n\n", __LINE__, bc_read.version) ; | |
1089 exit (1) ; | |
1090 return ; | |
1091 } ; | |
1092 | |
1093 bc_read.version = bc_write.version = 0 ; | |
1094 | |
1095 if (memcmp (bc_write.description, bc_read.description, sizeof (bc_write.description)) != 0) | |
1096 { printf ("\n\nLine %d : description mismatch :\n\twrite : '%s'\n\tread : '%s'\n\n", __LINE__, bc_write.description, bc_read.description) ; | |
1097 errors ++ ; | |
1098 } ; | |
1099 | |
1100 if (memcmp (bc_write.originator, bc_read.originator, sizeof (bc_write.originator)) != 0) | |
1101 { printf ("\n\nLine %d : originator mismatch :\n\twrite : '%s'\n\tread : '%s'\n\n", __LINE__, bc_write.originator, bc_read.originator) ; | |
1102 errors ++ ; | |
1103 } ; | |
1104 | |
1105 if (memcmp (bc_write.originator_reference, bc_read.originator_reference, sizeof (bc_write.originator_reference)) != 0) | |
1106 { printf ("\n\nLine %d : originator_reference mismatch :\n\twrite : '%s'\n\tread : '%s'\n\n", __LINE__, bc_write.originator_reference, bc_read.originator_reference) ; | |
1107 errors ++ ; | |
1108 } ; | |
1109 | |
1110 if (memcmp (bc_write.origination_date, bc_read.origination_date, sizeof (bc_write.origination_date)) != 0) | |
1111 { printf ("\n\nLine %d : origination_date mismatch :\n\twrite : '%s'\n\tread : '%s'\n\n", __LINE__, bc_write.origination_date, bc_read.origination_date) ; | |
1112 errors ++ ; | |
1113 } ; | |
1114 | |
1115 if (memcmp (bc_write.origination_time, bc_read.origination_time, sizeof (bc_write.origination_time)) != 0) | |
1116 { printf ("\n\nLine %d : origination_time mismatch :\n\twrite : '%s'\n\tread : '%s'\n\n", __LINE__, bc_write.origination_time, bc_read.origination_time) ; | |
1117 errors ++ ; | |
1118 } ; | |
1119 | |
1120 if (memcmp (bc_write.umid, bc_read.umid, sizeof (bc_write.umid)) != 0) | |
1121 { printf ("\n\nLine %d : umid mismatch :\n\twrite : '%s'\n\tread : '%s'\n\n", __LINE__, bc_write.umid, bc_read.umid) ; | |
1122 errors ++ ; | |
1123 } ; | |
1124 | |
1125 if (errors) | |
1126 exit (1) ; | |
1127 | |
1128 unlink (filename) ; | |
1129 puts ("ok") ; | |
1130 } /* broadcast_test */ | |
1131 | |
1132 static void | |
1133 broadcast_rdwr_test (const char *filename, int filetype) | |
1134 { SF_BROADCAST_INFO binfo ; | |
1135 SNDFILE *file ; | |
1136 SF_INFO sfinfo ; | |
1137 sf_count_t frames ; | |
1138 | |
1139 print_test_name (__func__, filename) ; | |
1140 | |
1141 create_short_sndfile (filename, filetype, 2) ; | |
1142 | |
1143 memset (&sfinfo, 0, sizeof (sfinfo)) ; | |
1144 memset (&binfo, 0, sizeof (binfo)) ; | |
1145 | |
1146 snprintf (binfo.description, sizeof (binfo.description), "Test description") ; | |
1147 snprintf (binfo.originator, sizeof (binfo.originator), "Test originator") ; | |
1148 snprintf (binfo.originator_reference, sizeof (binfo.originator_reference), "%08x-%08x", (unsigned int) time (NULL), (unsigned int) (~ time (NULL))) ; | |
1149 snprintf (binfo.origination_date, sizeof (binfo.origination_date), "%d/%02d/%02d", 2006, 3, 30) ; | |
1150 snprintf (binfo.origination_time, sizeof (binfo.origination_time), "%02d:%02d:%02d", 20, 27, 0) ; | |
1151 snprintf (binfo.umid, sizeof (binfo.umid), "Some umid") ; | |
1152 binfo.coding_history_size = 0 ; | |
1153 | |
1154 file = test_open_file_or_die (filename, SFM_RDWR, &sfinfo, SF_TRUE, __LINE__) ; | |
1155 frames = sfinfo.frames ; | |
1156 if (sf_command (file, SFC_SET_BROADCAST_INFO, &binfo, sizeof (binfo)) != SF_FALSE) | |
1157 { printf ("\n\nLine %d : sf_command (SFC_SET_BROADCAST_INFO) should have failed but didn't.\n\n", __LINE__) ; | |
1158 exit (1) ; | |
1159 } ; | |
1160 sf_close (file) ; | |
1161 | |
1162 file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ; | |
1163 sf_close (file) ; | |
1164 exit_if_true (frames != sfinfo.frames, "\n\nLine %d : Frame count %" PRId64 " should be %" PRId64 ".\n", __LINE__, sfinfo.frames, frames) ; | |
1165 | |
1166 unlink (filename) ; | |
1167 puts ("ok") ; | |
1168 } /* broadcast_rdwr_test */ | |
1169 | |
1170 static void | |
1171 check_coding_history_newlines (const char *filename) | |
1172 { static SF_BROADCAST_INFO bc_write, bc_read ; | |
1173 SNDFILE *file ; | |
1174 SF_INFO sfinfo ; | |
1175 unsigned k ; | |
1176 | |
1177 sfinfo.samplerate = 22050 ; | |
1178 sfinfo.format = SF_FORMAT_WAV | SF_FORMAT_PCM_16 ; | |
1179 sfinfo.channels = 1 ; | |
1180 | |
1181 memset (&bc_write, 0, sizeof (bc_write)) ; | |
1182 | |
1183 snprintf (bc_write.description, sizeof (bc_write.description), "Test description") ; | |
1184 snprintf (bc_write.originator, sizeof (bc_write.originator), "Test originator") ; | |
1185 snprintf (bc_write.originator_reference, sizeof (bc_write.originator_reference), "%08x-%08x", (unsigned int) time (NULL), (unsigned int) (~ time (NULL))) ; | |
1186 snprintf (bc_write.origination_date, sizeof (bc_write.origination_date), "%d/%02d/%02d", 2006, 3, 30) ; | |
1187 snprintf (bc_write.origination_time, sizeof (bc_write.origination_time), "%02d:%02d:%02d", 20, 27, 0) ; | |
1188 snprintf (bc_write.umid, sizeof (bc_write.umid), "Some umid") ; | |
1189 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") ; ; | |
1190 | |
1191 file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ; | |
1192 if (sf_command (file, SFC_SET_BROADCAST_INFO, &bc_write, sizeof (bc_write)) == SF_FALSE) | |
1193 { printf ("\n\nLine %d : sf_command (SFC_SET_BROADCAST_INFO) failed.\n\n", __LINE__) ; | |
1194 exit (1) ; | |
1195 } ; | |
1196 | |
1197 test_write_double_or_die (file, 0, double_data, BUFFER_LEN, __LINE__) ; | |
1198 sf_close (file) ; | |
1199 | |
1200 memset (&bc_read, 0, sizeof (bc_read)) ; | |
1201 | |
1202 file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ; | |
1203 if (sf_command (file, SFC_GET_BROADCAST_INFO, &bc_read, sizeof (bc_read)) == SF_FALSE) | |
1204 { printf ("\n\nLine %d : sf_command (SFC_SET_BROADCAST_INFO) failed.\n\n", __LINE__) ; | |
1205 exit (1) ; | |
1206 } ; | |
1207 check_log_buffer_or_die (file, __LINE__) ; | |
1208 sf_close (file) ; | |
1209 | |
1210 if (bc_read.coding_history_size == 0) | |
1211 { printf ("\n\nLine %d : missing coding history.\n\n", __LINE__) ; | |
1212 exit (1) ; | |
1213 } ; | |
1214 | |
1215 if (strstr (bc_read.coding_history, "Last line") == NULL) | |
1216 { printf ("\n\nLine %d : coding history truncated.\n\n", __LINE__) ; | |
1217 exit (1) ; | |
1218 } ; | |
1219 | |
1220 for (k = 1 ; k < bc_read.coding_history_size ; k++) | |
1221 { if (bc_read.coding_history [k] == '\n' && bc_read.coding_history [k - 1] != '\r') | |
1222 { printf ("\n\nLine %d : '\\n' without '\\r' before.\n\n", __LINE__) ; | |
1223 exit (1) ; | |
1224 } ; | |
1225 | |
1226 if (bc_read.coding_history [k] == '\r' && bc_read.coding_history [k + 1] != '\n') | |
1227 { printf ("\n\nLine %d : '\\r' without '\\n' after.\n\n", __LINE__) ; | |
1228 exit (1) ; | |
1229 } ; | |
1230 | |
1231 if (bc_read.coding_history [k] == 0 && k < bc_read.coding_history_size - 1) | |
1232 { printf ("\n\nLine %d : '\\0' within coding history at index %d of %d.\n\n", __LINE__, k, bc_read.coding_history_size) ; | |
1233 exit (1) ; | |
1234 } ; | |
1235 } ; | |
1236 | |
1237 return ; | |
1238 } /* check_coding_history_newlines */ | |
1239 | |
1240 static void | |
1241 broadcast_coding_history_test (const char *filename) | |
1242 { static SF_BROADCAST_INFO bc_write, bc_read ; | |
1243 SNDFILE *file ; | |
1244 SF_INFO sfinfo ; | |
1245 const char *default_history = "A=PCM,F=22050,W=16,M=mono" ; | |
1246 const char *supplied_history = | |
1247 "A=PCM,F=44100,W=24,M=mono,T=other\r\n" | |
1248 "A=PCM,F=22050,W=16,M=mono,T=yet_another\r\n" ; | |
1249 | |
1250 print_test_name ("broadcast_coding_history_test", filename) ; | |
1251 | |
1252 sfinfo.samplerate = 22050 ; | |
1253 sfinfo.format = SF_FORMAT_WAV | SF_FORMAT_PCM_16 ; | |
1254 sfinfo.channels = 1 ; | |
1255 | |
1256 memset (&bc_write, 0, sizeof (bc_write)) ; | |
1257 | |
1258 snprintf (bc_write.description, sizeof (bc_write.description), "Test description") ; | |
1259 snprintf (bc_write.originator, sizeof (bc_write.originator), "Test originator") ; | |
1260 snprintf (bc_write.originator_reference, sizeof (bc_write.originator_reference), "%08x-%08x", (unsigned int) time (NULL), (unsigned int) (~ time (NULL))) ; | |
1261 snprintf (bc_write.origination_date, sizeof (bc_write.origination_date), "%d/%02d/%02d", 2006, 3, 30) ; | |
1262 snprintf (bc_write.origination_time, sizeof (bc_write.origination_time), "%02d:%02d:%02d", 20, 27, 0) ; | |
1263 snprintf (bc_write.umid, sizeof (bc_write.umid), "Some umid") ; | |
1264 /* Coding history will be filled in by the library. */ | |
1265 bc_write.coding_history_size = 0 ; | |
1266 | |
1267 file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ; | |
1268 if (sf_command (file, SFC_SET_BROADCAST_INFO, &bc_write, sizeof (bc_write)) == SF_FALSE) | |
1269 { printf ("\n\nLine %d : sf_command (SFC_SET_BROADCAST_INFO) failed.\n\n", __LINE__) ; | |
1270 exit (1) ; | |
1271 } ; | |
1272 | |
1273 test_write_double_or_die (file, 0, double_data, BUFFER_LEN, __LINE__) ; | |
1274 sf_close (file) ; | |
1275 | |
1276 memset (&bc_read, 0, sizeof (bc_read)) ; | |
1277 | |
1278 file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ; | |
1279 if (sf_command (file, SFC_GET_BROADCAST_INFO, &bc_read, sizeof (bc_read)) == SF_FALSE) | |
1280 { printf ("\n\nLine %d : sf_command (SFC_SET_BROADCAST_INFO) failed.\n\n", __LINE__) ; | |
1281 exit (1) ; | |
1282 } ; | |
1283 check_log_buffer_or_die (file, __LINE__) ; | |
1284 sf_close (file) ; | |
1285 | |
1286 if (bc_read.coding_history_size == 0) | |
1287 { printf ("\n\nLine %d : missing coding history.\n\n", __LINE__) ; | |
1288 exit (1) ; | |
1289 } ; | |
1290 | |
1291 if (bc_read.coding_history_size < strlen (default_history) || memcmp (bc_read.coding_history, default_history, strlen (default_history)) != 0) | |
1292 { printf ("\n\n" | |
1293 "Line %d : unexpected coding history '%.*s',\n" | |
1294 " should be '%s'\n\n", __LINE__, bc_read.coding_history_size, bc_read.coding_history, default_history) ; | |
1295 exit (1) ; | |
1296 } ; | |
1297 | |
1298 bc_write.coding_history_size = strlen (supplied_history) ; | |
1299 bc_write.coding_history_size = snprintf (bc_write.coding_history, sizeof (bc_write.coding_history), "%s", supplied_history) ; | |
1300 | |
1301 file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ; | |
1302 if (sf_command (file, SFC_SET_BROADCAST_INFO, &bc_write, sizeof (bc_write)) == SF_FALSE) | |
1303 { printf ("\n\nLine %d : sf_command (SFC_SET_BROADCAST_INFO) failed.\n\n", __LINE__) ; | |
1304 exit (1) ; | |
1305 } ; | |
1306 | |
1307 test_write_double_or_die (file, 0, double_data, BUFFER_LEN, __LINE__) ; | |
1308 sf_close (file) ; | |
1309 | |
1310 memset (&bc_read, 0, sizeof (bc_read)) ; | |
1311 | |
1312 file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ; | |
1313 if (sf_command (file, SFC_GET_BROADCAST_INFO, &bc_read, sizeof (bc_read)) == SF_FALSE) | |
1314 { printf ("\n\nLine %d : sf_command (SFC_SET_BROADCAST_INFO) failed.\n\n", __LINE__) ; | |
1315 exit (1) ; | |
1316 } ; | |
1317 | |
1318 check_log_buffer_or_die (file, __LINE__) ; | |
1319 sf_close (file) ; | |
1320 | |
1321 if (strstr (bc_read.coding_history, supplied_history) != bc_read.coding_history) | |
1322 { printf ("\n\nLine %d : unexpected coding history :\n" | |
1323 "----------------------------------------------------\n%s" | |
1324 "----------------------------------------------------\n" | |
1325 "should be this :\n" | |
1326 "----------------------------------------------------\n%s" | |
1327 "----------------------------------------------------\n" | |
1328 "with one more line at the end.\n\n", | |
1329 __LINE__, bc_read.coding_history, supplied_history) ; | |
1330 exit (1) ; | |
1331 } ; | |
1332 | |
1333 check_coding_history_newlines (filename) ; | |
1334 | |
1335 unlink (filename) ; | |
1336 puts ("ok") ; | |
1337 } /* broadcast_coding_history_test */ | |
1338 | |
1339 /*============================================================================== | |
1340 */ | |
1341 | |
1342 static void | |
1343 broadcast_coding_history_size (const char *filename) | |
1344 { /* SF_BROADCAST_INFO struct with coding_history field of 1024 bytes. */ | |
1345 static SF_BROADCAST_INFO_VAR (1024) bc_write ; | |
1346 static SF_BROADCAST_INFO_VAR (1024) bc_read ; | |
1347 SNDFILE *file ; | |
1348 SF_INFO sfinfo ; | |
1349 int k ; | |
1350 | |
1351 print_test_name (__func__, filename) ; | |
1352 | |
1353 sfinfo.samplerate = 22050 ; | |
1354 sfinfo.format = SF_FORMAT_WAV | SF_FORMAT_PCM_16 ; | |
1355 sfinfo.channels = 1 ; | |
1356 | |
1357 memset (&bc_write, 0, sizeof (bc_write)) ; | |
1358 | |
1359 snprintf (bc_write.description, sizeof (bc_write.description), "Test description") ; | |
1360 snprintf (bc_write.originator, sizeof (bc_write.originator), "Test originator") ; | |
1361 snprintf (bc_write.originator_reference, sizeof (bc_write.originator_reference), "%08x-%08x", (unsigned int) time (NULL), (unsigned int) (~ time (NULL))) ; | |
1362 snprintf (bc_write.origination_date, sizeof (bc_write.origination_date), "%d/%02d/%02d", 2006, 3, 30) ; | |
1363 snprintf (bc_write.origination_time, sizeof (bc_write.origination_time), "%02d:%02d:%02d", 20, 27, 0) ; | |
1364 snprintf (bc_write.umid, sizeof (bc_write.umid), "Some umid") ; | |
1365 bc_write.coding_history_size = 0 ; | |
1366 | |
1367 for (k = 0 ; bc_write.coding_history_size < 512 ; k++) | |
1368 { snprintf (bc_write.coding_history + bc_write.coding_history_size, | |
1369 sizeof (bc_write.coding_history) - bc_write.coding_history_size, "line %4d\n", k) ; | |
1370 bc_write.coding_history_size = strlen (bc_write.coding_history) ; | |
1371 } ; | |
1372 | |
1373 exit_if_true (bc_write.coding_history_size < 512, | |
1374 "\n\nLine %d : bc_write.coding_history_size (%d) should be > 512.\n\n", __LINE__, bc_write.coding_history_size) ; | |
1375 | |
1376 file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ; | |
1377 if (sf_command (file, SFC_SET_BROADCAST_INFO, &bc_write, sizeof (bc_write)) == SF_FALSE) | |
1378 { printf ("\n\nLine %d : sf_command (SFC_SET_BROADCAST_INFO) failed.\n\n", __LINE__) ; | |
1379 exit (1) ; | |
1380 } ; | |
1381 | |
1382 test_write_double_or_die (file, 0, double_data, BUFFER_LEN, __LINE__) ; | |
1383 sf_close (file) ; | |
1384 | |
1385 memset (&bc_read, 0, sizeof (bc_read)) ; | |
1386 | |
1387 file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ; | |
1388 if (sf_command (file, SFC_GET_BROADCAST_INFO, &bc_read, sizeof (bc_read)) == SF_FALSE) | |
1389 { printf ("\n\nLine %d : sf_command (SFC_SET_BROADCAST_INFO) failed.\n\n", __LINE__) ; | |
1390 exit (1) ; | |
1391 } ; | |
1392 check_log_buffer_or_die (file, __LINE__) ; | |
1393 sf_close (file) ; | |
1394 | |
1395 exit_if_true (bc_read.coding_history_size < 512, | |
1396 "\n\nLine %d : unexpected coding history size %d (should be > 512).\n\n", __LINE__, bc_read.coding_history_size) ; | |
1397 | |
1398 exit_if_true (strstr (bc_read.coding_history, "libsndfile") == NULL, | |
1399 "\n\nLine %d : coding history incomplete (should contain 'libsndfile').\n\n", __LINE__) ; | |
1400 | |
1401 unlink (filename) ; | |
1402 puts ("ok") ; | |
1403 } /* broadcast_coding_history_size */ | |
1404 | |
1405 /*============================================================================== | |
1406 */ | |
1407 static void | |
1408 cart_test (const char *filename, int filetype) | |
1409 { static SF_CART_INFO ca_write, ca_read ; | |
1410 SNDFILE *file ; | |
1411 SF_INFO sfinfo ; | |
1412 int errors = 0 ; | |
1413 | |
1414 print_test_name ("cart_test", filename) ; | |
1415 | |
1416 sfinfo.samplerate = 11025 ; | |
1417 sfinfo.format = filetype ; | |
1418 sfinfo.channels = 1 ; | |
1419 memset (&ca_write, 0, sizeof (ca_write)) ; | |
1420 | |
1421 // example test data | |
1422 snprintf (ca_write.artist, sizeof (ca_write.artist), "Test artist") ; | |
1423 snprintf (ca_write.version, sizeof (ca_write.version), "Test version") ; | |
1424 snprintf (ca_write.cut_id, sizeof (ca_write.cut_id), "Test cut ID") ; | |
1425 snprintf (ca_write.client_id, sizeof (ca_write.client_id), "Test client ID") ; | |
1426 snprintf (ca_write.category, sizeof (ca_write.category), "Test category") ; | |
1427 snprintf (ca_write.classification, sizeof (ca_write.classification), "Test classification") ; | |
1428 snprintf (ca_write.out_cue, sizeof (ca_write.out_cue), "Test out cue") ; | |
1429 snprintf (ca_write.start_date, sizeof (ca_write.start_date), "%d/%02d/%02d", 2006, 3, 30) ; | |
1430 snprintf (ca_write.start_time, sizeof (ca_write.start_time), "%02d:%02d:%02d", 20, 27, 0) ; | |
1431 snprintf (ca_write.end_date, sizeof (ca_write.end_date), "%d/%02d/%02d", 2006, 3, 30) ; | |
1432 snprintf (ca_write.end_time, sizeof (ca_write.end_time), "%02d:%02d:%02d", 20, 27, 0) ; | |
1433 snprintf (ca_write.producer_app_id, sizeof (ca_write.producer_app_id), "Test producer app id") ; | |
1434 snprintf (ca_write.producer_app_version, sizeof (ca_write.producer_app_version), "Test producer app version") ; | |
1435 snprintf (ca_write.user_def, sizeof (ca_write.user_def), "test user def test test") ; | |
1436 ca_write.level_reference = 42 ; | |
1437 snprintf (ca_write.url, sizeof (ca_write.url), "http://www.test.com/test_url") ; | |
1438 snprintf (ca_write.tag_text, sizeof (ca_write.tag_text), "tag text test! \r\n") ; // must be terminated \r\n to be valid | |
1439 ca_write.tag_text_size = strlen (ca_write.tag_text) ; | |
1440 | |
1441 file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ; | |
1442 if (sf_command (file, SFC_SET_CART_INFO, &ca_write, sizeof (ca_write)) == SF_FALSE) | |
1443 exit (1) ; | |
1444 | |
1445 test_write_double_or_die (file, 0, double_data, BUFFER_LEN, __LINE__) ; | |
1446 sf_close (file) ; | |
1447 | |
1448 memset (&ca_read, 0, sizeof (ca_read)) ; | |
1449 | |
1450 file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ; | |
1451 if (sf_command (file, SFC_GET_CART_INFO, &ca_read, sizeof (ca_read)) == SF_FALSE) | |
1452 { printf ("\n\nLine %d : sf_command (SFC_GET_CART_INFO) failed.\n\n", __LINE__) ; | |
1453 exit (1) ; | |
1454 return ; | |
1455 } ; | |
1456 check_log_buffer_or_die (file, __LINE__) ; | |
1457 sf_close (file) ; | |
1458 | |
1459 | |
1460 if (memcmp (ca_write.artist, ca_read.artist, sizeof (ca_write.artist)) != 0) | |
1461 { printf ("\n\nLine %d : artist mismatch :\n\twrite : '%s'\n\tread : '%s'\n\n", __LINE__, ca_write.artist, ca_read.artist) ; | |
1462 errors ++ ; | |
1463 } ; | |
1464 | |
1465 if (memcmp (ca_write.version, ca_read.version, sizeof (ca_write.version)) != 0) | |
1466 { printf ("\n\nLine %d : version mismatch :\n\twrite : '%s'\n\tread : '%s'\n\n", __LINE__, ca_write.version, ca_read.version) ; | |
1467 errors ++ ; | |
1468 } ; | |
1469 | |
1470 if (memcmp (ca_write.title, ca_read.title, sizeof (ca_write.title)) != 0) | |
1471 { printf ("\n\nLine %d : title mismatch :\n\twrite : '%s'\n\tread : '%s'\n\n", __LINE__, ca_write.title, ca_read.title) ; | |
1472 errors ++ ; | |
1473 } ; | |
1474 | |
1475 if (memcmp (ca_write.cut_id, ca_read.cut_id, sizeof (ca_write.cut_id)) != 0) | |
1476 { printf ("\n\nLine %d : cut_id mismatch :\n\twrite : '%s'\n\tread : '%s'\n\n", __LINE__, ca_write.cut_id, ca_read.cut_id) ; | |
1477 errors ++ ; | |
1478 } ; | |
1479 | |
1480 if (memcmp (ca_write.client_id, ca_read.client_id, sizeof (ca_write.client_id)) != 0) | |
1481 { printf ("\n\nLine %d : client_id mismatch :\n\twrite : '%s'\n\tread : '%s'\n\n", __LINE__, ca_write.client_id, ca_read.client_id) ; | |
1482 errors ++ ; | |
1483 } ; | |
1484 | |
1485 if (memcmp (ca_write.category, ca_read.category, sizeof (ca_write.category)) != 0) | |
1486 { printf ("\n\nLine %d : category mismatch :\n\twrite : '%s'\n\tread : '%s'\n\n", __LINE__, ca_write.category, ca_read.category) ; | |
1487 errors ++ ; | |
1488 } ; | |
1489 | |
1490 if (memcmp (ca_write.out_cue, ca_read.out_cue, sizeof (ca_write.out_cue)) != 0) | |
1491 { printf ("\n\nLine %d : out_cue mismatch :\n\twrite : '%s'\n\tread : '%s'\n\n", __LINE__, ca_write.out_cue, ca_read.out_cue) ; | |
1492 errors ++ ; | |
1493 } ; | |
1494 | |
1495 if (memcmp (ca_write.start_date, ca_read.start_date, sizeof (ca_write.start_date)) != 0) | |
1496 { printf ("\n\nLine %d : start_date mismatch :\n\twrite : '%s'\n\tread : '%s'\n\n", __LINE__, ca_write.start_date, ca_read.start_date) ; | |
1497 errors ++ ; | |
1498 } ; | |
1499 | |
1500 | |
1501 if (memcmp (ca_write.start_time, ca_read.start_time, sizeof (ca_write.start_time)) != 0) | |
1502 { printf ("\n\nLine %d : start_time mismatch :\n\twrite : '%s'\n\tread : '%s'\n\n", __LINE__, ca_write.start_time, ca_read.start_time) ; | |
1503 errors ++ ; | |
1504 } ; | |
1505 | |
1506 | |
1507 if (memcmp (ca_write.end_date, ca_read.end_date, sizeof (ca_write.end_date)) != 0) | |
1508 { printf ("\n\nLine %d : end_date mismatch :\n\twrite : '%s'\n\tread : '%s'\n\n", __LINE__, ca_write.end_date, ca_read.end_date) ; | |
1509 errors ++ ; | |
1510 } ; | |
1511 | |
1512 | |
1513 if (memcmp (ca_write.end_time, ca_read.end_time, sizeof (ca_write.end_time)) != 0) | |
1514 { printf ("\n\nLine %d : end_time mismatch :\n\twrite : '%s'\n\tread : '%s'\n\n", __LINE__, ca_write.end_time, ca_read.end_time) ; | |
1515 errors ++ ; | |
1516 } ; | |
1517 | |
1518 | |
1519 if (memcmp (ca_write.producer_app_id, ca_read.producer_app_id, sizeof (ca_write.producer_app_id)) != 0) | |
1520 { printf ("\n\nLine %d : producer_app_id mismatch :\n\twrite : '%s'\n\tread : '%s'\n\n", __LINE__, ca_write.producer_app_id, ca_read.producer_app_id) ; | |
1521 errors ++ ; | |
1522 } ; | |
1523 | |
1524 | |
1525 if (memcmp (ca_write.producer_app_version, ca_read.producer_app_version, sizeof (ca_write.producer_app_version)) != 0) | |
1526 { printf ("\n\nLine %d : producer_app_version mismatch :\n\twrite : '%s'\n\tread : '%s'\n\n", __LINE__, ca_write.producer_app_version, ca_read.producer_app_version) ; | |
1527 errors ++ ; | |
1528 } ; | |
1529 | |
1530 | |
1531 if (memcmp (ca_write.user_def, ca_read.user_def, sizeof (ca_write.user_def)) != 0) | |
1532 { printf ("\n\nLine %d : user_def mismatch :\n\twrite : '%s'\n\tread : '%s'\n\n", __LINE__, ca_write.user_def, ca_read.user_def) ; | |
1533 errors ++ ; | |
1534 } ; | |
1535 | |
1536 | |
1537 if (ca_write.level_reference != ca_read.level_reference) | |
1538 { printf ("\n\nLine %d : level_reference mismatch :\n\twrite : '%d'\n\tread : '%d'\n\n", __LINE__, ca_write.level_reference, ca_read.level_reference) ; | |
1539 errors ++ ; | |
1540 } ; | |
1541 | |
1542 // TODO: make this more helpful | |
1543 if (memcmp (ca_write.post_timers, ca_read.post_timers, sizeof (ca_write.post_timers)) != 0) | |
1544 { printf ("\n\nLine %d : post_timers mismatch :\n'\n\n", __LINE__) ; | |
1545 errors ++ ; | |
1546 } ; | |
1547 | |
1548 if (memcmp (ca_write.url, ca_read.url, sizeof (ca_write.url)) != 0) | |
1549 { printf ("\n\nLine %d : url mismatch :\n\twrite : '%s'\n\tread : '%s'\n\n", __LINE__, ca_write.url, ca_read.url) ; | |
1550 errors ++ ; | |
1551 } ; | |
1552 | |
1553 | |
1554 if (memcmp (ca_write.tag_text, ca_read.tag_text, (size_t) (ca_read.tag_text_size)) != 0) | |
1555 { printf ("\n\nLine %d : tag_text mismatch :\n\twrite : '%s'\n\tread : '%s'\n\n", __LINE__, ca_write.tag_text, ca_read.tag_text) ; | |
1556 errors ++ ; | |
1557 } ; | |
1558 | |
1559 | |
1560 if (errors) | |
1561 exit (1) ; | |
1562 | |
1563 unlink (filename) ; | |
1564 puts ("ok") ; | |
1565 } /* cart_test */ | |
1566 | |
1567 static void | |
1568 cart_rdwr_test (const char *filename, int filetype) | |
1569 { SF_CART_INFO cinfo ; | |
1570 SNDFILE *file ; | |
1571 SF_INFO sfinfo ; | |
1572 sf_count_t frames ; | |
1573 | |
1574 print_test_name (__func__, filename) ; | |
1575 | |
1576 create_short_sndfile (filename, filetype, 2) ; | |
1577 | |
1578 memset (&sfinfo, 0, sizeof (sfinfo)) ; | |
1579 memset (&cinfo, 0, sizeof (cinfo)) ; | |
1580 | |
1581 snprintf (cinfo.artist, sizeof (cinfo.artist), "Test artist") ; | |
1582 snprintf (cinfo.version, sizeof (cinfo.version), "Test version") ; | |
1583 snprintf (cinfo.cut_id, sizeof (cinfo.cut_id), "Test cut ID") ; | |
1584 snprintf (cinfo.client_id, sizeof (cinfo.client_id), "Test client ID") ; | |
1585 snprintf (cinfo.category, sizeof (cinfo.category), "Test category") ; | |
1586 snprintf (cinfo.classification, sizeof (cinfo.classification), "Test classification") ; | |
1587 snprintf (cinfo.out_cue, sizeof (cinfo.out_cue), "Test out cue") ; | |
1588 snprintf (cinfo.start_date, sizeof (cinfo.start_date), "%d/%02d/%02d", 2006, 3, 30) ; | |
1589 snprintf (cinfo.start_time, sizeof (cinfo.start_time), "%02d:%02d:%02d", 20, 27, 0) ; | |
1590 snprintf (cinfo.end_date, sizeof (cinfo.end_date), "%d/%02d/%02d", 2006, 3, 30) ; | |
1591 snprintf (cinfo.end_time, sizeof (cinfo.end_time), "%02d:%02d:%02d", 20, 27, 0) ; | |
1592 snprintf (cinfo.producer_app_id, sizeof (cinfo.producer_app_id), "Test producer app id") ; | |
1593 snprintf (cinfo.producer_app_version, sizeof (cinfo.producer_app_version), "Test producer app version") ; | |
1594 snprintf (cinfo.user_def, sizeof (cinfo.user_def), "test user def test test") ; | |
1595 cinfo.level_reference = 42 ; | |
1596 snprintf (cinfo.url, sizeof (cinfo.url), "http://www.test.com/test_url") ; | |
1597 snprintf (cinfo.tag_text, sizeof (cinfo.tag_text), "tag text test!\r\n") ; | |
1598 cinfo.tag_text_size = strlen (cinfo.tag_text) ; | |
1599 | |
1600 file = test_open_file_or_die (filename, SFM_RDWR, &sfinfo, SF_TRUE, __LINE__) ; | |
1601 frames = sfinfo.frames ; | |
1602 if (sf_command (file, SFC_SET_CART_INFO, &cinfo, sizeof (cinfo)) != SF_FALSE) | |
1603 { printf ("\n\nLine %d : sf_command (SFC_SET_CART_INFO) should have failed but didn't.\n\n", __LINE__) ; | |
1604 exit (1) ; | |
1605 } ; | |
1606 sf_close (file) ; | |
1607 | |
1608 file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ; | |
1609 sf_close (file) ; | |
1610 exit_if_true (frames != sfinfo.frames, "\n\nLine %d : Frame count %" PRId64 " should be %" PRId64 ".\n", __LINE__, sfinfo.frames, frames) ; | |
1611 | |
1612 unlink (filename) ; | |
1613 puts ("ok") ; | |
1614 } /* cart_rdwr_test */ | |
1615 | |
1616 /*============================================================================== | |
1617 */ | |
1618 | |
1619 static void | |
1620 channel_map_test (const char *filename, int filetype) | |
1621 { SNDFILE *file ; | |
1622 SF_INFO sfinfo ; | |
1623 int channel_map_read [4], channel_map_write [4] = | |
1624 { SF_CHANNEL_MAP_LEFT, SF_CHANNEL_MAP_RIGHT, SF_CHANNEL_MAP_LFE, | |
1625 SF_CHANNEL_MAP_REAR_CENTER | |
1626 } ; | |
1627 | |
1628 print_test_name ("channel_map_test", filename) ; | |
1629 | |
1630 memset (&sfinfo, 0, sizeof (sfinfo)) ; | |
1631 sfinfo.samplerate = 11025 ; | |
1632 sfinfo.format = filetype ; | |
1633 sfinfo.channels = ARRAY_LEN (channel_map_read) ; | |
1634 | |
1635 switch (filetype & SF_FORMAT_TYPEMASK) | |
1636 { /* WAVEX and RF64 have a default channel map, even if you don't specify one. */ | |
1637 case SF_FORMAT_WAVEX : | |
1638 case SF_FORMAT_RF64 : | |
1639 /* Write file without channel map. */ | |
1640 file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ; | |
1641 test_write_double_or_die (file, 0, double_data, BUFFER_LEN, __LINE__) ; | |
1642 sf_close (file) ; | |
1643 | |
1644 /* Read file making default channel map exists. */ | |
1645 file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ; | |
1646 exit_if_true ( | |
1647 sf_command (file, SFC_GET_CHANNEL_MAP_INFO, channel_map_read, sizeof (channel_map_read)) == SF_FALSE, | |
1648 "\n\nLine %d : sf_command (SFC_GET_CHANNEL_MAP_INFO) should not have failed.\n\n", __LINE__ | |
1649 ) ; | |
1650 check_log_buffer_or_die (file, __LINE__) ; | |
1651 sf_close (file) ; | |
1652 break ; | |
1653 | |
1654 default : | |
1655 break ; | |
1656 } ; | |
1657 | |
1658 /* Write file with a channel map. */ | |
1659 file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ; | |
1660 exit_if_true ( | |
1661 sf_command (file, SFC_SET_CHANNEL_MAP_INFO, channel_map_write, sizeof (channel_map_write)) == SF_FALSE, | |
1662 "\n\nLine %d : sf_command (SFC_SET_CHANNEL_MAP_INFO) failed.\n\n", __LINE__ | |
1663 ) ; | |
1664 test_write_double_or_die (file, 0, double_data, BUFFER_LEN, __LINE__) ; | |
1665 sf_close (file) ; | |
1666 | |
1667 /* Read file making sure no channel map exists. */ | |
1668 file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ; | |
1669 exit_if_true ( | |
1670 sf_command (file, SFC_GET_CHANNEL_MAP_INFO, channel_map_read, sizeof (channel_map_read)) != SF_TRUE, | |
1671 "\n\nLine %d : sf_command (SFC_GET_CHANNEL_MAP_INFO) failed.\n\n", __LINE__ | |
1672 ) ; | |
1673 check_log_buffer_or_die (file, __LINE__) ; | |
1674 sf_close (file) ; | |
1675 | |
1676 exit_if_true ( | |
1677 memcmp (channel_map_read, channel_map_write, sizeof (channel_map_read)) != 0, | |
1678 "\n\nLine %d : Channel map read does not match channel map written.\n\n", __LINE__ | |
1679 ) ; | |
1680 | |
1681 unlink (filename) ; | |
1682 puts ("ok") ; | |
1683 } /* channel_map_test */ | |
1684 | |
1685 static void | |
1686 raw_needs_endswap_test (const char *filename, int filetype) | |
1687 { static int subtypes [] = | |
1688 { SF_FORMAT_FLOAT, SF_FORMAT_DOUBLE, | |
1689 SF_FORMAT_PCM_16, SF_FORMAT_PCM_24, SF_FORMAT_PCM_32 | |
1690 } ; | |
1691 SNDFILE *file ; | |
1692 SF_INFO sfinfo ; | |
1693 unsigned k ; | |
1694 int needs_endswap ; | |
1695 | |
1696 print_test_name (__func__, filename) ; | |
1697 | |
1698 for (k = 0 ; k < ARRAY_LEN (subtypes) ; k++) | |
1699 { | |
1700 if (filetype == (SF_ENDIAN_LITTLE | SF_FORMAT_AIFF)) | |
1701 switch (subtypes [k]) | |
1702 { /* Little endian AIFF does not AFAIK support fl32 and fl64. */ | |
1703 case SF_FORMAT_FLOAT : | |
1704 case SF_FORMAT_DOUBLE : | |
1705 continue ; | |
1706 default : | |
1707 break ; | |
1708 } ; | |
1709 | |
1710 memset (&sfinfo, 0, sizeof (sfinfo)) ; | |
1711 sfinfo.samplerate = 11025 ; | |
1712 sfinfo.format = filetype | subtypes [k] ; | |
1713 sfinfo.channels = 1 ; | |
1714 | |
1715 file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ; | |
1716 test_write_double_or_die (file, 0, double_data, BUFFER_LEN, __LINE__) ; | |
1717 sf_close (file) ; | |
1718 | |
1719 memset (&sfinfo, 0, sizeof (sfinfo)) ; | |
1720 file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ; | |
1721 | |
1722 needs_endswap = sf_command (file, SFC_RAW_DATA_NEEDS_ENDSWAP, NULL, 0) ; | |
1723 | |
1724 switch (filetype) | |
1725 { case SF_FORMAT_WAV : | |
1726 case SF_FORMAT_WAVEX : | |
1727 case SF_FORMAT_AIFF | SF_ENDIAN_LITTLE : | |
1728 exit_if_true (needs_endswap != CPU_IS_BIG_ENDIAN, | |
1729 "\n\nLine %d : SFC_RAW_DATA_NEEDS_ENDSWAP failed for (%d | %d).\n\n", __LINE__, filetype, k) ; | |
1730 break ; | |
1731 | |
1732 case SF_FORMAT_AIFF : | |
1733 case SF_FORMAT_WAV | SF_ENDIAN_BIG : | |
1734 exit_if_true (needs_endswap != CPU_IS_LITTLE_ENDIAN, | |
1735 "\n\nLine %d : SFC_RAW_DATA_NEEDS_ENDSWAP failed for (%d | %d).\n\n", __LINE__, filetype, k) ; | |
1736 break ; | |
1737 | |
1738 default : | |
1739 printf ("\n\nLine %d : bad format value %d.\n\n", __LINE__, filetype) ; | |
1740 exit (1) ; | |
1741 break ; | |
1742 } ; | |
1743 | |
1744 sf_close (file) ; | |
1745 } ; | |
1746 | |
1747 unlink (filename) ; | |
1748 puts ("ok") ; | |
1749 } /* raw_needs_endswap_test */ |