Skip to content

Modular Bun Audio Library Outline

Cameron Brooks edited this page May 30, 2025 · 1 revision

This document expands on the technical approach for building a Bun‑native audio library inspired by AudioNodes. The goal is to keep the codebase lightweight while still allowing dynamic routing and real‑time control of short loops.

Library Core

  • TypeScript Classes wrap Web Audio nodes. Examples include:
    • SamplerNode for buffered playback and seamless looping.
    • GainNodeWrapper for volume automation.
    • FilterNodeWrapper for tone shaping.
  • Each wrapper exposes a .connect() method so instances can be chained just like the native AudioNode graph.
  • The code lives in frontend/audio/modularNodes.ts and is compiled with Bun for the browser bundle.

Looping Utility

  • The detectLoop function performs a simple cross‑correlation on an AudioBuffer to find a smooth end point.
  • applyCrossfade fades the start and end of a clip so loops are gapless.
  • These utilities work hand‑in‑hand with the existing librosa_encoder.py script, which trims and normalizes incoming audio files on the server.

Real‑Time Control Hooks

  • bindControl() lets DOM elements modify any AudioParam. For example, moving the mouse over a slider can change filter cutoff or sampler playback rate.
  • This keeps the API flexible without requiring a heavy UI framework.

Next Ideas

  1. Store each user's node graph as JSON for easy reloading and sharing.
  2. Add wrappers for additional effects (compressor, panner) as needed.
  3. Explore compiling DSP‑heavy functions to WebAssembly for extra speed.

By combining Bun's fast TypeScript tooling with small Web Audio wrappers, we can deliver a responsive, modular interface that echoes AudioNodes' workflow without the overhead.

Clone this wiki locally