Commit 6bf299d2 authored by Sebastian Ramacher's avatar Sebastian Ramacher

New upstream version 2.0.0

parent e2217923
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
......@@ -13,8 +13,8 @@
</head>
<body class="normal">
<hr>
<h1>SoundTouch audio processing library v1.9.2</h1>
<p class="normal">SoundTouch library Copyright © Olli Parviainen 2001-2015</p>
<h1>SoundTouch audio processing library v2.0</h1>
<p class="normal">SoundTouch library Copyright © Olli Parviainen 2001-2017</p>
<hr>
<h2>1. Introduction </h2>
<p>SoundTouch is an open-source audio processing library that allows
......@@ -55,6 +55,9 @@ instead of the make-win.bat script, directories bin and lib may need to
be created manually to the SoundTouch package root for the final
executables. The make-win.bat script creates these directories
automatically. </p>
<p><strong>C# example</strong>: The source code package includes also a C# example
application for Windows that shows how to invoke SoundTouch.dll
dynamic-load library for processing mp3 audio.
<p><strong>OpenMP NOTE</strong>: If activating the OpenMP parallel computing in
the compilation, the target program will require additional vcomp dll library to
properly run. In Visual C++ 9.0 these libraries can be found in the following
......@@ -156,7 +159,7 @@ directly and remove the following definition:<blockquote>
sstrip SoundTouch.dll</pre>
</blockquote>
<h3>2.1. Building in Android</h3>
<h3>2.3. Building in Android</h3>
<p>Android compilation instructions are within the
source code package, see file &quot;<b>source/Android-lib/README-SoundTouch-Android.html</b>&quot;
in the source code package. </p>
......@@ -377,7 +380,10 @@ processors vs. non-SIMD implementation:</p>
<p>SoundTouch 1.9 onwards support running the algorithms parallel in several CPU
cores. Based on benchmark the experienced multi-core processing speed-up gain
ranges between +30% (on a high-spec dual-core x86 Windows PC) to 215% (on a moderately low-spec
quad-core ARM of Raspberry Pi2).</p>
quad-core ARM of Raspberry Pi2). </p>
<p>See an external blog article with more detailed discussion about the
<a href="http://www.softwarecoven.com/parallel-computing-in-embedded-mobile-devices/">
SoundTouch OpenMP optimization</a>.</p>
<p>The parallel computing support is implemented using OpenMP spec 3.0
instructions. These instructions are supported by Visual C++ 2008 and later, and
GCC v4.2 and later. Compilers that do not supporting OpenMP will ignore these
......@@ -567,6 +573,16 @@ this corresponds to lowering the pitch by -0.318 semitones:</p>
<hr>
<h2>5. Change History</h2>
<h3>5.1. SoundTouch library Change History </h3>
<p><b>2.0:</b></p>
<ul>
<li>Added functions to get initial processing latency, duration ratio between the original input and processed output tracks, and clarified reporting of input/output batch sizes</li>
<li>Fixed issue that added brief sequence of silence to beginning of output audio</li>
<li>Adjusted algorithm parameters to reduce reverberating effect at tempo slowdown</li>
<li>Bugfix: Fixed a glitch that could cause negative array indexing in quick seek algorithm</li>
<li>Bugfix: flush() didn't properly flush final samples from the pipeline on 2nd time in case that soundtouch object instance was recycled and used for processing a second audio stream.</li>
<li>Bugfix: Pi value had incorrect 9th/10th decimals</li>
<li>Added C# example application that uses SoundTouch dll library for processing MP3 files</li>
</ul>
<p><b>1.9.2:</b></p>
<ul>
<li>Fix in GNU package configuration</li>
......@@ -575,8 +591,8 @@ this corresponds to lowering the pitch by -0.318 semitones:</p>
<ul>
<li>Improved SoundTouch::flush() function so that it returns precisely the desired amount of samples for exact output duration control</li>
<li>Redesigned quickseek algorithm for improved sound quality when using the quickseek mode. The new quickseek algorithm can find 99% as good results as the
default full-scan mode, while the quickseek algorithm is remarkable less
CPU intensive.</li>
default full-scan mode, while the quickseek algorithm is remarkable less
CPU intensive.</li>
<li>Added adaptive integer divider scaling for improved sound quality when using integer processing algorithm
</li>
</ul>
......@@ -819,10 +835,12 @@ switch "-bpm"</li>
<p>Kudos for these people who have contributed to development or
submitted bugfixes:</p>
<ul>
<li> Arthur A</li>
<li> Arthur A</li>
<li> Paul Adenot</li>
<li> Richard Ash</li>
<li> Stanislav Brabec</li>
<li> Christian Budde</li>
<li> Jamie Bullock</li>
<li> Chris Bryan</li>
<li> Jacek Caban</li>
<li> Brian Cameron</li>
......@@ -830,23 +848,28 @@ submitted bugfixes:</p>
<li> David Clark</li>
<li> Patrick Colis</li>
<li> Miquel Colon</li>
<li> Jim Credland</li>
<li> Jim Credland</li>
<li> Sandro Cumerlato</li>
<li> Justin Frankel</li>
<li> Masa H.</li>
<li> Masa H.</li>
<li> Jason Garland</li>
<li> Takashi Iwai</li>
<li> Thomas Klausner</li>
<li> Mathias Möhl</li>
<li> Thomas Klausner</li>
<li> Tony Mechelynck </li>
<li> Mathias M&ouml;hl</li>
<li> Yuval Naveh</li>
<li> Mats Palmgren </li>
<li> Chandni Patel</li>
<li> Paulo Pizarro</li>
<li> Andrey Ponomarenko</li>
<li> Blaise Potard</li>
<li> Michael Pruett</li>
<li> Michael Pruett</li>
<li> Rajeev Puran</li>
<li> RJ Ryan</li>
<li> John Sheehy</li>
<li> RJ Ryan</li>
<li> John Sheehy</li>
<li> Tim Shuttleworth</li>
<li> Albert Sirvent</li>
<li> Tyson Smith</li>
<li> John Stumpo</li>
<li> Katja Vetter</li>
</ul>
......@@ -866,9 +889,9 @@ General Public License for more details.</p>
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA</p>
<hr><!--
$Id: README.html 230 2015-09-20 07:38:32Z oparviai $
$Id: README.html 253 2017-07-30 09:35:00Z oparviai $
-->
<p>
<i>README.html file updated in Sep-2015</i></p>
<i>README.html file updated in July-2017</i></p>
</body>
</html>
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
dnl SoundTouch configure.ac, by David W. Durham
dnl
dnl $Id: configure.ac 230 2015-09-20 07:38:32Z oparviai $
dnl $Id: configure.ac 253 2017-07-30 09:35:00Z oparviai $
dnl
dnl This file is part of SoundTouch, an audio processing library for pitch/time adjustments
dnl
......@@ -19,7 +19,7 @@ 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.9.2], [http://www.surina.net/soundtouch])
AC_INIT([SoundTouch], [2.0.0], [http://www.surina.net/soundtouch])
dnl Default to libSoundTouch.so.$LIB_SONAME.0.0
LIB_SONAME=1
AC_SUBST(LIB_SONAME)
......
......@@ -26,10 +26,10 @@
///
////////////////////////////////////////////////////////////////////////////////
//
// Last changed : $Date: 2012-08-30 22:53:44 +0300 (Thu, 30 Aug 2012) $
// Last changed : $Date: 2016-01-12 19:24:46 +0200 (ti, 12 tammi 2016) $
// File revision : $Revision: 4 $
//
// $Id: BPMDetect.h 150 2012-08-30 19:53:44Z oparviai $
// $Id: BPMDetect.h 239 2016-01-12 17:24:46Z oparviai $
//
////////////////////////////////////////////////////////////////////////////////
//
......@@ -77,12 +77,6 @@ protected:
/// Auto-correlation accumulator bins.
float *xcorr;
/// Amplitude envelope sliding average approximation level accumulator
double envelopeAccu;
/// RMS volume sliding average approximation level accumulator
double RMSVolumeAccu;
/// Sample average counter.
int decimateCount;
......
......@@ -15,7 +15,7 @@
///
////////////////////////////////////////////////////////////////////////////////
//
// Last changed : $Date: 2014-01-05 23:40:22 +0200 (Sun, 05 Jan 2014) $
// Last changed : $Date: 2014-01-05 23:40:22 +0200 (su, 05 tammi 2014) $
// File revision : $Revision: 4 $
//
// $Id: FIFOSampleBuffer.h 177 2014-01-05 21:40:22Z oparviai $
......
......@@ -17,7 +17,7 @@
///
////////////////////////////////////////////////////////////////////////////////
//
// Last changed : $Date: 2012-06-13 22:29:53 +0300 (Wed, 13 Jun 2012) $
// Last changed : $Date: 2012-06-13 22:29:53 +0300 (ke, 13 kesä 2012) $
// File revision : $Revision: 4 $
//
// $Id: FIFOSamplePipe.h 143 2012-06-13 19:29:53Z oparviai $
......
File mode changed from 100644 to 100755
......@@ -8,10 +8,10 @@
///
////////////////////////////////////////////////////////////////////////////////
//
// Last changed : $Date: 2015-05-18 18:25:07 +0300 (Mon, 18 May 2015) $
// Last changed : $Date: 2017-07-30 12:28:06 +0300 (su, 30 heinä 2017) $
// File revision : $Revision: 3 $
//
// $Id: STTypes.h 215 2015-05-18 15:25:07Z oparviai $
// $Id: STTypes.h 252 2017-07-30 09:28:06Z oparviai $
//
////////////////////////////////////////////////////////////////////////////////
//
......@@ -143,8 +143,10 @@ namespace soundtouch
#endif // SOUNDTOUCH_FLOAT_SAMPLES
#ifdef SOUNDTOUCH_ALLOW_X86_OPTIMIZATIONS
// Allow MMX optimizations
#define SOUNDTOUCH_ALLOW_MMX 1
// Allow MMX optimizations (not available in X64 mode)
#if (!_M_X64)
#define SOUNDTOUCH_ALLOW_MMX 1
#endif
#endif
#else
......
......@@ -41,10 +41,10 @@
///
////////////////////////////////////////////////////////////////////////////////
//
// Last changed : $Date: 2015-09-20 10:38:32 +0300 (Sun, 20 Sep 2015) $
// Last changed : $Date: 2017-07-30 12:35:00 +0300 (su, 30 heinä 2017) $
// File revision : $Revision: 4 $
//
// $Id: SoundTouch.h 230 2015-09-20 07:38:32Z oparviai $
// $Id: SoundTouch.h 253 2017-07-30 09:35:00Z oparviai $
//
////////////////////////////////////////////////////////////////////////////////
//
......@@ -79,10 +79,10 @@ namespace soundtouch
{
/// Soundtouch library version string
#define SOUNDTOUCH_VERSION "1.9.2"
#define SOUNDTOUCH_VERSION "2.0.0"
/// SoundTouch library version id
#define SOUNDTOUCH_VERSION_ID (10902)
#define SOUNDTOUCH_VERSION_ID (20000)
//
// Available setting IDs for the 'setSetting' & 'get_setting' functions:
......@@ -116,30 +116,61 @@ namespace soundtouch
#define SETTING_OVERLAP_MS 5
/// Call "getSetting" with this ID to query nominal average processing sequence
/// size in samples. This value tells approcimate value how many input samples
/// SoundTouch needs to gather before it does DSP processing run for the sample batch.
/// Call "getSetting" with this ID to query processing sequence size in samples.
/// This value gives approximate value of how many input samples you'll need to
/// feed into SoundTouch after initial buffering to get out a new batch of
/// output samples.
///
/// This value does not include initial buffering at beginning of a new processing
/// stream, use SETTING_INITIAL_LATENCY to get the initial buffering size.
///
/// Notices:
/// - This is read-only parameter, i.e. setSetting ignores this parameter
/// - Returned value is approximate average value, exact processing batch
/// size may wary from time to time
/// - This parameter value is not constant but may change depending on
/// - This parameter value is not constant but change depending on
/// tempo/pitch/rate/samplerate settings.
#define SETTING_NOMINAL_INPUT_SEQUENCE 6
#define SETTING_NOMINAL_INPUT_SEQUENCE 6
/// Call "getSetting" with this ID to query nominal average processing output
/// size in samples. This value tells approcimate value how many output samples
/// SoundTouch outputs once it does DSP processing run for a batch of input samples.
///
///
/// Notices:
/// - This is read-only parameter, i.e. setSetting ignores this parameter
/// - Returned value is approximate average value, exact processing batch
/// size may wary from time to time
/// - This parameter value is not constant but may change depending on
/// - This parameter value is not constant but change depending on
/// tempo/pitch/rate/samplerate settings.
#define SETTING_NOMINAL_OUTPUT_SEQUENCE 7
#define SETTING_NOMINAL_OUTPUT_SEQUENCE 7
/// Call "getSetting" with this ID to query initial processing latency, i.e.
/// approx. how many samples you'll need to enter to SoundTouch pipeline before
/// you can expect to get first batch of ready output samples out.
///
/// After the first output batch, you can then expect to get approx.
/// SETTING_NOMINAL_OUTPUT_SEQUENCE ready samples out for every
/// SETTING_NOMINAL_INPUT_SEQUENCE samples that you enter into SoundTouch.
///
/// Example:
/// processing with parameter -tempo=5
/// => initial latency = 5509 samples
/// input sequence = 4167 samples
/// output sequence = 3969 samples
///
/// Accordingly, you can expect to feed in approx. 5509 samples at beginning of
/// the stream, and then you'll get out the first 3969 samples. After that, for
/// every approx. 4167 samples that you'll put in, you'll receive again approx.
/// 3969 samples out.
///
/// This also means that average latency during stream processing is
/// INITIAL_LATENCY-OUTPUT_SEQUENCE/2, in the above example case 5509-3969/2
/// = 3524 samples
///
/// Notices:
/// - This is read-only parameter, i.e. setSetting ignores this parameter
/// - This parameter value is not constant but change depending on
/// tempo/pitch/rate/samplerate settings.
#define SETTING_INITIAL_LATENCY 8
class SoundTouch : public FIFOProcessor
{
......@@ -228,6 +259,24 @@ public:
/// Sets sample rate.
void setSampleRate(uint srate);
/// Get ratio between input and output audio durations, useful for calculating
/// processed output duration: if you'll process a stream of N samples, then
/// you can expect to get out N * getInputOutputSampleRatio() samples.
///
/// This ratio will give accurate target duration ratio for a full audio track,
/// given that the the whole track is processed with same processing parameters.
///
/// If this ratio is applied to calculate intermediate offsets inside a processing
/// stream, then this ratio is approximate and can deviate +- some tens of milliseconds
/// from ideal offset, yet by end of the audio stream the duration ratio will become
/// exact.
///
/// Example: if processing with parameters "-tempo=15 -pitch=-3", the function
/// will return value 0.8695652... Now, if processing an audio stream whose duration
/// is exactly one million audio samples, then you can expect the processed
/// output duration be 0.869565 * 1000000 = 869565 samples.
double getInputOutputSampleRatio();
/// Flushes the last samples from the processing pipeline to the output.
/// Clears also the internal processing buffers.
//
......@@ -286,6 +335,11 @@ public:
/// Returns number of samples currently unprocessed.
virtual uint numUnprocessedSamples() const;
/// Return number of channels
uint numChannels() const
{
return channels;
}
/// Other handy functions that are implemented in the ancestor classes (see
/// classes 'FIFOProcessor' and 'FIFOSamplePipe')
......
File mode changed from 100644 to 100755
......@@ -7,7 +7,7 @@
@REM Copyright (c) Olli Parviainen
@REM File Created: 09/Sep/2003
@REM
@REM $Id: make-win.bat 197 2014-04-06 18:03:48Z oparviai $
@REM $Id: make-win.bat 254 2017-07-30 09:56:40Z oparviai $
@rem ****************************
@rem try first for VS6.0 support
......@@ -33,16 +33,17 @@ md lib
devenv source\SoundTouch\SoundTouch.vcproj /upgrade
devenv source\SoundTouch\SoundTouch.vcproj /build debug
devenv source\SoundTouch\SoundTouch.vcproj /build release
devenv source\SoundTouch\SoundTouch.vcproj /build releasex64
devenv source\SoundStretch\SoundStretch.vcproj /upgrade
devenv source\SoundStretch\SoundStretch.vcproj /build debug
devenv source\SoundStretch\SoundStretch.vcproj /build release
devenv source\SoundStretch\SoundStretch.vcproj /build releasex64
devenv source\SoundStretch\SoundStretch.sln /upgrade
devenv source\SoundStretch\SoundStretch.sln /build debug
devenv source\SoundStretch\SoundStretch.sln /build release
devenv source\SoundStretch\SoundStretch.sln /build releasex64
devenv source\SoundTouchDll\SoundTouchDll.vcproj /upgrade
devenv source\SoundTouchDll\SoundTouchDll.vcproj /build debug
devenv source\SoundTouchDll\SoundTouchDll.vcproj /build release
devenv source\SoundTouchDll\SoundTouchDll.vcproj /build releasex64
devenv source\SoundTouchDll\SoundTouchDll.sln /upgrade
devenv source\SoundTouchDll\SoundTouchDll.sln /build debug
devenv source\SoundTouchDll\SoundTouchDll.sln /build release
devenv source\SoundTouchDll\SoundTouchDll.sln /build releasex64
@goto end
......@@ -50,14 +51,14 @@ devenv source\SoundTouchDll\SoundTouchDll.vcproj /build releasex64
:nodevdir
@echo off
echo *********************************************************************
echo ****************************************************************************
echo **
echo ** ERROR: Visual Studio path not set.
echo **
echo ** Run "vsvars32.bat" or "vcvars32.bat" from Visual Studio installation
echo ** directory, e.g. "\Program Files\Microsoft Visual Studio\VC98\Bin",
echo ** Run "vsvars32.bat" or "vcvars32.bat" from Visual Studio installation dir,
echo ** e.g. "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin",
echo ** then try again.
echo **
echo *********************************************************************
echo ****************************************************************************
:end
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
......@@ -72,6 +72,14 @@ calling function <strong>SoundTouch.getVersionString() </strong>from the Android
application's main thread at least once before calling other SoundTouch
processing routines. See the SoundTouch Android example application and comments
in the <strong>soundtouch-jni.cpp </strong>source code file for more details.</p>
<p>
<strong>SoundTouch performance in Android</strong></p>
<p>
See external blog articles for more discussion about the
<a href="http://www.softwarecoven.com/parallel-computing-in-embedded-mobile-devices/">
SoundTouch OpenMP implementation</a> and the
<a href="http://www.softwarecoven.com/parallel-computing-with-openmp-in-android/">
SoundTouch performance benchmark tests in Android environment</a>.</p>
<hr />
<h2>
Calling SoundTouch native routines from Android application</h2>
......@@ -116,7 +124,7 @@ in the <strong>soundtouch-jni.cpp </strong>source code file for more details.</p
<hr />
<p style="text-align: center"><i>Copyright &copy; Olli Parviainen</i></p>
<!--
$Id: README-SoundTouch-Android.html 216 2015-05-18 15:28:41Z oparviai $
$Id: README-SoundTouch-Android.html 235 2015-11-11 21:47:19Z oparviai $
-->
</body>
</html>
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
......@@ -8,7 +8,7 @@
///
////////////////////////////////////////////////////////////////////////////////
//
// Last changed : $Date: 2014-04-06 18:57:21 +0300 (Sun, 06 Apr 2014) $
// Last changed : $Date: 2014-04-06 18:57:21 +0300 (su, 06 huhti 2014) $
// File revision : $Revision: 4 $
//
// $Id: RunParameters.cpp 195 2014-04-06 15:57:21Z oparviai $
......
......@@ -8,7 +8,7 @@
///
////////////////////////////////////////////////////////////////////////////////
//
// Last changed : $Date: 2014-04-06 18:57:21 +0300 (Sun, 06 Apr 2014) $
// Last changed : $Date: 2014-04-06 18:57:21 +0300 (su, 06 huhti 2014) $
// File revision : $Revision: 4 $
//
// $Id: RunParameters.h 195 2014-04-06 15:57:21Z oparviai $
......
......@@ -17,7 +17,7 @@
///
////////////////////////////////////////////////////////////////////////////////
//
// Last changed : $Date: 2014-10-05 19:20:24 +0300 (Sun, 05 Oct 2014) $
// Last changed : $Date: 2014-10-05 19:20:24 +0300 (su, 05 loka 2014) $
// File revision : $Revision: 4 $
//
// $Id: WavFile.cpp 200 2014-10-05 16:20:24Z oparviai $
......
......@@ -16,7 +16,7 @@
///
////////////////////////////////////////////////////////////////////////////////
//
// Last changed : $Date: 2014-10-05 19:20:24 +0300 (Sun, 05 Oct 2014) $
// Last changed : $Date: 2014-10-05 19:20:24 +0300 (su, 05 loka 2014) $
// File revision : $Revision: 4 $
//
// $Id: WavFile.h 200 2014-10-05 16:20:24Z oparviai $
......
......@@ -8,10 +8,10 @@
///
////////////////////////////////////////////////////////////////////////////////
//
// Last changed : $Date: 2015-05-18 20:32:21 +0300 (Mon, 18 May 2015) $
// Last changed : $Date: 2017-07-30 12:35:00 +0300 (su, 30 heinä 2017) $
// File revision : $Revision: 4 $
//
// $Id: main.cpp 219 2015-05-18 17:32:21Z oparviai $
// $Id: main.cpp 253 2017-07-30 09:35:00Z oparviai $
//
////////////////////////////////////////////////////////////////////////////////
//
......@@ -65,7 +65,7 @@ using namespace std;
static const char _helloText[] =
"\n"
" SoundStretch v%s - Written by Olli Parviainen 2001 - 2015\n"
" SoundStretch v%s - Copyright (c) Olli Parviainen 2001 - 2017\n"
"==================================================================\n"
"author e-mail: <oparviai"
"@"
......
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
......@@ -12,10 +12,10 @@
///
////////////////////////////////////////////////////////////////////////////////
//
// Last changed : $Date: 2014-01-05 23:40:22 +0200 (Sun, 05 Jan 2014) $
// Last changed : $Date: 2016-01-12 19:26:21 +0200 (ti, 12 tammi 2016) $
// File revision : $Revision: 4 $
//
// $Id: AAFilter.cpp 177 2014-01-05 21:40:22Z oparviai $
// $Id: AAFilter.cpp 240 2016-01-12 17:26:21Z oparviai $
//
////////////////////////////////////////////////////////////////////////////////
//
......@@ -49,7 +49,7 @@
using namespace soundtouch;
#define PI 3.141592655357989
#define PI 3.14159265358979323846
#define TWOPI (2 * PI)
// define this to save AA filter coefficients to a file
......
......@@ -13,7 +13,7 @@
///
////////////////////////////////////////////////////////////////////////////////
//
// Last changed : $Date: 2014-01-07 21:41:23 +0200 (Tue, 07 Jan 2014) $
// Last changed : $Date: 2014-01-07 21:41:23 +0200 (ti, 07 tammi 2014) $
// File revision : $Revision: 4 $
//
// $Id: AAFilter.h 187 2014-01-07 19:41:23Z oparviai $
......
......@@ -26,10 +26,10 @@
///
////////////////////////////////////////////////////////////////////////////////
//
// Last changed : $Date: 2015-02-21 23:24:29 +0200 (Sat, 21 Feb 2015) $
// Last changed : $Date: 2016-01-05 22:59:57 +0200 (ti, 05 tammi 2016) $
// File revision : $Revision: 4 $
//
// $Id: BPMDetect.cpp 202 2015-02-21 21:24:29Z oparviai $
// $Id: BPMDetect.cpp 237 2016-01-05 20:59:57Z oparviai $
//
////////////////////////////////////////////////////////////////////////////////
//
......@@ -67,13 +67,18 @@ using namespace soundtouch;
#define INPUT_BLOCK_SAMPLES 2048
#define DECIMATED_BLOCK_SAMPLES 256
/// decay constant for calculating RMS volume sliding average approximation
/// (time constant is about 10 sec)
const float avgdecay = 0.99986f;
/// Target sample rate after decimation
const int target_srate = 1000;
/// Normalization coefficient for calculating RMS sliding average approximation.
const float avgnorm = (1 - avgdecay);
/// XCorr update sequence size, update in about 200msec chunks
const int xcorr_update_sequence = 200;
/// XCorr decay time constant, decay to half in 30 seconds
/// If it's desired to have the system adapt quicker to beat rate
/// changes within a continuing music stream, then the
/// 'xcorr_decay_time_constant' value can be reduced, yet that
/// can increase possibility of glitches in bpm detection.
const double xcorr_decay_time_constant = 30.0;
////////////////////////////////////////////////////////////////////////////////
......@@ -115,21 +120,8 @@ BPMDetect::BPMDetect(int numChannels, int aSampleRate)
decimateSum = 0;
decimateCount = 0;
envelopeAccu = 0;
// 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 = (1500 * 1500) / avgnorm;
#else
// float samples, scaled to range [-1..+1[
RMSVolumeAccu = (0.045f * 0.045f) / avgnorm;
#endif
// choose decimation factor so that result is approx. 1000 Hz
decimateBy = sampleRate / 1000;
decimateBy = sampleRate / target_srate;
assert(decimateBy > 0);
assert(INPUT_BLOCK_SAMPLES < decimateBy * DECIMATED_BLOCK_SAMPLES);
......@@ -226,6 +218,10 @@ void BPMDetect::updateXCorr(int process_samples)
assert(buffer->numSamples() >= (uint)(process_samples + windowLen));
pBuffer = buffer->ptrBegin();
// calculate decay factor for xcorr filtering
float xcorr_decay = (float)pow(0.5, 1.0 / (xcorr_decay_time_constant * target_srate / process_samples));
#pragma omp parallel for
for (offs = windowStart; offs < windowLen; offs ++)
{
......@@ -237,51 +233,9 @@ void BPMDetect::updateXCorr(int process_samples)
{
sum += pBuffer[i] * pBuffer[i + offs]; // scaling the sub-result shouldn't be necessary
}
// xcorr[offs] *= xcorr_decay; // decay 'xcorr' here with suitable coefficients
// if it's desired that the system adapts automatically to
// various bpms, e.g. in processing continouos music stream.
// The 'xcorr_decay' should be a value that's smaller than but
// close to one, and should also depend on 'process_samples' value.
xcorr[offs] *= xcorr_decay; // decay 'xcorr' here with suitable time constant.
xcorr[offs] += (float)sum;
}
}
// Calculates envelope of the sample data
void BPMDetect::calcEnvelope(SAMPLETYPE *samples, int numsamples)
{
const static double decay = 0.7f; // decay constant for smoothing the envelope
const static double norm = (1 - decay);
int i;
LONG_SAMPLETYPE out;
double val;
for (i = 0; i < numsamples; i ++)
{
// calc average RMS volume
RMSVolumeAccu *= avgdecay;
val = (float)fabs((float)samples[i]);
RMSVolumeAccu += val * val;
// cut amplitudes that are below cutoff ~2 times RMS volume
// (we're interested in peak values, not the silent moments)
if (val < 0.5 * sqrt(RMSVolumeAccu * avgnorm))
{
val = 0;
}
// smooth amplitude envelope
envelopeAccu *= decay;
envelopeAccu += val;
out = (LONG_SAMPLETYPE)(envelopeAccu * norm);
#ifdef SOUNDTOUCH_INTEGER_SAMPLES
// cut peaks (shouldn't be necessary though)
if (out > 32767) out = 32767;
#endif // SOUNDTOUCH_INTEGER_SAMPLES
samples[i] = (SAMPLETYPE)out;
xcorr[offs] += (float)fabs(sum);
}
}
......@@ -304,23 +258,16 @@ void BPMDetect::inputSamples(const SAMPLETYPE *samples, int numSamples)
samples += block * channels;
numSamples -= block;
// envelope new samples and add them to buffer
calcEnvelope(decimated, decSamples);
buffer->putSamples(decimated, decSamples);
}
// when the buffer has enought samples for processing...
if ((int)buffer->numSamples() > windowLen)
while ((int)buffer->numSamples() >= windowLen + xcorr_update_sequence)
{
int processLength;
// how many samples are processed
processLength = (int)buffer->numSamples() - windowLen;
// ... calculate autocorrelations for oldest samples...
updateXCorr(processLength);