123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694 |
- /*
- ** Copyright (C) 1999-2011 Erik de Castro Lopo <erikd@mega-nerd.com>
- **
- ** This program is free software; you can redistribute it and/or modify
- ** it under the terms of the GNU General Public License as published by
- ** the Free Software Foundation; either version 2 of the License, or
- ** (at your option) any later version.
- **
- ** This program is distributed in the hope that it will be useful,
- ** but WITHOUT ANY WARRANTY; without even the implied warranty of
- ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- ** GNU General Public License for more details.
- **
- ** You should have received a copy of the GNU General Public License
- ** along with this program; if not, write to the Free Software
- ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- */
- #include "sfconfig.h"
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <math.h>
- #if HAVE_UNISTD_H
- #include <unistd.h>
- #endif
- #include <sndfile.h>
- #include "dft_cmp.h"
- #include "utils.h"
- #define SAMPLE_RATE 16000
- static void float_scaled_test (const char *filename, int allow_exit, int replace_float, int filetype, double target_snr) ;
- static void double_scaled_test (const char *filename, int allow_exit, int replace_float, int filetype, double target_snr) ;
- static void float_short_little_test (const char * filename) ;
- static void float_short_big_test (const char * filename) ;
- static void float_int_little_test (const char * filename) ;
- static void float_int_big_test (const char * filename) ;
- static void double_short_little_test (const char * filename) ;
- static void double_short_big_test (const char * filename) ;
- static void double_int_little_test (const char * filename) ;
- static void double_int_big_test (const char * filename) ;
- static double double_data [DFT_DATA_LENGTH] ;
- static double double_test [DFT_DATA_LENGTH] ;
- static float float_data [DFT_DATA_LENGTH] ;
- static float float_test [DFT_DATA_LENGTH] ;
- static double double_data [DFT_DATA_LENGTH] ;
- static short short_data [DFT_DATA_LENGTH] ;
- static int int_data [DFT_DATA_LENGTH] ;
- int
- main (int argc, char *argv [])
- { int allow_exit = 1 ;
- if (argc == 2 && ! strstr (argv [1], "no-exit"))
- allow_exit = 0 ;
- #if ((HAVE_LRINTF == 0) && (HAVE_LRINT_REPLACEMENT == 0))
- puts ("*** Cannot run this test on this platform because it lacks lrintf().") ;
- exit (0) ;
- #endif
- /* Float tests. */
- float_scaled_test ("float.raw", allow_exit, SF_FALSE, SF_ENDIAN_LITTLE | SF_FORMAT_RAW | SF_FORMAT_FLOAT, -163.0) ;
- /* Test both signed and unsigned 8 bit files. */
- float_scaled_test ("pcm_s8.raw", allow_exit, SF_FALSE, SF_FORMAT_RAW | SF_FORMAT_PCM_S8, -39.0) ;
- float_scaled_test ("pcm_u8.raw", allow_exit, SF_FALSE, SF_FORMAT_RAW | SF_FORMAT_PCM_U8, -39.0) ;
- float_scaled_test ("pcm_16.raw", allow_exit, SF_FALSE, SF_ENDIAN_BIG | SF_FORMAT_RAW | SF_FORMAT_PCM_16, -87.0) ;
- float_scaled_test ("pcm_24.raw", allow_exit, SF_FALSE, SF_ENDIAN_LITTLE | SF_FORMAT_RAW | SF_FORMAT_PCM_24, -138.0) ;
- float_scaled_test ("pcm_32.raw", allow_exit, SF_FALSE, SF_ENDIAN_BIG | SF_FORMAT_RAW | SF_FORMAT_PCM_32, -163.0) ;
- float_scaled_test ("ulaw.raw", allow_exit, SF_FALSE, SF_FORMAT_RAW | SF_FORMAT_ULAW, -50.0) ;
- float_scaled_test ("alaw.raw", allow_exit, SF_FALSE, SF_FORMAT_RAW | SF_FORMAT_ALAW, -49.0) ;
- float_scaled_test ("ima_adpcm.wav", allow_exit, SF_FALSE, SF_FORMAT_WAV | SF_FORMAT_IMA_ADPCM, -47.0) ;
- float_scaled_test ("ms_adpcm.wav" , allow_exit, SF_FALSE, SF_FORMAT_WAV | SF_FORMAT_MS_ADPCM, -40.0) ;
- float_scaled_test ("gsm610.raw" , allow_exit, SF_FALSE, SF_FORMAT_RAW | SF_FORMAT_GSM610, -33.0) ;
- float_scaled_test ("g721_32.au", allow_exit, SF_FALSE, SF_FORMAT_AU | SF_FORMAT_G721_32, -34.0) ;
- float_scaled_test ("g723_24.au", allow_exit, SF_FALSE, SF_FORMAT_AU | SF_FORMAT_G723_24, -34.0) ;
- float_scaled_test ("g723_40.au", allow_exit, SF_FALSE, SF_FORMAT_AU | SF_FORMAT_G723_40, -40.0) ;
- /* PAF files do not use the same encoding method for 24 bit PCM data as other file
- ** formats so we need to explicitly test it here.
- */
- float_scaled_test ("le_paf_24.paf", allow_exit, SF_FALSE, SF_ENDIAN_LITTLE | SF_FORMAT_PAF | SF_FORMAT_PCM_24, -149.0) ;
- float_scaled_test ("be_paf_24.paf", allow_exit, SF_FALSE, SF_ENDIAN_BIG | SF_FORMAT_PAF | SF_FORMAT_PCM_24, -149.0) ;
- float_scaled_test ("dwvw_12.raw", allow_exit, SF_FALSE, SF_FORMAT_RAW | SF_FORMAT_DWVW_12, -64.0) ;
- float_scaled_test ("dwvw_16.raw", allow_exit, SF_FALSE, SF_FORMAT_RAW | SF_FORMAT_DWVW_16, -92.0) ;
- float_scaled_test ("dwvw_24.raw", allow_exit, SF_FALSE, SF_FORMAT_RAW | SF_FORMAT_DWVW_24, -151.0) ;
- float_scaled_test ("adpcm.vox", allow_exit, SF_FALSE, SF_FORMAT_RAW | SF_FORMAT_VOX_ADPCM, -40.0) ;
- float_scaled_test ("dpcm_16.xi", allow_exit, SF_FALSE, SF_FORMAT_XI | SF_FORMAT_DPCM_16, -90.0) ;
- float_scaled_test ("dpcm_8.xi" , allow_exit, SF_FALSE, SF_FORMAT_XI | SF_FORMAT_DPCM_8 , -41.0) ;
- float_scaled_test ("pcm_s8.sds", allow_exit, SF_FALSE, SF_FORMAT_SDS | SF_FORMAT_PCM_S8, -90.0) ;
- float_scaled_test ("pcm_16.sds", allow_exit, SF_FALSE, SF_FORMAT_SDS | SF_FORMAT_PCM_16, -140.0) ;
- float_scaled_test ("pcm_24.sds", allow_exit, SF_FALSE, SF_FORMAT_SDS | SF_FORMAT_PCM_24, -170.0) ;
- #if HAVE_EXTERNAL_LIBS
- float_scaled_test ("flac_8.flac", allow_exit, SF_FALSE, SF_FORMAT_FLAC | SF_FORMAT_PCM_S8, -39.0) ;
- float_scaled_test ("flac_16.flac", allow_exit, SF_FALSE, SF_FORMAT_FLAC | SF_FORMAT_PCM_16, -87.0) ;
- float_scaled_test ("flac_24.flac", allow_exit, SF_FALSE, SF_FORMAT_FLAC | SF_FORMAT_PCM_24, -138.0) ;
- float_scaled_test ("vorbis.oga", allow_exit, SF_FALSE, SF_FORMAT_OGG | SF_FORMAT_VORBIS, -31.0) ;
- #endif
- float_scaled_test ("replace_float.raw", allow_exit, SF_TRUE, SF_ENDIAN_LITTLE | SF_FORMAT_RAW | SF_FORMAT_FLOAT, -163.0) ;
- /*==============================================================================
- ** Double tests.
- */
- double_scaled_test ("double.raw", allow_exit, SF_FALSE, SF_FORMAT_RAW | SF_FORMAT_DOUBLE, -300.0) ;
- /* Test both signed (AIFF) and unsigned (WAV) 8 bit files. */
- double_scaled_test ("pcm_s8.raw", allow_exit, SF_FALSE, SF_FORMAT_RAW | SF_FORMAT_PCM_S8, -39.0) ;
- double_scaled_test ("pcm_u8.raw", allow_exit, SF_FALSE, SF_FORMAT_RAW | SF_FORMAT_PCM_U8, -39.0) ;
- double_scaled_test ("pcm_16.raw", allow_exit, SF_FALSE, SF_FORMAT_RAW | SF_FORMAT_PCM_16, -87.0) ;
- double_scaled_test ("pcm_24.raw", allow_exit, SF_FALSE, SF_FORMAT_RAW | SF_FORMAT_PCM_24, -135.0) ;
- double_scaled_test ("pcm_32.raw", allow_exit, SF_FALSE, SF_FORMAT_RAW | SF_FORMAT_PCM_32, -184.0) ;
- double_scaled_test ("ulaw.raw", allow_exit, SF_FALSE, SF_FORMAT_RAW | SF_FORMAT_ULAW, -50.0) ;
- double_scaled_test ("alaw.raw", allow_exit, SF_FALSE, SF_FORMAT_RAW | SF_FORMAT_ALAW, -49.0) ;
- double_scaled_test ("ima_adpcm.wav", allow_exit, SF_FALSE, SF_FORMAT_WAV | SF_FORMAT_IMA_ADPCM, -47.0) ;
- double_scaled_test ("ms_adpcm.wav" , allow_exit, SF_FALSE, SF_FORMAT_WAV | SF_FORMAT_MS_ADPCM, -40.0) ;
- double_scaled_test ("gsm610.raw" , allow_exit, SF_FALSE, SF_FORMAT_RAW | SF_FORMAT_GSM610, -33.0) ;
- double_scaled_test ("g721_32.au", allow_exit, SF_FALSE, SF_FORMAT_AU | SF_FORMAT_G721_32, -34.0) ;
- double_scaled_test ("g723_24.au", allow_exit, SF_FALSE, SF_FORMAT_AU | SF_FORMAT_G723_24, -34.0) ;
- double_scaled_test ("g723_40.au", allow_exit, SF_FALSE, SF_FORMAT_AU | SF_FORMAT_G723_40, -40.0) ;
- /* 24 bit PCM PAF files tested here. */
- double_scaled_test ("be_paf_24.paf", allow_exit, SF_FALSE, SF_ENDIAN_BIG | SF_FORMAT_PAF | SF_FORMAT_PCM_24, -151.0) ;
- double_scaled_test ("le_paf_24.paf", allow_exit, SF_FALSE, SF_ENDIAN_LITTLE | SF_FORMAT_PAF | SF_FORMAT_PCM_24, -151.0) ;
- double_scaled_test ("dwvw_12.raw", allow_exit, SF_FALSE, SF_FORMAT_RAW | SF_FORMAT_DWVW_12, -64.0) ;
- double_scaled_test ("dwvw_16.raw", allow_exit, SF_FALSE, SF_FORMAT_RAW | SF_FORMAT_DWVW_16, -92.0) ;
- double_scaled_test ("dwvw_24.raw", allow_exit, SF_FALSE, SF_FORMAT_RAW | SF_FORMAT_DWVW_24, -151.0) ;
- double_scaled_test ("adpcm.vox" , allow_exit, SF_FALSE, SF_FORMAT_RAW | SF_FORMAT_VOX_ADPCM, -40.0) ;
- double_scaled_test ("dpcm_16.xi", allow_exit, SF_FALSE, SF_FORMAT_XI | SF_FORMAT_DPCM_16, -90.0) ;
- double_scaled_test ("dpcm_8.xi" , allow_exit, SF_FALSE, SF_FORMAT_XI | SF_FORMAT_DPCM_8 , -42.0) ;
- double_scaled_test ("pcm_s8.sds", allow_exit, SF_FALSE, SF_FORMAT_SDS | SF_FORMAT_PCM_S8, -90.0) ;
- double_scaled_test ("pcm_16.sds", allow_exit, SF_FALSE, SF_FORMAT_SDS | SF_FORMAT_PCM_16, -140.0) ;
- double_scaled_test ("pcm_24.sds", allow_exit, SF_FALSE, SF_FORMAT_SDS | SF_FORMAT_PCM_24, -180.0) ;
- #if HAVE_EXTERNAL_LIBS
- double_scaled_test ("flac_8.flac", allow_exit, SF_FALSE, SF_FORMAT_FLAC | SF_FORMAT_PCM_S8, -39.0) ;
- double_scaled_test ("flac_16.flac", allow_exit, SF_FALSE, SF_FORMAT_FLAC | SF_FORMAT_PCM_16, -87.0) ;
- double_scaled_test ("flac_24.flac", allow_exit, SF_FALSE, SF_FORMAT_FLAC | SF_FORMAT_PCM_24, -138.0) ;
- double_scaled_test ("vorbis.oga", allow_exit, SF_FALSE, SF_FORMAT_OGG | SF_FORMAT_VORBIS, -29.0) ;
- #endif
- double_scaled_test ("replace_double.raw", allow_exit, SF_TRUE, SF_FORMAT_RAW | SF_FORMAT_DOUBLE, -300.0) ;
- putchar ('\n') ;
- /* Float int tests. */
- float_short_little_test ("float_short_little.au") ;
- float_short_big_test ("float_short_big.au") ;
- float_int_little_test ("float_int_little.au") ;
- float_int_big_test ("float_int_big.au") ;
- double_short_little_test ("double_short_little.au") ;
- double_short_big_test ("double_short_big.au") ;
- double_int_little_test ("double_int_little.au") ;
- double_int_big_test ("double_int_big.au") ;
- return 0 ;
- } /* main */
- /*============================================================================================
- * Here are the test functions.
- */
- static void
- float_scaled_test (const char *filename, int allow_exit, int replace_float, int filetype, double target_snr)
- { SNDFILE *file ;
- SF_INFO sfinfo ;
- double snr ;
- print_test_name ("float_scaled_test", filename) ;
- gen_windowed_sine_float (float_data, DFT_DATA_LENGTH, 1.0) ;
- sfinfo.samplerate = SAMPLE_RATE ;
- sfinfo.frames = DFT_DATA_LENGTH ;
- sfinfo.channels = 1 ;
- sfinfo.format = filetype ;
- file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
- sf_command (file, SFC_TEST_IEEE_FLOAT_REPLACE, NULL, replace_float) ;
- test_write_float_or_die (file, 0, float_data, DFT_DATA_LENGTH, __LINE__) ;
- sf_close (file) ;
- memset (float_test, 0, sizeof (float_test)) ;
- file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
- sf_command (file, SFC_TEST_IEEE_FLOAT_REPLACE, NULL, replace_float) ;
- exit_if_true (sfinfo.format != filetype, "\n\nLine %d: Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__, filetype, sfinfo.format) ;
- 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) ;
- exit_if_true (sfinfo.channels != 1, "\n\nLine %d: Incorrect number of channels in file.\n", __LINE__) ;
- check_log_buffer_or_die (file, __LINE__) ;
- test_read_float_or_die (file, 0, float_test, DFT_DATA_LENGTH, __LINE__) ;
- sf_close (file) ;
- snr = dft_cmp_float (__LINE__, float_data, float_test, DFT_DATA_LENGTH, target_snr, allow_exit) ;
- exit_if_true (snr > target_snr, "% 6.1fdB SNR\n\n Error : should be better than % 6.1fdB\n\n", snr, target_snr) ;
- printf ("% 6.1fdB SNR ... ok\n", snr) ;
- unlink (filename) ;
- return ;
- } /* float_scaled_test */
- static void
- double_scaled_test (const char *filename, int allow_exit, int replace_float, int filetype, double target_snr)
- { SNDFILE *file ;
- SF_INFO sfinfo ;
- double snr ;
- print_test_name ("double_scaled_test", filename) ;
- gen_windowed_sine_double (double_data, DFT_DATA_LENGTH, 0.95) ;
- sfinfo.samplerate = SAMPLE_RATE ;
- sfinfo.frames = DFT_DATA_LENGTH ;
- sfinfo.channels = 1 ;
- sfinfo.format = filetype ;
- file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
- sf_command (file, SFC_TEST_IEEE_FLOAT_REPLACE, NULL, replace_float) ;
- test_write_double_or_die (file, 0, double_data, DFT_DATA_LENGTH, __LINE__) ;
- sf_close (file) ;
- memset (double_test, 0, sizeof (double_test)) ;
- file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
- sf_command (file, SFC_TEST_IEEE_FLOAT_REPLACE, NULL, replace_float) ;
- exit_if_true (sfinfo.format != filetype, "\n\nLine %d: Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__, filetype, sfinfo.format) ;
- 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) ;
- exit_if_true (sfinfo.channels != 1, "\n\nLine %d: Incorrect number of channels in file.\n", __LINE__) ;
- check_log_buffer_or_die (file, __LINE__) ;
- test_read_double_or_die (file, 0, double_test, DFT_DATA_LENGTH, __LINE__) ;
- sf_close (file) ;
- snr = dft_cmp_double (__LINE__, double_data, double_test, DFT_DATA_LENGTH, target_snr, allow_exit) ;
- exit_if_true (snr > target_snr, "% 6.1fdB SNR\n\n Error : should be better than % 6.1fdB\n\n", snr, target_snr) ;
- printf ("% 6.1fdB SNR ... ok\n", snr) ;
- unlink (filename) ;
- return ;
- } /* double_scaled_test */
- /*==============================================================================
- */
- static void
- float_short_little_test (const char * filename)
- { SNDFILE *file ;
- SF_INFO sfinfo ;
- unsigned k, max ;
- print_test_name ("float_short_little_test", filename) ;
- gen_windowed_sine_float (float_data, ARRAY_LEN (float_data), 0.98) ;
- sfinfo.samplerate = SAMPLE_RATE ;
- sfinfo.frames = ARRAY_LEN (short_data) ;
- sfinfo.channels = 1 ;
- sfinfo.format = SF_ENDIAN_LITTLE | SF_FORMAT_AU | SF_FORMAT_FLOAT ;
- file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
- test_write_float_or_die (file, 0, float_data, ARRAY_LEN (float_data), __LINE__) ;
- sf_close (file) ;
- file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
- if (sfinfo.frames != ARRAY_LEN (float_data))
- { 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) ;
- exit (1) ;
- } ;
- if (sfinfo.channels != 1)
- { printf ("\n\nLine %d: Incorrect number of channels in file.\n", __LINE__) ;
- exit (1) ;
- } ;
- sf_command (file, SFC_SET_SCALE_FLOAT_INT_READ, NULL, SF_TRUE) ;
- test_read_short_or_die (file, 0, short_data, ARRAY_LEN (short_data), __LINE__) ;
- sf_close (file) ;
- max = 0 ;
- for (k = 0 ; k < ARRAY_LEN (short_data) ; k++)
- if ((unsigned) abs (short_data [k]) > max)
- max = abs (short_data [k]) ;
- if (1.0 * abs (max - 0x7FFF) / 0x7FFF > 0.01)
- { printf ("\n\nLine %d: Bad maximum (%d should be %d).\n\n", __LINE__, max, 0x7FFF) ;
- exit (1) ;
- } ;
- unlink (filename) ;
- puts ("ok") ;
- } /* float_short_little_test */
- static void
- float_short_big_test (const char * filename)
- { SNDFILE *file ;
- SF_INFO sfinfo ;
- unsigned k, max ;
- print_test_name ("float_short_big_test", filename) ;
- gen_windowed_sine_float (float_data, ARRAY_LEN (float_data), 0.98) ;
- sfinfo.samplerate = SAMPLE_RATE ;
- sfinfo.frames = ARRAY_LEN (short_data) ;
- sfinfo.channels = 1 ;
- sfinfo.format = SF_ENDIAN_BIG | SF_FORMAT_AU | SF_FORMAT_FLOAT ;
- file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
- test_write_float_or_die (file, 0, float_data, ARRAY_LEN (float_data), __LINE__) ;
- sf_close (file) ;
- file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
- if (sfinfo.frames != ARRAY_LEN (float_data))
- { 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) ;
- exit (1) ;
- } ;
- if (sfinfo.channels != 1)
- { printf ("\n\nLine %d: Incorrect number of channels in file.\n", __LINE__) ;
- exit (1) ;
- } ;
- sf_command (file, SFC_SET_SCALE_FLOAT_INT_READ, NULL, SF_TRUE) ;
- test_read_short_or_die (file, 0, short_data, ARRAY_LEN (short_data), __LINE__) ;
- sf_close (file) ;
- max = 0 ;
- for (k = 0 ; k < ARRAY_LEN (short_data) ; k++)
- if ((unsigned) abs (short_data [k]) > max)
- max = abs (short_data [k]) ;
- if (1.0 * abs (max - 0x7FFF) / 0x7FFF > 0.01)
- { printf ("\n\nLine %d: Bad maximum (%d should be %d).\n\n", __LINE__, max, 0x7FFF) ;
- exit (1) ;
- } ;
- unlink (filename) ;
- puts ("ok") ;
- } /* float_short_big_test */
- static void
- float_int_little_test (const char * filename)
- { SNDFILE *file ;
- SF_INFO sfinfo ;
- unsigned k, max ;
- print_test_name ("float_int_little_test", filename) ;
- gen_windowed_sine_float (float_data, ARRAY_LEN (float_data), 0.98) ;
- sfinfo.samplerate = SAMPLE_RATE ;
- sfinfo.frames = ARRAY_LEN (int_data) ;
- sfinfo.channels = 1 ;
- sfinfo.format = SF_ENDIAN_LITTLE | SF_FORMAT_AU | SF_FORMAT_FLOAT ;
- file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
- test_write_float_or_die (file, 0, float_data, ARRAY_LEN (float_data), __LINE__) ;
- sf_close (file) ;
- file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
- if (sfinfo.frames != ARRAY_LEN (float_data))
- { 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) ;
- exit (1) ;
- } ;
- if (sfinfo.channels != 1)
- { printf ("\n\nLine %d: Incorrect number of channels in file.\n", __LINE__) ;
- exit (1) ;
- } ;
- sf_command (file, SFC_SET_SCALE_FLOAT_INT_READ, NULL, SF_TRUE) ;
- test_read_int_or_die (file, 0, int_data, ARRAY_LEN (int_data), __LINE__) ;
- sf_close (file) ;
- max = 0 ;
- for (k = 0 ; k < ARRAY_LEN (int_data) ; k++)
- if ((unsigned) abs (int_data [k]) > max)
- max = abs (int_data [k]) ;
- if (1.0 * abs (max - 0x7FFFFFFF) / 0x7FFFFFFF > 0.01)
- { printf ("\n\nLine %d: Bad maximum (%d should be %d).\n\n", __LINE__, max, 0x7FFFFFFF) ;
- exit (1) ;
- } ;
- unlink (filename) ;
- puts ("ok") ;
- } /* float_int_little_test */
- static void
- float_int_big_test (const char * filename)
- { SNDFILE *file ;
- SF_INFO sfinfo ;
- unsigned k, max ;
- print_test_name ("float_int_big_test", filename) ;
- gen_windowed_sine_float (float_data, ARRAY_LEN (float_data), 0.98) ;
- sfinfo.samplerate = SAMPLE_RATE ;
- sfinfo.frames = ARRAY_LEN (int_data) ;
- sfinfo.channels = 1 ;
- sfinfo.format = SF_ENDIAN_BIG | SF_FORMAT_AU | SF_FORMAT_FLOAT ;
- file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
- test_write_float_or_die (file, 0, float_data, ARRAY_LEN (float_data), __LINE__) ;
- sf_close (file) ;
- file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
- if (sfinfo.frames != ARRAY_LEN (float_data))
- { 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) ;
- exit (1) ;
- } ;
- if (sfinfo.channels != 1)
- { printf ("\n\nLine %d: Incorrect number of channels in file.\n", __LINE__) ;
- exit (1) ;
- } ;
- sf_command (file, SFC_SET_SCALE_FLOAT_INT_READ, NULL, SF_TRUE) ;
- test_read_int_or_die (file, 0, int_data, ARRAY_LEN (int_data), __LINE__) ;
- sf_close (file) ;
- max = 0 ;
- for (k = 0 ; k < ARRAY_LEN (int_data) ; k++)
- if ((unsigned) abs (int_data [k]) > max)
- max = abs (int_data [k]) ;
- if (1.0 * abs (max - 0x7FFFFFFF) / 0x7FFFFFFF > 0.01)
- { printf ("\n\nLine %d: Bad maximum (%d should be %d).\n\n", __LINE__, max, 0x7FFFFFFF) ;
- exit (1) ;
- } ;
- unlink (filename) ;
- puts ("ok") ;
- } /* float_int_big_test */
- static void
- double_short_little_test (const char * filename)
- { SNDFILE *file ;
- SF_INFO sfinfo ;
- unsigned k, max ;
- print_test_name ("double_short_little_test", filename) ;
- gen_windowed_sine_double (double_data, ARRAY_LEN (double_data), 0.98) ;
- sfinfo.samplerate = SAMPLE_RATE ;
- sfinfo.frames = ARRAY_LEN (short_data) ;
- sfinfo.channels = 1 ;
- sfinfo.format = SF_ENDIAN_LITTLE | SF_FORMAT_AU | SF_FORMAT_DOUBLE ;
- file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
- test_write_double_or_die (file, 0, double_data, ARRAY_LEN (double_data), __LINE__) ;
- sf_close (file) ;
- file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
- if (sfinfo.frames != ARRAY_LEN (double_data))
- { 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) ;
- exit (1) ;
- } ;
- if (sfinfo.channels != 1)
- { printf ("\n\nLine %d: Incorrect number of channels in file.\n", __LINE__) ;
- exit (1) ;
- } ;
- sf_command (file, SFC_SET_SCALE_FLOAT_INT_READ, NULL, SF_TRUE) ;
- test_read_short_or_die (file, 0, short_data, ARRAY_LEN (short_data), __LINE__) ;
- sf_close (file) ;
- max = 0 ;
- for (k = 0 ; k < ARRAY_LEN (short_data) ; k++)
- if ((unsigned) abs (short_data [k]) > max)
- max = abs (short_data [k]) ;
- if (1.0 * abs (max - 0x7FFF) / 0x7FFF > 0.01)
- { printf ("\n\nLine %d: Bad maximum (%d should be %d).\n\n", __LINE__, max, 0x7FFF) ;
- exit (1) ;
- } ;
- unlink (filename) ;
- puts ("ok") ;
- } /* double_short_little_test */
- static void
- double_short_big_test (const char * filename)
- { SNDFILE *file ;
- SF_INFO sfinfo ;
- unsigned k, max ;
- print_test_name ("double_short_big_test", filename) ;
- gen_windowed_sine_double (double_data, ARRAY_LEN (double_data), 0.98) ;
- sfinfo.samplerate = SAMPLE_RATE ;
- sfinfo.frames = ARRAY_LEN (short_data) ;
- sfinfo.channels = 1 ;
- sfinfo.format = SF_ENDIAN_BIG | SF_FORMAT_AU | SF_FORMAT_DOUBLE ;
- file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
- test_write_double_or_die (file, 0, double_data, ARRAY_LEN (double_data), __LINE__) ;
- sf_close (file) ;
- file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
- if (sfinfo.frames != ARRAY_LEN (double_data))
- { 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) ;
- exit (1) ;
- } ;
- if (sfinfo.channels != 1)
- { printf ("\n\nLine %d: Incorrect number of channels in file.\n", __LINE__) ;
- exit (1) ;
- } ;
- sf_command (file, SFC_SET_SCALE_FLOAT_INT_READ, NULL, SF_TRUE) ;
- test_read_short_or_die (file, 0, short_data, ARRAY_LEN (short_data), __LINE__) ;
- sf_close (file) ;
- max = 0 ;
- for (k = 0 ; k < ARRAY_LEN (short_data) ; k++)
- if ((unsigned) abs (short_data [k]) > max)
- max = abs (short_data [k]) ;
- if (1.0 * abs (max - 0x7FFF) / 0x7FFF > 0.01)
- { printf ("\n\nLine %d: Bad maximum (%d should be %d).\n\n", __LINE__, max, 0x7FFF) ;
- exit (1) ;
- } ;
- unlink (filename) ;
- puts ("ok") ;
- } /* double_short_big_test */
- static void
- double_int_little_test (const char * filename)
- { SNDFILE *file ;
- SF_INFO sfinfo ;
- unsigned k, max ;
- print_test_name ("double_int_little_test", filename) ;
- gen_windowed_sine_double (double_data, ARRAY_LEN (double_data), 0.98) ;
- sfinfo.samplerate = SAMPLE_RATE ;
- sfinfo.frames = ARRAY_LEN (int_data) ;
- sfinfo.channels = 1 ;
- sfinfo.format = SF_ENDIAN_LITTLE | SF_FORMAT_AU | SF_FORMAT_DOUBLE ;
- file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
- test_write_double_or_die (file, 0, double_data, ARRAY_LEN (double_data), __LINE__) ;
- sf_close (file) ;
- file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
- if (sfinfo.frames != ARRAY_LEN (double_data))
- { 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) ;
- exit (1) ;
- } ;
- if (sfinfo.channels != 1)
- { printf ("\n\nLine %d: Incorrect number of channels in file.\n", __LINE__) ;
- exit (1) ;
- } ;
- sf_command (file, SFC_SET_SCALE_FLOAT_INT_READ, NULL, SF_TRUE) ;
- test_read_int_or_die (file, 0, int_data, ARRAY_LEN (int_data), __LINE__) ;
- sf_close (file) ;
- max = 0 ;
- for (k = 0 ; k < ARRAY_LEN (int_data) ; k++)
- if ((unsigned) abs (int_data [k]) > max)
- max = abs (int_data [k]) ;
- if (1.0 * abs (max - 0x7FFFFFFF) / 0x7FFFFFFF > 0.01)
- { printf ("\n\nLine %d: Bad maximum (%d should be %d).\n\n", __LINE__, max, 0x7FFFFFFF) ;
- exit (1) ;
- } ;
- unlink (filename) ;
- puts ("ok") ;
- } /* double_int_little_test */
- static void
- double_int_big_test (const char * filename)
- { SNDFILE *file ;
- SF_INFO sfinfo ;
- unsigned k, max ;
- print_test_name ("double_int_big_test", filename) ;
- gen_windowed_sine_double (double_data, ARRAY_LEN (double_data), 0.98) ;
- sfinfo.samplerate = SAMPLE_RATE ;
- sfinfo.frames = ARRAY_LEN (int_data) ;
- sfinfo.channels = 1 ;
- sfinfo.format = SF_ENDIAN_BIG | SF_FORMAT_AU | SF_FORMAT_DOUBLE ;
- file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
- test_write_double_or_die (file, 0, double_data, ARRAY_LEN (double_data), __LINE__) ;
- sf_close (file) ;
- file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
- if (sfinfo.frames != ARRAY_LEN (double_data))
- { 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) ;
- exit (1) ;
- } ;
- if (sfinfo.channels != 1)
- { printf ("\n\nLine %d: Incorrect number of channels in file.\n", __LINE__) ;
- exit (1) ;
- } ;
- sf_command (file, SFC_SET_SCALE_FLOAT_INT_READ, NULL, SF_TRUE) ;
- test_read_int_or_die (file, 0, int_data, ARRAY_LEN (int_data), __LINE__) ;
- sf_close (file) ;
- max = 0 ;
- for (k = 0 ; k < ARRAY_LEN (int_data) ; k++)
- if ((unsigned) abs (int_data [k]) > max)
- max = abs (int_data [k]) ;
- if (1.0 * abs (max - 0x7FFFFFFF) / 0x7FFFFFFF > 0.01)
- { printf ("\n\nLine %d: Bad maximum (%d should be %d).\n\n", __LINE__, max, 0x7FFFFFFF) ;
- exit (1) ;
- } ;
- unlink (filename) ;
- puts ("ok") ;
- } /* double_int_big_test */
|