@schmooky/zvuk 1.12.0 → 1.14.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -1,17 +1,22 @@
1
1
  declare class ZvukError extends Error {
2
- constructor(message: string);
2
+ constructor(message: string, options?: ErrorOptions);
3
3
  }
4
4
  declare class EngineClosedError extends ZvukError {
5
5
  constructor();
6
6
  }
7
7
  declare class BusNotFoundError extends ZvukError {
8
- constructor(name: string);
8
+ constructor(name: string, hint?: string | null);
9
9
  }
10
10
  declare class SoundNotFoundError extends ZvukError {
11
- constructor(name: string);
11
+ constructor(name: string, hint?: string | null);
12
12
  }
13
+ /**
14
+ * A fetch or decode failure for one URL. The underlying failure is kept on
15
+ * `cause` as well as summarised into the message, so a logger that walks
16
+ * the cause chain gets the original stack.
17
+ */
13
18
  declare class DecodeError extends ZvukError {
14
- constructor(url: string, cause: unknown);
19
+ constructor(url: string, cause: unknown, message?: string);
15
20
  }
16
21
  interface DecodeAttempt {
17
22
  readonly url: string;
@@ -135,7 +140,7 @@ interface SendOptions {
135
140
  amount?: number;
136
141
  /**
137
142
  * Tap the source bus's output (post-fader, post-FX) when `true`,
138
- * or input (pre-fader, pre-FX) when `false`. Default `true` — almost
143
+ * or input (pre-fader, pre-FX) when `false`. Default `true`, which is almost
139
144
  * always what you want. Pre-fader sends are mainly useful for
140
145
  * monitoring buses that should hear the dry signal regardless of how
141
146
  * the user has faded the source bus down.
@@ -145,9 +150,9 @@ interface SendOptions {
145
150
  interface MasterLimiterConfig {
146
151
  /** Threshold in dB. Default -1 (just below 0 dBFS). */
147
152
  threshold?: number;
148
- /** Compression ratio. Default 20 (brick-wall). */
153
+ /** Compression ratio. Default 20, high enough to be limiter-like without being a brick wall. */
149
154
  ratio?: number;
150
- /** Attack in seconds. Default 0.001 (fast — catches the transient). */
155
+ /** Attack in seconds. Default 0.001, fast enough to catch the transient. */
151
156
  attack?: number;
152
157
  /** Release in seconds. Default 0.05. */
153
158
  release?: number;
@@ -155,7 +160,7 @@ interface MasterLimiterConfig {
155
160
  interface MasterConfig {
156
161
  /** Headroom in dB applied to the master gain (negative). Default: 0. */
157
162
  headroom?: number;
158
- /** Optional brick-wall limiter on the master output. */
163
+ /** Optional fast-attack soft limiter on the master output (best-effort peak control). */
159
164
  limiter?: MasterLimiterConfig;
160
165
  }
161
166
  /**
@@ -164,7 +169,7 @@ interface MasterConfig {
164
169
  * - `ArrayBuffer` — encoded bytes; zvuk decodes via the engine's AudioContext.
165
170
  * - `string` — a URL; zvuk fetches and decodes via its normal loader (and
166
171
  * the cache).
167
- * - `undefined` / `null` — explicit "I don't have this" — falls through to
172
+ * - `undefined` / `null` — explicit "I don't have this". Falls through to
168
173
  * the URL list passed to `loadSound` (or throws if none was given).
169
174
  */
170
175
  type ResolvedAsset = AudioBuffer | ArrayBuffer | string;
@@ -183,19 +188,19 @@ interface ResolveAssetContext {
183
188
  * so resolvers can mix cached and uncached sounds without branching at the
184
189
  * call site.
185
190
  *
186
- * The resolver runs before any fetch — if it returns a buffer or URL, the
191
+ * The resolver runs before any fetch. If it returns a buffer or URL, the
187
192
  * URL list passed to `loadSound` is only used as the resolution key.
188
193
  */
189
194
  type AssetResolver = (ctx: ResolveAssetContext) => ResolvedAsset | undefined | null | Promise<ResolvedAsset | undefined | null>;
190
195
  /**
191
- * External ticker for driving the scheduler's task dispatch — typically
196
+ * External ticker for driving the scheduler's task dispatch. Typically
192
197
  * a host's existing render loop (Pixi `app.ticker`, GSAP `gsap.ticker`).
193
198
  *
194
199
  * The scheduler subscribes lazily: only while there are pending tasks. When
195
200
  * the queue drains, it unsubscribes so a 60 Hz host loop isn't waking the
196
201
  * scheduler 60 times per second to do nothing.
197
202
  *
198
- * Without a `TickSource`, the scheduler dispatches via `setTimeout` — see
203
+ * Without a `TickSource`, the scheduler dispatches via `setTimeout`. See
199
204
  * the "Runtime timing" guide for trade-offs around browser timer
200
205
  * throttling and tab visibility.
201
206
  *
@@ -228,7 +233,7 @@ interface VoiceDefaults {
228
233
  /**
229
234
  * Default click-free fade-out duration applied by `voice.stop()`, in
230
235
  * seconds. Web Audio cuts source nodes mid-waveform, which produces a
231
- * digital click on non-zero crossings — a tiny linear ramp on the gain
236
+ * digital click on non-zero crossings. A tiny linear ramp on the gain
232
237
  * stage before the source actually stops eliminates that. Default 0.008
233
238
  * (8 ms): inaudible as fade, sufficient as click suppressor.
234
239
  *
@@ -261,7 +266,7 @@ interface EngineConfig<TBusName extends string = string> {
261
266
  latencyHint?: AudioContextLatencyCategory | number;
262
267
  /**
263
268
  * External ticker (e.g. Pixi `app.ticker`, GSAP `gsap.ticker`) that drives
264
- * scheduler dispatch. Without one, the scheduler uses `setTimeout` —
269
+ * scheduler dispatch. Without one, the scheduler uses `setTimeout`,
265
270
  * which browsers throttle to ~1 Hz on hidden tabs. Inject a host ticker
266
271
  * to align dispatch to your render loop and avoid spawning a parallel rAF
267
272
  * loop. See the "Runtime timing" guide for the full trade-off.
@@ -290,12 +295,26 @@ interface EngineConfig<TBusName extends string = string> {
290
295
  * automatically on return. This is also the iOS Safari workaround for
291
296
  * suspension-on-blur.
292
297
  *
293
- * Set to `false` if you want music to keep playing across tab switches —
298
+ * Set to `false` if you want music to keep playing across tab switches:
294
299
  * e.g. background music players where a brief navigation away from the
295
300
  * page shouldn't pause playback. Audio continues running on the Web Audio
296
301
  * thread regardless of tab visibility.
297
302
  */
298
303
  autoPauseOnHidden?: boolean;
304
+ /**
305
+ * Decoded-buffer cache limits. Decoded audio costs 4 bytes per sample per
306
+ * channel, so a few minutes of stereo 48 kHz is tens of megabytes and an
307
+ * entry count says nothing useful about memory.
308
+ *
309
+ * Defaults: 64 MiB, 128 entries. The cache is LRU on both.
310
+ */
311
+ cache?: CacheConfig;
312
+ }
313
+ interface CacheConfig {
314
+ /** Ceiling on decoded bytes held in the cache. Default 64 MiB. */
315
+ maxBytes?: number;
316
+ /** Ceiling on cached entries, applied alongside `maxBytes`. Default 128. */
317
+ maxEntries?: number;
299
318
  }
300
319
  interface FadeOptions {
301
320
  to: number;
@@ -312,6 +331,13 @@ interface StopOptions {
312
331
  fade?: number;
313
332
  }
314
333
  interface VoiceJitter {
334
+ /**
335
+ * Center value the jitter varies around. Defaults to 1 (the neutral
336
+ * volume / playback rate). Set it to combine a base with jitter, e.g.
337
+ * `{ base: 1.5, jitter: 0.1 }` plays at 1.5 ± 0.1 per voice.
338
+ */
339
+ base?: number;
340
+ /** Maximum ± random deviation from `base`, drawn once per voice. */
315
341
  jitter?: number;
316
342
  }
317
343
  /**
@@ -350,7 +376,7 @@ interface SpatialOptions {
350
376
  /**
351
377
  * Occlusion amount (0..1). Drives an internal low-pass filter that
352
378
  * sweeps cutoff from 22050 Hz (transparent) down to ~500 Hz (heavily
353
- * muffled), plus a small gain dip — the standard "behind a wall"
379
+ * muffled), plus a small gain dip. That is the standard "behind a wall"
354
380
  * effect. Independent of distance attenuation; combine via a
355
381
  * `Parameter` if you want one knob to drive both.
356
382
  * 3D only; ignored when `pan` is used.
@@ -362,7 +388,7 @@ interface PlayOptions {
362
388
  volume?: number | VoiceJitter;
363
389
  /**
364
390
  * Fade-in duration (seconds) applied to the voice's gain at start.
365
- * Default 0 (instant). Convenience for "drop in smoothly" — the dual
391
+ * Default 0 (instant). Convenience for "drop in smoothly", the mirror
366
392
  * of the click-free stop fade. Equivalent to playing at `volume: 0`
367
393
  * and immediately calling `voice.fade({ to: volume, duration: fadeIn })`.
368
394
  */
@@ -373,9 +399,9 @@ interface PlayOptions {
373
399
  loop?: boolean;
374
400
  /** Override the default bus for this voice. */
375
401
  bus?: string;
376
- /** Voice priority — higher = more likely to survive stealing. Default 0. */
402
+ /** Voice priority. Higher survives stealing for longer. Default 0. */
377
403
  priority?: number;
378
- /** AbortSignal — voice stops when aborted. */
404
+ /** AbortSignal. The voice stops when it aborts. */
379
405
  signal?: AbortSignal;
380
406
  /** 2D pan or 3D position. Inserts a Spatializer between the voice and its bus. */
381
407
  spatializer?: SpatialOptions;
@@ -390,11 +416,11 @@ interface PlayOptions {
390
416
  /**
391
417
  * Equal-power crossfade duration (seconds) at the loop boundary. When
392
418
  * `loop` is true and this is non-zero, zvuk spawns a parallel buffer
393
- * source at every loop point and ramps between them — masking the click
419
+ * source at every loop point and ramps between them, masking the click
394
420
  * that AudioBufferSourceNode's native loop produces when the region
395
421
  * doesn't end on a zero crossing.
396
422
  *
397
- * Default `0` (off — native hard-cut loop). Cost is one extra
423
+ * Default `0`, meaning off, which leaves the native hard-cut loop. Cost is one extra
398
424
  * AudioBufferSourceNode + GainNode per loop iteration; with default
399
425
  * Web Audio dispatch this is well under 1% CPU per voice.
400
426
  *
@@ -416,8 +442,9 @@ interface LoadSoundOptions {
416
442
  signal?: AbortSignal;
417
443
  /**
418
444
  * Run RMS-based loudness normalization on the decoded buffer so it sits at
419
- * the same perceived loudness as other normalized sounds. Pass `true` for
420
- * defaults or an options object to tune the target.
445
+ * the same RMS level as other normalized sounds. (Full-band RMS, not
446
+ * perceptual/LUFS.) Pass `true` for defaults or an options object to tune
447
+ * the target.
421
448
  */
422
449
  normalize?: boolean | LoudnessOptions$1;
423
450
  }
@@ -426,7 +453,7 @@ interface LoadSoundOptions {
426
453
  * optional outro tail. Modelled on the Wwise / FMOD pattern every casino
427
454
  * slot, action game, and rhythm game uses for combat/win/menu music.
428
455
  *
429
- * Each part accepts a single URL or a codec ladder — the same shape as
456
+ * Each part accepts a single URL or a codec ladder, the same shape as
430
457
  * `engine.loadSound`'s second argument.
431
458
  */
432
459
  interface MusicParts {
@@ -437,7 +464,7 @@ interface MusicParts {
437
464
  interface MusicLoadOptions extends LoadSoundOptions {
438
465
  /**
439
466
  * Equal-power crossfade (seconds) at the loop boundary. Mirrors
440
- * `PlayOptions.loopCrossfade` — masks the click that would otherwise
467
+ * `PlayOptions.loopCrossfade`. Masks the click that would otherwise
441
468
  * fire if the loop region doesn't end on a zero crossing. Default `0`.
442
469
  */
443
470
  loopCrossfade?: number;
@@ -469,7 +496,7 @@ type MusicState = 'intro' | 'loop' | 'outro' | 'ended';
469
496
  interface PreloadItem {
470
497
  /** Sound name, registered on `engine.sound(name)` after preload completes. */
471
498
  name: string;
472
- /** URL or codec ladder — same shape as `engine.loadSound`. */
499
+ /** URL or codec ladder, the same shape as `engine.loadSound`. */
473
500
  url: string | readonly string[];
474
501
  /** Per-item options (bus, normalize, etc.). Forwarded to `loadSound`. */
475
502
  options?: LoadSoundOptions;
@@ -477,7 +504,7 @@ interface PreloadItem {
477
504
  interface PreloadProgressEvent {
478
505
  /** Name of the item that just completed (success or failure). */
479
506
  readonly name: string;
480
- /** Outcome — `'loaded'` on decode success, `'failed'` otherwise. */
507
+ /** Outcome. `'loaded'` on decode success, `'failed'` otherwise. */
481
508
  readonly status: 'loaded' | 'failed';
482
509
  /** Error attached when `status === 'failed'`. */
483
510
  readonly error?: unknown;
@@ -493,7 +520,7 @@ interface PreloadOptions {
493
520
  */
494
521
  signal?: AbortSignal;
495
522
  /**
496
- * Maximum concurrent loads. Default 4 — chosen for balance with browser
523
+ * Maximum concurrent loads. Default 4, which balances against browser
497
524
  * connection limits (typically 6 per host) so the rest of the page's
498
525
  * fetches don't starve. Lower for cheap mobile data plans, higher when
499
526
  * you control the host and want to saturate.
@@ -501,7 +528,7 @@ interface PreloadOptions {
501
528
  concurrency?: number;
502
529
  /**
503
530
  * Fires once per item as it settles. Use this to drive a loading-screen
504
- * progress bar. The event is cumulative — `event.completed / event.total`
531
+ * progress bar. The event is cumulative, so `event.completed / event.total`
505
532
  * is a fraction in [0..1].
506
533
  */
507
534
  onProgress?: (event: PreloadProgressEvent) => void;
@@ -651,6 +678,18 @@ declare class Voice {
651
678
  * finished.
652
679
  */
653
680
  level(): AudioLevel;
681
+ /**
682
+ * Cheap loudness proxy for voice stealing, in [0..1].
683
+ *
684
+ * `level()` allocates an AnalyserNode and keeps it for the voice's
685
+ * lifetime, so using it to rank 64 candidates left 64 permanent analysers
686
+ * on the graph — and a freshly created analyser reads silence anyway,
687
+ * because its buffer hasn't filled yet. Reuse a tap that already exists;
688
+ * otherwise read the voice's own gain, which costs nothing.
689
+ *
690
+ * @internal
691
+ */
692
+ levelHint(): number;
654
693
  /** Async iterator of lifecycle cues — yields started, optional paused, ended. */
655
694
  cues(): AsyncIterableIterator<VoiceCue>;
656
695
  private finish;
@@ -709,13 +748,15 @@ declare class Send {
709
748
  declare class Bus {
710
749
  readonly name: string;
711
750
  readonly input: GainNode;
712
- /** Sub-bus where FX inserts go. Currently == input; reserved for FX chain. */
751
+ /** Sub-bus the FX chain splices into: input → fxInput → (fx…) → output. */
713
752
  readonly fxInput: GainNode;
714
753
  /** Output node — connect to master.input or another bus.input for sends. */
715
754
  readonly output: GainNode;
716
755
  private _level;
717
756
  private _muted;
718
757
  private _soloed;
758
+ /** True while the engine's solo rule is silencing this (non-soloed) bus. */
759
+ private _soloVeiled;
719
760
  private readonly ctx;
720
761
  private _concurrency;
721
762
  private _voices;
@@ -845,6 +886,13 @@ declare class Ducker implements FxInsert {
845
886
  private analyser;
846
887
  private buf;
847
888
  private rafId;
889
+ /** Timestamp of the previous tick (ms), for measuring the real frame delta. */
890
+ private lastTickMs;
891
+ /**
892
+ * Envelope-follower state, 1 = not ducking. It starts at unity: starting
893
+ * at 0 made every freshly-inserted ducker drop its target bus to silence
894
+ * and swell it back over the release time.
895
+ */
848
896
  private envelope;
849
897
  private targetGain;
850
898
  private ctx;
@@ -858,6 +906,17 @@ declare class Ducker implements FxInsert {
858
906
  set bypassed(v: boolean);
859
907
  dispose(): void;
860
908
  private tick;
909
+ /**
910
+ * A hidden tab stops firing rAF, so the envelope freezes wherever it was.
911
+ * Come back to a ducker that was mid-duck and the music stays quiet with
912
+ * nothing driving it back up. Reset to unity on return and let the next
913
+ * few frames re-duck if the source really is still loud.
914
+ */
915
+ private handleVisibility;
916
+ private resetEnvelope;
917
+ private releaseToUnity;
918
+ private startLoop;
919
+ private stopLoop;
861
920
  }
862
921
 
863
922
  type FilterKind = 'lowpass' | 'highpass' | 'bandpass' | 'notch' | 'peaking' | 'allpass';
@@ -886,6 +945,8 @@ declare class Filter implements FxInsert {
886
945
  setFrequency(hz: number): void;
887
946
  setQ(q: number): void;
888
947
  setType(t: FilterKind): void;
948
+ /** Set the filter gain in dB. Only affects `peaking` (the one shelf-like mode exposed). */
949
+ setGain(db: number): void;
889
950
  get bypassed(): boolean;
890
951
  set bypassed(v: boolean);
891
952
  dispose(): void;
@@ -919,6 +980,8 @@ declare class Reverb implements FxInsert {
919
980
  private preDelay;
920
981
  private ctx;
921
982
  private _bypassed;
983
+ /** Active wet mix (0..1), so bypass can restore it instead of guessing. */
984
+ private _wet;
922
985
  constructor(ctx: AudioContext, config?: ReverbConfig);
923
986
  setWet(mix: number): void;
924
987
  setImpulse(buffer: AudioBuffer): void;
@@ -949,21 +1012,25 @@ declare class StretchProcessor {
949
1012
  }
950
1013
 
951
1014
  /**
952
- * Realtime time-stretch via AudioWorklet.
1015
+ * Realtime *varispeed* via AudioWorklet.
953
1016
  *
954
- * The companion to the offline `StretchProcessor`. Loads a worklet processor
955
- * into the AudioContext and exposes a node whose `stretch` AudioParam can be
956
- * automated live — boss intros that bend in real time, slow-mo stings, etc.
1017
+ * The realtime companion to the offline `StretchProcessor`. Loads a worklet
1018
+ * processor into the AudioContext and exposes a node whose `stretch`
1019
+ * AudioParam can be automated live — boss intros that bend in real time,
1020
+ * slow-mo stings, etc.
957
1021
  *
958
- * The worklet uses a phase-vocoder-lite ring buffer + linear-interp resampler
959
- * paired with a small 1024-sample OLA grain to keep transients crisp. It's
960
- * not as good as a dedicated SOLA pass for offline rendering, but it sounds
961
- * fine for live ramps in the 0.5×–2× range.
1022
+ * IMPORTANT: unlike the offline `StretchProcessor`, this node is NOT
1023
+ * pitch-preserving. It resamples a ring buffer at a variable read rate via
1024
+ * linear interpolation, so changing `stretch` shifts pitch *and* tempo
1025
+ * together — classic varispeed / tape-style speed change. It is cheap and
1026
+ * sounds fine for live ramps across the 0.25×–4× range when you don't need
1027
+ * pitch held constant. For pitch-preserving (offline) stretching, use
1028
+ * `StretchProcessor`.
962
1029
  */
963
1030
  interface StretchWorkletOptions {
964
- /** Initial stretch factor. 1 = play at source rate. > 1 = faster. */
1031
+ /** Initial stretch factor. 1 = play at source rate. > 1 = faster (higher pitch). */
965
1032
  stretchFactor?: number;
966
- /** Grain size in samples. Default 1024. Larger = smoother but more latency. */
1033
+ /** Ring-buffer sizing hint in samples (ring = 8×). Default 1024. */
967
1034
  grainSize?: number;
968
1035
  }
969
1036
  interface StretchWorkletNode extends AudioNode {
@@ -1051,7 +1118,19 @@ declare class Parameter {
1051
1118
  }): () => void;
1052
1119
  }
1053
1120
 
1054
- type EngineState = 'cold' | 'unlocking' | 'live' | 'interrupted' | 'closed';
1121
+ /**
1122
+ * Engine lifecycle, mirroring the underlying AudioContext:
1123
+ *
1124
+ * - `cold` — no context yet, or a failed unlock.
1125
+ * - `unlocking` — a resume() is in flight.
1126
+ * - `live` — the context is running.
1127
+ * - `suspended` — the context was paused, normally by `autoPauseOnHidden`
1128
+ * on tab hide. Recoverable with `unlock()`.
1129
+ * - `interrupted` — iOS took the audio session (phone call, Siri).
1130
+ * `resume()` does not recover from this; the OS has to hand it back.
1131
+ * - `closed` — terminal.
1132
+ */
1133
+ type EngineState = 'cold' | 'unlocking' | 'live' | 'suspended' | 'interrupted' | 'closed';
1055
1134
 
1056
1135
  interface MusicBuffers {
1057
1136
  intro?: AudioBuffer;
@@ -1079,11 +1158,20 @@ interface MusicDeps {
1079
1158
  declare class Music {
1080
1159
  readonly name: string;
1081
1160
  private deps;
1161
+ private live;
1082
1162
  constructor(name: string, deps: MusicDeps);
1083
1163
  get loopDuration(): number;
1084
1164
  get hasIntro(): boolean;
1085
1165
  get hasOutro(): boolean;
1086
1166
  play(options?: MusicPlayOptions): MusicVoice;
1167
+ /** Live playback instances spawned from this asset. */
1168
+ voices(): readonly MusicVoice[];
1169
+ /**
1170
+ * Stop every live instance. `engine.close()` uses this — without it a
1171
+ * music voice kept its source nodes running past the engine that owned
1172
+ * them, the way streams used to.
1173
+ */
1174
+ stopAll(opts?: StopOptions): void;
1087
1175
  }
1088
1176
  interface MusicVoiceDeps {
1089
1177
  ctx: AudioContext;
@@ -1173,6 +1261,13 @@ interface SoundDeps {
1173
1261
  applyConcurrency?: (v: Voice, bus: string) => boolean;
1174
1262
  /** Engine-level default click-free fade for voice.stop() (seconds). */
1175
1263
  defaultStopFade?: number;
1264
+ /**
1265
+ * Name reported on spawned voices, when it differs from the registry key.
1266
+ * Sprites and variant bundles register under internal keys; their voices
1267
+ * should still say which public asset they came from so `engine.crossfade`
1268
+ * can find them.
1269
+ */
1270
+ sourceName?: string;
1176
1271
  }
1177
1272
  /**
1178
1273
  * A loaded sample — owns one decoded AudioBuffer, spawns Voices on play().
@@ -1298,6 +1393,13 @@ declare class Variants {
1298
1393
  private lastIndex;
1299
1394
  private bag;
1300
1395
  constructor(name: string, sounds: Sound[], options?: VariantsOptions);
1396
+ /**
1397
+ * Index of the variant the most recent `play()` picked, or `-1` before the
1398
+ * first one. Read it when something outside the mix has to follow the
1399
+ * pick: a subtitle for the line that actually fired, a telemetry event, an
1400
+ * animation keyed to which take you got.
1401
+ */
1402
+ get lastPick(): number;
1301
1403
  /** Spawn a Voice on a randomly-picked variant. */
1302
1404
  play(options?: PlayOptions): Voice;
1303
1405
  /** Force the next pick to use a specific variant index. Useful for tests. */
@@ -1492,8 +1594,10 @@ interface Engine<TBusName extends string = string> {
1492
1594
  * over the same window with `equal-power` curves so the perceived loudness
1493
1595
  * stays flat.
1494
1596
  *
1495
- * Returns the new Voice. If `to` is already playing, its level is faded up
1496
- * from 0 instead of starting fresh.
1597
+ * Returns the new Voice — a fresh voice for `to` is always started at
1598
+ * volume 0 and faded up. Only voices of `from` on the same bus the new
1599
+ * voice plays on are faded out; instances of `from` on other buses are
1600
+ * left untouched.
1497
1601
  */
1498
1602
  crossfade(from: string, to: string, options?: CrossfadeOptions): Voice;
1499
1603
  scheduleAt(audioTime: number, fn: () => void): () => void;
@@ -1545,12 +1649,14 @@ interface CrossfadeOptions {
1545
1649
  declare function createEngine<TBusName extends string = string>(config?: EngineConfig<TBusName>): Engine<TBusName>;
1546
1650
 
1547
1651
  /**
1548
- * The Master stage. Headroom-aware gain into an optional brick-wall limiter,
1549
- * then to destination. Buses connect their output to master.input.
1652
+ * The Master stage. Headroom-aware gain into an optional soft limiter, then to
1653
+ * destination. Buses connect their output to master.input.
1550
1654
  *
1551
1655
  * Headroom is a static gain offset; the limiter is a fast-attack
1552
- * DynamicsCompressorNode that catches peaks the headroom can't tame when
1553
- * heavy FX stack on top of busy mixes.
1656
+ * DynamicsCompressorNode that catches most peaks the headroom can't tame when
1657
+ * heavy FX stack on top of busy mixes. Note it is best-effort, not a true
1658
+ * brick-wall limiter — with a finite attack and no lookahead, transient peaks
1659
+ * above the threshold can still pass, so it does not guarantee a hard ceiling.
1554
1660
  */
1555
1661
  declare class Master {
1556
1662
  readonly input: GainNode;
@@ -1622,10 +1728,14 @@ declare function pickSourceOrder(urls: readonly string[]): readonly string[];
1622
1728
  /**
1623
1729
  * RMS-based loudness normalization on a decoded AudioBuffer.
1624
1730
  *
1625
- * `engine.loadSound(..., { normalize: true })` runs this at decode-time
1626
- * and produces a buffer pre-scaled so all sounds sit at the same perceived
1627
- * loudness — removing a workflow tax that game-audio teams currently pay
1628
- * in their DAW. Pass an object to override the target RMS or peak ceiling.
1731
+ * `engine.loadSound(..., { normalize: true })` runs this at decode-time and
1732
+ * produces a buffer pre-scaled so all sounds sit at the same RMS level —
1733
+ * removing a workflow tax that game-audio teams currently pay in their DAW.
1734
+ * Pass an object to override the target RMS or peak ceiling.
1735
+ *
1736
+ * NOTE: this is full-band RMS, not perceptual (K-weighted / LUFS) loudness —
1737
+ * two spectrally different clips at equal RMS may still differ in perceived
1738
+ * loudness.
1629
1739
  */
1630
1740
  interface LoudnessOptions {
1631
1741
  /** Target RMS (linear, 0..1). Default 0.1 (~ -20 dBFS). */
@@ -1634,7 +1744,7 @@ interface LoudnessOptions {
1634
1744
  peakCeiling?: number;
1635
1745
  }
1636
1746
  type NormalizeFlag = boolean | LoudnessOptions;
1637
- declare function applyLoudnessNormalization(buffer: AudioBuffer, flag: NormalizeFlag): AudioBuffer;
1747
+ declare function applyLoudnessNormalization(buffer: AudioBuffer, flag: NormalizeFlag, ctx?: BaseAudioContext): AudioBuffer;
1638
1748
  declare function computeNormalizationGain(buffer: AudioBuffer, opts: Required<LoudnessOptions>): number;
1639
1749
 
1640
1750
  export { AggregateDecodeError, type ApplyOptions, type AssetResolver, type AudioLevel, type AudioMimeType, Bus, type BusConfig, BusGroup, BusNotFoundError, Compressor, type CompressorConfig, type ConcurrencyConfig, type CrossfadeOptions, type DecodeAttempt, DecodeError, type DistanceModel, Ducker, type DuckerConfig, type Engine, EngineClosedError, type EngineConfig, type EngineState, type FadeCurve, type FadeOptions, Filter, type FilterConfig, type FilterKind, type FxInsert, type LoadSoundOptions, type LoudnessOptions, Master, type MasterConfig, type MasterLimiterConfig, Music, type MusicLoadOptions, type MusicParts, type MusicPlayOptions, type MusicState, MusicVoice, type NormalizeFlag, Parameter, type ParameterCurve, type PlayOptions, PreloadError, type PreloadFailure, type PreloadItem, type PreloadOptions, type PreloadProgressEvent, type ResolveAssetContext, type ResolvedAsset, Reverb, type ReverbConfig, Send, type SendOptions, type SidechainConfig, type SkipToOutroOptions, Snapshot, type SnapshotState, Sound, SoundNotFoundError, type SpatialOptions, Spatializer, Sprite, type SpriteMap, type SpriteRegion, type SpriteRegionPlayOptions, type StopOptions, StreamSound, StretchProcessor, type StretchWorkletNode, type StretchWorkletOptions, type TickSource, type VariantStrategy, Variants, type VariantsOptions, Voice, type VoiceDefaults, type VoiceJitter, ZvukError, applyLoudnessNormalization, canPlay, computeNormalizationGain, createEngine, createStretchWorkletNode, ensureStretchWorklet, mimeForUrl, pickSource, pickSourceOrder };