2007-05-14 09:55:24 +00:00
[+ AutoGen5 template c +]
/*
2017-05-03 19:59:31 +00:00
** Copyright (C) 1999-2017 Erik de Castro Lopo <erikd@mega-nerd.com>
2007-05-14 09:55:24 +00:00
**
** 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.
*/
2005-09-03 06:12:30 +00:00
#include "sfconfig.h"
2007-05-14 09:55:24 +00:00
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
2012-02-18 01:59:32 +00:00
#include <inttypes.h>
2007-05-14 09:55:24 +00:00
2005-09-03 03:50:47 +00:00
#if HAVE_UNISTD_H
2007-05-14 09:55:24 +00:00
#include <unistd.h>
2017-04-12 07:11:06 +00:00
#else
#include "sf_unistd.h"
2007-05-14 09:55:24 +00:00
#endif
#include <sndfile.h>
#include "dft_cmp.h"
#include "utils.h"
2005-01-29 05:33:57 +00:00
#define SAMPLE_RATE 16000
2007-05-14 09:55:24 +00:00
2021-02-21 10:11:34 +00:00
static const char FPT_TEST_PREFIX[] = "fpt" ;
2007-05-14 09:55:24 +00:00
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) ;
2007-08-19 06:47:18 +00:00
[+ FOR float_type +][+ FOR int_type +][+ FOR endian_type
2021-02-14 04:45:07 +00:00
+]static void [+ (get "float_name") +]_[+ (get "int_name") +]_[+ (get "end_name") +]_test (const char * filename, int replace_float) ;
2007-08-19 06:47:18 +00:00
[+ ENDFOR endian_type +][+ ENDFOR int_type +][+ ENDFOR float_type
2007-05-14 09:55:24 +00:00
+]
static double double_data [DFT_DATA_LENGTH] ;
2007-08-19 06:46:15 +00:00
static double double_test [DFT_DATA_LENGTH] ;
2007-05-14 09:55:24 +00:00
static float float_data [DFT_DATA_LENGTH] ;
2007-08-19 06:46:15 +00:00
static float float_test [DFT_DATA_LENGTH] ;
2007-05-14 09:55:24 +00:00
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 ;
2013-07-30 11:18:52 +00:00
#if (HAVE_LRINTF == 0)
2007-05-14 09:55:24 +00:00
puts ("*** Cannot run this test on this platform because it lacks lrintf().") ;
exit (0) ;
#endif
/* Float tests. */
2014-07-04 10:36:28 +00:00
float_scaled_test ("float.raw", allow_exit, SF_FALSE, SF_ENDIAN_LITTLE | SF_FORMAT_RAW | SF_FORMAT_FLOAT,
OS_IS_OPENBSD ? -98.0 : -163.0) ;
2007-05-14 09:55:24 +00:00
/* 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) ;
2014-12-15 10:20:29 +00:00
float_scaled_test ("g721_32.au", allow_exit, SF_FALSE, SF_FORMAT_AU | SF_FORMAT_G721_32, -32.3) ;
float_scaled_test ("g723_24.au", allow_exit, SF_FALSE, SF_FORMAT_AU | SF_FORMAT_G723_24, -32.3) ;
2007-05-14 09:55:24 +00:00
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) ;
2015-09-20 00:30:08 +00:00
float_scaled_test ("pcm_s8.sds", allow_exit, SF_FALSE, SF_FORMAT_SDS | SF_FORMAT_PCM_S8, -89.0) ;
float_scaled_test ("pcm_16.sds", allow_exit, SF_FALSE, SF_FORMAT_SDS | SF_FORMAT_PCM_16, -132.0) ;
2007-05-14 09:55:24 +00:00
float_scaled_test ("pcm_24.sds", allow_exit, SF_FALSE, SF_FORMAT_SDS | SF_FORMAT_PCM_24, -170.0) ;
2012-03-06 08:15:45 +00:00
float_scaled_test ("alac_16.caf", allow_exit, SF_FALSE, SF_FORMAT_CAF | SF_FORMAT_ALAC_16, -90.0) ;
2014-04-05 02:21:31 +00:00
float_scaled_test ("alac_32.caf", allow_exit, SF_FALSE, SF_FORMAT_CAF | SF_FORMAT_ALAC_32, -76.0) ;
2015-09-20 00:30:08 +00:00
float_scaled_test ("alac_24.caf", allow_exit, SF_FALSE, SF_FORMAT_CAF | SF_FORMAT_ALAC_24, -153.0) ;
float_scaled_test ("alac_20.caf", allow_exit, SF_FALSE, SF_FORMAT_CAF | SF_FORMAT_ALAC_20, -125.0) ;
2012-03-06 08:15:45 +00:00
2016-03-13 20:18:05 +00:00
#if HAVE_EXTERNAL_XIPH_LIBS
2005-02-12 09:24:04 +00:00
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) ;
2005-01-29 05:33:57 +00:00
2007-08-11 22:45:23 +00:00
float_scaled_test ("vorbis.oga", allow_exit, SF_FALSE, SF_FORMAT_OGG | SF_FORMAT_VORBIS, -31.0) ;
Opus file support
Ogg: Introduce new functions ogg_sync_fseek(), ogg_ftell(), ogg_next_page(),
ogg_stream_next_page(), ogg_sync_last_page_before(), and
ogg_stream_unpack_page(). Use ogg_sync_* for ogg_read_first_page(). Bump libogg
version requirement from 1.1.3 to 1.3.0 as LibOgg 1.3.0 is required for
ogg_stream_pageout_fill() and ogg_stream_flush_fill().
Opus: Add opus support. Document added commands
SFC_(GET|SET)_ORIGINAL_SAMPLERATE. Added or extended tests ogg_opus_test,
compression_size_test, floating_point_test, lossy_comp_test, string_test,
external_libs_test. Change Opus to non-experimental.
2018-07-09 21:37:06 +00:00
float_scaled_test ("opus.opus", allow_exit, SF_FALSE, SF_FORMAT_OGG | SF_FORMAT_OPUS, -32.0) ;
2008-06-02 23:23:18 +00:00
#endif
2007-08-09 11:54:38 +00:00
2019-02-10 06:45:55 +00:00
#if HAVE_MPEG
2021-01-12 05:18:23 +00:00
float_scaled_test ("mpeg.mp3", allow_exit, SF_FALSE, SF_FORMAT_MPEG | SF_FORMAT_MPEG_LAYER_III, -52.0) ;
2019-02-10 06:45:55 +00:00
#endif
2007-05-14 09:55:24 +00:00
float_scaled_test ("replace_float.raw", allow_exit, SF_TRUE, SF_ENDIAN_LITTLE | SF_FORMAT_RAW | SF_FORMAT_FLOAT, -163.0) ;
/*==============================================================================
** Double tests.
*/
2014-07-04 10:36:28 +00:00
double_scaled_test ("double.raw", allow_exit, SF_FALSE, SF_FORMAT_RAW | SF_FORMAT_DOUBLE, -201.0) ;
2007-05-14 09:55:24 +00:00
/* 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) ;
2014-12-15 10:20:29 +00:00
double_scaled_test ("g721_32.au", allow_exit, SF_FALSE, SF_FORMAT_AU | SF_FORMAT_G721_32, -32.3) ;
double_scaled_test ("g723_24.au", allow_exit, SF_FALSE, SF_FORMAT_AU | SF_FORMAT_G723_24, -32.3) ;
2007-05-14 09:55:24 +00:00
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) ;
2014-12-15 10:20:29 +00:00
double_scaled_test ("dpcm_8.xi" , allow_exit, SF_FALSE, SF_FORMAT_XI | SF_FORMAT_DPCM_8 , -41.0) ;
2007-05-14 09:55:24 +00:00
2015-09-20 00:30:08 +00:00
double_scaled_test ("pcm_s8.sds", allow_exit, SF_FALSE, SF_FORMAT_SDS | SF_FORMAT_PCM_S8, -89.0) ;
double_scaled_test ("pcm_16.sds", allow_exit, SF_FALSE, SF_FORMAT_SDS | SF_FORMAT_PCM_16, -132.0) ;
2007-05-14 09:55:24 +00:00
double_scaled_test ("pcm_24.sds", allow_exit, SF_FALSE, SF_FORMAT_SDS | SF_FORMAT_PCM_24, -180.0) ;
2012-03-06 08:15:45 +00:00
double_scaled_test ("alac_16.caf", allow_exit, SF_FALSE, SF_FORMAT_CAF | SF_FORMAT_ALAC_16, -90.0) ;
2015-09-20 00:30:08 +00:00
double_scaled_test ("alac_20.caf", allow_exit, SF_FALSE, SF_FORMAT_CAF | SF_FORMAT_ALAC_20, -125.0) ;
double_scaled_test ("alac_24.caf", allow_exit, SF_FALSE, SF_FORMAT_CAF | SF_FORMAT_ALAC_24, -153.0) ;
2012-03-06 09:20:28 +00:00
double_scaled_test ("alac_32.caf", allow_exit, SF_FALSE, SF_FORMAT_CAF | SF_FORMAT_ALAC_32, -186.0) ;
2012-03-06 08:15:45 +00:00
2016-03-13 20:18:05 +00:00
#if HAVE_EXTERNAL_XIPH_LIBS
2005-02-12 09:24:04 +00:00
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) ;
2005-01-29 05:33:57 +00:00
2007-08-11 22:45:23 +00:00
double_scaled_test ("vorbis.oga", allow_exit, SF_FALSE, SF_FORMAT_OGG | SF_FORMAT_VORBIS, -29.0) ;
Opus file support
Ogg: Introduce new functions ogg_sync_fseek(), ogg_ftell(), ogg_next_page(),
ogg_stream_next_page(), ogg_sync_last_page_before(), and
ogg_stream_unpack_page(). Use ogg_sync_* for ogg_read_first_page(). Bump libogg
version requirement from 1.1.3 to 1.3.0 as LibOgg 1.3.0 is required for
ogg_stream_pageout_fill() and ogg_stream_flush_fill().
Opus: Add opus support. Document added commands
SFC_(GET|SET)_ORIGINAL_SAMPLERATE. Added or extended tests ogg_opus_test,
compression_size_test, floating_point_test, lossy_comp_test, string_test,
external_libs_test. Change Opus to non-experimental.
2018-07-09 21:37:06 +00:00
double_scaled_test ("opus.opus", allow_exit, SF_FALSE, SF_FORMAT_OGG | SF_FORMAT_OPUS, -32.0) ;
2008-06-02 23:23:18 +00:00
#endif
2007-08-09 11:54:38 +00:00
2019-02-10 06:45:55 +00:00
#if HAVE_MPEG
2021-01-12 05:18:23 +00:00
double_scaled_test ("mpeg.mp3", allow_exit, SF_FALSE, SF_FORMAT_MPEG | SF_FORMAT_MPEG_LAYER_III, -52.0) ;
2019-02-10 06:45:55 +00:00
#endif
2014-07-04 10:36:28 +00:00
double_scaled_test ("replace_double.raw", allow_exit, SF_TRUE, SF_FORMAT_RAW | SF_FORMAT_DOUBLE, -201.0) ;
2007-05-14 09:55:24 +00:00
putchar ('\n') ;
/* Float int tests. */
2021-02-14 04:45:07 +00:00
[+ FOR float_type +][+ FOR int_type +][+ FOR endian_type +]
[+ (get "float_name") +]_[+ (get "int_name") +]_[+ (get "end_name") +]_test ("[+ (get "float_name") +]_[+ (get "int_name") +]_[+ (get "end_name") +].au", SF_FALSE) ;
[+ (get "float_name") +]_[+ (get "int_name") +]_[+ (get "end_name") +]_test ("[+ (get "float_name") +]_[+ (get "int_name") +]_[+ (get "end_name") +]_replace.au", SF_TRUE) ;
[+ ENDFOR endian_type +][+ ENDFOR int_type +][+ ENDFOR float_type +]
2004-10-07 10:59:59 +00:00
2007-05-14 09:55:24 +00:00
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)
2007-08-19 06:46:15 +00:00
{ SNDFILE * file ;
2007-05-14 09:55:24 +00:00
SF_INFO sfinfo ;
double snr ;
2012-02-25 12:01:21 +00:00
int byterate ;
2007-05-14 09:55:24 +00:00
2021-02-21 10:11:34 +00:00
get_unique_test_name (&filename, FPT_TEST_PREFIX) ;
2007-05-14 09:55:24 +00:00
print_test_name ("float_scaled_test", filename) ;
2014-12-15 10:20:29 +00:00
gen_windowed_sine_float (float_data, DFT_DATA_LENGTH, 0.9999) ;
2007-05-14 09:55:24 +00:00
2017-05-03 19:59:31 +00:00
memset (&sfinfo, 0, sizeof (sfinfo)) ;
2014-07-03 11:26:11 +00:00
sfinfo.samplerate = SAMPLE_RATE ;
2007-05-14 09:55:24 +00:00
sfinfo.frames = DFT_DATA_LENGTH ;
sfinfo.channels = 1 ;
sfinfo.format = filetype ;
2007-09-01 08:21:44 +00:00
file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
2007-05-14 09:55:24 +00:00
sf_command (file, SFC_TEST_IEEE_FLOAT_REPLACE, NULL, replace_float) ;
2007-08-19 06:46:15 +00:00
test_write_float_or_die (file, 0, float_data, DFT_DATA_LENGTH, __LINE__) ;
2007-05-14 09:55:24 +00:00
sf_close (file) ;
memset (float_test, 0, sizeof (float_test)) ;
2004-10-28 22:21:40 +00:00
file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
2007-05-14 09:55:24 +00:00
sf_command (file, SFC_TEST_IEEE_FLOAT_REPLACE, NULL, replace_float) ;
2006-04-29 00:01:28 +00:00
exit_if_true (sfinfo.format != filetype, "\n\nLine %d: Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__, filetype, sfinfo.format) ;
2012-02-18 01:59:32 +00:00
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) ;
2006-04-29 00:01:28 +00:00
exit_if_true (sfinfo.channels != 1, "\n\nLine %d: Incorrect number of channels in file.\n", __LINE__) ;
2007-05-14 09:55:24 +00:00
check_log_buffer_or_die (file, __LINE__) ;
test_read_float_or_die (file, 0, float_test, DFT_DATA_LENGTH, __LINE__) ;
2012-02-25 12:01:21 +00:00
byterate = sf_current_byterate (file) ;
exit_if_true (byterate <= 0, "\n\nLine %d: byterate is zero.\n", __LINE__) ;
2007-05-14 09:55:24 +00:00
sf_close (file) ;
2007-08-19 06:46:15 +00:00
snr = dft_cmp_float (__LINE__, float_data, float_test, DFT_DATA_LENGTH, target_snr, allow_exit) ;
2007-05-14 09:55:24 +00:00
2006-04-29 00:01:28 +00:00
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) ;
2007-05-14 09:55:24 +00:00
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 ;
2012-02-25 12:01:21 +00:00
int byterate ;
2007-05-14 09:55:24 +00:00
2021-02-21 10:11:34 +00:00
get_unique_test_name (&filename, FPT_TEST_PREFIX) ;
2007-05-14 09:55:24 +00:00
print_test_name ("double_scaled_test", filename) ;
2014-12-15 10:20:29 +00:00
gen_windowed_sine_double (double_data, DFT_DATA_LENGTH, 0.9999) ;
2007-05-14 09:55:24 +00:00
2017-05-03 19:59:31 +00:00
memset (&sfinfo, 0, sizeof (sfinfo)) ;
2014-07-03 11:26:11 +00:00
sfinfo.samplerate = SAMPLE_RATE ;
2007-05-14 09:55:24 +00:00
sfinfo.frames = DFT_DATA_LENGTH ;
sfinfo.channels = 1 ;
sfinfo.format = filetype ;
2007-09-01 08:21:44 +00:00
file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
2007-05-14 09:55:24 +00:00
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) ;
2007-08-19 06:46:15 +00:00
memset (double_test, 0, sizeof (double_test)) ;
2007-05-14 09:55:24 +00:00
2004-10-28 22:21:40 +00:00
file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
2007-05-14 09:55:24 +00:00
sf_command (file, SFC_TEST_IEEE_FLOAT_REPLACE, NULL, replace_float) ;
2006-04-29 00:01:28 +00:00
exit_if_true (sfinfo.format != filetype, "\n\nLine %d: Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__, filetype, sfinfo.format) ;
2012-02-18 01:59:32 +00:00
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) ;
2006-04-29 00:01:28 +00:00
exit_if_true (sfinfo.channels != 1, "\n\nLine %d: Incorrect number of channels in file.\n", __LINE__) ;
2007-05-14 09:55:24 +00:00
check_log_buffer_or_die (file, __LINE__) ;
2007-08-19 06:46:15 +00:00
test_read_double_or_die (file, 0, double_test, DFT_DATA_LENGTH, __LINE__) ;
2007-05-14 09:55:24 +00:00
2012-02-25 12:01:21 +00:00
byterate = sf_current_byterate (file) ;
exit_if_true (byterate <= 0, "\n\nLine %d: byterate is zero.\n", __LINE__) ;
2007-05-14 09:55:24 +00:00
sf_close (file) ;
2007-08-19 06:46:15 +00:00
snr = dft_cmp_double (__LINE__, double_data, double_test, DFT_DATA_LENGTH, target_snr, allow_exit) ;
2007-05-14 09:55:24 +00:00
2006-04-29 00:01:28 +00:00
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) ;
2007-05-14 09:55:24 +00:00
unlink (filename) ;
return ;
} /* double_scaled_test */
/*==============================================================================
*/
2007-08-19 06:47:18 +00:00
[+ FOR float_type +][+ FOR int_type +][+ FOR endian_type
2007-05-14 09:55:24 +00:00
+]
static void
2021-02-14 04:45:07 +00:00
[+ (get "float_name") +]_[+ (get "int_name") +]_[+ (get "end_name") +]_test (const char * filename, int replace_float)
2007-05-14 09:55:24 +00:00
{ SNDFILE * file ;
SF_INFO sfinfo ;
2015-12-17 11:37:38 +00:00
int max ;
unsigned k ;
2007-05-14 09:55:24 +00:00
2021-02-21 10:11:34 +00:00
get_unique_test_name (&filename, FPT_TEST_PREFIX) ;
2004-10-07 10:59:59 +00:00
print_test_name ("[+ (get "float_name") +]_[+ (get "int_name") +]_[+ (get "end_name") +]_test", filename) ;
2007-05-14 09:55:24 +00:00
2014-12-15 10:20:29 +00:00
gen_windowed_sine_[+ (get "float_name") +] ([+ (get "float_name") +]_data, ARRAY_LEN ([+ (get "float_name") +]_data), 0.9999) ;
2007-05-14 09:55:24 +00:00
2017-05-03 19:59:31 +00:00
memset (&sfinfo, 0, sizeof (sfinfo)) ;
2007-05-14 09:55:24 +00:00
sfinfo.samplerate = SAMPLE_RATE ;
sfinfo.frames = ARRAY_LEN ([+ (get "int_name") +]_data) ;
sfinfo.channels = 1 ;
2004-10-07 10:59:59 +00:00
sfinfo.format = [+ (get "end_type") +] | SF_FORMAT_AU | [+ (get "minor_type") +] ;
2007-05-14 09:55:24 +00:00
2004-10-28 22:21:40 +00:00
file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
2021-02-14 04:45:07 +00:00
sf_command (file, SFC_TEST_IEEE_FLOAT_REPLACE, NULL, replace_float) ;
2004-10-05 12:39:20 +00:00
test_write_[+ (get "float_name") +]_or_die (file, 0, [+ (get "float_name") +]_data, ARRAY_LEN ([+ (get "float_name") +]_data), __LINE__) ;
2007-05-14 09:55:24 +00:00
sf_close (file) ;
2004-10-28 22:21:40 +00:00
file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
2021-02-14 04:45:07 +00:00
sf_command (file, SFC_TEST_IEEE_FLOAT_REPLACE, NULL, replace_float) ;
2007-05-14 09:55:24 +00:00
if (sfinfo.frames != ARRAY_LEN ([+ (get "float_name") +]_data))
2012-02-18 01:59:32 +00:00
{ printf ( "\n\nLine %d: Incorrect number of frames in file (too short). (%" PRId64 " should be %d)\n" , __LINE__ , sfinfo . frames , DFT_DATA_LENGTH ) ;
2007-05-14 09:55:24 +00:00
exit (1) ;
} ;
if (sfinfo.channels != 1)
2004-10-17 01:12:35 +00:00
{ printf ( "\n\nLine %d: Incorrect number of channels in file.\n" , __LINE__ ) ;
2007-05-14 09:55:24 +00:00
exit (1) ;
} ;
2004-09-30 15:58:58 +00:00
sf_command (file, SFC_SET_SCALE_FLOAT_INT_READ, NULL, SF_TRUE) ;
2007-05-14 09:55:24 +00:00
2004-10-05 12:39:20 +00:00
test_read_[+ (get "int_name") +]_or_die (file, 0, [+ (get "int_name") +]_data, ARRAY_LEN ([+ (get "int_name") +]_data), __LINE__) ;
2007-05-14 09:55:24 +00:00
sf_close (file) ;
max = 0 ;
for (k = 0 ; k < ARRAY_LEN ([+ (get "int_name") +]_data) ; k++)
2015-11-22 09:22:13 +00:00
if (abs ([+ (get "int_name") +]_data [k]) > max)
2007-05-14 09:55:24 +00:00
max = abs ([+ (get "int_name") +]_data [k]) ;
if (1.0 * abs (max - [+ (get "int_max") +]) / [+ (get "int_max") +] > 0.01)
2004-10-17 01:12:35 +00:00
{ printf ( "\n\nLine %d: Bad maximum (%d should be %d).\n\n" , __LINE__ , max , [ + ( get "int_max" ) + ] ) ;
2007-05-14 09:55:24 +00:00
exit (1) ;
} ;
2004-09-30 20:19:26 +00:00
unlink (filename) ;
2007-05-14 09:55:24 +00:00
puts ("ok") ;
2004-10-07 10:59:59 +00:00
} /* [+ (get "float_name") +]_[+ (get "int_name") +]_[+ (get "end_name") +]_test */
[+ ENDFOR endian_type +][+ ENDFOR int_type +][+ ENDFOR float_type +]
2007-05-14 09:55:24 +00:00