Skip to main content

getMasterInput

Added in 5.8.0

Get the first node of the master chain. Connect audio you generate yourself to it instead of context.destination, and it goes through master volume, mute, panning and the master limiter exactly like a loaded sound.

getMasterInput(): AudioNode;

Parameters​

This method takes no parameters.

Returns​

AudioNode: the master gain node, the node every sound's gain node connects to.

Example​

import { SoundHub } from 'soundhub';

const soundHub = new SoundHub();
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 follows the master controls, like a loaded sound
soundHub.setGlobalVolume(0.5);
soundHub.muteAllSounds();

An HTML audio element works the same way:

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

source.connect(soundHub.getMasterInput());
element.play();

Good to know​

  • The master chain runs like this. The spatial panner is only there while a master spatial position is set, and the limiter only while it is on:

    your source → [getMasterInput] master gain → master spatial panner → master stereo panner [getMasterOutput] → limiter → speakers
  • Input or output? Use getMasterInput() to feed audio into the mix. Use getMasterOutput() to observe the mix, for example with an AnalyserNode. The output already includes whatever you connected here, so tapping your own source separately would count it twice in a visualisation.

  • Do not connect the returned node onward yourself. The hub owns the rest of the chain and rewires it when you toggle the limiter or change master spatial audio. Your connections into this node are left alone.

  • 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. Put a gain node in front, as in the example, and let the limiter be a safety net rather than a constant clamp.

See also​