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