Reference
API
Generated by TypeDoc on every build from src/index.ts.
The narrative concept pages are still the best way to learn — this index is for "I know the name, link me to it."
Class
- AggregateDecodeErrorThrown when every URL in a fallback list fails to load. Subclass of DecodeError so existing
- BusA Bus is a named mix bucket with its own gain stage, optional FX inserts, a voice-concurrency limit, and an optional sidechain key. Voices are connected to bus.input. The master receives bus.output. level/mute use 10ms ramps to avoid clicks; raw gain.value writes would pop audibly on browsers that don't smooth the parameter. Public time arguments (fadeTo) are seconds.
- BusGroupA logical handle that addresses several buses at once. Doesn't change the audio graph — applies operations (level, fade, mute, solo) to every member in parallel. Useful when several buses form a sub-mix that should always be controlled together: combat = weapons + enemies + environment; voice = dialogue + effort sounds; etc. Construct via
- BusNotFoundError
- CompressorDynamics compressor as a bus FX insert. Wraps DynamicsCompressorNode and a make-up gain node, and exposes
- DecodeError
- DuckerSidechain ducker. Inserts on the *target* bus (e.g. music) and listens to the level of a source bus (e.g. voice). When the source is loud, the target's gain drops; when quiet, it returns. Implementation: an envelope follower running on the source bus's RMS, driving an additional gain node spliced into the target's FX chain. The envelope follower runs on the main thread at ~60 Hz — fine for a speech ducker, not for sample-accurate audio-rate sidechaining. For that, use a custom AudioWorklet (planned).
- EngineClosedError
- FilterBiquad filter as a bus FX insert. Bypass is a graph swap, not a parameter trick — when bypassed, input is connected directly to output, leaving the biquad fully detached so its delay-line state can't bleed into the dry signal.
- MasterThe Master stage. Headroom-aware gain into an optional soft limiter, then to destination. Buses connect their output to master.input. Headroom is a static gain offset; the limiter is a fast-attack DynamicsCompressorNode that catches most peaks the headroom can't tame when heavy FX stack on top of busy mixes. Note it is best-effort, not a true brick-wall limiter — with a finite attack and no lookahead, transient peaks above the threshold can still pass, so it does not guarantee a hard ceiling.
- MusicStinger → loop → outro music asset. The pattern every casino slot, action game, and rhythm game uses for combat/win/menu music: an intro that plays once, a body that loops cleanly until you ask it to stop, and an outro tail that plays once at the natural loop boundary so the music ends musically instead of cutting off mid-bar. Construct via
- MusicVoiceOne live playback instance of a
- ParameterA named float you can drive at runtime. Set it from anywhere; subscribers (bus levels, FX wet, voice gain) update immediately. Bind a target to a parameter with
- PreloadErrorThrown by
- ReverbConvolution reverb. Mixes a dry signal with a wet path that runs through a ConvolverNode. If no impulse response is provided, a synthetic noise decay is generated — quick and free, but not as nice as a real IR.
- SendOne configured send from a source bus to a target bus. Returned by
- SnapshotA captured mix-state preset. Capture it once with the engine in a known good state ("menu mood"), then
- SoundA loaded sample — owns one decoded AudioBuffer, spawns Voices on play(). Sound is created via engine.loadSound() / bank load; constructor is package-private.
- SoundNotFoundError
- SpatializerPannerNode + occlusion biquad wrapper. Inserted between a Voice and its Bus when a play call passes a
- SpriteOne buffer, many named regions, one fetch. Use for cascades, UI variants, low-latency one-shots — anything where the cost of N separate decodes outweighs the cost of N region offsets into a single buffer. Built on top of an underlying Sound (the buffer); regions are cooperative — overlapping regions just produce overlapping voices.
- StreamSoundStream a long media file through HTMLAudioElement → MediaElementAudioSource. Use for music tracks > 30s where decoding the whole file into RAM (the loadSound path) would waste memory and stall on iOS. The element handles progressive download and seek; we just route its output into the engine's bus graph so it picks up the same FX/sidechain as buffer-based voices. Created lazily — the underlying MediaElementAudioSource is only built on first play(), since it can't be reattached to a different bus once created.
- StretchProcessorPitch-preserving time-stretch via overlap-add granular synthesis with cross-correlation alignment (a SOLA-style approximation). Used to render an offline stretched copy of an AudioBuffer at load time — not realtime. For realtime tempo control, see the (planned) AudioWorklet implementation. stretchFactor > 1 = play faster (shorter buffer). stretchFactor < 1 = not currently supported (use rate via PlaybackRate).
- VariantsA bundle of N alternate sounds that play one at a time. The classic casino-slot pattern: every coin / win / reel-stop trigger plays a randomised variant so stacked SFX don't sound robotic. Construct via
- VoiceOne playback instance, returned from sound.play(). Owns its source node and gain stage; disposes itself on natural end, signal abort, or stop(). Voice constructor is package-private — callers obtain instances via Sound.play().
- ZvukError
Function
Interface
- ApplyOptions
- AudioLevelLive amplitude readout, returned by
- BusConfig
- CompressorConfig
- ConcurrencyConfig
- CrossfadeOptions
- DecodeAttempt
- DuckerConfig
- EngineThe audio engine. Generic in
- EngineConfig
- FadeOptions
- FilterConfig
- FxInsertCommon FX insert contract. Every FX exposes a single input + a single output node so the bus can splice it into the (fxInput → output) hop.
- LoadSoundOptions
- LoudnessOptionsRMS-based loudness normalization on a decoded AudioBuffer.
- MasterConfig
- MasterLimiterConfig
- MusicLoadOptions
- MusicPartsA three-part music asset: optional intro stinger, mandatory loop body, optional outro tail. Modelled on the Wwise / FMOD pattern every casino slot, action game, and rhythm game uses for combat/win/menu music. Each part accepts a single URL or a codec ladder — the same shape as
- MusicPlayOptions
- PlayOptions
- PreloadFailure
- PreloadItemOne entry in a
- PreloadOptions
- PreloadProgressEvent
- ResolveAssetContext
- ReverbConfig
- SendOptions
- SidechainConfig
- SkipToOutroOptions
- SnapshotState
- SpatialOptions
- SpriteMap
- SpriteRegion
- StopOptions
- StretchWorkletNode
- StretchWorkletOptions
- TickSourceExternal ticker for driving the scheduler's task dispatch — typically a host's existing render loop (Pixi
- VariantsOptions
- VoiceDefaults
- VoiceJitter
TypeAlias
- AssetResolverHook for adopting buffers from an external asset system (Pixi assetpack, IndexedDB cache, custom manifest) instead of (or in addition to) zvuk's URL fetcher. Returning
- AudioMimeTypeCodec capability + asset-source picking. Recommended encoding pipeline: - Primary: WebM/Opus — smallest, best quality/byte, supported in Chrome, Firefox, Edge, and Safari 14.1+ on macOS / iOS 17+. - Fallback: AAC in M4A — required for older iOS Safari (≤16) and older macOS Safari without Opus support. Ship both; pickSource() returns the first URL the browser can decode. canPlay() uses HTMLAudioElement.canPlayType — it gives a sound (no pun intended) prediction without actually fetching anything. The Web Audio decoder will accept anything HTMLAudioElement says it can play, plus a few extras (uncompressed WAV always works), so canPlay is conservative.
- DistanceModelDistance-attenuation curve. Mirrors
- EngineState
- FadeCurve
- FilterKind
- MusicState
- NormalizeFlag
- ParameterCurve
- ResolvedAssetAnything an
- SpriteRegionPlayOptions
- VariantStrategyStrategy for picking which variant fires on each