projects
/
aubio.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
| inline |
side by side
(parent:
e1bfde5
)
src/mathutils.c: freqtomidi and miditofreq to not produce infs and nans
author
Paul Brossier
<piem@piem.org>
Wed, 6 Mar 2013 20:28:36 +0000
(15:28 -0500)
committer
Paul Brossier
<piem@piem.org>
Wed, 6 Mar 2013 20:28:36 +0000
(15:28 -0500)
src/mathutils.c
patch
|
blob
|
history
diff --git
a/src/mathutils.c
b/src/mathutils.c
index 815c235518d0781991d926daeab6a758daac278c..74063a27a1fd2672137371b50eb5d6aa1abfa418 100644
(file)
--- 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;