annotate src/libsndfile-1.0.25/tests/floating_point_test.c @ 83:ae30d91d2ffe

Replace these with versions built using an older toolset (so as to avoid ABI compatibilities when linking on Ubuntu 14.04 for packaging purposes)
author Chris Cannam
date Fri, 07 Feb 2020 11:51:13 +0000
parents c7265573341e
children
rev   line source
Chris@0 1 /*
Chris@0 2 ** Copyright (C) 1999-2011 Erik de Castro Lopo <erikd@mega-nerd.com>
Chris@0 3 **
Chris@0 4 ** This program is free software; you can redistribute it and/or modify
Chris@0 5 ** it under the terms of the GNU General Public License as published by
Chris@0 6 ** the Free Software Foundation; either version 2 of the License, or
Chris@0 7 ** (at your option) any later version.
Chris@0 8 **
Chris@0 9 ** This program is distributed in the hope that it will be useful,
Chris@0 10 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@0 11 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@0 12 ** GNU General Public License for more details.
Chris@0 13 **
Chris@0 14 ** You should have received a copy of the GNU General Public License
Chris@0 15 ** along with this program; if not, write to the Free Software
Chris@0 16 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Chris@0 17 */
Chris@0 18
Chris@0 19 #include "sfconfig.h"
Chris@0 20
Chris@0 21 #include <stdio.h>
Chris@0 22 #include <stdlib.h>
Chris@0 23 #include <string.h>
Chris@0 24 #include <math.h>
Chris@0 25
Chris@0 26 #if HAVE_UNISTD_H
Chris@0 27 #include <unistd.h>
Chris@0 28 #endif
Chris@0 29
Chris@0 30 #include <sndfile.h>
Chris@0 31
Chris@0 32 #include "dft_cmp.h"
Chris@0 33 #include "utils.h"
Chris@0 34
Chris@0 35 #define SAMPLE_RATE 16000
Chris@0 36
Chris@0 37 static void float_scaled_test (const char *filename, int allow_exit, int replace_float, int filetype, double target_snr) ;
Chris@0 38 static void double_scaled_test (const char *filename, int allow_exit, int replace_float, int filetype, double target_snr) ;
Chris@0 39
Chris@0 40 static void float_short_little_test (const char * filename) ;
Chris@0 41 static void float_short_big_test (const char * filename) ;
Chris@0 42 static void float_int_little_test (const char * filename) ;
Chris@0 43 static void float_int_big_test (const char * filename) ;
Chris@0 44 static void double_short_little_test (const char * filename) ;
Chris@0 45 static void double_short_big_test (const char * filename) ;
Chris@0 46 static void double_int_little_test (const char * filename) ;
Chris@0 47 static void double_int_big_test (const char * filename) ;
Chris@0 48
Chris@0 49
Chris@0 50 static double double_data [DFT_DATA_LENGTH] ;
Chris@0 51 static double double_test [DFT_DATA_LENGTH] ;
Chris@0 52
Chris@0 53 static float float_data [DFT_DATA_LENGTH] ;
Chris@0 54 static float float_test [DFT_DATA_LENGTH] ;
Chris@0 55
Chris@0 56 static double double_data [DFT_DATA_LENGTH] ;
Chris@0 57 static short short_data [DFT_DATA_LENGTH] ;
Chris@0 58 static int int_data [DFT_DATA_LENGTH] ;
Chris@0 59
Chris@0 60 int
Chris@0 61 main (int argc, char *argv [])
Chris@0 62 { int allow_exit = 1 ;
Chris@0 63
Chris@0 64 if (argc == 2 && ! strstr (argv [1], "no-exit"))
Chris@0 65 allow_exit = 0 ;
Chris@0 66
Chris@0 67 #if ((HAVE_LRINTF == 0) && (HAVE_LRINT_REPLACEMENT == 0))
Chris@0 68 puts ("*** Cannot run this test on this platform because it lacks lrintf().") ;
Chris@0 69 exit (0) ;
Chris@0 70 #endif
Chris@0 71
Chris@0 72 /* Float tests. */
Chris@0 73 float_scaled_test ("float.raw", allow_exit, SF_FALSE, SF_ENDIAN_LITTLE | SF_FORMAT_RAW | SF_FORMAT_FLOAT, -163.0) ;
Chris@0 74
Chris@0 75 /* Test both signed and unsigned 8 bit files. */
Chris@0 76 float_scaled_test ("pcm_s8.raw", allow_exit, SF_FALSE, SF_FORMAT_RAW | SF_FORMAT_PCM_S8, -39.0) ;
Chris@0 77 float_scaled_test ("pcm_u8.raw", allow_exit, SF_FALSE, SF_FORMAT_RAW | SF_FORMAT_PCM_U8, -39.0) ;
Chris@0 78
Chris@0 79 float_scaled_test ("pcm_16.raw", allow_exit, SF_FALSE, SF_ENDIAN_BIG | SF_FORMAT_RAW | SF_FORMAT_PCM_16, -87.0) ;
Chris@0 80 float_scaled_test ("pcm_24.raw", allow_exit, SF_FALSE, SF_ENDIAN_LITTLE | SF_FORMAT_RAW | SF_FORMAT_PCM_24, -138.0) ;
Chris@0 81 float_scaled_test ("pcm_32.raw", allow_exit, SF_FALSE, SF_ENDIAN_BIG | SF_FORMAT_RAW | SF_FORMAT_PCM_32, -163.0) ;
Chris@0 82
Chris@0 83 float_scaled_test ("ulaw.raw", allow_exit, SF_FALSE, SF_FORMAT_RAW | SF_FORMAT_ULAW, -50.0) ;
Chris@0 84 float_scaled_test ("alaw.raw", allow_exit, SF_FALSE, SF_FORMAT_RAW | SF_FORMAT_ALAW, -49.0) ;
Chris@0 85
Chris@0 86 float_scaled_test ("ima_adpcm.wav", allow_exit, SF_FALSE, SF_FORMAT_WAV | SF_FORMAT_IMA_ADPCM, -47.0) ;
Chris@0 87 float_scaled_test ("ms_adpcm.wav" , allow_exit, SF_FALSE, SF_FORMAT_WAV | SF_FORMAT_MS_ADPCM, -40.0) ;
Chris@0 88 float_scaled_test ("gsm610.raw" , allow_exit, SF_FALSE, SF_FORMAT_RAW | SF_FORMAT_GSM610, -33.0) ;
Chris@0 89
Chris@0 90 float_scaled_test ("g721_32.au", allow_exit, SF_FALSE, SF_FORMAT_AU | SF_FORMAT_G721_32, -34.0) ;
Chris@0 91 float_scaled_test ("g723_24.au", allow_exit, SF_FALSE, SF_FORMAT_AU | SF_FORMAT_G723_24, -34.0) ;
Chris@0 92 float_scaled_test ("g723_40.au", allow_exit, SF_FALSE, SF_FORMAT_AU | SF_FORMAT_G723_40, -40.0) ;
Chris@0 93
Chris@0 94 /* PAF files do not use the same encoding method for 24 bit PCM data as other file
Chris@0 95 ** formats so we need to explicitly test it here.
Chris@0 96 */
Chris@0 97 float_scaled_test ("le_paf_24.paf", allow_exit, SF_FALSE, SF_ENDIAN_LITTLE | SF_FORMAT_PAF | SF_FORMAT_PCM_24, -149.0) ;
Chris@0 98 float_scaled_test ("be_paf_24.paf", allow_exit, SF_FALSE, SF_ENDIAN_BIG | SF_FORMAT_PAF | SF_FORMAT_PCM_24, -149.0) ;
Chris@0 99
Chris@0 100 float_scaled_test ("dwvw_12.raw", allow_exit, SF_FALSE, SF_FORMAT_RAW | SF_FORMAT_DWVW_12, -64.0) ;
Chris@0 101 float_scaled_test ("dwvw_16.raw", allow_exit, SF_FALSE, SF_FORMAT_RAW | SF_FORMAT_DWVW_16, -92.0) ;
Chris@0 102 float_scaled_test ("dwvw_24.raw", allow_exit, SF_FALSE, SF_FORMAT_RAW | SF_FORMAT_DWVW_24, -151.0) ;
Chris@0 103
Chris@0 104 float_scaled_test ("adpcm.vox", allow_exit, SF_FALSE, SF_FORMAT_RAW | SF_FORMAT_VOX_ADPCM, -40.0) ;
Chris@0 105
Chris@0 106 float_scaled_test ("dpcm_16.xi", allow_exit, SF_FALSE, SF_FORMAT_XI | SF_FORMAT_DPCM_16, -90.0) ;
Chris@0 107 float_scaled_test ("dpcm_8.xi" , allow_exit, SF_FALSE, SF_FORMAT_XI | SF_FORMAT_DPCM_8 , -41.0) ;
Chris@0 108
Chris@0 109 float_scaled_test ("pcm_s8.sds", allow_exit, SF_FALSE, SF_FORMAT_SDS | SF_FORMAT_PCM_S8, -90.0) ;
Chris@0 110 float_scaled_test ("pcm_16.sds", allow_exit, SF_FALSE, SF_FORMAT_SDS | SF_FORMAT_PCM_16, -140.0) ;
Chris@0 111 float_scaled_test ("pcm_24.sds", allow_exit, SF_FALSE, SF_FORMAT_SDS | SF_FORMAT_PCM_24, -170.0) ;
Chris@0 112
Chris@0 113 #if HAVE_EXTERNAL_LIBS
Chris@0 114 float_scaled_test ("flac_8.flac", allow_exit, SF_FALSE, SF_FORMAT_FLAC | SF_FORMAT_PCM_S8, -39.0) ;
Chris@0 115 float_scaled_test ("flac_16.flac", allow_exit, SF_FALSE, SF_FORMAT_FLAC | SF_FORMAT_PCM_16, -87.0) ;
Chris@0 116 float_scaled_test ("flac_24.flac", allow_exit, SF_FALSE, SF_FORMAT_FLAC | SF_FORMAT_PCM_24, -138.0) ;
Chris@0 117
Chris@0 118 float_scaled_test ("vorbis.oga", allow_exit, SF_FALSE, SF_FORMAT_OGG | SF_FORMAT_VORBIS, -31.0) ;
Chris@0 119 #endif
Chris@0 120
Chris@0 121 float_scaled_test ("replace_float.raw", allow_exit, SF_TRUE, SF_ENDIAN_LITTLE | SF_FORMAT_RAW | SF_FORMAT_FLOAT, -163.0) ;
Chris@0 122
Chris@0 123 /*==============================================================================
Chris@0 124 ** Double tests.
Chris@0 125 */
Chris@0 126
Chris@0 127 double_scaled_test ("double.raw", allow_exit, SF_FALSE, SF_FORMAT_RAW | SF_FORMAT_DOUBLE, -300.0) ;
Chris@0 128
Chris@0 129 /* Test both signed (AIFF) and unsigned (WAV) 8 bit files. */
Chris@0 130 double_scaled_test ("pcm_s8.raw", allow_exit, SF_FALSE, SF_FORMAT_RAW | SF_FORMAT_PCM_S8, -39.0) ;
Chris@0 131 double_scaled_test ("pcm_u8.raw", allow_exit, SF_FALSE, SF_FORMAT_RAW | SF_FORMAT_PCM_U8, -39.0) ;
Chris@0 132
Chris@0 133 double_scaled_test ("pcm_16.raw", allow_exit, SF_FALSE, SF_FORMAT_RAW | SF_FORMAT_PCM_16, -87.0) ;
Chris@0 134 double_scaled_test ("pcm_24.raw", allow_exit, SF_FALSE, SF_FORMAT_RAW | SF_FORMAT_PCM_24, -135.0) ;
Chris@0 135 double_scaled_test ("pcm_32.raw", allow_exit, SF_FALSE, SF_FORMAT_RAW | SF_FORMAT_PCM_32, -184.0) ;
Chris@0 136
Chris@0 137 double_scaled_test ("ulaw.raw", allow_exit, SF_FALSE, SF_FORMAT_RAW | SF_FORMAT_ULAW, -50.0) ;
Chris@0 138 double_scaled_test ("alaw.raw", allow_exit, SF_FALSE, SF_FORMAT_RAW | SF_FORMAT_ALAW, -49.0) ;
Chris@0 139
Chris@0 140 double_scaled_test ("ima_adpcm.wav", allow_exit, SF_FALSE, SF_FORMAT_WAV | SF_FORMAT_IMA_ADPCM, -47.0) ;
Chris@0 141 double_scaled_test ("ms_adpcm.wav" , allow_exit, SF_FALSE, SF_FORMAT_WAV | SF_FORMAT_MS_ADPCM, -40.0) ;
Chris@0 142 double_scaled_test ("gsm610.raw" , allow_exit, SF_FALSE, SF_FORMAT_RAW | SF_FORMAT_GSM610, -33.0) ;
Chris@0 143
Chris@0 144 double_scaled_test ("g721_32.au", allow_exit, SF_FALSE, SF_FORMAT_AU | SF_FORMAT_G721_32, -34.0) ;
Chris@0 145 double_scaled_test ("g723_24.au", allow_exit, SF_FALSE, SF_FORMAT_AU | SF_FORMAT_G723_24, -34.0) ;
Chris@0 146 double_scaled_test ("g723_40.au", allow_exit, SF_FALSE, SF_FORMAT_AU | SF_FORMAT_G723_40, -40.0) ;
Chris@0 147
Chris@0 148 /* 24 bit PCM PAF files tested here. */
Chris@0 149 double_scaled_test ("be_paf_24.paf", allow_exit, SF_FALSE, SF_ENDIAN_BIG | SF_FORMAT_PAF | SF_FORMAT_PCM_24, -151.0) ;
Chris@0 150 double_scaled_test ("le_paf_24.paf", allow_exit, SF_FALSE, SF_ENDIAN_LITTLE | SF_FORMAT_PAF | SF_FORMAT_PCM_24, -151.0) ;
Chris@0 151
Chris@0 152 double_scaled_test ("dwvw_12.raw", allow_exit, SF_FALSE, SF_FORMAT_RAW | SF_FORMAT_DWVW_12, -64.0) ;
Chris@0 153 double_scaled_test ("dwvw_16.raw", allow_exit, SF_FALSE, SF_FORMAT_RAW | SF_FORMAT_DWVW_16, -92.0) ;
Chris@0 154 double_scaled_test ("dwvw_24.raw", allow_exit, SF_FALSE, SF_FORMAT_RAW | SF_FORMAT_DWVW_24, -151.0) ;
Chris@0 155
Chris@0 156 double_scaled_test ("adpcm.vox" , allow_exit, SF_FALSE, SF_FORMAT_RAW | SF_FORMAT_VOX_ADPCM, -40.0) ;
Chris@0 157
Chris@0 158 double_scaled_test ("dpcm_16.xi", allow_exit, SF_FALSE, SF_FORMAT_XI | SF_FORMAT_DPCM_16, -90.0) ;
Chris@0 159 double_scaled_test ("dpcm_8.xi" , allow_exit, SF_FALSE, SF_FORMAT_XI | SF_FORMAT_DPCM_8 , -42.0) ;
Chris@0 160
Chris@0 161 double_scaled_test ("pcm_s8.sds", allow_exit, SF_FALSE, SF_FORMAT_SDS | SF_FORMAT_PCM_S8, -90.0) ;
Chris@0 162 double_scaled_test ("pcm_16.sds", allow_exit, SF_FALSE, SF_FORMAT_SDS | SF_FORMAT_PCM_16, -140.0) ;
Chris@0 163 double_scaled_test ("pcm_24.sds", allow_exit, SF_FALSE, SF_FORMAT_SDS | SF_FORMAT_PCM_24, -180.0) ;
Chris@0 164
Chris@0 165 #if HAVE_EXTERNAL_LIBS
Chris@0 166 double_scaled_test ("flac_8.flac", allow_exit, SF_FALSE, SF_FORMAT_FLAC | SF_FORMAT_PCM_S8, -39.0) ;
Chris@0 167 double_scaled_test ("flac_16.flac", allow_exit, SF_FALSE, SF_FORMAT_FLAC | SF_FORMAT_PCM_16, -87.0) ;
Chris@0 168 double_scaled_test ("flac_24.flac", allow_exit, SF_FALSE, SF_FORMAT_FLAC | SF_FORMAT_PCM_24, -138.0) ;
Chris@0 169
Chris@0 170 double_scaled_test ("vorbis.oga", allow_exit, SF_FALSE, SF_FORMAT_OGG | SF_FORMAT_VORBIS, -29.0) ;
Chris@0 171 #endif
Chris@0 172
Chris@0 173 double_scaled_test ("replace_double.raw", allow_exit, SF_TRUE, SF_FORMAT_RAW | SF_FORMAT_DOUBLE, -300.0) ;
Chris@0 174
Chris@0 175 putchar ('\n') ;
Chris@0 176 /* Float int tests. */
Chris@0 177 float_short_little_test ("float_short_little.au") ;
Chris@0 178 float_short_big_test ("float_short_big.au") ;
Chris@0 179 float_int_little_test ("float_int_little.au") ;
Chris@0 180 float_int_big_test ("float_int_big.au") ;
Chris@0 181 double_short_little_test ("double_short_little.au") ;
Chris@0 182 double_short_big_test ("double_short_big.au") ;
Chris@0 183 double_int_little_test ("double_int_little.au") ;
Chris@0 184 double_int_big_test ("double_int_big.au") ;
Chris@0 185
Chris@0 186
Chris@0 187 return 0 ;
Chris@0 188 } /* main */
Chris@0 189
Chris@0 190 /*============================================================================================
Chris@0 191 * Here are the test functions.
Chris@0 192 */
Chris@0 193
Chris@0 194 static void
Chris@0 195 float_scaled_test (const char *filename, int allow_exit, int replace_float, int filetype, double target_snr)
Chris@0 196 { SNDFILE *file ;
Chris@0 197 SF_INFO sfinfo ;
Chris@0 198 double snr ;
Chris@0 199
Chris@0 200 print_test_name ("float_scaled_test", filename) ;
Chris@0 201
Chris@0 202 gen_windowed_sine_float (float_data, DFT_DATA_LENGTH, 1.0) ;
Chris@0 203
Chris@0 204 sfinfo.samplerate = SAMPLE_RATE ;
Chris@0 205 sfinfo.frames = DFT_DATA_LENGTH ;
Chris@0 206 sfinfo.channels = 1 ;
Chris@0 207 sfinfo.format = filetype ;
Chris@0 208
Chris@0 209 file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
Chris@0 210 sf_command (file, SFC_TEST_IEEE_FLOAT_REPLACE, NULL, replace_float) ;
Chris@0 211
Chris@0 212 test_write_float_or_die (file, 0, float_data, DFT_DATA_LENGTH, __LINE__) ;
Chris@0 213
Chris@0 214 sf_close (file) ;
Chris@0 215
Chris@0 216 memset (float_test, 0, sizeof (float_test)) ;
Chris@0 217
Chris@0 218 file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
Chris@0 219 sf_command (file, SFC_TEST_IEEE_FLOAT_REPLACE, NULL, replace_float) ;
Chris@0 220
Chris@0 221 exit_if_true (sfinfo.format != filetype, "\n\nLine %d: Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__, filetype, sfinfo.format) ;
Chris@0 222 exit_if_true (sfinfo.frames < DFT_DATA_LENGTH, "\n\nLine %d: Incorrect number of frames in file (too short). (%ld should be %d)\n", __LINE__, SF_COUNT_TO_LONG (sfinfo.frames), DFT_DATA_LENGTH) ;
Chris@0 223 exit_if_true (sfinfo.channels != 1, "\n\nLine %d: Incorrect number of channels in file.\n", __LINE__) ;
Chris@0 224
Chris@0 225 check_log_buffer_or_die (file, __LINE__) ;
Chris@0 226
Chris@0 227 test_read_float_or_die (file, 0, float_test, DFT_DATA_LENGTH, __LINE__) ;
Chris@0 228
Chris@0 229 sf_close (file) ;
Chris@0 230
Chris@0 231 snr = dft_cmp_float (__LINE__, float_data, float_test, DFT_DATA_LENGTH, target_snr, allow_exit) ;
Chris@0 232
Chris@0 233 exit_if_true (snr > target_snr, "% 6.1fdB SNR\n\n Error : should be better than % 6.1fdB\n\n", snr, target_snr) ;
Chris@0 234
Chris@0 235 printf ("% 6.1fdB SNR ... ok\n", snr) ;
Chris@0 236
Chris@0 237 unlink (filename) ;
Chris@0 238
Chris@0 239 return ;
Chris@0 240 } /* float_scaled_test */
Chris@0 241
Chris@0 242 static void
Chris@0 243 double_scaled_test (const char *filename, int allow_exit, int replace_float, int filetype, double target_snr)
Chris@0 244 { SNDFILE *file ;
Chris@0 245 SF_INFO sfinfo ;
Chris@0 246 double snr ;
Chris@0 247
Chris@0 248 print_test_name ("double_scaled_test", filename) ;
Chris@0 249
Chris@0 250 gen_windowed_sine_double (double_data, DFT_DATA_LENGTH, 0.95) ;
Chris@0 251
Chris@0 252 sfinfo.samplerate = SAMPLE_RATE ;
Chris@0 253 sfinfo.frames = DFT_DATA_LENGTH ;
Chris@0 254 sfinfo.channels = 1 ;
Chris@0 255 sfinfo.format = filetype ;
Chris@0 256
Chris@0 257 file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
Chris@0 258 sf_command (file, SFC_TEST_IEEE_FLOAT_REPLACE, NULL, replace_float) ;
Chris@0 259
Chris@0 260 test_write_double_or_die (file, 0, double_data, DFT_DATA_LENGTH, __LINE__) ;
Chris@0 261
Chris@0 262 sf_close (file) ;
Chris@0 263
Chris@0 264 memset (double_test, 0, sizeof (double_test)) ;
Chris@0 265
Chris@0 266 file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
Chris@0 267 sf_command (file, SFC_TEST_IEEE_FLOAT_REPLACE, NULL, replace_float) ;
Chris@0 268
Chris@0 269 exit_if_true (sfinfo.format != filetype, "\n\nLine %d: Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__, filetype, sfinfo.format) ;
Chris@0 270 exit_if_true (sfinfo.frames < DFT_DATA_LENGTH, "\n\nLine %d: Incorrect number of frames in file (too short). (%ld should be %d)\n", __LINE__, SF_COUNT_TO_LONG (sfinfo.frames), DFT_DATA_LENGTH) ;
Chris@0 271 exit_if_true (sfinfo.channels != 1, "\n\nLine %d: Incorrect number of channels in file.\n", __LINE__) ;
Chris@0 272
Chris@0 273 check_log_buffer_or_die (file, __LINE__) ;
Chris@0 274
Chris@0 275 test_read_double_or_die (file, 0, double_test, DFT_DATA_LENGTH, __LINE__) ;
Chris@0 276
Chris@0 277 sf_close (file) ;
Chris@0 278
Chris@0 279 snr = dft_cmp_double (__LINE__, double_data, double_test, DFT_DATA_LENGTH, target_snr, allow_exit) ;
Chris@0 280
Chris@0 281 exit_if_true (snr > target_snr, "% 6.1fdB SNR\n\n Error : should be better than % 6.1fdB\n\n", snr, target_snr) ;
Chris@0 282
Chris@0 283 printf ("% 6.1fdB SNR ... ok\n", snr) ;
Chris@0 284
Chris@0 285 unlink (filename) ;
Chris@0 286
Chris@0 287 return ;
Chris@0 288 } /* double_scaled_test */
Chris@0 289
Chris@0 290 /*==============================================================================
Chris@0 291 */
Chris@0 292
Chris@0 293
Chris@0 294 static void
Chris@0 295 float_short_little_test (const char * filename)
Chris@0 296 { SNDFILE *file ;
Chris@0 297 SF_INFO sfinfo ;
Chris@0 298 unsigned k, max ;
Chris@0 299
Chris@0 300 print_test_name ("float_short_little_test", filename) ;
Chris@0 301
Chris@0 302 gen_windowed_sine_float (float_data, ARRAY_LEN (float_data), 0.98) ;
Chris@0 303
Chris@0 304 sfinfo.samplerate = SAMPLE_RATE ;
Chris@0 305 sfinfo.frames = ARRAY_LEN (short_data) ;
Chris@0 306 sfinfo.channels = 1 ;
Chris@0 307 sfinfo.format = SF_ENDIAN_LITTLE | SF_FORMAT_AU | SF_FORMAT_FLOAT ;
Chris@0 308
Chris@0 309 file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
Chris@0 310 test_write_float_or_die (file, 0, float_data, ARRAY_LEN (float_data), __LINE__) ;
Chris@0 311 sf_close (file) ;
Chris@0 312
Chris@0 313 file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
Chris@0 314
Chris@0 315 if (sfinfo.frames != ARRAY_LEN (float_data))
Chris@0 316 { printf ("\n\nLine %d: Incorrect number of frames in file (too short). (%ld should be %d)\n", __LINE__, SF_COUNT_TO_LONG (sfinfo.frames), DFT_DATA_LENGTH) ;
Chris@0 317 exit (1) ;
Chris@0 318 } ;
Chris@0 319
Chris@0 320 if (sfinfo.channels != 1)
Chris@0 321 { printf ("\n\nLine %d: Incorrect number of channels in file.\n", __LINE__) ;
Chris@0 322 exit (1) ;
Chris@0 323 } ;
Chris@0 324
Chris@0 325 sf_command (file, SFC_SET_SCALE_FLOAT_INT_READ, NULL, SF_TRUE) ;
Chris@0 326
Chris@0 327 test_read_short_or_die (file, 0, short_data, ARRAY_LEN (short_data), __LINE__) ;
Chris@0 328 sf_close (file) ;
Chris@0 329
Chris@0 330 max = 0 ;
Chris@0 331 for (k = 0 ; k < ARRAY_LEN (short_data) ; k++)
Chris@0 332 if ((unsigned) abs (short_data [k]) > max)
Chris@0 333 max = abs (short_data [k]) ;
Chris@0 334
Chris@0 335 if (1.0 * abs (max - 0x7FFF) / 0x7FFF > 0.01)
Chris@0 336 { printf ("\n\nLine %d: Bad maximum (%d should be %d).\n\n", __LINE__, max, 0x7FFF) ;
Chris@0 337 exit (1) ;
Chris@0 338 } ;
Chris@0 339
Chris@0 340 unlink (filename) ;
Chris@0 341 puts ("ok") ;
Chris@0 342 } /* float_short_little_test */
Chris@0 343
Chris@0 344 static void
Chris@0 345 float_short_big_test (const char * filename)
Chris@0 346 { SNDFILE *file ;
Chris@0 347 SF_INFO sfinfo ;
Chris@0 348 unsigned k, max ;
Chris@0 349
Chris@0 350 print_test_name ("float_short_big_test", filename) ;
Chris@0 351
Chris@0 352 gen_windowed_sine_float (float_data, ARRAY_LEN (float_data), 0.98) ;
Chris@0 353
Chris@0 354 sfinfo.samplerate = SAMPLE_RATE ;
Chris@0 355 sfinfo.frames = ARRAY_LEN (short_data) ;
Chris@0 356 sfinfo.channels = 1 ;
Chris@0 357 sfinfo.format = SF_ENDIAN_BIG | SF_FORMAT_AU | SF_FORMAT_FLOAT ;
Chris@0 358
Chris@0 359 file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
Chris@0 360 test_write_float_or_die (file, 0, float_data, ARRAY_LEN (float_data), __LINE__) ;
Chris@0 361 sf_close (file) ;
Chris@0 362
Chris@0 363 file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
Chris@0 364
Chris@0 365 if (sfinfo.frames != ARRAY_LEN (float_data))
Chris@0 366 { printf ("\n\nLine %d: Incorrect number of frames in file (too short). (%ld should be %d)\n", __LINE__, SF_COUNT_TO_LONG (sfinfo.frames), DFT_DATA_LENGTH) ;
Chris@0 367 exit (1) ;
Chris@0 368 } ;
Chris@0 369
Chris@0 370 if (sfinfo.channels != 1)
Chris@0 371 { printf ("\n\nLine %d: Incorrect number of channels in file.\n", __LINE__) ;
Chris@0 372 exit (1) ;
Chris@0 373 } ;
Chris@0 374
Chris@0 375 sf_command (file, SFC_SET_SCALE_FLOAT_INT_READ, NULL, SF_TRUE) ;
Chris@0 376
Chris@0 377 test_read_short_or_die (file, 0, short_data, ARRAY_LEN (short_data), __LINE__) ;
Chris@0 378 sf_close (file) ;
Chris@0 379
Chris@0 380 max = 0 ;
Chris@0 381 for (k = 0 ; k < ARRAY_LEN (short_data) ; k++)
Chris@0 382 if ((unsigned) abs (short_data [k]) > max)
Chris@0 383 max = abs (short_data [k]) ;
Chris@0 384
Chris@0 385 if (1.0 * abs (max - 0x7FFF) / 0x7FFF > 0.01)
Chris@0 386 { printf ("\n\nLine %d: Bad maximum (%d should be %d).\n\n", __LINE__, max, 0x7FFF) ;
Chris@0 387 exit (1) ;
Chris@0 388 } ;
Chris@0 389
Chris@0 390 unlink (filename) ;
Chris@0 391 puts ("ok") ;
Chris@0 392 } /* float_short_big_test */
Chris@0 393
Chris@0 394 static void
Chris@0 395 float_int_little_test (const char * filename)
Chris@0 396 { SNDFILE *file ;
Chris@0 397 SF_INFO sfinfo ;
Chris@0 398 unsigned k, max ;
Chris@0 399
Chris@0 400 print_test_name ("float_int_little_test", filename) ;
Chris@0 401
Chris@0 402 gen_windowed_sine_float (float_data, ARRAY_LEN (float_data), 0.98) ;
Chris@0 403
Chris@0 404 sfinfo.samplerate = SAMPLE_RATE ;
Chris@0 405 sfinfo.frames = ARRAY_LEN (int_data) ;
Chris@0 406 sfinfo.channels = 1 ;
Chris@0 407 sfinfo.format = SF_ENDIAN_LITTLE | SF_FORMAT_AU | SF_FORMAT_FLOAT ;
Chris@0 408
Chris@0 409 file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
Chris@0 410 test_write_float_or_die (file, 0, float_data, ARRAY_LEN (float_data), __LINE__) ;
Chris@0 411 sf_close (file) ;
Chris@0 412
Chris@0 413 file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
Chris@0 414
Chris@0 415 if (sfinfo.frames != ARRAY_LEN (float_data))
Chris@0 416 { printf ("\n\nLine %d: Incorrect number of frames in file (too short). (%ld should be %d)\n", __LINE__, SF_COUNT_TO_LONG (sfinfo.frames), DFT_DATA_LENGTH) ;
Chris@0 417 exit (1) ;
Chris@0 418 } ;
Chris@0 419
Chris@0 420 if (sfinfo.channels != 1)
Chris@0 421 { printf ("\n\nLine %d: Incorrect number of channels in file.\n", __LINE__) ;
Chris@0 422 exit (1) ;
Chris@0 423 } ;
Chris@0 424
Chris@0 425 sf_command (file, SFC_SET_SCALE_FLOAT_INT_READ, NULL, SF_TRUE) ;
Chris@0 426
Chris@0 427 test_read_int_or_die (file, 0, int_data, ARRAY_LEN (int_data), __LINE__) ;
Chris@0 428 sf_close (file) ;
Chris@0 429
Chris@0 430 max = 0 ;
Chris@0 431 for (k = 0 ; k < ARRAY_LEN (int_data) ; k++)
Chris@0 432 if ((unsigned) abs (int_data [k]) > max)
Chris@0 433 max = abs (int_data [k]) ;
Chris@0 434
Chris@0 435 if (1.0 * abs (max - 0x7FFFFFFF) / 0x7FFFFFFF > 0.01)
Chris@0 436 { printf ("\n\nLine %d: Bad maximum (%d should be %d).\n\n", __LINE__, max, 0x7FFFFFFF) ;
Chris@0 437 exit (1) ;
Chris@0 438 } ;
Chris@0 439
Chris@0 440 unlink (filename) ;
Chris@0 441 puts ("ok") ;
Chris@0 442 } /* float_int_little_test */
Chris@0 443
Chris@0 444 static void
Chris@0 445 float_int_big_test (const char * filename)
Chris@0 446 { SNDFILE *file ;
Chris@0 447 SF_INFO sfinfo ;
Chris@0 448 unsigned k, max ;
Chris@0 449
Chris@0 450 print_test_name ("float_int_big_test", filename) ;
Chris@0 451
Chris@0 452 gen_windowed_sine_float (float_data, ARRAY_LEN (float_data), 0.98) ;
Chris@0 453
Chris@0 454 sfinfo.samplerate = SAMPLE_RATE ;
Chris@0 455 sfinfo.frames = ARRAY_LEN (int_data) ;
Chris@0 456 sfinfo.channels = 1 ;
Chris@0 457 sfinfo.format = SF_ENDIAN_BIG | SF_FORMAT_AU | SF_FORMAT_FLOAT ;
Chris@0 458
Chris@0 459 file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
Chris@0 460 test_write_float_or_die (file, 0, float_data, ARRAY_LEN (float_data), __LINE__) ;
Chris@0 461 sf_close (file) ;
Chris@0 462
Chris@0 463 file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
Chris@0 464
Chris@0 465 if (sfinfo.frames != ARRAY_LEN (float_data))
Chris@0 466 { printf ("\n\nLine %d: Incorrect number of frames in file (too short). (%ld should be %d)\n", __LINE__, SF_COUNT_TO_LONG (sfinfo.frames), DFT_DATA_LENGTH) ;
Chris@0 467 exit (1) ;
Chris@0 468 } ;
Chris@0 469
Chris@0 470 if (sfinfo.channels != 1)
Chris@0 471 { printf ("\n\nLine %d: Incorrect number of channels in file.\n", __LINE__) ;
Chris@0 472 exit (1) ;
Chris@0 473 } ;
Chris@0 474
Chris@0 475 sf_command (file, SFC_SET_SCALE_FLOAT_INT_READ, NULL, SF_TRUE) ;
Chris@0 476
Chris@0 477 test_read_int_or_die (file, 0, int_data, ARRAY_LEN (int_data), __LINE__) ;
Chris@0 478 sf_close (file) ;
Chris@0 479
Chris@0 480 max = 0 ;
Chris@0 481 for (k = 0 ; k < ARRAY_LEN (int_data) ; k++)
Chris@0 482 if ((unsigned) abs (int_data [k]) > max)
Chris@0 483 max = abs (int_data [k]) ;
Chris@0 484
Chris@0 485 if (1.0 * abs (max - 0x7FFFFFFF) / 0x7FFFFFFF > 0.01)
Chris@0 486 { printf ("\n\nLine %d: Bad maximum (%d should be %d).\n\n", __LINE__, max, 0x7FFFFFFF) ;
Chris@0 487 exit (1) ;
Chris@0 488 } ;
Chris@0 489
Chris@0 490 unlink (filename) ;
Chris@0 491 puts ("ok") ;
Chris@0 492 } /* float_int_big_test */
Chris@0 493
Chris@0 494 static void
Chris@0 495 double_short_little_test (const char * filename)
Chris@0 496 { SNDFILE *file ;
Chris@0 497 SF_INFO sfinfo ;
Chris@0 498 unsigned k, max ;
Chris@0 499
Chris@0 500 print_test_name ("double_short_little_test", filename) ;
Chris@0 501
Chris@0 502 gen_windowed_sine_double (double_data, ARRAY_LEN (double_data), 0.98) ;
Chris@0 503
Chris@0 504 sfinfo.samplerate = SAMPLE_RATE ;
Chris@0 505 sfinfo.frames = ARRAY_LEN (short_data) ;
Chris@0 506 sfinfo.channels = 1 ;
Chris@0 507 sfinfo.format = SF_ENDIAN_LITTLE | SF_FORMAT_AU | SF_FORMAT_DOUBLE ;
Chris@0 508
Chris@0 509 file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
Chris@0 510 test_write_double_or_die (file, 0, double_data, ARRAY_LEN (double_data), __LINE__) ;
Chris@0 511 sf_close (file) ;
Chris@0 512
Chris@0 513 file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
Chris@0 514
Chris@0 515 if (sfinfo.frames != ARRAY_LEN (double_data))
Chris@0 516 { printf ("\n\nLine %d: Incorrect number of frames in file (too short). (%ld should be %d)\n", __LINE__, SF_COUNT_TO_LONG (sfinfo.frames), DFT_DATA_LENGTH) ;
Chris@0 517 exit (1) ;
Chris@0 518 } ;
Chris@0 519
Chris@0 520 if (sfinfo.channels != 1)
Chris@0 521 { printf ("\n\nLine %d: Incorrect number of channels in file.\n", __LINE__) ;
Chris@0 522 exit (1) ;
Chris@0 523 } ;
Chris@0 524
Chris@0 525 sf_command (file, SFC_SET_SCALE_FLOAT_INT_READ, NULL, SF_TRUE) ;
Chris@0 526
Chris@0 527 test_read_short_or_die (file, 0, short_data, ARRAY_LEN (short_data), __LINE__) ;
Chris@0 528 sf_close (file) ;
Chris@0 529
Chris@0 530 max = 0 ;
Chris@0 531 for (k = 0 ; k < ARRAY_LEN (short_data) ; k++)
Chris@0 532 if ((unsigned) abs (short_data [k]) > max)
Chris@0 533 max = abs (short_data [k]) ;
Chris@0 534
Chris@0 535 if (1.0 * abs (max - 0x7FFF) / 0x7FFF > 0.01)
Chris@0 536 { printf ("\n\nLine %d: Bad maximum (%d should be %d).\n\n", __LINE__, max, 0x7FFF) ;
Chris@0 537 exit (1) ;
Chris@0 538 } ;
Chris@0 539
Chris@0 540 unlink (filename) ;
Chris@0 541 puts ("ok") ;
Chris@0 542 } /* double_short_little_test */
Chris@0 543
Chris@0 544 static void
Chris@0 545 double_short_big_test (const char * filename)
Chris@0 546 { SNDFILE *file ;
Chris@0 547 SF_INFO sfinfo ;
Chris@0 548 unsigned k, max ;
Chris@0 549
Chris@0 550 print_test_name ("double_short_big_test", filename) ;
Chris@0 551
Chris@0 552 gen_windowed_sine_double (double_data, ARRAY_LEN (double_data), 0.98) ;
Chris@0 553
Chris@0 554 sfinfo.samplerate = SAMPLE_RATE ;
Chris@0 555 sfinfo.frames = ARRAY_LEN (short_data) ;
Chris@0 556 sfinfo.channels = 1 ;
Chris@0 557 sfinfo.format = SF_ENDIAN_BIG | SF_FORMAT_AU | SF_FORMAT_DOUBLE ;
Chris@0 558
Chris@0 559 file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
Chris@0 560 test_write_double_or_die (file, 0, double_data, ARRAY_LEN (double_data), __LINE__) ;
Chris@0 561 sf_close (file) ;
Chris@0 562
Chris@0 563 file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
Chris@0 564
Chris@0 565 if (sfinfo.frames != ARRAY_LEN (double_data))
Chris@0 566 { printf ("\n\nLine %d: Incorrect number of frames in file (too short). (%ld should be %d)\n", __LINE__, SF_COUNT_TO_LONG (sfinfo.frames), DFT_DATA_LENGTH) ;
Chris@0 567 exit (1) ;
Chris@0 568 } ;
Chris@0 569
Chris@0 570 if (sfinfo.channels != 1)
Chris@0 571 { printf ("\n\nLine %d: Incorrect number of channels in file.\n", __LINE__) ;
Chris@0 572 exit (1) ;
Chris@0 573 } ;
Chris@0 574
Chris@0 575 sf_command (file, SFC_SET_SCALE_FLOAT_INT_READ, NULL, SF_TRUE) ;
Chris@0 576
Chris@0 577 test_read_short_or_die (file, 0, short_data, ARRAY_LEN (short_data), __LINE__) ;
Chris@0 578 sf_close (file) ;
Chris@0 579
Chris@0 580 max = 0 ;
Chris@0 581 for (k = 0 ; k < ARRAY_LEN (short_data) ; k++)
Chris@0 582 if ((unsigned) abs (short_data [k]) > max)
Chris@0 583 max = abs (short_data [k]) ;
Chris@0 584
Chris@0 585 if (1.0 * abs (max - 0x7FFF) / 0x7FFF > 0.01)
Chris@0 586 { printf ("\n\nLine %d: Bad maximum (%d should be %d).\n\n", __LINE__, max, 0x7FFF) ;
Chris@0 587 exit (1) ;
Chris@0 588 } ;
Chris@0 589
Chris@0 590 unlink (filename) ;
Chris@0 591 puts ("ok") ;
Chris@0 592 } /* double_short_big_test */
Chris@0 593
Chris@0 594 static void
Chris@0 595 double_int_little_test (const char * filename)
Chris@0 596 { SNDFILE *file ;
Chris@0 597 SF_INFO sfinfo ;
Chris@0 598 unsigned k, max ;
Chris@0 599
Chris@0 600 print_test_name ("double_int_little_test", filename) ;
Chris@0 601
Chris@0 602 gen_windowed_sine_double (double_data, ARRAY_LEN (double_data), 0.98) ;
Chris@0 603
Chris@0 604 sfinfo.samplerate = SAMPLE_RATE ;
Chris@0 605 sfinfo.frames = ARRAY_LEN (int_data) ;
Chris@0 606 sfinfo.channels = 1 ;
Chris@0 607 sfinfo.format = SF_ENDIAN_LITTLE | SF_FORMAT_AU | SF_FORMAT_DOUBLE ;
Chris@0 608
Chris@0 609 file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
Chris@0 610 test_write_double_or_die (file, 0, double_data, ARRAY_LEN (double_data), __LINE__) ;
Chris@0 611 sf_close (file) ;
Chris@0 612
Chris@0 613 file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
Chris@0 614
Chris@0 615 if (sfinfo.frames != ARRAY_LEN (double_data))
Chris@0 616 { printf ("\n\nLine %d: Incorrect number of frames in file (too short). (%ld should be %d)\n", __LINE__, SF_COUNT_TO_LONG (sfinfo.frames), DFT_DATA_LENGTH) ;
Chris@0 617 exit (1) ;
Chris@0 618 } ;
Chris@0 619
Chris@0 620 if (sfinfo.channels != 1)
Chris@0 621 { printf ("\n\nLine %d: Incorrect number of channels in file.\n", __LINE__) ;
Chris@0 622 exit (1) ;
Chris@0 623 } ;
Chris@0 624
Chris@0 625 sf_command (file, SFC_SET_SCALE_FLOAT_INT_READ, NULL, SF_TRUE) ;
Chris@0 626
Chris@0 627 test_read_int_or_die (file, 0, int_data, ARRAY_LEN (int_data), __LINE__) ;
Chris@0 628 sf_close (file) ;
Chris@0 629
Chris@0 630 max = 0 ;
Chris@0 631 for (k = 0 ; k < ARRAY_LEN (int_data) ; k++)
Chris@0 632 if ((unsigned) abs (int_data [k]) > max)
Chris@0 633 max = abs (int_data [k]) ;
Chris@0 634
Chris@0 635 if (1.0 * abs (max - 0x7FFFFFFF) / 0x7FFFFFFF > 0.01)
Chris@0 636 { printf ("\n\nLine %d: Bad maximum (%d should be %d).\n\n", __LINE__, max, 0x7FFFFFFF) ;
Chris@0 637 exit (1) ;
Chris@0 638 } ;
Chris@0 639
Chris@0 640 unlink (filename) ;
Chris@0 641 puts ("ok") ;
Chris@0 642 } /* double_int_little_test */
Chris@0 643
Chris@0 644 static void
Chris@0 645 double_int_big_test (const char * filename)
Chris@0 646 { SNDFILE *file ;
Chris@0 647 SF_INFO sfinfo ;
Chris@0 648 unsigned k, max ;
Chris@0 649
Chris@0 650 print_test_name ("double_int_big_test", filename) ;
Chris@0 651
Chris@0 652 gen_windowed_sine_double (double_data, ARRAY_LEN (double_data), 0.98) ;
Chris@0 653
Chris@0 654 sfinfo.samplerate = SAMPLE_RATE ;
Chris@0 655 sfinfo.frames = ARRAY_LEN (int_data) ;
Chris@0 656 sfinfo.channels = 1 ;
Chris@0 657 sfinfo.format = SF_ENDIAN_BIG | SF_FORMAT_AU | SF_FORMAT_DOUBLE ;
Chris@0 658
Chris@0 659 file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
Chris@0 660 test_write_double_or_die (file, 0, double_data, ARRAY_LEN (double_data), __LINE__) ;
Chris@0 661 sf_close (file) ;
Chris@0 662
Chris@0 663 file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
Chris@0 664
Chris@0 665 if (sfinfo.frames != ARRAY_LEN (double_data))
Chris@0 666 { printf ("\n\nLine %d: Incorrect number of frames in file (too short). (%ld should be %d)\n", __LINE__, SF_COUNT_TO_LONG (sfinfo.frames), DFT_DATA_LENGTH) ;
Chris@0 667 exit (1) ;
Chris@0 668 } ;
Chris@0 669
Chris@0 670 if (sfinfo.channels != 1)
Chris@0 671 { printf ("\n\nLine %d: Incorrect number of channels in file.\n", __LINE__) ;
Chris@0 672 exit (1) ;
Chris@0 673 } ;
Chris@0 674
Chris@0 675 sf_command (file, SFC_SET_SCALE_FLOAT_INT_READ, NULL, SF_TRUE) ;
Chris@0 676
Chris@0 677 test_read_int_or_die (file, 0, int_data, ARRAY_LEN (int_data), __LINE__) ;
Chris@0 678 sf_close (file) ;
Chris@0 679
Chris@0 680 max = 0 ;
Chris@0 681 for (k = 0 ; k < ARRAY_LEN (int_data) ; k++)
Chris@0 682 if ((unsigned) abs (int_data [k]) > max)
Chris@0 683 max = abs (int_data [k]) ;
Chris@0 684
Chris@0 685 if (1.0 * abs (max - 0x7FFFFFFF) / 0x7FFFFFFF > 0.01)
Chris@0 686 { printf ("\n\nLine %d: Bad maximum (%d should be %d).\n\n", __LINE__, max, 0x7FFFFFFF) ;
Chris@0 687 exit (1) ;
Chris@0 688 } ;
Chris@0 689
Chris@0 690 unlink (filename) ;
Chris@0 691 puts ("ok") ;
Chris@0 692 } /* double_int_big_test */
Chris@0 693
Chris@0 694