@hussmartinez/audio-sdk 0.4.0 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +106 -23
- package/dist/assets/audio/audio.worker.js +1 -1
- package/dist/index.d.ts +795 -148
- package/dist/index.js +1737 -515
- package/dist/index.js.map +1 -1
- package/dist/lazy/inline-worker-D8bxbE-Q.js +30 -0
- package/dist/lazy/{inline-worker-BB2jwrIT.js.map → inline-worker-D8bxbE-Q.js.map} +1 -1
- package/formats/hm-audio-command/v2.schema.json +381 -0
- package/formats/hm-audio-plan/v2.schema.json +226 -0
- package/package.json +8 -6
- package/dist/lazy/inline-worker-BB2jwrIT.js +0 -30
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
|
+
"$id": "https://github.com/ie-huss-martinez/audio-sdk/blob/main/formats/hm-audio-plan/v2.schema.json",
|
|
4
|
+
"title": "hm-audio-plan, version 2",
|
|
5
|
+
"description": "An audio-sdk multitrack plan: tracks of clips positioned in time over immutable sources, mixed on playback and export, with the metadata export writes (docs/formats/hm-audio-plan.md, docs/adr/0006, sdk-core ADR 0045). Every position and length is a whole number of frames at sampleRate. Beyond this schema, readers check that every clip lies within a source the document lists, that its fades fit it, that each track's clips are in time order and don't overlap, and that keys are unique across tracks and clips.",
|
|
6
|
+
"type": "object",
|
|
7
|
+
"required": [
|
|
8
|
+
"format",
|
|
9
|
+
"version",
|
|
10
|
+
"sampleRate",
|
|
11
|
+
"channels",
|
|
12
|
+
"gainDb",
|
|
13
|
+
"sources",
|
|
14
|
+
"tracks",
|
|
15
|
+
"metadata"
|
|
16
|
+
],
|
|
17
|
+
"additionalProperties": false,
|
|
18
|
+
"properties": {
|
|
19
|
+
"format": {
|
|
20
|
+
"const": "hm-audio-plan"
|
|
21
|
+
},
|
|
22
|
+
"version": {
|
|
23
|
+
"const": 2
|
|
24
|
+
},
|
|
25
|
+
"sampleRate": {
|
|
26
|
+
"description": "Frames per second.",
|
|
27
|
+
"type": "integer",
|
|
28
|
+
"minimum": 1,
|
|
29
|
+
"maximum": 9007199254740991
|
|
30
|
+
},
|
|
31
|
+
"channels": {
|
|
32
|
+
"type": "integer",
|
|
33
|
+
"minimum": 1,
|
|
34
|
+
"maximum": 9007199254740991
|
|
35
|
+
},
|
|
36
|
+
"gainDb": {
|
|
37
|
+
"description": "The master gain, applied to the mix.",
|
|
38
|
+
"$ref": "#/$defs/gainDb"
|
|
39
|
+
},
|
|
40
|
+
"sources": {
|
|
41
|
+
"description": "The sources the clips play, by the ids the clips use.",
|
|
42
|
+
"type": "object",
|
|
43
|
+
"propertyNames": {
|
|
44
|
+
"minLength": 1
|
|
45
|
+
},
|
|
46
|
+
"additionalProperties": {
|
|
47
|
+
"$ref": "#/$defs/source"
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
"tracks": {
|
|
51
|
+
"description": "The tracks, from top to bottom. A plan has at least one.",
|
|
52
|
+
"type": "array",
|
|
53
|
+
"minItems": 1,
|
|
54
|
+
"items": {
|
|
55
|
+
"$ref": "#/$defs/track"
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
"metadata": {
|
|
59
|
+
"$ref": "#/$defs/metadata"
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
"$defs": {
|
|
63
|
+
"frames": {
|
|
64
|
+
"description": "A whole number of frames.",
|
|
65
|
+
"type": "integer",
|
|
66
|
+
"minimum": 0,
|
|
67
|
+
"maximum": 9007199254740991
|
|
68
|
+
},
|
|
69
|
+
"key": {
|
|
70
|
+
"description": "A track's or a clip's key, stable across edits. Tracks and clips share one namespace.",
|
|
71
|
+
"type": "string",
|
|
72
|
+
"minLength": 1
|
|
73
|
+
},
|
|
74
|
+
"gainDb": {
|
|
75
|
+
"description": "A gain in decibels. Copied, never computed, so it compares exactly.",
|
|
76
|
+
"type": "number",
|
|
77
|
+
"minimum": -120,
|
|
78
|
+
"maximum": 120
|
|
79
|
+
},
|
|
80
|
+
"fade": {
|
|
81
|
+
"type": "object",
|
|
82
|
+
"required": ["frames", "curve"],
|
|
83
|
+
"additionalProperties": false,
|
|
84
|
+
"properties": {
|
|
85
|
+
"frames": {
|
|
86
|
+
"$ref": "#/$defs/frames"
|
|
87
|
+
},
|
|
88
|
+
"curve": {
|
|
89
|
+
"enum": ["linear", "equalPower"]
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
},
|
|
93
|
+
"clip": {
|
|
94
|
+
"description": "A range of a source, from start inclusive to end exclusive, placed on the timeline frame at, with its gain and fades.",
|
|
95
|
+
"type": "object",
|
|
96
|
+
"required": ["key", "at", "source", "start", "end", "gainDb", "fadeIn", "fadeOut"],
|
|
97
|
+
"additionalProperties": false,
|
|
98
|
+
"properties": {
|
|
99
|
+
"key": {
|
|
100
|
+
"$ref": "#/$defs/key"
|
|
101
|
+
},
|
|
102
|
+
"at": {
|
|
103
|
+
"description": "The timeline frame the clip starts on.",
|
|
104
|
+
"$ref": "#/$defs/frames"
|
|
105
|
+
},
|
|
106
|
+
"source": {
|
|
107
|
+
"type": "string",
|
|
108
|
+
"minLength": 1
|
|
109
|
+
},
|
|
110
|
+
"start": {
|
|
111
|
+
"$ref": "#/$defs/frames"
|
|
112
|
+
},
|
|
113
|
+
"end": {
|
|
114
|
+
"$ref": "#/$defs/frames"
|
|
115
|
+
},
|
|
116
|
+
"gainDb": {
|
|
117
|
+
"$ref": "#/$defs/gainDb"
|
|
118
|
+
},
|
|
119
|
+
"fadeIn": {
|
|
120
|
+
"$ref": "#/$defs/fade"
|
|
121
|
+
},
|
|
122
|
+
"fadeOut": {
|
|
123
|
+
"$ref": "#/$defs/fade"
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
},
|
|
127
|
+
"trackName": {
|
|
128
|
+
"description": "A track's name, in Unicode code points. Empty means none. It's untrusted text.",
|
|
129
|
+
"type": "string",
|
|
130
|
+
"maxLength": 100
|
|
131
|
+
},
|
|
132
|
+
"track": {
|
|
133
|
+
"description": "Clips in time order that never overlap, with the track's name, gain, mute and solo.",
|
|
134
|
+
"type": "object",
|
|
135
|
+
"required": ["key", "name", "gainDb", "muted", "soloed", "clips"],
|
|
136
|
+
"additionalProperties": false,
|
|
137
|
+
"properties": {
|
|
138
|
+
"key": {
|
|
139
|
+
"$ref": "#/$defs/key"
|
|
140
|
+
},
|
|
141
|
+
"name": {
|
|
142
|
+
"$ref": "#/$defs/trackName"
|
|
143
|
+
},
|
|
144
|
+
"gainDb": {
|
|
145
|
+
"$ref": "#/$defs/gainDb"
|
|
146
|
+
},
|
|
147
|
+
"muted": {
|
|
148
|
+
"type": "boolean"
|
|
149
|
+
},
|
|
150
|
+
"soloed": {
|
|
151
|
+
"type": "boolean"
|
|
152
|
+
},
|
|
153
|
+
"clips": {
|
|
154
|
+
"type": "array",
|
|
155
|
+
"items": {
|
|
156
|
+
"$ref": "#/$defs/clip"
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
},
|
|
161
|
+
"source": {
|
|
162
|
+
"type": "object",
|
|
163
|
+
"required": ["frames"],
|
|
164
|
+
"additionalProperties": false,
|
|
165
|
+
"properties": {
|
|
166
|
+
"frames": {
|
|
167
|
+
"description": "The source's length in frames.",
|
|
168
|
+
"type": "integer",
|
|
169
|
+
"minimum": 1,
|
|
170
|
+
"maximum": 9007199254740991
|
|
171
|
+
},
|
|
172
|
+
"asset": {
|
|
173
|
+
"$ref": "#/$defs/asset"
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
},
|
|
177
|
+
"asset": {
|
|
178
|
+
"description": "A content-addressed reference to the source's bytes (sdk-core ADR 0045, section 2).",
|
|
179
|
+
"type": "object",
|
|
180
|
+
"required": ["asset", "mediaType", "size"],
|
|
181
|
+
"additionalProperties": false,
|
|
182
|
+
"properties": {
|
|
183
|
+
"asset": {
|
|
184
|
+
"type": "string",
|
|
185
|
+
"pattern": "^sha256:[0-9a-f]{64}$"
|
|
186
|
+
},
|
|
187
|
+
"mediaType": {
|
|
188
|
+
"type": "string",
|
|
189
|
+
"maxLength": 255,
|
|
190
|
+
"pattern": "^[a-z0-9][a-z0-9!#$&^_.+-]*/[a-z0-9][a-z0-9!#$&^_.+-]*$"
|
|
191
|
+
},
|
|
192
|
+
"size": {
|
|
193
|
+
"type": "integer",
|
|
194
|
+
"minimum": 0,
|
|
195
|
+
"maximum": 9007199254740991
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
},
|
|
199
|
+
"metadataText": {
|
|
200
|
+
"type": "string",
|
|
201
|
+
"maxLength": 1000
|
|
202
|
+
},
|
|
203
|
+
"metadata": {
|
|
204
|
+
"type": "object",
|
|
205
|
+
"required": ["title", "artist", "album", "year", "comment"],
|
|
206
|
+
"additionalProperties": false,
|
|
207
|
+
"properties": {
|
|
208
|
+
"title": {
|
|
209
|
+
"$ref": "#/$defs/metadataText"
|
|
210
|
+
},
|
|
211
|
+
"artist": {
|
|
212
|
+
"$ref": "#/$defs/metadataText"
|
|
213
|
+
},
|
|
214
|
+
"album": {
|
|
215
|
+
"$ref": "#/$defs/metadataText"
|
|
216
|
+
},
|
|
217
|
+
"year": {
|
|
218
|
+
"$ref": "#/$defs/metadataText"
|
|
219
|
+
},
|
|
220
|
+
"comment": {
|
|
221
|
+
"$ref": "#/$defs/metadataText"
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hussmartinez/audio-sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "Client-side audio SDK: a headless core, a React editor and a custom element. Audio never leaves the device.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -68,8 +68,9 @@
|
|
|
68
68
|
"@changesets/changelog-github": "^1.0.1",
|
|
69
69
|
"@changesets/cli": "^3.0.3",
|
|
70
70
|
"@commitlint/cli": "^21.2.4",
|
|
71
|
-
"@hussmartinez/sdk-config": "^0.
|
|
71
|
+
"@hussmartinez/sdk-config": "^0.9.0",
|
|
72
72
|
"@microsoft/api-extractor": "^7.60.1",
|
|
73
|
+
"@size-limit/esbuild": "^14.3.0",
|
|
73
74
|
"@size-limit/file": "^14.3.0",
|
|
74
75
|
"@types/node": "^24.19.2",
|
|
75
76
|
"@types/react": "^19.3.0",
|
|
@@ -80,7 +81,7 @@
|
|
|
80
81
|
"fast-check": "^4.10.2",
|
|
81
82
|
"husky": "^9.1.7",
|
|
82
83
|
"lint-staged": "^17.6.0",
|
|
83
|
-
"playwright": "
|
|
84
|
+
"playwright": "1.65.0",
|
|
84
85
|
"publint": "^0.3.25",
|
|
85
86
|
"react": "^19.3.0",
|
|
86
87
|
"react-dom": "^19.3.0",
|
|
@@ -97,7 +98,8 @@
|
|
|
97
98
|
"lint:css": "stylelint \"**/*.css\" --allow-empty-input",
|
|
98
99
|
"lint:deps": "hm-lint-deps src",
|
|
99
100
|
"check:single-copy": "hm-check-single-copy",
|
|
100
|
-
"
|
|
101
|
+
"check:playwright-image": "hm-check-playwright-image",
|
|
102
|
+
"conformance:update": "vitest run --project unit test/conformance test/v1 --update",
|
|
101
103
|
"typecheck": "tsc -p tsconfig.json && tsc -p tsconfig.test.json",
|
|
102
104
|
"build": "vite build && pnpm check:api",
|
|
103
105
|
"test": "vitest run --project unit",
|
|
@@ -109,7 +111,7 @@
|
|
|
109
111
|
"check:api": "tsc -p tsconfig.build.json && api-extractor run && api-extractor run -c api-extractor.react.json && api-extractor run -c api-extractor.element.json",
|
|
110
112
|
"check:package": "publint run --pack pnpm --strict && attw --pack . --profile esm-only --exclude-entrypoints ./styles.css",
|
|
111
113
|
"api:update": "tsc -p tsconfig.build.json && api-extractor run --local && api-extractor run -c api-extractor.react.json --local && api-extractor run -c api-extractor.element.json --local",
|
|
112
|
-
"verify": "pnpm lint && pnpm lint:css && pnpm typecheck && pnpm lint:deps && pnpm check:single-copy && pnpm build && pnpm test && pnpm test:browser && pnpm build:examples && pnpm test:e2e && pnpm check:size && pnpm check:api && pnpm check:package",
|
|
113
|
-
"verify:fast": "pnpm typecheck && pnpm test && pnpm lint:deps && pnpm check:single-copy && pnpm check:api"
|
|
114
|
+
"verify": "pnpm lint && pnpm lint:css && pnpm typecheck && pnpm lint:deps && pnpm check:single-copy && pnpm check:playwright-image && pnpm build && pnpm test && pnpm test:browser && pnpm build:examples && pnpm test:e2e && pnpm check:size && pnpm check:api && pnpm check:package",
|
|
115
|
+
"verify:fast": "pnpm typecheck && pnpm test && pnpm lint:deps && pnpm check:single-copy && pnpm check:playwright-image && pnpm check:api"
|
|
114
116
|
}
|
|
115
117
|
}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
// src/workers/audio.worker.ts?worker&inline
|
|
2
|
-
var jsContent = "var e=/* @__PURE__ */ Symbol.for(`@hussmartinez/sdk-core/SdkError`),t=class extends Error{name=`SdkError`;code;constructor(t,n,r={}){super(n,`cause`in r?{cause:r.cause}:void 0),this.code=t,Object.defineProperty(this,e,{value:!0}),r.details!==void 0&&(this.details=r.details)}};function n(n,r){if(typeof n!=`object`||!n)return!1;let i=n;return(n instanceof t||i[e]===!0)&&typeof i.code==`string`&&typeof i.message==`string`&&(r===void 0||i.code===r)}var r=1<<20;function i(e,t,n){if(!Number.isSafeInteger(t)||t<n)throw RangeError(`The ${e} must be an integer of at least ${n}, not ${String(t)}.`)}function a(e,t={}){let n=t.windowSize??r;i(`window size`,n,1);let a=e.size,o=0,s=/* @__PURE__ */ new Uint8Array;return{size:a,async bytes(t,r){i(`offset`,t,0),i(`length`,r,0);let c=Math.min(t,a),l=Math.min(a,c+r);if(c<o||l>o+s.length){let t=Math.min(a,c+Math.max(r,n));s=new Uint8Array(await e.slice(c,t).arrayBuffer()),o=c}return s.subarray(c-o,l-o)}}}var o=8,s=16,c=`UNKNOWN`;function l(e,t={}){let n=t.includeStack??!1,r=h(t.maxDepth),i=/* @__PURE__ */ new Set,a=(e,t)=>{i.add(e);let o=u(e),s=n&&p(e)?e.stack:void 0;return typeof s==`string`&&(o.stack=s),p(e)&&`cause`in e&&t<r&&!i.has(e.cause)&&(o.cause=a(e.cause,t+1)),o};return a(e,0)}function u(e){if(n(e)){let t={name:e.name,code:e.code,message:e.message},n=d(e.details);return n!==void 0&&(t.details=n),t}if(p(e)&&typeof e.message==`string`){let t=typeof e.name==`string`?e.name:`Error`;return{name:`SdkError`,code:c,message:e.message,details:{originalName:t}}}return typeof e==`string`?{name:`SdkError`,code:c,message:e,details:{thrownType:`string`}}:{name:`SdkError`,code:c,message:`A value that isn't an Error was thrown.`,details:{thrownType:e===null?`null`:typeof e}}}function d(e){if(!m(e))return;let t=f(e,0);return m(t)?t:void 0}function f(e,t){if(e===null||typeof e==`string`||typeof e==`boolean`)return e;if(typeof e==`number`)return Number.isFinite(e)?e:void 0;if(!(t>=s)){if(Array.isArray(e))return e.flatMap(e=>{let n=f(e,t+1);return n===void 0?[]:[n]});if(m(e)){let n={};for(let[r,i]of Object.entries(e)){let e=f(i,t+1);e!==void 0&&(n[r]=e)}return n}}}function p(e){return typeof e==`object`&&!!e}function m(e){if(typeof e!=`object`||!e)return!1;let t=Object.getPrototypeOf(e);return t===Object.prototype||t===null}function h(e){if(e===void 0)return o;if(!Number.isInteger(e)||e<0)throw RangeError(`maxDepth must be a non-negative integer, received ${e}.`);return e}[...Array.from({length:12},(e,t)=>`F${t+1}`)];var g=`hm-rpc`;function _(e){return{protocol:g,version:1,...e}}function v(e){if(typeof e!=`object`||!e)return;let t=e;if(t.protocol!==`hm-rpc`||typeof t.version!=`number`)return;let n=Number.isSafeInteger(t.id);switch(t.type){case`ready`:return t;case`call`:return n&&typeof t.method==`string`?t:void 0;case`cancel`:case`progress`:case`result`:return n?t:void 0;case`error`:return n?t:void 0;case`crash`:return t;default:return}}function y(e,t){let n=/* @__PURE__ */ new Set,r=/* @__PURE__ */ new Map,i=e=>{if(typeof e!=`object`||!e)return e;if(r.has(e))return r.get(e);if(ArrayBuffer.isView(e)){let i=b(e)?e:x(e);return t&&i===e&&n.add(e.buffer),r.set(e,i),i}return C(e)?(t&&n.add(e),r.set(e,e),e):Array.isArray(e)?a(e,()=>[],(e,t)=>{t.forEach((t,n)=>{e[n]=i(t)})}):e instanceof Map?a(e,()=>/* @__PURE__ */ new Map,(e,t)=>{for(let[n,r]of t)e.set(i(n),i(r))}):e instanceof Set?a(e,()=>/* @__PURE__ */ new Set,(e,t)=>{for(let n of t)e.add(i(n))}):w(e)?a(e,()=>({}),(e,t)=>{for(let[n,r]of Object.entries(t))e[n]=i(r)}):(r.set(e,e),e)},a=(e,t,n)=>{let i=t();return r.set(e,i),n(i,e),T(e,i)?(r.set(e,e),e):i};return{value:i(e),transferables:[...n]}}function ee(e,t,n){if(n.length===0)e(t,[]);else try{e(t,n)}catch{e(t,[])}}function b(e){return e.buffer instanceof ArrayBuffer&&e.byteOffset===0&&e.byteLength===e.buffer.byteLength}function x(e){let t=new Uint8Array(e.buffer,e.byteOffset,e.byteLength).slice();if(e instanceof DataView)return new DataView(t.buffer);let n=e.constructor;return new n(t.buffer)}var S=[`ArrayBuffer`,`MessagePort`,`ImageBitmap`,`OffscreenCanvas`,`ReadableStream`,`WritableStream`,`TransformStream`,`VideoFrame`,`AudioData`];function C(e){let t=globalThis;return S.some(n=>{let r=t[n];return typeof r==`function`&&e instanceof r})}function w(e){let t=Object.getPrototypeOf(e);return t===Object.prototype||t===null}function T(e,t){if(Array.isArray(e)){let n=t;return e.length===n.length&&e.every((e,t)=>e===n[t])}if(e instanceof Map){let n=[...t];return[...e].every(([e,t],r)=>n[r]?.[0]===e&&n[r]?.[1]===t)}if(e instanceof Set){let n=[...t];return[...e].every((e,t)=>n[t]===e)}let n=t;return Object.entries(e).every(([e,t])=>n[e]===t)}function E(e,n={}){let r=n.scope??globalThis,i=n.includeStack??!1,a=/* @__PURE__ */ new Map,o=(e,t=[])=>{r.postMessage(e,t)},s=(e,t)=>{o(_({type:`error`,id:e,error:l(t,{includeStack:i})}))},c=(e,n,i)=>{let a=y(i,!0);try{ee((e,t)=>r.postMessage(e,t),_({type:`result`,id:e,output:a.value}),a.transferables)}catch(r){s(e,new t(`WORKER_DATA_NOT_CLONEABLE`,`The result of \"${n}\" can't be sent to the page.`,{cause:r,details:{method:n}}))}},u=n=>{let{id:r,method:i}=n,l=Object.hasOwn(e,i)?e[i]:void 0;if(typeof l!=`function`){s(r,new t(`WORKER_METHOD_NOT_FOUND`,`The worker has no method \"${i}\".`,{details:{method:i}}));return}let u=new AbortController;a.set(r,u);let d={signal:u.signal,progress:e=>{a.get(r)===u&&o(_({type:`progress`,id:r,value:e}))}};Promise.resolve().then(()=>l.call(e,n.input,d)).then(e=>{a.delete(r),c(r,i,e)},e=>{a.delete(r),s(r,e)})},d=e=>{o(_({type:`crash`,error:l(e,{includeStack:i})}))};r.addEventListener(`message`,e=>{let t=v(e.data);t!==void 0&&t.version===1&&(t.type===`call`?u(t):t.type===`cancel`&&a.get(t.id)?.abort())}),r.addEventListener(`error`,e=>{let t=e;d(t.error??Error(t.message))}),r.addEventListener(`unhandledrejection`,e=>{d(e.reason)}),o(_({type:`ready`,...n.packageVersion===void 0?{}:{packageVersion:n.packageVersion}}))}var D=class extends t{name=`AudioError`};function O(e,t){return new D(`INVALID_AUDIO`,`Invalid ${e} file: ${t}.`,{details:{container:e,reason:t}})}function k(e,t){return new D(`UNSUPPORTED_FORMAT`,`Unsupported sample format in ${e}: ${t}.`,{details:{container:e,codec:t}})}async function A(e,t,n){let r=await e.slice(t,t+n).arrayBuffer();return new DataView(r)}function j(e,t=0){return e.byteLength<t+4?``:String.fromCharCode(e.getUint8(t),e.getUint8(t+1),e.getUint8(t+2),e.getUint8(t+3))}function te(e){let{container:t,channels:n,sampleRate:r,bytesPerSample:i,blockAlign:a,frames:o,dataOffset:s}=e;if(!Number.isInteger(n)||n<1||n>1024)throw O(t,`channel count out of range`);if(!Number.isInteger(r)||r<1)throw O(t,`sample rate out of range`);if(![1,2,3,4,8].includes(i))throw O(t,`sample size out of range`);if(a!==n*i)throw O(t,`frame size doesn't match the channels and sample size`);if(!Number.isSafeInteger(o)||o<0||!Number.isSafeInteger(s))throw O(t,`length out of range`);return e}const ne={NONE:{encoding:`int`,littleEndian:!1},twos:{encoding:`int`,littleEndian:!1},sowt:{encoding:`int`,littleEndian:!0},in24:{encoding:`int`,littleEndian:!1,bits:24},\"42ni\":{encoding:`int`,littleEndian:!0,bits:24},in32:{encoding:`int`,littleEndian:!1,bits:32},\"23ni\":{encoding:`int`,littleEndian:!0,bits:32},fl32:{encoding:`float`,littleEndian:!1,bits:32},FL32:{encoding:`float`,littleEndian:!1,bits:32},fl64:{encoding:`float`,littleEndian:!1,bits:64},FL64:{encoding:`float`,littleEndian:!1,bits:64}};function re(e,t){let n=e.getUint16(t,!1),r=n&32767;return n&32768||r===0||r===32767?NaN:(e.getUint32(t+2,!1)*2**32+e.getUint32(t+6,!1))*2**(r-16383-63)}function ie(e,t){if(e.byteLength<(t?22:18))throw O(`aiff`,`truncated COMM chunk`);let n=re(e,8);if(!Number.isInteger(n)||n<1||n>2**31)throw O(`aiff`,`sample rate out of range`);return{channels:e.getInt16(0,!1),frames:e.getUint32(2,!1),bits:e.getInt16(6,!1),sampleRate:n,type:t?j(e,18):`NONE`}}async function ae(e){let t=await A(e,0,12),n=j(t,8);if(j(t)!==`FORM`||n!==`AIFF`&&n!==`AIFC`)throw O(`aiff`,`missing FORM header`);let r=n===`AIFC`,i,a,o=12;for(let t=0;o+8<=e.size;t+=1){if(t>=1024)throw O(`aiff`,`too many chunks`);let n=await A(e,o,8),s=j(n),c=n.getUint32(4,!1),l=o+8,u=e.size-l;if(s===`COMM`){if(c>u)throw O(`aiff`,`truncated COMM chunk`);i=ie(await A(e,l,Math.min(c,64)),r)}else if(s===`SSND`){let t=await A(e,l,8);if(c<8||t.byteLength<8)throw O(`aiff`,`truncated SSND chunk`);let n=l+8+t.getUint32(0,!1),r=Math.min(l+c,e.size);if(n>r)throw O(`aiff`,`sound data offset past the chunk`);a={offset:n,size:r-n}}if(i&&a)break;o=l+c+c%2}if(!i)throw O(`aiff`,`missing COMM chunk`);if(!a)throw O(`aiff`,`missing SSND chunk`);let s=ne[i.type];if(!s)throw k(`aiff`,i.type||`unknown`);let c=s.bits??i.bits;if(c<1||c>64)throw O(`aiff`,`sample size out of range`);if(s.encoding===`float`&&c!==32&&c!==64)throw k(`aiff`,`${c}-bit float`);if(s.encoding===`int`&&c>32)throw k(`aiff`,`${c}-bit integer`);let l=Math.ceil(c/8),u=te({container:`aiff`,sampleRate:i.sampleRate,channels:i.channels,encoding:s.encoding,bytesPerSample:l,littleEndian:s.littleEndian,dataOffset:a.offset,blockAlign:i.channels*l,frames:i.frames});return u.frames*u.blockAlign>a.size?{...u,frames:Math.floor(a.size/u.blockAlign),declaredFrames:u.frames}:u}function oe(e,t,n){let{channels:r,bytesPerSample:i,blockAlign:a,encoding:o,littleEndian:s}=t;if(e.byteLength<n*a)throw RangeError(`Expected ${n*a} bytes, got ${e.byteLength}.`);let c=Array.from({length:r},()=>new Float32Array(n)),l=se(o,i,s);for(let t=0;t<r;t+=1){let r=c[t],o=t*i;for(let t=0;t<n;t+=1)r[t]=l(e,o),o+=a}return c}function se(e,t,n){if(e===`float`)return t===8?(e,t)=>ce(Math.fround(e.getFloat64(t,n))):(e,t)=>ce(e.getFloat32(t,n));if(e===`uint`)return(e,t)=>(e.getUint8(t)-128)/128;switch(t){case 1:return(e,t)=>e.getInt8(t)/128;case 2:return(e,t)=>e.getInt16(t,n)/32768;case 3:return(e,t)=>{let r=e.getUint8(t),i=e.getUint8(t+1),a=e.getUint8(t+2);return((n?r|i<<8|a<<16:r<<16|i<<8|a)<<8>>8)/8388608};default:return(e,t)=>e.getInt32(t,n)/2147483648}}function ce(e){return Number.isFinite(e)?e:0}const le=[0,0,0,0,16,0,128,0,0,170,0,56,155,113],ue=4294967295;async function de(e,t){let n=await A(e,t,8);if(n.byteLength<8)return!1;for(let e=0;e<4;e+=1){let t=n.getUint8(e);if(t<32||t>126)return!1}return n.getUint32(4,!0)<=e.size-t-8}function fe(e){if(e.byteLength<16)throw O(`wav`,`truncated fmt chunk`);let t=e.getUint16(0,!0),n={channels:e.getUint16(2,!0),sampleRate:e.getUint32(4,!0),blockAlign:e.getUint16(12,!0),bitsPerSample:e.getUint16(14,!0)};if(t===65534){if(e.byteLength<40)throw O(`wav`,`truncated extensible fmt chunk`);t=e.getUint16(24,!0);for(let[t,n]of le.entries())if(e.getUint8(26+t)!==n)throw k(`wav`,`extensible subformat`)}return{tag:t,...n}}function pe(e,t,n,r){let{tag:i,channels:a,sampleRate:o,blockAlign:s,bitsPerSample:c}=e;if(c%8!=0)throw O(`wav`,`sample size isn't whole bytes`);let l=c/8,u;if(i===1&&[1,2,3,4].includes(l))u=l===1?`uint`:`int`;else if(i===3&&[4,8].includes(l))u=`float`;else throw k(`wav`,`format ${i} at ${c} bits`);if(s<1)throw O(`wav`,`frame size is zero`);return te({container:`wav`,sampleRate:o,channels:a,encoding:u,bytesPerSample:l,littleEndian:!0,dataOffset:t,blockAlign:s,frames:Math.floor(n/s),...r===void 0?{}:{declaredFrames:Math.floor(r/s)}})}async function me(e){let t=await A(e,0,12),n=j(t);if(n!==`RIFF`&&n!==`RF64`||j(t,8)!==`WAVE`)throw O(`wav`,`missing RIFF header`);let r,i,a,o=12;for(let t=0;o+8<=e.size;t+=1){if(t>=1024)throw O(`wav`,`too many chunks`);let s=await A(e,o,8),c=j(s),l=s.getUint32(4,!0),u=o+8,d=e.size-u;if(c===`ds64`&&n===`RF64`){let t=await A(e,u,16);if(t.byteLength<16)throw O(`wav`,`truncated ds64 chunk`);let n=t.getUint32(12,!0);if(n>=2**21)throw O(`wav`,`data size out of range`);a=n*2**32+t.getUint32(8,!0)}else if(c===`fmt `){if(l>d)throw O(`wav`,`truncated fmt chunk`);r=fe(await A(e,u,Math.min(l,64)))}else if(c===`data`){let t=l;if(n===`RF64`&&l===ue){if(a===void 0)throw O(`wav`,`RF64 file without ds64 chunk`);t=a}else(l===ue||l===0&&!await de(e,u))&&(t=d);if(i={offset:u,size:Math.min(t,d),declared:t>d?t:void 0},r)break;o=u+t+t%2;continue}if(r&&i)break;o=u+l+l%2}if(!r)throw O(`wav`,`missing fmt chunk`);if(!i)throw O(`wav`,`missing data chunk`);return pe(r,i.offset,i.size,i.declared)}async function he(e){let t=await A(e,0,12),n=j(t),r=j(t,8),i;if((n===`RIFF`||n===`RF64`)&&r===`WAVE`)i=await me(e);else if(n===`FORM`&&(r===`AIFF`||r===`AIFC`))i=await ae(e);else throw new D(`UNSUPPORTED_FORMAT`,`The file's container isn't recognised.`,{details:{container:`unknown`}});if(i.frames===0)throw O(i.container,`no audio frames`);return{layout:i,probe:{container:i.container,codec:`pcm`,sampleRate:i.sampleRate,channels:i.channels,frameBound:i.frames,expectedFrames:i.frames,...i.declaredFrames===void 0?{}:{declaredFrames:i.declaredFrames},frameTolerance:0}}}async function ge(e,t,n,r){if(!Number.isSafeInteger(n)||!Number.isSafeInteger(r)||n<0||r<0||n+r>t.frames)throw RangeError(`Frames ${n} to ${n+r} are outside the file.`);let i=r*t.blockAlign,a=await A(e,t.dataOffset+n*t.blockAlign,i);if(a.byteLength<i)throw O(t.container,`file shorter than probed`);return oe(a,t,r)}function _e(e,t){let n=[],r=[];for(let i of e){let e=Math.ceil(i.length/t),a=new Float32Array(e),o=new Float32Array(e);for(let n=0;n<e;n+=1){let e=Math.min(i.length,(n+1)*t),r=1/0,s=-1/0;for(let a=n*t;a<e;a+=1){let e=i[a];e<r&&(r=e),e>s&&(s=e)}a[n]=r,o[n]=s}n.push(a),r.push(o)}return{min:n,max:r}}const M=1<<20;async function ve(e,t,n,r,i,a){let o=t;for(let s=t;s<e.size;s+=M){let t=await e.bytes(s,M+n),c=Math.min(M,e.size-s);for(let e=0;e<c;e+=1){if(t[e]!==255)continue;let n=r(t,e);if(n===void 0)continue;let c=s+e,l=c>=o;l&&(o=c+Math.max(1,i(n))),a(n,l)}}}async function N(e,t,n,r,i,a,o=3){let s=await e.bytes(t,n+65536);for(let c=0;c<Math.min(n,s.length);c+=1){if(s[c]!==255)continue;let n=r(s,c);if(n===void 0)continue;let l=c,u=n;for(let d=1;;d+=1){if(d===o)return{offset:t+c,first:n};let f=l+i(u);if(f===s.length&&t+s.length===e.size)return{offset:t+c,first:n};let p=r(s,f);if(p===void 0||!a(n,p))break;l=f,u=p}}}const ye=[96e3,88200,64e3,48e3,44100,32e3,24e3,22050,16e3,12e3,11025,8e3,7350];function P(e,t){let n=0,r=0,i=0,a=a=>{let o=0;for(let s=0;s<a;s+=1){if(n===0){if(i>=e.length)throw O(t,`truncated AudioSpecificConfig`);r=e[i],i+=1,n=8}--n,o=o*2+(r>>n&1)}return o};a(5)===31&&a(6);let o=a(4),s=o===15?a(24):ye[o];if(s===void 0||s===0)throw O(t,`AAC sample rate out of range`);return{coreRate:s,channelConfiguration:a(4)}}function F(e){return e===0||e===7?8:Math.max(2,e)}function I(e){return e<=24e3?e*2:e}function L(e,t){let n=n=>e[t+n],r=n(1),i=n(2),a=n(3),o=n(4),s=n(5),c=n(6);if(n(0)!==255||r===void 0||i===void 0||a===void 0||o===void 0||s===void 0||c===void 0||(r&246)!=240)return;let l=i>>2&15,u=ye[l];if(u===void 0)return;let d=(i&1)<<2|a>>6,f=(a&3)<<11|o<<3|s>>5;if(!(f<(r&1?7:9)))return{sampleRate:u,channelConfiguration:d,blocks:(c&3)+1,frameLength:f}}const be=(e,t)=>e.sampleRate===t.sampleRate&&e.channelConfiguration===t.channelConfiguration;async function xe(e,t){return N(a(e),t,65536,L,e=>e.frameLength,be)}async function Se(e,t){let n=a(e),r=await N(n,t,65536,L,e=>e.frameLength,be);if(!r)throw O(`adts`,`no frames`);let i=r.first.sampleRate,o=I(i),s=F(r.first.channelConfiguration),c=1024*Math.ceil(o/i),l=0,u=0;if(await ve(n,r.offset,7,L,e=>e.frameLength,(e,t)=>{let n=Math.max(1,Math.ceil(o/e.sampleRate)),r=Math.ceil(F(e.channelConfiguration)/s);l+=e.blocks*1024*n*r,t&&(u+=e.blocks)}),l===0)throw O(`adts`,`no frames`);return{container:`adts`,codec:`aac`,sampleRate:o,channels:s,frameBound:l,expectedFrames:Math.min(u*c,l),frameTolerance:2*c}}function R(e,t){let n=2**(e-1),r=2**e-1,i=/* @__PURE__ */ new Uint32Array(256);for(let a=0;a<256;a+=1){let o=a*2**(e-8);for(let e=0;e<8;e+=1)o=o>=n?(o*2^t)&r:o*2&r,o>>>=0;i[a]=o>>>0}return i}const Ce=R(8,7);R(16,32773),R(32,79764919);function we(e,t=0,n=e.length){let r=0;for(let i=t;i<n;i+=1)r=Ce[r^e[i]];return r}function z(e,t){if(e.length<34)throw O(t,`truncated STREAMINFO`);let n=new DataView(e.buffer,e.byteOffset,e.byteLength),r=n.getUint16(0),i=n.getUint16(2),a=n.getUint32(10),o=a>>>12,s=(a>>>9&7)+1,c=(a>>>4&31)+1,l=(a&15)*2**32+n.getUint32(14);if(r<16||i<r)throw O(t,`block sizes out of range`);if(o===0)throw O(t,`sample rate is zero`);if(c<4)throw O(t,`sample size out of range`);return{minBlockSize:r,maxBlockSize:i,sampleRate:o,channels:s,bitsPerSample:c,totalFrames:l}}const Te=[void 0,88200,176400,192e3,8e3,16e3,22050,24e3,32e3,44100,48e3,96e3];function B(e,t){let n=n=>e[t+n];if(n(0)!==255||((n(1)??0)&254)!=248)return;let r=n(2),i=n(3);if(r===void 0||i===void 0)return;let a=r>>4,o=r&15,s=i>>4,c=i>>1&7;if(a===0||o===15||s>10||c===3||i&1)return;let l=4,u=n(l);if(u===void 0)return;let d;if(u<128)d=0;else if(u>=192&&u<224)d=1;else if(u>=224&&u<240)d=2;else if(u>=240&&u<248)d=3;else if(u>=248&&u<252)d=4;else if(u>=252&&u<254)d=5;else if(u===254)d=6;else return;l+=1;for(let e=0;e<d;e+=1,l+=1){let e=n(l);if(e===void 0||(e&192)!=128)return}let f;if(a===1)f=192;else if(a<=5)f=576*2**(a-2);else if(a===6||a===7){let e=n(l);if(e===void 0)return;if(a===6)f=e+1,l+=1;else{let t=n(l+1);if(t===void 0)return;f=e*256+t+1,l+=2}}else f=256*2**(a-8);let p=Te[o];if(o>=12){let e=n(l);if(e===void 0)return;if(o===12)p=e*1e3,l+=1;else{let t=n(l+1);if(t===void 0)return;p=o===13?e*256+t:(e*256+t)*10,l+=2}if(p===0)return}let m=n(l);if(m!==void 0&&we(e,t,t+l)===m)return{blockSize:f,sampleRate:p,channels:s<8?s+1:2,length:l+1}}function Ee(e){if(e.length<10||e[0]!==73||e[1]!==68||e[2]!==51)return 0;let t=0;for(let n=6;n<10;n+=1){let r=e[n];if(r&128)return 0;t=t*128+r}let n=e[5]&16?10:0;return 10+t+n}const De=1<<20;function Oe(e,t){let n=e.sampleRate!==void 0&&e.sampleRate<t.sampleRate?Math.ceil(t.sampleRate/e.sampleRate):1,r=Math.ceil(e.channels/t.channels);return e.blockSize*n*r}async function ke(e){let t=a(e),n=Ee(await t.bytes(0,10)),r=await t.bytes(n,4);if(String.fromCharCode(...r)!==`fLaC`)throw O(`flac`,`missing fLaC marker`);n+=4;let i;for(let e=0;;e+=1){if(e>=1024)throw O(`flac`,`too many metadata blocks`);let r=await t.bytes(n,4);if(r.length<4)throw O(`flac`,`truncated metadata`);let a=!!(r[0]&128),o=r[0]&127,s=r[1]<<16|r[2]<<8|r[3];if(o===127)throw O(`flac`,`invalid metadata block type`);if(e===0){if(o!==0||s!==34)throw O(`flac`,`STREAMINFO isn't first`);i=z(await t.bytes(n+4,34),`flac`)}if(n+=4+s,n>t.size)throw O(`flac`,`metadata exceeds the file`);if(a)break}if(!i)throw O(`flac`,`missing STREAMINFO`);let o=0,s=0;for(let e=n;e<t.size;e+=De){let n=await t.bytes(e,1048592),r=Math.min(De,t.size-e);for(let e=0;e<r;e+=1){if(n[e]!==255)continue;let t=B(n,e);t&&(o+=Oe(t,i),s+=1)}}if(s===0)throw O(`flac`,`no audio frames`);if(i.totalFrames>o)throw O(`flac`,`STREAMINFO claims more than the frames carry`);return{container:`flac`,codec:`flac`,sampleRate:i.sampleRate,channels:i.channels,frameBound:o,expectedFrames:i.totalFrames>0?i.totalFrames:o,frameTolerance:i.maxBlockSize}}async function V(e,t){let n=a(e),r,i=-1,o=[],s=0,c=0,l=0;for(;c+27<=n.size;){let e=await n.bytes(c,65307);if(e[0]!==79||e[1]!==103||e[2]!==103||e[3]!==83){if(l===0)throw O(`ogg`,`missing first page`);c+=1;continue}let a=new DataView(e.buffer,e.byteOffset,e.byteLength),u=a.getUint8(4),d=a.getUint8(5),f=a.getUint8(26);if(u!==0||e.length<27+f){if(l===0)throw O(`ogg`,`malformed first page`);c+=1;continue}let p=0;for(let t=0;t<f;t+=1)p+=e[27+t];let m=27+f+p;if(m>e.length)break;let h=a.getUint32(14,!0),g=!!(d&2);if(r===void 0){if(!g)throw O(`ogg`,`first page doesn't begin a stream`);r=h}else if(h!==r){if(g)throw new D(`UNSUPPORTED_FORMAT`,`Ogg files with several streams aren't supported.`,{details:{container:`ogg`,reason:`multiplexed streams`}});c+=m,l+=1;continue}d&1||(o=[],s=0);let _=27+f;for(let n=0;n<f;n+=1){let r=e[27+n];if(o.length<64){let t=Math.min(r,64-o.length);for(let n=0;n<t;n+=1)o.push(e[_+n])}s+=r,_+=r,r<255&&(t({head:Uint8Array.from(o),length:s}),o=[],s=0)}let v=a.getInt32(10,!0),y=a.getUint32(6,!0);(v!==-1||y!==4294967295)&&(i=v*2**32+y),c+=m,l+=1}if(l===0)throw O(`ogg`,`missing first page`);return{lastGranule:i}}function Ae(e){return e[0]===127&&e[1]===70&&e[2]===76&&e[3]===65&&e[4]===67}async function je(e){let t,n=0,r=0,i=0,a=0,{lastGranule:o}=await V(e,({head:e})=>{if(n+=1,n===1){if(!Ae(e)||e[5]!==1)throw O(`ogg`,`not a FLAC mapping version 1`);let n=String.fromCharCode(...e.subarray(9,13)),i=(e[13]??127)&127;if(n!==`fLaC`||i!==0)throw O(`ogg`,`missing FLAC STREAMINFO`);t=z(e.subarray(17,51),`ogg`),r=(e[7]??0)<<8|(e[8]??0);return}if(!t)return;let o=e[0]===255&&((e[1]??0)&254)==248;if(n-1<=r||r===0&&!o&&a===0)return;a+=1;let s=B(e,0);if(!s)i+=t.maxBlockSize;else{if(s.channels!==t.channels)throw O(`ogg`,`a frame's channel count differs from STREAMINFO`);if(s.sampleRate!==void 0&&s.sampleRate!==t.sampleRate)throw O(`ogg`,`a frame's sample rate differs from STREAMINFO`);i+=s.blockSize}});if(!t)throw O(`ogg`,`missing FLAC header`);if(a===0)throw O(`ogg`,`no audio frames`);if(t.totalFrames>i||o>i)throw O(`ogg`,`a declared length exceeds the frames`);let s=o>0?o:t.totalFrames;return{container:`ogg`,codec:`flac`,sampleRate:t.sampleRate,channels:t.channels,frameBound:i,expectedFrames:s>0?s:i,frameTolerance:t.maxBlockSize}}const Me=48e3,H=5760;function U(e){return String.fromCharCode(...e.subarray(0,8))===`OpusHead`}function Ne(e){return e<12?[480,960,1920,2880][e%4]:e<16?[480,960][e%2]:[120,240,480,960][e%4]}function Pe(e,t){let n=e[0];if(t===0||n===void 0)return H;let r=Ne(n>>3),i=n&3,a;if(i===0)a=1;else if(i===1||i===2)a=2;else{let t=e[1];if(t===void 0)return H;a=t&63}let o=a*r;return o===0||o>5760?H:o}function Fe(e,t){if(!U(e)||e.length<19)throw O(t,`malformed OpusHead`);if(e[8]&240)throw O(t,`unsupported OpusHead version`);let n=e[9],r=e[10]|e[11]<<8,i=e[18];if(n===0)throw O(t,`no channels`);if(i===0?n>2:i!==1||n>8)throw new D(`UNSUPPORTED_FORMAT`,`Unsupported Opus channel mapping.`,{details:{container:t,codec:`opus`,reason:`channel mapping family ${i}`}});return{channels:n,preSkip:r}}async function Ie(e){let t=0,n=0,r=0,i=0,{lastGranule:a}=await V(e,({head:e,length:a})=>{if(r+=1,r===1)({channels:t,preSkip:n}=Fe(e,`ogg`));else if(r===2){if(String.fromCharCode(...e.subarray(0,8))!==`OpusTags`)throw O(`ogg`,`missing OpusTags`)}else i+=Pe(e,a)});if(r<2)throw O(`ogg`,`missing Opus headers`);if(i===0)throw O(`ogg`,`no audio packets`);if(a>i)throw O(`ogg`,`a declared length exceeds the packets`);let o=a>0?Math.max(0,a-n):i;return{container:`ogg`,codec:`opus`,sampleRate:Me,channels:t,frameBound:i,expectedFrames:o,frameTolerance:Math.max(H,n)}}const Le=`vorbis`;function Re(e){return e[0]===1&&String.fromCharCode(...e.subarray(1,7))===Le}function ze(e,t){if(!Re(e)||e.length<30)throw O(t,`malformed Vorbis header`);let n=new DataView(e.buffer,e.byteOffset,e.byteLength);if(n.getUint32(7,!0)!==0)throw O(t,`unsupported Vorbis version`);let r=n.getUint8(11),i=n.getUint32(12,!0),a=n.getUint8(28),o=a&15,s=a>>4;if(o<6||s>13||o>s||(n.getUint8(29)&1)!=1)throw O(t,`Vorbis block sizes out of range`);if(r===0||i===0)throw O(t,`Vorbis format out of range`);return{channels:r,sampleRate:i,largeBlock:2**s}}async function Be(e){let t=0,n=0,r=0,i=0,a=0,{lastGranule:o}=await V(e,({head:e})=>{if(i+=1,i===1)({channels:t,sampleRate:n,largeBlock:r}=ze(e,`ogg`));else if(i===2||i===3){let t=i===2?3:5;if(e[0]!==t||String.fromCharCode(...e.subarray(1,7))!==Le)throw O(`ogg`,`missing Vorbis comment or setup header`)}else a+=1});if(i<3)throw O(`ogg`,`missing Vorbis headers`);if(a===0)throw O(`ogg`,`no audio packets`);let s=r/2*a;if(o>s)throw O(`ogg`,`a declared length exceeds the packets`);return{container:`ogg`,codec:`vorbis`,sampleRate:n,channels:t,frameBound:s,expectedFrames:o>0?o:s,frameTolerance:r}}const W=440786851,Ve=357149030,He=374648427,Ue=524531317,We=/* @__PURE__ */ new Set([Ue,475249515,307544935,272869232,423732329,290298740,Ve,He,W]);function G(e,t){return new D(`UNSUPPORTED_FORMAT`,`Unsupported Matroska: ${e}.`,{details:t===void 0?{container:`webm`,reason:e}:{container:`webm`,codec:t,reason:e}})}function Ge(e,t){let n=e[t];if(n===void 0||n===0)return;let r=Math.clz32(n)-23;if(r>4||t+r>e.length)return;let i=0;for(let n=0;n<r;n+=1)i=i*256+e[t+n];return{id:i,length:r}}function K(e,t){let n=e[t];if(n===void 0||n===0)return;let r=Math.clz32(n)-23;if(t+r>e.length)return;let i=n&255>>r,a=i===255>>r;for(let n=1;n<r;n+=1){let r=e[t+n];i=i*256+r,r!==255&&(a=!1)}return{value:i,length:r,unknown:a}}async function q(e,t){let n=await e.bytes(t,12),r=Ge(n,0);if(!r)return;let i=K(n,r.length);if(i){if(!i.unknown&&!Number.isSafeInteger(i.value))throw O(`webm`,`element size out of range`);return{id:r.id,body:t+r.length+i.length,size:i.unknown?void 0:i.value}}}function J(e){let t=[],n=0;for(;n<e.length;){let r=Ge(e,n),i=r&&K(e,n+r.length);if(!r||!i||i.unknown)throw O(`webm`,`malformed element`);let a=n+r.length+i.length;if(a+i.value>e.length)throw O(`webm`,`element exceeds its parent`);t.push({id:r.id,data:e.subarray(a,a+i.value)}),n=a+i.value}return t}const Y=e=>e.reduce((e,t)=>e*256+t,0);function Ke(e){let t=new DataView(e.buffer,e.byteOffset,e.byteLength);return e.length===4?t.getFloat32(0):e.length===8?t.getFloat64(0):NaN}function qe(e,t){if(e===`A_OPUS`){if(!t)throw O(`webm`,`missing OpusHead`);let e=Fe(t,`webm`);return{codec:`opus`,sampleRate:Me,channels:e.channels,tolerance:Math.max(H,e.preSkip),frameSamples:Pe}}if(e===`A_VORBIS`){if(t?.[0]!==2)throw O(`webm`,`malformed Vorbis headers`);let e=1;for(let n=0;n<2;n+=1){for(;t[e]===255;)e+=1;if(t[e]===void 0)throw O(`webm`,`malformed Vorbis headers`);e+=1}let n=ze(t.subarray(e),`webm`),r=n.largeBlock/2;return{codec:`vorbis`,sampleRate:n.sampleRate,channels:n.channels,tolerance:n.largeBlock,frameSamples:()=>r}}if(e===`A_FLAC`){let e=t&&String.fromCharCode(...t.subarray(0,4));if(!t||e!==`fLaC`||(t[4]??127)&127)throw O(`webm`,`missing FLAC STREAMINFO`);let n=z(t.subarray(8,42),`webm`);return{codec:`flac`,sampleRate:n.sampleRate,channels:n.channels,tolerance:n.maxBlockSize,frameSamples(e){let t=B(e,0);if(!t)return n.maxBlockSize;if(t.channels!==n.channels)throw O(`webm`,`a frame's channel count differs from STREAMINFO`);if(t.sampleRate!==void 0&&t.sampleRate!==n.sampleRate)throw O(`webm`,`a frame's sample rate differs from STREAMINFO`);return t.blockSize}}}if(e.startsWith(`A_AAC`)){if(!t)throw G(`AAC without an AudioSpecificConfig`,`aac`);let e=P(t,`webm`),n=I(e.coreRate),r=1024*Math.ceil(n/e.coreRate);return{codec:`aac`,sampleRate:n,channels:F(e.channelConfiguration),tolerance:2*r,frameSamples:()=>r}}throw G(`codec ${e}`,e)}function Je(e){let t=[];for(let n of J(e)){if(n.id!==174)continue;let e=J(n.data),r=t=>e.find(e=>e.id===t)?.data,i=r(131);if(!i||Y(i)!==2)continue;let a=r(215),o=r(134);if(!a||!o)throw O(`webm`,`incomplete audio track`);let s=String.fromCharCode(...o).replace(/\\0+$/,``);t.push({number:Y(a),codec:qe(s,r(25506))})}if(t.length===0)throw O(`webm`,`no audio track`);if(t.length>1)throw G(`several audio tracks`);return t[0]}function Ye(e,t){let n=K(e,0);if(!n||n.unknown)throw O(`webm`,`malformed block`);if(n.value!==t.number)return 0;let r=n.length+2,i=e[r];if(i===void 0)throw O(`webm`,`truncated block`);r+=1;let a=i>>1&3,o=[];if(a===0)o.push(e.length-r);else{let t=e[r];if(t===void 0)throw O(`webm`,`truncated block`);let n=t+1;if(r+=1,a===1)for(let t=0;t<n-1;t+=1){let t=0;for(;;){let n=e[r];if(n===void 0)throw O(`webm`,`truncated lacing`);if(r+=1,t+=n,n<255)break}o.push(t)}else if(a===3){let t=K(e,r);if(!t||t.unknown)throw O(`webm`,`malformed lacing`);r+=t.length,o.push(t.value);for(let t=1;t<n-1;t+=1){let n=K(e,r);if(!n||n.unknown)throw O(`webm`,`malformed lacing`);r+=n.length;let i=2**(7*n.length-1)-1;o.push(o[t-1]+n.value-i)}}let i=e.length-r;if(a===2){if(i%n!==0)throw O(`webm`,`fixed lacing doesn't divide the block`);for(let e=0;e<n;e+=1)o.push(i/n)}else{let e=o.reduce((e,t)=>e+t,0);o.push(i-e)}}if(o.some(e=>e<0)||r+o.reduce((e,t)=>e+t,0)>e.length)throw O(`webm`,`lacing exceeds the block`);let s=0;for(let n of o)s+=t.codec.frameSamples(e.subarray(r,r+Math.min(n,16)),n),r+=n;return s}async function Xe(e){let t=a(e),n=await q(t,0);if(!n||n.id!==W||n.size===void 0)throw O(`webm`,`missing EBML header`);let r=J(await t.bytes(n.body,n.size)).find(e=>e.id===17026),i=r?String.fromCharCode(...r.data).replace(/\\0+$/,``):``;if(i!==`webm`&&i!==`matroska`)throw G(`document type ${i||`missing`}`);let o=await q(t,n.body+n.size);if(!o||o.id!==408125543)throw O(`webm`,`missing Segment`);let s=Math.min(t.size,o.body+(o.size??t.size)),c,l=1e6,u,d=0,f=0,p,m=o.body;for(;m<s;){let e=await q(t,m);if(!e)throw O(`webm`,`malformed element`);if(p!==void 0&&(m>=p||We.has(e.id))&&(p=void 0),p===void 0){if(e.id===W)throw G(`several segments`);if(e.id===Ue){if(!c)throw O(`webm`,`clusters before the tracks`);if(p=e.size===void 0?1/0:e.body+e.size,p!==1/0&&p>s)throw O(`webm`,`element exceeds its parent`);m=e.body;continue}if(e.size===void 0)throw O(`webm`,`unknown size outside a Segment or Cluster`);let n=e.body+e.size;if(n>s)throw O(`webm`,`element exceeds its parent`);if(e.id===Ve){let n=J(await t.bytes(e.body,e.size)),r=n.find(e=>e.id===2807729),i=n.find(e=>e.id===17545);r&&(l=Y(r.data)),i&&(u=Ke(i.data))}else if(e.id===He){if(c)throw G(`several Tracks elements`);c=Je(await t.bytes(e.body,e.size))}m=n;continue}if(e.size===void 0)throw O(`webm`,`unknown size inside a Cluster`);let n=e.body+e.size;if(n>Math.min(p,s))throw O(`webm`,`element exceeds its parent`);let r=c;if(e.id===163)d+=Ye(await t.bytes(e.body,e.size),r),f+=1;else if(e.id===160)for(let n of J(await t.bytes(e.body,e.size)))n.id===161&&(d+=Ye(n.data,r),f+=1);m=n}if(!c)throw O(`webm`,`missing Tracks`);if(f===0||d===0)throw O(`webm`,`no audio blocks`);let{codec:h}=c,g=d;if(u!==void 0){if(!Number.isFinite(u)||u<0)throw O(`webm`,`Duration out of range`);if(g=Math.round(u*l/1e9*h.sampleRate),g>d)throw O(`webm`,`the Duration claims more than the blocks carry`)}return{container:`webm`,codec:h.codec,sampleRate:h.sampleRate,channels:h.channels,frameBound:d,expectedFrames:g,frameTolerance:h.tolerance}}function X(e,t){return new D(`UNSUPPORTED_FORMAT`,`Unsupported MP4: ${e}.`,{details:t===void 0?{container:`mp4`,reason:e}:{container:`mp4`,codec:t,reason:e}})}var Ze=class{boxes=0;reader;constructor(e){this.reader=e}async u8(e){let t=await this.reader.bytes(e,1);if(t.length<1)throw O(`mp4`,`truncated box`);return t[0]}async view(e,t){let n=await this.reader.bytes(e,t);if(n.length<t)throw O(`mp4`,`truncated box`);return new DataView(n.buffer,n.byteOffset,n.byteLength)}async children(e,t,n=!1){let r=[],i=e;for(;i+8<=t;){if(this.boxes+=1,this.boxes>1e5)throw O(`mp4`,`too many boxes`);let e=await this.view(i,8),a=e.getUint32(0),o=String.fromCharCode(e.getUint8(4),e.getUint8(5),e.getUint8(6),e.getUint8(7)),s=8;if(a===1){let e=await this.view(i+8,8),t=e.getUint32(0);if(t>=2**21)throw O(`mp4`,`box size out of range`);a=t*2**32+e.getUint32(4),s=16}else if(a===0){if(!n)throw O(`mp4`,`open-ended box inside another`);a=t-i}if(a<s||i+a>t)throw O(`mp4`,`box exceeds its parent`);r.push({type:o,body:i+s,end:i+a}),i+=a}return r}async child(e,t){return(await this.children(e.body,e.end)).find(e=>e.type===t)}async need(e,t){let n=await this.child(e,t);if(!n)throw O(`mp4`,`missing ${t} box`);return n}};async function Qe(e,t){let n=0;for(let r=0;r<4;r+=1){let i=await e.u8(t+r);if(n=n*128+(i&127),!(i&128))return[n,r+1]}throw O(`mp4`,`malformed descriptor length`)}async function $e(e,t){let n=t.body+4,r=async r=>{if(await e.u8(n)!==r)throw X(`unexpected ES descriptor`);let[i,a]=await Qe(e,n+1);if(n+=1+a,n+i>t.end)throw O(`mp4`,`descriptor exceeds its box`)};await r(3);let i=await e.u8(n+2);n+=3,i&128&&(n+=2),i&64&&(n+=1+await e.u8(n)),i&32&&(n+=2),await r(4);let a=await e.u8(n);if(![64,102,103,104].includes(a))throw X(`object type ${a}`,a===107||a===105?`mp3`:`unknown`);return n+=13,await r(5),P(await e.reader.bytes(n,Math.min(5,t.end-n)),`mp4`)}async function et(e){let t=a(e),n=new Ze(t),r=await n.children(0,t.size,!0);if(r.some(e=>e.type===`moof`))throw X(`fragmented MP4`);let i=r.find(e=>e.type===`moov`);if(!i)throw O(`mp4`,`missing moov box`);let o=[];for(let e of(await n.children(i.body,i.end)).filter(e=>e.type===`trak`)){let t=await n.child(e,`mdia`),r=t&&await n.child(t,`hdlr`);t&&r&&(await n.view(r.body+8,4)).getUint32(0)===1936684398&&o.push({trak:e,mdia:t})}if(o.length===0)throw O(`mp4`,`no audio track`);if(o.length>1)throw X(`several audio tracks`);let{trak:s,mdia:c}=o[0],l=await n.need(c,`mdhd`),u=await n.u8(l.body),d=await n.view(l.body+4,u===1?28:16),f=d.getUint32(u===1?16:8),p=u===1?d.getUint32(20)*2**32+d.getUint32(24):d.getUint32(12);if(f===0)throw O(`mp4`,`timescale is zero`);let m=await n.need(await n.need(c,`minf`),`stbl`),h=await n.need(m,`stsd`),[g]=await n.children(h.body+8,h.end);if(!g)throw O(`mp4`,`empty sample description`);let _=await n.view(g.body,28),v=_.getUint16(8);if(v>1)throw X(`sound sample entry version 2`);let y=_.getUint16(16),ee=_.getUint32(24)>>>16,b=g.body+28+(v===1?16:0),x,S,C,w;if(g.type===`mp4a`){let e=(await n.children(b,g.end)).find(e=>e.type===`esds`);if(!e)throw O(`mp4`,`missing esds box`);let{coreRate:t,channelConfiguration:r}=await $e(n,e);x=`aac`,S=I(t),C=F(r||y),w=1024*Math.ceil(S/t)}else if(g.type===`alac`){let e=(await n.children(b,g.end)).find(e=>e.type===`alac`);if(!e)throw O(`mp4`,`missing ALAC configuration`);let t=await n.view(e.body+4,24);if(x=`alac`,w=t.getUint32(0),C=t.getUint8(9),S=t.getUint32(20)||ee,w===0||w>1<<20)throw O(`mp4`,`ALAC frame length out of range`);if(C===0||S===0)throw O(`mp4`,`ALAC format out of range`)}else throw X(`codec ${g.type}`,g.type);await tt(n,i,s,{timescale:f,duration:p,decodeRate:S,tolerance:2*w});let T=await nt(n,m,t.size);if(T===0)throw O(`mp4`,`no audio samples`);let E=T*w,D=p===0?E:Math.round(p*S/f);if(D>E)throw O(`mp4`,`the duration claims more than the samples carry`);return{container:`mp4`,codec:x,sampleRate:S,channels:C,frameBound:E,expectedFrames:D,frameTolerance:2*w}}async function tt(e,t,n,r){let i=(await e.children(n.body,n.end)).filter(e=>e.type===`edts`);if(i.length===0)return;if(i.length>1)throw X(`several edit lists`);let a=(await e.children(i[0].body,i[0].end)).filter(e=>e.type===`elst`);if(a.length===0)return;if(a.length>1)throw X(`several edit lists`);let o=a[0],s=await e.need(t,`mvhd`),c=await e.u8(s.body),l=(await e.view(s.body+(c===1?20:12),4)).getUint32(0);if(l===0)throw O(`mp4`,`movie timescale is zero`);let u=await e.u8(o.body),d=(await e.view(o.body+4,4)).getUint32(0),f=u===1?20:12;if(o.body+8+d*f>o.end)throw O(`mp4`,`edit list exceeds its box`);if(d>2)throw X(`edit list with more than two edits`);let p=!1;for(let t=0;t<d;t+=1){let n=await e.view(o.body+8+t*f,f),i=u===1?n.getUint32(0)*2**32+n.getUint32(4):n.getUint32(0),a=u===1?n.getInt32(8)*2**32+n.getUint32(12):n.getInt32(4),s=n.getInt16(u===1?16:8),c=n.getUint16(u===1?18:10);if(a===-1){if(p||t>0)throw X(`edit list with an empty edit after another edit`);if(i*r.decodeRate/l>r.tolerance)throw X(`edit list with a long empty edit`)}else{if(p)throw X(`edit list with several media edits`);if(p=!0,s!==1||c!==0)throw X(`edit list with a media rate other than 1`);if(a<0||r.duration===0||a+Math.ceil(i*r.timescale/l)>r.duration)throw X(`edit list beyond the media`)}}}async function nt(e,t,n){let r=await e.child(t,`stsz`);if(!r)throw await e.child(t,`stz2`)?X(`compact sample sizes`):O(`mp4`,`missing stsz box`);let i=await e.view(r.body+4,8),a=i.getUint32(0),o=i.getUint32(4);if(a===0&&r.body+12+o*4>r.end)throw O(`mp4`,`stsz table exceeds its box`);let s=await e.need(t,`stsc`),c=(await e.view(s.body+4,4)).getUint32(0);if(s.body+8+c*12>s.end)throw O(`mp4`,`stsc table exceeds its box`);let l=await e.child(t,`stco`)??await e.child(t,`co64`);if(!l)throw O(`mp4`,`missing chunk offsets`);let u=l.type===`co64`,d=(await e.view(l.body+4,4)).getUint32(0);if(l.body+8+d*(u?8:4)>l.end)throw O(`mp4`,`chunk offsets exceed their box`);let f=0,p=0,m=0;for(let t=1;t<=d;t+=1){for(;p<c;){let n=await e.view(s.body+8+p*12,12);if(n.getUint32(0)>t)break;m=n.getUint32(4),p+=1}let i=await e.view(l.body+8+(t-1)*(u?8:4),u?8:4),d=u?i.getUint32(0)*2**32+i.getUint32(4):i.getUint32(0);for(let t=0;t<m;t+=1){if(f>=o)throw O(`mp4`,`the sample tables disagree`);let t=a===0?(await e.view(r.body+12+f*4,4)).getUint32(0):a;if(d+t>n)throw O(`mp4`,`a sample lies outside the file`);d+=t,f+=1}}if(f!==o)throw O(`mp4`,`the sample tables disagree`);return o}const rt={1:[44100,48e3,32e3],2:[22050,24e3,16e3],2.5:[11025,12e3,8e3]},it={\"1-1\":[0,32,64,96,128,160,192,224,256,288,320,352,384,416,448],\"1-2\":[0,32,48,56,64,80,96,112,128,160,192,224,256,320,384],\"1-3\":[0,32,40,48,56,64,80,96,112,128,160,192,224,256,320],\"2-1\":[0,32,48,56,64,80,96,112,128,144,160,176,192,224,256],\"2-2\":[0,8,16,24,32,40,48,56,64,80,96,112,128,144,160],\"2-3\":[0,8,16,24,32,40,48,56,64,80,96,112,128,144,160]};function Z(e,t){let n=e[t],r=e[t+1],i=e[t+2],a=e[t+3];if(n!==255||r===void 0||i===void 0||a===void 0||(r&224)!=224)return;let o=r>>3&3,s=r>>1&3,c=i>>4,l=i>>2&3;if(o===1||s===0||c===0||c===15||l===3||(a&3)==2)return;let u=o===3?1:o===2?2:2.5,d=4-s,f=rt[u]?.[l],p=it[`${u===1?1:2}-${d}`]?.[c]*1e3,m=i>>1&1,h=a>>6==3?1:2,g,_;if(d===1?(g=384,_=(Math.floor(12*p/f)+m)*4):d===2||u===1?(g=1152,_=Math.floor(144*p/f)+m):(g=576,_=Math.floor(72*p/f)+m),!(_<4))return{version:u,layer:d,sampleRate:f,channels:h,samplesPerFrame:g,frameLength:_,protected:!(r&1)}}function at(e,t){let n=new DataView(e.buffer,e.byteOffset,e.byteLength),r=t=>t+4<=e.length?String.fromCharCode(...e.subarray(t,t+4)):``,i=t.version===1?t.channels===1?17:32:t.channels===1?9:17,a=4+(t.protected?2:0)+i,o=r(a);if(o===`Xing`||o===`Info`){if(a+8>e.length)return;let t=n.getUint32(a+4);a+=8;let i;if(t&1){if(a+4>e.length)return;i=n.getUint32(a),a+=4}if(t&2&&(a+=4),t&4&&(a+=100),t&8&&(a+=4),a+24<=e.length&&r(a)===`LAME`){let t=e[a+21]*65536+e[a+22]*256+e[a+23];return{...i===void 0?{}:{frames:i},delay:t>>12,padding:t&4095}}return i===void 0?{}:{frames:i}}if(r(36)===`VBRI`&&54<=e.length)return{delay:n.getUint16(42),frames:n.getUint32(50)}}const ot=65536,st=(e,t)=>e.version===t.version&&e.layer===t.layer&&e.sampleRate===t.sampleRate;async function ct(e,t){return N(a(e),t,ot,Z,e=>e.frameLength,st)}function lt(e,t,n){let r=e.sampleRate<t?Math.ceil(t/e.sampleRate):1;return e.samplesPerFrame*r*Math.ceil(e.channels/n)}async function ut(e,t){let n=a(e),r=await N(n,t,ot,Z,e=>e.frameLength,st);if(!r)throw O(`mp3`,`no frames`);let{sampleRate:i,channels:o,samplesPerFrame:s}=r.first,c=at(await n.bytes(r.offset,r.first.frameLength),r.first),l=0,u=0;if(await ve(n,r.offset,4,Z,e=>e.frameLength,(e,t)=>{l+=lt(e,i,o),t&&(u+=1)}),l===0)throw O(`mp3`,`no frames`);let d=c?.delay??0,f=c?.padding??0,p=u*s;if(c?.frames!==void 0){let e=c.frames*s;if(e>l)throw O(`mp3`,`the tag claims more than the frames carry`);p=Math.max(0,e-d-f)}return{container:`mp3`,codec:`mp3`,sampleRate:i,channels:o,frameBound:l,expectedFrames:Math.min(p,l),frameTolerance:2*s+d+f}}function dt(e,t){return new D(`UNSUPPORTED_FORMAT`,`This container or codec isn't supported.`,{details:t===void 0?{container:e}:{container:e,codec:t}})}async function ft(e){let t=a(e),n=await t.bytes(0,64),r=(e,t)=>String.fromCharCode(...n.subarray(e,t)),i=r(0,4),o=r(8,12);if((i===`RIFF`||i===`RF64`)&&o===`WAVE`||i===`FORM`&&(o===`AIFF`||o===`AIFC`))return he(e);if(i===`fLaC`)return{probe:await ke(e)};if(n[0]===26&&n[1]===69&&n[2]===223&&n[3]===163)return{probe:await Xe(e)};if([`ftyp`,`moov`,`mdat`,`free`,`skip`,`wide`].includes(r(4,8)))return{probe:await et(e)};let s=Ee(n);if(s>0){let n=await t.bytes(s,4);if(String.fromCharCode(...n)===`fLaC`)return{probe:await ke(e)}}if(i===`OggS`){let r=n[26]??0,i=await t.bytes(27+r,8);if(Ae(i))return{probe:await je(e)};if(U(i))return{probe:await Ie(e)};if(Re(i))return{probe:await Be(e)};throw dt(`ogg`)}let[c,l]=await Promise.all([ct(e,s),xe(e,s)]);if(c&&(!l||c.offset<=l.offset))return{probe:await ut(e,s)};if(l)return{probe:await Se(e,s)};throw dt(`unknown`)}function pt(e){return 10**(e/20)}function mt(e,t){return e===`equalPower`?Math.sin(t*Math.PI/2):t}function ht(e,t){let n=e.end-e.start,r=pt(e.gainDb),{fadeIn:i,fadeOut:a}=e;i.frames>0&&t<i.frames&&(r*=mt(i.curve,t/i.frames));let o=n-1-t;return a.frames>0&&o<a.frames&&(r*=mt(a.curve,Math.max(0,o)/a.frames)),r}function gt(e,t){let n=Array.from({length:t},()=>Array(e).fill(0)),r=(e,t,r)=>{n[e][t]=r},i=Math.SQRT1_2;switch(`${e}>${t}`){case`1>2`:r(0,0,1),r(1,0,1);break;case`1>4`:r(0,0,1),r(1,0,1);break;case`1>6`:r(2,0,1);break;case`2>4`:case`2>6`:r(0,0,1),r(1,1,1);break;case`4>6`:r(0,0,1),r(1,1,1),r(4,2,1),r(5,3,1);break;case`2>1`:r(0,0,.5),r(0,1,.5);break;case`4>1`:for(let e=0;e<4;e+=1)r(0,e,.25);break;case`6>1`:r(0,0,i),r(0,1,i),r(0,2,1),r(0,4,.5),r(0,5,.5);break;case`4>2`:r(0,0,.5),r(0,2,.5),r(1,1,.5),r(1,3,.5);break;case`6>2`:r(0,0,1),r(0,2,i),r(0,4,i),r(1,1,1),r(1,2,i),r(1,5,i);break;case`6>4`:r(0,0,1),r(0,2,i),r(1,1,1),r(1,2,i),r(2,4,1),r(3,5,1);break;default:for(let n=0;n<Math.min(e,t);n+=1)r(n,n,1)}return n}const Q={pcm16:2,pcm24:3,float32:4},_t=[0,0,0,0,16,0,128,0,0,170,0,56,155,113],vt={1:4,2:3,4:51,6:63},$=4294967295,yt=[[`title`,`INAM`],[`artist`,`IART`],[`album`,`IPRD`],[`year`,`ICRD`],[`comment`,`ICMT`]];function bt(e){return e.frames*e.channels*Q[e.sampleFormat]}var xt=class{bytes;view;at=0;constructor(e){this.bytes=new Uint8Array(e),this.view=new DataView(this.bytes.buffer)}text(e){for(let t=0;t<e.length;t+=1)this.bytes[this.at+t]=e.charCodeAt(t);this.at+=e.length}u16(e){this.view.setUint16(this.at,e,!0),this.at+=2}u32(e){this.view.setUint32(this.at,e,!0),this.at+=4}u64(e){this.u32(e%2**32),this.u32(Math.floor(e/2**32))}raw(e){this.bytes.set(e,this.at),this.at+=e.length}};function St(e){let t=new TextEncoder,n=yt.flatMap(([n,r])=>{let i=e[n];return i===``?[]:[{id:r,value:t.encode(`${i}\\0`)}]});if(n.length===0)return;let r=new xt(4+n.reduce((e,{value:t})=>e+8+t.length+t.length%2,0));r.text(`INFO`);for(let{id:e,value:t}of n)r.text(e),r.u32(t.length),r.raw(t),t.length%2==1&&(r.at+=1);return r.bytes}function Ct(e){let{sampleRate:t,channels:n,frames:r,sampleFormat:i,metadata:a}=e,o=Q[i],s=i===`float32`,c=n>2||o>2,l=c?40:s?18:16,u=St(a),d=bt(e),f=d%2,p=8+l+(s?12:0)+(u?8+u.length:0)+8+d+f,m=4+p,h=m>$||d>$||r>$,g=new xt(12+(h?36:0)+p-d-f);g.text(h?`RF64`:`RIFF`),g.u32(h?$:m),g.text(`WAVE`),h&&(g.text(`ds64`),g.u32(28),g.u64(m+36),g.u64(d),g.u64(r),g.u32(0)),g.text(`fmt `),g.u32(l);let _=s?3:1;if(g.u16(c?65534:_),g.u16(n),g.u32(t),g.u32(t*n*o),g.u16(n*o),g.u16(o*8),c){g.u16(22),g.u16(o*8),g.u32(vt[n]??0),g.u16(_);for(let e of _t)g.bytes[g.at++]=e}else s&&g.u16(0);return s&&(g.text(`fact`),g.u32(4),g.u32(h?$:r)),u&&(g.text(`LIST`),g.u32(u.length),g.raw(u)),g.text(`data`),g.u32(h?$:d),g.bytes}function wt(e){return e<0?-Math.round(-e):Math.round(e)}function Tt(e,t){let n=Number.isFinite(e)?Math.max(-1,Math.min(1,e)):0;if(t===`float32`)return Math.fround(n);let r=t===`pcm16`?32768:8388608;return Math.min(r-1,wt(n*r))+0}function Et(e,t,n){let r=Q[n],i=new Uint8Array(t*e.length*r),a=new DataView(i.buffer),o=0;for(let i=0;i<t;i+=1)for(let t of e){let e=Tt(t[i]??0,n);n===`float32`?a.setFloat32(o,e,!0):n===`pcm16`?a.setInt16(o,e,!0):(a.setUint8(o,e&255),a.setUint8(o+1,e>>8&255),a.setUint8(o+2,e>>16&255)),o+=r}return i}function Dt(e){let{channels:t,frames:n,sampleFormat:r,segments:i}=e,a=Array.from({length:t},()=>new Float32Array(n)),o=new Float64Array(t);for(let e of i){let n=gt(e.samples.length,t);for(let r=0;r<e.frames;r+=1){let i=ht(e.clip,e.within+r);o.fill(0);for(let i=0;i<e.samples.length;i+=1){let a=e.samples[i][r];for(let e=0;e<t;e+=1)o[e]=o[e]+n[e][i]*a}for(let n=0;n<t;n+=1)a[n][e.at+r]=o[n]*i}}return Et(a,n,r)}function Ot(e){E({probe:({file:e})=>ft(e),async readBlock({file:e,layout:t,start:n,frames:r,bucket:i}){let a=await ge(e,t,n,r);return{channels:a,..._e(a,i)}},peaks:({channels:e,bucket:t})=>_e(e,t),wavHeader:e=>Ct(e),renderBlock:e=>Dt(e)},{...e,packageVersion:`0.4.0`})}Ot();\n";
|
|
3
|
-
var blob = typeof self !== "undefined" && self.Blob && new Blob(["URL.revokeObjectURL(import.meta.url);", jsContent], { type: "text/javascript;charset=utf-8" });
|
|
4
|
-
function WorkerWrapper(options) {
|
|
5
|
-
let objURL;
|
|
6
|
-
try {
|
|
7
|
-
objURL = blob && (self.URL || self.webkitURL).createObjectURL(blob);
|
|
8
|
-
if (!objURL) throw "";
|
|
9
|
-
const worker = new Worker(objURL, {
|
|
10
|
-
type: "module",
|
|
11
|
-
name: options?.name
|
|
12
|
-
});
|
|
13
|
-
worker.addEventListener("error", () => {
|
|
14
|
-
(self.URL || self.webkitURL).revokeObjectURL(objURL);
|
|
15
|
-
});
|
|
16
|
-
return worker;
|
|
17
|
-
} catch (e) {
|
|
18
|
-
return new Worker("data:text/javascript;charset=utf-8," + encodeURIComponent(jsContent), {
|
|
19
|
-
type: "module",
|
|
20
|
-
name: options?.name
|
|
21
|
-
});
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
// src/adapters/audio-worker/inline-worker.ts
|
|
25
|
-
function createInlineWorker() {
|
|
26
|
-
return new WorkerWrapper({ name: "hm-audio" });
|
|
27
|
-
}
|
|
28
|
-
export { createInlineWorker };
|
|
29
|
-
|
|
30
|
-
//# sourceMappingURL=inline-worker-BB2jwrIT.js.map
|