Changeset 79c2e52 for src/mathutils.c


Ignore:
Timestamp:
Aug 22, 2005, 10:59:13 PM (14 years ago)
Author:
Paul Brossier <piem@altern.org>
Branches:
feature/autosink, feature/constantq, feature/pitchshift, feature/pydocstrings, feature/timestretch, master, pitchshift, sampler, timestretch, yinfft+
Children:
3ec9d9c
Parents:
98ef4df
Message:

added bintomidi, freqtobin, miditofreq

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/mathutils.c

    r98ef4df r79c2e52  
    346346
    347347smpl_t aubio_freqtomidi(smpl_t freq) {
    348   smpl_t midi = freq/6.875;
    349   /* log(freq/A-2)/log(2) */
    350   midi = LOG(midi)/0.69314718055995;
    351   midi *= 12;
    352   midi -= 3; 
    353   return midi;
     348        /* log(freq/A-2)/log(2) */
     349        smpl_t midi = freq/6.875;
     350        midi = LOG(midi)/0.69314718055995;
     351        midi *= 12;
     352        midi -= 3; 
     353        return midi;
     354}
     355
     356smpl_t aubio_miditofreq(smpl_t midi) {
     357        smpl_t freq = (midi+3.)/12.;
     358        freq = EXP(freq*0.69314718055995);
     359        freq *= 6.875;
     360        return freq;
    354361}
    355362
     
    359366}
    360367
    361 
    362368smpl_t aubio_bintomidi(smpl_t bin, smpl_t samplerate, smpl_t fftsize) {
    363369  smpl_t midi = aubio_bintofreq(bin,samplerate,fftsize);
    364370  return aubio_freqtomidi(midi);
     371}
     372
     373smpl_t aubio_freqtobin(smpl_t freq, smpl_t samplerate, smpl_t fftsize) {
     374  smpl_t bin = fftsize/samplerate;
     375  return freq*bin;
     376}
     377
     378smpl_t aubio_miditobin(smpl_t midi, smpl_t samplerate, smpl_t fftsize) {
     379  smpl_t freq = aubio_miditofreq(midi);
     380  return aubio_freqtobin(freq,samplerate,fftsize);
    365381}
    366382
Note: See TracChangeset for help on using the changeset viewer.