changeset 50:d84049e20c61

Use peak interpolator class
author Chris Cannam
date Tue, 11 Sep 2012 20:42:52 +0100
parents d6705fec7a94
children 0997774f5fdc
files .hgignore CepstralPitchTracker.cpp
diffstat 2 files changed, 8 insertions(+), 66 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/.hgignore	Tue Sep 11 20:42:52 2012 +0100
@@ -0,0 +1,5 @@
+syntax: glob
+*.o
+*.so
+*.bak
+test/test-*
\ No newline at end of file
--- a/CepstralPitchTracker.cpp	Tue Sep 11 17:34:13 2012 +0100
+++ b/CepstralPitchTracker.cpp	Tue Sep 11 20:42:52 2012 +0100
@@ -24,6 +24,7 @@
 
 #include "CepstralPitchTracker.h"
 #include "MeanFilter.h"
+#include "PeakInterpolator.h"
 
 #include "vamp-sdk/FFT.h"
 
@@ -257,71 +258,6 @@
     fs[1].push_back(nf);
 }
 
-double
-CepstralPitchTracker::cubicInterpolate(const double y[4], double x)
-{
-    double a0 = y[3] - y[2] - y[0] + y[1];
-    double a1 = y[0] - y[1] - a0;
-    double a2 = y[2] - y[0];
-    double a3 = y[1];
-    return
-        a0 * x * x * x +
-        a1 * x * x +
-        a2 * x +
-        a3;
-}
-
-double
-CepstralPitchTracker::findInterpolatedPeak(const double *in, int maxbin)
-{
-    if (maxbin < 2 || maxbin > m_bins - 3) {
-        return maxbin;
-    }
-
-    double maxval = 0.0;
-    double maxidx = maxbin;
-
-    const int divisions = 10;
-    double y[4];
-
-    y[0] = in[maxbin-1];
-    y[1] = in[maxbin];
-    y[2] = in[maxbin+1];
-    y[3] = in[maxbin+2];
-    for (int i = 0; i < divisions; ++i) {
-        double probe = double(i) / double(divisions);
-        double value = cubicInterpolate(y, probe);
-        if (value > maxval) {
-            maxval = value; 
-            maxidx = maxbin + probe;
-        }
-    }
-
-    y[3] = y[2];
-    y[2] = y[1];
-    y[1] = y[0];
-    y[0] = in[maxbin-2];
-    for (int i = 0; i < divisions; ++i) {
-        double probe = double(i) / double(divisions);
-        double value = cubicInterpolate(y, probe);
-        if (value > maxval) {
-            maxval = value; 
-            maxidx = maxbin - 1 + probe;
-        }
-    }
-
-/*
-    std::cerr << "centre = " << maxbin << ": ["
-              << in[maxbin-2] << ","
-              << in[maxbin-1] << ","
-              << in[maxbin] << ","
-              << in[maxbin+1] << ","
-              << in[maxbin+2] << "] -> " << maxidx << std::endl;
-*/
-
-    return maxidx;
-}
-
 CepstralPitchTracker::FeatureSet
 CepstralPitchTracker::process(const float *const *inputBuffers, RealTime timestamp)
 {
@@ -391,7 +327,8 @@
         }
     }
 
-    double cimax = findInterpolatedPeak(data, maxbin);
+    PeakInterpolator pi;
+    double cimax = pi.findPeakLocation(data, m_bins, maxbin);
     double peakfreq = m_inputSampleRate / (cimax + m_binFrom);
 
     double confidence = 0.0;