carta1 1.1.7 → 1.1.8
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.
|
@@ -5,21 +5,20 @@
|
|
|
5
5
|
* responsible for distributing available bits across frequency bands to minimize
|
|
6
6
|
* perceptual distortion while maintaining the target bitrate.
|
|
7
7
|
*
|
|
8
|
-
* The module uses Rate-Distortion Optimization (RDO)
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
8
|
+
* The module uses Rate-Distortion Optimization (RDO) by searching over a
|
|
9
|
+
* predefined set of valid Band Frequency Unit (BFU) counts. For each count,
|
|
10
|
+
* it performs a greedy bit distribution to find the best allocation. This
|
|
11
|
+
* approach optimally trades off the cost of encoding more frequency bands
|
|
12
|
+
* (metadata overhead) against the benefit of reducing truncation distortion.
|
|
13
13
|
*
|
|
14
14
|
* Key components:
|
|
15
|
-
* - RDO
|
|
16
|
-
* -
|
|
17
|
-
* -
|
|
18
|
-
* - Support for variable word lengths per BFU
|
|
15
|
+
* - RDO search over valid BFU counts to select the optimal number of bands.
|
|
16
|
+
* - Greedy bit allocation for a fixed BFU count using a max-heap.
|
|
17
|
+
* - Exponential distortion modeling based on scale factors.
|
|
18
|
+
* - Support for variable word lengths per BFU.
|
|
19
19
|
*
|
|
20
|
-
* The algorithm ensures that
|
|
21
|
-
*
|
|
22
|
-
* audio compression at the target bitrate.
|
|
20
|
+
* The algorithm ensures that the codec dynamically adapts the encoded bandwidth
|
|
21
|
+
* to best match the signal characteristics for the given bitrate.
|
|
23
22
|
*/
|
|
24
23
|
|
|
25
24
|
import {
|
|
@@ -31,58 +30,158 @@ import {
|
|
|
31
30
|
WORD_LENGTH_BITS,
|
|
32
31
|
INV_POWER_OF_TWO,
|
|
33
32
|
SCALE_FACTORS,
|
|
33
|
+
BFU_AMOUNTS,
|
|
34
34
|
} from '../core/constants.js'
|
|
35
35
|
|
|
36
36
|
/**
|
|
37
|
-
* Allocate bits
|
|
37
|
+
* Allocate bits by finding the optimal BFU count and distribution using RDO.
|
|
38
|
+
* This function searches through the valid BFU counts to find the one that
|
|
39
|
+
* minimizes the total perceptual distortion.
|
|
40
|
+
*
|
|
38
41
|
* @param {Array<Float32Array>} bfuData
|
|
39
42
|
* @param {Int32Array} bfuSizes
|
|
40
|
-
* @param {number} maxBfuCount
|
|
43
|
+
* @param {number} maxBfuCount The maximum BFU index to consider (e.g., from BFU_AMOUNTS)
|
|
41
44
|
* @param {number} allocationBias
|
|
42
45
|
* @returns {{bfuCount:number, allocation:Int32Array, scaleFactorIndices:Int32Array}}
|
|
43
46
|
*/
|
|
44
47
|
export function allocateBits(bfuData, bfuSizes, maxBfuCount, allocationBias) {
|
|
45
|
-
const
|
|
46
|
-
const
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
48
|
+
const allScaleFactorIndices = new Int32Array(maxBfuCount)
|
|
49
|
+
const zeroBitDistortions = new Float32Array(maxBfuCount)
|
|
50
|
+
|
|
51
|
+
for (let i = 0; i < maxBfuCount; i++) {
|
|
52
|
+
const sz = bfuSizes[i] | 0
|
|
53
|
+
if (sz === 0) continue
|
|
54
|
+
|
|
55
|
+
const sfi = findScaleFactor(bfuData[i].subarray(0, sz))
|
|
56
|
+
allScaleFactorIndices[i] = sfi
|
|
57
|
+
if (sfi > 0) {
|
|
58
|
+
const scaleFactor = SCALE_FACTORS[sfi]
|
|
59
|
+
const effectiveScaleFactor = Math.pow(scaleFactor, allocationBias)
|
|
60
|
+
zeroBitDistortions[i] = effectiveScaleFactor * 2.0 * sz
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
let bestResult = null
|
|
65
|
+
let minTotalDistortion = Infinity
|
|
66
|
+
|
|
67
|
+
for (const candidateBfuCount of BFU_AMOUNTS) {
|
|
68
|
+
if (candidateBfuCount > maxBfuCount) continue
|
|
69
|
+
|
|
70
|
+
const availableBits =
|
|
71
|
+
FRAME_BITS -
|
|
72
|
+
FRAME_OVERHEAD_BITS -
|
|
73
|
+
candidateBfuCount * BITS_PER_BFU_METADATA
|
|
74
|
+
|
|
75
|
+
if (availableBits < 0) continue
|
|
76
|
+
|
|
77
|
+
const rdoResult = distributeBitsRDO(
|
|
78
|
+
candidateBfuCount,
|
|
79
|
+
bfuSizes,
|
|
80
|
+
availableBits,
|
|
81
|
+
allocationBias,
|
|
82
|
+
allScaleFactorIndices
|
|
83
|
+
)
|
|
84
|
+
|
|
85
|
+
const totalDistortion = calculateTotalDistortion(
|
|
86
|
+
candidateBfuCount,
|
|
87
|
+
maxBfuCount,
|
|
88
|
+
bfuSizes,
|
|
89
|
+
rdoResult.wordLengths,
|
|
90
|
+
rdoResult.scaleFactorIndices,
|
|
91
|
+
allocationBias,
|
|
92
|
+
zeroBitDistortions
|
|
93
|
+
)
|
|
94
|
+
|
|
95
|
+
if (totalDistortion < minTotalDistortion) {
|
|
96
|
+
minTotalDistortion = totalDistortion
|
|
97
|
+
bestResult = {
|
|
98
|
+
bfuCount: candidateBfuCount,
|
|
99
|
+
allocation: rdoResult.wordLengths,
|
|
100
|
+
scaleFactorIndices: rdoResult.scaleFactorIndices,
|
|
101
|
+
}
|
|
102
|
+
}
|
|
61
103
|
}
|
|
104
|
+
|
|
105
|
+
if (!bestResult) {
|
|
106
|
+
const fallbackBfuCount = BFU_AMOUNTS[0]
|
|
107
|
+
return {
|
|
108
|
+
bfuCount: fallbackBfuCount,
|
|
109
|
+
allocation: new Int32Array(fallbackBfuCount),
|
|
110
|
+
scaleFactorIndices: new Int32Array(NUM_BFUS),
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
return bestResult
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Calculates the total distortion for a given allocation.
|
|
119
|
+
* This includes quantization distortion for coded bands and truncation
|
|
120
|
+
* distortion for uncoded bands.
|
|
121
|
+
* @param {number} activeBfuCount - The number of BFUs that were coded.
|
|
122
|
+
* @param {number} maxBfuCount - The total number of BFUs considered.
|
|
123
|
+
* @param {Int32Array} bfuSizes - Sizes of each BFU.
|
|
124
|
+
* @param {Int32Array} wordLengths - The allocated word length for each active BFU.
|
|
125
|
+
* @param {Int32Array} scaleFactorIndices - The scale factor index for each BFU.
|
|
126
|
+
* @param {number} allocationBias - The RDO bias factor.
|
|
127
|
+
* @param {Float32Array} zeroBitDistortions - Pre-calculated distortion for uncoded bands.
|
|
128
|
+
* @returns {number} The total calculated distortion.
|
|
129
|
+
*/
|
|
130
|
+
function calculateTotalDistortion(
|
|
131
|
+
activeBfuCount,
|
|
132
|
+
maxBfuCount,
|
|
133
|
+
bfuSizes,
|
|
134
|
+
wordLengths,
|
|
135
|
+
scaleFactorIndices,
|
|
136
|
+
allocationBias,
|
|
137
|
+
zeroBitDistortions
|
|
138
|
+
) {
|
|
139
|
+
let totalDistortion = 0.0
|
|
140
|
+
|
|
141
|
+
for (let i = 0; i < activeBfuCount; i++) {
|
|
142
|
+
const wl = wordLengths[i] | 0
|
|
143
|
+
const bits = WORD_LENGTH_BITS[wl] | 0
|
|
144
|
+
if (bits === 0) {
|
|
145
|
+
totalDistortion += zeroBitDistortions[i]
|
|
146
|
+
continue
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
const sfi = scaleFactorIndices[i]
|
|
150
|
+
if (sfi === 0) continue
|
|
151
|
+
|
|
152
|
+
const scaleFactor = SCALE_FACTORS[sfi]
|
|
153
|
+
const effectiveScaleFactor = Math.pow(scaleFactor, allocationBias)
|
|
154
|
+
const distortionFactor = INV_POWER_OF_TWO[bits]
|
|
155
|
+
|
|
156
|
+
totalDistortion += effectiveScaleFactor * distortionFactor * bfuSizes[i]
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
for (let i = activeBfuCount; i < maxBfuCount; i++) {
|
|
160
|
+
totalDistortion += zeroBitDistortions[i]
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
return totalDistortion
|
|
62
164
|
}
|
|
63
165
|
|
|
64
166
|
/**
|
|
65
167
|
* Distributes available bits across Band Frequency Units (BFUs) using Rate-Distortion Optimization.
|
|
66
|
-
*
|
|
67
|
-
* This function implements an optimized greedy RDO allocator that minimizes perceptual distortion
|
|
68
|
-
* while staying within the bit budget. It uses a priority queue (max-heap) to greedily allocate
|
|
69
|
-
* bits to the BFUs that provide the greatest distortion reduction per bit spent.
|
|
168
|
+
* (Modified to accept pre-calculated scale factors)
|
|
70
169
|
*
|
|
71
170
|
* @param {number} activeBfuCount
|
|
72
|
-
* @param {Array<Float32Array>} bfuData
|
|
73
171
|
* @param {Int32Array} bfuSizes
|
|
74
172
|
* @param {number} remainingBits
|
|
75
173
|
* @param {number} allocationBias
|
|
174
|
+
* @param {Int32Array} allScaleFactorIndices - Pre-calculated SFIs for all potential BFUs.
|
|
76
175
|
* @returns {{wordLengths: Int32Array, scaleFactorIndices: Int32Array}}
|
|
77
176
|
*/
|
|
78
177
|
function distributeBitsRDO(
|
|
79
178
|
activeBfuCount,
|
|
80
|
-
bfuData,
|
|
81
179
|
bfuSizes,
|
|
82
180
|
remainingBits,
|
|
83
|
-
allocationBias
|
|
181
|
+
allocationBias,
|
|
182
|
+
allScaleFactorIndices
|
|
84
183
|
) {
|
|
85
|
-
const scaleFactorTable =
|
|
184
|
+
const scaleFactorTable = allScaleFactorIndices
|
|
86
185
|
const wordLengths = new Int32Array(activeBfuCount)
|
|
87
186
|
|
|
88
187
|
const heapIndices = []
|
|
@@ -108,9 +207,7 @@ function distributeBitsRDO(
|
|
|
108
207
|
const sz = bfuSizes[bfuIndex] | 0
|
|
109
208
|
if (sz === 0) continue
|
|
110
209
|
|
|
111
|
-
const sfi =
|
|
112
|
-
scaleFactorTable[bfuIndex] = sfi
|
|
113
|
-
|
|
210
|
+
const sfi = scaleFactorTable[bfuIndex]
|
|
114
211
|
if (sfi === 0) continue
|
|
115
212
|
|
|
116
213
|
const currentWl = 0
|
|
@@ -392,11 +392,16 @@ export function quantizationStage(context) {
|
|
|
392
392
|
scaleFactorIndices,
|
|
393
393
|
} = allocateBits(bfuData, bfuSizes, bfuCount, options.allocationBias)
|
|
394
394
|
|
|
395
|
+
const slicedWordLengthIndices = allocation.slice(0, selectedBfuCount)
|
|
396
|
+
const slicedScaleFactorIndices = scaleFactorIndices.slice(
|
|
397
|
+
0,
|
|
398
|
+
selectedBfuCount
|
|
399
|
+
)
|
|
395
400
|
const quantizedCoefficients = []
|
|
396
401
|
|
|
397
402
|
for (let bfu = 0; bfu < selectedBfuCount; bfu++) {
|
|
398
403
|
const data = bfuData[bfu].subarray(0, bfuSizes[bfu])
|
|
399
|
-
const wordLength =
|
|
404
|
+
const wordLength = slicedWordLengthIndices[bfu]
|
|
400
405
|
const bitsPerSample = WORD_LENGTH_BITS[wordLength]
|
|
401
406
|
const quantized = quantize(data, scaleFactorIndices[bfu], bitsPerSample)
|
|
402
407
|
quantizedCoefficients.push(quantized)
|
|
@@ -404,8 +409,8 @@ export function quantizationStage(context) {
|
|
|
404
409
|
|
|
405
410
|
return {
|
|
406
411
|
nBfu: selectedBfuCount,
|
|
407
|
-
scaleFactorIndices,
|
|
408
|
-
wordLengthIndices:
|
|
412
|
+
scaleFactorIndices: slicedScaleFactorIndices,
|
|
413
|
+
wordLengthIndices: slicedWordLengthIndices,
|
|
409
414
|
quantizedCoefficients,
|
|
410
415
|
blockModes,
|
|
411
416
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var e={},r=44100,t=new Uint8Array([0,8,0,0]),n=2048,o=212,a=new Int32Array([8,8,8,8,4,4,4,4,8,8,8,8,6,6,6,6,6,6,6,6,6,6,6,6,7,7,7,7,9,9,9,9,10,10,10,10,12,12,12,12,12,12,12,12,20,20,20,20,20,20,20,20]),i=new Int32Array([20,28,32,36,40,44,48,52]),u=new Int32Array([20,36,52]),f=new Int32Array([0,8,16,24,32,36,40,44,48,56,64,72,80,86,92,98,104,110,116,122,128,134,140,146,152,159,166,173,180,189,198,207,216,226,236,246,256,268,280,292,304,316,328,340,352,372,392,412,432,452,472,492]),c=new Int32Array([0,32,64,96,8,40,72,104,12,44,76,108,20,52,84,116,26,58,90,122,128,160,192,224,134,166,198,230,141,173,205,237,150,182,214,246,256,288,320,352,384,416,448,480,268,300,332,364,396,428,460,492]),l=256,s=512,v=function(){for(var e=new Float64Array(32),r=0;r<32;r++)e[r]=Math.sin((r+.5)*Math.PI/64);return e}(),h=46,y=new Float32Array([-1461907e-11,-9205479e-11,-56157569e-12,.00030117269,.0002422519,-.00085293897,-.0005205574,.0020340169,.00078333891,-.0042153862,-.00075614988,.0078402944,-61169922e-12,-.01344162,.0024626821,.021736089,-.007801671,-.034090221,.01880949,.054326009,-.043596379,-.099384367,.13207909,.46424159]),d=function(){for(var e=new Float32Array(48),r=0;r<24;r++)e[r]=2*y[r],e[47-r]=2*y[r];return e}(),b=function(){for(var e=new Float32Array(24),r=0;r<24;r++)e[r]=d[2*r];return e}(),p=function(){for(var e=new Float32Array(24),r=0;r<24;r++)e[r]=d[2*r+1];return e}(),m=[{size:128,windowStart:48},{size:128,windowStart:48},{size:256,windowStart:112}],w=32,g=32,k=16,S=32767,A=32768,O=new Int32Array([0,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16]),M=function(){for(var e=new Float64Array(64),r=0;r<64;r++)e[r]=Math.pow(2,r/3-21);return e}(),B=function(){for(var e=O[15],r=new Float64Array(e+1),t=0;t<=e;t++)r[t]=Math.pow(2,-t);return r}();function j(e,r,t,n){if(0!==n){var o=Math.floor(r/8),a=r%8;t&=(1<<n)-1;for(var i=0;i<n&&o<e.length;){var u=8-a,f=Math.min(n-i,u),c=t>>n-i-f&(1<<f)-1,l=(1<<f)-1<<u-f;e[o]=e[o]&~l|c<<u-f,i+=f,o++,a=0}}}function F(e,r,t){if(0===t)return 0;for(var n=Math.floor(r/8),o=r%8,a=0,i=0;i<t&&n<e.length;){var u=8-o,f=Math.min(t-i,u),c=(1<<f)-1;a=a<<f|e[n]>>u-f&c,i+=f,n++,o=0}return a}function P(e,r,t){var n=F(e,r,t);return n>=1<<t-1?n-(1<<t):n}function T(e){return T="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},T(e)}function C(e,r){for(var t=0;t<r.length;t++){var n=r[t];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,x(n.key),n)}}function x(e){var r=function(e,r){if("object"!=T(e)||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var n=t.call(e,r||"default");if("object"!=T(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===r?String:Number)(e)}(e,"string");return"symbol"==T(r)?r:r+""}function z(e,r){var t="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!t){if(Array.isArray(e)||(t=function(e,r){if(e){if("string"==typeof e)return I(e,r);var t={}.toString.call(e).slice(8,-1);return"Object"===t&&e.constructor&&(t=e.constructor.name),"Map"===t||"Set"===t?Array.from(e):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?I(e,r):void 0}}(e))||r&&e&&"number"==typeof e.length){t&&(e=t);var n=0,o=function(){};return{s:o,n:function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}},e:function(e){throw e},f:o}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var a,i=!0,u=!1;return{s:function(){t=t.call(e)},n:function(){var e=t.next();return i=e.done,e},e:function(e){u=!0,a=e},f:function(){try{i||null==t.return||t.return()}finally{if(u)throw a}}}}function I(e,r){(null==r||r>e.length)&&(r=e.length);for(var t=0,n=Array(r);t<r;t++)n[t]=e[t];return n}function q(e){var r=new Uint8Array(o),t=new DataView(r.buffer),n=i.indexOf(e.nBfu),a=2-e.blockModes[0]<<14|2-e.blockModes[1]<<12|3-e.blockModes[2]<<10|n<<5;t.setUint16(0,a,!1);for(var u=16,f=0;f<e.nBfu;f++)j(r,u,e.wordLengthIndices[f],4),u+=4;for(var c=0;c<e.nBfu;c++)j(r,u,e.scaleFactorIndices[c],6),u+=6;for(var l=0;l<e.nBfu;l++){var s=O[e.wordLengthIndices[l]];if(s>0){var v,h=z(e.quantizedCoefficients[l]);try{for(h.s();!(v=h.n()).done;){var y=v.value;j(r,u,y<0?y+(1<<s):y,s),u+=s}}catch(e){h.e(e)}finally{h.f()}}}return r[209]=0,r[210]=0,r[211]=0,r}function E(e){if(e.length!==o)throw new Error("Frame must be ".concat(o," bytes"));for(var r=new DataView(e.buffer,e.byteOffset,e.byteLength).getUint16(0,!1),t=[2-(r>>14&3),2-(r>>12&3),3-(r>>10&3)],n=i[r>>5&7],u=16,f=new Int32Array(n),c=0;c<n;c++)f[c]=F(e,u,4),u+=4;for(var l=new Int32Array(n),s=0;s<n;s++)l[s]=F(e,u,6),u+=6;for(var v=[],h=0;h<n;h++){var y=O[f[h]],d=a[h],b=new Int32Array(d);if(y>0)for(var p=0;p<d;p++)b[p]=P(e,u,y),u+=y;v.push(b)}return{nBfu:n,scaleFactorIndices:l,wordLengthIndices:f,quantizedCoefficients:v,blockModes:t}}var _=function(){return e=function e(){!function(e,r){if(!(e instanceof r))throw new TypeError("Cannot call a class as a function")}(this,e)},o=[{key:"createHeader",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"",r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:1,a=new Uint8Array(n),i=new DataView(a.buffer);a.set(t,0);var u=(new TextEncoder).encode(e);return a.set(u.subarray(0,Math.min(u.length,255)),4),i.setUint32(260,r,!0),a[264]=o,a}},{key:"parseHeader",value:function(e){if(e.length!==n)throw new Error("Header must be ".concat(n," bytes"));for(var r=0;r<t.length;r++)if(e[r]!==t[r])throw new Error("Invalid AEA file");var o=new DataView(e.buffer,e.byteOffset,e.byteLength),a=e.indexOf(0,4),i=-1===a?256:a-4;return{title:(new TextDecoder).decode(e.subarray(4,4+i)),frameCount:o.getUint32(260,!0),channelCount:e[264]}}}],(r=null)&&C(e.prototype,r),o&&C(e,o),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,r,o}();function D(e){return D="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},D(e)}function U(e,r){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);r&&(n=n.filter(function(r){return Object.getOwnPropertyDescriptor(e,r).enumerable})),t.push.apply(t,n)}return t}function H(e){for(var r=1;r<arguments.length;r++){var t=null!=arguments[r]?arguments[r]:{};r%2?U(Object(t),!0).forEach(function(r){W(e,r,t[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):U(Object(t)).forEach(function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(t,r))})}return e}function W(e,r,t){return(r=V(r))in e?Object.defineProperty(e,r,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[r]=t,e}function L(e,r){return function(e){if(Array.isArray(e))return e}(e)||function(e,r){var t=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=t){var n,o,a,i,u=[],f=!0,c=!1;try{if(a=(t=t.call(e)).next,0===r){if(Object(t)!==t)return;f=!1}else for(;!(f=(n=a.call(t)).done)&&(u.push(n.value),u.length!==r);f=!0);}catch(e){c=!0,o=e}finally{try{if(!f&&null!=t.return&&(i=t.return(),Object(i)!==i))return}finally{if(c)throw o}}return u}}(e,r)||function(e,r){if(e){if("string"==typeof e)return G(e,r);var t={}.toString.call(e).slice(8,-1);return"Object"===t&&e.constructor&&(t=e.constructor.name),"Map"===t||"Set"===t?Array.from(e):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?G(e,r):void 0}}(e,r)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function G(e,r){(null==r||r>e.length)&&(r=e.length);for(var t=0,n=Array(r);t<r;t++)n[t]=e[t];return n}function N(e,r){for(var t=0;t<r.length;t++){var n=r[t];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,V(n.key),n)}}function V(e){var r=function(e,r){if("object"!=D(e)||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var n=t.call(e,r||"default");if("object"!=D(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===r?String:Number)(e)}(e,"string");return"symbol"==D(r)?r:r+""}var R=function(){return e=function e(){var r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};!function(e,r){if(!(e instanceof r))throw new TypeError("Cannot call a class as a function")}(this,e),this.values={transientThresholdLow:1,transientThresholdMid:1.5,transientThresholdHigh:2,allocationBias:1,fixedBlockModes:null},this.metadata={transientThresholdLow:{default:this.values.transientThresholdLow,name:"Low Band Transient Threshold",description:"Controls the transient detection threshold for the low frequency band (0-5.5kHz). Lower values make detection more sensitive, triggering short blocks more easily. Higher values require stronger transients.",range:[.01,2],step:.01},transientThresholdMid:{default:this.values.transientThresholdMid,name:"Mid Band Transient Threshold",description:"Controls the transient detection threshold for the mid frequency band (5.5-11kHz). Lower values make detection more sensitive, triggering short blocks more easily. Higher values require stronger transients.",range:[.01,3],step:.01},transientThresholdHigh:{default:this.values.transientThresholdHigh,name:"High Band Transient Threshold",description:"Controls the transient detection threshold for the high frequency band (11-22kHz). Lower values make detection more sensitive, triggering short blocks more easily. Higher values require stronger transients.",range:[.01,4],step:.01},allocationBias:{default:this.values.allocationBias,name:"Bit allocation bias",description:"Controls how bits are distributed across the frequency spectrum during allocation. Higher values focus more bits on loud spectral components, while lower values spread bits more evenly across frequencies.",range:[.5,3],step:.01},fixedBlockModes:{default:this.values.fixedBlockModes,name:"Fixed block modes",description:"Override transient detection and use fixed block modes. Format: [low, mid, high] where low/mid can be 0 or 2, high can be 0 or 3. When set, transient detection is skipped.",type:"array"}},r&&this.setOptions(r)},(r=[{key:"setOptions",value:function(e){for(var r=0,t=Object.entries(e);r<t.length;r++){var n=L(t[r],2),o=n[0],a=n[1];o in this.values&&this.setValue(o,a)}}},{key:"setValue",value:function(e,r){if(!(e in this.metadata))throw new Error("Unknown option: ".concat(e));var t=this.metadata[e];if("array"!==t.type){var n=L(t.range,2),o=n[0],a=n[1];if(r<o||r>a)throw new Error("Value for ".concat(e," must be between ").concat(o," and ").concat(a,", got ").concat(r))}this.values[e]=r}},{key:"getValue",value:function(e){if(!(e in this.values))throw new Error("Unknown option: ".concat(e));return this.values[e]}},{key:"transientThresholdLow",get:function(){return this.values.transientThresholdLow}},{key:"transientThresholdMid",get:function(){return this.values.transientThresholdMid}},{key:"transientThresholdHigh",get:function(){return this.values.transientThresholdHigh}},{key:"allocationBias",get:function(){return this.values.allocationBias}},{key:"fixedBlockModes",get:function(){return this.values.fixedBlockModes}},{key:"getMetadata",value:function(e){return this.metadata[e]}},{key:"getAllMetadata",value:function(){return H({},this.metadata)}},{key:"reset",value:function(){for(var e=0,r=Object.entries(this.metadata);e<r.length;e++){var t=L(r[e],2),n=t[0],o=t[1];this.values[n]=o.default}}},{key:"toObject",value:function(){return{values:H({},this.values),metadata:H({},this.metadata)}}}])&&N(e.prototype,r),t&&N(e,t),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,r,t}();function $(e){throw new Error(e)}function J(e){for(var r=arguments.length,t=new Array(r>1?r-1:0),n=1;n<r;n++)t[n-1]=arguments[n];var o=t.map(function(r){return r(e)});return function(e){return o.reduce(function(e,r){return r(e)},e)}}function K(e,r){for(var t=r[e.length],n=0;n<e.length;n++)t[n]=e[e.length-1-n];return t}function Q(e,r){var t,n,o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null,a=e.length,i=a>>1,u=null!==(t=null==o||null===(n=o.delay)||void 0===n?void 0:n[a])&&void 0!==t?t:$("qmfAnalysis: qmfWorkBuffers.delay[".concat(a,"] is required"));u.set(r),u.set(e,r.length);for(var f=new Float32Array(i),c=new Float32Array(i),l=0;l<i;l++){for(var s=0,v=0,h=2*l,y=0;y<24;y++)s+=u[h+47-2*y]*b[y],v+=u[h+46-2*y]*p[y];f[l]=s+v,c[l]=s-v}return{lowBand:f,highBand:c,newDelay:u.slice(-46)}}function X(e,r,t){var n,o,a=arguments.length>3&&void 0!==arguments[3]?arguments[3]:null,i=e.length,u=2*i,f=null!==(n=null==a||null===(o=a.delay)||void 0===o?void 0:o[u])&&void 0!==n?n:$("qmfSynthesis: qmfWorkBuffers.delay[".concat(u,"] is required"));f.set(t);for(var c=0;c<i;c++){var l=e[c],s=r[c],v=h+2*c;f[v]=.5*(l+s),f[v+1]=.5*(l-s)}for(var y=new Float32Array(u),d=0;d<i;d++){for(var m=2*d,w=0,g=0,k=0;k<24;k++){var S=m+2*k;w+=f[S]*b[k],g+=f[S+1]*p[k]}y[2*d]=g,y[2*d+1]=w}return{output:y,newDelay:f.slice(-46)}}function Y(e){return Y="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},Y(e)}function Z(e,r){for(var t=0;t<r.length;t++){var n=r[t];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,ee(n.key),n)}}function ee(e){var r=function(e,r){if("object"!=Y(e)||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var n=t.call(e,r||"default");if("object"!=Y(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===r?String:Number)(e)}(e,"string");return"symbol"==Y(r)?r:r+""}var re=function(){return e=function e(){!function(e,r){if(!(e instanceof r))throw new TypeError("Cannot call a class as a function")}(this,e)},t=[{key:"fft",value:function(e,r){var t=e.length;if(1!==t){for(var n=Math.log2(t),o=0;o<t;o++){for(var a=0,i=o,u=0;u<n;u++)a=a<<1|1&i,i>>=1;if(a>o){var f=[e[a],e[o]];e[o]=f[0],e[a]=f[1];var c=[r[a],r[o]];r[o]=c[0],r[a]=c[1]}}for(var l=2;l<=t;l<<=1)for(var s=l>>1,v=-2*Math.PI/l,h=Math.cos(v),y=Math.sin(v),d=0;d<t;d+=l)for(var b=1,p=0,m=0;m<s;m++){var w=d+m,g=w+s,k=e[w],S=r[w],A=e[g],O=r[g],M=A*b-O*p,B=A*p+O*b;e[w]=k+M,r[w]=S+B,e[g]=k-M,r[g]=S-B;var j=b*h-p*y;p=b*y+p*h,b=j}}}}],(r=null)&&Z(e.prototype,r),t&&Z(e,t),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,r,t}();function te(e){return te="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},te(e)}function ne(e,r,t){return r=ae(r),function(e,r){if(r&&("object"==te(r)||"function"==typeof r))return r;if(void 0!==r)throw new TypeError("Derived constructors may only return object or undefined");return function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e)}(e,oe()?Reflect.construct(r,t||[],ae(e).constructor):r.apply(e,t))}function oe(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(oe=function(){return!!e})()}function ae(e){return ae=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},ae(e)}function ie(e,r){if("function"!=typeof r&&null!==r)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(r&&r.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),r&&ue(e,r)}function ue(e,r){return ue=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,r){return e.__proto__=r,e},ue(e,r)}function fe(e,r){for(var t=0;t<r.length;t++){var n=r[t];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,le(n.key),n)}}function ce(e,r,t){return r&&fe(e.prototype,r),t&&fe(e,t),Object.defineProperty(e,"prototype",{writable:!1}),e}function le(e){var r=function(e,r){if("object"!=te(e)||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var n=t.call(e,r||"default");if("object"!=te(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===r?String:Number)(e)}(e,"string");return"symbol"==te(r)?r:r+""}function se(e,r){if(!(e instanceof r))throw new TypeError("Cannot call a class as a function")}var ve=ce(function e(r,t){se(this,e),this.size=r,this.halfSize=r>>1,this.quarterSize=r>>2,this.fftSize=this.halfSize>>1;var n=2*Math.PI/(8*r),o=2*Math.PI/r,a=Math.sqrt(t/r);this.sinCosTable=new Float64Array(this.halfSize);for(var i=0;i<this.quarterSize;i++){var u=o*i+n;this.sinCosTable[2*i]=a*Math.cos(u),this.sinCosTable[2*i+1]=a*Math.sin(u)}}),he=function(){function e(r,t){return se(this,e),ne(this,e,[r,t])}return ie(e,ve),ce(e,[{key:"transform",value:function(e){var r,t,n,o=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null,a=null!==(r=null==o?void 0:o[this.fftSize])&&void 0!==r?r:$("MDCT.transform: mdctBuffers[".concat(this.fftSize,"] is required")),i=null!==(t=null==a?void 0:a.real)&&void 0!==t?t:$("MDCT.transform: mdctBuffers[".concat(this.fftSize,"].real is required")),u=null!==(n=null==a?void 0:a.imag)&&void 0!==n?n:$("MDCT.transform: mdctBuffers[".concat(this.fftSize,"].imag is required")),f=this.quarterSize,c=3*f;i.fill(0),u.fill(0);for(var l=0;l<f;l+=2){var s=c+l,v=f+l,h=f-1-l,y=e[c-1-l]+e[s],d=e[v]-e[h],b=this.sinCosTable[l],p=this.sinCosTable[l+1];i[l>>1]=y*b+d*p,u[l>>1]=d*b-y*p}for(var m=f;m<this.halfSize;m+=2){var w=m>>1,g=m-f,k=f+m,S=5*f-1-m,A=e[c-1-m]-e[g],O=e[k]+e[S],M=this.sinCosTable[m],B=this.sinCosTable[m+1];i[w]=A*M+O*B,u[w]=O*M-A*B}re.fft(i,u);for(var j=new Float32Array(this.halfSize),F=0;F<this.fftSize;F++){var P=this.sinCosTable[2*F],T=this.sinCosTable[2*F+1],C=i[F],x=u[F];j[2*F]=-C*P-x*T,j[this.halfSize-1-2*F]=-C*T+x*P}return j}}])}(),ye=function(){function e(r){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;return se(this,e),ne(this,e,[r,t||r])}return ie(e,ve),ce(e,[{key:"transform",value:function(e){var r,t,n,o=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null,a=null!==(r=null==o?void 0:o[this.fftSize])&&void 0!==r?r:$("IMDCT.transform: mdctBuffers[".concat(this.fftSize,"] is required")),i=null!==(t=null==a?void 0:a.real)&&void 0!==t?t:$("IMDCT.transform: mdctBuffers[".concat(this.fftSize,"].real is required")),u=null!==(n=null==a?void 0:a.imag)&&void 0!==n?n:$("IMDCT.transform: mdctBuffers[".concat(this.fftSize,"].imag is required")),f=this.quarterSize,c=3*f;i.fill(0),u.fill(0);for(var l=0;l<this.fftSize;l++){var s=2*l,v=-e[s],h=-e[this.halfSize-1-s],y=this.sinCosTable[s],d=this.sinCosTable[s+1];i[l]=h*d+v*y,u[l]=h*y-v*d}re.fft(i,u);for(var b=new Float32Array(this.size),p=0;p<this.fftSize/2;p++){var m=2*p,w=this.sinCosTable[m],g=this.sinCosTable[m+1],k=i[p],S=u[p],A=k*w+S*g,O=k*g-S*w;b[c-1-m]=A,b[c+m]=A,b[f+m]=O,b[f-1-m]=-O}for(var M=this.fftSize/2;M<this.fftSize;M++){var B=2*(M-this.fftSize/2)+f,j=2*M,F=this.sinCosTable[j],P=this.sinCosTable[j+1],T=i[M],C=u[M],x=T*F+C*P,z=T*P-C*F;b[c-1-B]=x,b[B-f]=-x,b[f+B]=z,b[5*f-1-B]=z}return b}}])}(),de=new he(64,.5),be=new he(l,.5),pe=new he(s,1),me=new ye(64,512),we=new ye(l,2048),ge=new ye(s,2048);function ke(e,r,t){for(var n=e.length,o=new Float32Array(2*n),a=0;a<n;a++){var i=t[a],u=t[2*n-1-a],f=e[a],c=r[n-1-a];o[a]=f*u-c*i,o[2*n-1-a]=f*i+c*u}return o}function Se(e,r,t){var n=e.length,o=new Int32Array(n);if(0===t||0===r)return o.fill(0,0,n),o;for(var a=(1<<t-1)-1,i=a/M[r],u=a,f=-a,c=0;c<n;c++){var l=e[c]*i,s=l+(l>=0?.5:-.5)|0;o[c]=s>u?u:s<f?f:s}return o}function Ae(e,r,t){if(0===t||0===r)return new Float32Array(e.length);for(var n=M[r],o=(1<<t-1)-1,a=new Float32Array(e.length),i=0;i<e.length;i++)a[i]=e[i]*n/o;return a}function Oe(e,r,t,n){var o=t,a=function(e,r,t,n,o){for(var a=new Int32Array(52),i=new Int32Array(e),u=[],f=[],c=function(e,r,t){var n=a[e],i=M[n];if(0===i)return 0;var u=Math.pow(i,o),f=0|O[r],c=0|O[t];return u*((0===f?2:B[f])-B[c])},l=0;l<e;l++){var s=0|t[l];if(0!==s){var v=Me(r[l].subarray(0,s));if(a[l]=v,0!==v){var h=0,y=1,d=O[y]-O[h]|0;if(!(d<=0)){var b=c(l,h,y);u.push(l),f.push(b/d)}}}}for(var p=(u.length>>1)-1;p>=0;p--)je(u,f,p);for(;n>0&&u.length>0;){var m=u[0],w=0|i[m],g=w+1,k=0|t[m],S=(O[g]-O[w]|0)*k;if(S>n||S<=0)Be(u,f);else if(n-=S,i[m]=g,g<15){var A=g+1,j=O[A]-O[g]|0;j>0?(f[0]=c(m,g,A)/j,je(u,f,0)):Be(u,f)}else Be(u,f)}return{wordLengths:i,scaleFactorIndices:a}}(o,e,r,1656-10*o,n);return{bfuCount:o,allocation:a.wordLengths,scaleFactorIndices:a.scaleFactorIndices}}function Me(e){for(var r=0,t=0;t<e.length;t++){var n=Math.abs(e[t]);n>r&&(r=n)}if(0===r)return 0;var o=Math.ceil(3*(Math.log2(r)+21));return Math.max(0,Math.min(63,o))}function Be(e,r){var t=e.length-1;e[0]=e[t],r[0]=r[t],e.pop(),r.pop(),e.length&&je(e,r,0)}function je(e,r,t){for(var n=e.length,o=t,a=e[o],i=r[o];;){var u=1+(o<<1),f=u+1,c=o,l=i;if(u<n&&r[u]>l&&(c=u,l=r[u]),f<n&&r[f]>l&&(c=f),c===o)break;e[o]=e[c],r[o]=r[c],o=c}e[o]=a,r[o]=i}function Fe(e){return Fe="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},Fe(e)}function Pe(e,r){for(var t=0;t<r.length;t++){var n=r[t];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,Ce(n.key),n)}}function Te(e,r,t){return r&&Pe(e.prototype,r),t&&Pe(e,t),Object.defineProperty(e,"prototype",{writable:!1}),e}function Ce(e){var r=function(e,r){if("object"!=Fe(e)||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var n=t.call(e,r||"default");if("object"!=Fe(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===r?String:Number)(e)}(e,"string");return"symbol"==Fe(r)?r:r+""}var xe=Te(function e(){!function(e,r){if(!(e instanceof r))throw new TypeError("Cannot call a class as a function")}(this,e),this.transformBuffers={64:new Float32Array(64),128:new Float32Array(128),256:new Float32Array(256),512:new Float32Array(512)},this.qmfWorkBuffers={delay:{128:new Float32Array(174),256:new Float32Array(302),512:new Float32Array(558)},highBandDelay:{128:new Float32Array(167),256:new Float32Array(295)}},this.qmfDelays={lowBand:new Float32Array(h),midBand:new Float32Array(h),highBand:new Float32Array(39)},this.transientDetection=[new Float32Array(64),new Float32Array(64),new Float32Array(128)],this.mdctBuffers={16:{real:new Float32Array(16),imag:new Float32Array(16)},64:{real:new Float32Array(64),imag:new Float32Array(64)},128:{real:new Float32Array(128),imag:new Float32Array(128)}},this.mdctOverlap=[new Float32Array(32),new Float32Array(32),new Float32Array(32)],this.imdctOverlap=[new Float32Array(256),new Float32Array(256),new Float32Array(512)],this.reversalBuffers={32:new Float32Array(32),128:new Float32Array(128),256:new Float32Array(256)}});function ze(e,r,t){if(!r)return!1;var n=function(e,r){var t=function(e,r){for(var t=0,n=0,o=0;o<e.length;o++){var a=Math.abs(e[o]),i=a-Math.abs(r[o]);i>0&&(t+=i),n+=a*a}var u=Math.sqrt(n)||1e-6;return t/u}(e,r),n=Ie(e),o=Ie(r),a=Math.abs(n-o),i=qe(e),u=qe(r),f=Math.abs(i-u),c=function(e,r){for(var t=0,n=0,o=0;o<e.length;o++)t+=e[o]*e[o],n+=r[o]*r[o];t=Math.max(t,1e-10),n=Math.max(n,1e-10);var a=10*Math.log10(t/n);return Math.max(0,a)}(e,r);return{spectralFlux:t,flatnessChange:a,hfChange:f,energyChange:c}}(e,r),o=function(e){var r=e.spectralFlux,t=e.flatnessChange,n=e.hfChange,o=e.energyChange,a=r,i=Math.sqrt(t),u=Math.log1p(10*n)/Math.log1p(10),f=Math.min(o/30,1);return(a+i+u+f)/4}(n);return o>t}function Ie(e){for(var r=0,t=0,n=0,o=0;o<e.length;o++){var a=Math.abs(e[o]);a>1e-10&&(r+=Math.log(a),t+=a,n++)}if(0===n)return 0;var i=Math.exp(r/n),u=t/n;return u>1e-10?i/u:0}function qe(e){for(var r=Math.floor(e.length/2),t=0,n=0,o=0;o<r;o++)t+=e[o]*e[o];for(var a=r;a<e.length;a++)n+=e[a]*e[a];var i=t+n;return i>0?n/i:0}function Ee(e){var r,t=null!==(r=null==e?void 0:e.bufferPool)&&void 0!==r?r:$("qmfAnalysisStage: bufferPool is required"),n=t.qmfDelays;return function(e){var r=Q(e,n.lowBand,t.qmfWorkBuffers);n.lowBand=r.newDelay;var o=Q(r.lowBand,n.midBand,t.qmfWorkBuffers);n.midBand=o.newDelay;var a=t.qmfWorkBuffers.highBandDelay[r.highBand.length];a.set(n.highBand),a.set(r.highBand,n.highBand.length);var i=a.slice(0,r.highBand.length);return n.highBand=a.slice(r.highBand.length),{bands:[o.lowBand,o.highBand,i]}}}function _e(e){var r,t,n=null!==(r=null==e?void 0:e.bufferPool)&&void 0!==r?r:$("blockSelectorStage: bufferPool is required"),o=null!==(t=null==e?void 0:e.options)&&void 0!==t?t:$("blockSelectorStage: options is required");return function(e){var r,t=e.bands;if(o.fixedBlockModes)r=o.fixedBlockModes;else{var a=[128,128,256];r=t.map(function(e,r){var t=function(e,r){var t=new Float32Array(r),n=new Float32Array(r),o=Math.min(e.length,r);t.set(e.subarray(0,o)),re.fft(t,n);for(var a=new Float32Array(r/2),i=0;i<r/2;i++)a[i]=Math.sqrt(t[i]*t[i]+n[i]*n[i]);return a}(e,a[r]),i=ze(t,n.transientDetection[r],o.transientThresholdLow);return n.transientDetection[r]=t,i*Math.max(r+1,2)})}return{bands:t,blockModes:r}}}function De(e){var r,t=null!==(r=null==e?void 0:e.bufferPool)&&void 0!==r?r:$("mdctStage: bufferPool is required"),n=t.mdctOverlap,o=[be,be,pe];function a(e,r,t,n,a){var u=m[r];return 0===t?function(e,r,t,n,o,a){var u=2===r?s:l,f=a.transformBuffers[u];f.fill(0),f.set(o,t.windowStart),i(e,o,t.size),f.set(e,t.windowStart+32);var c=n.transform(f,a.mdctBuffers);r>0&&(c=K(c,a.reversalBuffers));return c}(e,r,u,o[r],n,a):function(e,r,t,n,o){for(var a=1<<(256===t.size?3:2),u=new Float32Array(t.size),f=0;f<a;f++){var c=f*w,l=e.subarray(c,c+w),s=o.transformBuffers[64];s.fill(0),s.set(n,0),i(l,n,w),s.set(l,g);var v=de.transform(s,o.mdctBuffers);r>0&&(v=K(v,o.reversalBuffers)),u.set(v,c)}return u}(e,r,u,n,a)}function i(e,r,t){for(var n=t-g,o=0;o<g;o++){var a=e[n+o];r[o]=v[o]*a,e[n+o]=a*v[31-o]}}return function(e){var r=e.bands,o=e.blockModes,i=e.originalFrame,u=new Float32Array(512);return r.forEach(function(e,r){var i=a(e,r,o[r],n[r],t),f=function(e){return 0===e?0:1===e?128:256}(r);u.set(i,f)}),{bands:r,coefficients:u,blockModes:o,originalFrame:i}}}function Ue(e){var r,t=null!==(r=null==e?void 0:e.options)&&void 0!==r?r:$("quantizationStage: options is required");return function(e){for(var r=e.coefficients,n=e.blockModes,o=function(e,r){for(var t=[],n=[],o=0,i=0,l=0;l<3;l++){for(var s=o,v=2===l?256:128,h=l<2?u[l]:a.length,y=0===r[l]?f:c;i<h;){var d=a[i],b=y[i]-s,p=b+d,m=new Float32Array(d);if(b>=0&&p<=v)m.set(e.subarray(s+b,s+p));else if(m.fill(0),b<v&&p>0){var w=Math.max(0,b),g=Math.min(v,p);m.set(e.subarray(s+w,s+g),Math.max(0,-b))}t.push(m),n.push(d),i++}o+=v}return{bfuData:t,bfuSizes:n,bfuCount:i}}(r,n),i=o.bfuData,l=o.bfuSizes,s=Oe(i,l,o.bfuCount,t.allocationBias),v=s.bfuCount,h=s.allocation,y=s.scaleFactorIndices,d=[],b=0;b<v;b++){var p=i[b].subarray(0,l[b]),m=h[b],w=O[m],g=Se(p,y[b],w);d.push(g)}return{nBfu:v,scaleFactorIndices:y,wordLengthIndices:h.slice(0,v),quantizedCoefficients:d,blockModes:n}}}function He(){return J({options:arguments.length>0&&void 0!==arguments[0]?arguments[0]:new R,bufferPool:arguments.length>1&&void 0!==arguments[1]?arguments[1]:new xe},Ee,_e,De,Ue)}function We(){return function(e){for(var r=new Float32Array(512),t=e.nBfu,n=e.scaleFactorIndices,o=e.wordLengthIndices,a=e.quantizedCoefficients,i=e.blockModes,l=0;l<t;l++){var s=O[o[l]],v=0;l>=u[0]&&(v=1),l>=u[1]&&(v=2);var h=0===i[v]?f[l]:c[l];if(s>0){var y=Ae(a[l],n[l],s);r.set(y,h)}}return{coefficients:r,blockModes:i}}}function Le(e){var r,t=null!==(r=null==e?void 0:e.bufferPool)&&void 0!==r?r:$("imdctStage: bufferPool is required"),n=t.imdctOverlap,o=[we,we,ge];function a(e,r,t,n,a,i){return 0===t?function(e,r,t,n,o,a){var i=e;r>0&&(i=K(e,n.reversalBuffers));var u=a.transform(i,n.mdctBuffers),f=u.length/4,c=n.transformBuffers[512];c.fill(0);for(var l=0;l<o.size;l++)c[l]=u[f+l];var s=t.slice(2*o.size-k,2*o.size),h=ke(s.slice(0,k),c.slice(0,k),v);t.set(h,0);for(var y=0;y<k;y++)s[y]=c[k+y];for(var d=2===r?240:112,b=0;b<d;b++)t[32+b]=c[k+b];for(var p=0;p<k;p++)t[2*o.size-k+p]=c[o.size-k+p];return t.slice(0,o.size)}(e,r,n,a,i,o[r]):function(e,r,t,n,o){var a=1<<(256===o.size?3:2),i=n.transformBuffers[512];i.fill(0);for(var u=t.slice(2*o.size-k,2*o.size),f=0,c=0,l=0;l<a;l++){var s=e.slice(c,c+w);r>0&&(s=K(s,n.reversalBuffers));for(var h=me.transform(s,n.mdctBuffers),y=h.length/4,d=0;d<w;d++)i[f+d]=h[y+d];var b=ke(u.slice(0,k),i.slice(f,f+k),v);t.set(b,f);for(var p=0;p<k;p++)u[p]=i[f+k+p];f+=w,c+=w}for(var m=0;m<k;m++)t[2*o.size-k+m]=i[o.size-k+m];return t.slice(0,o.size)}(e,r,n,a,i)}return function(e){var r=e.coefficients,o=e.blockModes;return m.map(function(e,i){var u=function(e,r){var t=[0,128,256,512];return e.subarray(t[r],t[r+1])}(r,i);return a(u,i,o[i],n[i],t,e)})}}function Ge(e){var r,t=null!==(r=null==e?void 0:e.bufferPool)&&void 0!==r?r:$("qmfSynthesisStage: bufferPool is required"),n=t.qmfDelays;return function(e){var r=t.qmfWorkBuffers.highBandDelay[e[2].length];r.set(n.highBand),r.set(e[2],n.highBand.length);var o=r.slice(0,2*e[0].length);n.highBand=r.slice(2*e[0].length);var a=X(e[0],e[1],n.midBand,t.qmfWorkBuffers);n.midBand=a.newDelay;var i=X(a.output,o,n.lowBand,t.qmfWorkBuffers);return n.lowBand=i.newDelay,i.output}}function Ne(){return J({bufferPool:arguments.length>0&&void 0!==arguments[0]?arguments[0]:new xe},We,Le,Ge)}function Ve(e){return Ve="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},Ve(e)}function Re(e,r){var t="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!t){if(Array.isArray(e)||(t=Qe(e))||r&&e&&"number"==typeof e.length){t&&(e=t);var n=0,o=function(){};return{s:o,n:function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}},e:function(e){throw e},f:o}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var a,i=!0,u=!1;return{s:function(){t=t.call(e)},n:function(){var e=t.next();return i=e.done,e},e:function(e){u=!0,a=e},f:function(){try{i||null==t.return||t.return()}finally{if(u)throw a}}}}function $e(e,r,t,n,o,a,i){try{var u=e[a](i),f=u.value}catch(e){return void t(e)}u.done?r(f):Promise.resolve(f).then(n,o)}function Je(e){return function(){var r=this,t=arguments;return new Promise(function(n,o){var a=e.apply(r,t);function i(e){$e(a,n,o,i,u,"next",e)}function u(e){$e(a,n,o,i,u,"throw",e)}i(void 0)})}}function Ke(e,r){return function(e){if(Array.isArray(e))return e}(e)||function(e,r){var t=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=t){var n,o,a,i,u=[],f=!0,c=!1;try{if(a=(t=t.call(e)).next,0===r){if(Object(t)!==t)return;f=!1}else for(;!(f=(n=a.call(t)).done)&&(u.push(n.value),u.length!==r);f=!0);}catch(e){c=!0,o=e}finally{try{if(!f&&null!=t.return&&(i=t.return(),Object(i)!==i))return}finally{if(c)throw o}}return u}}(e,r)||Qe(e,r)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function Qe(e,r){if(e){if("string"==typeof e)return Xe(e,r);var t={}.toString.call(e).slice(8,-1);return"Object"===t&&e.constructor&&(t=e.constructor.name),"Map"===t||"Set"===t?Array.from(e):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?Xe(e,r):void 0}}function Xe(e,r){(null==r||r>e.length)&&(r=e.length);for(var t=0,n=Array(r);t<r;t++)n[t]=e[t];return n}function Ye(e){if(null!=e){var r=e["function"==typeof Symbol&&Symbol.iterator||"@@iterator"],t=0;if(r)return r.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length))return{next:function(){return e&&t>=e.length&&(e=void 0),{value:e&&e[t++],done:!e}}}}throw new TypeError(Ve(e)+" is not iterable")}function Ze(){/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */var e,r,t="function"==typeof Symbol?Symbol:{},n=t.iterator||"@@iterator",o=t.toStringTag||"@@toStringTag";function a(t,n,o,a){var f=n&&n.prototype instanceof u?n:u,c=Object.create(f.prototype);return er(c,"_invoke",function(t,n,o){var a,u,f,c=0,l=o||[],s=!1,v={p:0,n:0,v:e,a:h,f:h.bind(e,4),d:function(r,t){return a=r,u=0,f=e,v.n=t,i}};function h(t,n){for(u=t,f=n,r=0;!s&&c&&!o&&r<l.length;r++){var o,a=l[r],h=v.p,y=a[2];t>3?(o=y===n)&&(f=a[(u=a[4])?5:(u=3,3)],a[4]=a[5]=e):a[0]<=h&&((o=t<2&&h<a[1])?(u=0,v.v=n,v.n=a[1]):h<y&&(o=t<3||a[0]>n||n>y)&&(a[4]=t,a[5]=n,v.n=y,u=0))}if(o||t>1)return i;throw s=!0,n}return function(o,l,y){if(c>1)throw TypeError("Generator is already running");for(s&&1===l&&h(l,y),u=l,f=y;(r=u<2?e:f)||!s;){a||(u?u<3?(u>1&&(v.n=-1),h(u,f)):v.n=f:v.v=f);try{if(c=2,a){if(u||(o="next"),r=a[o]){if(!(r=r.call(a,f)))throw TypeError("iterator result is not an object");if(!r.done)return r;f=r.value,u<2&&(u=0)}else 1===u&&(r=a.return)&&r.call(a),u<2&&(f=TypeError("The iterator does not provide a '"+o+"' method"),u=1);a=e}else if((r=(s=v.n<0)?f:t.call(n,v))!==i)break}catch(r){a=e,u=1,f=r}finally{c=1}}return{value:r,done:s}}}(t,o,a),!0),c}var i={};function u(){}function f(){}function c(){}r=Object.getPrototypeOf;var l=[][n]?r(r([][n]())):(er(r={},n,function(){return this}),r),s=c.prototype=u.prototype=Object.create(l);function v(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,c):(e.__proto__=c,er(e,o,"GeneratorFunction")),e.prototype=Object.create(s),e}return f.prototype=c,er(s,"constructor",c),er(c,"constructor",f),f.displayName="GeneratorFunction",er(c,o,"GeneratorFunction"),er(s),er(s,o,"Generator"),er(s,n,function(){return this}),er(s,"toString",function(){return"[object Generator]"}),(Ze=function(){return{w:a,m:v}})()}function er(e,r,t,n){var o=Object.defineProperty;try{o({},"",{})}catch(e){o=0}er=function(e,r,t,n){if(r)o?o(e,r,{value:t,enumerable:!n,configurable:!n,writable:!n}):e[r]=t;else{var a=function(r,t){er(e,r,function(e){return this._invoke(r,t,e)})};a("next",0),a("throw",1),a("return",2)}},er(e,r,t,n)}function rr(e,r){for(var t=0;t<r.length;t++){var n=r[t];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,tr(n.key),n)}}function tr(e){var r=function(e,r){if("object"!=Ve(e)||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var n=t.call(e,r||"default");if("object"!=Ve(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===r?String:Number)(e)}(e,"string");return"symbol"==Ve(r)?r:r+""}function nr(e){return function(){return new or(e.apply(this,arguments))}}function or(e){var r,t;function n(r,t){try{var a=e[r](t),i=a.value,u=i instanceof ur;Promise.resolve(u?i.v:i).then(function(t){if(u){var f="return"===r?"return":"next";if(!i.k||t.done)return n(f,t);t=e[f](t).value}o(a.done?"return":"normal",t)},function(e){n("throw",e)})}catch(e){o("throw",e)}}function o(e,o){switch(e){case"return":r.resolve({value:o,done:!0});break;case"throw":r.reject(o);break;default:r.resolve({value:o,done:!1})}(r=r.next)?n(r.key,r.arg):t=null}this._invoke=function(e,o){return new Promise(function(a,i){var u={key:e,arg:o,resolve:a,reject:i,next:null};t?t=t.next=u:(r=t=u,n(e,o))})},"function"!=typeof e.return&&(this.return=void 0)}function ar(e){return new ur(e,0)}function ir(e){var r={},t=!1;function n(r,n){return t=!0,n=new Promise(function(t){t(e[r](n))}),{done:!1,value:new ur(n,1)}}return r["undefined"!=typeof Symbol&&Symbol.iterator||"@@iterator"]=function(){return this},r.next=function(e){return t?(t=!1,e):n("next",e)},"function"==typeof e.throw&&(r.throw=function(e){if(t)throw t=!1,e;return n("throw",e)}),"function"==typeof e.return&&(r.return=function(e){return t?(t=!1,e):n("return",e)}),r}function ur(e,r){this.v=e,this.k=r}function fr(e){var r,t,n,o=2;for("undefined"!=typeof Symbol&&(t=Symbol.asyncIterator,n=Symbol.iterator);o--;){if(t&&null!=(r=e[t]))return r.call(e);if(n&&null!=(r=e[n]))return new cr(r.call(e));t="@@asyncIterator",n="@@iterator"}throw new TypeError("Object is not async iterable")}function cr(e){function r(e){if(Object(e)!==e)return Promise.reject(new TypeError(e+" is not an object."));var r=e.done;return Promise.resolve(e.value).then(function(e){return{value:e,done:r}})}return cr=function(e){this.s=e,this.n=e.next},cr.prototype={s:null,n:null,next:function(){return r(this.n.apply(this.s,arguments))},return:function(e){var t=this.s.return;return void 0===t?Promise.resolve({value:e,done:!0}):r(t.apply(this.s,arguments))},throw:function(e){var t=this.s.return;return void 0===t?Promise.reject(e):r(t.apply(this.s,arguments))}},new cr(e)}or.prototype["function"==typeof Symbol&&Symbol.asyncIterator||"@@asyncIterator"]=function(){return this},or.prototype.next=function(e){return this._invoke("next",e)},or.prototype.throw=function(e){return this._invoke("throw",e)},or.prototype.return=function(e){return this._invoke("return",e)};var lr=function(){function e(){!function(e,r){if(!(e instanceof r))throw new TypeError("Cannot call a class as a function")}(this,e)}return t=e,a=null,i=[{key:"encodeStream",value:function(r){return nr(function(r){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return Ze().m(function n(){var o,a,i,u;return Ze().w(function(n){for(;;)switch(n.n){case 0:if(o=t.channelCount,a=void 0===o?1:o,i=t.onProgress,u=t.encoderOptions,1!==a){n.n=2;break}return n.d(Ye(ir(fr(e._encodeMonoStream(r,i,u)))),1);case 1:case 3:n.n=5;break;case 2:if(2!==a){n.n=4;break}return n.d(Ye(ir(fr(e._encodeStereoStream(r,i,u)))),3);case 4:throw new Error("Unsupported channel count: ".concat(a));case 5:return n.a(2)}},n)})()}).apply(this,arguments)}},{key:"_encodeMonoStream",value:function(e,r,t){return nr(Ze().m(function n(){var o,a,i,u,f,c,l,s,v,h,y;return Ze().w(function(n){for(;;)switch(n.n){case 0:o=t||new R,a=He(o),i=0,u=!1,f=!1,n.p=1,l=fr(e);case 2:return n.n=3,ar(l.next());case 3:if(!(u=!(s=n.v).done)){n.n=6;break}return v=s.value,h=a(v),n.n=4,h;case 4:r&&r(i++);case 5:u=!1,n.n=2;break;case 6:n.n=8;break;case 7:n.p=7,y=n.v,f=!0,c=y;case 8:if(n.p=8,n.p=9,!u||null==l.return){n.n=10;break}return n.n=10,ar(l.return());case 10:if(n.p=10,!f){n.n=11;break}throw c;case 11:return n.f(10);case 12:return n.f(8);case 13:return n.a(2)}},n,null,[[9,,10,12],[1,7,8,13]])}))()}},{key:"_encodeStereoStream",value:function(e,r,t){return nr(Ze().m(function n(){var o,a,i,u,f,c,l,s,v,h,y,d,b,p,m;return Ze().w(function(n){for(;;)switch(n.n){case 0:o=t||new R,a=He(o),i=He(o),u=0,f=!1,c=!1,n.p=1,s=fr(e);case 2:return n.n=3,ar(s.next());case 3:if(!(f=!(v=n.v).done)){n.n=7;break}return h=Ke(v.value,2),y=h[0],d=h[1],b=a(y),p=i(d),n.n=4,b;case 4:return n.n=5,p;case 5:r&&r(u++);case 6:f=!1,n.n=2;break;case 7:n.n=9;break;case 8:n.p=8,m=n.v,c=!0,l=m;case 9:if(n.p=9,n.p=10,!f||null==s.return){n.n=11;break}return n.n=11,ar(s.return());case 11:if(n.p=11,!c){n.n=12;break}throw l;case 12:return n.f(11);case 13:return n.f(9);case 14:return n.a(2)}},n,null,[[10,,11,13],[1,8,9,14]])}))()}},{key:"decodeStream",value:function(r){return nr(function(r){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return Ze().m(function n(){var o,a,i;return Ze().w(function(n){for(;;)switch(n.n){case 0:if(o=t.channelCount,a=void 0===o?1:o,i=t.onProgress,1!==a){n.n=2;break}return n.d(Ye(ir(fr(e._decodeMonoStream(r,i)))),1);case 1:case 3:n.n=5;break;case 2:if(2!==a){n.n=4;break}return n.d(Ye(ir(fr(e._decodeStereoStream(r,i)))),3);case 4:throw new Error("Unsupported channel count: ".concat(a));case 5:return n.a(2)}},n)})()}).apply(this,arguments)}},{key:"_decodeMonoStream",value:function(e,r){return nr(Ze().m(function t(){var n,o,a;return Ze().w(function(t){for(;;)switch(t.n){case 0:return n=Ne(),o=0,a=function(){var t=nr(Ze().m(function t(){var a,i,u,f,c,l,s,v;return Ze().w(function(t){for(;;)switch(t.n){case 0:a=!1,i=!1,t.p=1,f=fr(e);case 2:return t.n=3,ar(f.next());case 3:if(!(a=!(c=t.v).done)){t.n=6;break}return l=c.value,s=n(l),t.n=4,s;case 4:r&&r(o++);case 5:a=!1,t.n=2;break;case 6:t.n=8;break;case 7:t.p=7,v=t.v,i=!0,u=v;case 8:if(t.p=8,t.p=9,!a||null==f.return){t.n=10;break}return t.n=10,ar(f.return());case 10:if(t.p=10,!i){t.n=11;break}throw u;case 11:return t.f(10);case 12:return t.f(8);case 13:return t.a(2)}},t,null,[[9,,10,12],[1,7,8,13]])}));return function(){return t.apply(this,arguments)}}(),t.d(Ye(ir(fr(a()))),1);case 1:return t.a(2)}},t)}))()}},{key:"_decodeStereoStream",value:function(r,t){return nr(Ze().m(function n(){var o,a,i,u;return Ze().w(function(n){for(;;)switch(n.n){case 0:return o=Ne(),a=Ne(),i=0,u=function(){var n=nr(Ze().m(function n(){var u,f,c,l,s,v,h,y,d,b,p,m,w,g,k;return Ze().w(function(n){for(;;)switch(n.n){case 0:u=null,f=!0,c=!1,l=!1,n.p=1,v=fr(r);case 2:return n.n=3,ar(v.next());case 3:if(!(c=!(h=n.v).done)){n.n=8;break}if(y=h.value,!f){n.n=4;break}u=y,n.n=6;break;case 4:return d=y,b=o(u),p=a(d),n.n=5,[b,p];case 5:t&&t(i++);case 6:f=!f;case 7:c=!1,n.n=2;break;case 8:n.n=10;break;case 9:n.p=9,k=n.v,l=!0,s=k;case 10:if(n.p=10,n.p=11,!c||null==v.return){n.n=12;break}return n.n=12,ar(v.return());case 12:if(n.p=12,!l){n.n=13;break}throw s;case 13:return n.f(12);case 14:return n.f(10);case 15:if(f||!u){n.n=17;break}return m=e._createDummyFrame(),w=o(u),g=a(m),n.n=16,[w,g];case 16:t&&t(i++);case 17:return n.a(2)}},n,null,[[11,,12,14],[1,9,10,15]])}));return function(){return n.apply(this,arguments)}}(),n.d(Ye(ir(fr(u()))),1);case 1:return n.a(2)}},n)}))()}},{key:"frameBufferToFrames",value:function(e){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:512;return Ze().m(function t(){var n,o,a,i,u,f,c,l,s,v,h,y,d,b,p,m;return Ze().w(function(t){for(;;)switch(t.n){case 0:if(1!==(n=e.length)){t.n=4;break}o=Ke(e,1),a=o[0],i=0;case 1:if(!(i<a.length)){t.n=3;break}for(u=new Float32Array(r),f=Math.min(i+r,a.length),c=0;c<f-i;c++)u[c]=a[i+c];return t.n=2,u;case 2:i+=r,t.n=1;break;case 3:t.n=9;break;case 4:if(2!==n){t.n=8;break}l=Ke(e,2),s=l[0],v=l[1],h=Math.max(s.length,v.length),y=0;case 5:if(!(y<h)){t.n=7;break}for(d=new Float32Array(r),b=new Float32Array(r),p=Math.min(y+r,h),m=0;m<p-y;m++)d[m]=y+m<s.length?s[y+m]:0,b[m]=y+m<v.length?v[y+m]:0;return t.n=6,[d,b];case 6:y+=r,t.n=5;break;case 7:t.n=9;break;case 8:throw new Error("Unsupported channel count: ".concat(n));case 9:return t.a(2)}},t)})()}},{key:"collectFrames",value:(c=Je(Ze().m(function e(r){var t,n,o,a,i,u,f,c;return Ze().w(function(e){for(;;)switch(e.n){case 0:t=[],n=!1,o=!1,e.p=1,i=fr(r);case 2:return e.n=3,i.next();case 3:if(!(n=!(u=e.v).done)){e.n=5;break}f=u.value,t.push(f);case 4:n=!1,e.n=2;break;case 5:e.n=7;break;case 6:e.p=6,c=e.v,o=!0,a=c;case 7:if(e.p=7,e.p=8,!n||null==i.return){e.n=9;break}return e.n=9,i.return();case 9:if(e.p=9,!o){e.n=10;break}throw a;case 10:return e.f(9);case 11:return e.f(7);case 12:return e.a(2,t)}},e,null,[[8,,9,11],[1,6,7,12]])})),function(e){return c.apply(this,arguments)})},{key:"_createDummyFrame",value:function(){return{nBfu:0,blockModes:[0,0,0],scaleFactorIndices:new Int32Array(0),wordLengthIndices:new Int32Array(0),quantizedCoefficients:[]}}},{key:"createAeaBlob",value:(f=Je(Ze().m(function e(r){var t,n,o,a,i,u,f,c,l,s,v,h,y,d,b,p,m,w,g,k,S=arguments;return Ze().w(function(e){for(;;)switch(e.n){case 0:n=(t=S.length>1&&void 0!==S[1]?S[1]:{}).title,o=void 0===n?"encoded by atrac1.js":n,a=t.channelCount,i=void 0===a?1:a,u=[],f=!1,c=!1,e.p=1,s=fr(r);case 2:return e.n=3,s.next();case 3:if(!(f=!(v=e.v).done)){e.n=5;break}h=v.value,u.push(q(h));case 4:f=!1,e.n=2;break;case 5:e.n=7;break;case 6:e.p=6,k=e.v,c=!0,l=k;case 7:if(e.p=7,e.p=8,!f||null==s.return){e.n=9;break}return e.n=9,s.return();case 9:if(e.p=9,!c){e.n=10;break}throw l;case 10:return e.f(9);case 11:return e.f(7);case 12:for(y=_.createHeader(o,u.length,i),d=y.length+u.reduce(function(e,r){return e+r.length},0),(b=new Uint8Array(d)).set(y,0),p=y.length,m=0,w=u;m<w.length;m++)g=w[m],b.set(g,p),p+=g.length;return e.a(2,new Blob([b],{type:"application/octet-stream"}))}},e,null,[[8,,9,11],[1,6,7,12]])})),function(e){return f.apply(this,arguments)})},{key:"createWavBlob",value:function(t){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1,o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:r,a=Array.isArray(t)?t:[t];if(1===n)return e._createMonoWavBlob(a,o);if(2===n)return e._createStereoWavBlob(a,o);throw new Error("Unsupported channel count: ".concat(n))}},{key:"_createMonoWavBlob",value:function(r,t){var n=r.reduce(function(e,r){return e+r.length},0),o=new ArrayBuffer(44+2*n),a=new DataView(o);e._writeWavHeader(a,n,1,t);var i,u=44,f=Re(r);try{for(f.s();!(i=f.n()).done;)for(var c=i.value,l=0;l<c.length;l++){var s=Math.max(-1,Math.min(1,c[l]));a.setInt16(u,s<0?s*A:s*S,!0),u+=2}}catch(e){f.e(e)}finally{f.f()}return new Blob([o],{type:"audio/wav"})}},{key:"_createStereoWavBlob",value:function(r,t){var n=r.reduce(function(e,r){var t=Ke(r,2),n=t[0],o=t[1];return e+Math.max(n.length,o.length)},0),o=new ArrayBuffer(44+2*n*2),a=new DataView(o);e._writeWavHeader(a,n,2,t);var i,u=44,f=Re(r);try{for(f.s();!(i=f.n()).done;)for(var c=Ke(i.value,2),l=c[0],s=c[1],v=Math.max(l.length,s.length),h=0;h<v;h++){var y=h<l.length?l[h]:0,d=h<s.length?s[h]:0,b=Math.max(-1,Math.min(1,y)),p=Math.max(-1,Math.min(1,d));a.setInt16(u,b<0?b*A:b*S,!0),u+=2,a.setInt16(u,p<0?p*A:p*S,!0),u+=2}}catch(e){f.e(e)}finally{f.f()}return new Blob([o],{type:"audio/wav"})}},{key:"_writeWavHeader",value:function(e,r,t,n){var o=n*t*2,a=2*t,i=r*a,u=36+i,f=0,c=function(r,t){for(var n=0;n<t.length;n++)e.setUint8(r+n,t.charCodeAt(n))};c(f,"RIFF"),f+=4,e.setUint32(f,u,!0),c(f+=4,"WAVE"),c(f+=4,"fmt "),f+=4,e.setUint32(f,16,!0),f+=4,e.setUint16(f,1,!0),f+=2,e.setUint16(f,t,!0),f+=2,e.setUint32(f,n,!0),f+=4,e.setUint32(f,o,!0),f+=4,e.setUint16(f,a,!0),f+=2,e.setUint16(f,16,!0),c(f+=2,"data"),f+=4,e.setUint32(f,i,!0)}},{key:"parseAeaBlob",value:(u=Je(Ze().m(function e(r){var t,a,i,u,f,c;return Ze().w(function(e){for(;;)switch(e.n){case 0:return e.n=1,r.arrayBuffer();case 1:for(t=e.v,a=new Uint8Array(t.slice(0,n)),i=_.parseHeader(a),u=[],f=n;f<t.byteLength;f+=o)(c=new Uint8Array(t.slice(f,f+o))).length===o&&u.push(c);return e.a(2,{info:i,frameData:u})}},e)})),function(e){return u.apply(this,arguments)})},{key:"deserializedFrameStream",value:Ze().m(function e(r){var t,n,o,a;return Ze().w(function(e){for(;;)switch(e.n){case 0:t=Re(r),e.p=1,t.s();case 2:if((n=t.n()).done){e.n=4;break}return o=n.value,e.n=3,E(o);case 3:e.n=2;break;case 4:e.n=6;break;case 5:e.p=5,a=e.v,t.e(a);case 6:return e.p=6,t.f(),e.f(6);case 7:return e.a(2)}},e,null,[[1,5,6,7]])})},{key:"assemblePcmFrames",value:function(e,r){if(1===r){var t,n=e.reduce(function(e,r){return e+r.length},0),o=new Float32Array(n),a=0,i=Re(e);try{for(i.s();!(t=i.n()).done;){var u=t.value;o.set(u,a),a+=u.length}}catch(e){i.e(e)}finally{i.f()}return o}if(2===r){var f,c=e.reduce(function(e,r){var t=Ke(r,2),n=t[0],o=t[1];return e+Math.max(n.length,o.length)},0),l=new Float32Array(2*c),s=0,v=Re(e);try{for(v.s();!(f=v.n()).done;)for(var h=Ke(f.value,2),y=h[0],d=h[1],b=Math.max(y.length,d.length),p=0;p<b;p++)l[2*s]=p<y.length?y[p]:0,l[2*s+1]=p<d.length?d[p]:0,s++}catch(e){v.e(e)}finally{v.f()}return l}throw new Error("Unsupported channel count: ".concat(r))}}],a&&rr(t.prototype,a),i&&rr(t,i),Object.defineProperty(t,"prototype",{writable:!1}),t;var t,a,i,u,f,c}();function sr(e){return sr="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},sr(e)}function vr(e,r){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);r&&(n=n.filter(function(r){return Object.getOwnPropertyDescriptor(e,r).enumerable})),t.push.apply(t,n)}return t}function hr(e){for(var r=1;r<arguments.length;r++){var t=null!=arguments[r]?arguments[r]:{};r%2?vr(Object(t),!0).forEach(function(r){yr(e,r,t[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):vr(Object(t)).forEach(function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(t,r))})}return e}function yr(e,r,t){return(r=function(e){var r=function(e,r){if("object"!=sr(e)||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var n=t.call(e,r||"default");if("object"!=sr(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===r?String:Number)(e)}(e,"string");return"symbol"==sr(r)?r:r+""}(r))in e?Object.defineProperty(e,r,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[r]=t,e}function dr(){/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */var e,r,t="function"==typeof Symbol?Symbol:{},n=t.iterator||"@@iterator",o=t.toStringTag||"@@toStringTag";function a(t,n,o,a){var f=n&&n.prototype instanceof u?n:u,c=Object.create(f.prototype);return br(c,"_invoke",function(t,n,o){var a,u,f,c=0,l=o||[],s=!1,v={p:0,n:0,v:e,a:h,f:h.bind(e,4),d:function(r,t){return a=r,u=0,f=e,v.n=t,i}};function h(t,n){for(u=t,f=n,r=0;!s&&c&&!o&&r<l.length;r++){var o,a=l[r],h=v.p,y=a[2];t>3?(o=y===n)&&(f=a[(u=a[4])?5:(u=3,3)],a[4]=a[5]=e):a[0]<=h&&((o=t<2&&h<a[1])?(u=0,v.v=n,v.n=a[1]):h<y&&(o=t<3||a[0]>n||n>y)&&(a[4]=t,a[5]=n,v.n=y,u=0))}if(o||t>1)return i;throw s=!0,n}return function(o,l,y){if(c>1)throw TypeError("Generator is already running");for(s&&1===l&&h(l,y),u=l,f=y;(r=u<2?e:f)||!s;){a||(u?u<3?(u>1&&(v.n=-1),h(u,f)):v.n=f:v.v=f);try{if(c=2,a){if(u||(o="next"),r=a[o]){if(!(r=r.call(a,f)))throw TypeError("iterator result is not an object");if(!r.done)return r;f=r.value,u<2&&(u=0)}else 1===u&&(r=a.return)&&r.call(a),u<2&&(f=TypeError("The iterator does not provide a '"+o+"' method"),u=1);a=e}else if((r=(s=v.n<0)?f:t.call(n,v))!==i)break}catch(r){a=e,u=1,f=r}finally{c=1}}return{value:r,done:s}}}(t,o,a),!0),c}var i={};function u(){}function f(){}function c(){}r=Object.getPrototypeOf;var l=[][n]?r(r([][n]())):(br(r={},n,function(){return this}),r),s=c.prototype=u.prototype=Object.create(l);function v(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,c):(e.__proto__=c,br(e,o,"GeneratorFunction")),e.prototype=Object.create(s),e}return f.prototype=c,br(s,"constructor",c),br(c,"constructor",f),f.displayName="GeneratorFunction",br(c,o,"GeneratorFunction"),br(s),br(s,o,"Generator"),br(s,n,function(){return this}),br(s,"toString",function(){return"[object Generator]"}),(dr=function(){return{w:a,m:v}})()}function br(e,r,t,n){var o=Object.defineProperty;try{o({},"",{})}catch(e){o=0}br=function(e,r,t,n){if(r)o?o(e,r,{value:t,enumerable:!n,configurable:!n,writable:!n}):e[r]=t;else{var a=function(r,t){br(e,r,function(e){return this._invoke(r,t,e)})};a("next",0),a("throw",1),a("return",2)}},br(e,r,t,n)}function pr(e,r,t,n,o,a,i){try{var u=e[a](i),f=u.value}catch(e){return void t(e)}u.done?r(f):Promise.resolve(f).then(n,o)}function mr(e){return function(){var r=this,t=arguments;return new Promise(function(n,o){var a=e.apply(r,t);function i(e){pr(a,n,o,i,u,"next",e)}function u(e){pr(a,n,o,i,u,"throw",e)}i(void 0)})}}function wr(e,r,t){return gr.apply(this,arguments)}function gr(){return(gr=mr(dr().m(function e(r,t,n){var o,a,i,u,f,c,l;return dr().w(function(e){for(;;)switch(e.n){case 0:return n=null!=n?n:"encoded by carta1",e.p=1,o=lr.frameBufferToFrames(r),a=r.length,i=new R(t),u=lr.encodeStream(o,{channelCount:a,encoderOptions:i}),e.n=2,lr.collectFrames(u);case 2:return f=e.v,e.n=3,lr.createAeaBlob(f,{title:n,channelCount:a});case 3:return c=e.v,e.a(2,{aeaBlob:c});case 4:throw e.p=4,l=e.v,console.error("Worker encode error:",l),l;case 5:return e.a(2)}},e,null,[[1,4]])}))).apply(this,arguments)}function kr(){return(new R).toObject()}function Sr(e){return Ar.apply(this,arguments)}function Ar(){return(Ar=mr(dr().m(function e(t){var n,o,a,i,u,f,c,l,s;return dr().w(function(e){for(;;)switch(e.n){case 0:return n=t.header,o=t.aeaData,(a=t.info)?i=hr({sampleRate:r},a):n?(u=_.parseHeader(n),i=hr({sampleRate:r},u)):i={channelCount:2,sampleRate:r},f=lr.deserializedFrameStream(o),c=lr.decodeStream(f,{channelCount:i.channelCount}),e.n=1,lr.collectFrames(c);case 1:return l=e.v,s=lr.createWavBlob(l,i.channelCount,i.sampleRate),e.a(2,{wavBlob:s,info:i})}},e)}))).apply(this,arguments)}self.onmessage=function(){var e=mr(dr().m(function e(r){var t,n,o,a,i,u,f,c,l,s,v;return dr().w(function(e){for(;;)switch(e.n){case 0:t=r.data,n=t.jobId,o=t.type,a=t.pcmData,i=t.aea,u=t.options,f=t.title,c=t.blob,e.p=1,s=o,e.n="encode"===s?2:"decode"===s?4:"parseAea"===s?6:"getEncoderOptions"===s?8:9;break;case 2:return e.n=3,wr(a,u,f);case 3:return l=e.v,e.a(3,10);case 4:return e.n=5,Sr(i);case 5:return l=e.v,e.a(3,10);case 6:return e.n=7,lr.parseAeaBlob(c);case 7:return l=e.v,e.a(3,10);case 8:return l=kr(),e.a(3,10);case 9:throw new Error("Unknown worker message type: ".concat(o));case 10:self.postMessage({jobId:n,result:l}),e.n=12;break;case 11:e.p=11,v=e.v,console.error("Worker error:",v),self.postMessage({jobId:n,error:v.message});case 12:return e.a(2)}},e,null,[[1,11]])}));return function(r){return e.apply(this,arguments)}}();var Or=self;for(var Mr in e)Or[Mr]=e[Mr];e.__esModule&&Object.defineProperty(Or,"__esModule",{value:!0});
|
|
1
|
+
var e={},r=44100,t=new Uint8Array([0,8,0,0]),n=2048,o=212,a=new Int32Array([8,8,8,8,4,4,4,4,8,8,8,8,6,6,6,6,6,6,6,6,6,6,6,6,7,7,7,7,9,9,9,9,10,10,10,10,12,12,12,12,12,12,12,12,20,20,20,20,20,20,20,20]),i=new Int32Array([20,28,32,36,40,44,48,52]),u=new Int32Array([20,36,52]),f=new Int32Array([0,8,16,24,32,36,40,44,48,56,64,72,80,86,92,98,104,110,116,122,128,134,140,146,152,159,166,173,180,189,198,207,216,226,236,246,256,268,280,292,304,316,328,340,352,372,392,412,432,452,472,492]),c=new Int32Array([0,32,64,96,8,40,72,104,12,44,76,108,20,52,84,116,26,58,90,122,128,160,192,224,134,166,198,230,141,173,205,237,150,182,214,246,256,288,320,352,384,416,448,480,268,300,332,364,396,428,460,492]),l=256,s=512,v=function(){for(var e=new Float64Array(32),r=0;r<32;r++)e[r]=Math.sin((r+.5)*Math.PI/64);return e}(),h=46,y=new Float32Array([-1461907e-11,-9205479e-11,-56157569e-12,.00030117269,.0002422519,-.00085293897,-.0005205574,.0020340169,.00078333891,-.0042153862,-.00075614988,.0078402944,-61169922e-12,-.01344162,.0024626821,.021736089,-.007801671,-.034090221,.01880949,.054326009,-.043596379,-.099384367,.13207909,.46424159]),d=function(){for(var e=new Float32Array(48),r=0;r<24;r++)e[r]=2*y[r],e[47-r]=2*y[r];return e}(),b=function(){for(var e=new Float32Array(24),r=0;r<24;r++)e[r]=d[2*r];return e}(),p=function(){for(var e=new Float32Array(24),r=0;r<24;r++)e[r]=d[2*r+1];return e}(),m=[{size:128,windowStart:48},{size:128,windowStart:48},{size:256,windowStart:112}],w=32,g=32,k=16,S=32767,A=32768,M=new Int32Array([0,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16]),O=function(){for(var e=new Float64Array(64),r=0;r<64;r++)e[r]=Math.pow(2,r/3-21);return e}(),j=function(){for(var e=M[15],r=new Float64Array(e+1),t=0;t<=e;t++)r[t]=Math.pow(2,-t);return r}();function B(e,r,t,n){if(0!==n){var o=Math.floor(r/8),a=r%8;t&=(1<<n)-1;for(var i=0;i<n&&o<e.length;){var u=8-a,f=Math.min(n-i,u),c=t>>n-i-f&(1<<f)-1,l=(1<<f)-1<<u-f;e[o]=e[o]&~l|c<<u-f,i+=f,o++,a=0}}}function F(e,r,t){if(0===t)return 0;for(var n=Math.floor(r/8),o=r%8,a=0,i=0;i<t&&n<e.length;){var u=8-o,f=Math.min(t-i,u),c=(1<<f)-1;a=a<<f|e[n]>>u-f&c,i+=f,n++,o=0}return a}function P(e,r,t){var n=F(e,r,t);return n>=1<<t-1?n-(1<<t):n}function T(e){return T="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},T(e)}function I(e,r){for(var t=0;t<r.length;t++){var n=r[t];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,C(n.key),n)}}function C(e){var r=function(e,r){if("object"!=T(e)||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var n=t.call(e,r||"default");if("object"!=T(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===r?String:Number)(e)}(e,"string");return"symbol"==T(r)?r:r+""}function x(e,r){var t="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!t){if(Array.isArray(e)||(t=function(e,r){if(e){if("string"==typeof e)return z(e,r);var t={}.toString.call(e).slice(8,-1);return"Object"===t&&e.constructor&&(t=e.constructor.name),"Map"===t||"Set"===t?Array.from(e):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?z(e,r):void 0}}(e))||r&&e&&"number"==typeof e.length){t&&(e=t);var n=0,o=function(){};return{s:o,n:function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}},e:function(e){throw e},f:o}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var a,i=!0,u=!1;return{s:function(){t=t.call(e)},n:function(){var e=t.next();return i=e.done,e},e:function(e){u=!0,a=e},f:function(){try{i||null==t.return||t.return()}finally{if(u)throw a}}}}function z(e,r){(null==r||r>e.length)&&(r=e.length);for(var t=0,n=Array(r);t<r;t++)n[t]=e[t];return n}function q(e){var r=new Uint8Array(o),t=new DataView(r.buffer),n=i.indexOf(e.nBfu),a=2-e.blockModes[0]<<14|2-e.blockModes[1]<<12|3-e.blockModes[2]<<10|n<<5;t.setUint16(0,a,!1);for(var u=16,f=0;f<e.nBfu;f++)B(r,u,e.wordLengthIndices[f],4),u+=4;for(var c=0;c<e.nBfu;c++)B(r,u,e.scaleFactorIndices[c],6),u+=6;for(var l=0;l<e.nBfu;l++){var s=M[e.wordLengthIndices[l]];if(s>0){var v,h=x(e.quantizedCoefficients[l]);try{for(h.s();!(v=h.n()).done;){var y=v.value;B(r,u,y<0?y+(1<<s):y,s),u+=s}}catch(e){h.e(e)}finally{h.f()}}}return r[209]=0,r[210]=0,r[211]=0,r}function E(e){if(e.length!==o)throw new Error("Frame must be ".concat(o," bytes"));for(var r=new DataView(e.buffer,e.byteOffset,e.byteLength).getUint16(0,!1),t=[2-(r>>14&3),2-(r>>12&3),3-(r>>10&3)],n=i[r>>5&7],u=16,f=new Int32Array(n),c=0;c<n;c++)f[c]=F(e,u,4),u+=4;for(var l=new Int32Array(n),s=0;s<n;s++)l[s]=F(e,u,6),u+=6;for(var v=[],h=0;h<n;h++){var y=M[f[h]],d=a[h],b=new Int32Array(d);if(y>0)for(var p=0;p<d;p++)b[p]=P(e,u,y),u+=y;v.push(b)}return{nBfu:n,scaleFactorIndices:l,wordLengthIndices:f,quantizedCoefficients:v,blockModes:t}}var _=function(){return e=function e(){!function(e,r){if(!(e instanceof r))throw new TypeError("Cannot call a class as a function")}(this,e)},o=[{key:"createHeader",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"",r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:1,a=new Uint8Array(n),i=new DataView(a.buffer);a.set(t,0);var u=(new TextEncoder).encode(e);return a.set(u.subarray(0,Math.min(u.length,255)),4),i.setUint32(260,r,!0),a[264]=o,a}},{key:"parseHeader",value:function(e){if(e.length!==n)throw new Error("Header must be ".concat(n," bytes"));for(var r=0;r<t.length;r++)if(e[r]!==t[r])throw new Error("Invalid AEA file");var o=new DataView(e.buffer,e.byteOffset,e.byteLength),a=e.indexOf(0,4),i=-1===a?256:a-4;return{title:(new TextDecoder).decode(e.subarray(4,4+i)),frameCount:o.getUint32(260,!0),channelCount:e[264]}}}],(r=null)&&I(e.prototype,r),o&&I(e,o),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,r,o}();function D(e){return D="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},D(e)}function U(e,r){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);r&&(n=n.filter(function(r){return Object.getOwnPropertyDescriptor(e,r).enumerable})),t.push.apply(t,n)}return t}function H(e){for(var r=1;r<arguments.length;r++){var t=null!=arguments[r]?arguments[r]:{};r%2?U(Object(t),!0).forEach(function(r){L(e,r,t[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):U(Object(t)).forEach(function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(t,r))})}return e}function L(e,r,t){return(r=V(r))in e?Object.defineProperty(e,r,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[r]=t,e}function W(e,r){return function(e){if(Array.isArray(e))return e}(e)||function(e,r){var t=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=t){var n,o,a,i,u=[],f=!0,c=!1;try{if(a=(t=t.call(e)).next,0===r){if(Object(t)!==t)return;f=!1}else for(;!(f=(n=a.call(t)).done)&&(u.push(n.value),u.length!==r);f=!0);}catch(e){c=!0,o=e}finally{try{if(!f&&null!=t.return&&(i=t.return(),Object(i)!==i))return}finally{if(c)throw o}}return u}}(e,r)||function(e,r){if(e){if("string"==typeof e)return G(e,r);var t={}.toString.call(e).slice(8,-1);return"Object"===t&&e.constructor&&(t=e.constructor.name),"Map"===t||"Set"===t?Array.from(e):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?G(e,r):void 0}}(e,r)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function G(e,r){(null==r||r>e.length)&&(r=e.length);for(var t=0,n=Array(r);t<r;t++)n[t]=e[t];return n}function N(e,r){for(var t=0;t<r.length;t++){var n=r[t];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,V(n.key),n)}}function V(e){var r=function(e,r){if("object"!=D(e)||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var n=t.call(e,r||"default");if("object"!=D(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===r?String:Number)(e)}(e,"string");return"symbol"==D(r)?r:r+""}var R=function(){return e=function e(){var r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};!function(e,r){if(!(e instanceof r))throw new TypeError("Cannot call a class as a function")}(this,e),this.values={transientThresholdLow:1,transientThresholdMid:1.5,transientThresholdHigh:2,allocationBias:1,fixedBlockModes:null},this.metadata={transientThresholdLow:{default:this.values.transientThresholdLow,name:"Low Band Transient Threshold",description:"Controls the transient detection threshold for the low frequency band (0-5.5kHz). Lower values make detection more sensitive, triggering short blocks more easily. Higher values require stronger transients.",range:[.01,2],step:.01},transientThresholdMid:{default:this.values.transientThresholdMid,name:"Mid Band Transient Threshold",description:"Controls the transient detection threshold for the mid frequency band (5.5-11kHz). Lower values make detection more sensitive, triggering short blocks more easily. Higher values require stronger transients.",range:[.01,3],step:.01},transientThresholdHigh:{default:this.values.transientThresholdHigh,name:"High Band Transient Threshold",description:"Controls the transient detection threshold for the high frequency band (11-22kHz). Lower values make detection more sensitive, triggering short blocks more easily. Higher values require stronger transients.",range:[.01,4],step:.01},allocationBias:{default:this.values.allocationBias,name:"Bit allocation bias",description:"Controls how bits are distributed across the frequency spectrum during allocation. Higher values focus more bits on loud spectral components, while lower values spread bits more evenly across frequencies.",range:[.5,3],step:.01},fixedBlockModes:{default:this.values.fixedBlockModes,name:"Fixed block modes",description:"Override transient detection and use fixed block modes. Format: [low, mid, high] where low/mid can be 0 or 2, high can be 0 or 3. When set, transient detection is skipped.",type:"array"}},r&&this.setOptions(r)},(r=[{key:"setOptions",value:function(e){for(var r=0,t=Object.entries(e);r<t.length;r++){var n=W(t[r],2),o=n[0],a=n[1];o in this.values&&this.setValue(o,a)}}},{key:"setValue",value:function(e,r){if(!(e in this.metadata))throw new Error("Unknown option: ".concat(e));var t=this.metadata[e];if("array"!==t.type){var n=W(t.range,2),o=n[0],a=n[1];if(r<o||r>a)throw new Error("Value for ".concat(e," must be between ").concat(o," and ").concat(a,", got ").concat(r))}this.values[e]=r}},{key:"getValue",value:function(e){if(!(e in this.values))throw new Error("Unknown option: ".concat(e));return this.values[e]}},{key:"transientThresholdLow",get:function(){return this.values.transientThresholdLow}},{key:"transientThresholdMid",get:function(){return this.values.transientThresholdMid}},{key:"transientThresholdHigh",get:function(){return this.values.transientThresholdHigh}},{key:"allocationBias",get:function(){return this.values.allocationBias}},{key:"fixedBlockModes",get:function(){return this.values.fixedBlockModes}},{key:"getMetadata",value:function(e){return this.metadata[e]}},{key:"getAllMetadata",value:function(){return H({},this.metadata)}},{key:"reset",value:function(){for(var e=0,r=Object.entries(this.metadata);e<r.length;e++){var t=W(r[e],2),n=t[0],o=t[1];this.values[n]=o.default}}},{key:"toObject",value:function(){return{values:H({},this.values),metadata:H({},this.metadata)}}}])&&N(e.prototype,r),t&&N(e,t),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,r,t}();function $(e){throw new Error(e)}function J(e){for(var r=arguments.length,t=new Array(r>1?r-1:0),n=1;n<r;n++)t[n-1]=arguments[n];var o=t.map(function(r){return r(e)});return function(e){return o.reduce(function(e,r){return r(e)},e)}}function K(e,r){for(var t=r[e.length],n=0;n<e.length;n++)t[n]=e[e.length-1-n];return t}function Q(e,r){var t,n,o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null,a=e.length,i=a>>1,u=null!==(t=null==o||null===(n=o.delay)||void 0===n?void 0:n[a])&&void 0!==t?t:$("qmfAnalysis: qmfWorkBuffers.delay[".concat(a,"] is required"));u.set(r),u.set(e,r.length);for(var f=new Float32Array(i),c=new Float32Array(i),l=0;l<i;l++){for(var s=0,v=0,h=2*l,y=0;y<24;y++)s+=u[h+47-2*y]*b[y],v+=u[h+46-2*y]*p[y];f[l]=s+v,c[l]=s-v}return{lowBand:f,highBand:c,newDelay:u.slice(-46)}}function X(e,r,t){var n,o,a=arguments.length>3&&void 0!==arguments[3]?arguments[3]:null,i=e.length,u=2*i,f=null!==(n=null==a||null===(o=a.delay)||void 0===o?void 0:o[u])&&void 0!==n?n:$("qmfSynthesis: qmfWorkBuffers.delay[".concat(u,"] is required"));f.set(t);for(var c=0;c<i;c++){var l=e[c],s=r[c],v=h+2*c;f[v]=.5*(l+s),f[v+1]=.5*(l-s)}for(var y=new Float32Array(u),d=0;d<i;d++){for(var m=2*d,w=0,g=0,k=0;k<24;k++){var S=m+2*k;w+=f[S]*b[k],g+=f[S+1]*p[k]}y[2*d]=g,y[2*d+1]=w}return{output:y,newDelay:f.slice(-46)}}function Y(e){return Y="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},Y(e)}function Z(e,r){for(var t=0;t<r.length;t++){var n=r[t];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,ee(n.key),n)}}function ee(e){var r=function(e,r){if("object"!=Y(e)||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var n=t.call(e,r||"default");if("object"!=Y(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===r?String:Number)(e)}(e,"string");return"symbol"==Y(r)?r:r+""}var re=function(){return e=function e(){!function(e,r){if(!(e instanceof r))throw new TypeError("Cannot call a class as a function")}(this,e)},t=[{key:"fft",value:function(e,r){var t=e.length;if(1!==t){for(var n=Math.log2(t),o=0;o<t;o++){for(var a=0,i=o,u=0;u<n;u++)a=a<<1|1&i,i>>=1;if(a>o){var f=[e[a],e[o]];e[o]=f[0],e[a]=f[1];var c=[r[a],r[o]];r[o]=c[0],r[a]=c[1]}}for(var l=2;l<=t;l<<=1)for(var s=l>>1,v=-2*Math.PI/l,h=Math.cos(v),y=Math.sin(v),d=0;d<t;d+=l)for(var b=1,p=0,m=0;m<s;m++){var w=d+m,g=w+s,k=e[w],S=r[w],A=e[g],M=r[g],O=A*b-M*p,j=A*p+M*b;e[w]=k+O,r[w]=S+j,e[g]=k-O,r[g]=S-j;var B=b*h-p*y;p=b*y+p*h,b=B}}}}],(r=null)&&Z(e.prototype,r),t&&Z(e,t),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,r,t}();function te(e){return te="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},te(e)}function ne(e,r,t){return r=ae(r),function(e,r){if(r&&("object"==te(r)||"function"==typeof r))return r;if(void 0!==r)throw new TypeError("Derived constructors may only return object or undefined");return function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e)}(e,oe()?Reflect.construct(r,t||[],ae(e).constructor):r.apply(e,t))}function oe(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(oe=function(){return!!e})()}function ae(e){return ae=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},ae(e)}function ie(e,r){if("function"!=typeof r&&null!==r)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(r&&r.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),r&&ue(e,r)}function ue(e,r){return ue=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,r){return e.__proto__=r,e},ue(e,r)}function fe(e,r){for(var t=0;t<r.length;t++){var n=r[t];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,le(n.key),n)}}function ce(e,r,t){return r&&fe(e.prototype,r),t&&fe(e,t),Object.defineProperty(e,"prototype",{writable:!1}),e}function le(e){var r=function(e,r){if("object"!=te(e)||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var n=t.call(e,r||"default");if("object"!=te(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===r?String:Number)(e)}(e,"string");return"symbol"==te(r)?r:r+""}function se(e,r){if(!(e instanceof r))throw new TypeError("Cannot call a class as a function")}var ve=ce(function e(r,t){se(this,e),this.size=r,this.halfSize=r>>1,this.quarterSize=r>>2,this.fftSize=this.halfSize>>1;var n=2*Math.PI/(8*r),o=2*Math.PI/r,a=Math.sqrt(t/r);this.sinCosTable=new Float64Array(this.halfSize);for(var i=0;i<this.quarterSize;i++){var u=o*i+n;this.sinCosTable[2*i]=a*Math.cos(u),this.sinCosTable[2*i+1]=a*Math.sin(u)}}),he=function(){function e(r,t){return se(this,e),ne(this,e,[r,t])}return ie(e,ve),ce(e,[{key:"transform",value:function(e){var r,t,n,o=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null,a=null!==(r=null==o?void 0:o[this.fftSize])&&void 0!==r?r:$("MDCT.transform: mdctBuffers[".concat(this.fftSize,"] is required")),i=null!==(t=null==a?void 0:a.real)&&void 0!==t?t:$("MDCT.transform: mdctBuffers[".concat(this.fftSize,"].real is required")),u=null!==(n=null==a?void 0:a.imag)&&void 0!==n?n:$("MDCT.transform: mdctBuffers[".concat(this.fftSize,"].imag is required")),f=this.quarterSize,c=3*f;i.fill(0),u.fill(0);for(var l=0;l<f;l+=2){var s=c+l,v=f+l,h=f-1-l,y=e[c-1-l]+e[s],d=e[v]-e[h],b=this.sinCosTable[l],p=this.sinCosTable[l+1];i[l>>1]=y*b+d*p,u[l>>1]=d*b-y*p}for(var m=f;m<this.halfSize;m+=2){var w=m>>1,g=m-f,k=f+m,S=5*f-1-m,A=e[c-1-m]-e[g],M=e[k]+e[S],O=this.sinCosTable[m],j=this.sinCosTable[m+1];i[w]=A*O+M*j,u[w]=M*O-A*j}re.fft(i,u);for(var B=new Float32Array(this.halfSize),F=0;F<this.fftSize;F++){var P=this.sinCosTable[2*F],T=this.sinCosTable[2*F+1],I=i[F],C=u[F];B[2*F]=-I*P-C*T,B[this.halfSize-1-2*F]=-I*T+C*P}return B}}])}(),ye=function(){function e(r){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;return se(this,e),ne(this,e,[r,t||r])}return ie(e,ve),ce(e,[{key:"transform",value:function(e){var r,t,n,o=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null,a=null!==(r=null==o?void 0:o[this.fftSize])&&void 0!==r?r:$("IMDCT.transform: mdctBuffers[".concat(this.fftSize,"] is required")),i=null!==(t=null==a?void 0:a.real)&&void 0!==t?t:$("IMDCT.transform: mdctBuffers[".concat(this.fftSize,"].real is required")),u=null!==(n=null==a?void 0:a.imag)&&void 0!==n?n:$("IMDCT.transform: mdctBuffers[".concat(this.fftSize,"].imag is required")),f=this.quarterSize,c=3*f;i.fill(0),u.fill(0);for(var l=0;l<this.fftSize;l++){var s=2*l,v=-e[s],h=-e[this.halfSize-1-s],y=this.sinCosTable[s],d=this.sinCosTable[s+1];i[l]=h*d+v*y,u[l]=h*y-v*d}re.fft(i,u);for(var b=new Float32Array(this.size),p=0;p<this.fftSize/2;p++){var m=2*p,w=this.sinCosTable[m],g=this.sinCosTable[m+1],k=i[p],S=u[p],A=k*w+S*g,M=k*g-S*w;b[c-1-m]=A,b[c+m]=A,b[f+m]=M,b[f-1-m]=-M}for(var O=this.fftSize/2;O<this.fftSize;O++){var j=2*(O-this.fftSize/2)+f,B=2*O,F=this.sinCosTable[B],P=this.sinCosTable[B+1],T=i[O],I=u[O],C=T*F+I*P,x=T*P-I*F;b[c-1-j]=C,b[j-f]=-C,b[f+j]=x,b[5*f-1-j]=x}return b}}])}(),de=new he(64,.5),be=new he(l,.5),pe=new he(s,1),me=new ye(64,512),we=new ye(l,2048),ge=new ye(s,2048);function ke(e,r,t){for(var n=e.length,o=new Float32Array(2*n),a=0;a<n;a++){var i=t[a],u=t[2*n-1-a],f=e[a],c=r[n-1-a];o[a]=f*u-c*i,o[2*n-1-a]=f*i+c*u}return o}function Se(e,r,t){var n=e.length,o=new Int32Array(n);if(0===t||0===r)return o.fill(0,0,n),o;for(var a=(1<<t-1)-1,i=a/O[r],u=a,f=-a,c=0;c<n;c++){var l=e[c]*i,s=l+(l>=0?.5:-.5)|0;o[c]=s>u?u:s<f?f:s}return o}function Ae(e,r,t){if(0===t||0===r)return new Float32Array(e.length);for(var n=O[r],o=(1<<t-1)-1,a=new Float32Array(e.length),i=0;i<e.length;i++)a[i]=e[i]*n/o;return a}function Me(e,r){var t="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!t){if(Array.isArray(e)||(t=function(e,r){if(e){if("string"==typeof e)return Oe(e,r);var t={}.toString.call(e).slice(8,-1);return"Object"===t&&e.constructor&&(t=e.constructor.name),"Map"===t||"Set"===t?Array.from(e):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?Oe(e,r):void 0}}(e))||r&&e&&"number"==typeof e.length){t&&(e=t);var n=0,o=function(){};return{s:o,n:function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}},e:function(e){throw e},f:o}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var a,i=!0,u=!1;return{s:function(){t=t.call(e)},n:function(){var e=t.next();return i=e.done,e},e:function(e){u=!0,a=e},f:function(){try{i||null==t.return||t.return()}finally{if(u)throw a}}}}function Oe(e,r){(null==r||r>e.length)&&(r=e.length);for(var t=0,n=Array(r);t<r;t++)n[t]=e[t];return n}function je(e,r,t,n,o,a,i){for(var u=0,f=0;f<e;f++){var c=0|n[f],l=0|M[c];if(0!==l){var s=o[f];if(0!==s){var v=O[s];u+=Math.pow(v,a)*j[l]*t[f]}}else u+=i[f]}for(var h=e;h<r;h++)u+=i[h];return u}function Be(e,r,t,n,o){for(var a=o,i=new Int32Array(e),u=[],f=[],c=function(e,r,t){var o=a[e],i=O[o];if(0===i)return 0;var u=Math.pow(i,n),f=0|M[r],c=0|M[t];return u*((0===f?2:j[f])-j[c])},l=0;l<e;l++){if(0!==(0|r[l]))if(0!==a[l]){var s=M[1]-M[0]|0;if(!(s<=0)){var v=c(l,0,1);u.push(l),f.push(v/s)}}}for(var h=(u.length>>1)-1;h>=0;h--)Te(u,f,h);for(;t>0&&u.length>0;){var y=u[0],d=0|i[y],b=d+1,p=0|r[y],m=(M[b]-M[d]|0)*p;if(m>t||m<=0)Pe(u,f);else if(t-=m,i[y]=b,b<15){var w=b+1,g=M[w]-M[b]|0;g>0?(f[0]=c(y,b,w)/g,Te(u,f,0)):Pe(u,f)}else Pe(u,f)}return{wordLengths:i,scaleFactorIndices:a}}function Fe(e){for(var r=0,t=0;t<e.length;t++){var n=Math.abs(e[t]);n>r&&(r=n)}if(0===r)return 0;var o=Math.ceil(3*(Math.log2(r)+21));return Math.max(0,Math.min(63,o))}function Pe(e,r){var t=e.length-1;e[0]=e[t],r[0]=r[t],e.pop(),r.pop(),e.length&&Te(e,r,0)}function Te(e,r,t){for(var n=e.length,o=t,a=e[o],i=r[o];;){var u=1+(o<<1),f=u+1,c=o,l=i;if(u<n&&r[u]>l&&(c=u,l=r[u]),f<n&&r[f]>l&&(c=f),c===o)break;e[o]=e[c],r[o]=r[c],o=c}e[o]=a,r[o]=i}function Ie(e){return Ie="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},Ie(e)}function Ce(e,r){for(var t=0;t<r.length;t++){var n=r[t];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,ze(n.key),n)}}function xe(e,r,t){return r&&Ce(e.prototype,r),t&&Ce(e,t),Object.defineProperty(e,"prototype",{writable:!1}),e}function ze(e){var r=function(e,r){if("object"!=Ie(e)||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var n=t.call(e,r||"default");if("object"!=Ie(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===r?String:Number)(e)}(e,"string");return"symbol"==Ie(r)?r:r+""}var qe=xe(function e(){!function(e,r){if(!(e instanceof r))throw new TypeError("Cannot call a class as a function")}(this,e),this.transformBuffers={64:new Float32Array(64),128:new Float32Array(128),256:new Float32Array(256),512:new Float32Array(512)},this.qmfWorkBuffers={delay:{128:new Float32Array(174),256:new Float32Array(302),512:new Float32Array(558)},highBandDelay:{128:new Float32Array(167),256:new Float32Array(295)}},this.qmfDelays={lowBand:new Float32Array(h),midBand:new Float32Array(h),highBand:new Float32Array(39)},this.transientDetection=[new Float32Array(64),new Float32Array(64),new Float32Array(128)],this.mdctBuffers={16:{real:new Float32Array(16),imag:new Float32Array(16)},64:{real:new Float32Array(64),imag:new Float32Array(64)},128:{real:new Float32Array(128),imag:new Float32Array(128)}},this.mdctOverlap=[new Float32Array(32),new Float32Array(32),new Float32Array(32)],this.imdctOverlap=[new Float32Array(256),new Float32Array(256),new Float32Array(512)],this.reversalBuffers={32:new Float32Array(32),128:new Float32Array(128),256:new Float32Array(256)}});function Ee(e,r,t){if(!r)return!1;var n=function(e,r){var t=function(e,r){for(var t=0,n=0,o=0;o<e.length;o++){var a=Math.abs(e[o]),i=a-Math.abs(r[o]);i>0&&(t+=i),n+=a*a}var u=Math.sqrt(n)||1e-6;return t/u}(e,r),n=_e(e),o=_e(r),a=Math.abs(n-o),i=De(e),u=De(r),f=Math.abs(i-u),c=function(e,r){for(var t=0,n=0,o=0;o<e.length;o++)t+=e[o]*e[o],n+=r[o]*r[o];t=Math.max(t,1e-10),n=Math.max(n,1e-10);var a=10*Math.log10(t/n);return Math.max(0,a)}(e,r);return{spectralFlux:t,flatnessChange:a,hfChange:f,energyChange:c}}(e,r),o=function(e){var r=e.spectralFlux,t=e.flatnessChange,n=e.hfChange,o=e.energyChange,a=r,i=Math.sqrt(t),u=Math.log1p(10*n)/Math.log1p(10),f=Math.min(o/30,1);return(a+i+u+f)/4}(n);return o>t}function _e(e){for(var r=0,t=0,n=0,o=0;o<e.length;o++){var a=Math.abs(e[o]);a>1e-10&&(r+=Math.log(a),t+=a,n++)}if(0===n)return 0;var i=Math.exp(r/n),u=t/n;return u>1e-10?i/u:0}function De(e){for(var r=Math.floor(e.length/2),t=0,n=0,o=0;o<r;o++)t+=e[o]*e[o];for(var a=r;a<e.length;a++)n+=e[a]*e[a];var i=t+n;return i>0?n/i:0}function Ue(e){var r,t=null!==(r=null==e?void 0:e.bufferPool)&&void 0!==r?r:$("qmfAnalysisStage: bufferPool is required"),n=t.qmfDelays;return function(e){var r=Q(e,n.lowBand,t.qmfWorkBuffers);n.lowBand=r.newDelay;var o=Q(r.lowBand,n.midBand,t.qmfWorkBuffers);n.midBand=o.newDelay;var a=t.qmfWorkBuffers.highBandDelay[r.highBand.length];a.set(n.highBand),a.set(r.highBand,n.highBand.length);var i=a.slice(0,r.highBand.length);return n.highBand=a.slice(r.highBand.length),{bands:[o.lowBand,o.highBand,i]}}}function He(e){var r,t,n=null!==(r=null==e?void 0:e.bufferPool)&&void 0!==r?r:$("blockSelectorStage: bufferPool is required"),o=null!==(t=null==e?void 0:e.options)&&void 0!==t?t:$("blockSelectorStage: options is required");return function(e){var r,t=e.bands;if(o.fixedBlockModes)r=o.fixedBlockModes;else{var a=[128,128,256];r=t.map(function(e,r){var t=function(e,r){var t=new Float32Array(r),n=new Float32Array(r),o=Math.min(e.length,r);t.set(e.subarray(0,o)),re.fft(t,n);for(var a=new Float32Array(r/2),i=0;i<r/2;i++)a[i]=Math.sqrt(t[i]*t[i]+n[i]*n[i]);return a}(e,a[r]),i=Ee(t,n.transientDetection[r],o.transientThresholdLow);return n.transientDetection[r]=t,i*Math.max(r+1,2)})}return{bands:t,blockModes:r}}}function Le(e){var r,t=null!==(r=null==e?void 0:e.bufferPool)&&void 0!==r?r:$("mdctStage: bufferPool is required"),n=t.mdctOverlap,o=[be,be,pe];function a(e,r,t,n,a){var u=m[r];return 0===t?function(e,r,t,n,o,a){var u=2===r?s:l,f=a.transformBuffers[u];f.fill(0),f.set(o,t.windowStart),i(e,o,t.size),f.set(e,t.windowStart+32);var c=n.transform(f,a.mdctBuffers);r>0&&(c=K(c,a.reversalBuffers));return c}(e,r,u,o[r],n,a):function(e,r,t,n,o){for(var a=1<<(256===t.size?3:2),u=new Float32Array(t.size),f=0;f<a;f++){var c=f*w,l=e.subarray(c,c+w),s=o.transformBuffers[64];s.fill(0),s.set(n,0),i(l,n,w),s.set(l,g);var v=de.transform(s,o.mdctBuffers);r>0&&(v=K(v,o.reversalBuffers)),u.set(v,c)}return u}(e,r,u,n,a)}function i(e,r,t){for(var n=t-g,o=0;o<g;o++){var a=e[n+o];r[o]=v[o]*a,e[n+o]=a*v[31-o]}}return function(e){var r=e.bands,o=e.blockModes,i=e.originalFrame,u=new Float32Array(512);return r.forEach(function(e,r){var i=a(e,r,o[r],n[r],t),f=function(e){return 0===e?0:1===e?128:256}(r);u.set(i,f)}),{bands:r,coefficients:u,blockModes:o,originalFrame:i}}}function We(e){var r,t=null!==(r=null==e?void 0:e.options)&&void 0!==r?r:$("quantizationStage: options is required");return function(e){for(var r=e.coefficients,n=e.blockModes,o=function(e,r){for(var t=[],n=[],o=0,i=0,l=0;l<3;l++){for(var s=o,v=2===l?256:128,h=l<2?u[l]:a.length,y=0===r[l]?f:c;i<h;){var d=a[i],b=y[i]-s,p=b+d,m=new Float32Array(d);if(b>=0&&p<=v)m.set(e.subarray(s+b,s+p));else if(m.fill(0),b<v&&p>0){var w=Math.max(0,b),g=Math.min(v,p);m.set(e.subarray(s+w,s+g),Math.max(0,-b))}t.push(m),n.push(d),i++}o+=v}return{bfuData:t,bfuSizes:n,bfuCount:i}}(r,n),l=o.bfuData,s=o.bfuSizes,v=function(e,r,t,n){for(var o=new Int32Array(t),a=new Float32Array(t),u=0;u<t;u++){var f=0|r[u];if(0!==f){var c=Fe(e[u].subarray(0,f));if(o[u]=c,c>0){var l=O[c],s=Math.pow(l,n);a[u]=2*s*f}}}var v,h=null,y=1/0,d=Me(i);try{for(d.s();!(v=d.n()).done;){var b=v.value;if(!(b>t)){var p=1656-10*b;if(!(p<0)){var m=Be(b,r,p,n,o),w=je(b,t,r,m.wordLengths,m.scaleFactorIndices,n,a);w<y&&(y=w,h={bfuCount:b,allocation:m.wordLengths,scaleFactorIndices:m.scaleFactorIndices})}}}}catch(e){d.e(e)}finally{d.f()}if(!h){var g=i[0];return{bfuCount:g,allocation:new Int32Array(g),scaleFactorIndices:new Int32Array(52)}}return h}(l,s,o.bfuCount,t.allocationBias),h=v.bfuCount,y=v.allocation,d=v.scaleFactorIndices,b=y.slice(0,h),p=d.slice(0,h),m=[],w=0;w<h;w++){var g=l[w].subarray(0,s[w]),k=b[w],S=M[k],A=Se(g,d[w],S);m.push(A)}return{nBfu:h,scaleFactorIndices:p,wordLengthIndices:b,quantizedCoefficients:m,blockModes:n}}}function Ge(){return J({options:arguments.length>0&&void 0!==arguments[0]?arguments[0]:new R,bufferPool:arguments.length>1&&void 0!==arguments[1]?arguments[1]:new qe},Ue,He,Le,We)}function Ne(){return function(e){for(var r=new Float32Array(512),t=e.nBfu,n=e.scaleFactorIndices,o=e.wordLengthIndices,a=e.quantizedCoefficients,i=e.blockModes,l=0;l<t;l++){var s=M[o[l]],v=0;l>=u[0]&&(v=1),l>=u[1]&&(v=2);var h=0===i[v]?f[l]:c[l];if(s>0){var y=Ae(a[l],n[l],s);r.set(y,h)}}return{coefficients:r,blockModes:i}}}function Ve(e){var r,t=null!==(r=null==e?void 0:e.bufferPool)&&void 0!==r?r:$("imdctStage: bufferPool is required"),n=t.imdctOverlap,o=[we,we,ge];function a(e,r,t,n,a,i){return 0===t?function(e,r,t,n,o,a){var i=e;r>0&&(i=K(e,n.reversalBuffers));var u=a.transform(i,n.mdctBuffers),f=u.length/4,c=n.transformBuffers[512];c.fill(0);for(var l=0;l<o.size;l++)c[l]=u[f+l];var s=t.slice(2*o.size-k,2*o.size),h=ke(s.slice(0,k),c.slice(0,k),v);t.set(h,0);for(var y=0;y<k;y++)s[y]=c[k+y];for(var d=2===r?240:112,b=0;b<d;b++)t[32+b]=c[k+b];for(var p=0;p<k;p++)t[2*o.size-k+p]=c[o.size-k+p];return t.slice(0,o.size)}(e,r,n,a,i,o[r]):function(e,r,t,n,o){var a=1<<(256===o.size?3:2),i=n.transformBuffers[512];i.fill(0);for(var u=t.slice(2*o.size-k,2*o.size),f=0,c=0,l=0;l<a;l++){var s=e.slice(c,c+w);r>0&&(s=K(s,n.reversalBuffers));for(var h=me.transform(s,n.mdctBuffers),y=h.length/4,d=0;d<w;d++)i[f+d]=h[y+d];var b=ke(u.slice(0,k),i.slice(f,f+k),v);t.set(b,f);for(var p=0;p<k;p++)u[p]=i[f+k+p];f+=w,c+=w}for(var m=0;m<k;m++)t[2*o.size-k+m]=i[o.size-k+m];return t.slice(0,o.size)}(e,r,n,a,i)}return function(e){var r=e.coefficients,o=e.blockModes;return m.map(function(e,i){var u=function(e,r){var t=[0,128,256,512];return e.subarray(t[r],t[r+1])}(r,i);return a(u,i,o[i],n[i],t,e)})}}function Re(e){var r,t=null!==(r=null==e?void 0:e.bufferPool)&&void 0!==r?r:$("qmfSynthesisStage: bufferPool is required"),n=t.qmfDelays;return function(e){var r=t.qmfWorkBuffers.highBandDelay[e[2].length];r.set(n.highBand),r.set(e[2],n.highBand.length);var o=r.slice(0,2*e[0].length);n.highBand=r.slice(2*e[0].length);var a=X(e[0],e[1],n.midBand,t.qmfWorkBuffers);n.midBand=a.newDelay;var i=X(a.output,o,n.lowBand,t.qmfWorkBuffers);return n.lowBand=i.newDelay,i.output}}function $e(){return J({bufferPool:arguments.length>0&&void 0!==arguments[0]?arguments[0]:new qe},Ne,Ve,Re)}function Je(e){return Je="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},Je(e)}function Ke(e,r){var t="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!t){if(Array.isArray(e)||(t=Ze(e))||r&&e&&"number"==typeof e.length){t&&(e=t);var n=0,o=function(){};return{s:o,n:function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}},e:function(e){throw e},f:o}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var a,i=!0,u=!1;return{s:function(){t=t.call(e)},n:function(){var e=t.next();return i=e.done,e},e:function(e){u=!0,a=e},f:function(){try{i||null==t.return||t.return()}finally{if(u)throw a}}}}function Qe(e,r,t,n,o,a,i){try{var u=e[a](i),f=u.value}catch(e){return void t(e)}u.done?r(f):Promise.resolve(f).then(n,o)}function Xe(e){return function(){var r=this,t=arguments;return new Promise(function(n,o){var a=e.apply(r,t);function i(e){Qe(a,n,o,i,u,"next",e)}function u(e){Qe(a,n,o,i,u,"throw",e)}i(void 0)})}}function Ye(e,r){return function(e){if(Array.isArray(e))return e}(e)||function(e,r){var t=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=t){var n,o,a,i,u=[],f=!0,c=!1;try{if(a=(t=t.call(e)).next,0===r){if(Object(t)!==t)return;f=!1}else for(;!(f=(n=a.call(t)).done)&&(u.push(n.value),u.length!==r);f=!0);}catch(e){c=!0,o=e}finally{try{if(!f&&null!=t.return&&(i=t.return(),Object(i)!==i))return}finally{if(c)throw o}}return u}}(e,r)||Ze(e,r)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function Ze(e,r){if(e){if("string"==typeof e)return er(e,r);var t={}.toString.call(e).slice(8,-1);return"Object"===t&&e.constructor&&(t=e.constructor.name),"Map"===t||"Set"===t?Array.from(e):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?er(e,r):void 0}}function er(e,r){(null==r||r>e.length)&&(r=e.length);for(var t=0,n=Array(r);t<r;t++)n[t]=e[t];return n}function rr(e){if(null!=e){var r=e["function"==typeof Symbol&&Symbol.iterator||"@@iterator"],t=0;if(r)return r.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length))return{next:function(){return e&&t>=e.length&&(e=void 0),{value:e&&e[t++],done:!e}}}}throw new TypeError(Je(e)+" is not iterable")}function tr(){/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */var e,r,t="function"==typeof Symbol?Symbol:{},n=t.iterator||"@@iterator",o=t.toStringTag||"@@toStringTag";function a(t,n,o,a){var f=n&&n.prototype instanceof u?n:u,c=Object.create(f.prototype);return nr(c,"_invoke",function(t,n,o){var a,u,f,c=0,l=o||[],s=!1,v={p:0,n:0,v:e,a:h,f:h.bind(e,4),d:function(r,t){return a=r,u=0,f=e,v.n=t,i}};function h(t,n){for(u=t,f=n,r=0;!s&&c&&!o&&r<l.length;r++){var o,a=l[r],h=v.p,y=a[2];t>3?(o=y===n)&&(f=a[(u=a[4])?5:(u=3,3)],a[4]=a[5]=e):a[0]<=h&&((o=t<2&&h<a[1])?(u=0,v.v=n,v.n=a[1]):h<y&&(o=t<3||a[0]>n||n>y)&&(a[4]=t,a[5]=n,v.n=y,u=0))}if(o||t>1)return i;throw s=!0,n}return function(o,l,y){if(c>1)throw TypeError("Generator is already running");for(s&&1===l&&h(l,y),u=l,f=y;(r=u<2?e:f)||!s;){a||(u?u<3?(u>1&&(v.n=-1),h(u,f)):v.n=f:v.v=f);try{if(c=2,a){if(u||(o="next"),r=a[o]){if(!(r=r.call(a,f)))throw TypeError("iterator result is not an object");if(!r.done)return r;f=r.value,u<2&&(u=0)}else 1===u&&(r=a.return)&&r.call(a),u<2&&(f=TypeError("The iterator does not provide a '"+o+"' method"),u=1);a=e}else if((r=(s=v.n<0)?f:t.call(n,v))!==i)break}catch(r){a=e,u=1,f=r}finally{c=1}}return{value:r,done:s}}}(t,o,a),!0),c}var i={};function u(){}function f(){}function c(){}r=Object.getPrototypeOf;var l=[][n]?r(r([][n]())):(nr(r={},n,function(){return this}),r),s=c.prototype=u.prototype=Object.create(l);function v(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,c):(e.__proto__=c,nr(e,o,"GeneratorFunction")),e.prototype=Object.create(s),e}return f.prototype=c,nr(s,"constructor",c),nr(c,"constructor",f),f.displayName="GeneratorFunction",nr(c,o,"GeneratorFunction"),nr(s),nr(s,o,"Generator"),nr(s,n,function(){return this}),nr(s,"toString",function(){return"[object Generator]"}),(tr=function(){return{w:a,m:v}})()}function nr(e,r,t,n){var o=Object.defineProperty;try{o({},"",{})}catch(e){o=0}nr=function(e,r,t,n){if(r)o?o(e,r,{value:t,enumerable:!n,configurable:!n,writable:!n}):e[r]=t;else{var a=function(r,t){nr(e,r,function(e){return this._invoke(r,t,e)})};a("next",0),a("throw",1),a("return",2)}},nr(e,r,t,n)}function or(e,r){for(var t=0;t<r.length;t++){var n=r[t];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,ar(n.key),n)}}function ar(e){var r=function(e,r){if("object"!=Je(e)||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var n=t.call(e,r||"default");if("object"!=Je(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===r?String:Number)(e)}(e,"string");return"symbol"==Je(r)?r:r+""}function ir(e){return function(){return new ur(e.apply(this,arguments))}}function ur(e){var r,t;function n(r,t){try{var a=e[r](t),i=a.value,u=i instanceof lr;Promise.resolve(u?i.v:i).then(function(t){if(u){var f="return"===r?"return":"next";if(!i.k||t.done)return n(f,t);t=e[f](t).value}o(a.done?"return":"normal",t)},function(e){n("throw",e)})}catch(e){o("throw",e)}}function o(e,o){switch(e){case"return":r.resolve({value:o,done:!0});break;case"throw":r.reject(o);break;default:r.resolve({value:o,done:!1})}(r=r.next)?n(r.key,r.arg):t=null}this._invoke=function(e,o){return new Promise(function(a,i){var u={key:e,arg:o,resolve:a,reject:i,next:null};t?t=t.next=u:(r=t=u,n(e,o))})},"function"!=typeof e.return&&(this.return=void 0)}function fr(e){return new lr(e,0)}function cr(e){var r={},t=!1;function n(r,n){return t=!0,n=new Promise(function(t){t(e[r](n))}),{done:!1,value:new lr(n,1)}}return r["undefined"!=typeof Symbol&&Symbol.iterator||"@@iterator"]=function(){return this},r.next=function(e){return t?(t=!1,e):n("next",e)},"function"==typeof e.throw&&(r.throw=function(e){if(t)throw t=!1,e;return n("throw",e)}),"function"==typeof e.return&&(r.return=function(e){return t?(t=!1,e):n("return",e)}),r}function lr(e,r){this.v=e,this.k=r}function sr(e){var r,t,n,o=2;for("undefined"!=typeof Symbol&&(t=Symbol.asyncIterator,n=Symbol.iterator);o--;){if(t&&null!=(r=e[t]))return r.call(e);if(n&&null!=(r=e[n]))return new vr(r.call(e));t="@@asyncIterator",n="@@iterator"}throw new TypeError("Object is not async iterable")}function vr(e){function r(e){if(Object(e)!==e)return Promise.reject(new TypeError(e+" is not an object."));var r=e.done;return Promise.resolve(e.value).then(function(e){return{value:e,done:r}})}return vr=function(e){this.s=e,this.n=e.next},vr.prototype={s:null,n:null,next:function(){return r(this.n.apply(this.s,arguments))},return:function(e){var t=this.s.return;return void 0===t?Promise.resolve({value:e,done:!0}):r(t.apply(this.s,arguments))},throw:function(e){var t=this.s.return;return void 0===t?Promise.reject(e):r(t.apply(this.s,arguments))}},new vr(e)}ur.prototype["function"==typeof Symbol&&Symbol.asyncIterator||"@@asyncIterator"]=function(){return this},ur.prototype.next=function(e){return this._invoke("next",e)},ur.prototype.throw=function(e){return this._invoke("throw",e)},ur.prototype.return=function(e){return this._invoke("return",e)};var hr=function(){function e(){!function(e,r){if(!(e instanceof r))throw new TypeError("Cannot call a class as a function")}(this,e)}return t=e,a=null,i=[{key:"encodeStream",value:function(r){return ir(function(r){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return tr().m(function n(){var o,a,i,u;return tr().w(function(n){for(;;)switch(n.n){case 0:if(o=t.channelCount,a=void 0===o?1:o,i=t.onProgress,u=t.encoderOptions,1!==a){n.n=2;break}return n.d(rr(cr(sr(e._encodeMonoStream(r,i,u)))),1);case 1:case 3:n.n=5;break;case 2:if(2!==a){n.n=4;break}return n.d(rr(cr(sr(e._encodeStereoStream(r,i,u)))),3);case 4:throw new Error("Unsupported channel count: ".concat(a));case 5:return n.a(2)}},n)})()}).apply(this,arguments)}},{key:"_encodeMonoStream",value:function(e,r,t){return ir(tr().m(function n(){var o,a,i,u,f,c,l,s,v,h,y;return tr().w(function(n){for(;;)switch(n.n){case 0:o=t||new R,a=Ge(o),i=0,u=!1,f=!1,n.p=1,l=sr(e);case 2:return n.n=3,fr(l.next());case 3:if(!(u=!(s=n.v).done)){n.n=6;break}return v=s.value,h=a(v),n.n=4,h;case 4:r&&r(i++);case 5:u=!1,n.n=2;break;case 6:n.n=8;break;case 7:n.p=7,y=n.v,f=!0,c=y;case 8:if(n.p=8,n.p=9,!u||null==l.return){n.n=10;break}return n.n=10,fr(l.return());case 10:if(n.p=10,!f){n.n=11;break}throw c;case 11:return n.f(10);case 12:return n.f(8);case 13:return n.a(2)}},n,null,[[9,,10,12],[1,7,8,13]])}))()}},{key:"_encodeStereoStream",value:function(e,r,t){return ir(tr().m(function n(){var o,a,i,u,f,c,l,s,v,h,y,d,b,p,m;return tr().w(function(n){for(;;)switch(n.n){case 0:o=t||new R,a=Ge(o),i=Ge(o),u=0,f=!1,c=!1,n.p=1,s=sr(e);case 2:return n.n=3,fr(s.next());case 3:if(!(f=!(v=n.v).done)){n.n=7;break}return h=Ye(v.value,2),y=h[0],d=h[1],b=a(y),p=i(d),n.n=4,b;case 4:return n.n=5,p;case 5:r&&r(u++);case 6:f=!1,n.n=2;break;case 7:n.n=9;break;case 8:n.p=8,m=n.v,c=!0,l=m;case 9:if(n.p=9,n.p=10,!f||null==s.return){n.n=11;break}return n.n=11,fr(s.return());case 11:if(n.p=11,!c){n.n=12;break}throw l;case 12:return n.f(11);case 13:return n.f(9);case 14:return n.a(2)}},n,null,[[10,,11,13],[1,8,9,14]])}))()}},{key:"decodeStream",value:function(r){return ir(function(r){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return tr().m(function n(){var o,a,i;return tr().w(function(n){for(;;)switch(n.n){case 0:if(o=t.channelCount,a=void 0===o?1:o,i=t.onProgress,1!==a){n.n=2;break}return n.d(rr(cr(sr(e._decodeMonoStream(r,i)))),1);case 1:case 3:n.n=5;break;case 2:if(2!==a){n.n=4;break}return n.d(rr(cr(sr(e._decodeStereoStream(r,i)))),3);case 4:throw new Error("Unsupported channel count: ".concat(a));case 5:return n.a(2)}},n)})()}).apply(this,arguments)}},{key:"_decodeMonoStream",value:function(e,r){return ir(tr().m(function t(){var n,o,a;return tr().w(function(t){for(;;)switch(t.n){case 0:return n=$e(),o=0,a=function(){var t=ir(tr().m(function t(){var a,i,u,f,c,l,s,v;return tr().w(function(t){for(;;)switch(t.n){case 0:a=!1,i=!1,t.p=1,f=sr(e);case 2:return t.n=3,fr(f.next());case 3:if(!(a=!(c=t.v).done)){t.n=6;break}return l=c.value,s=n(l),t.n=4,s;case 4:r&&r(o++);case 5:a=!1,t.n=2;break;case 6:t.n=8;break;case 7:t.p=7,v=t.v,i=!0,u=v;case 8:if(t.p=8,t.p=9,!a||null==f.return){t.n=10;break}return t.n=10,fr(f.return());case 10:if(t.p=10,!i){t.n=11;break}throw u;case 11:return t.f(10);case 12:return t.f(8);case 13:return t.a(2)}},t,null,[[9,,10,12],[1,7,8,13]])}));return function(){return t.apply(this,arguments)}}(),t.d(rr(cr(sr(a()))),1);case 1:return t.a(2)}},t)}))()}},{key:"_decodeStereoStream",value:function(r,t){return ir(tr().m(function n(){var o,a,i,u;return tr().w(function(n){for(;;)switch(n.n){case 0:return o=$e(),a=$e(),i=0,u=function(){var n=ir(tr().m(function n(){var u,f,c,l,s,v,h,y,d,b,p,m,w,g,k;return tr().w(function(n){for(;;)switch(n.n){case 0:u=null,f=!0,c=!1,l=!1,n.p=1,v=sr(r);case 2:return n.n=3,fr(v.next());case 3:if(!(c=!(h=n.v).done)){n.n=8;break}if(y=h.value,!f){n.n=4;break}u=y,n.n=6;break;case 4:return d=y,b=o(u),p=a(d),n.n=5,[b,p];case 5:t&&t(i++);case 6:f=!f;case 7:c=!1,n.n=2;break;case 8:n.n=10;break;case 9:n.p=9,k=n.v,l=!0,s=k;case 10:if(n.p=10,n.p=11,!c||null==v.return){n.n=12;break}return n.n=12,fr(v.return());case 12:if(n.p=12,!l){n.n=13;break}throw s;case 13:return n.f(12);case 14:return n.f(10);case 15:if(f||!u){n.n=17;break}return m=e._createDummyFrame(),w=o(u),g=a(m),n.n=16,[w,g];case 16:t&&t(i++);case 17:return n.a(2)}},n,null,[[11,,12,14],[1,9,10,15]])}));return function(){return n.apply(this,arguments)}}(),n.d(rr(cr(sr(u()))),1);case 1:return n.a(2)}},n)}))()}},{key:"frameBufferToFrames",value:function(e){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:512;return tr().m(function t(){var n,o,a,i,u,f,c,l,s,v,h,y,d,b,p,m;return tr().w(function(t){for(;;)switch(t.n){case 0:if(1!==(n=e.length)){t.n=4;break}o=Ye(e,1),a=o[0],i=0;case 1:if(!(i<a.length)){t.n=3;break}for(u=new Float32Array(r),f=Math.min(i+r,a.length),c=0;c<f-i;c++)u[c]=a[i+c];return t.n=2,u;case 2:i+=r,t.n=1;break;case 3:t.n=9;break;case 4:if(2!==n){t.n=8;break}l=Ye(e,2),s=l[0],v=l[1],h=Math.max(s.length,v.length),y=0;case 5:if(!(y<h)){t.n=7;break}for(d=new Float32Array(r),b=new Float32Array(r),p=Math.min(y+r,h),m=0;m<p-y;m++)d[m]=y+m<s.length?s[y+m]:0,b[m]=y+m<v.length?v[y+m]:0;return t.n=6,[d,b];case 6:y+=r,t.n=5;break;case 7:t.n=9;break;case 8:throw new Error("Unsupported channel count: ".concat(n));case 9:return t.a(2)}},t)})()}},{key:"collectFrames",value:(c=Xe(tr().m(function e(r){var t,n,o,a,i,u,f,c;return tr().w(function(e){for(;;)switch(e.n){case 0:t=[],n=!1,o=!1,e.p=1,i=sr(r);case 2:return e.n=3,i.next();case 3:if(!(n=!(u=e.v).done)){e.n=5;break}f=u.value,t.push(f);case 4:n=!1,e.n=2;break;case 5:e.n=7;break;case 6:e.p=6,c=e.v,o=!0,a=c;case 7:if(e.p=7,e.p=8,!n||null==i.return){e.n=9;break}return e.n=9,i.return();case 9:if(e.p=9,!o){e.n=10;break}throw a;case 10:return e.f(9);case 11:return e.f(7);case 12:return e.a(2,t)}},e,null,[[8,,9,11],[1,6,7,12]])})),function(e){return c.apply(this,arguments)})},{key:"_createDummyFrame",value:function(){return{nBfu:0,blockModes:[0,0,0],scaleFactorIndices:new Int32Array(0),wordLengthIndices:new Int32Array(0),quantizedCoefficients:[]}}},{key:"createAeaBlob",value:(f=Xe(tr().m(function e(r){var t,n,o,a,i,u,f,c,l,s,v,h,y,d,b,p,m,w,g,k,S=arguments;return tr().w(function(e){for(;;)switch(e.n){case 0:n=(t=S.length>1&&void 0!==S[1]?S[1]:{}).title,o=void 0===n?"encoded by atrac1.js":n,a=t.channelCount,i=void 0===a?1:a,u=[],f=!1,c=!1,e.p=1,s=sr(r);case 2:return e.n=3,s.next();case 3:if(!(f=!(v=e.v).done)){e.n=5;break}h=v.value,u.push(q(h));case 4:f=!1,e.n=2;break;case 5:e.n=7;break;case 6:e.p=6,k=e.v,c=!0,l=k;case 7:if(e.p=7,e.p=8,!f||null==s.return){e.n=9;break}return e.n=9,s.return();case 9:if(e.p=9,!c){e.n=10;break}throw l;case 10:return e.f(9);case 11:return e.f(7);case 12:for(y=_.createHeader(o,u.length,i),d=y.length+u.reduce(function(e,r){return e+r.length},0),(b=new Uint8Array(d)).set(y,0),p=y.length,m=0,w=u;m<w.length;m++)g=w[m],b.set(g,p),p+=g.length;return e.a(2,new Blob([b],{type:"application/octet-stream"}))}},e,null,[[8,,9,11],[1,6,7,12]])})),function(e){return f.apply(this,arguments)})},{key:"createWavBlob",value:function(t){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1,o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:r,a=Array.isArray(t)?t:[t];if(1===n)return e._createMonoWavBlob(a,o);if(2===n)return e._createStereoWavBlob(a,o);throw new Error("Unsupported channel count: ".concat(n))}},{key:"_createMonoWavBlob",value:function(r,t){var n=r.reduce(function(e,r){return e+r.length},0),o=new ArrayBuffer(44+2*n),a=new DataView(o);e._writeWavHeader(a,n,1,t);var i,u=44,f=Ke(r);try{for(f.s();!(i=f.n()).done;)for(var c=i.value,l=0;l<c.length;l++){var s=Math.max(-1,Math.min(1,c[l]));a.setInt16(u,s<0?s*A:s*S,!0),u+=2}}catch(e){f.e(e)}finally{f.f()}return new Blob([o],{type:"audio/wav"})}},{key:"_createStereoWavBlob",value:function(r,t){var n=r.reduce(function(e,r){var t=Ye(r,2),n=t[0],o=t[1];return e+Math.max(n.length,o.length)},0),o=new ArrayBuffer(44+2*n*2),a=new DataView(o);e._writeWavHeader(a,n,2,t);var i,u=44,f=Ke(r);try{for(f.s();!(i=f.n()).done;)for(var c=Ye(i.value,2),l=c[0],s=c[1],v=Math.max(l.length,s.length),h=0;h<v;h++){var y=h<l.length?l[h]:0,d=h<s.length?s[h]:0,b=Math.max(-1,Math.min(1,y)),p=Math.max(-1,Math.min(1,d));a.setInt16(u,b<0?b*A:b*S,!0),u+=2,a.setInt16(u,p<0?p*A:p*S,!0),u+=2}}catch(e){f.e(e)}finally{f.f()}return new Blob([o],{type:"audio/wav"})}},{key:"_writeWavHeader",value:function(e,r,t,n){var o=n*t*2,a=2*t,i=r*a,u=36+i,f=0,c=function(r,t){for(var n=0;n<t.length;n++)e.setUint8(r+n,t.charCodeAt(n))};c(f,"RIFF"),f+=4,e.setUint32(f,u,!0),c(f+=4,"WAVE"),c(f+=4,"fmt "),f+=4,e.setUint32(f,16,!0),f+=4,e.setUint16(f,1,!0),f+=2,e.setUint16(f,t,!0),f+=2,e.setUint32(f,n,!0),f+=4,e.setUint32(f,o,!0),f+=4,e.setUint16(f,a,!0),f+=2,e.setUint16(f,16,!0),c(f+=2,"data"),f+=4,e.setUint32(f,i,!0)}},{key:"parseAeaBlob",value:(u=Xe(tr().m(function e(r){var t,a,i,u,f,c;return tr().w(function(e){for(;;)switch(e.n){case 0:return e.n=1,r.arrayBuffer();case 1:for(t=e.v,a=new Uint8Array(t.slice(0,n)),i=_.parseHeader(a),u=[],f=n;f<t.byteLength;f+=o)(c=new Uint8Array(t.slice(f,f+o))).length===o&&u.push(c);return e.a(2,{info:i,frameData:u})}},e)})),function(e){return u.apply(this,arguments)})},{key:"deserializedFrameStream",value:tr().m(function e(r){var t,n,o,a;return tr().w(function(e){for(;;)switch(e.n){case 0:t=Ke(r),e.p=1,t.s();case 2:if((n=t.n()).done){e.n=4;break}return o=n.value,e.n=3,E(o);case 3:e.n=2;break;case 4:e.n=6;break;case 5:e.p=5,a=e.v,t.e(a);case 6:return e.p=6,t.f(),e.f(6);case 7:return e.a(2)}},e,null,[[1,5,6,7]])})},{key:"assemblePcmFrames",value:function(e,r){if(1===r){var t,n=e.reduce(function(e,r){return e+r.length},0),o=new Float32Array(n),a=0,i=Ke(e);try{for(i.s();!(t=i.n()).done;){var u=t.value;o.set(u,a),a+=u.length}}catch(e){i.e(e)}finally{i.f()}return o}if(2===r){var f,c=e.reduce(function(e,r){var t=Ye(r,2),n=t[0],o=t[1];return e+Math.max(n.length,o.length)},0),l=new Float32Array(2*c),s=0,v=Ke(e);try{for(v.s();!(f=v.n()).done;)for(var h=Ye(f.value,2),y=h[0],d=h[1],b=Math.max(y.length,d.length),p=0;p<b;p++)l[2*s]=p<y.length?y[p]:0,l[2*s+1]=p<d.length?d[p]:0,s++}catch(e){v.e(e)}finally{v.f()}return l}throw new Error("Unsupported channel count: ".concat(r))}}],a&&or(t.prototype,a),i&&or(t,i),Object.defineProperty(t,"prototype",{writable:!1}),t;var t,a,i,u,f,c}();function yr(e){return yr="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},yr(e)}function dr(e,r){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);r&&(n=n.filter(function(r){return Object.getOwnPropertyDescriptor(e,r).enumerable})),t.push.apply(t,n)}return t}function br(e){for(var r=1;r<arguments.length;r++){var t=null!=arguments[r]?arguments[r]:{};r%2?dr(Object(t),!0).forEach(function(r){pr(e,r,t[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):dr(Object(t)).forEach(function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(t,r))})}return e}function pr(e,r,t){return(r=function(e){var r=function(e,r){if("object"!=yr(e)||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var n=t.call(e,r||"default");if("object"!=yr(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===r?String:Number)(e)}(e,"string");return"symbol"==yr(r)?r:r+""}(r))in e?Object.defineProperty(e,r,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[r]=t,e}function mr(){/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */var e,r,t="function"==typeof Symbol?Symbol:{},n=t.iterator||"@@iterator",o=t.toStringTag||"@@toStringTag";function a(t,n,o,a){var f=n&&n.prototype instanceof u?n:u,c=Object.create(f.prototype);return wr(c,"_invoke",function(t,n,o){var a,u,f,c=0,l=o||[],s=!1,v={p:0,n:0,v:e,a:h,f:h.bind(e,4),d:function(r,t){return a=r,u=0,f=e,v.n=t,i}};function h(t,n){for(u=t,f=n,r=0;!s&&c&&!o&&r<l.length;r++){var o,a=l[r],h=v.p,y=a[2];t>3?(o=y===n)&&(f=a[(u=a[4])?5:(u=3,3)],a[4]=a[5]=e):a[0]<=h&&((o=t<2&&h<a[1])?(u=0,v.v=n,v.n=a[1]):h<y&&(o=t<3||a[0]>n||n>y)&&(a[4]=t,a[5]=n,v.n=y,u=0))}if(o||t>1)return i;throw s=!0,n}return function(o,l,y){if(c>1)throw TypeError("Generator is already running");for(s&&1===l&&h(l,y),u=l,f=y;(r=u<2?e:f)||!s;){a||(u?u<3?(u>1&&(v.n=-1),h(u,f)):v.n=f:v.v=f);try{if(c=2,a){if(u||(o="next"),r=a[o]){if(!(r=r.call(a,f)))throw TypeError("iterator result is not an object");if(!r.done)return r;f=r.value,u<2&&(u=0)}else 1===u&&(r=a.return)&&r.call(a),u<2&&(f=TypeError("The iterator does not provide a '"+o+"' method"),u=1);a=e}else if((r=(s=v.n<0)?f:t.call(n,v))!==i)break}catch(r){a=e,u=1,f=r}finally{c=1}}return{value:r,done:s}}}(t,o,a),!0),c}var i={};function u(){}function f(){}function c(){}r=Object.getPrototypeOf;var l=[][n]?r(r([][n]())):(wr(r={},n,function(){return this}),r),s=c.prototype=u.prototype=Object.create(l);function v(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,c):(e.__proto__=c,wr(e,o,"GeneratorFunction")),e.prototype=Object.create(s),e}return f.prototype=c,wr(s,"constructor",c),wr(c,"constructor",f),f.displayName="GeneratorFunction",wr(c,o,"GeneratorFunction"),wr(s),wr(s,o,"Generator"),wr(s,n,function(){return this}),wr(s,"toString",function(){return"[object Generator]"}),(mr=function(){return{w:a,m:v}})()}function wr(e,r,t,n){var o=Object.defineProperty;try{o({},"",{})}catch(e){o=0}wr=function(e,r,t,n){if(r)o?o(e,r,{value:t,enumerable:!n,configurable:!n,writable:!n}):e[r]=t;else{var a=function(r,t){wr(e,r,function(e){return this._invoke(r,t,e)})};a("next",0),a("throw",1),a("return",2)}},wr(e,r,t,n)}function gr(e,r,t,n,o,a,i){try{var u=e[a](i),f=u.value}catch(e){return void t(e)}u.done?r(f):Promise.resolve(f).then(n,o)}function kr(e){return function(){var r=this,t=arguments;return new Promise(function(n,o){var a=e.apply(r,t);function i(e){gr(a,n,o,i,u,"next",e)}function u(e){gr(a,n,o,i,u,"throw",e)}i(void 0)})}}function Sr(e,r,t){return Ar.apply(this,arguments)}function Ar(){return(Ar=kr(mr().m(function e(r,t,n){var o,a,i,u,f,c,l;return mr().w(function(e){for(;;)switch(e.n){case 0:return n=null!=n?n:"encoded by carta1",e.p=1,o=hr.frameBufferToFrames(r),a=r.length,i=new R(t),u=hr.encodeStream(o,{channelCount:a,encoderOptions:i}),e.n=2,hr.collectFrames(u);case 2:return f=e.v,e.n=3,hr.createAeaBlob(f,{title:n,channelCount:a});case 3:return c=e.v,e.a(2,{aeaBlob:c});case 4:throw e.p=4,l=e.v,console.error("Worker encode error:",l),l;case 5:return e.a(2)}},e,null,[[1,4]])}))).apply(this,arguments)}function Mr(){return(new R).toObject()}function Or(e){return jr.apply(this,arguments)}function jr(){return(jr=kr(mr().m(function e(t){var n,o,a,i,u,f,c,l,s;return mr().w(function(e){for(;;)switch(e.n){case 0:return n=t.header,o=t.aeaData,(a=t.info)?i=br({sampleRate:r},a):n?(u=_.parseHeader(n),i=br({sampleRate:r},u)):i={channelCount:2,sampleRate:r},f=hr.deserializedFrameStream(o),c=hr.decodeStream(f,{channelCount:i.channelCount}),e.n=1,hr.collectFrames(c);case 1:return l=e.v,s=hr.createWavBlob(l,i.channelCount,i.sampleRate),e.a(2,{wavBlob:s,info:i})}},e)}))).apply(this,arguments)}self.onmessage=function(){var e=kr(mr().m(function e(r){var t,n,o,a,i,u,f,c,l,s,v;return mr().w(function(e){for(;;)switch(e.n){case 0:t=r.data,n=t.jobId,o=t.type,a=t.pcmData,i=t.aea,u=t.options,f=t.title,c=t.blob,e.p=1,s=o,e.n="encode"===s?2:"decode"===s?4:"parseAea"===s?6:"getEncoderOptions"===s?8:9;break;case 2:return e.n=3,Sr(a,u,f);case 3:return l=e.v,e.a(3,10);case 4:return e.n=5,Or(i);case 5:return l=e.v,e.a(3,10);case 6:return e.n=7,hr.parseAeaBlob(c);case 7:return l=e.v,e.a(3,10);case 8:return l=Mr(),e.a(3,10);case 9:throw new Error("Unknown worker message type: ".concat(o));case 10:self.postMessage({jobId:n,result:l}),e.n=12;break;case 11:e.p=11,v=e.v,console.error("Worker error:",v),self.postMessage({jobId:n,error:v.message});case 12:return e.a(2)}},e,null,[[1,11]])}));return function(r){return e.apply(this,arguments)}}();var Br=self;for(var Fr in e)Br[Fr]=e[Fr];e.__esModule&&Object.defineProperty(Br,"__esModule",{value:!0});
|
|
2
2
|
//# sourceMappingURL=carta1-worker.min.js.map
|