Merge from -mdev.

This commit is contained in:
Erik de Castro Lopo 2007-11-17 21:09:28 +11:00
commit f1b4ef2174
13 changed files with 459 additions and 251 deletions

View File

@ -1,3 +1,49 @@
2007-11-17 Erik de Castro Lopo <erikd AT mega-nerd DOT com>
* src/sndfile.c
Fix calculation of internal value psf->read_current when attempting to read
past end of audio data.
Remove redundant code.
* tests/lossy_comp_test.c
Add read_raw_test to check that raw reads do not go past the end of the
audio data section.
Clean up error output messages.
* src/sndfile.c
Add code to prevent sf_read_raw from reading past the end of the audio data.
* tests/Makefile.am
Add the wav_pcm lossy_comp_test.
2007-11-16 Erik de Castro Lopo <erikd AT mega-nerd DOT com>
* configure.ac src/Makefile.am src/create_symbols_file.py
More OS/2 fixes from David Yeo.
2007-11-12 Erik de Castro Lopo <erikd AT mega-nerd DOT com>
* src/file_io.c tests/utils.tpl tests/benchmark.tpl
Improve handling of requirements for O_BINARY as suggested by Ed Schouten.
2007-11-11 Erik de Castro Lopo <erikd AT mega-nerd DOT com>
* src/common.h
Fix symbol class when SF_MIN is nested inside SF_MAX or vice versa.
* src/create_symbols_file.py
Add support for OS/2 contributed by David Yeo.
2007-11-05 Erik de Castro Lopo <erikd AT mega-nerd DOT com>
* M4/gcc_version.m4
Add macro AC_GCC_VERSION to detect GCC_MAJOR_VERSION and GCC_MINOR_VERSION.
* configure.ac
Use AC_GCC_VERSION to work around gcc-4.2 inline warning stupidity.
See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33995
Use -fgnu-inline to prevent stupid warnings.
2007-11-03 Erik de Castro Lopo <erikd AT mega-nerd DOT com>
* tests/util.tpl

33
M4/gcc_version.m4 Normal file
View File

@ -0,0 +1,33 @@
dnl @synopsis AC_GCC_VERSION
dnl
dnl Find the version of gcc.
dnl @version 1.0 Nov 05 2007
dnl @author Erik de Castro Lopo <erikd AT mega-nerd DOT com>
dnl
dnl Permission to use, copy, modify, distribute, and sell this file for any
dnl purpose is hereby granted without fee, provided that the above copyright
dnl and this permission notice appear in all copies. No representations are
dnl made about the suitability of this software for any purpose. It is
dnl provided "as is" without express or implied warranty.
dnl
AC_DEFUN([AC_GCC_VERSION],
[
if test "x$ac_cv_c_compiler_gnu" = "xyes" ; then
AC_MSG_CHECKING([for version of $CC])
GCC_VERSION=`$CC -dumpversion`
AC_MSG_RESULT($GCC_VERSION)
changequote(,)dnl
GCC_MINOR_VERSION=`echo $GCC_VERSION | sed "s/^[0-9]\+\.//" | sed "s/\..*//"`
GCC_MAJOR_VERSION=`echo $GCC_VERSION | sed "s/\..*//"`
changequote([,])dnl
fi
AC_SUBST(GCC_VERSION)
AC_SUBST(GCC_MAJOR_VERSION)
AC_SUBST(GCC_MINOR_VERSION)
])# AC_GCC_VERSION

View File

@ -38,6 +38,7 @@ AC_LANG([C])
SHARED_VERSION_INFO="1:18:0"
AC_PROG_CC
AC_PROG_CXX
AM_PROG_LIBTOOL
AC_CHECK_PROG(HAVE_AUTOGEN, autogen, yes, no)
@ -508,6 +509,18 @@ win32_target_dll=0
if test x$ac_cv_c_compiler_gnu = xyes ; then
AC_ADD_CFLAGS(-std=gnu99)
AC_GCC_VERSION
if test "x$GCC_MAJOR_VERSION$GCC_MINOR_VERSION" = "x42" ; then
AC_MSG_WARN([****************************************************************])
AC_MSG_WARN([** GCC version 4.2 warns about the inline keyword for no good **])
AC_MSG_WARN([** reason but the maintainers do not see it as a bug. **])
AC_MSG_WARN([** See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33995 **])
AC_MSG_WARN([** Using -fgnu-inline to avoid this stupidity. **])
AC_MSG_WARN([****************************************************************])
AC_ADD_CFLAGS([-fgnu89-inline])
fi
CFLAGS="$CFLAGS -W -Wall"
CXXFLAGS="$CXXFLAGS -W -Wall"
@ -560,6 +573,9 @@ if test x$ac_cv_c_compiler_gnu = xyes ; then
win32_target_dll=0
fi
;;
os2*)
SHLIB_VERSION_ARG="-Wl,-export-symbols \$(srcdir)/Symbols.os2"
;;
*)
;;
esac
@ -568,8 +584,6 @@ if test x$ac_cv_c_compiler_gnu = xyes ; then
fi
AC_DEFINE([COMPILER_IS_GCC],1, [Set to 1 if the compile is GNU GCC.])
GCC_MAJOR_VERSION=`$CC -dumpversion | sed "s/\..*//"`
AC_DEFINE_UNQUOTED([GCC_MAJOR_VERSION],${GCC_MAJOR_VERSION}, [Major version of GCC or 3 otherwise.])
fi
AC_DEFINE_UNQUOTED(WIN32_TARGET_DLL, ${win32_target_dll}, [Set to 1 if windows DLL is being built.])
@ -652,7 +666,7 @@ AC_MSG_RESULT([
if test x$ac_cv_c_compiler_gnu = xyes ; then
echo -e " Tools :\n"
echo " Compiler is GCC : ............. ${ac_cv_c_compiler_gnu}"
echo " GCC major version : ........... ${GCC_MAJOR_VERSION}"
echo " GCC version : ................. ${GCC_VERSION}."
if test $GCC_MAJOR_VERSION -lt 3 ; then
echo -e "\n ** This compiler version allows applications to write"
echo " ** to static strings within the library."

View File

@ -99,8 +99,11 @@ libsndfile.def: create_symbols_file.py
cygsndfile.def: create_symbols_file.py
./create_symbols_file.py cygwin $(VERSION) > cygsndfile.def
Symbols.os2: create_symbols_file.py
./create_symbols_file.py os2 $(VERSION) > Symbols.os2
# Fake dependancy to force the creation of these files.
sndfile.o : Symbols.linux Symbols.darwin libsndfile.def cygsndfile.def
sndfile.o : Symbols.linux Symbols.darwin libsndfile.def cygsndfile.def Symbols.os2
#======================================================================
# Disable autoheader.

View File

@ -89,16 +89,16 @@
#if (COMPILER_IS_GCC == 1)
#define SF_MAX(x,y) ({ \
typeof (x) _xmax = (x) ; \
typeof (y) _ymax = (y) ; \
(void) (&_xmax == &_ymax) ; \
_xmax > _ymax ? _xmax : _ymax ; })
typeof (x) _x1 = (x) ; \
typeof (y) _y1 = (y) ; \
(void) (&_x1 == &_y1) ; \
_x1 > _y1 ? _x1 : _y1 ; })
#define SF_MIN(x,y) ({ \
typeof (x) _xmin = (x) ; \
typeof (y) _ymin = (y) ; \
(void) (&_xmin == &_ymin) ; \
_xmin < _ymin ? _xmin : _ymin ; })
typeof (x) _x2 = (x) ; \
typeof (y) _y2 = (y) ; \
(void) (&_x2 == &_y2) ; \
_x2 < _y2 ? _x2 : _y2 ; })
#else
#define SF_MAX(a,b) ((a) > (b) ? (a) : (b))
#define SF_MIN(a,b) ((a) < (b) ? (a) : (b))

View File

@ -105,6 +105,18 @@ def win32_symbols (progname, version, name):
print
return
def os2_symbols (progname, version, name):
print "; Auto-generated by %s\n" %progname
print "LIBRARY %s%s.dll" % (name, re.sub ("\..*", "", version))
print "INITINSTANCE TERMINSTANCE"
print "CODE PRELOAD MOVEABLE DISCARDABLE"
print "DATA PRELOAD MOVEABLE MULTIPLE NONSHARED"
print "EXPORTS\n"
for name, ordinal in ALL_SYMBOLS:
print "_%-20s @%s" % (name, ordinal)
print
return
def no_symbols (os_name):
print
print "No known way of restricting exported symbols on '%s'." % os_name
@ -125,6 +137,7 @@ if len (sys.argv) != 3:
print " darwin (ie MacOSX)"
print " win32 (ie wintendo)"
print " cygwin (Cygwin on wintendo)"
print " os2 (OS/2)"
print
sys.exit (1)
@ -139,6 +152,8 @@ elif os_name == "win32":
win32_symbols (progname, version, "libsndfile")
elif os_name == "cygwin":
win32_symbols (progname, version, "cygsndfile")
elif os_name == "os2":
os2_symbols (progname, version, "sndfile")
else:
no_symbols (os_name)

View File

@ -55,6 +55,15 @@
#define SENSIBLE_SIZE (0x40000000)
/*
** Neat solution to the Win32/OS2 binary file flage requirement.
** If O_BINARY isn't already defined by the inclusion of the system
** headers, set it to zero.
*/
#ifndef O_BINARY
#define O_BINARY 0
#endif
static void psf_log_syserr (SF_PRIVATE *psf, int error) ;
#if (USE_WINDOWS_API == 0)
@ -526,17 +535,17 @@ psf_open_fd (const char * pathname, int open_mode)
switch (open_mode)
{ case SFM_READ :
oflag = O_RDONLY ;
oflag = O_RDONLY | O_BINARY ;
mode = 0 ;
break ;
case SFM_WRITE :
oflag = O_WRONLY | O_CREAT | O_TRUNC ;
oflag = O_WRONLY | O_CREAT | O_TRUNC | O_BINARY ;
mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH ;
break ;
case SFM_RDWR :
oflag = O_RDWR | O_CREAT ;
oflag = O_RDWR | O_CREAT | O_BINARY ;
mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH ;
break ;
@ -545,11 +554,6 @@ psf_open_fd (const char * pathname, int open_mode)
break ;
} ;
#if OS_IS_WIN32
/* For Cygwin. */
oflag |= O_BINARY ;
#endif
if (mode == 0)
fd = open (pathname, oflag) ;
else

View File

