Alexandre Lision | 7c6f4a6 | 2013-09-05 13:27:01 -0400 | [diff] [blame] | 1 | [+ AutoGen5 template c +] |
| 2 | /* |
| 3 | ** Copyright (C) 1999-2011 Erik de Castro Lopo <erikd@mega-nerd.com> |
| 4 | ** |
| 5 | ** This program is free software; you can redistribute it and/or modify |
| 6 | ** it under the terms of the GNU General Public License as published by |
| 7 | ** the Free Software Foundation; either version 2 of the License, or |
| 8 | ** (at your option) any later version. |
| 9 | ** |
| 10 | ** This program is distributed in the hope that it will be useful, |
| 11 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | ** GNU General Public License for more details. |
| 14 | ** |
| 15 | ** You should have received a copy of the GNU General Public License |
| 16 | ** along with this program; if not, write to the Free Software |
| 17 | ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 18 | */ |
| 19 | |
| 20 | #include "sfconfig.h" |
| 21 | |
| 22 | #include <stdio.h> |
| 23 | #include <stdlib.h> |
| 24 | #include <string.h> |
| 25 | #include <math.h> |
| 26 | |
| 27 | #if HAVE_UNISTD_H |
| 28 | #include <unistd.h> |
| 29 | #endif |
| 30 | |
| 31 | #include <sndfile.h> |
| 32 | |
| 33 | #include "utils.h" |
| 34 | |
| 35 | #define BUFFER_SIZE (1<<12) |
| 36 | |
| 37 | static void lrintf_test (void) ; |
| 38 | |
| 39 | [+ FOR data_type |
| 40 | +]static void pcm_test_[+ (get "name") +] (const char *filename, int filetype, uint64_t hash) ; |
| 41 | [+ ENDFOR data_type |
| 42 | +] |
| 43 | static void pcm_test_float (const char *filename, int filetype, uint64_t hash, int replace_float) ; |
| 44 | static void pcm_test_double (const char *filename, int filetype, uint64_t hash, int replace_float) ; |
| 45 | |
| 46 | typedef union |
| 47 | { double d [BUFFER_SIZE + 1] ; |
| 48 | float f [BUFFER_SIZE + 1] ; |
| 49 | int i [BUFFER_SIZE + 1] ; |
| 50 | short s [BUFFER_SIZE + 1] ; |
| 51 | } BUFFER ; |
| 52 | |
| 53 | /* Data written to the file. */ |
| 54 | static BUFFER data_out ; |
| 55 | |
| 56 | /* Data read back from the file. */ |
| 57 | static BUFFER data_in ; |
| 58 | |
| 59 | int |
| 60 | main (void) |
| 61 | { |
| 62 | lrintf_test () ; |
| 63 | |
| 64 | pcm_test_bits_8 ("pcm-s8.raw", SF_FORMAT_RAW | SF_FORMAT_PCM_S8, 0x1cda335091249dbfLL) ; |
| 65 | pcm_test_bits_8 ("pcm-u8.raw", SF_FORMAT_RAW | SF_FORMAT_PCM_U8, 0x7f748c433d695f3fLL) ; |
| 66 | |
| 67 | pcm_test_bits_16 ("le-pcm16.raw", SF_ENDIAN_LITTLE | SF_FORMAT_RAW | SF_FORMAT_PCM_16, 0x3a2b956c881ebf08LL) ; |
| 68 | pcm_test_bits_16 ("be-pcm16.raw", SF_ENDIAN_BIG | SF_FORMAT_RAW | SF_FORMAT_PCM_16, 0xd9e2f840c55750f8LL) ; |
| 69 | |
| 70 | pcm_test_bits_24 ("le-pcm24.raw", SF_ENDIAN_LITTLE | SF_FORMAT_RAW | SF_FORMAT_PCM_24, 0x933b6a759ab496f8LL) ; |
| 71 | pcm_test_bits_24 ("be-pcm24.raw", SF_ENDIAN_BIG | SF_FORMAT_RAW | SF_FORMAT_PCM_24, 0xbb1f3eaf9c30b6f8LL) ; |
| 72 | |
| 73 | pcm_test_bits_32 ("le-pcm32.raw", SF_ENDIAN_LITTLE | SF_FORMAT_RAW | SF_FORMAT_PCM_32, 0xa77aece1c1c17f08LL) ; |
| 74 | pcm_test_bits_32 ("be-pcm32.raw", SF_ENDIAN_BIG | SF_FORMAT_RAW | SF_FORMAT_PCM_32, 0x3099ddf142d0b0f8LL) ; |
| 75 | |
| 76 | /* Lite remove start */ |
| 77 | pcm_test_float ("le-float.raw", SF_ENDIAN_LITTLE | SF_FORMAT_RAW | SF_FORMAT_FLOAT, 0x3c2ad04f7554267aLL, SF_FALSE) ; |
| 78 | pcm_test_float ("be-float.raw", SF_ENDIAN_BIG | SF_FORMAT_RAW | SF_FORMAT_FLOAT, 0x074de3e248fa9186LL, SF_FALSE) ; |
| 79 | |
| 80 | pcm_test_double ("le-double.raw", SF_ENDIAN_LITTLE | SF_FORMAT_RAW | SF_FORMAT_DOUBLE, 0xc682726f958f669cLL, SF_FALSE) ; |
| 81 | pcm_test_double ("be-double.raw", SF_ENDIAN_BIG | SF_FORMAT_RAW | SF_FORMAT_DOUBLE, 0xd9a3583f8ee51164LL, SF_FALSE) ; |
| 82 | |
| 83 | pcm_test_float ("le-float.raw", SF_ENDIAN_LITTLE | SF_FORMAT_RAW | SF_FORMAT_FLOAT, 0x3c2ad04f7554267aLL, SF_TRUE) ; |
| 84 | pcm_test_float ("be-float.raw", SF_ENDIAN_BIG | SF_FORMAT_RAW | SF_FORMAT_FLOAT, 0x074de3e248fa9186LL, SF_TRUE) ; |
| 85 | |
| 86 | pcm_test_double ("le-double.raw", SF_ENDIAN_LITTLE | SF_FORMAT_RAW | SF_FORMAT_DOUBLE, 0xc682726f958f669cLL, SF_TRUE) ; |
| 87 | pcm_test_double ("be-double.raw", SF_ENDIAN_BIG | SF_FORMAT_RAW | SF_FORMAT_DOUBLE, 0xd9a3583f8ee51164LL, SF_TRUE) ; |
| 88 | /* Lite remove end */ |
| 89 | |
| 90 | return 0 ; |
| 91 | } /* main */ |
| 92 | |
| 93 | /*============================================================================================ |
| 94 | ** Here are the test functions. |
| 95 | */ |
| 96 | |
| 97 | static void |
| 98 | lrintf_test (void) |
| 99 | { int k, items ; |
| 100 | float *float_data ; |
| 101 | int *int_data ; |
| 102 | |
| 103 | print_test_name ("lrintf_test", "") ; |
| 104 | |
| 105 | items = 1024 ; |
| 106 | |
| 107 | float_data = data_out.f ; |
| 108 | int_data = data_in.i ; |
| 109 | |
| 110 | for (k = 0 ; k < items ; k++) |
| 111 | float_data [k] = (k * ((k % 2) ? 333333.0 : -333333.0)) ; |
| 112 | |
| 113 | for (k = 0 ; k < items ; k++) |
| 114 | int_data [k] = lrintf (float_data [k]) ; |
| 115 | |
| 116 | for (k = 0 ; k < items ; k++) |
| 117 | if (fabs (int_data [k] - float_data [k]) > 1.0) |
| 118 | { printf ("\n\nLine %d: float : Incorrect sample (#%d : %f => %d).\n", __LINE__, k, float_data [k], int_data [k]) ; |
| 119 | exit (1) ; |
| 120 | } ; |
| 121 | |
| 122 | printf ("ok\n") ; |
| 123 | } /* lrintf_test */ |
| 124 | |
| 125 | [+ FOR data_type |
| 126 | +]static void |
| 127 | pcm_test_[+ (get "name") +] (const char *filename, int filetype, uint64_t hash) |
| 128 | { SNDFILE *file ; |
| 129 | SF_INFO sfinfo ; |
| 130 | int k, items, zero_count ; |
| 131 | short *short_out, *short_in ; |
| 132 | int *int_out, *int_in ; |
| 133 | /* Lite remove start */ |
| 134 | float *float_out, *float_in ; |
| 135 | double *double_out, *double_in ; |
| 136 | /* Lite remove end */ |
| 137 | |
| 138 | print_test_name ("pcm_test_[+ (get "name") +]", filename) ; |
| 139 | |
| 140 | items = [+ (get "item_count") +] ; |
| 141 | |
| 142 | short_out = data_out.s ; |
| 143 | short_in = data_in.s ; |
| 144 | |
| 145 | zero_count = 0 ; |
| 146 | for (k = 0 ; k < items ; k++) |
| 147 | { short_out [k] = [+ (get "short_func") +] ; |
| 148 | zero_count = short_out [k] ? zero_count : zero_count + 1 ; |
| 149 | } ; |
| 150 | |
| 151 | if (zero_count > items / 4) |
| 152 | { printf ("\n\nLine %d: too many zeros.\n", __LINE__) ; |
| 153 | exit (1) ; |
| 154 | } ; |
| 155 | |
| 156 | sfinfo.samplerate = 44100 ; |
| 157 | sfinfo.frames = 123456789 ; /* Wrong length. Library should correct this on sf_close. */ |
| 158 | sfinfo.channels = 1 ; |
| 159 | sfinfo.format = filetype ; |
| 160 | |
| 161 | file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ; |
| 162 | |
| 163 | test_write_short_or_die (file, 0, short_out, items, __LINE__) ; |
| 164 | |
| 165 | sf_close (file) ; |
| 166 | |
| 167 | memset (short_in, 0, items * sizeof (short)) ; |
| 168 | |
| 169 | file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ; |
| 170 | |
| 171 | if (sfinfo.format != filetype) |
| 172 | { printf ("\n\nLine %d: Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__, filetype, sfinfo.format) ; |
| 173 | exit (1) ; |
| 174 | } ; |
| 175 | |
| 176 | if (sfinfo.frames != items) |
| 177 | { printf ("\n\nLine %d: Incorrect number of frames in file. (%d => %ld)\n", __LINE__, items, SF_COUNT_TO_LONG (sfinfo.frames)) ; |
| 178 | exit (1) ; |
| 179 | } ; |
| 180 | |
| 181 | if (sfinfo.channels != 1) |
| 182 | { printf ("\n\nLine %d: Incorrect number of channels in file.\n", __LINE__) ; |
| 183 | exit (1) ; |
| 184 | } ; |
| 185 | |
| 186 | check_log_buffer_or_die (file, __LINE__) ; |
| 187 | |
| 188 | test_read_short_or_die (file, 0, short_in, items, __LINE__) ; |
| 189 | |
| 190 | for (k = 0 ; k < items ; k++) |
| 191 | if (short_out [k] != short_in [k]) |
| 192 | { printf ("\n\nLine %d: Incorrect sample (#%d : 0x%x => 0x%x).\n", __LINE__, k, short_out [k], short_in [k]) ; |
| 193 | exit (1) ; |
| 194 | } ; |
| 195 | |
| 196 | sf_close (file) ; |
| 197 | |
| 198 | /* Finally, check the file hash. */ |
| 199 | check_file_hash_or_die (filename, hash, __LINE__) ; |
| 200 | |
| 201 | /*-------------------------------------------------------------------------- |
| 202 | ** Test sf_read/write_int () |
| 203 | */ |
| 204 | zero_count = 0 ; |
| 205 | |
| 206 | int_out = data_out.i ; |
| 207 | int_in = data_in.i ; |
| 208 | for (k = 0 ; k < items ; k++) |
| 209 | { int_out [k] = [+ (get "int_func") +] ; |
| 210 | zero_count = int_out [k] ? zero_count : zero_count + 1 ; |
| 211 | } ; |
| 212 | |
| 213 | if (zero_count > items / 4) |
| 214 | { printf ("\n\nLine %d: too many zeros.\n", __LINE__) ; |
| 215 | exit (1) ; |
| 216 | } ; |
| 217 | |
| 218 | sfinfo.samplerate = 44100 ; |
| 219 | sfinfo.frames = 123456789 ; /* Wrong length. Library should correct this on sf_close. */ |
| 220 | sfinfo.channels = 1 ; |
| 221 | sfinfo.format = filetype ; |
| 222 | |
| 223 | file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ; |
| 224 | |
| 225 | test_write_int_or_die (file, 0, int_out, items, __LINE__) ; |
| 226 | |
| 227 | sf_close (file) ; |
| 228 | |
| 229 | memset (int_in, 0, items * sizeof (int)) ; |
| 230 | |
| 231 | file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ; |
| 232 | |
| 233 | if (sfinfo.format != filetype) |
| 234 | { printf ("\n\nLine %d: Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__, filetype, sfinfo.format) ; |
| 235 | exit (1) ; |
| 236 | } ; |
| 237 | |
| 238 | if (sfinfo.frames != items) |
| 239 | { printf ("\n\nLine %d: Incorrect number of frames in file. (%d => %ld)\n", __LINE__, items, SF_COUNT_TO_LONG (sfinfo.frames)) ; |
| 240 | exit (1) ; |
| 241 | } ; |
| 242 | |
| 243 | if (sfinfo.channels != 1) |
| 244 | { printf ("\n\nLine %d: Incorrect number of channels in file.\n", __LINE__) ; |
| 245 | exit (1) ; |
| 246 | } ; |
| 247 | |
| 248 | check_log_buffer_or_die (file, __LINE__) ; |
| 249 | |
| 250 | test_read_int_or_die (file, 0, int_in, items, __LINE__) ; |
| 251 | |
| 252 | for (k = 0 ; k < items ; k++) |
| 253 | if (int_out [k] != int_in [k]) |
| 254 | { printf ("\n\nLine %d: int : Incorrect sample (#%d : 0x%x => 0x%x).\n", __LINE__, k, int_out [k], int_in [k]) ; |
| 255 | exit (1) ; |
| 256 | } ; |
| 257 | |
| 258 | sf_close (file) ; |
| 259 | |
| 260 | /* Lite remove start */ |
| 261 | /*-------------------------------------------------------------------------- |
| 262 | ** Test sf_read/write_float () |
| 263 | */ |
| 264 | zero_count = 0 ; |
| 265 | |
| 266 | float_out = data_out.f ; |
| 267 | float_in = data_in.f ; |
| 268 | for (k = 0 ; k < items ; k++) |
| 269 | { float_out [k] = [+ (get "float_func") +] ; |
| 270 | zero_count = (fabs (float_out [k]) > 1e-10) ? zero_count : zero_count + 1 ; |
| 271 | } ; |
| 272 | |
| 273 | if (zero_count > items / 4) |
| 274 | { printf ("\n\nLine %d: too many zeros (%d/%d).\n", __LINE__, zero_count, items) ; |
| 275 | exit (1) ; |
| 276 | } ; |
| 277 | |
| 278 | sfinfo.samplerate = 44100 ; |
| 279 | sfinfo.frames = 123456789 ; /* Wrong length. Library should correct this on sf_close. */ |
| 280 | sfinfo.channels = 1 ; |
| 281 | sfinfo.format = filetype ; |
| 282 | |
| 283 | file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ; |
| 284 | |
| 285 | sf_command (file, SFC_SET_NORM_FLOAT, NULL, SF_FALSE) ; |
| 286 | |
| 287 | test_write_float_or_die (file, 0, float_out, items, __LINE__) ; |
| 288 | |
| 289 | sf_close (file) ; |
| 290 | |
| 291 | memset (float_in, 0, items * sizeof (float)) ; |
| 292 | |
| 293 | file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ; |
| 294 | |
| 295 | if (sfinfo.format != filetype) |
| 296 | { printf ("\n\nLine %d: Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__, filetype, sfinfo.format) ; |
| 297 | exit (1) ; |
| 298 | } ; |
| 299 | |
| 300 | if (sfinfo.frames != items) |
| 301 | { printf ("\n\nLine %d: Incorrect number of frames in file. (%d => %ld)\n", __LINE__, items, SF_COUNT_TO_LONG (sfinfo.frames)) ; |
| 302 | exit (1) ; |
| 303 | } ; |
| 304 | |
| 305 | if (sfinfo.channels != 1) |
| 306 | { printf ("\n\nLine %d: Incorrect number of channels in file.\n", __LINE__) ; |
| 307 | exit (1) ; |
| 308 | } ; |
| 309 | |
| 310 | check_log_buffer_or_die (file, __LINE__) ; |
| 311 | |
| 312 | sf_command (file, SFC_SET_NORM_FLOAT, NULL, SF_FALSE) ; |
| 313 | |
| 314 | test_read_float_or_die (file, 0, float_in, items, __LINE__) ; |
| 315 | |
| 316 | for (k = 0 ; k < items ; k++) |
| 317 | if (fabs (float_out [k] - float_in [k]) > 1e-10) |
| 318 | { printf ("\n\nLine %d: float : Incorrect sample (#%d : %f => %f).\n", __LINE__, k, (double) float_out [k], (double) float_in [k]) ; |
| 319 | exit (1) ; |
| 320 | } ; |
| 321 | |
| 322 | sf_close (file) ; |
| 323 | |
| 324 | /*-------------------------------------------------------------------------- |
| 325 | ** Test sf_read/write_double () |
| 326 | */ |
| 327 | zero_count = 0 ; |
| 328 | |
| 329 | double_out = data_out.d ; |
| 330 | double_in = data_in.d ; |
| 331 | for (k = 0 ; k < items ; k++) |
| 332 | { double_out [k] = [+ (get "float_func") +] ; |
| 333 | zero_count = (fabs (double_out [k]) > 1e-10) ? zero_count : zero_count + 1 ; |
| 334 | } ; |
| 335 | |
| 336 | if (zero_count > items / 4) |
| 337 | { printf ("\n\nLine %d: too many zeros (%d/%d).\n", __LINE__, zero_count, items) ; |
| 338 | exit (1) ; |
| 339 | } ; |
| 340 | |
| 341 | sfinfo.samplerate = 44100 ; |
| 342 | sfinfo.frames = 123456789 ; /* Wrong length. Library should correct this on sf_close. */ |
| 343 | sfinfo.channels = 1 ; |
| 344 | sfinfo.format = filetype ; |
| 345 | |
| 346 | file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ; |
| 347 | |
| 348 | sf_command (file, SFC_SET_NORM_DOUBLE, NULL, SF_FALSE) ; |
| 349 | |
| 350 | test_write_double_or_die (file, 0, double_out, items, __LINE__) ; |
| 351 | |
| 352 | sf_close (file) ; |
| 353 | |
| 354 | memset (double_in, 0, items * sizeof (double)) ; |
| 355 | |
| 356 | file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ; |
| 357 | |
| 358 | if (sfinfo.format != filetype) |
| 359 | { printf ("\n\nLine %d: Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__, filetype, sfinfo.format) ; |
| 360 | exit (1) ; |
| 361 | } ; |
| 362 | |
| 363 | if (sfinfo.frames != items) |
| 364 | { printf ("\n\nLine %d: Incorrect number of frames in file. (%d => %ld)\n", __LINE__, items, SF_COUNT_TO_LONG (sfinfo.frames)) ; |
| 365 | exit (1) ; |
| 366 | } ; |
| 367 | |
| 368 | if (sfinfo.channels != 1) |
| 369 | { printf ("\n\nLine %d: Incorrect number of channels in file.\n", __LINE__) ; |
| 370 | exit (1) ; |
| 371 | } ; |
| 372 | |
| 373 | check_log_buffer_or_die (file, __LINE__) ; |
| 374 | |
| 375 | sf_command (file, SFC_SET_NORM_DOUBLE, NULL, SF_FALSE) ; |
| 376 | |
| 377 | test_read_double_or_die (file, 0, double_in, items, __LINE__) ; |
| 378 | |
| 379 | for (k = 0 ; k < items ; k++) |
| 380 | if (fabs (double_out [k] - double_in [k]) > 1e-10) |
| 381 | { printf ("\n\nLine %d: double : Incorrect sample (#%d : %f => %f).\n", __LINE__, k, double_out [k], double_in [k]) ; |
| 382 | exit (1) ; |
| 383 | } ; |
| 384 | |
| 385 | sf_close (file) ; |
| 386 | /* Lite remove end */ |
| 387 | unlink (filename) ; |
| 388 | |
| 389 | puts ("ok") ; |
| 390 | } /* pcm_test_[+ (get "name") +] */ |
| 391 | |
| 392 | [+ ENDFOR data_type |
| 393 | +] |
| 394 | |
| 395 | /*============================================================================== |
| 396 | */ |
| 397 | |
| 398 | static void |
| 399 | pcm_test_float (const char *filename, int filetype, uint64_t hash, int replace_float) |
| 400 | { SNDFILE *file ; |
| 401 | SF_INFO sfinfo ; |
| 402 | int k, items, frames ; |
| 403 | int sign ; |
| 404 | double *data, error ; |
| 405 | |
| 406 | print_test_name (replace_float ? "pcm_test_float (replace)" : "pcm_test_float", filename) ; |
| 407 | |
| 408 | items = BUFFER_SIZE ; |
| 409 | |
| 410 | data = data_out.d ; |
| 411 | for (sign = 1, k = 0 ; k < items ; k++) |
| 412 | { data [k] = ((double) (k * sign)) / 100.0 ; |
| 413 | sign = (sign > 0) ? -1 : 1 ; |
| 414 | } ; |
| 415 | |
| 416 | sfinfo.samplerate = 44100 ; |
| 417 | sfinfo.frames = items ; |
| 418 | sfinfo.channels = 1 ; |
| 419 | sfinfo.format = filetype ; |
| 420 | |
| 421 | file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ; |
| 422 | sf_command (file, SFC_TEST_IEEE_FLOAT_REPLACE, NULL, replace_float) ; |
| 423 | if (replace_float && string_in_log_buffer (file, "Using IEEE replacement") == 0) |
| 424 | { printf ("\n\nLine %d : Float replacement code not working.\n\n", __LINE__) ; |
| 425 | dump_log_buffer (file) ; |
| 426 | exit (1) ; |
| 427 | } ; |
| 428 | |
| 429 | test_write_double_or_die (file, 0, data, items, __LINE__) ; |
| 430 | |
| 431 | sf_close (file) ; |
| 432 | |
| 433 | check_file_hash_or_die (filename, hash, __LINE__) ; |
| 434 | |
| 435 | memset (data, 0, items * sizeof (double)) ; |
| 436 | |
| 437 | if ((filetype & SF_FORMAT_TYPEMASK) != SF_FORMAT_RAW) |
| 438 | memset (&sfinfo, 0, sizeof (sfinfo)) ; |
| 439 | |
| 440 | file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ; |
| 441 | sf_command (file, SFC_TEST_IEEE_FLOAT_REPLACE, NULL, replace_float) ; |
| 442 | if (replace_float && string_in_log_buffer (file, "Using IEEE replacement") == 0) |
| 443 | { printf ("\n\nLine %d : Float replacement code not working.\n\n", __LINE__) ; |
| 444 | dump_log_buffer (file) ; |
| 445 | exit (1) ; |
| 446 | } ; |
| 447 | |
| 448 | if (sfinfo.format != filetype) |
| 449 | { printf ("\n\nError (%s:%d) Mono : Returned format incorrect (0x%08X => 0x%08X).\n", __FILE__, __LINE__, filetype, sfinfo.format) ; |
| 450 | exit (1) ; |
| 451 | } ; |
| 452 | |
| 453 | if (sfinfo.frames != items) |
| 454 | { printf ("\n\nError (%s:%d) Mono : Incorrect number of frames in file. (%d => %ld)\n", __FILE__, __LINE__, items, SF_COUNT_TO_LONG (sfinfo.frames)) ; |
| 455 | exit (1) ; |
| 456 | } ; |
| 457 | |
| 458 | if (sfinfo.channels != 1) |
| 459 | { printf ("\n\nError (%s:%d) Mono : Incorrect number of channels in file.\n", __FILE__, __LINE__) ; |
| 460 | exit (1) ; |
| 461 | } ; |
| 462 | |
| 463 | check_log_buffer_or_die (file, __LINE__) ; |
| 464 | |
| 465 | test_read_double_or_die (file, 0, data, items, __LINE__) ; |
| 466 | |
| 467 | for (sign = -1, k = 0 ; k < items ; k++) |
| 468 | { error = fabs (data [k] - ((double) k) / 100.0 * (sign *= -1)) ; |
| 469 | if (fabs (data [k]) > 1e-100 && fabs (error / data [k]) > 1e-5) |
| 470 | { printf ("\n\nError (%s:%d) Mono : Incorrect sample (#%d : %f => %f).\n", __FILE__, __LINE__, k, ((double) k) / 100.0, data [k]) ; |
| 471 | exit (1) ; |
| 472 | } ; |
| 473 | } ; |
| 474 | |
| 475 | /* Seek to start of file. */ |
| 476 | test_seek_or_die (file, 0, SEEK_SET, 0, sfinfo.channels, __LINE__) ; |
| 477 | |
| 478 | test_read_double_or_die (file, 0, data, 4, __LINE__) ; |
| 479 | for (k = 0 ; k < 4 ; k++) |
| 480 | { error = fabs (data [k] - ((double) k) / 100.0 * (sign *= -1)) ; |
| 481 | if (fabs (data [k]) > 1e-100 && fabs (error / data [k]) > 1e-5) |
| 482 | { printf ("\n\nError (%s:%d) Mono : Incorrect sample (#%d : %f => %f).\n", __FILE__, __LINE__, k, ((double) k) / 100.0, data [k]) ; |
| 483 | exit (1) ; |
| 484 | } ; |
| 485 | } ; |
| 486 | |
| 487 | /* Seek to offset from start of file. */ |
| 488 | test_seek_or_die (file, 10, SEEK_SET, 10, sfinfo.channels, __LINE__) ; |
| 489 | |
| 490 | test_read_double_or_die (file, 0, data + 10, 4, __LINE__) ; |
| 491 | for (k = 10 ; k < 14 ; k++) |
| 492 | { error = fabs (data [k] - ((double) k) / 100.0 * (sign *= -1)) ; |
| 493 | if (fabs (data [k]) > 1e-100 && fabs (error / data [k]) > 1e-5) |
| 494 | { printf ("\n\nError (%s:%d) Mono : Incorrect sample (#%d : %f => %f).\n", __FILE__, __LINE__, k, ((double) k) / 100.0, data [k]) ; |
| 495 | exit (1) ; |
| 496 | } ; |
| 497 | } ; |
| 498 | |
| 499 | /* Seek to offset from current position. */ |
| 500 | test_seek_or_die (file, 6, SEEK_CUR, 20, sfinfo.channels, __LINE__) ; |
| 501 | |
| 502 | test_read_double_or_die (file, 0, data + 20, 4, __LINE__) ; |
| 503 | for (k = 20 ; k < 24 ; k++) |
| 504 | { error = fabs (data [k] - ((double) k) / 100.0 * (sign *= -1)) ; |
| 505 | if (fabs (data [k]) > 1e-100 && fabs (error / data [k]) > 1e-5) |
| 506 | { printf ("\n\nError (%s:%d) Mono : Incorrect sample (#%d : %f => %f).\n", __FILE__, __LINE__, k, ((double) k) / 100.0, data [k]) ; |
| 507 | exit (1) ; |
| 508 | } ; |
| 509 | } ; |
| 510 | |
| 511 | /* Seek to offset from end of file. */ |
| 512 | test_seek_or_die (file, -1 * (sfinfo.frames - 10), SEEK_END, 10, sfinfo.channels, __LINE__) ; |
| 513 | |
| 514 | test_read_double_or_die (file, 0, data + 10, 4, __LINE__) ; |
| 515 | for (k = 10 ; k < 14 ; k++) |
| 516 | { error = fabs (data [k] - ((double) k) / 100.0 * (sign *= -1)) ; |
| 517 | if (fabs (data [k]) > 1e-100 && fabs (error / data [k]) > 1e-5) |
| 518 | { printf ("\n\nError (%s:%d) Mono : Incorrect sample (#%d : %f => %f).\n", __FILE__, __LINE__, k, ((double) k) / 100.0, data [k]) ; |
| 519 | exit (1) ; |
| 520 | } ; |
| 521 | } ; |
| 522 | |
| 523 | sf_close (file) ; |
| 524 | |
| 525 | /* Now test Stereo. */ |
| 526 | |
| 527 | if ((filetype & SF_FORMAT_TYPEMASK) == SF_FORMAT_SVX) /* SVX is mono only */ |
| 528 | { printf ("ok\n") ; |
| 529 | return ; |
| 530 | } ; |
| 531 | |
| 532 | items = BUFFER_SIZE ; |
| 533 | |
| 534 | data = data_out.d ; |
| 535 | for (sign = -1, k = 0 ; k < items ; k++) |
| 536 | data [k] = ((double) k) / 100.0 * (sign *= -1) ; |
| 537 | |
| 538 | sfinfo.samplerate = 44100 ; |
| 539 | sfinfo.frames = items ; |
| 540 | sfinfo.channels = 2 ; |
| 541 | sfinfo.format = filetype ; |
| 542 | |
| 543 | frames = items / sfinfo.channels ; |
| 544 | |
| 545 | file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ; |
| 546 | sf_command (file, SFC_TEST_IEEE_FLOAT_REPLACE, NULL, replace_float) ; |
| 547 | if (replace_float && string_in_log_buffer (file, "Using IEEE replacement") == 0) |
| 548 | { printf ("\n\nLine %d : Float replacement code not working.\n\n", __LINE__) ; |
| 549 | dump_log_buffer (file) ; |
| 550 | exit (1) ; |
| 551 | } ; |
| 552 | |
| 553 | test_writef_double_or_die (file, 0, data, frames, __LINE__) ; |
| 554 | |
| 555 | sf_close (file) ; |
| 556 | |
| 557 | check_file_hash_or_die (filename, hash, __LINE__) ; |
| 558 | |
| 559 | memset (data, 0, items * sizeof (double)) ; |
| 560 | |
| 561 | if ((filetype & SF_FORMAT_TYPEMASK) != SF_FORMAT_RAW) |
| 562 | memset (&sfinfo, 0, sizeof (sfinfo)) ; |
| 563 | |
| 564 | file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ; |
| 565 | sf_command (file, SFC_TEST_IEEE_FLOAT_REPLACE, NULL, replace_float) ; |
| 566 | if (replace_float && string_in_log_buffer (file, "Using IEEE replacement") == 0) |
| 567 | { printf ("\n\nLine %d : Float replacement code not working.\n\n", __LINE__) ; |
| 568 | dump_log_buffer (file) ; |
| 569 | exit (1) ; |
| 570 | } ; |
| 571 | |
| 572 | if (sfinfo.format != filetype) |
| 573 | { printf ("\n\nError (%s:%d) Stereo : Returned format incorrect (0x%08X => 0x%08X).\n", __FILE__, __LINE__, filetype, sfinfo.format) ; |
| 574 | exit (1) ; |
| 575 | } ; |
| 576 | |
| 577 | if (sfinfo.frames != frames) |
| 578 | { printf ("\n\nError (%s:%d) Stereo : Incorrect number of frames in file. (%d => %ld)\n", __FILE__, __LINE__, frames, SF_COUNT_TO_LONG (sfinfo.frames)) ; |
| 579 | exit (1) ; |
| 580 | } ; |
| 581 | |
| 582 | if (sfinfo.channels != 2) |
| 583 | { printf ("\n\nError (%s:%d) Stereo : Incorrect number of channels in file.\n", __FILE__, __LINE__) ; |
| 584 | exit (1) ; |
| 585 | } ; |
| 586 | |
| 587 | check_log_buffer_or_die (file, __LINE__) ; |
| 588 | |
| 589 | test_readf_double_or_die (file, 0, data, frames, __LINE__) ; |
| 590 | for (sign = -1, k = 0 ; k < items ; k++) |
| 591 | { error = fabs (data [k] - ((double) k) / 100.0 * (sign *= -1)) ; |
| 592 | if (fabs (data [k]) > 1e-100 && fabs (error / data [k]) > 1e-5) |
| 593 | { printf ("\n\nError (%s:%d) Stereo : Incorrect sample (#%d : %f => %f).\n", __FILE__, __LINE__, k, ((double) k) / 100.0, data [k]) ; |
| 594 | exit (1) ; |
| 595 | } ; |
| 596 | } ; |
| 597 | |
| 598 | /* Seek to start of file. */ |
| 599 | test_seek_or_die (file, 0, SEEK_SET, 0, sfinfo.channels, __LINE__) ; |
| 600 | |
| 601 | test_readf_double_or_die (file, 0, data, 4, __LINE__) ; |
| 602 | for (k = 0 ; k < 4 ; k++) |
| 603 | { error = fabs (data [k] - ((double) k) / 100.0 * (sign *= -1)) ; |
| 604 | if (fabs (data [k]) > 1e-100 && fabs (error / data [k]) > 1e-5) |
| 605 | { printf ("\n\nError (%s:%d) Stereo : Incorrect sample (#%d : %f => %f).\n", __FILE__, __LINE__, k, ((double) k) / 100.0, data [k]) ; |
| 606 | exit (1) ; |
| 607 | } ; |
| 608 | } ; |
| 609 | |
| 610 | /* Seek to offset from start of file. */ |
| 611 | test_seek_or_die (file, 10, SEEK_SET, 10, sfinfo.channels, __LINE__) ; |
| 612 | |
| 613 | test_readf_double_or_die (file, 0, data + 20, 2, __LINE__) ; |
| 614 | for (k = 20 ; k < 24 ; k++) |
| 615 | { error = fabs (data [k] - ((double) k) / 100.0 * (sign *= -1)) ; |
| 616 | if (fabs (data [k]) > 1e-100 && fabs (error / data [k]) > 1e-5) |
| 617 | { printf ("\n\nError (%s:%d) Stereo : Incorrect sample (#%d : %f => %f).\n", __FILE__, __LINE__, k, ((double) k) / 100.0, data [k]) ; |
| 618 | exit (1) ; |
| 619 | } ; |
| 620 | } ; |
| 621 | |
| 622 | /* Seek to offset from current position. */ |
| 623 | test_seek_or_die (file, 8, SEEK_CUR, 20, sfinfo.channels, __LINE__) ; |
| 624 | |
| 625 | test_readf_double_or_die (file, 0, data + 40, 2, __LINE__) ; |
| 626 | for (k = 40 ; k < 44 ; k++) |
| 627 | { error = fabs (data [k] - ((double) k) / 100.0 * (sign *= -1)) ; |
| 628 | if (fabs (data [k]) > 1e-100 && fabs (error / data [k]) > 1e-5) |
| 629 | { printf ("\n\nError (%s:%d) Stereo : Incorrect sample (#%d : %f => %f).\n", __FILE__, __LINE__, k, ((double) k) / 100.0, data [k]) ; |
| 630 | exit (1) ; |
| 631 | } ; |
| 632 | } ; |
| 633 | |
| 634 | /* Seek to offset from end of file. */ |
| 635 | test_seek_or_die (file, -1 * (sfinfo.frames - 10), SEEK_END, 10, sfinfo.channels, __LINE__) ; |
| 636 | |
| 637 | test_readf_double_or_die (file, 0, data + 20, 2, __LINE__) ; |
| 638 | for (k = 20 ; k < 24 ; k++) |
| 639 | { error = fabs (data [k] - ((double) k) / 100.0 * (sign *= -1)) ; |
| 640 | if (fabs (data [k]) > 1e-100 && fabs (error / data [k]) > 1e-5) |
| 641 | { printf ("\n\nError (%s:%d) Stereo : Incorrect sample (#%d : %f => %f).\n", __FILE__, __LINE__, k, ((double) k) / 100.0, data [k]) ; |
| 642 | exit (1) ; |
| 643 | } ; |
| 644 | } ; |
| 645 | |
| 646 | sf_close (file) ; |
| 647 | |
| 648 | printf ("ok\n") ; |
| 649 | unlink (filename) ; |
| 650 | } /* pcm_test_float */ |
| 651 | |
| 652 | static void |
| 653 | pcm_test_double (const char *filename, int filetype, uint64_t hash, int replace_float) |
| 654 | { SNDFILE *file ; |
| 655 | SF_INFO sfinfo ; |
| 656 | int k, items, frames ; |
| 657 | int sign ; |
| 658 | double *data, error ; |
| 659 | |
| 660 | /* This is the best test routine. Other should be brought up to this standard. */ |
| 661 | |
| 662 | print_test_name (replace_float ? "pcm_test_double (replace)" : "pcm_test_double", filename) ; |
| 663 | |
| 664 | items = BUFFER_SIZE ; |
| 665 | |
| 666 | data = data_out.d ; |
| 667 | for (sign = 1, k = 0 ; k < items ; k++) |
| 668 | { data [k] = ((double) (k * sign)) / 100.0 ; |
| 669 | sign = (sign > 0) ? -1 : 1 ; |
| 670 | } ; |
| 671 | |
| 672 | sfinfo.samplerate = 44100 ; |
| 673 | sfinfo.frames = items ; |
| 674 | sfinfo.channels = 1 ; |
| 675 | sfinfo.format = filetype ; |
| 676 | |
| 677 | file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ; |
| 678 | sf_command (file, SFC_TEST_IEEE_FLOAT_REPLACE, NULL, replace_float) ; |
| 679 | if (replace_float && string_in_log_buffer (file, "Using IEEE replacement") == 0) |
| 680 | { printf ("\n\nLine %d : Float replacement code not working.\n\n", __LINE__) ; |
| 681 | dump_log_buffer (file) ; |
| 682 | exit (1) ; |
| 683 | } ; |
| 684 | |
| 685 | test_write_double_or_die (file, 0, data, items, __LINE__) ; |
| 686 | |
| 687 | sf_close (file) ; |
| 688 | |
| 689 | #if (defined (WIN32) || defined (_WIN32)) |
| 690 | /* File hashing on Win32 fails due to slighty different |
| 691 | ** calculated values of the sin() function. |
| 692 | */ |
| 693 | hash = hash ; /* Avoid compiler warning. */ |
| 694 | #else |
| 695 | check_file_hash_or_die (filename, hash, __LINE__) ; |
| 696 | #endif |
| 697 | |
| 698 | memset (data, 0, items * sizeof (double)) ; |
| 699 | |
| 700 | if ((filetype & SF_FORMAT_TYPEMASK) != SF_FORMAT_RAW) |
| 701 | memset (&sfinfo, 0, sizeof (sfinfo)) ; |
| 702 | |
| 703 | file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ; |
| 704 | sf_command (file, SFC_TEST_IEEE_FLOAT_REPLACE, NULL, replace_float) ; |
| 705 | if (replace_float && string_in_log_buffer (file, "Using IEEE replacement") == 0) |
| 706 | { printf ("\n\nLine %d : Float replacement code not working.\n\n", __LINE__) ; |
| 707 | dump_log_buffer (file) ; |
| 708 | exit (1) ; |
| 709 | } ; |
| 710 | |
| 711 | if (sfinfo.format != filetype) |
| 712 | { printf ("\n\nError (%s:%d) Mono : Returned format incorrect (0x%08X => 0x%08X).\n", __FILE__, __LINE__, filetype, sfinfo.format) ; |
| 713 | exit (1) ; |
| 714 | } ; |
| 715 | |
| 716 | if (sfinfo.frames != items) |
| 717 | { printf ("\n\nError (%s:%d) Mono : Incorrect number of frames in file. (%d => %ld)\n", __FILE__, __LINE__, items, SF_COUNT_TO_LONG (sfinfo.frames)) ; |
| 718 | exit (1) ; |
| 719 | } ; |
| 720 | |
| 721 | if (sfinfo.channels != 1) |
| 722 | { printf ("\n\nError (%s:%d) Mono : Incorrect number of channels in file.\n", __FILE__, __LINE__) ; |
| 723 | exit (1) ; |
| 724 | } ; |
| 725 | |
| 726 | check_log_buffer_or_die (file, __LINE__) ; |
| 727 | |
| 728 | test_read_double_or_die (file, 0, data, items, __LINE__) ; |
| 729 | |
| 730 | for (sign = -1, k = 0 ; k < items ; k++) |
| 731 | { error = fabs (data [k] - ((double) k) / 100.0 * (sign *= -1)) ; |
| 732 | if (fabs (data [k]) > 1e-100 && fabs (error / data [k]) > 1e-5) |
| 733 | { printf ("\n\nError (%s:%d) Mono : Incorrect sample (#%d : %f => %f).\n", __FILE__, __LINE__, k, ((double) k) / 100.0, data [k]) ; |
| 734 | exit (1) ; |
| 735 | } ; |
| 736 | } ; |
| 737 | |
| 738 | /* Seek to start of file. */ |
| 739 | test_seek_or_die (file, 0, SEEK_SET, 0, sfinfo.channels, __LINE__) ; |
| 740 | |
| 741 | test_read_double_or_die (file, 0, data, 4, __LINE__) ; |
| 742 | for (k = 0 ; k < 4 ; k++) |
| 743 | { error = fabs (data [k] - ((double) k) / 100.0 * (sign *= -1)) ; |
| 744 | if (fabs (data [k]) > 1e-100 && fabs (error / data [k]) > 1e-5) |
| 745 | { printf ("\n\nError (%s:%d) Mono : Incorrect sample (#%d : %f => %f).\n", __FILE__, __LINE__, k, ((double) k) / 100.0, data [k]) ; |
| 746 | exit (1) ; |
| 747 | } ; |
| 748 | } ; |
| 749 | |
| 750 | /* Seek to offset from start of file. */ |
| 751 | test_seek_or_die (file, 10, SEEK_SET, 10, sfinfo.channels, __LINE__) ; |
| 752 | |
| 753 | test_read_double_or_die (file, 0, data + 10, 4, __LINE__) ; |
| 754 | |
| 755 | test_seek_or_die (file, 0, SEEK_CUR, 14, sfinfo.channels, __LINE__) ; |
| 756 | |
| 757 | for (k = 10 ; k < 14 ; k++) |
| 758 | { error = fabs (data [k] - ((double) k) / 100.0 * (sign *= -1)) ; |
| 759 | if (fabs (data [k]) > 1e-100 && fabs (error / data [k]) > 1e-5) |
| 760 | { printf ("\n\nError (%s:%d) Mono : Incorrect sample (#%d : %f => %f).\n", __FILE__, __LINE__, k, ((double) k) / 100.0, data [k]) ; |
| 761 | exit (1) ; |
| 762 | } ; |
| 763 | } ; |
| 764 | |
| 765 | /* Seek to offset from current position. */ |
| 766 | test_seek_or_die (file, 6, SEEK_CUR, 20, sfinfo.channels, __LINE__) ; |
| 767 | |
| 768 | test_read_double_or_die (file, 0, data + 20, 4, __LINE__) ; |
| 769 | for (k = 20 ; k < 24 ; k++) |
| 770 | { error = fabs (data [k] - ((double) k) / 100.0 * (sign *= -1)) ; |
| 771 | if (fabs (data [k]) > 1e-100 && fabs (error / data [k]) > 1e-5) |
| 772 | { printf ("\n\nError (%s:%d) Mono : Incorrect sample (#%d : %f => %f).\n", __FILE__, __LINE__, k, ((double) k) / 100.0, data [k]) ; |
| 773 | exit (1) ; |
| 774 | } ; |
| 775 | } ; |
| 776 | |
| 777 | /* Seek to offset from end of file. */ |
| 778 | test_seek_or_die (file, -1 * (sfinfo.frames - 10), SEEK_END, 10, sfinfo.channels, __LINE__) ; |
| 779 | |
| 780 | test_read_double_or_die (file, 0, data + 10, 4, __LINE__) ; |
| 781 | for (k = 10 ; k < 14 ; k++) |
| 782 | { error = fabs (data [k] - ((double) k) / 100.0 * (sign *= -1)) ; |
| 783 | if (fabs (data [k]) > 1e-100 && fabs (error / data [k]) > 1e-5) |
| 784 | { printf ("\n\nError (%s:%d) Mono : Incorrect sample (#%d : %f => %f).\n", __FILE__, __LINE__, k, ((double) k) / 100.0, data [k]) ; |
| 785 | exit (1) ; |
| 786 | } ; |
| 787 | } ; |
| 788 | |
| 789 | sf_close (file) ; |
| 790 | |
| 791 | /* Now test Stereo. */ |
| 792 | |
| 793 | if ((filetype & SF_FORMAT_TYPEMASK) == SF_FORMAT_SVX) /* SVX is mono only */ |
| 794 | { printf ("ok\n") ; |
| 795 | return ; |
| 796 | } ; |
| 797 | |
| 798 | items = BUFFER_SIZE ; |
| 799 | |
| 800 | data = data_out.d ; |
| 801 | for (sign = -1, k = 0 ; k < items ; k++) |
| 802 | data [k] = ((double) k) / 100.0 * (sign *= -1) ; |
| 803 | |
| 804 | sfinfo.samplerate = 44100 ; |
| 805 | sfinfo.frames = items ; |
| 806 | sfinfo.channels = 2 ; |
| 807 | sfinfo.format = filetype ; |
| 808 | |
| 809 | frames = items / sfinfo.channels ; |
| 810 | |
| 811 | file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ; |
| 812 | sf_command (file, SFC_TEST_IEEE_FLOAT_REPLACE, NULL, replace_float) ; |
| 813 | if (replace_float && string_in_log_buffer (file, "Using IEEE replacement") == 0) |
| 814 | { printf ("\n\nLine %d : Float replacement code not working.\n\n", __LINE__) ; |
| 815 | dump_log_buffer (file) ; |
| 816 | exit (1) ; |
| 817 | } ; |
| 818 | |
| 819 | test_writef_double_or_die (file, 0, data, frames, __LINE__) ; |
| 820 | |
| 821 | sf_close (file) ; |
| 822 | |
| 823 | #if (defined (WIN32) || defined (_WIN32)) |
| 824 | /* File hashing on Win32 fails due to slighty different |
| 825 | ** calculated values. |
| 826 | */ |
| 827 | hash = hash ; /* Avoid compiler warning. */ |
| 828 | #else |
| 829 | check_file_hash_or_die (filename, hash, __LINE__) ; |
| 830 | #endif |
| 831 | |
| 832 | memset (data, 0, items * sizeof (double)) ; |
| 833 | |
| 834 | if ((filetype & SF_FORMAT_TYPEMASK) != SF_FORMAT_RAW) |
| 835 | memset (&sfinfo, 0, sizeof (sfinfo)) ; |
| 836 | |
| 837 | file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ; |
| 838 | sf_command (file, SFC_TEST_IEEE_FLOAT_REPLACE, NULL, replace_float) ; |
| 839 | if (replace_float && string_in_log_buffer (file, "Using IEEE replacement") == 0) |
| 840 | { printf ("\n\nLine %d : Float replacement code not working.\n\n", __LINE__) ; |
| 841 | dump_log_buffer (file) ; |
| 842 | exit (1) ; |
| 843 | } ; |
| 844 | |
| 845 | if (sfinfo.format != filetype) |
| 846 | { printf ("\n\nError (%s:%d) Stereo : Returned format incorrect (0x%08X => 0x%08X).\n", __FILE__, __LINE__, filetype, sfinfo.format) ; |
| 847 | exit (1) ; |
| 848 | } ; |
| 849 | |
| 850 | if (sfinfo.frames != frames) |
| 851 | { printf ("\n\nError (%s:%d) Stereo : Incorrect number of frames in file. (%d => %ld)\n", __FILE__, __LINE__, frames, SF_COUNT_TO_LONG (sfinfo.frames)) ; |
| 852 | exit (1) ; |
| 853 | } ; |
| 854 | |
| 855 | if (sfinfo.channels != 2) |
| 856 | { printf ("\n\nError (%s:%d) Stereo : Incorrect number of channels in file.\n", __FILE__, __LINE__) ; |
| 857 | exit (1) ; |
| 858 | } ; |
| 859 | |
| 860 | check_log_buffer_or_die (file, __LINE__) ; |
| 861 | |
| 862 | test_readf_double_or_die (file, 0, data, frames, __LINE__) ; |
| 863 | |
| 864 | for (sign = -1, k = 0 ; k < items ; k++) |
| 865 | { error = fabs (data [k] - ((double) k) / 100.0 * (sign *= -1)) ; |
| 866 | if (fabs (data [k]) > 1e-100 && fabs (error / data [k]) > 1e-5) |
| 867 | { printf ("\n\nError (%s:%d) Stereo : Incorrect sample (#%d : %f => %f).\n", __FILE__, __LINE__, k, ((double) k) / 100.0, data [k]) ; |
| 868 | exit (1) ; |
| 869 | } ; |
| 870 | } ; |
| 871 | |
| 872 | /* Seek to start of file. */ |
| 873 | test_seek_or_die (file, 0, SEEK_SET, 0, sfinfo.channels, __LINE__) ; |
| 874 | |
| 875 | test_read_double_or_die (file, 0, data, 4, __LINE__) ; |
| 876 | for (k = 0 ; k < 4 ; k++) |
| 877 | { error = fabs (data [k] - ((double) k) / 100.0 * (sign *= -1)) ; |
| 878 | if (fabs (data [k]) > 1e-100 && fabs (error / data [k]) > 1e-5) |
| 879 | { printf ("\n\nError (%s:%d) Stereo : Incorrect sample (#%d : %f => %f).\n", __FILE__, __LINE__, k, ((double) k) / 100.0, data [k]) ; |
| 880 | exit (1) ; |
| 881 | } ; |
| 882 | } ; |
| 883 | |
| 884 | /* Seek to offset from start of file. */ |
| 885 | test_seek_or_die (file, 10, SEEK_SET, 10, sfinfo.channels, __LINE__) ; |
| 886 | |
| 887 | test_read_double_or_die (file, 0, data + 10, 4, __LINE__) ; |
| 888 | for (k = 20 ; k < 24 ; k++) |
| 889 | { error = fabs (data [k] - ((double) k) / 100.0 * (sign *= -1)) ; |
| 890 | if (fabs (data [k]) > 1e-100 && fabs (error / data [k]) > 1e-5) |
| 891 | { printf ("\n\nError (%s:%d) Stereo : Incorrect sample (#%d : %f => %f).\n", __FILE__, __LINE__, k, ((double) k) / 100.0, data [k]) ; |
| 892 | exit (1) ; |
| 893 | } ; |
| 894 | } ; |
| 895 | |
| 896 | /* Seek to offset from current position. */ |
| 897 | test_seek_or_die (file, 8, SEEK_CUR, 20, sfinfo.channels, __LINE__) ; |
| 898 | |
| 899 | test_readf_double_or_die (file, 0, data + 40, 4, __LINE__) ; |
| 900 | for (k = 40 ; k < 44 ; k++) |
| 901 | { error = fabs (data [k] - ((double) k) / 100.0 * (sign *= -1)) ; |
| 902 | if (fabs (data [k]) > 1e-100 && fabs (error / data [k]) > 1e-5) |
| 903 | { printf ("\n\nError (%s:%d) Stereo : Incorrect sample (#%d : %f => %f).\n", __FILE__, __LINE__, k, ((double) k) / 100.0, data [k]) ; |
| 904 | exit (1) ; |
| 905 | } ; |
| 906 | } ; |
| 907 | |
| 908 | /* Seek to offset from end of file. */ |
| 909 | test_seek_or_die (file, -1 * (sfinfo.frames -10), SEEK_END, 10, sfinfo.channels, __LINE__) ; |
| 910 | |
| 911 | test_readf_double_or_die (file, 0, data + 20, 4, __LINE__) ; |
| 912 | for (k = 20 ; k < 24 ; k++) |
| 913 | { error = fabs (data [k] - ((double) k) / 100.0 * (sign *= -1)) ; |
| 914 | if (fabs (data [k]) > 1e-100 && fabs (error / data [k]) > 1e-5) |
| 915 | { printf ("\n\nError (%s:%d) Stereo : Incorrect sample (#%d : %f => %f).\n", __FILE__, __LINE__, k, ((double) k) / 100.0, data [k]) ; |
| 916 | exit (1) ; |
| 917 | } ; |
| 918 | } ; |
| 919 | |
| 920 | sf_close (file) ; |
| 921 | |
| 922 | printf ("ok\n") ; |
| 923 | unlink (filename) ; |
| 924 | } /* pcm_test_double */ |
| 925 | |
| 926 | /*============================================================================== |
| 927 | */ |