Hi i’m facing a problem with respect to decibel convertion
Question: html5 volume accepted range is between 0 – 1 now how to convert decibel value i,e between -96 to 96 into 0-1.
Here is what i have tried:
function linearToDecibel(linearValue) {
// Convert linear value to decibels
var decibelValue = 20 * Math.log10(linearValue);
return decibelValue;
}
console.log(linearToDecibel(96)) // my expection is value 1 or 100%
Further conversion i dont know please help me.
2
Answers
To convert -96 -> 96 on a range of 0 -> 1 you can
(x + 96) / (96 * 2)
And you can simplify by
(x + 96) / 192
You can normalize the
value
based on thefromRange
, and then scale it to thetoRange
.