@ -1281,7 +1281,7 @@ sf_set_string (SNDFILE *sndfile, int str_type, const char* str)
sf_count_t
sf_read_raw (SNDFILE *sndfile, void *ptr, sf_count_t bytes)
{ SF_PRIVATE *psf ;
sf_count_t count ;
sf_count_t count, extra ;
int bytewidth, blockwidth ;
VALIDATE_SNDFILE_AND_ASSIGN_PSF (sndfile, psf, 1) ;
@ -1306,10 +1306,14 @@ sf_read_raw (SNDFILE *sndfile, void *ptr, sf_count_t bytes)
count = psf_fread (ptr, 1, bytes, psf) ;
if (count < bytes)
psf_memset (((char*) ptr) + count, 0, bytes - count) ;
psf->read_current += count / blockwidth ;
if (psf->read_current + count / blockwidth <= psf->sf.frames)
psf->read_current += count / blockwidth ;
else
{ count = (psf->sf.frames - psf->read_current) * blockwidth ;
extra = bytes - count ;
psf_memset (((char *) ptr) + count, 0, extra) ;
psf->read_current = psf->sf.frames ;
} ;
psf->last_op = SFM_READ ;
@ -1352,22 +1356,17 @@ sf_read_short (SNDFILE *sndfile, short *ptr, sf_count_t len)
count = psf->read_short (psf, ptr, len) ;
if (psf->read_current + count / psf->sf.channels > psf->sf.frames)
if (psf->read_current + count / psf->sf.channels <= psf->sf.frames)
psf->read_current += count / psf->sf.channels ;
else
{ count = (psf->sf.frames - psf->read_current) * psf->sf.channels ;
extra = len - count ;
psf_memset (ptr + count, 0, extra * sizeof (short)) ;
psf->read_current = psf->sf.frames ;
} ;
psf->read_current += count / psf->sf.channels ;
psf->last_op = SFM_READ ;
if (psf->read_current > psf->sf.frames)
{ count = psf->sf.channels * (psf->read_current - psf->sf.frames) ;
psf->read_current = psf->sf.frames ;
} ;
return count ;
} /* sf_read_short */
@ -1399,22 +1398,17 @@ sf_readf_short (SNDFILE *sndfile, short *ptr, sf_count_t frames)
count = psf->read_short (psf, ptr, frames * psf->sf.channels) ;
if (psf->read_current + count / psf->sf.channels > psf->sf.frames)
if (psf->read_current + count / psf->sf.channels <= psf->sf.frames)
psf->read_current += count / psf->sf.channels ;
else
{ count = (psf->sf.frames - psf->read_current) * psf->sf.channels ;
extra = frames * psf->sf.channels - count ;
psf_memset (ptr + count, 0, extra * sizeof (short)) ;
psf->read_current = psf->sf.frames ;
} ;
psf->read_current += count / psf->sf.channels ;
psf->last_op = SFM_READ ;
if (psf->read_current > psf->sf.frames)
{ count = psf->sf.channels * (psf->read_current - psf->sf.frames) ;
psf->read_current = psf->sf.frames ;
} ;
return count / psf->sf.channels ;
} /* sf_readf_short */
@ -1454,22 +1448,17 @@ sf_read_int (SNDFILE *sndfile, int *ptr, sf_count_t len)
count = psf->read_int (psf, ptr, len) ;
if (psf->read_current + count / psf->sf.channels > psf->sf.frames)
if (psf->read_current + count / psf->sf.channels <= psf->sf.frames)
psf->read_current += count / psf->sf.channels ;
else
{ count = (psf->sf.frames - psf->read_current) * psf->sf.channels ;
extra = len - count ;
psf_memset (ptr + count, 0, extra * sizeof (int)) ;
psf->read_current = psf->sf.frames ;
} ;
psf->read_current += count / psf->sf.channels ;
psf->last_op = SFM_READ ;
if (psf->read_current > psf->sf.frames)
{ count = psf->sf.channels * (psf->read_current - psf->sf.frames) ;
psf->read_current = psf->sf.frames ;
} ;
return count ;
} /* sf_read_int */
@ -1501,22 +1490,17 @@ sf_readf_int (SNDFILE *sndfile, int *ptr, sf_count_t frames)
count = psf->read_int (psf, ptr, frames * psf->sf.channels) ;
if (psf->read_current + count / psf->sf.channels > psf->sf.frames)
if (psf->read_current + count / psf->sf.channels <= psf->sf.frames)
psf->read_current += count / psf->sf.channels ;
else
{ count = (psf->sf.frames - psf->read_current) * psf->sf.channels ;
extra = frames * psf->sf.channels - count ;
psf_memset (ptr + count, 0, extra * sizeof (int)) ;
psf->read_current = psf->sf.frames ;
} ;
psf->read_current += count / psf->sf.channels ;
psf->last_op = SFM_READ ;
if (psf->read_current > psf->sf.frames)
{ count = psf->sf.channels * (psf->read_current - psf->sf.frames) ;
psf->read_current = psf->sf.frames ;
} ;
return count / psf->sf.channels ;
} /* sf_readf_int */
@ -1556,22 +1540,17 @@ sf_read_float (SNDFILE *sndfile, float *ptr, sf_count_t len)
count = psf->read_float (psf, ptr, len) ;
if (psf->read_current + count / psf->sf.channels > psf->sf.frames)
if (psf->read_current + count / psf->sf.channels <= psf->sf.frames)
psf->read_current += count / psf->sf.channels ;
else
{ count = (psf->sf.frames - psf->read_current) * psf->sf.channels ;
extra = len - count ;
psf_memset (ptr + count, 0, extra * sizeof (float)) ;
psf->read_current = psf->sf.frames ;
} ;
psf->read_current += count / psf->sf.channels ;
psf->last_op = SFM_READ ;
if (psf->read_current > psf->sf.frames)
{ count = psf->sf.channels * (psf->read_current - psf->sf.frames) ;
psf->read_current = psf->sf.frames ;
} ;
return count ;
} /* sf_read_float */
@ -1603,22 +1582,17 @@ sf_readf_float (SNDFILE *sndfile, float *ptr, sf_count_t frames)
count = psf->read_float (psf, ptr, frames * psf->sf.channels) ;
if (psf->read_current + count / psf->sf.channels > psf->sf.frames)
if (psf->read_current + count / psf->sf.channels <= psf->sf.frames)
psf->read_current += count / psf->sf.channels ;
else
{ count = (psf->sf.frames - psf->read_current) * psf->sf.channels ;
extra = frames * psf->sf.channels - count ;
psf_memset (ptr + count, 0, extra * sizeof (float)) ;
psf->read_current = psf->sf.frames ;
} ;
psf->read_current += count / psf->sf.channels ;
psf->last_op = SFM_READ ;
if (psf->read_current > psf->sf.frames)
{ count = psf->sf.channels * (psf->read_current - psf->sf.frames) ;
psf->read_current = psf->sf.frames ;
} ;
return count / psf->sf.channels ;
} /* sf_readf_float */
@ -1658,22 +1632,17 @@ sf_read_double (SNDFILE *sndfile, double *ptr, sf_count_t len)
count = psf->read_double (psf, ptr, len) ;
if (psf->read_current + count / psf->sf.channels > psf->sf.frames)
if (psf->read_current + count / psf->sf.channels <= psf->sf.frames)
psf->read_current += count / psf->sf.channels ;
else
{ count = (psf->sf.frames - psf->read_current) * psf->sf.channels ;
extra = len - count ;
psf_memset (ptr + count, 0, extra * sizeof (double)) ;
psf->read_current = psf->sf.frames ;
} ;
psf->read_current += count / psf->sf.channels ;
psf->last_op = SFM_READ ;
if (psf->read_current > psf->sf.frames)
{ count = psf->sf.channels * (psf->read_current - psf->sf.frames) ;
psf->read_current = psf->sf.frames ;
} ;
return count ;
} /* sf_read_double */
@ -1705,22 +1674,17 @@ sf_readf_double (SNDFILE *sndfile, double *ptr, sf_count_t frames)
count = psf->read_double (psf, ptr, frames * psf->sf.channels) ;
if (psf->read_current + count / psf->sf.channels > psf->sf.frames)
if (psf->read_current + count / psf->sf.channels <= psf->sf.frames)
psf->read_current += count / psf->sf.channels ;
else
{ count = (psf->sf.frames - psf->read_current) * psf->sf.channels ;
extra = frames * psf->sf.channels - count ;
psf_memset (ptr + count, 0, extra * sizeof (double)) ;
psf->read_current = psf->sf.frames ;
} ;
psf->read_current += count / psf->sf.channels ;
psf->last_op = SFM_READ ;
if (psf->read_current > psf->sf.frames)
{ count = psf->sf.channels * (psf->read_current - psf->sf.frames) ;
psf->read_current = psf->sf.frames ;
} ;
return count / psf->sf.channels ;
} /* sf_readf_double */

View File

@ -205,6 +205,7 @@ endif
wav-tests: write_read_test lossy_comp_test peak_chunk_test header_test misc_test multi_file_test
./write_read_test wav
./lossy_comp_test wav_pcm
./lossy_comp_test wav_ima
./lossy_comp_test wav_msadpcm
./lossy_comp_test wav_ulaw

View File

@ -42,13 +42,21 @@
#define M_PI 3.14159265358979323846264338
#endif
#if (defined (WIN32) || defined (_WIN32))
#define WRITE_FLAGS (O_WRONLY | O_CREAT | O_TRUNC | O_BINARY)
#define READ_FLAGS (O_RDONLY | O_BINARY)
/*
** Neat solution to the Win32/OS2 binary file flage requirement.
** If O_BINARY isn't already defined by the inclusion of the system
** headers, set it to zero.
*/
#ifndef O_BINARY
#define O_BINARY 0
#endif
#define WRITE_FLAGS (O_WRONLY | O_CREAT | O_TRUNC | O_BINARY)
#define READ_FLAGS (O_RDONLY | O_BINARY)
#if (defined (WIN32) || defined (_WIN32) || defined (__OS2__))
#define WRITE_PERMS 0777
#else
#define WRITE_FLAGS (O_WRONLY | O_CREAT | O_TRUNC)
#define READ_FLAGS (O_RDONLY)
#define WRITE_PERMS (S_IRUSR | S_IWUSR | S_IRGRP)
#endif

View File

@ -80,12 +80,15 @@ main (int argc, char *argv [])
if (do_all || strcmp (argv [1], "ver") == 0)
{ char buffer [128] ;
print_test_name ("version_test", "(none)") ;
buffer [0] = 0 ;
sf_command (NULL, SFC_GET_LIB_VERSION, buffer, sizeof (buffer)) ;
if (strlen (buffer) < 1)
{ printf ("Line %d: could not retrieve lib version.\n", __LINE__) ;
exit (1) ;
} ;
puts ("ok") ;
test_count++ ;
} ;

