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 rw_test (const char *filename) { SNDFILE *file ; SF_INFO sfinfo_rd, sfinfo_rw ; memset (&sfinfo_rd, 0, sizeof (sfinfo_rd)) ; memset (&sfinfo_rw, 0, sizeof (sfinfo_rw)) ; /* Open the file in read only mode and fill in the SF_INFO struct. */ if ((file = sf_open (filename, SFM_READ, &sfinfo_rd)) == NULL) { printf ("\n\nLine %d : sf_open SFM_READ failed : %s\n\n", __LINE__, sf_strerror (NULL)) ; exit (1) ; } ; check_log_buffer_or_die (file, __LINE__) ; sf_close (file) ; /* Now open read/write and close the file. */ if ((file = sf_open (filename, SFM_RDWR, &sfinfo_rw)) == NULL) { printf ("\n\nLine %d : sf_open SFM_RDWR failed : %s\n\n", __LINE__, sf_strerror (NULL)) ; exit (1) ; } ; check_log_buffer_or_die (file, __LINE__) ; sf_close (file) ; /* Open again as read only again and fill in a new SF_INFO struct. */ memset (&sfinfo_rw, 0, sizeof (sfinfo_rw)) ; if ((file = sf_open (filename, SFM_READ, &sfinfo_rw)) == NULL) { printf ("\n\nLine %d : sf_open SFM_RDWR failed : %s\n\n", __LINE__, sf_strerror (NULL)) ; exit (1) ; } ; check_log_buffer_or_die (file, __LINE__) ; sf_close (file) ; /* Now compare the two. */ if (sfinfo_rd.format != sfinfo_rw.format) { printf ("\n\nLine %d : format mismatch (0x%08X != 0x%08X).\n\n", __LINE__, sfinfo_rd.format, sfinfo_rw.format) ; exit (1) ; } ; if (sfinfo_rd.channels != sfinfo_rw.channels) { printf ("\n\nLine %d : channel count mismatch (%d != %d).\n\n", __LINE__, sfinfo_rd.channels, sfinfo_rw.channels) ; exit (1) ; } ; if (sfinfo_rd.frames != sfinfo_rw.frames) { printf ("\n\nLine %d : frame count mismatch (rd %ld != rw %ld).\n\n", __LINE__, SF_COUNT_TO_LONG (sfinfo_rd.frames), SF_COUNT_TO_LONG (sfinfo_rw.frames)) ; exit (1) ; } ; return ; } /* rw_test */
static void large_free_test (const char *filename, int format, size_t chunk_size) { SNDFILE * file ; SF_INFO sfinfo ; SF_CHUNK_INFO chunk_info ; char chunk_data [20002] ; short audio [16] ; int err ; print_test_name (__func__, filename) ; exit_if_true (sizeof (chunk_data) <= chunk_size, "\n\nLine %d : sizeof (data) < chunk_size\n\n", __LINE__) ; memset (chunk_data, 53, sizeof (chunk_data)) ; chunk_data [chunk_size] = 0 ; sfinfo.samplerate = 44100 ; sfinfo.channels = 1 ; sfinfo.frames = 0 ; sfinfo.format = format ; file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ; /* Set up the chunk to write. */ memset (&chunk_info, 0, sizeof (chunk_info)) ; snprintf (chunk_info.id, sizeof (chunk_info.id), "free") ; chunk_info.id_size = 4 ; chunk_info.data = chunk_data ; chunk_info.datalen = chunk_size ; err = sf_set_chunk (file, &chunk_info) ; exit_if_true ( err != SF_ERR_NO_ERROR, "\n\nLine %d : sf_set_chunk returned for testdata : %s\n\n", __LINE__, sf_error_number (err) ) ; memset (chunk_info.data, 0, chunk_info.datalen) ; /* Add some audio data. */ memset (audio, 0, sizeof (audio)) ; sf_write_short (file, audio, ARRAY_LEN (audio)) ; sf_close (file) ; file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ; exit_if_true ( sfinfo.frames != ARRAY_LEN (audio), "\n\nLine %d : Incorrect sample count (%d should be %d)\n", __LINE__, (int) sfinfo.frames, (int) ARRAY_LEN (audio) ) ; if (chunk_size < 512) check_log_buffer_or_die (file, __LINE__) ; sf_close (file) ; unlink (filename) ; puts ("ok") ; } /* large_free_test */
static void headerless_test (const char * filename, int format, int expected) { static short buffer [BUFFER_SIZE] ; SNDFILE *file ; SF_INFO sfinfo ; int k ; format &= SF_FORMAT_SUBMASK ; print_test_name (__func__, filename) ; for (k = 0 ; k < BUFFER_SIZE ; k++) buffer [k] = k ; sfinfo.samplerate = 8000 ; sfinfo.frames = 0 ; sfinfo.channels = 1 ; sfinfo.format = SF_FORMAT_RAW | format ; file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ; if ((k = sf_write_short (file, buffer, BUFFER_SIZE)) != BUFFER_SIZE) { printf ("Line %d: sf_write_short failed with short write (%d => %d).\n", __LINE__, BUFFER_SIZE, k) ; fflush (stdout) ; puts (sf_strerror (file)) ; exit (1) ; } ; sf_close (file) ; memset (buffer, 0, sizeof (buffer)) ; /* We should be able to detect these so clear sfinfo. */ memset (&sfinfo, 0, sizeof (sfinfo)) ; file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ; if (sfinfo.format != expected) { printf ("Line %d: Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__, expected, sfinfo.format) ; exit (1) ; } ; if (sfinfo.frames < BUFFER_SIZE) { printf ("Line %d: Incorrect number of.frames in file. (%d => %ld)\n", __LINE__, BUFFER_SIZE, 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) ; } ; check_log_buffer_or_die (file, __LINE__) ; sf_close (file) ; printf ("ok\n") ; unlink (filename) ; } /* headerless_test */
static void string_short_rdwr_test (const char *filename, int typemajor) { SNDFILE *file ; SF_INFO sfinfo ; sf_count_t frames = BUFFER_LEN ; const char * str ; print_test_name (__func__, filename) ; memset (&sfinfo, 0, sizeof (sfinfo)) ; sfinfo.format = typemajor | SF_FORMAT_PCM_16 ; sfinfo.samplerate = 44100 ; sfinfo.channels = 1 ; sfinfo.frames = 0 ; file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_FALSE, __LINE__) ; /* Write data to file. */ test_write_short_or_die (file, 0, data_out, BUFFER_LEN, __LINE__) ; sf_set_string (file, SF_STR_TITLE, long_title) ; sf_set_string (file, SF_STR_ARTIST, long_artist) ; sf_close (file) ; /* Open the file RDWR. */ file = test_open_file_or_die (filename, SFM_RDWR, &sfinfo, SF_FALSE, __LINE__) ; exit_if_true (frames != sfinfo.frames, "\n\nLine %d : Frame count %" PRId64 " should be %" PRId64 ".\n", __LINE__, sfinfo.frames, frames) ; str = sf_get_string (file, SF_STR_TITLE) ; exit_if_true (str == NULL, "\n\nLine %d : SF_STR_TITLE string is NULL.\n", __LINE__) ; exit_if_true (strcmp (str, long_title) != 0, "\n\nLine %d : SF_STR_TITLE doesn't match what was written.\n", __LINE__) ; str = sf_get_string (file, SF_STR_ARTIST) ; exit_if_true (str == NULL, "\n\nLine %d : SF_STR_TITLE string is NULL.\n", __LINE__) ; exit_if_true (strcmp (str, long_artist) != 0, "\n\nLine %d : SF_STR_ARTIST doesn't match what was written.\n", __LINE__) ; /* Change title and artist. */ sf_set_string (file, SF_STR_TITLE, title) ; sf_set_string (file, SF_STR_ARTIST, artist) ; sf_close (file) ; file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_FALSE, __LINE__) ; check_log_buffer_or_die (file, __LINE__) ; str = sf_get_string (file, SF_STR_TITLE) ; exit_if_true (str == NULL, "\n\nLine %d : SF_STR_TITLE string is NULL.\n", __LINE__) ; exit_if_true (strcmp (str, title) != 0, "\n\nLine %d : SF_STR_TITLE doesn't match what was written.\n", __LINE__) ; str = sf_get_string (file, SF_STR_ARTIST) ; exit_if_true (str == NULL, "\n\nLine %d : SF_STR_ARTIST string is NULL.\n", __LINE__) ; exit_if_true (strcmp (str, artist) != 0, "\n\nLine %d : SF_STR_ARTIST doesn't match what was written.\n", __LINE__) ; sf_close (file) ; unlink (filename) ; puts ("ok") ; } /* string_short_rdwr_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 rf64_downgrade_test (const char *filename) { static short output [BUFFER_LEN] ; static short input [BUFFER_LEN] ; SNDFILE *file ; SF_INFO sfinfo ; unsigned k ; print_test_name (__func__, filename) ; sf_info_clear (&sfinfo) ; sfinfo.samplerate = 44100 ; sfinfo.frames = ARRAY_LEN (output) ; sfinfo.channels = 1 ; sfinfo.format = SF_FORMAT_RF64 | SF_FORMAT_PCM_16 ; file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ; exit_if_true (sf_command (file, SFC_RF64_AUTO_DOWNGRADE, NULL, SF_FALSE) != SF_FALSE, "\n\nLine %d: sf_command failed.\n", __LINE__) ; exit_if_true (sf_command (file, SFC_RF64_AUTO_DOWNGRADE, NULL, SF_TRUE) != SF_TRUE, "\n\nLine %d: sf_command failed.\n", __LINE__) ; test_write_short_or_die (file, 0, output, ARRAY_LEN (output), __LINE__) ; exit_if_true (sf_command (file, SFC_RF64_AUTO_DOWNGRADE, NULL, SF_FALSE) != SF_TRUE, "\n\nLine %d: sf_command failed.\n", __LINE__) ; exit_if_true (sf_command (file, SFC_RF64_AUTO_DOWNGRADE, NULL, SF_TRUE) != SF_TRUE, "\n\nLine %d: sf_command failed.\n", __LINE__) ; sf_close (file) ; memset (input, 0, sizeof (input)) ; sf_info_clear (&sfinfo) ; file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ; exit_if_true (sfinfo.format != (SF_FORMAT_WAVEX | SF_FORMAT_PCM_16), "\n\nLine %d: RF64 to WAV downgrade failed.\n", __LINE__) ; exit_if_true (sfinfo.frames != ARRAY_LEN (output), "\n\nLine %d: Incorrect number of frames in file (too short). (%d should be %d)\n", __LINE__, (int) sfinfo.frames, (int) ARRAY_LEN (output)) ; 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_short_or_die (file, 0, input, ARRAY_LEN (input), __LINE__) ; sf_close (file) ; for (k = 0 ; k < ARRAY_LEN (input) ; k++) exit_if_true (input [k] != output [k], "\n\nLine: %d: Error on input %d, expected %d, got %d\n", __LINE__, k, output [k], input [k]) ; puts ("ok") ; unlink (filename) ; return ; } /* rf64_downgrade_test */
static void rf64_long_file_downgrade_test (const char *filename) { static int output [BUFFER_LEN] ; static int input [1] = { 0 } ; SNDFILE *file ; SF_INFO sfinfo ; sf_count_t output_frames = 0 ; print_test_name (__func__, filename) ; sf_info_clear (&sfinfo) ; memset (output, 0, sizeof (output)) ; output [0] = 0x1020304 ; sfinfo.samplerate = 44100 ; sfinfo.frames = ARRAY_LEN (output) ; sfinfo.channels = 1 ; sfinfo.format = SF_FORMAT_RF64 | SF_FORMAT_PCM_32 ; file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ; exit_if_true (sf_command (file, SFC_RF64_AUTO_DOWNGRADE, NULL, SF_TRUE) != SF_TRUE, "\n\nLine %d: sf_command failed.\n", __LINE__) ; while (output_frames * sizeof (output [0]) < 0x100000000) { test_write_int_or_die (file, 0, output, ARRAY_LEN (output), __LINE__) ; output_frames += ARRAY_LEN (output) ; } ; sf_close (file) ; sf_info_clear (&sfinfo) ; file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ; exit_if_true (sfinfo.format != (SF_FORMAT_RF64 | SF_FORMAT_PCM_32), "\n\nLine %d: RF64 to WAV downgrade should have failed.\n", __LINE__) ; exit_if_true (sfinfo.channels != 1, "\n\nLine %d: Incorrect number of channels in file.\n", __LINE__) ; exit_if_true (sfinfo.frames != output_frames, "\n\nLine %d: Incorrect number of frames in file (%d should be %d).\n", __LINE__, (int) sfinfo.frames, (int) output_frames) ; /* Check that the first sample read is the same as the first written. */ test_read_int_or_die (file, 0, input, ARRAY_LEN (input), __LINE__) ; exit_if_true (input [0] != output [0], "\n\nLine %d: Bad first sample (0x%08x).\n", __LINE__, input [0]) ; check_log_buffer_or_die (file, __LINE__) ; sf_close (file) ; puts ("ok") ; unlink (filename) ; return ; } /* rf64_long_file_downgrade_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 wav_subchunk_test (size_t chunk_size) { SNDFILE * file ; SF_INFO sfinfo ; SF_CHUNK_INFO chunk_info ; char filename [256] ; char chunk_data [10240] ; short audio [16] ; int err, value ; snprintf (filename, sizeof (filename), "subchunk_%04d.wav", (int) chunk_size) ; print_test_name (__func__, filename) ; exit_if_true (sizeof (chunk_data) < chunk_size, "\n\nLine %d : sizeof (data) < chunk_size\n\n", __LINE__) ; memset (chunk_data, 53, sizeof (chunk_data)) ; chunk_data [chunk_size] = 0 ; /* Fill in the chunk data. */ value = MAKE_MARKER ('a', 'd', 't', 'l') ; memcpy (chunk_data, &value, sizeof (value)) ; value = MAKE_MARKER ('n', 'o', 't', 'e') ; memcpy (chunk_data + 4, &value, sizeof (value)) ; value = H2LE_32 (chunk_size - 12) ; memcpy (chunk_data + 8, &value, sizeof (value)) ; sfinfo.samplerate = 44100 ; sfinfo.channels = 1 ; sfinfo.frames = 0 ; sfinfo.format = SF_FORMAT_WAV | SF_FORMAT_PCM_16 ; file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ; /* Set up the chunk to write. */ memset (&chunk_info, 0, sizeof (chunk_info)) ; snprintf (chunk_info.id, sizeof (chunk_info.id), "LIST") ; chunk_info.id_size = 4 ; chunk_info.data = chunk_data ; chunk_info.datalen = chunk_size ; err = sf_set_chunk (file, &chunk_info) ; exit_if_true ( err != SF_ERR_NO_ERROR, "\n\nLine %d : sf_set_chunk returned for testdata : %s\n\n", __LINE__, sf_error_number (err) ) ; memset (chunk_info.data, 0, chunk_info.datalen) ; /* Add some audio data. */ memset (audio, 0, sizeof (audio)) ; sf_write_short (file, audio, ARRAY_LEN (audio)) ; sf_close (file) ; file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ; exit_if_true ( sfinfo.frames != ARRAY_LEN (audio), "\n\nLine %d : Incorrect sample count (%d should be %d)\n", __LINE__, (int) sfinfo.frames, (int) ARRAY_LEN (audio) ) ; if (chunk_size < 512) check_log_buffer_or_die (file, __LINE__) ; sf_close (file) ; unlink (filename) ; puts ("ok") ; } /* wav_subchunk_test */
static void old_test (void) { static short buffer [BUFFER_SIZE] ; SNDFILE *file ; SF_INFO sfinfo ; int k, filetype ; const char *filename = "headerless.wav" ; print_test_name (__func__, "") ; for (k = 0 ; k < BUFFER_SIZE ; k++) buffer [k] = k ; filetype = SF_FORMAT_WAV | SF_FORMAT_PCM_16 ; sfinfo.samplerate = 32000 ; sfinfo.frames = 123456789 ; /* Wrong length. Library should correct this on sf_close. */ sfinfo.channels = 1 ; sfinfo.format = filetype ; file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ; if ((k = sf_write_short (file, buffer, BUFFER_SIZE)) != BUFFER_SIZE) { printf ("Line %d: sf_write_short failed with short write (%d => %d).\n", __LINE__, BUFFER_SIZE, k) ; fflush (stdout) ; puts (sf_strerror (file)) ; exit (1) ; } ; sf_close (file) ; memset (buffer, 0, sizeof (buffer)) ; /* Read as RAW but get the bit width and endian-ness correct. */ sfinfo.format = filetype = SF_ENDIAN_LITTLE | SF_FORMAT_RAW | SF_FORMAT_PCM_16 ; file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ; if (sfinfo.format != filetype) { printf ("Line %d: Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__, filetype, sfinfo.format) ; exit (1) ; } ; if (sfinfo.frames < BUFFER_SIZE) { printf ("Line %d: Incorrect number of.frames in file. (%d => %ld)\n", __LINE__, BUFFER_SIZE, 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) ; } ; check_log_buffer_or_die (file, __LINE__) ; if ((k = sf_read_short (file, buffer, BUFFER_SIZE)) != BUFFER_SIZE) { printf ("Line %d: short read (%d).\n", __LINE__, k) ; exit (1) ; } ; for (k = 0 ; k < BUFFER_SIZE - 22 ; k++) if (buffer [k + 22] != k) { printf ("Line %d: Incorrect sample (#%d : 0x%x => 0x%x).\n", __LINE__, k, k, buffer [k]) ; exit (1) ; } ; sf_close (file) ; printf ("ok\n") ; unlink (filename) ; } /* old_test */
static void extra_header_test (const char *filename, int filetype) { SNDFILE *outfile ; SF_INFO sfinfo ; sf_count_t frames ; short buffer [8] ; int k = 0 ; print_test_name ("extra_header_test", filename) ; sfinfo.samplerate = 44100 ; sfinfo.format = (filetype | SF_FORMAT_PCM_16) ; sfinfo.channels = 1 ; memset (buffer, 0xA0, sizeof (buffer)) ; /* Now write some frames. */ frames = ARRAY_LEN (buffer) / sfinfo.channels ; /* Test the file with extra header data. */ outfile = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, 464) ; sf_set_string (outfile, SF_STR_TITLE, filename) ; test_writef_short_or_die (outfile, k, buffer, frames, 466) ; sf_set_string (outfile, SF_STR_COPYRIGHT, "(c) 1980 Erik") ; sf_close (outfile) ; #if 1 /* ** Erik de Castro Lopo <*****@*****.**> May 23 2004. ** ** This file has extra string data in the header and therefore cannot ** currently be opened in SFM_RDWR mode. This is fixable, but its in ** a part of the code I don't want to fiddle with until the Ogg/Vorbis ** integration is done. */ if (sf_open (filename, SFM_RDWR, &sfinfo) != NULL) { printf ("\n\nError : should not be able to open this file in SFM_RDWR.\n\n") ; exit (1) ; } ; unlink (filename) ; puts ("ok") ; return ; #else hexdump_file (filename, 0, 100000) ; /* Open again for read/write. */ outfile = test_open_file_or_die (filename, SFM_RDWR, &sfinfo, 493) ; /* ** 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 = 1 ; k < 6 ; k++) { printf ("\n*** pass %d\n", k) ; memset (buffer, 0xA0 + k, sizeof (buffer)) ; test_seek_or_die (outfile, k * frames, SEEK_SET, k * frames, sfinfo.channels, 514) ; test_seek_or_die (outfile, 0, SEEK_END, k * frames, sfinfo.channels, 515) ; /* Open file again and make sure no errors in log buffer. */ if (0) { infile = test_open_file_or_die (filename, SFM_READ, &sfinfo, 519) ; check_log_buffer_or_die (infile, 520) ; sf_close (infile) ; } ; if (sfinfo.frames != k * frames) { printf ("\n\nLine %d : Incorrect sample count (%ld should be %ld)\n", 525, SF_COUNT_TO_LONG (sfinfo.frames), SF_COUNT_TO_LONG (k + frames)) ; dump_log_buffer (infile) ; exit (1) ; } ; if ((k & 1) == 0) test_write_short_or_die (outfile, k, buffer, sfinfo.channels * frames, 531) ; else test_writef_short_or_die (outfile, k, buffer, frames, 533) ; hexdump_file (filename, 0, 100000) ; } ; sf_close (outfile) ; unlink (filename) ; puts ("ok") ; return ; #endif } /* extra_header_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 update_header_sub (const char *filename, int typemajor, int write_mode) { SNDFILE *outfile, *infile ; SF_INFO sfinfo ; int k, frames ; sfinfo.samplerate = 44100 ; sfinfo.format = (typemajor | SF_FORMAT_PCM_16) ; sfinfo.channels = 1 ; sfinfo.frames = 0 ; frames = BUFFER_LEN / sfinfo.channels ; outfile = test_open_file_or_die (filename, write_mode, &sfinfo, SF_TRUE, __LINE__) ; for (k = 0 ; k < BUFFER_LEN ; k++) data_out [k] = k + 1 ; test_write_int_or_die (outfile, 0, data_out, BUFFER_LEN, __LINE__) ; if (typemajor != SF_FORMAT_HTK) { /* The HTK header is not correct when the file is first written. */ infile = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ; sf_close (infile) ; } ; sf_command (outfile, SFC_UPDATE_HEADER_NOW, NULL, 0) ; /* ** Open file and check log buffer for an error. If header update failed ** the the log buffer will contain errors. */ infile = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ; check_log_buffer_or_die (infile, __LINE__) ; if (sfinfo.frames < BUFFER_LEN || sfinfo.frames > BUFFER_LEN + 50) { printf ("\n\nLine %d : Incorrect sample count (%ld should be %d)\n", __LINE__, SF_COUNT_TO_LONG (sfinfo.frames), BUFFER_LEN) ; dump_log_buffer (infile) ; exit (1) ; } ; test_read_int_or_die (infile, 0, data_in, BUFFER_LEN, __LINE__) ; for (k = 0 ; k < BUFFER_LEN ; k++) if (data_out [k] != k + 1) printf ("Error : line %d\n", __LINE__) ; sf_close (infile) ; /* Set auto update on. */ sf_command (outfile, SFC_SET_UPDATE_HEADER_AUTO, NULL, SF_TRUE) ; /* Write more data_out. */ for (k = 0 ; k < BUFFER_LEN ; k++) data_out [k] = k + 2 ; test_write_int_or_die (outfile, 0, data_out, BUFFER_LEN, __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__) ; if (sfinfo.frames < 2 * BUFFER_LEN || sfinfo.frames > 2 * BUFFER_LEN + 50) { printf ("\n\nLine %d : Incorrect sample count (%ld should be %d)\n", __LINE__, SF_COUNT_TO_LONG (sfinfo.frames), 2 * BUFFER_LEN) ; dump_log_buffer (infile) ; exit (1) ; } ; sf_close (infile) ; sf_close (outfile) ; unlink (filename) ; } /* update_header_sub */
static void raw_offset_test (const char *filename, int typeminor) { SNDFILE *sndfile ; SF_INFO sfinfo ; sf_count_t start ; int k ; print_test_name ("raw_offset_test", filename) ; sfinfo.samplerate = 44100 ; sfinfo.format = SF_FORMAT_RAW | typeminor ; sfinfo.channels = 1 ; sfinfo.frames = 0 ; sndfile = test_open_file_or_die (filename, SFM_RDWR, &sfinfo, SF_TRUE, __LINE__) ; start = 0 ; sf_command (sndfile, SFC_FILE_TRUNCATE, &start, sizeof (start)) ; for (k = 0 ; k < BUFFER_LEN ; k++) data [k] = k ; test_write_short_or_die (sndfile, 0, data, BUFFER_LEN, __LINE__) ; sf_close (sndfile) ; sndfile = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ; check_log_buffer_or_die (sndfile, __LINE__) ; if (ABS (BUFFER_LEN - sfinfo.frames) > 1) { printf ("\n\nLine %d : Incorrect sample count (%" PRId64 " should be %d)\n", __LINE__, sfinfo.frames, BUFFER_LEN) ; dump_log_buffer (sndfile) ; exit (1) ; } ; memset (data, 0 , sizeof (data)) ; test_read_short_or_die (sndfile, 0, data, BUFFER_LEN, __LINE__) ; for (k = 0 ; k < BUFFER_LEN ; k++) if (data [k] != k) printf ("Error : line %d\n", __LINE__) ; /* Set dataoffset to 2 bytes from beginning of file. */ start = 2 ; sf_command (sndfile, SFC_SET_RAW_START_OFFSET, &start, sizeof (start)) ; /* Seek to new start */ test_seek_or_die (sndfile, 0, SEEK_SET, 0, sfinfo.channels, __LINE__) ; memset (data, 0 , sizeof (data)) ; test_read_short_or_die (sndfile, 0, data, BUFFER_LEN - 1, __LINE__) ; for (k = 0 ; k < BUFFER_LEN - 1 ; k++) if (data [k] != k + 1) { printf ("Error : line %d\n", __LINE__) ; exit (1) ; } ; /* Set dataoffset to 4 bytes from beginning of file. */ start = 4 ; sf_command (sndfile, SFC_SET_RAW_START_OFFSET, &start, sizeof (start)) ; /* Seek to new start */ test_seek_or_die (sndfile, 0, SEEK_SET, 0, sfinfo.channels, __LINE__) ; memset (data, 0 , sizeof (data)) ; test_read_short_or_die (sndfile, 0, data, BUFFER_LEN - 2, __LINE__) ; for (k = 0 ; k < BUFFER_LEN - 2 ; k++) if (data [k] != k + 2) { printf ("Error : line %d\n", __LINE__) ; exit (1) ; } ; /* Set dataoffset back to 0 bytes from beginning of file. */ start = 0 ; sf_command (sndfile, SFC_SET_RAW_START_OFFSET, &start, sizeof (start)) ; /* Seek to new start */ test_seek_or_die (sndfile, 0, SEEK_SET, 0, sfinfo.channels, __LINE__) ; memset (data, 0 , sizeof (data)) ; test_read_short_or_die (sndfile, 0, data, BUFFER_LEN, __LINE__) ; for (k = 0 ; k < BUFFER_LEN ; k++) if (data [k] != k) { printf ("Error : line %d\n", __LINE__) ; exit (1) ; } ; sf_close (sndfile) ; unlink (filename) ; puts ("ok") ; } /* raw_offset_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 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 string_start_end_test (const char *filename, int typemajor) { const char *cptr ; SNDFILE *file ; SF_INFO sfinfo ; int errors = 0 ; print_test_name ("string_start_end_test", filename) ; memset (&sfinfo, 0, sizeof (sfinfo)) ; sfinfo.samplerate = 44100 ; sfinfo.channels = 1 ; sfinfo.frames = 0 ; sfinfo.format = typemajor | SF_FORMAT_PCM_16 ; file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ; /* Write stuff at start of file. */ sf_set_string (file, SF_STR_TITLE, filename) ; sf_set_string (file, SF_STR_SOFTWARE, software) ; sf_set_string (file, SF_STR_ARTIST, artist) ; sf_set_string (file, SF_STR_GENRE, genre) ; sf_set_string (file, SF_STR_TRACKNUMBER, trackno) ; /* Write data to file. */ test_write_short_or_die (file, 0, data_out, BUFFER_LEN, __LINE__) ; test_seek_or_die (file, 0, SEEK_SET, 0, sfinfo.channels, __LINE__) ; /* Write more stuff at end of file. */ sf_set_string (file, SF_STR_COPYRIGHT, copyright) ; sf_set_string (file, SF_STR_COMMENT, comment) ; sf_set_string (file, SF_STR_DATE, date) ; sf_set_string (file, SF_STR_ALBUM, album) ; sf_set_string (file, SF_STR_LICENSE, license) ; sf_close (file) ; file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ; check_log_buffer_or_die (file, __LINE__) ; if (sfinfo.frames != BUFFER_LEN) { printf ("***** Bad frame count %d (should be %d)\n\n", (int) sfinfo.frames, BUFFER_LEN) ; errors ++ ; } ; cptr = sf_get_string (file, SF_STR_TITLE) ; if (cptr == NULL || strcmp (filename, cptr) != 0) { if (errors++ == 0) puts ("\n") ; printf (" Bad filename : %s\n", cptr) ; } ; cptr = sf_get_string (file, SF_STR_COPYRIGHT) ; if (cptr == NULL || strcmp (copyright, cptr) != 0) { if (errors++ == 0) puts ("\n") ; printf (" Bad copyright : %s\n", cptr) ; } ; cptr = sf_get_string (file, SF_STR_SOFTWARE) ; if (cptr == NULL || strstr (cptr, software) != cptr) { if (errors++ == 0) puts ("\n") ; printf (" Bad software : %s\n", cptr) ; } ; if (str_count (cptr, "libsndfile") != 1) { if (errors++ == 0) puts ("\n") ; printf (" Bad software : %s\n", cptr) ; } ; cptr = sf_get_string (file, SF_STR_ARTIST) ; if (cptr == NULL || strcmp (artist, cptr) != 0) { if (errors++ == 0) puts ("\n") ; printf (" Bad artist : %s\n", cptr) ; } ; cptr = sf_get_string (file, SF_STR_COMMENT) ; if (cptr == NULL || strcmp (comment, cptr) != 0) { if (errors++ == 0) puts ("\n") ; printf (" Bad comment : %s\n", cptr) ; } ; if (typemajor != SF_FORMAT_AIFF) { cptr = sf_get_string (file, SF_STR_DATE) ; if (cptr == NULL || strcmp (date, cptr) != 0) { if (errors++ == 0) puts ("\n") ; printf (" Bad date : %s\n", cptr) ; } ; cptr = sf_get_string (file, SF_STR_GENRE) ; if (cptr == NULL || strcmp (genre, cptr) != 0) { if (errors++ == 0) puts ("\n") ; printf (" Bad genre : %s\n", cptr) ; } ; } ; switch (typemajor) { case SF_FORMAT_AIFF : case SF_FORMAT_WAV : case SF_FORMAT_WAVEX : case SF_ENDIAN_BIG | SF_FORMAT_WAV : case SF_FORMAT_RF64 : /* These formats do not support the following. */ break ; default : cptr = sf_get_string (file, SF_STR_ALBUM) ; if (cptr == NULL || strcmp (album, cptr) != 0) { if (errors++ == 0) puts ("\n") ; printf (" Bad album : %s\n", cptr) ; } ; cptr = sf_get_string (file, SF_STR_LICENSE) ; if (cptr == NULL || strcmp (license, cptr) != 0) { if (errors++ == 0) puts ("\n") ; printf (" Bad license : %s\n", cptr) ; } ; cptr = sf_get_string (file, SF_STR_TRACKNUMBER) ; if (cptr == NULL || strcmp (trackno, cptr) != 0) { if (errors++ == 0) puts ("\n") ; printf (" Bad track no. : %s\n", cptr) ; } ; break ; } ; if (errors > 0) { printf ("\n*** Error count : %d ***\n\n", errors) ; dump_log_buffer (file) ; exit (1) ; } ; sf_close (file) ; unlink (filename) ; puts ("ok") ; } /* string_start_end_test */
static void string_start_test (const char *filename, int formattype) { const char *cptr ; SNDFILE *file ; SF_INFO sfinfo ; int errors = 0 ; int typemajor = SF_FORMAT_TYPEMASK & formattype ; print_test_name ("string_start_test", filename) ; memset (&sfinfo, 0, sizeof (sfinfo)) ; sfinfo.samplerate = 44100 ; sfinfo.channels = 1 ; sfinfo.frames = 0 ; switch (formattype) { case SF_FORMAT_OGG | SF_FORMAT_OPUS : /* Opus only supports some discrete sample rates. */ sfinfo.samplerate = 48000 ; break ; case SF_FORMAT_OGG | SF_FORMAT_VORBIS : break ; default : formattype |= SF_FORMAT_PCM_16 ; break ; } ; sfinfo.format = formattype ; file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ; /* Write stuff at start of file. */ sf_set_string (file, SF_STR_TITLE, filename) ; sf_set_string (file, SF_STR_SOFTWARE, software) ; sf_set_string (file, SF_STR_ARTIST, artist) ; sf_set_string (file, SF_STR_COPYRIGHT, copyright) ; sf_set_string (file, SF_STR_COMMENT, comment) ; sf_set_string (file, SF_STR_DATE, date) ; sf_set_string (file, SF_STR_ALBUM, album) ; sf_set_string (file, SF_STR_LICENSE, license) ; /* Write data to file. */ test_write_short_or_die (file, 0, data_out, BUFFER_LEN, __LINE__) ; sf_close (file) ; file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ; check_log_buffer_or_die (file, __LINE__) ; if (sfinfo.frames != BUFFER_LEN) { printf ("***** Bad frame count %d (should be %d)\n\n", (int) sfinfo.frames, BUFFER_LEN) ; errors ++ ; } ; cptr = sf_get_string (file, SF_STR_TITLE) ; if (cptr == NULL || strcmp (filename, cptr) != 0) { if (errors++ == 0) puts ("\n") ; printf (" Bad filename : %s\n", cptr) ; } ; cptr = sf_get_string (file, SF_STR_COPYRIGHT) ; if (cptr == NULL || strcmp (copyright, cptr) != 0) { if (errors++ == 0) puts ("\n") ; printf (" Bad copyright : %s\n", cptr) ; } ; cptr = sf_get_string (file, SF_STR_SOFTWARE) ; if (cptr == NULL || strstr (cptr, software) != cptr) { if (errors++ == 0) puts ("\n") ; printf (" Bad software : %s\n", cptr) ; } ; if (cptr && str_count (cptr, "libsndfile") != 1) { if (errors++ == 0) puts ("\n") ; printf (" Bad software : %s\n", cptr) ; } ; cptr = sf_get_string (file, SF_STR_ARTIST) ; if (cptr == NULL || strcmp (artist, cptr) != 0) { if (errors++ == 0) puts ("\n") ; printf (" Bad artist : %s\n", cptr) ; } ; cptr = sf_get_string (file, SF_STR_COMMENT) ; if (cptr == NULL || strcmp (comment, cptr) != 0) { if (errors++ == 0) puts ("\n") ; printf (" Bad comment : %s\n", cptr) ; } ; if (typemajor != SF_FORMAT_AIFF) { cptr = sf_get_string (file, SF_STR_DATE) ; if (cptr == NULL || strcmp (date, cptr) != 0) { if (errors++ == 0) puts ("\n") ; printf (" Bad date : %s\n", cptr) ; } ; } ; if (typemajor != SF_FORMAT_WAV && typemajor != SF_FORMAT_AIFF) { cptr = sf_get_string (file, SF_STR_ALBUM) ; if (cptr == NULL || strcmp (album, cptr) != 0) { if (errors++ == 0) puts ("\n") ; printf (" Bad album : %s\n", cptr) ; } ; } ; if (typemajor != SF_FORMAT_WAV && typemajor != SF_FORMAT_AIFF && typemajor != SF_FORMAT_RF64) { cptr = sf_get_string (file, SF_STR_LICENSE) ; if (cptr == NULL || strcmp (license, cptr) != 0) { if (errors++ == 0) puts ("\n") ; printf (" Bad license : %s\n", cptr) ; } ; } ; if (errors > 0) { printf ("\n*** Error count : %d ***\n\n", errors) ; dump_log_buffer (file) ; exit (1) ; } ; sf_close (file) ; unlink (filename) ; puts ("ok") ; } /* string_start_test */
static void update_header_test (char *filename, int typemajor) { SNDFILE *outfile, *infile ; SF_INFO sfinfo ; int k, frames ; printf (" update_header_test : %s ", filename) ; fflush (stdout) ; k = abs (18 - strlen (filename)) ; PUT_DOTS (k) ; sfinfo.samplerate = 44100 ; sfinfo.format = (typemajor | SF_FORMAT_PCM_16) ; sfinfo.channels = 1 ; sfinfo.frames = 0 ; frames = BUFFER_LEN / sfinfo.channels ; outfile = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, __LINE__) ; for (k = 0 ; k < BUFFER_LEN ; k++) data_out [k] = k + 1 ; test_write_short_or_die (outfile, 0, data_out, BUFFER_LEN, __LINE__) ; infile = test_open_file_or_die (filename, SFM_READ, &sfinfo, __LINE__) ; sf_close (infile) ; sf_command (outfile, SFC_UPDATE_HEADER_NOW, NULL, 0) ; /* Open file and check log buffer for an error. If header update failed ** the the log buffer will contain errors. */ infile = test_open_file_or_die (filename, SFM_READ, &sfinfo, __LINE__) ; check_log_buffer_or_die (infile) ; if (abs (BUFFER_LEN - sfinfo.frames) > 1) { printf ("\n\nLine %d : Incorrect sample count (%ld should be %d)\n", __LINE__, SF_COUNT_TO_LONG (sfinfo.frames), BUFFER_LEN) ; dump_log_buffer (infile) ; exit (1) ; } ; test_read_short_or_die (infile, 0, data_in, BUFFER_LEN, __LINE__) ; for (k = 0 ; k < BUFFER_LEN ; k++) if (data_out [k] != k + 1) printf ("Error : line %d\n", __LINE__) ; sf_close (infile) ; /* Set auto update on. */ sf_command (outfile, SFC_SET_UPDATE_HEADER_AUTO, NULL, SF_TRUE) ; /* Write more data_out. */ for (k = 0 ; k < BUFFER_LEN ; k++) data_out [k] = k + 2 ; test_write_short_or_die (outfile, 0, data_out, BUFFER_LEN, __LINE__) ; /* Open file again and make sure no errors in log buffer. */ infile = test_open_file_or_die (filename, SFM_READ, &sfinfo, __LINE__) ; check_log_buffer_or_die (infile) ; if (abs (2 * BUFFER_LEN - sfinfo.frames) > 1) { printf ("\n\nLine %d : Incorrect sample count (%ld should be %d)\n", __LINE__, SF_COUNT_TO_LONG (sfinfo.frames), 2 * BUFFER_LEN) ; dump_log_buffer (infile) ; exit (1) ; } ; sf_close (infile) ; sf_close (outfile) ; unlink (filename) ; puts ("ok") ; } /* update_header_test */
static void lcomp_test_int (const char *str, const char *filename, int filetype, double margin) { SNDFILE *file ; SF_INFO sfinfo ; int k, m, *orig, *data, sum_abs ; long datalen, seekpos ; double scale ; printf ("\nThis is program is not part of the libsndfile test suite.\n\n") ; printf (" lcomp_test_int : %s ... ", str) ; fflush (stdout) ; datalen = BUFFER_SIZE ; scale = 1.0 * 0x10000 ; data = data_buffer.i ; orig = orig_buffer.i ; gen_signal_double (orig_buffer.d, 32000.0 * scale, datalen) ; for (k = 0 ; k < datalen ; k++) orig [k] = orig_buffer.d [k] ; sfinfo.samplerate = SAMPLE_RATE ; sfinfo.frames = 123456789 ; /* Ridiculous value. */ sfinfo.channels = 1 ; sfinfo.format = filetype ; if (! (file = sf_open (filename, SFM_WRITE, &sfinfo))) { printf ("sf_open_write failed with error : ") ; puts (sf_strerror (NULL)) ; exit (1) ; } ; if ((k = sf_writef_int (file, orig, datalen)) != datalen) { printf ("sf_writef_int failed with short write (%ld => %d).\n", datalen, k) ; exit (1) ; } ; sf_close (file) ; memset (data, 0, datalen * sizeof (int)) ; if ((filetype & SF_FORMAT_TYPEMASK) != SF_FORMAT_RAW) memset (&sfinfo, 0, sizeof (sfinfo)) ; if (! (file = sf_open (filename, SFM_READ, &sfinfo))) { printf ("sf_open_read failed with error : ") ; puts (sf_strerror (NULL)) ; exit (1) ; } ; if ((sfinfo.format & (SF_FORMAT_TYPEMASK | SF_FORMAT_SUBMASK)) != (filetype & (SF_FORMAT_TYPEMASK | SF_FORMAT_SUBMASK))) { printf ("Line %d: Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__, filetype, sfinfo.format) ; exit (1) ; } ; if (sfinfo.frames < datalen) { printf ("Too few.frames in file. (%ld should be a little more than %ld)\n", datalen, SF_COUNT_TO_LONG (sfinfo.frames)) ; exit (1) ; } ; if (sfinfo.frames > (datalen + datalen / 2)) { printf ("Too many.frames in file. (%ld should be a little more than %ld)\n", datalen, SF_COUNT_TO_LONG (sfinfo.frames)) ; exit (1) ; } ; if (sfinfo.channels != 1) { printf ("Incorrect number of channels in file.\n") ; exit (1) ; } ; check_log_buffer_or_die (file, __LINE__) ; if ((k = sf_readf_int (file, data, datalen)) != datalen) { printf ("Line %d: short read (%d should be %ld).\n", __LINE__, k, datalen) ; exit (1) ; } ; sum_abs = 0 ; for (k = 0 ; k < datalen ; k++) { if (error_function (data [k] / scale, orig [k] / scale, margin)) { printf ("Line %d: Incorrect sample (#%d : %f should be %f).\n", __LINE__, k, data [k] / scale, orig [k] / scale) ; oct_save_int (orig, data, datalen) ; exit (1) ; } ; sum_abs = abs (sum_abs + abs (data [k])) ; } ; if (sum_abs < 1.0) { printf ("Line %d: Signal is all zeros.\n", __LINE__) ; exit (1) ; } ; if ((k = sf_readf_int (file, data, datalen)) != sfinfo.frames - datalen) { printf ("Line %d: Incorrect read length (%ld should be %d).\n", __LINE__, SF_COUNT_TO_LONG (sfinfo.frames - datalen), k) ; exit (1) ; } ; /* This check is only for block based encoders which must append silence ** to the end of a file so as to fill out a block. */ if ((sfinfo.format & SF_FORMAT_SUBMASK) != SF_FORMAT_MS_ADPCM) for (k = 0 ; k < sfinfo.frames - datalen ; k++) if (abs (data [k] / scale) > decay_response (k)) { printf ("Line %d : Incorrect sample B (#%d : abs (%d) should be < %d).\n", __LINE__, k, data [k], decay_response (k)) ; exit (1) ; } ; if (! sfinfo.seekable) { printf ("ok\n") ; return ; } ; /* Now test sf_seek function. */ if ((k = sf_seek (file, 0, SEEK_SET)) != 0) { printf ("Line %d: Seek to start of file failed (%d).\n", __LINE__, k) ; exit (1) ; } ; for (m = 0 ; m < 3 ; m++) { int n ; if ((k = sf_readf_int (file, data, 11)) != 11) { printf ("Line %d: Incorrect read length (11 => %d).\n", __LINE__, k) ; exit (1) ; } ; for (k = 0 ; k < 11 ; k++) if (error_function (data [k] / scale, orig [k + m * 11] / scale, margin)) { printf ("Line %d: Incorrect sample (m = %d) (#%d : %d => %d).\n", __LINE__, m, k + m * 11, orig [k + m * 11], data [k]) ; for (n = 0 ; n < 1 ; n++) printf ("%d ", data [n]) ; printf ("\n") ; exit (1) ; } ; } ; seekpos = BUFFER_SIZE / 10 ; /* Check seek from start of file. */ if ((k = sf_seek (file, seekpos, SEEK_SET)) != seekpos) { printf ("Seek to start of file + %ld failed (%d).\n", seekpos, k) ; exit (1) ; } ; if ((k = sf_readf_int (file, data, 1)) != 1) { printf ("Line %d: sf_readf_int (file, data, 1) returned %d.\n", __LINE__, k) ; exit (1) ; } ; if (error_function ((double) data [0], (double) orig [seekpos], margin)) { printf ("Line %d: sf_seek (SEEK_SET) followed by sf_readf_int failed (%d, %d).\n", __LINE__, orig [1], data [0]) ; exit (1) ; } ; if ((k = sf_seek (file, 0, SEEK_CUR)) != seekpos + 1) { printf ("Line %d: sf_seek (SEEK_CUR) with 0 offset failed (%d should be %ld)\n", __LINE__, k, seekpos + 1) ; exit (1) ; } ; seekpos = sf_seek (file, 0, SEEK_CUR) + BUFFER_SIZE / 5 ; k = sf_seek (file, BUFFER_SIZE / 5, SEEK_CUR) ; sf_readf_int (file, data, 1) ; if (error_function ((double) data [0], (double) orig [seekpos], margin) || k != seekpos) { printf ("Line %d: sf_seek (forwards, SEEK_CUR) followed by sf_readf_int failed (%d, %d) (%d, %ld).\n", __LINE__, data [0], orig [seekpos], k, seekpos + 1) ; exit (1) ; } ; seekpos = sf_seek (file, 0, SEEK_CUR) - 20 ; /* Check seek backward from current position. */ k = sf_seek (file, -20, SEEK_CUR) ; sf_readf_int (file, data, 1) ; if (error_function ((double) data [0], (double) orig [seekpos], margin) || k != seekpos) { printf ("sf_seek (backwards, SEEK_CUR) followed by sf_readf_int failed (%d, %d) (%d, %ld).\n", data [0], orig [seekpos], k, seekpos) ; exit (1) ; } ; /* Check that read past end of file returns number of items. */ sf_seek (file, (int) sfinfo.frames, SEEK_SET) ; if ((k = sf_readf_int (file, data, datalen)) != 0) { printf ("Line %d: Return value from sf_readf_int past end of file incorrect (%d).\n", __LINE__, k) ; exit (1) ; } ; /* Check seek backward from end. */ if ((k = sf_seek (file, 5 - (int) sfinfo.frames, SEEK_END)) != 5) { printf ("sf_seek (SEEK_END) returned %d instead of %d.\n", k, 5) ; exit (1) ; } ; sf_readf_int (file, data, 1) ; if (error_function (data [0] / scale, orig [5] / scale, margin)) { printf ("Line %d: sf_seek (SEEK_END) followed by sf_readf_short failed (%d should be %d).\n", __LINE__, data [0], orig [5]) ; exit (1) ; } ; sf_close (file) ; printf ("ok\n") ; } /* lcomp_test_int */