I'm working with the AudioContext() on a hearing-test and I was wondering how to raise/lower the volume by x dB. Is it even possible?
At the moment, I have a gainNode connected to my AudioContext, which looks (in short) like this:
var context = new AudioContext(), gainNode;
context.decodeAudioData(req.target.response, function(buffer) {
gainNode = context.createGain();
...
}
To change the volume I do this:
gainNode.gain.value = {-1 to 1}
Here, I don't have a chance to exactly define a dB value. Are there other ways?
I think the problem is, the browser never knows the exact volume of the sound coming out of the speakers, therefore there is no base to calculate a new dB-volume.
An approach to determine the current dB-value is via the difference of 2 sounds, such as a test sound (white noise) and spoken numbers. To calculate the difference I found the formula:
20 * Math.log10(gainNoise / gainSpeech);
Then I have a basis of e.g. -6 dB, when speech is -0.6 and noise is -0.3. But how do I raise this value by a certain dB value?
Example: I raise -6 dB by 5 dB to -1 dB. How do I recalculate speech / noise?