@schmooky/zvuk 1.11.1 → 1.13.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/README.md CHANGED
@@ -55,9 +55,9 @@ zvuk is the layer above. It gives you the routing primitives a real game audio t
55
55
  | Mixer | FX | Loading | DX |
56
56
  | --- | --- | --- | --- |
57
57
  | Named buses with FX inserts | Compressor (DynamicsCompressor + makeup) | Codec ladder (`['x.webm', 'x.m4a']`) | Lazy AudioContext (no constructor side-effects) |
58
- | Master headroom + brick-wall limiter | Filter (BiquadFilter, all 6 modes) | Audio sprites (one buffer, N regions) | iOS Safari unlock + visibility resume |
59
- | Voice concurrency + stealing | Reverb (convolution + synthetic IR) | Stream long media via MediaElementSource | Sample-accurate scheduler |
60
- | Sidechain ducking (Ducker) | Time-stretch (offline SOLA + realtime Worklet) | Loudness normalization on load | Async cues iterator on every Voice |
58
+ | Master headroom + soft limiter (DynamicsCompressor) | Filter (BiquadFilter, all 6 modes) | Audio sprites (one buffer, N regions) | iOS Safari unlock + visibility resume |
59
+ | Voice concurrency + stealing | Reverb (convolution + synthetic IR) | Stream long media via MediaElementSource | Audio-clock scheduler (`scheduleAt`) |
60
+ | Sidechain ducking (Ducker) | Pitch-preserving time-stretch (offline SOLA) + realtime varispeed Worklet | Loudness normalization on load | Async cues iterator on every Voice |
61
61
  | Snapshots — capture & crossfade the mix | Spatializer (2D pan + 3D HRTF) | AbortSignal cancellation | "Did you mean…" on bus/sound name typos |
62
62
 
63
63
  ## Examples
