getMasterLimiterNode
Added in 5.8.0
Get the live limiter node, so you can fine-tune it or read how much gain reduction it applies. Returns null while the master limiter is off.
getMasterLimiterNode(): DynamicsCompressorNode | null;
Parameters
This method takes no parameters.
Returns
DynamicsCompressorNode | null: the limiter node, or null when the limiter is off.
Example
Adjust the limiter to taste:
import { SoundHub } from 'soundhub';
const soundHub = new SoundHub({ masterLimiter: true });
const limiter = soundHub.getMasterLimiterNode();
if (limiter) {
limiter.threshold.value = -6; // start limiting earlier
limiter.ratio.value = 12; // a little softer than the default brick wall
limiter.release.value = 0.4; // recover more slowly
}
Show a gain reduction meter:
function drawMeter() {
const limiter = soundHub.getMasterLimiterNode();
// `reduction` is 0 when nothing is held back, and negative dB when it is
const amount = limiter ? Math.abs(limiter.reduction) : 0;
meterBar.style.width = `${Math.min(100, (amount / 20) * 100)}%`;
requestAnimationFrame(drawMeter);
}
drawMeter();
Good to know
- Do not connect or disconnect this node yourself. The hub owns its place in the graph and rewires it when you toggle the limiter or change master spatial audio. Reading and writing its
AudioParamvalues is fine. - The defaults are
threshold-3,knee0,ratio20,attack0.003andrelease0.25. setMasterLimiter(false)throws this node away. Turning the limiter back on creates a new node with the defaults, so ask for the node again and reapply your settings. The meter example asks every frame for that reason.
See also
masterLimiter: what the limiter does and when to use it.setMasterLimiter: turn it on or off.isMasterLimiterEnabled: check whether it is on.