Posts: 991

Threads: 249

Joined: Feb 2008

Say I have a range: 20Hz - 20kHz

I want to have the midi values 0-127 increase from 20 to 20k using a logarithmic scale that will assign each octave the same amount of Midi steps.

Now another kicker is that there will be a fine tuner knob that will assign 128 steps to each octave using the frequency of the coarse tuner as it's central frequency for the octave designation.

Thanks,

jimmy Vig

Posts: 991

Threads: 249

Joined: Feb 2008

I tinkered around with the first part and came up with this...

Function

ExponentialFrequencyGrowth

`function int'Midi`

double low=20

int high=20000

rep Midi

,low*1.056

int Freq=low+0.5

out Freq

I'm not sure if it's right. Really I don't know how to do math functions with QM...any help?
Posts: 11,001

Threads: 128

Joined: Dec 2002

I think you can use pow(2 x).

Macro

Macro848

`;int midi=0`

int midi=127

double p=midi/12.7

double r=pow(2 p)*20

out r

Posts: 991

Threads: 249

Joined: Feb 2008

That works. It's pretty close to what I had worked out, only a couple hundred Hz at 20k which isn't bad for hacking around.

I've just about got it all worked out. The pow is much cleaner than my hack way! Thanks bunches!

jimmy Vig

Posts: 11,001

Threads: 128

Joined: Dec 2002

Macro

Macro848

`;int midi=0`

int midi=127

double p=midi/12.7436031497752

double r=pow(2 p)*20

out r

How to get the 12.7436031497752:

out 127/log2(20000.0/20)

Function log2

`;/`

function^ ^value

;Calculates base 2 logarithm. Ie power to which must be raised 2 to get value.

;For natural logarithm, instead use log. For base 10 - log10.

ret log(value)/log(2)

Posts: 991

Threads: 249

Joined: Feb 2008

Thanks a bunch. Geeze, talk about being able to write mathematically precise functions with QM now.

I'll be sure to post what I have when I get it finished, I don't know if many people will use it, but if there is ever another audio techie surfing the forum, they'll get a dose of fun with program control via midi.

Thanks,

jimmy Vig