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