Calculation synthesizer midi values :)

wimvandenborre

New member
Joined
Mar 23, 2022
Messages
3
Hey everyone,

I'm coding a program that converts incoming midi notes to an external synth, i have all the formulas for calculating midi notes to herzt (frequency of a note) but now I need to calculate this to an external synth which accepts tuning values from 0 to 255, see below.

I'm now trying to find how to calculate from midi notes to the 0 to 255 values or from first converting midi to frequency, then (insert formula :) ) from frequency to 0 to 255 values.

Any help would be appreciated.

So: value 0 = C1 = 32.70 hz. = midi note 24
value 127 = C2 = 65.41 hz. = midi note 36
value 255 = C3 = 130.81 hz = midi note 48

I have found that converting midi notes to hertz is this function:

1
2
3
4
5
6

float noteToFreq(int note) {
float a = 440; //frequency of A (coomon value is 440Hz)
return (a / 32) * pow(2, ((note - 9) / 12.0));
}


So now I need to convert the incoming midi notes to the outgoing value 0 to 255.
 
I don't know that much about music theory so I have a couple of questions. Apparently the midi notes correspond to half steps on a keyboard? Is that correct? Have you thought about going directly from midi notes to synth values? It's easy to get 0, 127, 255 from 24, 36, 48. What are the synth values you need for the 12 half steps between C2 and C3? It might be easier to calculate them directly from the midi numbers. I'm guessing it will be easier if you skip the frequencies in the calculations. Take into consideration that I might not know what I'm talking about here.
 
I don't have other calculations at this moment but indeed, there are 12 semitones in an octave, every midi note is a half step.

Will see if i can find more synth points but I think this data should be enough, I hope :D
 
Hey hey, I solved it, I just diveded 128 by 12 (to get the 12 semitones)= 10,62 then I deduct the incoming midi note with 24 and multiply the remainder with 10,62. It works :)
 
And apparently you didn't need to use the frequencies as I suspected, right?
 
Top