]> git.sesse.net Git - pitch/blobdiff - pitch.cpp
Start a bit above DC, to combat microphones with huge low-frequency content.
[pitch] / pitch.cpp
index 91afda5fb0618d7f0e611223f1089980f1a123ee..36be752bbd66e87163e71921348a95644ebf8b6b 100644 (file)
--- a/pitch.cpp
+++ b/pitch.cpp
@@ -190,10 +190,10 @@ void find_peak_magnitudes(std::complex<double> *in, double *out, unsigned num_sa
 
 std::pair<double, double> find_peak(double *in, unsigned num_samples)
 {
-       double best_peak = in[0];
-       unsigned best_bin = 0;
+       double best_peak = in[5];
+       unsigned best_bin = 5;
 
-       for (unsigned i = 1; i < num_samples / 2 + 1; ++i) {
+       for (unsigned i = 6; i < num_samples / 2 + 1; ++i) {
                if (in[i] > best_peak) {
                        best_peak = in[i];
                        best_bin = i;
@@ -259,6 +259,8 @@ std::pair<double, double> adjust_for_overtones(std::pair<double, double> base, d
                unsigned middle = unsigned(floor(freq_to_bin(base.first, num_samples) * i + 0.5));
                unsigned lower = middle - (i+1)/2, upper = middle + (i+1)/2;
 
+               if (lower < 1)
+                       lower = 1;
                if (upper >= num_samples)
                        upper = num_samples - 2;