DecibelUtils
Converts between linear ratios and decibels. A decibel value is a logarithm, so it is a plain number here rather than a [MetricUnit]: decibel gains add where linear ratios multiply, which does not fit MetricUnit's arithmetic.
Amplitude ratios (a signal's level, such as a voltage or a sample value) use 20 × log10; power ratios use 10 × log10. Halving the amplitude is about -6 dB; halving the power is about -3 dB.
DecibelUtils.amplitudeToDecibels(0.5) -- -6.0206
DecibelUtils.decibelsToAmplitude(-6) -- 0.5012
DecibelUtils.powerToDecibels(2) -- 3.0103
Check which kind a property is before converting: a volume that scales a signal is an amplitude ratio.
Functions
amplitudeToDecibels
DecibelUtils.amplitudeToDecibels(ratio: number--
1 is unchanged
) → numberThe decibels of an amplitude ratio: 20 × log10(ratio). A ratio of 0 is negative infinity (silence).
decibelsToAmplitude
DecibelUtils.decibelsToAmplitude(decibels: number--
0 is unchanged
) → numberThe amplitude ratio of a decibel gain: 10 ^ (decibels / 20).
powerToDecibels
DecibelUtils.powerToDecibels(ratio: number--
1 is unchanged
) → numberThe decibels of a power ratio: 10 × log10(ratio). A ratio of 0 is negative infinity.
decibelsToPower
DecibelUtils.decibelsToPower(decibels: number--
0 is unchanged
) → numberThe power ratio of a decibel gain: 10 ^ (decibels / 10).