2 ** Copyright (C) 2001-2011 Erik de Castro Lopo <erikd@mega-nerd.com>
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.
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.
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.
36 #define BUFFER_LEN (1<<10)
37 #define LOG_BUFFER_SIZE 1024
39 static void float_norm_test (const char *filename
) ;
40 static void double_norm_test (const char *filename
) ;
41 static void format_tests (void) ;
42 static void calc_peak_test (int filetype
, const char *filename
) ;
43 static void truncate_test (const char *filename
, int filetype
) ;
44 static void instrument_test (const char *filename
, int filetype
) ;
45 static void channel_map_test (const char *filename
, int filetype
) ;
46 static void current_sf_info_test (const char *filename
) ;
47 static void raw_needs_endswap_test (const char *filename
, int filetype
) ;
49 static void broadcast_test (const char *filename
, int filetype
) ;
50 static void broadcast_rdwr_test (const char *filename
, int filetype
) ;
51 static void broadcast_coding_history_test (const char *filename
) ;
52 static void broadcast_coding_history_size (const char *filename
) ;
54 /* Force the start of this buffer to be double aligned. Sparc-solaris will
58 static int int_data
[BUFFER_LEN
] ;
59 static float float_data
[BUFFER_LEN
] ;
60 static double double_data
[BUFFER_LEN
] ;
63 main (int argc
, char *argv
[])
68 { printf ("Usage : %s <test>\n", argv
[0]) ;
69 printf (" Where <test> is one of the following:\n") ;
70 printf (" ver - test sf_command (SFC_GETLIB_VERSION)\n") ;
71 printf (" norm - test floating point normalisation\n") ;
72 printf (" format - test format string commands\n") ;
73 printf (" peak - test peak calculation\n") ;
74 printf (" trunc - test file truncation\n") ;
75 printf (" inst - test set/get of SF_INSTRUMENT.\n") ;
76 printf (" chanmap - test set/get of channel map data..\n") ;
77 printf (" bext - test set/get of SF_BROADCAST_INFO.\n") ;
78 printf (" bextch - test set/get of SF_BROADCAST_INFO coding_history.\n") ;
79 printf (" rawend - test SFC_RAW_NEEDS_ENDSWAP.\n") ;
80 printf (" all - perform all tests\n") ;
84 do_all
=! strcmp (argv
[1], "all") ;
86 if (do_all
|| strcmp (argv
[1], "ver") == 0)
89 print_test_name ("version_test", "(none)") ;
91 sf_command (NULL
, SFC_GET_LIB_VERSION
, buffer
, sizeof (buffer
)) ;
92 if (strlen (buffer
) < 1)
93 { printf ("Line %d: could not retrieve lib version.\n", __LINE__
) ;
100 if (do_all
|| strcmp (argv
[1], "norm") == 0)
101 { /* Preliminary float/double normalisation tests. More testing
102 ** is done in the program 'floating_point_test'.
104 float_norm_test ("float.wav") ;
105 double_norm_test ("double.wav") ;
109 if (do_all
|| strcmp (argv
[1], "peak") == 0)
110 { calc_peak_test (SF_ENDIAN_BIG
| SF_FORMAT_RAW
, "be-peak.raw") ;
111 calc_peak_test (SF_ENDIAN_LITTLE
| SF_FORMAT_RAW
, "le-peak.raw") ;
115 if (do_all
|| ! strcmp (argv
[1], "format"))
120 if (do_all
|| strcmp (argv
[1], "trunc") == 0)
121 { truncate_test ("truncate.raw", SF_FORMAT_RAW
| SF_FORMAT_PCM_32
) ;
122 truncate_test ("truncate.au" , SF_FORMAT_AU
| SF_FORMAT_PCM_16
) ;
126 if (do_all
|| strcmp (argv
[1], "inst") == 0)
127 { instrument_test ("instrument.wav", SF_FORMAT_WAV
| SF_FORMAT_PCM_16
) ;
128 instrument_test ("instrument.aiff" , SF_FORMAT_AIFF
| SF_FORMAT_PCM_24
) ;
129 /*-instrument_test ("instrument.xi", SF_FORMAT_XI | SF_FORMAT_DPCM_16) ;-*/
133 if (do_all
|| strcmp (argv
[1], "current_sf_info") == 0)
134 { current_sf_info_test ("current.wav") ;
138 if (do_all
|| strcmp (argv
[1], "bext") == 0)
139 { broadcast_test ("broadcast.wav", SF_FORMAT_WAV
| SF_FORMAT_PCM_16
) ;
140 broadcast_rdwr_test ("broadcast.wav", SF_FORMAT_WAV
| SF_FORMAT_PCM_16
) ;
142 broadcast_test ("broadcast.wavex", SF_FORMAT_WAVEX
| SF_FORMAT_PCM_16
) ;
143 broadcast_rdwr_test ("broadcast.wavex", SF_FORMAT_WAVEX
| SF_FORMAT_PCM_16
) ;
145 broadcast_test ("broadcast.rf64", SF_FORMAT_RF64
| SF_FORMAT_PCM_16
) ;
146 broadcast_rdwr_test ("broadcast.rf64", SF_FORMAT_RF64
| SF_FORMAT_PCM_16
) ;
150 if (do_all
|| strcmp (argv
[1], "bextch") == 0)
151 { broadcast_coding_history_test ("coding_history.wav") ;
152 broadcast_coding_history_size ("coding_hist_size.wav") ;
156 if (do_all
|| strcmp (argv
[1], "chanmap") == 0)
157 { channel_map_test ("chanmap.wavex", SF_FORMAT_WAVEX
| SF_FORMAT_PCM_16
) ;
158 channel_map_test ("chanmap.rf64", SF_FORMAT_RF64
| SF_FORMAT_PCM_16
) ;
159 channel_map_test ("chanmap.aifc" , SF_FORMAT_AIFF
| SF_FORMAT_PCM_16
) ;
160 channel_map_test ("chanmap.caf" , SF_FORMAT_CAF
| SF_FORMAT_PCM_16
) ;
164 if (do_all
|| strcmp (argv
[1], "rawend") == 0)
165 { raw_needs_endswap_test ("raw_end.wav", SF_FORMAT_WAV
) ;
166 raw_needs_endswap_test ("raw_end.wavex", SF_FORMAT_WAVEX
) ;
167 raw_needs_endswap_test ("raw_end.rifx", SF_ENDIAN_BIG
| SF_FORMAT_WAV
) ;
168 raw_needs_endswap_test ("raw_end.aiff", SF_FORMAT_AIFF
) ;
169 raw_needs_endswap_test ("raw_end.aiff_le", SF_ENDIAN_LITTLE
| SF_FORMAT_AIFF
) ;
174 { printf ("Mono : ************************************\n") ;
175 printf ("Mono : * No '%s' test defined.\n", argv
[1]) ;
176 printf ("Mono : ************************************\n") ;
183 /*============================================================================================
184 ** Here are the test functions.
188 float_norm_test (const char *filename
)
193 print_test_name ("float_norm_test", filename
) ;
195 sfinfo
.samplerate
= 44100 ;
196 sfinfo
.format
= (SF_FORMAT_RAW
| SF_FORMAT_PCM_16
) ;
197 sfinfo
.channels
= 1 ;
198 sfinfo
.frames
= BUFFER_LEN
;
200 /* Create float_data with all values being less than 1.0. */
201 for (k
= 0 ; k
< BUFFER_LEN
/ 2 ; k
++)
202 float_data
[k
] = (k
+ 5) / (2.0 * BUFFER_LEN
) ;
203 for (k
= BUFFER_LEN
/ 2 ; k
< BUFFER_LEN
; k
++)
204 float_data
[k
] = (k
+ 5) ;
206 if (! (file
= sf_open (filename
, SFM_WRITE
, &sfinfo
)))
207 { printf ("Line %d: sf_open_write failed with error : ", __LINE__
) ;
209 puts (sf_strerror (NULL
)) ;
213 /* Normalisation is on by default so no need to do anything here. */
215 if ((k
= sf_write_float (file
, float_data
, BUFFER_LEN
/ 2)) != BUFFER_LEN
/ 2)
216 { printf ("Line %d: sf_write_float failed with short write (%d ->%d)\n", __LINE__
, BUFFER_LEN
, k
) ;
220 /* Turn normalisation off. */
221 sf_command (file
, SFC_SET_NORM_FLOAT
, NULL
, SF_FALSE
) ;
223 if ((k
= sf_write_float (file
, float_data
+ BUFFER_LEN
/ 2, BUFFER_LEN
/ 2)) != BUFFER_LEN
/ 2)
224 { printf ("Line %d: sf_write_float failed with short write (%d ->%d)\n", __LINE__
, BUFFER_LEN
, k
) ;
230 /* sfinfo struct should still contain correct data. */
231 if (! (file
= sf_open (filename
, SFM_READ
, &sfinfo
)))
232 { printf ("Line %d: sf_open_read failed with error : ", __LINE__
) ;
234 puts (sf_strerror (NULL
)) ;
238 if (sfinfo
.format
!= (SF_FORMAT_RAW
| SF_FORMAT_PCM_16
))
239 { printf ("Line %d: Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__
, (SF_FORMAT_RAW
| SF_FORMAT_PCM_16
), sfinfo
.format
) ;
243 if (sfinfo
.frames
!= BUFFER_LEN
)
244 { printf ("\n\nLine %d: Incorrect number of.frames in file. (%d => %ld)\n", __LINE__
, BUFFER_LEN
, SF_COUNT_TO_LONG (sfinfo
.frames
)) ;
248 if (sfinfo
.channels
!= 1)
249 { printf ("Line %d: Incorrect number of channels in file.\n", __LINE__
) ;
253 /* Read float_data and check that it is normalised (ie default). */
254 if ((k
= sf_read_float (file
, float_data
, BUFFER_LEN
)) != BUFFER_LEN
)
255 { printf ("\n\nLine %d: sf_read_float failed with short read (%d ->%d)\n", __LINE__
, BUFFER_LEN
, k
) ;
259 for (k
= 0 ; k
< BUFFER_LEN
; k
++)
260 if (float_data
[k
] >= 1.0)
261 { printf ("\n\nLine %d: float_data [%d] == %f which is greater than 1.0\n", __LINE__
, k
, float_data
[k
]) ;
265 /* Seek to start of file, turn normalisation off, read float_data and check again. */
266 sf_seek (file
, 0, SEEK_SET
) ;
267 sf_command (file
, SFC_SET_NORM_FLOAT
, NULL
, SF_FALSE
) ;
269 if ((k
= sf_read_float (file
, float_data
, BUFFER_LEN
)) != BUFFER_LEN
)
270 { printf ("\n\nLine %d: sf_read_float failed with short read (%d ->%d)\n", __LINE__
, BUFFER_LEN
, k
) ;
274 for (k
= 0 ; k
< BUFFER_LEN
; k
++)
275 if (float_data
[k
] < 1.0)
276 { printf ("\n\nLine %d: float_data [%d] == %f which is less than 1.0\n", __LINE__
, k
, float_data
[k
]) ;
280 /* Seek to start of file, turn normalisation on, read float_data and do final check. */
281 sf_seek (file
, 0, SEEK_SET
) ;
282 sf_command (file
, SFC_SET_NORM_FLOAT
, NULL
, SF_TRUE
) ;
284 if ((k
= sf_read_float (file
, float_data
, BUFFER_LEN
)) != BUFFER_LEN
)
285 { printf ("\n\nLine %d: sf_read_float failed with short read (%d ->%d)\n", __LINE__
, BUFFER_LEN
, k
) ;
289 for (k
= 0 ; k
< BUFFER_LEN
; k
++)
290 if (float_data
[k
] > 1.0)
291 { printf ("\n\nLine %d: float_data [%d] == %f which is greater than 1.0\n", __LINE__
, k
, float_data
[k
]) ;
301 } /* float_norm_test */
304 double_norm_test (const char *filename
)
309 print_test_name ("double_norm_test", filename
) ;
311 sfinfo
.samplerate
= 44100 ;
312 sfinfo
.format
= (SF_FORMAT_RAW
| SF_FORMAT_PCM_16
) ;
313 sfinfo
.channels
= 1 ;
314 sfinfo
.frames
= BUFFER_LEN
;
316 /* Create double_data with all values being less than 1.0. */
317 for (k
= 0 ; k
< BUFFER_LEN
/ 2 ; k
++)
318 double_data
[k
] = (k
+ 5) / (2.0 * BUFFER_LEN
) ;
319 for (k
= BUFFER_LEN
/ 2 ; k
< BUFFER_LEN
; k
++)
320 double_data
[k
] = (k
+ 5) ;
322 if (! (file
= sf_open (filename
, SFM_WRITE
, &sfinfo
)))
323 { printf ("Line %d: sf_open_write failed with error : ", __LINE__
) ;
325 puts (sf_strerror (NULL
)) ;
329 /* Normailsation is on by default so no need to do anything here. */
330 /*-sf_command (file, "set-norm-double", "true", 0) ;-*/
332 if ((k
= sf_write_double (file
, double_data
, BUFFER_LEN
/ 2)) != BUFFER_LEN
/ 2)
333 { printf ("Line %d: sf_write_double failed with short write (%d ->%d)\n", __LINE__
, BUFFER_LEN
, k
) ;
337 /* Turn normalisation off. */
338 sf_command (file
, SFC_SET_NORM_DOUBLE
, NULL
, SF_FALSE
) ;
340 if ((k
= sf_write_double (file
, double_data
+ BUFFER_LEN
/ 2, BUFFER_LEN
/ 2)) != BUFFER_LEN
/ 2)
341 { printf ("Line %d: sf_write_double failed with short write (%d ->%d)\n", __LINE__
, BUFFER_LEN
, k
) ;
347 if (! (file
= sf_open (filename
, SFM_READ
, &sfinfo
)))
348 { printf ("Line %d: sf_open_read failed with error : ", __LINE__
) ;
350 puts (sf_strerror (NULL
)) ;
354 if (sfinfo
.format
!= (SF_FORMAT_RAW
| SF_FORMAT_PCM_16
))
355 { printf ("Line %d: Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__
, (SF_FORMAT_RAW
| SF_FORMAT_PCM_16
), sfinfo
.format
) ;
359 if (sfinfo
.frames
!= BUFFER_LEN
)
360 { printf ("\n\nLine %d: Incorrect number of.frames in file. (%d => %ld)\n", __LINE__
, BUFFER_LEN
, SF_COUNT_TO_LONG (sfinfo
.frames
)) ;
364 if (sfinfo
.channels
!= 1)
365 { printf ("Line %d: Incorrect number of channels in file.\n", __LINE__
) ;
369 /* Read double_data and check that it is normalised (ie default). */
370 if ((k
= sf_read_double (file
, double_data
, BUFFER_LEN
)) != BUFFER_LEN
)
371 { printf ("\n\nLine %d: sf_read_double failed with short read (%d ->%d)\n", __LINE__
, BUFFER_LEN
, k
) ;
375 for (k
= 0 ; k
< BUFFER_LEN
; k
++)
376 if (double_data
[k
] >= 1.0)
377 { printf ("\n\nLine %d: double_data [%d] == %f which is greater than 1.0\n", __LINE__
, k
, double_data
[k
]) ;
381 /* Seek to start of file, turn normalisation off, read double_data and check again. */
382 sf_seek (file
, 0, SEEK_SET
) ;
383 sf_command (file
, SFC_SET_NORM_DOUBLE
, NULL
, SF_FALSE
) ;
385 if ((k
= sf_read_double (file
, double_data
, BUFFER_LEN
)) != BUFFER_LEN
)
386 { printf ("\n\nLine %d: sf_read_double failed with short read (%d ->%d)\n", __LINE__
, BUFFER_LEN
, k
) ;
390 for (k
= 0 ; k
< BUFFER_LEN
; k
++)
391 if (double_data
[k
] < 1.0)
392 { printf ("\n\nLine %d: double_data [%d] == %f which is less than 1.0\n", __LINE__
, k
, double_data
[k
]) ;
396 /* Seek to start of file, turn normalisation on, read double_data and do final check. */
397 sf_seek (file
, 0, SEEK_SET
) ;
398 sf_command (file
, SFC_SET_NORM_DOUBLE
, NULL
, SF_TRUE
) ;
400 if ((k
= sf_read_double (file
, double_data
, BUFFER_LEN
)) != BUFFER_LEN
)
401 { printf ("\n\nLine %d: sf_read_double failed with short read (%d ->%d)\n", __LINE__
, BUFFER_LEN
, k
) ;
405 for (k
= 0 ; k
< BUFFER_LEN
; k
++)
406 if (double_data
[k
] > 1.0)
407 { printf ("\n\nLine %d: double_data [%d] == %f which is greater than 1.0\n", __LINE__
, k
, double_data
[k
]) ;
417 } /* double_norm_test */
421 { SF_FORMAT_INFO format_info
;
423 const char *last_name
;
426 print_test_name ("format_tests", "(null)") ;
428 /* Clear out SF_INFO struct and set channels > 0. */
429 memset (&sfinfo
, 0, sizeof (sfinfo
)) ;
430 sfinfo
.channels
= 1 ;
432 /* First test simple formats. */
434 sf_command (NULL
, SFC_GET_SIMPLE_FORMAT_COUNT
, &count
, sizeof (int)) ;
436 if (count
< 0 || count
> 30)
437 { printf ("Line %d: Weird count.\n", __LINE__
) ;
441 format_info
.format
= 0 ;
442 sf_command (NULL
, SFC_GET_SIMPLE_FORMAT
, &format_info
, sizeof (format_info
)) ;
444 last_name
= format_info
.name
;
445 for (k
= 1 ; k
< count
; k
++)
446 { format_info
.format
= k
;
447 sf_command (NULL
, SFC_GET_SIMPLE_FORMAT
, &format_info
, sizeof (format_info
)) ;
448 if (strcmp (last_name
, format_info
.name
) >= 0)
449 { printf ("\n\nLine %d: format names out of sequence `%s' < `%s'.\n", __LINE__
, last_name
, format_info
.name
) ;
452 sfinfo
.format
= format_info
.format
;
454 if (! sf_format_check (&sfinfo
))
455 { printf ("\n\nLine %d: sf_format_check failed.\n", __LINE__
) ;
456 printf (" Name : %s\n", format_info
.name
) ;
457 printf (" Format : 0x%X\n", sfinfo
.format
) ;
458 printf (" Channels : 0x%X\n", sfinfo
.channels
) ;
459 printf (" Sample Rate : 0x%X\n", sfinfo
.samplerate
) ;
462 last_name
= format_info
.name
;
464 format_info
.format
= 666 ;
465 sf_command (NULL
, SFC_GET_SIMPLE_FORMAT
, &format_info
, sizeof (format_info
)) ;
467 /* Now test major formats. */
468 sf_command (NULL
, SFC_GET_FORMAT_MAJOR_COUNT
, &count
, sizeof (int)) ;
470 if (count
< 0 || count
> 30)
471 { printf ("Line %d: Weird count.\n", __LINE__
) ;
475 format_info
.format
= 0 ;
476 sf_command (NULL
, SFC_GET_FORMAT_MAJOR
, &format_info
, sizeof (format_info
)) ;
478 last_name
= format_info
.name
;
479 for (k
= 1 ; k
< count
; k
++)
480 { format_info
.format
= k
;
481 sf_command (NULL
, SFC_GET_FORMAT_MAJOR
, &format_info
, sizeof (format_info
)) ;
482 if (strcmp (last_name
, format_info
.name
) >= 0)
483 { printf ("\n\nLine %d: format names out of sequence (%d) `%s' < `%s'.\n", __LINE__
, k
, last_name
, format_info
.name
) ;
487 last_name
= format_info
.name
;
489 format_info
.format
= 666 ;
490 sf_command (NULL
, SFC_GET_FORMAT_MAJOR
, &format_info
, sizeof (format_info
)) ;
492 /* Now test subtype formats. */
493 sf_command (NULL
, SFC_GET_FORMAT_SUBTYPE_COUNT
, &count
, sizeof (int)) ;
495 if (count
< 0 || count
> 30)
496 { printf ("Line %d: Weird count.\n", __LINE__
) ;
500 format_info
.format
= 0 ;
501 sf_command (NULL
, SFC_GET_FORMAT_SUBTYPE
, &format_info
, sizeof (format_info
)) ;
503 last_name
= format_info
.name
;
504 for (k
= 1 ; k
< count
; k
++)
505 { format_info
.format
= k
;
506 sf_command (NULL
, SFC_GET_FORMAT_SUBTYPE
, &format_info
, sizeof (format_info
)) ;
508 format_info
.format
= 666 ;
509 sf_command (NULL
, SFC_GET_FORMAT_SUBTYPE
, &format_info
, sizeof (format_info
)) ;
516 calc_peak_test (int filetype
, const char *filename
)
522 print_test_name ("calc_peak_test", filename
) ;
524 format
= (filetype
| SF_FORMAT_PCM_16
) ;
526 sfinfo
.samplerate
= 44100 ;
527 sfinfo
.format
= format
;
528 sfinfo
.channels
= 1 ;
529 sfinfo
.frames
= BUFFER_LEN
;
531 /* Create double_data with max value of 0.5. */
532 for (k
= 0 ; k
< BUFFER_LEN
; k
++)
533 double_data
[k
] = (k
+ 1) / (2.0 * BUFFER_LEN
) ;
535 file
= test_open_file_or_die (filename
, SFM_WRITE
, &sfinfo
, SF_TRUE
, __LINE__
) ;
537 test_write_double_or_die (file
, 0, double_data
, BUFFER_LEN
, __LINE__
) ;
541 file
= test_open_file_or_die (filename
, SFM_READ
, &sfinfo
, SF_TRUE
, __LINE__
) ;
543 if (sfinfo
.format
!= format
)
544 { printf ("Line %d: Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__
, format
, sfinfo
.format
) ;
548 if (sfinfo
.frames
!= BUFFER_LEN
)
549 { printf ("\n\nLine %d: Incorrect number of.frames in file. (%d => %ld)\n", __LINE__
, BUFFER_LEN
, SF_COUNT_TO_LONG (sfinfo
.frames
)) ;
553 if (sfinfo
.channels
!= 1)
554 { printf ("Line %d: Incorrect number of channels in file.\n", __LINE__
) ;
558 sf_command (file
, SFC_CALC_SIGNAL_MAX
, &peak
, sizeof (peak
)) ;
559 if (fabs (peak
- (1 << 14)) > 1.0)
560 { printf ("Line %d : Peak value should be %d (is %f).\n", __LINE__
, (1 << 14), peak
) ;
564 sf_command (file
, SFC_CALC_NORM_SIGNAL_MAX
, &peak
, sizeof (peak
)) ;
565 if (fabs (peak
- 0.5) > 4e-5)
566 { printf ("Line %d : Peak value should be %f (is %f).\n", __LINE__
, 0.5, peak
) ;
572 format
= (filetype
| SF_FORMAT_FLOAT
) ;
573 sfinfo
.samplerate
= 44100 ;
574 sfinfo
.format
= format
;
575 sfinfo
.channels
= 1 ;
576 sfinfo
.frames
= BUFFER_LEN
;
578 /* Create double_data with max value of 0.5. */
579 for (k
= 0 ; k
< BUFFER_LEN
; k
++)
580 double_data
[k
] = (k
+ 1) / (2.0 * BUFFER_LEN
) ;
582 file
= test_open_file_or_die (filename
, SFM_WRITE
, &sfinfo
, SF_TRUE
, __LINE__
) ;
584 test_write_double_or_die (file
, 0, double_data
, BUFFER_LEN
, __LINE__
) ;
588 file
= test_open_file_or_die (filename
, SFM_READ
, &sfinfo
, SF_TRUE
, __LINE__
) ;
590 if (sfinfo
.format
!= format
)
591 { printf ("Line %d: Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__
, format
, sfinfo
.format
) ;
595 if (sfinfo
.frames
!= BUFFER_LEN
)
596 { printf ("\n\nLine %d: Incorrect number of.frames in file. (%d => %ld)\n", __LINE__
, BUFFER_LEN
, SF_COUNT_TO_LONG (sfinfo
.frames
)) ;
600 if (sfinfo
.channels
!= 1)
601 { printf ("Line %d: Incorrect number of channels in file.\n", __LINE__
) ;
605 sf_command (file
, SFC_CALC_SIGNAL_MAX
, &peak
, sizeof (peak
)) ;
606 if (fabs (peak
- 0.5) > 1e-5)
607 { printf ("Line %d : Peak value should be %f (is %f).\n", __LINE__
, 0.5, peak
) ;
611 sf_command (file
, SFC_CALC_NORM_SIGNAL_MAX
, &peak
, sizeof (peak
)) ;
612 if (fabs (peak
- 0.5) > 1e-5)
613 { printf ("Line %d : Peak value should be %f (is %f).\n", __LINE__
, 0.5, peak
) ;
622 } /* calc_peak_test */
625 truncate_test (const char *filename
, int filetype
)
630 print_test_name ("truncate_test", filename
) ;
632 sfinfo
.samplerate
= 11025 ;
633 sfinfo
.format
= filetype
;
634 sfinfo
.channels
= 2 ;
636 file
= test_open_file_or_die (filename
, SFM_RDWR
, &sfinfo
, SF_TRUE
, __LINE__
) ;
638 test_write_int_or_die (file
, 0, int_data
, BUFFER_LEN
, __LINE__
) ;
641 if (sf_command (file
, SFC_FILE_TRUNCATE
, &len
, sizeof (len
)))
642 { printf ("Line %d: sf_command (SFC_FILE_TRUNCATE) returned error.\n", __LINE__
) ;
646 test_seek_or_die (file
, 0, SEEK_CUR
, len
, 2, __LINE__
) ;
647 test_seek_or_die (file
, 0, SEEK_END
, len
, 2, __LINE__
) ;
653 } /* truncate_test */
655 /*------------------------------------------------------------------------------
659 instrumet_rw_test (const char *filename
)
663 memset (&sfinfo
, 0, sizeof (SF_INFO
)) ;
665 sndfile
= test_open_file_or_die (filename
, SFM_RDWR
, &sfinfo
, SF_FALSE
, __LINE__
) ;
667 if (sf_command (sndfile
, SFC_GET_INSTRUMENT
, &inst
, sizeof (inst
)) == SF_TRUE
)
668 { inst
.basenote
= 22 ;
670 if (sf_command (sndfile
, SFC_SET_INSTRUMENT
, &inst
, sizeof (inst
)) == SF_TRUE
)
671 printf ("Sucess: [%s] updated\n", filename
) ;
673 printf ("Error: SFC_SET_INSTRUMENT on [%s] [%s]\n", filename
, sf_strerror (sndfile
)) ;
676 printf ("Error: SFC_GET_INSTRUMENT on [%s] [%s]\n", filename
, sf_strerror (sndfile
)) ;
679 if (sf_command (sndfile
, SFC_UPDATE_HEADER_NOW
, NULL
, 0) != 0)
680 printf ("Error: SFC_UPDATE_HEADER_NOW on [%s] [%s]\n", filename
, sf_strerror (sndfile
)) ;
682 sf_write_sync (sndfile
) ;
686 } /* instrumet_rw_test */
689 instrument_test (const char *filename
, int filetype
)
690 { static SF_INSTRUMENT write_inst
=
694 5, 6, /* key low and high */
695 7, 8, /* velocity low and high */
701 SF_INSTRUMENT read_inst
;
705 print_test_name ("instrument_test", filename
) ;
707 sfinfo
.samplerate
= 11025 ;
708 sfinfo
.format
= filetype
;
709 sfinfo
.channels
= 1 ;
711 file
= test_open_file_or_die (filename
, SFM_WRITE
, &sfinfo
, SF_TRUE
, __LINE__
) ;
712 if (sf_command (file
, SFC_SET_INSTRUMENT
, &write_inst
, sizeof (write_inst
)) == SF_FALSE
)
713 { printf ("\n\nLine %d : sf_command (SFC_SET_INSTRUMENT) failed.\n\n", __LINE__
) ;
716 test_write_double_or_die (file
, 0, double_data
, BUFFER_LEN
, __LINE__
) ;
719 memset (&read_inst
, 0, sizeof (read_inst
)) ;
721 file
= test_open_file_or_die (filename
, SFM_READ
, &sfinfo
, SF_TRUE
, __LINE__
) ;
722 if (sf_command (file
, SFC_GET_INSTRUMENT
, &read_inst
, sizeof (read_inst
)) == SF_FALSE
)
723 { printf ("\n\nLine %d : sf_command (SFC_GET_INSTRUMENT) failed.\n\n", __LINE__
) ;
727 check_log_buffer_or_die (file
, __LINE__
) ;
730 if ((filetype
& SF_FORMAT_TYPEMASK
) == SF_FORMAT_WAV
)
732 ** For all the fields that WAV doesn't support, modify the
733 ** write_inst struct to hold the default value that the WAV
734 ** module should hold.
736 write_inst
.detune
= 0 ;
737 write_inst
.key_lo
= write_inst
.velocity_lo
= 0 ;
738 write_inst
.key_hi
= write_inst
.velocity_hi
= 127 ;
739 write_inst
.gain
= 1 ;
742 if ((filetype
& SF_FORMAT_TYPEMASK
) == SF_FORMAT_XI
)
744 ** For all the fields that XI doesn't support, modify the
745 ** write_inst struct to hold the default value that the XI
746 ** module should hold.
748 write_inst
.basenote
= 0 ;
749 write_inst
.detune
= 0 ;
750 write_inst
.key_lo
= write_inst
.velocity_lo
= 0 ;
751 write_inst
.key_hi
= write_inst
.velocity_hi
= 127 ;
752 write_inst
.gain
= 1 ;
755 if (memcmp (&write_inst
, &read_inst
, sizeof (write_inst
)) != 0)
756 { printf ("\n\nLine %d : instrument comparison failed.\n\n", __LINE__
) ;
757 printf ("W Base Note : %u\n"
759 " Low Note : %u\tHigh Note : %u\n"
760 " Low Vel. : %u\tHigh Vel. : %u\n"
761 " Gain : %d\tCount : %d\n"
763 " start : %d\tend : %d\tcount :%d\n"
765 " start : %d\tend : %d\tcount :%d\n\n",
768 write_inst
.key_lo
, write_inst
.key_hi
,
769 write_inst
.velocity_lo
, write_inst
.velocity_hi
,
770 write_inst
.gain
, write_inst
.loop_count
,
771 write_inst
.loops
[0].mode
, write_inst
.loops
[0].start
,
772 write_inst
.loops
[0].end
, write_inst
.loops
[0].count
,
773 write_inst
.loops
[1].mode
, write_inst
.loops
[1].start
,
774 write_inst
.loops
[1].end
, write_inst
.loops
[1].count
) ;
775 printf ("R Base Note : %u\n"
777 " Low Note : %u\tHigh Note : %u\n"
778 " Low Vel. : %u\tHigh Vel. : %u\n"
779 " Gain : %d\tCount : %d\n"
781 " start : %d\tend : %d\tcount :%d\n"
783 " start : %d\tend : %d\tcount :%d\n\n",
786 read_inst
.key_lo
, read_inst
.key_hi
,
787 read_inst
.velocity_lo
, read_inst
.velocity_hi
,
788 read_inst
.gain
, read_inst
.loop_count
,
789 read_inst
.loops
[0].mode
, read_inst
.loops
[0].start
,
790 read_inst
.loops
[0].end
, read_inst
.loops
[0].count
,
791 read_inst
.loops
[1].mode
, read_inst
.loops
[1].start
,
792 read_inst
.loops
[1].end
, read_inst
.loops
[1].count
) ;
794 if ((filetype
& SF_FORMAT_TYPEMASK
) != SF_FORMAT_XI
)
798 if (0) instrumet_rw_test (filename
) ;
802 } /* instrument_test */
805 current_sf_info_test (const char *filename
)
806 { SNDFILE
*outfile
, *infile
;
807 SF_INFO outinfo
, ininfo
;
809 print_test_name ("current_sf_info_test", filename
) ;
811 outinfo
.samplerate
= 44100 ;
812 outinfo
.format
= (SF_FORMAT_WAV
| SF_FORMAT_PCM_16
) ;
813 outinfo
.channels
= 1 ;
816 outfile
= test_open_file_or_die (filename
, SFM_WRITE
, &outinfo
, SF_TRUE
, __LINE__
) ;
817 sf_command (outfile
, SFC_SET_UPDATE_HEADER_AUTO
, NULL
, 0) ;
819 exit_if_true (outinfo
.frames
!= 0,
820 "\n\nLine %d : Initial sfinfo.frames is not zero.\n\n", __LINE__
823 test_write_double_or_die (outfile
, 0, double_data
, BUFFER_LEN
, __LINE__
) ;
824 sf_command (outfile
, SFC_GET_CURRENT_SF_INFO
, &outinfo
, sizeof (outinfo
)) ;
826 exit_if_true (outinfo
.frames
!= BUFFER_LEN
,
827 "\n\nLine %d : Initial sfinfo.frames (%ld) should be %d.\n\n", __LINE__
,
828 SF_COUNT_TO_LONG (outinfo
.frames
), BUFFER_LEN
831 /* Read file making sure no channel map exists. */
832 memset (&ininfo
, 0, sizeof (ininfo
)) ;
833 infile
= test_open_file_or_die (filename
, SFM_READ
, &ininfo
, SF_TRUE
, __LINE__
) ;
835 test_write_double_or_die (outfile
, 0, double_data
, BUFFER_LEN
, __LINE__
) ;
837 sf_command (infile
, SFC_GET_CURRENT_SF_INFO
, &ininfo
, sizeof (ininfo
)) ;
839 exit_if_true (ininfo
.frames
!= BUFFER_LEN
,
840 "\n\nLine %d : Initial sfinfo.frames (%ld) should be %d.\n\n", __LINE__
,
841 SF_COUNT_TO_LONG (ininfo
.frames
), BUFFER_LEN
849 } /* current_sf_info_test */
852 broadcast_test (const char *filename
, int filetype
)
853 { static SF_BROADCAST_INFO bc_write
, bc_read
;
858 print_test_name ("broadcast_test", filename
) ;
860 sfinfo
.samplerate
= 11025 ;
861 sfinfo
.format
= filetype
;
862 sfinfo
.channels
= 1 ;
864 memset (&bc_write
, 0, sizeof (bc_write
)) ;
866 snprintf (bc_write
.description
, sizeof (bc_write
.description
), "Test description") ;
867 snprintf (bc_write
.originator
, sizeof (bc_write
.originator
), "Test originator") ;
868 snprintf (bc_write
.originator_reference
, sizeof (bc_write
.originator_reference
), "%08x-%08x", (unsigned int) time (NULL
), (unsigned int) (~ time (NULL
))) ;
869 snprintf (bc_write
.origination_date
, sizeof (bc_write
.origination_date
), "%d/%02d/%02d", 2006, 3, 30) ;
870 snprintf (bc_write
.origination_time
, sizeof (bc_write
.origination_time
), "%02d:%02d:%02d", 20, 27, 0) ;
871 snprintf (bc_write
.umid
, sizeof (bc_write
.umid
), "Some umid") ;
872 bc_write
.coding_history_size
= 0 ;
874 file
= test_open_file_or_die (filename
, SFM_WRITE
, &sfinfo
, SF_TRUE
, __LINE__
) ;
875 if (sf_command (file
, SFC_SET_BROADCAST_INFO
, &bc_write
, sizeof (bc_write
)) == SF_FALSE
)
876 { printf ("\n\nLine %d : sf_command (SFC_SET_BROADCAST_INFO) failed.\n\n", __LINE__
) ;
879 test_write_double_or_die (file
, 0, double_data
, BUFFER_LEN
, __LINE__
) ;
882 memset (&bc_read
, 0, sizeof (bc_read
)) ;
884 file
= test_open_file_or_die (filename
, SFM_READ
, &sfinfo
, SF_TRUE
, __LINE__
) ;
885 if (sf_command (file
, SFC_GET_BROADCAST_INFO
, &bc_read
, sizeof (bc_read
)) == SF_FALSE
)
886 { printf ("\n\nLine %d : sf_command (SFC_GET_BROADCAST_INFO) failed.\n\n", __LINE__
) ;
890 check_log_buffer_or_die (file
, __LINE__
) ;
893 if (bc_read
.version
!= 1)
894 { printf ("\n\nLine %d : Read bad version number %d.\n\n", __LINE__
, bc_read
.version
) ;
899 bc_read
.version
= bc_write
.version
= 0 ;
901 if (memcmp (bc_write
.description
, bc_read
.description
, sizeof (bc_write
.description
)) != 0)
902 { printf ("\n\nLine %d : description mismatch :\n\twrite : '%s'\n\tread : '%s'\n\n", __LINE__
, bc_write
.description
, bc_read
.description
) ;
906 if (memcmp (bc_write
.originator
, bc_read
.originator
, sizeof (bc_write
.originator
)) != 0)
907 { printf ("\n\nLine %d : originator mismatch :\n\twrite : '%s'\n\tread : '%s'\n\n", __LINE__
, bc_write
.originator
, bc_read
.originator
) ;
911 if (memcmp (bc_write
.originator_reference
, bc_read
.originator_reference
, sizeof (bc_write
.originator_reference
)) != 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
) ;
916 if (memcmp (bc_write
.origination_date
, bc_read
.origination_date
, sizeof (bc_write
.origination_date
)) != 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
) ;
921 if (memcmp (bc_write
.origination_time
, bc_read
.origination_time
, sizeof (bc_write
.origination_time
)) != 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
) ;
926 if (memcmp (bc_write
.umid
, bc_read
.umid
, sizeof (bc_write
.umid
)) != 0)
927 { printf ("\n\nLine %d : umid mismatch :\n\twrite : '%s'\n\tread : '%s'\n\n", __LINE__
, bc_write
.umid
, bc_read
.umid
) ;
936 } /* broadcast_test */
939 broadcast_rdwr_test (const char *filename
, int filetype
)
940 { SF_BROADCAST_INFO binfo
;
945 print_test_name (__func__
, filename
) ;
947 create_short_sndfile (filename
, filetype
, 2) ;
949 memset (&sfinfo
, 0, sizeof (sfinfo
)) ;
950 memset (&binfo
, 0, sizeof (binfo
)) ;
952 snprintf (binfo
.description
, sizeof (binfo
.description
), "Test description") ;
953 snprintf (binfo
.originator
, sizeof (binfo
.originator
), "Test originator") ;
954 snprintf (binfo
.originator_reference
, sizeof (binfo
.originator_reference
), "%08x-%08x", (unsigned int) time (NULL
), (unsigned int) (~ time (NULL
))) ;
955 snprintf (binfo
.origination_date
, sizeof (binfo
.origination_date
), "%d/%02d/%02d", 2006, 3, 30) ;
956 snprintf (binfo
.origination_time
, sizeof (binfo
.origination_time
), "%02d:%02d:%02d", 20, 27, 0) ;
957 snprintf (binfo
.umid
, sizeof (binfo
.umid
), "Some umid") ;
958 binfo
.coding_history_size
= 0 ;
960 file
= test_open_file_or_die (filename
, SFM_RDWR
, &sfinfo
, SF_TRUE
, __LINE__
) ;
961 frames
= sfinfo
.frames
;
962 if (sf_command (file
, SFC_SET_BROADCAST_INFO
, &binfo
, sizeof (binfo
)) != SF_FALSE
)
963 { printf ("\n\nLine %d : sf_command (SFC_SET_BROADCAST_INFO) should have failed but didn't.\n\n", __LINE__
) ;
968 file
= test_open_file_or_die (filename
, SFM_READ
, &sfinfo
, SF_TRUE
, __LINE__
) ;
970 exit_if_true (frames
!= sfinfo
.frames
, "\n\nLine %d : Frame count %lld should be %lld.\n", __LINE__
, sfinfo
.frames
, frames
) ;
974 } /* broadcast_rdwr_test */
977 check_coding_history_newlines (const char *filename
)
978 { static SF_BROADCAST_INFO bc_write
, bc_read
;
983 sfinfo
.samplerate
= 22050 ;
984 sfinfo
.format
= SF_FORMAT_WAV
| SF_FORMAT_PCM_16
;
985 sfinfo
.channels
= 1 ;
987 memset (&bc_write
, 0, sizeof (bc_write
)) ;
989 snprintf (bc_write
.description
, sizeof (bc_write
.description
), "Test description") ;
990 snprintf (bc_write
.originator
, sizeof (bc_write
.originator
), "Test originator") ;
991 snprintf (bc_write
.originator_reference
, sizeof (bc_write
.originator_reference
), "%08x-%08x", (unsigned int) time (NULL
), (unsigned int) (~ time (NULL
))) ;
992 snprintf (bc_write
.origination_date
, sizeof (bc_write
.origination_date
), "%d/%02d/%02d", 2006, 3, 30) ;
993 snprintf (bc_write
.origination_time
, sizeof (bc_write
.origination_time
), "%02d:%02d:%02d", 20, 27, 0) ;
994 snprintf (bc_write
.umid
, sizeof (bc_write
.umid
), "Some umid") ;
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") ; ;
997 file
= test_open_file_or_die (filename
, SFM_WRITE
, &sfinfo
, SF_TRUE
, __LINE__
) ;
998 if (sf_command (file
, SFC_SET_BROADCAST_INFO
, &bc_write
, sizeof (bc_write
)) == SF_FALSE
)
999 { printf ("\n\nLine %d : sf_command (SFC_SET_BROADCAST_INFO) failed.\n\n", __LINE__
) ;
1003 test_write_double_or_die (file
, 0, double_data
, BUFFER_LEN
, __LINE__
) ;
1006 memset (&bc_read
, 0, sizeof (bc_read
)) ;
1008 file
= test_open_file_or_die (filename
, SFM_READ
, &sfinfo
, SF_TRUE
, __LINE__
) ;
1009 if (sf_command (file
, SFC_GET_BROADCAST_INFO
, &bc_read
, sizeof (bc_read
)) == SF_FALSE
)
1010 { printf ("\n\nLine %d : sf_command (SFC_SET_BROADCAST_INFO) failed.\n\n", __LINE__
) ;
1013 check_log_buffer_or_die (file
, __LINE__
) ;
1016 if (bc_read
.coding_history_size
== 0)
1017 { printf ("\n\nLine %d : missing coding history.\n\n", __LINE__
) ;
1021 if (strstr (bc_read
.coding_history
, "Last line") == NULL
)
1022 { printf ("\n\nLine %d : coding history truncated.\n\n", __LINE__
) ;
1026 for (k
= 1 ; k
< bc_read
.coding_history_size
; k
++)
1027 { if (bc_read
.coding_history
[k
] == '\n' && bc_read
.coding_history
[k
- 1] != '\r')
1028 { printf ("\n\nLine %d : '\\n' without '\\r' before.\n\n", __LINE__
) ;
1032 if (bc_read
.coding_history
[k
] == '\r' && bc_read
.coding_history
[k
+ 1] != '\n')
1033 { printf ("\n\nLine %d : '\\r' without '\\n' after.\n\n", __LINE__
) ;
1037 if (bc_read
.coding_history
[k
] == 0 && k
< bc_read
.coding_history_size
- 1)
1038 { printf ("\n\nLine %d : '\\0' within coding history at index %d of %d.\n\n", __LINE__
, k
, bc_read
.coding_history_size
) ;
1044 } /* check_coding_history_newlines */
1047 broadcast_coding_history_test (const char *filename
)
1048 { static SF_BROADCAST_INFO bc_write
, bc_read
;
1051 const char *default_history
= "A=PCM,F=22050,W=16,M=mono" ;
1052 const char *supplied_history
=
1053 "A=PCM,F=44100,W=24,M=mono,T=other\r\n"
1054 "A=PCM,F=22050,W=16,M=mono,T=yet_another\r\n" ;
1056 print_test_name ("broadcast_coding_history_test", filename
) ;
1058 sfinfo
.samplerate
= 22050 ;
1059 sfinfo
.format
= SF_FORMAT_WAV
| SF_FORMAT_PCM_16
;
1060 sfinfo
.channels
= 1 ;
1062 memset (&bc_write
, 0, sizeof (bc_write
)) ;
1064 snprintf (bc_write
.description
, sizeof (bc_write
.description
), "Test description") ;
1065 snprintf (bc_write
.originator
, sizeof (bc_write
.originator
), "Test originator") ;
1066 snprintf (bc_write
.originator_reference
, sizeof (bc_write
.originator_reference
), "%08x-%08x", (unsigned int) time (NULL
), (unsigned int) (~ time (NULL
))) ;
1067 snprintf (bc_write
.origination_date
, sizeof (bc_write
.origination_date
), "%d/%02d/%02d", 2006, 3, 30) ;
1068 snprintf (bc_write
.origination_time
, sizeof (bc_write
.origination_time
), "%02d:%02d:%02d", 20, 27, 0) ;
1069 snprintf (bc_write
.umid
, sizeof (bc_write
.umid
), "Some umid") ;
1070 /* Coding history will be filled in by the library. */
1071 bc_write
.coding_history_size
= 0 ;
1073 file
= test_open_file_or_die (filename
, SFM_WRITE
, &sfinfo
, SF_TRUE
, __LINE__
) ;
1074 if (sf_command (file
, SFC_SET_BROADCAST_INFO
, &bc_write
, sizeof (bc_write
)) == SF_FALSE
)
1075 { printf ("\n\nLine %d : sf_command (SFC_SET_BROADCAST_INFO) failed.\n\n", __LINE__
) ;
1079 test_write_double_or_die (file
, 0, double_data
, BUFFER_LEN
, __LINE__
) ;
1082 memset (&bc_read
, 0, sizeof (bc_read
)) ;
1084 file
= test_open_file_or_die (filename
, SFM_READ
, &sfinfo
, SF_TRUE
, __LINE__
) ;
1085 if (sf_command (file
, SFC_GET_BROADCAST_INFO
, &bc_read
, sizeof (bc_read
)) == SF_FALSE
)
1086 { printf ("\n\nLine %d : sf_command (SFC_SET_BROADCAST_INFO) failed.\n\n", __LINE__
) ;
1089 check_log_buffer_or_die (file
, __LINE__
) ;
1092 if (bc_read
.coding_history_size
== 0)
1093 { printf ("\n\nLine %d : missing coding history.\n\n", __LINE__
) ;
1097 if (bc_read
.coding_history_size
< strlen (default_history
) || memcmp (bc_read
.coding_history
, default_history
, strlen (default_history
)) != 0)
1099 "Line %d : unexpected coding history '%.*s',\n"
1100 " should be '%s'\n\n", __LINE__
, bc_read
.coding_history_size
, bc_read
.coding_history
, default_history
) ;
1104 bc_write
.coding_history_size
= strlen (supplied_history
) ;
1105 bc_write
.coding_history_size
= snprintf (bc_write
.coding_history
, sizeof (bc_write
.coding_history
), "%s", supplied_history
) ;
1107 file
= test_open_file_or_die (filename
, SFM_WRITE
, &sfinfo
, SF_TRUE
, __LINE__
) ;
1108 if (sf_command (file
, SFC_SET_BROADCAST_INFO
, &bc_write
, sizeof (bc_write
)) == SF_FALSE
)
1109 { printf ("\n\nLine %d : sf_command (SFC_SET_BROADCAST_INFO) failed.\n\n", __LINE__
) ;
1113 test_write_double_or_die (file
, 0, double_data
, BUFFER_LEN
, __LINE__
) ;
1116 memset (&bc_read
, 0, sizeof (bc_read
)) ;
1118 file
= test_open_file_or_die (filename
, SFM_READ
, &sfinfo
, SF_TRUE
, __LINE__
) ;
1119 if (sf_command (file
, SFC_GET_BROADCAST_INFO
, &bc_read
, sizeof (bc_read
)) == SF_FALSE
)
1120 { printf ("\n\nLine %d : sf_command (SFC_SET_BROADCAST_INFO) failed.\n\n", __LINE__
) ;
1124 check_log_buffer_or_die (file
, __LINE__
) ;
1127 if (strstr (bc_read
.coding_history
, supplied_history
) != bc_read
.coding_history
)
1128 { printf ("\n\nLine %d : unexpected coding history :\n"
1129 "----------------------------------------------------\n%s"
1130 "----------------------------------------------------\n"
1131 "should be this :\n"
1132 "----------------------------------------------------\n%s"
1133 "----------------------------------------------------\n"
1134 "with one more line at the end.\n\n",
1135 __LINE__
, bc_read
.coding_history
, supplied_history
) ;
1139 check_coding_history_newlines (filename
) ;
1143 } /* broadcast_coding_history_test */
1145 /*==============================================================================
1149 broadcast_coding_history_size (const char *filename
)
1150 { /* SF_BROADCAST_INFO struct with coding_history field of 1024 bytes. */
1151 static SF_BROADCAST_INFO_VAR (1024) bc_write
;
1152 static SF_BROADCAST_INFO_VAR (1024) bc_read
;
1157 print_test_name (__func__
, filename
) ;
1159 sfinfo
.samplerate
= 22050 ;
1160 sfinfo
.format
= SF_FORMAT_WAV
| SF_FORMAT_PCM_16
;
1161 sfinfo
.channels
= 1 ;
1163 memset (&bc_write
, 0, sizeof (bc_write
)) ;
1165 snprintf (bc_write
.description
, sizeof (bc_write
.description
), "Test description") ;
1166 snprintf (bc_write
.originator
, sizeof (bc_write
.originator
), "Test originator") ;
1167 snprintf (bc_write
.originator_reference
, sizeof (bc_write
.originator_reference
), "%08x-%08x", (unsigned int) time (NULL
), (unsigned int) (~ time (NULL
))) ;
1168 snprintf (bc_write
.origination_date
, sizeof (bc_write
.origination_date
), "%d/%02d/%02d", 2006, 3, 30) ;
1169 snprintf (bc_write
.origination_time
, sizeof (bc_write
.origination_time
), "%02d:%02d:%02d", 20, 27, 0) ;
1170 snprintf (bc_write
.umid
, sizeof (bc_write
.umid
), "Some umid") ;
1171 bc_write
.coding_history_size
= 0 ;
1173 for (k
= 0 ; bc_write
.coding_history_size
< 512 ; k
++)
1174 { snprintf (bc_write
.coding_history
+ bc_write
.coding_history_size
,
1175 sizeof (bc_write
.coding_history
) - bc_write
.coding_history_size
, "line %4d\n", k
) ;
1176 bc_write
.coding_history_size
= strlen (bc_write
.coding_history
) ;
1179 exit_if_true (bc_write
.coding_history_size
< 512,
1180 "\n\nLine %d : bc_write.coding_history_size (%d) should be > 512.\n\n", __LINE__
, bc_write
.coding_history_size
) ;
1182 file
= test_open_file_or_die (filename
, SFM_WRITE
, &sfinfo
, SF_TRUE
, __LINE__
) ;
1183 if (sf_command (file
, SFC_SET_BROADCAST_INFO
, &bc_write
, sizeof (bc_write
)) == SF_FALSE
)
1184 { printf ("\n\nLine %d : sf_command (SFC_SET_BROADCAST_INFO) failed.\n\n", __LINE__
) ;
1188 test_write_double_or_die (file
, 0, double_data
, BUFFER_LEN
, __LINE__
) ;
1191 memset (&bc_read
, 0, sizeof (bc_read
)) ;
1193 file
= test_open_file_or_die (filename
, SFM_READ
, &sfinfo
, SF_TRUE
, __LINE__
) ;
1194 if (sf_command (file
, SFC_GET_BROADCAST_INFO
, &bc_read
, sizeof (bc_read
)) == SF_FALSE
)
1195 { printf ("\n\nLine %d : sf_command (SFC_SET_BROADCAST_INFO) failed.\n\n", __LINE__
) ;
1198 check_log_buffer_or_die (file
, __LINE__
) ;
1201 exit_if_true (bc_read
.coding_history_size
< 512,
1202 "\n\nLine %d : unexpected coding history size %d (should be > 512).\n\n", __LINE__
, bc_read
.coding_history_size
) ;
1204 exit_if_true (strstr (bc_read
.coding_history
, "libsndfile") == NULL
,
1205 "\n\nLine %d : coding history incomplete (should contain 'libsndfile').\n\n", __LINE__
) ;
1209 } /* broadcast_coding_history_size */
1211 /*==============================================================================
1215 channel_map_test (const char *filename
, int filetype
)
1218 int channel_map_read
[4], channel_map_write
[4] =
1219 { SF_CHANNEL_MAP_LEFT
, SF_CHANNEL_MAP_RIGHT
, SF_CHANNEL_MAP_LFE
,
1220 SF_CHANNEL_MAP_REAR_CENTER
1223 print_test_name ("channel_map_test", filename
) ;
1225 memset (&sfinfo
, 0, sizeof (sfinfo
)) ;
1226 sfinfo
.samplerate
= 11025 ;
1227 sfinfo
.format
= filetype
;
1228 sfinfo
.channels
= ARRAY_LEN (channel_map_read
) ;
1230 switch (filetype
& SF_FORMAT_TYPEMASK
)
1231 { /* WAVEX and RF64 have a default channel map, even if you don't specify one. */
1232 case SF_FORMAT_WAVEX
:
1233 case SF_FORMAT_RF64
:
1234 /* Write file without channel map. */
1235 file
= test_open_file_or_die (filename
, SFM_WRITE
, &sfinfo
, SF_TRUE
, __LINE__
) ;
1236 test_write_double_or_die (file
, 0, double_data
, BUFFER_LEN
, __LINE__
) ;
1239 /* Read file making default channel map exists. */
1240 file
= test_open_file_or_die (filename
, SFM_READ
, &sfinfo
, SF_TRUE
, __LINE__
) ;
1242 sf_command (file
, SFC_GET_CHANNEL_MAP_INFO
, channel_map_read
, sizeof (channel_map_read
)) == SF_FALSE
,
1243 "\n\nLine %d : sf_command (SFC_GET_CHANNEL_MAP_INFO) should not have failed.\n\n", __LINE__
1245 check_log_buffer_or_die (file
, __LINE__
) ;
1253 /* Write file with a channel map. */
1254 file
= test_open_file_or_die (filename
, SFM_WRITE
, &sfinfo
, SF_TRUE
, __LINE__
) ;
1256 sf_command (file
, SFC_SET_CHANNEL_MAP_INFO
, channel_map_write
, sizeof (channel_map_write
)) == SF_FALSE
,
1257 "\n\nLine %d : sf_command (SFC_SET_CHANNEL_MAP_INFO) failed.\n\n", __LINE__
1259 test_write_double_or_die (file
, 0, double_data
, BUFFER_LEN
, __LINE__
) ;
1262 /* Read file making sure no channel map exists. */
1263 file
= test_open_file_or_die (filename
, SFM_READ
, &sfinfo
, SF_TRUE
, __LINE__
) ;
1265 sf_command (file
, SFC_GET_CHANNEL_MAP_INFO
, channel_map_read
, sizeof (channel_map_read
)) != SF_TRUE
,
1266 "\n\nLine %d : sf_command (SFC_GET_CHANNEL_MAP_INFO) failed.\n\n", __LINE__
1268 check_log_buffer_or_die (file
, __LINE__
) ;
1272 memcmp (channel_map_read
, channel_map_write
, sizeof (channel_map_read
)) != 0,
1273 "\n\nLine %d : Channel map read does not match channel map written.\n\n", __LINE__
1278 } /* channel_map_test */
1281 raw_needs_endswap_test (const char *filename
, int filetype
)
1282 { static int subtypes
[] =
1283 { SF_FORMAT_FLOAT
, SF_FORMAT_DOUBLE
,
1284 SF_FORMAT_PCM_16
, SF_FORMAT_PCM_24
, SF_FORMAT_PCM_32
1291 print_test_name (__func__
, filename
) ;
1293 for (k
= 0 ; k
< ARRAY_LEN (subtypes
) ; k
++)
1295 if (filetype
== (SF_ENDIAN_LITTLE
| SF_FORMAT_AIFF
))
1296 switch (subtypes
[k
])
1297 { /* Little endian AIFF does not AFAIK support fl32 and fl64. */
1298 case SF_FORMAT_FLOAT
:
1299 case SF_FORMAT_DOUBLE
:
1305 memset (&sfinfo
, 0, sizeof (sfinfo
)) ;
1306 sfinfo
.samplerate
= 11025 ;
1307 sfinfo
.format
= filetype
| subtypes
[k
] ;
1308 sfinfo
.channels
= 1 ;
1310 file
= test_open_file_or_die (filename
, SFM_WRITE
, &sfinfo
, SF_TRUE
, __LINE__
) ;
1311 test_write_double_or_die (file
, 0, double_data
, BUFFER_LEN
, __LINE__
) ;
1314 memset (&sfinfo
, 0, sizeof (sfinfo
)) ;
1315 file
= test_open_file_or_die (filename
, SFM_READ
, &sfinfo
, SF_TRUE
, __LINE__
) ;
1317 needs_endswap
= sf_command (file
, SFC_RAW_DATA_NEEDS_ENDSWAP
, NULL
, 0) ;
1320 { case SF_FORMAT_WAV
:
1321 case SF_FORMAT_WAVEX
:
1322 case SF_FORMAT_AIFF
| SF_ENDIAN_LITTLE
:
1323 exit_if_true (needs_endswap
!= CPU_IS_BIG_ENDIAN
,
1324 "\n\nLine %d : SFC_RAW_DATA_NEEDS_ENDSWAP failed for (%d | %d).\n\n", __LINE__
, filetype
, k
) ;
1327 case SF_FORMAT_AIFF
:
1328 case SF_FORMAT_WAV
| SF_ENDIAN_BIG
:
1329 exit_if_true (needs_endswap
!= CPU_IS_LITTLE_ENDIAN
,
1330 "\n\nLine %d : SFC_RAW_DATA_NEEDS_ENDSWAP failed for (%d | %d).\n\n", __LINE__
, filetype
, k
) ;
1334 printf ("\n\nLine %d : bad format value %d.\n\n", __LINE__
, filetype
) ;
1344 } /* raw_needs_endswap_test */