static void read_write_peak_test (const char *filename, int filetype) { SNDFILE *file ; SF_INFO sfinfo ; double small_data [10] ; double max_peak = 0.0 ; unsigned k ; print_test_name (__func__, filename) ; for (k = 0 ; k < ARRAY_LEN (small_data) ; k ++) small_data [k] = 0.1 ; sfinfo.samplerate = 44100 ; sfinfo.channels = 2 ; sfinfo.format = filetype ; sfinfo.frames = 0 ; /* Open the file, add peak chunk and write samples with value 0.1. */ file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_FALSE, __LINE__) ; sf_command (file, SFC_SET_ADD_PEAK_CHUNK, NULL, SF_TRUE) ; test_write_double_or_die (file, 0, small_data, ARRAY_LEN (small_data), __LINE__) ; sf_close (file) ; /* Open the fiel RDWR, write sample valied 1.25. */ file = test_open_file_or_die (filename, SFM_RDWR, &sfinfo, SF_FALSE, __LINE__) ; for (k = 0 ; k < ARRAY_LEN (small_data) ; k ++) small_data [k] = 1.0 ; test_write_double_or_die (file, 0, small_data, ARRAY_LEN (small_data), __LINE__) ; sf_command (file, SFC_GET_SIGNAL_MAX, &max_peak, sizeof (max_peak)) ; sf_close (file) ; exit_if_true (max_peak < 0.1, "\n\nLine %d : max peak (%5.3f) should not be 0.1.\n\n", __LINE__, max_peak) ; /* Open the file and test the values written to the PEAK chunk. */ file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_FALSE, __LINE__) ; exit_if_true (sfinfo.channels * sfinfo.frames != 2 * ARRAY_LEN (small_data), "Line %d : frame count is %ld, should be %d\n", __LINE__, SF_COUNT_TO_LONG (sfinfo.frames), 2 * ARRAY_LEN (small_data)) ; sf_command (file, SFC_GET_SIGNAL_MAX, &max_peak, sizeof (double)) ; sf_close (file) ; exit_if_true (max_peak < 1.0, "\n\nLine %d : max peak (%5.3f) should be 1.0.\n\n", __LINE__, max_peak) ; unlink (filename) ; puts ("ok") ; } /* read_write_peak_test */
static void channel_map_test (const char *filename, int filetype) { SNDFILE *file ; SF_INFO sfinfo ; int channel_map_read [4], channel_map_write [4] = { SF_CHANNEL_MAP_FRONT_LEFT, SF_CHANNEL_MAP_FRONT_CENTER, SF_CHANNEL_MAP_REAR_LEFT, SF_CHANNEL_MAP_REAR_RIGHT } ; print_test_name ("channel_map_test", filename) ; memset (&sfinfo, 0, sizeof (sfinfo)) ; sfinfo.samplerate = 11025 ; sfinfo.format = filetype ; sfinfo.channels = ARRAY_LEN (channel_map_read) ; /* Write file without channel map. */ file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ; test_write_double_or_die (file, 0, double_data, BUFFER_LEN, __LINE__) ; sf_close (file) ; /* Read file making sure no channel map exists. */ file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ; exit_if_true ( sf_command (file, SFC_GET_CHANNEL_MAP_INFO, channel_map_read, sizeof (channel_map_read)) != SF_FALSE, "\n\nLine %d : sf_command (SFC_GET_CHANNEL_MAP_INFO) should have failed.\n\n", __LINE__ ) ; check_log_buffer_or_die (file, __LINE__) ; sf_close (file) ; /* Write file with a channel map. */ file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ; test_write_double_or_die (file, 0, double_data, BUFFER_LEN, __LINE__) ; exit_if_true ( sf_command (file, SFC_SET_CHANNEL_MAP_INFO, channel_map_write, sizeof (channel_map_write)) == SF_FALSE, "\n\nLine %d : sf_command (SFC_SET_CHANNEL_MAP_INFO) failed.\n\n", __LINE__ ) ; sf_close (file) ; /* Read file making sure no channel map exists. */ file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ; exit_if_true ( sf_command (file, SFC_GET_CHANNEL_MAP_INFO, channel_map_read, sizeof (channel_map_read)) != SF_TRUE, "\n\nLine %d : sf_command (SFC_GET_CHANNEL_MAP_INFO) failed.\n\n", __LINE__ ) ; check_log_buffer_or_die (file, __LINE__) ; sf_close (file) ; exit_if_true ( memcmp (channel_map_read, channel_map_write, sizeof (channel_map_read)) != 0, "\n\nLine %d : Channel map read does not match channel map written.\n\n", __LINE__ ) ; unlink (filename) ; puts ("ok") ; } /* channel_map_test */
static void current_sf_info_test (const char *filename) { SNDFILE *outfile, *infile ; SF_INFO outinfo, ininfo ; sf_count_t last_count ; print_test_name ("current_sf_info_test", filename) ; outinfo.samplerate = 44100 ; outinfo.format = (SF_FORMAT_WAV | SF_FORMAT_PCM_16) ; outinfo.channels = 1 ; outinfo.frames = 0 ; outfile = test_open_file_or_die (filename, SFM_WRITE, &outinfo, SF_TRUE, __LINE__) ; sf_command (outfile, SFC_SET_UPDATE_HEADER_AUTO, NULL, 0) ; exit_if_true (outinfo.frames != 0, "\n\nLine %d : Initial sfinfo.frames is not zero.\n\n", __LINE__ ) ; test_write_double_or_die (outfile, 0, double_data, BUFFER_LEN, __LINE__) ; sf_command (outfile, SFC_GET_CURRENT_SF_INFO, &outinfo, sizeof (outinfo)) ; exit_if_true (outinfo.frames != BUFFER_LEN, "\n\nLine %d : Initial sfinfo.frames (%ld) should be %d.\n\n", __LINE__, SF_COUNT_TO_LONG (outinfo.frames), BUFFER_LEN ) ; /* Read file making sure no channel map exists. */ memset (&ininfo, 0, sizeof (ininfo)) ; infile = test_open_file_or_die (filename, SFM_READ, &ininfo, SF_TRUE, __LINE__) ; last_count = ininfo.frames ; test_write_double_or_die (outfile, 0, double_data, BUFFER_LEN, __LINE__) ; sf_command (infile, SFC_GET_CURRENT_SF_INFO, &ininfo, sizeof (ininfo)) ; exit_if_true (ininfo.frames != BUFFER_LEN, "\n\nLine %d : Initial sfinfo.frames (%ld) should be %d.\n\n", __LINE__, SF_COUNT_TO_LONG (ininfo.frames), BUFFER_LEN ) ; sf_close (outfile) ; sf_close (infile) ; unlink (filename) ; puts ("ok") ; } /* current_sf_info_test */
static void rdwr_double_test (const char *filename) { SNDFILE *file ; SF_INFO sfinfo ; sf_count_t frames ; double buffer [160] ; print_test_name ("rdwr_double_test", filename) ; memset (buffer, 0, sizeof (buffer)) ; /* Create sound file with no data. */ sfinfo.format = SF_FORMAT_WAV | SF_FORMAT_DOUBLE ; sfinfo.samplerate = 16000 ; sfinfo.channels = 1 ; unlink (filename) ; frames = ARRAY_LEN (buffer) ; /* Open again for read/write. */ file = test_open_file_or_die (filename, SFM_RDWR, &sfinfo, SF_TRUE, __LINE__) ; test_write_double_or_die (file, 0, buffer, frames, __LINE__) ; test_read_double_or_die (file, 0, buffer, frames, __LINE__) ; sf_close (file) ; unlink (filename) ; puts ("ok") ; return ; } /* rdwr_double_test */
static void double_scaled_test (const char *filename, int allow_exit, int replace_float, int filetype, double target_snr) { SNDFILE *file ; SF_INFO sfinfo ; double snr ; print_test_name ("double_scaled_test", filename) ; gen_windowed_sine (orig_data, DFT_DATA_LENGTH, 0.95) ; sfinfo.samplerate = SAMPLE_RATE ; sfinfo.frames = DFT_DATA_LENGTH ; sfinfo.channels = 1 ; sfinfo.format = filetype ; file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, __LINE__) ; sf_command (file, SFC_TEST_IEEE_FLOAT_REPLACE, NULL, replace_float) ; test_write_double_or_die (file, 0, orig_data, DFT_DATA_LENGTH, __LINE__) ; sf_close (file) ; memset (test_data, 0, sizeof (test_data)) ; file = test_open_file_or_die (filename, SFM_READ, &sfinfo, __LINE__) ; sf_command (file, SFC_TEST_IEEE_FLOAT_REPLACE, NULL, replace_float) ; if (sfinfo.format != filetype) { printf ("\n\nLine %d: Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__, filetype, sfinfo.format) ; exit (1) ; } ; if (sfinfo.frames < DFT_DATA_LENGTH) { printf ("\n\nLine %d: Incorrect number of.frames in file (too short). (%ld should be %d)\n", __LINE__, SF_COUNT_TO_LONG (sfinfo.frames), DFT_DATA_LENGTH) ; exit (1) ; } ; if (sfinfo.channels != 1) { printf ("\n\nLine %d: Incorrect number of channels in file.\n", __LINE__) ; exit (1) ; } ; check_log_buffer_or_die (file, __LINE__) ; test_read_double_or_die (file, 0, test_data, DFT_DATA_LENGTH, __LINE__) ; sf_close (file) ; snr = dft_cmp (__LINE__, orig_data, test_data, DFT_DATA_LENGTH, target_snr, allow_exit) ; if (snr < target_snr) printf ("% 6.1fdB SNR ... ok\n", snr) ; unlink (filename) ; return ; } /* double_scaled_test */
static void double_scaled_test (const char *filename, int allow_exit, int replace_float, int filetype, double target_snr) { SNDFILE *file ; SF_INFO sfinfo ; double snr ; int byterate ; print_test_name ("double_scaled_test", filename) ; gen_windowed_sine_double (double_data, DFT_DATA_LENGTH, 0.9999) ; sfinfo.samplerate = SAMPLE_RATE ; sfinfo.frames = DFT_DATA_LENGTH ; sfinfo.channels = 1 ; sfinfo.format = filetype ; file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ; sf_command (file, SFC_TEST_IEEE_FLOAT_REPLACE, NULL, replace_float) ; test_write_double_or_die (file, 0, double_data, DFT_DATA_LENGTH, __LINE__) ; sf_close (file) ; memset (double_test, 0, sizeof (double_test)) ; file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ; sf_command (file, SFC_TEST_IEEE_FLOAT_REPLACE, NULL, replace_float) ; exit_if_true (sfinfo.format != filetype, "\n\nLine %d: Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__, filetype, sfinfo.format) ; exit_if_true (sfinfo.frames < DFT_DATA_LENGTH, "\n\nLine %d: Incorrect number of frames in file (too short). (%" PRId64 " should be %d)\n", __LINE__, sfinfo.frames, DFT_DATA_LENGTH) ; exit_if_true (sfinfo.channels != 1, "\n\nLine %d: Incorrect number of channels in file.\n", __LINE__) ; check_log_buffer_or_die (file, __LINE__) ; test_read_double_or_die (file, 0, double_test, DFT_DATA_LENGTH, __LINE__) ; byterate = sf_current_byterate (file) ; exit_if_true (byterate <= 0, "\n\nLine %d: byterate is zero.\n", __LINE__) ; sf_close (file) ; snr = dft_cmp_double (__LINE__, double_data, double_test, DFT_DATA_LENGTH, target_snr, allow_exit) ; exit_if_true (snr > target_snr, "% 6.1fdB SNR\n\n Error : should be better than % 6.1fdB\n\n", snr, target_snr) ; printf ("% 6.1fdB SNR ... ok\n", snr) ; unlink (filename) ; return ; } /* double_scaled_test */
static void double_int_big_test (const char * filename) { SNDFILE *file ; SF_INFO sfinfo ; unsigned k, max ; print_test_name ("double_int_big_test", filename) ; gen_windowed_sine_double (double_data, ARRAY_LEN (double_data), 0.9999) ; sfinfo.samplerate = SAMPLE_RATE ; sfinfo.frames = ARRAY_LEN (int_data) ; sfinfo.channels = 1 ; sfinfo.format = SF_ENDIAN_BIG | SF_FORMAT_AU | SF_FORMAT_DOUBLE ; file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ; test_write_double_or_die (file, 0, double_data, ARRAY_LEN (double_data), __LINE__) ; sf_close (file) ; file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ; if (sfinfo.frames != ARRAY_LEN (double_data)) { printf ("\n\nLine %d: Incorrect number of frames in file (too short). (%" PRId64 " should be %d)\n", __LINE__, sfinfo.frames, DFT_DATA_LENGTH) ; exit (1) ; } ; if (sfinfo.channels != 1) { printf ("\n\nLine %d: Incorrect number of channels in file.\n", __LINE__) ; exit (1) ; } ; sf_command (file, SFC_SET_SCALE_FLOAT_INT_READ, NULL, SF_TRUE) ; test_read_int_or_die (file, 0, int_data, ARRAY_LEN (int_data), __LINE__) ; sf_close (file) ; max = 0 ; for (k = 0 ; k < ARRAY_LEN (int_data) ; k++) if (abs (int_data [k]) > max) max = abs (int_data [k]) ; if (1.0 * abs (max - 0x7FFFFFFF) / 0x7FFFFFFF > 0.01) { printf ("\n\nLine %d: Bad maximum (%d should be %d).\n\n", __LINE__, max, 0x7FFFFFFF) ; exit (1) ; } ; unlink (filename) ; puts ("ok") ; } /* double_int_big_test */
static void ogg_double_test (void) { const char * filename = "vorbis_double.oga" ; SNDFILE * file ; SF_INFO sfinfo ; double seek_data [10] ; print_test_name ("ogg_double_test", filename) ; gen_windowed_sine_double (data_out.d, ARRAY_LEN (data_out.d), 0.95) ; memset (&sfinfo, 0, sizeof (sfinfo)) ; /* Set up output file type. */ sfinfo.format = SF_FORMAT_OGG | SF_FORMAT_VORBIS ; sfinfo.channels = 1 ; sfinfo.samplerate = SAMPLE_RATE ; /* Write the output file. */ file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_FALSE, __LINE__) ; test_write_double_or_die (file, 0, data_out.d, ARRAY_LEN (data_out.d), __LINE__) ; sf_close (file) ; /* Read the file in again. */ memset (&sfinfo, 0, sizeof (sfinfo)) ; file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_FALSE, __LINE__) ; test_read_double_or_die (file, 0, data_in.d, ARRAY_LEN (data_in.d), __LINE__) ; sf_close (file) ; puts ("ok") ; /* Test seeking. */ print_test_name ("ogg_seek_test", filename) ; file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_FALSE, __LINE__) ; test_seek_or_die (file, 10, SEEK_SET, 10, sfinfo.channels, __LINE__) ; test_read_double_or_die (file, 0, seek_data, ARRAY_LEN (seek_data), __LINE__) ; compare_double_or_die (seek_data, data_in.d + 10, ARRAY_LEN (seek_data), __LINE__) ; sf_close (file) ; puts ("ok") ; unlink (filename) ; } /* ogg_double_test */
static void update_seek_double_test (const char *filename, int filetype) { SNDFILE *outfile, *infile ; SF_INFO sfinfo ; sf_count_t frames ; double buffer [8] ; int k ; print_test_name ("update_seek_double_test", filename) ; memset (buffer, 0, sizeof (buffer)) ; /* Create sound outfile with no data. */ sfinfo.format = filetype | SF_FORMAT_DOUBLE ; sfinfo.samplerate = 48000 ; sfinfo.channels = 2 ; if (sf_format_check (&sfinfo) == SF_FALSE) sfinfo.channels = 1 ; outfile = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ; sf_close (outfile) ; /* Open again for read/write. */ outfile = test_open_file_or_die (filename, SFM_RDWR, &sfinfo, SF_TRUE, __LINE__) ; /* ** In auto header update mode, seeking to the end of the file with ** SEEK_SET will fail from the 2nd seek on. seeking to 0, SEEK_END ** will seek to 0 anyway */ if (sf_command (outfile, SFC_SET_UPDATE_HEADER_AUTO, NULL, SF_TRUE) == 0) { printf ("\n\nError : sf_command (SFC_SET_UPDATE_HEADER_AUTO) return error : %s\n\n", sf_strerror (outfile)) ; exit (1) ; } ; /* Now write some frames. */ frames = ARRAY_LEN (buffer) / sfinfo.channels ; for (k = 0 ; k < 6 ; k++) { test_seek_or_die (outfile, k * frames, SEEK_SET, k * frames, sfinfo.channels, __LINE__) ; test_seek_or_die (outfile, 0, SEEK_END, k * frames, sfinfo.channels, __LINE__) ; /* Open file again and make sure no errors in log buffer. */ infile = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ; check_log_buffer_or_die (infile, __LINE__) ; sf_close (infile) ; if (sfinfo.frames != k * frames) { printf ("\n\nLine %d : Incorrect sample count (%ld should be %ld)\n", __LINE__, SF_COUNT_TO_LONG (sfinfo.frames), SF_COUNT_TO_LONG (k + frames)) ; dump_log_buffer (infile) ; exit (1) ; } ; if ((k & 1) == 0) test_write_double_or_die (outfile, k, buffer, sfinfo.channels * frames, __LINE__) ; else test_writef_double_or_die (outfile, k, buffer, frames, __LINE__) ; } ; sf_close (outfile) ; unlink (filename) ; puts ("ok") ; return ; } /* update_seek_double_test */
static void check_coding_history_newlines (const char *filename) { static SF_BROADCAST_INFO bc_write, bc_read ; SNDFILE *file ; SF_INFO sfinfo ; unsigned k ; sfinfo.samplerate = 22050 ; sfinfo.format = SF_FORMAT_WAV | SF_FORMAT_PCM_16 ; sfinfo.channels = 1 ; memset (&bc_write, 0, sizeof (bc_write)) ; snprintf (bc_write.description, sizeof (bc_write.description), "Test description") ; snprintf (bc_write.originator, sizeof (bc_write.originator), "Test originator") ; snprintf (bc_write.originator_reference, sizeof (bc_write.originator_reference), "%08x-%08x", (unsigned int) time (NULL), (unsigned int) (~ time (NULL))) ; snprintf (bc_write.origination_date, sizeof (bc_write.origination_date), "%d/%02d/%02d", 2006, 3, 30) ; snprintf (bc_write.origination_time, sizeof (bc_write.origination_time), "%02d:%02d:%02d", 20, 27, 0) ; snprintf (bc_write.umid, sizeof (bc_write.umid), "Some umid") ; 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") ; ; file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ; if (sf_command (file, SFC_SET_BROADCAST_INFO, &bc_write, sizeof (bc_write)) == SF_FALSE) { printf ("\n\nLine %d : sf_command (SFC_SET_BROADCAST_INFO) failed.\n\n", __LINE__) ; exit (1) ; } ; test_write_double_or_die (file, 0, double_data, BUFFER_LEN, __LINE__) ; sf_close (file) ; memset (&bc_read, 0, sizeof (bc_read)) ; file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ; if (sf_command (file, SFC_GET_BROADCAST_INFO, &bc_read, sizeof (bc_read)) == SF_FALSE) { printf ("\n\nLine %d : sf_command (SFC_SET_BROADCAST_INFO) failed.\n\n", __LINE__) ; exit (1) ; } ; check_log_buffer_or_die (file, __LINE__) ; sf_close (file) ; if (bc_read.coding_history_size == 0) { printf ("\n\nLine %d : missing coding history.\n\n", __LINE__) ; exit (1) ; } ; if (strstr (bc_read.coding_history, "Last line") == NULL) { printf ("\n\nLine %d : coding history truncated.\n\n", __LINE__) ; exit (1) ; } ; for (k = 1 ; k < bc_read.coding_history_size ; k++) { if (bc_read.coding_history [k] == '\n' && bc_read.coding_history [k - 1] != '\r') { printf ("\n\nLine %d : '\\n' without '\\r' before.\n\n", __LINE__) ; exit (1) ; } ; if (bc_read.coding_history [k] == '\r' && bc_read.coding_history [k + 1] != '\n') { printf ("\n\nLine %d : '\\r' without '\\n' after.\n\n", __LINE__) ; exit (1) ; } ; if (bc_read.coding_history [k] == 0 && k < bc_read.coding_history_size - 1) { printf ("\n\nLine %d : '\\0' within coding history at index %d of %d.\n\n", __LINE__, k, bc_read.coding_history_size) ; exit (1) ; } ; } ; return ; } /* check_coding_history_newlines */
static void broadcast_test (const char *filename, int filetype) { static SF_BROADCAST_INFO bc_write, bc_read ; SNDFILE *file ; SF_INFO sfinfo ; int errors = 0 ; print_test_name ("broadcast_test", filename) ; sfinfo.samplerate = 11025 ; sfinfo.format = filetype ; sfinfo.channels = 1 ; memset (&bc_write, 0, sizeof (bc_write)) ; snprintf (bc_write.description, sizeof (bc_write.description), "Test description") ; snprintf (bc_write.originator, sizeof (bc_write.originator), "Test originator") ; snprintf (bc_write.originator_reference, sizeof (bc_write.originator_reference), "%08x-%08x", (unsigned int) time (NULL), (unsigned int) (~ time (NULL))) ; snprintf (bc_write.origination_date, sizeof (bc_write.origination_date), "%d/%02d/%02d", 2006, 3, 30) ; snprintf (bc_write.origination_time, sizeof (bc_write.origination_time), "%02d:%02d:%02d", 20, 27, 0) ; snprintf (bc_write.umid, sizeof (bc_write.umid), "Some umid") ; bc_write.coding_history_size = 0 ; file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ; if (sf_command (file, SFC_SET_BROADCAST_INFO, &bc_write, sizeof (bc_write)) == SF_FALSE) { printf ("\n\nLine %d : sf_command (SFC_SET_BROADCAST_INFO) failed.\n\n", __LINE__) ; exit (1) ; } ; test_write_double_or_die (file, 0, double_data, BUFFER_LEN, __LINE__) ; sf_close (file) ; memset (&bc_read, 0, sizeof (bc_read)) ; file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ; if (sf_command (file, SFC_GET_BROADCAST_INFO, &bc_read, sizeof (bc_read)) == SF_FALSE) { printf ("\n\nLine %d : sf_command (SFC_GET_BROADCAST_INFO) failed.\n\n", __LINE__) ; exit (1) ; return ; } ; check_log_buffer_or_die (file, __LINE__) ; sf_close (file) ; if (bc_read.version != 1) { printf ("\n\nLine %d : Read bad version number %d.\n\n", __LINE__, bc_read.version) ; exit (1) ; return ; } ; bc_read.version = bc_write.version = 0 ; if (memcmp (bc_write.description, bc_read.description, sizeof (bc_write.description)) != 0) { printf ("\n\nLine %d : description mismatch :\n\twrite : '%s'\n\tread : '%s'\n\n", __LINE__, bc_write.description, bc_read.description) ; errors ++ ; } ; if (memcmp (bc_write.originator, bc_read.originator, sizeof (bc_write.originator)) != 0) { printf ("\n\nLine %d : originator mismatch :\n\twrite : '%s'\n\tread : '%s'\n\n", __LINE__, bc_write.originator, bc_read.originator) ; errors ++ ; } ; if (memcmp (bc_write.originator_reference, bc_read.originator_reference, sizeof (bc_write.originator_reference)) != 0) { printf ("\n\nLine %d : originator_reference mismatch :\n\twrite : '%s'\n\tread : '%s'\n\n", __LINE__, bc_write.originator_reference, bc_read.originator_reference) ; errors ++ ; } ; if (memcmp (bc_write.origination_date, bc_read.origination_date, sizeof (bc_write.origination_date)) != 0) { printf ("\n\nLine %d : origination_date mismatch :\n\twrite : '%s'\n\tread : '%s'\n\n", __LINE__, bc_write.origination_date, bc_read.origination_date) ; errors ++ ; } ; if (memcmp (bc_write.origination_time, bc_read.origination_time, sizeof (bc_write.origination_time)) != 0) { printf ("\n\nLine %d : origination_time mismatch :\n\twrite : '%s'\n\tread : '%s'\n\n", __LINE__, bc_write.origination_time, bc_read.origination_time) ; errors ++ ; } ; if (memcmp (bc_write.umid, bc_read.umid, sizeof (bc_write.umid)) != 0) { printf ("\n\nLine %d : umid mismatch :\n\twrite : '%s'\n\tread : '%s'\n\n", __LINE__, bc_write.umid, bc_read.umid) ; errors ++ ; } ; if (errors) exit (1) ; unlink (filename) ; puts ("ok") ; } /* broadcast_test */
static void instrument_test (const char *filename, int filetype) { static SF_INSTRUMENT write_inst = { 2, /* gain */ 3, /* detune */ 4, /* basenote */ 5, 6, /* key low and high */ 7, 8, /* velocity low and high */ 2, /* loop_count */ { { 801, 2, 3, 0 }, { 801, 3, 4, 0 }, } } ; SF_INSTRUMENT read_inst ; SNDFILE *file ; SF_INFO sfinfo ; print_test_name ("instrument_test", filename) ; sfinfo.samplerate = 11025 ; sfinfo.format = filetype ; sfinfo.channels = 1 ; file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ; if (sf_command (file, SFC_SET_INSTRUMENT, &write_inst, sizeof (write_inst)) == SF_FALSE) { printf ("\n\nLine %d : sf_command (SFC_SET_INSTRUMENT) failed.\n\n", __LINE__) ; exit (1) ; } ; test_write_double_or_die (file, 0, double_data, BUFFER_LEN, __LINE__) ; sf_close (file) ; memset (&read_inst, 0, sizeof (read_inst)) ; file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ; if (sf_command (file, SFC_GET_INSTRUMENT, &read_inst, sizeof (read_inst)) == SF_FALSE) { printf ("\n\nLine %d : sf_command (SFC_GET_INSTRUMENT) failed.\n\n", __LINE__) ; exit (1) ; return ; } ; check_log_buffer_or_die (file, __LINE__) ; sf_close (file) ; if ((filetype & SF_FORMAT_TYPEMASK) == SF_FORMAT_WAV) { /* ** For all the fields that WAV doesn't support, modify the ** write_inst struct to hold the default value that the WAV ** module should hold. */ write_inst.detune = 0 ; write_inst.key_lo = write_inst.velocity_lo = 0 ; write_inst.key_hi = write_inst.velocity_hi = 127 ; write_inst.gain = 1 ; } ; if ((filetype & SF_FORMAT_TYPEMASK) == SF_FORMAT_XI) { /* ** For all the fields that XI doesn't support, modify the ** write_inst struct to hold the default value that the XI ** module should hold. */ write_inst.basenote = 0 ; write_inst.detune = 0 ; write_inst.key_lo = write_inst.velocity_lo = 0 ; write_inst.key_hi = write_inst.velocity_hi = 127 ; write_inst.gain = 1 ; } ; if (memcmp (&write_inst, &read_inst, sizeof (write_inst)) != 0) { printf ("\n\nLine %d : instrument comparison failed.\n\n", __LINE__) ; printf ("W Base Note : %u\n" " Detune : %u\n" " Low Note : %u\tHigh Note : %u\n" " Low Vel. : %u\tHigh Vel. : %u\n" " Gain : %d\tCount : %d\n" " mode : %d\n" " start : %d\tend : %d\tcount :%d\n" " mode : %d\n" " start : %d\tend : %d\tcount :%d\n\n", write_inst.basenote, write_inst.detune, write_inst.key_lo, write_inst.key_hi, write_inst.velocity_lo, write_inst.velocity_hi, write_inst.gain, write_inst.loop_count, write_inst.loops [0].mode, write_inst.loops [0].start, write_inst.loops [0].end, write_inst.loops [0].count, write_inst.loops [1].mode, write_inst.loops [1].start, write_inst.loops [1].end, write_inst.loops [1].count) ; printf ("R Base Note : %u\n" " Detune : %u\n" " Low Note : %u\tHigh Note : %u\n" " Low Vel. : %u\tHigh Vel. : %u\n" " Gain : %d\tCount : %d\n" " mode : %d\n" " start : %d\tend : %d\tcount :%d\n" " mode : %d\n" " start : %d\tend : %d\tcount :%d\n\n", read_inst.basenote, read_inst.detune, read_inst.key_lo, read_inst.key_hi, read_inst.velocity_lo, read_inst.velocity_hi, read_inst.gain, read_inst.loop_count, read_inst.loops [0].mode, read_inst.loops [0].start, read_inst.loops [0].end, read_inst.loops [0].count, read_inst.loops [1].mode, read_inst.loops [1].start, read_inst.loops [1].end, read_inst.loops [1].count) ; if ((filetype & SF_FORMAT_TYPEMASK) != SF_FORMAT_XI) exit (1) ; } ; if (0) instrumet_rw_test (filename) ; unlink (filename) ; puts ("ok") ; } /* instrument_test */
static void calc_peak_test (int filetype, const char *filename) { SNDFILE *file ; SF_INFO sfinfo ; int k, format ; double peak ; print_test_name ("calc_peak_test", filename) ; format = (filetype | SF_FORMAT_PCM_16) ; sfinfo.samplerate = 44100 ; sfinfo.format = format ; sfinfo.channels = 1 ; sfinfo.frames = BUFFER_LEN ; /* Create double_data with max value of 0.5. */ for (k = 0 ; k < BUFFER_LEN ; k++) double_data [k] = (k + 1) / (2.0 * BUFFER_LEN) ; file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ; test_write_double_or_die (file, 0, double_data, BUFFER_LEN, __LINE__) ; sf_close (file) ; file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ; if (sfinfo.format != format) { printf ("Line %d: Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__, format, sfinfo.format) ; exit (1) ; } ; if (sfinfo.frames != BUFFER_LEN) { printf ("\n\nLine %d: Incorrect number of.frames in file. (%d => %ld)\n", __LINE__, BUFFER_LEN, SF_COUNT_TO_LONG (sfinfo.frames)) ; exit (1) ; } ; if (sfinfo.channels != 1) { printf ("Line %d: Incorrect number of channels in file.\n", __LINE__) ; exit (1) ; } ; sf_command (file, SFC_CALC_SIGNAL_MAX, &peak, sizeof (peak)) ; if (fabs (peak - (1 << 14)) > 1.0) { printf ("Line %d : Peak value should be %d (is %f).\n", __LINE__, (1 << 14), peak) ; exit (1) ; } ; sf_command (file, SFC_CALC_NORM_SIGNAL_MAX, &peak, sizeof (peak)) ; if (fabs (peak - 0.5) > 4e-5) { printf ("Line %d : Peak value should be %f (is %f).\n", __LINE__, 0.5, peak) ; exit (1) ; } ; sf_close (file) ; format = (filetype | SF_FORMAT_FLOAT) ; sfinfo.samplerate = 44100 ; sfinfo.format = format ; sfinfo.channels = 1 ; sfinfo.frames = BUFFER_LEN ; /* Create double_data with max value of 0.5. */ for (k = 0 ; k < BUFFER_LEN ; k++) double_data [k] = (k + 1) / (2.0 * BUFFER_LEN) ; file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ; test_write_double_or_die (file, 0, double_data, BUFFER_LEN, __LINE__) ; sf_close (file) ; file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ; if (sfinfo.format != format) { printf ("Line %d: Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__, format, sfinfo.format) ; exit (1) ; } ; if (sfinfo.frames != BUFFER_LEN) { printf ("\n\nLine %d: Incorrect number of.frames in file. (%d => %ld)\n", __LINE__, BUFFER_LEN, SF_COUNT_TO_LONG (sfinfo.frames)) ; exit (1) ; } ; if (sfinfo.channels != 1) { printf ("Line %d: Incorrect number of channels in file.\n", __LINE__) ; exit (1) ; } ; sf_command (file, SFC_CALC_SIGNAL_MAX, &peak, sizeof (peak)) ; if (fabs (peak - 0.5) > 1e-5) { printf ("Line %d : Peak value should be %f (is %f).\n", __LINE__, 0.5, peak) ; exit (1) ; } ; sf_command (file, SFC_CALC_NORM_SIGNAL_MAX, &peak, sizeof (peak)) ; if (fabs (peak - 0.5) > 1e-5) { printf ("Line %d : Peak value should be %f (is %f).\n", __LINE__, 0.5, peak) ; exit (1) ; } ; sf_close (file) ; unlink (filename) ; printf ("ok\n") ; } /* calc_peak_test */
static void raw_needs_endswap_test (const char *filename, int filetype) { static int subtypes [] = { SF_FORMAT_FLOAT, SF_FORMAT_DOUBLE, SF_FORMAT_PCM_16, SF_FORMAT_PCM_24, SF_FORMAT_PCM_32 } ; SNDFILE *file ; SF_INFO sfinfo ; unsigned k ; int needs_endswap ; print_test_name (__func__, filename) ; for (k = 0 ; k < ARRAY_LEN (subtypes) ; k++) { if (filetype == (SF_ENDIAN_LITTLE | SF_FORMAT_AIFF)) switch (subtypes [k]) { /* Little endian AIFF does not AFAIK support fl32 and fl64. */ case SF_FORMAT_FLOAT : case SF_FORMAT_DOUBLE : continue ; default : break ; } ; memset (&sfinfo, 0, sizeof (sfinfo)) ; sfinfo.samplerate = 11025 ; sfinfo.format = filetype | subtypes [k] ; sfinfo.channels = 1 ; file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ; test_write_double_or_die (file, 0, double_data, BUFFER_LEN, __LINE__) ; sf_close (file) ; memset (&sfinfo, 0, sizeof (sfinfo)) ; file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ; needs_endswap = sf_command (file, SFC_RAW_DATA_NEEDS_ENDSWAP, NULL, 0) ; switch (filetype) { case SF_FORMAT_WAV : case SF_FORMAT_WAVEX : case SF_FORMAT_AIFF | SF_ENDIAN_LITTLE : exit_if_true (needs_endswap != CPU_IS_BIG_ENDIAN, "\n\nLine %d : SFC_RAW_DATA_NEEDS_ENDSWAP failed for (%d | %d).\n\n", __LINE__, filetype, k) ; break ; case SF_FORMAT_AIFF : case SF_FORMAT_WAV | SF_ENDIAN_BIG : exit_if_true (needs_endswap != CPU_IS_LITTLE_ENDIAN, "\n\nLine %d : SFC_RAW_DATA_NEEDS_ENDSWAP failed for (%d | %d).\n\n", __LINE__, filetype, k) ; break ; default : printf ("\n\nLine %d : bad format value %d.\n\n", __LINE__, filetype) ; exit (1) ; break ; } ; sf_close (file) ; } ; unlink (filename) ; puts ("ok") ; } /* raw_needs_endswap_test */
static void broadcast_coding_history_size (const char *filename) { /* SF_BROADCAST_INFO struct with coding_history field of 1024 bytes. */ static SF_BROADCAST_INFO_VAR (1024) bc_write ; static SF_BROADCAST_INFO_VAR (1024) bc_read ; SNDFILE *file ; SF_INFO sfinfo ; int k ; print_test_name (__func__, filename) ; sfinfo.samplerate = 22050 ; sfinfo.format = SF_FORMAT_WAV | SF_FORMAT_PCM_16 ; sfinfo.channels = 1 ; memset (&bc_write, 0, sizeof (bc_write)) ; snprintf (bc_write.description, sizeof (bc_write.description), "Test description") ; snprintf (bc_write.originator, sizeof (bc_write.originator), "Test originator") ; snprintf (bc_write.originator_reference, sizeof (bc_write.originator_reference), "%08x-%08x", (unsigned int) time (NULL), (unsigned int) (~ time (NULL))) ; snprintf (bc_write.origination_date, sizeof (bc_write.origination_date), "%d/%02d/%02d", 2006, 3, 30) ; snprintf (bc_write.origination_time, sizeof (bc_write.origination_time), "%02d:%02d:%02d", 20, 27, 0) ; snprintf (bc_write.umid, sizeof (bc_write.umid), "Some umid") ; bc_write.coding_history_size = 0 ; for (k = 0 ; bc_write.coding_history_size < 512 ; k++) { snprintf (bc_write.coding_history + bc_write.coding_history_size, sizeof (bc_write.coding_history) - bc_write.coding_history_size, "line %4d\n", k) ; bc_write.coding_history_size = strlen (bc_write.coding_history) ; } ; exit_if_true (bc_write.coding_history_size < 512, "\n\nLine %d : bc_write.coding_history_size (%d) should be > 512.\n\n", __LINE__, bc_write.coding_history_size) ; file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ; if (sf_command (file, SFC_SET_BROADCAST_INFO, &bc_write, sizeof (bc_write)) == SF_FALSE) { printf ("\n\nLine %d : sf_command (SFC_SET_BROADCAST_INFO) failed.\n\n", __LINE__) ; exit (1) ; } ; test_write_double_or_die (file, 0, double_data, BUFFER_LEN, __LINE__) ; sf_close (file) ; memset (&bc_read, 0, sizeof (bc_read)) ; file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ; if (sf_command (file, SFC_GET_BROADCAST_INFO, &bc_read, sizeof (bc_read)) == SF_FALSE) { printf ("\n\nLine %d : sf_command (SFC_SET_BROADCAST_INFO) failed.\n\n", __LINE__) ; exit (1) ; } ; check_log_buffer_or_die (file, __LINE__) ; sf_close (file) ; exit_if_true (bc_read.coding_history_size < 512, "\n\nLine %d : unexpected coding history size %d (should be > 512).\n\n", __LINE__, bc_read.coding_history_size) ; exit_if_true (strstr (bc_read.coding_history, "libsndfile") == NULL, "\n\nLine %d : coding history incomplete (should contain 'libsndfile').\n\n", __LINE__) ; unlink (filename) ; puts ("ok") ; } /* broadcast_coding_history_size */
static void broadcast_coding_history_test (const char *filename) { static SF_BROADCAST_INFO bc_write, bc_read ; SNDFILE *file ; SF_INFO sfinfo ; const char *default_history = "A=PCM,F=22050,W=16,M=mono" ; const char *supplied_history = "A=PCM,F=44100,W=24,M=mono,T=other\r\n" "A=PCM,F=22050,W=16,M=mono,T=yet_another\r\n" ; print_test_name ("broadcast_coding_history_test", filename) ; sfinfo.samplerate = 22050 ; sfinfo.format = SF_FORMAT_WAV | SF_FORMAT_PCM_16 ; sfinfo.channels = 1 ; memset (&bc_write, 0, sizeof (bc_write)) ; snprintf (bc_write.description, sizeof (bc_write.description), "Test description") ; snprintf (bc_write.originator, sizeof (bc_write.originator), "Test originator") ; snprintf (bc_write.originator_reference, sizeof (bc_write.originator_reference), "%08x-%08x", (unsigned int) time (NULL), (unsigned int) (~ time (NULL))) ; snprintf (bc_write.origination_date, sizeof (bc_write.origination_date), "%d/%02d/%02d", 2006, 3, 30) ; snprintf (bc_write.origination_time, sizeof (bc_write.origination_time), "%02d:%02d:%02d", 20, 27, 0) ; snprintf (bc_write.umid, sizeof (bc_write.umid), "Some umid") ; /* Coding history will be filled in by the library. */ bc_write.coding_history_size = 0 ; file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ; if (sf_command (file, SFC_SET_BROADCAST_INFO, &bc_write, sizeof (bc_write)) == SF_FALSE) { printf ("\n\nLine %d : sf_command (SFC_SET_BROADCAST_INFO) failed.\n\n", __LINE__) ; exit (1) ; } ; test_write_double_or_die (file, 0, double_data, BUFFER_LEN, __LINE__) ; sf_close (file) ; memset (&bc_read, 0, sizeof (bc_read)) ; file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ; if (sf_command (file, SFC_GET_BROADCAST_INFO, &bc_read, sizeof (bc_read)) == SF_FALSE) { printf ("\n\nLine %d : sf_command (SFC_SET_BROADCAST_INFO) failed.\n\n", __LINE__) ; exit (1) ; } ; check_log_buffer_or_die (file, __LINE__) ; sf_close (file) ; if (bc_read.coding_history_size == 0) { printf ("\n\nLine %d : missing coding history.\n\n", __LINE__) ; exit (1) ; } ; if (bc_read.coding_history_size < strlen (default_history) || memcmp (bc_read.coding_history, default_history, strlen (default_history)) != 0) { printf ("\n\n" "Line %d : unexpected coding history '%.*s',\n" " should be '%s'\n\n", __LINE__, bc_read.coding_history_size, bc_read.coding_history, default_history) ; exit (1) ; } ; bc_write.coding_history_size = strlen (supplied_history) ; bc_write.coding_history_size = snprintf (bc_write.coding_history, sizeof (bc_write.coding_history), "%s", supplied_history) ; file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ; if (sf_command (file, SFC_SET_BROADCAST_INFO, &bc_write, sizeof (bc_write)) == SF_FALSE) { printf ("\n\nLine %d : sf_command (SFC_SET_BROADCAST_INFO) failed.\n\n", __LINE__) ; exit (1) ; } ; test_write_double_or_die (file, 0, double_data, BUFFER_LEN, __LINE__) ; sf_close (file) ; memset (&bc_read, 0, sizeof (bc_read)) ; file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ; if (sf_command (file, SFC_GET_BROADCAST_INFO, &bc_read, sizeof (bc_read)) == SF_FALSE) { printf ("\n\nLine %d : sf_command (SFC_SET_BROADCAST_INFO) failed.\n\n", __LINE__) ; exit (1) ; } ; check_log_buffer_or_die (file, __LINE__) ; sf_close (file) ; if (strstr (bc_read.coding_history, supplied_history) != bc_read.coding_history) { printf ("\n\nLine %d : unexpected coding history :\n" "----------------------------------------------------\n%s" "----------------------------------------------------\n" "should be this :\n" "----------------------------------------------------\n%s" "----------------------------------------------------\n" "with one more line at the end.\n\n", __LINE__, bc_read.coding_history, supplied_history) ; exit (1) ; } ; check_coding_history_newlines (filename) ; unlink (filename) ; puts ("ok") ; } /* broadcast_coding_history_test */
static void test_float_peak (const char *filename, int filetype) { SNDFILE *file ; SF_INFO sfinfo ; int k, frames, count ; print_test_name ("test_float_peak", filename) ; memset (&sfinfo, 0, sizeof (sfinfo)) ; sfinfo.samplerate = 44100 ; sfinfo.format = filetype ; sfinfo.channels = 4 ; sfinfo.frames = 0 ; frames = BUFFER_LEN / sfinfo.channels ; /* Create some random data with a peak value of 0.66. */ for (k = 0 ; k < BUFFER_LEN ; k++) data [k] = (rand () % 2000) / 3000.0 ; /* Insert some larger peaks a know locations. */ data [4 * (frames / 8) + 0] = (frames / 8) * 0.01 ; /* First channel */ data [4 * (frames / 6) + 1] = (frames / 6) * 0.01 ; /* Second channel */ data [4 * (frames / 4) + 2] = (frames / 4) * 0.01 ; /* Third channel */ data [4 * (frames / 2) + 3] = (frames / 2) * 0.01 ; /* Fourth channel */ /* Write a file with PEAK chunks. */ file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, 0, __LINE__) ; /* Try to confuse the header writer by adding a removing the PEAK chunk. */ sf_command (file, SFC_SET_ADD_PEAK_CHUNK, NULL, SF_TRUE) ; sf_command (file, SFC_SET_ADD_PEAK_CHUNK, NULL, SF_FALSE) ; sf_command (file, SFC_SET_ADD_PEAK_CHUNK, NULL, SF_TRUE) ; /* Write the data in four passed. The data is designed so that peaks will ** be written in the different calls to sf_write_double (). */ for (count = 0 ; count < 4 ; count ++) test_write_double_or_die (file, 0, data + count * BUFFER_LEN / 4, BUFFER_LEN / 4, BUFFER_LEN / 4) ; sf_close (file) ; file = test_open_file_or_die (filename, SFM_READ, &sfinfo, 0, __LINE__) ; if (sfinfo.format != filetype) { printf ("\n\nLine %d: Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__, filetype, sfinfo.format) ; exit (1) ; } ; if (sfinfo.frames != frames) { printf ("\n\nLine %d: Incorrect number of frames in file. (%d => %ld)\n", __LINE__, frames, (long) sfinfo.frames) ; exit (1) ; } ; if (sfinfo.channels != 4) { printf ("\n\nLine %d: Incorrect number of channels in file.\n", __LINE__) ; exit (1) ; } ; /* Check these two commands. */ if (sf_command (file, SFC_GET_SIGNAL_MAX, data, sizeof (double)) == SF_FALSE) { printf ("\n\nLine %d: Command should have returned SF_TRUE.\n", __LINE__) ; exit (1) ; } ; if (fabs (data [0] - (frames / 2) * 0.01) > 0.01) { printf ("\n\nLine %d: Bad peak value (%f should be %f) for command SFC_GET_SIGNAL_MAX.\n", __LINE__, data [0], (frames / 2) * 0.01) ; exit (1) ; } ; if (sf_command (file, SFC_GET_MAX_ALL_CHANNELS, data, sizeof (double) * sfinfo.channels) == SF_FALSE) { printf ("\n\nLine %d: Command should have returned SF_TRUE.\n", __LINE__) ; exit (1) ; } ; if (fabs (data [3] - (frames / 2) * 0.01) > 0.01) { printf ("\n\nLine %d: Bad peak value (%f should be %f) for command SFC_GET_MAX_ALL_CHANNELS.\n", __LINE__, data [0], (frames / 2) * 0.01) ; exit (1) ; } ; /* Get the log buffer data. */ log_buffer [0] = 0 ; sf_command (file, SFC_GET_LOG_INFO, log_buffer, LOG_BUFFER_SIZE) ; if (strlen (log_buffer) == 0) { printf ("\n\nLine %d: Empty log buffer,\n", __LINE__) ; exit (1) ; } ; check_logged_peaks (log_buffer) ; sf_close (file) ; /* Write a file ***without*** PEAK chunks. */ file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, 0, __LINE__) ; /* Try to confuse the header writer by adding a removing the PEAK chunk. */ sf_command (file, SFC_SET_ADD_PEAK_CHUNK, NULL, SF_FALSE) ; sf_command (file, SFC_SET_ADD_PEAK_CHUNK, NULL, SF_TRUE) ; sf_command (file, SFC_SET_ADD_PEAK_CHUNK, NULL, SF_FALSE) ; /* Write the data in four passed. The data is designed so that peaks will ** be written in the different calls to sf_write_double (). */ for (count = 0 ; count < 4 ; count ++) test_write_double_or_die (file, 0, data + count * BUFFER_LEN / 4, BUFFER_LEN / 4, BUFFER_LEN / 4) ; sf_close (file) ; file = test_open_file_or_die (filename, SFM_READ, &sfinfo, 0, __LINE__) ; /* Check these two commands. */ if (sf_command (file, SFC_GET_SIGNAL_MAX, data, sizeof (double))) { printf ("\n\nLine %d: Command should have returned SF_FALSE.\n", __LINE__) ; exit (1) ; } ; if (sf_command (file, SFC_GET_MAX_ALL_CHANNELS, data, sizeof (double) * sfinfo.channels)) { printf ("\n\nLine %d: Command should have returned SF_FALSE.\n", __LINE__) ; exit (1) ; } ; /* Get the log buffer data. */ log_buffer [0] = 0 ; sf_command (file, SFC_GET_LOG_INFO, log_buffer, LOG_BUFFER_SIZE) ; if (strlen (log_buffer) == 0) { printf ("\n\nLine %d: Empty log buffer,\n", __LINE__) ; exit (1) ; } ; if (strstr (log_buffer, "PEAK :") != NULL) { printf ("\n\nLine %d: Should not have a PEAK chunk in this file.\n\n", __LINE__) ; puts (log_buffer) ; exit (1) ; } ; sf_close (file) ; unlink (filename) ; printf ("ok\n") ; } /* test_float_peak */