cannam@85: /* cannam@85: ** Copyright (C) 2001-2011 Erik de Castro Lopo cannam@85: ** cannam@85: ** This program is free software; you can redistribute it and/or modify cannam@85: ** it under the terms of the GNU General Public License as published by cannam@85: ** the Free Software Foundation; either version 2 of the License, or cannam@85: ** (at your option) any later version. cannam@85: ** cannam@85: ** This program is distributed in the hope that it will be useful, cannam@85: ** but WITHOUT ANY WARRANTY; without even the implied warranty of cannam@85: ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the cannam@85: ** GNU General Public License for more details. cannam@85: ** cannam@85: ** You should have received a copy of the GNU General Public License cannam@85: ** along with this program; if not, write to the Free Software cannam@85: ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. cannam@85: */ cannam@85: cannam@85: #include "sfconfig.h" cannam@85: cannam@85: #include cannam@85: #include cannam@85: #include cannam@85: #include cannam@85: cannam@85: #if HAVE_UNISTD_H cannam@85: #include cannam@85: #endif cannam@85: cannam@85: #include cannam@85: cannam@85: #include cannam@85: cannam@85: #include "utils.h" cannam@85: cannam@85: #define BUFFER_LEN (1<<10) cannam@85: #define LOG_BUFFER_SIZE 1024 cannam@85: cannam@85: static void float_norm_test (const char *filename) ; cannam@85: static void double_norm_test (const char *filename) ; cannam@85: static void format_tests (void) ; cannam@85: static void calc_peak_test (int filetype, const char *filename) ; cannam@85: static void truncate_test (const char *filename, int filetype) ; cannam@85: static void instrument_test (const char *filename, int filetype) ; cannam@85: static void channel_map_test (const char *filename, int filetype) ; cannam@85: static void current_sf_info_test (const char *filename) ; cannam@85: static void raw_needs_endswap_test (const char *filename, int filetype) ; cannam@85: cannam@85: static void broadcast_test (const char *filename, int filetype) ; cannam@85: static void broadcast_rdwr_test (const char *filename, int filetype) ; cannam@85: static void broadcast_coding_history_test (const char *filename) ; cannam@85: static void broadcast_coding_history_size (const char *filename) ; cannam@85: cannam@85: /* Force the start of this buffer to be double aligned. Sparc-solaris will cannam@85: ** choke if its not. cannam@85: */ cannam@85: cannam@85: static int int_data [BUFFER_LEN] ; cannam@85: static float float_data [BUFFER_LEN] ; cannam@85: static double double_data [BUFFER_LEN] ; cannam@85: cannam@85: int cannam@85: main (int argc, char *argv []) cannam@85: { int do_all = 0 ; cannam@85: int test_count = 0 ; cannam@85: cannam@85: if (argc != 2) cannam@85: { printf ("Usage : %s \n", argv [0]) ; cannam@85: printf (" Where is one of the following:\n") ; cannam@85: printf (" ver - test sf_command (SFC_GETLIB_VERSION)\n") ; cannam@85: printf (" norm - test floating point normalisation\n") ; cannam@85: printf (" format - test format string commands\n") ; cannam@85: printf (" peak - test peak calculation\n") ; cannam@85: printf (" trunc - test file truncation\n") ; cannam@85: printf (" inst - test set/get of SF_INSTRUMENT.\n") ; cannam@85: printf (" chanmap - test set/get of channel map data..\n") ; cannam@85: printf (" bext - test set/get of SF_BROADCAST_INFO.\n") ; cannam@85: printf (" bextch - test set/get of SF_BROADCAST_INFO coding_history.\n") ; cannam@85: printf (" rawend - test SFC_RAW_NEEDS_ENDSWAP.\n") ; cannam@85: printf (" all - perform all tests\n") ; cannam@85: exit (1) ; cannam@85: } ; cannam@85: cannam@85: do_all =! strcmp (argv [1], "all") ; cannam@85: cannam@85: if (do_all || strcmp (argv [1], "ver") == 0) cannam@85: { char buffer [128] ; cannam@85: cannam@85: print_test_name ("version_test", "(none)") ; cannam@85: buffer [0] = 0 ; cannam@85: sf_command (NULL, SFC_GET_LIB_VERSION, buffer, sizeof (buffer)) ; cannam@85: if (strlen (buffer) < 1) cannam@85: { printf ("Line %d: could not retrieve lib version.\n", __LINE__) ; cannam@85: exit (1) ; cannam@85: } ; cannam@85: puts ("ok") ; cannam@85: test_count ++ ; cannam@85: } ; cannam@85: cannam@85: if (do_all || strcmp (argv [1], "norm") == 0) cannam@85: { /* Preliminary float/double normalisation tests. More testing cannam@85: ** is done in the program 'floating_point_test'. cannam@85: */ cannam@85: float_norm_test ("float.wav") ; cannam@85: double_norm_test ("double.wav") ; cannam@85: test_count ++ ; cannam@85: } ; cannam@85: cannam@85: if (do_all || strcmp (argv [1], "peak") == 0) cannam@85: { calc_peak_test (SF_ENDIAN_BIG | SF_FORMAT_RAW, "be-peak.raw") ; cannam@85: calc_peak_test (SF_ENDIAN_LITTLE | SF_FORMAT_RAW, "le-peak.raw") ; cannam@85: test_count ++ ; cannam@85: } ; cannam@85: cannam@85: if (do_all || ! strcmp (argv [1], "format")) cannam@85: { format_tests () ; cannam@85: test_count ++ ; cannam@85: } ; cannam@85: cannam@85: if (do_all || strcmp (argv [1], "trunc") == 0) cannam@85: { truncate_test ("truncate.raw", SF_FORMAT_RAW | SF_FORMAT_PCM_32) ; cannam@85: truncate_test ("truncate.au" , SF_FORMAT_AU | SF_FORMAT_PCM_16) ; cannam@85: test_count ++ ; cannam@85: } ; cannam@85: cannam@85: if (do_all || strcmp (argv [1], "inst") == 0) cannam@85: { instrument_test ("instrument.wav", SF_FORMAT_WAV | SF_FORMAT_PCM_16) ; cannam@85: instrument_test ("instrument.aiff" , SF_FORMAT_AIFF | SF_FORMAT_PCM_24) ; cannam@85: /*-instrument_test ("instrument.xi", SF_FORMAT_XI | SF_FORMAT_DPCM_16) ;-*/ cannam@85: test_count ++ ; cannam@85: } ; cannam@85: cannam@85: if (do_all || strcmp (argv [1], "current_sf_info") == 0) cannam@85: { current_sf_info_test ("current.wav") ; cannam@85: test_count ++ ; cannam@85: } ; cannam@85: cannam@85: if (do_all || strcmp (argv [1], "bext") == 0) cannam@85: { broadcast_test ("broadcast.wav", SF_FORMAT_WAV | SF_FORMAT_PCM_16) ; cannam@85: broadcast_rdwr_test ("broadcast.wav", SF_FORMAT_WAV | SF_FORMAT_PCM_16) ; cannam@85: cannam@85: broadcast_test ("broadcast.wavex", SF_FORMAT_WAVEX | SF_FORMAT_PCM_16) ; cannam@85: broadcast_rdwr_test ("broadcast.wavex", SF_FORMAT_WAVEX | SF_FORMAT_PCM_16) ; cannam@85: cannam@85: broadcast_test ("broadcast.rf64", SF_FORMAT_RF64 | SF_FORMAT_PCM_16) ; cannam@85: broadcast_rdwr_test ("broadcast.rf64", SF_FORMAT_RF64 | SF_FORMAT_PCM_16) ; cannam@85: test_count ++ ; cannam@85: } ; cannam@85: cannam@85: if (do_all || strcmp (argv [1], "bextch") == 0) cannam@85: { broadcast_coding_history_test ("coding_history.wav") ; cannam@85: broadcast_coding_history_size ("coding_hist_size.wav") ; cannam@85: test_count ++ ; cannam@85: } ; cannam@85: cannam@85: if (do_all || strcmp (argv [1], "chanmap") == 0) cannam@85: { channel_map_test ("chanmap.wavex", SF_FORMAT_WAVEX | SF_FORMAT_PCM_16) ; cannam@85: channel_map_test ("chanmap.rf64", SF_FORMAT_RF64 | SF_FORMAT_PCM_16) ; cannam@85: channel_map_test ("chanmap.aifc" , SF_FORMAT_AIFF | SF_FORMAT_PCM_16) ; cannam@85: channel_map_test ("chanmap.caf" , SF_FORMAT_CAF | SF_FORMAT_PCM_16) ; cannam@85: test_count ++ ; cannam@85: } ; cannam@85: cannam@85: if (do_all || strcmp (argv [1], "rawend") == 0) cannam@85: { raw_needs_endswap_test ("raw_end.wav", SF_FORMAT_WAV) ; cannam@85: raw_needs_endswap_test ("raw_end.wavex", SF_FORMAT_WAVEX) ; cannam@85: raw_needs_endswap_test ("raw_end.rifx", SF_ENDIAN_BIG | SF_FORMAT_WAV) ; cannam@85: raw_needs_endswap_test ("raw_end.aiff", SF_FORMAT_AIFF) ; cannam@85: raw_needs_endswap_test ("raw_end.aiff_le", SF_ENDIAN_LITTLE | SF_FORMAT_AIFF) ; cannam@85: test_count ++ ; cannam@85: } ; cannam@85: cannam@85: if (test_count == 0) cannam@85: { printf ("Mono : ************************************\n") ; cannam@85: printf ("Mono : * No '%s' test defined.\n", argv [1]) ; cannam@85: printf ("Mono : ************************************\n") ; cannam@85: return 1 ; cannam@85: } ; cannam@85: cannam@85: return 0 ; cannam@85: } /* main */ cannam@85: cannam@85: /*============================================================================================ cannam@85: ** Here are the test functions. cannam@85: */ cannam@85: cannam@85: static void cannam@85: float_norm_test (const char *filename) cannam@85: { SNDFILE *file ; cannam@85: SF_INFO sfinfo ; cannam@85: unsigned int k ; cannam@85: cannam@85: print_test_name ("float_norm_test", filename) ; cannam@85: cannam@85: sfinfo.samplerate = 44100 ; cannam@85: sfinfo.format = (SF_FORMAT_RAW | SF_FORMAT_PCM_16) ; cannam@85: sfinfo.channels = 1 ; cannam@85: sfinfo.frames = BUFFER_LEN ; cannam@85: cannam@85: /* Create float_data with all values being less than 1.0. */ cannam@85: for (k = 0 ; k < BUFFER_LEN / 2 ; k++) cannam@85: float_data [k] = (k + 5) / (2.0 * BUFFER_LEN) ; cannam@85: for (k = BUFFER_LEN / 2 ; k < BUFFER_LEN ; k++) cannam@85: float_data [k] = (k + 5) ; cannam@85: cannam@85: if (! (file = sf_open (filename, SFM_WRITE, &sfinfo))) cannam@85: { printf ("Line %d: sf_open_write failed with error : ", __LINE__) ; cannam@85: fflush (stdout) ; cannam@85: puts (sf_strerror (NULL)) ; cannam@85: exit (1) ; cannam@85: } ; cannam@85: cannam@85: /* Normalisation is on by default so no need to do anything here. */ cannam@85: cannam@85: if ((k = sf_write_float (file, float_data, BUFFER_LEN / 2)) != BUFFER_LEN / 2) cannam@85: { printf ("Line %d: sf_write_float failed with short write (%d ->%d)\n", __LINE__, BUFFER_LEN, k) ; cannam@85: exit (1) ; cannam@85: } ; cannam@85: cannam@85: /* Turn normalisation off. */ cannam@85: sf_command (file, SFC_SET_NORM_FLOAT, NULL, SF_FALSE) ; cannam@85: cannam@85: if ((k = sf_write_float (file, float_data + BUFFER_LEN / 2, BUFFER_LEN / 2)) != BUFFER_LEN / 2) cannam@85: { printf ("Line %d: sf_write_float failed with short write (%d ->%d)\n", __LINE__, BUFFER_LEN, k) ; cannam@85: exit (1) ; cannam@85: } ; cannam@85: cannam@85: sf_close (file) ; cannam@85: cannam@85: /* sfinfo struct should still contain correct data. */ cannam@85: if (! (file = sf_open (filename, SFM_READ, &sfinfo))) cannam@85: { printf ("Line %d: sf_open_read failed with error : ", __LINE__) ; cannam@85: fflush (stdout) ; cannam@85: puts (sf_strerror (NULL)) ; cannam@85: exit (1) ; cannam@85: } ; cannam@85: cannam@85: if (sfinfo.format != (SF_FORMAT_RAW | SF_FORMAT_PCM_16)) cannam@85: { printf ("Line %d: Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__, (SF_FORMAT_RAW | SF_FORMAT_PCM_16), sfinfo.format) ; cannam@85: exit (1) ; cannam@85: } ; cannam@85: cannam@85: if (sfinfo.frames != BUFFER_LEN) cannam@85: { printf ("\n\nLine %d: Incorrect number of.frames in file. (%d => %ld)\n", __LINE__, BUFFER_LEN, SF_COUNT_TO_LONG (sfinfo.frames)) ; cannam@85: exit (1) ; cannam@85: } ; cannam@85: cannam@85: if (sfinfo.channels != 1) cannam@85: { printf ("Line %d: Incorrect number of channels in file.\n", __LINE__) ; cannam@85: exit (1) ; cannam@85: } ; cannam@85: cannam@85: /* Read float_data and check that it is normalised (ie default). */ cannam@85: if ((k = sf_read_float (file, float_data, BUFFER_LEN)) != BUFFER_LEN) cannam@85: { printf ("\n\nLine %d: sf_read_float failed with short read (%d ->%d)\n", __LINE__, BUFFER_LEN, k) ; cannam@85: exit (1) ; cannam@85: } ; cannam@85: cannam@85: for (k = 0 ; k < BUFFER_LEN ; k++) cannam@85: if (float_data [k] >= 1.0) cannam@85: { printf ("\n\nLine %d: float_data [%d] == %f which is greater than 1.0\n", __LINE__, k, float_data [k]) ; cannam@85: exit (1) ; cannam@85: } ; cannam@85: cannam@85: /* Seek to start of file, turn normalisation off, read float_data and check again. */ cannam@85: sf_seek (file, 0, SEEK_SET) ; cannam@85: sf_command (file, SFC_SET_NORM_FLOAT, NULL, SF_FALSE) ; cannam@85: cannam@85: if ((k = sf_read_float (file, float_data, BUFFER_LEN)) != BUFFER_LEN) cannam@85: { printf ("\n\nLine %d: sf_read_float failed with short read (%d ->%d)\n", __LINE__, BUFFER_LEN, k) ; cannam@85: exit (1) ; cannam@85: } ; cannam@85: cannam@85: for (k = 0 ; k < BUFFER_LEN ; k++) cannam@85: if (float_data [k] < 1.0) cannam@85: { printf ("\n\nLine %d: float_data [%d] == %f which is less than 1.0\n", __LINE__, k, float_data [k]) ; cannam@85: exit (1) ; cannam@85: } ; cannam@85: cannam@85: /* Seek to start of file, turn normalisation on, read float_data and do final check. */ cannam@85: sf_seek (file, 0, SEEK_SET) ; cannam@85: sf_command (file, SFC_SET_NORM_FLOAT, NULL, SF_TRUE) ; cannam@85: cannam@85: if ((k = sf_read_float (file, float_data, BUFFER_LEN)) != BUFFER_LEN) cannam@85: { printf ("\n\nLine %d: sf_read_float failed with short read (%d ->%d)\n", __LINE__, BUFFER_LEN, k) ; cannam@85: exit (1) ; cannam@85: } ; cannam@85: cannam@85: for (k = 0 ; k < BUFFER_LEN ; k++) cannam@85: if (float_data [k] > 1.0) cannam@85: { printf ("\n\nLine %d: float_data [%d] == %f which is greater than 1.0\n", __LINE__, k, float_data [k]) ; cannam@85: exit (1) ; cannam@85: } ; cannam@85: cannam@85: cannam@85: sf_close (file) ; cannam@85: cannam@85: unlink (filename) ; cannam@85: cannam@85: printf ("ok\n") ; cannam@85: } /* float_norm_test */ cannam@85: cannam@85: static void cannam@85: double_norm_test (const char *filename) cannam@85: { SNDFILE *file ; cannam@85: SF_INFO sfinfo ; cannam@85: unsigned int k ; cannam@85: cannam@85: print_test_name ("double_norm_test", filename) ; cannam@85: cannam@85: sfinfo.samplerate = 44100 ; cannam@85: sfinfo.format = (SF_FORMAT_RAW | SF_FORMAT_PCM_16) ; cannam@85: sfinfo.channels = 1 ; cannam@85: sfinfo.frames = BUFFER_LEN ; cannam@85: cannam@85: /* Create double_data with all values being less than 1.0. */ cannam@85: for (k = 0 ; k < BUFFER_LEN / 2 ; k++) cannam@85: double_data [k] = (k + 5) / (2.0 * BUFFER_LEN) ; cannam@85: for (k = BUFFER_LEN / 2 ; k < BUFFER_LEN ; k++) cannam@85: double_data [k] = (k + 5) ; cannam@85: cannam@85: if (! (file = sf_open (filename, SFM_WRITE, &sfinfo))) cannam@85: { printf ("Line %d: sf_open_write failed with error : ", __LINE__) ; cannam@85: fflush (stdout) ; cannam@85: puts (sf_strerror (NULL)) ; cannam@85: exit (1) ; cannam@85: } ; cannam@85: cannam@85: /* Normailsation is on by default so no need to do anything here. */ cannam@85: /*-sf_command (file, "set-norm-double", "true", 0) ;-*/ cannam@85: cannam@85: if ((k = sf_write_double (file, double_data, BUFFER_LEN / 2)) != BUFFER_LEN / 2) cannam@85: { printf ("Line %d: sf_write_double failed with short write (%d ->%d)\n", __LINE__, BUFFER_LEN, k) ; cannam@85: exit (1) ; cannam@85: } ; cannam@85: cannam@85: /* Turn normalisation off. */ cannam@85: sf_command (file, SFC_SET_NORM_DOUBLE, NULL, SF_FALSE) ; cannam@85: cannam@85: if ((k = sf_write_double (file, double_data + BUFFER_LEN / 2, BUFFER_LEN / 2)) != BUFFER_LEN / 2) cannam@85: { printf ("Line %d: sf_write_double failed with short write (%d ->%d)\n", __LINE__, BUFFER_LEN, k) ; cannam@85: exit (1) ; cannam@85: } ; cannam@85: cannam@85: sf_close (file) ; cannam@85: cannam@85: if (! (file = sf_open (filename, SFM_READ, &sfinfo))) cannam@85: { printf ("Line %d: sf_open_read failed with error : ", __LINE__) ; cannam@85: fflush (stdout) ; cannam@85: puts (sf_strerror (NULL)) ; cannam@85: exit (1) ; cannam@85: } ; cannam@85: cannam@85: if (sfinfo.format != (SF_FORMAT_RAW | SF_FORMAT_PCM_16)) cannam@85: { printf ("Line %d: Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__, (SF_FORMAT_RAW | SF_FORMAT_PCM_16), sfinfo.format) ; cannam@85: exit (1) ; cannam@85: } ; cannam@85: cannam@85: if (sfinfo.frames != BUFFER_LEN) cannam@85: { printf ("\n\nLine %d: Incorrect number of.frames in file. (%d => %ld)\n", __LINE__, BUFFER_LEN, SF_COUNT_TO_LONG (sfinfo.frames)) ; cannam@85: exit (1) ; cannam@85: } ; cannam@85: cannam@85: if (sfinfo.channels != 1) cannam@85: { printf ("Line %d: Incorrect number of channels in file.\n", __LINE__) ; cannam@85: exit (1) ; cannam@85: } ; cannam@85: cannam@85: /* Read double_data and check that it is normalised (ie default). */ cannam@85: if ((k = sf_read_double (file, double_data, BUFFER_LEN)) != BUFFER_LEN) cannam@85: { printf ("\n\nLine %d: sf_read_double failed with short read (%d ->%d)\n", __LINE__, BUFFER_LEN, k) ; cannam@85: exit (1) ; cannam@85: } ; cannam@85: cannam@85: for (k = 0 ; k < BUFFER_LEN ; k++) cannam@85: if (double_data [k] >= 1.0) cannam@85: { printf ("\n\nLine %d: double_data [%d] == %f which is greater than 1.0\n", __LINE__, k, double_data [k]) ; cannam@85: exit (1) ; cannam@85: } ; cannam@85: cannam@85: /* Seek to start of file, turn normalisation off, read double_data and check again. */ cannam@85: sf_seek (file, 0, SEEK_SET) ; cannam@85: sf_command (file, SFC_SET_NORM_DOUBLE, NULL, SF_FALSE) ; cannam@85: cannam@85: if ((k = sf_read_double (file, double_data, BUFFER_LEN)) != BUFFER_LEN) cannam@85: { printf ("\n\nLine %d: sf_read_double failed with short read (%d ->%d)\n", __LINE__, BUFFER_LEN, k) ; cannam@85: exit (1) ; cannam@85: } ; cannam@85: cannam@85: for (k = 0 ; k < BUFFER_LEN ; k++) cannam@85: if (double_data [k] < 1.0) cannam@85: { printf ("\n\nLine %d: double_data [%d] == %f which is less than 1.0\n", __LINE__, k, double_data [k]) ; cannam@85: exit (1) ; cannam@85: } ; cannam@85: cannam@85: /* Seek to start of file, turn normalisation on, read double_data and do final check. */ cannam@85: sf_seek (file, 0, SEEK_SET) ; cannam@85: sf_command (file, SFC_SET_NORM_DOUBLE, NULL, SF_TRUE) ; cannam@85: cannam@85: if ((k = sf_read_double (file, double_data, BUFFER_LEN)) != BUFFER_LEN) cannam@85: { printf ("\n\nLine %d: sf_read_double failed with short read (%d ->%d)\n", __LINE__, BUFFER_LEN, k) ; cannam@85: exit (1) ; cannam@85: } ; cannam@85: cannam@85: for (k = 0 ; k < BUFFER_LEN ; k++) cannam@85: if (double_data [k] > 1.0) cannam@85: { printf ("\n\nLine %d: double_data [%d] == %f which is greater than 1.0\n", __LINE__, k, double_data [k]) ; cannam@85: exit (1) ; cannam@85: } ; cannam@85: cannam@85: cannam@85: sf_close (file) ; cannam@85: cannam@85: unlink (filename) ; cannam@85: cannam@85: printf ("ok\n") ; cannam@85: } /* double_norm_test */ cannam@85: cannam@85: static void cannam@85: format_tests (void) cannam@85: { SF_FORMAT_INFO format_info ; cannam@85: SF_INFO sfinfo ; cannam@85: const char *last_name ; cannam@85: int k, count ; cannam@85: cannam@85: print_test_name ("format_tests", "(null)") ; cannam@85: cannam@85: /* Clear out SF_INFO struct and set channels > 0. */ cannam@85: memset (&sfinfo, 0, sizeof (sfinfo)) ; cannam@85: sfinfo.channels = 1 ; cannam@85: cannam@85: /* First test simple formats. */ cannam@85: cannam@85: sf_command (NULL, SFC_GET_SIMPLE_FORMAT_COUNT, &count, sizeof (int)) ; cannam@85: cannam@85: if (count < 0 || count > 30) cannam@85: { printf ("Line %d: Weird count.\n", __LINE__) ; cannam@85: exit (1) ; cannam@85: } ; cannam@85: cannam@85: format_info.format = 0 ; cannam@85: sf_command (NULL, SFC_GET_SIMPLE_FORMAT, &format_info, sizeof (format_info)) ; cannam@85: cannam@85: last_name = format_info.name ; cannam@85: for (k = 1 ; k < count ; k ++) cannam@85: { format_info.format = k ; cannam@85: sf_command (NULL, SFC_GET_SIMPLE_FORMAT, &format_info, sizeof (format_info)) ; cannam@85: if (strcmp (last_name, format_info.name) >= 0) cannam@85: { printf ("\n\nLine %d: format names out of sequence `%s' < `%s'.\n", __LINE__, last_name, format_info.name) ; cannam@85: exit (1) ; cannam@85: } ; cannam@85: sfinfo.format = format_info.format ; cannam@85: cannam@85: if (! sf_format_check (&sfinfo)) cannam@85: { printf ("\n\nLine %d: sf_format_check failed.\n", __LINE__) ; cannam@85: printf (" Name : %s\n", format_info.name) ; cannam@85: printf (" Format : 0x%X\n", sfinfo.format) ; cannam@85: printf (" Channels : 0x%X\n", sfinfo.channels) ; cannam@85: printf (" Sample Rate : 0x%X\n", sfinfo.samplerate) ; cannam@85: exit (1) ; cannam@85: } ; cannam@85: last_name = format_info.name ; cannam@85: } ; cannam@85: format_info.format = 666 ; cannam@85: sf_command (NULL, SFC_GET_SIMPLE_FORMAT, &format_info, sizeof (format_info)) ; cannam@85: cannam@85: /* Now test major formats. */ cannam@85: sf_command (NULL, SFC_GET_FORMAT_MAJOR_COUNT, &count, sizeof (int)) ; cannam@85: cannam@85: if (count < 0 || count > 30) cannam@85: { printf ("Line %d: Weird count.\n", __LINE__) ; cannam@85: exit (1) ; cannam@85: } ; cannam@85: cannam@85: format_info.format = 0 ; cannam@85: sf_command (NULL, SFC_GET_FORMAT_MAJOR, &format_info, sizeof (format_info)) ; cannam@85: cannam@85: last_name = format_info.name ; cannam@85: for (k = 1 ; k < count ; k ++) cannam@85: { format_info.format = k ; cannam@85: sf_command (NULL, SFC_GET_FORMAT_MAJOR, &format_info, sizeof (format_info)) ; cannam@85: if (strcmp (last_name, format_info.name) >= 0) cannam@85: { printf ("\n\nLine %d: format names out of sequence (%d) `%s' < `%s'.\n", __LINE__, k, last_name, format_info.name) ; cannam@85: exit (1) ; cannam@85: } ; cannam@85: cannam@85: last_name = format_info.name ; cannam@85: } ; cannam@85: format_info.format = 666 ; cannam@85: sf_command (NULL, SFC_GET_FORMAT_MAJOR, &format_info, sizeof (format_info)) ; cannam@85: cannam@85: /* Now test subtype formats. */ cannam@85: sf_command (NULL, SFC_GET_FORMAT_SUBTYPE_COUNT, &count, sizeof (int)) ; cannam@85: cannam@85: if (count < 0 || count > 30) cannam@85: { printf ("Line %d: Weird count.\n", __LINE__) ; cannam@85: exit (1) ; cannam@85: } ; cannam@85: cannam@85: format_info.format = 0 ; cannam@85: sf_command (NULL, SFC_GET_FORMAT_SUBTYPE, &format_info, sizeof (format_info)) ; cannam@85: cannam@85: last_name = format_info.name ; cannam@85: for (k = 1 ; k < count ; k ++) cannam@85: { format_info.format = k ; cannam@85: sf_command (NULL, SFC_GET_FORMAT_SUBTYPE, &format_info, sizeof (format_info)) ; cannam@85: } ; cannam@85: format_info.format = 666 ; cannam@85: sf_command (NULL, SFC_GET_FORMAT_SUBTYPE, &format_info, sizeof (format_info)) ; cannam@85: cannam@85: cannam@85: printf ("ok\n") ; cannam@85: } /* format_tests */ cannam@85: cannam@85: static void cannam@85: calc_peak_test (int filetype, const char *filename) cannam@85: { SNDFILE *file ; cannam@85: SF_INFO sfinfo ; cannam@85: int k, format ; cannam@85: double peak ; cannam@85: cannam@85: print_test_name ("calc_peak_test", filename) ; cannam@85: cannam@85: format = (filetype | SF_FORMAT_PCM_16) ; cannam@85: cannam@85: sfinfo.samplerate = 44100 ; cannam@85: sfinfo.format = format ; cannam@85: sfinfo.channels = 1 ; cannam@85: sfinfo.frames = BUFFER_LEN ; cannam@85: cannam@85: /* Create double_data with max value of 0.5. */ cannam@85: for (k = 0 ; k < BUFFER_LEN ; k++) cannam@85: double_data [k] = (k + 1) / (2.0 * BUFFER_LEN) ; cannam@85: cannam@85: file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ; cannam@85: cannam@85: test_write_double_or_die (file, 0, double_data, BUFFER_LEN, __LINE__) ; cannam@85: cannam@85: sf_close (file) ; cannam@85: cannam@85: file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ; cannam@85: cannam@85: if (sfinfo.format != format) cannam@85: { printf ("Line %d: Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__, format, sfinfo.format) ; cannam@85: exit (1) ; cannam@85: } ; cannam@85: cannam@85: if (sfinfo.frames != BUFFER_LEN) cannam@85: { printf ("\n\nLine %d: Incorrect number of.frames in file. (%d => %ld)\n", __LINE__, BUFFER_LEN, SF_COUNT_TO_LONG (sfinfo.frames)) ; cannam@85: exit (1) ; cannam@85: } ; cannam@85: cannam@85: if (sfinfo.channels != 1) cannam@85: { printf ("Line %d: Incorrect number of channels in file.\n", __LINE__) ; cannam@85: exit (1) ; cannam@85: } ; cannam@85: cannam@85: sf_command (file, SFC_CALC_SIGNAL_MAX, &peak, sizeof (peak)) ; cannam@85: if (fabs (peak - (1 << 14)) > 1.0) cannam@85: { printf ("Line %d : Peak value should be %d (is %f).\n", __LINE__, (1 << 14), peak) ; cannam@85: exit (1) ; cannam@85: } ; cannam@85: cannam@85: sf_command (file, SFC_CALC_NORM_SIGNAL_MAX, &peak, sizeof (peak)) ; cannam@85: if (fabs (peak - 0.5) > 4e-5) cannam@85: { printf ("Line %d : Peak value should be %f (is %f).\n", __LINE__, 0.5, peak) ; cannam@85: exit (1) ; cannam@85: } ; cannam@85: cannam@85: sf_close (file) ; cannam@85: cannam@85: format = (filetype | SF_FORMAT_FLOAT) ; cannam@85: sfinfo.samplerate = 44100 ; cannam@85: sfinfo.format = format ; cannam@85: sfinfo.channels = 1 ; cannam@85: sfinfo.frames = BUFFER_LEN ; cannam@85: cannam@85: /* Create double_data with max value of 0.5. */ cannam@85: for (k = 0 ; k < BUFFER_LEN ; k++) cannam@85: double_data [k] = (k + 1) / (2.0 * BUFFER_LEN) ; cannam@85: cannam@85: file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ; cannam@85: cannam@85: test_write_double_or_die (file, 0, double_data, BUFFER_LEN, __LINE__) ; cannam@85: cannam@85: sf_close (file) ; cannam@85: cannam@85: file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ; cannam@85: cannam@85: if (sfinfo.format != format) cannam@85: { printf ("Line %d: Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__, format, sfinfo.format) ; cannam@85: exit (1) ; cannam@85: } ; cannam@85: cannam@85: if (sfinfo.frames != BUFFER_LEN) cannam@85: { printf ("\n\nLine %d: Incorrect number of.frames in file. (%d => %ld)\n", __LINE__, BUFFER_LEN, SF_COUNT_TO_LONG (sfinfo.frames)) ; cannam@85: exit (1) ; cannam@85: } ; cannam@85: cannam@85: if (sfinfo.channels != 1) cannam@85: { printf ("Line %d: Incorrect number of channels in file.\n", __LINE__) ; cannam@85: exit (1) ; cannam@85: } ; cannam@85: cannam@85: sf_command (file, SFC_CALC_SIGNAL_MAX, &peak, sizeof (peak)) ; cannam@85: if (fabs (peak - 0.5) > 1e-5) cannam@85: { printf ("Line %d : Peak value should be %f (is %f).\n", __LINE__, 0.5, peak) ; cannam@85: exit (1) ; cannam@85: } ; cannam@85: cannam@85: sf_command (file, SFC_CALC_NORM_SIGNAL_MAX, &peak, sizeof (peak)) ; cannam@85: if (fabs (peak - 0.5) > 1e-5) cannam@85: { printf ("Line %d : Peak value should be %f (is %f).\n", __LINE__, 0.5, peak) ; cannam@85: exit (1) ; cannam@85: } ; cannam@85: cannam@85: sf_close (file) ; cannam@85: cannam@85: unlink (filename) ; cannam@85: cannam@85: printf ("ok\n") ; cannam@85: } /* calc_peak_test */ cannam@85: cannam@85: static void cannam@85: truncate_test (const char *filename, int filetype) cannam@85: { SNDFILE *file ; cannam@85: SF_INFO sfinfo ; cannam@85: sf_count_t len ; cannam@85: cannam@85: print_test_name ("truncate_test", filename) ; cannam@85: cannam@85: sfinfo.samplerate = 11025 ; cannam@85: sfinfo.format = filetype ; cannam@85: sfinfo.channels = 2 ; cannam@85: cannam@85: file = test_open_file_or_die (filename, SFM_RDWR, &sfinfo, SF_TRUE, __LINE__) ; cannam@85: cannam@85: test_write_int_or_die (file, 0, int_data, BUFFER_LEN, __LINE__) ; cannam@85: cannam@85: len = 100 ; cannam@85: if (sf_command (file, SFC_FILE_TRUNCATE, &len, sizeof (len))) cannam@85: { printf ("Line %d: sf_command (SFC_FILE_TRUNCATE) returned error.\n", __LINE__) ; cannam@85: exit (1) ; cannam@85: } ; cannam@85: cannam@85: test_seek_or_die (file, 0, SEEK_CUR, len, 2, __LINE__) ; cannam@85: test_seek_or_die (file, 0, SEEK_END, len, 2, __LINE__) ; cannam@85: cannam@85: sf_close (file) ; cannam@85: cannam@85: unlink (filename) ; cannam@85: puts ("ok") ; cannam@85: } /* truncate_test */ cannam@85: cannam@85: /*------------------------------------------------------------------------------ cannam@85: */ cannam@85: cannam@85: static void cannam@85: instrumet_rw_test (const char *filename) cannam@85: { SNDFILE *sndfile ; cannam@85: SF_INFO sfinfo ; cannam@85: SF_INSTRUMENT inst ; cannam@85: memset (&sfinfo, 0, sizeof (SF_INFO)) ; cannam@85: cannam@85: sndfile = test_open_file_or_die (filename, SFM_RDWR, &sfinfo, SF_FALSE, __LINE__) ; cannam@85: cannam@85: if (sf_command (sndfile, SFC_GET_INSTRUMENT, &inst, sizeof (inst)) == SF_TRUE) cannam@85: { inst.basenote = 22 ; cannam@85: cannam@85: if (sf_command (sndfile, SFC_SET_INSTRUMENT, &inst, sizeof (inst)) == SF_TRUE) cannam@85: printf ("Sucess: [%s] updated\n", filename) ; cannam@85: else cannam@85: printf ("Error: SFC_SET_INSTRUMENT on [%s] [%s]\n", filename, sf_strerror (sndfile)) ; cannam@85: } cannam@85: else cannam@85: printf ("Error: SFC_GET_INSTRUMENT on [%s] [%s]\n", filename, sf_strerror (sndfile)) ; cannam@85: cannam@85: cannam@85: if (sf_command (sndfile, SFC_UPDATE_HEADER_NOW, NULL, 0) != 0) cannam@85: printf ("Error: SFC_UPDATE_HEADER_NOW on [%s] [%s]\n", filename, sf_strerror (sndfile)) ; cannam@85: cannam@85: sf_write_sync (sndfile) ; cannam@85: sf_close (sndfile) ; cannam@85: cannam@85: return ; cannam@85: } /* instrumet_rw_test */ cannam@85: cannam@85: static void cannam@85: instrument_test (const char *filename, int filetype) cannam@85: { static SF_INSTRUMENT write_inst = cannam@85: { 2, /* gain */ cannam@85: 3, /* detune */ cannam@85: 4, /* basenote */ cannam@85: 5, 6, /* key low and high */ cannam@85: 7, 8, /* velocity low and high */ cannam@85: 2, /* loop_count */ cannam@85: { { 801, 2, 3, 0 }, cannam@85: { 801, 3, 4, 0 }, cannam@85: } cannam@85: } ; cannam@85: SF_INSTRUMENT read_inst ; cannam@85: SNDFILE *file ; cannam@85: SF_INFO sfinfo ; cannam@85: cannam@85: print_test_name ("instrument_test", filename) ; cannam@85: cannam@85: sfinfo.samplerate = 11025 ; cannam@85: sfinfo.format = filetype ; cannam@85: sfinfo.channels = 1 ; cannam@85: cannam@85: file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ; cannam@85: if (sf_command (file, SFC_SET_INSTRUMENT, &write_inst, sizeof (write_inst)) == SF_FALSE) cannam@85: { printf ("\n\nLine %d : sf_command (SFC_SET_INSTRUMENT) failed.\n\n", __LINE__) ; cannam@85: exit (1) ; cannam@85: } ; cannam@85: test_write_double_or_die (file, 0, double_data, BUFFER_LEN, __LINE__) ; cannam@85: sf_close (file) ; cannam@85: cannam@85: memset (&read_inst, 0, sizeof (read_inst)) ; cannam@85: cannam@85: file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ; cannam@85: if (sf_command (file, SFC_GET_INSTRUMENT, &read_inst, sizeof (read_inst)) == SF_FALSE) cannam@85: { printf ("\n\nLine %d : sf_command (SFC_GET_INSTRUMENT) failed.\n\n", __LINE__) ; cannam@85: exit (1) ; cannam@85: return ; cannam@85: } ; cannam@85: check_log_buffer_or_die (file, __LINE__) ; cannam@85: sf_close (file) ; cannam@85: cannam@85: if ((filetype & SF_FORMAT_TYPEMASK) == SF_FORMAT_WAV) cannam@85: { /* cannam@85: ** For all the fields that WAV doesn't support, modify the cannam@85: ** write_inst struct to hold the default value that the WAV cannam@85: ** module should hold. cannam@85: */ cannam@85: write_inst.detune = 0 ; cannam@85: write_inst.key_lo = write_inst.velocity_lo = 0 ; cannam@85: write_inst.key_hi = write_inst.velocity_hi = 127 ; cannam@85: write_inst.gain = 1 ; cannam@85: } ; cannam@85: cannam@85: if ((filetype & SF_FORMAT_TYPEMASK) == SF_FORMAT_XI) cannam@85: { /* cannam@85: ** For all the fields that XI doesn't support, modify the cannam@85: ** write_inst struct to hold the default value that the XI cannam@85: ** module should hold. cannam@85: */ cannam@85: write_inst.basenote = 0 ; cannam@85: write_inst.detune = 0 ; cannam@85: write_inst.key_lo = write_inst.velocity_lo = 0 ; cannam@85: write_inst.key_hi = write_inst.velocity_hi = 127 ; cannam@85: write_inst.gain = 1 ; cannam@85: } ; cannam@85: cannam@85: if (memcmp (&write_inst, &read_inst, sizeof (write_inst)) != 0) cannam@85: { printf ("\n\nLine %d : instrument comparison failed.\n\n", __LINE__) ; cannam@85: printf ("W Base Note : %u\n" cannam@85: " Detune : %u\n" cannam@85: " Low Note : %u\tHigh Note : %u\n" cannam@85: " Low Vel. : %u\tHigh Vel. : %u\n" cannam@85: " Gain : %d\tCount : %d\n" cannam@85: " mode : %d\n" cannam@85: " start : %d\tend : %d\tcount :%d\n" cannam@85: " mode : %d\n" cannam@85: " start : %d\tend : %d\tcount :%d\n\n", cannam@85: write_inst.basenote, cannam@85: write_inst.detune, cannam@85: write_inst.key_lo, write_inst.key_hi, cannam@85: write_inst.velocity_lo, write_inst.velocity_hi, cannam@85: write_inst.gain, write_inst.loop_count, cannam@85: write_inst.loops [0].mode, write_inst.loops [0].start, cannam@85: write_inst.loops [0].end, write_inst.loops [0].count, cannam@85: write_inst.loops [1].mode, write_inst.loops [1].start, cannam@85: write_inst.loops [1].end, write_inst.loops [1].count) ; cannam@85: printf ("R Base Note : %u\n" cannam@85: " Detune : %u\n" cannam@85: " Low Note : %u\tHigh Note : %u\n" cannam@85: " Low Vel. : %u\tHigh Vel. : %u\n" cannam@85: " Gain : %d\tCount : %d\n" cannam@85: " mode : %d\n" cannam@85: " start : %d\tend : %d\tcount :%d\n" cannam@85: " mode : %d\n" cannam@85: " start : %d\tend : %d\tcount :%d\n\n", cannam@85: read_inst.basenote, cannam@85: read_inst.detune, cannam@85: read_inst.key_lo, read_inst.key_hi, cannam@85: read_inst.velocity_lo, read_inst.velocity_hi, cannam@85: read_inst.gain, read_inst.loop_count, cannam@85: read_inst.loops [0].mode, read_inst.loops [0].start, cannam@85: read_inst.loops [0].end, read_inst.loops [0].count, cannam@85: read_inst.loops [1].mode, read_inst.loops [1].start, cannam@85: read_inst.loops [1].end, read_inst.loops [1].count) ; cannam@85: cannam@85: if ((filetype & SF_FORMAT_TYPEMASK) != SF_FORMAT_XI) cannam@85: exit (1) ; cannam@85: } ; cannam@85: cannam@85: if (0) instrumet_rw_test (filename) ; cannam@85: cannam@85: unlink (filename) ; cannam@85: puts ("ok") ; cannam@85: } /* instrument_test */ cannam@85: cannam@85: static void cannam@85: current_sf_info_test (const char *filename) cannam@85: { SNDFILE *outfile, *infile ; cannam@85: SF_INFO outinfo, ininfo ; cannam@85: cannam@85: print_test_name ("current_sf_info_test", filename) ; cannam@85: cannam@85: outinfo.samplerate = 44100 ; cannam@85: outinfo.format = (SF_FORMAT_WAV | SF_FORMAT_PCM_16) ; cannam@85: outinfo.channels = 1 ; cannam@85: outinfo.frames = 0 ; cannam@85: cannam@85: outfile = test_open_file_or_die (filename, SFM_WRITE, &outinfo, SF_TRUE, __LINE__) ; cannam@85: sf_command (outfile, SFC_SET_UPDATE_HEADER_AUTO, NULL, 0) ; cannam@85: cannam@85: exit_if_true (outinfo.frames != 0, cannam@85: "\n\nLine %d : Initial sfinfo.frames is not zero.\n\n", __LINE__ cannam@85: ) ; cannam@85: cannam@85: test_write_double_or_die (outfile, 0, double_data, BUFFER_LEN, __LINE__) ; cannam@85: sf_command (outfile, SFC_GET_CURRENT_SF_INFO, &outinfo, sizeof (outinfo)) ; cannam@85: cannam@85: exit_if_true (outinfo.frames != BUFFER_LEN, cannam@85: "\n\nLine %d : Initial sfinfo.frames (%ld) should be %d.\n\n", __LINE__, cannam@85: SF_COUNT_TO_LONG (outinfo.frames), BUFFER_LEN cannam@85: ) ; cannam@85: cannam@85: /* Read file making sure no channel map exists. */ cannam@85: memset (&ininfo, 0, sizeof (ininfo)) ; cannam@85: infile = test_open_file_or_die (filename, SFM_READ, &ininfo, SF_TRUE, __LINE__) ; cannam@85: cannam@85: test_write_double_or_die (outfile, 0, double_data, BUFFER_LEN, __LINE__) ; cannam@85: cannam@85: sf_command (infile, SFC_GET_CURRENT_SF_INFO, &ininfo, sizeof (ininfo)) ; cannam@85: cannam@85: exit_if_true (ininfo.frames != BUFFER_LEN, cannam@85: "\n\nLine %d : Initial sfinfo.frames (%ld) should be %d.\n\n", __LINE__, cannam@85: SF_COUNT_TO_LONG (ininfo.frames), BUFFER_LEN cannam@85: ) ; cannam@85: cannam@85: sf_close (outfile) ; cannam@85: sf_close (infile) ; cannam@85: cannam@85: unlink (filename) ; cannam@85: puts ("ok") ; cannam@85: } /* current_sf_info_test */ cannam@85: cannam@85: static void cannam@85: broadcast_test (const char *filename, int filetype) cannam@85: { static SF_BROADCAST_INFO bc_write, bc_read ; cannam@85: SNDFILE *file ; cannam@85: SF_INFO sfinfo ; cannam@85: int errors = 0 ; cannam@85: cannam@85: print_test_name ("broadcast_test", filename) ; cannam@85: cannam@85: sfinfo.samplerate = 11025 ; cannam@85: sfinfo.format = filetype ; cannam@85: sfinfo.channels = 1 ; cannam@85: cannam@85: memset (&bc_write, 0, sizeof (bc_write)) ; cannam@85: cannam@85: snprintf (bc_write.description, sizeof (bc_write.description), "Test description") ; cannam@85: snprintf (bc_write.originator, sizeof (bc_write.originator), "Test originator") ; cannam@85: snprintf (bc_write.originator_reference, sizeof (bc_write.originator_reference), "%08x-%08x", (unsigned int) time (NULL), (unsigned int) (~ time (NULL))) ; cannam@85: snprintf (bc_write.origination_date, sizeof (bc_write.origination_date), "%d/%02d/%02d", 2006, 3, 30) ; cannam@85: snprintf (bc_write.origination_time, sizeof (bc_write.origination_time), "%02d:%02d:%02d", 20, 27, 0) ; cannam@85: snprintf (bc_write.umid, sizeof (bc_write.umid), "Some umid") ; cannam@85: bc_write.coding_history_size = 0 ; cannam@85: cannam@85: file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ; cannam@85: if (sf_command (file, SFC_SET_BROADCAST_INFO, &bc_write, sizeof (bc_write)) == SF_FALSE) cannam@85: { printf ("\n\nLine %d : sf_command (SFC_SET_BROADCAST_INFO) failed.\n\n", __LINE__) ; cannam@85: exit (1) ; cannam@85: } ; cannam@85: test_write_double_or_die (file, 0, double_data, BUFFER_LEN, __LINE__) ; cannam@85: sf_close (file) ; cannam@85: cannam@85: memset (&bc_read, 0, sizeof (bc_read)) ; cannam@85: cannam@85: file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ; cannam@85: if (sf_command (file, SFC_GET_BROADCAST_INFO, &bc_read, sizeof (bc_read)) == SF_FALSE) cannam@85: { printf ("\n\nLine %d : sf_command (SFC_GET_BROADCAST_INFO) failed.\n\n", __LINE__) ; cannam@85: exit (1) ; cannam@85: return ; cannam@85: } ; cannam@85: check_log_buffer_or_die (file, __LINE__) ; cannam@85: sf_close (file) ; cannam@85: cannam@85: if (bc_read.version != 1) cannam@85: { printf ("\n\nLine %d : Read bad version number %d.\n\n", __LINE__, bc_read.version) ; cannam@85: exit (1) ; cannam@85: return ; cannam@85: } ; cannam@85: cannam@85: bc_read.version = bc_write.version = 0 ; cannam@85: cannam@85: if (memcmp (bc_write.description, bc_read.description, sizeof (bc_write.description)) != 0) cannam@85: { printf ("\n\nLine %d : description mismatch :\n\twrite : '%s'\n\tread : '%s'\n\n", __LINE__, bc_write.description, bc_read.description) ; cannam@85: errors ++ ; cannam@85: } ; cannam@85: cannam@85: if (memcmp (bc_write.originator, bc_read.originator, sizeof (bc_write.originator)) != 0) cannam@85: { printf ("\n\nLine %d : originator mismatch :\n\twrite : '%s'\n\tread : '%s'\n\n", __LINE__, bc_write.originator, bc_read.originator) ; cannam@85: errors ++ ; cannam@85: } ; cannam@85: cannam@85: if (memcmp (bc_write.originator_reference, bc_read.originator_reference, sizeof (bc_write.originator_reference)) != 0) cannam@85: { printf ("\n\nLine %d : originator_reference mismatch :\n\twrite : '%s'\n\tread : '%s'\n\n", __LINE__, bc_write.originator_reference, bc_read.originator_reference) ; cannam@85: errors ++ ; cannam@85: } ; cannam@85: cannam@85: if (memcmp (bc_write.origination_date, bc_read.origination_date, sizeof (bc_write.origination_date)) != 0) cannam@85: { printf ("\n\nLine %d : origination_date mismatch :\n\twrite : '%s'\n\tread : '%s'\n\n", __LINE__, bc_write.origination_date, bc_read.origination_date) ; cannam@85: errors ++ ; cannam@85: } ; cannam@85: cannam@85: if (memcmp (bc_write.origination_time, bc_read.origination_time, sizeof (bc_write.origination_time)) != 0) cannam@85: { printf ("\n\nLine %d : origination_time mismatch :\n\twrite : '%s'\n\tread : '%s'\n\n", __LINE__, bc_write.origination_time, bc_read.origination_time) ; cannam@85: errors ++ ; cannam@85: } ; cannam@85: cannam@85: if (memcmp (bc_write.umid, bc_read.umid, sizeof (bc_write.umid)) != 0) cannam@85: { printf ("\n\nLine %d : umid mismatch :\n\twrite : '%s'\n\tread : '%s'\n\n", __LINE__, bc_write.umid, bc_read.umid) ; cannam@85: errors ++ ; cannam@85: } ; cannam@85: cannam@85: if (errors) cannam@85: exit (1) ; cannam@85: cannam@85: unlink (filename) ; cannam@85: puts ("ok") ; cannam@85: } /* broadcast_test */ cannam@85: cannam@85: static void cannam@85: broadcast_rdwr_test (const char *filename, int filetype) cannam@85: { SF_BROADCAST_INFO binfo ; cannam@85: SNDFILE *file ; cannam@85: SF_INFO sfinfo ; cannam@85: sf_count_t frames ; cannam@85: cannam@85: print_test_name (__func__, filename) ; cannam@85: cannam@85: create_short_sndfile (filename, filetype, 2) ; cannam@85: cannam@85: memset (&sfinfo, 0, sizeof (sfinfo)) ; cannam@85: memset (&binfo, 0, sizeof (binfo)) ; cannam@85: cannam@85: snprintf (binfo.description, sizeof (binfo.description), "Test description") ; cannam@85: snprintf (binfo.originator, sizeof (binfo.originator), "Test originator") ; cannam@85: snprintf (binfo.originator_reference, sizeof (binfo.originator_reference), "%08x-%08x", (unsigned int) time (NULL), (unsigned int) (~ time (NULL))) ; cannam@85: snprintf (binfo.origination_date, sizeof (binfo.origination_date), "%d/%02d/%02d", 2006, 3, 30) ; cannam@85: snprintf (binfo.origination_time, sizeof (binfo.origination_time), "%02d:%02d:%02d", 20, 27, 0) ; cannam@85: snprintf (binfo.umid, sizeof (binfo.umid), "Some umid") ; cannam@85: binfo.coding_history_size = 0 ; cannam@85: cannam@85: file = test_open_file_or_die (filename, SFM_RDWR, &sfinfo, SF_TRUE, __LINE__) ; cannam@85: frames = sfinfo.frames ; cannam@85: if (sf_command (file, SFC_SET_BROADCAST_INFO, &binfo, sizeof (binfo)) != SF_FALSE) cannam@85: { printf ("\n\nLine %d : sf_command (SFC_SET_BROADCAST_INFO) should have failed but didn't.\n\n", __LINE__) ; cannam@85: exit (1) ; cannam@85: } ; cannam@85: sf_close (file) ; cannam@85: cannam@85: file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ; cannam@85: sf_close (file) ; cannam@85: exit_if_true (frames != sfinfo.frames, "\n\nLine %d : Frame count %lld should be %lld.\n", __LINE__, sfinfo.frames, frames) ; cannam@85: cannam@85: unlink (filename) ; cannam@85: puts ("ok") ; cannam@85: } /* broadcast_rdwr_test */ cannam@85: cannam@85: static void cannam@85: check_coding_history_newlines (const char *filename) cannam@85: { static SF_BROADCAST_INFO bc_write, bc_read ; cannam@85: SNDFILE *file ; cannam@85: SF_INFO sfinfo ; cannam@85: unsigned k ; cannam@85: cannam@85: sfinfo.samplerate = 22050 ; cannam@85: sfinfo.format = SF_FORMAT_WAV | SF_FORMAT_PCM_16 ; cannam@85: sfinfo.channels = 1 ; cannam@85: cannam@85: memset (&bc_write, 0, sizeof (bc_write)) ; cannam@85: cannam@85: snprintf (bc_write.description, sizeof (bc_write.description), "Test description") ; cannam@85: snprintf (bc_write.originator, sizeof (bc_write.originator), "Test originator") ; cannam@85: snprintf (bc_write.originator_reference, sizeof (bc_write.originator_reference), "%08x-%08x", (unsigned int) time (NULL), (unsigned int) (~ time (NULL))) ; cannam@85: snprintf (bc_write.origination_date, sizeof (bc_write.origination_date), "%d/%02d/%02d", 2006, 3, 30) ; cannam@85: snprintf (bc_write.origination_time, sizeof (bc_write.origination_time), "%02d:%02d:%02d", 20, 27, 0) ; cannam@85: snprintf (bc_write.umid, sizeof (bc_write.umid), "Some umid") ; cannam@85: bc_write.coding_history_size = snprintf (bc_write.coding_history, sizeof (bc_write.coding_history), "This has\nUnix\nand\rMac OS9\rline endings.\nLast line") ; ; cannam@85: cannam@85: file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ; cannam@85: if (sf_command (file, SFC_SET_BROADCAST_INFO, &bc_write, sizeof (bc_write)) == SF_FALSE) cannam@85: { printf ("\n\nLine %d : sf_command (SFC_SET_BROADCAST_INFO) failed.\n\n", __LINE__) ; cannam@85: exit (1) ; cannam@85: } ; cannam@85: cannam@85: test_write_double_or_die (file, 0, double_data, BUFFER_LEN, __LINE__) ; cannam@85: sf_close (file) ; cannam@85: cannam@85: memset (&bc_read, 0, sizeof (bc_read)) ; cannam@85: cannam@85: file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ; cannam@85: if (sf_command (file, SFC_GET_BROADCAST_INFO, &bc_read, sizeof (bc_read)) == SF_FALSE) cannam@85: { printf ("\n\nLine %d : sf_command (SFC_SET_BROADCAST_INFO) failed.\n\n", __LINE__) ; cannam@85: exit (1) ; cannam@85: } ; cannam@85: check_log_buffer_or_die (file, __LINE__) ; cannam@85: sf_close (file) ; cannam@85: cannam@85: if (bc_read.coding_history_size == 0) cannam@85: { printf ("\n\nLine %d : missing coding history.\n\n", __LINE__) ; cannam@85: exit (1) ; cannam@85: } ; cannam@85: cannam@85: if (strstr (bc_read.coding_history, "Last line") == NULL) cannam@85: { printf ("\n\nLine %d : coding history truncated.\n\n", __LINE__) ; cannam@85: exit (1) ; cannam@85: } ; cannam@85: cannam@85: for (k = 1 ; k < bc_read.coding_history_size ; k++) cannam@85: { if (bc_read.coding_history [k] == '\n' && bc_read.coding_history [k - 1] != '\r') cannam@85: { printf ("\n\nLine %d : '\\n' without '\\r' before.\n\n", __LINE__) ; cannam@85: exit (1) ; cannam@85: } ; cannam@85: cannam@85: if (bc_read.coding_history [k] == '\r' && bc_read.coding_history [k + 1] != '\n') cannam@85: { printf ("\n\nLine %d : '\\r' without '\\n' after.\n\n", __LINE__) ; cannam@85: exit (1) ; cannam@85: } ; cannam@85: cannam@85: if (bc_read.coding_history [k] == 0 && k < bc_read.coding_history_size - 1) cannam@85: { printf ("\n\nLine %d : '\\0' within coding history at index %d of %d.\n\n", __LINE__, k, bc_read.coding_history_size) ; cannam@85: exit (1) ; cannam@85: } ; cannam@85: } ; cannam@85: cannam@85: return ; cannam@85: } /* check_coding_history_newlines */ cannam@85: cannam@85: static void cannam@85: broadcast_coding_history_test (const char *filename) cannam@85: { static SF_BROADCAST_INFO bc_write, bc_read ; cannam@85: SNDFILE *file ; cannam@85: SF_INFO sfinfo ; cannam@85: const char *default_history = "A=PCM,F=22050,W=16,M=mono" ; cannam@85: const char *supplied_history = cannam@85: "A=PCM,F=44100,W=24,M=mono,T=other\r\n" cannam@85: "A=PCM,F=22050,W=16,M=mono,T=yet_another\r\n" ; cannam@85: cannam@85: print_test_name ("broadcast_coding_history_test", filename) ; cannam@85: cannam@85: sfinfo.samplerate = 22050 ; cannam@85: sfinfo.format = SF_FORMAT_WAV | SF_FORMAT_PCM_16 ; cannam@85: sfinfo.channels = 1 ; cannam@85: cannam@85: memset (&bc_write, 0, sizeof (bc_write)) ; cannam@85: cannam@85: snprintf (bc_write.description, sizeof (bc_write.description), "Test description") ; cannam@85: snprintf (bc_write.originator, sizeof (bc_write.originator), "Test originator") ; cannam@85: snprintf (bc_write.originator_reference, sizeof (bc_write.originator_reference), "%08x-%08x", (unsigned int) time (NULL), (unsigned int) (~ time (NULL))) ; cannam@85: snprintf (bc_write.origination_date, sizeof (bc_write.origination_date), "%d/%02d/%02d", 2006, 3, 30) ; cannam@85: snprintf (bc_write.origination_time, sizeof (bc_write.origination_time), "%02d:%02d:%02d", 20, 27, 0) ; cannam@85: snprintf (bc_write.umid, sizeof (bc_write.umid), "Some umid") ; cannam@85: /* Coding history will be filled in by the library. */ cannam@85: bc_write.coding_history_size = 0 ; cannam@85: cannam@85: file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ; cannam@85: if (sf_command (file, SFC_SET_BROADCAST_INFO, &bc_write, sizeof (bc_write)) == SF_FALSE) cannam@85: { printf ("\n\nLine %d : sf_command (SFC_SET_BROADCAST_INFO) failed.\n\n", __LINE__) ; cannam@85: exit (1) ; cannam@85: } ; cannam@85: cannam@85: test_write_double_or_die (file, 0, double_data, BUFFER_LEN, __LINE__) ; cannam@85: sf_close (file) ; cannam@85: cannam@85: memset (&bc_read, 0, sizeof (bc_read)) ; cannam@85: cannam@85: file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ; cannam@85: if (sf_command (file, SFC_GET_BROADCAST_INFO, &bc_read, sizeof (bc_read)) == SF_FALSE) cannam@85: { printf ("\n\nLine %d : sf_command (SFC_SET_BROADCAST_INFO) failed.\n\n", __LINE__) ; cannam@85: exit (1) ; cannam@85: } ; cannam@85: check_log_buffer_or_die (file, __LINE__) ; cannam@85: sf_close (file) ; cannam@85: cannam@85: if (bc_read.coding_history_size == 0) cannam@85: { printf ("\n\nLine %d : missing coding history.\n\n", __LINE__) ; cannam@85: exit (1) ; cannam@85: } ; cannam@85: cannam@85: if (bc_read.coding_history_size < strlen (default_history) || memcmp (bc_read.coding_history, default_history, strlen (default_history)) != 0) cannam@85: { printf ("\n\n" cannam@85: "Line %d : unexpected coding history '%.*s',\n" cannam@85: " should be '%s'\n\n", __LINE__, bc_read.coding_history_size, bc_read.coding_history, default_history) ; cannam@85: exit (1) ; cannam@85: } ; cannam@85: cannam@85: bc_write.coding_history_size = strlen (supplied_history) ; cannam@85: bc_write.coding_history_size = snprintf (bc_write.coding_history, sizeof (bc_write.coding_history), "%s", supplied_history) ; cannam@85: cannam@85: file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ; cannam@85: if (sf_command (file, SFC_SET_BROADCAST_INFO, &bc_write, sizeof (bc_write)) == SF_FALSE) cannam@85: { printf ("\n\nLine %d : sf_command (SFC_SET_BROADCAST_INFO) failed.\n\n", __LINE__) ; cannam@85: exit (1) ; cannam@85: } ; cannam@85: cannam@85: test_write_double_or_die (file, 0, double_data, BUFFER_LEN, __LINE__) ; cannam@85: sf_close (file) ; cannam@85: cannam@85: memset (&bc_read, 0, sizeof (bc_read)) ; cannam@85: cannam@85: file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ; cannam@85: if (sf_command (file, SFC_GET_BROADCAST_INFO, &bc_read, sizeof (bc_read)) == SF_FALSE) cannam@85: { printf ("\n\nLine %d : sf_command (SFC_SET_BROADCAST_INFO) failed.\n\n", __LINE__) ; cannam@85: exit (1) ; cannam@85: } ; cannam@85: cannam@85: check_log_buffer_or_die (file, __LINE__) ; cannam@85: sf_close (file) ; cannam@85: cannam@85: if (strstr (bc_read.coding_history, supplied_history) != bc_read.coding_history) cannam@85: { printf ("\n\nLine %d : unexpected coding history :\n" cannam@85: "----------------------------------------------------\n%s" cannam@85: "----------------------------------------------------\n" cannam@85: "should be this :\n" cannam@85: "----------------------------------------------------\n%s" cannam@85: "----------------------------------------------------\n" cannam@85: "with one more line at the end.\n\n", cannam@85: __LINE__, bc_read.coding_history, supplied_history) ; cannam@85: exit (1) ; cannam@85: } ; cannam@85: cannam@85: check_coding_history_newlines (filename) ; cannam@85: cannam@85: unlink (filename) ; cannam@85: puts ("ok") ; cannam@85: } /* broadcast_coding_history_test */ cannam@85: cannam@85: /*============================================================================== cannam@85: */ cannam@85: cannam@85: static void cannam@85: broadcast_coding_history_size (const char *filename) cannam@85: { /* SF_BROADCAST_INFO struct with coding_history field of 1024 bytes. */ cannam@85: static SF_BROADCAST_INFO_VAR (1024) bc_write ; cannam@85: static SF_BROADCAST_INFO_VAR (1024) bc_read ; cannam@85: SNDFILE *file ; cannam@85: SF_INFO sfinfo ; cannam@85: int k ; cannam@85: cannam@85: print_test_name (__func__, filename) ; cannam@85: cannam@85: sfinfo.samplerate = 22050 ; cannam@85: sfinfo.format = SF_FORMAT_WAV | SF_FORMAT_PCM_16 ; cannam@85: sfinfo.channels = 1 ; cannam@85: cannam@85: memset (&bc_write, 0, sizeof (bc_write)) ; cannam@85: cannam@85: snprintf (bc_write.description, sizeof (bc_write.description), "Test description") ; cannam@85: snprintf (bc_write.originator, sizeof (bc_write.originator), "Test originator") ; cannam@85: snprintf (bc_write.originator_reference, sizeof (bc_write.originator_reference), "%08x-%08x", (unsigned int) time (NULL), (unsigned int) (~ time (NULL))) ; cannam@85: snprintf (bc_write.origination_date, sizeof (bc_write.origination_date), "%d/%02d/%02d", 2006, 3, 30) ; cannam@85: snprintf (bc_write.origination_time, sizeof (bc_write.origination_time), "%02d:%02d:%02d", 20, 27, 0) ; cannam@85: snprintf (bc_write.umid, sizeof (bc_write.umid), "Some umid") ; cannam@85: bc_write.coding_history_size = 0 ; cannam@85: cannam@85: for (k = 0 ; bc_write.coding_history_size < 512 ; k++) cannam@85: { snprintf (bc_write.coding_history + bc_write.coding_history_size, cannam@85: sizeof (bc_write.coding_history) - bc_write.coding_history_size, "line %4d\n", k) ; cannam@85: bc_write.coding_history_size = strlen (bc_write.coding_history) ; cannam@85: } ; cannam@85: cannam@85: exit_if_true (bc_write.coding_history_size < 512, cannam@85: "\n\nLine %d : bc_write.coding_history_size (%d) should be > 512.\n\n", __LINE__, bc_write.coding_history_size) ; cannam@85: cannam@85: file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ; cannam@85: if (sf_command (file, SFC_SET_BROADCAST_INFO, &bc_write, sizeof (bc_write)) == SF_FALSE) cannam@85: { printf ("\n\nLine %d : sf_command (SFC_SET_BROADCAST_INFO) failed.\n\n", __LINE__) ; cannam@85: exit (1) ; cannam@85: } ; cannam@85: cannam@85: test_write_double_or_die (file, 0, double_data, BUFFER_LEN, __LINE__) ; cannam@85: sf_close (file) ; cannam@85: cannam@85: memset (&bc_read, 0, sizeof (bc_read)) ; cannam@85: cannam@85: file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ; cannam@85: if (sf_command (file, SFC_GET_BROADCAST_INFO, &bc_read, sizeof (bc_read)) == SF_FALSE) cannam@85: { printf ("\n\nLine %d : sf_command (SFC_SET_BROADCAST_INFO) failed.\n\n", __LINE__) ; cannam@85: exit (1) ; cannam@85: } ; cannam@85: check_log_buffer_or_die (file, __LINE__) ; cannam@85: sf_close (file) ; cannam@85: cannam@85: exit_if_true (bc_read.coding_history_size < 512, cannam@85: "\n\nLine %d : unexpected coding history size %d (should be > 512).\n\n", __LINE__, bc_read.coding_history_size) ; cannam@85: cannam@85: exit_if_true (strstr (bc_read.coding_history, "libsndfile") == NULL, cannam@85: "\n\nLine %d : coding history incomplete (should contain 'libsndfile').\n\n", __LINE__) ; cannam@85: cannam@85: unlink (filename) ; cannam@85: puts ("ok") ; cannam@85: } /* broadcast_coding_history_size */ cannam@85: cannam@85: /*============================================================================== cannam@85: */ cannam@85: cannam@85: static void cannam@85: channel_map_test (const char *filename, int filetype) cannam@85: { SNDFILE *file ; cannam@85: SF_INFO sfinfo ; cannam@85: int channel_map_read [4], channel_map_write [4] = cannam@85: { SF_CHANNEL_MAP_LEFT, SF_CHANNEL_MAP_RIGHT, SF_CHANNEL_MAP_LFE, cannam@85: SF_CHANNEL_MAP_REAR_CENTER cannam@85: } ; cannam@85: cannam@85: print_test_name ("channel_map_test", filename) ; cannam@85: cannam@85: memset (&sfinfo, 0, sizeof (sfinfo)) ; cannam@85: sfinfo.samplerate = 11025 ; cannam@85: sfinfo.format = filetype ; cannam@85: sfinfo.channels = ARRAY_LEN (channel_map_read) ; cannam@85: cannam@85: switch (filetype & SF_FORMAT_TYPEMASK) cannam@85: { /* WAVEX and RF64 have a default channel map, even if you don't specify one. */ cannam@85: case SF_FORMAT_WAVEX : cannam@85: case SF_FORMAT_RF64 : cannam@85: /* Write file without channel map. */ cannam@85: file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ; cannam@85: test_write_double_or_die (file, 0, double_data, BUFFER_LEN, __LINE__) ; cannam@85: sf_close (file) ; cannam@85: cannam@85: /* Read file making default channel map exists. */ cannam@85: file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ; cannam@85: exit_if_true ( cannam@85: sf_command (file, SFC_GET_CHANNEL_MAP_INFO, channel_map_read, sizeof (channel_map_read)) == SF_FALSE, cannam@85: "\n\nLine %d : sf_command (SFC_GET_CHANNEL_MAP_INFO) should not have failed.\n\n", __LINE__ cannam@85: ) ; cannam@85: check_log_buffer_or_die (file, __LINE__) ; cannam@85: sf_close (file) ; cannam@85: break ; cannam@85: cannam@85: default : cannam@85: break ; cannam@85: } ; cannam@85: cannam@85: /* Write file with a channel map. */ cannam@85: file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ; cannam@85: exit_if_true ( cannam@85: sf_command (file, SFC_SET_CHANNEL_MAP_INFO, channel_map_write, sizeof (channel_map_write)) == SF_FALSE, cannam@85: "\n\nLine %d : sf_command (SFC_SET_CHANNEL_MAP_INFO) failed.\n\n", __LINE__ cannam@85: ) ; cannam@85: test_write_double_or_die (file, 0, double_data, BUFFER_LEN, __LINE__) ; cannam@85: sf_close (file) ; cannam@85: cannam@85: /* Read file making sure no channel map exists. */ cannam@85: file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ; cannam@85: exit_if_true ( cannam@85: sf_command (file, SFC_GET_CHANNEL_MAP_INFO, channel_map_read, sizeof (channel_map_read)) != SF_TRUE, cannam@85: "\n\nLine %d : sf_command (SFC_GET_CHANNEL_MAP_INFO) failed.\n\n", __LINE__ cannam@85: ) ; cannam@85: check_log_buffer_or_die (file, __LINE__) ; cannam@85: sf_close (file) ; cannam@85: cannam@85: exit_if_true ( cannam@85: memcmp (channel_map_read, channel_map_write, sizeof (channel_map_read)) != 0, cannam@85: "\n\nLine %d : Channel map read does not match channel map written.\n\n", __LINE__ cannam@85: ) ; cannam@85: cannam@85: unlink (filename) ; cannam@85: puts ("ok") ; cannam@85: } /* channel_map_test */ cannam@85: cannam@85: static void cannam@85: raw_needs_endswap_test (const char *filename, int filetype) cannam@85: { static int subtypes [] = cannam@85: { SF_FORMAT_FLOAT, SF_FORMAT_DOUBLE, cannam@85: SF_FORMAT_PCM_16, SF_FORMAT_PCM_24, SF_FORMAT_PCM_32 cannam@85: } ; cannam@85: SNDFILE *file ; cannam@85: SF_INFO sfinfo ; cannam@85: unsigned k ; cannam@85: int needs_endswap ; cannam@85: cannam@85: print_test_name (__func__, filename) ; cannam@85: cannam@85: for (k = 0 ; k < ARRAY_LEN (subtypes) ; k++) cannam@85: { cannam@85: if (filetype == (SF_ENDIAN_LITTLE | SF_FORMAT_AIFF)) cannam@85: switch (subtypes [k]) cannam@85: { /* Little endian AIFF does not AFAIK support fl32 and fl64. */ cannam@85: case SF_FORMAT_FLOAT : cannam@85: case SF_FORMAT_DOUBLE : cannam@85: continue ; cannam@85: default : cannam@85: break ; cannam@85: } ; cannam@85: cannam@85: memset (&sfinfo, 0, sizeof (sfinfo)) ; cannam@85: sfinfo.samplerate = 11025 ; cannam@85: sfinfo.format = filetype | subtypes [k] ; cannam@85: sfinfo.channels = 1 ; cannam@85: cannam@85: file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ; cannam@85: test_write_double_or_die (file, 0, double_data, BUFFER_LEN, __LINE__) ; cannam@85: sf_close (file) ; cannam@85: cannam@85: memset (&sfinfo, 0, sizeof (sfinfo)) ; cannam@85: file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ; cannam@85: cannam@85: needs_endswap = sf_command (file, SFC_RAW_DATA_NEEDS_ENDSWAP, NULL, 0) ; cannam@85: cannam@85: switch (filetype) cannam@85: { case SF_FORMAT_WAV : cannam@85: case SF_FORMAT_WAVEX : cannam@85: case SF_FORMAT_AIFF | SF_ENDIAN_LITTLE : cannam@85: exit_if_true (needs_endswap != CPU_IS_BIG_ENDIAN, cannam@85: "\n\nLine %d : SFC_RAW_DATA_NEEDS_ENDSWAP failed for (%d | %d).\n\n", __LINE__, filetype, k) ; cannam@85: break ; cannam@85: cannam@85: case SF_FORMAT_AIFF : cannam@85: case SF_FORMAT_WAV | SF_ENDIAN_BIG : cannam@85: exit_if_true (needs_endswap != CPU_IS_LITTLE_ENDIAN, cannam@85: "\n\nLine %d : SFC_RAW_DATA_NEEDS_ENDSWAP failed for (%d | %d).\n\n", __LINE__, filetype, k) ; cannam@85: break ; cannam@85: cannam@85: default : cannam@85: printf ("\n\nLine %d : bad format value %d.\n\n", __LINE__, filetype) ; cannam@85: exit (1) ; cannam@85: break ; cannam@85: } ; cannam@85: cannam@85: sf_close (file) ; cannam@85: } ; cannam@85: cannam@85: unlink (filename) ; cannam@85: puts ("ok") ; cannam@85: } /* raw_needs_endswap_test */