@avoid.quest/audio 0.0.0-stage → 0.1.1-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +98 -2
- package/dist/effects/index.d.ts +215 -0
- package/dist/effects/index.js +451 -0
- package/dist/effects/index.js.map +1 -0
- package/dist/errors-BT9HxDLn.js +74 -0
- package/dist/errors-BT9HxDLn.js.map +1 -0
- package/dist/errors-ChTQFwuZ.d.ts +53 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +3 -0
- package/dist/midi/index.d.ts +138 -0
- package/dist/midi/index.js +302 -0
- package/dist/midi/index.js.map +1 -0
- package/dist/native-Bern4_PB.js +172 -0
- package/dist/native-Bern4_PB.js.map +1 -0
- package/dist/pcm-buffer-DSzGHbon.js +436 -0
- package/dist/pcm-buffer-DSzGHbon.js.map +1 -0
- package/dist/playback/index.d.ts +295 -0
- package/dist/playback/index.js +1209 -0
- package/dist/playback/index.js.map +1 -0
- package/dist/queue/index.d.ts +133 -0
- package/dist/queue/index.js +563 -0
- package/dist/queue/index.js.map +1 -0
- package/dist/recognize/index.d.ts +124 -0
- package/dist/recognize/index.js +273 -0
- package/dist/recognize/index.js.map +1 -0
- package/dist/routing/index.d.ts +109 -0
- package/dist/routing/index.js +555 -0
- package/dist/routing/index.js.map +1 -0
- package/dist/shazam-gBrX1NEY.d.ts +27 -0
- package/dist/sync/index.d.ts +214 -0
- package/dist/sync/index.js +881 -0
- package/dist/sync/index.js.map +1 -0
- package/dist/worklet-loader-BabwPALw.d.ts +41 -0
- package/dist/worklet-loader-f741D1tk.js +160 -0
- package/dist/worklet-loader-f741D1tk.js.map +1 -0
- package/dist/worklets/couch-live.d.ts +1 -0
- package/dist/worklets/couch-live.js +283 -0
- package/dist/worklets/couch-live.js.map +1 -0
- package/dist/worklets/meter.d.ts +7 -0
- package/dist/worklets/meter.js +74 -0
- package/dist/worklets/meter.js.map +1 -0
- package/dist/worklets/pcm-capture.d.ts +6 -0
- package/dist/worklets/pcm-capture.js +52 -0
- package/dist/worklets/pcm-capture.js.map +1 -0
- package/package.json +114 -4
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { Effect } from "effect";
|
|
2
|
+
import { n as AudioDecodeError } from "../errors-ChTQFwuZ.js";
|
|
3
|
+
import { a as SHAZAM_MAX_PCM_BYTES, c as ShazamPeak, d as bytesToBase64, f as float32ToPcm16Le, i as SHAZAM_MAX_DURATION_SECONDS, l as ShazamSignatureResult, n as generateShazamSignature, o as SHAZAM_MAX_SAMPLES, p as resampleMonoTo16kHz, r as generateShazamSignatureSync, s as SHAZAM_SAMPLE_RATE, t as computePeakCorrection, u as base64ToBytes } from "../shazam-gBrX1NEY.js";
|
|
4
|
+
/**
|
|
5
|
+
* Pure TypeScript IEEE 802.3 CRC32 over `Uint8Array` (zero `node:zlib` imports).
|
|
6
|
+
* Matches IEEE test vector: `crc32(utf8("123456789")) === 0xcbf43926`.
|
|
7
|
+
*/
|
|
8
|
+
export declare function crc32(bytes: Uint8Array, seed?: number): number;
|
|
9
|
+
/**
|
|
10
|
+
* Convenience helper computing IEEE 802.3 CRC32 over a UTF-8 string.
|
|
11
|
+
*/
|
|
12
|
+
export declare function crc32String(input: string, seed?: number): number;
|
|
13
|
+
interface PlaylistEntry {
|
|
14
|
+
readonly url: string;
|
|
15
|
+
readonly title: string;
|
|
16
|
+
readonly durationSeconds?: number;
|
|
17
|
+
readonly attributes?: Readonly<Record<string, string>>;
|
|
18
|
+
}
|
|
19
|
+
interface M3uPlaylist {
|
|
20
|
+
readonly format: "m3u";
|
|
21
|
+
readonly isExtended: boolean;
|
|
22
|
+
readonly tvgUrl?: string;
|
|
23
|
+
readonly entries: readonly PlaylistEntry[];
|
|
24
|
+
}
|
|
25
|
+
interface PlsPlaylist {
|
|
26
|
+
readonly format: "pls";
|
|
27
|
+
readonly numberOfEntries?: number;
|
|
28
|
+
readonly version?: number;
|
|
29
|
+
readonly entries: readonly PlaylistEntry[];
|
|
30
|
+
}
|
|
31
|
+
type ParsedPlaylist = M3uPlaylist | PlsPlaylist;
|
|
32
|
+
export declare function parseM3u(content: string, baseUrl?: string): M3uPlaylist;
|
|
33
|
+
export declare function parsePls(content: string, baseUrl?: string): PlsPlaylist;
|
|
34
|
+
interface HlsVariantStream {
|
|
35
|
+
readonly url: string;
|
|
36
|
+
readonly bandwidth: number;
|
|
37
|
+
readonly averageBandwidth?: number;
|
|
38
|
+
readonly codecs?: string;
|
|
39
|
+
readonly resolution?: {
|
|
40
|
+
readonly width: number;
|
|
41
|
+
readonly height: number;
|
|
42
|
+
};
|
|
43
|
+
readonly frameRate?: number;
|
|
44
|
+
readonly audioGroup?: string;
|
|
45
|
+
readonly subtitlesGroup?: string;
|
|
46
|
+
readonly name?: string;
|
|
47
|
+
readonly attributes: Readonly<Record<string, string>>;
|
|
48
|
+
}
|
|
49
|
+
interface HlsMediaRendition {
|
|
50
|
+
readonly type: string;
|
|
51
|
+
readonly groupId: string;
|
|
52
|
+
readonly name: string;
|
|
53
|
+
readonly url?: string;
|
|
54
|
+
readonly language?: string;
|
|
55
|
+
readonly isDefault: boolean;
|
|
56
|
+
readonly autoSelect: boolean;
|
|
57
|
+
readonly attributes: Readonly<Record<string, string>>;
|
|
58
|
+
}
|
|
59
|
+
interface HlsMasterPlaylist {
|
|
60
|
+
readonly kind: "master";
|
|
61
|
+
readonly version?: number;
|
|
62
|
+
readonly independentSegments: boolean;
|
|
63
|
+
readonly variants: readonly HlsVariantStream[];
|
|
64
|
+
readonly renditions: readonly HlsMediaRendition[];
|
|
65
|
+
readonly cacheTtlMs: number;
|
|
66
|
+
}
|
|
67
|
+
interface HlsMediaSegment {
|
|
68
|
+
readonly url: string;
|
|
69
|
+
readonly durationSeconds: number;
|
|
70
|
+
readonly title?: string;
|
|
71
|
+
readonly sequence: number;
|
|
72
|
+
readonly discontinuity: boolean;
|
|
73
|
+
readonly mapUri?: string;
|
|
74
|
+
}
|
|
75
|
+
interface HlsMediaPlaylist {
|
|
76
|
+
readonly kind: "media";
|
|
77
|
+
readonly version?: number;
|
|
78
|
+
readonly targetDurationSeconds: number;
|
|
79
|
+
readonly mediaSequence: number;
|
|
80
|
+
readonly playlistType?: "VOD" | "EVENT";
|
|
81
|
+
readonly hasEndList: boolean;
|
|
82
|
+
readonly isLive: boolean;
|
|
83
|
+
readonly segments: readonly HlsMediaSegment[];
|
|
84
|
+
readonly cacheTtlMs: number;
|
|
85
|
+
}
|
|
86
|
+
type HlsManifest = HlsMasterPlaylist | HlsMediaPlaylist;
|
|
87
|
+
export declare function parseHlsManifest(content: string, baseUrl?: string): HlsManifest;
|
|
88
|
+
export declare function parsePlaylist(content: string, baseUrl?: string): ParsedPlaylist;
|
|
89
|
+
/** Upper bound for a single PCM ring buffer, in seconds. */
|
|
90
|
+
export declare const PCM_RING_MAX_SECONDS = 60;
|
|
91
|
+
interface PcmRingBufferOptions {
|
|
92
|
+
/** Sample rate of the pushed mono Float32 frames (e.g. `AudioContext.sampleRate`). */
|
|
93
|
+
readonly sampleRate: number;
|
|
94
|
+
/**
|
|
95
|
+
* Rolling window length in seconds. Defaults to
|
|
96
|
+
* `SHAZAM_MAX_DURATION_SECONDS` (12 s); clamped to `PCM_RING_MAX_SECONDS`.
|
|
97
|
+
*/
|
|
98
|
+
readonly maxSeconds?: number;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Fixed-capacity rolling window of mono Float32 PCM. `push` never allocates;
|
|
102
|
+
* only `snapshot` allocates the returned copy.
|
|
103
|
+
*/
|
|
104
|
+
interface PcmRingBuffer {
|
|
105
|
+
readonly sampleRate: number;
|
|
106
|
+
readonly capacityFrames: number;
|
|
107
|
+
/** Frames currently retained (`<= capacityFrames`). */
|
|
108
|
+
readonly bufferedFrames: () => number;
|
|
109
|
+
readonly bufferedSeconds: () => number;
|
|
110
|
+
/** Frames pushed since creation / the last `clear()`. */
|
|
111
|
+
readonly totalFrames: () => number;
|
|
112
|
+
readonly push: (chunk: Float32Array) => void;
|
|
113
|
+
/** Copies the most recent `seconds` (default: everything retained) in chronological order. */
|
|
114
|
+
readonly snapshot: (seconds?: number) => Float32Array;
|
|
115
|
+
readonly clear: () => void;
|
|
116
|
+
}
|
|
117
|
+
/** Creates a DOM-free rolling PCM window for live audio awaiting fingerprinting. */
|
|
118
|
+
export declare function createPcmRingBuffer(options: PcmRingBufferOptions): PcmRingBuffer;
|
|
119
|
+
/** Converts mono Float32 PCM at any rate into the newest 12 s of 16 kHz PCM16LE. */
|
|
120
|
+
export declare function prepareShazamPcm(samples: Float32Array, sampleRate: number): Uint8Array;
|
|
121
|
+
/** Fingerprints mono Float32 PCM; fails with `AudioDecodeError` on empty input. */
|
|
122
|
+
export declare function generateShazamSignatureFromFloat32(samples: Float32Array, sampleRate: number): Effect.Effect<ShazamSignatureResult, AudioDecodeError>;
|
|
123
|
+
export declare const SHAZAM_HANNING_WINDOW: Float32Array;
|
|
124
|
+
export { type HlsManifest, type HlsMasterPlaylist, type HlsMediaPlaylist, type HlsMediaRendition, type HlsMediaSegment, type HlsVariantStream, type M3uPlaylist, type ParsedPlaylist, type PcmRingBuffer, type PcmRingBufferOptions, type PlaylistEntry, type PlsPlaylist, SHAZAM_MAX_DURATION_SECONDS, SHAZAM_MAX_PCM_BYTES, SHAZAM_MAX_SAMPLES, SHAZAM_SAMPLE_RATE, type ShazamPeak, type ShazamSignatureResult, base64ToBytes, bytesToBase64, computePeakCorrection, float32ToPcm16Le, generateShazamSignature, generateShazamSignatureSync, resampleMonoTo16kHz };
|
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
import { _ as crc32, a as computePeakCorrection, c as SHAZAM_HANNING_WINDOW, d as SHAZAM_MAX_SAMPLES, f as SHAZAM_SAMPLE_RATE, g as resampleMonoTo16kHz, h as float32ToPcm16Le, i as prepareShazamPcm, l as SHAZAM_MAX_DURATION_SECONDS, m as bytesToBase64, n as createPcmRingBuffer, o as generateShazamSignature, p as base64ToBytes, r as generateShazamSignatureFromFloat32, s as generateShazamSignatureSync, t as PCM_RING_MAX_SECONDS, u as SHAZAM_MAX_PCM_BYTES, v as crc32String } from "../pcm-buffer-DSzGHbon.js";
|
|
2
|
+
// src/recognize/playlist-m3u.ts
|
|
3
|
+
const BOM_RE = /^\uFEFF/u;
|
|
4
|
+
const NEWLINE_RE = /\r?\n/u;
|
|
5
|
+
const SPACE_RE = /\s/u;
|
|
6
|
+
const FILE_EXT_RE = /\.[^.]+$/u;
|
|
7
|
+
const SEP_RE = /[_-]+/gu;
|
|
8
|
+
const ATTR_RE = /(?<key>[A-Za-z0-9_-]+)=(?:"(?<quoted>[^"]*)"|(?<bare>[^,\s]*))/gu;
|
|
9
|
+
const PLS_LINE_RE = /^(?<field>file|title|length)(?<index>\d+)\s*=\s*(?<value>.*)$/iu;
|
|
10
|
+
const PLS_COUNT_RE = /^numberofentries\s*=\s*(?<count>\d+)$/iu;
|
|
11
|
+
const PLS_VER_RE = /^version\s*=\s*(?<ver>\d+)$/iu;
|
|
12
|
+
const splitLines = (content) => content.replace(BOM_RE, "").split(NEWLINE_RE).map((l) => l.trim()).filter(Boolean);
|
|
13
|
+
const splitTag = (line) => {
|
|
14
|
+
const i = line.indexOf(":");
|
|
15
|
+
return i === -1 ? [line, ""] : [line.slice(0, i), line.slice(i + 1)];
|
|
16
|
+
};
|
|
17
|
+
function resolveUri(uri, baseUrl) {
|
|
18
|
+
const trimmed = uri.trim();
|
|
19
|
+
if (!baseUrl) return trimmed;
|
|
20
|
+
try {
|
|
21
|
+
return new URL(trimmed, baseUrl).href;
|
|
22
|
+
} catch {
|
|
23
|
+
return trimmed;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
const parseNum = (raw) => {
|
|
27
|
+
const n = raw === void 0 ? NaN : Number(raw.trim());
|
|
28
|
+
return Number.isFinite(n) ? n : void 0;
|
|
29
|
+
};
|
|
30
|
+
const parseNonNeg = (raw) => {
|
|
31
|
+
const n = parseNum(raw);
|
|
32
|
+
return n !== void 0 && n >= 0 ? n : void 0;
|
|
33
|
+
};
|
|
34
|
+
function parseAttributes(input) {
|
|
35
|
+
const attrs = {};
|
|
36
|
+
for (const m of input.matchAll(ATTR_RE)) {
|
|
37
|
+
const key = m.groups?.key;
|
|
38
|
+
if (key !== void 0) attrs[key] = m.groups?.quoted ?? m.groups?.bare ?? "";
|
|
39
|
+
}
|
|
40
|
+
return attrs;
|
|
41
|
+
}
|
|
42
|
+
function fallbackTitle(url) {
|
|
43
|
+
try {
|
|
44
|
+
const seg = new URL(url, "https://placeholder.invalid").pathname.split("/").findLast(Boolean);
|
|
45
|
+
const cleaned = seg ? decodeURIComponent(seg).replace(FILE_EXT_RE, "").replaceAll(SEP_RE, " ").trim() : "";
|
|
46
|
+
if (cleaned) return cleaned;
|
|
47
|
+
} catch {}
|
|
48
|
+
return "Unknown Track";
|
|
49
|
+
}
|
|
50
|
+
function findUnquotedComma(body) {
|
|
51
|
+
let quoted = false;
|
|
52
|
+
for (let i = 0; i < body.length; i += 1) {
|
|
53
|
+
const ch = body[i];
|
|
54
|
+
if (ch === "\"") quoted = !quoted;
|
|
55
|
+
else if (ch === "," && !quoted) return i;
|
|
56
|
+
}
|
|
57
|
+
return -1;
|
|
58
|
+
}
|
|
59
|
+
function parseExtinf(body) {
|
|
60
|
+
const comma = findUnquotedComma(body);
|
|
61
|
+
const meta = comma >= 0 ? body.slice(0, comma) : body;
|
|
62
|
+
const space = meta.search(SPACE_RE);
|
|
63
|
+
const attrStr = space >= 0 ? meta.slice(space + 1).trim() : "";
|
|
64
|
+
const attrs = attrStr ? parseAttributes(attrStr) : void 0;
|
|
65
|
+
return {
|
|
66
|
+
attributes: attrs && Object.keys(attrs).length > 0 ? attrs : void 0,
|
|
67
|
+
duration: parseNonNeg(space >= 0 ? meta.slice(0, space) : meta),
|
|
68
|
+
title: (comma >= 0 ? body.slice(comma + 1).trim() : "") || void 0
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
function parseM3u(content, baseUrl) {
|
|
72
|
+
let isExtended = false;
|
|
73
|
+
let tvgUrl;
|
|
74
|
+
const entries = [];
|
|
75
|
+
let pending;
|
|
76
|
+
for (const line of splitLines(content)) if (line.startsWith("#EXTM3U")) {
|
|
77
|
+
isExtended = true;
|
|
78
|
+
const attrs = parseAttributes(line.slice(7));
|
|
79
|
+
tvgUrl = attrs["x-tvg-url"] ?? attrs["url-tvg"] ?? tvgUrl;
|
|
80
|
+
} else if (line.startsWith("#EXTINF:")) pending = parseExtinf(line.slice(8));
|
|
81
|
+
else if (!line.startsWith("#")) {
|
|
82
|
+
const url = resolveUri(line, baseUrl);
|
|
83
|
+
entries.push({
|
|
84
|
+
attributes: pending?.attributes,
|
|
85
|
+
durationSeconds: pending?.duration,
|
|
86
|
+
title: pending?.title ?? fallbackTitle(url),
|
|
87
|
+
url
|
|
88
|
+
});
|
|
89
|
+
pending = void 0;
|
|
90
|
+
}
|
|
91
|
+
return {
|
|
92
|
+
entries,
|
|
93
|
+
format: "m3u",
|
|
94
|
+
isExtended,
|
|
95
|
+
tvgUrl
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
function applyPlsLine(line, byIndex) {
|
|
99
|
+
const m = PLS_LINE_RE.exec(line)?.groups;
|
|
100
|
+
const index = Number(m?.index);
|
|
101
|
+
if (!m || !Number.isFinite(index)) return;
|
|
102
|
+
const bucket = byIndex.get(index) ?? {};
|
|
103
|
+
const field = m.field?.toLowerCase();
|
|
104
|
+
const val = (m.value ?? "").trim();
|
|
105
|
+
if (field === "file") bucket.file = val;
|
|
106
|
+
else if (field === "title") bucket.title = val;
|
|
107
|
+
else if (field === "length") bucket.length = parseNonNeg(val);
|
|
108
|
+
byIndex.set(index, bucket);
|
|
109
|
+
}
|
|
110
|
+
function parsePls(content, baseUrl) {
|
|
111
|
+
const byIndex = /* @__PURE__ */ new Map();
|
|
112
|
+
let numberOfEntries;
|
|
113
|
+
let version;
|
|
114
|
+
for (const line of splitLines(content)) {
|
|
115
|
+
if (line.startsWith("[") || line.startsWith(";") || line.startsWith("#")) continue;
|
|
116
|
+
const count = PLS_COUNT_RE.exec(line)?.groups?.count;
|
|
117
|
+
const ver = PLS_VER_RE.exec(line)?.groups?.ver;
|
|
118
|
+
if (count !== void 0) numberOfEntries = Number(count);
|
|
119
|
+
else if (ver === void 0) applyPlsLine(line, byIndex);
|
|
120
|
+
else version = Number(ver);
|
|
121
|
+
}
|
|
122
|
+
const entries = [];
|
|
123
|
+
for (const idx of [...byIndex.keys()].toSorted((a, b) => a - b)) {
|
|
124
|
+
const item = byIndex.get(idx);
|
|
125
|
+
if (!item?.file) continue;
|
|
126
|
+
const url = resolveUri(item.file, baseUrl);
|
|
127
|
+
entries.push({
|
|
128
|
+
durationSeconds: item.length,
|
|
129
|
+
title: item.title || fallbackTitle(url),
|
|
130
|
+
url
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
return {
|
|
134
|
+
entries,
|
|
135
|
+
format: "pls",
|
|
136
|
+
numberOfEntries,
|
|
137
|
+
version
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
// src/recognize/playlist-hls.ts
|
|
141
|
+
const RES_RE = /^(?<width>\d+)x(?<height>\d+)$/iu;
|
|
142
|
+
const parseRes = (raw) => {
|
|
143
|
+
const g = raw ? RES_RE.exec(raw)?.groups : void 0;
|
|
144
|
+
return g?.width && g.height ? {
|
|
145
|
+
height: Number(g.height),
|
|
146
|
+
width: Number(g.width)
|
|
147
|
+
} : void 0;
|
|
148
|
+
};
|
|
149
|
+
function parseHlsMaster(lines, baseUrl) {
|
|
150
|
+
let version;
|
|
151
|
+
let independentSegments = false;
|
|
152
|
+
const variants = [];
|
|
153
|
+
const renditions = [];
|
|
154
|
+
let pendingAttrs;
|
|
155
|
+
for (const line of lines) if (line.startsWith("#")) {
|
|
156
|
+
const [tag, val] = splitTag(line);
|
|
157
|
+
if (tag === "#EXT-X-VERSION") version = parseNum(val);
|
|
158
|
+
else if (tag === "#EXT-X-INDEPENDENT-SEGMENTS") independentSegments = true;
|
|
159
|
+
else if (tag === "#EXT-X-MEDIA") {
|
|
160
|
+
const a = parseAttributes(val);
|
|
161
|
+
renditions.push({
|
|
162
|
+
attributes: a,
|
|
163
|
+
autoSelect: a.AUTOSELECT === "YES",
|
|
164
|
+
groupId: a["GROUP-ID"] ?? "",
|
|
165
|
+
isDefault: a.DEFAULT === "YES",
|
|
166
|
+
language: a.LANGUAGE,
|
|
167
|
+
name: a.NAME ?? "",
|
|
168
|
+
type: a.TYPE ?? "",
|
|
169
|
+
url: a.URI ? resolveUri(a.URI, baseUrl) : void 0
|
|
170
|
+
});
|
|
171
|
+
} else if (tag === "#EXT-X-STREAM-INF") pendingAttrs = parseAttributes(val);
|
|
172
|
+
} else if (pendingAttrs) {
|
|
173
|
+
variants.push({
|
|
174
|
+
attributes: pendingAttrs,
|
|
175
|
+
audioGroup: pendingAttrs.AUDIO,
|
|
176
|
+
averageBandwidth: parseNum(pendingAttrs["AVERAGE-BANDWIDTH"]),
|
|
177
|
+
bandwidth: parseNum(pendingAttrs.BANDWIDTH) ?? 0,
|
|
178
|
+
codecs: pendingAttrs.CODECS,
|
|
179
|
+
frameRate: parseNum(pendingAttrs["FRAME-RATE"]),
|
|
180
|
+
name: pendingAttrs.NAME,
|
|
181
|
+
resolution: parseRes(pendingAttrs.RESOLUTION),
|
|
182
|
+
subtitlesGroup: pendingAttrs.SUBTITLES,
|
|
183
|
+
url: resolveUri(line, baseUrl)
|
|
184
|
+
});
|
|
185
|
+
pendingAttrs = void 0;
|
|
186
|
+
}
|
|
187
|
+
return {
|
|
188
|
+
cacheTtlMs: Number.POSITIVE_INFINITY,
|
|
189
|
+
independentSegments,
|
|
190
|
+
kind: "master",
|
|
191
|
+
renditions,
|
|
192
|
+
variants,
|
|
193
|
+
version
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
const HLS_MEDIA_TAGS = {
|
|
197
|
+
"#EXT-X-DISCONTINUITY": (_v, s) => {
|
|
198
|
+
s.nextDiscontinuity = true;
|
|
199
|
+
},
|
|
200
|
+
"#EXT-X-ENDLIST": (_v, s) => {
|
|
201
|
+
s.hasEndList = true;
|
|
202
|
+
},
|
|
203
|
+
"#EXT-X-MAP": (v, s, baseUrl) => {
|
|
204
|
+
const uri = parseAttributes(v).URI;
|
|
205
|
+
if (uri) s.currentMapUri = resolveUri(uri, baseUrl);
|
|
206
|
+
},
|
|
207
|
+
"#EXT-X-MEDIA-SEQUENCE": (v, s) => {
|
|
208
|
+
s.mediaSequence = parseNonNeg(v) ?? s.mediaSequence;
|
|
209
|
+
},
|
|
210
|
+
"#EXT-X-PLAYLIST-TYPE": (v, s) => {
|
|
211
|
+
const t = v.trim().toUpperCase();
|
|
212
|
+
if (t === "VOD" || t === "EVENT") s.playlistType = t;
|
|
213
|
+
},
|
|
214
|
+
"#EXT-X-TARGETDURATION": (v, s) => {
|
|
215
|
+
s.targetDurationSeconds = parseNonNeg(v) ?? s.targetDurationSeconds;
|
|
216
|
+
},
|
|
217
|
+
"#EXT-X-VERSION": (v, s) => {
|
|
218
|
+
s.version = parseNum(v);
|
|
219
|
+
},
|
|
220
|
+
"#EXTINF": (v, s) => {
|
|
221
|
+
const comma = v.indexOf(",");
|
|
222
|
+
s.pendingDuration = parseNonNeg(comma === -1 ? v : v.slice(0, comma)) ?? 0;
|
|
223
|
+
s.pendingTitle = (comma === -1 ? "" : v.slice(comma + 1).trim()) || void 0;
|
|
224
|
+
}
|
|
225
|
+
};
|
|
226
|
+
function parseHlsMedia(lines, baseUrl) {
|
|
227
|
+
const s = {
|
|
228
|
+
hasEndList: false,
|
|
229
|
+
mediaSequence: 0,
|
|
230
|
+
nextDiscontinuity: false,
|
|
231
|
+
targetDurationSeconds: 0
|
|
232
|
+
};
|
|
233
|
+
const segments = [];
|
|
234
|
+
for (const line of lines) if (line.startsWith("#")) {
|
|
235
|
+
const [tag, val] = splitTag(line);
|
|
236
|
+
HLS_MEDIA_TAGS[tag]?.(val, s, baseUrl);
|
|
237
|
+
} else if (s.pendingDuration !== void 0) {
|
|
238
|
+
segments.push({
|
|
239
|
+
discontinuity: s.nextDiscontinuity,
|
|
240
|
+
durationSeconds: s.pendingDuration,
|
|
241
|
+
mapUri: s.currentMapUri,
|
|
242
|
+
sequence: s.mediaSequence + segments.length,
|
|
243
|
+
title: s.pendingTitle,
|
|
244
|
+
url: resolveUri(line, baseUrl)
|
|
245
|
+
});
|
|
246
|
+
s.pendingDuration = void 0;
|
|
247
|
+
s.pendingTitle = void 0;
|
|
248
|
+
s.nextDiscontinuity = false;
|
|
249
|
+
}
|
|
250
|
+
const isLive = !s.hasEndList && s.playlistType !== "VOD";
|
|
251
|
+
return {
|
|
252
|
+
cacheTtlMs: isLive ? s.targetDurationSeconds * 500 : Number.POSITIVE_INFINITY,
|
|
253
|
+
hasEndList: s.hasEndList,
|
|
254
|
+
isLive,
|
|
255
|
+
kind: "media",
|
|
256
|
+
mediaSequence: s.mediaSequence,
|
|
257
|
+
playlistType: s.playlistType,
|
|
258
|
+
segments,
|
|
259
|
+
targetDurationSeconds: s.targetDurationSeconds,
|
|
260
|
+
version: s.version
|
|
261
|
+
};
|
|
262
|
+
}
|
|
263
|
+
function parseHlsManifest(content, baseUrl) {
|
|
264
|
+
const lines = splitLines(content);
|
|
265
|
+
return lines.some((l) => l.startsWith("#EXT-X-STREAM-INF:") || l.startsWith("#EXT-X-MEDIA:")) ? parseHlsMaster(lines, baseUrl) : parseHlsMedia(lines, baseUrl);
|
|
266
|
+
}
|
|
267
|
+
// src/recognize/playlist.ts
|
|
268
|
+
function parsePlaylist(content, baseUrl) {
|
|
269
|
+
return content.replace(BOM_RE, "").trimStart().toLowerCase().startsWith("[playlist]") ? parsePls(content, baseUrl) : parseM3u(content, baseUrl);
|
|
270
|
+
}
|
|
271
|
+
export { PCM_RING_MAX_SECONDS, SHAZAM_HANNING_WINDOW, SHAZAM_MAX_DURATION_SECONDS, SHAZAM_MAX_PCM_BYTES, SHAZAM_MAX_SAMPLES, SHAZAM_SAMPLE_RATE, base64ToBytes, bytesToBase64, computePeakCorrection, crc32, crc32String, createPcmRingBuffer, float32ToPcm16Le, generateShazamSignature, generateShazamSignatureFromFloat32, generateShazamSignatureSync, parseHlsManifest, parseM3u, parsePlaylist, parsePls, prepareShazamPcm, resampleMonoTo16kHz };
|
|
272
|
+
|
|
273
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../src/recognize/playlist-m3u.ts","../../src/recognize/playlist-hls.ts","../../src/recognize/playlist.ts"],"sourcesContent":["export interface PlaylistEntry {\n readonly url: string;\n readonly title: string;\n readonly durationSeconds?: number;\n readonly attributes?: Readonly<Record<string, string>>;\n}\n\nexport interface M3uPlaylist {\n readonly format: \"m3u\";\n readonly isExtended: boolean;\n readonly tvgUrl?: string;\n readonly entries: readonly PlaylistEntry[];\n}\n\nexport interface PlsPlaylist {\n readonly format: \"pls\";\n readonly numberOfEntries?: number;\n readonly version?: number;\n readonly entries: readonly PlaylistEntry[];\n}\n\nexport type ParsedPlaylist = M3uPlaylist | PlsPlaylist;\n\nexport const BOM_RE = /^\\uFEFF/u;\nconst NEWLINE_RE = /\\r?\\n/u;\nconst SPACE_RE = /\\s/u;\nconst FILE_EXT_RE = /\\.[^.]+$/u;\nconst SEP_RE = /[_-]+/gu;\nconst ATTR_RE =\n /(?<key>[A-Za-z0-9_-]+)=(?:\"(?<quoted>[^\"]*)\"|(?<bare>[^,\\s]*))/gu;\nconst PLS_LINE_RE =\n /^(?<field>file|title|length)(?<index>\\d+)\\s*=\\s*(?<value>.*)$/iu;\nconst PLS_COUNT_RE = /^numberofentries\\s*=\\s*(?<count>\\d+)$/iu;\nconst PLS_VER_RE = /^version\\s*=\\s*(?<ver>\\d+)$/iu;\n\nexport const splitLines = (content: string): string[] =>\n content\n .replace(BOM_RE, \"\")\n .split(NEWLINE_RE)\n .map((l) => l.trim())\n .filter(Boolean);\n\nexport const splitTag = (line: string): readonly [string, string] => {\n const i = line.indexOf(\":\");\n return i === -1 ? [line, \"\"] : [line.slice(0, i), line.slice(i + 1)];\n};\n\nexport function resolveUri(uri: string, baseUrl?: string): string {\n const trimmed = uri.trim();\n if (!baseUrl) {\n return trimmed;\n }\n try {\n return new URL(trimmed, baseUrl).href;\n } catch {\n return trimmed;\n }\n}\n\nexport const parseNum = (raw: string | undefined): number | undefined => {\n const n = raw === undefined ? Number.NaN : Number(raw.trim());\n return Number.isFinite(n) ? n : undefined;\n};\n\nexport const parseNonNeg = (raw: string | undefined): number | undefined => {\n const n = parseNum(raw);\n return n !== undefined && n >= 0 ? n : undefined;\n};\n\nexport function parseAttributes(input: string): Record<string, string> {\n const attrs: Record<string, string> = {};\n for (const m of input.matchAll(ATTR_RE)) {\n const key = m.groups?.key;\n if (key !== undefined) {\n attrs[key] = m.groups?.quoted ?? m.groups?.bare ?? \"\";\n }\n }\n return attrs;\n}\n\nfunction fallbackTitle(url: string): string {\n try {\n const seg = new URL(url, \"https://placeholder.invalid\").pathname\n .split(\"/\")\n .findLast(Boolean);\n const cleaned = seg\n ? decodeURIComponent(seg)\n .replace(FILE_EXT_RE, \"\")\n .replaceAll(SEP_RE, \" \")\n .trim()\n : \"\";\n if (cleaned) {\n return cleaned;\n }\n } catch {\n // Fall through\n }\n return \"Unknown Track\";\n}\n\nfunction findUnquotedComma(body: string): number {\n let quoted = false;\n for (let i = 0; i < body.length; i += 1) {\n const ch = body[i];\n if (ch === '\"') {\n quoted = !quoted;\n } else if (ch === \",\" && !quoted) {\n return i;\n }\n }\n return -1;\n}\n\nfunction parseExtinf(body: string): {\n readonly duration?: number;\n readonly title?: string;\n readonly attributes?: Record<string, string>;\n} {\n const comma = findUnquotedComma(body);\n const meta = comma >= 0 ? body.slice(0, comma) : body;\n const space = meta.search(SPACE_RE);\n const attrStr = space >= 0 ? meta.slice(space + 1).trim() : \"\";\n const attrs = attrStr ? parseAttributes(attrStr) : undefined;\n return {\n attributes: attrs && Object.keys(attrs).length > 0 ? attrs : undefined,\n duration: parseNonNeg(space >= 0 ? meta.slice(0, space) : meta),\n title: (comma >= 0 ? body.slice(comma + 1).trim() : \"\") || undefined,\n };\n}\n\nexport function parseM3u(content: string, baseUrl?: string): M3uPlaylist {\n let isExtended = false;\n let tvgUrl: string | undefined;\n const entries: PlaylistEntry[] = [];\n let pending: ReturnType<typeof parseExtinf> | undefined;\n\n for (const line of splitLines(content)) {\n if (line.startsWith(\"#EXTM3U\")) {\n isExtended = true;\n const attrs = parseAttributes(line.slice(7));\n tvgUrl = attrs[\"x-tvg-url\"] ?? attrs[\"url-tvg\"] ?? tvgUrl;\n } else if (line.startsWith(\"#EXTINF:\")) {\n pending = parseExtinf(line.slice(8));\n } else if (!line.startsWith(\"#\")) {\n const url = resolveUri(line, baseUrl);\n entries.push({\n attributes: pending?.attributes,\n durationSeconds: pending?.duration,\n title: pending?.title ?? fallbackTitle(url),\n url,\n });\n pending = undefined;\n }\n }\n return { entries, format: \"m3u\", isExtended, tvgUrl };\n}\n\ninterface PlsBucket {\n file?: string;\n title?: string;\n length?: number;\n}\n\nfunction applyPlsLine(line: string, byIndex: Map<number, PlsBucket>): void {\n const m = PLS_LINE_RE.exec(line)?.groups;\n const index = Number(m?.index);\n if (!m || !Number.isFinite(index)) {\n return;\n }\n const bucket = byIndex.get(index) ?? {};\n const field = m.field?.toLowerCase();\n const val = (m.value ?? \"\").trim();\n if (field === \"file\") {\n bucket.file = val;\n } else if (field === \"title\") {\n bucket.title = val;\n } else if (field === \"length\") {\n bucket.length = parseNonNeg(val);\n }\n byIndex.set(index, bucket);\n}\n\nexport function parsePls(content: string, baseUrl?: string): PlsPlaylist {\n const byIndex = new Map<number, PlsBucket>();\n let numberOfEntries: number | undefined;\n let version: number | undefined;\n\n for (const line of splitLines(content)) {\n if (line.startsWith(\"[\") || line.startsWith(\";\") || line.startsWith(\"#\")) {\n continue;\n }\n const count = PLS_COUNT_RE.exec(line)?.groups?.count;\n const ver = PLS_VER_RE.exec(line)?.groups?.ver;\n if (count !== undefined) {\n numberOfEntries = Number(count);\n } else if (ver === undefined) {\n applyPlsLine(line, byIndex);\n } else {\n version = Number(ver);\n }\n }\n\n const entries: PlaylistEntry[] = [];\n for (const idx of [...byIndex.keys()].toSorted((a, b) => a - b)) {\n const item = byIndex.get(idx);\n if (!item?.file) {\n continue;\n }\n const url = resolveUri(item.file, baseUrl);\n entries.push({\n durationSeconds: item.length,\n title: item.title || fallbackTitle(url),\n url,\n });\n }\n return { entries, format: \"pls\", numberOfEntries, version };\n}\n","import {\n parseAttributes,\n parseNonNeg,\n parseNum,\n resolveUri,\n splitLines,\n splitTag,\n} from \"./playlist-m3u.ts\";\n\nexport interface HlsVariantStream {\n readonly url: string;\n readonly bandwidth: number;\n readonly averageBandwidth?: number;\n readonly codecs?: string;\n readonly resolution?: { readonly width: number; readonly height: number };\n readonly frameRate?: number;\n readonly audioGroup?: string;\n readonly subtitlesGroup?: string;\n readonly name?: string;\n readonly attributes: Readonly<Record<string, string>>;\n}\n\nexport interface HlsMediaRendition {\n readonly type: string;\n readonly groupId: string;\n readonly name: string;\n readonly url?: string;\n readonly language?: string;\n readonly isDefault: boolean;\n readonly autoSelect: boolean;\n readonly attributes: Readonly<Record<string, string>>;\n}\n\nexport interface HlsMasterPlaylist {\n readonly kind: \"master\";\n readonly version?: number;\n readonly independentSegments: boolean;\n readonly variants: readonly HlsVariantStream[];\n readonly renditions: readonly HlsMediaRendition[];\n readonly cacheTtlMs: number;\n}\n\nexport interface HlsMediaSegment {\n readonly url: string;\n readonly durationSeconds: number;\n readonly title?: string;\n readonly sequence: number;\n readonly discontinuity: boolean;\n readonly mapUri?: string;\n}\n\nexport interface HlsMediaPlaylist {\n readonly kind: \"media\";\n readonly version?: number;\n readonly targetDurationSeconds: number;\n readonly mediaSequence: number;\n readonly playlistType?: \"VOD\" | \"EVENT\";\n readonly hasEndList: boolean;\n readonly isLive: boolean;\n readonly segments: readonly HlsMediaSegment[];\n readonly cacheTtlMs: number;\n}\n\nexport type HlsManifest = HlsMasterPlaylist | HlsMediaPlaylist;\n\nconst RES_RE = /^(?<width>\\d+)x(?<height>\\d+)$/iu;\n\nconst parseRes = (\n raw: string | undefined\n): { readonly width: number; readonly height: number } | undefined => {\n const g = raw ? RES_RE.exec(raw)?.groups : undefined;\n return g?.width && g.height\n ? { height: Number(g.height), width: Number(g.width) }\n : undefined;\n};\n\nfunction parseHlsMaster(\n lines: readonly string[],\n baseUrl?: string\n): HlsMasterPlaylist {\n let version: number | undefined;\n let independentSegments = false;\n const variants: HlsVariantStream[] = [];\n const renditions: HlsMediaRendition[] = [];\n let pendingAttrs: Record<string, string> | undefined;\n\n for (const line of lines) {\n if (line.startsWith(\"#\")) {\n const [tag, val] = splitTag(line);\n if (tag === \"#EXT-X-VERSION\") {\n version = parseNum(val);\n } else if (tag === \"#EXT-X-INDEPENDENT-SEGMENTS\") {\n independentSegments = true;\n } else if (tag === \"#EXT-X-MEDIA\") {\n const a = parseAttributes(val);\n renditions.push({\n attributes: a,\n autoSelect: a.AUTOSELECT === \"YES\",\n groupId: a[\"GROUP-ID\"] ?? \"\",\n isDefault: a.DEFAULT === \"YES\",\n language: a.LANGUAGE,\n name: a.NAME ?? \"\",\n type: a.TYPE ?? \"\",\n url: a.URI ? resolveUri(a.URI, baseUrl) : undefined,\n });\n } else if (tag === \"#EXT-X-STREAM-INF\") {\n pendingAttrs = parseAttributes(val);\n }\n } else if (pendingAttrs) {\n variants.push({\n attributes: pendingAttrs,\n audioGroup: pendingAttrs.AUDIO,\n averageBandwidth: parseNum(pendingAttrs[\"AVERAGE-BANDWIDTH\"]),\n bandwidth: parseNum(pendingAttrs.BANDWIDTH) ?? 0,\n codecs: pendingAttrs.CODECS,\n frameRate: parseNum(pendingAttrs[\"FRAME-RATE\"]),\n name: pendingAttrs.NAME,\n resolution: parseRes(pendingAttrs.RESOLUTION),\n subtitlesGroup: pendingAttrs.SUBTITLES,\n url: resolveUri(line, baseUrl),\n });\n pendingAttrs = undefined;\n }\n }\n return {\n cacheTtlMs: Number.POSITIVE_INFINITY,\n independentSegments,\n kind: \"master\",\n renditions,\n variants,\n version,\n };\n}\n\ninterface HlsMediaState {\n version?: number;\n targetDurationSeconds: number;\n mediaSequence: number;\n playlistType?: \"VOD\" | \"EVENT\";\n hasEndList: boolean;\n currentMapUri?: string;\n nextDiscontinuity: boolean;\n pendingDuration?: number;\n pendingTitle?: string;\n}\n\nconst HLS_MEDIA_TAGS: Readonly<\n Record<string, (val: string, s: HlsMediaState, baseUrl?: string) => void>\n> = {\n \"#EXT-X-DISCONTINUITY\": (_v, s) => {\n s.nextDiscontinuity = true;\n },\n \"#EXT-X-ENDLIST\": (_v, s) => {\n s.hasEndList = true;\n },\n \"#EXT-X-MAP\": (v, s, baseUrl) => {\n const uri = parseAttributes(v).URI;\n if (uri) {\n s.currentMapUri = resolveUri(uri, baseUrl);\n }\n },\n \"#EXT-X-MEDIA-SEQUENCE\": (v, s) => {\n s.mediaSequence = parseNonNeg(v) ?? s.mediaSequence;\n },\n \"#EXT-X-PLAYLIST-TYPE\": (v, s) => {\n const t = v.trim().toUpperCase();\n if (t === \"VOD\" || t === \"EVENT\") {\n s.playlistType = t;\n }\n },\n \"#EXT-X-TARGETDURATION\": (v, s) => {\n s.targetDurationSeconds = parseNonNeg(v) ?? s.targetDurationSeconds;\n },\n \"#EXT-X-VERSION\": (v, s) => {\n s.version = parseNum(v);\n },\n \"#EXTINF\": (v, s) => {\n const comma = v.indexOf(\",\");\n s.pendingDuration = parseNonNeg(comma === -1 ? v : v.slice(0, comma)) ?? 0;\n s.pendingTitle =\n (comma === -1 ? \"\" : v.slice(comma + 1).trim()) || undefined;\n },\n};\n\nfunction parseHlsMedia(\n lines: readonly string[],\n baseUrl?: string\n): HlsMediaPlaylist {\n const s: HlsMediaState = {\n hasEndList: false,\n mediaSequence: 0,\n nextDiscontinuity: false,\n targetDurationSeconds: 0,\n };\n const segments: HlsMediaSegment[] = [];\n\n for (const line of lines) {\n if (line.startsWith(\"#\")) {\n const [tag, val] = splitTag(line);\n HLS_MEDIA_TAGS[tag]?.(val, s, baseUrl);\n } else if (s.pendingDuration !== undefined) {\n segments.push({\n discontinuity: s.nextDiscontinuity,\n durationSeconds: s.pendingDuration,\n mapUri: s.currentMapUri,\n sequence: s.mediaSequence + segments.length,\n title: s.pendingTitle,\n url: resolveUri(line, baseUrl),\n });\n s.pendingDuration = undefined;\n s.pendingTitle = undefined;\n s.nextDiscontinuity = false;\n }\n }\n\n const isLive = !s.hasEndList && s.playlistType !== \"VOD\";\n return {\n cacheTtlMs: isLive\n ? s.targetDurationSeconds * 500\n : Number.POSITIVE_INFINITY,\n hasEndList: s.hasEndList,\n isLive,\n kind: \"media\",\n mediaSequence: s.mediaSequence,\n playlistType: s.playlistType,\n segments,\n targetDurationSeconds: s.targetDurationSeconds,\n version: s.version,\n };\n}\n\nexport function parseHlsManifest(\n content: string,\n baseUrl?: string\n): HlsManifest {\n const lines = splitLines(content);\n return lines.some(\n (l) => l.startsWith(\"#EXT-X-STREAM-INF:\") || l.startsWith(\"#EXT-X-MEDIA:\")\n )\n ? parseHlsMaster(lines, baseUrl)\n : parseHlsMedia(lines, baseUrl);\n}\n","import { BOM_RE, parseM3u, parsePls } from \"./playlist-m3u.ts\";\nimport type { ParsedPlaylist } from \"./playlist-m3u.ts\";\n\nexport { parseHlsManifest } from \"./playlist-hls.ts\";\nexport type {\n HlsManifest,\n HlsMasterPlaylist,\n HlsMediaPlaylist,\n HlsMediaRendition,\n HlsMediaSegment,\n HlsVariantStream,\n} from \"./playlist-hls.ts\";\nexport { parseM3u, parsePls } from \"./playlist-m3u.ts\";\nexport type {\n M3uPlaylist,\n ParsedPlaylist,\n PlaylistEntry,\n PlsPlaylist,\n} from \"./playlist-m3u.ts\";\n\nexport function parsePlaylist(\n content: string,\n baseUrl?: string\n): ParsedPlaylist {\n return content\n .replace(BOM_RE, \"\")\n .trimStart()\n .toLowerCase()\n .startsWith(\"[playlist]\")\n ? parsePls(content, ba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,cACd,SACA,SACgB;CAChB,OAAO,QACJ,QAAQ,QAAQ,EAAE,CAAC,CACnB,UAAU,CAAC,CACX,YAAY,CAAC,CACb,WAAW,YAAY,IACtB,SAAS,SAAS,OAAO,IACzB,SAAS,SAAS,OAAO;AAC/B"}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { a as createWorkletBlobUrl, i as WorkletModuleHandle, n as VITE_AUDIO_WORKLET_OPTIMIZE_DEPS_EXCLUDE, o as createWorkletModuleUrl, r as WorkletId, s as loadAudioWorklet, t as LoadAudioWorkletOptions } from "../worklet-loader-BabwPALw.js";
|
|
2
|
+
import { Effect, Scope } from "effect";
|
|
3
|
+
import { c as AudioRoutingError, d as AudioWorkletError, u as AudioUnsupportedError } from "../errors-ChTQFwuZ.js";
|
|
4
|
+
export declare const METER_PROCESSOR_NAME: "avoid-meter";
|
|
5
|
+
interface MeterWorkletFrame {
|
|
6
|
+
readonly leftPeak: number;
|
|
7
|
+
readonly rightPeak: number;
|
|
8
|
+
readonly leftRms: number;
|
|
9
|
+
readonly rightRms: number;
|
|
10
|
+
}
|
|
11
|
+
export declare const DEFAULT_METER_FLOOR_DB = -60;
|
|
12
|
+
export declare const DEFAULT_METER_INTERVAL_MS = 50;
|
|
13
|
+
export declare const DEFAULT_ANALYSER_FFT_SIZE = 256;
|
|
14
|
+
interface StereoMeterReading {
|
|
15
|
+
readonly leftPeak: number;
|
|
16
|
+
readonly rightPeak: number;
|
|
17
|
+
readonly leftRms: number;
|
|
18
|
+
readonly rightRms: number;
|
|
19
|
+
readonly leftDb: number;
|
|
20
|
+
readonly rightDb: number;
|
|
21
|
+
readonly leftNormalized: number;
|
|
22
|
+
readonly rightNormalized: number;
|
|
23
|
+
}
|
|
24
|
+
interface LoadMeterWorkletOptions {
|
|
25
|
+
readonly moduleUrl?: string;
|
|
26
|
+
readonly inlineSource?: string;
|
|
27
|
+
readonly fallbackToBlob?: boolean;
|
|
28
|
+
readonly fetchImpl?: (input: string | URL | Request, init?: RequestInit) => Promise<Response>;
|
|
29
|
+
}
|
|
30
|
+
interface StereoMeterOptions {
|
|
31
|
+
readonly mode?: "auto" | "worklet" | "analyser";
|
|
32
|
+
readonly intervalMs?: number;
|
|
33
|
+
readonly fftSize?: number;
|
|
34
|
+
readonly floorDb?: number;
|
|
35
|
+
readonly workletOptions?: LoadMeterWorkletOptions;
|
|
36
|
+
}
|
|
37
|
+
interface StereoMeter {
|
|
38
|
+
readonly subscribe: (listener: (reading: StereoMeterReading) => void) => () => void;
|
|
39
|
+
readonly getLatest: () => StereoMeterReading;
|
|
40
|
+
readonly isActive: () => boolean;
|
|
41
|
+
readonly dispose: () => void;
|
|
42
|
+
}
|
|
43
|
+
export declare function linearToDb(amplitude: number): number;
|
|
44
|
+
export declare function dbToNormalized(db: number, floorDb?: number): number;
|
|
45
|
+
export declare function computePeakAndRms(samples: Float32Array): {
|
|
46
|
+
readonly peak: number;
|
|
47
|
+
readonly rms: number;
|
|
48
|
+
};
|
|
49
|
+
export declare function buildStereoMeterReading(frame: MeterWorkletFrame, floorDb?: number): StereoMeterReading;
|
|
50
|
+
export declare function loadMeterWorklet(context: BaseAudioContext, options?: LoadMeterWorkletOptions): Effect.Effect<void, AudioUnsupportedError | AudioWorkletError>;
|
|
51
|
+
export declare function createStereoMeter(context: BaseAudioContext, source: AudioNode, options?: StereoMeterOptions): Effect.Effect<StereoMeter, never, Scope.Scope>;
|
|
52
|
+
export declare const MAX_OUTPUT_DELAY_MS = 500;
|
|
53
|
+
export declare const DELAY_RAMP_TIME_CONSTANT_S = 0.02;
|
|
54
|
+
type DeviceSinkStatus = "empty" | "ok" | "unsupported" | "unplugged" | "failed";
|
|
55
|
+
interface SinkIdCapabilities {
|
|
56
|
+
readonly audioContextSetSinkId: boolean;
|
|
57
|
+
readonly mediaElementSetSinkId: boolean;
|
|
58
|
+
}
|
|
59
|
+
interface SinkCapableAudioContext extends AudioContext {
|
|
60
|
+
setSinkId?: (sinkId: string) => Promise<void>;
|
|
61
|
+
readonly sinkId?: string;
|
|
62
|
+
}
|
|
63
|
+
interface SinkCapableMediaElement extends Omit<HTMLAudioElement, "setSinkId" | "sinkId"> {
|
|
64
|
+
setSinkId?: (sinkId: string) => Promise<void>;
|
|
65
|
+
readonly sinkId?: string;
|
|
66
|
+
}
|
|
67
|
+
interface MultiSinkState {
|
|
68
|
+
readonly mainSinkId: string;
|
|
69
|
+
readonly mainDelayMs: number;
|
|
70
|
+
readonly cueSinkId: string | undefined;
|
|
71
|
+
readonly cueDelayMs: number;
|
|
72
|
+
readonly cueVolume: number;
|
|
73
|
+
readonly deviceSinks: Readonly<Record<string, {
|
|
74
|
+
readonly deviceId: string;
|
|
75
|
+
readonly delayMs: number;
|
|
76
|
+
readonly status: DeviceSinkStatus;
|
|
77
|
+
}>>;
|
|
78
|
+
}
|
|
79
|
+
interface RoutingTransactionPatch {
|
|
80
|
+
readonly mainSinkId?: string;
|
|
81
|
+
readonly mainDelayMs?: number;
|
|
82
|
+
readonly cueSinkId?: string | undefined;
|
|
83
|
+
readonly cueDelayMs?: number;
|
|
84
|
+
readonly cueVolume?: number;
|
|
85
|
+
}
|
|
86
|
+
interface MultiSinkRouterOptions {
|
|
87
|
+
readonly createAudioElement?: () => SinkCapableMediaElement;
|
|
88
|
+
readonly maxDelayMs?: number;
|
|
89
|
+
}
|
|
90
|
+
interface MultiSinkRouter {
|
|
91
|
+
readonly mainInput: GainNode;
|
|
92
|
+
readonly realtimeInput: GainNode;
|
|
93
|
+
readonly cueInput: GainNode;
|
|
94
|
+
readonly capabilities: SinkIdCapabilities;
|
|
95
|
+
readonly getState: () => MultiSinkState;
|
|
96
|
+
readonly applyTransaction: (patch: RoutingTransactionPatch) => Effect.Effect<MultiSinkState, AudioRoutingError>;
|
|
97
|
+
readonly setMainSink: (sinkId: string) => Effect.Effect<MultiSinkState, AudioRoutingError>;
|
|
98
|
+
readonly setCueSink: (sinkId: string | undefined) => Effect.Effect<MultiSinkState, AudioRoutingError>;
|
|
99
|
+
readonly setMainDelayMs: (delayMs: number) => number;
|
|
100
|
+
readonly setCueDelayMs: (delayMs: number) => number;
|
|
101
|
+
readonly setCueVolume: (volume: number) => number;
|
|
102
|
+
readonly attachDeviceSink: (nodeId: string, source: AudioNode, deviceId: string, delayMs?: number) => Effect.Effect<DeviceSinkStatus, AudioRoutingError>;
|
|
103
|
+
readonly detachDeviceSink: (nodeId: string) => void;
|
|
104
|
+
readonly dispose: () => void;
|
|
105
|
+
}
|
|
106
|
+
export declare const detectSinkIdCapabilities: () => SinkIdCapabilities;
|
|
107
|
+
export declare const clampOutputDelayMs: (delayMs: number, maxDelayMs?: number) => number;
|
|
108
|
+
export declare function createMultiSinkRouter(context: SinkCapableAudioContext, options?: MultiSinkRouterOptions): Effect.Effect<MultiSinkRouter, never, Scope.Scope>;
|
|
109
|
+
export { type DeviceSinkStatus, type LoadAudioWorkletOptions, type LoadMeterWorkletOptions, type MeterWorkletFrame, type MultiSinkRouter, type MultiSinkRouterOptions, type MultiSinkState, type RoutingTransactionPatch, type SinkCapableAudioContext, type SinkCapableMediaElement, type SinkIdCapabilities, type StereoMeter, type StereoMeterOptions, type StereoMeterReading, VITE_AUDIO_WORKLET_OPTIMIZE_DEPS_EXCLUDE, type WorkletId, type WorkletModuleHandle, createWorkletBlobUrl, createWorkletModuleUrl, loadAudioWorklet };
|