BlogHotel.orgAccueil | Créer un blog | Imprimer la page Imprimer | Blog hasard Au hasard | Chercher des blogs Rechercher | Entrer dans le chat du blog Chat | | Jeux Jeux | Adminitration et édition du Blog Manager



Tworowski - Live Electronic Designer - Max-MSP

28/7/2005 - Midi to freq and freq to midi in C

/* here are the same two functions Mtof and FtoM but in c this time.

this way you can compare the two codes (Lisp and C)*/

 

// Mtof.c :
#include
#include
main ()
{
float freq;
int midi, midif;
printf("midi note : ");
scanf("%d", &midi);
midif = midi - 69;
freq = ((exp2(midif / 12.0)) * 440.0);
printf("%8.2f ", freq);
}

// from M.I.D.I to frequency

//______________second program____________________

//FtoM.c :
#include
#include
main ()
{
float freq, ref=440., semiton;
int midi;
printf("freq : ");
scanf("%f", &freq);
semiton = ((log(freq / ref) / log(2.0)) * 12.0);
midi = ((semiton + 69) + 0.5);
printf("%d ", midi);
}

// from frequency to M.I.D.I

The two includes are stdio.h and math .h (i don't really know why it does not appear in the code...)


<- Précédent :: Suivant ->

A Propos

Max-MSP patches and other stuff like C and Lisp...

Derniers Articles

Express yourself



Counter

<--live cam-->


Blog suivant >> Signaler un abus?Haut de page