mirror of
https://github.com/captbaritone/webamp.git
synced 2026-07-22 09:37:17 +00:00
Fixes issue #717
GainNode now attenuates or boosts the signal correctly, according to the logarithmic dB scale
This commit is contained in:
parent
b351a29e5b
commit
99b4ad5f98
1 changed files with 3 additions and 4 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue