X-Git-Url: https://git.sesse.net/?p=pitch;a=blobdiff_plain;f=pitch.cpp;h=c8246dcf5f28436277ad51c6cff8bf94f145bc64;hp=1c272f1080b734bb7ae891611660edf6c915d2c0;hb=2bb871a3a6ca4b73e8583de4de97f7b55dd1614c;hpb=aa161533b7b8e32cafefce9f71776c5602148110 diff --git a/pitch.cpp b/pitch.cpp index 1c272f1..c8246dc 100644 --- a/pitch.cpp +++ b/pitch.cpp @@ -46,7 +46,7 @@ int main() in = reinterpret_cast (fftw_malloc(sizeof(double) * FFT_LENGTH / PAD_FACTOR)); in_windowed = reinterpret_cast (fftw_malloc(sizeof(double) * FFT_LENGTH)); out = reinterpret_cast *> (fftw_malloc(sizeof(std::complex) * (FFT_LENGTH / 2 + 1))); - bins = reinterpret_cast (fftw_malloc(sizeof(double) * FFT_LENGTH / 2 + 1)); + bins = reinterpret_cast (fftw_malloc(sizeof(double) * (FFT_LENGTH / 2 + 1))); memset(in, 0, sizeof(double) * FFT_LENGTH / PAD_FACTOR); @@ -234,6 +234,9 @@ std::pair 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 peak = interpolate_peak(in[best_bin - 1], in[best_bin],