Converting Frequency to Hex for Midi tuning Dump
May 26, 2009 at 4:46am
Converting Frequency to Hex for Midi tuning DumpI have written half of a Max program that generates certain frequencies that I wish to play via Midi keyboard. But I’m stuck at the point where I want to retune the MIDI synth on my Mac. I’ve read the page on MIDI.ORG < http://www.midi.org/techspecs/midituning.php> that spells out how to construct the System Exclusive Message, but I can’t understand how to convert frequency to two sets of hexadecimal numbers. First of all “are cents logarithmic?” and how the hell do they come up with “100 cents / 214 = .0061″ ? And just by the way, I don’t want to simply use a synthesizer, I need to reassign midi keys and frequencies. Thanks Jawny 

May 26, 2009 at 5:52am
There are 1200 cents in an octave, or 100 in a semitone. But why not work with a pitchbend? The math is a bit simpler and is quickly implemented. You’d have to convert frequency to a midi note number and a certain amount of pitch bend. And xbendout gives you have high precision. _ 

May 26, 2009 at 6:24am
how the hell do they come up with “100 cents / 214 = .0061″ ? To answer one part of your question, the [sxformat] object in Max will format and send your messages. It will send the values as hex, so you can determine the frequency in decimal (14bit value sent as two 7bit values) and it’ll make the hex conversion for you before it sends the data. 100 cents / 214 = 0.0061. Really? Not by my calculator. But it’s true if it’s “2 to the 14th” (14 bytes :: 100 / 16384 = 0.0061.) That’s a definite typo on their site which they should change. 

May 26, 2009 at 2:22pm
Ahhh, you’re a genius, it must be “two to the fourteenth” and it just doesn’t print well. So I haven’t had time to follow up on the sxformat object, but I know the message is supposed to be sent as three numbers that represent the desired pitch. the first is the highest standard midi key below the pitch you want, then the next two are the “cents”. But since the hex number “64″ equals 100, and that is easily achievable with one of the two numbers it sends, what is the use of having two hex numbers (128 x 128)to represent those one hundred tones? Ouch, I think I just answered my question, so what you’re saying is that each hex interval = .0061 of a cent. So let’s say I take the remainder when I convert frequency to midi, then scale the first two decimal places separately… No that only gives me a resolution of 100 (which is okay) but to actually get 16384 (128 x 128)resolution, I actually need to convert all the decimal remainder of the note to base 128, take the two most significant digits and convert them to hex. That’s just insane, am I missing something here? And btw, I don’t want to use the pitch wheel because any one note can be adjusted on the fly, and the xbend and bendout object affect either all notes or all notes with a similar midi key number, which limits the selection of notes and makes any scale over 12 tones impossible. But a good suggestion, Thanks 

May 26, 2009 at 6:59pm
jawnypants wrote on Tue, 26 May 2009 09:22 No, it’s pretty close, it’s another way to look at the numbers. But you don’t need to go to base 128, technically, because sxformat will take integer values and send hex. You take the decimal remainder (which is float and has a higher precision than 14bit), scale it to 14bit integer (016383), then find the MSB and LSB with [/ 128] and [% 128] — essentially converting to base 128, but getting the values as base 10 integers (from 0127 for each “digit”). These are the values your device should be expecting after a Tuning Change command. See if this works. You’ll have to supply the rest of the sxformat command.
– Pasted Max Patch, click to expand. –
Copy all of the following text.Then, in Max, select New From Clipboard.


Jun 18, 2009 at 5:08am


Jun 18, 2009 at 5:15am
SJJ, 

Jun 18, 2009 at 4:59pm
It wouldn’t help you much, as its useless if you don’t have more information about their sysex implementation. I doubt that it has any. Its a plug and play synth, not much to tweak. But who knows… Stefan 
You must be logged in to reply to this topic.