ref: 037319af38b6b3d8ad5de68bc90a843d1d5c0412
parent: e1bfde5b4ebe6465f95565b3f3ba978db22bbf30
author: Paul Brossier <piem@piem.org>
date: Wed Mar 6 10:28:36 EST 2013
src/mathutils.c: freqtomidi and miditofreq to not produce infs and nans
--- a/src/mathutils.c
+++ b/src/mathutils.c
@@ -398,6 +398,7 @@
smpl_t
aubio_freqtomidi (smpl_t freq)
{
+ if (freq < 2. || freq > 100000.) return 0.; // avoid nans and infs
/* log(freq/A-2)/log(2) */
smpl_t midi = freq / 6.875;
midi = LOG (midi) / 0.69314718055995;
@@ -409,6 +410,7 @@
smpl_t
aubio_miditofreq (smpl_t midi)
{
+ if (midi > 140.) return 0.; // avoid infs
smpl_t freq = (midi + 3.) / 12.;
freq = EXP (freq * 0.69314718055995);
freq *= 6.875;