Lesson 12 of 15
Decibels to Gain
Decibels
Decibels (dB) measure sound level on a logarithmic scale, matching how human hearing perceives loudness.
dB to Linear Gain
The Web Audio API's GainNode expects a linear gain value (0 to 1+). Convert from dB:
gain = 10^(dB / 20)
Key Reference Points
| dB | Gain | Meaning |
|---|---|---|
| 0 | 1.0000 | Unity — no change |
| −6 | 0.5012 | Approximately half loudness |
| −20 | 0.1000 | One-tenth amplitude |
| +6 | 1.9953 | Approximately double loudness |
| −∞ | 0 | Silence |
Why Logarithmic?
A 6 dB increase always doubles the amplitude, regardless of the starting level. This matches how we perceive sound — each doubling of loudness feels like a similar step up.
Your Task
Implement dBToGain(db) that converts decibels to linear gain.
Run your code to hear the same note played at 0 dB and −12 dB.
Web Audio API loading...
Loading...
Click "Run" to execute your code.