Fix a possible segfault.
[pitch] / pitch.cpp
index 1c272f1..97238f5 100644 (file)
--- a/pitch.cpp
+++ b/pitch.cpp
@@ -234,6 +234,9 @@ std::pair<double, double> find_peak(double *in, unsigned num_samples)
                }
        }
 
+       if (best_bin == 0 || best_bin == num_samples / 2) {
+               return std::make_pair(-1.0, 0.0);
+       }
        std::pair<double, double> peak = 
                interpolate_peak(in[best_bin - 1],
                                 in[best_bin],