getMasterOutput
Get the node where the finished mix leaves the master chain. Connect an AnalyserNode to it to draw a meter or a spectrum of everything the hub plays.
getMasterOutput(): AudioNode;
Parameters
This method takes no parameters.
Returns
AudioNode: the master stereo panner. Master volume, mute and master panning have been applied by this point.
Example
import { SoundHub } from 'soundhub';
const soundHub = new SoundHub();
await soundHub.loadSound('music', '/audio/theme.mp3');
const analyser = soundHub.getContext().createAnalyser();
analyser.fftSize = 256;
// Only tap the mix. The hub already sends it to the speakers.
soundHub.getMasterOutput().connect(analyser);
soundHub.play('music');
const data = new Uint8Array(analyser.frequencyBinCount);
function draw() {
analyser.getByteFrequencyData(data);
// ...draw the bars from data
requestAnimationFrame(draw);
}
draw();
Good to know
- The node sits before the master limiter. An analyser here sees the mix before limiting, so peaks can read higher than what reaches the speakers.
- The hub already connects this node to the speakers (through the limiter when it is on). Connecting your analyser onward to
context.destinationas well would play the mix a second time, and that copy would skip the limiter. - Since 6.3.2, rebuilding the master chain no longer disconnects nodes you connected here.
setMasterLimiter,setMasterSpatialPositionandcleanupGlobalPanonly undo the links the hub made itself, so your analyser keeps working. - Audio you connect to
getMasterInputis already part of this output.
See also
getMasterInput: feed your own audio into the mix.getContext: the context to create the analyser in.getMasterLimiterNode: read how much the limiter holds back.