ref: e391790ac75d01f4eb89534f17f0a58ba0273b5a
parent: 10482d231382d920a0b9a8467e6062ea01387618
author: Paul Brossier <piem@piem.org>
date: Sat Aug 1 06:28:38 EDT 2015
src/pitch/pitchyin.c, src/pitch/pitchyinfft.c: avoid producing NaN on silence (closes #7)
--- a/src/pitch/pitchyin.c
+++ b/src/pitch/pitchyin.c
@@ -145,7 +145,11 @@
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])) {
--- a/src/pitch/pitchyinfft.c
+++ b/src/pitch/pitchyinfft.c
@@ -135,7 +135,11 @@
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);