2

I have a sound file and I am using the audio gain node to control how loud the file should play. The sound values go from 0 to 1, 1 being the max volume

The user can pick between 12 levels of volume, which should change the sound in a logarithmic way. I just can't figure out the formula for it.

I'm currently using a formula to normalize the 1-2 values to a 0 to 1 range, however I'm not sure how to increase the gain non linearly.


// sound level = the value between 0 and 1, corresponding to the user input which is from 1 to 12.
export const setSoundFileVolume = (soundLevel) => {
  return (((100 / 12) * Number(soundLevel));
};

How can I set the sound logarithmically?

1 Answers1

2

I normally use this function (in C):

double linear_to_logarithmic(double x){
    return log2(1+x);
};

But in javascript, maybe you should have a look at this:

https://stackoverflow.com/a/846249/5832844

Ruben Medrano
  • 161
  • 2
  • 10