fftw_execute(p);
find_peak_magnitudes(out, bins, FFT_LENGTH);
std::pair<double, double> peak = find_peak(bins, FFT_LENGTH);
- peak = adjust_for_overtones(peak, bins, FFT_LENGTH);
+ if (peak.first > 0.0)
+ peak = adjust_for_overtones(peak, bins, FFT_LENGTH);
if (peak.first < 50.0 || peak.second - log10(FFT_LENGTH) < 0.0) {
#if TUNING == WELL_TEMPERED_GUITAR
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;
}
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;