C Program Convert MIDI note to pitch

How to write a C Program Convert MIDI note to pitch in C Programming Language ?

This C Program Convert MIDI note to pitch.

Solution:

  1. #include <math.h>
  2. #include <stdio.h>
  3. typedef unsigned char byte;
  4.  
  5. // Convert MIDI note to pitch
  6.  
  7. void OnNoteOn(float *freqPtr, byte channel, byte note, byte velocity)
  8. {
  9.   if (velocity > 1)
  10.   {
  11.     printf(">>Frequency Before In Function: %f\n", freq);
  12.     *freqPtr = 440 * pow(2,(note/12));
  13.     printf(">>Frequency After In Function: %f\n", *freq);
  14.   }
  15. }
  16.  
  17. int main()
  18. {
  19.   float freq = 0;
  20.   printf("Frequency Before: %f\n", freq);
  21.   OnNoteOn(&freq, 1, 50, 20);
  22.   printf("Frequency After: %f\n", freq);
  23. }


Learn More :