@@ -96,9 +96,9 @@ engine.crossfade('intro', 'main', { duration: 1.5 });
96
96
  ```ts
97
97
  import { Ducker } from '@schmooky/zvuk';
98
98
 
99
- const ducker = new Ducker(engine.context, {
100
- source: engine.bus('voice').output,
101
- target: engine.bus('music'),
99
+ // The source bus (keyed from) is the 2nd argument; the target bus is
100
+ // whichever bus you add the ducker to.
101
+ const ducker = new Ducker(engine.context, engine.bus('voice'), {
102
102
  amount: 0.7, attack: 0.08, release: 0.6,
103
103
  });
104
104
  engine.bus('music').addFx(ducker);
@@ -182,9 +182,9 @@ Releases are driven by [Changesets](https://github.com/changesets/changesets) on
182
182
  1. Add a changeset describing your change: `pnpm changeset`
183
183
  2. Open a PR; CI gates on lint + typecheck + tests + lib build + docs build.
184
184
  3. On merge to `main`, the release workflow opens (or updates) a `Version Packages` PR that bumps the version and regenerates `CHANGELOG.md`.
185
- 4. Merging that PR publishes to npm with provenance attestation and creates a GitHub Release.
185
+ 4. Merging that PR publishes to npm with provenance attestation and creates a GitHub Release. Auth uses **npm OIDC trusted publishing** — no `NPM_TOKEN` secret; the workflow exchanges a GitHub OIDC token for a short-lived npm publish token.
186
186
 
187
- For per-branch preview publishes on non-`main` branches, a snapshot workflow auto-publishes under a sanitized branch dist-tag — install with `pnpm add @schmooky/zvuk@<branch>`.
187
+ The same `release.yml` workflow handles per-branch preview publishes: pushing a non-`main` branch (or running it via `workflow_dispatch`) snapshot-publishes the pending changesets under a sanitized branch dist-tag — install with `pnpm add @schmooky/zvuk@<branch>`.
188
188
 
189
189
  ## CLI
190
190
 
package/dist/index.d.ts CHANGED
@@ -145,7 +145,7 @@ interface SendOptions {
145
145
  interface MasterLimiterConfig {
146
146
  /** Threshold in dB. Default -1 (just below 0 dBFS). */
147
147
  threshold?: number;
148
- /** Compression ratio. Default 20 (brick-wall). */
148
+ /** Compression ratio. Default 20 (high — limiter-like, but not a true brick wall). */
149
149
  ratio?: number;
150
150
  /** Attack in seconds. Default 0.001 (fast — catches the transient). */
151
151
  attack?: number;
@@ -155,7 +155,7 @@ interface MasterLimiterConfig {
155
155
  interface MasterConfig {
156
156
  /** Headroom in dB applied to the master gain (negative). Default: 0. */
157
157
  headroom?: number;
158
- /** Optional brick-wall limiter on the master output. */
158
+ /** Optional fast-attack soft limiter on the master output (best-effort peak control). */
159
159
  limiter?: MasterLimiterConfig;
160
160
  }
161
161
  /**
@@ -312,6 +312,13 @@ interface StopOptions {
312
312
  fade?: number;
313
313
  }
314
314
  interface VoiceJitter {
315
+ /**
316
+ * Center value the jitter varies around. Defaults to 1 (the neutral
317
+ * volume / playback rate). Set it to combine a base with jitter, e.g.
318
+ * `{ base: 1.5, jitter: 0.1 }` plays at 1.5 ± 0.1 per voice.
319
+ */
320
+ base?: number;
321
+ /** Maximum ± random deviation from `base`, drawn once per voice. */
315
322
  jitter?: number;
316
323
  }
317
324
  /**
@@ -416,8 +423,9 @@ interface LoadSoundOptions {
416
423
  signal?: AbortSignal;
417
424
  /**
418
425
  * 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.
426
+ * the same RMS level as other normalized sounds. (Full-band RMS, not
427
+ * perceptual/LUFS.) Pass `true` for defaults or an options object to tune
428
+ * the target.
421
429
  */
422
430
  normalize?: boolean | LoudnessOptions$1;
423
431
  }
@@ -709,13 +717,15 @@ declare class Send {
709
717
  declare class Bus {
710
718
  readonly name: string;
711
719
  readonly input: GainNode;
712
- /** Sub-bus where FX inserts go. Currently == input; reserved for FX chain. */
720
+ /** Sub-bus the FX chain splices into: input → fxInput → (fx…) → output. */
713
721
  readonly fxInput: GainNode;
714
722
  /** Output node — connect to master.input or another bus.input for sends. */
715
723
  readonly output: GainNode;
716
724
  private _level;
717
725
  private _muted;
718
726
  private _soloed;
727
+ /** True while the engine's solo rule is silencing this (non-soloed) bus. */
728
+ private _soloVeiled;
719
729
  private readonly ctx;
720
730
  private _concurrency;
721
731
  private _voices;
@@ -845,6 +855,8 @@ declare class Ducker implements FxInsert {
845
855
  private analyser;
846
856
  private buf;
847
857
  private rafId;
858
+ /** Timestamp of the previous tick (ms), for measuring the real frame delta. */
859
+ private lastTickMs;
848
860
  private envelope;
849
861
  private targetGain;
850
862
  private ctx;
@@ -886,6 +898,8 @@ declare class Filter implements FxInsert {
886
898
  setFrequency(hz: number): void;
887
899
  setQ(q: number): void;
888
900
  setType(t: FilterKind): void;
901
+ /** Set the filter gain in dB. Only affects `peaking` (the one shelf-like mode exposed). */
902
+ setGain(db: number): void;
889
903
  get bypassed(): boolean;
890
904
  set bypassed(v: boolean);
891
905
  dispose(): void;
@@ -919,6 +933,8 @@ declare class Reverb implements FxInsert {
919
933
  private preDelay;
920
934
  private ctx;
921
935
  private _bypassed;
936
+ /** Active wet mix (0..1), so bypass can restore it instead of guessing. */
937
+ private _wet;
922
938
  constructor(ctx: AudioContext, config?: ReverbConfig);
923
939
  setWet(mix: number): void;
924
940
  setImpulse(buffer: AudioBuffer): void;
@@ -949,21 +965,25 @@ declare class StretchProcessor {
949
965
  }
950
966
 
951
967
  /**
952
- * Realtime time-stretch via AudioWorklet.
968
+ * Realtime *varispeed* via AudioWorklet.
953
969
  *
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.
970
+ * The realtime companion to the offline `StretchProcessor`. Loads a worklet
971
+ * processor into the AudioContext and exposes a node whose `stretch`
972
+ * AudioParam can be automated live — boss intros that bend in real time,
973
+ * slow-mo stings, etc.
957
974
  *
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.
975
+ * IMPORTANT: unlike the offline `StretchProcessor`, this node is NOT
976
+ * pitch-preserving. It resamples a ring buffer at a variable read rate via
977
+ * linear interpolation, so changing `stretch` shifts pitch *and* tempo
978
+ * together — classic varispeed / tape-style speed change. It is cheap and
979
+ * sounds fine for live ramps across the 0.25×–4× range when you don't need
980
+ * pitch held constant. For pitch-preserving (offline) stretching, use
981
+ * `StretchProcessor`.
962
982
  */
963
983
  interface StretchWorkletOptions {
964
- /** Initial stretch factor. 1 = play at source rate. > 1 = faster. */
984
+ /** Initial stretch factor. 1 = play at source rate. > 1 = faster (higher pitch). */
965
985
  stretchFactor?: number;
966
- /** Grain size in samples. Default 1024. Larger = smoother but more latency. */
986
+ /** Ring-buffer sizing hint in samples (ring = 8×). Default 1024. */
967
987
  grainSize?: number;
968
988
  }
969
989
  interface StretchWorkletNode extends AudioNode {
@@ -1332,6 +1352,21 @@ declare class Snapshot {
1332
1352
  private getParam;
1333
1353
  constructor(name: string, state: SnapshotState, getBus: (name: string) => Bus | undefined, getParam: (name: string) => Parameter | undefined);
1334
1354
  apply(opts?: ApplyOptions): Promise<void>;
1355
+ /**
1356
+ * Snap the live mix to a linear interpolation between this snapshot and
1357
+ * `other`. `t` is clamped to [0, 1]: `t = 0` matches this snapshot,
1358
+ * `t = 1` matches `other`, and intermediate values lerp every shared
1359
+ * bus level and parameter.
1360
+ *
1361
+ * Designed to be called continuously (e.g. from a `Parameter` subscriber)
1362
+ * — each call snaps instantly. For a one-shot crossfade with a fade
1363
+ * duration, use `apply({ fade })` instead.
1364
+ *
1365
+ * Buses or parameters present in only one of the two snapshots are
1366
+ * skipped. Mute flags are not interpolated: `t < 0.5` uses this
1367
+ * snapshot's mute, `t >= 0.5` uses `other`'s.
1368
+ */
1369
+ blendWith(other: Snapshot, t: number): void;
1335
1370
  }
1336
1371
 
1337
1372
  /**
@@ -1477,8 +1512,10 @@ interface Engine<TBusName extends string = string> {
1477
1512
  * over the same window with `equal-power` curves so the perceived loudness
1478
1513
  * stays flat.
1479
1514
  *
1480
- * Returns the new Voice. If `to` is already playing, its level is faded up
1481
- * from 0 instead of starting fresh.
1515
+ * Returns the new Voice — a fresh voice for `to` is always started at
1516
+ * volume 0 and faded up. Only voices of `from` on the same bus the new
1517
+ * voice plays on are faded out; instances of `from` on other buses are
1518
+ * left untouched.
1482
1519
  */
1483
1520
  crossfade(from: string, to: string, options?: CrossfadeOptions): Voice;
1484
1521
  scheduleAt(audioTime: number, fn: () => void): () => void;
@@ -1491,6 +1528,20 @@ interface Engine<TBusName extends string = string> {
1491
1528
  captureSnapshot(name: string): Snapshot;
1492
1529
  /** Build a Snapshot from explicit state without capturing the live engine. */
1493
1530
  snapshot(name: string, state: SnapshotState): Snapshot;
1531
+ /**
1532
+ * Snap the live mix to a linear interpolation between two snapshots.
1533
+ * `t` is clamped to [0, 1]: `t = 0` matches `a`, `t = 1` matches `b`,
1534
+ * intermediate values lerp every shared bus level and parameter.
1535
+ *
1536
+ * Drive a `Parameter` to animate over time — each call snaps instantly,
1537
+ * so a per-frame subscriber gives a continuous blend without scheduling
1538
+ * fades. Use `snapshot.apply({ fade })` for one-shot crossfades.
1539
+ *
1540
+ * const tension = engine.parameter('tension', 0);
1541
+ * tension.bindTo((t) => engine.blendSnapshots(calm, combat, t));
1542
+ * tension.set(0.4); // mix is now 40% of the way to combat
1543
+ */
1544
+ blendSnapshots(a: Snapshot, b: Snapshot, t: number): void;
1494
1545
  }
1495
1546
  interface CrossfadeOptions {
1496
1547
  /** Crossfade duration in seconds. Default 1.5. */
@@ -1516,12 +1567,14 @@ interface CrossfadeOptions {
1516
1567
  declare function createEngine<TBusName extends string = string>(config?: EngineConfig<TBusName>): Engine<TBusName>;
1517
1568
 
1518
1569
  /**
1519
- * The Master stage. Headroom-aware gain into an optional brick-wall limiter,
1520
- * then to destination. Buses connect their output to master.input.
1570
+ * The Master stage. Headroom-aware gain into an optional soft limiter, then to
1571
+ * destination. Buses connect their output to master.input.
1521
1572
  *
1522
1573
  * Headroom is a static gain offset; the limiter is a fast-attack
1523
- * DynamicsCompressorNode that catches peaks the headroom can't tame when
1524
- * heavy FX stack on top of busy mixes.
1574
+ * DynamicsCompressorNode that catches most peaks the headroom can't tame when
1575
+ * heavy FX stack on top of busy mixes. Note it is best-effort, not a true
1576
+ * brick-wall limiter — with a finite attack and no lookahead, transient peaks
1577
+ * above the threshold can still pass, so it does not guarantee a hard ceiling.
1525
1578
  */
1526
1579
  declare class Master {
1527
1580
  readonly input: GainNode;
@@ -1593,10 +1646,14 @@ declare function pickSourceOrder(urls: readonly string[]): readonly string[];
1593
1646
  /**
1594
1647
  * RMS-based loudness normalization on a decoded AudioBuffer.
1595
1648
  *
1596
- * `engine.loadSound(..., { normalize: true })` runs this at decode-time
1597
- * and produces a buffer pre-scaled so all sounds sit at the same perceived
1598
- * loudness — removing a workflow tax that game-audio teams currently pay
1599
- * in their DAW. Pass an object to override the target RMS or peak ceiling.
1649
+ * `engine.loadSound(..., { normalize: true })` runs this at decode-time and
1650
+ * produces a buffer pre-scaled so all sounds sit at the same RMS level —
1651
+ * removing a workflow tax that game-audio teams currently pay in their DAW.
1652
+ * Pass an object to override the target RMS or peak ceiling.
1653
+ *
1654
+ * NOTE: this is full-band RMS, not perceptual (K-weighted / LUFS) loudness —
1655
+ * two spectrally different clips at equal RMS may still differ in perceived
1656
+ * loudness.
1600
1657
  */
1601
1658
  interface LoudnessOptions {
1602
1659
  /** Target RMS (linear, 0..1). Default 0.1 (~ -20 dBFS). */
@@ -1605,7 +1662,7 @@ interface LoudnessOptions {
1605
1662
  peakCeiling?: number;
1606
1663
  }
1607
1664
  type NormalizeFlag = boolean | LoudnessOptions;
1608
- declare function applyLoudnessNormalization(buffer: AudioBuffer, flag: NormalizeFlag): AudioBuffer;
1665
+ declare function applyLoudnessNormalization(buffer: AudioBuffer, flag: NormalizeFlag, ctx?: BaseAudioContext): AudioBuffer;
1609
1666
  declare function computeNormalizationGain(buffer: AudioBuffer, opts: Required<LoudnessOptions>): number;
1610
1667
 
1611
1668
  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 };