@maruaudio/dsp/math/decibels converts decibels to linear amplitude in f64. dbToGain is the ordinary amplitude law, 10^(dB/20); dbToRbjAmplitude is the RBJ Audio EQ Cookbook term A, 10^(dB/40), used by peaking and shelf filters. Both are a single Math.pow call, so their edge behavior is ECMAScript's.
import { dbToGain, dbToRbjAmplitude } from "@maruaudio/dsp/math/decibels"
dbToGain(-6.020599913279624) // 0.5
dbToRbjAmplitude(12.041199826559248) // 2Functions
| Name | Input | Output | Domain as coded |
|---|---|---|---|
dbToGain | decibels | 10 ** (decibels / 20) | Any number; −Infinity → 0, +Infinity → +Infinity, NaN → NaN |
dbToRbjAmplitude | decibels | 10 ** (decibels / 40) | Same edges as dbToGain |
DECIBELS_ALGORITHM_REVISION | constant | 1 | Revision of this conversion law |
Lifecycle
None. Stateless functions with no preparation or instance state.
When to use it
Any place a level is set in decibels and applied as a multiplier: a gain control, a trim, a filter's boost or cut. Use dbToRbjAmplitude only for the cookbook's A term, as @maru/filters-biquad does. The reverse direction, gain to decibels, belongs to @maru/mixing-levels (shared behavior).
Limits
- f64 throughout; there is no
Math.fround. Callers that store f32 round the result themselves. - No clamp: very large inputs overflow to +Infinity (
Number.MAX_VALUEdoes), andNumber.MIN_VALUEreturns exactly 1.