Change volume slider to a logarithmic scale

This commit is contained in:
Christopher Andrews 2024-05-19 09:49:43 +10:00
parent dffb7a84b6
commit 2be9d73943
No known key found for this signature in database
GPG Key ID: 5057A0B271D87046
2 changed files with 5 additions and 2 deletions

View File

@ -225,7 +225,7 @@
<svg class="unmuted" viewBox="0 0 80 80"><use xlink:href="static/gfx/svg-defs.svg#speaker"></use></svg>
<svg class="muted" viewBox="0 0 80 80"><use xlink:href="static/gfx/svg-defs.svg#speaker-muted"></use></svg>
</div>
<input title="Volume" id="openwebrx-panel-volume" class="openwebrx-panel-slider" type="range" min="0" max="150" value="50" step="1" onchange="UI.setVolume(this.value);" oninput="UI.setVolume(this.value);">
<input title="Volume" id="openwebrx-panel-volume" class="openwebrx-panel-slider" type="range" min="0" max="150" value="100" step="1" onchange="UI.setVolume(this.value);" oninput="UI.setVolume(this.value);">
<div title="Tuning step" class="openwebrx-button openwebrx-slider-button" onclick="tuning_step_reset();">
<svg viewBox="0 0 80 80"><use xlink:href="static/gfx/svg-defs.svg#tuning-step"></use></svg>
</div>

View File

@ -75,7 +75,10 @@ UI.setVolume = function(x) {
this.volume = x;
LS.save('volume', x);
$('#openwebrx-panel-volume').val(x)
if (audioEngine) audioEngine.setVolume(x / 100);
//Map 0-150 to -60 to 0db gain
xdb = (x / 2.5) - 60;
gain = Math.pow(10, xdb / 20);
if (audioEngine) audioEngine.setVolume(gain);
}
};