audio 2.0.0 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +30 -17
- package/audio.d.ts +13 -1
- package/bin/cli.js +5 -6
- package/core.js +33 -5
- package/dist/audio.all.js +95 -14
- package/dist/audio.js +95 -14
- package/dist/audio.min.js +1 -1
- package/fn/play.js +18 -7
- package/package.json +1 -5
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# <img src="logo.svg" width="20" height="20" alt="audio"> audio [](https://github.com/audiojs/audio/actions/workflows/test.yml) [](https://npmjs.org/package/audio)
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
_Audio in JavaScript_
|
|
4
4
|
|
|
5
5
|
```js
|
|
6
6
|
audio('raw-take.wav')
|
|
@@ -12,23 +12,26 @@ audio('raw-take.wav')
|
|
|
12
12
|
|
|
13
13
|
<!-- <img src="preview.svg?v=1" alt="Audiojs demo" width="540"> -->
|
|
14
14
|
|
|
15
|
-
* **
|
|
16
|
-
* **Streaming** —
|
|
17
|
-
* **Immutable** —
|
|
18
|
-
* **
|
|
19
|
-
* **Analysis** —
|
|
20
|
-
* **Modular** – pluggable ops
|
|
21
|
-
* **CLI** —
|
|
22
|
-
* **Isomorphic** —
|
|
23
|
-
* **Audio-first** –
|
|
15
|
+
* **Any Format** — fast wasm codecs, no ffmpeg.
|
|
16
|
+
* **Streaming** — playback during decode.
|
|
17
|
+
* **Immutable** — safe edits, infinite undo/redo.
|
|
18
|
+
* **Page Cache** — open 10Gb+ files.
|
|
19
|
+
* **Analysis** — loudness, spectrum, and more.
|
|
20
|
+
* **Modular** – pluggable ops, tree-shakable.
|
|
21
|
+
* **CLI** — playback, unix pipes, tab completion.
|
|
22
|
+
* **Isomorphic** — node / browser.
|
|
23
|
+
* **Audio-first** – dB, Hz, LUFS, not bytes and indices.
|
|
24
24
|
|
|
25
25
|
<!--
|
|
26
26
|
* [Architecture](docs/architecture.md) – stream-first design, pages & blocks, non-destructive editing, plan compilation
|
|
27
27
|
* [Plugins](docs/plugins.md) – custom ops, stats, descriptors (process, plan, resolve, call), persistent ctx
|
|
28
28
|
-->
|
|
29
29
|
|
|
30
|
-
|
|
30
|
+
<div align="center">
|
|
31
31
|
|
|
32
|
+
#### [Quick Start](#quick-start) [Recipes](#recipes) [API](#api) [CLI](#cli) [Plugins](docs/plugins.md) [Architecture](docs/architecture.md) [FAQ](#faq) [Ecosystem](#ecosystem)
|
|
33
|
+
|
|
34
|
+
</div>
|
|
32
35
|
|
|
33
36
|
## Quick Start
|
|
34
37
|
|
|
@@ -296,11 +299,15 @@ a.sampleRate // sample rate
|
|
|
296
299
|
a.length // total samples per channel
|
|
297
300
|
|
|
298
301
|
// playback
|
|
299
|
-
a.currentTime // position in seconds
|
|
302
|
+
a.currentTime // position in seconds (smooth interpolation during playback)
|
|
300
303
|
a.playing // true during playback
|
|
301
304
|
a.paused // true when paused
|
|
302
|
-
a.volume =
|
|
305
|
+
a.volume = 0.5 // 0..1 linear (settable)
|
|
306
|
+
a.muted = true // mute gate (independent of volume)
|
|
303
307
|
a.loop = true // on/off (settable)
|
|
308
|
+
a.ended // true when playback ended naturally (not via stop)
|
|
309
|
+
a.seeking // true during a seek operation
|
|
310
|
+
a.played // promise, resolves when playback starts
|
|
304
311
|
a.recording // true during mic recording
|
|
305
312
|
|
|
306
313
|
// state
|
|
@@ -412,13 +419,15 @@ src.stop() // finalize
|
|
|
412
419
|
|
|
413
420
|
Live playback with dB volume, seeking, looping. Mic recording via `audio-mic`.
|
|
414
421
|
|
|
415
|
-
* **`.play(opts?)`** – start playback. `{ at, duration, volume, loop }`.
|
|
422
|
+
* **`.play(opts?)`** – start playback. `{ at, duration, volume, loop }`. `.played` promise resolves when output starts.
|
|
416
423
|
* **`.pause()`**, **`.resume()`**, **`.seek(t)`**, **`.stop()`** – playback control.
|
|
417
424
|
* **`.record(opts?)`** – mic recording. `{ deviceId, sampleRate, channels }`.
|
|
418
425
|
|
|
419
426
|
```js
|
|
420
427
|
a.play({ at: 30, duration: 10 }) // play 30s–40s
|
|
421
|
-
a.
|
|
428
|
+
await a.played // wait for output to start
|
|
429
|
+
a.volume = 0.5; a.loop = true // live adjustments
|
|
430
|
+
a.muted = true // mute without changing volume
|
|
422
431
|
a.pause(); a.seek(60); a.resume() // jump to 1:00
|
|
423
432
|
a.stop() // end playback or recording
|
|
424
433
|
|
|
@@ -462,6 +471,9 @@ Events, lifecycle, undo/redo, serialization.
|
|
|
462
471
|
* `'change'` – any edit or undo.
|
|
463
472
|
* `'metadata'` – stream header decoded. Payload: `{ sampleRate, channels }`.
|
|
464
473
|
* `'timeupdate'` – playback position. Payload: `currentTime`.
|
|
474
|
+
* `'play'` – playback started or resumed.
|
|
475
|
+
* `'pause'` – playback paused.
|
|
476
|
+
* `'volumechange'` – volume or muted changed.
|
|
465
477
|
* `'ended'` – playback finished (not on loop).
|
|
466
478
|
* `'progress'` – during save/encode. Payload: `{ offset, total }` in seconds.
|
|
467
479
|
* **`.dispose()`** – release resources. Supports `using` for auto-dispose.
|
|
@@ -607,7 +619,7 @@ audio --completions fish | source # fish
|
|
|
607
619
|
|
|
608
620
|
<dl>
|
|
609
621
|
<dt>How is this different from Web Audio API?</dt>
|
|
610
|
-
<dd>Web Audio API is a real-time graph for playback and synthesis. This is for
|
|
622
|
+
<dd>Web Audio API is a real-time audio graph for playback and synthesis. This is for work on audio files specifically. For Web Audio API in Node, see <a href="https://github.com/audiojs/web-audio-api">web-audio-api</a>.</dd>
|
|
611
623
|
|
|
612
624
|
<dt>What formats are supported?</dt>
|
|
613
625
|
<dd>Decode: WAV, MP3, FLAC, OGG Vorbis, Opus, AAC, AIFF, CAF, WebM, AMR, WMA, QOA via <a href="https://github.com/audiojs/audio-decode">audio-decode</a>. Encode: WAV, MP3, FLAC, Opus, OGG, AIFF via <a href="https://github.com/audiojs/audio-encode">audio-encode</a>. Codecs are WASM-based, lazy-loaded on first use.</dd>
|
|
@@ -640,7 +652,8 @@ audio --completions fish | source # fish
|
|
|
640
652
|
* [audio-decode](https://github.com/audiojs/audio-decode) – codec decoding (13+ formats)
|
|
641
653
|
* [encode-audio](https://github.com/audiojs/audio-encode) – codec encoding
|
|
642
654
|
* [audio-filter](https://github.com/audiojs/audio-filter) – filters (weighting, EQ, auditory)
|
|
643
|
-
* [audio-speaker](https://github.com/audiojs/audio-speaker) – audio output
|
|
655
|
+
* [audio-speaker](https://github.com/audiojs/audio-speaker) – audio output
|
|
656
|
+
* [audio-mic](https://github.com/audiojs/audio-mic) – audio input
|
|
644
657
|
* [audio-type](https://github.com/nickolanack/audio-type) – format detection
|
|
645
658
|
* [pcm-convert](https://github.com/nickolanack/pcm-convert) – PCM format conversion
|
|
646
659
|
|
package/audio.d.ts
CHANGED
|
@@ -37,10 +37,18 @@ export interface AudioInstance {
|
|
|
37
37
|
playing: boolean
|
|
38
38
|
/** True when paused */
|
|
39
39
|
paused: boolean
|
|
40
|
-
/** Playback volume
|
|
40
|
+
/** Playback volume, 0 (silent) to 1 (full). Clamped. */
|
|
41
41
|
volume: number
|
|
42
|
+
/** Whether playback is muted (independent of volume) */
|
|
43
|
+
muted: boolean
|
|
42
44
|
/** Whether playback loops */
|
|
43
45
|
loop: boolean
|
|
46
|
+
/** True when playback ended naturally (not via stop) */
|
|
47
|
+
ended: boolean
|
|
48
|
+
/** True during a seek operation */
|
|
49
|
+
seeking: boolean
|
|
50
|
+
/** Promise — resolves when playback actually starts (speaker opens), rejects on failure */
|
|
51
|
+
played: Promise<void>
|
|
44
52
|
/** Current playback block for visualization */
|
|
45
53
|
block: Float32Array | null
|
|
46
54
|
|
|
@@ -52,6 +60,10 @@ export interface AudioInstance {
|
|
|
52
60
|
on(event: 'progress', fn: (event: { offset: number, total: number }) => void): this
|
|
53
61
|
on(event: 'timeupdate', fn: (time: number) => void): this
|
|
54
62
|
on(event: 'ended', fn: () => void): this
|
|
63
|
+
on(event: 'play', fn: () => void): this
|
|
64
|
+
on(event: 'pause', fn: () => void): this
|
|
65
|
+
on(event: 'volumechange', fn: () => void): this
|
|
66
|
+
on(event: 'error', fn: (err: Error) => void): this
|
|
55
67
|
on(event: string, fn: (...args: any[]) => void): this
|
|
56
68
|
/** Unsubscribe from instance event */
|
|
57
69
|
off(event: string, fn: (...args: any[]) => void): this
|
package/bin/cli.js
CHANGED
|
@@ -384,9 +384,8 @@ async function playback(p, totalSec, decodedSec, a, src) {
|
|
|
384
384
|
}
|
|
385
385
|
|
|
386
386
|
const VOL = '▁▂▃▄▅▆▇'
|
|
387
|
-
let volBar =
|
|
388
|
-
let n = Math.
|
|
389
|
-
n = Math.max(1, Math.min(7, n))
|
|
387
|
+
let volBar = v => {
|
|
388
|
+
let n = Math.max(1, Math.min(7, Math.round(v * 7)))
|
|
390
389
|
let tail = 7 - n
|
|
391
390
|
return VOL.slice(0, n) + (tail ? DIM + '▁'.repeat(tail) + RST : '')
|
|
392
391
|
}
|
|
@@ -484,8 +483,8 @@ async function playback(p, totalSec, decodedSec, a, src) {
|
|
|
484
483
|
else if (k === '\x1b[1;2D' || k === '\x1b[1;5D' || k === '\x1bb') { let t = Math.max(0, p.currentTime - 60); p.seek(t); render(t) }
|
|
485
484
|
else if (k === '\x1b[C') { let t = Math.max(0, p.currentTime + 10); p.seek(t); render(t) }
|
|
486
485
|
else if (k === '\x1b[D') { let t = Math.max(0, p.currentTime - 10); p.seek(t); render(t) }
|
|
487
|
-
else if (k === '\x1b[A') { p.volume = Math.min(p.volume +
|
|
488
|
-
else if (k === '\x1b[B') { p.volume = Math.max(p.volume -
|
|
486
|
+
else if (k === '\x1b[A') { p.volume = Math.min(p.volume + 0.1, 1); render(p.currentTime) }
|
|
487
|
+
else if (k === '\x1b[B') { p.volume = Math.max(p.volume - 0.1, 0); render(p.currentTime) }
|
|
489
488
|
else if (k === 'l') { p.loop = !p.loop; render(p.currentTime) }
|
|
490
489
|
else if (k === 'q' || k === '\x03') p.stop()
|
|
491
490
|
})
|
|
@@ -961,7 +960,7 @@ Player controls:
|
|
|
961
960
|
space Pause / resume
|
|
962
961
|
←/→ Seek ±10s
|
|
963
962
|
⇧←/⇧→ Seek ±60s
|
|
964
|
-
↑/↓ Volume ±
|
|
963
|
+
↑/↓ Volume ±10%
|
|
965
964
|
l Toggle loop
|
|
966
965
|
q Quit
|
|
967
966
|
|
package/core.js
CHANGED
|
@@ -12,7 +12,7 @@ import encode from 'encode-audio'
|
|
|
12
12
|
import convert, { parse as parseFmt } from 'pcm-convert'
|
|
13
13
|
import parseDuration from 'parse-duration'
|
|
14
14
|
|
|
15
|
-
audio.version = '2.
|
|
15
|
+
audio.version = '2.1.0'
|
|
16
16
|
|
|
17
17
|
/** Parse time value: number passthrough, string via parse-duration or timecode. */
|
|
18
18
|
export function parseTime(v) {
|
|
@@ -234,8 +234,9 @@ function create(pages, sampleRate, ch, length, opts = {}, stats) {
|
|
|
234
234
|
len: length, // source sample length
|
|
235
235
|
waiters: null, // decode notify queue (null when not streaming)
|
|
236
236
|
ev: {}, // instance event listeners
|
|
237
|
+
ct: 0, ctStamp: 0, // currentTime wall-clock interpolation
|
|
238
|
+
vol: 1, muted: false, // volume 0..1 linear with change events
|
|
237
239
|
}
|
|
238
|
-
a.currentTime = 0
|
|
239
240
|
|
|
240
241
|
// History (edit pipeline)
|
|
241
242
|
a.edits = []
|
|
@@ -246,9 +247,34 @@ function create(pages, sampleRate, ch, length, opts = {}, stats) {
|
|
|
246
247
|
a._.lenC = a._.len; a._.lenV = 0
|
|
247
248
|
a._.chC = a._.ch; a._.chV = 0
|
|
248
249
|
|
|
249
|
-
// Playback
|
|
250
|
+
// Playback (getter/setter for interpolation & events)
|
|
251
|
+
Object.defineProperties(a, {
|
|
252
|
+
currentTime: {
|
|
253
|
+
get() {
|
|
254
|
+
if (this.playing && !this.paused) {
|
|
255
|
+
let t = this._.ct + (performance.now() - this._.ctStamp) / 1000
|
|
256
|
+
let d = this.duration
|
|
257
|
+
return d > 0 ? Math.min(t, d) : t
|
|
258
|
+
}
|
|
259
|
+
return this._.ct
|
|
260
|
+
},
|
|
261
|
+
set(v) { this._.ct = v; this._.ctStamp = performance.now() },
|
|
262
|
+
enumerable: true, configurable: true
|
|
263
|
+
},
|
|
264
|
+
volume: {
|
|
265
|
+
get() { return this._.vol },
|
|
266
|
+
set(v) { v = Math.max(0, Math.min(1, +v || 0)); if (this._.vol !== v) { this._.vol = v; emit(this, 'volumechange') } },
|
|
267
|
+
enumerable: true, configurable: true
|
|
268
|
+
},
|
|
269
|
+
muted: {
|
|
270
|
+
get() { return this._.muted },
|
|
271
|
+
set(v) { v = !!v; if (this._.muted !== v) { this._.muted = v; emit(this, 'volumechange') } },
|
|
272
|
+
enumerable: true, configurable: true
|
|
273
|
+
},
|
|
274
|
+
})
|
|
250
275
|
a.playing = false; a.paused = false
|
|
251
|
-
a.
|
|
276
|
+
a.ended = false; a.seeking = false
|
|
277
|
+
a.loop = false; a.block = null
|
|
252
278
|
|
|
253
279
|
// Cache
|
|
254
280
|
a._.lru = new Set()
|
|
@@ -322,7 +348,7 @@ fn.push = function(data, fmt) {
|
|
|
322
348
|
|
|
323
349
|
/** Stop recording and/or finalize pushable stream. Drain partial page, signal EOF to waiting streams. No-op on non-pushable. */
|
|
324
350
|
fn.stop = function() {
|
|
325
|
-
this.playing = false; this.paused = false
|
|
351
|
+
this.playing = false; this.paused = false; this.seeking = false
|
|
326
352
|
if (this._._wake) this._._wake()
|
|
327
353
|
if (this.recording) {
|
|
328
354
|
this.recording = false
|
|
@@ -366,6 +392,7 @@ fn.record = function(opts = {}) {
|
|
|
366
392
|
|
|
367
393
|
fn.seek = function(t) {
|
|
368
394
|
t = Math.max(0, t)
|
|
395
|
+
this.seeking = true
|
|
369
396
|
this.currentTime = t
|
|
370
397
|
if (this.cache) {
|
|
371
398
|
let page = Math.floor(t * this.sampleRate / audio.PAGE_SIZE)
|
|
@@ -375,6 +402,7 @@ fn.seek = function(t) {
|
|
|
375
402
|
})()
|
|
376
403
|
}
|
|
377
404
|
if (this.playing) { this._._seekTo = t; if (this._._wake) this._._wake() }
|
|
405
|
+
else this.seeking = false
|
|
378
406
|
return this
|
|
379
407
|
}
|
|
380
408
|
|
package/dist/audio.all.js
CHANGED
|
@@ -102546,7 +102546,7 @@ function parse2(str = "", format = "ms") {
|
|
|
102546
102546
|
}
|
|
102547
102547
|
|
|
102548
102548
|
// core.js
|
|
102549
|
-
audio.version = "2.
|
|
102549
|
+
audio.version = "2.1.0";
|
|
102550
102550
|
function parseTime(v) {
|
|
102551
102551
|
if (v == null) return v;
|
|
102552
102552
|
if (typeof v === "number") {
|
|
@@ -102776,10 +102776,15 @@ function create(pages, sampleRate3, ch, length2, opts = {}, stats) {
|
|
|
102776
102776
|
// source sample length
|
|
102777
102777
|
waiters: null,
|
|
102778
102778
|
// decode notify queue (null when not streaming)
|
|
102779
|
-
ev: {}
|
|
102779
|
+
ev: {},
|
|
102780
102780
|
// instance event listeners
|
|
102781
|
+
ct: 0,
|
|
102782
|
+
ctStamp: 0,
|
|
102783
|
+
// currentTime wall-clock interpolation
|
|
102784
|
+
vol: 1,
|
|
102785
|
+
muted: false
|
|
102786
|
+
// volume 0..1 linear with change events
|
|
102781
102787
|
};
|
|
102782
|
-
a2.currentTime = 0;
|
|
102783
102788
|
a2.edits = [];
|
|
102784
102789
|
a2.version = 0;
|
|
102785
102790
|
a2._.pcm = null;
|
|
@@ -102791,9 +102796,56 @@ function create(pages, sampleRate3, ch, length2, opts = {}, stats) {
|
|
|
102791
102796
|
a2._.lenV = 0;
|
|
102792
102797
|
a2._.chC = a2._.ch;
|
|
102793
102798
|
a2._.chV = 0;
|
|
102799
|
+
Object.defineProperties(a2, {
|
|
102800
|
+
currentTime: {
|
|
102801
|
+
get() {
|
|
102802
|
+
if (this.playing && !this.paused) {
|
|
102803
|
+
let t2 = this._.ct + (performance.now() - this._.ctStamp) / 1e3;
|
|
102804
|
+
let d2 = this.duration;
|
|
102805
|
+
return d2 > 0 ? Math.min(t2, d2) : t2;
|
|
102806
|
+
}
|
|
102807
|
+
return this._.ct;
|
|
102808
|
+
},
|
|
102809
|
+
set(v) {
|
|
102810
|
+
this._.ct = v;
|
|
102811
|
+
this._.ctStamp = performance.now();
|
|
102812
|
+
},
|
|
102813
|
+
enumerable: true,
|
|
102814
|
+
configurable: true
|
|
102815
|
+
},
|
|
102816
|
+
volume: {
|
|
102817
|
+
get() {
|
|
102818
|
+
return this._.vol;
|
|
102819
|
+
},
|
|
102820
|
+
set(v) {
|
|
102821
|
+
v = Math.max(0, Math.min(1, +v || 0));
|
|
102822
|
+
if (this._.vol !== v) {
|
|
102823
|
+
this._.vol = v;
|
|
102824
|
+
emit(this, "volumechange");
|
|
102825
|
+
}
|
|
102826
|
+
},
|
|
102827
|
+
enumerable: true,
|
|
102828
|
+
configurable: true
|
|
102829
|
+
},
|
|
102830
|
+
muted: {
|
|
102831
|
+
get() {
|
|
102832
|
+
return this._.muted;
|
|
102833
|
+
},
|
|
102834
|
+
set(v) {
|
|
102835
|
+
v = !!v;
|
|
102836
|
+
if (this._.muted !== v) {
|
|
102837
|
+
this._.muted = v;
|
|
102838
|
+
emit(this, "volumechange");
|
|
102839
|
+
}
|
|
102840
|
+
},
|
|
102841
|
+
enumerable: true,
|
|
102842
|
+
configurable: true
|
|
102843
|
+
}
|
|
102844
|
+
});
|
|
102794
102845
|
a2.playing = false;
|
|
102795
102846
|
a2.paused = false;
|
|
102796
|
-
a2.
|
|
102847
|
+
a2.ended = false;
|
|
102848
|
+
a2.seeking = false;
|
|
102797
102849
|
a2.loop = false;
|
|
102798
102850
|
a2.block = null;
|
|
102799
102851
|
a2._.lru = /* @__PURE__ */ new Set();
|
|
@@ -102867,6 +102919,7 @@ fn.push = function(data3, fmt3) {
|
|
|
102867
102919
|
fn.stop = function() {
|
|
102868
102920
|
this.playing = false;
|
|
102869
102921
|
this.paused = false;
|
|
102922
|
+
this.seeking = false;
|
|
102870
102923
|
if (this._._wake) this._._wake();
|
|
102871
102924
|
if (this.recording) {
|
|
102872
102925
|
this.recording = false;
|
|
@@ -102911,6 +102964,7 @@ fn.record = function(opts = {}) {
|
|
|
102911
102964
|
};
|
|
102912
102965
|
fn.seek = function(t2) {
|
|
102913
102966
|
t2 = Math.max(0, t2);
|
|
102967
|
+
this.seeking = true;
|
|
102914
102968
|
this.currentTime = t2;
|
|
102915
102969
|
if (this.cache) {
|
|
102916
102970
|
let page2 = Math.floor(t2 * this.sampleRate / audio.PAGE_SIZE);
|
|
@@ -102922,7 +102976,7 @@ fn.seek = function(t2) {
|
|
|
102922
102976
|
if (this.playing) {
|
|
102923
102977
|
this._._seekTo = t2;
|
|
102924
102978
|
if (this._._wake) this._._wake();
|
|
102925
|
-
}
|
|
102979
|
+
} else this.seeking = false;
|
|
102926
102980
|
return this;
|
|
102927
102981
|
};
|
|
102928
102982
|
fn.read = async function(opts) {
|
|
@@ -103387,10 +103441,10 @@ function buildPlan(a2) {
|
|
|
103387
103441
|
if (!op) throw new Error(`Unknown op: ${type}`);
|
|
103388
103442
|
if (op.resolve) {
|
|
103389
103443
|
let ctx = { ...extra, stats: a2._.srcStats || a2.stats, sampleRate: sr, channelCount: ch, channel: channel2, at, duration: duration2, totalDuration: planLen(segs) / sr };
|
|
103390
|
-
let
|
|
103391
|
-
if (
|
|
103392
|
-
if (
|
|
103393
|
-
let edits = Array.isArray(
|
|
103444
|
+
let resolved2 = op.resolve(args, ctx);
|
|
103445
|
+
if (resolved2 === false) continue;
|
|
103446
|
+
if (resolved2) {
|
|
103447
|
+
let edits = Array.isArray(resolved2) ? resolved2 : [resolved2];
|
|
103394
103448
|
for (let r of edits) {
|
|
103395
103449
|
if (channel2 != null && r.channel == null) r.channel = channel2;
|
|
103396
103450
|
if (at != null && r.at == null) r.at = at;
|
|
@@ -103929,15 +103983,25 @@ audio.fn.play = function(opts) {
|
|
|
103929
103983
|
a2.playing = false;
|
|
103930
103984
|
a2.paused = opts?.paused ?? false;
|
|
103931
103985
|
a2.currentTime = offset;
|
|
103932
|
-
a2.volume = opts
|
|
103986
|
+
if (opts?.volume != null) a2.volume = opts.volume;
|
|
103933
103987
|
a2.loop = opts?.loop ?? false;
|
|
103934
103988
|
a2.block = null;
|
|
103935
103989
|
a2._._wake = null;
|
|
103936
103990
|
a2._._seekTo = null;
|
|
103991
|
+
a2.ended = false;
|
|
103992
|
+
let startResolve, startReject;
|
|
103993
|
+
a2.played = new Promise((r, j) => {
|
|
103994
|
+
startResolve = r;
|
|
103995
|
+
startReject = j;
|
|
103996
|
+
});
|
|
103997
|
+
a2.played.catch(() => {
|
|
103998
|
+
});
|
|
103937
103999
|
(async () => {
|
|
103938
104000
|
try {
|
|
103939
104001
|
let ch = a2.channels, sr = a2.sampleRate;
|
|
103940
104002
|
a2.playing = true;
|
|
104003
|
+
if (!a2.paused) emit(a2, "play");
|
|
104004
|
+
let resolved2 = false;
|
|
103941
104005
|
let wait = async () => {
|
|
103942
104006
|
while (a2.paused && a2.playing && a2._._seekTo == null) await new Promise((r) => {
|
|
103943
104007
|
a2._._wake = r;
|
|
@@ -103953,6 +104017,7 @@ audio.fn.play = function(opts) {
|
|
|
103953
104017
|
from = a2._._seekTo;
|
|
103954
104018
|
a2._._seekTo = null;
|
|
103955
104019
|
a2.currentTime = from;
|
|
104020
|
+
a2.seeking = false;
|
|
103956
104021
|
}
|
|
103957
104022
|
}
|
|
103958
104023
|
let write2 = Speaker({ sampleRate: sr, channels: ch, bitDepth: 32 });
|
|
@@ -103970,12 +104035,13 @@ audio.fn.play = function(opts) {
|
|
|
103970
104035
|
from = a2._._seekTo;
|
|
103971
104036
|
a2._._seekTo = null;
|
|
103972
104037
|
a2.currentTime = from;
|
|
104038
|
+
a2.seeking = false;
|
|
103973
104039
|
seeked = true;
|
|
103974
104040
|
break;
|
|
103975
104041
|
}
|
|
103976
104042
|
let end = Math.min(bOff + BLOCK, cLen), len = end - bOff;
|
|
103977
104043
|
a2.block = chunk[0].subarray(bOff, end);
|
|
103978
|
-
let g2 =
|
|
104044
|
+
let g2 = a2.muted ? 0 : a2.volume;
|
|
103979
104045
|
let buf = new Float32Array(len * ch);
|
|
103980
104046
|
for (let i = 0; i < len; i++) for (let c = 0; c < ch; c++)
|
|
103981
104047
|
buf[i * ch + c] = (chunk[c] || chunk[0])[bOff + i] * g2;
|
|
@@ -104002,6 +104068,10 @@ audio.fn.play = function(opts) {
|
|
|
104002
104068
|
break;
|
|
104003
104069
|
}
|
|
104004
104070
|
await send();
|
|
104071
|
+
if (!resolved2) {
|
|
104072
|
+
resolved2 = true;
|
|
104073
|
+
startResolve();
|
|
104074
|
+
}
|
|
104005
104075
|
played += len;
|
|
104006
104076
|
if (a2._._seekTo == null) {
|
|
104007
104077
|
a2.currentTime = from + played / sr;
|
|
@@ -104025,25 +104095,36 @@ audio.fn.play = function(opts) {
|
|
|
104025
104095
|
continue;
|
|
104026
104096
|
}
|
|
104027
104097
|
a2.playing = false;
|
|
104098
|
+
a2.ended = true;
|
|
104028
104099
|
emit(a2, "timeupdate", a2.currentTime);
|
|
104029
104100
|
break;
|
|
104030
104101
|
}
|
|
104031
104102
|
a2.playing = false;
|
|
104032
104103
|
emit(a2, "ended");
|
|
104104
|
+
if (!resolved2) startResolve();
|
|
104033
104105
|
} catch (err) {
|
|
104034
104106
|
console.error("Playback error:", err);
|
|
104035
104107
|
a2.playing = false;
|
|
104108
|
+
if (!resolved) startReject(err);
|
|
104109
|
+
else emit(a2, "error", err);
|
|
104036
104110
|
}
|
|
104037
104111
|
})();
|
|
104038
104112
|
return this;
|
|
104039
104113
|
};
|
|
104040
104114
|
var proto = audio.fn;
|
|
104041
104115
|
proto.pause = function() {
|
|
104042
|
-
this.paused
|
|
104116
|
+
if (!this.paused && this.playing) {
|
|
104117
|
+
this.paused = true;
|
|
104118
|
+
emit(this, "pause");
|
|
104119
|
+
}
|
|
104043
104120
|
};
|
|
104044
104121
|
proto.resume = function() {
|
|
104045
|
-
this.paused
|
|
104046
|
-
|
|
104122
|
+
if (this.paused) {
|
|
104123
|
+
this._.ctStamp = performance.now();
|
|
104124
|
+
this.paused = false;
|
|
104125
|
+
emit(this, "play");
|
|
104126
|
+
if (this._._wake) this._._wake();
|
|
104127
|
+
}
|
|
104047
104128
|
};
|
|
104048
104129
|
|
|
104049
104130
|
// fn/save.js
|
package/dist/audio.js
CHANGED
|
@@ -720,7 +720,7 @@ function parse2(str = "", format = "ms") {
|
|
|
720
720
|
}
|
|
721
721
|
|
|
722
722
|
// core.js
|
|
723
|
-
audio.version = "2.
|
|
723
|
+
audio.version = "2.1.0";
|
|
724
724
|
function parseTime(v) {
|
|
725
725
|
if (v == null) return v;
|
|
726
726
|
if (typeof v === "number") {
|
|
@@ -950,10 +950,15 @@ function create(pages, sampleRate2, ch, length, opts = {}, stats) {
|
|
|
950
950
|
// source sample length
|
|
951
951
|
waiters: null,
|
|
952
952
|
// decode notify queue (null when not streaming)
|
|
953
|
-
ev: {}
|
|
953
|
+
ev: {},
|
|
954
954
|
// instance event listeners
|
|
955
|
+
ct: 0,
|
|
956
|
+
ctStamp: 0,
|
|
957
|
+
// currentTime wall-clock interpolation
|
|
958
|
+
vol: 1,
|
|
959
|
+
muted: false
|
|
960
|
+
// volume 0..1 linear with change events
|
|
955
961
|
};
|
|
956
|
-
a2.currentTime = 0;
|
|
957
962
|
a2.edits = [];
|
|
958
963
|
a2.version = 0;
|
|
959
964
|
a2._.pcm = null;
|
|
@@ -965,9 +970,56 @@ function create(pages, sampleRate2, ch, length, opts = {}, stats) {
|
|
|
965
970
|
a2._.lenV = 0;
|
|
966
971
|
a2._.chC = a2._.ch;
|
|
967
972
|
a2._.chV = 0;
|
|
973
|
+
Object.defineProperties(a2, {
|
|
974
|
+
currentTime: {
|
|
975
|
+
get() {
|
|
976
|
+
if (this.playing && !this.paused) {
|
|
977
|
+
let t = this._.ct + (performance.now() - this._.ctStamp) / 1e3;
|
|
978
|
+
let d2 = this.duration;
|
|
979
|
+
return d2 > 0 ? Math.min(t, d2) : t;
|
|
980
|
+
}
|
|
981
|
+
return this._.ct;
|
|
982
|
+
},
|
|
983
|
+
set(v) {
|
|
984
|
+
this._.ct = v;
|
|
985
|
+
this._.ctStamp = performance.now();
|
|
986
|
+
},
|
|
987
|
+
enumerable: true,
|
|
988
|
+
configurable: true
|
|
989
|
+
},
|
|
990
|
+
volume: {
|
|
991
|
+
get() {
|
|
992
|
+
return this._.vol;
|
|
993
|
+
},
|
|
994
|
+
set(v) {
|
|
995
|
+
v = Math.max(0, Math.min(1, +v || 0));
|
|
996
|
+
if (this._.vol !== v) {
|
|
997
|
+
this._.vol = v;
|
|
998
|
+
emit(this, "volumechange");
|
|
999
|
+
}
|
|
1000
|
+
},
|
|
1001
|
+
enumerable: true,
|
|
1002
|
+
configurable: true
|
|
1003
|
+
},
|
|
1004
|
+
muted: {
|
|
1005
|
+
get() {
|
|
1006
|
+
return this._.muted;
|
|
1007
|
+
},
|
|
1008
|
+
set(v) {
|
|
1009
|
+
v = !!v;
|
|
1010
|
+
if (this._.muted !== v) {
|
|
1011
|
+
this._.muted = v;
|
|
1012
|
+
emit(this, "volumechange");
|
|
1013
|
+
}
|
|
1014
|
+
},
|
|
1015
|
+
enumerable: true,
|
|
1016
|
+
configurable: true
|
|
1017
|
+
}
|
|
1018
|
+
});
|
|
968
1019
|
a2.playing = false;
|
|
969
1020
|
a2.paused = false;
|
|
970
|
-
a2.
|
|
1021
|
+
a2.ended = false;
|
|
1022
|
+
a2.seeking = false;
|
|
971
1023
|
a2.loop = false;
|
|
972
1024
|
a2.block = null;
|
|
973
1025
|
a2._.lru = /* @__PURE__ */ new Set();
|
|
@@ -1041,6 +1093,7 @@ fn.push = function(data, fmt3) {
|
|
|
1041
1093
|
fn.stop = function() {
|
|
1042
1094
|
this.playing = false;
|
|
1043
1095
|
this.paused = false;
|
|
1096
|
+
this.seeking = false;
|
|
1044
1097
|
if (this._._wake) this._._wake();
|
|
1045
1098
|
if (this.recording) {
|
|
1046
1099
|
this.recording = false;
|
|
@@ -1085,6 +1138,7 @@ fn.record = function(opts = {}) {
|
|
|
1085
1138
|
};
|
|
1086
1139
|
fn.seek = function(t) {
|
|
1087
1140
|
t = Math.max(0, t);
|
|
1141
|
+
this.seeking = true;
|
|
1088
1142
|
this.currentTime = t;
|
|
1089
1143
|
if (this.cache) {
|
|
1090
1144
|
let page = Math.floor(t * this.sampleRate / audio.PAGE_SIZE);
|
|
@@ -1096,7 +1150,7 @@ fn.seek = function(t) {
|
|
|
1096
1150
|
if (this.playing) {
|
|
1097
1151
|
this._._seekTo = t;
|
|
1098
1152
|
if (this._._wake) this._._wake();
|
|
1099
|
-
}
|
|
1153
|
+
} else this.seeking = false;
|
|
1100
1154
|
return this;
|
|
1101
1155
|
};
|
|
1102
1156
|
fn.read = async function(opts) {
|
|
@@ -1561,10 +1615,10 @@ function buildPlan(a2) {
|
|
|
1561
1615
|
if (!op) throw new Error(`Unknown op: ${type}`);
|
|
1562
1616
|
if (op.resolve) {
|
|
1563
1617
|
let ctx = { ...extra, stats: a2._.srcStats || a2.stats, sampleRate: sr, channelCount: ch, channel, at, duration, totalDuration: planLen(segs) / sr };
|
|
1564
|
-
let
|
|
1565
|
-
if (
|
|
1566
|
-
if (
|
|
1567
|
-
let edits = Array.isArray(
|
|
1618
|
+
let resolved2 = op.resolve(args, ctx);
|
|
1619
|
+
if (resolved2 === false) continue;
|
|
1620
|
+
if (resolved2) {
|
|
1621
|
+
let edits = Array.isArray(resolved2) ? resolved2 : [resolved2];
|
|
1568
1622
|
for (let r of edits) {
|
|
1569
1623
|
if (channel != null && r.channel == null) r.channel = channel;
|
|
1570
1624
|
if (at != null && r.at == null) r.at = at;
|
|
@@ -2050,15 +2104,25 @@ audio.fn.play = function(opts) {
|
|
|
2050
2104
|
a2.playing = false;
|
|
2051
2105
|
a2.paused = opts?.paused ?? false;
|
|
2052
2106
|
a2.currentTime = offset;
|
|
2053
|
-
a2.volume = opts
|
|
2107
|
+
if (opts?.volume != null) a2.volume = opts.volume;
|
|
2054
2108
|
a2.loop = opts?.loop ?? false;
|
|
2055
2109
|
a2.block = null;
|
|
2056
2110
|
a2._._wake = null;
|
|
2057
2111
|
a2._._seekTo = null;
|
|
2112
|
+
a2.ended = false;
|
|
2113
|
+
let startResolve, startReject;
|
|
2114
|
+
a2.played = new Promise((r, j) => {
|
|
2115
|
+
startResolve = r;
|
|
2116
|
+
startReject = j;
|
|
2117
|
+
});
|
|
2118
|
+
a2.played.catch(() => {
|
|
2119
|
+
});
|
|
2058
2120
|
(async () => {
|
|
2059
2121
|
try {
|
|
2060
2122
|
let ch = a2.channels, sr = a2.sampleRate;
|
|
2061
2123
|
a2.playing = true;
|
|
2124
|
+
if (!a2.paused) emit(a2, "play");
|
|
2125
|
+
let resolved2 = false;
|
|
2062
2126
|
let wait = async () => {
|
|
2063
2127
|
while (a2.paused && a2.playing && a2._._seekTo == null) await new Promise((r) => {
|
|
2064
2128
|
a2._._wake = r;
|
|
@@ -2074,6 +2138,7 @@ audio.fn.play = function(opts) {
|
|
|
2074
2138
|
from = a2._._seekTo;
|
|
2075
2139
|
a2._._seekTo = null;
|
|
2076
2140
|
a2.currentTime = from;
|
|
2141
|
+
a2.seeking = false;
|
|
2077
2142
|
}
|
|
2078
2143
|
}
|
|
2079
2144
|
let write2 = Speaker({ sampleRate: sr, channels: ch, bitDepth: 32 });
|
|
@@ -2091,12 +2156,13 @@ audio.fn.play = function(opts) {
|
|
|
2091
2156
|
from = a2._._seekTo;
|
|
2092
2157
|
a2._._seekTo = null;
|
|
2093
2158
|
a2.currentTime = from;
|
|
2159
|
+
a2.seeking = false;
|
|
2094
2160
|
seeked = true;
|
|
2095
2161
|
break;
|
|
2096
2162
|
}
|
|
2097
2163
|
let end = Math.min(bOff + BLOCK, cLen), len = end - bOff;
|
|
2098
2164
|
a2.block = chunk[0].subarray(bOff, end);
|
|
2099
|
-
let g =
|
|
2165
|
+
let g = a2.muted ? 0 : a2.volume;
|
|
2100
2166
|
let buf = new Float32Array(len * ch);
|
|
2101
2167
|
for (let i = 0; i < len; i++) for (let c = 0; c < ch; c++)
|
|
2102
2168
|
buf[i * ch + c] = (chunk[c] || chunk[0])[bOff + i] * g;
|
|
@@ -2123,6 +2189,10 @@ audio.fn.play = function(opts) {
|
|
|
2123
2189
|
break;
|
|
2124
2190
|
}
|
|
2125
2191
|
await send();
|
|
2192
|
+
if (!resolved2) {
|
|
2193
|
+
resolved2 = true;
|
|
2194
|
+
startResolve();
|
|
2195
|
+
}
|
|
2126
2196
|
played += len;
|
|
2127
2197
|
if (a2._._seekTo == null) {
|
|
2128
2198
|
a2.currentTime = from + played / sr;
|
|
@@ -2146,25 +2216,36 @@ audio.fn.play = function(opts) {
|
|
|
2146
2216
|
continue;
|
|
2147
2217
|
}
|
|
2148
2218
|
a2.playing = false;
|
|
2219
|
+
a2.ended = true;
|
|
2149
2220
|
emit(a2, "timeupdate", a2.currentTime);
|
|
2150
2221
|
break;
|
|
2151
2222
|
}
|
|
2152
2223
|
a2.playing = false;
|
|
2153
2224
|
emit(a2, "ended");
|
|
2225
|
+
if (!resolved2) startResolve();
|
|
2154
2226
|
} catch (err) {
|
|
2155
2227
|
console.error("Playback error:", err);
|
|
2156
2228
|
a2.playing = false;
|
|
2229
|
+
if (!resolved) startReject(err);
|
|
2230
|
+
else emit(a2, "error", err);
|
|
2157
2231
|
}
|
|
2158
2232
|
})();
|
|
2159
2233
|
return this;
|
|
2160
2234
|
};
|
|
2161
2235
|
var proto = audio.fn;
|
|
2162
2236
|
proto.pause = function() {
|
|
2163
|
-
this.paused
|
|
2237
|
+
if (!this.paused && this.playing) {
|
|
2238
|
+
this.paused = true;
|
|
2239
|
+
emit(this, "pause");
|
|
2240
|
+
}
|
|
2164
2241
|
};
|
|
2165
2242
|
proto.resume = function() {
|
|
2166
|
-
this.paused
|
|
2167
|
-
|
|
2243
|
+
if (this.paused) {
|
|
2244
|
+
this._.ctStamp = performance.now();
|
|
2245
|
+
this.paused = false;
|
|
2246
|
+
emit(this, "play");
|
|
2247
|
+
if (this._._wake) this._._wake();
|
|
2248
|
+
}
|
|
2168
2249
|
};
|
|
2169
2250
|
|
|
2170
2251
|
// fn/save.js
|
package/dist/audio.min.js
CHANGED
|
@@ -11,4 +11,4 @@ var nn=Object.defineProperty;var rn=(e,t)=>()=>(e&&(t=e(e=0)),t);var ln=(e,t)=>{
|
|
|
11
11
|
}
|
|
12
12
|
}
|
|
13
13
|
registerProcessor('mic-processor', MicProcessor)
|
|
14
|
-
`,w=new Blob([g],{type:"application/javascript"}),y=URL.createObjectURL(w);await o.audioWorklet.addModule(y),URL.revokeObjectURL(y),c=new AudioWorkletNode(o,"mic-processor",{numberOfInputs:1,numberOfOutputs:0,channelCount:t}),s.connect(c),c.port.onmessage=_=>{if(f||!u)return;let A=u;u=null,A(null,p(_.data,n))}}else c=o.createScriptProcessor(2048,t,1),s.connect(c),c.connect(o.destination),c.onaudioprocess=w=>{if(f||!u)return;let y=u;u=null;let _=[];for(let A=0;A<t;A++)_.push(w.inputBuffer.getChannelData(A).slice());y(null,p(_,n))};return h.close=d,h.end=d,h.backend="mediastream",h;function h(g){if(g==null||f){d();return}o.state==="suspended"&&o.resume(),u=g}function d(){f||(f=!0,u=null,s.disconnect(),i.getTracks().forEach(g=>g.stop()),a&&o.close?.())}function p(g,w){let y=g.length,_=g[0].length,A=w/8,b=new Uint8Array(_*y*A),M=new DataView(b.buffer);for(let x=0;x<_;x++)for(let R=0;R<y;R++){let E=g[R][x],F=(x*y+R)*A;w===16?M.setInt16(F,Math.max(-32768,Math.min(32767,Math.round(E*32767))),!0):w===32?M.setFloat32(F,E,!0):w===8&&(b[F]=Math.max(0,Math.min(255,Math.round((E+1)*127.5))))}return b}}var At=rn(()=>{});function N(e){if(e){if(e=new Uint8Array(e.buffer||e),on(e))return"wav";if(pn(e))return"aiff";if(an(e))return"mp3";if(dn(e))return"aac";if(sn(e))return"flac";if(un(e))return"m4a";if(cn(e))return"opus";if(fn(e))return"oga";if(hn(e))return"qoa";if(mn(e))return"mid";if(gn(e))return"caf";if(yn(e))return"wma";if(wn(e))return"amr";if(_n(e))return"webm"}}function an(e){if(!(!e||e.length<3))return e[0]===73&&e[1]===68&&e[2]===51||e[0]===255&&(e[1]&224)===224&&(e[1]&6)!==0||e[0]===84&&e[1]===65&&e[2]===71}function on(e){if(!(!e||e.length<12))return e[0]===82&&e[1]===73&&e[2]===70&&e[3]===70&&e[8]===87&&e[9]===65&&e[10]===86&&e[11]===69}function fn(e){if(!(!e||e.length<4))return e[0]===79&&e[1]===103&&e[2]===103&&e[3]===83}function sn(e){if(!(!e||e.length<4))return e[0]===102&&e[1]===76&&e[2]===97&&e[3]===67}function un(e){if(!(!e||e.length<8))return e[4]===102&&e[5]===116&&e[6]===121&&e[7]===112||e[0]===77&&e[1]===52&&e[2]===65&&e[3]===32}function cn(e){if(!(!e||e.length<36))return e[0]===79&&e[1]===103&&e[2]===103&&e[3]===83&&e[28]===79&&e[29]===112&&e[30]===117&&e[31]===115&&e[32]===72&&e[33]===101&&e[34]===97&&e[35]===100}function hn(e){if(!(!e||e.length<4))return e[0]===113&&e[1]===111&&e[2]===97&&e[3]===102}function pn(e){if(!(!e||e.length<12))return e[0]===70&&e[1]===79&&e[2]===82&&e[3]===77&&e[8]===65&&e[9]===73&&e[10]===70&&(e[11]===70||e[11]===67)}function dn(e){if(!(!e||e.length<2))return e[0]===255&&(e[1]&240)===240&&(e[1]&6)===0}function mn(e){if(!(!e||e.length<4))return e[0]===77&&e[1]===84&&e[2]===104&&e[3]===100}function gn(e){if(!(!e||e.length<4))return e[0]===99&&e[1]===97&&e[2]===102&&e[3]===102}function yn(e){if(!(!e||e.length<8))return e[0]===48&&e[1]===38&&e[2]===178&&e[3]===117&&e[4]===142&&e[5]===102&&e[6]===207&&e[7]===17}function wn(e){if(!(!e||e.length<5))return e[0]===35&&e[1]===33&&e[2]===65&&e[3]===77&&e[4]===82}function _n(e){if(!(!e||e.length<4))return e[0]===26&&e[1]===69&&e[2]===223&&e[3]===163}var re=Object.freeze({channelData:Object.freeze([]),sampleRate:0});async function z(e){if(!e||typeof e=="string"||!(e.buffer||e.byteLength||e.length))throw TypeError("Expected ArrayBuffer or Uint8Array");let t=new Uint8Array(e),r=N(t);if(!r)throw Error("Unknown audio format");if(!z[r])throw Error("No decoder for "+r);let n=await z[r]();try{let l=await n(t),i=await n();return it(l,i)}catch(l){throw n.free(),l}}function T(e,t){z[e]=An(e,async()=>{let r=await t();if(r.decoder){let i=await r.decoder();return lt(a=>i.decode(a),i.flush?()=>i.flush():null,i.free?()=>i.free():null)}let n=r.default||r,l=typeof n=="function"?await n():n;return l.ready&&await l.ready,lt(i=>l.decode(i),l.flush?()=>l.flush():null,l.free?()=>l.free():null)})}function An(e,t){let r=async n=>{if(!n)return t();console.warn("decode."+e+"(data) is deprecated, use decode(data) or let dec = await decode."+e+"()");let l=await t();try{let i=await l(n instanceof Uint8Array?n:new Uint8Array(n.buffer||n)),a=await l();return it(i,a)}catch(i){throw l.free(),i}};return r.stream=t,r}T("mp3",()=>import("mpg123-decoder").then(e=>({decoder:async()=>{let t=new e.MPEGDecoder;return await t.ready,t}})));T("flac",()=>import("@wasm-audio-decoders/flac").then(e=>({decoder:async()=>{let t=new e.FLACDecoder;return await t.ready,t}})));T("opus",()=>import("ogg-opus-decoder").then(e=>({decoder:async()=>{let t=new e.OggOpusDecoder;return await t.ready,t}})));T("oga",()=>import("@wasm-audio-decoders/ogg-vorbis").then(e=>({decoder:async()=>{let t=new e.OggVorbisDecoder;return await t.ready,t}})));T("m4a",()=>import("@audio/decode-aac"));T("wav",()=>import("@audio/decode-wav"));T("qoa",()=>import("qoa-format").then(e=>({decoder:async()=>({decode:t=>e.decode(t)})})));T("aac",()=>import("@audio/decode-aac"));T("aiff",()=>import("@audio/decode-aiff"));T("caf",()=>import("@audio/decode-caf"));T("webm",()=>import("@audio/decode-webm"));T("amr",()=>import("@audio/decode-amr"));T("wma",()=>import("@audio/decode-wma"));function lt(e,t,r){let n=!1,l=async i=>{if(i){if(n)throw Error("Decoder already freed");try{return Ce(await e(i instanceof Uint8Array?i:new Uint8Array(i)))}catch(a){throw n=!0,r?.(),a}}if(n)return re;n=!0;try{let a=t?Ce(await t()):re;return r?.(),a}catch(a){throw r?.(),a}};return l.decode=l,l.flush=async()=>n?re:t?Ce(await t()):re,l.free=()=>{n||(n=!0,r?.())},l}function Ce(e){if(!e?.channelData?.length)return re;let{channelData:t,sampleRate:r,samplesDecoded:n}=e;if(n!=null&&n<t[0].length&&(t=t.map(l=>l.subarray(0,n))),!t[0]?.length)return re;if(t.length===2){let l=t[0],i=t[1],a=!0;for(let o=0;o<l.length;o+=37)if(l[o]!==i[o]){a=!1;break}a&&(t=[l])}return{channelData:t,sampleRate:r}}function it(e,t){if(!t?.channelData?.length)return e;if(!e?.channelData?.length)return t;let r=e.channelData.length,n=t.channelData.length,l=Math.max(r,n);return{channelData:Array.from({length:l},(i,a)=>{let o=e.channelData[a%r],s=t.channelData[a%n],f=new Float32Array(o.length+s.length);return f.set(o),f.set(s,o.length),f}),sampleRate:e.sampleRate}}var G=new Uint8Array(0),at={},ee=at;function le(e,t){at[e]=bn(async r=>{let n=(await t()).default,l=await n(r);return Mn(i=>l.encode(i),()=>l.flush(),()=>l.free())})}le("wav",()=>import("@audio/encode-wav"));le("aiff",()=>import("@audio/encode-aiff"));le("mp3",()=>import("@audio/encode-mp3"));le("ogg",()=>import("@audio/encode-ogg"));le("flac",()=>import("@audio/encode-flac"));le("opus",()=>import("@audio/encode-opus"));function bn(e){let t=async(r,n)=>{if(!n)return e(r);if(!n.sampleRate)throw Error("sampleRate is required");let l=ot(r);if(!l.length||!l[0].length)return G;let i=await e({channels:l.length,...n});try{let a=await i(l),o=await i();return xn(a,o)}catch(a){throw i.free(),a}};return t.stream=e,t}function ot(e){if(!e)return[];if(Array.isArray(e))return e[0]instanceof Float32Array?e:[];if(e instanceof Float32Array)return[e];if(e.getChannelData&&e.numberOfChannels){let t=[];for(let r=0;r<e.numberOfChannels;r++)t.push(e.getChannelData(r));return t}return[]}function Mn(e,t,r){let n=!1,l=async i=>{if(i){if(n)throw Error("Encoder already freed");let a=ot(i);try{return Pe(await e(a))}catch(o){throw n=!0,r?.(),o}}if(n)return G;n=!0;try{let a=t?Pe(await t()):G;return r?.(),a}catch(a){throw r?.(),a}};return l.encode=l,l.flush=async()=>n?G:t?Pe(await t()):G,l.free=()=>{n||(n=!0,r?.())},l}function Pe(e){return e?.length?e instanceof Uint8Array?e:e.buffer?new Uint8Array(e.buffer,e.byteOffset,e.byteLength):new Uint8Array(e):G}function xn(e,t){if(!t?.length)return e||G;if(!e?.length)return t||G;let r=new Uint8Array(e.length+t.length);return r.set(e),r.set(t,e.length),r}var Rn=[8e3,11025,16e3,22050,44100,48e3,88200,96e3,176400,192e3,352800,384e3],ct=typeof AudioBuffer<"u"?AudioBuffer:null;try{ct??=(await import("audio-buffer")).default}catch{}var En=new Set(Rn),$={float32:{C:Float32Array,min:-1,max:1},float64:{C:Float64Array,min:-1,max:1},uint8:{C:Uint8Array,min:0,max:255},uint16:{C:Uint16Array,min:0,max:65535},uint32:{C:Uint32Array,min:0,max:4294967295},int8:{C:Int8Array,min:-128,max:127},int16:{C:Int16Array,min:-32768,max:32767},int32:{C:Int32Array,min:-2147483648,max:2147483647}},we=e=>$[e]&&e||$[e+"32"]&&e+"32",ft={array:1,arraybuffer:1,buffer:1,audiobuffer:1},ie={mono:1,stereo:2,"2.1":3,quad:4,"5.1":6};for(let e=3;e<=32;e++)ie[e+"-channel"]||=e;var kn={};for(let e in ie)kn[ie[e]]||=e;var ht=e=>ArrayBuffer.isView(e)&&!(e instanceof DataView),Oe=e=>Array.isArray(e)&&e.length>0&&ht(e[0]),st=e=>e!=null&&typeof e!="string"&&!Oe(e)&&(Array.isArray(e)||ht(e)||e instanceof ArrayBuffer),pt=e=>e!=null&&typeof e.getChannelData=="function"&&typeof e.numberOfChannels=="number";function W(e){if(!e)return{};if(typeof e!="string"){let r={},n=e.dtype||e.type;return we(n)&&(r.dtype=we(n)),n&&ft[n]&&(r.container=n),e.channels!=null&&(r.channels=ie[e.channels]||+e.channels),e.numberOfChannels!=null&&(r.channels??=e.numberOfChannels),e.interleaved!=null&&(r.interleaved=e.interleaved),e.endianness&&(r.endianness=e.endianness),e.sampleRate!=null&&(r.sampleRate=e.sampleRate),e.rate!=null&&(r.sampleRate??=e.rate),e.container&&(r.container=e.container),r}let t={};for(let r of e.split(/\s*[,;_]\s*|\s+/)){let n=r.toLowerCase();if(we(n))t.dtype=we(n);else if(ft[n])t.container=n;else if(ie[n])t.channels=ie[n];else if(n==="interleaved")t.interleaved=!0;else if(n==="planar")t.interleaved=!1;else if(n==="le")t.endianness="le";else if(n==="be")t.endianness="be";else if(/^\d+$/.test(n)&&En.has(+n))t.sampleRate=+n;else throw Error("Unknown format token: "+r)}return t}function _e(e){return e==null?{}:pt(e)?{dtype:"float32",channels:e.numberOfChannels,interleaved:!1,sampleRate:e.sampleRate}:typeof Buffer<"u"&&Buffer.isBuffer(e)?{dtype:"uint8",container:"buffer"}:e instanceof Float32Array?{dtype:"float32"}:e instanceof Float64Array?{dtype:"float64"}:e instanceof Int8Array?{dtype:"int8"}:e instanceof Int16Array?{dtype:"int16"}:e instanceof Int32Array?{dtype:"int32"}:e instanceof Uint8Array?{dtype:"uint8"}:e instanceof Uint8ClampedArray?{dtype:"uint8"}:e instanceof Uint16Array?{dtype:"uint16"}:e instanceof Uint32Array?{dtype:"uint32"}:e instanceof ArrayBuffer?{container:"arraybuffer"}:Array.isArray(e)?Oe(e)?{..._e(e[0]),channels:e.length,interleaved:!1}:{container:"array"}:{}}function ut(e){return $[e]||{min:-1,max:1}}function he(e,t,r,n){if(!e)throw Error("Source data required");if(t==null)throw Error("Format required");let l=_e(e);r===void 0&&n===void 0?st(t)?(n=t,r=_e(n),t=l):(r=W(t),t=l):n===void 0?st(r)?(n=r,r=W(t),t=l):(t={...l,...W(t)},r=W(r)):(t={...l,...W(t)},r={...n?_e(n):{},...W(r)}),r.container==="audiobuffer"&&(r.dtype="float32"),r.dtype||(r.dtype=t.dtype),r.channels==null&&t.channels!=null&&(r.channels=t.channels),r.interleaved!=null&&t.interleaved==null&&(t.interleaved=!r.interleaved,t.channels||(t.channels=2)),t.interleaved!=null&&!t.channels&&(t.channels=2);let i=t.container==="array"?{min:-1,max:1}:ut(t.dtype),a=r.container==="array"?{min:-1,max:1}:ut(r.dtype),o;if(Oe(e)){let w=e.length,y=e[0].length;o=new e[0].constructor(y*w);for(let _=0;_<w;_++)o.set(e[_],y*_)}else if(pt(e)){let w=e.numberOfChannels,y=e.length;o=new Float32Array(y*w);for(let _=0;_<w;_++)o.set(e.getChannelData(_),y*_)}else e instanceof ArrayBuffer?o=new($[t.dtype]?.C||Uint8Array)(e):typeof Buffer<"u"&&Buffer.isBuffer(e)?o=new($[t.dtype]?.C||Uint8Array)(e.buffer.slice(e.byteOffset,e.byteOffset+e.byteLength)):o=e;let s=o.length,f=i.min!==a.min||i.max!==a.max,u=t.interleaved!=null&&r.interleaved!=null&&t.interleaved!==r.interleaved,c=t.channels||1,h=Math.floor(s/c),d=$[r.dtype]?.C||Float32Array,p;if(!f&&!u)p=r.container==="array"?Array.from(o):new d(o);else{p=r.container==="array"?new Array(s):new d(s);let w=i.max-i.min,y=a.max>1,_=i.min===-1&&i.max===1&&y?a.max-a.min+1:a.max-a.min,A=i.min===-1&&i.max===1&&y;if(u){let b=t.interleaved;for(let M=0;M<s;M++){let x=b?M%h*c+~~(M/h):M%c*h+~~(M/c),R=o[x];f&&(R=(R-i.min)/w*_+a.min,A&&(R=Math.round(R)),R<a.min?R=a.min:R>a.max&&(R=a.max)),p[M]=R}}else for(let b=0;b<s;b++){let M=(o[b]-i.min)/w*_+a.min;A&&(M=Math.round(M)),p[b]=M<a.min?a.min:M>a.max?a.max:M}}if(n)if(Array.isArray(n)){for(let w=0;w<s;w++)n[w]=p[w];p=n}else if(n instanceof ArrayBuffer){let w=new($[r.dtype]?.C||Uint8Array)(n);w.set(p),p=w}else n.set(p),p=n;let g=$[r.dtype];if(g&&g.C.BYTES_PER_ELEMENT>1&&t.endianness&&r.endianness&&t.endianness!==r.endianness&&p.buffer){let w=r.endianness==="le",y=new DataView(p.buffer),_=g.C.BYTES_PER_ELEMENT,A="set"+r.dtype[0].toUpperCase()+r.dtype.slice(1);for(let b=0;b<s;b++)y[A](b*_,p[b],w)}if(r.container==="audiobuffer"){let w=typeof AudioBuffer<"u"?AudioBuffer:ct;if(!w)throw Error("AudioBuffer not available. In Node.js: install audio-buffer package or set globalThis.AudioBuffer");let y=r.channels||1,_=Math.floor(p.length/y),A=r.sampleRate||t.sampleRate||44100,b=new w({length:_,numberOfChannels:y,sampleRate:A});if((u?r.interleaved:t.interleaved??!1)&&y>1)for(let x=0;x<y;x++){let R=new Float32Array(_);for(let E=0;E<_;E++)R[E]=p[E*y+x];b.copyToChannel(R,x)}else for(let x=0;x<y;x++)b.copyToChannel(p.subarray(x*_,(x+1)*_),x);return b}return(r.container==="arraybuffer"||r.container==="buffer")&&p.buffer||p}var k=Object.create(null),dt=6e4,mt=dt*60,Le=mt*24,gt=Le*365.25;k.year=k.yr=k.y=gt;k.month=k.mo=k.mth=gt/12;k.week=k.wk=k.w=Le*7;k.day=k.d=Le;k.hour=k.hr=k.h=mt;k.minute=k.min=k.m=dt;k.second=k.sec=k.s=1e3;k.millisecond=k.millisec=k.ms=1;k.microsecond=k.microsec=k.us=k.\u00B5s=.001;k.nanosecond=k.nanosec=k.ns=1e-6;k.group=",";k.decimal=".";k.placeholder=" _";var yt=k;var vn=/((?:\d{1,16}(?:\.\d{1,16})?|\.\d{1,16})(?:[eE][-+]?\d{1,4})?)\s?([\p{L}]{0,14})/gu;U.unit=yt;function U(e="",t="ms"){let r=null,n;return String(e).replace(new RegExp(`(\\d)[${U.unit.placeholder}${U.unit.group}](\\d)`,"g"),"$1$2").replace(U.unit.decimal,".").replace(vn,(l,i,a)=>{if(a)a=a.toLowerCase();else if(n){for(let o in U.unit)if(U.unit[o]<n){a=o;break}}else a=t;n=a=U.unit[a]||U.unit[a.replace(/s$/,"")],a&&(r=(r||0)+i*a)}),r&&r/(U.unit[t]||1)*(e[0]==="-"?-1:1)}m.version="2.0.0";function S(e){if(e==null)return e;if(typeof e=="number"){if(!Number.isFinite(e))throw new Error(`Invalid time: ${e}`);return e}let t=e.match(/^(\d+):(\d{1,2})(?::(\d{1,2}))?(?:\.(\d+))?$/);if(t){let[,n,l,i,a]=t,o=i!=null?+n*3600+ +l*60+ +i:+n*60+ +l;return a&&(o+=+("0."+a)),o}let r=U(e,"s");if(r!=null&&isFinite(r))return r;throw new Error(`Invalid time: ${e}`)}function m(e,t={}){if(e==null){let f=t.sampleRate||44100,u=t.channels||1,c=[],h=()=>{for(let p of c.splice(0))p()},d=Ae([],f,u,0,t,null);return d.decoded=!1,d.recording=!1,d._.acc=Mt({pages:d.pages,notify:h,ondata:(...p)=>D(d,"data",...p)}),d._.waiters=c,d}if(e&&typeof e=="object"&&!Array.isArray(e)&&e.edits){if(!e.source)throw new TypeError("audio: cannot restore document without source reference");let f=m(e.source,t);if(f.run)for(let u of e.edits)f.run(u);return f}if(Array.isArray(e)&&e.length&&!(e[0]instanceof Float32Array)){let f=e.map(h=>h?.pages?h:m(h,t)),u=f[0].clip?f[0].clip():m.from(f[0]);if(!u.insert)throw new Error('audio([...]): concat requires insert plugin \u2014 import "audio" instead of "audio/core.js"');for(let h=1;h<f.length;h++)u.insert(f[h]);let c=f.filter(h=>!h.decoded);return c.length&&(u.ready=Promise.all(c.map(h=>h.ready)).then(()=>(delete u.then,delete u.catch,!0)),u.ready.catch(()=>{}),Ie(u)),u}if(e?.getChannelData&&e?.numberOfChannels)return m.from(e,t);if(Array.isArray(e)&&e[0]instanceof Float32Array||typeof e=="number"){let f=m.from(e,t);return m.evict&&f.cache&&f.budget!==1/0&&(f.ready=m.evict(f).then(()=>(delete f.then,delete f.catch,!0)),f.ready.catch(()=>{}),Ie(f)),f}let r=typeof e=="string"?e:e instanceof URL?e.href:null,n=[],l=[],i=()=>{for(let f of l.splice(0))f()},a=Ae(n,0,0,0,{...t,source:r},null);a._.waiters=l,a.decoded=!1;let o,s;return a._.ready=new Promise((f,u)=>{o=f,s=u}),a._.ready.catch(()=>{}),a.ready=(async()=>{try{if(t.storage==="persistent"){if(!m.opfsCache)throw new Error('Persistent storage requires cache module (import "./cache.js")');try{t={...t,cache:await m.opfsCache(),budget:t.budget??m.DEFAULT_BUDGET??1/0}}catch{throw new Error('OPFS not available (required by storage: "persistent")')}a.cache=t.cache,a.budget=t.budget}let f=await Pn(e,{pages:n,notify:i,ondata:(...c)=>D(a,"data",...c)});a.sampleRate=f.sampleRate,a._.ch=f.channels,a._.chV=-1,f.acc&&(a._.acc=f.acc),D(a,"metadata",{sampleRate:f.sampleRate,channels:f.channels}),o();let u=await f.decoding;return a._.len=u.length,a._.lenV=-1,a.stats=u.stats,a.decoded=!0,i(),m.evict?.(a),delete a.then,delete a.catch,!0}catch(f){throw s(f),f}})(),a.ready.catch(()=>{}),Ie(a),a}function Ie(e){e.then=function(t,r){return e.ready.then(()=>(delete e.then,delete e.catch,e)).then(t,r)},e.catch=function(t){return e.then(null,t)}}m.from=function(e,t={}){if(Array.isArray(e)&&e[0]instanceof Float32Array)return pe(e,t);if(typeof e=="number")return Sn(e,t);if(typeof e=="function")return Fn(e,t);if(e?.pages)return Ae(e.pages,t.sampleRate??e.sampleRate,t.channels??e._.ch,e._.len,{source:e.source,storage:e.storage,cache:e.cache,budget:t.budget??e.budget},e.stats);if(e?.getChannelData){let r=Array.from({length:e.numberOfChannels},(n,l)=>new Float32Array(e.getChannelData(l)));return pe(r,{sampleRate:e.sampleRate,...t})}if(ArrayBuffer.isView(e)&&t.format){let r=W(t.format),n=r.channels||t.channels||1,l=r.sampleRate||t.sampleRate||44100,i={...r,channels:n};n>1&&i.interleaved==null&&(i.interleaved=!0);let a=he(e,i,{dtype:"float32",interleaved:!1,channels:n}),o=a.length/n,s=Array.from({length:n},(f,u)=>a.subarray(u*o,(u+1)*o));return pe(s,{sampleRate:l})}throw new TypeError("audio.from: expected Float32Array[], AudioBuffer, audio instance, function, or number")};var O={};m.fn=O;m.BLOCK_SIZE=1024;m.PAGE_SIZE=1024*m.BLOCK_SIZE;var V=Symbol("load"),be=Symbol("read");function D(e,t,...r){let n=e._.ev[t];if(n)for(let l of n)l(...r)}O.on=function(e,t){return(this._.ev[e]??=[]).push(t),this};O.off=function(e,t){if(!e)return this._.ev={},this;if(!t)return delete this._.ev[e],this;let r=this._.ev[e];if(r){let n=r.indexOf(t);n>=0&&r.splice(n,1)}return this};O.dispose=function(){this.stop(),this._.ev={},this._.pcm=null,this._.plan=null,this.pages.length=0,this.stats=null,this._.waiters=null,this._.acc=null};Symbol.dispose&&(O[Symbol.dispose]=O.dispose);m.use=function(...e){for(let t of e)t(m)};function Ae(e,t,r,n,l={},i){let a=Object.create(O);return a.pages=e,a.sampleRate=t,a.source=l.source??null,a.storage=l.storage||"memory",a.cache=l.cache||null,a.budget=l.budget??1/0,a.stats=i,a.decoded=!0,a.ready=Promise.resolve(!0),a._={ch:r,len:n,waiters:null,ev:{}},a.currentTime=0,a.edits=[],a.version=0,a._.pcm=null,a._.pcmV=-1,a._.plan=null,a._.planV=-1,a._.statsV=-1,a._.lenC=a._.len,a._.lenV=0,a._.chC=a._.ch,a._.chV=0,a.playing=!1,a.paused=!1,a.volume=0,a.loop=!1,a.block=null,a._.lru=new Set,a}function pe(e,t={}){let r=t.sampleRate||44100;return Ae(bt(e),r,e.length,e[0].length,t,m.statSession?.(r).page(e).done())}function Sn(e,t={}){let r=t.sampleRate||44100,n=t.channels||1;return pe(Array.from({length:n},()=>new Float32Array(Math.round(e*r))),{...t,sampleRate:r})}function Fn(e,t={}){let r=t.sampleRate||44100,n=t.channels||1,l=t.duration;if(l==null)throw new TypeError("audio.from(fn): duration required");let i=Math.round(l*r),a=Array.from({length:n},()=>new Float32Array(i));for(let o=0;o<i;o++){let s=e(o/r,o);if(typeof s=="number")for(let f=0;f<n;f++)a[f][o]=s;else for(let f=0;f<n;f++)a[f][o]=s[f]??0}return pe(a,{sampleRate:r})}Object.defineProperties(O,{length:{get(){return this._.len},configurable:!0},duration:{get(){return this.length/this.sampleRate},configurable:!0},channels:{get(){return this._.ch},configurable:!0}});O[V]=async function(){this._.ready&&await this._.ready,this._.acc?.drain()};O[be]=function(e,t){return Me(this,e,t)};O.push=function(e,t){let r=this._.acc;if(!r)throw new Error("push: instance is not pushable \u2014 create with audio()");let n=this._.ch,l=this.sampleRate,i;if(Array.isArray(e)&&e[0]instanceof Float32Array)i=e;else if(e instanceof Float32Array)i=[e];else if(ArrayBuffer.isView(e)){let a=t||{},o=typeof a=="string"?a:a.format||"int16",s=a.channels||n,f={dtype:o,channels:s};s>1&&(f.interleaved=!0);let u=he(e,f,{dtype:"float32",interleaved:!1,channels:s}),c=u.length/s;i=Array.from({length:s},(h,d)=>u.subarray(d*c,(d+1)*c))}else throw new TypeError("push: expected Float32Array[], Float32Array, or typed array");if(!this._.ch)this._.ch=i.length,this._.chV=-1;else if(i.length!==this._.ch)throw new TypeError(`push: expected ${this._.ch} channels, got ${i.length}`);return r.push(i,t&&t.sampleRate||l),this._.len=r.length,this._.lenV=-1,this};O.stop=function(){if(this.playing=!1,this.paused=!1,this._._wake&&this._._wake(),this.recording&&(this.recording=!1,this._._mic&&(this._._mic(null),this._._mic=null)),this._.acc&&!this.decoded&&(this._.acc.drain(),this.decoded=!0,this._.waiters))for(let e of this._.waiters.splice(0))e();return this};O.record=function(e={}){if(!this._.acc)throw new Error("record: instance is not pushable \u2014 create with audio()");if(this.recording)return this;this.recording=!0,this.decoded=!1;let t=this,r=this.sampleRate,n=this._.ch;return(async()=>{try{let{default:i}=await Promise.resolve().then(()=>(At(),_t)),a=i({sampleRate:r,channels:n,bitDepth:16,...e});t._._mic=a,a((o,s)=>{t.recording&&(o||!s||t.push(new Int16Array(s.buffer,s.byteOffset,s.byteLength/2),"int16"))})}catch(i){if(t.recording=!1,t.decoded=!0,t._.waiters)for(let a of t._.waiters.splice(0))a();throw i.code==="ERR_MODULE_NOT_FOUND"?new Error("record: audio-mic not installed \u2014 npm i audio-mic"):i}})().catch(()=>{}),this};O.seek=function(e){if(e=Math.max(0,e),this.currentTime=e,this.cache){let t=Math.floor(e*this.sampleRate/m.PAGE_SIZE);(async()=>{for(let r=Math.max(0,t-1);r<=Math.min(t+2,this.pages.length-1);r++)this.pages[r]===null&&await this.cache.has(r)&&(this.pages[r]=await this.cache.read(r))})()}return this.playing&&(this._._seekTo=e,this._._wake&&this._._wake()),this};O.read=async function(e){(typeof e!="object"||e===null)&&(e={});let{at:t,duration:r,format:n,channel:l,meta:i}=e;t=S(t),r=S(r),await this[V]();let a=await this[be](t,r);if(l!=null&&(a=[a[l]]),!n)return l!=null?a[0]:a;let o=ee[n]?await ee[n](a,{sampleRate:this.sampleRate,...i}):a.map(s=>he(s,"float32",n));return l!=null&&Array.isArray(o)?o[0]:o};function bt(e){let t=e[0].length,r=[];for(let n=0;n<t;n+=m.PAGE_SIZE)r.push(e.map(l=>l.subarray(n,Math.min(n+m.PAGE_SIZE,t))));return r}function Te(e,t,r,n,l){let i=Math.floor(r/m.PAGE_SIZE),a=i*m.PAGE_SIZE;for(let o=i;o<e.pages.length&&a<r+n;o++){let s=e.pages[o],f=s?s[0].length:m.PAGE_SIZE;if(a+f>r&&s){let u=Math.max(r-a,0),c=Math.min(r+n-a,f);e._.lru&&(e._.lru.delete(o),e._.lru.add(o)),l(s,t,u,c,Math.max(a-r,0))}a+=f}}function de(e,t,r,n,l,i){Te(e,t,r,n,(a,o,s,f,u)=>l.set(a[o].subarray(s,f),i+u))}function Me(e,t,r){let n=e.sampleRate,l=e._.ch,i=t!=null?Math.min(Math.max(Math.round(t*n),0),e._.len):0,a=r!=null?Math.round(r*n):e._.len-i;a=Math.min(Math.max(a,0),e._.len-i);let o=Array.from({length:l},()=>new Float32Array(a));for(let s=0;s<l;s++)de(e,s,i,a,o[s],0);return o}async function De(e){if(e instanceof ArrayBuffer)return e;if(e instanceof Uint8Array)return e.buffer.slice(e.byteOffset,e.byteOffset+e.byteLength);if(e instanceof URL)return De(e.href);if(typeof e=="string"){if(/^(https?|data|blob):/.test(e)||typeof window<"u")return(await fetch(e)).arrayBuffer();if(e.startsWith("file:")){let{fileURLToPath:n}=await import("url");e=n(e)}let{readFile:t}=await import("fs/promises"),r=await t(e);return r.buffer.slice(r.byteOffset,r.byteOffset+r.byteLength)}throw new TypeError("audio: unsupported source type")}async function Cn(e){if(e instanceof ArrayBuffer||e instanceof Uint8Array){let n=e instanceof ArrayBuffer?new Uint8Array(e):e.byteOffset||e.byteLength!==e.buffer.byteLength?new Uint8Array(e.buffer.slice(e.byteOffset,e.byteOffset+e.byteLength)):new Uint8Array(e.buffer);return{format:N(n),bytes:n}}if(typeof e=="string"&&!/^(https?|data|blob):/.test(e)&&typeof window>"u"){let n=e;if(e.startsWith("file:")){let{fileURLToPath:f}=await import("url");n=f(e)}let{open:l}=await import("fs/promises"),i=await l(n,"r"),a=new Uint8Array(12);await i.read(a,0,12,0),await i.close();let o=N(new Uint8Array(a)),{createReadStream:s}=await import("fs");return{format:o,reader:s(n)}}let t=await De(e),r=new Uint8Array(t);return{format:N(r),bytes:r}}function Mt(e={}){let{pages:t=[],notify:r,ondata:n}=e,l=0,i=0,a=0,o=0,s=null,f;function u(c){t.push(c),a+=c[0].length,r?.()}return{pages:t,get sampleRate(){return l},get channels(){return i},get length(){return a+o},get partial(){return o>0?s.map(c=>c.subarray(0,o)):null},get partialLen(){return o},push(c,h){s||(l=h,i=c.length,s=Array.from({length:i},()=>new Float32Array(m.PAGE_SIZE)),f=m.statSession?.(l)),f?.page(c);let d=0,p=c[0].length;for(;d<p;){let g=Math.min(p-d,m.PAGE_SIZE-o);for(let w=0;w<i;w++)s[w].set(c[w].subarray(d,d+g),o);d+=g,o+=g,o===m.PAGE_SIZE&&(u(s),s=Array.from({length:i},()=>new Float32Array(m.PAGE_SIZE)),o=0)}if(n){let g=f?.delta();g&&n({delta:g,offset:(a+o)/l,sampleRate:l,channels:i,pages:t})}r?.()},drain(){o>0&&(u(s.map(c=>c.slice(0,o))),s=Array.from({length:i},()=>new Float32Array(m.PAGE_SIZE)),o=0)},done(){if(o>0&&u(s.map(c=>c.slice(0,o))),f?.flush(),n&&f){let c=f.delta();c&&n({delta:c,offset:a/l,sampleRate:l,channels:i,pages:t})}return{stats:f?.done(),length:a}}}}async function Pn(e,t={}){let{format:r,bytes:n,reader:l}=await Cn(e);if(!r||!z[r]){n||(n=new Uint8Array(await De(e)));let{channelData:h,sampleRate:d}=await z(n.buffer||n),p=t.pages||[],g=bt(h);for(let y of g)p.push(y),t.notify?.();let w=m.statSession?.(d)?.page(h)?.done()??null;return{pages:p,sampleRate:d,channels:h.length,decoding:Promise.resolve({stats:w,length:h[0].length})}}let i=await z[r](),a=()=>new Promise(h=>setTimeout(h,0)),o,s=t.notify,f=new Promise(h=>{o=h}),u=Mt({pages:t.pages,ondata:t.ondata,notify:()=>{if(s?.(),o){let h=o;o=null,h()}}}),c=(async()=>{try{if(l)for await(let p of l){let g=p instanceof Uint8Array?p:new Uint8Array(p),w=await i(g);w.channelData.length&&u.push(w.channelData,w.sampleRate),await a()}else{let p=65536;for(let g=0;g<n.length;g+=p){let w=await i(n.subarray(g,Math.min(g+p,n.length)));w.channelData.length&&u.push(w.channelData,w.sampleRate),await a()}}let h=await i();return h.channelData.length&&u.push(h.channelData,h.sampleRate),u.done()}catch(h){if(o){let d=o;o=null,d()}throw h}})();if(await f,!u.sampleRate)throw new Error("audio: decoded no audio data");return{pages:u.pages,sampleRate:u.sampleRate,channels:u.channels,decoding:c,acc:u}}var j=m.fn,K={};function v(e,t,r,n,l){let i=[e,t,r];return n!=null&&n!==1&&(i[3]=n),l!==void 0&&(i[4]=l),i}function q(e,t,r=0){let n=e??r;return n<0&&(n=t+n),Math.min(Math.max(0,n),t)}function H(e,t){let r=e.sampleRate,n=e.at!=null?Math.round(e.at*r):0;return[n,e.duration!=null?n+Math.round(e.duration*r):t]}function On(e){return e!=null&&typeof e=="object"&&!Array.isArray(e)&&!ArrayBuffer.isView(e)&&!e.pages&&!e.getChannelData}m.op=function(e,t,r,n){if(!arguments.length)return K;if(arguments.length===1)return K[e];let l;if(typeof t!="function")l=t;else{let i,a;typeof r=="function"?(i=r,a=n):a=r,l={process:t},i&&(l.plan=i),a&&Object.assign(l,a)}if(!j[e]&&!l.hidden){let i=function(...a){let o={type:e,args:a},s=a[a.length-1];if(a.length&&On(s)){let{at:f,duration:u,channel:c,offset:h,length:d,...p}=s;o.args=a.slice(0,-1),f!=null&&(o.at=S(f)),u!=null&&(o.duration=S(u)),h!=null&&(o.offset=h),d!=null&&(o.length=d),c!=null&&(o.channel=c),Object.assign(o,p)}return this.run(o)};j[e]=l.call?function(...a){return l.call.call(this,i,...a)}:i}K[e]=l};function kt(e,t){e.edits.push(t),e.version++,D(e,"change")}function Ln(e){let t=e.edits.pop();return t&&(e.version++,D(e,"change")),t}Object.defineProperties(j,{length:{get(){if(this._.lenV===this.version)return this._.lenC;let e=this.edits.length?Y(this).totalLen:this._.len;return this._.lenC=e,this._.lenV=this.version,e},configurable:!0},channels:{get(){if(this._.chV===this.version)return this._.chC;let e=this._.ch;for(let t of this.edits)K[t.type]?.ch&&(e=K[t.type].ch(e,t.args));return this._.chC=e,this._.chV=this.version,e},configurable:!0}});async function ae(e,t,r,n){if(!m.ensurePages)return;let{segs:l,sr:i}=t,a=Math.round((r||0)*i),o=n!=null?a+Math.round(n*i):t.totalLen;for(let s of l){let f=Math.max(a,s[2]),u=Math.min(o,s[2]+s[1]);if(f>=u)continue;let c=Math.abs(s[3]||1),h=s[0]+(f-s[2])*c,d=(u-f)*c+1,p=s[4]===null?null:s[4]||e;p&&await m.ensurePages(p,h/i,d/i)}}async function vt(e){for(let{args:t}of e.edits)t?.[0]?.pages&&await t[0][V]()}j[be]=async function(e,t){if(!this.edits.length)return m.ensurePages&&await m.ensurePages(this,e,t),Me(this,e,t);await this[V](),await vt(this);let r=Y(this);return await ae(this,r,e,t),Ue(this,r,e,t)};j[Symbol.asyncIterator]=j.stream=async function*(e){let t=S(e?.at),r=S(e?.duration);if(this._.waiters&&!this.decoded&&!this.edits.length){let i=this.sampleRate,a=this._.acc,o=m.PAGE_SIZE,s=t?Math.round(t*i):0,f=r!=null?s+Math.round(r*i):1/0,u=s;for(;u<f;){let c=a?this.pages.length*o+a.partialLen:this._.len;for(;u>=c&&!this.decoded;)await new Promise(g=>this._.waiters.push(g)),c=a?this.pages.length*o+a.partialLen:this._.len;if(u>=c)break;let h=Math.min(f,c),d=Math.floor(u/o),p=u%o;if(d<this.pages.length){let g=this.pages[d],w=Math.min(g[0].length-p,h-u);yield g.map(y=>y.subarray(p,p+w)),u+=w}else if(a){let g=Math.min(a.partialLen-p,h-u);g>0&&(yield a.partial.map(w=>w.subarray(p,p+g).slice()),u+=g)}}return}await this.ready,await this[V](),await vt(this);let n=Y(this),l=new Set;for(let i of n.segs)i[4]&&i[4]!==null&&!l.has(i[4])&&(l.add(i[4]),await i[4][V]());await ae(this,n,t,r);for(let i of oe(this,n,t,r))yield i};j.undo=function(e=1){if(!this.edits.length)return e===1?null:[];let t=[];for(let r=0;r<e&&this.edits.length;r++)t.push(Ln(this));return e===1?t[0]:t};j.run=function(...e){let t=this.sampleRate;for(let r of e){if(!r.type)throw new TypeError("audio.run: edit must have type");let n={...r,args:r.args||[]};n.at!=null&&(n.at=S(n.at)),n.duration!=null&&(n.duration=S(n.duration)),n.offset!=null&&(n.at=n.offset/t,delete n.offset),n.length!=null&&(n.duration=n.length/t,delete n.length),kt(this,n)}return this};j.toJSON=function(){let e=this.edits.filter(t=>!t.args?.some(r=>typeof r=="function"));return{source:this.source,edits:e,sampleRate:this.sampleRate,channels:this.channels,duration:this.duration}};j.clone=function(){let e=m.from(this);for(let t of this.edits)kt(e,{...t});return e};var In=2**29;function St(e,t,r){if(Array.isArray(e)&&e[0]instanceof Float32Array)return t!=null?e.map(a=>a.subarray(t,t+r)):e;if(e?.getChannelData&&!e.pages){let a=Array.from({length:e.numberOfChannels},(o,s)=>new Float32Array(e.getChannelData(s)));return t!=null?a.map(o=>o.subarray(t,t+r)):a}if(t!=null)return Ct(e,t,r);if(e._.pcm&&e._.pcmV===e.version)return e._.pcm;if(!e.edits.length){let a=Me(e);return e._.pcm=a,e._.pcmV=e.version,a}let n=Y(e),l=me(n.segs);if(l>In)throw new Error(`Audio too large for flat render (${(l/1e6).toFixed(0)}M samples). Use streaming.`);let i=Ue(e,n);return e._.pcm=i,e._.pcmV=e.version,i}function me(e){let t=0;for(let r of e)t=Math.max(t,r[2]+r[1]);return t}function Y(e){if(e._.plan&&e._.planV===e.version)return e._.plan;let t=e.sampleRate,r=e._.ch,n=[[0,e._.len,0]],l=[];for(let a of e.edits){let{type:o,args:s=[],at:f,duration:u,channel:c,...h}=a,d=K[o];if(!d)throw new Error(`Unknown op: ${o}`);if(d.resolve){let p={...h,stats:e._.srcStats||e.stats,sampleRate:t,channelCount:r,channel:c,at:f,duration:u,totalDuration:me(n)/t},g=d.resolve(s,p);if(g===!1)continue;if(g){let w=Array.isArray(g)?g:[g];for(let y of w){c!=null&&y.channel==null&&(y.channel=c),f!=null&&y.at==null&&(y.at=f),u!=null&&y.duration==null&&(y.duration=u);let _=K[y.type];if(_?.plan&&typeof _.plan=="function"){let A=me(n),b=y.at!=null?Math.round(y.at*t):null,M=y.duration!=null?Math.round(y.duration*t):null;n=_.plan(n,{total:A,sampleRate:t,args:y.args||[],offset:b,length:M})}else l.push(y)}continue}}if(d.plan){let p=me(n),g=f!=null?Math.round(f*t):null,w=u!=null?Math.round(u*t):null;n=d.plan(n,{total:p,sampleRate:t,args:s,offset:g,length:w})}else l.push(a)}let i={segs:n,pipeline:l,totalLen:me(n),sr:t};return e._.plan=i,e._.planV=e.version,i}var xt=null,Rt=0;function Et(e,t,r,n,l,i,a){let o=a||1,s=Math.abs(o);if(s===1)return o>0?de(e,t,r,n,l,i):Te(e,t,r,n,(c,h,d,p,g)=>{for(let w=d;w<p;w++)l[i+(n-1-(g+w-d))]=c[h][w]});let f=Math.ceil(n*s)+1;f>Rt&&(Rt=f,xt=new Float32Array(f));let u=xt.subarray(0,f);u.fill(0),de(e,t,r,f,u,0),Ft(u,l,i,n,o)}function Ft(e,t,r,n,l){let i=Math.abs(l),a=l<0;for(let o=0;o<n;o++){let s=(a?n-1-o:o)*i,f=s|0,u=s-f;t[r+o]=f+1<e.length?e[f]+(e[f+1]-e[f])*u:e[f]||0}}function Ct(e,t,r){if(!e.edits.length)return Array.from({length:e._.ch},(i,a)=>{let o=new Float32Array(r);return de(e,a,t,r,o,0),o});let n=Y(e),l=n.sr;return Ue(e,n,t/l,r/l)}function*oe(e,t,r,n){let{segs:l,pipeline:i,totalLen:a,sr:o}=t,s=Math.round((r||0)*o),f=n!=null?s+Math.round(n*o):a,u=a/o,c=i.map(p=>{let g=K[p.type],{type:w,args:y,at:_,duration:A,channel:b,...M}=p;return{op:g.process,at:_!=null&&_<0?u+_:_,dur:A,channel:b,ctx:{...M,args:y||[],duration:A,sampleRate:o,totalDuration:u,render:St}}}),d=s>0&&c.length?Math.max(0,s-m.BLOCK_SIZE*8):s;for(let p=d;p<f;p+=m.BLOCK_SIZE){let g=p<s?s:f,w=Math.min(m.BLOCK_SIZE,g-p),y=Array.from({length:e._.ch},()=>new Float32Array(w));for(let A of l){let b=Math.max(p,A[2]),M=Math.min(p+w,A[2]+A[1]);if(b>=M)continue;let x=A[3]||1,R=A[4],E=Math.abs(x),F=M-b,I=b-p,L=x<0?A[0]+(A[1]-(b-A[2])-F)*E:A[0]+(b-A[2])*E;if(R!==null)if(R)if(R.edits.length===0)for(let P=0;P<e._.ch;P++)Et(R,P%R._.ch,L,F,y[P],I,x);else{let P=Math.ceil(F*E)+1,X=Ct(R,L,P);for(let B=0;B<e._.ch;B++){let Z=X[B%X.length];if(E===1)if(x<0)for(let Q=0;Q<F;Q++)y[B][I+Q]=Z[F-1-Q];else y[B].set(Z.subarray(0,F),I);else Ft(Z,y[B],I,F,x)}}else for(let P=0;P<e._.ch;P++)Et(e,P,L,F,y[P],I,x)}let _=p/o;for(let A of c){let{op:b,at:M,channel:x,ctx:R}=A;if(b)if(R.at=M!=null?M-_:void 0,R.blockOffset=_,x!=null){let E=typeof x=="number"?[x]:x,F=E.map(L=>y[L]),I=b(F,R);if(I&&I!==!1)for(let L=0;L<E.length;L++)y[E[L]]=I[L]}else{let E=b(y,R);if(E===!1||E===null)continue;E&&(y=E)}}p>=s&&(yield y)}}function Ue(e,t,r,n){let l=[];for(let o of oe(e,t,r,n))l.push(o);if(!l.length)return Array.from({length:e.channels},()=>new Float32Array(0));let i=l[0].length,a=l.reduce((o,s)=>o+s[0].length,0);return Array.from({length:i},(o,s)=>{let f=new Float32Array(a),u=0;for(let c of l)f.set(c[s],u),u+=c[0].length;return f})}var Tn=500*1024*1024;async function Dn(e){if(!e.cache||e.budget===1/0)return;let t=l=>l?l.reduce((i,a)=>i+a.byteLength,0):0,r=e.pages.reduce((l,i)=>l+t(i),0);if(r<=e.budget)return;let n=e._.lru&&e._.lru.size?[...e._.lru]:e.pages.map((l,i)=>i);for(let l of n){if(r<=e.budget)break;e.pages[l]&&(await e.cache.write(l,e.pages[l]),r-=t(e.pages[l]),e.pages[l]=null,e._.lru&&e._.lru.delete(l))}}async function Un(e,t,r){if(!e.cache)return;let n=m.PAGE_SIZE,l=e.sampleRate,i=t!=null?Math.max(0,Math.round(t*l)):0,a=r!=null?Math.round(r*l):e._.len-i,o=Math.floor(i/n),s=Math.min(Math.ceil((i+a)/n),e.pages.length);for(let f=o;f<s;f++)e.pages[f]===null&&await e.cache.has(f)&&(e.pages[f]=await e.cache.read(f))}async function Bn(e="audio-cache"){if(typeof navigator>"u"||!navigator.storage?.getDirectory)throw new Error("OPFS not available in this environment");let r=await(await navigator.storage.getDirectory()).getDirectoryHandle(e,{create:!0});return{async read(n){let a=await(await(await r.getFileHandle(`p${n}`)).getFile()).arrayBuffer(),o=new Float32Array(a),s=o[0]|0,f=(o.length-1)/s|0,u=[];for(let c=0;c<s;c++)u.push(o.slice(1+c*f,1+(c+1)*f));return u},async write(n,l){let a=await(await r.getFileHandle(`p${n}`,{create:!0})).createWritable(),o=1+l.reduce((u,c)=>u+c.length,0),s=new Float32Array(o);s[0]=l.length;let f=1;for(let u of l)s.set(u,f),f+=u.length;await a.write(s.buffer),await a.close()},has(n){return r.getFileHandle(`p${n}`).then(()=>!0,()=>!1)},async evict(n){try{await r.removeEntry(`p${n}`)}catch{}},async clear(){for await(let[n]of r)await r.removeEntry(n)}}}m.opfsCache=Bn;m.evict=Dn;m.ensurePages=Un;m.DEFAULT_BUDGET=Tn;var Be={};m.stat=function(e,t){if(!arguments.length)return Be;if(arguments.length===1)return Be[e];typeof t=="function"&&(t={block:t}),Be[e]=t};function xe(e){let t,r,n,l=0,i=null,a=0;function o(f){n=f,t=Object.entries(m.stat()).filter(([u,c])=>c.block).map(([u,c])=>({name:u,fn:c.block,ctx:{sampleRate:e}})),r=Object.create(null);for(let{name:u}of t)r[u]=Array.from({length:n},()=>[])}function s(f){for(let{name:u,fn:c,ctx:h}of t){let d=c(f,h);if(typeof d=="number")for(let p=0;p<n;p++)r[u][p].push(d);else for(let p=0;p<n;p++)r[u][p].push(d[p])}}return{page(f){r||o(f.length);let u=m.BLOCK_SIZE,c=0,h=f[0].length;if(a>0){let d=u-a;if(h>=d){for(let p=0;p<n;p++)i[p].set(f[p].subarray(0,d),a);s(i),c=d,a=0}else{for(let p=0;p<n;p++)i[p].set(f[p].subarray(0,h),a);return a+=h,this}}for(;c+u<=h;)s(Array.from({length:n},(d,p)=>f[p].subarray(c,c+u))),c+=u;if(c<h){i||(i=Array.from({length:n},()=>new Float32Array(u)));for(let d=0;d<n;d++)i[d].set(f[d].subarray(c));a=h-c}return this},flush(){a>0&&(s(Array.from({length:n},(f,u)=>i[u].subarray(0,a))),a=0)},delta(){if(!r)return;let f=Object.keys(r)[0];if(!f)return;let u=r[f][0].length;if(u<=l)return;let c={fromBlock:l};for(let h in r)c[h]=r[h].map(d=>new Float32Array(d.slice(l)));return l=u,c},done(){this.flush();let f={blockSize:m.BLOCK_SIZE};if(r)for(let u in r)f[u]=r[u].map(c=>new Float32Array(c));return f}}}function jn(e,t,r,n,l){if(n<=0||r<=t)return new Float32Array(Math.max(0,n));if(t=Math.max(0,t),r=Math.min(r,e.length),r<=t)return new Float32Array(n);let i=new Float32Array(n),a=(r-t)/n;for(let o=0;o<n;o++){let s=t+Math.floor(o*a),f=Math.min(t+Math.floor((o+1)*a),r);f<=s&&(f=s+1),i[o]=l(e,s,f)}return i}function qn(e,t,r){let n=e.blockSize,l=t.segs,i=t.totalLen;for(let u of l){let c=u[3]||1,h=u[4];if(h!=null||Math.abs(c)!==1||u[0]%n!==0||u[2]%n!==0)return null}let a=Math.ceil(i/n),o=Object.keys(e).filter(u=>u!=="blockSize"&&Array.isArray(e[u])),s=e[o[0]]?.length||1,f={blockSize:n};for(let u of o)f[u]=Array.from({length:s},()=>new Float32Array(a));for(let u of l){let c=u[0],h=u[1],d=u[2],p=u[3]||1,g=u[4],w=Math.floor(d/n),y=Math.ceil((d+h)/n);if(g===null)continue;let _=Math.floor(c/n),A=e[o[0]][0].length,b=p<0;for(let M=w;M<y&&M<a;M++){let x=b?_+(y-1-M):_+(M-w);if(!(x<0||x>=A))for(let R of o)for(let E=0;E<s;E++)f[R][E][M]=e[R][E][x]}}return f}m.statSession=xe;async function je(e,t){await e[V]();let r=S(t?.at),n=S(t?.duration),l=r!=null||n!=null;if(e.edits?.length&&e._.statsV!==e.version){if(e._.srcStats||(e._.srcStats=e.stats),l){let d=Y(e);await ae(e,d,r||0,n);let p=xe(e.sampleRate);for(let _ of oe(e,d,r||0,n))p.page(_);let g=p.done(),y=Object.values(g).find(_=>_?.[0]?.length)?.[0]?.length||0;return{stats:g,ch:e.channels,sr:e.sampleRate,from:0,to:y}}let h=Y(e);if(!h.pipeline.length&&e._.srcStats?.blockSize){let d=qn(e._.srcStats,h,e.sampleRate);if(d)e.stats=d,e._.statsV=e.version;else{let p=xe(e.sampleRate);await ae(e,h);for(let g of oe(e,h))p.page(g);e.stats=p.done(),e._.statsV=e.version}}else{let d=xe(e.sampleRate);await ae(e,h);for(let p of oe(e,h))d.page(p);e.stats=d.done(),e._.statsV=e.version}}let i=e.sampleRate,a=e.stats?.blockSize;if(!a)return{stats:e.stats,ch:e.channels,sr:i,from:0,to:0};let s=Object.values(e.stats).find(h=>h?.[0]?.length)?.[0]?.length||0,f=r!=null&&r<0?e.duration+r:r,u=f!=null?Math.floor(f*i/a):0,c=n!=null?Math.ceil(((f||0)+n)*i/a):s;return u=Math.max(0,Math.min(u,s)),c=Math.max(u,Math.min(c,s)),{stats:e.stats,ch:e.channels,sr:i,from:u,to:c}}m.fn.stat=async function(e,t){if(Array.isArray(e))return Promise.all(e.map(g=>this.stat(g,t)));if(typeof this[e]=="function"&&!m.stat(e))return this[e](t);let{stats:r,ch:n,sr:l,from:i,to:a}=await je(this,t),o=t?.bins,s=t?.channel,f=Array.isArray(s),u=s!=null?f?s:[s]:Array.from({length:n},(g,w)=>w),c=m.stat(e);if(c?.query&&o==null)return c.query(r,u,i,a,l);let h=r[e],d=c?.reduce;if(!h)throw new Error(`Unknown stat: '${e}'`);if(!d)throw new Error(`No reducer for stat: '${e}'`);if(o!=null){let g=o??a-i,w=A=>jn(h[A],i,a,g,d);if(f)return u.map(w);if(u.length===1)return w(u[0]);let y=new Float32Array(g),_=(a-i)/g;for(let A=0;A<g;A++){let b=i+Math.floor(A*_),M=Math.min(i+Math.floor((A+1)*_),a);M<=b&&(M=b+1);let x=0;for(let R of u)x+=d(h[R],b,M);y[A]=x/u.length}return y}if(f)return u.map(g=>d(h[g],i,a));if(u.length===1)return d(h[u[0]],i,a);let p=u.map(g=>d(h[g],i,a));return p.reduce((g,w)=>g+w,0)/p.length};function qe(e,t,r){let n=[],l=t+r;for(let i of e){let a=Math.max(i[2],t),o=Math.min(i[2]+i[1],l);a<o&&n.push(v(i[0]+(a-i[2])*Math.abs(i[3]||1),o-a,a-t,i[3],i[4]))}return n}var Qn=(e,t)=>{let{total:r,length:n}=t,l=q(t.offset,r);return qe(e,l,Math.max(0,Math.min(n??r-l,r-l)))};m.op("crop",{plan:Qn});m.fn.clip=function(e){let t=this.clone?this.clone():m.from(this),r=S(e?.at),n=S(e?.duration);return r!=null||n!=null?t.crop({at:r??0,duration:n??Math.max(0,this.duration-(r??0))}):t};m.fn.split=function(...e){let t=(Array.isArray(e[0])?e[0]:e).map(S),r=this.duration,n=[0,...t.sort((l,i)=>l-i).filter(l=>l>0&&l<r),r];return n.slice(0,-1).map((l,i)=>this.clip({at:l,duration:n[i+1]-l}))};import Vn from"audio-speaker";function Qe(e,t,r,n,l){let i=Math.min(l,r);if(n)for(let a=0;a<i;a++){let o=a/i;for(let s=0;s<t;s++)e[a*t+s]*=o}else{let a=r-i;for(let o=0;o<i;o++){let s=1-o/i;for(let f=0;f<t;f++)e[(a+o)*t+f]*=s}}}m.fn.play=function(e){let t=e?.at??0,r=e?.duration,n=this,l=m.BLOCK_SIZE;return n.playing&&(n.playing=!1,n.paused=!1,n._._wake&&n._._wake()),n.playing=!1,n.paused=e?.paused??!1,n.currentTime=t,n.volume=e?.volume??0,n.loop=e?.loop??!1,n.block=null,n._._wake=null,n._._seekTo=null,(async()=>{try{let i=n.channels,a=n.sampleRate;n.playing=!0;let o=async()=>{for(;n.paused&&n.playing&&n._._seekTo==null;)await new Promise(u=>{n._._wake=u});n._._wake=null},s=t,f=256;for(;n.playing;){if(n.paused){if(await o(),!n.playing)break;n._._seekTo!=null&&(s=n._._seekTo,n._._seekTo=null,n.currentTime=s)}let u=Vn({sampleRate:a,channels:i,bitDepth:32}),c=!1,h=0,d=!0,p=async()=>{let g=new Uint8Array(l*i*4);await new Promise(w=>u(g,w)),await new Promise(w=>u(g,w))};for await(let g of n.stream({at:s,duration:r})){if(!n.playing)break;let w=g[0].length;for(let y=0;y<w;y+=l){if(n._._seekTo!=null){s=n._._seekTo,n._._seekTo=null,n.currentTime=s,c=!0;break}let _=Math.min(y+l,w),A=_-y;n.block=g[0].subarray(y,_);let b=10**(n.volume/20),M=new Float32Array(A*i);for(let R=0;R<A;R++)for(let E=0;E<i;E++)M[R*i+E]=(g[E]||g[0])[y+R]*b;let x=()=>new Promise(R=>u(new Uint8Array(M.buffer),R));if(d&&(Qe(M,i,A,!0,f),d=!1),n.paused){if(Qe(M,i,A,!1,f),await x(),await p(),h+=A,n.currentTime=s+h/a,await o(),n._._seekTo!=null)continue;if(!n.playing)break;d=!0;continue}if(!n.playing){Qe(M,i,A,!1,f),await x();break}await x(),h+=A,n._._seekTo==null&&(n.currentTime=s+h/a,D(n,"timeupdate",n.currentTime))}if(c||!n.playing)break}if(!c&&!n.playing&&await p(),c&&(await p(),d=!0),u(null),!c){if(!n.playing)break;if(n.loop){s=0,n.currentTime=0,D(n,"timeupdate",0);continue}n.playing=!1,D(n,"timeupdate",n.currentTime);break}}n.playing=!1,D(n,"ended")}catch(i){console.error("Playback error:",i),n.playing=!1}})(),this};var Pt=m.fn;Pt.pause=function(){this.paused=!0};Pt.resume=function(){this.paused=!1,this._._wake&&this._._wake()};var Zn={aif:"aiff",oga:"ogg"};function Ot(e){return Zn[e]||e||"wav"}async function Lt(e,t,r,n){let l=await ee[t]({sampleRate:e.sampleRate,channels:e.channels,...r.meta}),i=0,a=0;for await(let s of e.stream({at:r.at,duration:r.duration})){let f=await l(s);f.length&&await n(f),i+=s[0].length,++a%2===0&&await new Promise(u=>setTimeout(u,0)),D(e,"progress",{offset:i/e.sampleRate,total:(r.duration!=null?S(r.duration):null)??e.duration})}let o=await l();return o.length&&await n(o),n(null)}m.fn.encode=async function(e,t={}){if(typeof e=="object"&&(t=e,e=void 0),e=Ot(e),!ee[e])throw new Error("Unknown format: "+e);let r=[];await Lt(this,e,t,a=>{a&&r.push(a)});let n=r.reduce((a,o)=>a+o.length,0),l=new Uint8Array(n),i=0;for(let a of r)l.set(a,i),i+=a.length;return l};m.fn.save=async function(e,t={}){let r=t.format??(typeof e=="string"?e.split(".").pop():"wav");if(r=Ot(r),!ee[r])throw new Error("Unknown format: "+r);let n,l;if(typeof e=="string"){let{createWriteStream:i}=await import("fs"),a=i(e);n=o=>{if(!a.write(Buffer.from(o)))return new Promise(s=>a.once("drain",s))},l=()=>new Promise((o,s)=>{a.on("finish",o),a.on("error",s),a.end()})}else if(e?.write)n=i=>e.write(i),l=()=>e.close?.();else throw new Error("Invalid save target");await Lt(this,r,t,i=>i?n(i):l?.())};function zn(e,t,r){let n=[],l=t+r;for(let i of e){let a=i[2]+i[1];if(a<=t)n.push(i);else if(i[2]>=l){let o=i.slice();o[2]=i[2]-r,n.push(o)}else{let o=Math.abs(i[3]||1);i[2]<t&&n.push(v(i[0],t-i[2],i[2],i[3],i[4])),a>l&&n.push(v(i[0]+(l-i[2])*o,a-l,t,i[3],i[4]))}}return n}var Gn=(e,t)=>{let{total:r}=t,n=q(t.offset,r);return zn(e,n,Math.min(t.length??r-n,r-n))};m.op("remove",{plan:Gn});function Wn(e,t,r,n){let l=[];for(let i of e)if(i[2]+i[1]<=t)l.push(i);else if(i[2]>=t){let a=i.slice();a[2]=i[2]+r,l.push(a)}else{let a=t-i[2],o=Math.abs(i[3]||1);l.push(v(i[0],a,i[2],i[3],i[4])),l.push(v(i[0]+a*o,i[1]-a,t+r,i[3],i[4]))}return l.push(v(0,r,t,void 0,n??null)),l.sort((i,a)=>i[2]-a[2]),l}var $n=(e,t)=>{let{total:r,sampleRate:n,args:l}=t,i=l[0],a=q(t.offset,r,r);typeof i!="number"&&!i?.pages&&(i=m.from(i,{sampleRate:n}));let o=typeof i=="number"?Math.round(i*n):i.length;return t.length!=null&&(o=Math.min(o,t.length)),Wn(e,a,o,typeof i=="number"?null:i)};m.op("insert",{plan:$n});function Kn(e,t,r,n,l){if(n==null){let s=[];for(let f=0;f<=t;f++)for(let u of e){let c=u.slice();c[2]=u[2]+r*f,s.push(c)}return s}let i=l??r-n,a=qe(e,n,i),o=[];for(let s of e){let f=s[2]+s[1];if(f<=n+i)o.push(s);else if(s[2]>=n+i){let u=s.slice();u[2]=s[2]+i*t,o.push(u)}else{let u=Math.abs(s[3]||1),c=n+i-s[2];o.push(v(s[0],c,s[2],s[3],s[4])),o.push(v(s[0]+c*u,f-n-i,n+i*(t+1),s[3],s[4]))}}for(let s=1;s<=t;s++)for(let f of a){let u=f.slice();u[2]=n+i*s+f[2],o.push(u)}return o.sort((s,f)=>s[2]-f[2]),o}var Hn=(e,t)=>{let{total:r,args:n,length:l}=t,i=t.offset!=null?q(t.offset,r):null;return Kn(e,n[0]??1,r,i,l)};m.op("repeat",{plan:Hn});var Yn=(e,t)=>{let r=t.unit==="linear",n=t.args[0]??(r?1:0),[l,i]=H(t,e[0].length),a=typeof n=="function",o=a?0:r?n:10**(n/20),s=(t.blockOffset||0)*t.sampleRate,f=r?u=>u:u=>10**(u/20);for(let u of e)for(let c=Math.max(0,l);c<Math.min(i,u.length);c++)u[c]*=a?f(n((s+c)/t.sampleRate)):o;return e};m.op("gain",{process:Yn});var It={linear:e=>e,exp:e=>e*e,log:e=>Math.sqrt(e),cos:e=>(1-Math.cos(e*Math.PI))/2},Jn=(e,t)=>{let r=t.args[0],n=It[t.curve]??It.linear,l=r>0,i=Math.abs(r),a=t.sampleRate,o=t.blockOffset||0,s=t.at!=null?t.at+o:void 0;s!=null&&s<0&&(s=t.totalDuration+s);let f=Math.round((t.totalDuration||e[0].length/a+o)*a),u=s!=null?Math.round(s*a):l?0:f-Math.round(i*a),c=Math.round(i*a),h=Math.round(o*a);for(let d of e)for(let p=0;p<d.length;p++){let g=h+p-u;g<0||g>=c||(d[p]*=n(l?g/c:1-g/c))}return e};m.op("fade",{process:Jn,call(e,...t){let r=t[t.length-1],n=typeof r=="object"?t.pop():typeof r=="string"?{curve:t.pop()}:null;typeof t[t.length-1]=="string"&&(n={...n,curve:t.pop()});let[l,i]=t;return i!=null?(e.call(this,Math.abs(l),n||{}),e.call(this,-Math.abs(i),n||{})):n?e.call(this,l,n):e.call(this,l)}});function Xn(e,t,r){let n=[];for(let l of e){let i=l[2]+l[1];if(i<=t||l[2]>=r){n.push(l);continue}let a=Math.abs(l[3]||1);l[2]<t&&n.push(v(l[0],t-l[2],l[2],l[3],l[4]));let o=Math.max(l[2],t),s=Math.min(i,r);n.push(v(l[0]+(o-l[2])*a,s-o,t+r-s,-(l[3]||1),l[4])),i>r&&n.push(v(l[0]+(r-l[2])*a,i-r,r,l[3],l[4]))}return n.sort((l,i)=>l[2]-i[2]),n}var Nn=(e,t)=>{let{total:r,length:n}=t,l=q(t.offset,r);return Xn(e,l,l+(n??r-l))};m.op("reverse",{plan:Nn});var er=(e,t)=>{let r=t.args[0],n=t.sampleRate,l=e[0].length;if(typeof r=="number")throw new TypeError("mix: expected audio instance or Float32Array[], not a number");let i=Array.isArray(r)?r[0].length:r.length,[a]=H(t,l),o=Math.max(0,-a),s=Math.max(0,a),f=Math.min(i-o,l-s);if(t.duration!=null&&(f=Math.min(f,Math.round(t.duration*n)-o)),f<=0)return e;let u=t.render(r,o,f);for(let c=0;c<e.length;c++){let h=u[c%u.length];for(let d=0;d<f;d++)e[c][s+d]+=h[d]}return e};m.op("mix",{process:er});var tr=(e,t)=>{let r=t.args[0],[n,l]=H(t,e[0].length),i=Math.max(0,-n),a=Math.max(0,n);for(let o=0;o<e.length;o++){let s=Array.isArray(r)?r[o]||r[0]:r;for(let f=i;f<s.length&&a+f-i<l;f++)e[o][a+f-i]=s[f]}return e};m.op("write",{process:tr});var nr=(e,t)=>{let r=t.args[0],n=e[0].length;if(Array.isArray(r))return r.map(a=>a==null?new Float32Array(n):new Float32Array(e[(a%e.length+e.length)%e.length]));let l=e.length,i=r;if(l===i)return!1;if(i<l){let a=new Float32Array(n);for(let s=0;s<l;s++)for(let f=0;f<n;f++)a[f]+=e[s][f];let o=1/l;for(let s=0;s<n;s++)a[s]*=o;return Array.from({length:i},()=>new Float32Array(a))}return Array.from({length:i},(a,o)=>new Float32Array(e[o%l]))},rr=(e,t)=>Array.isArray(t[0])?t[0].length:t[0];m.op("remix",{process:nr,ch:rr});function Tt(e){let t=e.filter(n=>n>0);if(!t.length)return-40;t.sort((n,l)=>n-l);let r=t[Math.floor(t.length*.1)];return Math.max(-80,Math.min(-20,10*Math.log10(r)+12))}function Ve(e,t,r,n,l){if(l==null){let i=[];for(let a=0;a<t;a++)for(let o=r;o<n;o++)i.push(e.energy[a][o]);l=Tt(i)}return 10**(l/20)}var Re=(e,t,r,n)=>{for(let l=0;l<r;l++)if(Math.max(Math.abs(e.min[l][t]),Math.abs(e.max[l][t]))>n)return!0;return!1},lr=(e,t)=>{let r=t.args[0];if(r==null){let o=[];for(let s=0;s<e.length;s++)for(let f=0;f<e[s].length;f+=m.BLOCK_SIZE){let u=Math.min(f+m.BLOCK_SIZE,e[s].length),c=0;for(let h=f;h<u;h++)c+=e[s][h]*e[s][h];o.push(c/(u-f))}r=Tt(o)}let n=10**(r/20),l=e[0].length,i=0,a=l-1;for(;i<l;i++){let o=!1;for(let s=0;s<e.length;s++)if(Math.abs(e[s][i])>n){o=!0;break}if(o)break}for(;a>=i;a--){let o=!1;for(let s=0;s<e.length;s++)if(Math.abs(e[s][a])>n){o=!0;break}if(o)break}return a++,i===0&&a===l?!1:e.map(o=>o.slice(i,a))},ir=(e,{stats:t,sampleRate:r,totalDuration:n})=>{if(!t?.min||!t?.energy)return null;let l=t.min.length,i=t.min[0].length,a=Math.round(n*r),o=Ve(t,l,0,t.energy[0].length,e[0]),s=0,f=i-1;for(;s<i&&!Re(t,s,l,o);s++);for(;f>=s&&!Re(t,f,l,o);f--);if(f++,s===0&&f===i)return!1;if(s>=f)return{type:"crop",args:[],at:0,duration:0};let u=s*m.BLOCK_SIZE,c=Math.min(f*m.BLOCK_SIZE,a);return{type:"crop",args:[],at:u/r,duration:(c-u)/r}};m.op("trim",{process:lr,resolve:ir});function C(e,t){let r=t.coefs;Array.isArray(r)||(r=[r]);let n=r.length;if(!t.state){t.state=new Array(n);for(let i=0;i<n;i++)t.state[i]=[0,0]}let l=t.state;for(let i=0,a=e.length;i<a;i++){let o=e[i];for(let s=0;s<n;s++){let f=r[s],u=l[s],c=f.b0*o+u[0];u[0]=f.b1*o-f.a1*c+u[1],u[1]=f.b2*o-f.a2*c,o=c}e[i]=o}return e}var{sin:ar,cos:or,sqrt:Dt,pow:Ee,PI:fr}=Math,ge={b0:0,b1:0,b2:0,a1:0,a2:0},fe={b0:1,b1:0,b2:0,a1:0,a2:0};var Ze=e=>({b0:e,b1:0,b2:0,a1:0,a2:0});function te(e,t,r,n,l,i){return{b0:e/n,b1:t/n,b2:r/n,a1:l/n,a2:i/n}}function ne(e,t,r){let n=2*fr*e/r,l=ar(n),i=or(n),a=l/(2*t);return{sinw:l,cosw:i,alpha:a}}function Ut(e,t,r){if(e<=0)return ge;if(e>=r/2)return fe;let{cosw:n,alpha:l}=ne(e,t,r);return te((1-n)/2,1-n,(1-n)/2,1+l,-2*n,1-l)}function ke(e,t,r){if(e<=0)return fe;if(e>=r/2)return ge;let{cosw:n,alpha:l}=ne(e,t,r);return te((1+n)/2,-(1+n),(1+n)/2,1+l,-2*n,1-l)}function Bt(e,t,r){if(e<=0||e>=r/2||t<=0)return ge;let{sinw:n,cosw:l,alpha:i}=ne(e,t,r);return te(n/2,0,-n/2,1+i,-2*l,1-i)}function jt(e,t,r){if(e<=0||e>=r/2)return fe;if(t<=0)return ge;let{cosw:n,alpha:l}=ne(e,t,r);return te(1,-2*n,1,1+l,-2*n,1-l)}function qt(e,t,r,n){if(e<=0||e>=r/2)return fe;if(t<=0)return Ze(Ee(10,n/20));let{cosw:l,alpha:i}=ne(e,t,r),a=Ee(10,n/40);return te(1+i*a,-2*l,1-i*a,1+i/a,-2*l,1-i/a)}function ve(e,t,r,n){let l=Ee(10,n/40);if(e<=0)return fe;if(e>=r/2)return Ze(l*l);let{cosw:i,alpha:a}=ne(e,t,r),o=2*Dt(l)*a;return te(l*(l+1-(l-1)*i+o),2*l*(l-1-(l+1)*i),l*(l+1-(l-1)*i-o),l+1+(l-1)*i+o,-2*(l-1+(l+1)*i),l+1+(l-1)*i-o)}function se(e,t,r,n){let l=Ee(10,n/40);if(e<=0)return Ze(l*l);if(e>=r/2)return fe;let{cosw:i,alpha:a}=ne(e,t,r),o=2*Dt(l)*a;return te(l*(l+1+(l-1)*i+o),-2*l*(l-1+(l+1)*i),l*(l+1+(l-1)*i-o),l+1-(l-1)*i+o,2*(l-1-(l+1)*i),l+1-(l-1)*i-o)}function ye(e,t={}){let r=t.fs||48e3;return(!t._sos||t._fs!==r)&&(t._fs=r,t._sos=ye.coefs(r)),t.state||(t.state=t._sos.map(()=>[0,0])),C(e,{coefs:t._sos,state:t.state})}ye.coefs=function(t=48e3){return t===48e3?[{b0:1.53512485958697,b1:-2.69169618940638,b2:1.19839281085285,a1:-1.69065929318241,a2:.73248077421585},{b0:1,b1:-2,b2:1,a1:-1.99004745483398,a2:.99007225036621}]:[se(1681,.7072,t,3.9997),ke(38,.7072,t)]};var sr=.4,ur=-70,cr=-10,hr=-.691;function Qt(e,t,r,n,l=0,i){i==null&&(i=e[0].length),typeof t=="number"&&(t=Array.from({length:t},(h,d)=>d));let a=Math.ceil(sr*r/n),o=[];for(let h=l;h<i;h+=a){let d=Math.min(h+a,i),p=0,g=0;for(let w of t)for(let y=h;y<d;y++)p+=e[w][y],g++;g>0&&o.push(p/g)}let s=10**(ur/10),f=o.filter(h=>h>s);if(!f.length)return null;let u=f.reduce((h,d)=>h+d,0)/f.length,c=f.filter(h=>h>u*10**(cr/10));return c.length?hr+10*Math.log10(c.reduce((h,d)=>h+d,0)/c.length):null}function Vt(e,t){let r=new Float64Array(e.dc.length);for(let n of t){let l=e.dc[n].length;if(!l){r[n]=0;continue}let i=0;for(let a=0;a<l;a++)i+=e.dc[n][a];r[n]=i/l}return r}function ze(e,t,r){let n=0;for(let l of t){let i=r?.[l]||0;for(let a=0;a<e.min[l].length;a++)n=Math.max(n,Math.abs(e.min[l][a]-i),Math.abs(e.max[l][a]-i))}return n?20*Math.log10(n):null}function Zt(e,t,r){if(!e.rms)return null;let n=0,l=0;for(let i of t){let a=r?.[i]||0;for(let o=0;o<e.rms[i].length;o++)n+=e.rms[i][o]-a*a,l++}return l&&n>0?10*Math.log10(n/l):null}function zt(e,t,r){return Qt(e.energy,t,r,e.blockSize)??null}var pr=(e,t,r)=>{let n=r-t;if(!n)return 0;let l=0;for(let i=t;i<r;i++)l+=e[i];return l/n};m.stat("energy",{block:(e,t)=>(t.k||(t.k=e.map(()=>({fs:t.sampleRate}))),e.map((r,n)=>{let l=new Float32Array(r);ye(l,t.k[n]);let i=0;for(let a=0;a<l.length;a++)i+=l[a]*l[a];return i/l.length})),reduce:pr});m.stat("db",{query:(e,t,r,n)=>{let l=0;for(let i of t)for(let a=r;a<Math.min(n,e.min[i].length);a++)l=Math.max(l,Math.abs(e.min[i][a]),Math.abs(e.max[i][a]));return l>0?20*Math.log10(l):-1/0}});m.stat("loudness",{query:(e,t,r,n,l)=>Qt(e.energy,t,l,e.blockSize,r,n)??-1/0});var dr={streaming:-14,podcast:-16,broadcast:-23};m.op("dc",{hidden:!0,process:(e,t)=>{let r=t.args[0];typeof r=="number"&&(r=[r]);for(let n=0;n<e.length;n++){let l=r[n%r.length]||0;if(!(Math.abs(l)<1e-10))for(let i=0;i<e[n].length;i++)e[n][i]-=l}return e}});m.op("clamp",{hidden:!0,process:(e,t)=>{let r=t.args[0];for(let n=0;n<e.length;n++)for(let l=0;l<e[n].length;l++)e[n][l]=Math.max(-r,Math.min(r,e[n][l]));return e}});m.op("normalize",{process:()=>!1,resolve:(e,t)=>{let{stats:r,sampleRate:n}=t;if(!r?.min)return null;let l=e[0],i=typeof l=="string"?"lufs":t.mode||"peak",a=dr[l]??(typeof l=="number"?l:t.target??0),o=r.min.length,s=t.channel!=null?Array.isArray(t.channel)?t.channel:[t.channel]:Array.from({length:o},(d,p)=>p),f=new Float64Array(o);t.dc!==!1&&r.dc&&(f=Vt(r,s));let u=s.some(d=>Math.abs(f[d])>1e-10),c;if(i==="lufs"?c=zt(r,s,n):i==="rms"?c=Zt(r,s,f):c=ze(r,s,f),c==null)return!1;let h=[];if(u&&h.push({type:"dc",args:[s.map(d=>f[d])]}),t.ceiling!=null){let d=ze(r,s,f);if(d==null)return!1;h.push({type:"gain",args:[a-d]}),h.push({type:"clamp",args:[10**(t.ceiling/20)]})}else h.push({type:"gain",args:[a-c]});return h.length===1?h[0]:h},call(e,t){if(typeof t=="string"||typeof t=="number")return e.call(this,t);if(t!=null&&typeof t=="object"){let{target:r,mode:n,at:l,duration:i,channel:a,...o}=t;return e.call(this,r,{mode:n,at:l,duration:i,channel:a,...o})}return e.call(this)}});var Ge;function Se(e,t){let r=t.fc,n=t.fs||44100,l=t.order||2,i=t.Q==null?.707:t.Q;if(!t.coefs||t._fc!==r||t._order!==l||t._Q!==i||t._fs!==n){if(l<=2)t.coefs=[ke(r,i,n)];else{if(!Ge)throw new Error("Import digital-filter/iir/butterworth.js for order > 2");t.coefs=Ge(l,r,n,"highpass")}t._fc=r,t._order=l,t._Q=i,t._fs=n}return C(e,t)}Se.useButterworth=e=>{Ge=e};var We;function Fe(e,t){let r=t.fc,n=t.fs||44100,l=t.order||2,i=t.Q==null?.707:t.Q;if(!t.coefs||t._fc!==r||t._order!==l||t._Q!==i||t._fs!==n){if(l<=2)t.coefs=[Ut(r,i,n)];else{if(!We)throw new Error("Import digital-filter/iir/butterworth.js for order > 2");t.coefs=We(l,r,n,"lowpass")}t._fc=r,t._order=l,t._Q=i,t._fs=n}return C(e,t)}Fe.useButterworth=e=>{We=e};function $e(e,t){let r=t.fc,n=t.Q==null?.707:t.Q,l=t.fs||44100;return(!t.coefs||t._fc!==r||t._Q!==n||t._fs!==l)&&(t.coefs=[Bt(r,n,l)],t._fc=r,t._Q=n,t._fs=l),C(e,t)}function Ke(e,t){let r=t.fc,n=t.Q==null?30:t.Q,l=t.fs||44100;return(!t.coefs||t._fc!==r||t._Q!==n||t._fs!==l)&&(t.coefs=[jt(r,n,l)],t._fc=r,t._Q=n,t._fs=l),C(e,t)}function He(e,t){let r=t.fc||200,n=t.gain||0,l=t.Q==null?.707:t.Q,i=t.fs||44100;return(!t._lo||t._fc!==r||t._gain!==n||t._Q!==l||t._fs!==i)&&(t._lo={coefs:[ve(r,l,i,n)]},t._fc=r,t._gain=n,t._Q=l,t._fs=i),C(e,t._lo)}function Ye(e,t){let r=t.fc||4e3,n=t.gain||0,l=t.Q==null?.707:t.Q,i=t.fs||44100;return(!t._hi||t._fc!==r||t._gain!==n||t._Q!==l||t._fs!==i)&&(t._hi={coefs:[se(r,l,i,n)]},t._fc=r,t._gain=n,t._Q=l,t._fs=i),C(e,t._hi)}function Je(e,t){let r=t.fs||44100,n=t.bands||[];(!t._filters||t._dirty)&&(t._filters=n.map(l=>({coefs:(l.type==="lowshelf"?ve:l.type==="highshelf"?se:qt)(l.fc,l.Q||1,r,l.gain||0)})),t._dirty=!1);for(let l of t._filters)C(e,l);return e}function J(e,t,r,n,l){t[r]||(t[r]=e.map(()=>l(t.sampleRate)));let i=t[r];for(let a=0;a<e.length;a++)n(e[a],i[a]);return e}var Xe={highpass:(e,t,r)=>J(e,t,"_hp",Se,n=>({fc:r[0],fs:n})),lowpass:(e,t,r)=>J(e,t,"_lp",Fe,n=>({fc:r[0],fs:n})),eq:(e,t,r)=>J(e,t,"_eq",Je,n=>({bands:[{fc:r[0],Q:r[2]??1,gain:r[1]??0,type:"peak"}],fs:n})),lowshelf:(e,t,r)=>J(e,t,"_ls",He,n=>({fc:r[0],gain:r[1]??0,Q:r[2]??.707,fs:n})),highshelf:(e,t,r)=>J(e,t,"_hs",Ye,n=>({fc:r[0],gain:r[1]??0,Q:r[2]??.707,fs:n})),notch:(e,t,r)=>J(e,t,"_notch",Ke,n=>({fc:r[0],Q:r[1]??30,fs:n})),bandpass:(e,t,r)=>J(e,t,"_bp",$e,n=>({fc:r[0],Q:r[1]??.707,fs:n}))},mr=(e,t)=>{let[r,...n]=t.args;if(typeof r=="function"){let i=n[0]||{};return J(e,t,"_custom",r,a=>({...i,fs:a}))}let l=Xe[r];if(!l)throw new Error(`Unknown filter type: ${r}`);return l(e,t,n)};m.op("filter",{process:mr,call(e,t,...r){if(typeof t=="function"){let n=r[0]||{},{at:l,duration:i,channel:a,offset:o,length:s,...f}=n,u={type:"filter",args:[t,f]};return l!=null&&(u.at=l),i!=null&&(u.duration=i),a!=null&&(u.channel=a),o!=null&&(u.offset=o),s!=null&&(u.length=s),this.run(u)}return e.call(this,t,...r)}});for(let e in Xe)m.op(e,{process:(t,r)=>Xe[e](t,r,r.args)});var gr=(e,t)=>{let r=t.args[0]??0;if(e.length<2)return!1;let n=typeof r=="function",[l,i]=H(t,e[0].length),a=(t.blockOffset||0)*t.sampleRate;if(!n){r=Math.max(-1,Math.min(1,r));let f=r<=0?1:1-r,u=r>=0?1:1+r,c=[f,u];for(let h=0;h<e.length;h++){let d=c[h]??1;if(d!==1)for(let p=Math.max(0,l);p<Math.min(i,e[h].length);p++)e[h][p]*=d}return e}let o=e[0],s=e[1];for(let f=Math.max(0,l);f<Math.min(i,o.length);f++){let u=Math.max(-1,Math.min(1,r((a+f)/t.sampleRate)));o[f]*=u<=0?1:1-u,s[f]*=u>=0?1:1+u}return e};m.op("pan",{process:gr});var yr=(e,t)=>{let{total:r,sampleRate:n,args:l}=t,i=l[0]??0,a=l.length>1?l[1]:i,o=Math.round(i*n),s=Math.round(a*n),f=e.map(u=>{let c=u.slice();return c[2]=u[2]+o,c});return o>0&&f.unshift(v(0,o,0,void 0,null)),s>0&&f.push(v(0,s,r+o,void 0,null)),f};m.op("pad",{plan:yr});var wr=(e,t)=>{let r=t.args[0];if(r===0)throw new RangeError("speed: rate cannot be 0");if(!r||r===1)return e;let n=Math.abs(r),l=[],i=0;for(let a of e){let o=Math.round(a[1]/n);l.push(v(a[0],o,i,a[4]===null?a[3]:(a[3]||1)*r,a[4])),i+=o}return l};m.op("speed",{plan:wr});m.op("transform",{process:(e,t)=>t.args[0](e,t),call(e,t){return this.run({type:"transform",args:[t]})}});var _r=(e,t,r)=>{let n=1/0;for(let l=t;l<r;l++)e[l]<n&&(n=e[l]);return n===1/0?0:n},Ar=(e,t,r)=>{let n=-1/0;for(let l=t;l<r;l++)e[l]>n&&(n=e[l]);return n===-1/0?0:n},br=(e,t,r)=>{let n=0;for(let l=t;l<r;l++)n+=e[l];return n},Mr=(e,t,r)=>{let n=r-t;if(!n)return 0;let l=0;for(let i=t;i<r;i++)l+=e[i];return l/n},xr=(e,t,r)=>{let n=r-t;if(!n)return 0;let l=0;for(let i=t;i<r;i++)l+=e[i];return Math.sqrt(l/n)};m.stat("min",{block:e=>e.map(t=>{let r=1/0;for(let n=0;n<t.length;n++)t[n]<r&&(r=t[n]);return r}),reduce:_r,query:(e,t,r,n)=>{let l=1/0;for(let i of t)for(let a=r;a<Math.min(n,e.min[i].length);a++)e.min[i][a]<l&&(l=e.min[i][a]);return l===1/0?0:l}});m.stat("max",{block:e=>e.map(t=>{let r=-1/0;for(let n=0;n<t.length;n++)t[n]>r&&(r=t[n]);return r}),reduce:Ar,query:(e,t,r,n)=>{let l=-1/0;for(let i of t)for(let a=r;a<Math.min(n,e.max[i].length);a++)e.max[i][a]>l&&(l=e.max[i][a]);return l===-1/0?0:l}});m.stat("dc",{block:e=>e.map(t=>{let r=0;for(let n=0;n<t.length;n++)r+=t[n];return r/t.length}),reduce:Mr});m.stat("clipping",{block:e=>e.map(t=>{let r=0;for(let n=0;n<t.length;n++)(t[n]>=1||t[n]<=-1)&&r++;return r}),reduce:br,query:(e,t,r,n,l)=>{let i=e.blockSize,a=[];for(let o=r;o<n;o++){let s=0;for(let f of t)s+=e.clipping[f][o]||0;s>0&&a.push(o*i/l)}return new Float32Array(a)}});m.stat("rms",{block:e=>e.map(t=>{let r=0;for(let n=0;n<t.length;n++)r+=t[n]*t[n];return r/t.length}),reduce:xr,query:(e,t,r,n)=>{let l=0,i=0;for(let a of t)for(let o=r;o<Math.min(n,e.rms[a].length);o++)l+=e.rms[a][o],i++;return i?Math.sqrt(l/i):0}});var{sqrt:Rr,sin:Er,cos:kr,abs:vr,SQRT1_2:Gt,SQRT2:Ri}=Math,Sr=6.283185307179586,Kt=new Map,Wt=0,$t=null;function Fr(e){let t=e>>>1,r=new Float64Array(e),n=new Float64Array(t),l=new Float64Array(t+1),a=[r.subarray(0,t+1),l],o=2/e,s=31-Math.clz32(e),f=new Uint32Array(e);for(let y=0;y<e;y++){let _=0,A=y;for(let b=0;b<s;b++)_=_<<1|A&1,A>>=1;f[y]=_}let u=0,c=2,h=t,d=[];for(;h=h>>>1;){c=c<<1;let y=c>>>3,_=y>1?y-1:0;d.push({offset:u,count:_}),u+=_}let p=new Float64Array(u<<2);c=2,h=t;let g=0;for(;h=h>>>1;){c=c<<1;let y=c>>>3,_=Sr/c,A=d[g].offset<<2;for(let b=1;b<y;b++){let M=b*_,x=Er(M),R=kr(M),E=A+(b-1<<2);p[E]=R,p[E+1]=x,p[E+2]=4*R*(R*R-.75),p[E+3]=4*x*(.75-x*x)}g++}let w={x:r,spectrum:n,complex:a,bSi:o,tw:p,stages:d,perm:f};return Kt.set(e,w),w}function Cr(e){if(e===Wt)return $t;let t=Kt.get(e)||Fr(e);return Wt=e,$t=t,t}function Pr(e){let t=e.length;if(t<2||t&t-1)throw Error("Input length must be a power of 2 (>= 2).");let r=Cr(t),{x:n,tw:l,stages:i,perm:a}=r;for(let u=0;u<t;u++)n[u]=e[a[u]];for(let u=0,c=4;u<t;c*=4){for(let h=u;h<t;h+=c){let d=n[h]-n[h+1];n[h]+=n[h+1],n[h+1]=d}u=2*(c-1)}let o=2,s=t>>>1,f=0;for(;s=s>>>1;){let u=0;o=o<<1;let c=o<<1,h=o>>>2,d=o>>>3;do{if(h!==1)for(let w=u;w<t;w+=c){let y=w,_=y+h,A=_+h,b=A+h,M=n[A]+n[b];n[b]-=n[A],n[A]=n[y]-M,n[y]+=M,y+=d,_+=d,A+=d,b+=d,M=n[A]+n[b];let x=n[A]-n[b];M=-M*Gt,x*=Gt;let R=n[_];n[b]=M+R,n[A]=M-R,n[_]=n[y]-x,n[y]+=x}else for(let w=u;w<t;w+=c){let y=w,_=y+2,A=_+1,b=n[_]+n[A];n[A]-=n[_],n[_]=n[y]-b,n[y]+=b}u=(c<<1)-o,c=c<<2}while(u<t);let{offset:p,count:g}=i[f];for(let w=0;w<g;w++){let y=p+w<<2,_=l[y],A=l[y+1],b=l[y+2],M=l[y+3];u=0,c=o<<1;do{for(let x=u;x<t;x+=c){let R=x+w+1,E=R+h,F=E+h,I=F+h,L=x+h-w-1,P=L+h,X=P+h,B=X+h,Z=n[X]*_-n[F]*A,Q=n[X]*A+n[F]*_,ue=n[B]*b-n[I]*M,ce=n[B]*M+n[I]*b,en=Z-ue;Z+=ue,ue=en,n[B]=Z+n[P],n[F]=Z-n[P];let tn=ce-Q;Q+=ce,ce=tn,n[I]=ce+n[E],n[X]=ce-n[E],n[P]=n[R]-Q,n[R]+=Q,n[E]=ue+n[L],n[L]-=ue}u=(c<<1)-o,c=c<<2}while(u<t)}f++}return r}function Ne(e,t){let r=Pr(e),n=e.length,{x:l,spectrum:i,bSi:a}=r,o=t||i,s=n>>>1;for(;--s;){let f=l[s],u=l[n-s];o[s]=a*Rr(f*f+u*u)}return o[0]=vr(a*l[0]),o}var{cos:Ht,sin:ki,abs:vi,exp:Si,sqrt:Fi,PI:Or,cosh:Ci,acosh:Pi,acos:Oi,pow:Li,log10:Ii}=Math,Yt=2*Or;function et(e,t){return .5-.5*Ht(Yt*e/(t-1))}function Jt(e){let t=e*e;return 1.2588966*14884e4*t*t/((t+424.36)*Math.sqrt((t+11599.29)*(t+544496.41))*(t+14884e4))}var Xt=e=>2595*Math.log10(1+e/700),Nt=e=>700*(10**(e/2595)-1),tt={};function Lr(e){if(tt[e])return tt[e];let t=new Float32Array(e);for(let r=0;r<e;r++)t[r]=et(r,e);return tt[e]=t}function nt(e,t,r={}){let{bins:n=128,fMin:l=30,fMax:i=Math.min(t/2,2e4),weight:a=!0}=r,o=e.length,s=Lr(o),f=new Float32Array(o);for(let g=0;g<o;g++)f[g]=e[g]*s[g];let u=Ne(f),c=Xt(l),h=Xt(i),d=t/o,p=new Float32Array(n);for(let g=0;g<n;g++){let w=Nt(c+(h-c)*g/n),y=Nt(c+(h-c)*(g+1)/n),_=Math.max(1,Math.floor(w/d)),A=Math.min(u.length-1,Math.ceil(y/d)),b=0,M=0;for(let R=_;R<=A;R++)b+=u[R]**2,M++;let x=M>0?Math.sqrt(b/M):0;a&&(x*=Jt((w+y)/2,t)),p[g]=x}return p}async function rt(e,t,r,n,l){let i=new Float64Array(n),a=0,o=new Float32Array(0);for await(let s of e.stream({at:t?.at,duration:t?.duration})){let f=s[0];if(!f||!f.length)continue;let u=f;o.length&&(u=new Float32Array(o.length+f.length),u.set(o,0),u.set(f,o.length));let c=u.length-u.length%r;for(let h=0;h<c;h+=r)l(u.subarray(h,h+r),i),a++;o=c<u.length?u.slice(c):new Float32Array(0)}return{acc:i,cnt:a}}m.fn.spectrum=async function(e){let t=e?.bins??128,r={bins:t,fMin:e?.fMin,fMax:e?.fMax,weight:e?.weight},n=this.sampleRate,{acc:l,cnt:i}=await rt(this,e,1024,t,(o,s)=>{let f=nt(o,n,r);for(let u=0;u<t;u++)s[u]+=f[u]**2});if(i===0)return new Float32Array(t);let a=new Float32Array(t);for(let o=0;o<t;o++)a[o]=20*Math.log10(Math.sqrt(l[o]/i)+1e-10);return a};function Ir(e,t,r={}){let{bins:n=13,nMel:l=40}=r,i=nt(e,t,{bins:l,weight:!1}),a=new Float32Array(l);for(let s=0;s<l;s++)a[s]=Math.log(i[s]**2+1e-10);let o=new Float32Array(n);for(let s=0;s<n;s++){let f=0;for(let u=0;u<l;u++)f+=a[u]*Math.cos(Math.PI*s*(2*u+1)/(2*l));o[s]=f}return o}m.fn.cepstrum=async function(e){let t=e?.bins??13,r=this.sampleRate,{acc:n,cnt:l}=await rt(this,e,1024,t,(a,o)=>{let s=Ir(a,r,{bins:t});for(let f=0;f<t;f++)o[f]+=s[f]});if(l===0)return new Float32Array(t);let i=new Float32Array(t);for(let a=0;a<t;a++)i[a]=n[a]/l;return i};m.fn.silence=async function(e){let{stats:t,ch:r,sr:n,from:l,to:i}=await je(this,e),a=t.blockSize,o=e?.minDuration??.1,s=Ve(t,r,l,i,e?.threshold),f=[],u=null;for(let c=l;c<i;c++)if(!Re(t,c,r,s))u==null&&(u=c);else if(u!=null){let h=u*a/n,d=c*a/n;d-h>=o&&f.push({at:h,duration:d-h}),u=null}if(u!=null){let c=u*a/n,h=Math.min(i*a/n,this.duration);h-c>=o&&f.push({at:c,duration:h-c})}return f};export{m as default,S as parseTime,St as render};
|
|
14
|
+
`,w=new Blob([g],{type:"application/javascript"}),y=URL.createObjectURL(w);await o.audioWorklet.addModule(y),URL.revokeObjectURL(y),c=new AudioWorkletNode(o,"mic-processor",{numberOfInputs:1,numberOfOutputs:0,channelCount:t}),s.connect(c),c.port.onmessage=_=>{if(f||!u)return;let A=u;u=null,A(null,p(_.data,n))}}else c=o.createScriptProcessor(2048,t,1),s.connect(c),c.connect(o.destination),c.onaudioprocess=w=>{if(f||!u)return;let y=u;u=null;let _=[];for(let A=0;A<t;A++)_.push(w.inputBuffer.getChannelData(A).slice());y(null,p(_,n))};return h.close=d,h.end=d,h.backend="mediastream",h;function h(g){if(g==null||f){d();return}o.state==="suspended"&&o.resume(),u=g}function d(){f||(f=!0,u=null,s.disconnect(),i.getTracks().forEach(g=>g.stop()),a&&o.close?.())}function p(g,w){let y=g.length,_=g[0].length,A=w/8,b=new Uint8Array(_*y*A),x=new DataView(b.buffer);for(let M=0;M<_;M++)for(let R=0;R<y;R++){let k=g[R][M],v=(M*y+R)*A;w===16?x.setInt16(v,Math.max(-32768,Math.min(32767,Math.round(k*32767))),!0):w===32?x.setFloat32(v,k,!0):w===8&&(b[v]=Math.max(0,Math.min(255,Math.round((k+1)*127.5))))}return b}}var At=rn(()=>{});function N(e){if(e){if(e=new Uint8Array(e.buffer||e),on(e))return"wav";if(pn(e))return"aiff";if(an(e))return"mp3";if(dn(e))return"aac";if(sn(e))return"flac";if(un(e))return"m4a";if(cn(e))return"opus";if(fn(e))return"oga";if(hn(e))return"qoa";if(mn(e))return"mid";if(gn(e))return"caf";if(yn(e))return"wma";if(wn(e))return"amr";if(_n(e))return"webm"}}function an(e){if(!(!e||e.length<3))return e[0]===73&&e[1]===68&&e[2]===51||e[0]===255&&(e[1]&224)===224&&(e[1]&6)!==0||e[0]===84&&e[1]===65&&e[2]===71}function on(e){if(!(!e||e.length<12))return e[0]===82&&e[1]===73&&e[2]===70&&e[3]===70&&e[8]===87&&e[9]===65&&e[10]===86&&e[11]===69}function fn(e){if(!(!e||e.length<4))return e[0]===79&&e[1]===103&&e[2]===103&&e[3]===83}function sn(e){if(!(!e||e.length<4))return e[0]===102&&e[1]===76&&e[2]===97&&e[3]===67}function un(e){if(!(!e||e.length<8))return e[4]===102&&e[5]===116&&e[6]===121&&e[7]===112||e[0]===77&&e[1]===52&&e[2]===65&&e[3]===32}function cn(e){if(!(!e||e.length<36))return e[0]===79&&e[1]===103&&e[2]===103&&e[3]===83&&e[28]===79&&e[29]===112&&e[30]===117&&e[31]===115&&e[32]===72&&e[33]===101&&e[34]===97&&e[35]===100}function hn(e){if(!(!e||e.length<4))return e[0]===113&&e[1]===111&&e[2]===97&&e[3]===102}function pn(e){if(!(!e||e.length<12))return e[0]===70&&e[1]===79&&e[2]===82&&e[3]===77&&e[8]===65&&e[9]===73&&e[10]===70&&(e[11]===70||e[11]===67)}function dn(e){if(!(!e||e.length<2))return e[0]===255&&(e[1]&240)===240&&(e[1]&6)===0}function mn(e){if(!(!e||e.length<4))return e[0]===77&&e[1]===84&&e[2]===104&&e[3]===100}function gn(e){if(!(!e||e.length<4))return e[0]===99&&e[1]===97&&e[2]===102&&e[3]===102}function yn(e){if(!(!e||e.length<8))return e[0]===48&&e[1]===38&&e[2]===178&&e[3]===117&&e[4]===142&&e[5]===102&&e[6]===207&&e[7]===17}function wn(e){if(!(!e||e.length<5))return e[0]===35&&e[1]===33&&e[2]===65&&e[3]===77&&e[4]===82}function _n(e){if(!(!e||e.length<4))return e[0]===26&&e[1]===69&&e[2]===223&&e[3]===163}var re=Object.freeze({channelData:Object.freeze([]),sampleRate:0});async function z(e){if(!e||typeof e=="string"||!(e.buffer||e.byteLength||e.length))throw TypeError("Expected ArrayBuffer or Uint8Array");let t=new Uint8Array(e),r=N(t);if(!r)throw Error("Unknown audio format");if(!z[r])throw Error("No decoder for "+r);let n=await z[r]();try{let l=await n(t),i=await n();return it(l,i)}catch(l){throw n.free(),l}}function D(e,t){z[e]=An(e,async()=>{let r=await t();if(r.decoder){let i=await r.decoder();return lt(a=>i.decode(a),i.flush?()=>i.flush():null,i.free?()=>i.free():null)}let n=r.default||r,l=typeof n=="function"?await n():n;return l.ready&&await l.ready,lt(i=>l.decode(i),l.flush?()=>l.flush():null,l.free?()=>l.free():null)})}function An(e,t){let r=async n=>{if(!n)return t();console.warn("decode."+e+"(data) is deprecated, use decode(data) or let dec = await decode."+e+"()");let l=await t();try{let i=await l(n instanceof Uint8Array?n:new Uint8Array(n.buffer||n)),a=await l();return it(i,a)}catch(i){throw l.free(),i}};return r.stream=t,r}D("mp3",()=>import("mpg123-decoder").then(e=>({decoder:async()=>{let t=new e.MPEGDecoder;return await t.ready,t}})));D("flac",()=>import("@wasm-audio-decoders/flac").then(e=>({decoder:async()=>{let t=new e.FLACDecoder;return await t.ready,t}})));D("opus",()=>import("ogg-opus-decoder").then(e=>({decoder:async()=>{let t=new e.OggOpusDecoder;return await t.ready,t}})));D("oga",()=>import("@wasm-audio-decoders/ogg-vorbis").then(e=>({decoder:async()=>{let t=new e.OggVorbisDecoder;return await t.ready,t}})));D("m4a",()=>import("@audio/decode-aac"));D("wav",()=>import("@audio/decode-wav"));D("qoa",()=>import("qoa-format").then(e=>({decoder:async()=>({decode:t=>e.decode(t)})})));D("aac",()=>import("@audio/decode-aac"));D("aiff",()=>import("@audio/decode-aiff"));D("caf",()=>import("@audio/decode-caf"));D("webm",()=>import("@audio/decode-webm"));D("amr",()=>import("@audio/decode-amr"));D("wma",()=>import("@audio/decode-wma"));function lt(e,t,r){let n=!1,l=async i=>{if(i){if(n)throw Error("Decoder already freed");try{return Pe(await e(i instanceof Uint8Array?i:new Uint8Array(i)))}catch(a){throw n=!0,r?.(),a}}if(n)return re;n=!0;try{let a=t?Pe(await t()):re;return r?.(),a}catch(a){throw r?.(),a}};return l.decode=l,l.flush=async()=>n?re:t?Pe(await t()):re,l.free=()=>{n||(n=!0,r?.())},l}function Pe(e){if(!e?.channelData?.length)return re;let{channelData:t,sampleRate:r,samplesDecoded:n}=e;if(n!=null&&n<t[0].length&&(t=t.map(l=>l.subarray(0,n))),!t[0]?.length)return re;if(t.length===2){let l=t[0],i=t[1],a=!0;for(let o=0;o<l.length;o+=37)if(l[o]!==i[o]){a=!1;break}a&&(t=[l])}return{channelData:t,sampleRate:r}}function it(e,t){if(!t?.channelData?.length)return e;if(!e?.channelData?.length)return t;let r=e.channelData.length,n=t.channelData.length,l=Math.max(r,n);return{channelData:Array.from({length:l},(i,a)=>{let o=e.channelData[a%r],s=t.channelData[a%n],f=new Float32Array(o.length+s.length);return f.set(o),f.set(s,o.length),f}),sampleRate:e.sampleRate}}var G=new Uint8Array(0),at={},ee=at;function le(e,t){at[e]=bn(async r=>{let n=(await t()).default,l=await n(r);return Mn(i=>l.encode(i),()=>l.flush(),()=>l.free())})}le("wav",()=>import("@audio/encode-wav"));le("aiff",()=>import("@audio/encode-aiff"));le("mp3",()=>import("@audio/encode-mp3"));le("ogg",()=>import("@audio/encode-ogg"));le("flac",()=>import("@audio/encode-flac"));le("opus",()=>import("@audio/encode-opus"));function bn(e){let t=async(r,n)=>{if(!n)return e(r);if(!n.sampleRate)throw Error("sampleRate is required");let l=ot(r);if(!l.length||!l[0].length)return G;let i=await e({channels:l.length,...n});try{let a=await i(l),o=await i();return xn(a,o)}catch(a){throw i.free(),a}};return t.stream=e,t}function ot(e){if(!e)return[];if(Array.isArray(e))return e[0]instanceof Float32Array?e:[];if(e instanceof Float32Array)return[e];if(e.getChannelData&&e.numberOfChannels){let t=[];for(let r=0;r<e.numberOfChannels;r++)t.push(e.getChannelData(r));return t}return[]}function Mn(e,t,r){let n=!1,l=async i=>{if(i){if(n)throw Error("Encoder already freed");let a=ot(i);try{return Ce(await e(a))}catch(o){throw n=!0,r?.(),o}}if(n)return G;n=!0;try{let a=t?Ce(await t()):G;return r?.(),a}catch(a){throw r?.(),a}};return l.encode=l,l.flush=async()=>n?G:t?Ce(await t()):G,l.free=()=>{n||(n=!0,r?.())},l}function Ce(e){return e?.length?e instanceof Uint8Array?e:e.buffer?new Uint8Array(e.buffer,e.byteOffset,e.byteLength):new Uint8Array(e):G}function xn(e,t){if(!t?.length)return e||G;if(!e?.length)return t||G;let r=new Uint8Array(e.length+t.length);return r.set(e),r.set(t,e.length),r}var Rn=[8e3,11025,16e3,22050,44100,48e3,88200,96e3,176400,192e3,352800,384e3],ct=typeof AudioBuffer<"u"?AudioBuffer:null;try{ct??=(await import("audio-buffer")).default}catch{}var kn=new Set(Rn),$={float32:{C:Float32Array,min:-1,max:1},float64:{C:Float64Array,min:-1,max:1},uint8:{C:Uint8Array,min:0,max:255},uint16:{C:Uint16Array,min:0,max:65535},uint32:{C:Uint32Array,min:0,max:4294967295},int8:{C:Int8Array,min:-128,max:127},int16:{C:Int16Array,min:-32768,max:32767},int32:{C:Int32Array,min:-2147483648,max:2147483647}},we=e=>$[e]&&e||$[e+"32"]&&e+"32",ft={array:1,arraybuffer:1,buffer:1,audiobuffer:1},ie={mono:1,stereo:2,"2.1":3,quad:4,"5.1":6};for(let e=3;e<=32;e++)ie[e+"-channel"]||=e;var En={};for(let e in ie)En[ie[e]]||=e;var ht=e=>ArrayBuffer.isView(e)&&!(e instanceof DataView),Oe=e=>Array.isArray(e)&&e.length>0&&ht(e[0]),st=e=>e!=null&&typeof e!="string"&&!Oe(e)&&(Array.isArray(e)||ht(e)||e instanceof ArrayBuffer),pt=e=>e!=null&&typeof e.getChannelData=="function"&&typeof e.numberOfChannels=="number";function W(e){if(!e)return{};if(typeof e!="string"){let r={},n=e.dtype||e.type;return we(n)&&(r.dtype=we(n)),n&&ft[n]&&(r.container=n),e.channels!=null&&(r.channels=ie[e.channels]||+e.channels),e.numberOfChannels!=null&&(r.channels??=e.numberOfChannels),e.interleaved!=null&&(r.interleaved=e.interleaved),e.endianness&&(r.endianness=e.endianness),e.sampleRate!=null&&(r.sampleRate=e.sampleRate),e.rate!=null&&(r.sampleRate??=e.rate),e.container&&(r.container=e.container),r}let t={};for(let r of e.split(/\s*[,;_]\s*|\s+/)){let n=r.toLowerCase();if(we(n))t.dtype=we(n);else if(ft[n])t.container=n;else if(ie[n])t.channels=ie[n];else if(n==="interleaved")t.interleaved=!0;else if(n==="planar")t.interleaved=!1;else if(n==="le")t.endianness="le";else if(n==="be")t.endianness="be";else if(/^\d+$/.test(n)&&kn.has(+n))t.sampleRate=+n;else throw Error("Unknown format token: "+r)}return t}function _e(e){return e==null?{}:pt(e)?{dtype:"float32",channels:e.numberOfChannels,interleaved:!1,sampleRate:e.sampleRate}:typeof Buffer<"u"&&Buffer.isBuffer(e)?{dtype:"uint8",container:"buffer"}:e instanceof Float32Array?{dtype:"float32"}:e instanceof Float64Array?{dtype:"float64"}:e instanceof Int8Array?{dtype:"int8"}:e instanceof Int16Array?{dtype:"int16"}:e instanceof Int32Array?{dtype:"int32"}:e instanceof Uint8Array?{dtype:"uint8"}:e instanceof Uint8ClampedArray?{dtype:"uint8"}:e instanceof Uint16Array?{dtype:"uint16"}:e instanceof Uint32Array?{dtype:"uint32"}:e instanceof ArrayBuffer?{container:"arraybuffer"}:Array.isArray(e)?Oe(e)?{..._e(e[0]),channels:e.length,interleaved:!1}:{container:"array"}:{}}function ut(e){return $[e]||{min:-1,max:1}}function he(e,t,r,n){if(!e)throw Error("Source data required");if(t==null)throw Error("Format required");let l=_e(e);r===void 0&&n===void 0?st(t)?(n=t,r=_e(n),t=l):(r=W(t),t=l):n===void 0?st(r)?(n=r,r=W(t),t=l):(t={...l,...W(t)},r=W(r)):(t={...l,...W(t)},r={...n?_e(n):{},...W(r)}),r.container==="audiobuffer"&&(r.dtype="float32"),r.dtype||(r.dtype=t.dtype),r.channels==null&&t.channels!=null&&(r.channels=t.channels),r.interleaved!=null&&t.interleaved==null&&(t.interleaved=!r.interleaved,t.channels||(t.channels=2)),t.interleaved!=null&&!t.channels&&(t.channels=2);let i=t.container==="array"?{min:-1,max:1}:ut(t.dtype),a=r.container==="array"?{min:-1,max:1}:ut(r.dtype),o;if(Oe(e)){let w=e.length,y=e[0].length;o=new e[0].constructor(y*w);for(let _=0;_<w;_++)o.set(e[_],y*_)}else if(pt(e)){let w=e.numberOfChannels,y=e.length;o=new Float32Array(y*w);for(let _=0;_<w;_++)o.set(e.getChannelData(_),y*_)}else e instanceof ArrayBuffer?o=new($[t.dtype]?.C||Uint8Array)(e):typeof Buffer<"u"&&Buffer.isBuffer(e)?o=new($[t.dtype]?.C||Uint8Array)(e.buffer.slice(e.byteOffset,e.byteOffset+e.byteLength)):o=e;let s=o.length,f=i.min!==a.min||i.max!==a.max,u=t.interleaved!=null&&r.interleaved!=null&&t.interleaved!==r.interleaved,c=t.channels||1,h=Math.floor(s/c),d=$[r.dtype]?.C||Float32Array,p;if(!f&&!u)p=r.container==="array"?Array.from(o):new d(o);else{p=r.container==="array"?new Array(s):new d(s);let w=i.max-i.min,y=a.max>1,_=i.min===-1&&i.max===1&&y?a.max-a.min+1:a.max-a.min,A=i.min===-1&&i.max===1&&y;if(u){let b=t.interleaved;for(let x=0;x<s;x++){let M=b?x%h*c+~~(x/h):x%c*h+~~(x/c),R=o[M];f&&(R=(R-i.min)/w*_+a.min,A&&(R=Math.round(R)),R<a.min?R=a.min:R>a.max&&(R=a.max)),p[x]=R}}else for(let b=0;b<s;b++){let x=(o[b]-i.min)/w*_+a.min;A&&(x=Math.round(x)),p[b]=x<a.min?a.min:x>a.max?a.max:x}}if(n)if(Array.isArray(n)){for(let w=0;w<s;w++)n[w]=p[w];p=n}else if(n instanceof ArrayBuffer){let w=new($[r.dtype]?.C||Uint8Array)(n);w.set(p),p=w}else n.set(p),p=n;let g=$[r.dtype];if(g&&g.C.BYTES_PER_ELEMENT>1&&t.endianness&&r.endianness&&t.endianness!==r.endianness&&p.buffer){let w=r.endianness==="le",y=new DataView(p.buffer),_=g.C.BYTES_PER_ELEMENT,A="set"+r.dtype[0].toUpperCase()+r.dtype.slice(1);for(let b=0;b<s;b++)y[A](b*_,p[b],w)}if(r.container==="audiobuffer"){let w=typeof AudioBuffer<"u"?AudioBuffer:ct;if(!w)throw Error("AudioBuffer not available. In Node.js: install audio-buffer package or set globalThis.AudioBuffer");let y=r.channels||1,_=Math.floor(p.length/y),A=r.sampleRate||t.sampleRate||44100,b=new w({length:_,numberOfChannels:y,sampleRate:A});if((u?r.interleaved:t.interleaved??!1)&&y>1)for(let M=0;M<y;M++){let R=new Float32Array(_);for(let k=0;k<_;k++)R[k]=p[k*y+M];b.copyToChannel(R,M)}else for(let M=0;M<y;M++)b.copyToChannel(p.subarray(M*_,(M+1)*_),M);return b}return(r.container==="arraybuffer"||r.container==="buffer")&&p.buffer||p}var E=Object.create(null),dt=6e4,mt=dt*60,Le=mt*24,gt=Le*365.25;E.year=E.yr=E.y=gt;E.month=E.mo=E.mth=gt/12;E.week=E.wk=E.w=Le*7;E.day=E.d=Le;E.hour=E.hr=E.h=mt;E.minute=E.min=E.m=dt;E.second=E.sec=E.s=1e3;E.millisecond=E.millisec=E.ms=1;E.microsecond=E.microsec=E.us=E.\u00B5s=.001;E.nanosecond=E.nanosec=E.ns=1e-6;E.group=",";E.decimal=".";E.placeholder=" _";var yt=E;var vn=/((?:\d{1,16}(?:\.\d{1,16})?|\.\d{1,16})(?:[eE][-+]?\d{1,4})?)\s?([\p{L}]{0,14})/gu;U.unit=yt;function U(e="",t="ms"){let r=null,n;return String(e).replace(new RegExp(`(\\d)[${U.unit.placeholder}${U.unit.group}](\\d)`,"g"),"$1$2").replace(U.unit.decimal,".").replace(vn,(l,i,a)=>{if(a)a=a.toLowerCase();else if(n){for(let o in U.unit)if(U.unit[o]<n){a=o;break}}else a=t;n=a=U.unit[a]||U.unit[a.replace(/s$/,"")],a&&(r=(r||0)+i*a)}),r&&r/(U.unit[t]||1)*(e[0]==="-"?-1:1)}m.version="2.1.0";function P(e){if(e==null)return e;if(typeof e=="number"){if(!Number.isFinite(e))throw new Error(`Invalid time: ${e}`);return e}let t=e.match(/^(\d+):(\d{1,2})(?::(\d{1,2}))?(?:\.(\d+))?$/);if(t){let[,n,l,i,a]=t,o=i!=null?+n*3600+ +l*60+ +i:+n*60+ +l;return a&&(o+=+("0."+a)),o}let r=U(e,"s");if(r!=null&&isFinite(r))return r;throw new Error(`Invalid time: ${e}`)}function m(e,t={}){if(e==null){let f=t.sampleRate||44100,u=t.channels||1,c=[],h=()=>{for(let p of c.splice(0))p()},d=Ae([],f,u,0,t,null);return d.decoded=!1,d.recording=!1,d._.acc=Mt({pages:d.pages,notify:h,ondata:(...p)=>O(d,"data",...p)}),d._.waiters=c,d}if(e&&typeof e=="object"&&!Array.isArray(e)&&e.edits){if(!e.source)throw new TypeError("audio: cannot restore document without source reference");let f=m(e.source,t);if(f.run)for(let u of e.edits)f.run(u);return f}if(Array.isArray(e)&&e.length&&!(e[0]instanceof Float32Array)){let f=e.map(h=>h?.pages?h:m(h,t)),u=f[0].clip?f[0].clip():m.from(f[0]);if(!u.insert)throw new Error('audio([...]): concat requires insert plugin \u2014 import "audio" instead of "audio/core.js"');for(let h=1;h<f.length;h++)u.insert(f[h]);let c=f.filter(h=>!h.decoded);return c.length&&(u.ready=Promise.all(c.map(h=>h.ready)).then(()=>(delete u.then,delete u.catch,!0)),u.ready.catch(()=>{}),Ie(u)),u}if(e?.getChannelData&&e?.numberOfChannels)return m.from(e,t);if(Array.isArray(e)&&e[0]instanceof Float32Array||typeof e=="number"){let f=m.from(e,t);return m.evict&&f.cache&&f.budget!==1/0&&(f.ready=m.evict(f).then(()=>(delete f.then,delete f.catch,!0)),f.ready.catch(()=>{}),Ie(f)),f}let r=typeof e=="string"?e:e instanceof URL?e.href:null,n=[],l=[],i=()=>{for(let f of l.splice(0))f()},a=Ae(n,0,0,0,{...t,source:r},null);a._.waiters=l,a.decoded=!1;let o,s;return a._.ready=new Promise((f,u)=>{o=f,s=u}),a._.ready.catch(()=>{}),a.ready=(async()=>{try{if(t.storage==="persistent"){if(!m.opfsCache)throw new Error('Persistent storage requires cache module (import "./cache.js")');try{t={...t,cache:await m.opfsCache(),budget:t.budget??m.DEFAULT_BUDGET??1/0}}catch{throw new Error('OPFS not available (required by storage: "persistent")')}a.cache=t.cache,a.budget=t.budget}let f=await Cn(e,{pages:n,notify:i,ondata:(...c)=>O(a,"data",...c)});a.sampleRate=f.sampleRate,a._.ch=f.channels,a._.chV=-1,f.acc&&(a._.acc=f.acc),O(a,"metadata",{sampleRate:f.sampleRate,channels:f.channels}),o();let u=await f.decoding;return a._.len=u.length,a._.lenV=-1,a.stats=u.stats,a.decoded=!0,i(),m.evict?.(a),delete a.then,delete a.catch,!0}catch(f){throw s(f),f}})(),a.ready.catch(()=>{}),Ie(a),a}function Ie(e){e.then=function(t,r){return e.ready.then(()=>(delete e.then,delete e.catch,e)).then(t,r)},e.catch=function(t){return e.then(null,t)}}m.from=function(e,t={}){if(Array.isArray(e)&&e[0]instanceof Float32Array)return pe(e,t);if(typeof e=="number")return Sn(e,t);if(typeof e=="function")return Fn(e,t);if(e?.pages)return Ae(e.pages,t.sampleRate??e.sampleRate,t.channels??e._.ch,e._.len,{source:e.source,storage:e.storage,cache:e.cache,budget:t.budget??e.budget},e.stats);if(e?.getChannelData){let r=Array.from({length:e.numberOfChannels},(n,l)=>new Float32Array(e.getChannelData(l)));return pe(r,{sampleRate:e.sampleRate,...t})}if(ArrayBuffer.isView(e)&&t.format){let r=W(t.format),n=r.channels||t.channels||1,l=r.sampleRate||t.sampleRate||44100,i={...r,channels:n};n>1&&i.interleaved==null&&(i.interleaved=!0);let a=he(e,i,{dtype:"float32",interleaved:!1,channels:n}),o=a.length/n,s=Array.from({length:n},(f,u)=>a.subarray(u*o,(u+1)*o));return pe(s,{sampleRate:l})}throw new TypeError("audio.from: expected Float32Array[], AudioBuffer, audio instance, function, or number")};var T={};m.fn=T;m.BLOCK_SIZE=1024;m.PAGE_SIZE=1024*m.BLOCK_SIZE;var V=Symbol("load"),be=Symbol("read");function O(e,t,...r){let n=e._.ev[t];if(n)for(let l of n)l(...r)}T.on=function(e,t){return(this._.ev[e]??=[]).push(t),this};T.off=function(e,t){if(!e)return this._.ev={},this;if(!t)return delete this._.ev[e],this;let r=this._.ev[e];if(r){let n=r.indexOf(t);n>=0&&r.splice(n,1)}return this};T.dispose=function(){this.stop(),this._.ev={},this._.pcm=null,this._.plan=null,this.pages.length=0,this.stats=null,this._.waiters=null,this._.acc=null};Symbol.dispose&&(T[Symbol.dispose]=T.dispose);m.use=function(...e){for(let t of e)t(m)};function Ae(e,t,r,n,l={},i){let a=Object.create(T);return a.pages=e,a.sampleRate=t,a.source=l.source??null,a.storage=l.storage||"memory",a.cache=l.cache||null,a.budget=l.budget??1/0,a.stats=i,a.decoded=!0,a.ready=Promise.resolve(!0),a._={ch:r,len:n,waiters:null,ev:{},ct:0,ctStamp:0,vol:1,muted:!1},a.edits=[],a.version=0,a._.pcm=null,a._.pcmV=-1,a._.plan=null,a._.planV=-1,a._.statsV=-1,a._.lenC=a._.len,a._.lenV=0,a._.chC=a._.ch,a._.chV=0,Object.defineProperties(a,{currentTime:{get(){if(this.playing&&!this.paused){let o=this._.ct+(performance.now()-this._.ctStamp)/1e3,s=this.duration;return s>0?Math.min(o,s):o}return this._.ct},set(o){this._.ct=o,this._.ctStamp=performance.now()},enumerable:!0,configurable:!0},volume:{get(){return this._.vol},set(o){o=Math.max(0,Math.min(1,+o||0)),this._.vol!==o&&(this._.vol=o,O(this,"volumechange"))},enumerable:!0,configurable:!0},muted:{get(){return this._.muted},set(o){o=!!o,this._.muted!==o&&(this._.muted=o,O(this,"volumechange"))},enumerable:!0,configurable:!0}}),a.playing=!1,a.paused=!1,a.ended=!1,a.seeking=!1,a.loop=!1,a.block=null,a._.lru=new Set,a}function pe(e,t={}){let r=t.sampleRate||44100;return Ae(bt(e),r,e.length,e[0].length,t,m.statSession?.(r).page(e).done())}function Sn(e,t={}){let r=t.sampleRate||44100,n=t.channels||1;return pe(Array.from({length:n},()=>new Float32Array(Math.round(e*r))),{...t,sampleRate:r})}function Fn(e,t={}){let r=t.sampleRate||44100,n=t.channels||1,l=t.duration;if(l==null)throw new TypeError("audio.from(fn): duration required");let i=Math.round(l*r),a=Array.from({length:n},()=>new Float32Array(i));for(let o=0;o<i;o++){let s=e(o/r,o);if(typeof s=="number")for(let f=0;f<n;f++)a[f][o]=s;else for(let f=0;f<n;f++)a[f][o]=s[f]??0}return pe(a,{sampleRate:r})}Object.defineProperties(T,{length:{get(){return this._.len},configurable:!0},duration:{get(){return this.length/this.sampleRate},configurable:!0},channels:{get(){return this._.ch},configurable:!0}});T[V]=async function(){this._.ready&&await this._.ready,this._.acc?.drain()};T[be]=function(e,t){return Me(this,e,t)};T.push=function(e,t){let r=this._.acc;if(!r)throw new Error("push: instance is not pushable \u2014 create with audio()");let n=this._.ch,l=this.sampleRate,i;if(Array.isArray(e)&&e[0]instanceof Float32Array)i=e;else if(e instanceof Float32Array)i=[e];else if(ArrayBuffer.isView(e)){let a=t||{},o=typeof a=="string"?a:a.format||"int16",s=a.channels||n,f={dtype:o,channels:s};s>1&&(f.interleaved=!0);let u=he(e,f,{dtype:"float32",interleaved:!1,channels:s}),c=u.length/s;i=Array.from({length:s},(h,d)=>u.subarray(d*c,(d+1)*c))}else throw new TypeError("push: expected Float32Array[], Float32Array, or typed array");if(!this._.ch)this._.ch=i.length,this._.chV=-1;else if(i.length!==this._.ch)throw new TypeError(`push: expected ${this._.ch} channels, got ${i.length}`);return r.push(i,t&&t.sampleRate||l),this._.len=r.length,this._.lenV=-1,this};T.stop=function(){if(this.playing=!1,this.paused=!1,this.seeking=!1,this._._wake&&this._._wake(),this.recording&&(this.recording=!1,this._._mic&&(this._._mic(null),this._._mic=null)),this._.acc&&!this.decoded&&(this._.acc.drain(),this.decoded=!0,this._.waiters))for(let e of this._.waiters.splice(0))e();return this};T.record=function(e={}){if(!this._.acc)throw new Error("record: instance is not pushable \u2014 create with audio()");if(this.recording)return this;this.recording=!0,this.decoded=!1;let t=this,r=this.sampleRate,n=this._.ch;return(async()=>{try{let{default:i}=await Promise.resolve().then(()=>(At(),_t)),a=i({sampleRate:r,channels:n,bitDepth:16,...e});t._._mic=a,a((o,s)=>{t.recording&&(o||!s||t.push(new Int16Array(s.buffer,s.byteOffset,s.byteLength/2),"int16"))})}catch(i){if(t.recording=!1,t.decoded=!0,t._.waiters)for(let a of t._.waiters.splice(0))a();throw i.code==="ERR_MODULE_NOT_FOUND"?new Error("record: audio-mic not installed \u2014 npm i audio-mic"):i}})().catch(()=>{}),this};T.seek=function(e){if(e=Math.max(0,e),this.seeking=!0,this.currentTime=e,this.cache){let t=Math.floor(e*this.sampleRate/m.PAGE_SIZE);(async()=>{for(let r=Math.max(0,t-1);r<=Math.min(t+2,this.pages.length-1);r++)this.pages[r]===null&&await this.cache.has(r)&&(this.pages[r]=await this.cache.read(r))})()}return this.playing?(this._._seekTo=e,this._._wake&&this._._wake()):this.seeking=!1,this};T.read=async function(e){(typeof e!="object"||e===null)&&(e={});let{at:t,duration:r,format:n,channel:l,meta:i}=e;t=P(t),r=P(r),await this[V]();let a=await this[be](t,r);if(l!=null&&(a=[a[l]]),!n)return l!=null?a[0]:a;let o=ee[n]?await ee[n](a,{sampleRate:this.sampleRate,...i}):a.map(s=>he(s,"float32",n));return l!=null&&Array.isArray(o)?o[0]:o};function bt(e){let t=e[0].length,r=[];for(let n=0;n<t;n+=m.PAGE_SIZE)r.push(e.map(l=>l.subarray(n,Math.min(n+m.PAGE_SIZE,t))));return r}function Te(e,t,r,n,l){let i=Math.floor(r/m.PAGE_SIZE),a=i*m.PAGE_SIZE;for(let o=i;o<e.pages.length&&a<r+n;o++){let s=e.pages[o],f=s?s[0].length:m.PAGE_SIZE;if(a+f>r&&s){let u=Math.max(r-a,0),c=Math.min(r+n-a,f);e._.lru&&(e._.lru.delete(o),e._.lru.add(o)),l(s,t,u,c,Math.max(a-r,0))}a+=f}}function de(e,t,r,n,l,i){Te(e,t,r,n,(a,o,s,f,u)=>l.set(a[o].subarray(s,f),i+u))}function Me(e,t,r){let n=e.sampleRate,l=e._.ch,i=t!=null?Math.min(Math.max(Math.round(t*n),0),e._.len):0,a=r!=null?Math.round(r*n):e._.len-i;a=Math.min(Math.max(a,0),e._.len-i);let o=Array.from({length:l},()=>new Float32Array(a));for(let s=0;s<l;s++)de(e,s,i,a,o[s],0);return o}async function De(e){if(e instanceof ArrayBuffer)return e;if(e instanceof Uint8Array)return e.buffer.slice(e.byteOffset,e.byteOffset+e.byteLength);if(e instanceof URL)return De(e.href);if(typeof e=="string"){if(/^(https?|data|blob):/.test(e)||typeof window<"u")return(await fetch(e)).arrayBuffer();if(e.startsWith("file:")){let{fileURLToPath:n}=await import("url");e=n(e)}let{readFile:t}=await import("fs/promises"),r=await t(e);return r.buffer.slice(r.byteOffset,r.byteOffset+r.byteLength)}throw new TypeError("audio: unsupported source type")}async function Pn(e){if(e instanceof ArrayBuffer||e instanceof Uint8Array){let n=e instanceof ArrayBuffer?new Uint8Array(e):e.byteOffset||e.byteLength!==e.buffer.byteLength?new Uint8Array(e.buffer.slice(e.byteOffset,e.byteOffset+e.byteLength)):new Uint8Array(e.buffer);return{format:N(n),bytes:n}}if(typeof e=="string"&&!/^(https?|data|blob):/.test(e)&&typeof window>"u"){let n=e;if(e.startsWith("file:")){let{fileURLToPath:f}=await import("url");n=f(e)}let{open:l}=await import("fs/promises"),i=await l(n,"r"),a=new Uint8Array(12);await i.read(a,0,12,0),await i.close();let o=N(new Uint8Array(a)),{createReadStream:s}=await import("fs");return{format:o,reader:s(n)}}let t=await De(e),r=new Uint8Array(t);return{format:N(r),bytes:r}}function Mt(e={}){let{pages:t=[],notify:r,ondata:n}=e,l=0,i=0,a=0,o=0,s=null,f;function u(c){t.push(c),a+=c[0].length,r?.()}return{pages:t,get sampleRate(){return l},get channels(){return i},get length(){return a+o},get partial(){return o>0?s.map(c=>c.subarray(0,o)):null},get partialLen(){return o},push(c,h){s||(l=h,i=c.length,s=Array.from({length:i},()=>new Float32Array(m.PAGE_SIZE)),f=m.statSession?.(l)),f?.page(c);let d=0,p=c[0].length;for(;d<p;){let g=Math.min(p-d,m.PAGE_SIZE-o);for(let w=0;w<i;w++)s[w].set(c[w].subarray(d,d+g),o);d+=g,o+=g,o===m.PAGE_SIZE&&(u(s),s=Array.from({length:i},()=>new Float32Array(m.PAGE_SIZE)),o=0)}if(n){let g=f?.delta();g&&n({delta:g,offset:(a+o)/l,sampleRate:l,channels:i,pages:t})}r?.()},drain(){o>0&&(u(s.map(c=>c.slice(0,o))),s=Array.from({length:i},()=>new Float32Array(m.PAGE_SIZE)),o=0)},done(){if(o>0&&u(s.map(c=>c.slice(0,o))),f?.flush(),n&&f){let c=f.delta();c&&n({delta:c,offset:a/l,sampleRate:l,channels:i,pages:t})}return{stats:f?.done(),length:a}}}}async function Cn(e,t={}){let{format:r,bytes:n,reader:l}=await Pn(e);if(!r||!z[r]){n||(n=new Uint8Array(await De(e)));let{channelData:h,sampleRate:d}=await z(n.buffer||n),p=t.pages||[],g=bt(h);for(let y of g)p.push(y),t.notify?.();let w=m.statSession?.(d)?.page(h)?.done()??null;return{pages:p,sampleRate:d,channels:h.length,decoding:Promise.resolve({stats:w,length:h[0].length})}}let i=await z[r](),a=()=>new Promise(h=>setTimeout(h,0)),o,s=t.notify,f=new Promise(h=>{o=h}),u=Mt({pages:t.pages,ondata:t.ondata,notify:()=>{if(s?.(),o){let h=o;o=null,h()}}}),c=(async()=>{try{if(l)for await(let p of l){let g=p instanceof Uint8Array?p:new Uint8Array(p),w=await i(g);w.channelData.length&&u.push(w.channelData,w.sampleRate),await a()}else{let p=65536;for(let g=0;g<n.length;g+=p){let w=await i(n.subarray(g,Math.min(g+p,n.length)));w.channelData.length&&u.push(w.channelData,w.sampleRate),await a()}}let h=await i();return h.channelData.length&&u.push(h.channelData,h.sampleRate),u.done()}catch(h){if(o){let d=o;o=null,d()}throw h}})();if(await f,!u.sampleRate)throw new Error("audio: decoded no audio data");return{pages:u.pages,sampleRate:u.sampleRate,channels:u.channels,decoding:c,acc:u}}var j=m.fn,K={};function S(e,t,r,n,l){let i=[e,t,r];return n!=null&&n!==1&&(i[3]=n),l!==void 0&&(i[4]=l),i}function q(e,t,r=0){let n=e??r;return n<0&&(n=t+n),Math.min(Math.max(0,n),t)}function H(e,t){let r=e.sampleRate,n=e.at!=null?Math.round(e.at*r):0;return[n,e.duration!=null?n+Math.round(e.duration*r):t]}function On(e){return e!=null&&typeof e=="object"&&!Array.isArray(e)&&!ArrayBuffer.isView(e)&&!e.pages&&!e.getChannelData}m.op=function(e,t,r,n){if(!arguments.length)return K;if(arguments.length===1)return K[e];let l;if(typeof t!="function")l=t;else{let i,a;typeof r=="function"?(i=r,a=n):a=r,l={process:t},i&&(l.plan=i),a&&Object.assign(l,a)}if(!j[e]&&!l.hidden){let i=function(...a){let o={type:e,args:a},s=a[a.length-1];if(a.length&&On(s)){let{at:f,duration:u,channel:c,offset:h,length:d,...p}=s;o.args=a.slice(0,-1),f!=null&&(o.at=P(f)),u!=null&&(o.duration=P(u)),h!=null&&(o.offset=h),d!=null&&(o.length=d),c!=null&&(o.channel=c),Object.assign(o,p)}return this.run(o)};j[e]=l.call?function(...a){return l.call.call(this,i,...a)}:i}K[e]=l};function Et(e,t){e.edits.push(t),e.version++,O(e,"change")}function Ln(e){let t=e.edits.pop();return t&&(e.version++,O(e,"change")),t}Object.defineProperties(j,{length:{get(){if(this._.lenV===this.version)return this._.lenC;let e=this.edits.length?Y(this).totalLen:this._.len;return this._.lenC=e,this._.lenV=this.version,e},configurable:!0},channels:{get(){if(this._.chV===this.version)return this._.chC;let e=this._.ch;for(let t of this.edits)K[t.type]?.ch&&(e=K[t.type].ch(e,t.args));return this._.chC=e,this._.chV=this.version,e},configurable:!0}});async function ae(e,t,r,n){if(!m.ensurePages)return;let{segs:l,sr:i}=t,a=Math.round((r||0)*i),o=n!=null?a+Math.round(n*i):t.totalLen;for(let s of l){let f=Math.max(a,s[2]),u=Math.min(o,s[2]+s[1]);if(f>=u)continue;let c=Math.abs(s[3]||1),h=s[0]+(f-s[2])*c,d=(u-f)*c+1,p=s[4]===null?null:s[4]||e;p&&await m.ensurePages(p,h/i,d/i)}}async function vt(e){for(let{args:t}of e.edits)t?.[0]?.pages&&await t[0][V]()}j[be]=async function(e,t){if(!this.edits.length)return m.ensurePages&&await m.ensurePages(this,e,t),Me(this,e,t);await this[V](),await vt(this);let r=Y(this);return await ae(this,r,e,t),Ue(this,r,e,t)};j[Symbol.asyncIterator]=j.stream=async function*(e){let t=P(e?.at),r=P(e?.duration);if(this._.waiters&&!this.decoded&&!this.edits.length){let i=this.sampleRate,a=this._.acc,o=m.PAGE_SIZE,s=t?Math.round(t*i):0,f=r!=null?s+Math.round(r*i):1/0,u=s;for(;u<f;){let c=a?this.pages.length*o+a.partialLen:this._.len;for(;u>=c&&!this.decoded;)await new Promise(g=>this._.waiters.push(g)),c=a?this.pages.length*o+a.partialLen:this._.len;if(u>=c)break;let h=Math.min(f,c),d=Math.floor(u/o),p=u%o;if(d<this.pages.length){let g=this.pages[d],w=Math.min(g[0].length-p,h-u);yield g.map(y=>y.subarray(p,p+w)),u+=w}else if(a){let g=Math.min(a.partialLen-p,h-u);g>0&&(yield a.partial.map(w=>w.subarray(p,p+g).slice()),u+=g)}}return}await this.ready,await this[V](),await vt(this);let n=Y(this),l=new Set;for(let i of n.segs)i[4]&&i[4]!==null&&!l.has(i[4])&&(l.add(i[4]),await i[4][V]());await ae(this,n,t,r);for(let i of oe(this,n,t,r))yield i};j.undo=function(e=1){if(!this.edits.length)return e===1?null:[];let t=[];for(let r=0;r<e&&this.edits.length;r++)t.push(Ln(this));return e===1?t[0]:t};j.run=function(...e){let t=this.sampleRate;for(let r of e){if(!r.type)throw new TypeError("audio.run: edit must have type");let n={...r,args:r.args||[]};n.at!=null&&(n.at=P(n.at)),n.duration!=null&&(n.duration=P(n.duration)),n.offset!=null&&(n.at=n.offset/t,delete n.offset),n.length!=null&&(n.duration=n.length/t,delete n.length),Et(this,n)}return this};j.toJSON=function(){let e=this.edits.filter(t=>!t.args?.some(r=>typeof r=="function"));return{source:this.source,edits:e,sampleRate:this.sampleRate,channels:this.channels,duration:this.duration}};j.clone=function(){let e=m.from(this);for(let t of this.edits)Et(e,{...t});return e};var In=2**29;function St(e,t,r){if(Array.isArray(e)&&e[0]instanceof Float32Array)return t!=null?e.map(a=>a.subarray(t,t+r)):e;if(e?.getChannelData&&!e.pages){let a=Array.from({length:e.numberOfChannels},(o,s)=>new Float32Array(e.getChannelData(s)));return t!=null?a.map(o=>o.subarray(t,t+r)):a}if(t!=null)return Pt(e,t,r);if(e._.pcm&&e._.pcmV===e.version)return e._.pcm;if(!e.edits.length){let a=Me(e);return e._.pcm=a,e._.pcmV=e.version,a}let n=Y(e),l=me(n.segs);if(l>In)throw new Error(`Audio too large for flat render (${(l/1e6).toFixed(0)}M samples). Use streaming.`);let i=Ue(e,n);return e._.pcm=i,e._.pcmV=e.version,i}function me(e){let t=0;for(let r of e)t=Math.max(t,r[2]+r[1]);return t}function Y(e){if(e._.plan&&e._.planV===e.version)return e._.plan;let t=e.sampleRate,r=e._.ch,n=[[0,e._.len,0]],l=[];for(let a of e.edits){let{type:o,args:s=[],at:f,duration:u,channel:c,...h}=a,d=K[o];if(!d)throw new Error(`Unknown op: ${o}`);if(d.resolve){let p={...h,stats:e._.srcStats||e.stats,sampleRate:t,channelCount:r,channel:c,at:f,duration:u,totalDuration:me(n)/t},g=d.resolve(s,p);if(g===!1)continue;if(g){let w=Array.isArray(g)?g:[g];for(let y of w){c!=null&&y.channel==null&&(y.channel=c),f!=null&&y.at==null&&(y.at=f),u!=null&&y.duration==null&&(y.duration=u);let _=K[y.type];if(_?.plan&&typeof _.plan=="function"){let A=me(n),b=y.at!=null?Math.round(y.at*t):null,x=y.duration!=null?Math.round(y.duration*t):null;n=_.plan(n,{total:A,sampleRate:t,args:y.args||[],offset:b,length:x})}else l.push(y)}continue}}if(d.plan){let p=me(n),g=f!=null?Math.round(f*t):null,w=u!=null?Math.round(u*t):null;n=d.plan(n,{total:p,sampleRate:t,args:s,offset:g,length:w})}else l.push(a)}let i={segs:n,pipeline:l,totalLen:me(n),sr:t};return e._.plan=i,e._.planV=e.version,i}var xt=null,Rt=0;function kt(e,t,r,n,l,i,a){let o=a||1,s=Math.abs(o);if(s===1)return o>0?de(e,t,r,n,l,i):Te(e,t,r,n,(c,h,d,p,g)=>{for(let w=d;w<p;w++)l[i+(n-1-(g+w-d))]=c[h][w]});let f=Math.ceil(n*s)+1;f>Rt&&(Rt=f,xt=new Float32Array(f));let u=xt.subarray(0,f);u.fill(0),de(e,t,r,f,u,0),Ft(u,l,i,n,o)}function Ft(e,t,r,n,l){let i=Math.abs(l),a=l<0;for(let o=0;o<n;o++){let s=(a?n-1-o:o)*i,f=s|0,u=s-f;t[r+o]=f+1<e.length?e[f]+(e[f+1]-e[f])*u:e[f]||0}}function Pt(e,t,r){if(!e.edits.length)return Array.from({length:e._.ch},(i,a)=>{let o=new Float32Array(r);return de(e,a,t,r,o,0),o});let n=Y(e),l=n.sr;return Ue(e,n,t/l,r/l)}function*oe(e,t,r,n){let{segs:l,pipeline:i,totalLen:a,sr:o}=t,s=Math.round((r||0)*o),f=n!=null?s+Math.round(n*o):a,u=a/o,c=i.map(p=>{let g=K[p.type],{type:w,args:y,at:_,duration:A,channel:b,...x}=p;return{op:g.process,at:_!=null&&_<0?u+_:_,dur:A,channel:b,ctx:{...x,args:y||[],duration:A,sampleRate:o,totalDuration:u,render:St}}}),d=s>0&&c.length?Math.max(0,s-m.BLOCK_SIZE*8):s;for(let p=d;p<f;p+=m.BLOCK_SIZE){let g=p<s?s:f,w=Math.min(m.BLOCK_SIZE,g-p),y=Array.from({length:e._.ch},()=>new Float32Array(w));for(let A of l){let b=Math.max(p,A[2]),x=Math.min(p+w,A[2]+A[1]);if(b>=x)continue;let M=A[3]||1,R=A[4],k=Math.abs(M),v=x-b,F=b-p,C=M<0?A[0]+(A[1]-(b-A[2])-v)*k:A[0]+(b-A[2])*k;if(R!==null)if(R)if(R.edits.length===0)for(let I=0;I<e._.ch;I++)kt(R,I%R._.ch,C,v,y[I],F,M);else{let I=Math.ceil(v*k)+1,X=Pt(R,C,I);for(let B=0;B<e._.ch;B++){let Z=X[B%X.length];if(k===1)if(M<0)for(let Q=0;Q<v;Q++)y[B][F+Q]=Z[v-1-Q];else y[B].set(Z.subarray(0,v),F);else Ft(Z,y[B],F,v,M)}}else for(let I=0;I<e._.ch;I++)kt(e,I,C,v,y[I],F,M)}let _=p/o;for(let A of c){let{op:b,at:x,channel:M,ctx:R}=A;if(b)if(R.at=x!=null?x-_:void 0,R.blockOffset=_,M!=null){let k=typeof M=="number"?[M]:M,v=k.map(C=>y[C]),F=b(v,R);if(F&&F!==!1)for(let C=0;C<k.length;C++)y[k[C]]=F[C]}else{let k=b(y,R);if(k===!1||k===null)continue;k&&(y=k)}}p>=s&&(yield y)}}function Ue(e,t,r,n){let l=[];for(let o of oe(e,t,r,n))l.push(o);if(!l.length)return Array.from({length:e.channels},()=>new Float32Array(0));let i=l[0].length,a=l.reduce((o,s)=>o+s[0].length,0);return Array.from({length:i},(o,s)=>{let f=new Float32Array(a),u=0;for(let c of l)f.set(c[s],u),u+=c[0].length;return f})}var Tn=500*1024*1024;async function Dn(e){if(!e.cache||e.budget===1/0)return;let t=l=>l?l.reduce((i,a)=>i+a.byteLength,0):0,r=e.pages.reduce((l,i)=>l+t(i),0);if(r<=e.budget)return;let n=e._.lru&&e._.lru.size?[...e._.lru]:e.pages.map((l,i)=>i);for(let l of n){if(r<=e.budget)break;e.pages[l]&&(await e.cache.write(l,e.pages[l]),r-=t(e.pages[l]),e.pages[l]=null,e._.lru&&e._.lru.delete(l))}}async function Un(e,t,r){if(!e.cache)return;let n=m.PAGE_SIZE,l=e.sampleRate,i=t!=null?Math.max(0,Math.round(t*l)):0,a=r!=null?Math.round(r*l):e._.len-i,o=Math.floor(i/n),s=Math.min(Math.ceil((i+a)/n),e.pages.length);for(let f=o;f<s;f++)e.pages[f]===null&&await e.cache.has(f)&&(e.pages[f]=await e.cache.read(f))}async function Bn(e="audio-cache"){if(typeof navigator>"u"||!navigator.storage?.getDirectory)throw new Error("OPFS not available in this environment");let r=await(await navigator.storage.getDirectory()).getDirectoryHandle(e,{create:!0});return{async read(n){let a=await(await(await r.getFileHandle(`p${n}`)).getFile()).arrayBuffer(),o=new Float32Array(a),s=o[0]|0,f=(o.length-1)/s|0,u=[];for(let c=0;c<s;c++)u.push(o.slice(1+c*f,1+(c+1)*f));return u},async write(n,l){let a=await(await r.getFileHandle(`p${n}`,{create:!0})).createWritable(),o=1+l.reduce((u,c)=>u+c.length,0),s=new Float32Array(o);s[0]=l.length;let f=1;for(let u of l)s.set(u,f),f+=u.length;await a.write(s.buffer),await a.close()},has(n){return r.getFileHandle(`p${n}`).then(()=>!0,()=>!1)},async evict(n){try{await r.removeEntry(`p${n}`)}catch{}},async clear(){for await(let[n]of r)await r.removeEntry(n)}}}m.opfsCache=Bn;m.evict=Dn;m.ensurePages=Un;m.DEFAULT_BUDGET=Tn;var Be={};m.stat=function(e,t){if(!arguments.length)return Be;if(arguments.length===1)return Be[e];typeof t=="function"&&(t={block:t}),Be[e]=t};function xe(e){let t,r,n,l=0,i=null,a=0;function o(f){n=f,t=Object.entries(m.stat()).filter(([u,c])=>c.block).map(([u,c])=>({name:u,fn:c.block,ctx:{sampleRate:e}})),r=Object.create(null);for(let{name:u}of t)r[u]=Array.from({length:n},()=>[])}function s(f){for(let{name:u,fn:c,ctx:h}of t){let d=c(f,h);if(typeof d=="number")for(let p=0;p<n;p++)r[u][p].push(d);else for(let p=0;p<n;p++)r[u][p].push(d[p])}}return{page(f){r||o(f.length);let u=m.BLOCK_SIZE,c=0,h=f[0].length;if(a>0){let d=u-a;if(h>=d){for(let p=0;p<n;p++)i[p].set(f[p].subarray(0,d),a);s(i),c=d,a=0}else{for(let p=0;p<n;p++)i[p].set(f[p].subarray(0,h),a);return a+=h,this}}for(;c+u<=h;)s(Array.from({length:n},(d,p)=>f[p].subarray(c,c+u))),c+=u;if(c<h){i||(i=Array.from({length:n},()=>new Float32Array(u)));for(let d=0;d<n;d++)i[d].set(f[d].subarray(c));a=h-c}return this},flush(){a>0&&(s(Array.from({length:n},(f,u)=>i[u].subarray(0,a))),a=0)},delta(){if(!r)return;let f=Object.keys(r)[0];if(!f)return;let u=r[f][0].length;if(u<=l)return;let c={fromBlock:l};for(let h in r)c[h]=r[h].map(d=>new Float32Array(d.slice(l)));return l=u,c},done(){this.flush();let f={blockSize:m.BLOCK_SIZE};if(r)for(let u in r)f[u]=r[u].map(c=>new Float32Array(c));return f}}}function jn(e,t,r,n,l){if(n<=0||r<=t)return new Float32Array(Math.max(0,n));if(t=Math.max(0,t),r=Math.min(r,e.length),r<=t)return new Float32Array(n);let i=new Float32Array(n),a=(r-t)/n;for(let o=0;o<n;o++){let s=t+Math.floor(o*a),f=Math.min(t+Math.floor((o+1)*a),r);f<=s&&(f=s+1),i[o]=l(e,s,f)}return i}function qn(e,t,r){let n=e.blockSize,l=t.segs,i=t.totalLen;for(let u of l){let c=u[3]||1,h=u[4];if(h!=null||Math.abs(c)!==1||u[0]%n!==0||u[2]%n!==0)return null}let a=Math.ceil(i/n),o=Object.keys(e).filter(u=>u!=="blockSize"&&Array.isArray(e[u])),s=e[o[0]]?.length||1,f={blockSize:n};for(let u of o)f[u]=Array.from({length:s},()=>new Float32Array(a));for(let u of l){let c=u[0],h=u[1],d=u[2],p=u[3]||1,g=u[4],w=Math.floor(d/n),y=Math.ceil((d+h)/n);if(g===null)continue;let _=Math.floor(c/n),A=e[o[0]][0].length,b=p<0;for(let x=w;x<y&&x<a;x++){let M=b?_+(y-1-x):_+(x-w);if(!(M<0||M>=A))for(let R of o)for(let k=0;k<s;k++)f[R][k][x]=e[R][k][M]}}return f}m.statSession=xe;async function je(e,t){await e[V]();let r=P(t?.at),n=P(t?.duration),l=r!=null||n!=null;if(e.edits?.length&&e._.statsV!==e.version){if(e._.srcStats||(e._.srcStats=e.stats),l){let d=Y(e);await ae(e,d,r||0,n);let p=xe(e.sampleRate);for(let _ of oe(e,d,r||0,n))p.page(_);let g=p.done(),y=Object.values(g).find(_=>_?.[0]?.length)?.[0]?.length||0;return{stats:g,ch:e.channels,sr:e.sampleRate,from:0,to:y}}let h=Y(e);if(!h.pipeline.length&&e._.srcStats?.blockSize){let d=qn(e._.srcStats,h,e.sampleRate);if(d)e.stats=d,e._.statsV=e.version;else{let p=xe(e.sampleRate);await ae(e,h);for(let g of oe(e,h))p.page(g);e.stats=p.done(),e._.statsV=e.version}}else{let d=xe(e.sampleRate);await ae(e,h);for(let p of oe(e,h))d.page(p);e.stats=d.done(),e._.statsV=e.version}}let i=e.sampleRate,a=e.stats?.blockSize;if(!a)return{stats:e.stats,ch:e.channels,sr:i,from:0,to:0};let s=Object.values(e.stats).find(h=>h?.[0]?.length)?.[0]?.length||0,f=r!=null&&r<0?e.duration+r:r,u=f!=null?Math.floor(f*i/a):0,c=n!=null?Math.ceil(((f||0)+n)*i/a):s;return u=Math.max(0,Math.min(u,s)),c=Math.max(u,Math.min(c,s)),{stats:e.stats,ch:e.channels,sr:i,from:u,to:c}}m.fn.stat=async function(e,t){if(Array.isArray(e))return Promise.all(e.map(g=>this.stat(g,t)));if(typeof this[e]=="function"&&!m.stat(e))return this[e](t);let{stats:r,ch:n,sr:l,from:i,to:a}=await je(this,t),o=t?.bins,s=t?.channel,f=Array.isArray(s),u=s!=null?f?s:[s]:Array.from({length:n},(g,w)=>w),c=m.stat(e);if(c?.query&&o==null)return c.query(r,u,i,a,l);let h=r[e],d=c?.reduce;if(!h)throw new Error(`Unknown stat: '${e}'`);if(!d)throw new Error(`No reducer for stat: '${e}'`);if(o!=null){let g=o??a-i,w=A=>jn(h[A],i,a,g,d);if(f)return u.map(w);if(u.length===1)return w(u[0]);let y=new Float32Array(g),_=(a-i)/g;for(let A=0;A<g;A++){let b=i+Math.floor(A*_),x=Math.min(i+Math.floor((A+1)*_),a);x<=b&&(x=b+1);let M=0;for(let R of u)M+=d(h[R],b,x);y[A]=M/u.length}return y}if(f)return u.map(g=>d(h[g],i,a));if(u.length===1)return d(h[u[0]],i,a);let p=u.map(g=>d(h[g],i,a));return p.reduce((g,w)=>g+w,0)/p.length};function qe(e,t,r){let n=[],l=t+r;for(let i of e){let a=Math.max(i[2],t),o=Math.min(i[2]+i[1],l);a<o&&n.push(S(i[0]+(a-i[2])*Math.abs(i[3]||1),o-a,a-t,i[3],i[4]))}return n}var Qn=(e,t)=>{let{total:r,length:n}=t,l=q(t.offset,r);return qe(e,l,Math.max(0,Math.min(n??r-l,r-l)))};m.op("crop",{plan:Qn});m.fn.clip=function(e){let t=this.clone?this.clone():m.from(this),r=P(e?.at),n=P(e?.duration);return r!=null||n!=null?t.crop({at:r??0,duration:n??Math.max(0,this.duration-(r??0))}):t};m.fn.split=function(...e){let t=(Array.isArray(e[0])?e[0]:e).map(P),r=this.duration,n=[0,...t.sort((l,i)=>l-i).filter(l=>l>0&&l<r),r];return n.slice(0,-1).map((l,i)=>this.clip({at:l,duration:n[i+1]-l}))};import Vn from"audio-speaker";function Qe(e,t,r,n,l){let i=Math.min(l,r);if(n)for(let a=0;a<i;a++){let o=a/i;for(let s=0;s<t;s++)e[a*t+s]*=o}else{let a=r-i;for(let o=0;o<i;o++){let s=1-o/i;for(let f=0;f<t;f++)e[(a+o)*t+f]*=s}}}m.fn.play=function(e){let t=e?.at??0,r=e?.duration,n=this,l=m.BLOCK_SIZE;n.playing&&(n.playing=!1,n.paused=!1,n._._wake&&n._._wake()),n.playing=!1,n.paused=e?.paused??!1,n.currentTime=t,e?.volume!=null&&(n.volume=e.volume),n.loop=e?.loop??!1,n.block=null,n._._wake=null,n._._seekTo=null,n.ended=!1;let i,a;return n.played=new Promise((o,s)=>{i=o,a=s}),n.played.catch(()=>{}),(async()=>{try{let o=n.channels,s=n.sampleRate;n.playing=!0,n.paused||O(n,"play");let f=!1,u=async()=>{for(;n.paused&&n.playing&&n._._seekTo==null;)await new Promise(d=>{n._._wake=d});n._._wake=null},c=t,h=256;for(;n.playing;){if(n.paused){if(await u(),!n.playing)break;n._._seekTo!=null&&(c=n._._seekTo,n._._seekTo=null,n.currentTime=c,n.seeking=!1)}let d=Vn({sampleRate:s,channels:o,bitDepth:32}),p=!1,g=0,w=!0,y=async()=>{let _=new Uint8Array(l*o*4);await new Promise(A=>d(_,A)),await new Promise(A=>d(_,A))};for await(let _ of n.stream({at:c,duration:r})){if(!n.playing)break;let A=_[0].length;for(let b=0;b<A;b+=l){if(n._._seekTo!=null){c=n._._seekTo,n._._seekTo=null,n.currentTime=c,n.seeking=!1,p=!0;break}let x=Math.min(b+l,A),M=x-b;n.block=_[0].subarray(b,x);let R=n.muted?0:n.volume,k=new Float32Array(M*o);for(let F=0;F<M;F++)for(let C=0;C<o;C++)k[F*o+C]=(_[C]||_[0])[b+F]*R;let v=()=>new Promise(F=>d(new Uint8Array(k.buffer),F));if(w&&(Qe(k,o,M,!0,h),w=!1),n.paused){if(Qe(k,o,M,!1,h),await v(),await y(),g+=M,n.currentTime=c+g/s,await u(),n._._seekTo!=null)continue;if(!n.playing)break;w=!0;continue}if(!n.playing){Qe(k,o,M,!1,h),await v();break}await v(),f||(f=!0,i()),g+=M,n._._seekTo==null&&(n.currentTime=c+g/s,O(n,"timeupdate",n.currentTime))}if(p||!n.playing)break}if(!p&&!n.playing&&await y(),p&&(await y(),w=!0),d(null),!p){if(!n.playing)break;if(n.loop){c=0,n.currentTime=0,O(n,"timeupdate",0);continue}n.playing=!1,n.ended=!0,O(n,"timeupdate",n.currentTime);break}}n.playing=!1,O(n,"ended"),f||i()}catch(o){console.error("Playback error:",o),n.playing=!1,resolved?O(n,"error",o):a(o)}})(),this};var Ct=m.fn;Ct.pause=function(){!this.paused&&this.playing&&(this.paused=!0,O(this,"pause"))};Ct.resume=function(){this.paused&&(this._.ctStamp=performance.now(),this.paused=!1,O(this,"play"),this._._wake&&this._._wake())};var Zn={aif:"aiff",oga:"ogg"};function Ot(e){return Zn[e]||e||"wav"}async function Lt(e,t,r,n){let l=await ee[t]({sampleRate:e.sampleRate,channels:e.channels,...r.meta}),i=0,a=0;for await(let s of e.stream({at:r.at,duration:r.duration})){let f=await l(s);f.length&&await n(f),i+=s[0].length,++a%2===0&&await new Promise(u=>setTimeout(u,0)),O(e,"progress",{offset:i/e.sampleRate,total:(r.duration!=null?P(r.duration):null)??e.duration})}let o=await l();return o.length&&await n(o),n(null)}m.fn.encode=async function(e,t={}){if(typeof e=="object"&&(t=e,e=void 0),e=Ot(e),!ee[e])throw new Error("Unknown format: "+e);let r=[];await Lt(this,e,t,a=>{a&&r.push(a)});let n=r.reduce((a,o)=>a+o.length,0),l=new Uint8Array(n),i=0;for(let a of r)l.set(a,i),i+=a.length;return l};m.fn.save=async function(e,t={}){let r=t.format??(typeof e=="string"?e.split(".").pop():"wav");if(r=Ot(r),!ee[r])throw new Error("Unknown format: "+r);let n,l;if(typeof e=="string"){let{createWriteStream:i}=await import("fs"),a=i(e);n=o=>{if(!a.write(Buffer.from(o)))return new Promise(s=>a.once("drain",s))},l=()=>new Promise((o,s)=>{a.on("finish",o),a.on("error",s),a.end()})}else if(e?.write)n=i=>e.write(i),l=()=>e.close?.();else throw new Error("Invalid save target");await Lt(this,r,t,i=>i?n(i):l?.())};function zn(e,t,r){let n=[],l=t+r;for(let i of e){let a=i[2]+i[1];if(a<=t)n.push(i);else if(i[2]>=l){let o=i.slice();o[2]=i[2]-r,n.push(o)}else{let o=Math.abs(i[3]||1);i[2]<t&&n.push(S(i[0],t-i[2],i[2],i[3],i[4])),a>l&&n.push(S(i[0]+(l-i[2])*o,a-l,t,i[3],i[4]))}}return n}var Gn=(e,t)=>{let{total:r}=t,n=q(t.offset,r);return zn(e,n,Math.min(t.length??r-n,r-n))};m.op("remove",{plan:Gn});function Wn(e,t,r,n){let l=[];for(let i of e)if(i[2]+i[1]<=t)l.push(i);else if(i[2]>=t){let a=i.slice();a[2]=i[2]+r,l.push(a)}else{let a=t-i[2],o=Math.abs(i[3]||1);l.push(S(i[0],a,i[2],i[3],i[4])),l.push(S(i[0]+a*o,i[1]-a,t+r,i[3],i[4]))}return l.push(S(0,r,t,void 0,n??null)),l.sort((i,a)=>i[2]-a[2]),l}var $n=(e,t)=>{let{total:r,sampleRate:n,args:l}=t,i=l[0],a=q(t.offset,r,r);typeof i!="number"&&!i?.pages&&(i=m.from(i,{sampleRate:n}));let o=typeof i=="number"?Math.round(i*n):i.length;return t.length!=null&&(o=Math.min(o,t.length)),Wn(e,a,o,typeof i=="number"?null:i)};m.op("insert",{plan:$n});function Kn(e,t,r,n,l){if(n==null){let s=[];for(let f=0;f<=t;f++)for(let u of e){let c=u.slice();c[2]=u[2]+r*f,s.push(c)}return s}let i=l??r-n,a=qe(e,n,i),o=[];for(let s of e){let f=s[2]+s[1];if(f<=n+i)o.push(s);else if(s[2]>=n+i){let u=s.slice();u[2]=s[2]+i*t,o.push(u)}else{let u=Math.abs(s[3]||1),c=n+i-s[2];o.push(S(s[0],c,s[2],s[3],s[4])),o.push(S(s[0]+c*u,f-n-i,n+i*(t+1),s[3],s[4]))}}for(let s=1;s<=t;s++)for(let f of a){let u=f.slice();u[2]=n+i*s+f[2],o.push(u)}return o.sort((s,f)=>s[2]-f[2]),o}var Hn=(e,t)=>{let{total:r,args:n,length:l}=t,i=t.offset!=null?q(t.offset,r):null;return Kn(e,n[0]??1,r,i,l)};m.op("repeat",{plan:Hn});var Yn=(e,t)=>{let r=t.unit==="linear",n=t.args[0]??(r?1:0),[l,i]=H(t,e[0].length),a=typeof n=="function",o=a?0:r?n:10**(n/20),s=(t.blockOffset||0)*t.sampleRate,f=r?u=>u:u=>10**(u/20);for(let u of e)for(let c=Math.max(0,l);c<Math.min(i,u.length);c++)u[c]*=a?f(n((s+c)/t.sampleRate)):o;return e};m.op("gain",{process:Yn});var It={linear:e=>e,exp:e=>e*e,log:e=>Math.sqrt(e),cos:e=>(1-Math.cos(e*Math.PI))/2},Jn=(e,t)=>{let r=t.args[0],n=It[t.curve]??It.linear,l=r>0,i=Math.abs(r),a=t.sampleRate,o=t.blockOffset||0,s=t.at!=null?t.at+o:void 0;s!=null&&s<0&&(s=t.totalDuration+s);let f=Math.round((t.totalDuration||e[0].length/a+o)*a),u=s!=null?Math.round(s*a):l?0:f-Math.round(i*a),c=Math.round(i*a),h=Math.round(o*a);for(let d of e)for(let p=0;p<d.length;p++){let g=h+p-u;g<0||g>=c||(d[p]*=n(l?g/c:1-g/c))}return e};m.op("fade",{process:Jn,call(e,...t){let r=t[t.length-1],n=typeof r=="object"?t.pop():typeof r=="string"?{curve:t.pop()}:null;typeof t[t.length-1]=="string"&&(n={...n,curve:t.pop()});let[l,i]=t;return i!=null?(e.call(this,Math.abs(l),n||{}),e.call(this,-Math.abs(i),n||{})):n?e.call(this,l,n):e.call(this,l)}});function Xn(e,t,r){let n=[];for(let l of e){let i=l[2]+l[1];if(i<=t||l[2]>=r){n.push(l);continue}let a=Math.abs(l[3]||1);l[2]<t&&n.push(S(l[0],t-l[2],l[2],l[3],l[4]));let o=Math.max(l[2],t),s=Math.min(i,r);n.push(S(l[0]+(o-l[2])*a,s-o,t+r-s,-(l[3]||1),l[4])),i>r&&n.push(S(l[0]+(r-l[2])*a,i-r,r,l[3],l[4]))}return n.sort((l,i)=>l[2]-i[2]),n}var Nn=(e,t)=>{let{total:r,length:n}=t,l=q(t.offset,r);return Xn(e,l,l+(n??r-l))};m.op("reverse",{plan:Nn});var er=(e,t)=>{let r=t.args[0],n=t.sampleRate,l=e[0].length;if(typeof r=="number")throw new TypeError("mix: expected audio instance or Float32Array[], not a number");let i=Array.isArray(r)?r[0].length:r.length,[a]=H(t,l),o=Math.max(0,-a),s=Math.max(0,a),f=Math.min(i-o,l-s);if(t.duration!=null&&(f=Math.min(f,Math.round(t.duration*n)-o)),f<=0)return e;let u=t.render(r,o,f);for(let c=0;c<e.length;c++){let h=u[c%u.length];for(let d=0;d<f;d++)e[c][s+d]+=h[d]}return e};m.op("mix",{process:er});var tr=(e,t)=>{let r=t.args[0],[n,l]=H(t,e[0].length),i=Math.max(0,-n),a=Math.max(0,n);for(let o=0;o<e.length;o++){let s=Array.isArray(r)?r[o]||r[0]:r;for(let f=i;f<s.length&&a+f-i<l;f++)e[o][a+f-i]=s[f]}return e};m.op("write",{process:tr});var nr=(e,t)=>{let r=t.args[0],n=e[0].length;if(Array.isArray(r))return r.map(a=>a==null?new Float32Array(n):new Float32Array(e[(a%e.length+e.length)%e.length]));let l=e.length,i=r;if(l===i)return!1;if(i<l){let a=new Float32Array(n);for(let s=0;s<l;s++)for(let f=0;f<n;f++)a[f]+=e[s][f];let o=1/l;for(let s=0;s<n;s++)a[s]*=o;return Array.from({length:i},()=>new Float32Array(a))}return Array.from({length:i},(a,o)=>new Float32Array(e[o%l]))},rr=(e,t)=>Array.isArray(t[0])?t[0].length:t[0];m.op("remix",{process:nr,ch:rr});function Tt(e){let t=e.filter(n=>n>0);if(!t.length)return-40;t.sort((n,l)=>n-l);let r=t[Math.floor(t.length*.1)];return Math.max(-80,Math.min(-20,10*Math.log10(r)+12))}function Ve(e,t,r,n,l){if(l==null){let i=[];for(let a=0;a<t;a++)for(let o=r;o<n;o++)i.push(e.energy[a][o]);l=Tt(i)}return 10**(l/20)}var Re=(e,t,r,n)=>{for(let l=0;l<r;l++)if(Math.max(Math.abs(e.min[l][t]),Math.abs(e.max[l][t]))>n)return!0;return!1},lr=(e,t)=>{let r=t.args[0];if(r==null){let o=[];for(let s=0;s<e.length;s++)for(let f=0;f<e[s].length;f+=m.BLOCK_SIZE){let u=Math.min(f+m.BLOCK_SIZE,e[s].length),c=0;for(let h=f;h<u;h++)c+=e[s][h]*e[s][h];o.push(c/(u-f))}r=Tt(o)}let n=10**(r/20),l=e[0].length,i=0,a=l-1;for(;i<l;i++){let o=!1;for(let s=0;s<e.length;s++)if(Math.abs(e[s][i])>n){o=!0;break}if(o)break}for(;a>=i;a--){let o=!1;for(let s=0;s<e.length;s++)if(Math.abs(e[s][a])>n){o=!0;break}if(o)break}return a++,i===0&&a===l?!1:e.map(o=>o.slice(i,a))},ir=(e,{stats:t,sampleRate:r,totalDuration:n})=>{if(!t?.min||!t?.energy)return null;let l=t.min.length,i=t.min[0].length,a=Math.round(n*r),o=Ve(t,l,0,t.energy[0].length,e[0]),s=0,f=i-1;for(;s<i&&!Re(t,s,l,o);s++);for(;f>=s&&!Re(t,f,l,o);f--);if(f++,s===0&&f===i)return!1;if(s>=f)return{type:"crop",args:[],at:0,duration:0};let u=s*m.BLOCK_SIZE,c=Math.min(f*m.BLOCK_SIZE,a);return{type:"crop",args:[],at:u/r,duration:(c-u)/r}};m.op("trim",{process:lr,resolve:ir});function L(e,t){let r=t.coefs;Array.isArray(r)||(r=[r]);let n=r.length;if(!t.state){t.state=new Array(n);for(let i=0;i<n;i++)t.state[i]=[0,0]}let l=t.state;for(let i=0,a=e.length;i<a;i++){let o=e[i];for(let s=0;s<n;s++){let f=r[s],u=l[s],c=f.b0*o+u[0];u[0]=f.b1*o-f.a1*c+u[1],u[1]=f.b2*o-f.a2*c,o=c}e[i]=o}return e}var{sin:ar,cos:or,sqrt:Dt,pow:ke,PI:fr}=Math,ge={b0:0,b1:0,b2:0,a1:0,a2:0},fe={b0:1,b1:0,b2:0,a1:0,a2:0};var Ze=e=>({b0:e,b1:0,b2:0,a1:0,a2:0});function te(e,t,r,n,l,i){return{b0:e/n,b1:t/n,b2:r/n,a1:l/n,a2:i/n}}function ne(e,t,r){let n=2*fr*e/r,l=ar(n),i=or(n),a=l/(2*t);return{sinw:l,cosw:i,alpha:a}}function Ut(e,t,r){if(e<=0)return ge;if(e>=r/2)return fe;let{cosw:n,alpha:l}=ne(e,t,r);return te((1-n)/2,1-n,(1-n)/2,1+l,-2*n,1-l)}function Ee(e,t,r){if(e<=0)return fe;if(e>=r/2)return ge;let{cosw:n,alpha:l}=ne(e,t,r);return te((1+n)/2,-(1+n),(1+n)/2,1+l,-2*n,1-l)}function Bt(e,t,r){if(e<=0||e>=r/2||t<=0)return ge;let{sinw:n,cosw:l,alpha:i}=ne(e,t,r);return te(n/2,0,-n/2,1+i,-2*l,1-i)}function jt(e,t,r){if(e<=0||e>=r/2)return fe;if(t<=0)return ge;let{cosw:n,alpha:l}=ne(e,t,r);return te(1,-2*n,1,1+l,-2*n,1-l)}function qt(e,t,r,n){if(e<=0||e>=r/2)return fe;if(t<=0)return Ze(ke(10,n/20));let{cosw:l,alpha:i}=ne(e,t,r),a=ke(10,n/40);return te(1+i*a,-2*l,1-i*a,1+i/a,-2*l,1-i/a)}function ve(e,t,r,n){let l=ke(10,n/40);if(e<=0)return fe;if(e>=r/2)return Ze(l*l);let{cosw:i,alpha:a}=ne(e,t,r),o=2*Dt(l)*a;return te(l*(l+1-(l-1)*i+o),2*l*(l-1-(l+1)*i),l*(l+1-(l-1)*i-o),l+1+(l-1)*i+o,-2*(l-1+(l+1)*i),l+1+(l-1)*i-o)}function se(e,t,r,n){let l=ke(10,n/40);if(e<=0)return Ze(l*l);if(e>=r/2)return fe;let{cosw:i,alpha:a}=ne(e,t,r),o=2*Dt(l)*a;return te(l*(l+1+(l-1)*i+o),-2*l*(l-1+(l+1)*i),l*(l+1+(l-1)*i-o),l+1-(l-1)*i+o,2*(l-1-(l+1)*i),l+1-(l-1)*i-o)}function ye(e,t={}){let r=t.fs||48e3;return(!t._sos||t._fs!==r)&&(t._fs=r,t._sos=ye.coefs(r)),t.state||(t.state=t._sos.map(()=>[0,0])),L(e,{coefs:t._sos,state:t.state})}ye.coefs=function(t=48e3){return t===48e3?[{b0:1.53512485958697,b1:-2.69169618940638,b2:1.19839281085285,a1:-1.69065929318241,a2:.73248077421585},{b0:1,b1:-2,b2:1,a1:-1.99004745483398,a2:.99007225036621}]:[se(1681,.7072,t,3.9997),Ee(38,.7072,t)]};var sr=.4,ur=-70,cr=-10,hr=-.691;function Qt(e,t,r,n,l=0,i){i==null&&(i=e[0].length),typeof t=="number"&&(t=Array.from({length:t},(h,d)=>d));let a=Math.ceil(sr*r/n),o=[];for(let h=l;h<i;h+=a){let d=Math.min(h+a,i),p=0,g=0;for(let w of t)for(let y=h;y<d;y++)p+=e[w][y],g++;g>0&&o.push(p/g)}let s=10**(ur/10),f=o.filter(h=>h>s);if(!f.length)return null;let u=f.reduce((h,d)=>h+d,0)/f.length,c=f.filter(h=>h>u*10**(cr/10));return c.length?hr+10*Math.log10(c.reduce((h,d)=>h+d,0)/c.length):null}function Vt(e,t){let r=new Float64Array(e.dc.length);for(let n of t){let l=e.dc[n].length;if(!l){r[n]=0;continue}let i=0;for(let a=0;a<l;a++)i+=e.dc[n][a];r[n]=i/l}return r}function ze(e,t,r){let n=0;for(let l of t){let i=r?.[l]||0;for(let a=0;a<e.min[l].length;a++)n=Math.max(n,Math.abs(e.min[l][a]-i),Math.abs(e.max[l][a]-i))}return n?20*Math.log10(n):null}function Zt(e,t,r){if(!e.rms)return null;let n=0,l=0;for(let i of t){let a=r?.[i]||0;for(let o=0;o<e.rms[i].length;o++)n+=e.rms[i][o]-a*a,l++}return l&&n>0?10*Math.log10(n/l):null}function zt(e,t,r){return Qt(e.energy,t,r,e.blockSize)??null}var pr=(e,t,r)=>{let n=r-t;if(!n)return 0;let l=0;for(let i=t;i<r;i++)l+=e[i];return l/n};m.stat("energy",{block:(e,t)=>(t.k||(t.k=e.map(()=>({fs:t.sampleRate}))),e.map((r,n)=>{let l=new Float32Array(r);ye(l,t.k[n]);let i=0;for(let a=0;a<l.length;a++)i+=l[a]*l[a];return i/l.length})),reduce:pr});m.stat("db",{query:(e,t,r,n)=>{let l=0;for(let i of t)for(let a=r;a<Math.min(n,e.min[i].length);a++)l=Math.max(l,Math.abs(e.min[i][a]),Math.abs(e.max[i][a]));return l>0?20*Math.log10(l):-1/0}});m.stat("loudness",{query:(e,t,r,n,l)=>Qt(e.energy,t,l,e.blockSize,r,n)??-1/0});var dr={streaming:-14,podcast:-16,broadcast:-23};m.op("dc",{hidden:!0,process:(e,t)=>{let r=t.args[0];typeof r=="number"&&(r=[r]);for(let n=0;n<e.length;n++){let l=r[n%r.length]||0;if(!(Math.abs(l)<1e-10))for(let i=0;i<e[n].length;i++)e[n][i]-=l}return e}});m.op("clamp",{hidden:!0,process:(e,t)=>{let r=t.args[0];for(let n=0;n<e.length;n++)for(let l=0;l<e[n].length;l++)e[n][l]=Math.max(-r,Math.min(r,e[n][l]));return e}});m.op("normalize",{process:()=>!1,resolve:(e,t)=>{let{stats:r,sampleRate:n}=t;if(!r?.min)return null;let l=e[0],i=typeof l=="string"?"lufs":t.mode||"peak",a=dr[l]??(typeof l=="number"?l:t.target??0),o=r.min.length,s=t.channel!=null?Array.isArray(t.channel)?t.channel:[t.channel]:Array.from({length:o},(d,p)=>p),f=new Float64Array(o);t.dc!==!1&&r.dc&&(f=Vt(r,s));let u=s.some(d=>Math.abs(f[d])>1e-10),c;if(i==="lufs"?c=zt(r,s,n):i==="rms"?c=Zt(r,s,f):c=ze(r,s,f),c==null)return!1;let h=[];if(u&&h.push({type:"dc",args:[s.map(d=>f[d])]}),t.ceiling!=null){let d=ze(r,s,f);if(d==null)return!1;h.push({type:"gain",args:[a-d]}),h.push({type:"clamp",args:[10**(t.ceiling/20)]})}else h.push({type:"gain",args:[a-c]});return h.length===1?h[0]:h},call(e,t){if(typeof t=="string"||typeof t=="number")return e.call(this,t);if(t!=null&&typeof t=="object"){let{target:r,mode:n,at:l,duration:i,channel:a,...o}=t;return e.call(this,r,{mode:n,at:l,duration:i,channel:a,...o})}return e.call(this)}});var Ge;function Se(e,t){let r=t.fc,n=t.fs||44100,l=t.order||2,i=t.Q==null?.707:t.Q;if(!t.coefs||t._fc!==r||t._order!==l||t._Q!==i||t._fs!==n){if(l<=2)t.coefs=[Ee(r,i,n)];else{if(!Ge)throw new Error("Import digital-filter/iir/butterworth.js for order > 2");t.coefs=Ge(l,r,n,"highpass")}t._fc=r,t._order=l,t._Q=i,t._fs=n}return L(e,t)}Se.useButterworth=e=>{Ge=e};var We;function Fe(e,t){let r=t.fc,n=t.fs||44100,l=t.order||2,i=t.Q==null?.707:t.Q;if(!t.coefs||t._fc!==r||t._order!==l||t._Q!==i||t._fs!==n){if(l<=2)t.coefs=[Ut(r,i,n)];else{if(!We)throw new Error("Import digital-filter/iir/butterworth.js for order > 2");t.coefs=We(l,r,n,"lowpass")}t._fc=r,t._order=l,t._Q=i,t._fs=n}return L(e,t)}Fe.useButterworth=e=>{We=e};function $e(e,t){let r=t.fc,n=t.Q==null?.707:t.Q,l=t.fs||44100;return(!t.coefs||t._fc!==r||t._Q!==n||t._fs!==l)&&(t.coefs=[Bt(r,n,l)],t._fc=r,t._Q=n,t._fs=l),L(e,t)}function Ke(e,t){let r=t.fc,n=t.Q==null?30:t.Q,l=t.fs||44100;return(!t.coefs||t._fc!==r||t._Q!==n||t._fs!==l)&&(t.coefs=[jt(r,n,l)],t._fc=r,t._Q=n,t._fs=l),L(e,t)}function He(e,t){let r=t.fc||200,n=t.gain||0,l=t.Q==null?.707:t.Q,i=t.fs||44100;return(!t._lo||t._fc!==r||t._gain!==n||t._Q!==l||t._fs!==i)&&(t._lo={coefs:[ve(r,l,i,n)]},t._fc=r,t._gain=n,t._Q=l,t._fs=i),L(e,t._lo)}function Ye(e,t){let r=t.fc||4e3,n=t.gain||0,l=t.Q==null?.707:t.Q,i=t.fs||44100;return(!t._hi||t._fc!==r||t._gain!==n||t._Q!==l||t._fs!==i)&&(t._hi={coefs:[se(r,l,i,n)]},t._fc=r,t._gain=n,t._Q=l,t._fs=i),L(e,t._hi)}function Je(e,t){let r=t.fs||44100,n=t.bands||[];(!t._filters||t._dirty)&&(t._filters=n.map(l=>({coefs:(l.type==="lowshelf"?ve:l.type==="highshelf"?se:qt)(l.fc,l.Q||1,r,l.gain||0)})),t._dirty=!1);for(let l of t._filters)L(e,l);return e}function J(e,t,r,n,l){t[r]||(t[r]=e.map(()=>l(t.sampleRate)));let i=t[r];for(let a=0;a<e.length;a++)n(e[a],i[a]);return e}var Xe={highpass:(e,t,r)=>J(e,t,"_hp",Se,n=>({fc:r[0],fs:n})),lowpass:(e,t,r)=>J(e,t,"_lp",Fe,n=>({fc:r[0],fs:n})),eq:(e,t,r)=>J(e,t,"_eq",Je,n=>({bands:[{fc:r[0],Q:r[2]??1,gain:r[1]??0,type:"peak"}],fs:n})),lowshelf:(e,t,r)=>J(e,t,"_ls",He,n=>({fc:r[0],gain:r[1]??0,Q:r[2]??.707,fs:n})),highshelf:(e,t,r)=>J(e,t,"_hs",Ye,n=>({fc:r[0],gain:r[1]??0,Q:r[2]??.707,fs:n})),notch:(e,t,r)=>J(e,t,"_notch",Ke,n=>({fc:r[0],Q:r[1]??30,fs:n})),bandpass:(e,t,r)=>J(e,t,"_bp",$e,n=>({fc:r[0],Q:r[1]??.707,fs:n}))},mr=(e,t)=>{let[r,...n]=t.args;if(typeof r=="function"){let i=n[0]||{};return J(e,t,"_custom",r,a=>({...i,fs:a}))}let l=Xe[r];if(!l)throw new Error(`Unknown filter type: ${r}`);return l(e,t,n)};m.op("filter",{process:mr,call(e,t,...r){if(typeof t=="function"){let n=r[0]||{},{at:l,duration:i,channel:a,offset:o,length:s,...f}=n,u={type:"filter",args:[t,f]};return l!=null&&(u.at=l),i!=null&&(u.duration=i),a!=null&&(u.channel=a),o!=null&&(u.offset=o),s!=null&&(u.length=s),this.run(u)}return e.call(this,t,...r)}});for(let e in Xe)m.op(e,{process:(t,r)=>Xe[e](t,r,r.args)});var gr=(e,t)=>{let r=t.args[0]??0;if(e.length<2)return!1;let n=typeof r=="function",[l,i]=H(t,e[0].length),a=(t.blockOffset||0)*t.sampleRate;if(!n){r=Math.max(-1,Math.min(1,r));let f=r<=0?1:1-r,u=r>=0?1:1+r,c=[f,u];for(let h=0;h<e.length;h++){let d=c[h]??1;if(d!==1)for(let p=Math.max(0,l);p<Math.min(i,e[h].length);p++)e[h][p]*=d}return e}let o=e[0],s=e[1];for(let f=Math.max(0,l);f<Math.min(i,o.length);f++){let u=Math.max(-1,Math.min(1,r((a+f)/t.sampleRate)));o[f]*=u<=0?1:1-u,s[f]*=u>=0?1:1+u}return e};m.op("pan",{process:gr});var yr=(e,t)=>{let{total:r,sampleRate:n,args:l}=t,i=l[0]??0,a=l.length>1?l[1]:i,o=Math.round(i*n),s=Math.round(a*n),f=e.map(u=>{let c=u.slice();return c[2]=u[2]+o,c});return o>0&&f.unshift(S(0,o,0,void 0,null)),s>0&&f.push(S(0,s,r+o,void 0,null)),f};m.op("pad",{plan:yr});var wr=(e,t)=>{let r=t.args[0];if(r===0)throw new RangeError("speed: rate cannot be 0");if(!r||r===1)return e;let n=Math.abs(r),l=[],i=0;for(let a of e){let o=Math.round(a[1]/n);l.push(S(a[0],o,i,a[4]===null?a[3]:(a[3]||1)*r,a[4])),i+=o}return l};m.op("speed",{plan:wr});m.op("transform",{process:(e,t)=>t.args[0](e,t),call(e,t){return this.run({type:"transform",args:[t]})}});var _r=(e,t,r)=>{let n=1/0;for(let l=t;l<r;l++)e[l]<n&&(n=e[l]);return n===1/0?0:n},Ar=(e,t,r)=>{let n=-1/0;for(let l=t;l<r;l++)e[l]>n&&(n=e[l]);return n===-1/0?0:n},br=(e,t,r)=>{let n=0;for(let l=t;l<r;l++)n+=e[l];return n},Mr=(e,t,r)=>{let n=r-t;if(!n)return 0;let l=0;for(let i=t;i<r;i++)l+=e[i];return l/n},xr=(e,t,r)=>{let n=r-t;if(!n)return 0;let l=0;for(let i=t;i<r;i++)l+=e[i];return Math.sqrt(l/n)};m.stat("min",{block:e=>e.map(t=>{let r=1/0;for(let n=0;n<t.length;n++)t[n]<r&&(r=t[n]);return r}),reduce:_r,query:(e,t,r,n)=>{let l=1/0;for(let i of t)for(let a=r;a<Math.min(n,e.min[i].length);a++)e.min[i][a]<l&&(l=e.min[i][a]);return l===1/0?0:l}});m.stat("max",{block:e=>e.map(t=>{let r=-1/0;for(let n=0;n<t.length;n++)t[n]>r&&(r=t[n]);return r}),reduce:Ar,query:(e,t,r,n)=>{let l=-1/0;for(let i of t)for(let a=r;a<Math.min(n,e.max[i].length);a++)e.max[i][a]>l&&(l=e.max[i][a]);return l===-1/0?0:l}});m.stat("dc",{block:e=>e.map(t=>{let r=0;for(let n=0;n<t.length;n++)r+=t[n];return r/t.length}),reduce:Mr});m.stat("clipping",{block:e=>e.map(t=>{let r=0;for(let n=0;n<t.length;n++)(t[n]>=1||t[n]<=-1)&&r++;return r}),reduce:br,query:(e,t,r,n,l)=>{let i=e.blockSize,a=[];for(let o=r;o<n;o++){let s=0;for(let f of t)s+=e.clipping[f][o]||0;s>0&&a.push(o*i/l)}return new Float32Array(a)}});m.stat("rms",{block:e=>e.map(t=>{let r=0;for(let n=0;n<t.length;n++)r+=t[n]*t[n];return r/t.length}),reduce:xr,query:(e,t,r,n)=>{let l=0,i=0;for(let a of t)for(let o=r;o<Math.min(n,e.rms[a].length);o++)l+=e.rms[a][o],i++;return i?Math.sqrt(l/i):0}});var{sqrt:Rr,sin:kr,cos:Er,abs:vr,SQRT1_2:Gt,SQRT2:Ri}=Math,Sr=6.283185307179586,Kt=new Map,Wt=0,$t=null;function Fr(e){let t=e>>>1,r=new Float64Array(e),n=new Float64Array(t),l=new Float64Array(t+1),a=[r.subarray(0,t+1),l],o=2/e,s=31-Math.clz32(e),f=new Uint32Array(e);for(let y=0;y<e;y++){let _=0,A=y;for(let b=0;b<s;b++)_=_<<1|A&1,A>>=1;f[y]=_}let u=0,c=2,h=t,d=[];for(;h=h>>>1;){c=c<<1;let y=c>>>3,_=y>1?y-1:0;d.push({offset:u,count:_}),u+=_}let p=new Float64Array(u<<2);c=2,h=t;let g=0;for(;h=h>>>1;){c=c<<1;let y=c>>>3,_=Sr/c,A=d[g].offset<<2;for(let b=1;b<y;b++){let x=b*_,M=kr(x),R=Er(x),k=A+(b-1<<2);p[k]=R,p[k+1]=M,p[k+2]=4*R*(R*R-.75),p[k+3]=4*M*(.75-M*M)}g++}let w={x:r,spectrum:n,complex:a,bSi:o,tw:p,stages:d,perm:f};return Kt.set(e,w),w}function Pr(e){if(e===Wt)return $t;let t=Kt.get(e)||Fr(e);return Wt=e,$t=t,t}function Cr(e){let t=e.length;if(t<2||t&t-1)throw Error("Input length must be a power of 2 (>= 2).");let r=Pr(t),{x:n,tw:l,stages:i,perm:a}=r;for(let u=0;u<t;u++)n[u]=e[a[u]];for(let u=0,c=4;u<t;c*=4){for(let h=u;h<t;h+=c){let d=n[h]-n[h+1];n[h]+=n[h+1],n[h+1]=d}u=2*(c-1)}let o=2,s=t>>>1,f=0;for(;s=s>>>1;){let u=0;o=o<<1;let c=o<<1,h=o>>>2,d=o>>>3;do{if(h!==1)for(let w=u;w<t;w+=c){let y=w,_=y+h,A=_+h,b=A+h,x=n[A]+n[b];n[b]-=n[A],n[A]=n[y]-x,n[y]+=x,y+=d,_+=d,A+=d,b+=d,x=n[A]+n[b];let M=n[A]-n[b];x=-x*Gt,M*=Gt;let R=n[_];n[b]=x+R,n[A]=x-R,n[_]=n[y]-M,n[y]+=M}else for(let w=u;w<t;w+=c){let y=w,_=y+2,A=_+1,b=n[_]+n[A];n[A]-=n[_],n[_]=n[y]-b,n[y]+=b}u=(c<<1)-o,c=c<<2}while(u<t);let{offset:p,count:g}=i[f];for(let w=0;w<g;w++){let y=p+w<<2,_=l[y],A=l[y+1],b=l[y+2],x=l[y+3];u=0,c=o<<1;do{for(let M=u;M<t;M+=c){let R=M+w+1,k=R+h,v=k+h,F=v+h,C=M+h-w-1,I=C+h,X=I+h,B=X+h,Z=n[X]*_-n[v]*A,Q=n[X]*A+n[v]*_,ue=n[B]*b-n[F]*x,ce=n[B]*x+n[F]*b,en=Z-ue;Z+=ue,ue=en,n[B]=Z+n[I],n[v]=Z-n[I];let tn=ce-Q;Q+=ce,ce=tn,n[F]=ce+n[k],n[X]=ce-n[k],n[I]=n[R]-Q,n[R]+=Q,n[k]=ue+n[C],n[C]-=ue}u=(c<<1)-o,c=c<<2}while(u<t)}f++}return r}function Ne(e,t){let r=Cr(e),n=e.length,{x:l,spectrum:i,bSi:a}=r,o=t||i,s=n>>>1;for(;--s;){let f=l[s],u=l[n-s];o[s]=a*Rr(f*f+u*u)}return o[0]=vr(a*l[0]),o}var{cos:Ht,sin:Ei,abs:vi,exp:Si,sqrt:Fi,PI:Or,cosh:Pi,acosh:Ci,acos:Oi,pow:Li,log10:Ii}=Math,Yt=2*Or;function et(e,t){return .5-.5*Ht(Yt*e/(t-1))}function Jt(e){let t=e*e;return 1.2588966*14884e4*t*t/((t+424.36)*Math.sqrt((t+11599.29)*(t+544496.41))*(t+14884e4))}var Xt=e=>2595*Math.log10(1+e/700),Nt=e=>700*(10**(e/2595)-1),tt={};function Lr(e){if(tt[e])return tt[e];let t=new Float32Array(e);for(let r=0;r<e;r++)t[r]=et(r,e);return tt[e]=t}function nt(e,t,r={}){let{bins:n=128,fMin:l=30,fMax:i=Math.min(t/2,2e4),weight:a=!0}=r,o=e.length,s=Lr(o),f=new Float32Array(o);for(let g=0;g<o;g++)f[g]=e[g]*s[g];let u=Ne(f),c=Xt(l),h=Xt(i),d=t/o,p=new Float32Array(n);for(let g=0;g<n;g++){let w=Nt(c+(h-c)*g/n),y=Nt(c+(h-c)*(g+1)/n),_=Math.max(1,Math.floor(w/d)),A=Math.min(u.length-1,Math.ceil(y/d)),b=0,x=0;for(let R=_;R<=A;R++)b+=u[R]**2,x++;let M=x>0?Math.sqrt(b/x):0;a&&(M*=Jt((w+y)/2,t)),p[g]=M}return p}async function rt(e,t,r,n,l){let i=new Float64Array(n),a=0,o=new Float32Array(0);for await(let s of e.stream({at:t?.at,duration:t?.duration})){let f=s[0];if(!f||!f.length)continue;let u=f;o.length&&(u=new Float32Array(o.length+f.length),u.set(o,0),u.set(f,o.length));let c=u.length-u.length%r;for(let h=0;h<c;h+=r)l(u.subarray(h,h+r),i),a++;o=c<u.length?u.slice(c):new Float32Array(0)}return{acc:i,cnt:a}}m.fn.spectrum=async function(e){let t=e?.bins??128,r={bins:t,fMin:e?.fMin,fMax:e?.fMax,weight:e?.weight},n=this.sampleRate,{acc:l,cnt:i}=await rt(this,e,1024,t,(o,s)=>{let f=nt(o,n,r);for(let u=0;u<t;u++)s[u]+=f[u]**2});if(i===0)return new Float32Array(t);let a=new Float32Array(t);for(let o=0;o<t;o++)a[o]=20*Math.log10(Math.sqrt(l[o]/i)+1e-10);return a};function Ir(e,t,r={}){let{bins:n=13,nMel:l=40}=r,i=nt(e,t,{bins:l,weight:!1}),a=new Float32Array(l);for(let s=0;s<l;s++)a[s]=Math.log(i[s]**2+1e-10);let o=new Float32Array(n);for(let s=0;s<n;s++){let f=0;for(let u=0;u<l;u++)f+=a[u]*Math.cos(Math.PI*s*(2*u+1)/(2*l));o[s]=f}return o}m.fn.cepstrum=async function(e){let t=e?.bins??13,r=this.sampleRate,{acc:n,cnt:l}=await rt(this,e,1024,t,(a,o)=>{let s=Ir(a,r,{bins:t});for(let f=0;f<t;f++)o[f]+=s[f]});if(l===0)return new Float32Array(t);let i=new Float32Array(t);for(let a=0;a<t;a++)i[a]=n[a]/l;return i};m.fn.silence=async function(e){let{stats:t,ch:r,sr:n,from:l,to:i}=await je(this,e),a=t.blockSize,o=e?.minDuration??.1,s=Ve(t,r,l,i,e?.threshold),f=[],u=null;for(let c=l;c<i;c++)if(!Re(t,c,r,s))u==null&&(u=c);else if(u!=null){let h=u*a/n,d=c*a/n;d-h>=o&&f.push({at:h,duration:d-h}),u=null}if(u!=null){let c=u*a/n,h=Math.min(i*a/n,this.duration);h-c>=o&&f.push({at:c,duration:h-c})}return f};export{m as default,P as parseTime,St as render};
|
package/fn/play.js
CHANGED
|
@@ -18,13 +18,21 @@ audio.fn.play = function(opts) {
|
|
|
18
18
|
let a = this, BLOCK = audio.BLOCK_SIZE
|
|
19
19
|
if (a.playing) { a.playing = false; a.paused = false; if (a._._wake) a._._wake() }
|
|
20
20
|
a.playing = false; a.paused = opts?.paused ?? false; a.currentTime = offset
|
|
21
|
-
|
|
21
|
+
if (opts?.volume != null) a.volume = opts.volume
|
|
22
|
+
a.loop = opts?.loop ?? false
|
|
22
23
|
a.block = null; a._._wake = null; a._._seekTo = null
|
|
24
|
+
a.ended = false
|
|
25
|
+
|
|
26
|
+
let startResolve, startReject
|
|
27
|
+
a.played = new Promise((r, j) => { startResolve = r; startReject = j })
|
|
28
|
+
a.played.catch(() => {})
|
|
23
29
|
|
|
24
30
|
;(async () => {
|
|
25
31
|
try {
|
|
26
32
|
let ch = a.channels, sr = a.sampleRate
|
|
27
33
|
a.playing = true
|
|
34
|
+
if (!a.paused) emit(a, 'play')
|
|
35
|
+
let resolved = false
|
|
28
36
|
let wait = async () => { while (a.paused && a.playing && a._._seekTo == null) await new Promise(r => { a._._wake = r }); a._._wake = null }
|
|
29
37
|
|
|
30
38
|
let from = offset, RAMP = 256 // ~6ms anti-click ramp
|
|
@@ -33,7 +41,7 @@ audio.fn.play = function(opts) {
|
|
|
33
41
|
if (a.paused) {
|
|
34
42
|
await wait()
|
|
35
43
|
if (!a.playing) break
|
|
36
|
-
if (a._._seekTo != null) { from = a._._seekTo; a._._seekTo = null; a.currentTime = from }
|
|
44
|
+
if (a._._seekTo != null) { from = a._._seekTo; a._._seekTo = null; a.currentTime = from; a.seeking = false }
|
|
37
45
|
}
|
|
38
46
|
let write = Speaker({ sampleRate: sr, channels: ch, bitDepth: 32 })
|
|
39
47
|
let seeked = false, played = 0, fadeIn = true
|
|
@@ -48,12 +56,12 @@ audio.fn.play = function(opts) {
|
|
|
48
56
|
for (let bOff = 0; bOff < cLen; bOff += BLOCK) {
|
|
49
57
|
if (a._._seekTo != null) {
|
|
50
58
|
from = a._._seekTo; a._._seekTo = null
|
|
51
|
-
a.currentTime = from; seeked = true; break
|
|
59
|
+
a.currentTime = from; a.seeking = false; seeked = true; break
|
|
52
60
|
}
|
|
53
61
|
let end = Math.min(bOff + BLOCK, cLen), len = end - bOff
|
|
54
62
|
a.block = chunk[0].subarray(bOff, end)
|
|
55
63
|
|
|
56
|
-
let g =
|
|
64
|
+
let g = a.muted ? 0 : a.volume
|
|
57
65
|
let buf = new Float32Array(len * ch)
|
|
58
66
|
for (let i = 0; i < len; i++) for (let c = 0; c < ch; c++)
|
|
59
67
|
buf[i * ch + c] = (chunk[c] || chunk[0])[bOff + i] * g
|
|
@@ -80,6 +88,7 @@ audio.fn.play = function(opts) {
|
|
|
80
88
|
}
|
|
81
89
|
|
|
82
90
|
await send()
|
|
91
|
+
if (!resolved) { resolved = true; startResolve() }
|
|
83
92
|
played += len
|
|
84
93
|
if (a._._seekTo == null) {
|
|
85
94
|
a.currentTime = from + played / sr
|
|
@@ -94,19 +103,21 @@ audio.fn.play = function(opts) {
|
|
|
94
103
|
if (seeked) continue
|
|
95
104
|
if (!a.playing) break
|
|
96
105
|
if (a.loop) { from = 0; a.currentTime = 0; emit(a, 'timeupdate', 0); continue }
|
|
97
|
-
a.playing = false
|
|
106
|
+
a.playing = false; a.ended = true
|
|
98
107
|
emit(a, 'timeupdate', a.currentTime)
|
|
99
108
|
break
|
|
100
109
|
}
|
|
101
110
|
a.playing = false; emit(a, 'ended')
|
|
111
|
+
if (!resolved) startResolve()
|
|
102
112
|
} catch (err) {
|
|
103
113
|
console.error('Playback error:', err)
|
|
104
114
|
a.playing = false
|
|
115
|
+
if (!resolved) startReject(err); else emit(a, 'error', err)
|
|
105
116
|
}
|
|
106
117
|
})()
|
|
107
118
|
return this
|
|
108
119
|
}
|
|
109
120
|
|
|
110
121
|
let proto = audio.fn
|
|
111
|
-
proto.pause = function() { this.paused = true }
|
|
112
|
-
proto.resume = function() { this.paused = false; if (this._._wake) this._._wake() }
|
|
122
|
+
proto.pause = function() { if (!this.paused && this.playing) { this.paused = true; emit(this, 'pause') } }
|
|
123
|
+
proto.resume = function() { if (this.paused) { this._.ctStamp = performance.now(); this.paused = false; emit(this, 'play'); if (this._._wake) this._._wake() } }
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "audio",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.1.0",
|
|
4
4
|
"description": "Audio loading, editing, and rendering for JavaScript",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "audio.js",
|
|
@@ -48,10 +48,6 @@
|
|
|
48
48
|
"demo": "vhs player.tape"
|
|
49
49
|
},
|
|
50
50
|
"dependencies": {
|
|
51
|
-
"@audio/decode-aiff": "^1.1.0",
|
|
52
|
-
"@audio/decode-caf": "^1.1.0",
|
|
53
|
-
"@audio/decode-wav": "^1.1.0",
|
|
54
|
-
"@audio/encode-mp3": "^1.0.1",
|
|
55
51
|
"a-weighting": "^2.0.1",
|
|
56
52
|
"audio-decode": "^3.8.1",
|
|
57
53
|
"audio-filter": "^2.2.2",
|