@margoengine/audio 0.0.0-stage → 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 +201 -0
- package/NOTICE +4 -0
- package/README.md +748 -3
- package/dist/ambisonics.d.ts +54 -0
- package/dist/ambisonics.js +118 -0
- package/dist/analyser.d.ts +45 -0
- package/dist/audio.d.ts +282 -0
- package/dist/binaural.d.ts +35 -0
- package/dist/binaural.js +123 -0
- package/dist/doppler.d.ts +44 -0
- package/dist/doppler.js +82 -0
- package/dist/errors-D8rc8kzg.js +7 -0
- package/dist/events.d.ts +54 -0
- package/dist/events.js +78 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.js +303 -0
- package/dist/listener.d.ts +116 -0
- package/dist/loader.d.ts +22 -0
- package/dist/math-C82bLsED.js +44 -0
- package/dist/math.d.ts +19 -0
- package/dist/music.d.ts +76 -0
- package/dist/music.js +106 -0
- package/dist/occlusion.d.ts +50 -0
- package/dist/occlusion.js +75 -0
- package/dist/outdoor.d.ts +37 -0
- package/dist/outdoor.js +46 -0
- package/dist/pan.d.ts +21 -0
- package/dist/pan.js +28 -0
- package/dist/rate-control-BiZ5FnNk.js +4 -0
- package/dist/rate-control.d.ts +5 -0
- package/dist/resample.d.ts +53 -0
- package/dist/resample.js +270 -0
- package/dist/scan.d.ts +66 -0
- package/dist/scan.js +75 -0
- package/dist/spectrogram-fft.d.ts +26 -0
- package/dist/spectrogram-windows.d.ts +24 -0
- package/dist/spectrogram.d.ts +143 -0
- package/dist/spectrogram.js +440 -0
- package/dist/sprites.d.ts +59 -0
- package/dist/sprites.js +99 -0
- package/dist/stretch.d.ts +25 -0
- package/dist/stretch.js +55 -0
- package/dist/voice-manager.d.ts +100 -0
- package/dist/voice-manager.js +178 -0
- package/dist/voices-CdfPmzIo.js +425 -0
- package/dist/voices.d.ts +45 -0
- package/dist/wav.d.ts +47 -0
- package/dist/wav.js +156 -0
- package/dist/zones.d.ts +43 -0
- package/dist/zones.js +75 -0
- package/package.json +127 -6
package/dist/zones.d.ts
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/// <reference lib="esnext.disposable" preserve="true" />
|
|
2
|
+
// @ts-ignore optional peer: its types apply when it is installed
|
|
3
|
+
import { type RoomReverbOptions } from '@margoengine/mixer/reflections';
|
|
4
|
+
import type { AudioListener } from './listener.js';
|
|
5
|
+
import type { Vec3 } from './math.js';
|
|
6
|
+
/** One axis-aligned world-space reverb area. Overlap selects greatest priority, then first in the list. */
|
|
7
|
+
export interface ReverbZone {
|
|
8
|
+
/** Unique nonempty zone name. */
|
|
9
|
+
name: string;
|
|
10
|
+
/** Inclusive world bounds in metres, copied at construction. */
|
|
11
|
+
min: Vec3;
|
|
12
|
+
/** Inclusive world bounds in metres, copied at construction. */
|
|
13
|
+
max: Vec3;
|
|
14
|
+
/** Finite overlap priority. Default 0. */
|
|
15
|
+
priority?: number;
|
|
16
|
+
/** Linear wet-send gain, 0..1. Default 0.25. Dry sound stays on its existing route. */
|
|
17
|
+
gain?: number;
|
|
18
|
+
/** Existing mixer room response settings. Default mixer room defaults; mix is always 1 (wet only). */
|
|
19
|
+
reverb?: Omit<RoomReverbOptions, 'mix'>;
|
|
20
|
+
}
|
|
21
|
+
/** Settings for wet-send transitions. */
|
|
22
|
+
export interface AudioReverbZonesOptions {
|
|
23
|
+
/** Mixer exponential fade seconds, about 98% settled. Default 0.1; 0 jumps. */
|
|
24
|
+
fade?: number;
|
|
25
|
+
}
|
|
26
|
+
/** Listener-selected wet returns, reusing the mixer's room convolution without replacing dry routes. */
|
|
27
|
+
export declare class AudioReverbZones {
|
|
28
|
+
/** Connect sound outputs here as extra wet sends. Keep their existing dry connections. */
|
|
29
|
+
readonly input: GainNode;
|
|
30
|
+
private readonly zones;
|
|
31
|
+
private readonly fade;
|
|
32
|
+
private selected;
|
|
33
|
+
private disposed;
|
|
34
|
+
private readonly listener;
|
|
35
|
+
constructor(listener: AudioListener, zones: readonly ReverbZone[], options?: AudioReverbZonesOptions);
|
|
36
|
+
/** Selected zone name, or null outside every area. */
|
|
37
|
+
get active(): string | null;
|
|
38
|
+
/** Select from the listener's current world position. Attached listeners call this each frame. */
|
|
39
|
+
update(): void;
|
|
40
|
+
/** Disconnect wet returns immediately. Disconnect external sends into input if their source will outlive this controller. */
|
|
41
|
+
dispose(): void;
|
|
42
|
+
[Symbol.dispose]: () => void;
|
|
43
|
+
}
|
package/dist/zones.js
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { r as e, t } from "./errors-D8rc8kzg.js";
|
|
2
|
+
import { rampParam as n } from "@margoengine/mixer";
|
|
3
|
+
import { createRoomReverb as r } from "@margoengine/mixer/reflections";
|
|
4
|
+
//#region src/zones.ts
|
|
5
|
+
var i = class {
|
|
6
|
+
constructor(n, i, a = {}) {
|
|
7
|
+
if (this.zones = [], this.selected = -1, this.disposed = !1, this.listener = n, this.fade = a.fade ?? .1, !Number.isFinite(this.fade) || this.fade < 0) throw e("Reverb zone fade must be finite and nonnegative; use seconds or 0 for a jump", "state");
|
|
8
|
+
let o = /* @__PURE__ */ new Set(), s = Array.from(i, (n) => {
|
|
9
|
+
if (!n || typeof n.name != "string" || !n.name || o.has(n.name)) throw t("state", "Reverb zones need unique nonempty names; name each zone once");
|
|
10
|
+
o.add(n.name);
|
|
11
|
+
let { min: r, max: i } = n;
|
|
12
|
+
if (r?.length !== 3 || i?.length !== 3 || [
|
|
13
|
+
0,
|
|
14
|
+
1,
|
|
15
|
+
2
|
|
16
|
+
].some((e) => !Number.isFinite(r[e]) || !Number.isFinite(i[e]) || r[e] > i[e])) throw e("Reverb zone bounds need three finite ordered coordinates; pass min and max in world metres", "state");
|
|
17
|
+
let a = n.priority ?? 0, s = n.gain ?? .25;
|
|
18
|
+
if (!Number.isFinite(a) || !Number.isFinite(s) || s < 0 || s > 1) throw e("Reverb zone needs finite priority and gain in 0..1; choose valid overlap and wet levels", "state");
|
|
19
|
+
return {
|
|
20
|
+
name: n.name,
|
|
21
|
+
min: Array.from(r),
|
|
22
|
+
max: Array.from(i),
|
|
23
|
+
priority: a,
|
|
24
|
+
gain: s,
|
|
25
|
+
reverb: n.reverb
|
|
26
|
+
};
|
|
27
|
+
}), c = n.context;
|
|
28
|
+
this.input = c.createGain();
|
|
29
|
+
try {
|
|
30
|
+
for (let e of s) {
|
|
31
|
+
let t = r(c, {
|
|
32
|
+
...e.reverb,
|
|
33
|
+
mix: 1
|
|
34
|
+
}), i = c.createGain();
|
|
35
|
+
i.gain.value = 0, this.zones.push({
|
|
36
|
+
...e,
|
|
37
|
+
send: i,
|
|
38
|
+
effect: t
|
|
39
|
+
}), this.input.connect(i).connect(t.input), t.output.connect(n.input);
|
|
40
|
+
}
|
|
41
|
+
n.addSource(this), this.update();
|
|
42
|
+
} catch (e) {
|
|
43
|
+
throw this.dispose(), e;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
get active() {
|
|
47
|
+
return this.zones[this.selected]?.name ?? null;
|
|
48
|
+
}
|
|
49
|
+
update() {
|
|
50
|
+
if (this.disposed) throw t("disposed", "AudioReverbZones is disposed; create a new zone controller");
|
|
51
|
+
let e = this.listener.position, r = -1;
|
|
52
|
+
if (this.zones.forEach((t, n) => {
|
|
53
|
+
(r < 0 || t.priority > this.zones[r].priority) && [
|
|
54
|
+
0,
|
|
55
|
+
1,
|
|
56
|
+
2
|
|
57
|
+
].every((n) => e[n] >= t.min[n] && e[n] <= t.max[n]) && (r = n);
|
|
58
|
+
}), r !== this.selected) {
|
|
59
|
+
for (let e = 0; e < this.zones.length; e++) n(this.listener.context, this.zones[e].send.gain, e === r ? this.zones[e].gain : 0, { seconds: this.fade });
|
|
60
|
+
this.selected = r;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
dispose() {
|
|
64
|
+
if (!this.disposed) {
|
|
65
|
+
this.disposed = !0, this.listener.removeSource(this), this.input.disconnect();
|
|
66
|
+
for (let e of this.zones) e.send.disconnect(), e.effect.dispose();
|
|
67
|
+
this.zones.length = 0, this.selected = -1;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
[Symbol.dispose ?? Symbol()]() {
|
|
71
|
+
this.dispose();
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
//#endregion
|
|
75
|
+
export { i as AudioReverbZones };
|
package/package.json
CHANGED
|
@@ -1,6 +1,127 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@margoengine/audio",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "@margoengine/audio",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Web Audio listener, global and positional sounds and a frequency analyser for Margo Engine.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"margoengine",
|
|
7
|
+
"webgpu",
|
|
8
|
+
"3d",
|
|
9
|
+
"audio"
|
|
10
|
+
],
|
|
11
|
+
"homepage": "https://margoengine.com",
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://github.com/scottcampbelldata/margoengine/issues"
|
|
14
|
+
},
|
|
15
|
+
"repository": {
|
|
16
|
+
"type": "git",
|
|
17
|
+
"url": "git+https://github.com/scottcampbelldata/margoengine.git",
|
|
18
|
+
"directory": "packages/audio"
|
|
19
|
+
},
|
|
20
|
+
"license": "Apache-2.0",
|
|
21
|
+
"author": "Scott Campbell",
|
|
22
|
+
"type": "module",
|
|
23
|
+
"publishConfig": {
|
|
24
|
+
"access": "public"
|
|
25
|
+
},
|
|
26
|
+
"scripts": {
|
|
27
|
+
"test:browser:outdoor-sound": "cd ../.. && node packages/audio/tests/outdoor-sound.browser.mjs",
|
|
28
|
+
"build": "node ../../scripts/build-optional.js audio",
|
|
29
|
+
"test": "npm run build && node --test tests/*.test.js",
|
|
30
|
+
"test:browser": "npm run build && node scripts/test-browser.js",
|
|
31
|
+
"test:browser:listener-disposal": "node tests/listener-disposal-browser.mjs",
|
|
32
|
+
"test:browser:spectrogram": "cd ../.. && node packages/audio/tests/spectrogram-browser.mjs",
|
|
33
|
+
"prepack": "npm run build"
|
|
34
|
+
},
|
|
35
|
+
"sideEffects": false,
|
|
36
|
+
"exports": {
|
|
37
|
+
".": {
|
|
38
|
+
"types": "./dist/index.d.ts",
|
|
39
|
+
"import": "./dist/index.js"
|
|
40
|
+
},
|
|
41
|
+
"./occlusion": {
|
|
42
|
+
"types": "./dist/occlusion.d.ts",
|
|
43
|
+
"import": "./dist/occlusion.js"
|
|
44
|
+
},
|
|
45
|
+
"./doppler": {
|
|
46
|
+
"types": "./dist/doppler.d.ts",
|
|
47
|
+
"import": "./dist/doppler.js"
|
|
48
|
+
},
|
|
49
|
+
"./outdoor": {
|
|
50
|
+
"types": "./dist/outdoor.d.ts",
|
|
51
|
+
"import": "./dist/outdoor.js"
|
|
52
|
+
},
|
|
53
|
+
"./events": {
|
|
54
|
+
"types": "./dist/events.d.ts",
|
|
55
|
+
"import": "./dist/events.js"
|
|
56
|
+
},
|
|
57
|
+
"./music": {
|
|
58
|
+
"types": "./dist/music.d.ts",
|
|
59
|
+
"import": "./dist/music.js"
|
|
60
|
+
},
|
|
61
|
+
"./zones": {
|
|
62
|
+
"types": "./dist/zones.d.ts",
|
|
63
|
+
"import": "./dist/zones.js"
|
|
64
|
+
},
|
|
65
|
+
"./ambisonics": {
|
|
66
|
+
"types": "./dist/ambisonics.d.ts",
|
|
67
|
+
"import": "./dist/ambisonics.js"
|
|
68
|
+
},
|
|
69
|
+
"./pan": {
|
|
70
|
+
"types": "./dist/pan.d.ts",
|
|
71
|
+
"import": "./dist/pan.js"
|
|
72
|
+
},
|
|
73
|
+
"./binaural": {
|
|
74
|
+
"types": "./dist/binaural.d.ts",
|
|
75
|
+
"import": "./dist/binaural.js"
|
|
76
|
+
},
|
|
77
|
+
"./voices": {
|
|
78
|
+
"types": "./dist/voice-manager.d.ts",
|
|
79
|
+
"import": "./dist/voice-manager.js"
|
|
80
|
+
},
|
|
81
|
+
"./sprites": {
|
|
82
|
+
"types": "./dist/sprites.d.ts",
|
|
83
|
+
"import": "./dist/sprites.js"
|
|
84
|
+
},
|
|
85
|
+
"./spectrogram": {
|
|
86
|
+
"types": "./dist/spectrogram.d.ts",
|
|
87
|
+
"import": "./dist/spectrogram.js"
|
|
88
|
+
},
|
|
89
|
+
"./wav": {
|
|
90
|
+
"types": "./dist/wav.d.ts",
|
|
91
|
+
"import": "./dist/wav.js"
|
|
92
|
+
},
|
|
93
|
+
"./scan": {
|
|
94
|
+
"types": "./dist/scan.d.ts",
|
|
95
|
+
"import": "./dist/scan.js"
|
|
96
|
+
},
|
|
97
|
+
"./resample": {
|
|
98
|
+
"types": "./dist/resample.d.ts",
|
|
99
|
+
"import": "./dist/resample.js"
|
|
100
|
+
},
|
|
101
|
+
"./stretch": {
|
|
102
|
+
"types": "./dist/stretch.d.ts",
|
|
103
|
+
"import": "./dist/stretch.js"
|
|
104
|
+
}
|
|
105
|
+
},
|
|
106
|
+
"files": [
|
|
107
|
+
"dist",
|
|
108
|
+
"NOTICE"
|
|
109
|
+
],
|
|
110
|
+
"peerDependencies": {
|
|
111
|
+
"@margoengine/core": "^0.1.0",
|
|
112
|
+
"@margoengine/bvh": "^0.1.0",
|
|
113
|
+
"@margoengine/mixer": "^0.1.0",
|
|
114
|
+
"@margoengine/compute": "^0.1.0"
|
|
115
|
+
},
|
|
116
|
+
"peerDependenciesMeta": {
|
|
117
|
+
"@margoengine/bvh": {
|
|
118
|
+
"optional": true
|
|
119
|
+
},
|
|
120
|
+
"@margoengine/mixer": {
|
|
121
|
+
"optional": true
|
|
122
|
+
},
|
|
123
|
+
"@margoengine/compute": {
|
|
124
|
+
"optional": true
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|