
Exponential parameter mapping
References : Posted by Russell Borogove
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 : float logmax = log10f( mMax );
float logmin = log10f( mMin );
float logdata = (mParam * (logmaxlogmin)) + logmin;
mData = powf( 10.0f, logdata );
if (mData < mMin)
{
mData = mMin;
}
if (mData > mMax)
{
mData = mMax;
} 
Comments
Added on : 25/03/02 by rerdavies[ AT ]msn[ DOT ]com Comment : No point in using heavy functions when lighterweight functions work just as well. Use ln instead of log10f, and exp instead of pow(10,x). Loglinear is the same, no matter which base you're using, and base e is way more efficient than base 10.
Added on : 05/12/02 by kaleja[ AT ]estarcion[ DOT ]com Comment : 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.
Added on : 21/08/03 by act_ion[ AT ]yahoo[ DOT ]com Comment : Just made my day!
pretty useful :) cheers Aktion
Added on : 08/09/06 by agillesp[ AT ]gmail Comment : You can trade an (expensive) ln for a (cheaper) divide here because of the logarithmic identity:
ln(x)  ln(y) == ln(x/y)

Add your own comment
Comments are displayed in fixed width, no HTML code allowed! 



