@al8b/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/README.md +23 -0
- package/dist/constants.d.mts +8 -0
- package/dist/constants.d.ts +8 -0
- package/dist/constants.js +37 -0
- package/dist/constants.js.map +1 -0
- package/dist/constants.mjs +10 -0
- package/dist/constants.mjs.map +1 -0
- package/dist/core/audio-core.d.mts +98 -0
- package/dist/core/audio-core.d.ts +98 -0
- package/dist/core/audio-core.js +664 -0
- package/dist/core/audio-core.js.map +1 -0
- package/dist/core/audio-core.mjs +641 -0
- package/dist/core/audio-core.mjs.map +1 -0
- package/dist/core/audio-worklet.d.mts +3 -0
- package/dist/core/audio-worklet.d.ts +3 -0
- package/dist/core/audio-worklet.js +153 -0
- package/dist/core/audio-worklet.js.map +1 -0
- package/dist/core/audio-worklet.mjs +128 -0
- package/dist/core/audio-worklet.mjs.map +1 -0
- package/dist/core/index.d.mts +2 -0
- package/dist/core/index.d.ts +2 -0
- package/dist/core/index.js +666 -0
- package/dist/core/index.js.map +1 -0
- package/dist/core/index.mjs +641 -0
- package/dist/core/index.mjs.map +1 -0
- package/dist/devices/beeper.d.mts +21 -0
- package/dist/devices/beeper.d.ts +21 -0
- package/dist/devices/beeper.js +286 -0
- package/dist/devices/beeper.js.map +1 -0
- package/dist/devices/beeper.mjs +261 -0
- package/dist/devices/beeper.mjs.map +1 -0
- package/dist/devices/index.d.mts +3 -0
- package/dist/devices/index.d.ts +3 -0
- package/dist/devices/index.js +534 -0
- package/dist/devices/index.js.map +1 -0
- package/dist/devices/index.mjs +507 -0
- package/dist/devices/index.mjs.map +1 -0
- package/dist/devices/music.d.mts +27 -0
- package/dist/devices/music.d.ts +27 -0
- package/dist/devices/music.js +104 -0
- package/dist/devices/music.js.map +1 -0
- package/dist/devices/music.mjs +81 -0
- package/dist/devices/music.mjs.map +1 -0
- package/dist/devices/sound.d.mts +22 -0
- package/dist/devices/sound.d.ts +22 -0
- package/dist/devices/sound.js +198 -0
- package/dist/devices/sound.js.map +1 -0
- package/dist/devices/sound.mjs +175 -0
- package/dist/devices/sound.mjs.map +1 -0
- package/dist/index.d.mts +4 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +916 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +888 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +37 -0
package/README.md
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# @al8b/audio
|
|
2
|
+
|
|
3
|
+
Audio primitives for the L8B runtime. This package provides the browser-facing audio core plus the asset wrappers used for sound effects, music playback, and synthesized beeps.
|
|
4
|
+
|
|
5
|
+
## Public API
|
|
6
|
+
|
|
7
|
+
- `AudioCore`
|
|
8
|
+
- `Sound`
|
|
9
|
+
- `Music`
|
|
10
|
+
- `Beeper`
|
|
11
|
+
|
|
12
|
+
## Notes
|
|
13
|
+
|
|
14
|
+
- Primarily consumed by `@al8b/runtime`.
|
|
15
|
+
- Depends on browser audio APIs and is not a standalone CLI-facing package.
|
|
16
|
+
|
|
17
|
+
## Scripts
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
bun run build
|
|
21
|
+
bun run test
|
|
22
|
+
bun run clean
|
|
23
|
+
```
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/** A4 reference frequency in Hz (concert pitch) */
|
|
2
|
+
declare const A4_FREQUENCY = 440;
|
|
3
|
+
/** Ratio between adjacent semitones in equal temperament */
|
|
4
|
+
declare const SEMITONE_RATIO: number;
|
|
5
|
+
/** MIDI note number for A4 */
|
|
6
|
+
declare const A4_MIDI_NOTE = 69;
|
|
7
|
+
|
|
8
|
+
export { A4_FREQUENCY, A4_MIDI_NOTE, SEMITONE_RATIO };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/** A4 reference frequency in Hz (concert pitch) */
|
|
2
|
+
declare const A4_FREQUENCY = 440;
|
|
3
|
+
/** Ratio between adjacent semitones in equal temperament */
|
|
4
|
+
declare const SEMITONE_RATIO: number;
|
|
5
|
+
/** MIDI note number for A4 */
|
|
6
|
+
declare const A4_MIDI_NOTE = 69;
|
|
7
|
+
|
|
8
|
+
export { A4_FREQUENCY, A4_MIDI_NOTE, SEMITONE_RATIO };
|
|
@@ -0,0 +1,37 @@
|
|
|
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/constants.ts
|
|
21
|
+
var constants_exports = {};
|
|
22
|
+
__export(constants_exports, {
|
|
23
|
+
A4_FREQUENCY: () => A4_FREQUENCY,
|
|
24
|
+
A4_MIDI_NOTE: () => A4_MIDI_NOTE,
|
|
25
|
+
SEMITONE_RATIO: () => SEMITONE_RATIO
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(constants_exports);
|
|
28
|
+
var A4_FREQUENCY = 440;
|
|
29
|
+
var SEMITONE_RATIO = 2 ** (1 / 12);
|
|
30
|
+
var A4_MIDI_NOTE = 69;
|
|
31
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
32
|
+
0 && (module.exports = {
|
|
33
|
+
A4_FREQUENCY,
|
|
34
|
+
A4_MIDI_NOTE,
|
|
35
|
+
SEMITONE_RATIO
|
|
36
|
+
});
|
|
37
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/constants.ts"],"sourcesContent":["/** A4 reference frequency in Hz (concert pitch) */\nexport const A4_FREQUENCY = 440;\n\n/** Ratio between adjacent semitones in equal temperament */\nexport const SEMITONE_RATIO = 2 ** (1 / 12);\n\n/** MIDI note number for A4 */\nexport const A4_MIDI_NOTE = 69;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;AACO,IAAMA,eAAe;AAGrB,IAAMC,iBAAiB,MAAM,IAAI;AAGjC,IAAMC,eAAe;","names":["A4_FREQUENCY","SEMITONE_RATIO","A4_MIDI_NOTE"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/constants.ts"],"sourcesContent":["/** A4 reference frequency in Hz (concert pitch) */\nexport const A4_FREQUENCY = 440;\n\n/** Ratio between adjacent semitones in equal temperament */\nexport const SEMITONE_RATIO = 2 ** (1 / 12);\n\n/** MIDI note number for A4 */\nexport const A4_MIDI_NOTE = 69;\n"],"mappings":";AACO,IAAMA,eAAe;AAGrB,IAAMC,iBAAiB,MAAM,IAAI;AAGjC,IAAMC,eAAe;","names":["A4_FREQUENCY","SEMITONE_RATIO","A4_MIDI_NOTE"]}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { Beeper } from '../devices/beeper.mjs';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* AudioCore - Web Audio API wrapper
|
|
5
|
+
* Manages audio context, beeper, and sound/music playback
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/** An actively playing sound/music that can be stopped */
|
|
9
|
+
interface PlayingHandle {
|
|
10
|
+
stop: () => void;
|
|
11
|
+
}
|
|
12
|
+
/** Item that can be woken up on audio context activation */
|
|
13
|
+
interface WakeUpItem {
|
|
14
|
+
wakeUp: () => void;
|
|
15
|
+
}
|
|
16
|
+
declare class AudioCore {
|
|
17
|
+
context: AudioContext;
|
|
18
|
+
private buffer;
|
|
19
|
+
private playing;
|
|
20
|
+
private wakeupList;
|
|
21
|
+
private workletNode?;
|
|
22
|
+
private beeper?;
|
|
23
|
+
private runtime;
|
|
24
|
+
private masterVolume;
|
|
25
|
+
constructor(runtime: any);
|
|
26
|
+
/**
|
|
27
|
+
* Check if audio context is running
|
|
28
|
+
*/
|
|
29
|
+
isStarted(): boolean;
|
|
30
|
+
/**
|
|
31
|
+
* Add item to wakeup list (for mobile audio activation)
|
|
32
|
+
*/
|
|
33
|
+
addToWakeUpList(item: WakeUpItem): void;
|
|
34
|
+
private interfaceCache;
|
|
35
|
+
/**
|
|
36
|
+
* Set master volume (0-1). Applied as a multiplier to all sound/music playback.
|
|
37
|
+
*/
|
|
38
|
+
setVolume(volume: number): void;
|
|
39
|
+
/**
|
|
40
|
+
* Get current master volume (0-1)
|
|
41
|
+
*/
|
|
42
|
+
getVolume(): number;
|
|
43
|
+
/**
|
|
44
|
+
* Get interface for game code
|
|
45
|
+
*/
|
|
46
|
+
getInterface(): Record<string, any>;
|
|
47
|
+
/**
|
|
48
|
+
* Play sound effect
|
|
49
|
+
*/
|
|
50
|
+
playSound(sound: any, volume?: number, pitch?: number, pan?: number, loopit?: boolean): number;
|
|
51
|
+
/**
|
|
52
|
+
* Play music
|
|
53
|
+
*/
|
|
54
|
+
playMusic(music: any, volume?: number, loopit?: boolean): number;
|
|
55
|
+
/**
|
|
56
|
+
* Get or create audio context (lazy initialization - created on first use)
|
|
57
|
+
* Note: Browser may suspend context until user interaction, which is handled automatically
|
|
58
|
+
*/
|
|
59
|
+
getContext(): AudioContext;
|
|
60
|
+
/**
|
|
61
|
+
* Start audio processor
|
|
62
|
+
*/
|
|
63
|
+
start(): Promise<void>;
|
|
64
|
+
/**
|
|
65
|
+
* Flush buffered messages
|
|
66
|
+
*/
|
|
67
|
+
private flushBuffer;
|
|
68
|
+
/**
|
|
69
|
+
* Get or create beeper
|
|
70
|
+
*/
|
|
71
|
+
getBeeper(): Beeper;
|
|
72
|
+
/**
|
|
73
|
+
* Play beep sequence
|
|
74
|
+
*/
|
|
75
|
+
beep(sequence: string): void;
|
|
76
|
+
/**
|
|
77
|
+
* Add beeps to audio processor
|
|
78
|
+
*/
|
|
79
|
+
addBeeps(beeps: any[]): void;
|
|
80
|
+
/**
|
|
81
|
+
* Cancel all beeps
|
|
82
|
+
*/
|
|
83
|
+
cancelBeeps(): void;
|
|
84
|
+
/**
|
|
85
|
+
* Add playing sound/music to list
|
|
86
|
+
*/
|
|
87
|
+
addPlaying(item: PlayingHandle): void;
|
|
88
|
+
/**
|
|
89
|
+
* Remove playing sound/music from list
|
|
90
|
+
*/
|
|
91
|
+
removePlaying(item: PlayingHandle): void;
|
|
92
|
+
/**
|
|
93
|
+
* Stop all playing sounds/music
|
|
94
|
+
*/
|
|
95
|
+
stopAll(): void;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export { AudioCore };
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { Beeper } from '../devices/beeper.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* AudioCore - Web Audio API wrapper
|
|
5
|
+
* Manages audio context, beeper, and sound/music playback
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/** An actively playing sound/music that can be stopped */
|
|
9
|
+
interface PlayingHandle {
|
|
10
|
+
stop: () => void;
|
|
11
|
+
}
|
|
12
|
+
/** Item that can be woken up on audio context activation */
|
|
13
|
+
interface WakeUpItem {
|
|
14
|
+
wakeUp: () => void;
|
|
15
|
+
}
|
|
16
|
+
declare class AudioCore {
|
|
17
|
+
context: AudioContext;
|
|
18
|
+
private buffer;
|
|
19
|
+
private playing;
|
|
20
|
+
private wakeupList;
|
|
21
|
+
private workletNode?;
|
|
22
|
+
private beeper?;
|
|
23
|
+
private runtime;
|
|
24
|
+
private masterVolume;
|
|
25
|
+
constructor(runtime: any);
|
|
26
|
+
/**
|
|
27
|
+
* Check if audio context is running
|
|
28
|
+
*/
|
|
29
|
+
isStarted(): boolean;
|
|
30
|
+
/**
|
|
31
|
+
* Add item to wakeup list (for mobile audio activation)
|
|
32
|
+
*/
|
|
33
|
+
addToWakeUpList(item: WakeUpItem): void;
|
|
34
|
+
private interfaceCache;
|
|
35
|
+
/**
|
|
36
|
+
* Set master volume (0-1). Applied as a multiplier to all sound/music playback.
|
|
37
|
+
*/
|
|
38
|
+
setVolume(volume: number): void;
|
|
39
|
+
/**
|
|
40
|
+
* Get current master volume (0-1)
|
|
41
|
+
*/
|
|
42
|
+
getVolume(): number;
|
|
43
|
+
/**
|
|
44
|
+
* Get interface for game code
|
|
45
|
+
*/
|
|
46
|
+
getInterface(): Record<string, any>;
|
|
47
|
+
/**
|
|
48
|
+
* Play sound effect
|
|
49
|
+
*/
|
|
50
|
+
playSound(sound: any, volume?: number, pitch?: number, pan?: number, loopit?: boolean): number;
|
|
51
|
+
/**
|
|
52
|
+
* Play music
|
|
53
|
+
*/
|
|
54
|
+
playMusic(music: any, volume?: number, loopit?: boolean): number;
|
|
55
|
+
/**
|
|
56
|
+
* Get or create audio context (lazy initialization - created on first use)
|
|
57
|
+
* Note: Browser may suspend context until user interaction, which is handled automatically
|
|
58
|
+
*/
|
|
59
|
+
getContext(): AudioContext;
|
|
60
|
+
/**
|
|
61
|
+
* Start audio processor
|
|
62
|
+
*/
|
|
63
|
+
start(): Promise<void>;
|
|
64
|
+
/**
|
|
65
|
+
* Flush buffered messages
|
|
66
|
+
*/
|
|
67
|
+
private flushBuffer;
|
|
68
|
+
/**
|
|
69
|
+
* Get or create beeper
|
|
70
|
+
*/
|
|
71
|
+
getBeeper(): Beeper;
|
|
72
|
+
/**
|
|
73
|
+
* Play beep sequence
|
|
74
|
+
*/
|
|
75
|
+
beep(sequence: string): void;
|
|
76
|
+
/**
|
|
77
|
+
* Add beeps to audio processor
|
|
78
|
+
*/
|
|
79
|
+
addBeeps(beeps: any[]): void;
|
|
80
|
+
/**
|
|
81
|
+
* Cancel all beeps
|
|
82
|
+
*/
|
|
83
|
+
cancelBeeps(): void;
|
|
84
|
+
/**
|
|
85
|
+
* Add playing sound/music to list
|
|
86
|
+
*/
|
|
87
|
+
addPlaying(item: PlayingHandle): void;
|
|
88
|
+
/**
|
|
89
|
+
* Remove playing sound/music from list
|
|
90
|
+
*/
|
|
91
|
+
removePlaying(item: PlayingHandle): void;
|
|
92
|
+
/**
|
|
93
|
+
* Stop all playing sounds/music
|
|
94
|
+
*/
|
|
95
|
+
stopAll(): void;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export { AudioCore };
|