acoustic-decibels
v2.0.1
Published
Sound-level maths: dB SPL conversions, incoherent source summation, distance attenuation and A-weighting.
Maintainers
Readme
acoustic-decibels
The decibel arithmetic you always end up re-deriving when working with sound levels. Pure ESM, zero dependencies.
- SPL ⇄ sound pressure (reference: 20 µPa)
- combine incoherent sources on an energy basis
- back out one level from a measured total (background subtraction)
- point-source inverse-square distance attenuation
- IEC 61672 A-weighting
Why decibels are annoying
They add logarithmically. Two identical machines are not "twice as loud" — they
are +3 dB. Ten of them are +10 dB. This library does that bookkeeping so you
do not have to keep 10^(L/10) in your head.
import { combineLevels, attenuateDistance, applyAWeighting } from 'acoustic-decibels';
combineLevels(80, 80); // 83.01 dB
combineLevels(...Array(10).fill(70)); // 80 dB
// a 100 dB point source, heard at 4 m instead of 1 m
attenuateDistance(100, 1, 4); // ~88 dB
// weight an 90 dB tone at 1 kHz for perceived loudness
applyAWeighting(90, 1000); // ~90 dBAPressure conversions
import { splFromPressure, pressureFromSpl } from 'acoustic-decibels';
splFromPressure(1); // 93.98 dB SPL (1 Pa)
pressureFromSpl(94); // ~1.0 PaA-weighting
aWeighting(f) returns the correction (dB) for a band at frequency f,
normalised to 0 dB at 1 kHz per the standard A-curve. Roughly -19 dB at
100 Hz, +1.2 dB around 2.5 kHz, rolling back off in the treble.
License
Apache-2.0
