comparison ConstrainedHarmonicPeak.cpp @ 9:5fb59edfab99

no pitch output in case of a) edge case or b) interpolated is outside freq range
author matthiasm
date Thu, 10 Apr 2014 18:37:55 +0100
parents e9b629578488
children f82a28c2209f
comparison
equal deleted inserted replaced
6:e9b629578488 9:5fb59edfab99
315 } 315 }
316 316
317 double maxdb = -120.0; 317 double maxdb = -120.0;
318 int maxidx = 0; 318 int maxidx = 0;
319 for (int i = 0; i <= maxbin - minbin; ++i) { 319 for (int i = 0; i <= maxbin - minbin; ++i) {
320 if (hps[i] > maxdb) { 320 if (hps[i] > maxdb) {
321 maxdb = hps[i]; 321 maxdb = hps[i];
322 maxidx = i; 322 maxidx = i;
323 } 323 }
324 }
325
326 if (maxidx == 0 || maxidx == maxbin - minbin) { // edge cases are useless
327 return fs;
324 } 328 }
325 329
326 double interpolated = findInterpolatedPeak(hps, maxidx, maxbin - minbin + 1); 330 double interpolated = findInterpolatedPeak(hps, maxidx, maxbin - minbin + 1);
331
327 interpolated = interpolated + minbin; 332 interpolated = interpolated + minbin;
328 333
329 double freq = interpolated * m_inputSampleRate / m_fftSize; 334 double freq = interpolated * m_inputSampleRate / m_fftSize;
335
336 if (freq < m_minFreq || freq > m_maxFreq) {
337 return fs;
338 }
330 339
331 Feature f; 340 Feature f;
332 f.values.push_back(freq); 341 f.values.push_back(freq);
333 fs[0].push_back(f); 342 fs[0].push_back(f);
334 343