Skip to content

EZ Web Audio / setMasterDestination

Function: setMasterDestination()

setMasterDestination(node): void

Defined in: packages/core/src/index.ts:231

Route all subsequently-created audio through a master destination node.

By default every sound, oscillator, sampler, beat track, layered sound, grain player, poly synth, font, and sprite connects its final output to the hardware output (audioContext.destination). Call setMasterDestination with an AudioNode to insert a shared master stage in front of the hardware — a limiter, a peak meter, a master gain, or an offline-render target — so a whole mix routes through one place.

Rules:

  • The node MUST belong to the shared library context (getAudioContext). Web Audio nodes cannot connect across AudioContexts.
  • Only instances created AFTER this call pick up the destination. Move an existing instance with instance.setDestination(node).
  • Pass null to restore direct-to-hardware routing for future instances.

Parameters

node

The master destination node, or null to clear it

AudioNode | null

Returns

void

Example

typescript
import { getAudioContext, setMasterDestination, createSound } from 'ez-web-audio'

const ctx = await getAudioContext()
const limiter = ctx.createDynamicsCompressor()
limiter.connect(ctx.destination)
setMasterDestination(limiter)      // everything created next runs through the limiter

const sound = await createSound('hit.mp3')
sound.play()                       // sound → ... → limiter → hardware

setMasterDestination(null)         // later instances go straight to hardware again