@threenative/core 0.1.0 → 0.3.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.
@@ -0,0 +1,94 @@
1
+ import { AudioListener, Object3D, Audio, Vector3, PositionalAudio } from 'three';
2
+
3
+ interface IAudioBusOptions {
4
+ readonly camera: Object3D;
5
+ readonly gestureTarget?: EventTarget;
6
+ readonly listener?: AudioListener;
7
+ readonly source?: () => EventTarget | undefined;
8
+ /**
9
+ * Ceiling on simultaneously sounding one-shots. Past it the oldest voice is stopped and its
10
+ * slot reused: a firefight generates far more cues than a listener can resolve, and the newest
11
+ * event is always the one they need to hear. Looping voices from `music` are exempt.
12
+ * Defaults to 48.
13
+ */
14
+ readonly maxVoices?: number;
15
+ }
16
+ interface IAudioPlayOptions {
17
+ readonly fade?: number;
18
+ readonly loop?: boolean;
19
+ readonly volume?: number;
20
+ /**
21
+ * Metres from the source where positional attenuation begins; `playAt` only. Three's panner
22
+ * default of 1 m makes a shot 20 m away all but inaudible — raise this to keep mid-distance
23
+ * sounds loud. Must be finite and positive.
24
+ */
25
+ readonly refDistance?: number;
26
+ /**
27
+ * How fast volume falls off past `refDistance`; `playAt` only. 0 keeps the sound at full
28
+ * volume at any distance. Must be finite and non-negative.
29
+ */
30
+ readonly rolloffFactor?: number;
31
+ /**
32
+ * Pitch offset in cents; ±100 is a semitone. Applied before the first sample rather than
33
+ * through three's `setDetune`, which ramps over ~30 ms and turns a percussive attack into an
34
+ * audible sweep. A few dozen cents of per-shot spread is what stops a repeated sample
35
+ * comb-filtering with its own copies into a metallic buzz.
36
+ */
37
+ readonly detune?: number;
38
+ /**
39
+ * Seconds of the buffer to pass before an exponential cut-off. A 1.4 s gunshot fired ten times
40
+ * a second stacks fourteen overlapping tails into mush; truncating all but the last keeps the
41
+ * transient and drops the wash. Must be finite and positive.
42
+ */
43
+ readonly cutoffSeconds?: number;
44
+ /**
45
+ * Low-pass corner in Hz. Air and geometry eat the top of a sound as it crosses a space, and a
46
+ * sample played flat at every range is the loudest tell that a game's audio is not in a place.
47
+ * Must be finite and positive.
48
+ */
49
+ readonly lowpassHz?: number;
50
+ }
51
+ interface IAudioRuntimeSnapshot {
52
+ readonly queued: number;
53
+ readonly voices: number;
54
+ /** Retired voices held for reuse. Bounded by peak concurrency, never by session length. */
55
+ readonly pooled: number;
56
+ }
57
+ declare class AudioBus {
58
+ #private;
59
+ readonly listener: AudioListener;
60
+ constructor(options: IAudioBusOptions);
61
+ get queued(): number;
62
+ get voices(): number;
63
+ /**
64
+ * Retired voices held for reuse. This is the number that used to climb without limit: it is
65
+ * now bounded by how many cues have ever sounded at once, so a gate can pin it.
66
+ */
67
+ get pooled(): number;
68
+ setCamera(camera: Object3D): void;
69
+ reparent(camera: Object3D): void;
70
+ unlock(): Promise<void>;
71
+ /**
72
+ * A cue with no place: the listener's own weapon, UI, narration.
73
+ *
74
+ * The returned voice is valid for as long as it is sounding. Once it ends the bus reclaims it
75
+ * and may hand the same object to a later cue, so a caller holding the reference past that
76
+ * point is addressing somebody else's sound. Read `isPlaying` before touching a voice you kept.
77
+ */
78
+ play(buffer: AudioBuffer, options?: IAudioPlayOptions): Audio;
79
+ /**
80
+ * A cue somewhere in the world, at a fixed point or riding a moving object.
81
+ *
82
+ * A `Vector3` source is read in the coordinate space of the camera's parent, which is the
83
+ * scene in the ordinary case. Pass an `Object3D` to weld the cue to something that moves.
84
+ *
85
+ * The same reclaim rule as `play` applies to the returned voice.
86
+ */
87
+ playAt(buffer: AudioBuffer, source: Object3D | Vector3, options?: IAudioPlayOptions): PositionalAudio;
88
+ music(buffer: AudioBuffer, options?: IAudioPlayOptions): Audio;
89
+ stop(): void;
90
+ dispose(): void;
91
+ }
92
+ declare function audioRuntimeSnapshot(): IAudioRuntimeSnapshot;
93
+
94
+ export { AudioBus as A, type IAudioBusOptions as I, audioRuntimeSnapshot as a, type IAudioPlayOptions as b };