audiocn

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.

LevelWhat it sounds like
0 dBFSFull scale. Anything louder clips and distorts.
−6 dBFSAbout half the amplitude
−18 to −12 dBFSA good level for speech
−60 dBFSThe bottom of a typical meter
-InfinityDigital 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:

PresetAttackReleasePeak hold
peak15 msfalls about 25 dB per second1.2 s
vu300 ms300 msnone
instantnonenonenone

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"
ModuleWhat it has
decibelsdbToGain, gainToDb, dbToLevel, levelToDb, clampDb, formatDb, peakDb, rmsDb
ballisticscreateBallistics, BALLISTICS, resolveBallistics
zonesDEFAULT_ZONES, zoneForDb, CLIP_THRESHOLD_DB, CLIP_HOLD_MS
taperlinearTaper, audioTaper, logTaper, resolveTaper
bandslogBandEdges, bandsFromSpectrum, resampleLevels
timeformatTime
frame-loopsubscribeFrame, one animation-frame loop for the page
frame-sourcecreateFrameEmitter, createFrameRelay
typesMeterFrame, 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.