-# Copyright (C) 1999-2015 Erik de Castro Lopo <erikd@mega-nerd.com>.
+# Copyright (C) 1999-2017 Erik de Castro Lopo <erikd@mega-nerd.com>.
dnl Require autoconf version
AC_PREREQ(2.57)
-AC_INIT([libsndfile],[1.0.26],[sndfile@mega-nerd.com],
+AC_INIT([libsndfile],[1.0.28],[sndfile@mega-nerd.com],
[libsndfile],[http://www.mega-nerd.com/libsndfile/])
# Put config stuff in Cfg.
AC_CONFIG_SRCDIR([src/sndfile.c])
AC_CANONICAL_TARGET([])
-AC_CONFIG_MACRO_DIR([M4])
AC_CONFIG_HEADERS([src/config.h])
AM_INIT_AUTOMAKE
MN_GCC_REALLY_IS_GCC
AC_PROG_SED
+m4_ifdef([AM_PROG_AR], [AM_PROG_AR])
-# Do not check for F77.
-define([AC_LIBTOOL_LANG_F77_CONFIG], [:])dnl
-
-AM_PROG_LIBTOOL
+LT_INIT
LT_PROG_RC
AC_PROG_INSTALL
AM_CONDITIONAL([LINUX_MINGW_CROSS_TEST],
[test "$build_os:$target_os:$host_os:$HAVE_WINE" = "linux-gnu:mingw32msvc:mingw32msvc:yes"])
+gl_VISIBILITY
+
#====================================================================================
# Couple of initializations here. Fill in real values later.
# Finished checking, handle options.
AC_ARG_ENABLE(experimental,
- AC_HELP_STRING([--enable-experimental], [enable experimental code]))
+ AS_HELP_STRING([--enable-experimental], [enable experimental code]))
EXPERIMENTAL_CODE=0
if test x$enable_experimental = xyes ; then
AC_DEFINE_UNQUOTED([ENABLE_EXPERIMENTAL_CODE],${EXPERIMENTAL_CODE}, [Set to 1 to enable experimental code.])
AC_ARG_ENABLE(werror,
- AC_HELP_STRING([--enable-werror], [enable -Werror in all Makefiles]))
+ AS_HELP_STRING([--enable-werror], [enable -Werror in all Makefiles]))
AC_ARG_ENABLE(stack-smash-protection,
- AC_HELP_STRING([--enable-stack-smash-protection], [Enable GNU GCC stack smash protection]))
+ AS_HELP_STRING([--enable-stack-smash-protection], [Enable GNU GCC stack smash protection]))
AC_ARG_ENABLE(gcc-pipe,
- AC_HELP_STRING([--disable-gcc-pipe], [disable gcc -pipe option]))
+ AS_HELP_STRING([--disable-gcc-pipe], [disable gcc -pipe option]))
AC_ARG_ENABLE(gcc-opt,
- AC_HELP_STRING([--disable-gcc-opt], [disable gcc optimisations]))
+ AS_HELP_STRING([--disable-gcc-opt], [disable gcc optimisations]))
AC_ARG_ENABLE(cpu-clip,
- AC_HELP_STRING([--disable-cpu-clip], [disable tricky cpu specific clipper]))
+ AS_HELP_STRING([--disable-cpu-clip], [disable tricky cpu specific clipper]))
AC_ARG_ENABLE(bow-docs,
- AC_HELP_STRING([--enable-bow-docs], [enable black-on-white html docs]))
+ AS_HELP_STRING([--enable-bow-docs], [enable black-on-white html docs]))
AC_ARG_ENABLE(sqlite,
- AC_HELP_STRING([--disable-sqlite], [disable use of sqlite]))
+ AS_HELP_STRING([--disable-sqlite], [disable use of sqlite]))
AC_ARG_ENABLE(alsa,
- AC_HELP_STRING([--disable-alsa], [disable use of ALSA]))
+ AS_HELP_STRING([--disable-alsa], [disable use of ALSA]))
AC_ARG_ENABLE(external-libs,
- AC_HELP_STRING([--disable-external-libs], [disable use of FLAC, Ogg and Vorbis [[default=no]]]))
+ AS_HELP_STRING([--disable-external-libs], [disable use of FLAC, Ogg and Vorbis [[default=no]]]))
AC_ARG_ENABLE(octave,
- AC_HELP_STRING([--enable-octave], [disable building of GNU Octave module]))
+ AS_HELP_STRING([--enable-octave], [disable building of GNU Octave module]))
+
+AC_ARG_ENABLE([full-suite],
+ AS_HELP_STRING([--disable-full-suite], [disable building and installing programs, documentation, only build library [[default=no]]]))
+AM_CONDITIONAL([FULL_SUITE], [test "x$enable_full_suite" != "xno"])
AC_ARG_ENABLE(test-coverage,
- AC_HELP_STRING([--enable-test-coverage], [enable test coverage]))
+ AS_HELP_STRING([--enable-test-coverage], [enable test coverage]))
AM_CONDITIONAL([ENABLE_TEST_COVERAGE], [test "$enable_test_coverage" = yes])
#====================================================================================
# Check for common 64 bit file offset types.
AC_CHECK_SIZEOF(off_t,1)
-AC_CHECK_SIZEOF(loff_t,1)
-AC_CHECK_SIZEOF(off64_t,1)
if test "$enable_largefile:$ac_cv_sizeof_off_t" = "no:8" ; then
echo
exit 1
fi
-
case "$host_os" in
mingw32*)
TYPEOF_SF_COUNT_T="__int64"
TYPEOF_SF_COUNT_T="int64_t"
SF_COUNT_MAX="0x7FFFFFFFFFFFFFFFLL"
SIZEOF_SF_COUNT_T=8
- elif test "x$ac_cv_sizeof_loff_t" = "x8" ; then
- TYPEOF_SF_COUNT_T="int64_t"
- SF_COUNT_MAX="0x7FFFFFFFFFFFFFFFLL"
- SIZEOF_SF_COUNT_T=8
- elif test "x$ac_cv_sizeof_off64_t" = "x8" ; then
- TYPEOF_SF_COUNT_T="int64_t"
- SF_COUNT_MAX="0x7FFFFFFFFFFFFFFFLL"
- SIZEOF_SF_COUNT_T=8
else
# Save the old sizeof (off_t) value and then unset it to see if it
# changes when Large File Support is enabled.
unset ac_cv_sizeof_off_t
AC_SYS_LARGEFILE
-
if test "x$ac_cv_sys_largefile_CFLAGS" = "xno" ; then
ac_cv_sys_largefile_CFLAGS=""
fi
if test "x$ac_cv_sizeof_off_t" = "x8" ; then
TYPEOF_SF_COUNT_T="int64_t"
SF_COUNT_MAX="0x7FFFFFFFFFFFFFFFLL"
+ SIZEOF_SF_COUNT_T=8
elif test "x$TYPEOF_SF_COUNT_T" = "xunknown" ; then
echo
echo "*** The configure process has determined that this system is capable"
AC_DEFINE_UNQUOTED([SF_COUNT_MAX],${SF_COUNT_MAX}, [Set to maximum allowed value of sf_count_t type.])
AC_SUBST(SF_COUNT_MAX)
-AC_CHECK_TYPES(ssize_t)
-AC_CHECK_SIZEOF(ssize_t,4)
+AC_TYPE_SSIZE_T
#====================================================================================
# Determine endian-ness of target processor.
#====================================================================================
# Check for Ogg, Vorbis and FLAC.
-HAVE_EXTERNAL_LIBS=0
-EXTERNAL_CFLAGS=""
-EXTERNAL_LIBS=""
+HAVE_EXTERNAL_XIPH_LIBS=0
+EXTERNAL_XIPH_CFLAGS=""
+EXTERNAL_XIPH_LIBS=""
# Check for pkg-config outside the if statement.
PKG_PROG_PKG_CONFIG
fi
if test x$ac_cv_flac$ac_cv_ogg$ac_cv_vorbis$ac_cv_vorbisenc = "xyesyesyesyes" ; then
- HAVE_EXTERNAL_LIBS=1
+ HAVE_EXTERNAL_XIPH_LIBS=1
enable_external_libs=yes
- EXTERNAL_CFLAGS="$FLAC_CFLAGS $OGG_CFLAGS $VORBIS_CFLAGS $VORBISENC_CFLAGS $SPEEX_CFLAGS"
- EXTERNAL_LIBS="$FLAC_LIBS $OGG_LIBS $VORBIS_LIBS $VORBISENC_LIBS $SPEEX_LIBS "
+ EXTERNAL_XIPH_CFLAGS="$FLAC_CFLAGS $OGG_CFLAGS $VORBIS_CFLAGS $VORBISENC_CFLAGS $SPEEX_CFLAGS"
+ EXTERNAL_XIPH_LIBS="$FLAC_LIBS $OGG_LIBS $VORBIS_LIBS $VORBISENC_LIBS $SPEEX_LIBS "
else
echo
AC_MSG_WARN([[*** One or more of the external libraries (ie libflac, libogg and]])
fi
fi
-AC_DEFINE_UNQUOTED([HAVE_EXTERNAL_LIBS], $HAVE_EXTERNAL_LIBS, [Will be set to 1 if flac, ogg and vorbis are available.])
+AC_DEFINE_UNQUOTED([HAVE_EXTERNAL_XIPH_LIBS], $HAVE_EXTERNAL_XIPH_LIBS, [Will be set to 1 if flac, ogg and vorbis are available.])
#====================================================================================
# Check for libsqlite3 (only used in regtest).
fi
AC_DEFINE_UNQUOTED([HAVE_SQLITE3],$HAVE_SQLITE3,[Set to 1 if you have libsqlite3.])
+AM_CONDITIONAL([HAVE_SQLITE3], [test "x$ac_cv_sqlite3" = "xyes"])
#====================================================================================
# Determine if the processor can do clipping on float to int conversions.
os_is_win32=0
os_is_openbsd=0
use_windows_api=0
-osx_darwin_version=0
-
case "$host_os" in
darwin* | rhapsody*)
- osx_darwin_version=$(echo "$host_os" | sed 's/\..*//;s/darwin//g')
if test x$HAVE_XCODE_SELECT = xyes ; then
developer_path=`xcode-select --print-path`
else
developer_path="/Developer"
fi
- OS_SPECIFIC_CFLAGS="-I${developer_path}/Headers/FlatCarbon"
OS_SPECIFIC_LINKS="-framework CoreAudio -framework AudioToolbox -framework CoreFoundation"
;;
mingw*)
AC_DEFINE_UNQUOTED(OS_IS_WIN32, ${os_is_win32}, [Set to 1 if compiling for Win32])
AC_DEFINE_UNQUOTED(OS_IS_OPENBSD, ${os_is_openbsd}, [Set to 1 if compiling for OpenBSD])
AC_DEFINE_UNQUOTED(USE_WINDOWS_API, ${use_windows_api}, [Set to 1 to use the native windows API])
-AC_DEFINE_UNQUOTED(OSX_DARWIN_VERSION, ${osx_darwin_version}, [The darwin version, no-zero is valid])
AM_CONDITIONAL(USE_WIN_VERSION_FILE, test ${use_windows_api} -eq 1)
#====================================================================================
MN_ADD_CFLAGS([-Wextra])
MN_ADD_CFLAGS([-Wdeclaration-after-statement])
MN_ADD_CFLAGS([-Wpointer-arith])
- MN_ADD_CFLAGS([-funsigned-char])
AC_LANG_PUSH([C++])
MN_ADD_CXXFLAGS([-Wextra])
MN_ADD_CXXFLAGS([-Wpointer-arith])
- MN_ADD_CXXFLAGS([-funsigned-char])
AC_LANG_POP([C++])
-
- MN_ADD_CFLAGS([-D_FORTIFY_SOURCE=2])
-
if test x$enable_stack_smash_protection = "xyes" ; then
XIPH_GCC_STACK_PROTECTOR
XIPH_GXX_STACK_PROTECTOR
MN_ADD_CFLAGS([-coverage])
fi
- CFLAGS="$CFLAGS -Wcast-align -Wcast-qual -Wshadow -Wbad-function-cast -Wwrite-strings -Wundef -Wuninitialized -Winit-self -Wnested-externs -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations -Waggregate-return"
- # -Winline -Wconversion -Wunreachable-code"
- CXXFLAGS="$CXXFLAGS -Wcast-align -Wcast-qual -Wshadow -Wwrite-strings -Wctor-dtor-privacy -Wnon-virtual-dtor -Woverloaded-virtual -Wreorder -Wsign-promo -Wundef -Wuninitialized -Winit-self"
+ dnl some distributions (such as Gentoo) have _FORTIFY_SOURCE always
+ dnl enabled. We test for this situation in order to prevent polluting
+ dnl the console with messages of macro redefinitions.
+ AX_ADD_FORTIFY_SOURCE
+
+ common_flags="-Wcast-align -Wcast-qual -Wshadow -Wwrite-strings -Wundef -Wuninitialized -Winit-self"
+
+ # -Winline -Wconversion "
+ CFLAGS="$CFLAGS $common_flags -Wbad-function-cast -Wnested-externs -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations -Waggregate-return -Wvla"
+ CXXFLAGS="$CXXFLAGS $common_flags -Wctor-dtor-privacy -Wnon-virtual-dtor -Woverloaded-virtual -Wreorder -Wsign-promo"
if test "x$enable_gcc_opt" = "xno" ; then
temp_CFLAGS=`echo $CFLAGS | $SED "s/O2/O0/"`
AC_SUBST(CLEAN_VERSION)
AC_SUBST(WIN_RC_VERSION)
-AC_SUBST(HAVE_EXTERNAL_LIBS)
+AC_SUBST(HAVE_EXTERNAL_XIPH_LIBS)
AC_SUBST(OS_SPECIFIC_CFLAGS)
AC_SUBST(OS_SPECIFIC_LINKS)
AC_SUBST(ALSA_LIBS)
AC_SUBST(SNDIO_LIBS)
-AC_SUBST(EXTERNAL_CFLAGS)
-AC_SUBST(EXTERNAL_LIBS)
+AC_SUBST(EXTERNAL_XIPH_CFLAGS)
+AC_SUBST(EXTERNAL_XIPH_LIBS)
AC_SUBST(SRC_BINDIR)
AC_SUBST(TEST_BINDIR)
./echo-install-dirs
# Remove symlink created by Scripts/android-configure.sh.
-test -h gdbclient && rm -f gdbclient
-
-(cd src && make genfiles)
-(cd tests && make genfiles)
+rm -f gdbclient
#include "sndfile.h"
#include "common.h"
-#if HAVE_EXTERNAL_LIBS
+#if HAVE_EXTERNAL_XIPH_LIBS
#include <FLAC/stream_decoder.h>
#include <FLAC/stream_encoder.h>
FLAC__StreamMetadata *metadata ;
- const FLAC__int32 * const * wbuffer ;
- FLAC__int32 * rbuffer [FLAC__MAX_CHANNELS] ;
+ const int32_t * const * wbuffer ;
+ int32_t * rbuffer [FLAC__MAX_CHANNELS] ;
- FLAC__int32* encbuffer ;
+ int32_t* encbuffer ;
unsigned bufferpos ;
const FLAC__Frame *frame ;
- FLAC__bool bufferbackup ;
unsigned compression ;
+
} FLAC_PRIVATE ;
typedef struct
static sf_count_t flac_write_f2flac (SF_PRIVATE *psf, const float *ptr, sf_count_t len) ;
static sf_count_t flac_write_d2flac (SF_PRIVATE *psf, const double *ptr, sf_count_t len) ;
-static void f2flac8_array (const float *src, FLAC__int32 *dest, int count, int normalize) ;
-static void f2flac16_array (const float *src, FLAC__int32 *dest, int count, int normalize) ;
-static void f2flac24_array (const float *src, FLAC__int32 *dest, int count, int normalize) ;
-static void f2flac8_clip_array (const float *src, FLAC__int32 *dest, int count, int normalize) ;
-static void f2flac16_clip_array (const float *src, FLAC__int32 *dest, int count, int normalize) ;
-static void f2flac24_clip_array (const float *src, FLAC__int32 *dest, int count, int normalize) ;
-static void d2flac8_array (const double *src, FLAC__int32 *dest, int count, int normalize) ;
-static void d2flac16_array (const double *src, FLAC__int32 *dest, int count, int normalize) ;
-static void d2flac24_array (const double *src, FLAC__int32 *dest, int count, int normalize) ;
-static void d2flac8_clip_array (const double *src, FLAC__int32 *dest, int count, int normalize) ;
-static void d2flac16_clip_array (const double *src, FLAC__int32 *dest, int count, int normalize) ;
-static void d2flac24_clip_array (const double *src, FLAC__int32 *dest, int count, int normalize) ;
+static void f2flac8_array (const float *src, int32_t *dest, int count, int normalize) ;
+static void f2flac16_array (const float *src, int32_t *dest, int count, int normalize) ;
+static void f2flac24_array (const float *src, int32_t *dest, int count, int normalize) ;
+static void f2flac8_clip_array (const float *src, int32_t *dest, int count, int normalize) ;
+static void f2flac16_clip_array (const float *src, int32_t *dest, int count, int normalize) ;
+static void f2flac24_clip_array (const float *src, int32_t *dest, int count, int normalize) ;
+static void d2flac8_array (const double *src, int32_t *dest, int count, int normalize) ;
+static void d2flac16_array (const double *src, int32_t *dest, int count, int normalize) ;
+static void d2flac24_array (const double *src, int32_t *dest, int count, int normalize) ;
+static void d2flac8_clip_array (const double *src, int32_t *dest, int count, int normalize) ;
+static void d2flac16_clip_array (const double *src, int32_t *dest, int count, int normalize) ;
+static void d2flac24_clip_array (const double *src, int32_t *dest, int count, int normalize) ;
static int flac_command (SF_PRIVATE *psf, int command, void *data, int datasize) ;
static FLAC__StreamDecoderTellStatus sf_flac_tell_callback (const FLAC__StreamDecoder *decoder, FLAC__uint64 *absolute_byte_offset, void *client_data) ;
static FLAC__StreamDecoderLengthStatus sf_flac_length_callback (const FLAC__StreamDecoder *decoder, FLAC__uint64 *stream_length, void *client_data) ;
static FLAC__bool sf_flac_eof_callback (const FLAC__StreamDecoder *decoder, void *client_data) ;
-static FLAC__StreamDecoderWriteStatus sf_flac_write_callback (const FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer [], void *client_data) ;
+static FLAC__StreamDecoderWriteStatus sf_flac_write_callback (const FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const int32_t * const buffer [], void *client_data) ;
static void sf_flac_meta_callback (const FLAC__StreamDecoder *decoder, const FLAC__StreamMetadata *metadata, void *client_data) ;
static void sf_flac_error_callback (const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data) ;
static FLAC__StreamEncoderWriteStatus sf_flac_enc_write_callback (const FLAC__StreamEncoder *encoder, const FLAC__byte buffer [], size_t bytes, unsigned samples, unsigned current_frame, void *client_data) ;
static void
-s2flac8_array (const short *src, FLAC__int32 *dest, int count)
+s2flac8_array (const short *src, int32_t *dest, int count)
{ while (--count >= 0)
dest [count] = src [count] >> 8 ;
} /* s2flac8_array */
static void
-s2flac16_array (const short *src, FLAC__int32 *dest, int count)
+s2flac16_array (const short *src, int32_t *dest, int count)
{ while (--count >= 0)
dest [count] = src [count] ;
} /* s2flac16_array */
static void
-s2flac24_array (const short *src, FLAC__int32 *dest, int count)
+s2flac24_array (const short *src, int32_t *dest, int count)
{ while (--count >= 0)
dest [count] = src [count] << 8 ;
} /* s2flac24_array */
static void
-i2flac8_array (const int *src, FLAC__int32 *dest, int count)
+i2flac8_array (const int *src, int32_t *dest, int count)
{ while (--count >= 0)
dest [count] = src [count] >> 24 ;
} /* i2flac8_array */
static void
-i2flac16_array (const int *src, FLAC__int32 *dest, int count)
+i2flac16_array (const int *src, int32_t *dest, int count)
{
while (--count >= 0)
dest [count] = src [count] >> 16 ;
} /* i2flac16_array */
static void
-i2flac24_array (const int *src, FLAC__int32 *dest, int count)
+i2flac24_array (const int *src, int32_t *dest, int count)
{ while (--count >= 0)
dest [count] = src [count] >> 8 ;
} /* i2flac24_array */
flac_buffer_copy (SF_PRIVATE *psf)
{ FLAC_PRIVATE* pflac = (FLAC_PRIVATE*) psf->codec_data ;
const FLAC__Frame *frame = pflac->frame ;
- const FLAC__int32* const *buffer = pflac->wbuffer ;
- unsigned i = 0, j, offset ;
+ const int32_t* const *buffer = pflac->wbuffer ;
+ unsigned i = 0, j, offset, channels, len ;
/*
** frame->header.blocksize is variable and we're using a constant blocksize
return 0 ;
} ;
+ if (frame->header.channels > FLAC__MAX_CHANNELS)
+ psf_log_printf (psf, "Ooops : frame->header.channels (%d) > FLAC__MAX_BLOCK_SIZE (%d)\n", __func__, __LINE__, frame->header.channels, FLAC__MAX_CHANNELS) ;
+
+ channels = SF_MIN (frame->header.channels, FLAC__MAX_CHANNELS) ;
+
if (pflac->ptr == NULL)
{ /*
- ** Not sure why this code is here and not elsewhere.
- ** Removing it causes valgrind errors.
+ ** This pointer is reset to NULL each time the current frame has been
+ ** decoded. Somehow its used during encoding and decoding.
*/
- pflac->bufferbackup = SF_TRUE ;
- for (i = 0 ; i < frame->header.channels ; i++)
+ for (i = 0 ; i < channels ; i++)
{
if (pflac->rbuffer [i] == NULL)
- pflac->rbuffer [i] = calloc (FLAC__MAX_BLOCK_SIZE, sizeof (FLAC__int32)) ;
+ pflac->rbuffer [i] = calloc (FLAC__MAX_BLOCK_SIZE, sizeof (int32_t)) ;
- memcpy (pflac->rbuffer [i], buffer [i], frame->header.blocksize * sizeof (FLAC__int32)) ;
+ memcpy (pflac->rbuffer [i], buffer [i], frame->header.blocksize * sizeof (int32_t)) ;
} ;
- pflac->wbuffer = (const FLAC__int32* const*) pflac->rbuffer ;
+ pflac->wbuffer = (const int32_t* const*) pflac->rbuffer ;
+
+ return 0 ;
+ } ;
+
+
+ len = SF_MIN (pflac->len, frame->header.blocksize) ;
+ if (pflac->remain % channels != 0)
+ { psf_log_printf (psf, "Error: pflac->remain %u channels %u\n", pflac->remain, channels) ;
return 0 ;
} ;
int shift = 16 - frame->header.bits_per_sample ;
if (shift < 0)
{ shift = abs (shift) ;
- for (i = 0 ; i < frame->header.blocksize && pflac->remain > 0 ; i++)
- { offset = pflac->pos + i * frame->header.channels ;
+ for (i = 0 ; i < len && pflac->remain > 0 ; i++)
+ { offset = pflac->pos + i * channels ;
if (pflac->bufferpos >= frame->header.blocksize)
break ;
- for (j = 0 ; j < frame->header.channels ; j++)
+ if (offset + channels > pflac->len)
+ break ;
+
+ for (j = 0 ; j < channels ; j++)
retpcm [offset + j] = buffer [j][pflac->bufferpos] >> shift ;
- pflac->remain -= frame->header.channels ;
+ pflac->remain -= channels ;
pflac->bufferpos++ ;
}
}
else
- { for (i = 0 ; i < frame->header.blocksize && pflac->remain > 0 ; i++)
- { offset = pflac->pos + i * frame->header.channels ;
+ { for (i = 0 ; i < len && pflac->remain > 0 ; i++)
+ { offset = pflac->pos + i * channels ;
if (pflac->bufferpos >= frame->header.blocksize)
break ;
- for (j = 0 ; j < frame->header.channels ; j++)
+ if (offset + channels > pflac->len)
+ break ;
+
+ for (j = 0 ; j < channels ; j++)
retpcm [offset + j] = ((uint16_t) buffer [j][pflac->bufferpos]) << shift ;
- pflac->remain -= frame->header.channels ;
+ pflac->remain -= channels ;
pflac->bufferpos++ ;
} ;
} ;
case PFLAC_PCM_INT :
{ int *retpcm = (int*) pflac->ptr ;
int shift = 32 - frame->header.bits_per_sample ;
- for (i = 0 ; i < frame->header.blocksize && pflac->remain > 0 ; i++)
- { offset = pflac->pos + i * frame->header.channels ;
+ for (i = 0 ; i < len && pflac->remain > 0 ; i++)
+ { offset = pflac->pos + i * channels ;
if (pflac->bufferpos >= frame->header.blocksize)
break ;
- for (j = 0 ; j < frame->header.channels ; j++)
+ if (offset + channels > pflac->len)
+ break ;
+
+ for (j = 0 ; j < channels ; j++)
retpcm [offset + j] = ((uint32_t) buffer [j][pflac->bufferpos]) << shift ;
- pflac->remain -= frame->header.channels ;
+ pflac->remain -= channels ;
pflac->bufferpos++ ;
} ;
} ;
{ float *retpcm = (float*) pflac->ptr ;
float norm = (psf->norm_float == SF_TRUE) ? 1.0 / (1 << (frame->header.bits_per_sample - 1)) : 1.0 ;
- for (i = 0 ; i < frame->header.blocksize && pflac->remain > 0 ; i++)
- { offset = pflac->pos + i * frame->header.channels ;
+ for (i = 0 ; i < len && pflac->remain > 0 ; i++)
+ { offset = pflac->pos + i * channels ;
if (pflac->bufferpos >= frame->header.blocksize)
break ;
- for (j = 0 ; j < frame->header.channels ; j++)
+ if (offset + channels > pflac->len)
+ break ;
+
+ for (j = 0 ; j < channels ; j++)
retpcm [offset + j] = buffer [j][pflac->bufferpos] * norm ;
- pflac->remain -= frame->header.channels ;
+ pflac->remain -= channels ;
pflac->bufferpos++ ;
} ;
} ;
{ double *retpcm = (double*) pflac->ptr ;
double norm = (psf->norm_double == SF_TRUE) ? 1.0 / (1 << (frame->header.bits_per_sample - 1)) : 1.0 ;
- for (i = 0 ; i < frame->header.blocksize && pflac->remain > 0 ; i++)
- { offset = pflac->pos + i * frame->header.channels ;
+ for (i = 0 ; i < len && pflac->remain > 0 ; i++)
+ { offset = pflac->pos + i * channels ;
if (pflac->bufferpos >= frame->header.blocksize)
break ;
- for (j = 0 ; j < frame->header.channels ; j++)
+ if (offset + channels > pflac->len)
+ break ;
+
+ for (j = 0 ; j < channels ; j++)
retpcm [offset + j] = buffer [j][pflac->bufferpos] * norm ;
- pflac->remain -= frame->header.channels ;
+ pflac->remain -= channels ;
pflac->bufferpos++ ;
} ;
} ;
return 0 ;
} ;
- offset = i * frame->header.channels ;
- pflac->pos += i * frame->header.channels ;
+ offset = i * channels ;
+ pflac->pos += i * channels ;
return offset ;
} /* flac_buffer_copy */
} /* sf_flac_eof_callback */
static FLAC__StreamDecoderWriteStatus
-sf_flac_write_callback (const FLAC__StreamDecoder * UNUSED (decoder), const FLAC__Frame *frame, const FLAC__int32 * const buffer [], void *client_data)
+sf_flac_write_callback (const FLAC__StreamDecoder * UNUSED (decoder), const FLAC__Frame *frame, const int32_t * const buffer [], void *client_data)
{ SF_PRIVATE *psf = (SF_PRIVATE*) client_data ;
FLAC_PRIVATE* pflac = (FLAC_PRIVATE*) psf->codec_data ;
pflac->frame = frame ;
pflac->bufferpos = 0 ;
- pflac->bufferbackup = SF_FALSE ;
pflac->wbuffer = buffer ;
flac_buffer_copy (psf) ;
static void
sf_flac_meta_get_vorbiscomments (SF_PRIVATE *psf, const FLAC__StreamMetadata *metadata)
-{ FLAC_TAG tags [] =
+{ static FLAC_TAG tags [] =
{ { "title", SF_STR_TITLE },
{ "copyright", SF_STR_COPYRIGHT },
{ "software", SF_STR_SOFTWARE },
if ((cptr = strchr (value, '=')) != NULL)
value = cptr + 1 ;
- psf_log_printf (psf, " %-10s : %s\n", tags [k].tag, value) ;
+ psf_log_printf (psf, " %-12s : %s\n", tags [k].tag, value) ;
psf_store_string (psf, tags [k].type, value) ;
} ;
static void
sf_flac_meta_callback (const FLAC__StreamDecoder * UNUSED (decoder), const FLAC__StreamMetadata *metadata, void *client_data)
{ SF_PRIVATE *psf = (SF_PRIVATE*) client_data ;
- int bitwidth = 0 ;
+ FLAC_PRIVATE* pflac = (FLAC_PRIVATE*) psf->codec_data ;
+ int bitwidth = 0, i ;
switch (metadata->type)
{ case FLAC__METADATA_TYPE_STREAMINFO :
if (bitwidth > 0)
psf_log_printf (psf, " Bit width : %d\n", bitwidth) ;
+
+
+ for (i = 0 ; i < psf->sf.channels ; i++)
+ pflac->rbuffer [i] = calloc (FLAC__MAX_BLOCK_SIZE, sizeof (int32_t)) ;
+
+ pflac->wbuffer = (const int32_t* const*) pflac->rbuffer ;
break ;
case FLAC__METADATA_TYPE_VORBIS_COMMENT :
if (psf->error == 0)
psf->dataoffset = psf_ftell (psf) ;
- pflac->encbuffer = calloc (ENC_BUFFER_SIZE, sizeof (FLAC__int32)) ;
+ pflac->encbuffer = calloc (ENC_BUFFER_SIZE, sizeof (int32_t)) ;
return psf->error ;
} /* flac_write_header */
/* Set the default value here. Over-ridden later if necessary. */
pflac->compression = FLAC_DEFAULT_COMPRESSION_LEVEL ;
-
if (psf->file.mode == SFM_RDWR)
return SFE_BAD_MODE_RW ;
if ((error = flac_enc_init (psf)))
return error ;
+ /* In an ideal world we would write the header at this point. Unfortunately
+ ** that would prevent string metadata being added so we have to hold off.
+ */
+
psf->write_header = flac_write_header ;
} ;
if (psf->file.mode == SFM_WRITE)
{ FLAC__stream_encoder_finish (pflac->fse) ;
FLAC__stream_encoder_delete (pflac->fse) ;
-
- if (pflac->encbuffer)
- free (pflac->encbuffer) ;
+ free (pflac->encbuffer) ;
} ;
if (psf->file.mode == SFM_READ)
static unsigned
flac_read_loop (SF_PRIVATE *psf, unsigned len)
{ FLAC_PRIVATE* pflac = (FLAC_PRIVATE*) psf->codec_data ;
+ FLAC__StreamDecoderState state ;
pflac->pos = 0 ;
pflac->len = len ;
pflac->remain = len ;
+
+ state = FLAC__stream_decoder_get_state (pflac->fsd) ;
+ if (state > FLAC__STREAM_DECODER_END_OF_STREAM)
+ { psf_log_printf (psf, "FLAC__stream_decoder_get_state returned %s\n", FLAC__StreamDecoderStateString [state]) ;
+ /* Current frame is busted, so NULL the pointer. */
+ pflac->frame = NULL ;
+ } ;
+
+ /* First copy data that has already been decoded and buffered. */
if (pflac->frame != NULL && pflac->bufferpos < pflac->frame->header.blocksize)
flac_buffer_copy (psf) ;
+ /* Decode some more. */
while (pflac->pos < pflac->len)
{ if (FLAC__stream_decoder_process_single (pflac->fsd) == 0)
break ;
- if (FLAC__stream_decoder_get_state (pflac->fsd) >= FLAC__STREAM_DECODER_END_OF_STREAM)
+ state = FLAC__stream_decoder_get_state (pflac->fsd) ;
+ if (state >= FLAC__STREAM_DECODER_END_OF_STREAM)
+ { psf_log_printf (psf, "FLAC__stream_decoder_get_state returned %s\n", FLAC__StreamDecoderStateString [state]) ;
+ /* Current frame is busted, so NULL the pointer. */
+ pflac->frame = NULL ;
break ;
+ } ;
} ;
pflac->ptr = NULL ;
while (total < len)
{ pflac->ptr = ptr + total ;
readlen = (len - total > 0x1000000) ? 0x1000000 : (unsigned) (len - total) ;
+
current = flac_read_loop (psf, readlen) ;
if (current == 0)
break ;
static sf_count_t
flac_write_s2flac (SF_PRIVATE *psf, const short *ptr, sf_count_t len)
{ FLAC_PRIVATE* pflac = (FLAC_PRIVATE*) psf->codec_data ;
- void (*convert) (const short *, FLAC__int32 *, int) ;
+ void (*convert) (const short *, int32_t *, int) ;
int bufferlen, writecount, thiswrite ;
sf_count_t total = 0 ;
- FLAC__int32* buffer = pflac->encbuffer ;
+ int32_t* buffer = pflac->encbuffer ;
switch (SF_CODEC (psf->sf.format))
{ case SF_FORMAT_PCM_S8 :
return -1 ;
} ;
- bufferlen = ENC_BUFFER_SIZE / (sizeof (FLAC__int32) * psf->sf.channels) ;
+ bufferlen = ENC_BUFFER_SIZE / (sizeof (int32_t) * psf->sf.channels) ;
bufferlen *= psf->sf.channels ;
while (len > 0)
static sf_count_t
flac_write_i2flac (SF_PRIVATE *psf, const int *ptr, sf_count_t len)
{ FLAC_PRIVATE* pflac = (FLAC_PRIVATE*) psf->codec_data ;
- void (*convert) (const int *, FLAC__int32 *, int) ;
+ void (*convert) (const int *, int32_t *, int) ;
int bufferlen, writecount, thiswrite ;
sf_count_t total = 0 ;
- FLAC__int32* buffer = pflac->encbuffer ;
+ int32_t* buffer = pflac->encbuffer ;
switch (SF_CODEC (psf->sf.format))
{ case SF_FORMAT_PCM_S8 :
return -1 ;
} ;
- bufferlen = ENC_BUFFER_SIZE / (sizeof (FLAC__int32) * psf->sf.channels) ;
+ bufferlen = ENC_BUFFER_SIZE / (sizeof (int32_t) * psf->sf.channels) ;
bufferlen *= psf->sf.channels ;
while (len > 0)
static sf_count_t
flac_write_f2flac (SF_PRIVATE *psf, const float *ptr, sf_count_t len)
{ FLAC_PRIVATE* pflac = (FLAC_PRIVATE*) psf->codec_data ;
- void (*convert) (const float *, FLAC__int32 *, int, int) ;
+ void (*convert) (const float *, int32_t *, int, int) ;
int bufferlen, writecount, thiswrite ;
sf_count_t total = 0 ;
- FLAC__int32* buffer = pflac->encbuffer ;
+ int32_t* buffer = pflac->encbuffer ;
switch (SF_CODEC (psf->sf.format))
{ case SF_FORMAT_PCM_S8 :
return -1 ;
} ;
- bufferlen = ENC_BUFFER_SIZE / (sizeof (FLAC__int32) * psf->sf.channels) ;
+ bufferlen = ENC_BUFFER_SIZE / (sizeof (int32_t) * psf->sf.channels) ;
bufferlen *= psf->sf.channels ;
while (len > 0)
} /* flac_write_f2flac */
static void
-f2flac8_clip_array (const float *src, FLAC__int32 *dest, int count, int normalize)
+f2flac8_clip_array (const float *src, int32_t *dest, int count, int normalize)
{ float normfact, scaled_value ;
normfact = normalize ? (8.0 * 0x10) : 1.0 ;
} /* f2flac8_clip_array */
static void
-f2flac16_clip_array (const float *src, FLAC__int32 *dest, int count, int normalize)
+f2flac16_clip_array (const float *src, int32_t *dest, int count, int normalize)
{ float normfact, scaled_value ;
normfact = normalize ? (8.0 * 0x1000) : 1.0 ;
} /* f2flac16_clip_array */
static void
-f2flac24_clip_array (const float *src, FLAC__int32 *dest, int count, int normalize)
+f2flac24_clip_array (const float *src, int32_t *dest, int count, int normalize)
{ float normfact, scaled_value ;
normfact = normalize ? (8.0 * 0x100000) : 1.0 ;
} /* f2flac24_clip_array */
static void
-f2flac8_array (const float *src, FLAC__int32 *dest, int count, int normalize)
+f2flac8_array (const float *src, int32_t *dest, int count, int normalize)
{ float normfact = normalize ? (1.0 * 0x7F) : 1.0 ;
while (--count >= 0)
} /* f2flac8_array */
static void
-f2flac16_array (const float *src, FLAC__int32 *dest, int count, int normalize)
+f2flac16_array (const float *src, int32_t *dest, int count, int normalize)
{ float normfact = normalize ? (1.0 * 0x7FFF) : 1.0 ;
while (--count >= 0)
} /* f2flac16_array */
static void
-f2flac24_array (const float *src, FLAC__int32 *dest, int count, int normalize)
+f2flac24_array (const float *src, int32_t *dest, int count, int normalize)
{ float normfact = normalize ? (1.0 * 0x7FFFFF) : 1.0 ;
while (--count >= 0)
static sf_count_t
flac_write_d2flac (SF_PRIVATE *psf, const double *ptr, sf_count_t len)
{ FLAC_PRIVATE* pflac = (FLAC_PRIVATE*) psf->codec_data ;
- void (*convert) (const double *, FLAC__int32 *, int, int) ;
+ void (*convert) (const double *, int32_t *, int, int) ;
int bufferlen, writecount, thiswrite ;
sf_count_t total = 0 ;
- FLAC__int32* buffer = pflac->encbuffer ;
+ int32_t* buffer = pflac->encbuffer ;
switch (SF_CODEC (psf->sf.format))
{ case SF_FORMAT_PCM_S8 :
return -1 ;
} ;
- bufferlen = ENC_BUFFER_SIZE / (sizeof (FLAC__int32) * psf->sf.channels) ;
+ bufferlen = ENC_BUFFER_SIZE / (sizeof (int32_t) * psf->sf.channels) ;
bufferlen *= psf->sf.channels ;
while (len > 0)
} /* flac_write_d2flac */
static void
-d2flac8_clip_array (const double *src, FLAC__int32 *dest, int count, int normalize)
+d2flac8_clip_array (const double *src, int32_t *dest, int count, int normalize)
{ double normfact, scaled_value ;
normfact = normalize ? (8.0 * 0x10) : 1.0 ;
} /* d2flac8_clip_array */
static void
-d2flac16_clip_array (const double *src, FLAC__int32 *dest, int count, int normalize)
+d2flac16_clip_array (const double *src, int32_t *dest, int count, int normalize)
{ double normfact, scaled_value ;
normfact = normalize ? (8.0 * 0x1000) : 1.0 ;
} /* d2flac16_clip_array */
static void
-d2flac24_clip_array (const double *src, FLAC__int32 *dest, int count, int normalize)
+d2flac24_clip_array (const double *src, int32_t *dest, int count, int normalize)
{ double normfact, scaled_value ;
normfact = normalize ? (8.0 * 0x100000) : 1.0 ;
} /* d2flac24_clip_array */
static void
-d2flac8_array (const double *src, FLAC__int32 *dest, int count, int normalize)
+d2flac8_array (const double *src, int32_t *dest, int count, int normalize)
{ double normfact = normalize ? (1.0 * 0x7F) : 1.0 ;
while (--count >= 0)
} /* d2flac8_array */
static void
-d2flac16_array (const double *src, FLAC__int32 *dest, int count, int normalize)
+d2flac16_array (const double *src, int32_t *dest, int count, int normalize)
{ double normfact = normalize ? (1.0 * 0x7FFF) : 1.0 ;
while (--count >= 0)
} /* d2flac16_array */
static void
-d2flac24_array (const double *src, FLAC__int32 *dest, int count, int normalize)
+d2flac24_array (const double *src, int32_t *dest, int count, int normalize)
{ double normfact = normalize ? (1.0 * 0x7FFFFF) : 1.0 ;
while (--count >= 0)
} /* flac_byterate */
-#else /* HAVE_EXTERNAL_LIBS */
+#else /* HAVE_EXTERNAL_XIPH_LIBS */
int
flac_open (SF_PRIVATE *psf)