From: Paul Brossier Date: Wed, 6 Mar 2013 20:28:36 +0000 (-0500) Subject: src/mathutils.c: freqtomidi and miditofreq to not produce infs and nans X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=037319af38b6b3d8ad5de68bc90a843d1d5c0412;p=aubio.git src/mathutils.c: freqtomidi and miditofreq to not produce infs and nans --- 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;