Skip to content

Commit

Permalink
Updated SoundTouch library to 1.8.1 [r198]
Browse files Browse the repository at this point in the history
  • Loading branch information
skidau committed Sep 4, 2014
1 parent 7a01eff commit ba2bec1
Show file tree
Hide file tree
Showing 27 changed files with 1,415 additions and 696 deletions.
66 changes: 59 additions & 7 deletions Externals/soundtouch/AAFilter.cpp
Expand Up @@ -12,10 +12,10 @@
///
////////////////////////////////////////////////////////////////////////////////
//
// Last changed : $Date: 2009-01-11 11:34:24 +0000 (Sun, 11 Jan 2009) $
// Last changed : $Date: 2014-01-06 08:40:22 +1100 (Mon, 06 Jan 2014) $
// File revision : $Revision: 4 $
//
// $Id: AAFilter.cpp 45 2009-01-11 11:34:24Z oparviai $
// $Id: AAFilter.cpp 177 2014-01-05 21:40:22Z oparviai $
//
////////////////////////////////////////////////////////////////////////////////
//
Expand Down Expand Up @@ -52,6 +52,30 @@ using namespace soundtouch;
#define PI 3.141592655357989
#define TWOPI (2 * PI)

// define this to save AA filter coefficients to a file
// #define _DEBUG_SAVE_AAFILTER_COEFFICIENTS 1

#ifdef _DEBUG_SAVE_AAFILTER_COEFFICIENTS
#include <stdio.h>

static void _DEBUG_SAVE_AAFIR_COEFFS(SAMPLETYPE *coeffs, int len)
{
FILE *fptr = fopen("aa_filter_coeffs.txt", "wt");
if (fptr == NULL) return;

for (int i = 0; i < len; i ++)
{
double temp = coeffs[i];
fprintf(fptr, "%lf\n", temp);
}
fclose(fptr);
}

#else
#define _DEBUG_SAVE_AAFIR_COEFFS(x, y)
#endif


