Decibels and levels
The units audiocn uses, and the helpers in the audio core that convert between them.
Audio levels span a huge range, so audio tools measure them in decibels (dB), a logarithmic scale. audiocn uses dB wherever audio engineers would.
dBFS
dBFS means decibels relative to full scale. 0 dBFS is the loudest a digital signal can be; everything else is negative. Silence is -Infinity.
| Level | What it sounds like |
|---|---|
| 0 dBFS | Full scale. Anything louder clips and distorts. |
| −6 dBFS | About half the amplitude |
| −18 to −12 dBFS | A good level for speech |
| −60 dBFS | The bottom of a typical meter |
-Infinity | Digital silence |
Meters show dBFS. By default they cover −60 to 0 dBFS and colour three zones: green below −20, amber from −20, and red from −9.
dB as gain
A fader's value is gain in dB: how much a channel is raised or lowered. 0 dB leaves the signal unchanged, −6 dB halves the amplitude, and +6 dB doubles it. Faders can reach -Infinity to silence a channel completely.
Peak and RMS
- Peak is the loudest single sample. It tells you whether you are about to clip.
- RMS is the average power. It is closer to how loud something sounds.
Speech usually peaks 10–15 dB above its RMS. A dual meter shows both.
Ballistics
A meter that showed every sample would flicker too fast to read. Ballistics decide how it moves:
| Preset | Attack | Release | Peak hold |
|---|---|---|---|
peak | 15 ms | falls about 25 dB per second | 1.2 s |
vu | 300 ms | 300 ms | none |
instant | none | none | none |
The audio core
@audiocn/core (installed as lib/audio) has the maths every component uses:
import { dbToGain, dbToLevel, formatDb, gainToDb } from "@/lib/audio/decibels";
dbToGain(-6); // 0.501
gainToDb(0.5); // -6.02
dbToLevel(-30); // 0.5, linear in dB over −60..0
formatDb(-12.34); // "−12.3 dB"
formatDb(-Infinity); // "−∞ dB"| Module | What it has |
|---|---|
decibels | dbToGain, gainToDb, dbToLevel, levelToDb, clampDb, formatDb, peakDb, rmsDb |
ballistics | createBallistics, BALLISTICS, resolveBallistics |
zones | DEFAULT_ZONES, zoneForDb, CLIP_THRESHOLD_DB, CLIP_HOLD_MS |
taper | linearTaper, audioTaper, logTaper, resolveTaper |
bands | logBandEdges, bandsFromSpectrum, resampleLevels |
time | formatTime |
frame-loop | subscribeFrame, one animation-frame loop for the page |
frame-source | createFrameEmitter, createFrameRelay |
types | MeterFrame, VisualFrame, FrameSource, MeterZone, Taper |
Volume in players
Players are the one exception. VolumeControl and AudioPlayer use a 0..1 volume, the same as HTMLMediaElement.volume, because that is what media elements expect.