From 79c2e521740c351e4796efd9e35f94a6f3451794 Mon Sep 17 00:00:00 2001 From: Paul Brossier Date: Mon, 22 Aug 2005 20:59:13 +0000 Subject: [PATCH] added bintomidi, freqtobin, miditofreq --- src/mathutils.c | 30 +++++++++++++++++++++++------- src/mathutils.h | 3 +++ swig/aubio.i | 3 +++ 3 files changed, 29 insertions(+), 7 deletions(-) diff --git a/src/mathutils.c b/src/mathutils.c index b523d0ec..df2a471a 100644 --- a/src/mathutils.c +++ b/src/mathutils.c @@ -345,12 +345,19 @@ uint_t vec_peakpick(fvec_t * onset, uint_t pos) { } smpl_t aubio_freqtomidi(smpl_t freq) { - smpl_t midi = freq/6.875; - /* log(freq/A-2)/log(2) */ - midi = LOG(midi)/0.69314718055995; - midi *= 12; - midi -= 3; - return midi; + /* log(freq/A-2)/log(2) */ + smpl_t midi = freq/6.875; + midi = LOG(midi)/0.69314718055995; + midi *= 12; + midi -= 3; + return midi; +} + +smpl_t aubio_miditofreq(smpl_t midi) { + smpl_t freq = (midi+3.)/12.; + freq = EXP(freq*0.69314718055995); + freq *= 6.875; + return freq; } smpl_t aubio_bintofreq(smpl_t bin, smpl_t samplerate, smpl_t fftsize) { @@ -358,12 +365,21 @@ smpl_t aubio_bintofreq(smpl_t bin, smpl_t samplerate, smpl_t fftsize) { return freq*bin; } - smpl_t aubio_bintomidi(smpl_t bin, smpl_t samplerate, smpl_t fftsize) { smpl_t midi = aubio_bintofreq(bin,samplerate,fftsize); return aubio_freqtomidi(midi); } +smpl_t aubio_freqtobin(smpl_t freq, smpl_t samplerate, smpl_t fftsize) { + smpl_t bin = fftsize/samplerate; + return freq*bin; +} + +smpl_t aubio_miditobin(smpl_t midi, smpl_t samplerate, smpl_t fftsize) { + smpl_t freq = aubio_miditofreq(midi); + return aubio_freqtobin(freq,samplerate,fftsize); +} + /** returns 1 if wassilence is 0 and RMS(ibuf)