/*****************************************************************************
*
* Implementation of the class 'AAFilter'
Expand Down Expand Up @@ -99,7 +123,7 @@ void AAFilter::calculateCoeffs()
{
uint i;
double cntTemp, temp, tempCoeff,h, w;
double fc2, wc;
double wc;
double scaleCoeff, sum;
double *work;
SAMPLETYPE *coeffs;
Expand All @@ -112,8 +136,7 @@ void AAFilter::calculateCoeffs()
work = new double[length];
coeffs = new SAMPLETYPE[length];

fc2 = 2.0 * cutoffFreq;
wc = PI * fc2;
wc = 2.0 * PI * cutoffFreq;
tempCoeff = TWOPI / (double)length;

sum = 0;
Expand All @@ -124,7 +147,7 @@ void AAFilter::calculateCoeffs()
temp = cntTemp * wc;
if (temp != 0)
{
h = fc2 * sin(temp) / temp; // sinc function
h = sin(temp) / temp; // sinc function
}
else
{
Expand Down Expand Up @@ -153,17 +176,21 @@ void AAFilter::calculateCoeffs()

for (i = 0; i < length; i ++)
{
// scale & round to nearest integer
temp = work[i] * scaleCoeff;
//#if SOUNDTOUCH_INTEGER_SAMPLES
// scale & round to nearest integer
temp += (temp >= 0) ? 0.5 : -0.5;
// ensure no overfloods
assert(temp >= -32768 && temp <= 32767);
//#endif
coeffs[i] = (SAMPLETYPE)temp;
}

// Set coefficients. Use divide factor 14 => divide result by 2^14 = 16384
pFIR->setCoefficients(coeffs, length, 14);

_DEBUG_SAVE_AAFIR_COEFFS(coeffs, length);

delete[] work;
delete[] coeffs;
}
Expand All @@ -178,6 +205,31 @@ uint AAFilter::evaluate(SAMPLETYPE *dest, const SAMPLETYPE *src, uint numSamples
}


/// Applies the filter to the given src & dest pipes, so that processed amount of
/// samples get removed from src, and produced amount added to dest
/// Note : The amount of outputted samples is by value of 'filter length'
/// smaller than the amount of input samples.
uint AAFilter::evaluate(FIFOSampleBuffer &dest, FIFOSampleBuffer &src) const
{
SAMPLETYPE *pdest;
const SAMPLETYPE *psrc;
uint numSrcSamples;
uint result;
int numChannels = src.getChannels();

assert(numChannels == dest.getChannels());

numSrcSamples = src.numSamples();
psrc = src.ptrBegin();
pdest = dest.ptrEnd(numSrcSamples);
result = pFIR->evaluate(pdest, psrc, numSrcSamples, numChannels);
src.receiveSamples(result);
dest.putSamples(result);

return result;
}


uint AAFilter::getLength() const
{
return pFIR->getLength();
Expand Down
13 changes: 11 additions & 2 deletions Externals/soundtouch/AAFilter.h
Expand Up @@ -13,10 +13,10 @@
///
////////////////////////////////////////////////////////////////////////////////
//
// Last changed : $Date: 2008-02-10 16:26:55 +0000 (Sun, 10 Feb 2008) $
// Last changed : $Date: 2014-01-08 06:41:23 +1100 (Wed, 08 Jan 2014) $
// File revision : $Revision: 4 $
//
// $Id: AAFilter.h 11 2008-02-10 16:26:55Z oparviai $
// $Id: AAFilter.h 187 2014-01-07 19:41:23Z oparviai $
//
////////////////////////////////////////////////////////////////////////////////
//
Expand Down Expand Up @@ -45,6 +45,7 @@
#define AAFilter_H

#include "STTypes.h"
#include "FIFOSampleBuffer.h"

namespace soundtouch
{
Expand Down Expand Up @@ -84,6 +85,14 @@ class AAFilter
const SAMPLETYPE *src,
uint numSamples,
uint numChannels) const;

/// Applies the filter to the given src & dest pipes, so that processed amount of
/// samples get removed from src, and produced amount added to dest
/// Note : The amount of outputted samples is by value of 'filter length'
/// smaller than the amount of input samples.
uint evaluate(FIFOSampleBuffer &dest,
FIFOSampleBuffer &src) const;

};

}
Expand Down
2 changes: 1 addition & 1 deletion Externals/soundtouch/BPMDetect.cpp
Expand Up @@ -26,7 +26,7 @@
///
////////////////////////////////////////////////////////////////////////////////
//
// Last changed : $Date: 2012-08-30 19:45:25 +0000 (Thu, 30 Aug 2012) $
// Last changed : $Date: 2012-08-31 05:45:25 +1000 (Fri, 31 Aug 2012) $
// File revision : $Revision: 4 $
//
// $Id: BPMDetect.cpp 149 2012-08-30 19:45:25Z oparviai $
Expand Down
3 changes: 3 additions & 0 deletions Externals/soundtouch/CMakeLists.txt
Expand Up @@ -4,6 +4,9 @@ set(SRCS
cpu_detect_x86.cpp
FIFOSampleBuffer.cpp
FIRFilter.cpp
InterpolateCubic.cpp
InterpolateLinear.cpp
InterpolateShannon.cpp
mmx_optimized.cpp
PeakFinder.cpp
RateTransposer.cpp
Expand Down
6 changes: 5 additions & 1 deletion Externals/soundtouch/FIFOSampleBuffer.cpp
Expand Up @@ -15,7 +15,7 @@
///
////////////////////////////////////////////////////////////////////////////////
//
// Last changed : $Date: 2012-11-08 18:53:01 +0000 (Thu, 08 Nov 2012) $
// Last changed : $Date: 2012-11-09 05:53:01 +1100 (Fri, 09 Nov 2012) $
// File revision : $Revision: 4 $
//
// $Id: FIFOSampleBuffer.cpp 160 2012-11-08 18:53:01Z oparviai $
Expand Down Expand Up @@ -86,6 +86,10 @@ void FIFOSampleBuffer::setChannels(int numChannels)
samplesInBuffer = usedBytes / channels;
}

int FIFOSampleBuffer::getChannels()
{
return channels;
}

// if output location pointer 'bufferPos' isn't zero, 'rewinds' the buffer and
// zeroes this pointer by copying samples from the 'bufferPos' pointer
Expand Down
1 change: 1 addition & 0 deletions Externals/soundtouch/FIFOSampleBuffer.h
Expand Up @@ -161,6 +161,7 @@ class FIFOSampleBuffer : public FIFOSamplePipe

/// Sets number of channels, 1 = mono, 2 = stereo.
void setChannels(int numChannels);
int getChannels();

/// Returns nonzero if there aren't any samples available for outputting.
virtual int isEmpty() const;
Expand Down
3 changes: 1 addition & 2 deletions Externals/soundtouch/FIRFilter.cpp
Expand Up @@ -11,7 +11,7 @@
///
////////////////////////////////////////////////////////////////////////////////
//
// Last changed : $Date: 2013-06-12 15:24:44 +0000 (Wed, 12 Jun 2013) $
// Last changed : $Date: 2013-06-13 01:24:44 +1000 (Thu, 13 Jun 2013) $
// File revision : $Revision: 4 $
//
// $Id: FIRFilter.cpp 171 2013-06-12 15:24:44Z oparviai $
Expand Down Expand Up @@ -217,7 +217,6 @@ uint FIRFilter::evaluateFilterMulti(SAMPLETYPE *dest, const SAMPLETYPE *src, uin
sum[c] = 0;
}
}
free(sum);
return numSamples - length;
}

Expand Down
2 changes: 1 addition & 1 deletion Externals/soundtouch/FIRFilter.h
Expand Up @@ -11,7 +11,7 @@
///
////////////////////////////////////////////////////////////////////////////////
//
// Last changed : $Date: 2013-06-12 15:24:44 +0000 (Wed, 12 Jun 2013) $
// Last changed : $Date: 2013-06-13 01:24:44 +1000 (Thu, 13 Jun 2013) $
// File revision : $Revision: 4 $
//
// $Id: FIRFilter.h 171 2013-06-12 15:24:44Z oparviai $
Expand Down

0 comments on commit ba2bec1

Please sign in to comment.