From 037319af38b6b3d8ad5de68bc90a843d1d5c0412 Mon Sep 17 00:00:00 2001 From: Paul Brossier Date: Wed, 6 Mar 2013 15:28:36 -0500 Subject: [PATCH] src/mathutils.c: freqtomidi and miditofreq to not produce infs and nans --- src/mathutils.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/mathutils.c b/src/mathutils.c index 815c2355..74063a27 100644 --- a/src/mathutils.c +++ b/src/mathutils.c @@ -398,6 +398,7 @@ aubio_quadfrac (smpl_t s0, smpl_t s1, smpl_t s2, smpl_t pf) 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 @@ aubio_freqtomidi (smpl_t freq) 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; -- 2.26.2