From 7db50080c38cf885f0ff83b4711e3410160b5536 Mon Sep 17 00:00:00 2001 From: Marat Fayzullin Date: Mon, 20 May 2024 23:57:17 -0400 Subject: [PATCH] Cleaned up volume to gain translation. --- htdocs/lib/UI.js | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/htdocs/lib/UI.js b/htdocs/lib/UI.js index e2948549..23b00a9a 100644 --- a/htdocs/lib/UI.js +++ b/htdocs/lib/UI.js @@ -75,13 +75,11 @@ UI.setVolume = function(x) { this.volume = x; LS.save('volume', x); $('#openwebrx-panel-volume').val(x) - //Map 0-150 to -60 to 0db gain - xdb = (x / 2.5) - 60; - gain = Math.pow(10, xdb / 20); - if (x == 0) { - gain = 0; + if (audioEngine) { + // Map 0..150 to -60..0db gain + gain = x > 0? Math.pow(10, ((x / 2.5) - 60) / 20) : 0; + audioEngine.setVolume(gain); } - if (audioEngine) audioEngine.setVolume(gain); } };