AudioBits

Buses and routing

Route voices through named buses with independent gain and mute.

AudioBits API · 0.1.3 · Available on npm.

Buses form a single-parent tree rooted at master. Create them after startup. Gain and mute have separate stages.

import { createAudio } from "audiobits";
import { confirmation } from "audiobits/recipes";
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. Cycles and foreign/disposed buses are rejected. setGainDb() accepts -60–0 dB and ramps of 0–10 seconds (default 5 ms). setMuted() ramps independently over 5 ms. Master defaults to -12 dB.

Ownership

Non-master bus disposal recursively finalizes routed voices and descendants. Dispose master through the engine. Native nodes and routing stay outside recipe JSON. The gallery'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.

On this page