@margoengine/audio 0.0.0-stage → 1.0.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 +987 -2
- 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 +52 -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 +245 -0
- package/dist/scan.d.ts +66 -0
- package/dist/scan.js +75 -0
- package/dist/sinc-CbjImCBh.js +36 -0
- package/dist/sinc.d.ts +5 -0
- package/dist/spectrogram-fft-CRLetuHA.js +59 -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 +384 -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/vocoder-envelope.d.ts +5 -0
- package/dist/vocoder-phase.d.ts +7 -0
- package/dist/vocoder-split.d.ts +10 -0
- package/dist/vocoder.d.ts +59 -0
- package/dist/vocoder.js +291 -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 +130 -4
package/dist/wav.d.ts
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/** How a file stores each sample. `pcm8` is unsigned; the other integer formats are signed. */
|
|
2
|
+
export type WavSampleFormat = 'pcm8' | 'pcm16' | 'pcm24' | 'pcm32' | 'float32' | 'float64';
|
|
3
|
+
/** Decoded audio: one Float32Array per channel, samples nominally in -1..1. */
|
|
4
|
+
export interface WavAudio {
|
|
5
|
+
/** Frames per second, a positive integer. */
|
|
6
|
+
sampleRate: number;
|
|
7
|
+
/** One array per channel, all the same length. */
|
|
8
|
+
channels: Float32Array[];
|
|
9
|
+
/** The sample format of the file the audio was read from. */
|
|
10
|
+
format: WavSampleFormat;
|
|
11
|
+
/** The speaker bits of a WAVE_FORMAT_EXTENSIBLE file (bit 0 front left, bit 1 front right, bit 2 front centre, ...); 0 when absent or unspecified. */
|
|
12
|
+
channelMask: number;
|
|
13
|
+
}
|
|
14
|
+
/** What `encodeWav` needs: a rate and the channels (typed arrays or plain number arrays, all the same length). */
|
|
15
|
+
export interface WavInput {
|
|
16
|
+
sampleRate: number;
|
|
17
|
+
channels: ArrayLike<number>[];
|
|
18
|
+
/** The speaker bits written to an extensible header. Default: the usual layout for 1, 2, 4, 6 and 8 channels, else 0. */
|
|
19
|
+
channelMask?: number;
|
|
20
|
+
}
|
|
21
|
+
/** Options of `encodeWav`. */
|
|
22
|
+
export interface EncodeWavOptions {
|
|
23
|
+
/** Default `pcm16`. */
|
|
24
|
+
format?: WavSampleFormat;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Reads a RIFF WAVE file: 8, 16, 24 and 32-bit integer PCM and 32 and 64-bit float, plain or WAVE_FORMAT_EXTENSIBLE,
|
|
28
|
+
* with any number of channels. Chunks other than `fmt ` and `data` (`LIST`, `bext`, `iXML`, `cue `) are skipped. A
|
|
29
|
+
* `data` size that is 0xFFFFFFFF, or runs past the end of the file (a file still being written), reads to the end; a
|
|
30
|
+
* last partial frame is dropped. Integer samples become `value / 2^(bits - 1)` (8-bit: `(byte - 128) / 128`), so
|
|
31
|
+
* `encodeWav` of the result in the same format returns the same samples.
|
|
32
|
+
* @example
|
|
33
|
+
* const audio = decodeWav(bytes); // bytes: the file as a Uint8Array or ArrayBuffer
|
|
34
|
+
* console.log(audio.sampleRate, audio.channels.length, audio.channels[0].length);
|
|
35
|
+
*/
|
|
36
|
+
export declare function decodeWav(data: ArrayBuffer | ArrayBufferView): WavAudio;
|
|
37
|
+
/**
|
|
38
|
+
* Writes a RIFF WAVE file. Integer formats scale by `2^(bits - 1)`, round to nearest and clamp to the format's range
|
|
39
|
+
* (so 1 becomes the largest value, no wrap); float formats store the samples as they are. Files with more than two
|
|
40
|
+
* channels, or 24 or 32-bit integer or 64-bit float samples, use WAVE_FORMAT_EXTENSIBLE as the Microsoft guidance for
|
|
41
|
+
* multichannel and wide files says; the rest use the plain header every tool reads. NaN becomes 0 in integer formats.
|
|
42
|
+
* @example
|
|
43
|
+
* const left = new Float32Array(48_000).map((_, i) => Math.sin((2 * Math.PI * 440 * i) / 48_000) * 0.5);
|
|
44
|
+
* const file = encodeWav({sampleRate: 48_000, channels: [left, left]}, {format: 'pcm24'}); // a Uint8Array
|
|
45
|
+
* console.log(file.byteLength);
|
|
46
|
+
*/
|
|
47
|
+
export declare function encodeWav(audio: WavInput, options?: EncodeWavOptions): Uint8Array;
|
package/dist/wav.js
ADDED
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import { i as e, r as t, t as n } from "./errors-D8rc8kzg.js";
|
|
2
|
+
//#region src/wav.ts
|
|
3
|
+
var r = {
|
|
4
|
+
pcm8: 8,
|
|
5
|
+
pcm16: 16,
|
|
6
|
+
pcm24: 24,
|
|
7
|
+
pcm32: 32,
|
|
8
|
+
float32: 32,
|
|
9
|
+
float64: 64
|
|
10
|
+
}, i = 1, a = 3, o = 65534, s = [
|
|
11
|
+
0,
|
|
12
|
+
0,
|
|
13
|
+
0,
|
|
14
|
+
0,
|
|
15
|
+
16,
|
|
16
|
+
0,
|
|
17
|
+
128,
|
|
18
|
+
0,
|
|
19
|
+
0,
|
|
20
|
+
170,
|
|
21
|
+
0,
|
|
22
|
+
56,
|
|
23
|
+
155,
|
|
24
|
+
113
|
|
25
|
+
], c = {
|
|
26
|
+
1: 4,
|
|
27
|
+
2: 3,
|
|
28
|
+
4: 51,
|
|
29
|
+
6: 63,
|
|
30
|
+
8: 1599
|
|
31
|
+
}, l = (e, t) => n(e, t, "wav"), u = (e, t) => String.fromCharCode(e.getUint8(t), e.getUint8(t + 1), e.getUint8(t + 2), e.getUint8(t + 3));
|
|
32
|
+
function d(t) {
|
|
33
|
+
if (t instanceof ArrayBuffer) return new Uint8Array(t);
|
|
34
|
+
if (ArrayBuffer.isView(t)) return new Uint8Array(t.buffer, t.byteOffset, t.byteLength);
|
|
35
|
+
throw e("decodeWav needs an ArrayBuffer or a typed array holding the file; read the file into bytes first", "wav");
|
|
36
|
+
}
|
|
37
|
+
function f(e, t) {
|
|
38
|
+
if (e === i) {
|
|
39
|
+
if (t === 8) return "pcm8";
|
|
40
|
+
if (t === 16) return "pcm16";
|
|
41
|
+
if (t === 24) return "pcm24";
|
|
42
|
+
if (t === 32) return "pcm32";
|
|
43
|
+
}
|
|
44
|
+
if (e === a) {
|
|
45
|
+
if (t === 32) return "float32";
|
|
46
|
+
if (t === 64) return "float64";
|
|
47
|
+
}
|
|
48
|
+
throw l("unsupported", `WAV format tag ${e} with ${t} bits per sample is not supported; read 8, 16, 24 and 32-bit PCM and 32 and 64-bit float, or convert the file first`);
|
|
49
|
+
}
|
|
50
|
+
function p(e) {
|
|
51
|
+
let t = d(e), n = new DataView(t.buffer, t.byteOffset, t.byteLength);
|
|
52
|
+
if (t.length < 12) throw l("failed", "Not a WAV file: shorter than the 12-byte RIFF header");
|
|
53
|
+
let r = u(n, 0);
|
|
54
|
+
if (r === "RF64" || r === "BW64") throw l("unsupported", "RF64 and BW64 files (over 4 GiB) are not supported; split the audio into files under 4 GiB");
|
|
55
|
+
if (r !== "RIFF" || u(n, 8) !== "WAVE") throw l("failed", "Not a WAV file: it must start with RIFF and form type WAVE");
|
|
56
|
+
let i, a = -1, c = 0;
|
|
57
|
+
for (let e = 12; e + 8 <= t.length;) {
|
|
58
|
+
let r = u(n, e), d = n.getUint32(e + 4, !0), f = e + 8;
|
|
59
|
+
if (r === "fmt ") {
|
|
60
|
+
if (d < 16 || f + 16 > t.length) throw l("failed", "The WAV fmt chunk is shorter than 16 bytes");
|
|
61
|
+
let e = n.getUint16(f, !0), r = 0, a = n.getUint16(f + 14, !0);
|
|
62
|
+
if (e === o) {
|
|
63
|
+
if (d < 40 || f + 40 > t.length) throw l("failed", "The WAV extensible fmt chunk is shorter than 40 bytes");
|
|
64
|
+
if (n.getUint16(f + 16, !0) < 22) throw l("failed", "The WAV extensible fmt chunk has no 22-byte extension");
|
|
65
|
+
r = n.getUint32(f + 20, !0), e = n.getUint16(f + 24, !0);
|
|
66
|
+
for (let e = 0; e < s.length; e++) if (n.getUint8(f + 26 + e) !== s[e]) throw l("unsupported", "The WAV extensible SubFormat is not PCM or IEEE float; convert the file first");
|
|
67
|
+
}
|
|
68
|
+
i = {
|
|
69
|
+
tag: e,
|
|
70
|
+
channels: n.getUint16(f + 2, !0),
|
|
71
|
+
rate: n.getUint32(f + 4, !0),
|
|
72
|
+
bits: a,
|
|
73
|
+
mask: r
|
|
74
|
+
};
|
|
75
|
+
let c = n.getUint16(f + 12, !0);
|
|
76
|
+
if (i.channels < 1 || i.rate < 1) throw l("failed", "The WAV fmt chunk has no channels or a zero sample rate");
|
|
77
|
+
if (a === 0 || a % 8 || c !== i.channels * a / 8) throw l("failed", `The WAV fmt chunk is inconsistent: ${a} bits per sample, ${i.channels} channels, block align ${c}`);
|
|
78
|
+
} else if (r === "data" && a < 0 && (a = f, c = d === 4294967295 || f + d > t.length ? t.length - f : d, i)) break;
|
|
79
|
+
d += d & 1, e = f + d;
|
|
80
|
+
}
|
|
81
|
+
if (!i) throw l("failed", "The WAV file has no fmt chunk");
|
|
82
|
+
if (a < 0) throw l("failed", "The WAV file has no data chunk");
|
|
83
|
+
let p = f(i.tag, i.bits), m = i.bits / 8, h = Math.floor(c / (m * i.channels)), g = Array.from({ length: i.channels }, () => new Float32Array(h));
|
|
84
|
+
for (let e = 0, t = a; e < h; e++) for (let r = 0; r < i.channels; r++, t += m) {
|
|
85
|
+
let i;
|
|
86
|
+
switch (p) {
|
|
87
|
+
case "pcm8":
|
|
88
|
+
i = (n.getUint8(t) - 128) / 128;
|
|
89
|
+
break;
|
|
90
|
+
case "pcm16":
|
|
91
|
+
i = n.getInt16(t, !0) / 32768;
|
|
92
|
+
break;
|
|
93
|
+
case "pcm24":
|
|
94
|
+
i = (n.getUint8(t) | n.getUint8(t + 1) << 8 | n.getInt8(t + 2) << 16) / 8388608;
|
|
95
|
+
break;
|
|
96
|
+
case "pcm32":
|
|
97
|
+
i = n.getInt32(t, !0) / 2147483648;
|
|
98
|
+
break;
|
|
99
|
+
case "float32":
|
|
100
|
+
i = n.getFloat32(t, !0);
|
|
101
|
+
break;
|
|
102
|
+
default: i = n.getFloat64(t, !0);
|
|
103
|
+
}
|
|
104
|
+
g[r][e] = i;
|
|
105
|
+
}
|
|
106
|
+
return {
|
|
107
|
+
sampleRate: i.rate,
|
|
108
|
+
channels: g,
|
|
109
|
+
format: p,
|
|
110
|
+
channelMask: i.mask
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
function m(e, n = {}) {
|
|
114
|
+
let l = n.format ?? "pcm16";
|
|
115
|
+
if (!(l in r)) throw t(`Unknown WAV format ${String(l)}; use pcm8, pcm16, pcm24, pcm32, float32 or float64`, "wav");
|
|
116
|
+
let { sampleRate: u, channels: d } = e;
|
|
117
|
+
if (!Number.isInteger(u) || u < 1 || u > 4294967295) throw t("encodeWav needs an integer sampleRate from 1 to 4294967295", "wav");
|
|
118
|
+
if (!Array.isArray(d) || d.length < 1 || d.length > 65535) throw t("encodeWav needs from 1 to 65535 channels, each an array of samples", "wav");
|
|
119
|
+
let f = d[0]?.length;
|
|
120
|
+
if (!Number.isInteger(f) || d.some((e) => !e || e.length !== f)) throw t("encodeWav needs every channel to be an array of the same length", "wav");
|
|
121
|
+
let p = d.length, m = r[l], h = m / 8, g = l === "float32" || l === "float64", _ = p > 2 || l === "pcm24" || l === "pcm32" || l === "float64", v = _ ? 60 : 36, y = f * p * h, b = y & 1;
|
|
122
|
+
if (v + y + b > 4294967295) throw t("A WAV file holds under 4 GiB; split the audio into shorter files", "wav");
|
|
123
|
+
let x = new Uint8Array(v + 8 + y + b), S = new DataView(x.buffer), C = (e, t) => {
|
|
124
|
+
for (let n = 0; n < 4; n++) x[e + n] = t.charCodeAt(n);
|
|
125
|
+
};
|
|
126
|
+
C(0, "RIFF"), S.setUint32(4, x.length - 8, !0), C(8, "WAVE"), C(12, "fmt "), S.setUint32(16, _ ? 40 : 16, !0), S.setUint16(20, _ ? o : g ? a : i, !0), S.setUint16(22, p, !0), S.setUint32(24, u, !0), S.setUint32(28, u * p * h, !0), S.setUint16(32, p * h, !0), S.setUint16(34, m, !0);
|
|
127
|
+
let w;
|
|
128
|
+
_ && (S.setUint16(36, 22, !0), S.setUint16(38, m, !0), S.setUint32(40, e.channelMask ?? c[p] ?? 0, !0), S.setUint16(44, g ? a : i, !0), x.set(s, 46)), w = v, C(w, "data"), S.setUint32(w + 4, y, !0), w += 8;
|
|
129
|
+
let T = (e, t, n) => Math.min(n, Math.max(t, Math.round(e) || 0));
|
|
130
|
+
for (let e = 0; e < f; e++) for (let t = 0; t < p; t++, w += h) {
|
|
131
|
+
let n = d[t][e];
|
|
132
|
+
switch (l) {
|
|
133
|
+
case "pcm8":
|
|
134
|
+
S.setUint8(w, T(n * 128, -128, 127) + 128);
|
|
135
|
+
break;
|
|
136
|
+
case "pcm16":
|
|
137
|
+
S.setInt16(w, T(n * 32768, -32768, 32767), !0);
|
|
138
|
+
break;
|
|
139
|
+
case "pcm24": {
|
|
140
|
+
let e = T(n * 8388608, -8388608, 8388607);
|
|
141
|
+
S.setUint8(w, e & 255), S.setUint8(w + 1, e >> 8 & 255), S.setUint8(w + 2, e >> 16 & 255);
|
|
142
|
+
break;
|
|
143
|
+
}
|
|
144
|
+
case "pcm32":
|
|
145
|
+
S.setInt32(w, T(n * 2147483648, -2147483648, 2147483647), !0);
|
|
146
|
+
break;
|
|
147
|
+
case "float32":
|
|
148
|
+
S.setFloat32(w, n, !0);
|
|
149
|
+
break;
|
|
150
|
+
default: S.setFloat64(w, n, !0);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
return x;
|
|
154
|
+
}
|
|
155
|
+
//#endregion
|
|
156
|
+
export { p as decodeWav, m as encodeWav };
|
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,132 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@margoengine/audio",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "1.0.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:gpu:outdoor-film": "cd ../.. && node packages/audio/tests/outdoor-film.browser.mjs && node packages/audio/tests/outdoor-film.browser.mjs --compat",
|
|
28
|
+
"test:browser:outdoor-sound": "cd ../.. && node packages/audio/tests/outdoor-sound.browser.mjs",
|
|
29
|
+
"build": "node ../../scripts/build-optional.js audio",
|
|
30
|
+
"test": "npm run build && node --test tests/*.test.js",
|
|
31
|
+
"test:browser": "npm run build && node scripts/test-browser.js",
|
|
32
|
+
"test:browser:listener-disposal": "node tests/listener-disposal-browser.mjs",
|
|
33
|
+
"test:browser:spectrogram": "cd ../.. && node packages/audio/tests/spectrogram-browser.mjs",
|
|
34
|
+
"prepack": "npm run build"
|
|
35
|
+
},
|
|
36
|
+
"sideEffects": false,
|
|
37
|
+
"exports": {
|
|
38
|
+
".": {
|
|
39
|
+
"types": "./dist/index.d.ts",
|
|
40
|
+
"import": "./dist/index.js"
|
|
41
|
+
},
|
|
42
|
+
"./occlusion": {
|
|
43
|
+
"types": "./dist/occlusion.d.ts",
|
|
44
|
+
"import": "./dist/occlusion.js"
|
|
45
|
+
},
|
|
46
|
+
"./doppler": {
|
|
47
|
+
"types": "./dist/doppler.d.ts",
|
|
48
|
+
"import": "./dist/doppler.js"
|
|
49
|
+
},
|
|
50
|
+
"./outdoor": {
|
|
51
|
+
"types": "./dist/outdoor.d.ts",
|
|
52
|
+
"import": "./dist/outdoor.js"
|
|
53
|
+
},
|
|
54
|
+
"./events": {
|
|
55
|
+
"types": "./dist/events.d.ts",
|
|
56
|
+
"import": "./dist/events.js"
|
|
57
|
+
},
|
|
58
|
+
"./music": {
|
|
59
|
+
"types": "./dist/music.d.ts",
|
|
60
|
+
"import": "./dist/music.js"
|
|
61
|
+
},
|
|
62
|
+
"./zones": {
|
|
63
|
+
"types": "./dist/zones.d.ts",
|
|
64
|
+
"import": "./dist/zones.js"
|
|
65
|
+
},
|
|
66
|
+
"./ambisonics": {
|
|
67
|
+
"types": "./dist/ambisonics.d.ts",
|
|
68
|
+
"import": "./dist/ambisonics.js"
|
|
69
|
+
},
|
|
70
|
+
"./pan": {
|
|
71
|
+
"types": "./dist/pan.d.ts",
|
|
72
|
+
"import": "./dist/pan.js"
|
|
73
|
+
},
|
|
74
|
+
"./binaural": {
|
|
75
|
+
"types": "./dist/binaural.d.ts",
|
|
76
|
+
"import": "./dist/binaural.js"
|
|
77
|
+
},
|
|
78
|
+
"./voices": {
|
|
79
|
+
"types": "./dist/voice-manager.d.ts",
|
|
80
|
+
"import": "./dist/voice-manager.js"
|
|
81
|
+
},
|
|
82
|
+
"./sprites": {
|
|
83
|
+
"types": "./dist/sprites.d.ts",
|
|
84
|
+
"import": "./dist/sprites.js"
|
|
85
|
+
},
|
|
86
|
+
"./spectrogram": {
|
|
87
|
+
"types": "./dist/spectrogram.d.ts",
|
|
88
|
+
"import": "./dist/spectrogram.js"
|
|
89
|
+
},
|
|
90
|
+
"./wav": {
|
|
91
|
+
"types": "./dist/wav.d.ts",
|
|
92
|
+
"import": "./dist/wav.js"
|
|
93
|
+
},
|
|
94
|
+
"./scan": {
|
|
95
|
+
"types": "./dist/scan.d.ts",
|
|
96
|
+
"import": "./dist/scan.js"
|
|
97
|
+
},
|
|
98
|
+
"./resample": {
|
|
99
|
+
"types": "./dist/resample.d.ts",
|
|
100
|
+
"import": "./dist/resample.js"
|
|
101
|
+
},
|
|
102
|
+
"./stretch": {
|
|
103
|
+
"types": "./dist/stretch.d.ts",
|
|
104
|
+
"import": "./dist/stretch.js"
|
|
105
|
+
},
|
|
106
|
+
"./vocoder": {
|
|
107
|
+
"types": "./dist/vocoder.d.ts",
|
|
108
|
+
"import": "./dist/vocoder.js"
|
|
109
|
+
}
|
|
110
|
+
},
|
|
111
|
+
"files": [
|
|
112
|
+
"dist",
|
|
113
|
+
"NOTICE"
|
|
114
|
+
],
|
|
115
|
+
"peerDependencies": {
|
|
116
|
+
"@margoengine/core": "^1.0.0",
|
|
117
|
+
"@margoengine/bvh": "^1.0.0",
|
|
118
|
+
"@margoengine/mixer": "^1.0.0",
|
|
119
|
+
"@margoengine/compute": "^1.0.0"
|
|
120
|
+
},
|
|
121
|
+
"peerDependenciesMeta": {
|
|
122
|
+
"@margoengine/bvh": {
|
|
123
|
+
"optional": true
|
|
124
|
+
},
|
|
125
|
+
"@margoengine/mixer": {
|
|
126
|
+
"optional": true
|
|
127
|
+
},
|
|
128
|
+
"@margoengine/compute": {
|
|
129
|
+
"optional": true
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|