DOM ENGINEV0.10.0FIZLET

SOUND V0.10.0

fizlet/sound

The sound adapter. After each frame it reads the engine's event ring and plays the mapped cues, so collisions and game events make sound without knowing about audio. The default voice is a tiny synth (oscillators, no assets); pass play to use your own sounds. Silent until the first trusted gesture, while paused, and when switched off.

fizlet/sound · GZIP1,000 B1.0 KB of a 1.5 KB budget

Measured on this build: minified and gzipped with everything it imports, the way npm run size checks the budget in CI.

LIVE · LOADINGEvery built-in cue. No audio files: a tiny oscillator synth, silent until your first press.
MODULES · hosted on this site
import { sound } from "https://coded-dot-design.github.io/fizlet/dist/sound.js";
NPM · COMING SOON
npm install fizlet   # not published yet
import { sound } from "fizlet/sound";
IN SHORT
const sfx = sound(e, { cues: { boom: "boom" } });
e.events.emit("boom"); // in a step; plays after render
sfx.on = false;        // mute

API

Every export, with its doc comment, read from the published type declarations of v0.10.0.

Cue type

export type Cue = "fire" | "hit" | "boom" | "hurt" | "power" | "ready" | "win" | "end" | "click";

SoundOptions interface

export interface SoundOptions {
    /** event type → cue, e.g. { shot: "fire", wreck: "boom" }. */
    cues: Record<string, Cue>;
    /** Start switched on (default true). */
    on?: boolean;
    /** Master volume 0..1 (default 0.12). */
    volume?: number;
    /** Your own player instead of the synth. */
    play?: (cue: Cue, intensity: number) => void;
}

sound function

export declare function sound(e: Engine, o: SoundOptions): {
    play: (cue: Cue, intensity?: number) => void;
    dispose: () => void;
    on: boolean;
};

Sound type

export type Sound = ReturnType<typeof sound>;