@ra2web/wavefile
Version:
WAV file processing library from ra2web project
1,720 lines (1,675 loc) • 59.8 kB
JavaScript
// Helper function for prototype inheritance
function P(child, parent) {
child.prototype = Object.create(parent.prototype);
child.prototype.constructor = child;
child.__proto__ = parent;
}
function t(e) {
var t = n.call(this) || this;
return e && t.fromBuffer(e), t;
}
function n() {
return o.apply(this, arguments) || this;
}
function r(e, t, n) {
for (var r = [], i = 0; i < e; i++)
r.push(
this.b({
pa: t,
oa: n,
Q: 0.5 / Math.sin((Math.PI / (2 * e)) * (i + 0.5)),
}),
);
for (this.a = [], e = 0; e < r.length; e++)
this.a[e] = {
Ka: r[e].A[0],
La: r[e].A[1],
Ma: r[e].A[2],
Ha: r[e].D[0],
Ia: r[e].D[1],
k: r[e].k,
z: [0, 0],
};
}
function i(e, t, n) {
(n = (2 * Math.PI * n) / t), (t = 0), (this.a = []);
for (var r = 0; r <= e; r++)
0 == r - e / 2
? (this.a[r] = n)
: ((this.a[r] = Math.sin(n * (r - e / 2)) / (r - e / 2)),
(this.a[r] *= 0.54 - 0.46 * Math.cos((2 * Math.PI * r) / e))),
(t += this.a[r]);
for (n = 0; n <= e; n++) this.a[n] /= t;
this.z = this.b();
}
function a(e, t, n) {
(this.C = e),
(this.j = (e - 1) / t),
(this.M = this.I),
"point" === n.method
? (this.M = this.H)
: "linear" === n.method
? (this.M = this.G)
: "cubic" === n.method && (this.M = this.B),
(this.J = 1 - Math.max(0, Math.min(1, n.tension || 0))),
(this.v = n.sincFilterSize || 1),
(this.F = (function (e) {
return function (t) {
return (0 === t ? 1 : Math.sin(Math.PI * t) / (Math.PI * t)) * e(t);
};
})(n.sincWindow || O));
}
function o() {
return l.apply(this, arguments) || this;
}
function l() {
return s.apply(this, arguments) || this;
}
function s() {
var e = u.call(this) || this;
return (
(e.bitDepth = "0"),
(e.f = { h: 0, o: !1 }),
(e.G = {
4: 17,
8: 1,
"8a": 6,
"8m": 7,
16: 1,
24: 1,
32: 1,
"32f": 3,
64: 3,
}),
e
);
}
function u() {
return c.apply(this, arguments) || this;
}
function c() {
var e = f.call(this) || this;
return (
e.Z.push("RF64"),
(e.fmt = {
chunkId: "",
chunkSize: 0,
audioFormat: 0,
numChannels: 0,
sampleRate: 0,
byteRate: 0,
blockAlign: 0,
bitsPerSample: 0,
cbSize: 0,
validBitsPerSample: 0,
dwChannelMask: 0,
subformat: [],
}),
(e.fact = { chunkId: "", chunkSize: 0, dwSampleLength: 0 }),
(e.cue = { chunkId: "", chunkSize: 0, dwCuePoints: 0, points: [] }),
(e.smpl = {
chunkId: "",
chunkSize: 0,
dwManufacturer: 0,
dwProduct: 0,
dwSamplePeriod: 0,
dwMIDIUnityNote: 0,
dwMIDIPitchFraction: 0,
dwSMPTEFormat: 0,
dwSMPTEOffset: 0,
dwNumSampleLoops: 0,
dwSamplerData: 0,
loops: [],
}),
(e.bext = {
chunkId: "",
chunkSize: 0,
description: "",
originator: "",
originatorReference: "",
originationDate: "",
originationTime: "",
timeReference: [0, 0],
version: 0,
UMID: "",
loudnessValue: 0,
loudnessRange: 0,
maxTruePeakLevel: 0,
maxMomentaryLoudness: 0,
maxShortTermLoudness: 0,
reserved: "",
codingHistory: "",
}),
(e.iXML = { chunkId: "", chunkSize: 0, value: "" }),
(e.ds64 = {
chunkId: "",
chunkSize: 0,
riffSizeHigh: 0,
riffSizeLow: 0,
dataSizeHigh: 0,
dataSizeLow: 0,
originationTime: 0,
sampleCountHigh: 0,
sampleCountLow: 0,
}),
(e.data = { chunkId: "", chunkSize: 0, samples: new Uint8Array(0) }),
(e.LIST = []),
(e.junk = { chunkId: "", chunkSize: 0, chunkData: [] }),
(e._PMX = { chunkId: "", chunkSize: 0, value: "" }),
(e.g = { h: 16, o: !1, O: !1, R: !1 }),
e
);
}
function f() {
(this.container = ""),
(this.chunkSize = 0),
(this.format = ""),
(this.Y = null),
(this.c = 0),
(this.a = { h: 32, o: !1 }),
(this.Z = ["RIFF", "RIFX"]);
}
function h(e, t) {
(this.offset = Math.ceil((e + t) / 8)),
(this.b = e),
(this.c = t),
(this.a = (1 << (e - 1)) - 1),
(this.f = Math.pow(2, this.a + 1)),
(this.g = e + t),
(this.i = Math.pow(2, -(8 * this.offset - 1 - e)));
}
function d(e, t) {
(this.h = e),
(this.offset = Math.ceil(e / 8)),
(this.max = Math.pow(2, e) - 1),
(this.min = 0),
(this.S = this.a),
void 0 !== t &&
t &&
((this.max = Math.pow(2, e) / 2 - 1),
(this.min = -this.max - 1),
(this.S = this.f));
}
function p(e, t) {
return 0 < e
? parseInt((e / t.ea) * t.ca, 10)
: parseInt((e / t.fa) * t.da, 10);
}
function m(e, t) {
return parseInt(0 < e ? e * t.ca : e * t.da, 10);
}
function v(e, t) {
return 0 < e ? e / t.ea : e / t.fa;
}
function y(e) {
if (
"32f" != e &&
"64" != e &&
("8" > parseInt(e, 10) || "53" < parseInt(e, 10))
)
throw Error("Invalid bit depth.");
}
function g(e, t, n) {
if ("8" == e) {
(e = n ? -128 : 128), (n = 0);
for (var r = t.length; n < r; n++) t[n] = t[n] += e;
}
}
function b(e, t) {
t = void 0 === t ? 256 : t;
for (
var n = { index: 0, l: 0, step: 7 },
r = new Int16Array(2 * e.length),
i = [],
a = 0,
o = e.length,
l = 0;
0 < o;
) {
for (var s = Math.min(o, t), u = 0; u < s; u++) i.push(e[l]), l++;
(s = n),
(u = (i[1] << 8) | i[0]),
(s.l = 32767 < u ? u - 65536 : u),
(s.index = i[2]),
(s.step = B[s.index]),
(u = [s.l]);
for (var c = 4, f = i.length; c < f; c++) {
var h = i[c],
d = h >> 4;
u.push(x((d << 4) ^ h, s)), u.push(x(d, s));
}
(i = u), r.set(i, a), (a += i.length), (i = []), (o -= t);
}
return r.slice(0, a);
}
function w(e, t) {
var n = e[0];
k(n, t);
var r = [];
r.push(255 & n),
r.push((n >> 8) & 255),
r.push(t.index),
r.push(0),
(n = 3);
for (var i = e.length; n < i; n += 2) {
var a = k(e[n], t),
o = k(e[n + 1], t);
r.push((o << 4) | a);
}
return r;
}
function k(e, t) {
var n = e - t.l;
if (0 <= n) var r = 0;
else (r = 8), (n = -n);
var i = B[t.index],
a = i >> 3;
return (
n > i && ((r |= 4), (n -= i), (a += i)),
n > (i >>= 1) && ((r |= 2), (n -= i), (a += i)),
n > (i >>= 1) && ((r |= 1), (a += i)),
(n = r),
(t.l = 8 & n ? t.l - a : t.l + a),
-32768 > t.l ? (t.l = -32768) : 32767 < t.l && (t.l = 32767),
(t.index += U[7 & n]),
0 > t.index ? (t.index = 0) : 88 < t.index && (t.index = 88),
r
);
}
function x(e, t) {
var n = 0;
return (
4 & e && (n += t.step),
2 & e && (n += t.step >> 1),
1 & e && (n += t.step >> 2),
(n += t.step >> 3),
8 & e && (n = -n),
(t.l += n),
32767 < t.l ? (t.l = 32767) : -32768 > t.l && (t.l = -32768),
(t.index += U[e]),
0 > t.index ? (t.index = 0) : 88 < t.index && (t.index = 88),
(t.step = B[t.index]),
t.l
);
}
function S(e, t, n, r) {
for (
r = void 0 === r ? e.length : r, n = void 0 === n ? 0 : n;
n < r;
n += t
) {
var i = e,
a = t,
o = n;
a--;
for (var l = 0; l < a; l++) {
var s = i[o + l];
(i[o + l] = i[o + a]), (i[o + a] = s), a--;
}
}
}
function E(e, t, n) {
n = void 0 === n ? 0 : n;
for (var r = 0, i = e.length; r < i; ) {
var a = e.codePointAt(r);
if (128 > a) (t[n] = a), n++;
else {
var o = 0,
l = 0;
for (
2047 >= a
? ((o = 1), (l = 192))
: 65535 >= a
? ((o = 2), (l = 224))
: 1114111 >= a && ((o = 3), (l = 240), r++),
t[n] = (a >> (6 * o)) + l,
n++;
0 < o;
)
(t[n] = 128 | ((a >> (6 * (o - 1))) & 63)), n++, o--;
}
r++;
}
return n;
}
function T(e) {
var t = Math.floor(e);
return 0.5 > (e -= t) ? t : 0.5 < e ? t + 1 : t % 2 ? t + 1 : t;
}
function C(e, t, n) {
var r = void 0 === t ? 0 : t;
for (
n = void 0 === (n = void 0 === n ? e.length : n) ? e.length : n,
t = "",
r = void 0 === r ? 0 : r;
r < n;
) {
var i = 128,
a = 191,
o = !1,
l = e[r++];
if (0 <= l && 127 >= l) t += String.fromCharCode(l);
else {
var s = 0;
194 <= l && 223 >= l
? (s = 1)
: 224 <= l && 239 >= l
? ((s = 2), 224 === e[r] && (i = 160), 237 === e[r] && (a = 159))
: 240 <= l && 244 >= l
? ((s = 3), 240 === e[r] && (i = 144), 244 === e[r] && (a = 143))
: (o = !0),
(l &= (1 << (8 - s - 1)) - 1);
for (var u = 0; u < s; u++)
(e[r] < i || e[r] > a) && (o = !0), (l = (l << 6) | (63 & e[r])), r++;
o
? (t += String.fromCharCode(65533))
: 65535 >= l
? (t += String.fromCharCode(l))
: ((l -= 65536),
(t += String.fromCharCode(
55296 + ((l >> 10) & 1023),
56320 + (1023 & l),
)));
}
}
return t;
}
function I(e) {
var t = [];
return E(e, t), t;
}
function _(e, t, n, r) {
r = void 0 === r ? 0 : r;
for (
var i = A((t = t || {}).h, t.R, t.O),
a = Math.ceil(t.h / 8),
o = 0,
l = r,
s = e.length;
o < s;
o++
)
r = i.ga(n, e[o], r);
return t.o && S(n, a, l, r), r;
}
function z(e, t, n, r, i) {
(r = void 0 === r ? 0 : r), (i = void 0 === i ? e.length : i);
var a = A((t = t || {}).h, t.R, t.O);
(i -= (i - r) % a.offset),
t.o
? ((e = new Uint8Array(e)),
t.o && S(e, a.offset, r, i),
N(e, n, r, i, a))
: N(e, n, r, i, a);
}
function M(e, t) {
var n = [];
return _([e], t, n, 0), n;
}
function L(e, t, n) {
var r = [];
return z(e, t, r, (n = void 0 === n ? 0 : n), n + Math.ceil(t.h / 8)), r[0];
}
function N(e, t, n, r, i) {
for (var a = i.offset, o = 0; n < r; n += a, o++) t[o] = i.S(e, n);
}
function A(e, t, n) {
return t && 32 == e
? new h(8, 23)
: t && 64 == e
? new h(11, 52)
: new d(e, n);
}
function R(e, t) {
for (var n = I(e), r = n.length; r < t; r++) n.push(0);
return n;
}
function O(e) {
return Math.exp(((-e / 2) * e) / 2);
}
function D(e, t, n, r) {
r = (void 0 === r ? null : r) || {};
var i = new Float64Array(e.length * ((n - t) / t + 1));
r.method = r.method || "cubic";
var o = new a(e.length, i.length, {
method: r.method,
tension: r.tension || 0,
sincFilterSize: r.sincFilterSize || 6,
sincWindow: r.sincWindow || void 0,
clip: r.clip || "mirror",
});
if ((void 0 === r.LPF && (r.LPF = Q[r.method]), r.LPF)) {
r.LPFType = r.LPFType || "IIR";
var l = K[r.LPFType];
if (n > t) {
for (
t = new l(r.LPForder || $[r.LPFType], n, t / 2), n = 0, r = i.length;
n < r;
n++
)
i[n] = t.filter(o.M(n, e));
for (t.reset(), e = i.length - 1; 0 <= e; e--) i[e] = t.filter(i[e]);
} else {
for (
t = new l(r.LPForder || $[r.LPFType], t, n / 2), n = 0, r = e.length;
n < r;
n++
)
e[n] = t.filter(e[n]);
for (t.reset(), n = e.length - 1; 0 <= n; n--) e[n] = t.filter(e[n]);
F(e, i, o);
}
} else F(e, i, o);
return i;
}
function F(e, t, n) {
for (var r = 0, i = t.length; r < i; r++) t[r] = n.M(r, e);
}
function j(e, t) {
var n = e / t;
return n % 2 && n++, n;
}
var U = [-1, -1, -1, -1, 2, 4, 6, 8, -1, -1, -1, -1, 2, 4, 6, 8],
B = [
7, 8, 9, 10, 11, 12, 13, 14, 16, 17, 19, 21, 23, 25, 28, 31, 34, 37, 41,
45, 50, 55, 60, 66, 73, 80, 88, 97, 107, 118, 130, 143, 157, 173, 190,
209, 230, 253, 279, 307, 337, 371, 408, 449, 494, 544, 598, 658, 724, 796,
876, 963, 1060, 1166, 1282, 1411, 1552, 1707, 1878, 2066, 2272, 2499,
2749, 3024, 3327, 3660, 4026, 4428, 4871, 5358, 5894, 6484, 7132, 7845,
8630, 9493, 10442, 11487, 12635, 13899, 15289, 16818, 18500, 20350, 22385,
24623, 27086, 29794, 32767,
],
W = [
1, 1, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5,
5, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
7, 7, 7,
],
V = [
0, 0, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4,
4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
7, 7, 7, 7, 7, 7,
],
H = [0, 132, 396, 924, 1980, 4092, 8316, 16764],
X = Array(8)
.fill(0)
.map(function (e, t) {
return Math.pow(2, 8 * t);
});
(d.prototype.ga = function (e, t, n) {
(n = void 0 === n ? 0 : n), (t = this.b(Math.round(t)));
for (var r = 0, i = this.offset; r < i; r++)
(e[n] = 255 & Math.floor(t / X[r])), n++;
return n;
}),
(d.prototype.a = function (e, t) {
t = void 0 === t ? 0 : t;
for (var n = 0, r = 0; r < this.offset; r++) n += e[t + r] * X[r];
return n;
}),
(d.prototype.f = function (e, t) {
return this.c(this.a(e, void 0 === t ? 0 : t));
}),
(d.prototype.b = function (e) {
return e > this.max ? this.max : e < this.min ? this.min : e;
}),
(d.prototype.c = function (e) {
return e > this.max && (e -= 2 * this.max + 2), e;
}),
(h.prototype.ga = function (e, t, n) {
Math.abs(t) > this.f - 2 * this.g && (t = 0 > t ? -1 / 0 : 1 / 0);
var r = 0 > ((t = +t) || 1 / t) ? 1 : 0 > t ? 1 : 0;
t = Math.abs(t);
var i = Math.min(Math.floor(Math.log(t) / Math.LN2), 1023),
a = T((t / Math.pow(2, i)) * Math.pow(2, this.c));
return (
t != t
? ((a = Math.pow(2, this.c - 1)), (i = (1 << this.b) - 1))
: 0 !== t &&
(t >= Math.pow(2, 1 - this.a)
? (2 <= a / Math.pow(2, this.c) && ((i += 1), (a = 1)),
i > this.a
? ((i = (1 << this.b) - 1), (a = 0))
: ((i += this.a), (a = T(a) - Math.pow(2, this.c))))
: ((a = T(t / Math.pow(2, 1 - this.a - this.c))), (i = 0))),
this.j(e, n, r, i, a)
);
}),
(h.prototype.S = function (e, t) {
for (
var n = (1 << this.b) - 1, r = "", i = this.offset - 1;
0 <= i;
i--
) {
var a = e[i + t].toString(2);
r += "00000000".substring(a.length) + a;
}
return (
(i = "1" == r.charAt(0) ? -1 : 1),
(r = r.substring(1)),
(a = parseInt(r.substring(0, this.b), 2)),
(r = r.substring(this.b)),
a == n
? 0 !== parseInt(r, 2)
? NaN
: (1 / 0) * i
: (0 === a
? ((a += 1), (n = parseInt(r, 2)))
: (n = parseInt("1" + r, 2)),
i * n * this.i * Math.pow(2, a - this.a))
);
}),
(h.prototype.j = function (e, t, n, r, i) {
var a = [];
for (a.push(n), n = this.b; 0 < n; --n)
(a[n] = r % 2 ? 1 : 0), (r = Math.floor(r / 2));
for (r = a.length, n = this.c; 0 < n; --n)
(a[r + n] = i % 2 ? 1 : 0), (i = Math.floor(i / 2));
for (i = a.join(""), a = this.offset + t - 1, r = t; a >= t; )
(e[a] = parseInt(i.substring(0, 8), 2)), (i = i.substring(8)), a--, r++;
return r;
}),
(f.prototype.va = function (e) {
if (
((this.c = 0),
(this.container = this.u(e, 4)),
-1 === this.Z.indexOf(this.container))
)
throw Error("Not a supported format.");
(this.a.o = "RIFX" === this.container),
(this.chunkSize = this.b(e)),
(this.format = this.u(e, 4)),
(this.Y = {
chunkId: this.container,
chunkSize: this.chunkSize,
format: this.format,
subChunks: this.V(e),
});
}),
(f.prototype.s = function (e, t) {
t = void 0 !== t && t;
for (var n = this.Y.subChunks, r = [], i = 0; i < n.length; i++)
if (n[i].chunkId == e) {
if (!t) return n[i];
r.push(n[i]);
}
return "LIST" == e && r.length ? r : null;
}),
(f.prototype.u = function (e, t) {
var n = C(e, this.c, this.c + t);
return (this.c += t), n;
}),
(f.prototype.b = function (e) {
return (e = L(e, this.a, this.c)), (this.c += 4), e;
}),
(f.prototype.V = function (e) {
for (var t = [], n = this.c; n <= e.length - 8; )
t.push(this.$a(e, n)),
(n = (n += 8 + t[t.length - 1].chunkSize) % 2 ? n + 1 : n);
return t;
}),
(f.prototype.$a = function (e, t) {
var n = { chunkId: this.Ea(e, t), chunkSize: this.Fa(e, t) };
return (
"LIST" == n.chunkId
? ((n.format = C(e, t + 8, t + 12)),
(this.c += 4),
(n.subChunks = this.V(e)))
: ((this.c =
t + 8 + (n.chunkSize % 2 ? n.chunkSize + 1 : n.chunkSize)),
(n.chunkData = { start: t + 8, end: this.c })),
n
);
}),
(f.prototype.Ea = function (e, t) {
return (this.c += 4), C(e, t, t + 4);
}),
(f.prototype.Fa = function (e, t) {
return (this.c += 4), L(e, this.a, t + 4);
}),
P(c, f),
(c.prototype.fromBuffer = function (e, t) {
if (
((t = void 0 === t || t),
this.U(),
this.va(e),
(this.g.o = this.a.o),
"WAVE" != this.format)
)
throw Error('Could not find the "WAVE" format identifier');
this.hb(e),
this.jb(e),
this.ib(e),
this.eb(e),
this.qa(e),
this.fb(e),
this.ma(e),
this.gb(e, t),
this.lb(e),
this.ia(e),
this.na(e);
}),
(c.prototype.U = function () {
var e = new c();
Object.assign(this.fmt, e.fmt),
Object.assign(this.fact, e.fact),
Object.assign(this.cue, e.cue),
Object.assign(this.smpl, e.smpl),
Object.assign(this.bext, e.bext),
Object.assign(this.iXML, e.iXML),
Object.assign(this.ds64, e.ds64),
Object.assign(this.data, e.data),
(this.LIST = []),
Object.assign(this.junk, e.junk),
Object.assign(this._PMX, e._PMX);
}),
(c.prototype.jb = function (e) {
var t = this.s("fmt ");
if (!t) throw Error('Could not find the "fmt " chunk');
(this.c = t.chunkData.start),
(this.fmt.chunkId = t.chunkId),
(this.fmt.chunkSize = t.chunkSize),
(this.fmt.audioFormat = this.i(e)),
(this.fmt.numChannels = this.i(e)),
(this.fmt.sampleRate = this.b(e)),
(this.fmt.byteRate = this.b(e)),
(this.fmt.blockAlign = this.i(e)),
(this.fmt.bitsPerSample = this.i(e)),
this.kb(e);
}),
(c.prototype.kb = function (e) {
16 < this.fmt.chunkSize &&
((this.fmt.cbSize = this.i(e)),
18 < this.fmt.chunkSize &&
((this.fmt.validBitsPerSample = this.i(e)),
20 < this.fmt.chunkSize &&
((this.fmt.dwChannelMask = this.b(e)),
(this.fmt.subformat = [
this.b(e),
this.b(e),
this.b(e),
this.b(e),
]))));
}),
(c.prototype.ib = function (e) {
var t = this.s("fact");
t &&
((this.c = t.chunkData.start),
(this.fact.chunkId = t.chunkId),
(this.fact.chunkSize = t.chunkSize),
(this.fact.dwSampleLength = this.b(e)));
}),
(c.prototype.fb = function (e) {
var t = this.s("cue ");
if (t)
for (
this.c = t.chunkData.start,
this.cue.chunkId = t.chunkId,
this.cue.chunkSize = t.chunkSize,
this.cue.dwCuePoints = this.b(e),
t = 0;
t < this.cue.dwCuePoints;
t++
)
this.cue.points.push({
dwName: this.b(e),
dwPosition: this.b(e),
fccChunk: this.u(e, 4),
dwChunkStart: this.b(e),
dwBlockStart: this.b(e),
dwSampleOffset: this.b(e),
});
}),
(c.prototype.ma = function (e) {
var t = this.s("smpl");
if (t)
for (
this.c = t.chunkData.start,
this.smpl.chunkId = t.chunkId,
this.smpl.chunkSize = t.chunkSize,
this.smpl.dwManufacturer = this.b(e),
this.smpl.dwProduct = this.b(e),
this.smpl.dwSamplePeriod = this.b(e),
this.smpl.dwMIDIUnityNote = this.b(e),
this.smpl.dwMIDIPitchFraction = this.b(e),
this.smpl.dwSMPTEFormat = this.b(e),
this.smpl.dwSMPTEOffset = this.b(e),
this.smpl.dwNumSampleLoops = this.b(e),
this.smpl.dwSamplerData = this.b(e),
t = 0;
t < this.smpl.dwNumSampleLoops;
t++
)
this.smpl.loops.push({
dwName: this.b(e),
dwType: this.b(e),
dwStart: this.b(e),
dwEnd: this.b(e),
dwFraction: this.b(e),
dwPlayCount: this.b(e),
});
}),
(c.prototype.gb = function (e, t) {
var n = this.s("data");
if (!n) throw Error('Could not find the "data" chunk');
(this.data.chunkId = "data"),
(this.data.chunkSize = n.chunkSize),
t && (this.data.samples = e.slice(n.chunkData.start, n.chunkData.end));
}),
(c.prototype.eb = function (e) {
var t = this.s("bext");
t &&
((this.c = t.chunkData.start),
(this.bext.chunkId = t.chunkId),
(this.bext.chunkSize = t.chunkSize),
(this.bext.description = this.u(e, 256)),
(this.bext.originator = this.u(e, 32)),
(this.bext.originatorReference = this.u(e, 32)),
(this.bext.originationDate = this.u(e, 10)),
(this.bext.originationTime = this.u(e, 8)),
(this.bext.timeReference = [this.b(e), this.b(e)]),
(this.bext.version = this.i(e)),
(this.bext.UMID = this.u(e, 64)),
(this.bext.loudnessValue = this.i(e)),
(this.bext.loudnessRange = this.i(e)),
(this.bext.maxTruePeakLevel = this.i(e)),
(this.bext.maxMomentaryLoudness = this.i(e)),
(this.bext.maxShortTermLoudness = this.i(e)),
(this.bext.reserved = this.u(e, 180)),
(this.bext.codingHistory = this.u(e, this.bext.chunkSize - 602)));
}),
(c.prototype.qa = function (e) {
var t = this.s("iXML");
t &&
((this.c = t.chunkData.start),
(this.iXML.chunkId = t.chunkId),
(this.iXML.chunkSize = t.chunkSize),
(this.iXML.value = C(e, this.c, this.c + this.iXML.chunkSize)));
}),
(c.prototype.hb = function (e) {
var t = this.s("ds64");
if (t)
(this.c = t.chunkData.start),
(this.ds64.chunkId = t.chunkId),
(this.ds64.chunkSize = t.chunkSize),
(this.ds64.riffSizeHigh = this.b(e)),
(this.ds64.riffSizeLow = this.b(e)),
(this.ds64.dataSizeHigh = this.b(e)),
(this.ds64.dataSizeLow = this.b(e)),
(this.ds64.originationTime = this.b(e)),
(this.ds64.sampleCountHigh = this.b(e)),
(this.ds64.sampleCountLow = this.b(e));
else if ("RF64" == this.container)
throw Error('Could not find the "ds64" chunk');
}),
(c.prototype.ia = function (e) {
var t = this.s("LIST", !0);
if (null !== t)
for (var n = 0; n < t.length; n++) {
var r = t[n];
this.LIST.push({
chunkId: r.chunkId,
chunkSize: r.chunkSize,
format: r.format,
subChunks: [],
});
for (var i = 0; i < r.subChunks.length; i++)
this.ka(r.subChunks[i], r.format, e);
}
}),
(c.prototype.ka = function (e, t, n) {
"adtl" == t
? -1 < ["labl", "note", "ltxt"].indexOf(e.chunkId) && this.la(n, e)
: "INFO" == t && this.ja(n, e);
}),
(c.prototype.la = function (e, t) {
this.c = t.chunkData.start;
var n = { chunkId: t.chunkId, chunkSize: t.chunkSize, dwName: this.b(e) };
"ltxt" == t.chunkId
? ((n.dwSampleLength = this.b(e)),
(n.dwPurposeID = this.b(e)),
(n.dwCountry = this.i(e)),
(n.dwLanguage = this.i(e)),
(n.dwDialect = this.i(e)),
(n.dwCodePage = this.i(e)),
(n.value = ""))
: (n.value = this.X(e, this.c)),
this.LIST[this.LIST.length - 1].subChunks.push(n);
}),
(c.prototype.ja = function (e, t) {
(this.c = t.chunkData.start),
this.LIST[this.LIST.length - 1].subChunks.push({
chunkId: t.chunkId,
chunkSize: t.chunkSize,
value: this.X(e, this.c),
});
}),
(c.prototype.lb = function (e) {
var t = this.s("junk");
t &&
(this.junk = {
chunkId: t.chunkId,
chunkSize: t.chunkSize,
chunkData: [].slice.call(e.slice(t.chunkData.start, t.chunkData.end)),
});
}),
(c.prototype.na = function (e) {
var t = this.s("_PMX");
t &&
((this.c = t.chunkData.start),
(this._PMX.chunkId = t.chunkId),
(this._PMX.chunkSize = t.chunkSize),
(this._PMX.value = C(e, this.c, this.c + this._PMX.chunkSize)));
}),
(c.prototype.X = function (e, t) {
for (
var n = (t = void 0 === t ? 0 : t);
n < e.length && (this.c++, 0 !== e[n]);
n++
);
return C(e, t, this.c - 1);
}),
(c.prototype.i = function (e) {
return (e = L(e, this.g, this.c)), (this.c += 2), e;
}),
P(u, c),
(u.prototype.toBuffer = function () {
(this.g.o = "RIFX" === this.container), (this.a.o = this.g.o);
for (
var e = [
this.Sa(),
this.Oa(),
this.Da(),
this.bb(),
this.Qa(),
this.Pa(),
I(this.data.chunkId),
M(this.data.samples.length, this.a),
this.data.samples,
this.Ga(),
this.Ya(),
this.Ta(),
this.ab(),
],
t = 0,
n = 0;
n < e.length;
n++
)
t += e[n].length;
n = new Uint8Array(t + 12);
var r = E(this.container, n, 0);
for (
r = _([t + 4], this.a, n, void 0 === r ? 0 : r),
r = E(this.format, n, void 0 === r ? 0 : r),
t = 0;
t < e.length;
t++
)
n.set(e[t], r), (r += e[t].length);
return n;
}),
(u.prototype.Da = function () {
var e = [];
return (
this.Ca(),
this.bext.chunkId &&
((this.bext.chunkSize = 602 + this.bext.codingHistory.length),
(e = e.concat(
I(this.bext.chunkId),
M(602 + this.bext.codingHistory.length, this.a),
R(this.bext.description, 256),
R(this.bext.originator, 32),
R(this.bext.originatorReference, 32),
R(this.bext.originationDate, 10),
R(this.bext.originationTime, 8),
M(this.bext.timeReference[0], this.a),
M(this.bext.timeReference[1], this.a),
M(this.bext.version, this.g),
R(this.bext.UMID, 64),
M(this.bext.loudnessValue, this.g),
M(this.bext.loudnessRange, this.g),
M(this.bext.maxTruePeakLevel, this.g),
M(this.bext.maxMomentaryLoudness, this.g),
M(this.bext.maxShortTermLoudness, this.g),
R(this.bext.reserved, 180),
R(this.bext.codingHistory, this.bext.codingHistory.length),
))),
this.j(e),
e
);
}),
(u.prototype.Ca = function () {
for (var e in this.bext)
if (
this.bext.hasOwnProperty(e) &&
this.bext[e] &&
"timeReference" != e
) {
this.bext.chunkId = "bext";
break;
}
(this.bext.timeReference[0] || this.bext.timeReference[1]) &&
(this.bext.chunkId = "bext");
}),
(u.prototype.bb = function () {
var e = [];
if (this.iXML.chunkId) {
var t = I(this.iXML.value);
(this.iXML.chunkSize = t.length),
(e = e.concat(
I(this.iXML.chunkId),
M(this.iXML.chunkSize, this.a),
t,
));
}
return this.j(e), e;
}),
(u.prototype.Oa = function () {
var e = [];
return (
this.ds64.chunkId &&
(e = e.concat(
I(this.ds64.chunkId),
M(this.ds64.chunkSize, this.a),
M(this.ds64.riffSizeHigh, this.a),
M(this.ds64.riffSizeLow, this.a),
M(this.ds64.dataSizeHigh, this.a),
M(this.ds64.dataSizeLow, this.a),
M(this.ds64.originationTime, this.a),
M(this.ds64.sampleCountHigh, this.a),
M(this.ds64.sampleCountLow, this.a),
)),
this.j(e),
e
);
}),
(u.prototype.Ga = function () {
var e = [];
if (this.cue.chunkId) {
var t = this.Ja();
e = e.concat(
I(this.cue.chunkId),
M(t.length + 4, this.a),
M(this.cue.dwCuePoints, this.a),
t,
);
}
return this.j(e), e;
}),
(u.prototype.Ja = function () {
for (var e = [], t = 0; t < this.cue.dwCuePoints; t++)
e = e.concat(
M(this.cue.points[t].dwName, this.a),
M(this.cue.points[t].dwPosition, this.a),
I(this.cue.points[t].fccChunk),
M(this.cue.points[t].dwChunkStart, this.a),
M(this.cue.points[t].dwBlockStart, this.a),
M(this.cue.points[t].dwSampleOffset, this.a),
);
return e;
}),
(u.prototype.Ya = function () {
var e = [];
if (this.smpl.chunkId) {
var t = this.Za();
e = e.concat(
I(this.smpl.chunkId),
M(t.length + 36, this.a),
M(this.smpl.dwManufacturer, this.a),
M(this.smpl.dwProduct, this.a),
M(this.smpl.dwSamplePeriod, this.a),
M(this.smpl.dwMIDIUnityNote, this.a),
M(this.smpl.dwMIDIPitchFraction, this.a),
M(this.smpl.dwSMPTEFormat, this.a),
M(this.smpl.dwSMPTEOffset, this.a),
M(this.smpl.dwNumSampleLoops, this.a),
M(this.smpl.dwSamplerData, this.a),
t,
);
}
return this.j(e), e;
}),
(u.prototype.Za = function () {
for (var e = [], t = 0; t < this.smpl.dwNumSampleLoops; t++)
e = e.concat(
M(this.smpl.loops[t].dwName, this.a),
M(this.smpl.loops[t].dwType, this.a),
M(this.smpl.loops[t].dwStart, this.a),
M(this.smpl.loops[t].dwEnd, this.a),
M(this.smpl.loops[t].dwFraction, this.a),
M(this.smpl.loops[t].dwPlayCount, this.a),
);
return e;
}),
(u.prototype.Pa = function () {
var e = [];
return (
this.fact.chunkId &&
(e = e.concat(
I(this.fact.chunkId),
M(this.fact.chunkSize, this.a),
M(this.fact.dwSampleLength, this.a),
)),
this.j(e),
e
);
}),
(u.prototype.Qa = function () {
var e = [];
if (this.fmt.chunkId)
return (
(e = e.concat(
I(this.fmt.chunkId),
M(this.fmt.chunkSize, this.a),
M(this.fmt.audioFormat, this.g),
M(this.fmt.numChannels, this.g),
M(this.fmt.sampleRate, this.a),
M(this.fmt.byteRate, this.a),
M(this.fmt.blockAlign, this.g),
M(this.fmt.bitsPerSample, this.g),
this.Ra(),
)),
this.j(e),
e
);
throw Error('Could not find the "fmt " chunk');
}),
(u.prototype.Ra = function () {
var e = [];
return (
16 < this.fmt.chunkSize && (e = e.concat(M(this.fmt.cbSize, this.g))),
18 < this.fmt.chunkSize &&
(e = e.concat(M(this.fmt.validBitsPerSample, this.g))),
20 < this.fmt.chunkSize &&
(e = e.concat(M(this.fmt.dwChannelMask, this.a))),
24 < this.fmt.chunkSize &&
(e = e.concat(
M(this.fmt.subformat[0], this.a),
M(this.fmt.subformat[1], this.a),
M(this.fmt.subformat[2], this.a),
M(this.fmt.subformat[3], this.a),
)),
e
);
}),
(u.prototype.Ta = function () {
for (var e = [], t = 0; t < this.LIST.length; t++) {
var n = this.Va(this.LIST[t].subChunks, this.LIST[t].format);
e = e.concat(
I(this.LIST[t].chunkId),
M(n.length + 4, this.a),
I(this.LIST[t].format),
n,
);
}
return this.j(e), e;
}),
(u.prototype.Va = function (e, t) {
for (var n = [], r = 0, i = e.length; r < i; r++)
"INFO" == t
? (n = n.concat(this.Ua(e[r])))
: "adtl" == t && (n = n.concat(this.Wa(e[r]))),
this.j(n);
return n;
}),
(u.prototype.Ua = function (e) {
var t = [],
n = R(e.value, e.value.length);
return (
(t = t.concat(I(e.chunkId), M(n.length + 1, this.a), n)).push(0), t
);
}),
(u.prototype.Wa = function (e) {
var t = [];
if (-1 < ["labl", "note"].indexOf(e.chunkId)) {
var n = R(e.value, e.value.length);
(t = t.concat(
I(e.chunkId),
M(n.length + 5, this.a),
M(e.dwName, this.a),
n,
)).push(0);
} else "ltxt" == e.chunkId && (t = t.concat(this.Xa(e)));
return t;
}),
(u.prototype.Xa = function (e) {
return I(e.chunkId).concat(
M(e.value.length + 20, this.a),
M(e.dwName, this.a),
M(e.dwSampleLength, this.a),
M(e.dwPurposeID, this.a),
M(e.dwCountry, this.g),
M(e.dwLanguage, this.g),
M(e.dwDialect, this.g),
M(e.dwCodePage, this.g),
R(e.value, e.value.length),
);
}),
(u.prototype.ab = function () {
var e = [];
if (this._PMX.chunkId) {
var t = I(this._PMX.value);
(this._PMX.chunkSize = t.length),
(e = e.concat(
I(this._PMX.chunkId),
M(this._PMX.chunkSize, this.a),
t,
));
}
return this.j(e), e;
}),
(u.prototype.Sa = function () {
var e = [];
return this.junk.chunkId
? e.concat(
I(this.junk.chunkId),
M(this.junk.chunkData.length, this.a),
this.junk.chunkData,
)
: (this.j(e), e);
}),
(u.prototype.j = function (e) {
e.length % 2 && e.push(0);
}),
P(s, u),
(s.prototype.fromScratch = function (e, t, n, r, i) {
(i = i || {}), this.U(), this.W(e, t, n, r, i);
}),
(s.prototype.fromBuffer = function (e, t) {
u.prototype.fromBuffer.call(this, e, void 0 === t || t),
this.ya(),
this.$();
}),
(s.prototype.toBuffer = function () {
return this.aa(), u.prototype.toBuffer.call(this);
}),
(s.prototype.getSamples = function (e, t) {
e = void 0 !== e && e;
var n = new (t = void 0 === t ? Float64Array : t)(
this.data.samples.length / (this.f.h / 8),
);
if (
(z(this.data.samples, this.f, n, 0, this.data.samples.length),
!e && 1 < this.fmt.numChannels)
) {
var r = this.fmt.numChannels,
i = t;
i = void 0 === i ? Float64Array : i;
for (var a = [], o = 0; o < r; o++) a[o] = new i(n.length / r);
for (i = 0; i < r; i++) {
o = i;
for (var l = 0; o < n.length; o += r, l++) a[i][l] = n[o];
}
n = a;
}
return n;
}),
(s.prototype.getSample = function (e) {
if ((e *= this.f.h / 8) + this.f.h / 8 > this.data.samples.length)
throw Error("Range error");
return L(this.data.samples.slice(e, e + this.f.h / 8), this.f);
}),
(s.prototype.setSample = function (e, t) {
if ((e *= this.f.h / 8) + this.f.h / 8 > this.data.samples.length)
throw Error("Range error");
_([t], this.f, this.data.samples, void 0 === e ? 0 : e);
}),
(s.prototype.getiXML = function () {
return this.iXML.value;
}),
(s.prototype.setiXML = function (e) {
if ("string" != typeof e)
throw new TypeError("iXML value must be a string.");
(this.iXML.value = e), (this.iXML.chunkId = "iXML");
}),
(s.prototype.get_PMX = function () {
return this._PMX.value;
}),
(s.prototype.set_PMX = function (e) {
if ("string" != typeof e)
throw new TypeError("_PMX value must be a string.");
(this._PMX.value = e), (this._PMX.chunkId = "_PMX");
}),
(s.prototype.W = function (e, t, n, r, i) {
i.container || (i.container = "RIFF"),
(this.container = i.container),
(this.bitDepth = n);
var a = [];
if (0 < r.length)
if (r[0].constructor !== Number) {
a = new Float64Array(r[0].length * r.length);
for (var o = 0, l = r[0].length, s = 0; o < l; o++)
for (var u = 0, c = r.length; u < c; u++, s++) a[s] = r[u][o];
} else a = r;
(r = a),
this.$(),
(a = this.f.h / 8),
(this.data.samples = new Uint8Array(r.length * a)),
_(r, this.f, this.data.samples, 0),
this.cb(n, e, t, a, this.data.samples.length, i),
(this.data.chunkId = "data"),
(this.data.chunkSize = this.data.samples.length),
this.aa();
}),
(s.prototype.cb = function (e, t, n, r, i, a) {
"4" == e
? this.za(e, t, n, r, i, a)
: "8a" == e || "8m" == e
? this.Aa(e, t, n, r, i, a)
: -1 == Object.keys(this.G).indexOf(e) || 2 < t
? this.Ba(e, t, n, r, i, a)
: this.F(e, t, n, r, i, a);
}),
(s.prototype.F = function (e, t, n, r, i, a) {
(this.container = a.container),
(this.chunkSize = 36 + i),
(this.format = "WAVE"),
(this.bitDepth = e),
(this.fmt = {
chunkId: "fmt ",
chunkSize: 16,
audioFormat: this.G[e] || 65534,
numChannels: t,
sampleRate: n,
byteRate: t * r * n,
blockAlign: t * r,
bitsPerSample: parseInt(e, 10),
cbSize: 0,
validBitsPerSample: 0,
dwChannelMask: 0,
subformat: [],
});
}),
(s.prototype.za = function (e, t, n, r, i, a) {
this.F(e, t, n, r, i, a),
(this.chunkSize = 40 + i),
(this.fmt.chunkSize = 20),
(this.fmt.byteRate = 4055),
(this.fmt.blockAlign = 256),
(this.fmt.bitsPerSample = 4),
(this.fmt.cbSize = 2),
(this.fmt.validBitsPerSample = 505),
(this.fact = { chunkId: "fact", chunkSize: 4, dwSampleLength: 2 * i });
}),
(s.prototype.Ba = function (e, t, n, r, i, a) {
this.F(e, t, n, r, i, a),
(this.chunkSize = 60 + i),
(this.fmt.chunkSize = 40),
(this.fmt.bitsPerSample = 1 + ((parseInt(e, 10) - 1) | 7)),
(this.fmt.cbSize = 22),
(this.fmt.validBitsPerSample = parseInt(e, 10)),
(n = 0),
1 === t
? (n = 4)
: 2 === t
? (n = 3)
: 4 === t
? (n = 51)
: 6 === t
? (n = 63)
: 8 === t && (n = 1599),
((e = this.fmt).dwChannelMask = n),
(this.fmt.subformat = [1, 1048576, 2852126848, 1905997824]);
}),
(s.prototype.Aa = function (e, t, n, r, i, a) {
this.F(e, t, n, r, i, a),
(this.chunkSize = 40 + i),
(this.fmt.chunkSize = 20),
(this.fmt.cbSize = 2),
(this.fmt.validBitsPerSample = 8),
(this.fact = { chunkId: "fact", chunkSize: 4, dwSampleLength: i });
}),
(s.prototype.ya = function () {
3 === this.fmt.audioFormat && 32 === this.fmt.bitsPerSample
? (this.bitDepth = "32f")
: 6 === this.fmt.audioFormat
? (this.bitDepth = "8a")
: 7 === this.fmt.audioFormat
? (this.bitDepth = "8m")
: (this.bitDepth = this.fmt.bitsPerSample.toString());
}),
(s.prototype.wa = function () {
if (
!(
this.G[this.bitDepth] ||
(8 < parseInt(this.bitDepth, 10) && 54 > parseInt(this.bitDepth, 10))
)
)
throw Error("Invalid bit depth.");
}),
(s.prototype.$ = function () {
(this.f = {
h: 1 + ((parseInt(this.bitDepth, 10) - 1) | 7),
R: "32f" == this.bitDepth || "64" == this.bitDepth,
O: "8" != this.bitDepth,
o: "RIFX" == this.container,
}),
-1 < ["4", "8a", "8m"].indexOf(this.bitDepth) &&
((this.f.h = 8), (this.f.O = !1));
}),
(s.prototype.aa = function () {
this.wa();
var e = this.fmt.numChannels;
if (1 > e || 65535 < (e * this.fmt.bitsPerSample) / 8)
throw Error("Invalid number of channels.");
if (
1 > (e = this.fmt.sampleRate) ||
4294967295 < (this.fmt.bitsPerSample / 8) * this.fmt.numChannels * e
)
throw Error("Invalid sample rate.");
}),
P(l, s),
(l.prototype.getTag = function (e) {
return null !== (e = this.P(e)).w
? this.LIST[e.LIST].subChunks[e.w].value
: null;
}),
(l.prototype.setTag = function (e, t) {
var n = e;
if (n.constructor !== String) throw Error("Invalid tag name.");
if (4 > n.length) for (var r = 0, i = 4 - n.length; r < i; r++) n += " ";
(e = n),
null !== (n = this.P(e)).w
? ((this.LIST[n.LIST].subChunks[n.w].chunkSize = t.length + 1),
(this.LIST[n.LIST].subChunks[n.w].value = t))
: null !== n.LIST
? this.LIST[n.LIST].subChunks.push({
chunkId: e,
chunkSize: t.length + 1,
value: t,
})
: (this.LIST.push({
chunkId: "LIST",
chunkSize: t.length + 9,
format: "INFO",
subChunks: [],
}),
this.LIST[this.LIST.length - 1].subChunks.push({
chunkId: e,
chunkSize: t.length + 1,
value: t,
}));
}),
(l.prototype.deleteTag = function (e) {
return (
null !== (e = this.P(e)).w &&
(this.LIST[e.LIST].subChunks.splice(e.w, 1), !0)
);
}),
(l.prototype.listTags = function () {
var e = this.C("INFO"),
t = {};
if (null !== e)
for (var n = 0, r = this.LIST[e].subChunks.length; n < r; n++)
t[this.LIST[e].subChunks[n].chunkId] =
this.LIST[e].subChunks[n].value;
return t;
}),
(l.prototype.C = function (e) {
for (var t = 0, n = this.LIST.length; t < n; t++)
if (this.LIST[t].format == e) return t;
return null;
}),
(l.prototype.P = function (e) {
for (
var t = { LIST: null, w: null }, n = 0, r = this.LIST.length;
n < r;
n++
)
if ("INFO" == this.LIST[n].format) {
(t.LIST = n), (r = 0);
for (var i = this.LIST[n].subChunks.length; r < i; r++)
if (this.LIST[n].subChunks[r].chunkId == e) {
t.w = r;
break;
}
break;
}
return t;
}),
P(o, l),
(o.prototype.listCuePoints = function () {
for (var e = this.J(), t = 0, n = e.length; t < n; t++)
(e[t].position = (e[t].dwSampleOffset / this.fmt.sampleRate) * 1e3),
e[t].dwSampleLength
? ((e[t].end = (e[t].dwSampleLength / this.fmt.sampleRate) * 1e3),
(e[t].end += e[t].position))
: (e[t].end = null),
delete e[t].value;
return e;
}),
(o.prototype.setCuePoint = function (e) {
(this.cue.chunkId = "cue "), e.label || (e.label = "");
var t = this.J();
this.I(),
(this.cue.points = []),
(e.dwSampleOffset = (e.position * this.fmt.sampleRate) / 1e3),
(e.dwSampleLength = 0),
e.end &&
(e.dwSampleLength =
(e.end * this.fmt.sampleRate) / 1e3 - e.dwSampleOffset),
0 === t.length ? this.B(e, 1) : this.ra(t, e),
(this.cue.dwCuePoints = this.cue.points.length);
}),
(o.prototype.deleteCuePoint = function (e) {
this.cue.chunkId = "cue ";
var t = this.J();
this.I();
var n = this.cue.points.length;
this.cue.points = [];
for (var r = 0; r < n; r++) r + 1 !== e && this.B(t[r], r + 1);
(this.cue.dwCuePoints = this.cue.points.length),
this.cue.dwCuePoints
? (this.cue.chunkId = "cue ")
: ((this.cue.chunkId = ""), this.I());
}),
(o.prototype.updateLabel = function (e, t) {
var n = this.C("adtl");
if (null !== n)
for (var r = 0, i = this.LIST[n].subChunks.length; r < i; r++)
this.LIST[n].subChunks[r].dwName == e &&
(this.LIST[n].subChunks[r].value = t);
}),
(o.prototype.J = function () {
for (var e = [], t = 0; t < this.cue.points.length; t++) {
var n = this.cue.points[t],
r = this.Na(n.dwName);
(r.label = r.value ? r.value : ""),
(r.dwPosition = n.dwPosition),
(r.fccChunk = n.fccChunk),
(r.dwChunkStart = n.dwChunkStart),
(r.dwBlockStart = n.dwBlockStart),
(r.dwSampleOffset = n.dwSampleOffset),
e.push(r);
}
return e;
}),
(o.prototype.Na = function (e) {
var t = this.C("adtl"),
n = {};
return null !== t && this.ha(n, t, e), n;
}),
(o.prototype.ha = function (e, t, n) {
for (var r = 0, i = this.LIST[t].subChunks.length; r < i; r++)
if (this.LIST[t].subChunks[r].dwName == n) {
var a = this.LIST[t].subChunks[r];
(e.value = a.value || e.value),
(e.dwName = a.dwName || 0),
(e.dwSampleLength = a.dwSampleLength || 0),
(e.dwPurposeID = a.dwPurposeID || 0),
(e.dwCountry = a.dwCountry || 0),
(e.dwLanguage = a.dwLanguage || 0),
(e.dwDialect = a.dwDialect || 0),
(e.dwCodePage = a.dwCodePage || 0);
}
}),
(o.prototype.B = function (e, t) {
this.cue.points.push({
dwName: t,
dwPosition: e.dwPosition ? e.dwPosition : 0,
fccChunk: e.fccChunk ? e.fccChunk : "data",
dwChunkStart: e.dwChunkStart ? e.dwChunkStart : 0,
dwBlockStart: e.dwBlockStart ? e.dwBlockStart : 0,
dwSampleOffset: e.dwSampleOffset,
}),
this.ta(e, t);
}),
(o.prototype.ra = function (e, t) {
for (var n = !1, r = 0; r < e.length; r++)
e[r].dwSampleOffset > t.dwSampleOffset && !n
? (this.B(t, r + 1), this.B(e[r], r + 2), (n = !0))
: this.B(e[r], n ? r + 2 : r + 1);
n || this.B(t, this.cue.points.length + 1);
}),
(o.prototype.I = function () {
for (var e = 0, t = this.LIST.length; e < t; e++)
"adtl" == this.LIST[e].format && this.LIST.splice(e);
}),
(o.prototype.ta = function (e, t) {
var n = this.C("adtl");
null === n &&
(this.LIST.push({
chunkId: "LIST",
chunkSize: 4,
format: "adtl",
subChunks: [],
}),
(n = this.LIST.length - 1)),
this.sa(n, e, t),
e.dwSampleLength && this.ua(n, e, t);
}),
(o.prototype.sa = function (e, t, n) {
this.LIST[e].subChunks.push({
chunkId: "labl",
chunkSize: 4,
dwName: n,
value: t.label,
}),
(this.LIST[e].chunkSize += 12);
}),
(o.prototype.ua = function (e, t, n) {
this.LIST[e].subChunks.push({
chunkId: "ltxt",
chunkSize: 20,
dwName: n,
dwSampleLength: t.dwSampleLength,
dwPurposeID: t.dwPurposeID || 0,
dwCountry: t.dwCountry || 0,
dwLanguage: t.dwLanguage || 0,
dwDialect: t.dwDialect || 0,
dwCodePage: t.dwCodePage || 0,
value: t.label,
}),
(this.LIST[e].chunkSize += 28);
}),
(a.prototype.H = function (e, t) {
return this.f(Math.round(this.j * e), t);
}),
(a.prototype.G = function (e, t) {
e *= this.j;
var n = Math.floor(e);
return (1 - (e -= n)) * this.f(n, t) + e * this.f(n + 1, t);
}),
(a.prototype.B = function (e, t) {
e *= this.j;
var n = Math.floor(e),
r = [this.m(n, t), this.m(n + 1, t)],
i = [this.f(n, t), this.f(n + 1, t)],
a = (e -= n) * (n = e * e);
return (
(2 * a - 3 * n + 1) * i[0] +
(a - 2 * n + e) * r[0] +
(-2 * a + 3 * n) * i[1] +
(a - n) * r[1]
);
}),
(a.prototype.I = function (e, t) {
e *= this.j;
var n = Math.floor(e),
r = n + this.v,
i = 0;
for (n = n - this.v + 1; n <= r; n++) i += this.F(e - n) * this.f(n, t);
return i;
}),
(a.prototype.m = function (e, t) {
return (this.J * (this.f(e + 1, t) - this.f(e - 1, t))) / 2;
}),
(a.prototype.f = function (e, t) {
return 0 <= e && e < this.C ? t[e] : 0;
}),
(i.prototype.filter = function (e) {
this.z.L[this.z.N] = e;
for (var t = (e = 0), n = this.z.L.length; t < n; t++)
e += this.a[t] * this.z.L[(this.z.N + t) % this.z.L.length];
return (this.z.N = (this.z.N + 1) % this.z.L.length), e;
}),
(i.prototype.reset = function () {
this.z = this.b();
}),
(i.prototype.b = function () {
for (var e = [], t = 0; t < this.a.length - 1; t++) e.push(0);
return { L: e, N: 0 };
}),
(r.prototype.filter = function (e) {
for (var t = 0, n = this.a.length; t < n; t++) e = this.f(t, e);
return e;
}),
(r.prototype.b = function (e) {
var t = { D: [], A: [] };
return (
(e = this.c(e, t)),
(t.k = 1),
t.A.push((1 - e.ba) / (2 * e.K)),
t.A.push(2 * t.A[0]),
t.A.push(t.A[0]),
t
);
}),
(r.prototype.c = function (e, t) {
var n = {},
r = (2 * Math.PI * e.oa) / e.pa;
return (
(n.alpha = Math.sin(r) / (2 * e.Q)),
(n.ba = Math.cos(r)),
(n.K = 1 + n.alpha),
(t.K = n.K),
t.D.push((-2 * n.ba) / n.K),
(t.k = 1),
t.D.push((1 - n.alpha) / n.K),
n
);
}),
(r.prototype.f = function (e, t) {
var n =
t * this.a[e].k -
this.a[e].Ha * this.a[e].z[0] -
this.a[e].Ia * this.a[e].z[1],
r =
this.a[e].Ka * n +
this.a[e].La * this.a[e].z[0] +
this.a[e].Ma * this.a[e].z[1];
return (this.a[e].z[1] = this.a[e].z[0]), (this.a[e].z[0] = n), r;
}),
(r.prototype.reset = function () {
for (var e = 0; e < this.a.length; e++) this.a[e].z = [0, 0];
});
var Q = { point: !1, linear: !1, cubic: !0, sinc: !0 },
$ = { IIR: 16, FIR: 71 },
K = { IIR: r, FIR: i };
P(n, o),
(n.prototype.toRIFF = function () {
var e = new Float64Array(j(this.data.samples.length, this.f.h / 8));
z(this.data.samples, this.f, e, 0, this.data.samples.length),
this.m(this.fmt.numChannels, this.fmt.sampleRate, this.bitDepth, e, {
cont