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