PDA

View Full Version : Logarithmic knob Frequency Scaling


pylorca
09-02-2010, 04:02 PM
Hi!

Is in IPlug any way to specify the scale to use in a knob?

I've a knob from 20 to 22000 hz, it is very hard to set low frequencies.

Thanks

cerberus
09-02-2010, 10:45 PM
sure, the faders in the iplug example project are logarithmically scaled to db. so as one moves a
fader down: the db reduction per unit of fader travel becomes progressively greater. similarly,
one could apply any 2 dimensional curve function to any fader or knob.

olilarkin
09-03-2010, 03:04 AM
GetParam(kFilterCutoff)->InitDouble("Cutoff", 1000., 20., 10000., 0.000001, "Hz");
GetParam(kFilterCutoff)->SetShape(2.);


"The higher the shape, the more resolution around host value zero."

it doesn't work in AUs when you use the default interface

oli

pylorca
09-03-2010, 08:28 AM
GetParam(kFilterCutoff)->InitDouble("Cutoff", 1000., 20., 10000., 0.000001, "Hz");
GetParam(kFilterCutoff)->SetShape(2.);


"The higher the shape, the more resolution around host value zero."

it doesn't work in AUs when you use the default interface

oli

thanks it works fine :)

cerberus
09-03-2010, 06:49 PM
"The higher the shape, the more resolution around host value zero."


cool, i am starting to understand how to use the IParam class a bit better
from this tip, (i mean classes in general, seeing as i'm also learning c+)
e.g. i am calculating normalized values to set controls, but
i think i notice now there is a function to do that ( SetNormalized() ) ?


it doesn't work in AUs when you use the default interface

thanks. that is useful to know: for now i have scaled a control by
applying a calculated curve to the variable it affects.

Soundemote
10-19-2014, 08:14 PM
What's the math behind SetShape?

Tale
10-19-2014, 11:13 PM
I believe f(x) = x^shape, see FromNormalizedParam() and ToNormalizedParam() in IParam.h.

antto
10-21-2014, 01:37 AM
it's pow(normalized, SHAPE) and the reverse is done with pow(normalized, 1.0/SHAPE)

at shape 2.0 you get 0.25 (25%) in the middle of the param

i often want to set the shape so that a specific value of the parameter falls on the center
say, you have a freq param going from 20Hz to 18000Hz and you want to have 500Hz in the center

i can't pretend to like maths, so i use wolframalpha or a similar tool
the formula to get the "shape" is:
min + (0.5^x) * (max-min) = value
so in my case:
20 + (0.5^x) * (18000-20) = 500
http://www.wolframalpha.com/input/?i=20+%2B+%280.5^x%29+*+%2818000-20%29+%3D+500%2C+solve+for+real+x

shape = 5.2272

Soundemote
10-21-2014, 02:46 AM
thanks, very helpfuel!!

Andi!
07-10-2017, 01:40 AM
it doesn't work in AUs when you use the default interface

oli

Does anybody manage to assign a logarithmic frequency parameter to the AU automation ? I tried this my setting the flag kAudioUnitParameterFlag_DisplayLogarithmic and unit kAudioUnitParameterUnit_Hertz in IPlugAU.cpp and the AU validation shows that the flag/unit is assign correctly but the automation lines at least in Reaper and Garageband are still linear (very low resolution in the lower frequencies). Studio one additionally displays wrong frequency numbers, but it seems that the line is logarithmic. It seems that the flag is somehow ignored in some DAWs.

hannesmenzel
07-31-2018, 03:10 PM
Thanks to this old thread I could figure this out. After having some struggle with reactivating my old school math the equation should be:

shape = log((center value - min) / (max - min)) / log(0.5)

so, for antto's example (filter from 20 to 18000 centered @ 500 Hz:

shape = log((500-20) / (18000 - 20)) / log(0.5) = 5.2272148047932911480721579798557

So, you won't need to have a Wolfram Alpha premium account, the calculator on the table solves it. The 0.5 can be adjusted to where ever the knob should default, in the middle should work in most cases.

If anybody can tell me, which log is actually right, I would appreciate it. In this example both LN and LOG works.

Tale
08-01-2018, 12:51 AM
If anybody can tell me, which log is actually right, I would appreciate it. In this example both LN and LOG works.
Yeah, and it will also work with LOG2, or any base for that matter, as long as you use the same base for both logs (see Wikipedia (https://en.wikipedia.org/wiki/Logarithm#Change_of_base)). So LN is probably best, because it is likely more efficient.

earlevel
08-03-2018, 11:11 AM
Yeah, and it will also work with LOG2, or any base for that matter, as long as you use the same base for both logs (see Wikipedia (https://en.wikipedia.org/wiki/Logarithm#Change_of_base)). So LN is probably best, because it is likely more efficient.

Curious—why would LN likely be more efficient? I mean, it doesn't really matter, but on a binary cpu you'd think log2 is the first choice. Anyway, the difference between any will be very small, so use whatever you want. :)

Tale
08-04-2018, 01:10 AM
Curious—why would LN likely be more efficient? I mean, it doesn't really matter, but on a binary cpu you'd think log2 is the first choice.
When using x87 log2 probably is faster. However, when using SSE2 the log functions are likely calculated in software, so it depends on the math lib implementation. In MSVC log(x) seems to be faster than log2(x) or log10(x). Do note that log2(x) is more precise than log(x)/log(2) though.