Exponential volume control with a specified midpoint

Posted by Lars on Stack Overflow See other posts from Stack Overflow or by Lars
Published on 2014-06-06T19:59:27Z Indexed on 2014/06/06 21:26 UTC
Read the original article Hit count: 290

Filed under:
|
|
|

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));


}

© Stack Overflow or respective owner

Related posts about math

Related posts about volume