Master Audio: Presets and the Chain
The shortest path from a decoded buffer to a master is one call: masterAudio takes a preset (a named chain configuration), optionally a few overrides, and runs every enabled stage in a fixed order. This page covers that path: the presets, how to call the chain, the order it runs in, the loudness stage that ends it, and the JSON document a chain configuration serializes to. The result carries a report you can show before and after.
If dBFS, headroom, or mastering chain are unfamiliar, read Audio Basics and What Is Mastering? first.
Choose a path
| You want to… | Go to |
|---|---|
| Master a file with a preset, adjusting a value or two | This page |
| Have the library profile the source and propose a chain, with reasons | Mastering Assistant |
| Run one processor, a pair analysis, or load one as an insert | Mastering Processors |
| Clean noise, clicks, hum, clipping or reverb first | Audio Repair |
| See how the browser demo maps its controls onto the chain | Mastering Demo Implementation |
What You Will Learn
By the end of this page you should be able to:
- choose a preset by name and render it with
masterAudio; - override single values without leaving the preset's chain shape;
- predict which stages run and in which order, and drive a progress bar from the run;
- explain how the loudness stage reaches its target without crossing the true-peak ceiling;
- read and write the chain-config JSON document the CLI and the assistant exchange.
Presets
Presets are named chain configurations, not separate algorithms. Apply one with masterAudio({ samples, sampleRate, preset, overrides }); a preset name that does not exist throws RangeError.
pop, edm, acoustic, hipHop, aiMusic, speech, streaming, youtube, broadcast, podcast, audiobook, cinema, jpop, ambient, lofi, classical, drumAndBass, techno, metal, trap, rnb, jazz, kpop, trance, gameOst, vinyl, tapeHiss, fieldRecording, voiceMemo, shellac78
masteringPresetNames() returns this compact name list. The capability catalog's masteringPresets array adds kind, targetLufs, truePeakCeilingDbtp, and maxLimiterGainReductionDb for each name; restoration entries (kind: 'restoration') carry only name and kind, with no numeric fields. Use masteringPresetParams(preset) to expand a selected name into the chain config masterAudio accepts as overrides: nested objects in JavaScript and Node, flat dotted keys in Python and C.
See Choosing a Mastering Preset for how to pick one without treating a preset as a finished master.
The last five names (vinyl, tapeHiss, fieldRecording, voiceMemo, shellac78) are restoration presets: they enable repair stages only, with no loudness target, no ceiling, no tone or dynamics stage. Which stages each one turns on is a table on Audio Repair.
Master in one call
Start from a preset, then override only what you can name. Each step below keeps the previous one's chain shape.
import { init, masterAudio } from '@libraz/libsonare';
await init();
// 1. A preset alone.
const quick = masterAudio({ samples, sampleRate, preset: 'pop' });
// 2. The same preset with the loudness target and one compressor value overridden.
const progress: [number, string][] = [];
const tuned = masterAudio({
samples,
sampleRate,
preset: 'pop',
overrides: { loudness: { targetLufs: -16 }, dynamics: { compressor: { thresholdDb: -20 } } },
onProgress: (fraction, stage) => progress.push([fraction, stage]),
});
quick.stages; // the stages that ran, in chain order
progress[progress.length - 1]; // [1, 'loudness.optimize']: the last stage ends the bar
tuned.report.after.integratedLufs; // close to the -16 LUFS targetimport { masterAudio } from '@libraz/libsonare-native';
const quick = masterAudio({ samples, sampleRate, preset: 'pop' });
const tuned = masterAudio({
samples,
sampleRate,
preset: 'pop',
overrides: { loudness: { targetLufs: -16 }, dynamics: { compressor: { thresholdDb: -20 } } },
onProgress: (fraction, stage) => console.log(stage, fraction),
});
console.log(quick.stages, tuned.report.after.integratedLufs);import libsonare as sonare
quick = sonare.master_audio(samples, sr, preset="pop")
tuned = sonare.master_audio(
samples, sr,
preset="pop",
overrides={"loudness": {"targetLufs": -16}, "dynamics": {"compressor": {"thresholdDb": -20}}},
on_progress=lambda fraction, stage: print(stage, fraction),
)
print(quick.stages, tuned.report.after.integrated_lufs)sonare mastering source.wav --preset pop -o quick.wav
sonare mastering source.wav --preset pop \
--params loudness.targetLufs=-16,dynamics.compressor.thresholdDb=-20 \
--report mastering-report.json -o tuned.wavmasterAudioStereo takes left and right instead of samples and returns left and right; the stereo stages (stereo.imager, stereo.monoMaker) run only on that path. A single processor is a different call, masteringApplyProcessor, and a profile-and-suggest flow is the Mastering Assistant.
What the progress callback counts
onProgress reports the fraction of enabled DSP stages completed so far, with the name of the stage that just finished. Disabled stages are not counted, so the denominator is the chain you configured. The pop preset enables five stages, so the fractions are 0.2, 0.4, 0.6, 0.8 and 1.
The fraction reaches 1 as the last DSP stage returns. The trailing work (output measurement, spectrum, and the band deltas of the returned report) reports nothing, so the call keeps running for a moment once the bar is full. Drive a progress bar from the callback, but hold the UI in its working state until the call itself resolves.
Chain order
A full chain, masterAudio and every preset, runs its slots in one fixed order: repair → eq → dynamics → saturation → spectral → stereo (on the stereo path only) → maximizer → loudness. A configuration chooses which slots run, never where. The figure shows every slot the engine has, in run order, with the ones the pop preset enables filled in; the empty ones are still there in place, waiting for a configuration that turns them on.
- enabled in this configuration
- available, not enabled
Six repair stages share the first slot and run from damage confined to a few samples to damage spread over the whole signal: declip, declick, decrackle, dehum, denoise, dereverb. Why that order is not negotiable is the concept page Repair and Input Controls; the stage table, the realtime inserts and the detectors are on Audio Repair.
The loudness stage and the limiter
The loudness stage ends the chain. It does not trim the gain and then hand over to a separate limiter: it applies one static gain, then drives its own post-gain true-peak limiter to take back whatever that gain pushed over the ceiling.
How the target is reached
The gain is found by re-measuring the gated loudness at a candidate gain, because gain moves blocks across the −70 LUFS absolute gate; it equals target - current only when no block crosses it. The limiter's own reduction is not fed back into that solve. The same solve backs A/B loudness match, reference matching, LUFS normalize, and maximizer.loudnessOptimize, and every one of those paths shares the default below, so the chain, the standalone helper and the named processor normalize alike.
Bounding the limiter
loudness.maxLimiterGainReductionDb (maximizer.loudnessOptimize reads the same key as maxLimiterGainReductionDb; finite and at least 0) bounds how far the stage drives that limiter: the static gain may exceed the peak headroom toward the ceiling by at most this much. It decides how peaky an input the stage will still try to normalize, not how loud a master can get, because the allowance never permits more gain than the solved target gain asks for and the ceiling is never exceeded.
| Value | Behavior |
|---|---|
12 (default) | The limiter may take back up to 12 dB of the gain that exceeds the peak headroom |
0 | A strict headroom clamp; on peaky material the loudest targets fall short |
Peak headroom here is the distance from the input's true peak up to the ceiling (Clipping and Headroom). Take a mix at −18 LUFS whose true peak already sits at −1 dBTP, normalized toward −14 LUFS under a −1 dBTP ceiling: the target asks for +4 dB, the headroom is 0 dB, so all 4 dB of that gain lands above the ceiling and the limiter has to take it back. That is within the default 12 dB allowance; with 0 the gain stops at 0 dB and the mix stays at −18 LUFS.
A 6 s kick loop at -16.78 LUFS with a -14 LUFS target and -1 dBTP ceiling lands at -17.32 LUFS with 0 against -16.14 LUFS at the default. With 0 it ends up quieter than the input because the loop's true peak already sat above -1 dBTP, so the strict clamp applied a negative gain. Whatever shortfall remains is the limiter's own gain reduction, which the single solve does not re-measure, and is reported through loudnessTargetLimited.
The true-peak limiter
maximizer.truePeakLimiter enforces its ceiling sample by sample, never as a whole-block rescale, and every stage inside it carries its state across calls. Its output guard rechecks every earlier position a correction can raise, so a short burst cannot overshoot the true-peak ceiling, and lowering the ceiling live re-evaluates output already queued. maximizer.truePeakLimiter and maximizer.adaptiveRelease each report 129 samples of latency at their defaults.
The limiter's output does not depend on how the caller chunks the stream: the same material rendered in one block, in uniform blocks from 256 to 16384 samples, or in a ragged split that lands mid-transient comes out identical, so a streaming render and an offline render agree. What is left is a small inter-sample residue that is a property of measuring finer than the limiter runs, not of the block size: a meter at 8x or 16x oversampling reads the output of the default 4x limiter slightly above its ceiling. With a −1 dBTP ceiling at 48 kHz, a sine near fs/4 (12 kHz at 48 kHz) read −0.95 dBTP at 16x and broadband noise driven 24 dB into the limiter read −0.92 dBTP, so leave about 0.1 dB of margin when a finer meter checks the delivery. Meter at the limiter's own oversampling to see the ceiling held exactly, or raise its oversampleFactor to 8, which brought the same material to within 0.01 dB of the ceiling. A limiter at 8x or 16x also keeps a 4x reading under the ceiling.
Oversampling and surround weights
The internal oversampler and true-peak stages accept power-of-two oversampling factors from 1 to 16 (1, 2, 4, 8, 16), trading CPU for inter-sample-peak accuracy. The live mixer meter runs 4x or 8x.
Integrated LUFS measurement supports surround layouts up to 8 channels, applying the BS.1770 channel weights by loudspeaker position: +1.5 dB (a power weight of 1.41) for a channel between 60° and 120° azimuth at ear level, unity elsewhere, and the LFE channel left out. The 5.1 surrounds at ±110° take +1.5 dB; in 7.1 the side pair (Lss/Rss, ±90°) takes +1.5 dB and the back pair (Ls/Rs, ±135°) takes unity. The quad surrounds at ±135° are unity as well. The same weights apply to the live mixer meter, the playback loudness meter and night-mode dynamic range control.
Metering for a UI
Pass maxPoints to meteringVectorscope(...) and meteringPhaseScope(...): they thin the point series down to at most maxPoints points, so a busy scope stays cheap to draw. (Without maxPoints they emit one point per input sample.) meteringSpectrumFrame(...) reads a single, non-time-averaged spectrum frame for spectrum-analyzer snapshots.
Config style differs between entry points
The registry of processors is string-based so C, Python, Node, WASM, and CLI callers share identifiers. When you assemble a chain rather than a single processor, the config style depends on the entry point:
| Entry point | Config style |
|---|---|
masterAudio(...) on Node and WASM, and StreamingMasteringChain | Nested MasteringChainConfig objects (overrides); dot-notation leaf keys such as 'loudness.targetLufs' are also accepted in the same object |
Python master_audio(...) | A dict overrides with the same nested or dot-notation keys |
Mastering Assistant chainConfig | The nested config, ready as masterAudio's overrides; its multiband stage can carry the arbitrary-band object, see The chain-config JSON schema |
MasteringChainConfig accepts both spellings. A dot-notation leaf such as 'loudness.targetLufs': -20 can sit beside, or replace, the nested loudness: { targetLufs: -20 }, and the core validates the key and rejects an unknown one. Dot notation is the form the C ABI carries parameters in, which is what makes it the convenient shape when you are assembling overrides dynamically rather than writing them out.
The nested spelling is the canonical one, so prefer it in hand-written code: TypeScript checks a nested config field by field, while a dotted key is only checked at run time.
Repair chain keys follow the chain slots, not the one-shot registry names: use repair.denoise.* / repair.dereverb.* in flat overrides or the nested repair: { denoise: ..., dereverb: ... } shape in masterAudio(...).
An enum-valued chain key takes its choices name beside the number: repair.denoise.mode, repair.denoise.noiseEstimator, repair.decrackle.mode, repair.dehum.mode, dynamics.compressor.detector, and the multiband slope, mode and per-band detector keys. The same holds for the params of masteringApplyProcessor, masteringApplyProcessorStereo and masteringInsertTiming, and for --params and --chain-config on both CLIs. An unknown name is refused with the key and the valid names, and repair.decrackle.mode accepts only median (0) or waveletShrinkage (1). Mixer scene params take the choice's number (choices[].value), not its name.
The chain-config JSON schema
The nested MasteringChainConfig (the shape masterAudio takes as overrides, and the shape the assistant returns as chainConfig) has a JSON-document serialization used by the CLI and the Mastering Assistant: sonare mastering --chain-config <file> reads it. The document is { "version": 2, "params": { ... } }; version may be left out, and a version 1 document is refused as InvalidFormat. In a document the multiband compressor is always the structured form, so there is no fixed 3-band shape and no low/mid/high shorthand:
crossover.cutoffsHz[],crossover.slope,crossover.mode,crossover.firKernelSizebands[]: up to 64 bands, each withthresholdDb,ratio,attackMs,releaseMs,kneeDb,makeupGainDb,autoMakeup,detector,sidechainHighPassHz,pdrTimeMs,pdrReleaseScale
Field validation is strict: unknown keys anywhere in the dynamics.multibandComp object are rejected, and the band count must equal the cutoff count plus one. sidechainHighPassHz is the one sidechain high-pass control, in Hz, replacing the separate enable flag and frequency; leave it out for no high-pass.
On the Node and WASM MasteringChainConfig and in Python config dicts, dynamics.multibandComp accepts crossover (cutoffsHz, slope, mode, firKernelSize) and bands (MultibandCompressorBand), and flat keys dynamics.multibandComp.crossover.cutoffsHz.<i> and dynamics.multibandComp.bands.<i>.<field>. cutoffsHz replaces the cutoff list and sets the band count to its length plus one, and key order does not matter. The low/mid/high shorthand (lowCutoffHz, highCutoffHz, lowThresholdDb and the like) is refused: set crossover.cutoffsHz[0] and crossover.cutoffsHz[1] and bands[0..2].thresholdDb instead.
masterAudio({
samples,
sampleRate,
overrides: {
dynamics: {
multibandComp: {
crossover: { cutoffsHz: [200, 2000, 8000], slope: 'lr4', mode: 'linkwitzRiley' },
bands: [{ thresholdDb: -24 }, { ratio: 3 }, {}, { detector: 'peak' }],
},
},
},
})The band count is checked as 2 to 64 on every surface and both CLIs: a stage with one band is refused (multiband stage needs at least two bands; one band is the compressor stage), and a structurally invalid multiband stage is refused even when the stage is disabled. Preset and assistant chain params return a version 2 multiband stage as flat keys. The solo and insert entry points expose up to 8 cutoffNHz slots, so a single multiband.* call addresses up to 9 bands; the chain goes further, to 63 cutoffs and 64 bands.
The flat chain keys themselves, with their bounds and the lists above, are described by capabilityCatalog().chain; see Chain and preset sections.
Streaming chain config
StreamingMasteringChain renders block by block, so its constructor takes a StreamingMasteringChainConfig instead of preset and overrides. The stage objects sit at the top level beside the stream layout, and sampleRate and numChannels (1 or 2) are required:
const chain = new StreamingMasteringChain({
sampleRate: 48000,
numChannels: 2,
eq: { tilt: { tiltDb: 0.5 } },
loudness: { enabled: true, targetLufs: -14 },
loudnessStaticGainDb: -3.2, // measured offline with streamingLoudnessGain(...)
});The streaming chain cannot measure whole-signal loudness. The enabled loudness stage applies unity gain when loudnessStaticGainDb is omitted. Compute the gain with streamingLoudnessGain() from the same config. Flush with flushMono() or flushStereo() until it returns an empty buffer after the last input block, otherwise the chain's delayed samples and finite processor tails are dropped. The class and its methods are on Streaming and Realtime API.
Related
- Mastering Assistant — profile, suggest and preview, and the suggestion-to-render path
- Mastering Processors — the named solo, pair and stereo processors
- Audio Repair — detectors, the repair stage order and the restoration presets
- Mastering Demo Implementation — the chain that renders in the browser demo
- Capability Catalog — read the chain keys and parameter bounds from the build