@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
|
@@ -0,0 +1,440 @@
|
|
|
1
|
+
import { i as e, r as t, t as n } from "./errors-D8rc8kzg.js";
|
|
2
|
+
//#region src/spectrogram-fft.ts
|
|
3
|
+
var r = /* @__PURE__ */ new Map();
|
|
4
|
+
function i(e) {
|
|
5
|
+
let n = r.get(e);
|
|
6
|
+
if (n) return n;
|
|
7
|
+
if (!Number.isInteger(e) || e < 2 || e > 65536 || e & e - 1) throw t(`FFT size must be a power of two from 2 to 65536, got ${e}`, "state");
|
|
8
|
+
let i = new Float64Array(e / 2), a = new Float64Array(e / 2), o = new Uint32Array(e), s = Math.log2(e);
|
|
9
|
+
for (let t = 0; t < e / 2; t++) i[t] = Math.cos(2 * Math.PI * t / e), a[t] = -Math.sin(2 * Math.PI * t / e);
|
|
10
|
+
for (let t = 0; t < e; t++) {
|
|
11
|
+
let e = 0;
|
|
12
|
+
for (let n = 0; n < s; n++) e |= (t >> n & 1) << s - 1 - n;
|
|
13
|
+
o[t] = e;
|
|
14
|
+
}
|
|
15
|
+
return r.size >= 8 && r.delete(r.keys().next().value), r.set(e, n = {
|
|
16
|
+
size: e,
|
|
17
|
+
cos: i,
|
|
18
|
+
sin: a,
|
|
19
|
+
reverse: o
|
|
20
|
+
}), n;
|
|
21
|
+
}
|
|
22
|
+
function a(e, t, n, r = !1) {
|
|
23
|
+
let { size: i, cos: a, sin: o, reverse: s } = e;
|
|
24
|
+
for (let e = 0; e < i; e++) {
|
|
25
|
+
let r = s[e];
|
|
26
|
+
if (r > e) {
|
|
27
|
+
let i = t[e];
|
|
28
|
+
t[e] = t[r], t[r] = i, i = n[e], n[e] = n[r], n[r] = i;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
let c = r ? -1 : 1;
|
|
32
|
+
for (let e = 2; e <= i; e *= 2) {
|
|
33
|
+
let r = e / 2, s = i / e;
|
|
34
|
+
for (let l = 0; l < i; l += e) for (let e = 0, i = 0; e < r; e++, i += s) {
|
|
35
|
+
let s = a[i], u = c * o[i], d = l + e, f = d + r, p = t[f] * s - n[f] * u, m = t[f] * u + n[f] * s;
|
|
36
|
+
t[f] = t[d] - p, n[f] = n[d] - m, t[d] += p, n[d] += m;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
function o(e, t, n, r, i, o, s, c, l) {
|
|
41
|
+
let u = e.size;
|
|
42
|
+
r.set(t), i.set(n), a(e, r, i);
|
|
43
|
+
for (let e = 0; e <= u / 2; e++) {
|
|
44
|
+
let t = u - e & u - 1;
|
|
45
|
+
o[e] = (r[e] + r[t]) / 2, s[e] = (i[e] - i[t]) / 2, c[e] = (i[e] + i[t]) / 2, l[e] = (r[t] - r[e]) / 2;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
function s(e, t, n, r, i, o, s, c, l) {
|
|
49
|
+
let u = e.size;
|
|
50
|
+
for (let e = 0; e <= u / 2; e++) {
|
|
51
|
+
let a = u - e & u - 1, c = e === 0 || e === u / 2 ? 0 : n[e], l = e === 0 || e === u / 2 ? 0 : i[e];
|
|
52
|
+
o[e] = t[e] - l, s[e] = c + r[e], o[a] = t[e] + l, s[a] = -c + r[e];
|
|
53
|
+
}
|
|
54
|
+
a(e, o, s, !0);
|
|
55
|
+
let d = 1 / u;
|
|
56
|
+
for (let e = 0; e < u; e++) c[e] = o[e] * d, l[e] = s[e] * d;
|
|
57
|
+
}
|
|
58
|
+
//#endregion
|
|
59
|
+
//#region src/spectrogram-windows.ts
|
|
60
|
+
function c(e, t, n) {
|
|
61
|
+
l(e);
|
|
62
|
+
let r = new Float64Array(e), i = n.symmetric ? Math.max(e - 1, 1) : e;
|
|
63
|
+
for (let n = 0; n < e; n++) {
|
|
64
|
+
let e = 0;
|
|
65
|
+
for (let r = 0; r < t.length; r++) e += (r % 2 ? -1 : 1) * t[r] * Math.cos(2 * Math.PI * r * n / i);
|
|
66
|
+
r[n] = e;
|
|
67
|
+
}
|
|
68
|
+
return r;
|
|
69
|
+
}
|
|
70
|
+
function l(e) {
|
|
71
|
+
if (!Number.isInteger(e) || e < 1) throw t(`Window size must be a whole number of at least 1, got ${e}`, "state");
|
|
72
|
+
}
|
|
73
|
+
function u(e) {
|
|
74
|
+
let t = 1, n = 1;
|
|
75
|
+
for (let r = 1; r < 200 && n > 1e-17 * t; r++) n *= (e / (2 * r)) ** 2, t += n;
|
|
76
|
+
return t;
|
|
77
|
+
}
|
|
78
|
+
var d = {
|
|
79
|
+
rectangular(e) {
|
|
80
|
+
return l(e), new Float64Array(e).fill(1);
|
|
81
|
+
},
|
|
82
|
+
hann: (e, t = {}) => c(e, [.5, .5], t),
|
|
83
|
+
hamming: (e, t = {}) => c(e, [.54, .46], t),
|
|
84
|
+
blackman: (e, t = {}) => c(e, [
|
|
85
|
+
.42,
|
|
86
|
+
.5,
|
|
87
|
+
.08
|
|
88
|
+
], t),
|
|
89
|
+
blackmanHarris: (e, t = {}) => c(e, [
|
|
90
|
+
.35875,
|
|
91
|
+
.48829,
|
|
92
|
+
.14128,
|
|
93
|
+
.01168
|
|
94
|
+
], t),
|
|
95
|
+
kaiser(e, n = 8.6, r = {}) {
|
|
96
|
+
if (l(e), !(n >= 0) || !Number.isFinite(n)) throw t(`Kaiser beta must be 0 or more, got ${n}`, "state");
|
|
97
|
+
let i = new Float64Array(e), a = (r.symmetric ? Math.max(e - 1, 1) : e) / 2, o = u(n);
|
|
98
|
+
for (let t = 0; t < e; t++) {
|
|
99
|
+
let e = (t - a) / a;
|
|
100
|
+
i[t] = u(n * Math.sqrt(Math.max(0, 1 - e * e))) / o;
|
|
101
|
+
}
|
|
102
|
+
return i;
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
function f(e, n) {
|
|
106
|
+
if (e === void 0 || e === "hann") return d.hann(n);
|
|
107
|
+
if (typeof e != "string") {
|
|
108
|
+
if (e.length !== n) throw t(`A window array must hold ${n} numbers, got ${e.length}`, "state");
|
|
109
|
+
return Float64Array.from(e);
|
|
110
|
+
}
|
|
111
|
+
switch (e) {
|
|
112
|
+
case "hamming": return d.hamming(n);
|
|
113
|
+
case "blackman": return d.blackman(n);
|
|
114
|
+
case "blackman-harris": return d.blackmanHarris(n);
|
|
115
|
+
case "kaiser": return d.kaiser(n);
|
|
116
|
+
case "rectangular": return d.rectangular(n);
|
|
117
|
+
}
|
|
118
|
+
throw t(`Unknown window "${String(e)}"; use hann, hamming, blackman, blackman-harris, kaiser or rectangular`, "state");
|
|
119
|
+
}
|
|
120
|
+
//#endregion
|
|
121
|
+
//#region \0@oxc-project+runtime@0.153.0/helpers/esm/usingCtx.js
|
|
122
|
+
function p() {
|
|
123
|
+
var e = typeof SuppressedError == "function" ? SuppressedError : function(e, t) {
|
|
124
|
+
var n = Error();
|
|
125
|
+
return n.name = "SuppressedError", n.error = e, n.suppressed = t, n;
|
|
126
|
+
}, t = {}, n = [];
|
|
127
|
+
function r(e, t) {
|
|
128
|
+
if (t != null) {
|
|
129
|
+
if (Object(t) !== t) throw TypeError("using declarations can only be used with objects, functions, null, or undefined.");
|
|
130
|
+
if (e) var r = t[Symbol.asyncDispose || Symbol.for("Symbol.asyncDispose")];
|
|
131
|
+
if (r === void 0 && (r = t[Symbol.dispose || Symbol.for("Symbol.dispose")], e)) var i = r;
|
|
132
|
+
if (typeof r != "function") throw TypeError("Object is not disposable.");
|
|
133
|
+
i && (r = function() {
|
|
134
|
+
try {
|
|
135
|
+
i.call(t);
|
|
136
|
+
} catch (e) {
|
|
137
|
+
return Promise.reject(e);
|
|
138
|
+
}
|
|
139
|
+
}), n.push({
|
|
140
|
+
v: t,
|
|
141
|
+
d: r,
|
|
142
|
+
a: e
|
|
143
|
+
});
|
|
144
|
+
} else e && n.push({
|
|
145
|
+
d: t,
|
|
146
|
+
a: e
|
|
147
|
+
});
|
|
148
|
+
return t;
|
|
149
|
+
}
|
|
150
|
+
return {
|
|
151
|
+
e: t,
|
|
152
|
+
u: r.bind(null, !1),
|
|
153
|
+
a: r.bind(null, !0),
|
|
154
|
+
d: function() {
|
|
155
|
+
var r, i = this.e, a = 0;
|
|
156
|
+
function o() {
|
|
157
|
+
for (; r = n.pop();) try {
|
|
158
|
+
if (!r.a && a === 1) return a = 0, n.push(r), Promise.resolve().then(o);
|
|
159
|
+
if (r.d) {
|
|
160
|
+
var e = r.d.call(r.v);
|
|
161
|
+
if (r.a) return a |= 2, Promise.resolve(e).then(o, s);
|
|
162
|
+
} else a |= 1;
|
|
163
|
+
} catch (e) {
|
|
164
|
+
return s(e);
|
|
165
|
+
}
|
|
166
|
+
if (a === 1) return i === t ? Promise.resolve() : Promise.reject(i);
|
|
167
|
+
if (i !== t) throw i;
|
|
168
|
+
}
|
|
169
|
+
function s(n) {
|
|
170
|
+
return i = i === t ? n : new e(n, i), o();
|
|
171
|
+
}
|
|
172
|
+
return o();
|
|
173
|
+
}
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
//#endregion
|
|
177
|
+
//#region src/spectrogram.ts
|
|
178
|
+
var m = (e) => {
|
|
179
|
+
throw t(e, "state");
|
|
180
|
+
}, h = 2 ** 27;
|
|
181
|
+
function g(e, t) {
|
|
182
|
+
let n = t.size ?? 2048, r = t.hop ?? Math.max(1, n / 4), i = t.center ?? !0, a = t.sampleRate ?? 44100, o = t.pad ?? "reflect";
|
|
183
|
+
(!Number.isInteger(n) || n < 32 || n > 65536 || n & n - 1) && m(`STFT size must be a power of two from 32 to 65536, got ${n}`), (!Number.isInteger(r) || r < 1 || r > n) && m(`STFT hop must be a whole number from 1 to size (${n}), got ${r}`), (!(a > 0) || !Number.isFinite(a)) && m(`Sample rate must be a positive number, got ${a}`), o !== "reflect" && o !== "zero" && o !== "edge" && m(`Unknown pad "${String(o)}"; use reflect, zero or edge`), e < 1 && m("STFT needs at least one sample"), !i && e < n && m(`Without centring the signal needs at least size (${n}) samples, got ${e}`);
|
|
184
|
+
let s = i ? 1 + Math.floor(e / r) : 1 + Math.floor((e - n) / r), c = n / 2 + 1;
|
|
185
|
+
return s * c > h && m(`${s} frames of ${c} bins is over ${h} values; use a larger hop or a shorter signal`), {
|
|
186
|
+
size: n,
|
|
187
|
+
hop: r,
|
|
188
|
+
window: f(t.window, n),
|
|
189
|
+
center: i,
|
|
190
|
+
sampleRate: a,
|
|
191
|
+
frames: s,
|
|
192
|
+
bins: c,
|
|
193
|
+
pad: o
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
function _(t) {
|
|
197
|
+
if (typeof t != "object" || !t || typeof t.length != "number") throw e("Samples must be a Float32Array, Float64Array or array of numbers", "state");
|
|
198
|
+
for (let e = 0; e < t.length; e++) Number.isFinite(t[e]) || m(`Sample ${e} is ${t[e]}; samples must be finite numbers`);
|
|
199
|
+
return t;
|
|
200
|
+
}
|
|
201
|
+
var v = (e, t) => {
|
|
202
|
+
if (t === 1) return 0;
|
|
203
|
+
let n = 2 * (t - 1), r = (e % n + n) % n;
|
|
204
|
+
return r < t ? r : n - r;
|
|
205
|
+
};
|
|
206
|
+
function y(e, t) {
|
|
207
|
+
let n = e.length, r = t.center ? t.size / 2 : 0, i = new Float64Array(t.center ? n + t.size : n);
|
|
208
|
+
for (let a = 0; a < i.length; a++) {
|
|
209
|
+
let o = a - r;
|
|
210
|
+
o >= 0 && o < n ? i[a] = e[o] : t.pad === "reflect" ? i[a] = e[v(o, n)] : t.pad === "edge" && (i[a] = e[o < 0 ? 0 : n - 1]);
|
|
211
|
+
}
|
|
212
|
+
return i;
|
|
213
|
+
}
|
|
214
|
+
var b = class {
|
|
215
|
+
#e;
|
|
216
|
+
#t;
|
|
217
|
+
#n;
|
|
218
|
+
#r;
|
|
219
|
+
#i;
|
|
220
|
+
#a;
|
|
221
|
+
#o;
|
|
222
|
+
#s;
|
|
223
|
+
constructor(e, t, n, r) {
|
|
224
|
+
this.size = e, this.hop = t, this.window = n, this.frames = r, this.fft = i(e), this.bins = e / 2 + 1, this.span = (r - 1) * t + e, this.#e = new Float64Array(e), this.#t = new Float64Array(e), this.#n = new Float64Array(e), this.#r = new Float64Array(e), this.#i = new Float64Array(this.bins), this.#a = new Float64Array(this.bins), this.#o = new Float64Array(this.bins), this.#s = new Float64Array(this.bins);
|
|
225
|
+
let a = new Float64Array(this.span);
|
|
226
|
+
for (let i = 0; i < r; i++) for (let r = 0; r < e; r++) a[i * t + r] += n[r] * n[r];
|
|
227
|
+
this.inverseEnvelope = a.map((e) => e > 1e-12 ? 1 / e : 0);
|
|
228
|
+
}
|
|
229
|
+
analyse(e, t, n, r) {
|
|
230
|
+
let { size: i, hop: a, window: s, frames: c, bins: l } = this;
|
|
231
|
+
for (let u = 0; u < c; u += 2) {
|
|
232
|
+
r?.throwIfAborted();
|
|
233
|
+
let d = u + 1 < c;
|
|
234
|
+
for (let t = 0; t < i; t++) this.#e[t] = e[u * a + t] * s[t], this.#t[t] = d ? e[(u + 1) * a + t] * s[t] : 0;
|
|
235
|
+
o(this.fft, this.#e, this.#t, this.#n, this.#r, this.#i, this.#a, this.#o, this.#s);
|
|
236
|
+
for (let e = 0; e < l; e++) t[u * l + e] = this.#i[e], n[u * l + e] = this.#a[e], d && (t[(u + 1) * l + e] = this.#o[e], n[(u + 1) * l + e] = this.#s[e]);
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
synthesise(e, t, n, r) {
|
|
240
|
+
let { size: i, hop: a, window: o, frames: c, bins: l } = this;
|
|
241
|
+
n.fill(0);
|
|
242
|
+
for (let u = 0; u < c; u += 2) {
|
|
243
|
+
r?.throwIfAborted();
|
|
244
|
+
let d = u + 1 < c;
|
|
245
|
+
for (let n = 0; n < l; n++) this.#i[n] = e[u * l + n], this.#a[n] = t[u * l + n], this.#o[n] = d ? e[(u + 1) * l + n] : 0, this.#s[n] = d ? t[(u + 1) * l + n] : 0;
|
|
246
|
+
s(this.fft, this.#i, this.#a, this.#o, this.#s, this.#n, this.#r, this.#e, this.#t);
|
|
247
|
+
for (let e = 0; e < i; e++) n[u * a + e] += this.#e[e] * o[e], d && (n[(u + 1) * a + e] += this.#t[e] * o[e]);
|
|
248
|
+
}
|
|
249
|
+
for (let e = 0; e < n.length; e++) n[e] *= this.inverseEnvelope[e];
|
|
250
|
+
}
|
|
251
|
+
};
|
|
252
|
+
function x(e, t) {
|
|
253
|
+
let n = Infinity, r = 0;
|
|
254
|
+
for (let i = 0; i < Math.min(t, e.length); i++) {
|
|
255
|
+
let a = 0;
|
|
256
|
+
for (let n = i; n < e.length; n += t) a += e[n] * e[n];
|
|
257
|
+
n = Math.min(n, a), r = Math.max(r, a);
|
|
258
|
+
}
|
|
259
|
+
return r > 0 ? n / r : 0;
|
|
260
|
+
}
|
|
261
|
+
function S(e, t) {
|
|
262
|
+
let r = x(e, t);
|
|
263
|
+
if (!(r >= .1)) throw n("state", `Window and hop do not overlap-add evenly (smallest over largest summed squared window is ${r.toFixed(3)}, needs 0.1); use a hop of size / 4 or size / 2 with a Hann window`);
|
|
264
|
+
}
|
|
265
|
+
function C(e, t = {}) {
|
|
266
|
+
let n = _(e), r = g(n.length, t), i = t.signal, a = y(n, r);
|
|
267
|
+
i?.throwIfAborted();
|
|
268
|
+
let o = new Float32Array(r.frames * r.bins), s = new Float32Array(r.frames * r.bins), c = {
|
|
269
|
+
real: o,
|
|
270
|
+
imag: s,
|
|
271
|
+
frames: r.frames,
|
|
272
|
+
bins: r.bins,
|
|
273
|
+
size: r.size,
|
|
274
|
+
hop: r.hop,
|
|
275
|
+
sampleRate: r.sampleRate,
|
|
276
|
+
center: r.center,
|
|
277
|
+
length: n.length,
|
|
278
|
+
window: r.window
|
|
279
|
+
};
|
|
280
|
+
return "gpu" in t && t.gpu ? w(t.gpu, a, r, c, i) : (new b(r.size, r.hop, r.window, r.frames).analyse(a, o, s, i), c);
|
|
281
|
+
}
|
|
282
|
+
async function w(e, t, n, r, i) {
|
|
283
|
+
let { fft: a } = await import("@margoengine/compute/fft"), { size: o, hop: s, window: c, bins: l } = n, u = Math.max(1, Math.floor(2 ** 22 / o));
|
|
284
|
+
for (let f = 0; f < n.frames; f += u) try {
|
|
285
|
+
var d = p();
|
|
286
|
+
i?.throwIfAborted();
|
|
287
|
+
let m = Math.min(u, n.frames - f), h = new Float32Array(m * o);
|
|
288
|
+
for (let e = 0; e < m; e++) for (let n = 0; n < o; n++) h[e * o + n] = t[(f + e) * s + n] * c[n];
|
|
289
|
+
let { re: g, im: _ } = a(d.u(e.array(h, { shape: [m, o] })));
|
|
290
|
+
try {
|
|
291
|
+
let [e, t] = await Promise.all([g.read({ signal: i }), _.read({ signal: i })]);
|
|
292
|
+
for (let n = 0; n < m; n++) for (let i = 0; i < l; i++) r.real[(f + n) * l + i] = e[n * o + i], r.imag[(f + n) * l + i] = t[n * o + i];
|
|
293
|
+
} finally {
|
|
294
|
+
g.dispose(), _.dispose();
|
|
295
|
+
}
|
|
296
|
+
} catch (e) {
|
|
297
|
+
d.e = e;
|
|
298
|
+
} finally {
|
|
299
|
+
d.d();
|
|
300
|
+
}
|
|
301
|
+
return r;
|
|
302
|
+
}
|
|
303
|
+
function T(e, t = {}) {
|
|
304
|
+
S(e.window, e.hop);
|
|
305
|
+
let n = new b(e.size, e.hop, e.window, e.frames), r = new Float64Array(n.span);
|
|
306
|
+
return n.synthesise(e.real, e.imag, r, t.signal), E(r, e, t.length);
|
|
307
|
+
}
|
|
308
|
+
function E(e, t, n) {
|
|
309
|
+
let r = t.center ? t.size / 2 : 0, i = n ?? t.length;
|
|
310
|
+
return (!Number.isInteger(i) || i < 0 || r + i > e.length) && m(`Length must be a whole number from 0 to ${e.length - r}, got ${i}`), Float32Array.from(e.subarray(r, r + i));
|
|
311
|
+
}
|
|
312
|
+
var D = [
|
|
313
|
+
[
|
|
314
|
+
0,
|
|
315
|
+
0,
|
|
316
|
+
0
|
|
317
|
+
],
|
|
318
|
+
[
|
|
319
|
+
60,
|
|
320
|
+
0,
|
|
321
|
+
100
|
|
322
|
+
],
|
|
323
|
+
[
|
|
324
|
+
190,
|
|
325
|
+
40,
|
|
326
|
+
80
|
|
327
|
+
],
|
|
328
|
+
[
|
|
329
|
+
250,
|
|
330
|
+
150,
|
|
331
|
+
20
|
|
332
|
+
],
|
|
333
|
+
[
|
|
334
|
+
255,
|
|
335
|
+
250,
|
|
336
|
+
200
|
|
337
|
+
]
|
|
338
|
+
], O = (e) => {
|
|
339
|
+
let t = Math.min(.999999, Math.max(0, e)) * (D.length - 1), n = Math.floor(t), r = t - n;
|
|
340
|
+
return [
|
|
341
|
+
0,
|
|
342
|
+
1,
|
|
343
|
+
2
|
|
344
|
+
].map((e) => D[n][e] + r * (D[n + 1][e] - D[n][e]));
|
|
345
|
+
};
|
|
346
|
+
function k(e, t = {}) {
|
|
347
|
+
let n = t.dB ?? !0, r = t.floor ?? -100, [i, a] = t.range ?? [r, 0], o = e.frames * e.bins, s = new Float64Array(o);
|
|
348
|
+
(!(r < 0) || !(i < a)) && m(`Floor must be below 0 and range [low, high] needs low < high, got floor ${r}, range [${i}, ${a}]`);
|
|
349
|
+
let c = 0;
|
|
350
|
+
for (let t = 0; t < o; t++) s[t] = e.real[t] ** 2 + e.imag[t] ** 2, s[t] > c && (c = s[t]);
|
|
351
|
+
let l = t.ref === void 0 || t.ref === "max" ? c : t.ref;
|
|
352
|
+
!(l >= 0) && l !== 0 && m(`Reference power must be a number of 0 or more, got ${String(t.ref)}`);
|
|
353
|
+
let u = new Float32Array(o);
|
|
354
|
+
for (let e = 0; e < o; e++) u[e] = n ? Math.max(r, 10 * Math.log10(Math.max(s[e], 1e-30) / Math.max(l, 1e-30))) : s[e];
|
|
355
|
+
let d = t.origin === "high", f = (t) => d ? e.bins - 1 - t : t, p = t.colormap === "heat" ? O : t.colormap, h = (e) => Math.min(1, Math.max(0, (e - i) / (a - i)));
|
|
356
|
+
if (t.format === "f32" && !p) {
|
|
357
|
+
let t = new Float32Array(o);
|
|
358
|
+
for (let n = 0; n < e.bins; n++) for (let r = 0; r < e.frames; r++) t[n * e.frames + r] = u[r * e.bins + f(n)];
|
|
359
|
+
return {
|
|
360
|
+
width: e.frames,
|
|
361
|
+
height: e.bins,
|
|
362
|
+
channels: 1,
|
|
363
|
+
data: t
|
|
364
|
+
};
|
|
365
|
+
}
|
|
366
|
+
if (p) {
|
|
367
|
+
let t = new Uint8Array(4 * o);
|
|
368
|
+
for (let n = 0; n < e.bins; n++) for (let r = 0; r < e.frames; r++) {
|
|
369
|
+
let [i, a, o] = p(h(u[r * e.bins + f(n)])), s = 4 * (n * e.frames + r);
|
|
370
|
+
t[s] = Math.round(i), t[s + 1] = Math.round(a), t[s + 2] = Math.round(o), t[s + 3] = 255;
|
|
371
|
+
}
|
|
372
|
+
return {
|
|
373
|
+
width: e.frames,
|
|
374
|
+
height: e.bins,
|
|
375
|
+
channels: 4,
|
|
376
|
+
data: t
|
|
377
|
+
};
|
|
378
|
+
}
|
|
379
|
+
let g = new Uint8Array(o);
|
|
380
|
+
for (let t = 0; t < e.bins; t++) for (let n = 0; n < e.frames; n++) g[t * e.frames + n] = Math.round(255 * h(u[n * e.bins + f(t)]));
|
|
381
|
+
return {
|
|
382
|
+
width: e.frames,
|
|
383
|
+
height: e.bins,
|
|
384
|
+
channels: 1,
|
|
385
|
+
data: g
|
|
386
|
+
};
|
|
387
|
+
}
|
|
388
|
+
function A(e, t = {}) {
|
|
389
|
+
let { size: n, hop: r, frames: i } = e, a = e.center ?? !0, o = t.iterations ?? 32, s = t.momentum ?? .99, c = f(e.window, n), l = n / 2 + 1;
|
|
390
|
+
g(a ? Math.max(1, (i - 1) * r) : n + (i - 1) * r, {
|
|
391
|
+
size: n,
|
|
392
|
+
hop: r,
|
|
393
|
+
center: a,
|
|
394
|
+
window: c
|
|
395
|
+
}), (!Number.isInteger(i) || i < 1 || e.magnitude.length !== i * l) && m(`Magnitude needs frames x ${l} values; got ${e.magnitude.length} for ${i} frames`), (!Number.isInteger(o) || o < 1 || o > 1e4) && m(`Iterations must be a whole number from 1 to 10000, got ${o}`), s >= 0 && s <= .999 || m(`Momentum must be from 0 to 0.999, got ${s}`), S(c, r);
|
|
396
|
+
let u = i * l, d = Float64Array.from(e.magnitude), p = 0;
|
|
397
|
+
for (let e = 0; e < u; e++) (!(d[e] >= 0) || !Number.isFinite(d[e])) && m(`Magnitude ${e} is ${d[e]}; magnitudes must be finite and at least 0`), p += d[e] * d[e];
|
|
398
|
+
let h = new b(n, r, c, i), _ = new Float64Array(u), v = new Float64Array(u), y = new Float64Array(u), x = new Float64Array(u), C = new Float64Array(u), w = new Float64Array(u), T = new Float64Array(h.span), D = new Float64Array(o), O = t.init ?? "random";
|
|
399
|
+
if (typeof O == "object") {
|
|
400
|
+
(O.frames !== i || O.size !== n) && m("The init spectrum must have the same frames and size as the magnitude");
|
|
401
|
+
for (let e = 0; e < u; e++) {
|
|
402
|
+
let t = Math.hypot(O.real[e], O.imag[e]);
|
|
403
|
+
_[e] = t > 0 ? d[e] * O.real[e] / t : d[e], v[e] = t > 0 ? d[e] * O.imag[e] / t : 0;
|
|
404
|
+
}
|
|
405
|
+
} else if (O === "zero") _.set(d);
|
|
406
|
+
else if (O === "random") {
|
|
407
|
+
let e = (t.seed ?? 1) >>> 0;
|
|
408
|
+
for (let t = 0; t < u; t++) {
|
|
409
|
+
e = e + 1831565813 >>> 0;
|
|
410
|
+
let n = e;
|
|
411
|
+
n = Math.imul(n ^ n >>> 15, n | 1), n ^= n + Math.imul(n ^ n >>> 7, n | 61);
|
|
412
|
+
let r = 2 * Math.PI * ((n ^ n >>> 14) >>> 0) / 4294967296;
|
|
413
|
+
_[t] = d[t] * Math.cos(r), v[t] = d[t] * Math.sin(r);
|
|
414
|
+
}
|
|
415
|
+
} else m(`Unknown init "${String(O)}"; use random, zero or a Spectrum`);
|
|
416
|
+
for (let e = 0; e < i; e++) v[e * l] = 0, v[e * l + l - 1] = 0;
|
|
417
|
+
y.set(_), x.set(v);
|
|
418
|
+
for (let e = 0; e < o; e++) {
|
|
419
|
+
t.signal?.throwIfAborted(), h.synthesise(y, x, T, t.signal), h.analyse(T, C, w, t.signal);
|
|
420
|
+
let n = 0;
|
|
421
|
+
for (let e = 0; e < u; e++) {
|
|
422
|
+
let t = Math.hypot(C[e], w[e]), r = d[e] - t;
|
|
423
|
+
n += r * r;
|
|
424
|
+
let i = t > 1e-30 ? d[e] * C[e] / t : d[e], a = t > 1e-30 ? d[e] * w[e] / t : 0;
|
|
425
|
+
y[e] = i + s * (i - _[e]), x[e] = a + s * (a - v[e]), _[e] = i, v[e] = a;
|
|
426
|
+
}
|
|
427
|
+
D[e] = p > 0 ? Math.sqrt(n / p) : 0;
|
|
428
|
+
}
|
|
429
|
+
return h.synthesise(_, v, T, t.signal), {
|
|
430
|
+
samples: E(T, {
|
|
431
|
+
size: n,
|
|
432
|
+
center: a,
|
|
433
|
+
length: e.length ?? (a ? (i - 1) * r : h.span)
|
|
434
|
+
}, e.length),
|
|
435
|
+
convergence: D,
|
|
436
|
+
transforms: o * 2 * i + i
|
|
437
|
+
};
|
|
438
|
+
}
|
|
439
|
+
//#endregion
|
|
440
|
+
export { T as istft, x as overlapRatio, A as resynthesize, k as spectrogram, C as stft, d as windows };
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/// <reference lib="esnext.disposable" preserve="true" />
|
|
2
|
+
import { Audio, type AudioListener, type AudioOptions, type LoadAudioOptions } from '@margoengine/audio';
|
|
3
|
+
/** A named interval in a shared decoded audio buffer, in seconds. */
|
|
4
|
+
export interface AudioSprite {
|
|
5
|
+
/** Start in buffer seconds, finite and nonnegative. */
|
|
6
|
+
offset: number;
|
|
7
|
+
/** Positive finite buffer seconds, wholly within the buffer. */
|
|
8
|
+
duration: number;
|
|
9
|
+
/** Repeat only this interval. Default false. */
|
|
10
|
+
loop?: boolean;
|
|
11
|
+
}
|
|
12
|
+
/** Sound options independent of the sprite's authored interval/loop. */
|
|
13
|
+
export type AudioSpritePlayOptions = Omit<AudioOptions, 'offset' | 'duration' | 'loopStart' | 'loopEnd' | 'loop' | 'autoplay'>;
|
|
14
|
+
/** Named, overlapping clips sharing one buffer; no per-play buffer slicing or copying. */
|
|
15
|
+
export declare class AudioSpriteBank {
|
|
16
|
+
readonly listener: AudioListener;
|
|
17
|
+
readonly buffer: AudioBuffer;
|
|
18
|
+
private readonly sprites;
|
|
19
|
+
private readonly sounds;
|
|
20
|
+
/** Instances started by play(): released by the bank on natural end or stopAll. */
|
|
21
|
+
private readonly oneShots;
|
|
22
|
+
private disposed;
|
|
23
|
+
constructor(listener: AudioListener, buffer: AudioBuffer, sprites: Readonly<Record<string, AudioSprite>>);
|
|
24
|
+
/** Available sprite names, copied in map order. */
|
|
25
|
+
get names(): readonly string[];
|
|
26
|
+
/**
|
|
27
|
+
* Create a stopped clip with its authored loop bounds. The caller owns it: it can be played again after it ends or
|
|
28
|
+
* is stopped, until the caller or the bank disposes it.
|
|
29
|
+
*/
|
|
30
|
+
create(name: string, options?: AudioSpritePlayOptions): Audio;
|
|
31
|
+
/**
|
|
32
|
+
* Create and start an independent fire-and-forget instance; delay defaults to 0 audio-clock seconds. The bank
|
|
33
|
+
* releases it when it ends naturally or {@link stopAll} stops it; dispose one you stop yourself.
|
|
34
|
+
*/
|
|
35
|
+
play(name: string, options?: AudioSpritePlayOptions, delay?: number): Audio;
|
|
36
|
+
/** Stop every instance. play() instances are released; create() clips stay owned and can play again. */
|
|
37
|
+
stopAll(): void;
|
|
38
|
+
private release;
|
|
39
|
+
/** @internal Forget caller-disposed sounds on listener updates. */
|
|
40
|
+
update(): void;
|
|
41
|
+
/** Stop/release all owned instances. The shared buffer remains usable. Idempotent. */
|
|
42
|
+
dispose(): void;
|
|
43
|
+
[Symbol.dispose]: () => void;
|
|
44
|
+
}
|
|
45
|
+
/** A URL and optional explicit MIME/codec declaration, or a URL with a known extension. */
|
|
46
|
+
export type AudioCodecCandidate = string | {
|
|
47
|
+
readonly url: string;
|
|
48
|
+
readonly type: string;
|
|
49
|
+
};
|
|
50
|
+
/** Loading controls plus an injectable browser capability probe for workers or server-side tests. */
|
|
51
|
+
export interface AudioCodecFallbackOptions extends LoadAudioOptions {
|
|
52
|
+
/** Default lazily creates an HTML audio element. Order is the candidate list order; both maybe/probably are eligible. */
|
|
53
|
+
canPlayType?: (type: string) => CanPlayTypeResult;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Try each browser-supported URL once in order until fetching/decoding succeeds.
|
|
57
|
+
* Abort stops the complete operation; exhaustion preserves every failure as an AggregateError cause.
|
|
58
|
+
*/
|
|
59
|
+
export declare function loadAudioFallback(listener: AudioListener, candidates: readonly AudioCodecCandidate[], options?: AudioCodecFallbackOptions): Promise<AudioBuffer>;
|
package/dist/sprites.js
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { r as e, t } from "./errors-D8rc8kzg.js";
|
|
2
|
+
import { Audio as n } from "@margoengine/audio";
|
|
3
|
+
//#region src/sprites.ts
|
|
4
|
+
var r = class {
|
|
5
|
+
constructor(n, r, i) {
|
|
6
|
+
if (this.listener = n, this.buffer = r, this.sprites = /* @__PURE__ */ new Map(), this.sounds = /* @__PURE__ */ new Set(), this.oneShots = /* @__PURE__ */ new WeakSet(), this.disposed = !1, !r || !Number.isFinite(r.duration) || r.duration <= 0) throw t("state", "Audio sprites need a positive-duration decoded buffer; use listener.load first");
|
|
7
|
+
for (let [t, n] of Object.entries(i)) {
|
|
8
|
+
if (!t || !n || !Number.isFinite(n.offset) || n.offset < 0 || !Number.isFinite(n.duration) || n.duration <= 0 || n.offset + n.duration > r.duration || n.loop !== void 0 && typeof n.loop != "boolean") throw e("Audio sprite names and intervals must be valid and within the buffer; use a nonempty name and offset/duration in seconds", "state");
|
|
9
|
+
this.sprites.set(t, Object.freeze({ ...n }));
|
|
10
|
+
}
|
|
11
|
+
n.addSource(this);
|
|
12
|
+
}
|
|
13
|
+
get names() {
|
|
14
|
+
return [...this.sprites.keys()];
|
|
15
|
+
}
|
|
16
|
+
create(e, r = {}) {
|
|
17
|
+
if (this.disposed) throw t("disposed", "AudioSpriteBank is disposed; create a new bank");
|
|
18
|
+
let i = this.sprites.get(e);
|
|
19
|
+
if (!i) throw t("state", `Unknown audio sprite ${e}; choose a name from bank.names`);
|
|
20
|
+
let a = new n(this.listener, {
|
|
21
|
+
...r,
|
|
22
|
+
autoplay: !1,
|
|
23
|
+
offset: i.offset,
|
|
24
|
+
duration: i.duration,
|
|
25
|
+
loop: i.loop ?? !1,
|
|
26
|
+
loopStart: i.offset,
|
|
27
|
+
loopEnd: i.offset + i.duration,
|
|
28
|
+
onEnded: (e) => {
|
|
29
|
+
try {
|
|
30
|
+
r.onEnded?.(e);
|
|
31
|
+
} finally {
|
|
32
|
+
this.oneShots.has(e) && this.release(e);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}).setBuffer(this.buffer);
|
|
36
|
+
return this.sounds.add(a), a;
|
|
37
|
+
}
|
|
38
|
+
play(t, n = {}, r = 0) {
|
|
39
|
+
if (!Number.isFinite(r) || r < 0) throw e("Sprite delay must be finite and nonnegative; use seconds", "state");
|
|
40
|
+
let i = this.create(t, n);
|
|
41
|
+
return this.oneShots.add(i), i.play(r);
|
|
42
|
+
}
|
|
43
|
+
stopAll() {
|
|
44
|
+
for (let e of this.sounds) e.isDisposed ? this.sounds.delete(e) : this.oneShots.has(e) ? this.release(e) : e.stop();
|
|
45
|
+
}
|
|
46
|
+
release(e) {
|
|
47
|
+
this.sounds.delete(e), e.dispose();
|
|
48
|
+
}
|
|
49
|
+
update() {
|
|
50
|
+
for (let e of this.sounds) e.isDisposed && this.sounds.delete(e);
|
|
51
|
+
}
|
|
52
|
+
dispose() {
|
|
53
|
+
if (!this.disposed) {
|
|
54
|
+
this.disposed = !0, this.listener.removeSource(this);
|
|
55
|
+
for (let e of this.sounds) e.dispose();
|
|
56
|
+
this.sounds.clear();
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
[Symbol.dispose ?? Symbol()]() {
|
|
60
|
+
this.dispose();
|
|
61
|
+
}
|
|
62
|
+
}, i = {
|
|
63
|
+
mp3: "audio/mpeg",
|
|
64
|
+
ogg: "audio/ogg",
|
|
65
|
+
opus: "audio/ogg; codecs=\"opus\"",
|
|
66
|
+
wav: "audio/wav",
|
|
67
|
+
m4a: "audio/mp4",
|
|
68
|
+
mp4: "audio/mp4",
|
|
69
|
+
aac: "audio/aac",
|
|
70
|
+
webm: "audio/webm",
|
|
71
|
+
flac: "audio/flac"
|
|
72
|
+
};
|
|
73
|
+
async function a(e, n, r = {}) {
|
|
74
|
+
if (r.signal?.throwIfAborted(), !n.length) throw t("state", "Audio fallback needs at least one candidate; pass URLs or {url,type} entries");
|
|
75
|
+
let a = r.canPlayType ?? (() => {
|
|
76
|
+
if (typeof document > "u") throw t("unsupported", "Audio fallback needs canPlayType; pass options.canPlayType outside a document");
|
|
77
|
+
let e = document.createElement("audio");
|
|
78
|
+
return e.canPlayType.bind(e);
|
|
79
|
+
})(), o = n.map((e) => {
|
|
80
|
+
let n = typeof e == "string" ? e : e?.url, r = typeof e == "string" ? i[e.split(/[?#]/)[0].split(".").at(-1).toLowerCase()] : e?.type;
|
|
81
|
+
if (typeof n != "string" || !n || typeof r != "string" || !r) throw t("state", "Audio fallback candidate needs a URL and a known type; pass {url,type} for extensionless URLs");
|
|
82
|
+
return {
|
|
83
|
+
url: n,
|
|
84
|
+
type: r
|
|
85
|
+
};
|
|
86
|
+
}), s = [];
|
|
87
|
+
for (let { url: t, type: n } of o) {
|
|
88
|
+
r.signal?.throwIfAborted();
|
|
89
|
+
let i = a(n);
|
|
90
|
+
if (i === "maybe" || i === "probably") try {
|
|
91
|
+
return await e.load(t, r);
|
|
92
|
+
} catch (e) {
|
|
93
|
+
r.signal?.throwIfAborted(), s.push(e);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
throw s.length ? Object.assign(t("failed", "Every supported audio candidate failed; inspect cause.errors and supply a working URL/codec"), { cause: AggregateError(s, "Audio codec fallback exhausted") }) : t("unsupported", "No audio candidate is supported by this browser; supply another MIME/codec alternative");
|
|
97
|
+
}
|
|
98
|
+
//#endregion
|
|
99
|
+
export { r as AudioSpriteBank, a as loadAudioFallback };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/** Audio as `decodeWav` returns it: a rate and one Float32Array per channel. */
|
|
2
|
+
export interface StretchInput {
|
|
3
|
+
sampleRate: number;
|
|
4
|
+
channels: Float32Array[];
|
|
5
|
+
}
|
|
6
|
+
/** Options of {@link timeStretch}. */
|
|
7
|
+
export interface StretchOptions {
|
|
8
|
+
/** Frame length in milliseconds, 10 to 200; the synthesis hop is half of it. Default 40, a few pitch periods of speech. */
|
|
9
|
+
frameMs?: number;
|
|
10
|
+
/** How far, in milliseconds, a frame may move from its nominal place to match the waveform, 1 to 50. Default 10. */
|
|
11
|
+
toleranceMs?: number;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Makes audio `factor` times as long at the same pitch by WSOLA (Verhelst and Roelands 1993): 1.05 is 5 % longer
|
|
15
|
+
* (slower), 0.95 is 5 % shorter (faster). The output holds `round(length * factor)` samples. Every channel uses the
|
|
16
|
+
* same frame positions, chosen on their mean, so the stereo image stays put. A factor of 1 copies the samples.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* import {timeStretch} from '@margoengine/audio/stretch';
|
|
20
|
+
* const take = {sampleRate: 48000, channels: [new Float32Array(48000)]};
|
|
21
|
+
* const faster = timeStretch(take, 0.95);
|
|
22
|
+
* console.log(faster.channels[0].length); // 45600
|
|
23
|
+
* @throws RangeError for a factor outside 0.25 to 4 or an option out of range.
|
|
24
|
+
*/
|
|
25
|
+
export declare function timeStretch(audio: StretchInput, factor: number, options?: StretchOptions): StretchInput;
|
package/dist/stretch.js
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { i as e, r as t } from "./errors-D8rc8kzg.js";
|
|
2
|
+
//#region src/stretch.ts
|
|
3
|
+
var n = 4;
|
|
4
|
+
function r(r, i, a = {}) {
|
|
5
|
+
if (!r || typeof r != "object" || !Array.isArray(r.channels) || !r.channels.length) throw e("Pass {sampleRate, channels} audio with at least one channel", "audio-stretch");
|
|
6
|
+
let { sampleRate: o, channels: s } = r;
|
|
7
|
+
if (!s.every((e) => e instanceof Float32Array && e.length === s[0].length)) throw t("Every channel must be a Float32Array of the same length", "audio-stretch");
|
|
8
|
+
if (!Number.isInteger(o) || o < 1 || o > 768e3) throw t("sampleRate must be a whole number from 1 to 768000", "audio-stretch");
|
|
9
|
+
if (!(i >= .25 && i <= 4)) throw t("factor must be from 0.25 to 4", "audio-stretch");
|
|
10
|
+
let { frameMs: c = 40, toleranceMs: l = 10 } = a;
|
|
11
|
+
if (!(c >= 10 && c <= 200)) throw t("frameMs must be from 10 to 200", "audio-stretch");
|
|
12
|
+
if (!(l >= 1 && l <= 50)) throw t("toleranceMs must be from 1 to 50", "audio-stretch");
|
|
13
|
+
let u = s[0].length, d = Math.round(u * i);
|
|
14
|
+
if (i === 1) return {
|
|
15
|
+
sampleRate: o,
|
|
16
|
+
channels: s.map((e) => e.slice())
|
|
17
|
+
};
|
|
18
|
+
let f = Math.max(2, Math.round(c * o / 2e3)), p = 2 * f, m = f, h = m / i, g = Math.max(1, Math.round(l * o / 1e3)), _ = Float64Array.from({ length: p }, (e, t) => .5 - .5 * Math.cos(2 * Math.PI * t / p)), v = new Float32Array(u);
|
|
19
|
+
for (let e of s) for (let t = 0; t < u; t++) v[t] += e[t] / s.length;
|
|
20
|
+
let y = (e) => e >= 0 && e < u ? v[e] : 0, b = (e, t, n) => {
|
|
21
|
+
let r = 0;
|
|
22
|
+
for (let i = 0; i < p; i += n) r += y(e - f + i) * y(t - f + i);
|
|
23
|
+
return r;
|
|
24
|
+
}, x = Math.ceil(d / m) + 1, S = s.map(() => new Float32Array(d)), C = new Float64Array(d), w = 0;
|
|
25
|
+
for (let e = 0; e < x; e++) {
|
|
26
|
+
let t = Math.round(e * h), r = t;
|
|
27
|
+
if (e > 0) {
|
|
28
|
+
let e = w + m, i = 0, a = -Infinity;
|
|
29
|
+
for (let r = -g; r <= g; r += n) {
|
|
30
|
+
let o = b(e, t + r, n);
|
|
31
|
+
o > a && ([a, i] = [o, r]);
|
|
32
|
+
}
|
|
33
|
+
let o = i;
|
|
34
|
+
a = -Infinity;
|
|
35
|
+
for (let r = Math.max(-g, o - n + 1); r <= Math.min(g, o + n - 1); r++) {
|
|
36
|
+
let n = b(e, t + r, 1);
|
|
37
|
+
n > a && ([a, i] = [n, r]);
|
|
38
|
+
}
|
|
39
|
+
r = t + i;
|
|
40
|
+
}
|
|
41
|
+
w = r;
|
|
42
|
+
let i = e * m - f;
|
|
43
|
+
for (let e = 0; e < p; e++) {
|
|
44
|
+
let t = i + e, n = r - f + e;
|
|
45
|
+
if (!(t < 0 || t >= d) && (C[t] += _[e], !(n < 0 || n >= u))) for (let r = 0; r < s.length; r++) S[r][t] += _[e] * s[r][n];
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
for (let e = 0; e < d; e++) if (C[e] > 1e-9) for (let t of S) t[e] /= C[e];
|
|
49
|
+
return {
|
|
50
|
+
sampleRate: o,
|
|
51
|
+
channels: S
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
//#endregion
|
|
55
|
+
export { r as timeStretch };
|