Exponential volume control with a specified midpoint
- by Lars
I have a slider that returns values from 0 to 100.
I am using this to control the gain of an oscillator.
When the slider is at 0, I would like the gain to be 0.0
When the slider is at 50, I would like the gain to be 0.1
When the slider is at 100, I would like the gain to be 0.5
So I need to find an equation to get a smooth curve which passes through all of these points.
I've got the following equation which gives an exponential curve and gets the start and end points correct, but I don't know how to force the curve through the middle point. Can anyone help?
function logSlider(position){
var minP = 0;
var maxP = 100;
var minV = Math.log(0.0001);
var maxV = Math.log(0.5);
var scale = (maxV - minV) / (maxP - minP);
return Math.exp(minV + scale*(position-minP));
}