View File

@ -50,6 +50,8 @@ static void sdlcomp_test_int (const char *filename, int filetype, int chan, doub
static void sdlcomp_test_float (const char *filename, int filetype, int chan, double margin) ;
static void sdlcomp_test_double (const char *filename, int filetype, int chan, double margin) ;
static void read_raw_test (const char *filename, int filetype, int chan) ;
static int error_function (double data, double orig, double margin) ;
static int decay_response (int k) ;
@ -62,6 +64,8 @@ static void smoothed_diff_double (double *data, unsigned int datalen) ;
static void check_comment (SNDFILE * file, int format, int lineno) ;
static int is_lossy (int filetype) ;
/*
** Force the start of these buffers to be double aligned. Sparc-solaris will
** choke if they are not.
@ -105,16 +109,18 @@ main (int argc, char *argv [])
do_all = ! strcmp (argv [1], "all") ;
if (strcmp (argv [1], "wav_pcm") == 0)
if (do_all || strcmp (argv [1], "wav_pcm") == 0)
{ /* This is just a sanity test for PCM encoding. */
lcomp_test_short ("pcm.wav", SF_FORMAT_WAV | SF_FORMAT_PCM_16, 2, 0.00001) ;
lcomp_test_int ("pcm.wav", SF_FORMAT_WAV | SF_FORMAT_PCM_16, 2, 0.00001) ;
lcomp_test_short ("pcm.rifx", SF_ENDIAN_BIG | SF_FORMAT_WAV | SF_FORMAT_PCM_16, 2, 0.00001) ;
lcomp_test_int ("pcm.rifx", SF_ENDIAN_BIG | SF_FORMAT_WAV | SF_FORMAT_PCM_16, 2, 0.00001) ;
lcomp_test_short ("pcm.wav", SF_FORMAT_WAV | SF_FORMAT_PCM_16, 2, 1e-50) ;
lcomp_test_int ("pcm.wav", SF_FORMAT_WAV | SF_FORMAT_PCM_32, 2, 1e-50) ;
lcomp_test_short ("pcm.rifx", SF_ENDIAN_BIG | SF_FORMAT_WAV | SF_FORMAT_PCM_16, 2, 1e-50) ;
lcomp_test_int ("pcm.rifx", SF_ENDIAN_BIG | SF_FORMAT_WAV | SF_FORMAT_PCM_32, 2, 1e-50) ;
/* Lite remove start */
lcomp_test_float ("pcm.wav", SF_FORMAT_WAV | SF_FORMAT_PCM_16, 2, 0.005) ;
lcomp_test_double ("pcm.wav", SF_FORMAT_WAV | SF_FORMAT_PCM_16, 2, 0.005) ;
lcomp_test_float ("pcm.wav", SF_FORMAT_WAV | SF_FORMAT_FLOAT, 2, 1e-50) ;
lcomp_test_double ("pcm.wav", SF_FORMAT_WAV | SF_FORMAT_DOUBLE, 2, 1e-50) ;
/* Lite remove end */
read_raw_test ("pcm.wav", SF_FORMAT_WAV | SF_FORMAT_PCM_U8, 2) ;
test_count++ ;
} ;
@ -122,7 +128,7 @@ main (int argc, char *argv [])
/* Lite remove start */
if (do_all || strcmp (argv [1], "wav_ima") == 0)
{ lcomp_test_short ("ima.wav", SF_FORMAT_WAV | SF_FORMAT_IMA_ADPCM, 2, 0.18) ;
lcomp_test_int ("ima.wav", SF_FORMAT_WAV | SF_FORMAT_IMA_ADPCM, 2, 0.18) ;
lcomp_test_int ("ima.wav", SF_FORMAT_WAV | SF_FORMAT_IMA_ADPCM, 2, 0.65) ;
lcomp_test_float ("ima.wav", SF_FORMAT_WAV | SF_FORMAT_IMA_ADPCM, 2, 0.18) ;
lcomp_test_double ("ima.wav", SF_FORMAT_WAV | SF_FORMAT_IMA_ADPCM, 2, 0.18) ;
@ -180,6 +186,8 @@ main (int argc, char *argv [])
lcomp_test_float ("ulaw.wav", SF_FORMAT_WAV | SF_FORMAT_ULAW, 2, 0.04) ;
lcomp_test_double ("ulaw.wav", SF_FORMAT_WAV | SF_FORMAT_ULAW, 2, 0.04) ;
/* Lite remove end */
read_raw_test ("ulaw.wav", SF_FORMAT_WAV | SF_FORMAT_ULAW, 2) ;
test_count++ ;
} ;
@ -190,6 +198,8 @@ main (int argc, char *argv [])
lcomp_test_float ("alaw.wav", SF_FORMAT_WAV | SF_FORMAT_ALAW, 2, 0.04) ;
lcomp_test_double ("alaw.wav", SF_FORMAT_WAV | SF_FORMAT_ALAW, 2, 0.04) ;
/* Lite remove end */
read_raw_test ("alaw.wav", SF_FORMAT_WAV | SF_FORMAT_ALAW, 2) ;
test_count++ ;
} ;
@ -215,6 +225,8 @@ main (int argc, char *argv [])
lcomp_test_float ("ulaw.aiff", SF_FORMAT_AIFF | SF_FORMAT_ULAW, 2, 0.04) ;
lcomp_test_double ("ulaw.aiff", SF_FORMAT_AIFF | SF_FORMAT_ULAW, 2, 0.04) ;
/* Lite remove end */
read_raw_test ("ulaw.aiff", SF_FORMAT_AIFF | SF_FORMAT_ULAW, 2) ;
test_count++ ;
} ;
@ -225,6 +237,8 @@ main (int argc, char *argv [])
lcomp_test_float ("alaw.aiff", SF_FORMAT_AIFF | SF_FORMAT_ALAW, 2, 0.04) ;
lcomp_test_double ("alaw.aiff", SF_FORMAT_AIFF | SF_FORMAT_ALAW, 2, 0.04) ;
/* Lite remove end */
read_raw_test ("alaw.aiff", SF_FORMAT_AIFF | SF_FORMAT_ALAW, 2) ;
test_count++ ;
} ;
@ -312,6 +326,8 @@ main (int argc, char *argv [])
lcomp_test_float ("ulaw.caf", SF_FORMAT_CAF | SF_FORMAT_ULAW, 2, 0.04) ;
lcomp_test_double ("ulaw.caf", SF_FORMAT_CAF | SF_FORMAT_ULAW, 2, 0.04) ;
/* Lite remove end */
read_raw_test ("ulaw.caf", SF_FORMAT_CAF | SF_FORMAT_ULAW, 2) ;
test_count++ ;
} ;
@ -322,6 +338,8 @@ main (int argc, char *argv [])
lcomp_test_float ("alaw.caf", SF_FORMAT_CAF | SF_FORMAT_ALAW, 2, 0.04) ;
lcomp_test_double ("alaw.caf", SF_FORMAT_CAF | SF_FORMAT_ALAW, 2, 0.04) ;
/* Lite remove end */
read_raw_test ("alaw.caf", SF_FORMAT_CAF | SF_FORMAT_ALAW, 2) ;
test_count++ ;
} ;
@ -421,6 +439,8 @@ main (int argc, char *argv [])
lcomp_test_float ("ulaw.w64", SF_FORMAT_W64 | SF_FORMAT_ULAW, 2, 0.04) ;
lcomp_test_double ("ulaw.w64", SF_FORMAT_W64 | SF_FORMAT_ULAW, 2, 0.04) ;
/* Lite remove end */
read_raw_test ("ulaw.w64", SF_FORMAT_W64 | SF_FORMAT_ULAW, 2) ;
test_count++ ;
} ;
@ -431,6 +451,8 @@ main (int argc, char *argv [])
lcomp_test_float ("alaw.w64", SF_FORMAT_W64 | SF_FORMAT_ALAW, 2, 0.04) ;
lcomp_test_double ("alaw.w64", SF_FORMAT_W64 | SF_FORMAT_ALAW, 2, 0.04) ;
/* Lite remove end */
read_raw_test ("alaw.w64", SF_FORMAT_W64 | SF_FORMAT_ALAW, 2) ;
test_count++ ;
} ;
@ -634,7 +656,7 @@ lcomp_test_short (const char *filename, int filetype, int channels, double margi
{ test_readf_short_or_die (file, m, data, 11, __LINE__) ;
for (k = 0 ; k < channels * 11 ; k++)
if (error_function ((double) data [k], (double) orig [k + channels * m * 11], margin))
if (error_function (1.0 * data [k], 1.0 * orig [k + channels * m * 11], margin))
{ printf ("\n\nLine %d: Incorrect sample (m = %d) (#%d : %d => %d).\n", __LINE__, m, k + channels * m * 11, orig [k + channels * m * 11], data [k]) ;
for (m = 0 ; m < channels ; m++)
printf ("%d ", data [m]) ;
@ -653,7 +675,7 @@ lcomp_test_short (const char *filename, int filetype, int channels, double margi
test_readf_short_or_die (file, 0, data, 1, __LINE__) ;
if (error_function ((double) data [0], (double) orig [seekpos * channels], margin))
if (error_function (1.0 * data [0], 1.0 * orig [seekpos * channels], margin))
{ printf ("\n\nLine %d: sf_seek (SEEK_SET) followed by sf_readf_short failed (%d, %d).\n", __LINE__, orig [1], data [0]) ;
exit (1) ;
} ;
@ -666,7 +688,7 @@ lcomp_test_short (const char *filename, int filetype, int channels, double margi
seekpos = sf_seek (file, 0, SEEK_CUR) + BUFFER_SIZE / 5 ;
k = sf_seek (file, BUFFER_SIZE / 5, SEEK_CUR) ;
test_readf_short_or_die (file, 0, data, 1, __LINE__) ;
if (error_function ((double) data [0], (double) orig [seekpos * channels], margin) || k != seekpos)
if (error_function (1.0 * data [0], 1.0 * orig [seekpos * channels], margin) || k != seekpos)
{ printf ("\n\nLine %d: sf_seek (forwards, SEEK_CUR) followed by sf_readf_short failed (%d, %d) (%d, %d).\n", __LINE__, data [0], orig [seekpos * channels], k, seekpos + 1) ;
oct_save_short (orig, data, datalen) ;
exit (1) ;
@ -676,13 +698,13 @@ lcomp_test_short (const char *filename, int filetype, int channels, double margi
/* Check seek backward from current position. */
k = sf_seek (file, -20, SEEK_CUR) ;
test_readf_short_or_die (file, 0, data, 1, __LINE__) ;
if (error_function ((double) data [0], (double) orig [seekpos * channels], margin) || k != seekpos)
{ printf ("sf_seek (backwards, SEEK_CUR) followed by sf_readf_short failed (%d, %d) (%d, %d).\n", data [0], orig [seekpos * channels], k, seekpos) ;
if (error_function (1.0 * data [0], 1.0 * orig [seekpos * channels], margin) || k != seekpos)
{ printf ("\nLine %d: sf_seek (backwards, SEEK_CUR) followed by sf_readf_short failed (%d, %d) (%d, %d).\n", __LINE__, data [0], orig [seekpos * channels], k, seekpos) ;
exit (1) ;
} ;
/* Check that read past end of file returns number of items. */
sf_seek (file, (short) sfinfo.frames, SEEK_SET) ;
sf_seek (file, sfinfo.frames, SEEK_SET) ;
if ((k = sf_readf_short (file, data, datalen)) != 0)
{ printf ("\n\nLine %d: Return value from sf_readf_short past end of file incorrect (%d).\n", __LINE__, k) ;
@ -690,14 +712,14 @@ lcomp_test_short (const char *filename, int filetype, int channels, double margi
} ;
/* Check seek backward from end. */
if ((k = sf_seek (file, 5 - (short) sfinfo.frames, SEEK_END)) != 5)
{ printf ("sf_seek (SEEK_END) returned %d instead of %d.\n", k, 5) ;
if ((k = sf_seek (file, 5 - sfinfo.frames, SEEK_END)) != 5)
{ printf ("\n\nLine %d: sf_seek (SEEK_END) returned %d instead of %d.\n", __LINE__, k, 5) ;
exit (1) ;
} ;
test_readf_short_or_die (file, 0, data, channels, __LINE__) ;
if (error_function ((double) data [0], (double) orig [5], margin))
{ printf ("\n\nLine %d: sf_seek (SEEK_END) followed by sf_readf_short failed (%d should be %d).\n", __LINE__, data [0], orig [5]) ;
test_readf_short_or_die (file, 0, data, 1, __LINE__) ;
if (error_function (1.0 * data [0], 1.0 * orig [5 * channels], margin))
{ printf ("\nLine %d: sf_seek (SEEK_END) followed by sf_readf_short failed (%d should be %d).\n", __LINE__, data [0], orig [5 * channels]) ;
exit (1) ;
} ;
@ -714,22 +736,31 @@ static void
lcomp_test_int (const char *filename, int filetype, int channels, double margin)
{ SNDFILE *file ;
SF_INFO sfinfo ;
int k, m, *orig, *data, half_max_abs ;
int k, m, half_max_abs ;
long datalen, seekpos ;
double scale ;
double scale, max_val ;
int *orig, *data ;
print_test_name ("lcomp_test_int", filename) ;
datalen = BUFFER_SIZE / channels ;
scale = 1.0 * 0x10000 ;
if (is_lossy (filetype))
{ scale = 1.0 * 0x10000 ;
max_val = 32000.0 * scale ;
}
else
{ scale = 1.0 ;
max_val = 0x7fffffff * scale ;
} ;
data = data_buffer.i ;
orig = orig_buffer.i ;
gen_signal_double (orig_buffer.d, 32000.0 * scale, channels, datalen) ;
gen_signal_double (orig_buffer.d, max_val, channels, datalen) ;
for (k = 0 ; k < channels * datalen ; k++)
orig [k] = orig_buffer.d [k] ;
orig [k] = lrint (orig_buffer.d [k]) ;
sfinfo.samplerate = SAMPLE_RATE ;
sfinfo.frames = 123456789 ; /* Ridiculous value. */
@ -777,7 +808,7 @@ lcomp_test_int (const char *filename, int filetype, int channels, double margin)
half_max_abs = 0 ;
for (k = 0 ; k < datalen ; k++)
{ if (error_function (data [k] / scale, orig [k] / scale, margin))
{ printf ("\n\nLine %d: Incorrect sample (#%d : %f should be %f).\n", __LINE__, k, data [k] / scale, orig [k] / scale) ;
{ printf ("\nLine %d: Incorrect sample (#%d : %f should be %f).\n", __LINE__, k, data [k] / scale, orig [k] / scale) ;
oct_save_int (orig, data, datalen) ;
exit (1) ;
} ;
@ -824,7 +855,7 @@ lcomp_test_int (const char *filename, int filetype, int channels, double margin)
for (k = 0 ; k < channels * 11 ; k++)
if (error_function (data [k] / scale, orig [k + channels * m * 11] / scale, margin))
{ printf ("\n\nLine %d: Incorrect sample (m = %d) (#%d : %d => %d).\n", __LINE__, m, k + channels * m * 11, orig [k + channels * m * 11], data [k]) ;
{ printf ("\nLine %d: Incorrect sample (m = %d) (#%d : %d => %d).\n", __LINE__, m, k + channels * m * 11, orig [k + channels * m * 11], data [k]) ;
for (m = 0 ; m < channels ; m++)
printf ("%d ", data [m]) ;
printf ("\n") ;
@ -842,8 +873,8 @@ lcomp_test_int (const char *filename, int filetype, int channels, double margin)
test_readf_int_or_die (file, 0, data, 1, __LINE__) ;
if (error_function ((double) data [0], (double) orig [seekpos * channels], margin))
{ printf ("\n\nLine %d: sf_seek (SEEK_SET) followed by sf_readf_int failed (%d, %d).\n", __LINE__, orig [1], data [0]) ;
if (error_function (1.0 * data [0], 1.0 * orig [seekpos * channels], margin))
{ printf ("\nLine %d: sf_seek (SEEK_SET) followed by sf_readf_int failed (%d, %d).\n", __LINE__, orig [1], data [0]) ;
exit (1) ;
} ;
@ -855,8 +886,8 @@ lcomp_test_int (const char *filename, int filetype, int channels, double margin)
seekpos = sf_seek (file, 0, SEEK_CUR) + BUFFER_SIZE / 5 ;
k = sf_seek (file, BUFFER_SIZE / 5, SEEK_CUR) ;
test_readf_int_or_die (file, 0, data, 1, __LINE__) ;
if (error_function ((double) data [0], (double) orig [seekpos * channels], margin) || k != seekpos)
{ printf ("\n\nLine %d: sf_seek (forwards, SEEK_CUR) followed by sf_readf_int failed (%d, %d) (%d, %ld).\n", __LINE__, data [0], orig [seekpos * channels], k, seekpos + 1) ;
if (error_function (1.0 * data [0], 1.0 * orig [seekpos * channels], margin) || k != seekpos)
{ printf ("\nLine %d: sf_seek (forwards, SEEK_CUR) followed by sf_readf_int failed (%d, %d) (%d, %ld).\n", __LINE__, data [0], orig [seekpos * channels], k, seekpos + 1) ;
exit (1) ;
} ;
@ -864,13 +895,13 @@ lcomp_test_int (const char *filename, int filetype, int channels, double margin)
/* Check seek backward from current position. */
k = sf_seek (file, -20, SEEK_CUR) ;
test_readf_int_or_die (file, 0, data, 1, __LINE__) ;
if (error_function ((double) data [0], (double) orig [seekpos * channels], margin) || k != seekpos)
{ printf ("sf_seek (backwards, SEEK_CUR) followed by sf_readf_int failed (%d, %d) (%d, %ld).\n", data [0], orig [seekpos * channels], k, seekpos) ;
if (error_function (1.0 * data [0], 1.0 * orig [seekpos * channels], margin) || k != seekpos)
{ printf ("\nLine %d: sf_seek (backwards, SEEK_CUR) followed by sf_readf_int failed (%d, %d) (%d, %ld).\n", __LINE__, data [0], orig [seekpos * channels], k, seekpos) ;
exit (1) ;
} ;
/* Check that read past end of file returns number of items. */
sf_seek (file, (int) sfinfo.frames, SEEK_SET) ;
sf_seek (file, sfinfo.frames, SEEK_SET) ;
if ((k = sf_readf_int (file, data, datalen)) != 0)
{ printf ("\n\nLine %d: Return value from sf_readf_int past end of file incorrect (%d).\n", __LINE__, k) ;
@ -878,14 +909,14 @@ lcomp_test_int (const char *filename, int filetype, int channels, double margin)
} ;
/* Check seek backward from end. */
if ((k = sf_seek (file, 5 - (int) sfinfo.frames, SEEK_END)) != 5)
{ printf ("sf_seek (SEEK_END) returned %d instead of %d.\n", k, 5) ;
if ((k = sf_seek (file, 5 - sfinfo.frames, SEEK_END)) != 5)
{ printf ("\n\nLine %d: sf_seek (SEEK_END) returned %d instead of %d.\n", __LINE__, k, 5) ;
exit (1) ;
} ;
test_readf_int_or_die (file, 0, data, channels, __LINE__) ;
if (error_function (data [0] / scale, orig [5] / scale, margin))
{ printf ("\n\nLine %d: sf_seek (SEEK_END) followed by sf_readf_short failed (%d should be %d).\n", __LINE__, data [0], orig [5]) ;
test_readf_int_or_die (file, 0, data, 1, __LINE__) ;
if (error_function (data [0] / scale, orig [5 * channels] / scale, margin))
{ printf ("\nLine %d: sf_seek (SEEK_END) followed by sf_readf_short failed (%d should be %d).\n", __LINE__, data [0], orig [5]) ;
exit (1) ;
} ;
@ -916,7 +947,7 @@ lcomp_test_float (const char *filename, int filetype, int channels, double margi
gen_signal_double (orig_buffer.d, 32000.0, channels, datalen) ;
for (k = 0 ; k < channels * datalen ; k++)
orig [k] = (float) (orig_buffer.d [k]) ;
orig [k] = orig_buffer.d [k] ;
sfinfo.samplerate = SAMPLE_RATE ;
sfinfo.frames = 123456789 ; /* Ridiculous value. */
@ -970,8 +1001,8 @@ lcomp_test_float (const char *filename, int filetype, int channels, double margi
half_max_abs = 0.0 ;
for (k = 0 ; k < datalen ; k++)
{ if (error_function ((double) data [k], (double) orig [k], margin))
{ printf ("\n\nLine %d: Incorrect sample A (#%d : %f should be %f).\n", __LINE__, k, data [k], orig [k]) ;
{ if (error_function (data [k], orig [k], margin))
{ printf ("\nLine %d: Incorrect sample A (#%d : %f should be %f).\n", __LINE__, k, data [k], orig [k]) ;
oct_save_float (orig, data, datalen) ;
exit (1) ;
} ;
@ -1017,8 +1048,8 @@ lcomp_test_float (const char *filename, int filetype, int channels, double margi
{ test_readf_float_or_die (file, 0, data, 11, __LINE__) ;
for (k = 0 ; k < channels * 11 ; k++)
if (error_function ((double) data [k], (double) orig [k + channels * m * 11], margin))
{ printf ("\n\nLine %d: Incorrect sample (m = %d) (#%d : %f => %f).\n", __LINE__, m, k + channels * m * 11, orig [k + channels * m * 11], data [k]) ;
if (error_function (data [k], orig [k + channels * m * 11], margin))
{ printf ("\nLine %d: Incorrect sample (m = %d) (#%d : %f => %f).\n", __LINE__, m, k + channels * m * 11, orig [k + channels * m * 11], data [k]) ;
for (m = 0 ; m < channels ; m++)
printf ("%f ", data [m]) ;
printf ("\n") ;
@ -1036,8 +1067,8 @@ lcomp_test_float (const char *filename, int filetype, int channels, double margi
test_readf_float_or_die (file, 0, data, 1, __LINE__) ;
if (error_function ((double) data [0], (double) orig [seekpos * channels], margin))
{ printf ("\n\nLine %d: sf_seek (SEEK_SET) followed by sf_readf_float failed (%f, %f).\n", __LINE__, orig [1], data [0]) ;
if (error_function (data [0], orig [seekpos * channels], margin))
{ printf ("\nLine %d: sf_seek (SEEK_SET) followed by sf_readf_float failed (%f, %f).\n", __LINE__, orig [1], data [0]) ;
exit (1) ;
} ;
@ -1049,8 +1080,8 @@ lcomp_test_float (const char *filename, int filetype, int channels, double margi
seekpos = sf_seek (file, 0, SEEK_CUR) + BUFFER_SIZE / 5 ;
k = sf_seek (file, BUFFER_SIZE / 5, SEEK_CUR) ;
test_readf_float_or_die (file, 0, data, 1, __LINE__) ;
if (error_function ((double) data [0], (double) orig [seekpos * channels], margin) || k != seekpos)
{ printf ("\n\nLine %d: sf_seek (forwards, SEEK_CUR) followed by sf_readf_float failed (%f, %f) (%d, %d).\n", __LINE__, data [0], orig [seekpos * channels], k, seekpos + 1) ;
if (error_function (data [0], orig [seekpos * channels], margin) || k != seekpos)
{ printf ("\nLine %d: sf_seek (forwards, SEEK_CUR) followed by sf_readf_float failed (%f, %f) (%d, %d).\n", __LINE__, data [0], orig [seekpos * channels], k, seekpos + 1) ;
exit (1) ;
} ;
@ -1058,13 +1089,13 @@ lcomp_test_float (const char *filename, int filetype, int channels, double margi
/* Check seek backward from current position. */
k = sf_seek (file, -20, SEEK_CUR) ;
test_readf_float_or_die (file, 0, data, 1, __LINE__) ;
if (error_function ((double) data [0], (double) orig [seekpos * channels], margin) || k != seekpos)
{ printf ("sf_seek (backwards, SEEK_CUR) followed by sf_readf_float failed (%f, %f) (%d, %d).\n", data [0], orig [seekpos * channels], k, seekpos) ;
if (error_function (data [0], orig [seekpos * channels], margin) || k != seekpos)
{ printf ("\nLine %d: sf_seek (backwards, SEEK_CUR) followed by sf_readf_float failed (%f, %f) (%d, %d).\n", __LINE__, data [0], orig [seekpos * channels], k, seekpos) ;
exit (1) ;
} ;
/* Check that read past end of file returns number of items. */
sf_seek (file, (float) sfinfo.frames, SEEK_SET) ;
sf_seek (file, sfinfo.frames, SEEK_SET) ;
if ((k = sf_readf_float (file, data, datalen)) != 0)
{ printf ("\n\nLine %d: Return value from sf_readf_float past end of file incorrect (%d).\n", __LINE__, k) ;
@ -1072,14 +1103,14 @@ lcomp_test_float (const char *filename, int filetype, int channels, double margi
} ;
/* Check seek backward from end. */
if ((k = sf_seek (file, 5 - (float) sfinfo.frames, SEEK_END)) != 5)
{ printf ("sf_seek (SEEK_END) returned %d instead of %d.\n", k, 5) ;
if ((k = sf_seek (file, 5 - sfinfo.frames, SEEK_END)) != 5)
{ printf ("\n\nLine %d: sf_seek (SEEK_END) returned %d instead of %d.\n", __LINE__, k, 5) ;
exit (1) ;
} ;
test_readf_float_or_die (file, 0, data, channels, __LINE__) ;
if (error_function ((double) data [0], (double) orig [5], margin))
{ printf ("\n\nLine %d: sf_seek (SEEK_END) followed by sf_readf_short failed (%f should be %f).\n", __LINE__, data [0], orig [5]) ;
test_readf_float_or_die (file, 0, data, 1, __LINE__) ;
if (error_function (data [0], orig [5 * channels], margin))
{ printf ("\nLine %d: sf_seek (SEEK_END) followed by sf_readf_short failed (%f should be %f).\n", __LINE__, data [0], orig [5 * channels]) ;
exit (1) ;
} ;
@ -1110,7 +1141,7 @@ lcomp_test_double (const char *filename, int filetype, int channels, double marg
gen_signal_double (orig_buffer.d, 32000.0, channels, datalen) ;
for (k = 0 ; k < channels * datalen ; k++)
orig [k] = (double) (orig_buffer.d [k]) ;
orig [k] = orig_buffer.d [k] ;
sfinfo.samplerate = SAMPLE_RATE ;
sfinfo.frames = 123456789 ; /* Ridiculous value. */
@ -1164,8 +1195,8 @@ lcomp_test_double (const char *filename, int filetype, int channels, double marg
half_max_abs = 0.0 ;
for (k = 0 ; k < datalen ; k++)
{ if (error_function ((double) data [k], (double) orig [k], margin))
{ printf ("\n\nLine %d: Incorrect sample A (#%d : %f should be %f).\n", __LINE__, k, data [k], orig [k]) ;
{ if (error_function (data [k], orig [k], margin))
{ printf ("\nLine %d: Incorrect sample A (#%d : %f should be %f).\n", __LINE__, k, data [k], orig [k]) ;
oct_save_double (orig, data, datalen) ;
exit (1) ;
} ;
@ -1211,8 +1242,8 @@ lcomp_test_double (const char *filename, int filetype, int channels, double marg
{ test_readf_double_or_die (file, m, data, 11, __LINE__) ;
for (k = 0 ; k < channels * 11 ; k++)
if (error_function ((double) data [k], (double) orig [k + channels * m * 11], margin))
{ printf ("\n\nLine %d: Incorrect sample (m = %d) (#%d : %f => %f).\n", __LINE__, m, k + channels * m * 11, orig [k + channels * m * 11], data [k]) ;
if (error_function (data [k], orig [k + channels * m * 11], margin))
{ printf ("\nLine %d: Incorrect sample (m = %d) (#%d : %f => %f).\n", __LINE__, m, k + channels * m * 11, orig [k + channels * m * 11], data [k]) ;
for (m = 0 ; m < channels ; m++)
printf ("%f ", data [m]) ;
printf ("\n") ;
@ -1230,8 +1261,8 @@ lcomp_test_double (const char *filename, int filetype, int channels, double marg
test_readf_double_or_die (file, 0, data, 1, __LINE__) ;
if (error_function ((double) data [0], (double) orig [seekpos * channels], margin))
{ printf ("\n\nLine %d: sf_seek (SEEK_SET) followed by sf_readf_double failed (%f, %f).\n", __LINE__, orig [1], data [0]) ;
if (error_function (data [0], orig [seekpos * channels], margin))
{ printf ("\nLine %d: sf_seek (SEEK_SET) followed by sf_readf_double failed (%f, %f).\n", __LINE__, orig [1], data [0]) ;
exit (1) ;
} ;
@ -1243,8 +1274,8 @@ lcomp_test_double (const char *filename, int filetype, int channels, double marg
seekpos = sf_seek (file, 0, SEEK_CUR) + BUFFER_SIZE / 5 ;
k = sf_seek (file, BUFFER_SIZE / 5, SEEK_CUR) ;
test_readf_double_or_die (file, 0, data, 1, __LINE__) ;
if (error_function ((double) data [0], (double) orig [seekpos * channels], margin) || k != seekpos)
{ printf ("\n\nLine %d: sf_seek (forwards, SEEK_CUR) followed by sf_readf_double failed (%f, %f) (%d, %d).\n", __LINE__, data [0], orig [seekpos * channels], k, seekpos + 1) ;
if (error_function (data [0], orig [seekpos * channels], margin) || k != seekpos)
{ printf ("\nLine %d: sf_seek (forwards, SEEK_CUR) followed by sf_readf_double failed (%f, %f) (%d, %d).\n", __LINE__, data [0], orig [seekpos * channels], k, seekpos + 1) ;
exit (1) ;
} ;
@ -1252,13 +1283,13 @@ lcomp_test_double (const char *filename, int filetype, int channels, double marg
/* Check seek backward from current position. */
k = sf_seek (file, -20, SEEK_CUR) ;
test_readf_double_or_die (file, 0, data, 1, __LINE__) ;
if (error_function ((double) data [0], (double) orig [seekpos * channels], margin) || k != seekpos)
{ printf ("sf_seek (backwards, SEEK_CUR) followed by sf_readf_double failed (%f, %f) (%d, %d).\n", data [0], orig [seekpos * channels], k, seekpos) ;
if (error_function (data [0], orig [seekpos * channels], margin) || k != seekpos)
{ printf ("\nLine %d: sf_seek (backwards, SEEK_CUR) followed by sf_readf_double failed (%f, %f) (%d, %d).\n", __LINE__, data [0], orig [seekpos * channels], k, seekpos) ;
exit (1) ;
} ;
/* Check that read past end of file returns number of items. */
sf_seek (file, (double) sfinfo.frames, SEEK_SET) ;
sf_seek (file, sfinfo.frames, SEEK_SET) ;
if ((k = sf_readf_double (file, data, datalen)) != 0)
{ printf ("\n\nLine %d: Return value from sf_readf_double past end of file incorrect (%d).\n", __LINE__, k) ;
@ -1266,14 +1297,14 @@ lcomp_test_double (const char *filename, int filetype, int channels, double marg
} ;
/* Check seek backward from end. */
if ((k = sf_seek (file, 5 - (double) sfinfo.frames, SEEK_END)) != 5)
{ printf ("sf_seek (SEEK_END) returned %d instead of %d.\n", k, 5) ;
if ((k = sf_seek (file, 5 - sfinfo.frames, SEEK_END)) != 5)
{ printf ("\n\nLine %d: sf_seek (SEEK_END) returned %d instead of %d.\n", __LINE__, k, 5) ;
exit (1) ;
} ;
test_readf_double_or_die (file, 0, data, channels, __LINE__) ;
if (error_function ((double) data [0], (double) orig [5], margin))
{ printf ("\n\nLine %d: sf_seek (SEEK_END) followed by sf_readf_short failed (%f should be %f).\n", __LINE__, data [0], orig [5]) ;
test_readf_double_or_die (file, 0, data, 1, __LINE__) ;
if (error_function (data [0], orig [5 * channels], margin))
{ printf ("\nLine %d: sf_seek (SEEK_END) followed by sf_readf_short failed (%f should be %f).\n", __LINE__, data [0], orig [5 * channels]) ;
exit (1) ;
} ;
@ -1306,7 +1337,7 @@ channels = 1 ;
gen_signal_double (orig_buffer.d, 32000.0, channels, datalen) ;
for (k = 0 ; k < datalen ; k++)
orig [k] = (short) (orig_buffer.d [k]) ;
orig [k] = lrint (orig_buffer.d [k]) ;
sfinfo.samplerate = SAMPLE_RATE ;
sfinfo.frames = 123456789 ; /* Ridiculous value. */
@ -1378,8 +1409,8 @@ channels = 1 ;
half_max_abs = 0.0 ;
for (k = 0 ; k < datalen ; k++)
{ if (error_function ((double) data [k], (double) smooth [k], margin))
{ printf ("\n\nLine %d: Incorrect sample (#%d : %d should be %d).\n", __LINE__, k, data [k], smooth [k]) ;
{ if (error_function (1.0 * data [k], 1.0 * smooth [k], margin))
{ printf ("\nLine %d: Incorrect sample (#%d : %d should be %d).\n", __LINE__, k, data [k], smooth [k]) ;
oct_save_short (orig, smooth, datalen) ;
exit (1) ;
} ;
@ -1419,8 +1450,8 @@ channels = 1 ;
smoothed_diff_short (smooth, datalen / 7) ;
for (k = 0 ; k < datalen / 7 ; k++)
if (error_function ((double) data [k], (double) smooth [k], margin))
{ printf ("Incorrect sample C (#%d (%ld) : %d => %d).\n", k, k + m * (datalen / 7), smooth [k], data [k]) ;
if (error_function (1.0 * data [k], 1.0 * smooth [k], margin))
{ printf ("\nLine %d: Incorrect sample C (#%d (%ld) : %d => %d).\n", __LINE__, k, k + m * (datalen / 7), smooth [k], data [k]) ;
for (m = 0 ; m < 10 ; m++)
printf ("%d ", data [k]) ;
printf ("\n") ;
@ -1437,35 +1468,35 @@ channels = 1 ;
} ;
test_readf_short_or_die (file, 0, data, 1, __LINE__) ;
if (error_function ((double) data [0], (double) orig [seekpos * channels], margin))
{ printf ("sf_seek (SEEK_SET) followed by sf_read_short failed (%d, %d).\n", orig [1], data [0]) ;
if (error_function (1.0 * data [0], 1.0 * orig [seekpos * channels], margin))
{ printf ("\nLine %d: sf_seek (SEEK_SET) followed by sf_read_short failed (%d, %d).\n", __LINE__, orig [1], data [0]) ;
exit (1) ;
} ;
if ((k = sf_seek (file, 0, SEEK_CUR)) != seekpos + 1)
{ printf ("sf_seek (SEEK_CUR) with 0 offset failed (%d should be %d)\n", k, seekpos + 1) ;
{ printf ("\n\nLine %d: sf_seek (SEEK_CUR) with 0 offset failed (%d should be %d)\n", __LINE__, k, seekpos + 1) ;
exit (1) ;
} ;
seekpos = sf_seek (file, 0, SEEK_CUR) + BUFFER_SIZE / 5 ;
k = sf_seek (file, BUFFER_SIZE / 5, SEEK_CUR) ;
test_readf_short_or_die (file, 0, data, channels, __LINE__) ;
if (error_function ((double) data [0], (double) orig [seekpos * channels], margin) || k != seekpos)
{ printf ("sf_seek (forwards, SEEK_CUR) followed by sf_read_short failed (%d, %d) (%d, %d).\n", data [0], orig [seekpos * channels], k, seekpos + 1) ;
test_readf_short_or_die (file, 0, data, 1, __LINE__) ;
if (error_function (1.0 * data [0], 1.0 * orig [seekpos * channels], margin) || k != seekpos)
{ printf ("\nLine %d: sf_seek (forwards, SEEK_CUR) followed by sf_read_short failed (%d, %d) (%d, %d).\n", __LINE__, data [0], orig [seekpos * channels], k, seekpos + 1) ;
exit (1) ;
} ;
seekpos = sf_seek (file, 0, SEEK_CUR) - 20 ;
/* Check seek backward from current position. */
k = sf_seek (file, -20, SEEK_CUR) ;
test_readf_short_or_die (file, 0, data, channels, __LINE__) ;
if (error_function ((double) data [0], (double) orig [seekpos * channels], margin) || k != seekpos)
{ printf ("sf_seek (backwards, SEEK_CUR) followed by sf_read_short failed (%d, %d) (%d, %d).\n", data [0], orig [seekpos * channels], k, seekpos) ;
test_readf_short_or_die (file, 0, data, 1, __LINE__) ;
if (error_function (1.0 * data [0], 1.0 * orig [seekpos * channels], margin) || k != seekpos)
{ printf ("\nLine %d: sf_seek (backwards, SEEK_CUR) followed by sf_read_short failed (%d, %d) (%d, %d).\n", __LINE__, data [0], orig [seekpos * channels], k, seekpos) ;
exit (1) ;
} ;
/* Check that read past end of file returns number of items. */
sf_seek (file, (int) sfinfo.frames, SEEK_SET) ;
sf_seek (file, sfinfo.frames, SEEK_SET) ;
if ((k = sf_read_short (file, data, datalen)) != 0)
{ printf ("\n\nLine %d: Return value from sf_read_short past end of file incorrect (%d).\n", __LINE__, k) ;
@ -1474,14 +1505,14 @@ channels = 1 ;
/* Check seek backward from end. */
if ((k = sf_seek (file, 5 - (int) sfinfo.frames, SEEK_END)) != 5)
{ printf ("sf_seek (SEEK_END) returned %d instead of %d.\n", k, 5) ;
if ((k = sf_seek (file, 5 - sfinfo.frames, SEEK_END)) != 5)
{ printf ("\n\nLine %d: sf_seek (SEEK_END) returned %d instead of %d.\n", __LINE__, k, 5) ;
exit (1) ;
} ;
test_read_short_or_die (file, 0, data, channels, __LINE__) ;
if (error_function ((double) data [0], (double) orig [5], margin))
{ printf ("sf_seek (SEEK_END) followed by sf_read_short failed (%d should be %d).\n", data [0], orig [5]) ;
if (error_function (1.0 * data [0], 1.0 * orig [5 * channels], margin))
{ printf ("\nLine %d: sf_seek (SEEK_END) followed by sf_read_short failed (%d should be %d).\n", __LINE__, data [0], orig [5 * channels]) ;
exit (1) ;
} ;
} /* if (sfinfo.seekable) */
@ -1514,7 +1545,7 @@ channels = 1 ;
gen_signal_double (orig_buffer.d, 32000.0 * scale, channels, datalen) ;
for (k = 0 ; k < datalen ; k++)
orig [k] = (int) (orig_buffer.d [k]) ;
orig [k] = lrint (orig_buffer.d [k]) ;
sfinfo.samplerate = SAMPLE_RATE ;
sfinfo.frames = 123456789 ; /* Ridiculous value. */
@ -1583,7 +1614,7 @@ channels = 1 ;
half_max_abs = abs (data [0] >> 16) ;
for (k = 1 ; k < datalen ; k++)
{ if (error_function (data [k] / scale, smooth [k] / scale, margin))
{ printf ("\n\nLine %d: Incorrect sample (#%d : %d should be %d).\n", __LINE__, k, data [k], smooth [k]) ;
{ printf ("\nLine %d: Incorrect sample (#%d : %d should be %d).\n", __LINE__, k, data [k], smooth [k]) ;
oct_save_int (orig, smooth, datalen) ;
exit (1) ;
} ;
@ -1627,7 +1658,7 @@ channels = 1 ;
for (k = 0 ; k < datalen / 7 ; k++)
if (error_function (data [k] / scale, smooth [k] / scale, margin))
{ printf ("\n\nLine %d: Incorrect sample (#%d (%ld) : %d => %d).\n", __LINE__, k, k + m * (datalen / 7), smooth [k], data [k]) ;
{ printf ("\nLine %d: Incorrect sample (#%d (%ld) : %d => %d).\n", __LINE__, k, k + m * (datalen / 7), smooth [k], data [k]) ;
for (m = 0 ; m < 10 ; m++)
printf ("%d ", data [k]) ;
printf ("\n") ;
@ -1644,21 +1675,21 @@ channels = 1 ;
} ;
test_readf_int_or_die (file, 0, data, 1, __LINE__) ;
if (error_function ((double) data [0], (double) orig [seekpos * channels], margin))
{ printf ("sf_seek (SEEK_SET) followed by sf_readf_int failed (%d, %d).\n", orig [1], data [0]) ;
if (error_function (1.0 * data [0], 1.0 * orig [seekpos * channels], margin))
{ printf ("\nLine %d: sf_seek (SEEK_SET) followed by sf_readf_int failed (%d, %d).\n", __LINE__, orig [1], data [0]) ;
exit (1) ;
} ;
if ((k = sf_seek (file, 0, SEEK_CUR)) != seekpos + 1)
{ printf ("sf_seek (SEEK_CUR) with 0 offset failed (%d should be %d)\n", k, seekpos + 1) ;
{ printf ("\n\nLine %d: sf_seek (SEEK_CUR) with 0 offset failed (%d should be %d)\n", __LINE__, k, seekpos + 1) ;
exit (1) ;
} ;
seekpos = sf_seek (file, 0, SEEK_CUR) + BUFFER_SIZE / 5 ;
k = sf_seek (file, BUFFER_SIZE / 5, SEEK_CUR) ;
test_readf_int_or_die (file, 0, data, 1, __LINE__) ;
if (error_function ((double) data [0], (double) orig [seekpos * channels], margin) || k != seekpos)
{ printf ("sf_seek (forwards, SEEK_CUR) followed by sf_readf_int failed (%d, %d) (%d, %d).\n", data [0], orig [seekpos * channels], k, seekpos + 1) ;
if (error_function (1.0 * data [0], 1.0 * orig [seekpos * channels], margin) || k != seekpos)
{ printf ("\nLine %d: sf_seek (forwards, SEEK_CUR) followed by sf_readf_int failed (%d, %d) (%d, %d).\n", __LINE__, data [0], orig [seekpos * channels], k, seekpos + 1) ;
exit (1) ;
} ;
@ -1666,13 +1697,13 @@ channels = 1 ;
/* Check seek backward from current position. */
k = sf_seek (file, -20, SEEK_CUR) ;
test_readf_int_or_die (file, 0, data, 1, __LINE__) ;
if (error_function ((double) data [0], (double) orig [seekpos * channels], margin) || k != seekpos)
{ printf ("sf_seek (backwards, SEEK_CUR) followed by sf_readf_int failed (%d, %d) (%d, %d).\n", data [0], orig [seekpos * channels], k, seekpos) ;
if (error_function (1.0 * data [0], 1.0 * orig [seekpos * channels], margin) || k != seekpos)
{ printf ("\nLine %d: sf_seek (backwards, SEEK_CUR) followed by sf_readf_int failed (%d, %d) (%d, %d).\n", __LINE__, data [0], orig [seekpos * channels], k, seekpos) ;
exit (1) ;
} ;
/* Check that read past end of file returns number of items. */
sf_seek (file, (int) sfinfo.frames, SEEK_SET) ;
sf_seek (file, sfinfo.frames, SEEK_SET) ;
if ((k = sf_readf_int (file, data, datalen)) != 0)
{ printf ("\n\nLine %d: Return value from sf_readf_int past end of file incorrect (%d).\n", __LINE__, k) ;
@ -1681,14 +1712,14 @@ channels = 1 ;
/* Check seek backward from end. */
if ((k = sf_seek (file, 5 - (int) sfinfo.frames, SEEK_END)) != 5)
{ printf ("sf_seek (SEEK_END) returned %d instead of %d.\n", k, 5) ;
if ((k = sf_seek (file, 5 - sfinfo.frames, SEEK_END)) != 5)
{ printf ("\n\nLine %d: sf_seek (SEEK_END) returned %d instead of %d.\n", __LINE__, k, 5) ;
exit (1) ;
} ;
test_readf_int_or_die (file, 0, data, 1, __LINE__) ;
if (error_function (data [0] / scale, orig [5] / scale, margin))
{ printf ("\n\nLine %d: sf_seek (SEEK_END) followed by sf_readf_int failed (%d should be %d).\n", __LINE__, data [0], orig [5]) ;
{ printf ("\nLine %d: sf_seek (SEEK_END) followed by sf_readf_int failed (%d should be %d).\n", __LINE__, data [0], orig [5]) ;
exit (1) ;
} ;
} /* if (sfinfo.seekable) */
@ -1727,7 +1758,7 @@ printf ("** fix this ** ") ;
gen_signal_double (orig_buffer.d, 32000.0, channels, datalen) ;
for (k = 0 ; k < datalen ; k++)
orig [k] = (int) (orig_buffer.d [k]) ;
orig [k] = lrint (orig_buffer.d [k]) ;
sfinfo.samplerate = SAMPLE_RATE ;
sfinfo.frames = 123456789 ; /* Ridiculous value. */
@ -1782,7 +1813,7 @@ printf ("** fix this ** ") ;
half_max_abs = fabs (data [0]) ;
for (k = 1 ; k < datalen ; k++)
{ if (error_function (data [k], smooth [k], margin))
{ printf ("\n\nLine %d: Incorrect sample (#%d : %d should be %d).\n", __LINE__, k, (int) data [k], (int) smooth [k]) ;
{ printf ("\nLine %d: Incorrect sample (#%d : %d should be %d).\n", __LINE__, k, (int) data [k], (int) smooth [k]) ;
oct_save_float (orig, smooth, datalen) ;
exit (1) ;
} ;
@ -1823,8 +1854,8 @@ printf ("** fix this ** ") ;
smoothed_diff_float (smooth, datalen / 7) ;
for (k = 0 ; k < datalen / 7 ; k++)
if (error_function ((float) data [k], (float) smooth [k], margin))
{ printf ("Incorrect sample C (#%d (%ld) : %d => %d).\n", k, k + m * (datalen / 7), (int) smooth [k], (int) data [k]) ;
if (error_function (data [k], smooth [k], margin))
{ printf ("\nLine %d: Incorrect sample C (#%d (%ld) : %d => %d).\n", __LINE__, k, k + m * (datalen / 7), (int) smooth [k], (int) data [k]) ;
for (m = 0 ; m < 10 ; m++)
printf ("%d ", (int) data [k]) ;
printf ("\n") ;
@ -1839,23 +1870,23 @@ printf ("** fix this ** ") ;
{ printf ("Seek to start of file + %d failed (%d).\n", seekpos, k) ;
exit (1) ;
} ;
test_read_float_or_die (file, 0, data, 1, __LINE__) ;
test_read_float_or_die (file, 0, data, channels, __LINE__) ;
if (error_function ((float) data [0], (float) orig [seekpos * channels], margin))
{ printf ("sf_seek (SEEK_SET) followed by sf_read_float failed (%d, %d).\n", (int) orig [1], (int) data [0]) ;
if (error_function (data [0], orig [seekpos * channels], margin))
{ printf ("\nLine %d: sf_seek (SEEK_SET) followed by sf_read_float failed (%d, %d).\n", __LINE__, (int) orig [1], (int) data [0]) ;
exit (1) ;
} ;
if ((k = sf_seek (file, 0, SEEK_CUR)) != seekpos + 1)
{ printf ("sf_seek (SEEK_CUR) with 0 offset failed (%d should be %d)\n", k, seekpos + 1) ;
{ printf ("\n\nLine %d: sf_seek (SEEK_CUR) with 0 offset failed (%d should be %d)\n", __LINE__, k, seekpos + 1) ;
exit (1) ;
} ;
seekpos = sf_seek (file, 0, SEEK_CUR) + BUFFER_SIZE / 5 ;
k = sf_seek (file, BUFFER_SIZE / 5, SEEK_CUR) ;
test_read_float_or_die (file, 0, data, channels, __LINE__) ;
if (error_function ((float) data [0], (float) orig [seekpos * channels], margin) || k != seekpos)
{ printf ("sf_seek (forwards, SEEK_CUR) followed by sf_read_float failed (%d, %d) (%d, %d).\n", (int) data [0], (int) orig [seekpos * channels], k, seekpos + 1) ;
if (error_function (data [0], orig [seekpos * channels], margin) || k != seekpos)
{ printf ("\nLine %d: sf_seek (forwards, SEEK_CUR) followed by sf_read_float failed (%d, %d) (%d, %d).\n", __LINE__, (int) data [0], (int) orig [seekpos * channels], k, seekpos + 1) ;
exit (1) ;
} ;
@ -1863,13 +1894,13 @@ printf ("** fix this ** ") ;
/* Check seek backward from current position. */
k = sf_seek (file, -20, SEEK_CUR) ;
test_read_float_or_die (file, 0, data, channels, __LINE__) ;
if (error_function ((float) data [0], (float) orig [seekpos * channels], margin) || k != seekpos)
{ printf ("sf_seek (backwards, SEEK_CUR) followed by sf_read_float failed (%d, %d) (%d, %d).\n", (int) data [0], (int) orig [seekpos * channels], k, seekpos) ;
if (error_function (data [0], orig [seekpos * channels], margin) || k != seekpos)
{ printf ("\nLine %d: sf_seek (backwards, SEEK_CUR) followed by sf_read_float failed (%d, %d) (%d, %d).\n", __LINE__, (int) data [0], (int) orig [seekpos * channels], k, seekpos) ;
exit (1) ;
} ;
/* Check that read past end of file returns number of items. */
sf_seek (file, (int) sfinfo.frames, SEEK_SET) ;
sf_seek (file, sfinfo.frames, SEEK_SET) ;
if ((k = sf_read_float (file, data, datalen)) != 0)
{ printf ("\n\nLine %d: Return value from sf_read_float past end of file incorrect (%d).\n", __LINE__, k) ;
@ -1878,14 +1909,14 @@ printf ("** fix this ** ") ;
/* Check seek backward from end. */
if ((k = sf_seek (file, 5 - (int) sfinfo.frames, SEEK_END)) != 5)
{ printf ("sf_seek (SEEK_END) returned %d instead of %d.\n", k, 5) ;
if ((k = sf_seek (file, 5 - sfinfo.frames, SEEK_END)) != 5)
{ printf ("\n\nLine %d: sf_seek (SEEK_END) returned %d instead of %d.\n", __LINE__, k, 5) ;
exit (1) ;
} ;
test_read_float_or_die (file, 0, data, channels, __LINE__) ;
if (error_function ((float) data [0], (float) orig [5], margin))
{ printf ("sf_seek (SEEK_END) followed by sf_read_float failed (%d should be %d).\n", (int) data [0], (int) orig [5]) ;
if (error_function (data [0], orig [5 * channels], margin))
{ printf ("\nLine %d: sf_seek (SEEK_END) followed by sf_read_float failed (%f should be %f).\n", __LINE__, data [0], orig [5 * channels]) ;
exit (1) ;
} ;
} /* if (sfinfo.seekable) */
@ -2015,8 +2046,8 @@ channels = 1 ;
smoothed_diff_double (smooth, datalen / 7) ;
for (k = 0 ; k < datalen / 7 ; k++)
if (error_function ((double) data [k], (double) smooth [k], margin))
{ printf ("Incorrect sample C (#%d (%ld) : %d => %d).\n", k, k + m * (datalen / 7), (int) smooth [k], (int) data [k]) ;
if (error_function (data [k], smooth [k], margin))
{ printf ("\nLine %d: Incorrect sample C (#%d (%ld) : %d => %d).\n", __LINE__, k, k + m * (datalen / 7), (int) smooth [k], (int) data [k]) ;
for (m = 0 ; m < 10 ; m++)
printf ("%d ", (int) data [k]) ;
printf ("\n") ;
@ -2031,37 +2062,37 @@ channels = 1 ;
{ printf ("Seek to start of file + %d failed (%d).\n", seekpos, k) ;
exit (1) ;
} ;
test_read_double_or_die (file, 0, data, 1, __LINE__) ;
test_read_double_or_die (file, 0, data, channels, __LINE__) ;
if (error_function ((double) data [0], (double) orig [seekpos * channels], margin))
{ printf ("sf_seek (SEEK_SET) followed by sf_read_double failed (%d, %d).\n", (int) orig [1], (int) data [0]) ;
if (error_function (data [0], orig [seekpos * channels], margin))
{ printf ("\nLine %d: sf_seek (SEEK_SET) followed by sf_read_double failed (%d, %d).\n", __LINE__, (int) orig [1], (int) data [0]) ;
exit (1) ;
} ;
if ((k = sf_seek (file, 0, SEEK_CUR)) != seekpos + 1)
{ printf ("sf_seek (SEEK_CUR) with 0 offset failed (%d should be %d)\n", k, seekpos + 1) ;
{ printf ("\n\nLine %d: sf_seek (SEEK_CUR) with 0 offset failed (%d should be %d)\n", __LINE__, k, seekpos + 1) ;
exit (1) ;
} ;
seekpos = sf_seek (file, 0, SEEK_CUR) + BUFFER_SIZE / 5 ;
k = sf_seek (file, BUFFER_SIZE / 5, SEEK_CUR) ;
test_read_double_or_die (file, 0, data, 1, __LINE__) ;
if (error_function ((double) data [0], (double) orig [seekpos * channels], margin) || k != seekpos)
{ printf ("sf_seek (forwards, SEEK_CUR) followed by sf_read_double failed (%d, %d) (%d, %d).\n", (int) data [0], (int) orig [seekpos * channels], k, seekpos + 1) ;
test_read_double_or_die (file, 0, data, channels, __LINE__) ;
if (error_function (data [0], orig [seekpos * channels], margin) || k != seekpos)
{ printf ("\nLine %d: sf_seek (forwards, SEEK_CUR) followed by sf_read_double failed (%d, %d) (%d, %d).\n", __LINE__, (int) data [0], (int) orig [seekpos * channels], k, seekpos + 1) ;
exit (1) ;
} ;
seekpos = sf_seek (file, 0, SEEK_CUR) - 20 ;
/* Check seek backward from current position. */
k = sf_seek (file, -20, SEEK_CUR) ;
test_read_double_or_die (file, 0, data, 1, __LINE__) ;
if (error_function ((double) data [0], (double) orig [seekpos * channels], margin) || k != seekpos)
{ printf ("sf_seek (backwards, SEEK_CUR) followed by sf_read_double failed (%d, %d) (%d, %d).\n", (int) data [0], (int) orig [seekpos * channels], k, seekpos) ;
test_read_double_or_die (file, 0, data, channels, __LINE__) ;
if (error_function (data [0], orig [seekpos * channels], margin) || k != seekpos)
{ printf ("\nLine %d: sf_seek (backwards, SEEK_CUR) followed by sf_read_double failed (%d, %d) (%d, %d).\n", __LINE__, (int) data [0], (int) orig [seekpos * channels], k, seekpos) ;
exit (1) ;
} ;
/* Check that read past end of file returns number of items. */
sf_seek (file, (int) sfinfo.frames, SEEK_SET) ;
sf_seek (file, sfinfo.frames, SEEK_SET) ;
if ((k = sf_read_double (file, data, datalen)) != 0)
{ printf ("\n\nLine %d: Return value from sf_read_double past end of file incorrect (%d).\n", __LINE__, k) ;
@ -2070,14 +2101,14 @@ channels = 1 ;
/* Check seek backward from end. */
if ((k = sf_seek (file, 5 - (int) sfinfo.frames, SEEK_END)) != 5)
{ printf ("sf_seek (SEEK_END) returned %d instead of %d.\n", k, 5) ;
if ((k = sf_seek (file, 5 - sfinfo.frames, SEEK_END)) != 5)
{ printf ("\n\nLine %d: sf_seek (SEEK_END) returned %d instead of %d.\n", __LINE__, k, 5) ;
exit (1) ;
} ;
test_read_double_or_die (file, 0, data, 1, __LINE__) ;
if (error_function ((double) data [0], (double) orig [5], margin))
{ printf ("sf_seek (SEEK_END) followed by sf_read_double failed (%d should be %d).\n", (int) data [0], (int) orig [5]) ;
test_read_double_or_die (file, 0, data, channels, __LINE__) ;
if (error_function (data [0], orig [5 * channels], margin))
{ printf ("\nLine %d: sf_seek (SEEK_END) followed by sf_read_double failed (%f should be %f).\n", __LINE__, data [0], orig [5 * channels]) ;
exit (1) ;
} ;
} /* if (sfinfo.seekable) */
@ -2088,6 +2119,75 @@ channels = 1 ;
printf ("ok\n") ;
} /* sdlcomp_test_double */
static void
read_raw_test (const char *filename, int filetype, int channels)
{ SNDFILE *file ;
SF_INFO sfinfo ;
sf_count_t count ;
long datalen ;
short *orig, *data ;
int k ;
print_test_name ("read_raw_test", filename) ;
datalen = ARRAY_LEN (orig_buffer.s) / 2 ;
orig = orig_buffer.s ;
data = data_buffer.s ;
gen_signal_double (orig_buffer.d, 32000.0, channels, datalen) ;
for (k = 0 ; k < datalen ; k++)
orig [k] = lrint (orig_buffer.d [k]) ;
sfinfo.samplerate = SAMPLE_RATE ;
sfinfo.frames = 123456789 ; /* Ridiculous value. */
sfinfo.channels = channels ;
sfinfo.format = filetype ;
file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_FALSE, __LINE__) ;
test_write_short_or_die (file, 0, orig, datalen, __LINE__) ;
sf_set_string (file, SF_STR_COMMENT, long_comment) ;
sf_close (file) ;
memset (data, 0, datalen * sizeof (double)) ;
if ((filetype & SF_FORMAT_TYPEMASK) != SF_FORMAT_RAW)
memset (&sfinfo, 0, sizeof (sfinfo)) ;
file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_FALSE, __LINE__) ;
if (sfinfo.format != filetype)
{ printf ("Returned format incorrect (0x%08X => 0x%08X).\n", filetype, sfinfo.format) ;
exit (1) ;
} ;
if (sfinfo.frames < datalen / channels)
{ printf ("Too few.frames in file. (%ld should be a little more than %ld)\n", datalen, SF_COUNT_TO_LONG (sfinfo.frames)) ;
exit (1) ;
} ;
if (sfinfo.frames > (datalen + 400))
{ printf ("Too many.frames in file. (%ld should be a little more than %ld)\n", SF_COUNT_TO_LONG (sfinfo.frames), datalen) ;
exit (1) ;
} ;
if (sfinfo.channels != channels)
{ printf ("Incorrect number of channels in file.\n") ;
exit (1) ;
} ;
check_comment (file, filetype, __LINE__) ;
count = sf_read_raw (file, orig_buffer.c, datalen + 5 * channels) ;
if (count != sfinfo.channels * sfinfo.frames)
{ printf ("\nLine %d : sf_read_raw returned %ld should be %ld\n", __LINE__, SF_COUNT_TO_LONG (count), sfinfo.channels * SF_COUNT_TO_LONG (sfinfo.frames)) ;
exit (1) ;
} ;
unlink (filename) ;
printf ("ok\n") ;
} /* read_raw_test */
/*========================================================================================
** Auxiliary functions
*/
@ -2153,7 +2253,7 @@ error_function (double data, double orig, double margin)
error = fabs (data - orig) / fabs (orig) ;
if (error > margin)
{ printf ("\n\n*******************\nError : %f\n", error) ;
{ printf ("\n\nerror_function (data = %f, orig = %f, margin = %f) -> %f\n", data, orig, margin, error) ;
return 1 ;
} ;
return 0 ;
@ -2242,10 +2342,23 @@ check_comment (SNDFILE * file, int format, int lineno)
return ;
} /* check_comment */
/*
** Do not edit or modify anything in this comment block.
** The arch-tag line is a file identity tag for the GNU Arch
** revision control system.
**
** arch-tag: 5eb86888-3311-48b8-920e-c2a0393b7ad2
*/
static int
is_lossy (int filetype)
{
switch (SF_FORMAT_SUBMASK & filetype)
{ case SF_FORMAT_PCM_U8 :
case SF_FORMAT_PCM_S8 :
case SF_FORMAT_PCM_16 :
case SF_FORMAT_PCM_24 :
case SF_FORMAT_PCM_32 :
case SF_FORMAT_FLOAT :
case SF_FORMAT_DOUBLE :
return 0 ;
default :
break ;
} ;
return 1 ;
} /* is_lossy */

View File

@ -40,7 +40,7 @@ extern "C" {
#define PIPE_INDEX(x) ((x) + 500)
#define PIPE_TEST_LEN 12345
#if (defined (WIN32) || defined (_WIN32))
#if (defined (WIN32) || defined (_WIN32) || defined (__OS2__))
#define snprintf _snprintf
#endif
@ -155,6 +155,15 @@ int file_length (const char * fname) ;
#define LOG_BUFFER_SIZE 2048
/*
** Neat solution to the Win32/OS2 binary file flage requirement.
** If O_BINARY isn't already defined by the inclusion of the system
** headers, set it to zero.
*/
#ifndef O_BINARY
#define O_BINARY 0
#endif
[+ FOR float_type +]
void
gen_windowed_sine_[+ (get "name") +] ([+ (get "name") +] *data, int len, double maximum)
@ -439,19 +448,19 @@ test_open_file_or_die (const char *filename, int mode, SF_INFO *sfinfo, int allo
switch (mode)
{ case SFM_READ :
modestr = "SFM_READ" ;
oflags = O_RDONLY ;
oflags = O_RDONLY | O_BINARY ;
omode = 0 ;
break ;
case SFM_WRITE :
modestr = "SFM_WRITE" ;
oflags = O_WRONLY | O_CREAT | O_TRUNC ;
oflags = O_WRONLY | O_CREAT | O_TRUNC | O_BINARY ;
omode = S_IRUSR | S_IWUSR | S_IRGRP ;
break ;
case SFM_RDWR :
modestr = "SFM_RDWR" ;
oflags = O_RDWR | O_CREAT ;
oflags = O_RDWR | O_CREAT | O_BINARY ;
omode = S_IRUSR | S_IWUSR | S_IRGRP ;
break ;
default :
@ -460,11 +469,6 @@ test_open_file_or_die (const char *filename, int mode, SF_INFO *sfinfo, int allo
exit (1) ;
} ;
#if (defined (WIN32) || defined (_WIN32))
/* Stupid fscking windows. */
oflags |= O_BINARY ;
#endif
if (allow_fd && ((++count) & 1) == 1)
{ int fd ;