X-Git-Url: https://git.sesse.net/?p=pitch;a=blobdiff_plain;f=pitch.cpp;h=91afda5fb0618d7f0e611223f1089980f1a123ee;hp=8aff1485a1e9e44091263aef52b7195cf12479e2;hb=1a261eee89e163b53a334eeb57850f16d476c2df;hpb=19a95dfd3794695d80fe9eae0ba777def80dc3fc;ds=sidebyside diff --git a/pitch.cpp b/pitch.cpp index 8aff148..91afda5 100644 --- a/pitch.cpp +++ b/pitch.cpp @@ -225,9 +225,9 @@ std::pair find_peak(double *in, unsigned num_samples) 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; - } 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; }