Skip to content

Commit

Permalink
Prevent freq calculation to produce from NaN/inf -- #15
Browse files Browse the repository at this point in the history
  • Loading branch information
x42 committed Nov 11, 2019
1 parent 5a44436 commit a551bd2
Showing 1 changed file with 2 additions and 7 deletions.
9 changes: 2 additions & 7 deletions src/retuner.cc
Original file line number Diff line number Diff line change
Expand Up @@ -439,13 +439,8 @@ Retuner::findcycle (void)
x = _fftTdata[j - 1];
y = _fftTdata[j];
z = _fftTdata[j + 1];
_cycle = j + 0.5f * (x - z) / (z - 2 * y + x - 1e-9f);
if (_cycle < 0) {
// sometimes the above formula returns -inf
// which ends up crashing the process
// Cause : x, y, z being floats
// -> Could also be fixed by using doubles instead
_cycle = 0;
if (fabsf(z - 2 * y + x) > 2e-9f) {
_cycle = j + 0.5f * (x - z) / (z - 2 * y + x - 1e-9f);
}
}
}
Expand Down

0 comments on commit a551bd2

Please sign in to comment.