Fixes issue #717

GainNode now attenuates or boosts the signal correctly, according to the logarithmic dB scale
This commit is contained in:
Chuf 2019-03-14 20:32:54 +01:00 committed by Jordan Eldredge
parent b351a29e5b
commit 99b4ad5f98

View file

@ -188,13 +188,12 @@ export default class Media {
this._gainNode.gain.value = volume / 100;
}
// From 0 to 100
// The input value here is 0-100 which is kinda wrong, since it represents -12db to 12db.
// For now, 50 is 0db (no change).
// For now we map the values 0-100 to 0.25-1.75
// Equation used is: 10^((dB)/20) = x, where x (preamp.gain.value) is passed on to gainnode for boosting or attenuation.
setPreamp(value: number) {
const percentDelta = (value - 50) * 0.02;
this._preamp.gain.value = 1 + percentDelta * 0.75;
const db = (value / 100) * 24 - 12;
this._preamp.gain.value = Math.pow(10,(db/20));
}
// From -100 to 100