Forums > MaxMSP

Converting Frequency to Hex for Midi tuning Dump


May 26, 2009 | 5:52 am

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.

_
johan


May 26, 2009 | 6:24 am
jawnypants wrote on Mon, 25 May 2009 23:46
But I should go back to the beginning, probably, and ask if there is a Max object that already converts frequency to SysEx Hex.

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 (14-bit value sent as two 7-bit 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.
Smile


May 26, 2009 | 2:22 pm

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 | 6:59 pm

jawnypants wrote on Tue, 26 May 2009 09:22
to 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?

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 14-bit), scale it to 14-bit integer (0-16383), then find the MSB and LSB with [/ 128] and [% 128] — essentially converting to base 128, but getting the values as base 10 integers (from 0-127 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. –

June 18, 2009 | 5:08 am


June 18, 2009 | 5:15 am

SJJ,
First of all, thanks for the excellent patchwork you sent; sorry it took so long for me to reply, but I had to upgrade to Max 5 AND I only get to hack at this occasionally.
The patch you wrote apparently works beautifully, I’ve got sxformat set to send a single note tuning change, and I’ve captured its output, which looks correct.
One "last" question, does anyone know the device ID of the built in Apple AU Synth? SXFORMAT needs a number and the only identifier I can find for the AU Synth is "a". I tried getting it using umenu, but it only pulls up the names, not the device ID numbers.


June 18, 2009 | 4:59 pm

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


Viewing 8 posts - 1 through 8 (of 8 total)