Logarithmic function. TheVig Posting Freak Posts: 991 Threads: 249 Joined: Feb 2008 03-03-2010, 06:01 AM 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 Reply Reply TheVig Posting Freak Posts: 991 Threads: 249 Joined: Feb 2008 03-03-2010, 06:45 AM I tinkered around with the first part and came up with this... Function ExponentialFrequencyGrowth Code: ```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? Reply Reply Gintaras Administrator Posts: 11,093 Threads: 129 Joined: Dec 2002 03-03-2010, 07:09 AM I think you can use pow(2 x). Macro Macro848 Code: ```;int midi=0 int midi=127 double p=midi/12.7 double r=pow(2 p)*20 out r``` Reply Reply TheVig Posting Freak Posts: 991 Threads: 249 Joined: Feb 2008 03-03-2010, 07:47 AM 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 Reply Reply Gintaras Administrator Posts: 11,093 Threads: 129 Joined: Dec 2002 03-03-2010, 08:11 AM Macro Macro848 Code: ```;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: ```;/ 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)``` Reply Reply TheVig Posting Freak Posts: 991 Threads: 249 Joined: Feb 2008 03-03-2010, 07:25 PM 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 Reply Reply « Next Oldest | Next Newest »