Skip to main content

getMasterInput

Added in 5.8.0

getMasterInput(): AudioNode;

Returns the entry point of the master chain. Connect audio you generate yourself to this node instead of context.destination, and it is routed through master volume, mute, panning and the master limiter exactly like a loaded sound.

Return TypeDescription
AudioNodeThe first node of the master chain

getMasterInput or getMasterOutput?

They sit at opposite ends of the same chain:

your source → [getMasterInput] → volume → pan → limiter → [getMasterOutput] → speakers
MethodUse it toDirection
getMasterInput()Feed your own audio into the mixWrite
getMasterOutput()Observe the finished mix, e.g. with an AnalyserNodeRead

Because getMasterOutput() sits at the end, it already includes anything you connected to the input. You do not need to tap your own source separately, and doing so would count it twice in a visualisation.


Example: an oscillator that follows the master controls

const context = soundHub.getContext();

const osc = context.createOscillator();
const gain = context.createGain();

osc.type = 'sawtooth';
osc.frequency.value = 440;
gain.gain.value = 0.1;

osc.connect(gain);
gain.connect(soundHub.getMasterInput()); // not context.destination

osc.start();

// The oscillator now responds to the master controls, just like a loaded sound
soundHub.setGlobalVolume(0.5);
soundHub.muteAllSounds();

Example: an HTML audio element

const context = soundHub.getContext();
const element = document.querySelector('audio')!;

const source = context.createMediaElementSource(element);
source.connect(soundHub.getMasterInput());

element.play();
Watch your levels

Synthesized sources are often far hotter than recorded samples. A sawtooth at full amplitude peaks at 0 dBFS, while a typical sample peaks around -20 dBFS, so it can be ten times louder before you notice. Put a gain node in front to trim it to a matching level and let the limiter be a safety net rather than a constant clamp.

caution

Do not connect the returned node onward yourself. The sound manager owns the rest of the chain and rewires it when you toggle the limiter or change master spatial audio.