We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Is it possible to create a mapping of values that outputs a logarithmic (exponential) value instead of linear? I need to program something similar as a knob or slider, controlling a filter cutoff frequency... (that's exactly what I need it for :)
Cheers, H.
Answers
Is it possible? Sure. But you're probably going to have to do it yourself, since I don't think there's a
logMap()
function or anything.But this isn't as complicated as it might sound. Take a look at the Processing source to see how the
map()
function works. Most of it is done in a single line:You're going to have to come up with a similar formula that does your logarithmic mapping. Try writing down a few input numbers with the output that you want for them until you see a pattern.
Ok, thanks! I will have to do some reading on how exactly are thos sliders / knobs working :)
A similar question has been asked before. This discussion might help.
Ok, I did this (I think it works fine):
I got the idea from this post: http://stackoverflow.com/questions/846221/logarithmic-slider
More examples of non-linear interpolation / mapping methods (common in music and animation software) include sinusoidal, cubic, etc.
For simple examples (in C++) check out "Interpolation methods" (Paul Bourke, 1999).
Notice that rather than writing a map for each, you could also write different versions of lerp() -- linear: lerp(), cubic: "cerp()", sinusoidal in/out: "sierp()" / "soerp()", etc. etc. -- and then feed the interpolated value into the basic map(), e.g.:
Edit: For examples of using built-in bezier functions to do curve-based interpolation, see: