Revision 50:d84049e20c61

View differences:

.hgignore
1
syntax: glob
2
*.o
3
*.so
4
*.bak
5
test/test-*
CepstralPitchTracker.cpp
24 24

  
25 25
#include "CepstralPitchTracker.h"
26 26
#include "MeanFilter.h"
27
#include "PeakInterpolator.h"
27 28

  
28 29
#include "vamp-sdk/FFT.h"
29 30

  
......
257 258
    fs[1].push_back(nf);
258 259
}
259 260

  
260
double
261
CepstralPitchTracker::cubicInterpolate(const double y[4], double x)
262
{
263
    double a0 = y[3] - y[2] - y[0] + y[1];
264
    double a1 = y[0] - y[1] - a0;
265
    double a2 = y[2] - y[0];
266
    double a3 = y[1];
267
    return
268
        a0 * x * x * x +
269
        a1 * x * x +
270
        a2 * x +
271
        a3;
272
}
273

  
274
double
275
CepstralPitchTracker::findInterpolatedPeak(const double *in, int maxbin)
276
{
277
    if (maxbin < 2 || maxbin > m_bins - 3) {
278
        return maxbin;
279
    }
280

  
281
    double maxval = 0.0;
282
    double maxidx = maxbin;
283

  
284
    const int divisions = 10;
285
    double y[4];
286

  
287
    y[0] = in[maxbin-1];
288
    y[1] = in[maxbin];
289
    y[2] = in[maxbin+1];
290
    y[3] = in[maxbin+2];
291
    for (int i = 0; i < divisions; ++i) {
292
        double probe = double(i) / double(divisions);
293
        double value = cubicInterpolate(y, probe);
294
        if (value > maxval) {
295
            maxval = value; 
296
            maxidx = maxbin + probe;
297
        }
298
    }
299

  
300
    y[3] = y[2];
301
    y[2] = y[1];
302
    y[1] = y[0];
303
    y[0] = in[maxbin-2];
304
    for (int i = 0; i < divisions; ++i) {
305
        double probe = double(i) / double(divisions);
306
        double value = cubicInterpolate(y, probe);
307
        if (value > maxval) {
308
            maxval = value; 
309
            maxidx = maxbin - 1 + probe;
310
        }
311
    }
312

  
313
/*
314
    std::cerr << "centre = " << maxbin << ": ["
315
              << in[maxbin-2] << ","
316
              << in[maxbin-1] << ","
317
              << in[maxbin] << ","
318
              << in[maxbin+1] << ","
319
              << in[maxbin+2] << "] -> " << maxidx << std::endl;
320
*/
321

  
322
    return maxidx;
323
}
324

  
325 261
CepstralPitchTracker::FeatureSet
326 262
CepstralPitchTracker::process(const float *const *inputBuffers, RealTime timestamp)
327 263
{
......
391 327
        }
392 328
    }
393 329

  
394
    double cimax = findInterpolatedPeak(data, maxbin);
330
    PeakInterpolator pi;
331
    double cimax = pi.findPeakLocation(data, m_bins, maxbin);
395 332
    double peakfreq = m_inputSampleRate / (cimax + m_binFrom);
396 333

  
397 334
    double confidence = 0.0;

Also available in: Unified diff