From e391790ac75d01f4eb89534f17f0a58ba0273b5a Mon Sep 17 00:00:00 2001 From: Paul Brossier Date: Sat, 1 Aug 2015 10:28:38 +0200 Subject: [PATCH] src/pitch/pitchyin.c, src/pitch/pitchyinfft.c: avoid producing NaN on silence (closes #7) --- src/pitch/pitchyin.c | 6 +++++- src/pitch/pitchyinfft.c | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/pitch/pitchyin.c b/src/pitch/pitchyin.c index 33e9882a..6061f911 100644 --- a/src/pitch/pitchyin.c +++ b/src/pitch/pitchyin.c @@ -145,7 +145,11 @@ aubio_pitchyin_do (aubio_pitchyin_t * o, fvec_t * input, fvec_t * out) yin->data[tau] += SQR (tmp); } tmp2 += yin->data[tau]; - yin->data[tau] *= tau / tmp2; + if (tmp2 != 0) { + yin->data[tau] *= tau / tmp2; + } else { + yin->data[tau] = 1.; + } period = tau - 3; if (tau > 4 && (yin->data[period] < tol) && (yin->data[period] < yin->data[period + 1])) { diff --git a/src/pitch/pitchyinfft.c b/src/pitch/pitchyinfft.c index 3608b292..940ae4f9 100644 --- a/src/pitch/pitchyinfft.c +++ b/src/pitch/pitchyinfft.c @@ -135,7 +135,11 @@ aubio_pitchyinfft_do (aubio_pitchyinfft_t * p, fvec_t * input, fvec_t * output) yin->data[tau] = sum - fftout->data[tau]; // and the cumulative mean normalized difference function tmp += yin->data[tau]; - yin->data[tau] *= tau / tmp; + if (tmp != 0) { + yin->data[tau] *= tau / tmp; + } else { + yin->data[tau] = 1.; + } } // find best candidates tau = fvec_min_elem (yin); -- 2.11.0