summaryrefslogtreecommitdiff
path: root/libs/qm-dsp/dsp/tonal/ChangeDetectionFunction.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'libs/qm-dsp/dsp/tonal/ChangeDetectionFunction.cpp')
-rw-r--r--libs/qm-dsp/dsp/tonal/ChangeDetectionFunction.cpp36
1 files changed, 18 insertions, 18 deletions
diff --git a/libs/qm-dsp/dsp/tonal/ChangeDetectionFunction.cpp b/libs/qm-dsp/dsp/tonal/ChangeDetectionFunction.cpp
index 9b1a3219ac..bcc661dd1d 100644
--- a/libs/qm-dsp/dsp/tonal/ChangeDetectionFunction.cpp
+++ b/libs/qm-dsp/dsp/tonal/ChangeDetectionFunction.cpp
@@ -16,7 +16,7 @@
#include "ChangeDetectionFunction.h"
#ifndef PI
-#define PI (3.14159265358979323846)
+#define PI (3.14159265358979232846)
#endif
@@ -34,20 +34,20 @@ ChangeDetectionFunction::~ChangeDetectionFunction()
void ChangeDetectionFunction::setFilterWidth(const int iWidth)
{
m_iFilterWidth = iWidth*2+1;
-
+
// it is assumed that the gaussian is 0 outside of +/- FWHM
// => filter width = 2*FWHM = 2*2.3548*sigma
m_dFilterSigma = double(m_iFilterWidth) / double(2*2.3548);
m_vaGaussian.resize(m_iFilterWidth);
-
+
double dScale = 1.0 / (m_dFilterSigma*sqrt(2*PI));
-
+
for (int x = -(m_iFilterWidth-1)/2; x <= (m_iFilterWidth-1)/2; x++)
{
double w = dScale * std::exp ( -(x*x)/(2*m_dFilterSigma*m_dFilterSigma) );
m_vaGaussian[x + (m_iFilterWidth-1)/2] = w;
}
-
+
#ifdef DEBUG_CHANGE_DETECTION_FUNCTION
std::cerr << "Filter sigma: " << m_dFilterSigma << std::endl;
std::cerr << "Filter width: " << m_iFilterWidth << std::endl;
@@ -59,37 +59,37 @@ ChangeDistance ChangeDetectionFunction::process(const TCSGram& rTCSGram)
{
ChangeDistance retVal;
retVal.resize(rTCSGram.getSize(), 0.0);
-
+
TCSGram smoothedTCSGram;
for (int iPosition = 0; iPosition < rTCSGram.getSize(); iPosition++)
{
int iSkipLower = 0;
-
+
int iLowerPos = iPosition - (m_iFilterWidth-1)/2;
int iUpperPos = iPosition + (m_iFilterWidth-1)/2;
-
+
if (iLowerPos < 0)
{
iSkipLower = -iLowerPos;
iLowerPos = 0;
}
-
+
if (iUpperPos >= rTCSGram.getSize())
{
int iMaxIndex = rTCSGram.getSize() - 1;
iUpperPos = iMaxIndex;
}
-
+
TCSVector smoothedVector;
// for every bin of the vector, calculate the smoothed value
for (int iPC = 0; iPC < 6; iPC++)
- {
+ {
size_t j = 0;
double dSmoothedValue = 0.0;
TCSVector rCV;
-
+
for (int i = iLowerPos; i <= iUpperPos; i++)
{
rTCSGram.getTCSVector(i, rCV);
@@ -98,7 +98,7 @@ ChangeDistance ChangeDetectionFunction::process(const TCSGram& rTCSGram)
smoothedVector[iPC] = dSmoothedValue;
}
-
+
smoothedTCSGram.addTCSVector(smoothedVector);
}
@@ -109,10 +109,10 @@ ChangeDistance ChangeDetectionFunction::process(const TCSGram& rTCSGram)
if the current estimate is not confident enough, look further into the future/the past
e.g., High frequency content, zero crossing rate, spectral flatness
*/
-
+
TCSVector nextTCS;
TCSVector previousTCS;
-
+
int iWindow = 1;
// while (previousTCS.magnitude() < 0.1 && (iPosition-iWindow) > 0)
@@ -121,9 +121,9 @@ ChangeDistance ChangeDetectionFunction::process(const TCSGram& rTCSGram)
// std::cout << previousTCS.magnitude() << std::endl;
iWindow++;
}
-
+
iWindow = 1;
-
+
// while (nextTCS.magnitude() < 0.1 && (iPosition+iWindow) < (rTCSGram.getSize()-1) )
{
smoothedTCSGram.getTCSVector(iPosition+iWindow, nextTCS);
@@ -136,7 +136,7 @@ ChangeDistance ChangeDetectionFunction::process(const TCSGram& rTCSGram)
{
distance += std::pow(nextTCS[j] - previousTCS[j], 2.0);
}
-
+
retVal[iPosition] = std::pow(distance, 0.5);
}