diff 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
line wrap: on
line diff
--- a/ConstrainedHarmonicPeak.cpp	Mon Mar 10 14:51:09 2014 +0000
+++ b/ConstrainedHarmonicPeak.cpp	Thu Apr 10 18:37:55 2014 +0100
@@ -317,16 +317,25 @@
     double maxdb = -120.0;
     int maxidx = 0;
     for (int i = 0; i <= maxbin - minbin; ++i) {
-	if (hps[i] > maxdb) {
-	    maxdb = hps[i];
-	    maxidx = i;
-	}
+        if (hps[i] > maxdb) {
+            maxdb = hps[i];
+            maxidx = i;
+        }
+    }
+
+    if (maxidx == 0 || maxidx == maxbin - minbin) { // edge cases are useless
+        return fs;
     }
 
     double interpolated = findInterpolatedPeak(hps, maxidx, maxbin - minbin + 1);
+    
     interpolated = interpolated + minbin;
 
     double freq = interpolated * m_inputSampleRate / m_fftSize;
+    
+    if (freq < m_minFreq || freq > m_maxFreq) {
+        return fs;
+    }
 
     Feature f;
     f.values.push_back(freq);