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.
32 #if (HAVE_DECL_S_IRGRP == 0)
33 #include <sf_unistd.h>
36 #if (defined (WIN32) || defined (_WIN32))
45 #define BUFFER_LEN (1<<10)
46 #define LOG_BUFFER_SIZE 1024
48 static void update_header_test (const char *filename
, int typemajor
) ;
50 static void update_seek_short_test (const char *filename
, int filetype
) ;
51 static void update_seek_int_test (const char *filename
, int filetype
) ;
52 static void update_seek_float_test (const char *filename
, int filetype
) ;
53 static void update_seek_double_test (const char *filename
, int filetype
) ;
56 static void extra_header_test (const char *filename
, int filetype
) ;
58 static void header_shrink_test (const char *filename
, int filetype
) ;
60 /* Force the start of this buffer to be double aligned. Sparc-solaris will
63 static int data_out
[BUFFER_LEN
] ;
64 static int data_in
[BUFFER_LEN
] ;
67 main (int argc
, char *argv
[])
72 { printf ("Usage : %s <test>\n", argv
[0]) ;
73 printf (" Where <test> is one of the following:\n") ;
74 printf (" wav - test WAV file peak chunk\n") ;
75 printf (" aiff - test AIFF file PEAK chunk\n") ;
76 printf (" all - perform all tests\n") ;
80 do_all
=!strcmp (argv
[1], "all") ;
82 if (do_all
|| ! strcmp (argv
[1], "wav"))
83 { update_header_test ("header.wav", SF_FORMAT_WAV
) ;
84 update_seek_short_test ("header_short.wav", SF_FORMAT_WAV
) ;
85 update_seek_int_test ("header_int.wav", SF_FORMAT_WAV
) ;
86 update_seek_float_test ("header_float.wav", SF_FORMAT_WAV
) ;
87 update_seek_double_test ("header_double.wav", SF_FORMAT_WAV
) ;
88 header_shrink_test ("header_shrink.wav", SF_FORMAT_WAV
) ;
89 extra_header_test ("extra.wav", SF_FORMAT_WAV
) ;
91 update_header_test ("header.wavex", SF_FORMAT_WAVEX
) ;
92 update_seek_short_test ("header_short.wavex", SF_FORMAT_WAVEX
) ;
93 update_seek_int_test ("header_int.wavex", SF_FORMAT_WAVEX
) ;
94 update_seek_float_test ("header_float.wavex", SF_FORMAT_WAVEX
) ;
95 update_seek_double_test ("header_double.wavex", SF_FORMAT_WAVEX
) ;
96 header_shrink_test ("header_shrink.wavex", SF_FORMAT_WAVEX
) ;
97 extra_header_test ("extra.wavex", SF_FORMAT_WAVEX
) ;
101 if (do_all
|| ! strcmp (argv
[1], "aiff"))
102 { update_header_test ("header.aiff", SF_FORMAT_AIFF
) ;
103 update_seek_short_test ("header_short.aiff", SF_FORMAT_AIFF
) ;
104 update_seek_int_test ("header_int.aiff", SF_FORMAT_AIFF
) ;
105 update_seek_float_test ("header_float.aiff", SF_FORMAT_AIFF
) ;
106 update_seek_double_test ("header_double.aiff", SF_FORMAT_AIFF
) ;
107 header_shrink_test ("header_shrink.wav", SF_FORMAT_AIFF
) ;
108 extra_header_test ("extra.aiff", SF_FORMAT_AIFF
) ;
112 if (do_all
|| ! strcmp (argv
[1], "au"))
113 { update_header_test ("header.au", SF_FORMAT_AU
) ;
114 update_seek_short_test ("header_short.au", SF_FORMAT_AU
) ;
115 update_seek_int_test ("header_int.au", SF_FORMAT_AU
) ;
116 update_seek_float_test ("header_float.au", SF_FORMAT_AU
) ;
117 update_seek_double_test ("header_double.au", SF_FORMAT_AU
) ;
121 if (do_all
|| ! strcmp (argv
[1], "caf"))
122 { update_header_test ("header.caf", SF_FORMAT_CAF
) ;
123 update_seek_short_test ("header_short.caf", SF_FORMAT_CAF
) ;
124 update_seek_int_test ("header_int.caf", SF_FORMAT_CAF
) ;
125 update_seek_float_test ("header_float.caf", SF_FORMAT_CAF
) ;
126 update_seek_double_test ("header_double.caf", SF_FORMAT_CAF
) ;
127 /* extra_header_test ("extra.caf", SF_FORMAT_CAF) ; */
131 if (do_all
|| ! strcmp (argv
[1], "nist"))
132 { update_header_test ("header.nist", SF_FORMAT_NIST
) ;
133 update_seek_short_test ("header_short.nist", SF_FORMAT_NIST
) ;
134 update_seek_int_test ("header_int.nist", SF_FORMAT_NIST
) ;
138 if (do_all
|| ! strcmp (argv
[1], "paf"))
139 { update_header_test ("header.paf", SF_FORMAT_PAF
) ;
140 update_seek_short_test ("header_short.paf", SF_FORMAT_PAF
) ;
144 if (do_all
|| ! strcmp (argv
[1], "ircam"))
145 { update_header_test ("header.ircam", SF_FORMAT_IRCAM
) ;
146 update_seek_short_test ("header_short.ircam", SF_FORMAT_IRCAM
) ;
150 if (do_all
|| ! strcmp (argv
[1], "w64"))
151 { update_header_test ("header.w64", SF_FORMAT_W64
) ;
152 update_seek_short_test ("header_short.w64", SF_FORMAT_W64
) ;
153 update_seek_int_test ("header_int.w64", SF_FORMAT_W64
) ;
154 update_seek_float_test ("header_float.w64", SF_FORMAT_W64
) ;
155 update_seek_double_test ("header_double.w64", SF_FORMAT_W64
) ;
159 if (do_all
|| ! strcmp (argv
[1], "rf64"))
160 { update_header_test ("header.rf64", SF_FORMAT_RF64
) ;
161 update_seek_short_test ("header_short.rf64", SF_FORMAT_RF64
) ;
162 update_seek_int_test ("header_int.rf64", SF_FORMAT_RF64
) ;
163 update_seek_float_test ("header_float.rf64", SF_FORMAT_RF64
) ;
164 update_seek_double_test ("header_double.rf64", SF_FORMAT_RF64
) ;
168 if (do_all
|| ! strcmp (argv
[1], "mat4"))
169 { update_header_test ("header.mat4", SF_FORMAT_MAT4
) ;
170 update_seek_short_test ("header_short.mat4", SF_FORMAT_MAT4
) ;
171 update_seek_int_test ("header_int.mat4", SF_FORMAT_MAT4
) ;
172 update_seek_float_test ("header_float.mat4", SF_FORMAT_MAT4
) ;
173 update_seek_double_test ("header_double.mat4", SF_FORMAT_MAT4
) ;
177 if (do_all
|| ! strcmp (argv
[1], "mat5"))
178 { update_header_test ("header.mat5", SF_FORMAT_MAT5
) ;
179 update_seek_short_test ("header_short.mat5", SF_FORMAT_MAT5
) ;
180 update_seek_int_test ("header_int.mat5", SF_FORMAT_MAT5
) ;
181 update_seek_float_test ("header_float.mat5", SF_FORMAT_MAT5
) ;
182 update_seek_double_test ("header_double.mat5", SF_FORMAT_MAT5
) ;
186 if (do_all
|| ! strcmp (argv
[1], "pvf"))
187 { update_header_test ("header.pvf", SF_FORMAT_PVF
) ;
188 update_seek_short_test ("header_short.pvf", SF_FORMAT_PVF
) ;
192 if (do_all
|| ! strcmp (argv
[1], "avr"))
193 { update_header_test ("header.avr", SF_FORMAT_AVR
) ;
194 update_seek_short_test ("header_short.avr", SF_FORMAT_AVR
) ;
198 if (do_all
|| ! strcmp (argv
[1], "htk"))
199 { update_header_test ("header.htk", SF_FORMAT_HTK
) ;
200 update_seek_short_test ("header_short.htk", SF_FORMAT_HTK
) ;
204 if (do_all
|| ! strcmp (argv
[1], "svx"))
205 { update_header_test ("header.svx", SF_FORMAT_SVX
) ;
206 update_seek_short_test ("header_short.svx", SF_FORMAT_SVX
) ;
210 if (do_all
|| ! strcmp (argv
[1], "voc"))
211 { update_header_test ("header.voc", SF_FORMAT_VOC
) ;
212 /*-update_seek_short_test ("header_short.voc", SF_FORMAT_VOC) ;-*/
216 if (do_all
|| ! strcmp (argv
[1], "sds"))
217 { update_header_test ("header.sds", SF_FORMAT_SDS
) ;
218 /*-update_seek_short_test ("header_short.sds", SF_FORMAT_SDS) ;-*/
222 if (do_all
|| ! strcmp (argv
[1], "mpc2k"))
223 { update_header_test ("header.mpc", SF_FORMAT_MPC2K
) ;
224 update_seek_short_test ("header_short.mpc", SF_FORMAT_MPC2K
) ;
229 { printf ("Mono : ************************************\n") ;
230 printf ("Mono : * No '%s' test defined.\n", argv
[1]) ;
231 printf ("Mono : ************************************\n") ;
239 /*============================================================================================
240 ** Here are the test functions.
244 update_header_sub (const char *filename
, int typemajor
, int write_mode
)
245 { SNDFILE
*outfile
, *infile
;
249 sfinfo
.samplerate
= 44100 ;
250 sfinfo
.format
= (typemajor
| SF_FORMAT_PCM_16
) ;
251 sfinfo
.channels
= 1 ;
254 outfile
= test_open_file_or_die (filename
, write_mode
, &sfinfo
, SF_TRUE
, __LINE__
) ;
256 for (k
= 0 ; k
< BUFFER_LEN
; k
++)
257 data_out
[k
] = k
+ 1 ;
258 test_write_int_or_die (outfile
, 0, data_out
, BUFFER_LEN
, __LINE__
) ;
260 if (typemajor
!= SF_FORMAT_HTK
)
261 { /* The HTK header is not correct when the file is first written. */
262 infile
= test_open_file_or_die (filename
, SFM_READ
, &sfinfo
, SF_TRUE
, __LINE__
) ;
266 sf_command (outfile
, SFC_UPDATE_HEADER_NOW
, NULL
, 0) ;
269 ** Open file and check log buffer for an error. If header update failed
270 ** the the log buffer will contain errors.
272 infile
= test_open_file_or_die (filename
, SFM_READ
, &sfinfo
, SF_TRUE
, __LINE__
) ;
273 check_log_buffer_or_die (infile
, __LINE__
) ;
275 if (sfinfo
.frames
< BUFFER_LEN
|| sfinfo
.frames
> BUFFER_LEN
+ 50)
276 { printf ("\n\nLine %d : Incorrect sample count (%ld should be %d)\n", __LINE__
, SF_COUNT_TO_LONG (sfinfo
.frames
), BUFFER_LEN
) ;
277 dump_log_buffer (infile
) ;
281 test_read_int_or_die (infile
, 0, data_in
, BUFFER_LEN
, __LINE__
) ;
282 for (k
= 0 ; k
< BUFFER_LEN
; k
++)
283 if (data_out
[k
] != k
+ 1)
284 printf ("Error : line %d\n", __LINE__
) ;
288 /* Set auto update on. */
289 sf_command (outfile
, SFC_SET_UPDATE_HEADER_AUTO
, NULL
, SF_TRUE
) ;
291 /* Write more data_out. */
292 for (k
= 0 ; k
< BUFFER_LEN
; k
++)
293 data_out
[k
] = k
+ 2 ;
294 test_write_int_or_die (outfile
, 0, data_out
, BUFFER_LEN
, __LINE__
) ;
296 /* Open file again and make sure no errors in log buffer. */
297 infile
= test_open_file_or_die (filename
, SFM_READ
, &sfinfo
, SF_TRUE
, __LINE__
) ;
298 check_log_buffer_or_die (infile
, __LINE__
) ;
300 if (sfinfo
.frames
< 2 * BUFFER_LEN
|| sfinfo
.frames
> 2 * BUFFER_LEN
+ 50)
301 { printf ("\n\nLine %d : Incorrect sample count (%ld should be %d)\n", __LINE__
, SF_COUNT_TO_LONG (sfinfo
.frames
), 2 * BUFFER_LEN
) ;
302 dump_log_buffer (infile
) ;
311 } /* update_header_sub */
314 update_header_test (const char *filename
, int typemajor
)
316 print_test_name ("update_header_test", filename
) ;
318 update_header_sub (filename
, typemajor
, SFM_WRITE
) ;
319 update_header_sub (filename
, typemajor
, SFM_RDWR
) ;
323 } /* update_header_test */
325 /*==============================================================================
329 update_seek_short_test (const char *filename
, int filetype
)
330 { SNDFILE
*outfile
, *infile
;
336 print_test_name ("update_seek_short_test", filename
) ;
338 memset (buffer
, 0, sizeof (buffer
)) ;
340 /* Create sound outfile with no data. */
341 sfinfo
.format
= filetype
| SF_FORMAT_PCM_16
;
342 sfinfo
.samplerate
= 48000 ;
343 sfinfo
.channels
= 2 ;
345 if (sf_format_check (&sfinfo
) == SF_FALSE
)
346 sfinfo
.channels
= 1 ;
348 outfile
= test_open_file_or_die (filename
, SFM_WRITE
, &sfinfo
, SF_TRUE
, __LINE__
) ;
351 /* Open again for read/write. */
352 outfile
= test_open_file_or_die (filename
, SFM_RDWR
, &sfinfo
, SF_TRUE
, __LINE__
) ;
355 ** In auto header update mode, seeking to the end of the file with
356 ** SEEK_SET will fail from the 2nd seek on. seeking to 0, SEEK_END
357 ** will seek to 0 anyway
359 if (sf_command (outfile
, SFC_SET_UPDATE_HEADER_AUTO
, NULL
, SF_TRUE
) == 0)
360 { printf ("\n\nError : sf_command (SFC_SET_UPDATE_HEADER_AUTO) return error : %s\n\n", sf_strerror (outfile
)) ;
364 /* Now write some frames. */
365 frames
= ARRAY_LEN (buffer
) / sfinfo
.channels
;
367 for (k
= 0 ; k
< 6 ; k
++)
368 { test_seek_or_die (outfile
, k
* frames
, SEEK_SET
, k
* frames
, sfinfo
.channels
, __LINE__
) ;
369 test_seek_or_die (outfile
, 0, SEEK_END
, k
* frames
, sfinfo
.channels
, __LINE__
) ;
371 /* Open file again and make sure no errors in log buffer. */
372 infile
= test_open_file_or_die (filename
, SFM_READ
, &sfinfo
, SF_TRUE
, __LINE__
) ;
373 check_log_buffer_or_die (infile
, __LINE__
) ;
376 if (sfinfo
.frames
!= k
* frames
)
377 { printf ("\n\nLine %d : Incorrect sample count (%ld should be %ld)\n", __LINE__
, SF_COUNT_TO_LONG (sfinfo
.frames
), SF_COUNT_TO_LONG (k
+ frames
)) ;
378 dump_log_buffer (infile
) ;
383 test_write_short_or_die (outfile
, k
, buffer
, sfinfo
.channels
* frames
, __LINE__
) ;
385 test_writef_short_or_die (outfile
, k
, buffer
, frames
, __LINE__
) ;
393 } /* update_seek_short_test */
396 update_seek_int_test (const char *filename
, int filetype
)
397 { SNDFILE
*outfile
, *infile
;
403 print_test_name ("update_seek_int_test", filename
) ;
405 memset (buffer
, 0, sizeof (buffer
)) ;
407 /* Create sound outfile with no data. */
408 sfinfo
.format
= filetype
| SF_FORMAT_PCM_32
;
409 sfinfo
.samplerate
= 48000 ;
410 sfinfo
.channels
= 2 ;
412 if (sf_format_check (&sfinfo
) == SF_FALSE
)
413 sfinfo
.channels
= 1 ;
415 outfile
= test_open_file_or_die (filename
, SFM_WRITE
, &sfinfo
, SF_TRUE
, __LINE__
) ;
418 /* Open again for read/write. */
419 outfile
= test_open_file_or_die (filename
, SFM_RDWR
, &sfinfo
, SF_TRUE
, __LINE__
) ;
422 ** In auto header update mode, seeking to the end of the file with
423 ** SEEK_SET will fail from the 2nd seek on. seeking to 0, SEEK_END
424 ** will seek to 0 anyway
426 if (sf_command (outfile
, SFC_SET_UPDATE_HEADER_AUTO
, NULL
, SF_TRUE
) == 0)
427 { printf ("\n\nError : sf_command (SFC_SET_UPDATE_HEADER_AUTO) return error : %s\n\n", sf_strerror (outfile
)) ;
431 /* Now write some frames. */
432 frames
= ARRAY_LEN (buffer
) / sfinfo
.channels
;
434 for (k
= 0 ; k
< 6 ; k
++)
435 { test_seek_or_die (outfile
, k
* frames
, SEEK_SET
, k
* frames
, sfinfo
.channels
, __LINE__
) ;
436 test_seek_or_die (outfile
, 0, SEEK_END
, k
* frames
, sfinfo
.channels
, __LINE__
) ;
438 /* Open file again and make sure no errors in log buffer. */
439 infile
= test_open_file_or_die (filename
, SFM_READ
, &sfinfo
, SF_TRUE
, __LINE__
) ;
440 check_log_buffer_or_die (infile
, __LINE__
) ;
443 if (sfinfo
.frames
!= k
* frames
)
444 { printf ("\n\nLine %d : Incorrect sample count (%ld should be %ld)\n", __LINE__
, SF_COUNT_TO_LONG (sfinfo
.frames
), SF_COUNT_TO_LONG (k
+ frames
)) ;
445 dump_log_buffer (infile
) ;
450 test_write_int_or_die (outfile
, k
, buffer
, sfinfo
.channels
* frames
, __LINE__
) ;
452 test_writef_int_or_die (outfile
, k
, buffer
, frames
, __LINE__
) ;
460 } /* update_seek_int_test */
463 update_seek_float_test (const char *filename
, int filetype
)
464 { SNDFILE
*outfile
, *infile
;
470 print_test_name ("update_seek_float_test", filename
) ;
472 memset (buffer
, 0, sizeof (buffer
)) ;
474 /* Create sound outfile with no data. */
475 sfinfo
.format
= filetype
| SF_FORMAT_FLOAT
;
476 sfinfo
.samplerate
= 48000 ;
477 sfinfo
.channels
= 2 ;
479 if (sf_format_check (&sfinfo
) == SF_FALSE
)
480 sfinfo
.channels
= 1 ;
482 outfile
= test_open_file_or_die (filename
, SFM_WRITE
, &sfinfo
, SF_TRUE
, __LINE__
) ;
485 /* Open again for read/write. */
486 outfile
= test_open_file_or_die (filename
, SFM_RDWR
, &sfinfo
, SF_TRUE
, __LINE__
) ;
489 ** In auto header update mode, seeking to the end of the file with
490 ** SEEK_SET will fail from the 2nd seek on. seeking to 0, SEEK_END
491 ** will seek to 0 anyway
493 if (sf_command (outfile
, SFC_SET_UPDATE_HEADER_AUTO
, NULL
, SF_TRUE
) == 0)
494 { printf ("\n\nError : sf_command (SFC_SET_UPDATE_HEADER_AUTO) return error : %s\n\n", sf_strerror (outfile
)) ;
498 /* Now write some frames. */
499 frames
= ARRAY_LEN (buffer
) / sfinfo
.channels
;
501 for (k
= 0 ; k
< 6 ; k
++)
502 { test_seek_or_die (outfile
, k
* frames
, SEEK_SET
, k
* frames
, sfinfo
.channels
, __LINE__
) ;
503 test_seek_or_die (outfile
, 0, SEEK_END
, k
* frames
, sfinfo
.channels
, __LINE__
) ;
505 /* Open file again and make sure no errors in log buffer. */
506 infile
= test_open_file_or_die (filename
, SFM_READ
, &sfinfo
, SF_TRUE
, __LINE__
) ;
507 check_log_buffer_or_die (infile
, __LINE__
) ;
510 if (sfinfo
.frames
!= k
* frames
)
511 { printf ("\n\nLine %d : Incorrect sample count (%ld should be %ld)\n", __LINE__
, SF_COUNT_TO_LONG (sfinfo
.frames
), SF_COUNT_TO_LONG (k
+ frames
)) ;
512 dump_log_buffer (infile
) ;
517 test_write_float_or_die (outfile
, k
, buffer
, sfinfo
.channels
* frames
, __LINE__
) ;
519 test_writef_float_or_die (outfile
, k
, buffer
, frames
, __LINE__
) ;
527 } /* update_seek_float_test */
530 update_seek_double_test (const char *filename
, int filetype
)
531 { SNDFILE
*outfile
, *infile
;
537 print_test_name ("update_seek_double_test", filename
) ;
539 memset (buffer
, 0, sizeof (buffer
)) ;
541 /* Create sound outfile with no data. */
542 sfinfo
.format
= filetype
| SF_FORMAT_DOUBLE
;
543 sfinfo
.samplerate
= 48000 ;
544 sfinfo
.channels
= 2 ;
546 if (sf_format_check (&sfinfo
) == SF_FALSE
)
547 sfinfo
.channels
= 1 ;
549 outfile
= test_open_file_or_die (filename
, SFM_WRITE
, &sfinfo
, SF_TRUE
, __LINE__
) ;
552 /* Open again for read/write. */
553 outfile
= test_open_file_or_die (filename
, SFM_RDWR
, &sfinfo
, SF_TRUE
, __LINE__
) ;
556 ** In auto header update mode, seeking to the end of the file with
557 ** SEEK_SET will fail from the 2nd seek on. seeking to 0, SEEK_END
558 ** will seek to 0 anyway
560 if (sf_command (outfile
, SFC_SET_UPDATE_HEADER_AUTO
, NULL
, SF_TRUE
) == 0)
561 { printf ("\n\nError : sf_command (SFC_SET_UPDATE_HEADER_AUTO) return error : %s\n\n", sf_strerror (outfile
)) ;
565 /* Now write some frames. */
566 frames
= ARRAY_LEN (buffer
) / sfinfo
.channels
;
568 for (k
= 0 ; k
< 6 ; k
++)
569 { test_seek_or_die (outfile
, k
* frames
, SEEK_SET
, k
* frames
, sfinfo
.channels
, __LINE__
) ;
570 test_seek_or_die (outfile
, 0, SEEK_END
, k
* frames
, sfinfo
.channels
, __LINE__
) ;
572 /* Open file again and make sure no errors in log buffer. */
573 infile
= test_open_file_or_die (filename
, SFM_READ
, &sfinfo
, SF_TRUE
, __LINE__
) ;
574 check_log_buffer_or_die (infile
, __LINE__
) ;
577 if (sfinfo
.frames
!= k
* frames
)
578 { printf ("\n\nLine %d : Incorrect sample count (%ld should be %ld)\n", __LINE__
, SF_COUNT_TO_LONG (sfinfo
.frames
), SF_COUNT_TO_LONG (k
+ frames
)) ;
579 dump_log_buffer (infile
) ;
584 test_write_double_or_die (outfile
, k
, buffer
, sfinfo
.channels
* frames
, __LINE__
) ;
586 test_writef_double_or_die (outfile
, k
, buffer
, frames
, __LINE__
) ;
594 } /* update_seek_double_test */
599 header_shrink_test (const char *filename
, int filetype
)
600 { SNDFILE
*outfile
, *infile
;
603 float buffer
[8], bufferin
[8] ;
605 print_test_name ("header_shrink_test", filename
) ;
607 memset (&sfinfo
, 0, sizeof (sfinfo
)) ;
608 sfinfo
.samplerate
= 44100 ;
609 sfinfo
.format
= filetype
| SF_FORMAT_FLOAT
;
610 sfinfo
.channels
= 1 ;
612 memset (buffer
, 0xA0, sizeof (buffer
)) ;
614 /* Now write some frames. */
615 frames
= ARRAY_LEN (buffer
) / sfinfo
.channels
;
617 /* Test the file with extra header data. */
618 outfile
= test_open_file_or_die (filename
, SFM_WRITE
, &sfinfo
, SF_FALSE
, __LINE__
) ;
620 sf_command (outfile
, SFC_SET_ADD_PEAK_CHUNK
, NULL
, SF_TRUE
) ;
621 sf_command (outfile
, SFC_UPDATE_HEADER_NOW
, NULL
, SF_FALSE
) ;
622 sf_command (outfile
, SFC_SET_ADD_PEAK_CHUNK
, NULL
, SF_FALSE
) ;
624 test_writef_float_or_die (outfile
, 0, buffer
, frames
, __LINE__
) ;
627 /* Open again for read. */
628 infile
= test_open_file_or_die (filename
, SFM_READ
, &sfinfo
, SF_FALSE
, __LINE__
) ;
630 test_readf_float_or_die (infile
, 0, bufferin
, frames
, __LINE__
) ;
633 compare_float_or_die (buffer
, bufferin
, frames
, __LINE__
) ;
638 } /* header_shrink_test */
642 extra_header_test (const char *filename
, int filetype
)
643 { SNDFILE
*outfile
, *infile
;
649 print_test_name ("extra_header_test", filename
) ;
651 sfinfo
.samplerate
= 44100 ;
652 sfinfo
.format
= (filetype
| SF_FORMAT_PCM_16
) ;
653 sfinfo
.channels
= 1 ;
655 memset (buffer
, 0xA0, sizeof (buffer
)) ;
657 /* Now write some frames. */
658 frames
= ARRAY_LEN (buffer
) / sfinfo
.channels
;
660 /* Test the file with extra header data. */
661 outfile
= test_open_file_or_die (filename
, SFM_WRITE
, &sfinfo
, SF_TRUE
, 462) ;
662 sf_set_string (outfile
, SF_STR_TITLE
, filename
) ;
663 test_writef_short_or_die (outfile
, k
, buffer
, frames
, 464) ;
664 sf_set_string (outfile
, SF_STR_COPYRIGHT
, "(c) 1980 Erik") ;
669 ** Erik de Castro Lopo <erikd@mega-nerd.com> May 23 2004.
671 ** This file has extra string data in the header and therefore cannot
672 ** currently be opened in SFM_RDWR mode. This is fixable, but its in
673 ** a part of the code I don't want to fiddle with until the Ogg/Vorbis
674 ** integration is done.
677 if ((infile
= sf_open (filename
, SFM_RDWR
, &sfinfo
)) != NULL
)
678 { printf ("\n\nError : should not be able to open this file in SFM_RDWR.\n\n") ;
687 hexdump_file (filename
, 0, 100000) ;
689 /* Open again for read/write. */
690 outfile
= test_open_file_or_die (filename
, SFM_RDWR
, &sfinfo
, 491) ;
693 ** In auto header update mode, seeking to the end of the file with
694 ** SEEK_SET will fail from the 2nd seek on. seeking to 0, SEEK_END
695 ** will seek to 0 anyway
697 if (sf_command (outfile
, SFC_SET_UPDATE_HEADER_AUTO
, NULL
, SF_TRUE
) == 0)
698 { printf ("\n\nError : sf_command (SFC_SET_UPDATE_HEADER_AUTO) return error : %s\n\n", sf_strerror (outfile
)) ;
702 /* Now write some frames. */
703 frames
= ARRAY_LEN (buffer
) / sfinfo
.channels
;
705 for (k
= 1 ; k
< 6 ; k
++)
707 printf ("\n*** pass %d\n", k
) ;
708 memset (buffer
, 0xA0 + k
, sizeof (buffer
)) ;
711 test_seek_or_die (outfile
, k
* frames
, SEEK_SET
, k
* frames
, sfinfo
.channels
, 512) ;
712 test_seek_or_die (outfile
, 0, SEEK_END
, k
* frames
, sfinfo
.channels
, 513) ;
714 /* Open file again and make sure no errors in log buffer. */
716 { infile
= test_open_file_or_die (filename
, SFM_READ
, &sfinfo
, 517) ;
717 check_log_buffer_or_die (infile
, 518) ;
721 if (sfinfo
.frames
!= k
* frames
)
722 { printf ("\n\nLine %d : Incorrect sample count (%ld should be %ld)\n", 523, SF_COUNT_TO_LONG (sfinfo
.frames
), SF_COUNT_TO_LONG (k
+ frames
)) ;
723 dump_log_buffer (infile
) ;
728 test_write_short_or_die (outfile
, k
, buffer
, sfinfo
.channels
* frames
, 529) ;
730 test_writef_short_or_die (outfile
, k
, buffer
, frames
, 531) ;
731 hexdump_file (filename
, 0, 100000) ;
740 } /* extra_header_test */