Exponential parameter mapping

  • Author or source: Russell Borogove
  • Created: 2002-03-17 15:42:33
notes
Use this if you want to do an exponential map of a parameter (mParam) to a range (mMin -
mMax).
Output is in mData...
code
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
float logmax = log10f( mMax );
float logmin = log10f( mMin );
float logdata = (mParam * (logmax-logmin)) + logmin;

mData = powf( 10.0f, logdata );
if (mData < mMin)
{
  mData = mMin;
}
if (mData > mMax)
{
  mData = mMax;
}

Comments

No point in using heavy functions when lighter-weight functions work just as well. Use ln instead of log10f, and exp instead of pow(10,x). Log-linear is the same, no matter which base you're using, and base e is way more efficient than base 10.
Thanks for the tip. A set of VST param wrapper classes which offers linear float, exponential float, integer selection, and text selection controls, using this technique for the exponential response, can be found in the VST source code archive -- finally.
Just made my day!
pretty useful :) cheers Aktion
You can trade an (expensive) ln for a (cheaper) divide here because of the logarithmic identity:

ln(x) - ln(y) == ln(x/y)