summaryrefslogtreecommitdiff
path: root/Externals/soundtouch/AAFilter.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Externals/soundtouch/AAFilter.cpp')
-rw-r--r--Externals/soundtouch/AAFilter.cpp66
1 files changed, 59 insertions, 7 deletions
diff --git a/Externals/soundtouch/AAFilter.cpp b/Externals/soundtouch/AAFilter.cpp
index 010fb511b2..b3bb947bd6 100644
--- a/Externals/soundtouch/AAFilter.cpp
+++ b/Externals/soundtouch/AAFilter.cpp
@@ -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 $
//
////////////////////////////////////////////////////////////////////////////////
//
@@ -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'
@@ -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;
@@ -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;
@@ -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
{
@@ -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;
}
@@ -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();