Buses and routing
Route voices through named buses with independent gain and mute.
AudioBits API · 0.2.0 · Available on npm.
Buses form a single-parent tree rooted at master. Create them after startup. Gain and mute have separate stages.
Install confirmation from the source registry
under src/sounds/recipes/, then use this host code in src/:
import { createAudio } from "audiobits";
import { confirmation } from "./sounds/recipes/confirmation/recipe";
const audio = createAudio();
const sound = audio.sound(confirmation);
export async function playFromGesture() {
await audio.start();
const effects = audio.bus("effects");
effects.setGainDb(-6, 0.1);
sound.play({ bus: effects, seed: 42 });
}
export function stop() {
audio.stopAll({ tails: "cut" });
}
export async function dispose() {
await audio.dispose();
}audio.bus(name, parent = audio.master) reuses a live named bus. Use
setParent() to move it; another lookup does not reparent an existing bus.
Names contain 1–64 characters and cannot be blank. Cycles and foreign/disposed
buses are rejected before changing a route; setting the same parent adds no
connection. Playback defaults to master and rejects foreign/disposed buses
before allocation or stealing.
setGainDb() accepts -60–0 dB and ramps of 0–10 seconds (default 5 ms).
setMuted() ramps independently over 5 ms, preserving gain automation.
audio.setMuted() controls master mute, including a setting made before startup.
Master defaults to -12 dB.
Ownership
Non-master bus disposal recursively finalizes routed voices and descendants. Disposal is idempotent; a later lookup of the name creates a fresh bus. Dispose master through the engine. Native nodes and routing stay outside recipe JSON. The catalog's mixer is separate from copied sound examples.
Buses provide gain, mute, and routing. Shared effects are deferred until multiple real sound requirements justify an API.