@flare-engine/audio 0.1.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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Grzegorz Otto
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,30 @@
1
+ # @flare-engine/audio
2
+
3
+ Web-Audio-shaped runtime audio — `AudioManager` (init / suspend / resume), `SFXPool` (pre-decoded buffers + polyphony cap), `Music` (single-track with crossfade), `createChannels` (master / sfx / music gain mixer). Auto-suspends on app background; resumes on foreground.
4
+
5
+ ## Install
6
+
7
+ ```sh
8
+ bun add @flare-engine/audio
9
+ ```
10
+
11
+ Native: pair with `react-native-audio-api` (Web Audio API on native).
12
+
13
+ ## Usage
14
+
15
+ ```ts
16
+ import { AudioManager, SFXPool, createChannels } from '@flare-engine/audio';
17
+
18
+ const manager = new AudioManager(audioContext);
19
+ const channels = createChannels(audioContext);
20
+ const sfx = new SFXPool(audioContext, channels.sfx, { maxVoices: 8 });
21
+
22
+ await manager.init();
23
+ sfx.play('shoot');
24
+ ```
25
+
26
+ See [API spec](../../docs/design/api-specs.md#flare-engineaudio--4kb-gzip) and [skill reference](../../.github/skills/flare-audio/SKILL.md).
27
+
28
+ ## License
29
+
30
+ MIT
@@ -0,0 +1,156 @@
1
+ /**
2
+ * Minimal interfaces for the Web Audio API subset we use.
3
+ * At runtime these are provided by react-native-audio-api.
4
+ */
5
+ interface AudioDestinationNodeLike {
6
+ readonly channelCount: number;
7
+ }
8
+ interface GainNodeLike {
9
+ readonly gain: AudioParamLike;
10
+ connect(dest: AudioDestinationNodeLike | GainNodeLike): void;
11
+ disconnect(): void;
12
+ }
13
+ interface AudioParamLike {
14
+ value: number;
15
+ setValueAtTime(value: number, time: number): void;
16
+ linearRampToValueAtTime(value: number, time: number): void;
17
+ }
18
+ interface AudioBufferLike {
19
+ readonly duration: number;
20
+ readonly numberOfChannels: number;
21
+ readonly sampleRate: number;
22
+ readonly length: number;
23
+ }
24
+ interface AudioBufferSourceNodeLike {
25
+ buffer: AudioBufferLike | null;
26
+ loop: boolean;
27
+ connect(dest: GainNodeLike | AudioDestinationNodeLike): void;
28
+ disconnect(): void;
29
+ start(when?: number): void;
30
+ stop(when?: number): void;
31
+ readonly onended: ((this: AudioBufferSourceNodeLike, ev: unknown) => void) | null;
32
+ }
33
+ interface AudioContextLike {
34
+ readonly state: 'suspended' | 'running' | 'closed';
35
+ readonly currentTime: number;
36
+ readonly destination: AudioDestinationNodeLike;
37
+ createGain(): GainNodeLike;
38
+ createBufferSource(): AudioBufferSourceNodeLike;
39
+ resume(): Promise<void>;
40
+ suspend(): Promise<void>;
41
+ close(): Promise<void>;
42
+ }
43
+ /** Audio context state. */
44
+ type AudioState = 'uninitialized' | 'running' | 'suspended' | 'closed';
45
+ /**
46
+ * AudioManager — manages the AudioContext lifecycle.
47
+ * Wraps react-native-audio-api's AudioContext.
48
+ */
49
+ declare class AudioManager {
50
+ private ctx;
51
+ private factory;
52
+ /** Current audio state. */
53
+ get state(): AudioState;
54
+ /** The underlying AudioContext, or null if not initialized. */
55
+ get context(): AudioContextLike | null;
56
+ /** Current time from the AudioContext. */
57
+ get currentTime(): number;
58
+ /** Initialize with a factory that creates the native AudioContext. */
59
+ init(factory: () => AudioContextLike): void;
60
+ /** Suspend audio (e.g. on app background). */
61
+ suspend(): Promise<void>;
62
+ /** Resume audio (e.g. on app foreground). */
63
+ resume(): Promise<void>;
64
+ /** Close and dispose the AudioContext. */
65
+ close(): Promise<void>;
66
+ }
67
+
68
+ /** A volume channel that wraps a GainNode. */
69
+ interface Channel {
70
+ readonly name: string;
71
+ /** Current volume (0.0 - 1.0). */
72
+ volume: number;
73
+ /** The underlying GainNode. */
74
+ readonly node: GainNodeLike;
75
+ }
76
+ /** Standard channel names. */
77
+ type ChannelName = 'master' | 'sfx' | 'music';
78
+ /**
79
+ * Creates volume channels connected: sfx → master, music → master, master → destination.
80
+ * Returns a map of channels by name.
81
+ */
82
+ declare function createChannels(ctx: AudioContextLike): Map<ChannelName, Channel>;
83
+
84
+ /** Options for playing a sound effect. */
85
+ interface PlaySFXOptions {
86
+ /** Playback volume (0-1). Default: 1. */
87
+ volume?: number;
88
+ /** Playback rate. Default: 1. */
89
+ rate?: number;
90
+ /** Whether to loop. Default: false. */
91
+ loop?: boolean;
92
+ }
93
+ /** A handle to a playing SFX instance. */
94
+ interface SFXHandle {
95
+ /** Stop playback. */
96
+ stop(): void;
97
+ }
98
+ /**
99
+ * SFX pool — pre-decoded audio buffers with polyphony management.
100
+ * When max polyphony is reached, the oldest sound is killed.
101
+ */
102
+ declare class SFXPool {
103
+ private buffers;
104
+ private active;
105
+ private ctx;
106
+ private output;
107
+ private maxPolyphony;
108
+ constructor(maxPolyphony?: number);
109
+ /** Connect to an AudioContext and output GainNode. */
110
+ connect(ctx: AudioContextLike, output: GainNodeLike): void;
111
+ /** Register a pre-decoded audio buffer. */
112
+ register(name: string, buffer: AudioBufferLike): void;
113
+ /** Unregister a buffer. */
114
+ unregister(name: string): void;
115
+ /** Check if a buffer is registered. */
116
+ has(name: string): boolean;
117
+ /** Number of registered buffers. */
118
+ get size(): number;
119
+ /** Number of currently active sounds. */
120
+ get activeCount(): number;
121
+ /** Play a registered sound. Returns a handle, or null if not registered/no context. */
122
+ play(name: string, opts?: PlaySFXOptions): SFXHandle | null;
123
+ /** Stop all active sounds. */
124
+ stopAll(): void;
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;
154
+ }
155
+
156
+ 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 };
@@ -0,0 +1,156 @@
1
+ /**
2
+ * Minimal interfaces for the Web Audio API subset we use.
3
+ * At runtime these are provided by react-native-audio-api.
4
+ */
5
+ interface AudioDestinationNodeLike {
6
+ readonly channelCount: number;
7
+ }
8
+ interface GainNodeLike {
9
+ readonly gain: AudioParamLike;
10
+ connect(dest: AudioDestinationNodeLike | GainNodeLike): void;
11
+ disconnect(): void;
12
+ }
13
+ interface AudioParamLike {
14
+ value: number;
15
+ setValueAtTime(value: number, time: number): void;
16
+ linearRampToValueAtTime(value: number, time: number): void;
17
+ }
18
+ interface AudioBufferLike {
19
+ readonly duration: number;
20
+ readonly numberOfChannels: number;
21
+ readonly sampleRate: number;
22
+ readonly length: number;
23
+ }
24
+ interface AudioBufferSourceNodeLike {
25
+ buffer: AudioBufferLike | null;
26
+ loop: boolean;
27
+ connect(dest: GainNodeLike | AudioDestinationNodeLike): void;
28
+ disconnect(): void;
29
+ start(when?: number): void;
30
+ stop(when?: number): void;
31
+ readonly onended: ((this: AudioBufferSourceNodeLike, ev: unknown) => void) | null;
32
+ }
33
+ interface AudioContextLike {
34
+ readonly state: 'suspended' | 'running' | 'closed';
35
+ readonly currentTime: number;
36
+ readonly destination: AudioDestinationNodeLike;
37
+ createGain(): GainNodeLike;
38
+ createBufferSource(): AudioBufferSourceNodeLike;
39
+ resume(): Promise<void>;
40
+ suspend(): Promise<void>;
41
+ close(): Promise<void>;
42
+ }
43
+ /** Audio context state. */
44
+ type AudioState = 'uninitialized' | 'running' | 'suspended' | 'closed';
45
+ /**
46
+ * AudioManager — manages the AudioContext lifecycle.
47
+ * Wraps react-native-audio-api's AudioContext.
48
+ */
49
+ declare class AudioManager {
50
+ private ctx;
51
+ private factory;
52
+ /** Current audio state. */
53
+ get state(): AudioState;
54
+ /** The underlying AudioContext, or null if not initialized. */
55
+ get context(): AudioContextLike | null;
56
+ /** Current time from the AudioContext. */
57
+ get currentTime(): number;
58
+ /** Initialize with a factory that creates the native AudioContext. */
59
+ init(factory: () => AudioContextLike): void;
60
+ /** Suspend audio (e.g. on app background). */
61
+ suspend(): Promise<void>;
62
+ /** Resume audio (e.g. on app foreground). */
63
+ resume(): Promise<void>;
64
+ /** Close and dispose the AudioContext. */
65
+ close(): Promise<void>;
66
+ }
67
+
68
+ /** A volume channel that wraps a GainNode. */
69
+ interface Channel {
70
+ readonly name: string;
71
+ /** Current volume (0.0 - 1.0). */
72
+ volume: number;
73
+ /** The underlying GainNode. */
74
+ readonly node: GainNodeLike;
75
+ }
76
+ /** Standard channel names. */
77
+ type ChannelName = 'master' | 'sfx' | 'music';
78
+ /**
79
+ * Creates volume channels connected: sfx → master, music → master, master → destination.
80
+ * Returns a map of channels by name.
81
+ */
82
+ declare function createChannels(ctx: AudioContextLike): Map<ChannelName, Channel>;
83
+
84
+ /** Options for playing a sound effect. */
85
+ interface PlaySFXOptions {
86
+ /** Playback volume (0-1). Default: 1. */
87
+ volume?: number;
88
+ /** Playback rate. Default: 1. */
89
+ rate?: number;
90
+ /** Whether to loop. Default: false. */
91
+ loop?: boolean;
92
+ }
93
+ /** A handle to a playing SFX instance. */
94
+ interface SFXHandle {
95
+ /** Stop playback. */
96
+ stop(): void;
97
+ }
98
+ /**
99
+ * SFX pool — pre-decoded audio buffers with polyphony management.
100
+ * When max polyphony is reached, the oldest sound is killed.
101
+ */
102
+ declare class SFXPool {
103
+ private buffers;
104
+ private active;
105
+ private ctx;
106
+ private output;
107
+ private maxPolyphony;
108
+ constructor(maxPolyphony?: number);
109
+ /** Connect to an AudioContext and output GainNode. */
110
+ connect(ctx: AudioContextLike, output: GainNodeLike): void;
111
+ /** Register a pre-decoded audio buffer. */
112
+ register(name: string, buffer: AudioBufferLike): void;
113
+ /** Unregister a buffer. */
114
+ unregister(name: string): void;
115
+ /** Check if a buffer is registered. */
116
+ has(name: string): boolean;
117
+ /** Number of registered buffers. */
118
+ get size(): number;
119
+ /** Number of currently active sounds. */
120
+ get activeCount(): number;
121
+ /** Play a registered sound. Returns a handle, or null if not registered/no context. */
122
+ play(name: string, opts?: PlaySFXOptions): SFXHandle | null;
123
+ /** Stop all active sounds. */
124
+ stopAll(): void;
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;
154
+ }
155
+
156
+ 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 };
package/dist/index.js ADDED
@@ -0,0 +1,307 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ AudioManager: () => AudioManager,
24
+ Music: () => Music,
25
+ SFXPool: () => SFXPool,
26
+ createChannels: () => createChannels
27
+ });
28
+ module.exports = __toCommonJS(index_exports);
29
+
30
+ // src/audio-manager.ts
31
+ var AudioManager = class {
32
+ ctx = null;
33
+ factory = null;
34
+ /** Current audio state. */
35
+ get state() {
36
+ if (!this.ctx) return "uninitialized";
37
+ return this.ctx.state === "closed" ? "closed" : this.ctx.state;
38
+ }
39
+ /** The underlying AudioContext, or null if not initialized. */
40
+ get context() {
41
+ return this.ctx;
42
+ }
43
+ /** Current time from the AudioContext. */
44
+ get currentTime() {
45
+ return this.ctx?.currentTime ?? 0;
46
+ }
47
+ /** Initialize with a factory that creates the native AudioContext. */
48
+ init(factory) {
49
+ if (this.ctx) return;
50
+ this.factory = factory;
51
+ this.ctx = factory();
52
+ }
53
+ /** Suspend audio (e.g. on app background). */
54
+ async suspend() {
55
+ if (this.ctx?.state === "running") {
56
+ await this.ctx.suspend();
57
+ }
58
+ }
59
+ /** Resume audio (e.g. on app foreground). */
60
+ async resume() {
61
+ if (this.ctx?.state === "suspended") {
62
+ await this.ctx.resume();
63
+ }
64
+ }
65
+ /** Close and dispose the AudioContext. */
66
+ async close() {
67
+ if (this.ctx) {
68
+ await this.ctx.close();
69
+ this.ctx = null;
70
+ }
71
+ }
72
+ };
73
+
74
+ // src/channels.ts
75
+ function createChannels(ctx) {
76
+ const masterGain = ctx.createGain();
77
+ masterGain.gain.value = 1;
78
+ masterGain.connect(ctx.destination);
79
+ const sfxGain = ctx.createGain();
80
+ sfxGain.gain.value = 1;
81
+ sfxGain.connect(masterGain);
82
+ const musicGain = ctx.createGain();
83
+ musicGain.gain.value = 1;
84
+ musicGain.connect(masterGain);
85
+ const channels = /* @__PURE__ */ new Map();
86
+ channels.set("master", createChannel("master", masterGain));
87
+ channels.set("sfx", createChannel("sfx", sfxGain));
88
+ channels.set("music", createChannel("music", musicGain));
89
+ return channels;
90
+ }
91
+ function createChannel(name, node) {
92
+ let vol = 1;
93
+ return {
94
+ name,
95
+ get volume() {
96
+ return vol;
97
+ },
98
+ set volume(v) {
99
+ vol = Math.max(0, Math.min(1, v));
100
+ node.gain.value = vol;
101
+ },
102
+ node
103
+ };
104
+ }
105
+
106
+ // src/sfx-pool.ts
107
+ var SFXPool = class {
108
+ buffers = /* @__PURE__ */ new Map();
109
+ active = [];
110
+ ctx = null;
111
+ output = null;
112
+ maxPolyphony;
113
+ constructor(maxPolyphony = 16) {
114
+ this.maxPolyphony = maxPolyphony;
115
+ }
116
+ /** Connect to an AudioContext and output GainNode. */
117
+ connect(ctx, output) {
118
+ this.ctx = ctx;
119
+ this.output = output;
120
+ }
121
+ /** Register a pre-decoded audio buffer. */
122
+ register(name, buffer) {
123
+ this.buffers.set(name, buffer);
124
+ }
125
+ /** Unregister a buffer. */
126
+ unregister(name) {
127
+ this.buffers.delete(name);
128
+ }
129
+ /** Check if a buffer is registered. */
130
+ has(name) {
131
+ return this.buffers.has(name);
132
+ }
133
+ /** Number of registered buffers. */
134
+ get size() {
135
+ return this.buffers.size;
136
+ }
137
+ /** Number of currently active sounds. */
138
+ get activeCount() {
139
+ return this.active.length;
140
+ }
141
+ /** Play a registered sound. Returns a handle, or null if not registered/no context. */
142
+ play(name, opts) {
143
+ const buffer = this.buffers.get(name);
144
+ if (!buffer || !this.ctx || !this.output) return null;
145
+ while (this.active.length >= this.maxPolyphony) {
146
+ const oldest = this.active.shift();
147
+ oldest?.stop();
148
+ }
149
+ const source = this.ctx.createBufferSource();
150
+ source.buffer = buffer;
151
+ source.loop = opts?.loop ?? false;
152
+ const gain = this.ctx.createGain();
153
+ gain.gain.value = opts?.volume ?? 1;
154
+ source.connect(gain);
155
+ gain.connect(this.output);
156
+ const entry = {
157
+ name,
158
+ stop() {
159
+ try {
160
+ source.stop();
161
+ } catch {
162
+ }
163
+ gain.disconnect();
164
+ }
165
+ };
166
+ this.active.push(entry);
167
+ source.onended = () => {
168
+ const idx = this.active.indexOf(entry);
169
+ if (idx !== -1) {
170
+ this.active.splice(idx, 1);
171
+ }
172
+ gain.disconnect();
173
+ };
174
+ source.start();
175
+ return {
176
+ stop: () => {
177
+ entry.stop();
178
+ const idx = this.active.indexOf(entry);
179
+ if (idx !== -1) {
180
+ this.active.splice(idx, 1);
181
+ }
182
+ }
183
+ };
184
+ }
185
+ /** Stop all active sounds. */
186
+ stopAll() {
187
+ for (const entry of this.active) {
188
+ entry.stop();
189
+ }
190
+ this.active.length = 0;
191
+ }
192
+ };
193
+
194
+ // src/music.ts
195
+ var Music = class {
196
+ ctx = null;
197
+ output = null;
198
+ buffers = /* @__PURE__ */ new Map();
199
+ currentSource = null;
200
+ currentGain = null;
201
+ currentName = null;
202
+ /** Name of the currently playing track, or null. */
203
+ get playing() {
204
+ return this.currentName;
205
+ }
206
+ /** Connect to an AudioContext and output gain node. */
207
+ connect(ctx, output) {
208
+ this.ctx = ctx;
209
+ this.output = output;
210
+ }
211
+ /** Register a music track buffer. */
212
+ register(name, buffer) {
213
+ this.buffers.set(name, buffer);
214
+ }
215
+ /** Play a track. Stops any currently playing track. Loops by default. */
216
+ play(name, loop = true) {
217
+ if (!this.ctx || !this.output) return;
218
+ const buffer = this.buffers.get(name);
219
+ if (!buffer) return;
220
+ this.stopInternal();
221
+ const source = this.ctx.createBufferSource();
222
+ source.buffer = buffer;
223
+ source.loop = loop;
224
+ const gain = this.ctx.createGain();
225
+ gain.gain.value = 1;
226
+ source.connect(gain);
227
+ gain.connect(this.output);
228
+ source.start();
229
+ this.currentSource = source;
230
+ this.currentGain = gain;
231
+ this.currentName = name;
232
+ source.onended = () => {
233
+ if (this.currentSource === source) {
234
+ this.currentSource = null;
235
+ this.currentGain = null;
236
+ this.currentName = null;
237
+ }
238
+ gain.disconnect();
239
+ };
240
+ }
241
+ /** Stop the current track. */
242
+ stop() {
243
+ this.stopInternal();
244
+ }
245
+ /**
246
+ * Crossfade to another track over duration seconds.
247
+ * Fades out current and fades in the new track simultaneously.
248
+ */
249
+ crossfadeTo(name, duration, loop = true) {
250
+ if (!this.ctx || !this.output) return;
251
+ const buffer = this.buffers.get(name);
252
+ if (!buffer) return;
253
+ const now = this.ctx.currentTime;
254
+ if (this.currentGain && this.currentSource) {
255
+ const oldGain = this.currentGain;
256
+ const oldSource = this.currentSource;
257
+ oldGain.gain.setValueAtTime(oldGain.gain.value, now);
258
+ oldGain.gain.linearRampToValueAtTime(0, now + duration);
259
+ try {
260
+ oldSource.stop(now + duration);
261
+ } catch {
262
+ }
263
+ }
264
+ const source = this.ctx.createBufferSource();
265
+ source.buffer = buffer;
266
+ source.loop = loop;
267
+ const gain = this.ctx.createGain();
268
+ gain.gain.setValueAtTime(0, now);
269
+ gain.gain.linearRampToValueAtTime(1, now + duration);
270
+ source.connect(gain);
271
+ gain.connect(this.output);
272
+ source.start();
273
+ this.currentSource = source;
274
+ this.currentGain = gain;
275
+ this.currentName = name;
276
+ source.onended = () => {
277
+ if (this.currentSource === source) {
278
+ this.currentSource = null;
279
+ this.currentGain = null;
280
+ this.currentName = null;
281
+ }
282
+ gain.disconnect();
283
+ };
284
+ }
285
+ stopInternal() {
286
+ if (this.currentSource) {
287
+ try {
288
+ this.currentSource.stop();
289
+ } catch {
290
+ }
291
+ }
292
+ if (this.currentGain) {
293
+ this.currentGain.disconnect();
294
+ }
295
+ this.currentSource = null;
296
+ this.currentGain = null;
297
+ this.currentName = null;
298
+ }
299
+ };
300
+ // Annotate the CommonJS export names for ESM import in node:
301
+ 0 && (module.exports = {
302
+ AudioManager,
303
+ Music,
304
+ SFXPool,
305
+ createChannels
306
+ });
307
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts","../src/audio-manager.ts","../src/channels.ts","../src/sfx-pool.ts","../src/music.ts"],"sourcesContent":["export {\n type AudioContextLike,\n type AudioBufferLike,\n type AudioBufferSourceNodeLike,\n type AudioDestinationNodeLike,\n type AudioParamLike,\n type GainNodeLike,\n type AudioState,\n AudioManager,\n} from './audio-manager.js';\n\nexport { type Channel, type ChannelName, createChannels } from './channels.js';\n\nexport { type PlaySFXOptions, type SFXHandle, SFXPool } from './sfx-pool.js';\n\nexport { Music } from './music.js';\n","/**\n * Minimal interfaces for the Web Audio API subset we use.\n * At runtime these are provided by react-native-audio-api.\n */\n\nexport interface AudioDestinationNodeLike {\n readonly channelCount: number;\n}\n\nexport interface GainNodeLike {\n readonly gain: AudioParamLike;\n connect(dest: AudioDestinationNodeLike | GainNodeLike): void;\n disconnect(): void;\n}\n\nexport interface AudioParamLike {\n value: number;\n setValueAtTime(value: number, time: number): void;\n linearRampToValueAtTime(value: number, time: number): void;\n}\n\nexport interface AudioBufferLike {\n readonly duration: number;\n readonly numberOfChannels: number;\n readonly sampleRate: number;\n readonly length: number;\n}\n\nexport interface AudioBufferSourceNodeLike {\n buffer: AudioBufferLike | null;\n loop: boolean;\n connect(dest: GainNodeLike | AudioDestinationNodeLike): void;\n disconnect(): void;\n start(when?: number): void;\n stop(when?: number): void;\n readonly onended: ((this: AudioBufferSourceNodeLike, ev: unknown) => void) | null;\n}\n\nexport interface AudioContextLike {\n readonly state: 'suspended' | 'running' | 'closed';\n readonly currentTime: number;\n readonly destination: AudioDestinationNodeLike;\n createGain(): GainNodeLike;\n createBufferSource(): AudioBufferSourceNodeLike;\n resume(): Promise<void>;\n suspend(): Promise<void>;\n close(): Promise<void>;\n}\n\n/** Audio context state. */\nexport type AudioState = 'uninitialized' | 'running' | 'suspended' | 'closed';\n\n/**\n * AudioManager — manages the AudioContext lifecycle.\n * Wraps react-native-audio-api's AudioContext.\n */\nexport class AudioManager {\n private ctx: AudioContextLike | null = null;\n private factory: (() => AudioContextLike) | null = null;\n\n /** Current audio state. */\n get state(): AudioState {\n if (!this.ctx) return 'uninitialized';\n return this.ctx.state === 'closed' ? 'closed' : this.ctx.state;\n }\n\n /** The underlying AudioContext, or null if not initialized. */\n get context(): AudioContextLike | null {\n return this.ctx;\n }\n\n /** Current time from the AudioContext. */\n get currentTime(): number {\n return this.ctx?.currentTime ?? 0;\n }\n\n /** Initialize with a factory that creates the native AudioContext. */\n init(factory: () => AudioContextLike): void {\n if (this.ctx) return;\n this.factory = factory;\n this.ctx = factory();\n }\n\n /** Suspend audio (e.g. on app background). */\n async suspend(): Promise<void> {\n if (this.ctx?.state === 'running') {\n await this.ctx.suspend();\n }\n }\n\n /** Resume audio (e.g. on app foreground). */\n async resume(): Promise<void> {\n if (this.ctx?.state === 'suspended') {\n await this.ctx.resume();\n }\n }\n\n /** Close and dispose the AudioContext. */\n async close(): Promise<void> {\n if (this.ctx) {\n await this.ctx.close();\n this.ctx = null;\n }\n }\n}\n","import type { AudioContextLike, GainNodeLike } from './audio-manager.js';\n\n/** A volume channel that wraps a GainNode. */\nexport interface Channel {\n readonly name: string;\n /** Current volume (0.0 - 1.0). */\n volume: number;\n /** The underlying GainNode. */\n readonly node: GainNodeLike;\n}\n\n/** Standard channel names. */\nexport type ChannelName = 'master' | 'sfx' | 'music';\n\n/**\n * Creates volume channels connected: sfx → master, music → master, master → destination.\n * Returns a map of channels by name.\n */\nexport function createChannels(ctx: AudioContextLike): Map<ChannelName, Channel> {\n const masterGain = ctx.createGain();\n masterGain.gain.value = 1;\n masterGain.connect(ctx.destination);\n\n const sfxGain = ctx.createGain();\n sfxGain.gain.value = 1;\n sfxGain.connect(masterGain);\n\n const musicGain = ctx.createGain();\n musicGain.gain.value = 1;\n musicGain.connect(masterGain);\n\n const channels = new Map<ChannelName, Channel>();\n\n channels.set('master', createChannel('master', masterGain));\n channels.set('sfx', createChannel('sfx', sfxGain));\n channels.set('music', createChannel('music', musicGain));\n\n return channels;\n}\n\nfunction createChannel(name: string, node: GainNodeLike): Channel {\n let vol = 1;\n return {\n name,\n get volume() {\n return vol;\n },\n set volume(v: number) {\n vol = Math.max(0, Math.min(1, v));\n node.gain.value = vol;\n },\n node,\n };\n}\n","import type { AudioBufferLike, AudioContextLike, GainNodeLike } from './audio-manager.js';\n\n/** Options for playing a sound effect. */\nexport interface PlaySFXOptions {\n /** Playback volume (0-1). Default: 1. */\n volume?: number;\n /** Playback rate. Default: 1. */\n rate?: number;\n /** Whether to loop. Default: false. */\n loop?: boolean;\n}\n\n/** A handle to a playing SFX instance. */\nexport interface SFXHandle {\n /** Stop playback. */\n stop(): void;\n}\n\n/** Tracks an active playing source. */\ninterface ActiveSource {\n name: string;\n stop(): void;\n}\n\n/**\n * SFX pool — pre-decoded audio buffers with polyphony management.\n * When max polyphony is reached, the oldest sound is killed.\n */\nexport class SFXPool {\n private buffers = new Map<string, AudioBufferLike>();\n private active: ActiveSource[] = [];\n private ctx: AudioContextLike | null = null;\n private output: GainNodeLike | null = null;\n private maxPolyphony: number;\n\n constructor(maxPolyphony = 16) {\n this.maxPolyphony = maxPolyphony;\n }\n\n /** Connect to an AudioContext and output GainNode. */\n connect(ctx: AudioContextLike, output: GainNodeLike): void {\n this.ctx = ctx;\n this.output = output;\n }\n\n /** Register a pre-decoded audio buffer. */\n register(name: string, buffer: AudioBufferLike): void {\n this.buffers.set(name, buffer);\n }\n\n /** Unregister a buffer. */\n unregister(name: string): void {\n this.buffers.delete(name);\n }\n\n /** Check if a buffer is registered. */\n has(name: string): boolean {\n return this.buffers.has(name);\n }\n\n /** Number of registered buffers. */\n get size(): number {\n return this.buffers.size;\n }\n\n /** Number of currently active sounds. */\n get activeCount(): number {\n return this.active.length;\n }\n\n /** Play a registered sound. Returns a handle, or null if not registered/no context. */\n play(name: string, opts?: PlaySFXOptions): SFXHandle | null {\n const buffer = this.buffers.get(name);\n if (!buffer || !this.ctx || !this.output) return null;\n\n // Kill oldest if at max polyphony\n while (this.active.length >= this.maxPolyphony) {\n const oldest = this.active.shift();\n oldest?.stop();\n }\n\n const source = this.ctx.createBufferSource();\n source.buffer = buffer;\n source.loop = opts?.loop ?? false;\n\n // Create a per-source gain for volume control\n const gain = this.ctx.createGain();\n gain.gain.value = opts?.volume ?? 1;\n source.connect(gain);\n gain.connect(this.output);\n\n const entry: ActiveSource = {\n name,\n stop() {\n try {\n source.stop();\n } catch {\n // Already stopped\n }\n gain.disconnect();\n },\n };\n\n this.active.push(entry);\n\n // Clean up when playback ends\n (source as { onended: (() => void) | null }).onended = () => {\n const idx = this.active.indexOf(entry);\n if (idx !== -1) {\n this.active.splice(idx, 1);\n }\n gain.disconnect();\n };\n\n source.start();\n\n return {\n stop: () => {\n entry.stop();\n const idx = this.active.indexOf(entry);\n if (idx !== -1) {\n this.active.splice(idx, 1);\n }\n },\n };\n }\n\n /** Stop all active sounds. */\n stopAll(): void {\n for (const entry of this.active) {\n entry.stop();\n }\n this.active.length = 0;\n }\n}\n","import type {\n AudioBufferLike,\n AudioBufferSourceNodeLike,\n AudioContextLike,\n GainNodeLike,\n} from './audio-manager.js';\n\n/**\n * Music player — one track at a time, with crossfade support.\n * Loops by default.\n */\nexport class Music {\n private ctx: AudioContextLike | null = null;\n private output: GainNodeLike | null = null;\n private buffers = new Map<string, AudioBufferLike>();\n private currentSource: AudioBufferSourceNodeLike | null = null;\n private currentGain: GainNodeLike | null = null;\n private currentName: string | null = null;\n\n /** Name of the currently playing track, or null. */\n get playing(): string | null {\n return this.currentName;\n }\n\n /** Connect to an AudioContext and output gain node. */\n connect(ctx: AudioContextLike, output: GainNodeLike): void {\n this.ctx = ctx;\n this.output = output;\n }\n\n /** Register a music track buffer. */\n register(name: string, buffer: AudioBufferLike): void {\n this.buffers.set(name, buffer);\n }\n\n /** Play a track. Stops any currently playing track. Loops by default. */\n play(name: string, loop = true): void {\n if (!this.ctx || !this.output) return;\n const buffer = this.buffers.get(name);\n if (!buffer) return;\n\n this.stopInternal();\n\n const source = this.ctx.createBufferSource();\n source.buffer = buffer;\n source.loop = loop;\n\n const gain = this.ctx.createGain();\n gain.gain.value = 1;\n source.connect(gain);\n gain.connect(this.output);\n\n source.start();\n this.currentSource = source;\n this.currentGain = gain;\n this.currentName = name;\n\n (source as { onended: (() => void) | null }).onended = () => {\n if (this.currentSource === source) {\n this.currentSource = null;\n this.currentGain = null;\n this.currentName = null;\n }\n gain.disconnect();\n };\n }\n\n /** Stop the current track. */\n stop(): void {\n this.stopInternal();\n }\n\n /**\n * Crossfade to another track over duration seconds.\n * Fades out current and fades in the new track simultaneously.\n */\n crossfadeTo(name: string, duration: number, loop = true): void {\n if (!this.ctx || !this.output) return;\n const buffer = this.buffers.get(name);\n if (!buffer) return;\n\n const now = this.ctx.currentTime;\n\n // Fade out current\n if (this.currentGain && this.currentSource) {\n const oldGain = this.currentGain;\n const oldSource = this.currentSource;\n oldGain.gain.setValueAtTime(oldGain.gain.value, now);\n oldGain.gain.linearRampToValueAtTime(0, now + duration);\n // Schedule stop after fade\n try {\n oldSource.stop(now + duration);\n } catch {\n // Already stopped\n }\n }\n\n // Start new track fading in\n const source = this.ctx.createBufferSource();\n source.buffer = buffer;\n source.loop = loop;\n\n const gain = this.ctx.createGain();\n gain.gain.setValueAtTime(0, now);\n gain.gain.linearRampToValueAtTime(1, now + duration);\n source.connect(gain);\n gain.connect(this.output);\n\n source.start();\n this.currentSource = source;\n this.currentGain = gain;\n this.currentName = name;\n\n (source as { onended: (() => void) | null }).onended = () => {\n if (this.currentSource === source) {\n this.currentSource = null;\n this.currentGain = null;\n this.currentName = null;\n }\n gain.disconnect();\n };\n }\n\n private stopInternal(): void {\n if (this.currentSource) {\n try {\n this.currentSource.stop();\n } catch {\n // Already stopped\n }\n }\n if (this.currentGain) {\n this.currentGain.disconnect();\n }\n this.currentSource = null;\n this.currentGain = null;\n this.currentName = null;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACwDO,IAAM,eAAN,MAAmB;AAAA,EAChB,MAA+B;AAAA,EAC/B,UAA2C;AAAA;AAAA,EAGnD,IAAI,QAAoB;AACtB,QAAI,CAAC,KAAK,IAAK,QAAO;AACtB,WAAO,KAAK,IAAI,UAAU,WAAW,WAAW,KAAK,IAAI;AAAA,EAC3D;AAAA;AAAA,EAGA,IAAI,UAAmC;AACrC,WAAO,KAAK;AAAA,EACd;AAAA;AAAA,EAGA,IAAI,cAA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AAK,MAAM;AAExB,WAAO,MAAM;AACb,SAAK,gBAAgB;AACrB,SAAK,cAAc;AACnB,SAAK,cAAc;AAEnB,IAAC,OAA4C,UAAU,MAAM;AAC3D,UAAI,KAAK,kBAAkB,QAAQ;AACjC,aAAK,gBAAgB;AACrB,aAAK,cAAc;AACnB,aAAK,cAAc;AAAA,MACrB;AACA,WAAK,WAAW;AAAA,IAClB;AAAA,EACF;AAAA,EAEQ,eAAqB;AAC3B,QAAI,KAAK,eAAe;AACtB,UAAI;AACF,aAAK,cAAc,KAAK;AAAA,MAC1B,QAAQ;AAAA,MAER;AAAA,IACF;AACA,QAAI,KAAK,aAAa;AACpB,WAAK,YAAY,WAAW;AAAA,IAC9B;AACA,SAAK,gBAAgB;AACrB,SAAK,cAAc;AACnB,SAAK,cAAc;AAAA,EACrB;AACF;","names":[]}
package/dist/index.mjs ADDED
@@ -0,0 +1,277 @@
1
+ // src/audio-manager.ts
2
+ var AudioManager = class {
3
+ ctx = null;
4
+ factory = null;
5
+ /** Current audio state. */
6
+ get state() {
7
+ if (!this.ctx) return "uninitialized";
8
+ return this.ctx.state === "closed" ? "closed" : this.ctx.state;
9
+ }
10
+ /** The underlying AudioContext, or null if not initialized. */
11
+ get context() {
12
+ return this.ctx;
13
+ }
14
+ /** Current time from the AudioContext. */
15
+ get currentTime() {
16
+ return this.ctx?.currentTime ?? 0;
17
+ }
18
+ /** Initialize with a factory that creates the native AudioContext. */
19
+ init(factory) {
20
+ if (this.ctx) return;
21
+ this.factory = factory;
22
+ this.ctx = factory();
23
+ }
24
+ /** Suspend audio (e.g. on app background). */
25
+ async suspend() {
26
+ if (this.ctx?.state === "running") {
27
+ await this.ctx.suspend();
28
+ }
29
+ }
30
+ /** Resume audio (e.g. on app foreground). */
31
+ async resume() {
32
+ if (this.ctx?.state === "suspended") {
33
+ await this.ctx.resume();
34
+ }
35
+ }
36
+ /** Close and dispose the AudioContext. */
37
+ async close() {
38
+ if (this.ctx) {
39
+ await this.ctx.close();
40
+ this.ctx = null;
41
+ }
42
+ }
43
+ };
44
+
45
+ // src/channels.ts
46
+ function createChannels(ctx) {
47
+ const masterGain = ctx.createGain();
48
+ masterGain.gain.value = 1;
49
+ masterGain.connect(ctx.destination);
50
+ const sfxGain = ctx.createGain();
51
+ sfxGain.gain.value = 1;
52
+ sfxGain.connect(masterGain);
53
+ const musicGain = ctx.createGain();
54
+ musicGain.gain.value = 1;
55
+ musicGain.connect(masterGain);
56
+ const channels = /* @__PURE__ */ new Map();
57
+ channels.set("master", createChannel("master", masterGain));
58
+ channels.set("sfx", createChannel("sfx", sfxGain));
59
+ channels.set("music", createChannel("music", musicGain));
60
+ return channels;
61
+ }
62
+ function createChannel(name, node) {
63
+ let vol = 1;
64
+ return {
65
+ name,
66
+ get volume() {
67
+ return vol;
68
+ },
69
+ set volume(v) {
70
+ vol = Math.max(0, Math.min(1, v));
71
+ node.gain.value = vol;
72
+ },
73
+ node
74
+ };
75
+ }
76
+
77
+ // src/sfx-pool.ts
78
+ var SFXPool = class {
79
+ buffers = /* @__PURE__ */ new Map();
80
+ active = [];
81
+ ctx = null;
82
+ output = null;
83
+ maxPolyphony;
84
+ constructor(maxPolyphony = 16) {
85
+ this.maxPolyphony = maxPolyphony;
86
+ }
87
+ /** Connect to an AudioContext and output GainNode. */
88
+ connect(ctx, output) {
89
+ this.ctx = ctx;
90
+ this.output = output;
91
+ }
92
+ /** Register a pre-decoded audio buffer. */
93
+ register(name, buffer) {
94
+ this.buffers.set(name, buffer);
95
+ }
96
+ /** Unregister a buffer. */
97
+ unregister(name) {
98
+ this.buffers.delete(name);
99
+ }
100
+ /** Check if a buffer is registered. */
101
+ has(name) {
102
+ return this.buffers.has(name);
103
+ }
104
+ /** Number of registered buffers. */
105
+ get size() {
106
+ return this.buffers.size;
107
+ }
108
+ /** Number of currently active sounds. */
109
+ get activeCount() {
110
+ return this.active.length;
111
+ }
112
+ /** Play a registered sound. Returns a handle, or null if not registered/no context. */
113
+ play(name, opts) {
114
+ const buffer = this.buffers.get(name);
115
+ if (!buffer || !this.ctx || !this.output) return null;
116
+ while (this.active.length >= this.maxPolyphony) {
117
+ const oldest = this.active.shift();
118
+ oldest?.stop();
119
+ }
120
+ const source = this.ctx.createBufferSource();
121
+ source.buffer = buffer;
122
+ source.loop = opts?.loop ?? false;
123
+ const gain = this.ctx.createGain();
124
+ gain.gain.value = opts?.volume ?? 1;
125
+ source.connect(gain);
126
+ gain.connect(this.output);
127
+ const entry = {
128
+ name,
129
+ stop() {
130
+ try {
131
+ source.stop();
132
+ } catch {
133
+ }
134
+ gain.disconnect();
135
+ }
136
+ };
137
+ this.active.push(entry);
138
+ source.onended = () => {
139
+ const idx = this.active.indexOf(entry);
140
+ if (idx !== -1) {
141
+ this.active.splice(idx, 1);
142
+ }
143
+ gain.disconnect();
144
+ };
145
+ source.start();
146
+ return {
147
+ stop: () => {
148
+ entry.stop();
149
+ const idx = this.active.indexOf(entry);
150
+ if (idx !== -1) {
151
+ this.active.splice(idx, 1);
152
+ }
153
+ }
154
+ };
155
+ }
156
+ /** Stop all active sounds. */
157
+ stopAll() {
158
+ for (const entry of this.active) {
159
+ entry.stop();
160
+ }
161
+ this.active.length = 0;
162
+ }
163
+ };
164
+
165
+ // src/music.ts
166
+ var Music = class {
167
+ ctx = null;
168
+ output = null;
169
+ buffers = /* @__PURE__ */ new Map();
170
+ currentSource = null;
171
+ currentGain = null;
172
+ currentName = null;
173
+ /** Name of the currently playing track, or null. */
174
+ get playing() {
175
+ return this.currentName;
176
+ }
177
+ /** Connect to an AudioContext and output gain node. */
178
+ connect(ctx, output) {
179
+ this.ctx = ctx;
180
+ this.output = output;
181
+ }
182
+ /** Register a music track buffer. */
183
+ register(name, buffer) {
184
+ this.buffers.set(name, buffer);
185
+ }
186
+ /** Play a track. Stops any currently playing track. Loops by default. */
187
+ play(name, loop = true) {
188
+ if (!this.ctx || !this.output) return;
189
+ const buffer = this.buffers.get(name);
190
+ if (!buffer) return;
191
+ this.stopInternal();
192
+ const source = this.ctx.createBufferSource();
193
+ source.buffer = buffer;
194
+ source.loop = loop;
195
+ const gain = this.ctx.createGain();
196
+ gain.gain.value = 1;
197
+ source.connect(gain);
198
+ gain.connect(this.output);
199
+ source.start();
200
+ this.currentSource = source;
201
+ this.currentGain = gain;
202
+ this.currentName = name;
203
+ source.onended = () => {
204
+ if (this.currentSource === source) {
205
+ this.currentSource = null;
206
+ this.currentGain = null;
207
+ this.currentName = null;
208
+ }
209
+ gain.disconnect();
210
+ };
211
+ }
212
+ /** Stop the current track. */
213
+ stop() {
214
+ this.stopInternal();
215
+ }
216
+ /**
217
+ * Crossfade to another track over duration seconds.
218
+ * Fades out current and fades in the new track simultaneously.
219
+ */
220
+ crossfadeTo(name, duration, loop = true) {
221
+ if (!this.ctx || !this.output) return;
222
+ const buffer = this.buffers.get(name);
223
+ if (!buffer) return;
224
+ const now = this.ctx.currentTime;
225
+ if (this.currentGain && this.currentSource) {
226
+ const oldGain = this.currentGain;
227
+ const oldSource = this.currentSource;
228
+ oldGain.gain.setValueAtTime(oldGain.gain.value, now);
229
+ oldGain.gain.linearRampToValueAtTime(0, now + duration);
230
+ try {
231
+ oldSource.stop(now + duration);
232
+ } catch {
233
+ }
234
+ }
235
+ const source = this.ctx.createBufferSource();
236
+ source.buffer = buffer;
237
+ source.loop = loop;
238
+ const gain = this.ctx.createGain();
239
+ gain.gain.setValueAtTime(0, now);
240
+ gain.gain.linearRampToValueAtTime(1, now + duration);
241
+ source.connect(gain);
242
+ gain.connect(this.output);
243
+ source.start();
244
+ this.currentSource = source;
245
+ this.currentGain = gain;
246
+ this.currentName = name;
247
+ source.onended = () => {
248
+ if (this.currentSource === source) {
249
+ this.currentSource = null;
250
+ this.currentGain = null;
251
+ this.currentName = null;
252
+ }
253
+ gain.disconnect();
254
+ };
255
+ }
256
+ stopInternal() {
257
+ if (this.currentSource) {
258
+ try {
259
+ this.currentSource.stop();
260
+ } catch {
261
+ }
262
+ }
263
+ if (this.currentGain) {
264
+ this.currentGain.disconnect();
265
+ }
266
+ this.currentSource = null;
267
+ this.currentGain = null;
268
+ this.currentName = null;
269
+ }
270
+ };
271
+ export {
272
+ AudioManager,
273
+ Music,
274
+ SFXPool,
275
+ createChannels
276
+ };
277
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/audio-manager.ts","../src/channels.ts","../src/sfx-pool.ts","../src/music.ts"],"sourcesContent":["/**\n * Minimal interfaces for the Web Audio API subset we use.\n * At runtime these are provided by react-native-audio-api.\n */\n\nexport interface AudioDestinationNodeLike {\n readonly channelCount: number;\n}\n\nexport interface GainNodeLike {\n readonly gain: AudioParamLike;\n connect(dest: AudioDestinationNodeLike | GainNodeLike): void;\n disconnect(): void;\n}\n\nexport interface AudioParamLike {\n value: number;\n setValueAtTime(value: number, time: number): void;\n linearRampToValueAtTime(value: number, time: number): void;\n}\n\nexport interface AudioBufferLike {\n readonly duration: number;\n readonly numberOfChannels: number;\n readonly sampleRate: number;\n readonly length: number;\n}\n\nexport interface AudioBufferSourceNodeLike {\n buffer: AudioBufferLike | null;\n loop: boolean;\n connect(dest: GainNodeLike | AudioDestinationNodeLike): void;\n disconnect(): void;\n start(when?: number): void;\n stop(when?: number): void;\n readonly onended: ((this: AudioBufferSourceNodeLike, ev: unknown) => void) | null;\n}\n\nexport interface AudioContextLike {\n readonly state: 'suspended' | 'running' | 'closed';\n readonly currentTime: number;\n readonly destination: AudioDestinationNodeLike;\n createGain(): GainNodeLike;\n createBufferSource(): AudioBufferSourceNodeLike;\n resume(): Promise<void>;\n suspend(): Promise<void>;\n close(): Promise<void>;\n}\n\n/** Audio context state. */\nexport type AudioState = 'uninitialized' | 'running' | 'suspended' | 'closed';\n\n/**\n * AudioManager — manages the AudioContext lifecycle.\n * Wraps react-native-audio-api's AudioContext.\n */\nexport class AudioManager {\n private ctx: AudioContextLike | null = null;\n private factory: (() => AudioContextLike) | null = null;\n\n /** Current audio state. */\n get state(): AudioState {\n if (!this.ctx) return 'uninitialized';\n return this.ctx.state === 'closed' ? 'closed' : this.ctx.state;\n }\n\n /** The underlying AudioContext, or null if not initialized. */\n get context(): AudioContextLike | null {\n return this.ctx;\n }\n\n /** Current time from the AudioContext. */\n get currentTime(): number {\n return this.ctx?.currentTime ?? 0;\n }\n\n /** Initialize with a factory that creates the native AudioContext. */\n init(factory: () => AudioContextLike): void {\n if (this.ctx) return;\n this.factory = factory;\n this.ctx = factory();\n }\n\n /** Suspend audio (e.g. on app background). */\n async suspend(): Promise<void> {\n if (this.ctx?.state === 'running') {\n await this.ctx.suspend();\n }\n }\n\n /** Resume audio (e.g. on app foreground). */\n async resume(): Promise<void> {\n if (this.ctx?.state === 'suspended') {\n await this.ctx.resume();\n }\n }\n\n /** Close and dispose the AudioContext. */\n async close(): Promise<void> {\n if (this.ctx) {\n await this.ctx.close();\n this.ctx = null;\n }\n }\n}\n","import type { AudioContextLike, GainNodeLike } from './audio-manager.js';\n\n/** A volume channel that wraps a GainNode. */\nexport interface Channel {\n readonly name: string;\n /** Current volume (0.0 - 1.0). */\n volume: number;\n /** The underlying GainNode. */\n readonly node: GainNodeLike;\n}\n\n/** Standard channel names. */\nexport type ChannelName = 'master' | 'sfx' | 'music';\n\n/**\n * Creates volume channels connected: sfx → master, music → master, master → destination.\n * Returns a map of channels by name.\n */\nexport function createChannels(ctx: AudioContextLike): Map<ChannelName, Channel> {\n const masterGain = ctx.createGain();\n masterGain.gain.value = 1;\n masterGain.connect(ctx.destination);\n\n const sfxGain = ctx.createGain();\n sfxGain.gain.value = 1;\n sfxGain.connect(masterGain);\n\n const musicGain = ctx.createGain();\n musicGain.gain.value = 1;\n musicGain.connect(masterGain);\n\n const channels = new Map<ChannelName, Channel>();\n\n channels.set('master', createChannel('master', masterGain));\n channels.set('sfx', createChannel('sfx', sfxGain));\n channels.set('music', createChannel('music', musicGain));\n\n return channels;\n}\n\nfunction createChannel(name: string, node: GainNodeLike): Channel {\n let vol = 1;\n return {\n name,\n get volume() {\n return vol;\n },\n set volume(v: number) {\n vol = Math.max(0, Math.min(1, v));\n node.gain.value = vol;\n },\n node,\n };\n}\n","import type { AudioBufferLike, AudioContextLike, GainNodeLike } from './audio-manager.js';\n\n/** Options for playing a sound effect. */\nexport interface PlaySFXOptions {\n /** Playback volume (0-1). Default: 1. */\n volume?: number;\n /** Playback rate. Default: 1. */\n rate?: number;\n /** Whether to loop. Default: false. */\n loop?: boolean;\n}\n\n/** A handle to a playing SFX instance. */\nexport interface SFXHandle {\n /** Stop playback. */\n stop(): void;\n}\n\n/** Tracks an active playing source. */\ninterface ActiveSource {\n name: string;\n stop(): void;\n}\n\n/**\n * SFX pool — pre-decoded audio buffers with polyphony management.\n * When max polyphony is reached, the oldest sound is killed.\n */\nexport class SFXPool {\n private buffers = new Map<string, AudioBufferLike>();\n private active: ActiveSource[] = [];\n private ctx: AudioContextLike | null = null;\n private output: GainNodeLike | null = null;\n private maxPolyphony: number;\n\n constructor(maxPolyphony = 16) {\n this.maxPolyphony = maxPolyphony;\n }\n\n /** Connect to an AudioContext and output GainNode. */\n connect(ctx: AudioContextLike, output: GainNodeLike): void {\n this.ctx = ctx;\n this.output = output;\n }\n\n /** Register a pre-decoded audio buffer. */\n register(name: string, buffer: AudioBufferLike): void {\n this.buffers.set(name, buffer);\n }\n\n /** Unregister a buffer. */\n unregister(name: string): void {\n this.buffers.delete(name);\n }\n\n /** Check if a buffer is registered. */\n has(name: string): boolean {\n return this.buffers.has(name);\n }\n\n /** Number of registered buffers. */\n get size(): number {\n return this.buffers.size;\n }\n\n /** Number of currently active sounds. */\n get activeCount(): number {\n return this.active.length;\n }\n\n /** Play a registered sound. Returns a handle, or null if not registered/no context. */\n play(name: string, opts?: PlaySFXOptions): SFXHandle | null {\n const buffer = this.buffers.get(name);\n if (!buffer || !this.ctx || !this.output) return null;\n\n // Kill oldest if at max polyphony\n while (this.active.length >= this.maxPolyphony) {\n const oldest = this.active.shift();\n oldest?.stop();\n }\n\n const source = this.ctx.createBufferSource();\n source.buffer = buffer;\n source.loop = opts?.loop ?? false;\n\n // Create a per-source gain for volume control\n const gain = this.ctx.createGain();\n gain.gain.value = opts?.volume ?? 1;\n source.connect(gain);\n gain.connect(this.output);\n\n const entry: ActiveSource = {\n name,\n stop() {\n try {\n source.stop();\n } catch {\n // Already stopped\n }\n gain.disconnect();\n },\n };\n\n this.active.push(entry);\n\n // Clean up when playback ends\n (source as { onended: (() => void) | null }).onended = () => {\n const idx = this.active.indexOf(entry);\n if (idx !== -1) {\n this.active.splice(idx, 1);\n }\n gain.disconnect();\n };\n\n source.start();\n\n return {\n stop: () => {\n entry.stop();\n const idx = this.active.indexOf(entry);\n if (idx !== -1) {\n this.active.splice(idx, 1);\n }\n },\n };\n }\n\n /** Stop all active sounds. */\n stopAll(): void {\n for (const entry of this.active) {\n entry.stop();\n }\n this.active.length = 0;\n }\n}\n","import type {\n AudioBufferLike,\n AudioBufferSourceNodeLike,\n AudioContextLike,\n GainNodeLike,\n} from './audio-manager.js';\n\n/**\n * Music player — one track at a time, with crossfade support.\n * Loops by default.\n */\nexport class Music {\n private ctx: AudioContextLike | null = null;\n private output: GainNodeLike | null = null;\n private buffers = new Map<string, AudioBufferLike>();\n private currentSource: AudioBufferSourceNodeLike | null = null;\n private currentGain: GainNodeLike | null = null;\n private currentName: string | null = null;\n\n /** Name of the currently playing track, or null. */\n get playing(): string | null {\n return this.currentName;\n }\n\n /** Connect to an AudioContext and output gain node. */\n connect(ctx: AudioContextLike, output: GainNodeLike): void {\n this.ctx = ctx;\n this.output = output;\n }\n\n /** Register a music track buffer. */\n register(name: string, buffer: AudioBufferLike): void {\n this.buffers.set(name, buffer);\n }\n\n /** Play a track. Stops any currently playing track. Loops by default. */\n play(name: string, loop = true): void {\n if (!this.ctx || !this.output) return;\n const buffer = this.buffers.get(name);\n if (!buffer) return;\n\n this.stopInternal();\n\n const source = this.ctx.createBufferSource();\n source.buffer = buffer;\n source.loop = loop;\n\n const gain = this.ctx.createGain();\n gain.gain.value = 1;\n source.connect(gain);\n gain.connect(this.output);\n\n source.start();\n this.currentSource = source;\n this.currentGain = gain;\n this.currentName = name;\n\n (source as { onended: (() => void) | null }).onended = () => {\n if (this.currentSource === source) {\n this.currentSource = null;\n this.currentGain = null;\n this.currentName = null;\n }\n gain.disconnect();\n };\n }\n\n /** Stop the current track. */\n stop(): void {\n this.stopInternal();\n }\n\n /**\n * Crossfade to another track over duration seconds.\n * Fades out current and fades in the new track simultaneously.\n */\n crossfadeTo(name: string, duration: number, loop = true): void {\n if (!this.ctx || !this.output) return;\n const buffer = this.buffers.get(name);\n if (!buffer) return;\n\n const now = this.ctx.currentTime;\n\n // Fade out current\n if (this.currentGain && this.currentSource) {\n const oldGain = this.currentGain;\n const oldSource = this.currentSource;\n oldGain.gain.setValueAtTime(oldGain.gain.value, now);\n oldGain.gain.linearRampToValueAtTime(0, now + duration);\n // Schedule stop after fade\n try {\n oldSource.stop(now + duration);\n } catch {\n // Already stopped\n }\n }\n\n // Start new track fading in\n const source = this.ctx.createBufferSource();\n source.buffer = buffer;\n source.loop = loop;\n\n const gain = this.ctx.createGain();\n gain.gain.setValueAtTime(0, now);\n gain.gain.linearRampToValueAtTime(1, now + duration);\n source.connect(gain);\n gain.connect(this.output);\n\n source.start();\n this.currentSource = source;\n this.currentGain = gain;\n this.currentName = name;\n\n (source as { onended: (() => void) | null }).onended = () => {\n if (this.currentSource === source) {\n this.currentSource = null;\n this.currentGain = null;\n this.currentName = null;\n }\n gain.disconnect();\n };\n }\n\n private stopInternal(): void {\n if (this.currentSource) {\n try {\n this.currentSource.stop();\n } catch {\n // Already stopped\n }\n }\n if (this.currentGain) {\n this.currentGain.disconnect();\n }\n this.currentSource = null;\n this.currentGain = null;\n this.currentName = null;\n }\n}\n"],"mappings":";AAwDO,IAAM,eAAN,MAAmB;AAAA,EAChB,MAA+B;AAAA,EAC/B,UAA2C;AAAA;AAAA,EAGnD,IAAI,QAAoB;AACtB,QAAI,CAAC,KAAK,IAAK,QAAO;AACtB,WAAO,KAA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AAI,WAAW;AACjC,SAAK,KAAK,eAAe,GAAG,GAAG;AAC/B,SAAK,KAAK,wBAAwB,GAAG,MAAM,QAAQ;AACnD,WAAO,QAAQ,IAAI;AACnB,SAAK,QAAQ,KAAK,MAAM;AAExB,WAAO,MAAM;AACb,SAAK,gBAAgB;AACrB,SAAK,cAAc;AACnB,SAAK,cAAc;AAEnB,IAAC,OAA4C,UAAU,MAAM;AAC3D,UAAI,KAAK,kBAAkB,QAAQ;AACjC,aAAK,gBAAgB;AACrB,aAAK,cAAc;AACnB,aAAK,cAAc;AAAA,MACrB;AACA,WAAK,WAAW;AAAA,IAClB;AAAA,EACF;AAAA,EAEQ,eAAqB;AAC3B,QAAI,KAAK,eAAe;AACtB,UAAI;AACF,aAAK,cAAc,KAAK;AAAA,MAC1B,QAAQ;AAAA,MAER;AAAA,IACF;AACA,QAAI,KAAK,aAAa;AACpB,WAAK,YAAY,WAAW;AAAA,IAC9B;AACA,SAAK,gBAAgB;AACrB,SAAK,cAAc;AACnB,SAAK,cAAc;AAAA,EACrB;AACF;","names":[]}
package/package.json ADDED
@@ -0,0 +1,45 @@
1
+ {
2
+ "name": "@flare-engine/audio",
3
+ "version": "0.1.0",
4
+ "description": "AudioManager, SFX pool, music crossfade",
5
+ "keywords": ["flare-engine", "audio", "sfx", "music"],
6
+ "license": "MIT",
7
+ "author": "Grzegorz Otto",
8
+ "homepage": "https://github.com/grzott/flare-engine#readme",
9
+ "bugs": {
10
+ "url": "https://github.com/grzott/flare-engine/issues"
11
+ },
12
+ "repository": {
13
+ "type": "git",
14
+ "url": "git+https://github.com/grzott/flare-engine.git",
15
+ "directory": "packages/audio"
16
+ },
17
+ "main": "dist/index.js",
18
+ "module": "dist/index.mjs",
19
+ "types": "dist/index.d.ts",
20
+ "exports": {
21
+ ".": {
22
+ "types": "./dist/index.d.ts",
23
+ "import": "./dist/index.mjs",
24
+ "require": "./dist/index.js"
25
+ }
26
+ },
27
+ "files": ["dist", "README.md", "LICENSE"],
28
+ "scripts": {
29
+ "build": "tsup",
30
+ "test": "bun test",
31
+ "lint": "biome check src/",
32
+ "typecheck": "tsc --noEmit"
33
+ },
34
+ "dependencies": {
35
+ "@flare-engine/events": "^0.1.0"
36
+ },
37
+ "peerDependencies": {
38
+ "react-native-audio-api": ">=0.3.0"
39
+ },
40
+ "publishConfig": {
41
+ "access": "restricted",
42
+ "registry": "https://registry.npmjs.org/"
43
+ },
44
+ "sideEffects": false
45
+ }