From 99b4ad5f982c98116a9b8d15778b0bb98ef104fe Mon Sep 17 00:00:00 2001 From: Chuf <42591821+gapeman@users.noreply.github.com> Date: Thu, 14 Mar 2019 20:32:54 +0100 Subject: [PATCH] Fixes issue #717 GainNode now attenuates or boosts the signal correctly, according to the logarithmic dB scale --- js/media/index.ts | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/js/media/index.ts b/js/media/index.ts index 471b1a83..cbc54819 100644 --- a/js/media/index.ts +++ b/js/media/index.ts @@ -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