LabDAW

master-bus

A master output bus on a context: a gain for the volume, then a safety limiter, then the destination. Every source connects to its input, so one control governs the level and a loud mix cannot clip the output.

pnpm dlx shadcn@latest add @audio-ui/master-bus
import { createMasterBus } from "@/lib/master-bus";
Fileslib/master-bus.ts
Depends onNothing
npmNothing
Used byuse-master-bus
ExportKindWhat it is
MasterBusinterfaceA master output bus: the node every source connects to, its volume, and what takes it away.
createMasterBusfunctionA master output bus on ctx: a gain for the volume, then a safety limiter, then the destination.

Usage

Every sound of a screen (synth voices, drum hits, a device's engine) connects to the bus's input instead of ctx.destination. The bus is a gain for the volume, then a safety limiter: below -3 dBFS the sound passes unchanged, above it the peaks stay under full scale instead of clipping. It works the same in any framework.

import { createMasterBus } from "@/lib/master-bus";
import { webAudio } from "@/lib/web-audio";

const ctx = webAudio.getContext();
const bus = createMasterBus(ctx, 0.7);
engine.output.connect(bus.input);

bus.setVolume(0.5); // a short ramp, no click
bus.dispose(); // when the screen goes away

The limiter delays the sound by a few milliseconds. In React, useMasterBus makes one on the page's context and keeps its volume in sync with a value.

Built by Ouest Labs, the source code is available on GitHub.
RSS