annotate src/libsndfile-1.0.27/tests/header_test.tpl @ 148:b4bfdf10c4b3

Update Win64 capnp builds to v0.6
author Chris Cannam <cannam@all-day-breakfast.com>
date Mon, 22 May 2017 18:56:49 +0100
parents cd6cdf86811e
children
rev   line source
cannam@125 1 [+ AutoGen5 template c +]
cannam@125 2 /*
cannam@125 3 ** Copyright (C) 2001-2012 Erik de Castro Lopo <erikd@mega-nerd.com>
cannam@125 4 **
cannam@125 5 ** This program is free software ; you can redistribute it and/or modify
cannam@125 6 ** it under the terms of the GNU General Public License as published by
cannam@125 7 ** the Free Software Foundation ; either version 2 of the License, or
cannam@125 8 ** (at your option) any later version.
cannam@125 9 **
cannam@125 10 ** This program is distributed in the hope that it will be useful,
cannam@125 11 ** but WITHOUT ANY WARRANTY ; without even the implied warranty of
cannam@125 12 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
cannam@125 13 ** GNU General Public License for more details.
cannam@125 14 **
cannam@125 15 ** You should have received a copy of the GNU General Public License
cannam@125 16 ** along with this program ; if not, write to the Free Software
cannam@125 17 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
cannam@125 18 */
cannam@125 19
cannam@125 20 #include "sfconfig.h"
cannam@125 21
cannam@125 22 #include <stdio.h>
cannam@125 23 #include <stdlib.h>
cannam@125 24 #include <string.h>
cannam@125 25 #include <inttypes.h>
cannam@125 26 #include <math.h>
cannam@125 27
cannam@125 28 #include <sys/stat.h>
cannam@125 29
cannam@125 30 #if HAVE_UNISTD_H
cannam@125 31 #include <unistd.h>
cannam@125 32 #endif
cannam@125 33
cannam@125 34 #if (HAVE_DECL_S_IRGRP == 0)
cannam@125 35 #include <sf_unistd.h>
cannam@125 36 #endif
cannam@125 37
cannam@125 38 #if (defined (WIN32) || defined (_WIN32))
cannam@125 39 #include <io.h>
cannam@125 40 #include <direct.h>
cannam@125 41 #endif
cannam@125 42
cannam@125 43 #include <sndfile.h>
cannam@125 44
cannam@125 45 #include "utils.h"
cannam@125 46
cannam@125 47 #define BUFFER_LEN (1 << 10)
cannam@125 48 #define LOG_BUFFER_SIZE 1024
cannam@125 49
cannam@125 50 static void update_header_test (const char *filename, int typemajor) ;
cannam@125 51
cannam@125 52 [+ FOR data_type
cannam@125 53 +]static void update_seek_[+ (get "name") +]_test (const char *filename, int filetype) ;
cannam@125 54 [+ ENDFOR data_type
cannam@125 55 +]
cannam@125 56
cannam@125 57 static void extra_header_test (const char *filename, int filetype) ;
cannam@125 58
cannam@125 59 static void header_shrink_test (const char *filename, int filetype) ;
cannam@125 60
cannam@125 61 /* Force the start of this buffer to be double aligned. Sparc-solaris will
cannam@125 62 ** choke if its not.
cannam@125 63 */
cannam@125 64 static int data_out [BUFFER_LEN] ;
cannam@125 65 static int data_in [BUFFER_LEN] ;
cannam@125 66
cannam@125 67 int
cannam@125 68 main (int argc, char *argv [])
cannam@125 69 { int do_all = 0 ;
cannam@125 70 int test_count = 0 ;
cannam@125 71
cannam@125 72 if (argc != 2)
cannam@125 73 { printf ("Usage : %s <test>\n", argv [0]) ;
cannam@125 74 printf (" Where <test> is one of the following:\n") ;
cannam@125 75 printf (" wav - test WAV file peak chunk\n") ;
cannam@125 76 printf (" aiff - test AIFF file PEAK chunk\n") ;
cannam@125 77 printf (" all - perform all tests\n") ;
cannam@125 78 exit (1) ;
cannam@125 79 } ;
cannam@125 80
cannam@125 81 do_all= !strcmp (argv [1], "all") ;
cannam@125 82
cannam@125 83 if (do_all || ! strcmp (argv [1], "wav"))
cannam@125 84 { update_header_test ("header.wav", SF_FORMAT_WAV) ;
cannam@125 85 update_seek_short_test ("header_short.wav", SF_FORMAT_WAV) ;
cannam@125 86 update_seek_int_test ("header_int.wav", SF_FORMAT_WAV) ;
cannam@125 87 update_seek_float_test ("header_float.wav", SF_FORMAT_WAV) ;
cannam@125 88 update_seek_double_test ("header_double.wav", SF_FORMAT_WAV) ;
cannam@125 89 header_shrink_test ("header_shrink.wav", SF_FORMAT_WAV) ;
cannam@125 90 extra_header_test ("extra.wav", SF_FORMAT_WAV) ;
cannam@125 91
cannam@125 92 update_header_test ("header.wavex", SF_FORMAT_WAVEX) ;
cannam@125 93 update_seek_short_test ("header_short.wavex", SF_FORMAT_WAVEX) ;
cannam@125 94 update_seek_int_test ("header_int.wavex", SF_FORMAT_WAVEX) ;
cannam@125 95 update_seek_float_test ("header_float.wavex", SF_FORMAT_WAVEX) ;
cannam@125 96 update_seek_double_test ("header_double.wavex", SF_FORMAT_WAVEX) ;
cannam@125 97 header_shrink_test ("header_shrink.wavex", SF_FORMAT_WAVEX) ;
cannam@125 98 extra_header_test ("extra.wavex", SF_FORMAT_WAVEX) ;
cannam@125 99 test_count++ ;
cannam@125 100 } ;
cannam@125 101
cannam@125 102 if (do_all || ! strcmp (argv [1], "aiff"))
cannam@125 103 { update_header_test ("header.aiff", SF_FORMAT_AIFF) ;
cannam@125 104 update_seek_short_test ("header_short.aiff", SF_FORMAT_AIFF) ;
cannam@125 105 update_seek_int_test ("header_int.aiff", SF_FORMAT_AIFF) ;
cannam@125 106 update_seek_float_test ("header_float.aiff", SF_FORMAT_AIFF) ;
cannam@125 107 update_seek_double_test ("header_double.aiff", SF_FORMAT_AIFF) ;
cannam@125 108 header_shrink_test ("header_shrink.wav", SF_FORMAT_AIFF) ;
cannam@125 109 extra_header_test ("extra.aiff", SF_FORMAT_AIFF) ;
cannam@125 110 test_count++ ;
cannam@125 111 } ;
cannam@125 112
cannam@125 113 if (do_all || ! strcmp (argv [1], "au"))
cannam@125 114 { update_header_test ("header.au", SF_FORMAT_AU) ;
cannam@125 115 update_seek_short_test ("header_short.au", SF_FORMAT_AU) ;
cannam@125 116 update_seek_int_test ("header_int.au", SF_FORMAT_AU) ;
cannam@125 117 update_seek_float_test ("header_float.au", SF_FORMAT_AU) ;
cannam@125 118 update_seek_double_test ("header_double.au", SF_FORMAT_AU) ;
cannam@125 119 test_count++ ;
cannam@125 120 } ;
cannam@125 121
cannam@125 122 if (do_all || ! strcmp (argv [1], "caf"))
cannam@125 123 { update_header_test ("header.caf", SF_FORMAT_CAF) ;
cannam@125 124 update_seek_short_test ("header_short.caf", SF_FORMAT_CAF) ;
cannam@125 125 update_seek_int_test ("header_int.caf", SF_FORMAT_CAF) ;
cannam@125 126 update_seek_float_test ("header_float.caf", SF_FORMAT_CAF) ;
cannam@125 127 update_seek_double_test ("header_double.caf", SF_FORMAT_CAF) ;
cannam@125 128 /* extra_header_test ("extra.caf", SF_FORMAT_CAF) ; */
cannam@125 129 test_count++ ;
cannam@125 130 } ;
cannam@125 131
cannam@125 132 if (do_all || ! strcmp (argv [1], "nist"))
cannam@125 133 { update_header_test ("header.nist", SF_FORMAT_NIST) ;
cannam@125 134 update_seek_short_test ("header_short.nist", SF_FORMAT_NIST) ;
cannam@125 135 update_seek_int_test ("header_int.nist", SF_FORMAT_NIST) ;
cannam@125 136 test_count++ ;
cannam@125 137 } ;
cannam@125 138
cannam@125 139 if (do_all || ! strcmp (argv [1], "paf"))
cannam@125 140 { update_header_test ("header.paf", SF_FORMAT_PAF) ;
cannam@125 141 update_seek_short_test ("header_short.paf", SF_FORMAT_PAF) ;
cannam@125 142 test_count++ ;
cannam@125 143 } ;
cannam@125 144
cannam@125 145 if (do_all || ! strcmp (argv [1], "ircam"))
cannam@125 146 { update_header_test ("header.ircam", SF_FORMAT_IRCAM) ;
cannam@125 147 update_seek_short_test ("header_short.ircam", SF_FORMAT_IRCAM) ;
cannam@125 148 test_count++ ;
cannam@125 149 } ;
cannam@125 150
cannam@125 151 if (do_all || ! strcmp (argv [1], "w64"))
cannam@125 152 { update_header_test ("header.w64", SF_FORMAT_W64) ;
cannam@125 153 update_seek_short_test ("header_short.w64", SF_FORMAT_W64) ;
cannam@125 154 update_seek_int_test ("header_int.w64", SF_FORMAT_W64) ;
cannam@125 155 update_seek_float_test ("header_float.w64", SF_FORMAT_W64) ;
cannam@125 156 update_seek_double_test ("header_double.w64", SF_FORMAT_W64) ;
cannam@125 157 test_count++ ;
cannam@125 158 } ;
cannam@125 159
cannam@125 160 if (do_all || ! strcmp (argv [1], "rf64"))
cannam@125 161 { update_header_test ("header.rf64", SF_FORMAT_RF64) ;
cannam@125 162 update_seek_short_test ("header_short.rf64", SF_FORMAT_RF64) ;
cannam@125 163 update_seek_int_test ("header_int.rf64", SF_FORMAT_RF64) ;
cannam@125 164 update_seek_float_test ("header_float.rf64", SF_FORMAT_RF64) ;
cannam@125 165 update_seek_double_test ("header_double.rf64", SF_FORMAT_RF64) ;
cannam@125 166 test_count++ ;
cannam@125 167 } ;
cannam@125 168
cannam@125 169 if (do_all || ! strcmp (argv [1], "mat4"))
cannam@125 170 { update_header_test ("header.mat4", SF_FORMAT_MAT4) ;
cannam@125 171 update_seek_short_test ("header_short.mat4", SF_FORMAT_MAT4) ;
cannam@125 172 update_seek_int_test ("header_int.mat4", SF_FORMAT_MAT4) ;
cannam@125 173 update_seek_float_test ("header_float.mat4", SF_FORMAT_MAT4) ;
cannam@125 174 update_seek_double_test ("header_double.mat4", SF_FORMAT_MAT4) ;
cannam@125 175 test_count++ ;
cannam@125 176 } ;
cannam@125 177
cannam@125 178 if (do_all || ! strcmp (argv [1], "mat5"))
cannam@125 179 { update_header_test ("header.mat5", SF_FORMAT_MAT5) ;
cannam@125 180 update_seek_short_test ("header_short.mat5", SF_FORMAT_MAT5) ;
cannam@125 181 update_seek_int_test ("header_int.mat5", SF_FORMAT_MAT5) ;
cannam@125 182 update_seek_float_test ("header_float.mat5", SF_FORMAT_MAT5) ;
cannam@125 183 update_seek_double_test ("header_double.mat5", SF_FORMAT_MAT5) ;
cannam@125 184 test_count++ ;
cannam@125 185 } ;
cannam@125 186
cannam@125 187 if (do_all || ! strcmp (argv [1], "pvf"))
cannam@125 188 { update_header_test ("header.pvf", SF_FORMAT_PVF) ;
cannam@125 189 update_seek_short_test ("header_short.pvf", SF_FORMAT_PVF) ;
cannam@125 190 test_count++ ;
cannam@125 191 } ;
cannam@125 192
cannam@125 193 if (do_all || ! strcmp (argv [1], "avr"))
cannam@125 194 { update_header_test ("header.avr", SF_FORMAT_AVR) ;
cannam@125 195 update_seek_short_test ("header_short.avr", SF_FORMAT_AVR) ;
cannam@125 196 test_count++ ;
cannam@125 197 } ;
cannam@125 198
cannam@125 199 if (do_all || ! strcmp (argv [1], "htk"))
cannam@125 200 { update_header_test ("header.htk", SF_FORMAT_HTK) ;
cannam@125 201 update_seek_short_test ("header_short.htk", SF_FORMAT_HTK) ;
cannam@125 202 test_count++ ;
cannam@125 203 } ;
cannam@125 204
cannam@125 205 if (do_all || ! strcmp (argv [1], "svx"))
cannam@125 206 { update_header_test ("header.svx", SF_FORMAT_SVX) ;
cannam@125 207 update_seek_short_test ("header_short.svx", SF_FORMAT_SVX) ;
cannam@125 208 test_count++ ;
cannam@125 209 } ;
cannam@125 210
cannam@125 211 if (do_all || ! strcmp (argv [1], "voc"))
cannam@125 212 { update_header_test ("header.voc", SF_FORMAT_VOC) ;
cannam@125 213 /*-update_seek_short_test ("header_short.voc", SF_FORMAT_VOC) ;-*/
cannam@125 214 test_count++ ;
cannam@125 215 } ;
cannam@125 216
cannam@125 217 if (do_all || ! strcmp (argv [1], "sds"))
cannam@125 218 { update_header_test ("header.sds", SF_FORMAT_SDS) ;
cannam@125 219 /*-update_seek_short_test ("header_short.sds", SF_FORMAT_SDS) ;-*/
cannam@125 220 test_count++ ;
cannam@125 221 } ;
cannam@125 222
cannam@125 223 if (do_all || ! strcmp (argv [1], "mpc2k"))
cannam@125 224 { update_header_test ("header.mpc", SF_FORMAT_MPC2K) ;
cannam@125 225 update_seek_short_test ("header_short.mpc", SF_FORMAT_MPC2K) ;
cannam@125 226 test_count++ ;
cannam@125 227 } ;
cannam@125 228
cannam@125 229 if (test_count == 0)
cannam@125 230 { printf ("Mono : ************************************\n") ;
cannam@125 231 printf ("Mono : * No '%s' test defined.\n", argv [1]) ;
cannam@125 232 printf ("Mono : ************************************\n") ;
cannam@125 233 return 1 ;
cannam@125 234 } ;
cannam@125 235
cannam@125 236 return 0 ;
cannam@125 237 } /* main */
cannam@125 238
cannam@125 239
cannam@125 240 /*============================================================================================
cannam@125 241 ** Here are the test functions.
cannam@125 242 */
cannam@125 243
cannam@125 244 static void
cannam@125 245 update_header_sub (const char *filename, int typemajor, int write_mode)
cannam@125 246 { SNDFILE *outfile, *infile ;
cannam@125 247 SF_INFO sfinfo ;
cannam@125 248 int k ;
cannam@125 249
cannam@125 250 sfinfo.samplerate = 44100 ;
cannam@125 251 sfinfo.format = (typemajor | SF_FORMAT_PCM_16) ;
cannam@125 252 sfinfo.channels = 1 ;
cannam@125 253 sfinfo.frames = 0 ;
cannam@125 254
cannam@125 255 outfile = test_open_file_or_die (filename, write_mode, &sfinfo, SF_TRUE, __LINE__) ;
cannam@125 256
cannam@125 257 for (k = 0 ; k < BUFFER_LEN ; k++)
cannam@125 258 data_out [k] = k + 1 ;
cannam@125 259 test_write_int_or_die (outfile, 0, data_out, BUFFER_LEN, __LINE__) ;
cannam@125 260
cannam@125 261 if (typemajor != SF_FORMAT_HTK)
cannam@125 262 { /* The HTK header is not correct when the file is first written. */
cannam@125 263 infile = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
cannam@125 264 sf_close (infile) ;
cannam@125 265 } ;
cannam@125 266
cannam@125 267 sf_command (outfile, SFC_UPDATE_HEADER_NOW, NULL, 0) ;
cannam@125 268
cannam@125 269 /*
cannam@125 270 ** Open file and check log buffer for an error. If header update failed
cannam@125 271 ** the the log buffer will contain errors.
cannam@125 272 */
cannam@125 273 infile = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
cannam@125 274 check_log_buffer_or_die (infile, __LINE__) ;
cannam@125 275
cannam@125 276 if (sfinfo.frames < BUFFER_LEN || sfinfo.frames > BUFFER_LEN + 50)
cannam@125 277 { printf ("\n\nLine %d : Incorrect sample count (%" PRId64 " should be %d)\n", __LINE__, sfinfo.frames, BUFFER_LEN) ;
cannam@125 278 dump_log_buffer (infile) ;
cannam@125 279 exit (1) ;
cannam@125 280 } ;
cannam@125 281
cannam@125 282 test_read_int_or_die (infile, 0, data_in, BUFFER_LEN, __LINE__) ;
cannam@125 283 for (k = 0 ; k < BUFFER_LEN ; k++)
cannam@125 284 if (data_out [k] != k + 1)
cannam@125 285 printf ("Error : line %d\n", __LINE__) ;
cannam@125 286
cannam@125 287 sf_close (infile) ;
cannam@125 288
cannam@125 289 /* Set auto update on. */
cannam@125 290 sf_command (outfile, SFC_SET_UPDATE_HEADER_AUTO, NULL, SF_TRUE) ;
cannam@125 291
cannam@125 292 /* Write more data_out. */
cannam@125 293 for (k = 0 ; k < BUFFER_LEN ; k++)
cannam@125 294 data_out [k] = k + 2 ;
cannam@125 295 test_write_int_or_die (outfile, 0, data_out, BUFFER_LEN, __LINE__) ;
cannam@125 296
cannam@125 297 /* Open file again and make sure no errors in log buffer. */
cannam@125 298 infile = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
cannam@125 299 check_log_buffer_or_die (infile, __LINE__) ;
cannam@125 300
cannam@125 301 if (sfinfo.frames < 2 * BUFFER_LEN || sfinfo.frames > 2 * BUFFER_LEN + 50)
cannam@125 302 { printf ("\n\nLine %d : Incorrect sample count (%" PRId64 " should be %d)\n", __LINE__, sfinfo.frames, 2 * BUFFER_LEN) ;
cannam@125 303 dump_log_buffer (infile) ;
cannam@125 304 exit (1) ;
cannam@125 305 } ;
cannam@125 306
cannam@125 307 sf_close (infile) ;
cannam@125 308
cannam@125 309 sf_close (outfile) ;
cannam@125 310
cannam@125 311 unlink (filename) ;
cannam@125 312 } /* update_header_sub */
cannam@125 313
cannam@125 314 static void
cannam@125 315 update_header_test (const char *filename, int typemajor)
cannam@125 316 {
cannam@125 317 print_test_name ("update_header_test", filename) ;
cannam@125 318
cannam@125 319 update_header_sub (filename, typemajor, SFM_WRITE) ;
cannam@125 320 update_header_sub (filename, typemajor, SFM_RDWR) ;
cannam@125 321
cannam@125 322 unlink (filename) ;
cannam@125 323 puts ("ok") ;
cannam@125 324 } /* update_header_test */
cannam@125 325
cannam@125 326 /*==============================================================================
cannam@125 327 */
cannam@125 328
cannam@125 329 [+ FOR data_type
cannam@125 330 +]static void
cannam@125 331 update_seek_[+ (get "name") +]_test (const char *filename, int filetype)
cannam@125 332 { SNDFILE *outfile, *infile ;
cannam@125 333 SF_INFO sfinfo ;
cannam@125 334 sf_count_t frames ;
cannam@125 335 [+ (get "name") +] buffer [8] ;
cannam@125 336 int k ;
cannam@125 337
cannam@125 338 print_test_name ("update_seek_[+ (get "name") +]_test", filename) ;
cannam@125 339
cannam@125 340 memset (buffer, 0, sizeof (buffer)) ;
cannam@125 341
cannam@125 342 /* Create sound outfile with no data. */
cannam@125 343 sfinfo.format = filetype | [+ (get "format") +] ;
cannam@125 344 sfinfo.samplerate = 48000 ;
cannam@125 345 sfinfo.channels = 2 ;
cannam@125 346
cannam@125 347 if (sf_format_check (&sfinfo) == SF_FALSE)
cannam@125 348 sfinfo.channels = 1 ;
cannam@125 349
cannam@125 350 outfile = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
cannam@125 351 sf_close (outfile) ;
cannam@125 352
cannam@125 353 /* Open again for read/write. */
cannam@125 354 outfile = test_open_file_or_die (filename, SFM_RDWR, &sfinfo, SF_TRUE, __LINE__) ;
cannam@125 355
cannam@125 356 /*
cannam@125 357 ** In auto header update mode, seeking to the end of the file with
cannam@125 358 ** SEEK_SET will fail from the 2nd seek on. seeking to 0, SEEK_END
cannam@125 359 ** will seek to 0 anyway
cannam@125 360 */
cannam@125 361 if (sf_command (outfile, SFC_SET_UPDATE_HEADER_AUTO, NULL, SF_TRUE) == 0)
cannam@125 362 { printf ("\n\nError : sf_command (SFC_SET_UPDATE_HEADER_AUTO) return error : %s\n\n", sf_strerror (outfile)) ;
cannam@125 363 exit (1) ;
cannam@125 364 } ;
cannam@125 365
cannam@125 366 /* Now write some frames. */
cannam@125 367 frames = ARRAY_LEN (buffer) / sfinfo.channels ;
cannam@125 368
cannam@125 369 for (k = 0 ; k < 6 ; k++)
cannam@125 370 { test_seek_or_die (outfile, k * frames, SEEK_SET, k * frames, sfinfo.channels, __LINE__) ;
cannam@125 371 test_seek_or_die (outfile, 0, SEEK_END, k * frames, sfinfo.channels, __LINE__) ;
cannam@125 372
cannam@125 373 /* Open file again and make sure no errors in log buffer. */
cannam@125 374 infile = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
cannam@125 375 check_log_buffer_or_die (infile, __LINE__) ;
cannam@125 376 sf_close (infile) ;
cannam@125 377
cannam@125 378 if (sfinfo.frames != k * frames)
cannam@125 379 { printf ("\n\nLine %d : Incorrect sample count (%" PRId64 " should be %" PRId64 ")\n", __LINE__, sfinfo.frames, k + frames) ;
cannam@125 380 dump_log_buffer (infile) ;
cannam@125 381 exit (1) ;
cannam@125 382 } ;
cannam@125 383
cannam@125 384 if ((k & 1) == 0)
cannam@125 385 test_write_[+ (get "name") +]_or_die (outfile, k, buffer, sfinfo.channels * frames, __LINE__) ;
cannam@125 386 else
cannam@125 387 test_writef_[+ (get "name") +]_or_die (outfile, k, buffer, frames, __LINE__) ;
cannam@125 388 } ;
cannam@125 389
cannam@125 390 sf_close (outfile) ;
cannam@125 391 unlink (filename) ;
cannam@125 392
cannam@125 393 puts ("ok") ;
cannam@125 394 return ;
cannam@125 395 } /* update_seek_[+ (get "name") +]_test */
cannam@125 396
cannam@125 397 [+ ENDFOR data_type
cannam@125 398 +]
cannam@125 399
cannam@125 400 static void
cannam@125 401 header_shrink_test (const char *filename, int filetype)
cannam@125 402 { SNDFILE *outfile, *infile ;
cannam@125 403 SF_INFO sfinfo ;
cannam@125 404 sf_count_t frames ;
cannam@125 405 float buffer [8], bufferin [8] ;
cannam@125 406
cannam@125 407 print_test_name ("header_shrink_test", filename) ;
cannam@125 408
cannam@125 409 memset (&sfinfo, 0, sizeof (sfinfo)) ;
cannam@125 410 sfinfo.samplerate = 44100 ;
cannam@125 411 sfinfo.format = filetype | SF_FORMAT_FLOAT ;
cannam@125 412 sfinfo.channels = 1 ;
cannam@125 413
cannam@125 414 memset (buffer, 0xA0, sizeof (buffer)) ;
cannam@125 415
cannam@125 416 /* Now write some frames. */
cannam@125 417 frames = ARRAY_LEN (buffer) / sfinfo.channels ;
cannam@125 418
cannam@125 419 /* Test the file with extra header data. */
cannam@125 420 outfile = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_FALSE, __LINE__) ;
cannam@125 421
cannam@125 422 sf_command (outfile, SFC_SET_ADD_PEAK_CHUNK, NULL, SF_TRUE) ;
cannam@125 423 sf_command (outfile, SFC_UPDATE_HEADER_NOW, NULL, SF_FALSE) ;
cannam@125 424 sf_command (outfile, SFC_SET_ADD_PEAK_CHUNK, NULL, SF_FALSE) ;
cannam@125 425
cannam@125 426 test_writef_float_or_die (outfile, 0, buffer, frames, __LINE__) ;
cannam@125 427 sf_close (outfile) ;
cannam@125 428
cannam@125 429 /* Open again for read. */
cannam@125 430 infile = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_FALSE, __LINE__) ;
cannam@125 431
cannam@125 432 test_readf_float_or_die (infile, 0, bufferin, frames, __LINE__) ;
cannam@125 433 sf_close (infile) ;
cannam@125 434
cannam@125 435 compare_float_or_die (buffer, bufferin, frames, __LINE__) ;
cannam@125 436
cannam@125 437 unlink (filename) ;
cannam@125 438 puts ("ok") ;
cannam@125 439 return ;
cannam@125 440 } /* header_shrink_test */
cannam@125 441
cannam@125 442
cannam@125 443 static void
cannam@125 444 extra_header_test (const char *filename, int filetype)
cannam@125 445 { SNDFILE *outfile, *infile ;
cannam@125 446 SF_INFO sfinfo ;
cannam@125 447 sf_count_t frames ;
cannam@125 448 short buffer [8] ;
cannam@125 449 int k = 0 ;
cannam@125 450
cannam@125 451 print_test_name ("extra_header_test", filename) ;
cannam@125 452
cannam@125 453 sfinfo.samplerate = 44100 ;
cannam@125 454 sfinfo.format = (filetype | SF_FORMAT_PCM_16) ;
cannam@125 455 sfinfo.channels = 1 ;
cannam@125 456
cannam@125 457 memset (buffer, 0xA0, sizeof (buffer)) ;
cannam@125 458
cannam@125 459 /* Now write some frames. */
cannam@125 460 frames = ARRAY_LEN (buffer) / sfinfo.channels ;
cannam@125 461
cannam@125 462 /* Test the file with extra header data. */
cannam@125 463 outfile = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, [+ (tpl-file-line "%2$d") +]) ;
cannam@125 464 sf_set_string (outfile, SF_STR_TITLE, filename) ;
cannam@125 465 test_writef_short_or_die (outfile, k, buffer, frames, [+ (tpl-file-line "%2$d") +]) ;
cannam@125 466 sf_set_string (outfile, SF_STR_COPYRIGHT, "(c) 1980 Erik") ;
cannam@125 467 sf_close (outfile) ;
cannam@125 468
cannam@125 469 #if 1
cannam@125 470 /*
cannam@125 471 ** Erik de Castro Lopo <erikd@mega-nerd.com> May 23 2004.
cannam@125 472 **
cannam@125 473 ** This file has extra string data in the header and therefore cannot
cannam@125 474 ** currently be opened in SFM_RDWR mode. This is fixable, but its in
cannam@125 475 ** a part of the code I don't want to fiddle with until the Ogg/Vorbis
cannam@125 476 ** integration is done.
cannam@125 477 */
cannam@125 478
cannam@125 479 if ((infile = sf_open (filename, SFM_RDWR, &sfinfo)) != NULL)
cannam@125 480 { printf ("\n\nError : should not be able to open this file in SFM_RDWR.\n\n") ;
cannam@125 481 exit (1) ;
cannam@125 482 } ;
cannam@125 483
cannam@125 484 unlink (filename) ;
cannam@125 485 puts ("ok") ;
cannam@125 486 return ;
cannam@125 487 #else
cannam@125 488
cannam@125 489 hexdump_file (filename, 0, 100000) ;
cannam@125 490
cannam@125 491 /* Open again for read/write. */
cannam@125 492 outfile = test_open_file_or_die (filename, SFM_RDWR, &sfinfo, [+ (tpl-file-line "%2$d") +]) ;
cannam@125 493
cannam@125 494 /*
cannam@125 495 ** In auto header update mode, seeking to the end of the file with
cannam@125 496 ** SEEK_SET will fail from the 2nd seek on. seeking to 0, SEEK_END
cannam@125 497 ** will seek to 0 anyway
cannam@125 498 */
cannam@125 499 if (sf_command (outfile, SFC_SET_UPDATE_HEADER_AUTO, NULL, SF_TRUE) == 0)
cannam@125 500 { printf ("\n\nError : sf_command (SFC_SET_UPDATE_HEADER_AUTO) return error : %s\n\n", sf_strerror (outfile)) ;
cannam@125 501 exit (1) ;
cannam@125 502 } ;
cannam@125 503
cannam@125 504 /* Now write some frames. */
cannam@125 505 frames = ARRAY_LEN (buffer) / sfinfo.channels ;
cannam@125 506
cannam@125 507 for (k = 1 ; k < 6 ; k++)
cannam@125 508 {
cannam@125 509 printf ("\n*** pass %d\n", k) ;
cannam@125 510 memset (buffer, 0xA0 + k, sizeof (buffer)) ;
cannam@125 511
cannam@125 512
cannam@125 513 test_seek_or_die (outfile, k * frames, SEEK_SET, k * frames, sfinfo.channels, [+ (tpl-file-line "%2$d") +]) ;
cannam@125 514 test_seek_or_die (outfile, 0, SEEK_END, k * frames, sfinfo.channels, [+ (tpl-file-line "%2$d") +]) ;
cannam@125 515
cannam@125 516 /* Open file again and make sure no errors in log buffer. */
cannam@125 517 if (0)
cannam@125 518 { infile = test_open_file_or_die (filename, SFM_READ, &sfinfo, [+ (tpl-file-line "%2$d") +]) ;
cannam@125 519 check_log_buffer_or_die (infile, [+ (tpl-file-line "%2$d") +]) ;
cannam@125 520 sf_close (infile) ;
cannam@125 521 } ;
cannam@125 522
cannam@125 523 if (sfinfo.frames != k * frames)
cannam@125 524 { printf ("\n\nLine %d : Incorrect sample count (%" PRId64 " should be %" PRId64 ")\n", [+ (tpl-file-line "%2$d") +], sfinfo.frames, k + frames) ;
cannam@125 525 dump_log_buffer (infile) ;
cannam@125 526 exit (1) ;
cannam@125 527 } ;
cannam@125 528
cannam@125 529 if ((k & 1) == 0)
cannam@125 530 test_write_short_or_die (outfile, k, buffer, sfinfo.channels * frames, [+ (tpl-file-line "%2$d") +]) ;
cannam@125 531 else
cannam@125 532 test_writef_short_or_die (outfile, k, buffer, frames, [+ (tpl-file-line "%2$d") +]) ;
cannam@125 533 hexdump_file (filename, 0, 100000) ;
cannam@125 534 } ;
cannam@125 535
cannam@125 536 sf_close (outfile) ;
cannam@125 537 unlink (filename) ;
cannam@125 538
cannam@125 539 puts ("ok") ;
cannam@125 540 return ;
cannam@125 541 #endif
cannam@125 542 } /* extra_header_test */
cannam@125 543