Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

149
Views
How to set the volume logarithmically instead of linearly?

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?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

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

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!