@flare-engine/audio 0.2.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.
- package/LICENSE +201 -21
- package/NOTICE +2 -0
- package/README.md +50 -8
- package/dist/index.d.mts +120 -109
- package/dist/index.d.mts.map +1 -0
- package/dist/index.d.ts +120 -109
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +263 -297
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +259 -267
- package/dist/index.mjs.map +1 -1
- package/package.json +15 -10
package/dist/index.d.ts
CHANGED
|
@@ -1,44 +1,52 @@
|
|
|
1
|
+
//#region src/audio-manager.d.ts
|
|
1
2
|
/**
|
|
2
3
|
* Minimal interfaces for the Web Audio API subset we use.
|
|
3
4
|
* At runtime these are provided by react-native-audio-api.
|
|
4
5
|
*/
|
|
5
6
|
interface AudioDestinationNodeLike {
|
|
6
|
-
|
|
7
|
+
readonly channelCount: number;
|
|
7
8
|
}
|
|
8
9
|
interface GainNodeLike {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
readonly gain: AudioParamLike;
|
|
11
|
+
connect(dest: AudioDestinationNodeLike | GainNodeLike): void;
|
|
12
|
+
disconnect(): void;
|
|
12
13
|
}
|
|
13
14
|
interface AudioParamLike {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
value: number;
|
|
16
|
+
setValueAtTime(value: number, time: number): void;
|
|
17
|
+
linearRampToValueAtTime(value: number, time: number): void;
|
|
17
18
|
}
|
|
18
19
|
interface AudioBufferLike {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
20
|
+
readonly duration: number;
|
|
21
|
+
readonly numberOfChannels: number;
|
|
22
|
+
readonly sampleRate: number;
|
|
23
|
+
readonly length: number;
|
|
23
24
|
}
|
|
24
25
|
interface AudioBufferSourceNodeLike {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
26
|
+
buffer: AudioBufferLike | null;
|
|
27
|
+
loop: boolean;
|
|
28
|
+
/**
|
|
29
|
+
* Playback-rate param (Web Audio shape). Optional — not every injected node
|
|
30
|
+
* exposes it; `SFXPool.play`'s `rate` option is a no-op when this is absent.
|
|
31
|
+
*/
|
|
32
|
+
readonly playbackRate?: {
|
|
33
|
+
value: number;
|
|
34
|
+
};
|
|
35
|
+
connect(dest: GainNodeLike | AudioDestinationNodeLike): void;
|
|
36
|
+
disconnect(): void;
|
|
37
|
+
start(when?: number): void;
|
|
38
|
+
stop(when?: number): void;
|
|
39
|
+
onended: ((this: AudioBufferSourceNodeLike, ev: unknown) => void) | null;
|
|
32
40
|
}
|
|
33
41
|
interface AudioContextLike {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
+
readonly state: 'suspended' | 'running' | 'closed';
|
|
43
|
+
readonly currentTime: number;
|
|
44
|
+
readonly destination: AudioDestinationNodeLike;
|
|
45
|
+
createGain(): GainNodeLike;
|
|
46
|
+
createBufferSource(): AudioBufferSourceNodeLike;
|
|
47
|
+
resume(): Promise<void>;
|
|
48
|
+
suspend(): Promise<void>;
|
|
49
|
+
close(): Promise<void>;
|
|
42
50
|
}
|
|
43
51
|
/** Audio context state. */
|
|
44
52
|
type AudioState = 'uninitialized' | 'running' | 'suspended' | 'closed';
|
|
@@ -47,31 +55,31 @@ type AudioState = 'uninitialized' | 'running' | 'suspended' | 'closed';
|
|
|
47
55
|
* Wraps react-native-audio-api's AudioContext.
|
|
48
56
|
*/
|
|
49
57
|
declare class AudioManager {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
close(): Promise<void>;
|
|
58
|
+
private ctx;
|
|
59
|
+
/** Current audio state. */
|
|
60
|
+
get state(): AudioState;
|
|
61
|
+
/** The underlying AudioContext, or null if not initialized. */
|
|
62
|
+
get context(): AudioContextLike | null;
|
|
63
|
+
/** Current time from the AudioContext. */
|
|
64
|
+
get currentTime(): number;
|
|
65
|
+
/** Initialize with a factory that creates the native AudioContext. */
|
|
66
|
+
init(factory: () => AudioContextLike): void;
|
|
67
|
+
/** Suspend audio. Call from your own background handler — no automatic wiring. */
|
|
68
|
+
suspend(): Promise<void>;
|
|
69
|
+
/** Resume audio. Call from your own foreground handler — no automatic wiring. */
|
|
70
|
+
resume(): Promise<void>;
|
|
71
|
+
/** Close and dispose the AudioContext. */
|
|
72
|
+
close(): Promise<void>;
|
|
66
73
|
}
|
|
67
|
-
|
|
74
|
+
//#endregion
|
|
75
|
+
//#region src/channels.d.ts
|
|
68
76
|
/** A volume channel that wraps a GainNode. */
|
|
69
77
|
interface Channel {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
78
|
+
readonly name: string;
|
|
79
|
+
/** Current volume (0.0 - 1.0). */
|
|
80
|
+
volume: number;
|
|
81
|
+
/** The underlying GainNode. */
|
|
82
|
+
readonly node: GainNodeLike;
|
|
75
83
|
}
|
|
76
84
|
/** Standard channel names. */
|
|
77
85
|
type ChannelName = 'master' | 'sfx' | 'music';
|
|
@@ -80,77 +88,80 @@ type ChannelName = 'master' | 'sfx' | 'music';
|
|
|
80
88
|
* Returns a map of channels by name.
|
|
81
89
|
*/
|
|
82
90
|
declare function createChannels(ctx: AudioContextLike): Map<ChannelName, Channel>;
|
|
83
|
-
|
|
91
|
+
//#endregion
|
|
92
|
+
//#region src/music.d.ts
|
|
93
|
+
/**
|
|
94
|
+
* Music player — one track at a time, with crossfade support.
|
|
95
|
+
* Loops by default.
|
|
96
|
+
*/
|
|
97
|
+
declare class Music {
|
|
98
|
+
private ctx;
|
|
99
|
+
private output;
|
|
100
|
+
private buffers;
|
|
101
|
+
private currentSource;
|
|
102
|
+
private currentGain;
|
|
103
|
+
private currentName;
|
|
104
|
+
/** Name of the currently playing track, or null. */
|
|
105
|
+
get playing(): string | null;
|
|
106
|
+
/** Connect to an AudioContext and output gain node. */
|
|
107
|
+
connect(ctx: AudioContextLike, output: GainNodeLike): void;
|
|
108
|
+
/** Register a music track buffer. */
|
|
109
|
+
register(name: string, buffer: AudioBufferLike): void;
|
|
110
|
+
/** Play a track. Stops any currently playing track. Loops by default. */
|
|
111
|
+
play(name: string, loop?: boolean): void;
|
|
112
|
+
/** Stop the current track. */
|
|
113
|
+
stop(): void;
|
|
114
|
+
/**
|
|
115
|
+
* Crossfade to another track over duration seconds.
|
|
116
|
+
* Fades out current and fades in the new track simultaneously.
|
|
117
|
+
*/
|
|
118
|
+
crossfadeTo(name: string, duration: number, loop?: boolean): void;
|
|
119
|
+
private stopInternal;
|
|
120
|
+
}
|
|
121
|
+
//#endregion
|
|
122
|
+
//#region src/sfx-pool.d.ts
|
|
84
123
|
/** Options for playing a sound effect. */
|
|
85
124
|
interface PlaySFXOptions {
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
125
|
+
/** Playback volume (0-1). Default: 1. */
|
|
126
|
+
volume?: number;
|
|
127
|
+
/** Playback rate multiplier. Default: 1. Applied only when the audio node exposes a `playbackRate` param. */
|
|
128
|
+
rate?: number;
|
|
129
|
+
/** Whether to loop. Default: false. */
|
|
130
|
+
loop?: boolean;
|
|
92
131
|
}
|
|
93
132
|
/** A handle to a playing SFX instance. */
|
|
94
133
|
interface SFXHandle {
|
|
95
|
-
|
|
96
|
-
|
|
134
|
+
/** Stop playback. */
|
|
135
|
+
stop(): void;
|
|
97
136
|
}
|
|
98
137
|
/**
|
|
99
138
|
* SFX pool — pre-decoded audio buffers with polyphony management.
|
|
100
139
|
* When max polyphony is reached, the oldest sound is killed.
|
|
101
140
|
*/
|
|
102
141
|
declare class SFXPool {
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
/**
|
|
128
|
-
* Music player — one track at a time, with crossfade support.
|
|
129
|
-
* Loops by default.
|
|
130
|
-
*/
|
|
131
|
-
declare class Music {
|
|
132
|
-
private ctx;
|
|
133
|
-
private output;
|
|
134
|
-
private buffers;
|
|
135
|
-
private currentSource;
|
|
136
|
-
private currentGain;
|
|
137
|
-
private currentName;
|
|
138
|
-
/** Name of the currently playing track, or null. */
|
|
139
|
-
get playing(): string | null;
|
|
140
|
-
/** Connect to an AudioContext and output gain node. */
|
|
141
|
-
connect(ctx: AudioContextLike, output: GainNodeLike): void;
|
|
142
|
-
/** Register a music track buffer. */
|
|
143
|
-
register(name: string, buffer: AudioBufferLike): void;
|
|
144
|
-
/** Play a track. Stops any currently playing track. Loops by default. */
|
|
145
|
-
play(name: string, loop?: boolean): void;
|
|
146
|
-
/** Stop the current track. */
|
|
147
|
-
stop(): void;
|
|
148
|
-
/**
|
|
149
|
-
* Crossfade to another track over duration seconds.
|
|
150
|
-
* Fades out current and fades in the new track simultaneously.
|
|
151
|
-
*/
|
|
152
|
-
crossfadeTo(name: string, duration: number, loop?: boolean): void;
|
|
153
|
-
private stopInternal;
|
|
142
|
+
private buffers;
|
|
143
|
+
private active;
|
|
144
|
+
private ctx;
|
|
145
|
+
private output;
|
|
146
|
+
private maxPolyphony;
|
|
147
|
+
constructor(maxPolyphony?: number);
|
|
148
|
+
/** Connect to an AudioContext and output GainNode. */
|
|
149
|
+
connect(ctx: AudioContextLike, output: GainNodeLike): void;
|
|
150
|
+
/** Register a pre-decoded audio buffer. */
|
|
151
|
+
register(name: string, buffer: AudioBufferLike): void;
|
|
152
|
+
/** Unregister a buffer. */
|
|
153
|
+
unregister(name: string): void;
|
|
154
|
+
/** Check if a buffer is registered. */
|
|
155
|
+
has(name: string): boolean;
|
|
156
|
+
/** Number of registered buffers. */
|
|
157
|
+
get size(): number;
|
|
158
|
+
/** Number of currently active sounds. */
|
|
159
|
+
get activeCount(): number;
|
|
160
|
+
/** Play a registered sound. Returns a handle, or null if not registered/no context. */
|
|
161
|
+
play(name: string, opts?: PlaySFXOptions): SFXHandle | null;
|
|
162
|
+
/** Stop all active sounds. */
|
|
163
|
+
stopAll(): void;
|
|
154
164
|
}
|
|
155
|
-
|
|
165
|
+
//#endregion
|
|
156
166
|
export { type AudioBufferLike, type AudioBufferSourceNodeLike, type AudioContextLike, type AudioDestinationNodeLike, AudioManager, type AudioParamLike, type AudioState, type Channel, type ChannelName, type GainNodeLike, Music, type PlaySFXOptions, type SFXHandle, SFXPool, createChannels };
|
|
167
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/audio-manager.ts","../src/channels.ts","../src/music.ts","../src/sfx-pool.ts"],"mappings":";;;;;UAKiB;WACN;;UAGM;WACN,MAAM;EACf,QAAQ,MAAM,2BAA2B;EACzC;;UAGe;EACf;EACA,eAAe,eAAe;EAC9B,wBAAwB,eAAe;;UAGxB;WACN;WACA;WACA;WACA;;UAGM;EACf,QAAQ;EACR;;;;;WAKS;IAAiB;;EAC1B,QAAQ,MAAM,eAAe;EAC7B;EACA,MAAM;EACN,KAAK;EACL,WAAW,MAAM,2BAA2B;;UAG7B;WACN;WACA;WACA,aAAa;EACtB,cAAc;EACd,sBAAsB;EACtB,UAAU;EACV,WAAW;EACX,SAAS;;;KAIC;;;;;cAMC;UACH;;MAGJ,SAAS;;MAMT,WAAW;;MAKX;;EAKJ,KAAK,eAAe;;EAMd,WAAW;;EAOX,UAAU;;EAOV,SAAS;;;;;UClGA;WACN;;EAET;;WAES,MAAM;;;KAIL;;;;;iBAMI,eAAe,KAAK,mBAAmB,IAAI,aAAa;;;;;;;cCP3D;UACH;UACA;UACA;UACA;UACA;UACA;;MAGJ;;EAKJ,QAAQ,KAAK,kBAAkB,QAAQ;;EAMvC,SAAS,cAAc,QAAQ;;EAK/B,KAAK,cAAc;;EAgCnB;;;;;EAQA,YAAY,cAAc,kBAAkB;UA+CpC;;;;;UCxHO;;EAEf;;EAEA;;EAEA;;;UAIe;;EAEf;;;;;;cAaW;UACH;UACA;UACA;UACA;UACA;cAEI;;EAMZ,QAAQ,KAAK,kBAAkB,QAAQ;;EAMvC,SAAS,cAAc,QAAQ;;EAK/B,WAAW;;EAKX,IAAI;;MAKA;;MAKA;;EAKJ,KAAK,cAAc,OAAO,iBAAiB;;EA+D3C"}
|