Commit 1ef71a9b authored by Alessio Treglia's avatar Alessio Treglia

Imported Upstream version 1.7.0

parent c6da9494
This diff is collapsed.
SOUND_DIR=~/dev/test_sounds
OUT_DIR=./test_out
TEST_NAME=semmari
OUT_NAME=out
SS=./soundstretch
TEST_PARAM="-pitch=-3 -bpm"
mkdir $OUT_DIR
$SS $SOUND_DIR/$TEST_NAME-8b1.wav $OUT_DIR/$OUT_NAME-8b1.wav $TEST_PARAM
$SS $SOUND_DIR/$TEST_NAME-8b2.wav $OUT_DIR/$OUT_NAME-8b2.wav $TEST_PARAM
$SS $SOUND_DIR/$TEST_NAME-16b1.wav $OUT_DIR/$OUT_NAME-16b1.wav $TEST_PARAM
$SS $SOUND_DIR/$TEST_NAME-16b2.wav $OUT_DIR/$OUT_NAME-16b2.wav $TEST_PARAM
$SS $SOUND_DIR/$TEST_NAME-24b1.wav $OUT_DIR/$OUT_NAME-24b1.wav $TEST_PARAM
$SS $SOUND_DIR/$TEST_NAME-24b2.wav $OUT_DIR/$OUT_NAME-24b2.wav $TEST_PARAM
$SS $SOUND_DIR/$TEST_NAME-32b1.wav $OUT_DIR/$OUT_NAME-32b1.wav $TEST_PARAM
$SS $SOUND_DIR/$TEST_NAME-32b2.wav $OUT_DIR/$OUT_NAME-32b2.wav $TEST_PARAM
set SOUND_DIR=d:\dev\test_sounds
set OUT_DIR=.
set TEST_NAME=semmari
set OUT_NAME=out
set SS=soundstretch
set TEST_PARAM=-pitch=-3 -bpm
call %SS% %SOUND_DIR%\%TEST_NAME%-8b1.wav %OUT_DIR%\%OUT_NAME%-8b1.wav %TEST_PARAM%
call %SS% %SOUND_DIR%\%TEST_NAME%-8b2.wav %OUT_DIR%\%OUT_NAME%-8b2.wav %TEST_PARAM%
call %SS% %SOUND_DIR%\%TEST_NAME%-16b1.wav %OUT_DIR%\%OUT_NAME%-16b1.wav %TEST_PARAM%
call %SS% %SOUND_DIR%\%TEST_NAME%-16b2.wav %OUT_DIR%\%OUT_NAME%-16b2.wav %TEST_PARAM%
call %SS% %SOUND_DIR%\%TEST_NAME%-24b1.wav %OUT_DIR%\%OUT_NAME%-24b1.wav %TEST_PARAM%
call %SS% %SOUND_DIR%\%TEST_NAME%-24b2.wav %OUT_DIR%\%OUT_NAME%-24b2.wav %TEST_PARAM%
call %SS% %SOUND_DIR%\%TEST_NAME%-32b1.wav %OUT_DIR%\%OUT_NAME%-32b1.wav %TEST_PARAM%
call %SS% %SOUND_DIR%\%TEST_NAME%-32b2.wav %OUT_DIR%\%OUT_NAME%-32b2.wav %TEST_PARAM%
## vim:tw=78
## Process this file with automake to create Makefile.in
##
## $Id: am_include.mk 37 2008-12-25 16:33:39Z oparviai $
## $Id: am_include.mk 130 2011-07-17 11:46:22Z oparviai $
##
## Copyright (C) 2003 - David W. Durham
##
## This file is part of SoundTouch, an audio processing library for pitch/time adjustments
##
## SoundTouch is free software; you can redistribute it and/or modify it under the
......
dnl SoundTouch configure.ac, by David W. Durham
dnl
dnl $Id: configure.ac 104 2011-02-13 19:13:57Z oparviai $
dnl $Id: configure.ac 141 2012-04-04 19:47:28Z oparviai $
dnl
dnl This file is part of SoundTouch, an audio processing library for pitch/time adjustments
dnl
......@@ -19,11 +19,12 @@ dnl this program; if not, write to the Free Software Foundation, Inc., 59 Temple
dnl Place - Suite 330, Boston, MA 02111-1307, USA
# Process this file with autoconf to produce a configure script.
AC_INIT(SoundTouch, 1.6.0, [http://www.surina.net/soundtouch])
AC_INIT(SoundTouch, 1.7.0, [http://www.surina.net/soundtouch])
AC_CONFIG_AUX_DIR(config)
AM_CONFIG_HEADER([include/soundtouch_config.h])
AM_INIT_AUTOMAKE
AC_DISABLE_SHARED dnl This makes libtool only build static libs
#AC_DISABLE_SHARED dnl This makes libtool only build static libs
AC_DISABLE_STATIC dnl This makes libtool only build shared libs
#AC_GNU_SOURCE dnl enable posix extensions in glibc
AC_LANG(C++)
......@@ -55,12 +56,14 @@ dnl ############################################################################
AC_HEADER_STDC
#AC_HEADER_SYS_WAIT
# add any others you want to check for here
#AC_CHECK_HEADERS([fcntl.h limits.h stddef.h stdlib.h string.h sys/ioctl.h sys/vfs.h unistd.h])
AC_CHECK_HEADERS([cpuid.h])
if test "x$ac_cv_header_cpuid_h" = "xno"; then
AC_MSG_WARN([The cpuid.h file was not found therefore the x86 optimizations will be disabled.])
AC_MSG_WARN([If using a x86 architecture and optimizations are desired then please install gcc (>= 4.3).])
AC_MSG_WARN([If using a non-x86 architecture then this is expected and can be ignored.])
fi
dnl ############################################################################
dnl # Checks for typedefs, structures, and compiler characteristics $
......@@ -77,7 +80,21 @@ AC_ARG_ENABLE(integer-samples,
[default=yes]])],,
[enable_integer_samples=no])
# Let the user enable/disable the x86 optimizations.
# Useful when compiling on non-x86 architectures.
AC_ARG_ENABLE([x86-optimizations],
[AS_HELP_STRING([--enable-x86-optimizations],
[use MMX or SSE optimization
[default=yes]])],[enable_x86_optimizations="${enableval}"],
[enable_x86_optimizations=yes])
# Tell the Makefile.am if the user wants to disable optimizations.
# Makefile.am will enable them by default if support is available.
# Note: We check if optimizations are supported a few lines down.
AM_CONDITIONAL([X86_OPTIMIZATIONS], [test "x$enable_x86_optimizations" = "xyes"])
if test "x$enable_integer_samples" = "xyes"; then
echo "****** Integer sample type enabled ******"
AC_DEFINE(SOUNDTOUCH_INTEGER_SAMPLES,1,[Use Integer as Sample type])
......@@ -87,6 +104,93 @@ else
fi
# Check if optimizations are supported in the system at build time.
if test "x$enable_x86_optimizations" = "xyes" -a "x$ac_cv_header_cpuid_h" = "xyes"; then
echo "****** x86 optimizations enabled ******"
original_saved_CXXFLAGS=$CXXFLAGS
have_mmx_intrinsics=no
OPT_CXXFLAGS="-mmmx -Winline"
CXXFLAGS="$OPT_CXXFLAGS $CXXFLAGS"
# Check if the user can compile MMX code using intrinsics.
# GCC supports MMX intrinsics since version 3.3
# A more recent GCC (>= 4.3) is recommended.
AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
#if defined(__GNUC__) && (__GNUC__ < 3 || (__GNUC__ == 3 && __GNUC_MINOR__ < 3))
#error "Need GCC >= 3.3 for MMX intrinsics"
#endif
#include <mmintrin.h>
int main () {
__m64 loop = _mm_cvtsi32_si64 (1);
return _mm_cvtsi64_si32 (loop);
}]])],[have_mmx_intrinsics=yes])
CXXFLAGS=$original_saved_CXXFLAGS
# Inform the user if we did or did not find MMX support.
#
# If we enable optimization and integer samples we only require MMX.
# Disable optimizations in the SSTypes.h file if this is not the case.
if test "x$have_mmx_intrinsics" = "xyes" ; then
echo "****** MMX support found ******"
else
echo "****** No MMX support found ******"
if test "x$enable_integer_samples" = "xyes"; then
echo "****** Disabling optimizations. Using integer samples with no MMX support ******"
AC_DEFINE([SOUNDTOUCH_DISABLE_X86_OPTIMIZATIONS],[1],[Do not use x86 optimizations])
fi
fi
have_sse_intrinsics=no
OPT_CXXFLAGS="-msse -Winline"
CXXFLAGS="$OPT_CXXFLAGS $CXXFLAGS"
# Check if the user can compile SSE code using intrinsics.
# GCC supports SSE intrinsics since version 3.3
# A more recent GCC (>= 4.3) is recommended.
AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
#if defined(__GNUC__) && (__GNUC__ < 3 || (__GNUC__ == 3 && __GNUC_MINOR__ < 3))
#error "Need GCC >= 3.3 for SSE intrinsics"
#endif
#include <xmmintrin.h>
int main () {
_mm_setzero_ps();
return 0;
}]])],[have_sse_intrinsics=yes])
CXXFLAGS=$original_saved_CXXFLAGS
# Inform the user if we did or did not find SSE support.
#
# If we enable optimization and float samples we only require SSE.
# Disable optimizations in the SSTypes.h file if this is not the case.
if test "x$have_sse_intrinsics" = "xyes" ; then
echo "****** SSE support found ******"
else
echo "****** No SSE support found ******"
if test "x$enable_integer_samples" != "xyes"; then
echo "****** Disabling optimizations. Using float samples with no SSE support ******"
AC_DEFINE([SOUNDTOUCH_DISABLE_X86_OPTIMIZATIONS],[1],[Do not use x86 optimizations])
fi
fi
else
# Disable optimizations in SSTypes.h since the user requested it.
echo "****** x86 optimizations disabled ******"
AC_DEFINE([SOUNDTOUCH_DISABLE_X86_OPTIMIZATIONS],[1],[Do not use x86 optimizations])
fi
# SSTypes.h by default enables optimizations. Those already got disabled if
# the user requested for it or if the system does not support them.
#
# Now tell the Makefile.am the optimizations that are supported.
# Note:
# Makefile.am already knows if the user asked for optimizations. We apply
# optimizations by default (if support is available) and then disable all of
# them if the user requested it.
AM_CONDITIONAL([HAVE_MMX], [test "x$have_mmx_intrinsics" = "xyes"])
AM_CONDITIONAL([HAVE_SSE], [test "x$have_sse_intrinsics" = "xyes"])
dnl ############################################################################
dnl # Checks for library functions/classes #
......
......@@ -26,10 +26,10 @@
///
////////////////////////////////////////////////////////////////////////////////
//
// Last changed : $Date: 2010-01-06 20:59:23 +0200 (Wed, 06 Jan 2010) $
// Last changed : $Date: 2012-08-30 22:53:44 +0300 (Thu, 30 Aug 2012) $
// File revision : $Revision: 4 $
//
// $Id: BPMDetect.h 86 2010-01-06 18:59:23Z oparviai $
// $Id: BPMDetect.h 150 2012-08-30 19:53:44Z oparviai $
//
////////////////////////////////////////////////////////////////////////////////
//
......@@ -67,7 +67,7 @@ namespace soundtouch
#define MIN_BPM 29
/// Maximum allowed BPM rate. Used to restrict accepted result below a reasonable limit.
#define MAX_BPM 230
#define MAX_BPM 200
/// Class for calculating BPM rate for audio data.
......@@ -83,15 +83,6 @@ protected:
/// RMS volume sliding average approximation level accumulator
double RMSVolumeAccu;
/// Level below which to cut off signals
double cutCoeff;
/// Accumulator for accounting what proportion of samples exceed cutCoeff level
double aboveCutAccu;
/// Accumulator for total samples to calculate proportion of samples that exceed cutCoeff level
double totalAccu;
/// Sample average counter.
int decimateCount;
......@@ -137,6 +128,9 @@ protected:
int numsamples ///< Number of samples in buffer
);
/// remove constant bias from xcorr data
void removeBias();
public:
/// Constructor.
BPMDetect(int numChannels, ///< Number of channels in sample data.
......
......@@ -15,10 +15,10 @@
///
////////////////////////////////////////////////////////////////////////////////
//
// Last changed : $Date: 2009-02-21 18:00:14 +0200 (Sat, 21 Feb 2009) $
// Last changed : $Date: 2012-06-13 22:29:53 +0300 (Wed, 13 Jun 2012) $
// File revision : $Revision: 4 $
//
// $Id: FIFOSampleBuffer.h 63 2009-02-21 16:00:14Z oparviai $
// $Id: FIFOSampleBuffer.h 143 2012-06-13 19:29:53Z oparviai $
//
////////////////////////////////////////////////////////////////////////////////
//
......@@ -89,7 +89,7 @@ private:
/// Returns current capacity.
uint getCapacity() const;
public:
/// Constructor
......@@ -167,6 +167,10 @@ public:
/// Clears all the samples.
virtual void clear();
/// allow trimming (downwards) amount of samples in pipeline.
/// Returns adjusted amount of samples
uint adjustAmountOfSamples(uint numSamples);
};
}
......
......@@ -17,10 +17,10 @@
///
////////////////////////////////////////////////////////////////////////////////
//
// Last changed : $Date: 2009-04-13 16:18:48 +0300 (Mon, 13 Apr 2009) $
// Last changed : $Date: 2012-06-13 22:29:53 +0300 (Wed, 13 Jun 2012) $
// File revision : $Revision: 4 $
//
// $Id: FIFOSamplePipe.h 69 2009-04-13 13:18:48Z oparviai $
// $Id: FIFOSamplePipe.h 143 2012-06-13 19:29:53Z oparviai $
//
////////////////////////////////////////////////////////////////////////////////
//
......@@ -114,6 +114,11 @@ public:
/// Clears all the samples.
virtual void clear() = 0;
/// allow trimming (downwards) amount of samples in pipeline.
/// Returns adjusted amount of samples
virtual uint adjustAmountOfSamples(uint numSamples) = 0;
};
......@@ -214,6 +219,14 @@ public:
{
return output->isEmpty();
}
/// allow trimming (downwards) amount of samples in pipeline.
/// Returns adjusted amount of samples
virtual uint adjustAmountOfSamples(uint numSamples)
{
return output->adjustAmountOfSamples(numSamples);
}
};
}
......
......@@ -8,10 +8,10 @@
///
////////////////////////////////////////////////////////////////////////////////
//
// Last changed : $Date: 2011-07-16 11:45:37 +0300 (Sat, 16 Jul 2011) $
// Last changed : $Date: 2012-04-01 20:01:42 +0300 (Sun, 01 Apr 2012) $
// File revision : $Revision: 3 $
//
// $Id: STTypes.h 119 2011-07-16 08:45:37Z oparviai $
// $Id: STTypes.h 136 2012-04-01 17:01:42Z oparviai $
//
////////////////////////////////////////////////////////////////////////////////
//
......@@ -86,7 +86,7 @@ namespace soundtouch
#endif
#if (WIN32 || __i386__ || __x86_64__)
#if (_M_IX86 || __i386__ || __x86_64__ || _M_X64)
/// Define this to allow X86-specific assembler/intrinsic optimizations.
/// Notice that library contains also usual C++ versions of each of these
/// these routines, so if you're having difficulties getting the optimized
......@@ -95,6 +95,17 @@ namespace soundtouch
#define SOUNDTOUCH_ALLOW_X86_OPTIMIZATIONS 1
/// In GNU environment, allow the user to override this setting by
/// giving the following switch to the configure script:
/// ./configure --disable-x86-optimizations
/// ./configure --enable-x86-optimizations=no
#ifdef SOUNDTOUCH_DISABLE_X86_OPTIMIZATIONS
#undef SOUNDTOUCH_ALLOW_X86_OPTIMIZATIONS
#endif
#else
/// Always disable optimizations when not using a x86 systems.
#undef SOUNDTOUCH_ALLOW_X86_OPTIMIZATIONS
#endif
// If defined, allows the SIMD-optimized routines to take minor shortcuts
......@@ -132,8 +143,20 @@ namespace soundtouch
#endif
#endif // SOUNDTOUCH_INTEGER_SAMPLES
};
// define ST_NO_EXCEPTION_HANDLING switch to disable throwing std exceptions:
// #define ST_NO_EXCEPTION_HANDLING 1
#ifdef ST_NO_EXCEPTION_HANDLING
// Exceptions disabled. Throw asserts instead if enabled.
#include <assert.h>
#define ST_THROW_RT_ERROR(x) {assert((const char *)x);}
#else
// use c++ standard exceptions
#include <stdexcept>
#define ST_THROW_RT_ERROR(x) {throw std::runtime_error(x);}
#endif
// When this #define is active, eliminates a clicking sound when the "rate" or "pitch"
// parameter setting crosses from value <1 to >=1 or vice versa during processing.
......
......@@ -41,10 +41,10 @@
///
////////////////////////////////////////////////////////////////////////////////
//
// Last changed : $Date: 2011-07-15 22:27:10 +0300 (Fri, 15 Jul 2011) $
// Last changed : $Date: 2012-04-04 22:47:28 +0300 (Wed, 04 Apr 2012) $
// File revision : $Revision: 4 $
//
// $Id: SoundTouch.h 107 2011-07-15 19:27:10Z oparviai $
// $Id: SoundTouch.h 141 2012-04-04 19:47:28Z oparviai $
//
////////////////////////////////////////////////////////////////////////////////
//
......@@ -79,10 +79,10 @@ namespace soundtouch
{
/// Soundtouch library version string
#define SOUNDTOUCH_VERSION "1.6.0"
#define SOUNDTOUCH_VERSION "1.7.0"
/// SoundTouch library version id
#define SOUNDTOUCH_VERSION_ID (10600)
#define SOUNDTOUCH_VERSION_ID (10700)
//
// Available setting IDs for the 'setSetting' & 'get_setting' functions:
......
......@@ -7,7 +7,7 @@
@REM Copyright (c) Olli Parviainen
@REM File Created: 09/Sep/2003
@REM
@REM $Id: make-win.bat 98 2010-12-12 19:17:13Z oparviai $
@REM $Id: make-win.bat 142 2012-04-04 19:55:37Z oparviai $
@rem ****************************
@rem try first for VS6.0 support
......@@ -52,8 +52,9 @@ echo *********************************************************************
echo **
echo ** ERROR: Visual Studio path not set.
echo **
echo ** Run "vcvars32.bat" from Visual Studio installation directory, e.g.
echo ** "\Program Files\Microsoft Visual Studio\VC98\Bin", then try again.
echo ** Run "vsvars32.bat" or "vcvars32.bat" from Visual Studio installation
echo ** directory, e.g. "\Program Files\Microsoft Visual Studio\VC98\Bin",
echo ** then try again.
echo **
echo *********************************************************************
......
## Process this file with automake to create Makefile.in
##
## $Id: Makefile.am 43 2008-12-25 17:54:41Z oparviai $
## $Id: Makefile.am 128 2011-07-17 10:59:56Z oparviai $
##
## Copyright (C) 2003 - David W. Durham
##
......@@ -43,8 +43,9 @@ soundstretch_SOURCES=main.cpp RunParameters.cpp WavFile.cpp
## linker.
soundstretch_LDADD=../SoundTouch/libSoundTouch.la -lm
## linker flags
soundstretch_LDFLAGS=-s
## linker flags.
# OP 2011-7-17 Linker flags disabled to prevent stripping symbols by default
# soundstretch_LDFLAGS=-s
## additional compiler flags
soundstretch_CXXFLAGS=-O3
......
......@@ -8,10 +8,10 @@
///
////////////////////////////////////////////////////////////////////////////////
//
// Last changed : $Date: 2009-05-17 19:48:30 +0300 (Sun, 17 May 2009) $
// Last changed : $Date: 2011-09-02 21:56:11 +0300 (Fri, 02 Sep 2011) $
// File revision : $Revision: 4 $
//
// $Id: RunParameters.cpp 72 2009-05-17 16:48:30Z oparviai $
// $Id: RunParameters.cpp 131 2011-09-02 18:56:11Z oparviai $
//
////////////////////////////////////////////////////////////////////////////////
//
......@@ -36,7 +36,6 @@
//
////////////////////////////////////////////////////////////////////////////////
#include <stdexcept>
#include <string>
#include <stdlib.h>
......@@ -120,7 +119,7 @@ RunParameters::RunParameters(const int nParams, const char * const paramStr[])
}
string msg = whatText;
msg += usage;
throw runtime_error(msg.c_str());
ST_THROW_RT_ERROR(msg.c_str());
}
inFileName = NULL;
......@@ -200,14 +199,14 @@ void RunParameters::throwIllegalParamExp(const string &str) const
msg += str;
msg += "\".\n\n";
msg += usage;
throw runtime_error(msg.c_str());
ST_THROW_RT_ERROR(msg.c_str());
}
void RunParameters::throwLicense() const
{
throw runtime_error(licenseText);
ST_THROW_RT_ERROR(licenseText);
}
......
This diff is collapsed.
......@@ -16,10 +16,10 @@
///
////////////////////////////////////////////////////////////////////////////////
//
// Last changed : $Date: 2009-02-21 18:00:14 +0200 (Sat, 21 Feb 2009) $
// Last changed : $Date: 2012-09-01 10:57:22 +0300 (Sat, 01 Sep 2012) $
// File revision : $Revision: 4 $
//
// $Id: WavFile.h 63 2009-02-21 16:00:14Z oparviai $
// $Id: WavFile.h 153 2012-09-01 07:57:22Z oparviai $
//
////////////////////////////////////////////////////////////////////////////////
//
......@@ -92,15 +92,35 @@ typedef struct
} WavHeader;
/// Base class for processing WAV audio files.
class WavFileBase
{
private:
/// Conversion working buffer;
char *convBuff;
int convBuffSize;
protected:
WavFileBase();
virtual ~WavFileBase();
/// Get pointer to conversion buffer of at min. given size
void *getConvBuffer(int sizeByte);
};
/// Class for reading WAV audio files.
class WavInFile
class WavInFile : protected WavFileBase
{
private:
/// File pointer.
FILE *fptr;
/// Position within the audio stream
long position;
/// Counter of how many bytes of sample data have been read from the file.
uint dataRead;
long dataRead;
/// WAV header information
WavHeader header;
......@@ -158,12 +178,17 @@ public:
/// Get the audio file length in milliseconds
uint getLengthMS() const;
/// Returns how many milliseconds of audio have so far been read from the file
///
/// \return elapsed duration in milliseconds
uint getElapsedMS() const;
/// Reads audio samples from the WAV file. This routine works only for 8 bit samples.
/// Reads given number of elements from the file or if end-of-file reached, as many
/// elements as are left in the file.
///
/// \return Number of 8-bit integers read from the file.
int read(char *buffer, int maxElems);
int read(unsigned char *buffer, int maxElems);
/// Reads audio samples from the WAV file to 16 bit integer format. Reads given number
/// of elements from the file or if end-of-file reached, as many elements as are
......@@ -177,6 +202,7 @@ public:
/// Reads audio samples from the WAV file to floating point format, converting
/// sample values to range [-1,1[. Reads given number of elements from the file
/// or if end-of-file reached, as many elements as are left in the file.
/// Notice that reading in float format supports 8/16/24/32bit sample formats.
///
/// \return Number of elements read from the file.
int read(float *buffer, ///< Pointer to buffer where to read data.
......@@ -192,7 +218,7 @@ public:
/// Class for writing WAV audio files.
class WavOutFile
class WavOutFile : protected WavFileBase
{
private:
/// Pointer to the WAV file
......@@ -230,8 +256,8 @@ public:
/// Write data to WAV file. This function works only with 8bit samples.
/// Throws a 'runtime_error' exception if writing to file fails.
void write(const char *buffer, ///< Pointer to sample data buffer.
int numElems ///< How many array items are to be written to file.
void write(const unsigned char *buffer, ///< Pointer to sample data buffer.
int numElems ///< How many array items are to be written to file.
);
/// Write data to WAV file. Throws a 'runtime_error' exception if writing to
......
......@@ -8,10 +8,10 @@
///
////////////////////////////////////////////////////////////////////////////////
//
// Last changed : $Date: 2011-07-16 11:55:23 +0300 (Sat, 16 Jul 2011) $
// Last changed : $Date: 2012-04-04 22:47:28 +0300 (Wed, 04 Apr 2012) $
// File revision : $Revision: 4 $
//
// $Id: main.cpp 121 2011-07-16 08:55:23Z oparviai $
// $Id: main.cpp 141 2012-04-04 19:47:28Z oparviai $
//
////////////////////////////////////////////////////////////////////////////////
//
......@@ -39,6 +39,7 @@
#include <stdexcept>
#include <stdio.h>
#include <string.h>
#include <time.h>
#include "RunParameters.h"
#include "WavFile.h"
#include "SoundTouch.h"
......@@ -50,7 +51,7 @@ using namespace std;
// Processing chunk size
#define BUFF_SIZE 2048
#if WIN32
#if _WIN32
#include <io.h>
#include <fcntl.h>
......@@ -64,7 +65,7 @@ using namespace std;
static const char _helloText[] =
"\n"
" SoundStretch v%s - Written by Olli Parviainen 2001 - 2011\n"
" SoundStretch v%s - Written by Olli Parviainen 2001 - 2012\n"
"==================================================================\n"
"author e-mail: <oparviai"
"@"
......@@ -172,7 +173,6 @@ static void setup(SoundTouch *pSoundTouch, const WavInFile *inFile, const RunPar
// Processes the sound
static void process(SoundTouch *pSoundTouch, WavInFile *inFile, WavOutFile *outFile)
{
......@@ -309,8 +309,11 @@ int main(const int nParams, const char * const paramStr[])
// Setup the 'SoundTouch' object for processing the sound
setup(&soundTouch, inFile, params);
// clock_t cs = clock(); // for benchmarking processing duration
// Process the sound
process(&soundTouch, inFile, outFile);
// clock_t ce = clock(); // for benchmarking processing duration
// printf("duration: %lf\n", (double)(ce-cs)/CLOCKS_PER_SEC);
// Close WAV file handles & dispose of the objects
delete inFile;
......
......@@ -26,10 +26,10 @@
///
////////////////////////////////////////////////////////////////////////////////
//
// Last changed : $Date: 2011-07-13 11:07:14 +0300 (Wed, 13 Jul 2011) $
// Last changed : $Date: 2012-08-30 22:45:25 +0300 (Thu, 30 Aug 2012) $
// File revision : $Revision: 4 $
//
// $Id: BPMDetect.cpp 105 2011-07-13 08:07:14Z oparviai $
// $Id: BPMDetect.cpp 149 2012-08-30 19:45:25Z oparviai $
//
////////////////////////////////////////////////////////////////////////////////
//
......@@ -117,23 +117,19 @@ BPMDetect::BPMDetect(int numChannels, int aSampleRate)
envelopeAccu = 0;
// Initialize RMS volume accumulator to RMS level of 3000 (out of 32768) that's
// a typical RMS signal level value for song data. This value is then adapted
// Initialize RMS volume accumulator to RMS level of 1500 (out of 32768) that's
// safe initial RMS signal level value for song data. This value is then adapted
// to the actual level during processing.
#ifdef SOUNDTOUCH_INTEGER_SAMPLES
// integer samples
RMSVolumeAccu = (3000 * 3000) / avgnorm;
RMSVolumeAccu = (1500 * 1500) / avgnorm;
#else
// float samples, scaled to range [-1..+1[
RMSVolumeAccu = (0.092f * 0.092f) / avgnorm;
RMSVolumeAccu = (0.045f * 0.045f) / avgnorm;
#endif
cutCoeff = 1.75;
aboveCutAccu = 0;
totalAccu = 0;
// choose decimation factor so that result is approx. 500 Hz
decimateBy = sampleRate / 500;
// choose decimation factor so that result is approx. 1000 Hz
decimateBy = sampleRate / 1000;
assert(decimateBy > 0);
assert(INPUT_BLOCK_SAMPLES < decimateBy * DECIMATED_BLOCK_SAMPLES);
......@@ -270,31 +266,11 @@ void BPMDetect::calcEnvelope(SAMPLETYPE *samples, int numsamples)
// cut amplitudes that are below cutoff ~2 times RMS volume
// (we're interested in peak values, not the silent moments)
val -= cutCoeff * sqrt(RMSVolumeAccu * avgnorm);
if (val > 0)
{
aboveCutAccu += 1.0; // sample above threshold
}
else
if (val < 0.5 * sqrt(RMSVolumeAccu * avgnorm))
{
val = 0;
}
totalAccu += 1.0;
// maintain sliding statistic what proportion of 'val' samples is
// above cutoff threshold
aboveCutAccu *= 0.99931; // 2 sec time constant
totalAccu *= 0.99931;
if (totalAccu > 500)
{
// after initial settling, auto-adjust cutoff level so that ~8% of
// values are above the threshold
double d = (aboveCutAccu / totalAccu) - 0.08;
cutCoeff += 0.001 * d;
}
// smooth amplitude envelope
envelopeAccu *= decay;
envelopeAccu += val;
......@@ -306,12 +282,6 @@ void BPMDetect::calcEnvelope(SAMPLETYPE *samples, int numsamples)
#endif // SOUNDTOUCH_INTEGER_SAMPLES
samples[i] = (SAMPLETYPE)out;
}
// check that cutoff doesn't get too small - it can be just silent sequence!
if (cutCoeff < 1.5)
{
cutCoeff = 1.5;
}
}
......@@ -355,6 +325,26 @@ void BPMDetect::inputSamples(const SAMPLETYPE *samples, int numSamples)
void BPMDetect::removeBias()
{
int i;
float minval = 1e12f; // arbitrary large number
for (i = windowStart; i < windowLen; i ++)
{
if (xcorr[i] < minval)
{
minval = xcorr[i];