Fix an off-by-one in the undertone detection.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Fri, 28 Apr 2006 12:08:14 +0000 (12:08 +0000)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Fri, 28 Apr 2006 12:08:14 +0000 (12:08 +0000)
pitch.cpp

index 8aff148..91afda5 100644 (file)
--- a/pitch.cpp
+++ b/pitch.cpp
@@ -225,9 +225,9 @@ std::pair<double, double> find_peak(double *in, unsigned num_samples)
                        best_bin /= i;
 
                        // consider sliding one bin up or down
                        best_bin /= i;
 
                        // consider sliding one bin up or down
-                       if (best_bin > 0 && in[best_bin - 1] > in[best_bin] && in[best_bin - 1] > in[best_bin - 2]) {
+                       if (best_bin > 1 && in[best_bin - 1] > in[best_bin] && in[best_bin - 1] > in[best_bin - 2]) {
                                --best_bin;
                                --best_bin;
-                       } else if (best_bin < num_samples / 2 && in[best_bin + 1] > in[best_bin] && in[best_bin + 1] > in[best_bin + 2]) {
+                       } else if (best_bin < num_samples / 2 - 1 && in[best_bin + 1] > in[best_bin] && in[best_bin + 1] > in[best_bin + 2]) {
                                ++best_bin;
                        }
                           
                                ++best_bin;
                        }