Skip to main content

setMasterLimiter

Added in 5.8.0

Turn the master limiter on or off while the hub is running. Only the output chain is rewired, so sounds that are playing carry on.

setMasterLimiter(enabled: boolean): void;

Parameters​

ParameterTypeDefaultDescription
enabledbooleanrequiredtrue puts the limiter last in the master chain, false takes it out.

Returns​

Nothing.

Example​

import { SoundHub } from 'soundhub';

const soundHub = new SoundHub();

// Let the user decide, for example with a checkbox
checkbox.addEventListener('change', (e) => {
soundHub.setMasterLimiter((e.target as HTMLInputElement).checked);
});

// Or only while a busy scene is on
function startBossFight() {
soundHub.setMasterLimiter(true);
}

function endBossFight() {
soundHub.setMasterLimiter(false);
}

To have it on from the start, use the config instead:

const soundHub = new SoundHub({ masterLimiter: true });

Good to know​

  • Calling it with the state it already has does nothing, so it is safe to call repeatedly.
  • Turning it off throws the limiter node away, and turning it on again builds a new one with the default settings. Tweaks made through getMasterLimiterNode do not survive a toggle.
  • It updates masterLimiter in the config, so getConfig reports the current state.
  • Since 6.3.2 the rewiring no longer disconnects nodes you connected to getMasterOutput, such as an analyser.
  • No event is dispatched.

See also​