Skip to content

Getting Started

Installation

Terminal window
npm install waa-play

Quick Start: Class API (WaaPlayer)

WaaPlayer wraps an AudioContext and exposes every module as a method. This is the easiest way to get started.

import { WaaPlayer } from "waa-play";
const player = new WaaPlayer();
// Generate a 440 Hz sine tone, 2 seconds long
const buffer = player.createSineBuffer(440, 2);
// Start playback — returns a Playback handle
const playback = player.play(buffer);
// Listen to position updates
playback.on("timeupdate", ({ position }) => console.log(position));
// Clean up when done
player.dispose();

Quick Start: Function API (BYO AudioContext)

If you prefer full control, import individual functions and bring your own AudioContext. This approach is fully tree-shakeable.

import { createContext, ensureRunning, play } from "waa-play";
import { createSineBuffer } from "waa-play/synth";
const ctx = createContext();
await ensureRunning(ctx);
const buffer = createSineBuffer(ctx, 440, 2);
const pb = play(ctx, buffer);

Every function takes an AudioContext as its first argument, so there is never any hidden global state.

Modules

waa-play is organized into 12 independent modules. Each module is a separate entry point, so bundlers can tree-shake unused code.

ModuleImportPurpose
playerwaa-playWaaPlayer class — convenience wrapper around all modules
contextwaa-play/contextAudioContext lifecycle (createContext, ensureRunning, now)
bufferwaa-play/bufferAudio file loading (loadBuffer, loadBufferFromBlob)
playwaa-play/playCore playback engine — returns a Playback handle
emitterwaa-play/emitterType-safe event emitter (createEmitter<Events>())
nodeswaa-play/nodesAudio node factories, chain() / disconnectChain()
waveformwaa-play/waveformPeak / RMS extraction from AudioBuffer
fadewaa-play/fadeFade in, fade out, crossfade utilities
schedulerwaa-play/schedulerLookahead scheduler and clock
synthwaa-play/synthBuffer synthesis (sine, noise, click)
adapterswaa-play/adaptersFramework integration (getSnapshot, subscribeSnapshot, onFrame)
stretcherwaa-play/stretcherWSOLA-based pitch-preserving time-stretch