@schmooky/zvuk 1.8.0 → 1.10.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 +212 -7
- package/dist/index.js +315 -17
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -130,6 +130,18 @@ interface BusConfig {
|
|
|
130
130
|
concurrency?: ConcurrencyConfig;
|
|
131
131
|
sidechain?: SidechainConfig;
|
|
132
132
|
}
|
|
133
|
+
interface SendOptions {
|
|
134
|
+
/** Send level (0..1). Default 1. */
|
|
135
|
+
amount?: number;
|
|
136
|
+
/**
|
|
137
|
+
* Tap the source bus's output (post-fader, post-FX) when `true`,
|
|
138
|
+
* or input (pre-fader, pre-FX) when `false`. Default `true` — almost
|
|
139
|
+
* always what you want. Pre-fader sends are mainly useful for
|
|
140
|
+
* monitoring buses that should hear the dry signal regardless of how
|
|
141
|
+
* the user has faded the source bus down.
|
|
142
|
+
*/
|
|
143
|
+
post?: boolean;
|
|
144
|
+
}
|
|
133
145
|
interface MasterLimiterConfig {
|
|
134
146
|
/** Threshold in dB. Default -1 (just below 0 dBFS). */
|
|
135
147
|
threshold?: number;
|
|
@@ -285,11 +297,48 @@ interface StopOptions {
|
|
|
285
297
|
interface VoiceJitter {
|
|
286
298
|
jitter?: number;
|
|
287
299
|
}
|
|
300
|
+
/**
|
|
301
|
+
* Distance-attenuation curve. Mirrors `PannerNode.distanceModel`:
|
|
302
|
+
* - `'inverse'` (default) — natural-sounding rolloff, matches outdoor sound.
|
|
303
|
+
* - `'linear'` — straight-line attenuation between `refDistance` and `maxDistance`.
|
|
304
|
+
* - `'exponential'` — steeper than inverse; useful for tight environments.
|
|
305
|
+
*/
|
|
306
|
+
type DistanceModel = 'linear' | 'inverse' | 'exponential';
|
|
288
307
|
interface SpatialOptions {
|
|
289
308
|
/** [-1, 1] stereo pan (2D). Mutually exclusive with `position`. */
|
|
290
309
|
pan?: number;
|
|
291
310
|
/** [x, y, z] world-space position (3D). Mutually exclusive with `pan`. */
|
|
292
311
|
position?: [number, number, number];
|
|
312
|
+
/**
|
|
313
|
+
* Distance below which the source is at full volume. Default 1.
|
|
314
|
+
* 3D only; ignored when `pan` is used.
|
|
315
|
+
*/
|
|
316
|
+
refDistance?: number;
|
|
317
|
+
/**
|
|
318
|
+
* Distance beyond which `'linear'` attenuation reaches zero. The
|
|
319
|
+
* `'inverse'` and `'exponential'` models keep falling off but use this
|
|
320
|
+
* as the curve's anchor. Default 10000.
|
|
321
|
+
* 3D only; ignored when `pan` is used.
|
|
322
|
+
*/
|
|
323
|
+
maxDistance?: number;
|
|
324
|
+
/**
|
|
325
|
+
* How aggressively distance attenuates the sound. 1 is the natural
|
|
326
|
+
* rolloff for the chosen `distanceModel`; higher values produce a
|
|
327
|
+
* more dramatic falloff. Default 1.
|
|
328
|
+
* 3D only; ignored when `pan` is used.
|
|
329
|
+
*/
|
|
330
|
+
rolloffFactor?: number;
|
|
331
|
+
/** Distance-attenuation curve. Default `'inverse'`. 3D only. */
|
|
332
|
+
distanceModel?: DistanceModel;
|
|
333
|
+
/**
|
|
334
|
+
* Occlusion amount (0..1). Drives an internal low-pass filter that
|
|
335
|
+
* sweeps cutoff from 22050 Hz (transparent) down to ~500 Hz (heavily
|
|
336
|
+
* muffled), plus a small gain dip — the standard "behind a wall"
|
|
337
|
+
* effect. Independent of distance attenuation; combine via a
|
|
338
|
+
* `Parameter` if you want one knob to drive both.
|
|
339
|
+
* 3D only; ignored when `pan` is used.
|
|
340
|
+
*/
|
|
341
|
+
occlusion?: number;
|
|
293
342
|
}
|
|
294
343
|
interface PlayOptions {
|
|
295
344
|
/** Initial volume (0..1). Default 1. */
|
|
@@ -435,18 +484,43 @@ interface PreloadOptions {
|
|
|
435
484
|
}
|
|
436
485
|
|
|
437
486
|
/**
|
|
438
|
-
* PannerNode wrapper. Inserted between a Voice and
|
|
439
|
-
* passes a `spatializer` option.
|
|
440
|
-
*
|
|
441
|
-
*
|
|
487
|
+
* PannerNode + occlusion biquad wrapper. Inserted between a Voice and
|
|
488
|
+
* its Bus when a play call passes a `spatializer` option.
|
|
489
|
+
*
|
|
490
|
+
* - 2D pan uses `StereoPannerNode` (cheap, just left/right shift).
|
|
491
|
+
* - 3D uses `PannerNode` in HRTF mode (one node per voice — fine for
|
|
492
|
+
* the dozens of simultaneous voices a typical game holds, expensive
|
|
493
|
+
* past hundreds), followed by a biquad lowpass for occlusion plus a
|
|
494
|
+
* gain stage so occlusion can also drop level slightly.
|
|
495
|
+
*
|
|
496
|
+
* 3D config (`refDistance`, `maxDistance`, `rolloffFactor`,
|
|
497
|
+
* `distanceModel`) is configurable per voice via `SpatialOptions` and
|
|
498
|
+
* tunable live via the `set*` methods. Occlusion is a single 0..1 knob
|
|
499
|
+
* that drives the lowpass cutoff plus a small gain dip.
|
|
442
500
|
*/
|
|
443
501
|
declare class Spatializer {
|
|
444
|
-
private
|
|
502
|
+
private ctx;
|
|
445
503
|
private kind;
|
|
504
|
+
private input;
|
|
505
|
+
private output;
|
|
506
|
+
private stereoPan;
|
|
507
|
+
private panner;
|
|
508
|
+
private occlusionFilter;
|
|
509
|
+
private occlusionGain;
|
|
446
510
|
constructor(ctx: AudioContext, opts: SpatialOptions);
|
|
447
511
|
setPan(pan: number): void;
|
|
448
512
|
setPosition(x: number, y: number, z: number): void;
|
|
449
|
-
|
|
513
|
+
setRefDistance(d: number): void;
|
|
514
|
+
setMaxDistance(d: number): void;
|
|
515
|
+
setRolloffFactor(f: number): void;
|
|
516
|
+
setDistanceModel(m: DistanceModel): void;
|
|
517
|
+
/**
|
|
518
|
+
* Set occlusion amount (0..1). Drives the internal lowpass cutoff
|
|
519
|
+
* and a small gain dip — independent of distance attenuation.
|
|
520
|
+
* No-op on 2D spatializers.
|
|
521
|
+
*/
|
|
522
|
+
setOcclusion(amount: number): void;
|
|
523
|
+
/** Connects the spatializer's output into `dest` and returns the input the Voice should use. */
|
|
450
524
|
connectInto(dest: AudioNode): AudioNode;
|
|
451
525
|
dispose(): void;
|
|
452
526
|
private setPanner3D;
|
|
@@ -578,6 +652,26 @@ declare class Voice {
|
|
|
578
652
|
private computeOffset;
|
|
579
653
|
}
|
|
580
654
|
|
|
655
|
+
/**
|
|
656
|
+
* One configured send from a source bus to a target bus. Returned by
|
|
657
|
+
* `bus.send(target, ...)`; held by callers so the level can be adjusted
|
|
658
|
+
* (or the send removed) at runtime.
|
|
659
|
+
*/
|
|
660
|
+
declare class Send {
|
|
661
|
+
readonly source: Bus;
|
|
662
|
+
readonly target: Bus;
|
|
663
|
+
readonly post: boolean;
|
|
664
|
+
private gainNode;
|
|
665
|
+
private ctx;
|
|
666
|
+
private disposed;
|
|
667
|
+
constructor(source: Bus, target: Bus, options: SendOptions, ctx: AudioContext);
|
|
668
|
+
/** Live send level (0..1). Setter ramps over 10 ms to avoid clicks. */
|
|
669
|
+
get amount(): number;
|
|
670
|
+
set amount(v: number);
|
|
671
|
+
/** Fade the send to `target` over `duration` seconds. */
|
|
672
|
+
fadeTo(target: number, duration: number, curve?: FadeCurve): Promise<void>;
|
|
673
|
+
dispose(): void;
|
|
674
|
+
}
|
|
581
675
|
/**
|
|
582
676
|
* A Bus is a named mix bucket with its own gain stage, optional FX inserts,
|
|
583
677
|
* a voice-concurrency limit, and an optional sidechain key.
|
|
@@ -597,12 +691,21 @@ declare class Bus {
|
|
|
597
691
|
readonly output: GainNode;
|
|
598
692
|
private _level;
|
|
599
693
|
private _muted;
|
|
694
|
+
private _soloed;
|
|
600
695
|
private readonly ctx;
|
|
601
696
|
private _concurrency;
|
|
602
697
|
private _voices;
|
|
603
698
|
private _fxChain;
|
|
699
|
+
private _sends;
|
|
604
700
|
private _meterAnalyser;
|
|
605
701
|
private _meterBuf;
|
|
702
|
+
/**
|
|
703
|
+
* Engine-injected callback fired when this bus's solo state changes.
|
|
704
|
+
* The Engine uses it to coordinate the global "any soloed → mute the
|
|
705
|
+
* rest" rule across every bus in the graph. Bus does not depend on
|
|
706
|
+
* Engine; the callback is the only escape hatch.
|
|
707
|
+
*/
|
|
708
|
+
notifySoloChange?: (bus: Bus, soloed: boolean) => void;
|
|
606
709
|
constructor(ctx: AudioContext, name: string, config?: BusConfig);
|
|
607
710
|
get level(): number;
|
|
608
711
|
set level(v: number);
|
|
@@ -642,6 +745,47 @@ declare class Bus {
|
|
|
642
745
|
* reacts to overall bus level, or implement custom voice-stealing rules.
|
|
643
746
|
*/
|
|
644
747
|
meter(): AudioLevel;
|
|
748
|
+
/**
|
|
749
|
+
* Route a copy of this bus's signal into another bus at the configured
|
|
750
|
+
* level. `target.input` mixes the send naturally with whatever else is
|
|
751
|
+
* already feeding it, so the typical pattern — "send 30 % of music to a
|
|
752
|
+
* dedicated reverb bus" — is just two lines:
|
|
753
|
+
*
|
|
754
|
+
* ```ts
|
|
755
|
+
* const verbSend = engine.bus('music').send(engine.bus('reverb'), { amount: 0.3 });
|
|
756
|
+
* verbSend.amount = 0.5; // turn it up live
|
|
757
|
+
* verbSend.dispose(); // remove the send entirely
|
|
758
|
+
* ```
|
|
759
|
+
*
|
|
760
|
+
* Default tap is post-fader / post-FX (`post: true`); set `post: false`
|
|
761
|
+
* if you want a monitor send that hears the dry pre-fader signal.
|
|
762
|
+
*/
|
|
763
|
+
send(target: Bus, options?: SendOptions): Send;
|
|
764
|
+
/** Remove a previously-created send. Idempotent. */
|
|
765
|
+
removeSend(send: Send): void;
|
|
766
|
+
/** Read-only snapshot of every active send originating on this bus. */
|
|
767
|
+
sends(): readonly Send[];
|
|
768
|
+
/**
|
|
769
|
+
* Solo this bus. The engine coordinates the global rule: while any bus
|
|
770
|
+
* is soloed, every non-soloed bus is muted. Soloing multiple buses is
|
|
771
|
+
* additive — they all stay audible. Calling `unsolo()` (or `solo(false)`)
|
|
772
|
+
* removes this bus from the soloed set.
|
|
773
|
+
*
|
|
774
|
+
* Solo state is independent of `muted`; un-soloing returns the bus to
|
|
775
|
+
* whatever its `muted` setting was. Useful in mixer UIs where the user
|
|
776
|
+
* wants to A/B a single channel without disturbing the rest of the mix.
|
|
777
|
+
*/
|
|
778
|
+
solo(on?: boolean): void;
|
|
779
|
+
/** Turn solo off on this bus. Equivalent to `solo(false)`. */
|
|
780
|
+
unsolo(): void;
|
|
781
|
+
/** True when this bus is in the engine's solo set. */
|
|
782
|
+
get soloed(): boolean;
|
|
783
|
+
/**
|
|
784
|
+
* Engine-only. Apply a transient mute (or restore) driven by the global
|
|
785
|
+
* solo state. Distinct from `muted` so un-soloing returns the bus to its
|
|
786
|
+
* user-visible mute state without re-rendering.
|
|
787
|
+
*/
|
|
788
|
+
applySoloVeil(soloMute: boolean): void;
|
|
645
789
|
private rewireFxChain;
|
|
646
790
|
private rampOutput;
|
|
647
791
|
private ramp;
|
|
@@ -814,6 +958,44 @@ declare function ensureStretchWorklet(ctx: AudioContext): Promise<void>;
|
|
|
814
958
|
*/
|
|
815
959
|
declare function createStretchWorkletNode(ctx: AudioContext, options?: StretchWorkletOptions): StretchWorkletNode;
|
|
816
960
|
|
|
961
|
+
/**
|
|
962
|
+
* A logical handle that addresses several buses at once. Doesn't change
|
|
963
|
+
* the audio graph — applies operations (level, fade, mute, solo) to every
|
|
964
|
+
* member in parallel. Useful when several buses form a sub-mix that should
|
|
965
|
+
* always be controlled together: combat = weapons + enemies + environment;
|
|
966
|
+
* voice = dialogue + effort sounds; etc.
|
|
967
|
+
*
|
|
968
|
+
* Construct via `engine.busGroup(name, members)`; look up via
|
|
969
|
+
* `engine.busGroup(name)`. Snapshots and parameters can target a group
|
|
970
|
+
* instead of repeating bus names.
|
|
971
|
+
*/
|
|
972
|
+
declare class BusGroup {
|
|
973
|
+
readonly name: string;
|
|
974
|
+
readonly members: readonly Bus[];
|
|
975
|
+
constructor(name: string, members: readonly Bus[]);
|
|
976
|
+
/** Set the level on every member. Same 10 ms ramp as direct `bus.level =`. */
|
|
977
|
+
set level(v: number);
|
|
978
|
+
/**
|
|
979
|
+
* Read the current level. Returns the average across members — useful
|
|
980
|
+
* when every member shares a level (the common case) and informational
|
|
981
|
+
* otherwise.
|
|
982
|
+
*/
|
|
983
|
+
get level(): number;
|
|
984
|
+
set muted(v: boolean);
|
|
985
|
+
/** True if every member is currently muted. */
|
|
986
|
+
get muted(): boolean;
|
|
987
|
+
/**
|
|
988
|
+
* Fade every member to `target` over `duration` seconds. Returns when
|
|
989
|
+
* the slowest leg completes — in practice they're all equal because
|
|
990
|
+
* each member uses the same duration.
|
|
991
|
+
*/
|
|
992
|
+
fadeTo(target: number, duration: number, curve?: FadeCurve): Promise<void>;
|
|
993
|
+
/** Solo every member of the group. Engine handles the global mute-the-rest rule. */
|
|
994
|
+
solo(on?: boolean): void;
|
|
995
|
+
/** Un-solo every member. */
|
|
996
|
+
unsolo(): void;
|
|
997
|
+
}
|
|
998
|
+
|
|
817
999
|
type ParameterCurve = FadeCurve;
|
|
818
1000
|
type Subscriber = (value: number) => void;
|
|
819
1001
|
/**
|
|
@@ -1174,6 +1356,20 @@ interface Engine {
|
|
|
1174
1356
|
hasStream(name: string): boolean;
|
|
1175
1357
|
sound(name: string): Sound;
|
|
1176
1358
|
bus(name: string): Bus;
|
|
1359
|
+
/**
|
|
1360
|
+
* Define (with `members`) or look up (without) a `BusGroup` — a logical
|
|
1361
|
+
* handle that addresses several buses at once. Setting `group.level` or
|
|
1362
|
+
* `group.muted`, calling `group.fadeTo`, or `group.solo()` applies to
|
|
1363
|
+
* every member in parallel. Doesn't change the audio graph; pure
|
|
1364
|
+
* convenience for sub-mixes that always move together.
|
|
1365
|
+
*/
|
|
1366
|
+
busGroup(name: string, members?: readonly Bus[]): BusGroup;
|
|
1367
|
+
/**
|
|
1368
|
+
* Live amplitude readout on the master input. Same `{ rms, peak }`
|
|
1369
|
+
* shape as `bus.meter()` and `voice.level()`, just at the top of the
|
|
1370
|
+
* chain. First call lazily attaches a passive AnalyserNode tap.
|
|
1371
|
+
*/
|
|
1372
|
+
masterMeter(): AudioLevel;
|
|
1177
1373
|
/**
|
|
1178
1374
|
* Crossfade helper. Stops `from` over `duration` seconds while playing `to`
|
|
1179
1375
|
* over the same window with `equal-power` curves so the perceived loudness
|
|
@@ -1227,6 +1423,8 @@ declare class Master {
|
|
|
1227
1423
|
private limiterNode;
|
|
1228
1424
|
private limiterCfg;
|
|
1229
1425
|
private destination;
|
|
1426
|
+
private _meterAnalyser;
|
|
1427
|
+
private _meterBuf;
|
|
1230
1428
|
constructor(ctx: AudioContext, config?: MasterConfig);
|
|
1231
1429
|
setHeadroom(db: number): void;
|
|
1232
1430
|
get headroom(): number;
|
|
@@ -1237,6 +1435,13 @@ declare class Master {
|
|
|
1237
1435
|
setLimiter(cfg: MasterLimiterConfig | null): void;
|
|
1238
1436
|
/** Live gain reduction in dB. 0 if no limiter is engaged. */
|
|
1239
1437
|
get reduction(): number;
|
|
1438
|
+
/**
|
|
1439
|
+
* Live amplitude readout on the master input. Returns `{ rms, peak }`
|
|
1440
|
+
* as linear values in [0..1]. The first call lazily attaches an
|
|
1441
|
+
* AnalyserNode as a passive sibling of the master gain — no audio-path
|
|
1442
|
+
* change. Same shape as `bus.meter()` and `voice.level()`.
|
|
1443
|
+
*/
|
|
1444
|
+
meter(): AudioLevel;
|
|
1240
1445
|
dispose(): void;
|
|
1241
1446
|
private rewire;
|
|
1242
1447
|
}
|
|
@@ -1296,4 +1501,4 @@ type NormalizeFlag = boolean | LoudnessOptions;
|
|
|
1296
1501
|
declare function applyLoudnessNormalization(buffer: AudioBuffer, flag: NormalizeFlag): AudioBuffer;
|
|
1297
1502
|
declare function computeNormalizationGain(buffer: AudioBuffer, opts: Required<LoudnessOptions>): number;
|
|
1298
1503
|
|
|
1299
|
-
export { AggregateDecodeError, type ApplyOptions, type AssetResolver, type AudioLevel, type AudioMimeType, Bus, type BusConfig, BusNotFoundError, Compressor, type CompressorConfig, type ConcurrencyConfig, type CrossfadeOptions, type DecodeAttempt, DecodeError, 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, 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, Voice, type VoiceDefaults, type VoiceJitter, ZvukError, applyLoudnessNormalization, canPlay, computeNormalizationGain, createEngine, createStretchWorkletNode, ensureStretchWorklet, mimeForUrl, pickSource, pickSourceOrder };
|
|
1504
|
+
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, Voice, type VoiceDefaults, type VoiceJitter, ZvukError, applyLoudnessNormalization, canPlay, computeNormalizationGain, createEngine, createStretchWorkletNode, ensureStretchWorklet, mimeForUrl, pickSource, pickSourceOrder };
|