Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Logarithmic function.
#1
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
#2
I tinkered around with the first part and came up with this...
Function ExponentialFrequencyGrowth
Code:
Copy      Help
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?
#3
I think you can use pow(2 x).

Macro Macro848
Code:
Copy      Help
;int midi=0
int midi=127

double p=midi/12.7
double r=pow(2 p)*20
out r
#4
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
#5
Macro Macro848
Code:
Copy      Help
;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
Code:
Copy      Help
;/
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)
#6
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


Forum Jump:


Users browsing this thread: 1 Guest(s)