annotate src/libsndfile-1.0.27/tests/floating_point_test.tpl @ 84:08ae793730bd

Add null config files
author Chris Cannam
date Mon, 02 Mar 2020 14:03:47 +0000
parents 1df64224f5ac
children
rev   line source
Chris@40 1 [+ AutoGen5 template c +]
Chris@40 2 /*
Chris@40 3 ** Copyright (C) 1999-2016 Erik de Castro Lopo <erikd@mega-nerd.com>
Chris@40 4 **
Chris@40 5 ** This program is free software; you can redistribute it and/or modify
Chris@40 6 ** it under the terms of the GNU General Public License as published by
Chris@40 7 ** the Free Software Foundation; either version 2 of the License, or
Chris@40 8 ** (at your option) any later version.
Chris@40 9 **
Chris@40 10 ** This program is distributed in the hope that it will be useful,
Chris@40 11 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@40 12 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@40 13 ** GNU General Public License for more details.
Chris@40 14 **
Chris@40 15 ** You should have received a copy of the GNU General Public License
Chris@40 16 ** along with this program; if not, write to the Free Software
Chris@40 17 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Chris@40 18 */
Chris@40 19
Chris@40 20 #include "sfconfig.h"
Chris@40 21
Chris@40 22 #include <stdio.h>
Chris@40 23 #include <stdlib.h>
Chris@40 24 #include <string.h>
Chris@40 25 #include <math.h>
Chris@40 26 #include <inttypes.h>
Chris@40 27
Chris@40 28 #if HAVE_UNISTD_H
Chris@40 29 #include <unistd.h>
Chris@40 30 #endif
Chris@40 31
Chris@40 32 #include <sndfile.h>
Chris@40 33
Chris@40 34 #include "dft_cmp.h"
Chris@40 35 #include "utils.h"
Chris@40 36
Chris@40 37 #define SAMPLE_RATE 16000
Chris@40 38
Chris@40 39 static void float_scaled_test (const char *filename, int allow_exit, int replace_float, int filetype, double target_snr) ;
Chris@40 40 static void double_scaled_test (const char *filename, int allow_exit, int replace_float, int filetype, double target_snr) ;
Chris@40 41
Chris@40 42 [+ FOR float_type +][+ FOR int_type +][+ FOR endian_type
Chris@40 43 +]static void [+ (get "float_name") +]_[+ (get "int_name") +]_[+ (get "end_name") +]_test (const char * filename) ;
Chris@40 44 [+ ENDFOR endian_type +][+ ENDFOR int_type +][+ ENDFOR float_type
Chris@40 45 +]
Chris@40 46
Chris@40 47 static double double_data [DFT_DATA_LENGTH] ;
Chris@40 48 static double double_test [DFT_DATA_LENGTH] ;
Chris@40 49
Chris@40 50 static float float_data [DFT_DATA_LENGTH] ;
Chris@40 51 static float float_test [DFT_DATA_LENGTH] ;
Chris@40 52
Chris@40 53 static double double_data [DFT_DATA_LENGTH] ;
Chris@40 54 static short short_data [DFT_DATA_LENGTH] ;
Chris@40 55 static int int_data [DFT_DATA_LENGTH] ;
Chris@40 56
Chris@40 57 int
Chris@40 58 main (int argc, char *argv [])
Chris@40 59 { int allow_exit = 1 ;
Chris@40 60
Chris@40 61 if (argc == 2 && ! strstr (argv [1], "no-exit"))
Chris@40 62 allow_exit = 0 ;
Chris@40 63
Chris@40 64 #if (HAVE_LRINTF == 0)
Chris@40 65 puts ("*** Cannot run this test on this platform because it lacks lrintf().") ;
Chris@40 66 exit (0) ;
Chris@40 67 #endif
Chris@40 68
Chris@40 69 /* Float tests. */
Chris@40 70 float_scaled_test ("float.raw", allow_exit, SF_FALSE, SF_ENDIAN_LITTLE | SF_FORMAT_RAW | SF_FORMAT_FLOAT,
Chris@40 71 OS_IS_OPENBSD ? -98.0 : -163.0) ;
Chris@40 72
Chris@40 73 /* Test both signed and unsigned 8 bit files. */
Chris@40 74 float_scaled_test ("pcm_s8.raw", allow_exit, SF_FALSE, SF_FORMAT_RAW | SF_FORMAT_PCM_S8, -39.0) ;
Chris@40 75 float_scaled_test ("pcm_u8.raw", allow_exit, SF_FALSE, SF_FORMAT_RAW | SF_FORMAT_PCM_U8, -39.0) ;
Chris@40 76
Chris@40 77 float_scaled_test ("pcm_16.raw", allow_exit, SF_FALSE, SF_ENDIAN_BIG | SF_FORMAT_RAW | SF_FORMAT_PCM_16, -87.0) ;
Chris@40 78 float_scaled_test ("pcm_24.raw", allow_exit, SF_FALSE, SF_ENDIAN_LITTLE | SF_FORMAT_RAW | SF_FORMAT_PCM_24, -138.0) ;
Chris@40 79 float_scaled_test ("pcm_32.raw", allow_exit, SF_FALSE, SF_ENDIAN_BIG | SF_FORMAT_RAW | SF_FORMAT_PCM_32, -163.0) ;
Chris@40 80
Chris@40 81 float_scaled_test ("ulaw.raw", allow_exit, SF_FALSE, SF_FORMAT_RAW | SF_FORMAT_ULAW, -50.0) ;
Chris@40 82 float_scaled_test ("alaw.raw", allow_exit, SF_FALSE, SF_FORMAT_RAW | SF_FORMAT_ALAW, -49.0) ;
Chris@40 83
Chris@40 84 float_scaled_test ("ima_adpcm.wav", allow_exit, SF_FALSE, SF_FORMAT_WAV | SF_FORMAT_IMA_ADPCM, -47.0) ;
Chris@40 85 float_scaled_test ("ms_adpcm.wav" , allow_exit, SF_FALSE, SF_FORMAT_WAV | SF_FORMAT_MS_ADPCM, -40.0) ;
Chris@40 86 float_scaled_test ("gsm610.raw" , allow_exit, SF_FALSE, SF_FORMAT_RAW | SF_FORMAT_GSM610, -33.0) ;
Chris@40 87
Chris@40 88 float_scaled_test ("g721_32.au", allow_exit, SF_FALSE, SF_FORMAT_AU | SF_FORMAT_G721_32, -32.3) ;
Chris@40 89 float_scaled_test ("g723_24.au", allow_exit, SF_FALSE, SF_FORMAT_AU | SF_FORMAT_G723_24, -32.3) ;
Chris@40 90 float_scaled_test ("g723_40.au", allow_exit, SF_FALSE, SF_FORMAT_AU | SF_FORMAT_G723_40, -40.0) ;
Chris@40 91
Chris@40 92 /* PAF files do not use the same encoding method for 24 bit PCM data as other file
Chris@40 93 ** formats so we need to explicitly test it here.
Chris@40 94 */
Chris@40 95 float_scaled_test ("le_paf_24.paf", allow_exit, SF_FALSE, SF_ENDIAN_LITTLE | SF_FORMAT_PAF | SF_FORMAT_PCM_24, -149.0) ;
Chris@40 96 float_scaled_test ("be_paf_24.paf", allow_exit, SF_FALSE, SF_ENDIAN_BIG | SF_FORMAT_PAF | SF_FORMAT_PCM_24, -149.0) ;
Chris@40 97
Chris@40 98 float_scaled_test ("dwvw_12.raw", allow_exit, SF_FALSE, SF_FORMAT_RAW | SF_FORMAT_DWVW_12, -64.0) ;
Chris@40 99 float_scaled_test ("dwvw_16.raw", allow_exit, SF_FALSE, SF_FORMAT_RAW | SF_FORMAT_DWVW_16, -92.0) ;
Chris@40 100 float_scaled_test ("dwvw_24.raw", allow_exit, SF_FALSE, SF_FORMAT_RAW | SF_FORMAT_DWVW_24, -151.0) ;
Chris@40 101
Chris@40 102 float_scaled_test ("adpcm.vox", allow_exit, SF_FALSE, SF_FORMAT_RAW | SF_FORMAT_VOX_ADPCM, -40.0) ;
Chris@40 103
Chris@40 104 float_scaled_test ("dpcm_16.xi", allow_exit, SF_FALSE, SF_FORMAT_XI | SF_FORMAT_DPCM_16, -90.0) ;
Chris@40 105 float_scaled_test ("dpcm_8.xi" , allow_exit, SF_FALSE, SF_FORMAT_XI | SF_FORMAT_DPCM_8 , -41.0) ;
Chris@40 106
Chris@40 107 float_scaled_test ("pcm_s8.sds", allow_exit, SF_FALSE, SF_FORMAT_SDS | SF_FORMAT_PCM_S8, -89.0) ;
Chris@40 108 float_scaled_test ("pcm_16.sds", allow_exit, SF_FALSE, SF_FORMAT_SDS | SF_FORMAT_PCM_16, -132.0) ;
Chris@40 109 float_scaled_test ("pcm_24.sds", allow_exit, SF_FALSE, SF_FORMAT_SDS | SF_FORMAT_PCM_24, -170.0) ;
Chris@40 110
Chris@40 111 float_scaled_test ("alac_16.caf", allow_exit, SF_FALSE, SF_FORMAT_CAF | SF_FORMAT_ALAC_16, -90.0) ;
Chris@40 112 float_scaled_test ("alac_32.caf", allow_exit, SF_FALSE, SF_FORMAT_CAF | SF_FORMAT_ALAC_32, -76.0) ;
Chris@40 113 float_scaled_test ("alac_24.caf", allow_exit, SF_FALSE, SF_FORMAT_CAF | SF_FORMAT_ALAC_24, -153.0) ;
Chris@40 114 float_scaled_test ("alac_20.caf", allow_exit, SF_FALSE, SF_FORMAT_CAF | SF_FORMAT_ALAC_20, -125.0) ;
Chris@40 115
Chris@40 116 #if HAVE_EXTERNAL_XIPH_LIBS
Chris@40 117 float_scaled_test ("flac_8.flac", allow_exit, SF_FALSE, SF_FORMAT_FLAC | SF_FORMAT_PCM_S8, -39.0) ;
Chris@40 118 float_scaled_test ("flac_16.flac", allow_exit, SF_FALSE, SF_FORMAT_FLAC | SF_FORMAT_PCM_16, -87.0) ;
Chris@40 119 float_scaled_test ("flac_24.flac", allow_exit, SF_FALSE, SF_FORMAT_FLAC | SF_FORMAT_PCM_24, -138.0) ;
Chris@40 120
Chris@40 121 float_scaled_test ("vorbis.oga", allow_exit, SF_FALSE, SF_FORMAT_OGG | SF_FORMAT_VORBIS, -31.0) ;
Chris@40 122 #endif
Chris@40 123
Chris@40 124 float_scaled_test ("replace_float.raw", allow_exit, SF_TRUE, SF_ENDIAN_LITTLE | SF_FORMAT_RAW | SF_FORMAT_FLOAT, -163.0) ;
Chris@40 125
Chris@40 126 /*==============================================================================
Chris@40 127 ** Double tests.
Chris@40 128 */
Chris@40 129
Chris@40 130 double_scaled_test ("double.raw", allow_exit, SF_FALSE, SF_FORMAT_RAW | SF_FORMAT_DOUBLE, -201.0) ;
Chris@40 131
Chris@40 132 /* Test both signed (AIFF) and unsigned (WAV) 8 bit files. */
Chris@40 133 double_scaled_test ("pcm_s8.raw", allow_exit, SF_FALSE, SF_FORMAT_RAW | SF_FORMAT_PCM_S8, -39.0) ;
Chris@40 134 double_scaled_test ("pcm_u8.raw", allow_exit, SF_FALSE, SF_FORMAT_RAW | SF_FORMAT_PCM_U8, -39.0) ;
Chris@40 135
Chris@40 136 double_scaled_test ("pcm_16.raw", allow_exit, SF_FALSE, SF_FORMAT_RAW | SF_FORMAT_PCM_16, -87.0) ;
Chris@40 137 double_scaled_test ("pcm_24.raw", allow_exit, SF_FALSE, SF_FORMAT_RAW | SF_FORMAT_PCM_24, -135.0) ;
Chris@40 138 double_scaled_test ("pcm_32.raw", allow_exit, SF_FALSE, SF_FORMAT_RAW | SF_FORMAT_PCM_32, -184.0) ;
Chris@40 139
Chris@40 140 double_scaled_test ("ulaw.raw", allow_exit, SF_FALSE, SF_FORMAT_RAW | SF_FORMAT_ULAW, -50.0) ;
Chris@40 141 double_scaled_test ("alaw.raw", allow_exit, SF_FALSE, SF_FORMAT_RAW | SF_FORMAT_ALAW, -49.0) ;
Chris@40 142
Chris@40 143 double_scaled_test ("ima_adpcm.wav", allow_exit, SF_FALSE, SF_FORMAT_WAV | SF_FORMAT_IMA_ADPCM, -47.0) ;
Chris@40 144 double_scaled_test ("ms_adpcm.wav" , allow_exit, SF_FALSE, SF_FORMAT_WAV | SF_FORMAT_MS_ADPCM, -40.0) ;
Chris@40 145 double_scaled_test ("gsm610.raw" , allow_exit, SF_FALSE, SF_FORMAT_RAW | SF_FORMAT_GSM610, -33.0) ;
Chris@40 146
Chris@40 147 double_scaled_test ("g721_32.au", allow_exit, SF_FALSE, SF_FORMAT_AU | SF_FORMAT_G721_32, -32.3) ;
Chris@40 148 double_scaled_test ("g723_24.au", allow_exit, SF_FALSE, SF_FORMAT_AU | SF_FORMAT_G723_24, -32.3) ;
Chris@40 149 double_scaled_test ("g723_40.au", allow_exit, SF_FALSE, SF_FORMAT_AU | SF_FORMAT_G723_40, -40.0) ;
Chris@40 150
Chris@40 151 /* 24 bit PCM PAF files tested here. */
Chris@40 152 double_scaled_test ("be_paf_24.paf", allow_exit, SF_FALSE, SF_ENDIAN_BIG | SF_FORMAT_PAF | SF_FORMAT_PCM_24, -151.0) ;
Chris@40 153 double_scaled_test ("le_paf_24.paf", allow_exit, SF_FALSE, SF_ENDIAN_LITTLE | SF_FORMAT_PAF | SF_FORMAT_PCM_24, -151.0) ;
Chris@40 154
Chris@40 155 double_scaled_test ("dwvw_12.raw", allow_exit, SF_FALSE, SF_FORMAT_RAW | SF_FORMAT_DWVW_12, -64.0) ;
Chris@40 156 double_scaled_test ("dwvw_16.raw", allow_exit, SF_FALSE, SF_FORMAT_RAW | SF_FORMAT_DWVW_16, -92.0) ;
Chris@40 157 double_scaled_test ("dwvw_24.raw", allow_exit, SF_FALSE, SF_FORMAT_RAW | SF_FORMAT_DWVW_24, -151.0) ;
Chris@40 158
Chris@40 159 double_scaled_test ("adpcm.vox" , allow_exit, SF_FALSE, SF_FORMAT_RAW | SF_FORMAT_VOX_ADPCM, -40.0) ;
Chris@40 160
Chris@40 161 double_scaled_test ("dpcm_16.xi", allow_exit, SF_FALSE, SF_FORMAT_XI | SF_FORMAT_DPCM_16, -90.0) ;
Chris@40 162 double_scaled_test ("dpcm_8.xi" , allow_exit, SF_FALSE, SF_FORMAT_XI | SF_FORMAT_DPCM_8 , -41.0) ;
Chris@40 163
Chris@40 164 double_scaled_test ("pcm_s8.sds", allow_exit, SF_FALSE, SF_FORMAT_SDS | SF_FORMAT_PCM_S8, -89.0) ;
Chris@40 165 double_scaled_test ("pcm_16.sds", allow_exit, SF_FALSE, SF_FORMAT_SDS | SF_FORMAT_PCM_16, -132.0) ;
Chris@40 166 double_scaled_test ("pcm_24.sds", allow_exit, SF_FALSE, SF_FORMAT_SDS | SF_FORMAT_PCM_24, -180.0) ;
Chris@40 167
Chris@40 168 double_scaled_test ("alac_16.caf", allow_exit, SF_FALSE, SF_FORMAT_CAF | SF_FORMAT_ALAC_16, -90.0) ;
Chris@40 169 double_scaled_test ("alac_20.caf", allow_exit, SF_FALSE, SF_FORMAT_CAF | SF_FORMAT_ALAC_20, -125.0) ;
Chris@40 170 double_scaled_test ("alac_24.caf", allow_exit, SF_FALSE, SF_FORMAT_CAF | SF_FORMAT_ALAC_24, -153.0) ;
Chris@40 171 double_scaled_test ("alac_32.caf", allow_exit, SF_FALSE, SF_FORMAT_CAF | SF_FORMAT_ALAC_32, -186.0) ;
Chris@40 172
Chris@40 173 #if HAVE_EXTERNAL_XIPH_LIBS
Chris@40 174 double_scaled_test ("flac_8.flac", allow_exit, SF_FALSE, SF_FORMAT_FLAC | SF_FORMAT_PCM_S8, -39.0) ;
Chris@40 175 double_scaled_test ("flac_16.flac", allow_exit, SF_FALSE, SF_FORMAT_FLAC | SF_FORMAT_PCM_16, -87.0) ;
Chris@40 176 double_scaled_test ("flac_24.flac", allow_exit, SF_FALSE, SF_FORMAT_FLAC | SF_FORMAT_PCM_24, -138.0) ;
Chris@40 177
Chris@40 178 double_scaled_test ("vorbis.oga", allow_exit, SF_FALSE, SF_FORMAT_OGG | SF_FORMAT_VORBIS, -29.0) ;
Chris@40 179 #endif
Chris@40 180
Chris@40 181 double_scaled_test ("replace_double.raw", allow_exit, SF_TRUE, SF_FORMAT_RAW | SF_FORMAT_DOUBLE, -201.0) ;
Chris@40 182
Chris@40 183 putchar ('\n') ;
Chris@40 184 /* Float int tests. */
Chris@40 185 [+ FOR float_type +][+ FOR int_type +][+ FOR endian_type
Chris@40 186 +] [+ (get "float_name") +]_[+ (get "int_name") +]_[+ (get "end_name") +]_test ("[+ (get "float_name") +]_[+ (get "int_name") +]_[+ (get "end_name") +].au") ;
Chris@40 187 [+ ENDFOR endian_type +][+ ENDFOR int_type +][+ ENDFOR float_type
Chris@40 188 +]
Chris@40 189
Chris@40 190 return 0 ;
Chris@40 191 } /* main */
Chris@40 192
Chris@40 193 /*============================================================================================
Chris@40 194 * Here are the test functions.
Chris@40 195 */
Chris@40 196
Chris@40 197 static void
Chris@40 198 float_scaled_test (const char *filename, int allow_exit, int replace_float, int filetype, double target_snr)
Chris@40 199 { SNDFILE *file ;
Chris@40 200 SF_INFO sfinfo ;
Chris@40 201 double snr ;
Chris@40 202 int byterate ;
Chris@40 203
Chris@40 204 print_test_name ("float_scaled_test", filename) ;
Chris@40 205
Chris@40 206 gen_windowed_sine_float (float_data, DFT_DATA_LENGTH, 0.9999) ;
Chris@40 207
Chris@40 208 sfinfo.samplerate = SAMPLE_RATE ;
Chris@40 209 sfinfo.frames = DFT_DATA_LENGTH ;
Chris@40 210 sfinfo.channels = 1 ;
Chris@40 211 sfinfo.format = filetype ;
Chris@40 212
Chris@40 213 file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
Chris@40 214 sf_command (file, SFC_TEST_IEEE_FLOAT_REPLACE, NULL, replace_float) ;
Chris@40 215
Chris@40 216 test_write_float_or_die (file, 0, float_data, DFT_DATA_LENGTH, __LINE__) ;
Chris@40 217
Chris@40 218 sf_close (file) ;
Chris@40 219
Chris@40 220 memset (float_test, 0, sizeof (float_test)) ;
Chris@40 221
Chris@40 222 file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
Chris@40 223 sf_command (file, SFC_TEST_IEEE_FLOAT_REPLACE, NULL, replace_float) ;
Chris@40 224
Chris@40 225 exit_if_true (sfinfo.format != filetype, "\n\nLine %d: Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__, filetype, sfinfo.format) ;
Chris@40 226 exit_if_true (sfinfo.frames < DFT_DATA_LENGTH, "\n\nLine %d: Incorrect number of frames in file (too short). (%" PRId64 " should be %d)\n", __LINE__, sfinfo.frames, DFT_DATA_LENGTH) ;
Chris@40 227 exit_if_true (sfinfo.channels != 1, "\n\nLine %d: Incorrect number of channels in file.\n", __LINE__) ;
Chris@40 228
Chris@40 229 check_log_buffer_or_die (file, __LINE__) ;
Chris@40 230
Chris@40 231 test_read_float_or_die (file, 0, float_test, DFT_DATA_LENGTH, __LINE__) ;
Chris@40 232
Chris@40 233 byterate = sf_current_byterate (file) ;
Chris@40 234 exit_if_true (byterate <= 0, "\n\nLine %d: byterate is zero.\n", __LINE__) ;
Chris@40 235
Chris@40 236 sf_close (file) ;
Chris@40 237
Chris@40 238 snr = dft_cmp_float (__LINE__, float_data, float_test, DFT_DATA_LENGTH, target_snr, allow_exit) ;
Chris@40 239
Chris@40 240 exit_if_true (snr > target_snr, "% 6.1fdB SNR\n\n Error : should be better than % 6.1fdB\n\n", snr, target_snr) ;
Chris@40 241
Chris@40 242 printf ("% 6.1fdB SNR ... ok\n", snr) ;
Chris@40 243
Chris@40 244 unlink (filename) ;
Chris@40 245
Chris@40 246 return ;
Chris@40 247 } /* float_scaled_test */
Chris@40 248
Chris@40 249 static void
Chris@40 250 double_scaled_test (const char *filename, int allow_exit, int replace_float, int filetype, double target_snr)
Chris@40 251 { SNDFILE *file ;
Chris@40 252 SF_INFO sfinfo ;
Chris@40 253 double snr ;
Chris@40 254 int byterate ;
Chris@40 255
Chris@40 256 print_test_name ("double_scaled_test", filename) ;
Chris@40 257
Chris@40 258 gen_windowed_sine_double (double_data, DFT_DATA_LENGTH, 0.9999) ;
Chris@40 259
Chris@40 260 sfinfo.samplerate = SAMPLE_RATE ;
Chris@40 261 sfinfo.frames = DFT_DATA_LENGTH ;
Chris@40 262 sfinfo.channels = 1 ;
Chris@40 263 sfinfo.format = filetype ;
Chris@40 264
Chris@40 265 file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
Chris@40 266 sf_command (file, SFC_TEST_IEEE_FLOAT_REPLACE, NULL, replace_float) ;
Chris@40 267
Chris@40 268 test_write_double_or_die (file, 0, double_data, DFT_DATA_LENGTH, __LINE__) ;
Chris@40 269
Chris@40 270 sf_close (file) ;
Chris@40 271
Chris@40 272 memset (double_test, 0, sizeof (double_test)) ;
Chris@40 273
Chris@40 274 file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
Chris@40 275 sf_command (file, SFC_TEST_IEEE_FLOAT_REPLACE, NULL, replace_float) ;
Chris@40 276
Chris@40 277 exit_if_true (sfinfo.format != filetype, "\n\nLine %d: Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__, filetype, sfinfo.format) ;
Chris@40 278 exit_if_true (sfinfo.frames < DFT_DATA_LENGTH, "\n\nLine %d: Incorrect number of frames in file (too short). (%" PRId64 " should be %d)\n", __LINE__, sfinfo.frames, DFT_DATA_LENGTH) ;
Chris@40 279 exit_if_true (sfinfo.channels != 1, "\n\nLine %d: Incorrect number of channels in file.\n", __LINE__) ;
Chris@40 280
Chris@40 281 check_log_buffer_or_die (file, __LINE__) ;
Chris@40 282
Chris@40 283 test_read_double_or_die (file, 0, double_test, DFT_DATA_LENGTH, __LINE__) ;
Chris@40 284
Chris@40 285 byterate = sf_current_byterate (file) ;
Chris@40 286 exit_if_true (byterate <= 0, "\n\nLine %d: byterate is zero.\n", __LINE__) ;
Chris@40 287
Chris@40 288 sf_close (file) ;
Chris@40 289
Chris@40 290 snr = dft_cmp_double (__LINE__, double_data, double_test, DFT_DATA_LENGTH, target_snr, allow_exit) ;
Chris@40 291
Chris@40 292 exit_if_true (snr > target_snr, "% 6.1fdB SNR\n\n Error : should be better than % 6.1fdB\n\n", snr, target_snr) ;
Chris@40 293
Chris@40 294 printf ("% 6.1fdB SNR ... ok\n", snr) ;
Chris@40 295
Chris@40 296 unlink (filename) ;
Chris@40 297
Chris@40 298 return ;
Chris@40 299 } /* double_scaled_test */
Chris@40 300
Chris@40 301 /*==============================================================================
Chris@40 302 */
Chris@40 303
Chris@40 304 [+ FOR float_type +][+ FOR int_type +][+ FOR endian_type
Chris@40 305 +]
Chris@40 306 static void
Chris@40 307 [+ (get "float_name") +]_[+ (get "int_name") +]_[+ (get "end_name") +]_test (const char * filename)
Chris@40 308 { SNDFILE *file ;
Chris@40 309 SF_INFO sfinfo ;
Chris@40 310 int max ;
Chris@40 311 unsigned k ;
Chris@40 312
Chris@40 313 print_test_name ("[+ (get "float_name") +]_[+ (get "int_name") +]_[+ (get "end_name") +]_test", filename) ;
Chris@40 314
Chris@40 315 gen_windowed_sine_[+ (get "float_name") +] ([+ (get "float_name") +]_data, ARRAY_LEN ([+ (get "float_name") +]_data), 0.9999) ;
Chris@40 316
Chris@40 317 sfinfo.samplerate = SAMPLE_RATE ;
Chris@40 318 sfinfo.frames = ARRAY_LEN ([+ (get "int_name") +]_data) ;
Chris@40 319 sfinfo.channels = 1 ;
Chris@40 320 sfinfo.format = [+ (get "end_type") +] | SF_FORMAT_AU | [+ (get "minor_type") +] ;
Chris@40 321
Chris@40 322 file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
Chris@40 323 test_write_[+ (get "float_name") +]_or_die (file, 0, [+ (get "float_name") +]_data, ARRAY_LEN ([+ (get "float_name") +]_data), __LINE__) ;
Chris@40 324 sf_close (file) ;
Chris@40 325
Chris@40 326 file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
Chris@40 327
Chris@40 328 if (sfinfo.frames != ARRAY_LEN ([+ (get "float_name") +]_data))
Chris@40 329 { printf ("\n\nLine %d: Incorrect number of frames in file (too short). (%" PRId64 " should be %d)\n", __LINE__, sfinfo.frames, DFT_DATA_LENGTH) ;
Chris@40 330 exit (1) ;
Chris@40 331 } ;
Chris@40 332
Chris@40 333 if (sfinfo.channels != 1)
Chris@40 334 { printf ("\n\nLine %d: Incorrect number of channels in file.\n", __LINE__) ;
Chris@40 335 exit (1) ;
Chris@40 336 } ;
Chris@40 337
Chris@40 338 sf_command (file, SFC_SET_SCALE_FLOAT_INT_READ, NULL, SF_TRUE) ;
Chris@40 339
Chris@40 340 test_read_[+ (get "int_name") +]_or_die (file, 0, [+ (get "int_name") +]_data, ARRAY_LEN ([+ (get "int_name") +]_data), __LINE__) ;
Chris@40 341 sf_close (file) ;
Chris@40 342
Chris@40 343 max = 0 ;
Chris@40 344 for (k = 0 ; k < ARRAY_LEN ([+ (get "int_name") +]_data) ; k++)
Chris@40 345 if (abs ([+ (get "int_name") +]_data [k]) > max)
Chris@40 346 max = abs ([+ (get "int_name") +]_data [k]) ;
Chris@40 347
Chris@40 348 if (1.0 * abs (max - [+ (get "int_max") +]) / [+ (get "int_max") +] > 0.01)
Chris@40 349 { printf ("\n\nLine %d: Bad maximum (%d should be %d).\n\n", __LINE__, max, [+ (get "int_max") +]) ;
Chris@40 350 exit (1) ;
Chris@40 351 } ;
Chris@40 352
Chris@40 353 unlink (filename) ;
Chris@40 354 puts ("ok") ;
Chris@40 355 } /* [+ (get "float_name") +]_[+ (get "int_name") +]_[+ (get "end_name") +]_test */
Chris@40 356 [+ ENDFOR endian_type +][+ ENDFOR int_type +][+ ENDFOR float_type +]
Chris@40 357