shithub: aubio

Download patch

ref: 79c2e521740c351e4796efd9e35f94a6f3451794
parent: 98ef4df54174ec5488d697d9c0a8a0b0cda41aaa
author: Paul Brossier <piem@altern.org>
date: Mon Aug 22 16:59:13 EDT 2005

added bintomidi, freqtobin, miditofreq

--- a/src/mathutils.c
+++ b/src/mathutils.c
@@ -345,23 +345,39 @@
 }
 
 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) {
   smpl_t freq = samplerate/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);
 }
 
 
--- a/src/mathutils.h
+++ b/src/mathutils.h
@@ -230,8 +230,11 @@
 uint_t vec_peakpick(fvec_t * input, uint_t pos);
 
 smpl_t aubio_bintomidi(smpl_t bin, smpl_t samplerate, smpl_t fftsize);
+smpl_t aubio_miditobin(smpl_t midi, smpl_t samplerate, smpl_t fftsize);
 smpl_t aubio_bintofreq(smpl_t bin, smpl_t samplerate, smpl_t fftsize);
+smpl_t aubio_freqtobin(smpl_t freq, smpl_t samplerate, smpl_t fftsize);
 smpl_t aubio_freqtomidi(smpl_t freq);
+smpl_t aubio_miditofreq(smpl_t midi);
 
 uint_t aubio_silence_detection(fvec_t * ibuf, smpl_t threshold);
 smpl_t aubio_level_detection(fvec_t * ibuf, smpl_t threshold);
--- a/swig/aubio.i
+++ b/swig/aubio.i
@@ -121,8 +121,11 @@
 smpl_t aubio_quadfrac(smpl_t s0, smpl_t s1, smpl_t s2, smpl_t pf);
 uint_t vec_peakpick(fvec_t * input, uint_t pos);
 smpl_t aubio_bintomidi(smpl_t bin, smpl_t samplerate, smpl_t fftsize);
+smpl_t aubio_miditobin(smpl_t midi, smpl_t samplerate, smpl_t fftsize);
 smpl_t aubio_bintofreq(smpl_t bin, smpl_t samplerate, smpl_t fftsize);
+smpl_t aubio_freqtobin(smpl_t freq, smpl_t samplerate, smpl_t fftsize);
 smpl_t aubio_freqtomidi(smpl_t freq);
+smpl_t aubio_miditofreq(smpl_t midi);
 uint_t aubio_silence_detection(fvec_t * ibuf, smpl_t threshold);
 smpl_t aubio_level_detection(fvec_t * ibuf, smpl_t threshold);