@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,283 @@
|
|
|
1
|
+
const DEADBAND_SEC = .001;
|
|
2
|
+
const SLEW_RATE = .003;
|
|
3
|
+
const REPLACE_SEC = .2;
|
|
4
|
+
const JOIN_US = 1e3;
|
|
5
|
+
const noStats = () => ({
|
|
6
|
+
chunks: 0,
|
|
7
|
+
corrections: 0,
|
|
8
|
+
errorMax: Number.NEGATIVE_INFINITY,
|
|
9
|
+
errorMin: Number.POSITIVE_INFINITY,
|
|
10
|
+
filled: 0,
|
|
11
|
+
lost: 0,
|
|
12
|
+
skipped: 0,
|
|
13
|
+
slack: Number.POSITIVE_INFINITY
|
|
14
|
+
});
|
|
15
|
+
function resetStats(s) {
|
|
16
|
+
s.chunks = 0;
|
|
17
|
+
s.corrections = 0;
|
|
18
|
+
s.errorMax = Number.NEGATIVE_INFINITY;
|
|
19
|
+
s.errorMin = Number.POSITIVE_INFINITY;
|
|
20
|
+
s.filled = 0;
|
|
21
|
+
s.lost = 0;
|
|
22
|
+
s.skipped = 0;
|
|
23
|
+
s.slack = Number.POSITIVE_INFINITY;
|
|
24
|
+
}
|
|
25
|
+
function interpolateSample(samples, nextChunk, ch, idx, frac) {
|
|
26
|
+
const s = samples[idx] ?? 0;
|
|
27
|
+
if (frac === 0) return s;
|
|
28
|
+
return s + ((idx + 1 < samples.length ? samples[idx + 1] ?? s : (nextChunk?.channels[ch] ?? nextChunk?.channels[0])?.[0] ?? s) - s) * frac;
|
|
29
|
+
}
|
|
30
|
+
var LiveTimeline = class {
|
|
31
|
+
capacity;
|
|
32
|
+
ring;
|
|
33
|
+
head = 0;
|
|
34
|
+
tail = 0;
|
|
35
|
+
count = 0;
|
|
36
|
+
position = 0;
|
|
37
|
+
playing = false;
|
|
38
|
+
dry = false;
|
|
39
|
+
endStampUs;
|
|
40
|
+
correcting = 0;
|
|
41
|
+
settling = false;
|
|
42
|
+
rate = 1;
|
|
43
|
+
sampleRate;
|
|
44
|
+
stats = noStats();
|
|
45
|
+
constructor(sampleRate, capacity = 256) {
|
|
46
|
+
this.sampleRate = sampleRate;
|
|
47
|
+
this.capacity = Number.isFinite(capacity) ? Math.max(2, Math.floor(capacity)) : 256;
|
|
48
|
+
this.ring = Array.from({ length: this.capacity });
|
|
49
|
+
}
|
|
50
|
+
get length() {
|
|
51
|
+
return this.count;
|
|
52
|
+
}
|
|
53
|
+
get maxCapacity() {
|
|
54
|
+
return this.capacity;
|
|
55
|
+
}
|
|
56
|
+
reset() {
|
|
57
|
+
this.ring.fill(void 0);
|
|
58
|
+
this.head = 0;
|
|
59
|
+
this.tail = 0;
|
|
60
|
+
this.count = 0;
|
|
61
|
+
this.dry = false;
|
|
62
|
+
this.endStampUs = void 0;
|
|
63
|
+
this.stopSlew(true);
|
|
64
|
+
resetStats(this.stats);
|
|
65
|
+
}
|
|
66
|
+
takeStats() {
|
|
67
|
+
const snap = noStats();
|
|
68
|
+
this.takeStatsInto(snap);
|
|
69
|
+
return snap;
|
|
70
|
+
}
|
|
71
|
+
takeStatsInto(target) {
|
|
72
|
+
target.chunks = this.stats.chunks;
|
|
73
|
+
target.corrections = this.stats.corrections;
|
|
74
|
+
target.errorMax = this.stats.errorMax;
|
|
75
|
+
target.errorMin = this.stats.errorMin;
|
|
76
|
+
target.filled = this.stats.filled;
|
|
77
|
+
target.lost = this.stats.lost;
|
|
78
|
+
target.skipped = this.stats.skipped;
|
|
79
|
+
target.slack = this.stats.slack;
|
|
80
|
+
resetStats(this.stats);
|
|
81
|
+
}
|
|
82
|
+
stopSlew(resetPos = false) {
|
|
83
|
+
this.playing = false;
|
|
84
|
+
this.settling = false;
|
|
85
|
+
this.correcting = 0;
|
|
86
|
+
this.rate = 1;
|
|
87
|
+
if (resetPos) this.position = 0;
|
|
88
|
+
}
|
|
89
|
+
at(offset) {
|
|
90
|
+
return offset < this.count ? this.ring[(this.head + offset) % this.capacity] : void 0;
|
|
91
|
+
}
|
|
92
|
+
dropHead() {
|
|
93
|
+
this.ring[this.head] = void 0;
|
|
94
|
+
this.head = (this.head + 1) % this.capacity;
|
|
95
|
+
this.count -= 1;
|
|
96
|
+
}
|
|
97
|
+
push(chunk, next) {
|
|
98
|
+
if ((chunk.channels[0]?.length ?? 0) === 0) return;
|
|
99
|
+
const slack = this.playing ? this.queued() : chunk.frame - next;
|
|
100
|
+
const follows = this.endStampUs !== void 0 && Math.abs(chunk.stampUs - this.endStampUs) <= JOIN_US;
|
|
101
|
+
this.stats.chunks += 1;
|
|
102
|
+
this.stats.slack = Math.min(this.stats.slack, slack);
|
|
103
|
+
if (slack < 0 || this.dry && follows) this.stats.lost += 1;
|
|
104
|
+
this.dry = false;
|
|
105
|
+
if (this.count === this.capacity) {
|
|
106
|
+
this.dropHead();
|
|
107
|
+
this.stats.lost += 1;
|
|
108
|
+
if (this.playing) this.stopSlew(true);
|
|
109
|
+
}
|
|
110
|
+
this.ring[this.tail] = chunk;
|
|
111
|
+
this.tail = (this.tail + 1) % this.capacity;
|
|
112
|
+
this.count += 1;
|
|
113
|
+
}
|
|
114
|
+
render(frame, output) {
|
|
115
|
+
const frames = output[0]?.length ?? 0;
|
|
116
|
+
if (this.playing) this.steer(frame);
|
|
117
|
+
const chCount = output.length;
|
|
118
|
+
for (let i = 0; i < frames; i += 1) {
|
|
119
|
+
if (!this.playing && !this.place(frame + i)) {
|
|
120
|
+
for (let c = 0; c < chCount; c += 1) {
|
|
121
|
+
const outCh = output[c];
|
|
122
|
+
if (outCh) outCh[i] = 0;
|
|
123
|
+
}
|
|
124
|
+
if (this.dry) this.stats.filled += 1;
|
|
125
|
+
continue;
|
|
126
|
+
}
|
|
127
|
+
this.read(output, i, frame + i);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
queued() {
|
|
131
|
+
let frames = -this.position;
|
|
132
|
+
for (let i = 0; i < this.count; i += 1) frames += this.ring[(this.head + i) % this.capacity]?.channels[0]?.length ?? 0;
|
|
133
|
+
return frames / this.rate;
|
|
134
|
+
}
|
|
135
|
+
place(frame) {
|
|
136
|
+
while (this.count > 0) {
|
|
137
|
+
const chunk = this.at(0);
|
|
138
|
+
if (!chunk) return false;
|
|
139
|
+
const offset = Math.round(frame - chunk.frame);
|
|
140
|
+
const len = chunk.channels[0]?.length ?? 0;
|
|
141
|
+
if (offset < 0) return false;
|
|
142
|
+
if (offset < len) {
|
|
143
|
+
this.stats.skipped += offset;
|
|
144
|
+
this.position = offset;
|
|
145
|
+
this.playing = true;
|
|
146
|
+
return true;
|
|
147
|
+
}
|
|
148
|
+
this.stats.skipped += len;
|
|
149
|
+
this.dropHead();
|
|
150
|
+
}
|
|
151
|
+
return false;
|
|
152
|
+
}
|
|
153
|
+
steer(frame) {
|
|
154
|
+
const chunk = this.at(0);
|
|
155
|
+
if (!chunk) return;
|
|
156
|
+
const err = chunk.frame + this.position - frame;
|
|
157
|
+
this.stats.errorMin = Math.min(this.stats.errorMin, err);
|
|
158
|
+
this.stats.errorMax = Math.max(this.stats.errorMax, err);
|
|
159
|
+
if (Math.abs(err) > REPLACE_SEC * this.sampleRate) {
|
|
160
|
+
this.stopSlew();
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
const sign = Math.sign(err);
|
|
164
|
+
if (this.correcting === 0 && Math.abs(err) > DEADBAND_SEC * this.sampleRate) {
|
|
165
|
+
this.correcting = sign;
|
|
166
|
+
this.settling = false;
|
|
167
|
+
this.rate = 1 - sign * SLEW_RATE;
|
|
168
|
+
this.stats.corrections += 1;
|
|
169
|
+
} else if (this.correcting !== 0 && sign !== this.correcting) this.settling = true;
|
|
170
|
+
}
|
|
171
|
+
read(output, i, frameIdx) {
|
|
172
|
+
const chunk = this.at(0);
|
|
173
|
+
if (!chunk) return;
|
|
174
|
+
const next = this.at(1);
|
|
175
|
+
const idx = Math.floor(this.position);
|
|
176
|
+
const frac = this.position - idx;
|
|
177
|
+
const chCount = output.length;
|
|
178
|
+
for (let c = 0; c < chCount; c += 1) {
|
|
179
|
+
const outCh = output[c];
|
|
180
|
+
const samples = chunk.channels[c] ?? chunk.channels[0];
|
|
181
|
+
if (outCh && samples) outCh[i] = interpolateSample(samples, next, c, idx, frac);
|
|
182
|
+
}
|
|
183
|
+
this.position += this.rate;
|
|
184
|
+
const whole = Math.round(this.position);
|
|
185
|
+
if (this.settling && Math.abs(this.position - whole) < SLEW_RATE) {
|
|
186
|
+
this.position = whole;
|
|
187
|
+
this.rate = 1;
|
|
188
|
+
this.correcting = 0;
|
|
189
|
+
this.settling = false;
|
|
190
|
+
}
|
|
191
|
+
const len = chunk.channels[0]?.length ?? 0;
|
|
192
|
+
if (this.position < len) return;
|
|
193
|
+
this.position -= len;
|
|
194
|
+
this.endStampUs = chunk.stampUs + len / this.sampleRate * 1e6;
|
|
195
|
+
this.dropHead();
|
|
196
|
+
const nextChunk = this.at(0);
|
|
197
|
+
if (!nextChunk) {
|
|
198
|
+
this.dry = true;
|
|
199
|
+
this.stopSlew();
|
|
200
|
+
} else if (Math.abs(nextChunk.frame + this.position - (frameIdx + 1)) > REPLACE_SEC * this.sampleRate) this.stopSlew(true);
|
|
201
|
+
}
|
|
202
|
+
};
|
|
203
|
+
// src/worklets/couch-live.ts
|
|
204
|
+
const COUCH_LIVE_PROCESSOR_NAME = "couch-live";
|
|
205
|
+
if (typeof registerProcessor === "function") {
|
|
206
|
+
const reportFrames = sampleRate / 10;
|
|
207
|
+
registerProcessor(COUCH_LIVE_PROCESSOR_NAME, class CouchLiveProcessor extends AudioWorkletProcessor {
|
|
208
|
+
timeline = new LiveTimeline(sampleRate);
|
|
209
|
+
reportStats = noStats();
|
|
210
|
+
reportPayload;
|
|
211
|
+
epoch = 0;
|
|
212
|
+
next = currentFrame;
|
|
213
|
+
reported = currentFrame;
|
|
214
|
+
feed;
|
|
215
|
+
disposed = false;
|
|
216
|
+
onFeedMessage = (msgEvent) => {
|
|
217
|
+
const msg = msgEvent.data;
|
|
218
|
+
if (this.disposed || !msg || typeof msg !== "object") return;
|
|
219
|
+
if (msg.type === "dispose") this.dispose();
|
|
220
|
+
else if (msg.type === "chunk" && msg.chunk) this.timeline.push(msg.chunk, this.next);
|
|
221
|
+
else if (msg.type === "reset") {
|
|
222
|
+
this.timeline.reset();
|
|
223
|
+
this.epoch = typeof msg.epoch === "number" ? msg.epoch : 0;
|
|
224
|
+
}
|
|
225
|
+
};
|
|
226
|
+
onPortMessage = (event) => {
|
|
227
|
+
const { data } = event;
|
|
228
|
+
if (this.disposed || !data || typeof data !== "object") return;
|
|
229
|
+
if (data.type === "dispose") this.dispose();
|
|
230
|
+
else if (data.type === "poll") this.flushReport();
|
|
231
|
+
else if (data.port) {
|
|
232
|
+
this.detachFeed();
|
|
233
|
+
this.feed = data.port;
|
|
234
|
+
this.feed.addEventListener("message", this.onFeedMessage);
|
|
235
|
+
this.feed.start?.();
|
|
236
|
+
}
|
|
237
|
+
};
|
|
238
|
+
constructor() {
|
|
239
|
+
super();
|
|
240
|
+
this.reportPayload = {
|
|
241
|
+
epoch: 0,
|
|
242
|
+
stats: this.reportStats
|
|
243
|
+
};
|
|
244
|
+
this.port.addEventListener("message", this.onPortMessage);
|
|
245
|
+
this.port.start?.();
|
|
246
|
+
}
|
|
247
|
+
detachFeed() {
|
|
248
|
+
if (!this.feed) return;
|
|
249
|
+
this.feed.removeEventListener("message", this.onFeedMessage);
|
|
250
|
+
this.feed.close?.();
|
|
251
|
+
this.feed = void 0;
|
|
252
|
+
}
|
|
253
|
+
dispose() {
|
|
254
|
+
if (this.disposed) return;
|
|
255
|
+
this.disposed = true;
|
|
256
|
+
this.detachFeed();
|
|
257
|
+
this.timeline.reset();
|
|
258
|
+
this.port.removeEventListener("message", this.onPortMessage);
|
|
259
|
+
this.port.close?.();
|
|
260
|
+
}
|
|
261
|
+
flushReport() {
|
|
262
|
+
if (this.disposed || !this.feed) return;
|
|
263
|
+
this.timeline.takeStatsInto(this.reportStats);
|
|
264
|
+
this.reportPayload.epoch = this.epoch;
|
|
265
|
+
this.feed.postMessage(this.reportPayload);
|
|
266
|
+
}
|
|
267
|
+
process(_inputs, outputs) {
|
|
268
|
+
if (this.disposed) return false;
|
|
269
|
+
const [output] = outputs;
|
|
270
|
+
if (!output) return true;
|
|
271
|
+
this.timeline.render(currentFrame, output);
|
|
272
|
+
this.next = currentFrame + (output[0]?.length ?? 0);
|
|
273
|
+
if (this.next - this.reported >= reportFrames) {
|
|
274
|
+
this.reported = this.next;
|
|
275
|
+
this.flushReport();
|
|
276
|
+
}
|
|
277
|
+
return true;
|
|
278
|
+
}
|
|
279
|
+
});
|
|
280
|
+
}
|
|
281
|
+
export { COUCH_LIVE_PROCESSOR_NAME };
|
|
282
|
+
|
|
283
|
+
//# sourceMappingURL=couch-live.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"couch-live.js","names":[],"sources":["../../src/sync/live-timeline.ts","../../src/worklets/couch-live.ts"],"sourcesContent":["export interface LiveChunk {\n readonly frame: number;\n readonly stampUs: number;\n readonly channels: readonly Float32Array[];\n}\n\nexport type LiveMessage =\n | { readonly type: \"chunk\"; readonly chunk: LiveChunk }\n | { readonly type: \"reset\"; readonly epoch: number }\n | { readonly type: \"dispose\" };\n\nexport interface LiveClock {\n readonly offset: number;\n readonly sampleRate: number;\n}\n\nexport interface PageClockEstimator {\n readonly saw: (pageMs: number, ownMs?: number) => void;\n readonly pageMs: (ownMs?: number) => number;\n}\n\nexport interface LiveStats {\n chunks: number;\n lost: number;\n slack: number;\n filled: number;\n skipped: number;\n errorMin: number;\n errorMax: number;\n corrections: number;\n}\n\nexport const DEFAULT_LIVE_TIMELINE_CAPACITY = 256;\n\nconst DEADBAND_SEC = 0.001;\nconst SLEW_RATE = 0.003;\nconst REPLACE_SEC = 0.2;\nconst JOIN_US = 1000;\n\nexport const contextFrame = (clock: LiveClock, pageMs: number): number =>\n (clock.offset + pageMs / 1000) * clock.sampleRate;\n\nexport function pageClock(): PageClockEstimator {\n let aheadMs = Number.POSITIVE_INFINITY;\n return {\n pageMs: (ownMs = performance.now()): number => ownMs - aheadMs,\n saw: (pageMs: number, ownMs = performance.now()): void => {\n aheadMs = Math.min(aheadMs, ownMs - pageMs);\n },\n };\n}\n\nexport const noStats = (): LiveStats => ({\n chunks: 0,\n corrections: 0,\n errorMax: Number.NEGATIVE_INFINITY,\n errorMin: Number.POSITIVE_INFINITY,\n filled: 0,\n lost: 0,\n skipped: 0,\n slack: Number.POSITIVE_INFINITY,\n});\n\nexport function addStats(totals: LiveStats, stats: LiveStats): void {\n totals.chunks += stats.chunks;\n totals.lost += stats.lost;\n totals.slack = Math.min(totals.slack, stats.slack);\n totals.filled += stats.filled;\n totals.skipped += stats.skipped;\n totals.errorMin = Math.min(totals.errorMin, stats.errorMin);\n totals.errorMax = Math.max(totals.errorMax, stats.errorMax);\n totals.corrections += stats.corrections;\n}\n\nfunction resetStats(s: LiveStats): void {\n s.chunks = 0;\n s.corrections = 0;\n s.errorMax = Number.NEGATIVE_INFINITY;\n s.errorMin = Number.POSITIVE_INFINITY;\n s.filled = 0;\n s.lost = 0;\n s.skipped = 0;\n s.slack = Number.POSITIVE_INFINITY;\n}\n\nfunction interpolateSample(\n samples: Float32Array,\n nextChunk: LiveChunk | undefined,\n ch: number,\n idx: number,\n frac: number\n): number {\n const s = samples[idx] ?? 0;\n if (frac === 0) {\n return s;\n }\n const after =\n idx + 1 < samples.length\n ? (samples[idx + 1] ?? s)\n : ((nextChunk?.channels[ch] ?? nextChunk?.channels[0])?.[0] ?? s);\n return s + (after - s) * frac;\n}\n\nexport class LiveTimeline {\n private readonly capacity: number;\n private readonly ring: (LiveChunk | undefined)[];\n private head = 0;\n private tail = 0;\n private count = 0;\n private position = 0;\n private playing = false;\n private dry = false;\n private endStampUs: number | undefined;\n private correcting = 0;\n private settling = false;\n private rate = 1;\n private readonly sampleRate: number;\n\n stats: LiveStats = noStats();\n\n constructor(\n sampleRate: number,\n capacity: number = DEFAULT_LIVE_TIMELINE_CAPACITY\n ) {\n this.sampleRate = sampleRate;\n this.capacity = Number.isFinite(capacity)\n ? Math.max(2, Math.floor(capacity))\n : DEFAULT_LIVE_TIMELINE_CAPACITY;\n this.ring = Array.from<LiveChunk | undefined>({ length: this.capacity });\n }\n\n get length(): number {\n return this.count;\n }\n\n get maxCapacity(): number {\n return this.capacity;\n }\n\n reset(): void {\n this.ring.fill(undefined);\n this.head = 0;\n this.tail = 0;\n this.count = 0;\n this.dry = false;\n this.endStampUs = undefined;\n this.stopSlew(true);\n resetStats(this.stats);\n }\n\n takeStats(): LiveStats {\n const snap = noStats();\n this.takeStatsInto(snap);\n return snap;\n }\n\n takeStatsInto(target: LiveStats): void {\n target.chunks = this.stats.chunks;\n target.corrections = this.stats.corrections;\n target.errorMax = this.stats.errorMax;\n target.errorMin = this.stats.errorMin;\n target.filled = this.stats.filled;\n target.lost = this.stats.lost;\n target.skipped = this.stats.skipped;\n target.slack = this.stats.slack;\n resetStats(this.stats);\n }\n\n private stopSlew(resetPos = false): void {\n this.playing = false;\n this.settling = false;\n this.correcting = 0;\n this.rate = 1;\n if (resetPos) {\n this.position = 0;\n }\n }\n\n private at(offset: number): LiveChunk | undefined {\n return offset < this.count\n ? this.ring[(this.head + offset) % this.capacity]\n : undefined;\n }\n\n private dropHead(): void {\n this.ring[this.head] = undefined;\n this.head = (this.head + 1) % this.capacity;\n this.count -= 1;\n }\n\n push(chunk: LiveChunk, next: number): void {\n if ((chunk.channels[0]?.length ?? 0) === 0) {\n return;\n }\n const slack = this.playing ? this.queued() : chunk.frame - next;\n const follows =\n this.endStampUs !== undefined &&\n Math.abs(chunk.stampUs - this.endStampUs) <= JOIN_US;\n this.stats.chunks += 1;\n this.stats.slack = Math.min(this.stats.slack, slack);\n if (slack < 0 || (this.dry && follows)) {\n this.stats.lost += 1;\n }\n this.dry = false;\n if (this.count === this.capacity) {\n this.dropHead();\n this.stats.lost += 1;\n if (this.playing) {\n this.stopSlew(true);\n }\n }\n this.ring[this.tail] = chunk;\n this.tail = (this.tail + 1) % this.capacity;\n this.count += 1;\n }\n\n render(frame: number, output: Float32Array[]): void {\n const frames = output[0]?.length ?? 0;\n if (this.playing) {\n this.steer(frame);\n }\n const chCount = output.length;\n for (let i = 0; i < frames; i += 1) {\n if (!this.playing && !this.place(frame + i)) {\n for (let c = 0; c < chCount; c += 1) {\n const outCh = output[c];\n if (outCh) {\n outCh[i] = 0;\n }\n }\n if (this.dry) {\n this.stats.filled += 1;\n }\n continue;\n }\n this.read(output, i, frame + i);\n }\n }\n\n private queued(): number {\n let frames = -this.position;\n for (let i = 0; i < this.count; i += 1) {\n frames +=\n this.ring[(this.head + i) % this.capacity]?.channels[0]?.length ?? 0;\n }\n return frames / this.rate;\n }\n\n private place(frame: number): boolean {\n while (this.count > 0) {\n const chunk = this.at(0);\n if (!chunk) {\n return false;\n }\n const offset = Math.round(frame - chunk.frame);\n const len = chunk.channels[0]?.length ?? 0;\n if (offset < 0) {\n return false;\n }\n if (offset < len) {\n this.stats.skipped += offset;\n this.position = offset;\n this.playing = true;\n return true;\n }\n this.stats.skipped += len;\n this.dropHead();\n }\n return false;\n }\n\n private steer(frame: number): void {\n const chunk = this.at(0);\n if (!chunk) {\n return;\n }\n const err = chunk.frame + this.position - frame;\n this.stats.errorMin = Math.min(this.stats.errorMin, err);\n this.stats.errorMax = Math.max(this.stats.errorMax, err);\n if (Math.abs(err) > REPLACE_SEC * this.sampleRate) {\n this.stopSlew();\n return;\n }\n const sign = Math.sign(err);\n if (\n this.correcting === 0 &&\n Math.abs(err) > DEADBAND_SEC * this.sampleRate\n ) {\n this.correcting = sign;\n this.settling = false;\n this.rate = 1 - sign * SLEW_RATE;\n this.stats.corrections += 1;\n } else if (this.correcting !== 0 && sign !== this.correcting) {\n this.settling = true;\n }\n }\n\n private read(output: Float32Array[], i: number, frameIdx: number): void {\n const chunk = this.at(0);\n if (!chunk) {\n return;\n }\n const next = this.at(1);\n const idx = Math.floor(this.position);\n const frac = this.position - idx;\n const chCount = output.length;\n for (let c = 0; c < chCount; c += 1) {\n const outCh = output[c];\n const samples = chunk.channels[c] ?? chunk.channels[0];\n if (outCh && samples) {\n outCh[i] = interpolateSample(samples, next, c, idx, frac);\n }\n }\n this.position += this.rate;\n const whole = Math.round(this.position);\n if (this.settling && Math.abs(this.position - whole) < SLEW_RATE) {\n this.position = whole;\n this.rate = 1;\n this.correcting = 0;\n this.settling = false;\n }\n const len = chunk.channels[0]?.length ?? 0;\n if (this.position < len) {\n return;\n }\n this.position -= len;\n this.endStampUs = chunk.stampUs + (len / this.sampleRate) * 1e6;\n this.dropHead();\n const nextChunk = this.at(0);\n if (!nextChunk) {\n this.dry = true;\n this.stopSlew();\n } else if (\n Math.abs(nextChunk.frame + this.position - (frameIdx + 1)) >\n REPLACE_SEC * this.sampleRate\n ) {\n this.stopSlew(true);\n }\n }\n}\n","// Standalone \"couch-live\" AudioWorkletProcessor (LiveTimeline inlined by tsdown).\nimport { LiveTimeline, noStats } from \"../sync/live-timeline.ts\";\nimport type { LiveMessage, LiveStats } from \"../sync/live-timeline.ts\";\n\ndeclare const sampleRate: number;\ndeclare const currentFrame: number;\ndeclare function registerProcessor(\n name: string,\n processor: new () => object\n): void;\ndeclare class AudioWorkletProcessor {\n readonly port: MessagePort;\n}\n\nexport const COUCH_LIVE_PROCESSOR_NAME = \"couch-live\" as const;\n\nif (typeof registerProcessor === \"function\") {\n const reportFrames = sampleRate / 10;\n\n registerProcessor(\n COUCH_LIVE_PROCESSOR_NAME,\n class CouchLiveProcessor extends AudioWorkletProcessor {\n private readonly timeline = new LiveTimeline(sampleRate);\n private readonly reportStats: LiveStats = noStats();\n private readonly reportPayload: { epoch: number; stats: LiveStats };\n private epoch = 0;\n private next = currentFrame;\n private reported = currentFrame;\n private feed: MessagePort | undefined;\n private disposed = false;\n\n private readonly onFeedMessage = (\n msgEvent: MessageEvent<LiveMessage | null | undefined>\n ): void => {\n const msg = msgEvent.data;\n if (this.disposed || !msg || typeof msg !== \"object\") {\n return;\n }\n if (msg.type === \"dispose\") {\n this.dispose();\n } else if (msg.type === \"chunk\" && msg.chunk) {\n this.timeline.push(msg.chunk, this.next);\n } else if (msg.type === \"reset\") {\n this.timeline.reset();\n this.epoch = typeof msg.epoch === \"number\" ? msg.epoch : 0;\n }\n };\n\n private readonly onPortMessage = (\n event: MessageEvent<\n { port?: MessagePort; type?: string } | null | undefined\n >\n ): void => {\n const { data } = event;\n if (this.disposed || !data || typeof data !== \"object\") {\n return;\n }\n if (data.type === \"dispose\") {\n this.dispose();\n } else if (data.type === \"poll\") {\n this.flushReport();\n } else if (data.port) {\n this.detachFeed();\n this.feed = data.port;\n this.feed.addEventListener(\n \"message\",\n this.onFeedMessage as EventListener\n );\n this.feed.start?.();\n }\n };\n\n constructor() {\n super();\n this.reportPayload = { epoch: 0, stats: this.reportStats };\n this.port.addEventListener(\n \"message\",\n this.onPortMessage as EventListener\n );\n this.port.start?.();\n }\n\n private detachFeed(): void {\n if (!this.feed) {\n return;\n }\n this.feed.removeEventListener(\n \"message\",\n this.onFeedMessage as EventListener\n );\n this.feed.close?.();\n this.feed = undefined;\n }\n\n private dispose(): void {\n if (this.disposed) {\n return;\n }\n this.disposed = true;\n this.detachFeed();\n this.timeline.reset();\n this.port.removeEventListener(\n \"message\",\n this.onPortMessage as EventListener\n );\n this.port.close?.();\n }\n\n private flushReport(): void {\n if (this.disposed || !this.feed) {\n return;\n }\n this.timeline.takeStatsInto(this.reportStats);\n this.reportPayload.epoch = this.epoch;\n // oxlint-disable-next-line unicorn/require-post-message-target-origin\n this.feed.postMessage(this.reportPayload);\n }\n\n process(_inputs: Float32Array[][], outputs: Float32Array[][]): boolean {\n if (this.disposed) {\n return false;\n }\n const [output] = outputs;\n if (!output) {\n return true;\n }\n this.timeline.render(currentFrame, output);\n this.next = currentFrame + (output[0]?.length ?? 0);\n if (this.next - this.reported >= reportFrames) {\n this.reported = this.next;\n this.flushReport();\n }\n return true;\n }\n }\n );\n}\n"],"mappings":"AAkCA,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AChB,KAAK,OAAO,KAAK;IACjB,KAAK,KAAK,iBACR,WACA,KAAK,aACP;IACA,KAAK,KAAK,QAAQ;GACpB;EACF;EAEA,cAAc;GACZ,MAAM;GACN,KAAK,gBAAgB;IAAE,OAAO;IAAG,OAAO,KAAK;GAAY;GACzD,KAAK,KAAK,iBACR,WACA,KAAK,aACP;GACA,KAAK,KAAK,QAAQ;EACpB;EAEQ,aAAmB;GACzB,IAAI,CAAC,KAAK,MACR;GAEF,KAAK,KAAK,oBACR,WACA,KAAK,aACP;GACA,KAAK,KAAK,QAAQ;GAClB,KAAK,OAAO,KAAA;EACd;EAEQ,UAAgB;GACtB,IAAI,KAAK,UACP;GAEF,KAAK,WAAW;GAChB,KAAK,WAAW;GAChB,KAAK,SAAS,MAAM;GACpB,KAAK,KAAK,oBACR,WACA,KAAK,aACP;GACA,KAAK,KAAK,QAAQ;EACpB;EAEQ,cAAoB;GAC1B,IAAI,KAAK,YAAY,CAAC,KAAK,MACzB;GAEF,KAAK,SAAS,cAAc,KAAK,WAAW;GAC5C,KAAK,cAAc,QAAQ,KAAK;GAEhC,KAAK,KAAK,YAAY,KAAK,aAAa;EAC1C;EAEA,QAAQ,SAA2B,SAAoC;GACrE,IAAI,KAAK,UACP,OAAO;GAET,MAAM,CAAC,UAAU;GACjB,IAAI,CAAC,QACH,OAAO;GAET,KAAK,SAAS,OAAO,cAAc,MAAM;GACzC,KAAK,OAAO,gBAAgB,OAAO,EAAE,EAAE,UAAU;GACjD,IAAI,KAAK,OAAO,KAAK,YAAY,cAAc;IAC7C,KAAK,WAAW,KAAK;IACrB,KAAK,YAAY;GACnB;GACA,OAAO;EACT;CACF,CACF;AACF"}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
// src/worklets/meter.ts
|
|
2
|
+
const METER_PROCESSOR_NAME = "avoid-meter";
|
|
3
|
+
const DEFAULT_QUANTUM_FRAMES = 128;
|
|
4
|
+
if (typeof registerProcessor === "function") registerProcessor(METER_PROCESSOR_NAME, class AvoidMeterProcessor extends AudioWorkletProcessor {
|
|
5
|
+
leftPeak = 0;
|
|
6
|
+
rightPeak = 0;
|
|
7
|
+
leftSumSq = 0;
|
|
8
|
+
rightSumSq = 0;
|
|
9
|
+
sampleCount = 0;
|
|
10
|
+
reportSamples;
|
|
11
|
+
payload = {
|
|
12
|
+
leftPeak: 0,
|
|
13
|
+
leftRms: 0,
|
|
14
|
+
rightPeak: 0,
|
|
15
|
+
rightRms: 0
|
|
16
|
+
};
|
|
17
|
+
constructor(options) {
|
|
18
|
+
super(options);
|
|
19
|
+
const clampedMs = Math.max(10, Math.min(1e3, options?.processorOptions?.reportIntervalMs ?? 50));
|
|
20
|
+
this.reportSamples = Math.max(DEFAULT_QUANTUM_FRAMES, Math.round(sampleRate * clampedMs / 1e3));
|
|
21
|
+
this.port.addEventListener("message", (event) => {
|
|
22
|
+
if (event.data === "poll") this.flushMeter();
|
|
23
|
+
});
|
|
24
|
+
this.port.start?.();
|
|
25
|
+
}
|
|
26
|
+
flushMeter() {
|
|
27
|
+
const inv = this.sampleCount > 0 ? 1 / this.sampleCount : 0;
|
|
28
|
+
this.payload.leftPeak = this.leftPeak;
|
|
29
|
+
this.payload.rightPeak = this.rightPeak;
|
|
30
|
+
this.payload.leftRms = Math.sqrt(this.leftSumSq * inv);
|
|
31
|
+
this.payload.rightRms = Math.sqrt(this.rightSumSq * inv);
|
|
32
|
+
this.port.postMessage(this.payload);
|
|
33
|
+
this.leftPeak = 0;
|
|
34
|
+
this.rightPeak = 0;
|
|
35
|
+
this.leftSumSq = 0;
|
|
36
|
+
this.rightSumSq = 0;
|
|
37
|
+
this.sampleCount = 0;
|
|
38
|
+
}
|
|
39
|
+
process(inputs, outputs) {
|
|
40
|
+
const left = inputs[0]?.[0];
|
|
41
|
+
if (!left || left.length === 0) {
|
|
42
|
+
const outLen = outputs?.[0]?.[0]?.length ?? 0;
|
|
43
|
+
this.sampleCount += outLen > 0 ? outLen : DEFAULT_QUANTUM_FRAMES;
|
|
44
|
+
if (this.sampleCount >= this.reportSamples) this.flushMeter();
|
|
45
|
+
return true;
|
|
46
|
+
}
|
|
47
|
+
const right = inputs[0]?.[1] ?? left;
|
|
48
|
+
const frames = left.length;
|
|
49
|
+
let lPeak = this.leftPeak;
|
|
50
|
+
let rPeak = this.rightPeak;
|
|
51
|
+
let lSumSq = this.leftSumSq;
|
|
52
|
+
let rSumSq = this.rightSumSq;
|
|
53
|
+
for (let i = 0; i < frames; i += 1) {
|
|
54
|
+
const l = left[i] ?? 0;
|
|
55
|
+
const r = right[i] ?? 0;
|
|
56
|
+
const lAbs = l < 0 ? -l : l;
|
|
57
|
+
const rAbs = r < 0 ? -r : r;
|
|
58
|
+
if (lAbs > lPeak) lPeak = lAbs;
|
|
59
|
+
if (rAbs > rPeak) rPeak = rAbs;
|
|
60
|
+
lSumSq += l * l;
|
|
61
|
+
rSumSq += r * r;
|
|
62
|
+
}
|
|
63
|
+
this.leftPeak = lPeak;
|
|
64
|
+
this.rightPeak = rPeak;
|
|
65
|
+
this.leftSumSq = lSumSq;
|
|
66
|
+
this.rightSumSq = rSumSq;
|
|
67
|
+
this.sampleCount += frames;
|
|
68
|
+
if (this.sampleCount >= this.reportSamples) this.flushMeter();
|
|
69
|
+
return true;
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
export { METER_PROCESSOR_NAME };
|
|
73
|
+
|
|
74
|
+
//# sourceMappingURL=meter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"meter.js","names":[],"sources":["../../src/worklets/meter.ts"],"sourcesContent":["// Standalone zero-import AudioWorkletProcessor for stereo peak & RMS metering.\n\ndeclare const sampleRate: number;\ndeclare function registerProcessor(\n name: string,\n processor: new (options?: {\n processorOptions?: { reportIntervalMs?: number };\n }) => object\n): void;\ndeclare class AudioWorkletProcessor {\n readonly port: MessagePort;\n constructor(options?: { processorOptions?: { reportIntervalMs?: number } });\n}\n\nexport const METER_PROCESSOR_NAME = \"avoid-meter\" as const;\n\nexport interface MeterWorkletFrame {\n readonly leftPeak: number;\n readonly rightPeak: number;\n readonly leftRms: number;\n readonly rightRms: number;\n}\n\nconst DEFAULT_QUANTUM_FRAMES = 128;\n\nif (typeof registerProcessor === \"function\") {\n registerProcessor(\n METER_PROCESSOR_NAME,\n class AvoidMeterProcessor extends AudioWorkletProcessor {\n private leftPeak = 0;\n private rightPeak = 0;\n private leftSumSq = 0;\n private rightSumSq = 0;\n private sampleCount = 0;\n private readonly reportSamples: number;\n private readonly payload = {\n leftPeak: 0,\n leftRms: 0,\n rightPeak: 0,\n rightRms: 0,\n };\n\n constructor(options?: {\n processorOptions?: { reportIntervalMs?: number };\n }) {\n super(options);\n const clampedMs = Math.max(\n 10,\n Math.min(1000, options?.processorOptions?.reportIntervalMs ?? 50)\n );\n this.reportSamples = Math.max(\n DEFAULT_QUANTUM_FRAMES,\n Math.round((sampleRate * clampedMs) / 1000)\n );\n this.port.addEventListener(\"message\", (event: MessageEvent) => {\n if (event.data === \"poll\") {\n this.flushMeter();\n }\n });\n this.port.start?.();\n }\n\n private flushMeter(): void {\n const inv = this.sampleCount > 0 ? 1 / this.sampleCount : 0;\n this.payload.leftPeak = this.leftPeak;\n this.payload.rightPeak = this.rightPeak;\n this.payload.leftRms = Math.sqrt(this.leftSumSq * inv);\n this.payload.rightRms = Math.sqrt(this.rightSumSq * inv);\n // oxlint-disable-next-line unicorn/require-post-message-target-origin\n this.port.postMessage(this.payload);\n this.leftPeak = 0;\n this.rightPeak = 0;\n this.leftSumSq = 0;\n this.rightSumSq = 0;\n this.sampleCount = 0;\n }\n\n process(inputs: Float32Array[][], outputs?: Float32Array[][]): boolean {\n const left = inputs[0]?.[0];\n if (!left || left.length === 0) {\n const outLen = outputs?.[0]?.[0]?.length ?? 0;\n this.sampleCount += outLen > 0 ? outLen : DEFAULT_QUANTUM_FRAMES;\n if (this.sampleCount >= this.reportSamples) {\n this.flushMeter();\n }\n return true;\n }\n\n const right = inputs[0]?.[1] ?? left;\n const frames = left.length;\n let lPeak = this.leftPeak;\n let rPeak = this.rightPeak;\n let lSumSq = this.leftSumSq;\n let rSumSq = this.rightSumSq;\n\n for (let i = 0; i < frames; i += 1) {\n const l = left[i] ?? 0;\n const r = right[i] ?? 0;\n const lAbs = l < 0 ? -l : l;\n const rAbs = r < 0 ? -r : r;\n if (lAbs > lPeak) {\n lPeak = lAbs;\n }\n if (rAbs > rPeak) {\n rPeak = rAbs;\n }\n lSumSq += l * l;\n rSumSq += r * r;\n }\n\n this.leftPeak = lPeak;\n this.rightPeak = rPeak;\n this.leftSumSq = lSumSq;\n this.rightSumSq = rSumSq;\n this.sampleCount += frames;\n if (this.sampleCount >= this.reportSamples) {\n this.flushMeter();\n }\n return true;\n }\n }\n );\n}\n"],"mappings":";AAcA,MAAa,uBAAuB;AASpC,MAAM,yBAAyB;AAE/B,IAAI,OAAO,sBAAsB,YAC/B,kBACE,sBACA,MAAM,4BAA4B,sBAAsB;CAC9C,WAAW;CACX,YAAY;CACZ,YAAY;CACZ,aAAa;CACb,cAAc;CACL;CACA,UAAU;EACzB,UAAU;EACV,SAAS;EACT,WAAW;EACX,UAAU;CACZ;CAEA,YAAY,SAET;EACD,MAAM,OAAO;EACb,MAAM,YAAY,KAAK,IACrB,IACA,KAAK,IAAI,KAAM,SAAS,kBAAkB,oBAAoB,EAAE,CAClE;EACA,KAAK,gBAAgB,KAAK,IACxB,wBACA,KAAK,MAAO,aAAa,YAAa,GAAI,CAC5C;EACA,KAAK,KAAK,iBAAiB,YAAY,UAAwB;GAC7D,IAAI,MAAM,SAAS,QACjB,KAAK,WAAW;EAEpB,CAAC;EACD,KAAK,KAAK,QAAQ;CACpB;CAEQ,aAAmB;EACzB,MAAM,MAAM,KAAK,cAAc,IAAI,IAAI,KAAK,cAAc;EAC1D,KAAK,QAAQ,WAAW,KAAK;EAC7B,KAAK,QAAQ,YAAY,KAAK;EAC9B,KAAK,QAAQ,UAAU,KAAK,KAAK,KAAK,YAAY,GAAG;EACrD,K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|
|
3
|
+
/** Main-thread → processor message that ends the processor's lifetime. */
|
|
4
|
+
export declare const PCM_CAPTURE_STOP_MESSAGE: "stop";
|
|
5
|
+
/** Clamps a requested chunk size to whole frames within `[128, 16384]`. */
|
|
6
|
+
export declare function clampPcmChunkFrames(chunkFrames: number | undefined): number;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
// src/worklets/pcm-capture.ts
|
|
2
|
+
const PCM_CAPTURE_PROCESSOR_NAME = "avoid-pcm-capture";
|
|
3
|
+
const PCM_CAPTURE_DEFAULT_CHUNK_FRAMES = 2048;
|
|
4
|
+
/** Main-thread → processor message that ends the processor's lifetime. */
|
|
5
|
+
const PCM_CAPTURE_STOP_MESSAGE = "stop";
|
|
6
|
+
const PCM_CAPTURE_MIN_CHUNK_FRAMES = 128;
|
|
7
|
+
const PCM_CAPTURE_MAX_CHUNK_FRAMES = 16384;
|
|
8
|
+
/** Clamps a requested chunk size to whole frames within `[128, 16384]`. */
|
|
9
|
+
function clampPcmChunkFrames(chunkFrames) {
|
|
10
|
+
if (chunkFrames === void 0 || !Number.isFinite(chunkFrames)) return PCM_CAPTURE_DEFAULT_CHUNK_FRAMES;
|
|
11
|
+
return Math.max(PCM_CAPTURE_MIN_CHUNK_FRAMES, Math.min(PCM_CAPTURE_MAX_CHUNK_FRAMES, Math.round(chunkFrames)));
|
|
12
|
+
}
|
|
13
|
+
if (typeof registerProcessor === "function") registerProcessor(PCM_CAPTURE_PROCESSOR_NAME, class AvoidPcmCaptureProcessor extends AudioWorkletProcessor {
|
|
14
|
+
chunk;
|
|
15
|
+
writeIndex = 0;
|
|
16
|
+
stopped = false;
|
|
17
|
+
constructor(options) {
|
|
18
|
+
super(options);
|
|
19
|
+
this.chunk = new Float32Array(clampPcmChunkFrames(options?.processorOptions?.chunkFrames));
|
|
20
|
+
this.port.addEventListener("message", (event) => {
|
|
21
|
+
if (event.data === "stop") this.stopped = true;
|
|
22
|
+
});
|
|
23
|
+
if (typeof this.port.start === "function") this.port.start();
|
|
24
|
+
}
|
|
25
|
+
process(inputs) {
|
|
26
|
+
if (this.stopped) return false;
|
|
27
|
+
const [input] = inputs;
|
|
28
|
+
const first = input?.[0];
|
|
29
|
+
if (!input || !first || first.length === 0) return true;
|
|
30
|
+
const frames = first.length;
|
|
31
|
+
const channelCount = input.length;
|
|
32
|
+
const scale = 1 / channelCount;
|
|
33
|
+
const { chunk } = this;
|
|
34
|
+
const capacity = chunk.length;
|
|
35
|
+
let { writeIndex } = this;
|
|
36
|
+
for (let i = 0; i < frames; i += 1) {
|
|
37
|
+
let sum = 0;
|
|
38
|
+
for (let channel = 0; channel < channelCount; channel += 1) sum += input[channel]?.[i] ?? 0;
|
|
39
|
+
chunk[writeIndex] = sum * scale;
|
|
40
|
+
writeIndex += 1;
|
|
41
|
+
if (writeIndex === capacity) {
|
|
42
|
+
this.port.postMessage(chunk);
|
|
43
|
+
writeIndex = 0;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
this.writeIndex = writeIndex;
|
|
47
|
+
return true;
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
export { PCM_CAPTURE_DEFAULT_CHUNK_FRAMES, PCM_CAPTURE_PROCESSOR_NAME, PCM_CAPTURE_STOP_MESSAGE, clampPcmChunkFrames };
|
|
51
|
+
|
|
52
|
+
//# sourceMappingURL=pcm-capture.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pcm-capture.js","names":[],"sources":["../../src/worklets/pcm-capture.ts"],"sourcesContent":["// Standalone AudioWorkletProcessor that taps live audio as mono Float32 PCM\n// chunks for fingerprinting / analysis on the main thread.\n// Zero imports: compiles to a self-contained zero-import ESM file.\n\ninterface PcmCaptureNodeOptions {\n readonly processorOptions?: { readonly chunkFrames?: number };\n}\ndeclare function registerProcessor(\n name: string,\n processor: new (options?: PcmCaptureNodeOptions) => object\n): void;\ndeclare class AudioWorkletProcessor {\n readonly port: MessagePort;\n constructor(options?: PcmCaptureNodeOptions);\n}\n\nexport const PCM_CAPTURE_PROCESSOR_NAME = \"avoid-pcm-capture\" as const;\nexport const PCM_CAPTURE_DEFAULT_CHUNK_FRAMES = 2048;\n/** Main-thread → processor message that ends the processor's lifetime. */\nexport const PCM_CAPTURE_STOP_MESSAGE = \"stop\" as const;\nconst PCM_CAPTURE_MIN_CHUNK_FRAMES = 128;\nconst PCM_CAPTURE_MAX_CHUNK_FRAMES = 16_384;\n\n/** Clamps a requested chunk size to whole frames within `[128, 16384]`. */\nexport function clampPcmChunkFrames(chunkFrames: number | undefined): number {\n if (chunkFrames === undefined || !Number.isFinite(chunkFrames)) {\n return PCM_CAPTURE_DEFAULT_CHUNK_FRAMES;\n }\n return Math.max(\n PCM_CAPTURE_MIN_CHUNK_FRAMES,\n Math.min(PCM_CAPTURE_MAX_CHUNK_FRAMES, Math.round(chunkFrames))\n );\n}\n\nif (typeof registerProcessor === \"function\") {\n registerProcessor(\n PCM_CAPTURE_PROCESSOR_NAME,\n class AvoidPcmCaptureProcessor extends AudioWorkletProcessor {\n // Preallocated once: process() never allocates. postMessage structured-\n // clones the chunk, so the same buffer is safely reused for the next one.\n private readonly chunk: Float32Array;\n private writeIndex = 0;\n private stopped = false;\n\n constructor(options?: PcmCaptureNodeOptions) {\n super(options);\n this.chunk = new Float32Array(\n clampPcmChunkFrames(options?.processorOptions?.chunkFrames)\n );\n this.port.addEventListener(\"message\", (event: MessageEvent) => {\n if (event.data === PCM_CAPTURE_STOP_MESSAGE) {\n this.stopped = true;\n }\n });\n if (typeof this.port.start === \"function\") {\n this.port.start();\n }\n }\n\n process(inputs: Float32Array[][]): boolean {\n if (this.stopped) {\n // Returning false lets the engine release the processor once the\n // owning Scope has torn the capture down.\n return false;\n }\n const [input] = inputs;\n const first = input?.[0];\n if (!input || !first || first.length === 0) {\n // Inactive/disconnected input: keep the node alive, capture nothing.\n return true;\n }\n\n const frames = first.length;\n const channelCount = input.length;\n const scale = 1 / channelCount;\n const { chunk } = this;\n const capacity = chunk.length;\n let { writeIndex } = this;\n\n for (let i = 0; i < frames; i += 1) {\n let sum = 0;\n for (let channel = 0; channel < channelCount; channel += 1) {\n sum += input[channel]?.[i] ?? 0;\n }\n chunk[writeIndex] = sum * scale;\n writeIndex += 1;\n if (writeIndex === capacity) {\n // oxlint-disable-next-line unicorn/require-post-message-target-origin\n this.port.postMessage(chunk);\n writeIndex = 0;\n }\n }\n\n this.writeIndex = writeIndex;\n return true;\n }\n }\n );\n}\n"],"mappings":";AAgBA,MAAa,6BAA6B;AAC1C,MAAa,mCAAmC;;AAEhD,MAAa,2BAA2B;AACxC,MAAM,+BAA+B;AACrC,MAAM,+BAA+B;;AAGrC,SAAgB,oBAAoB,aAAyC;CAC3E,IAAI,gBAAgB,KAAA,KAAa,CAAC,OAAO,SAAS,WAAW,GAC3D,OAAO;CAET,OAAO,KAAK,IACV,8BACA,KAAK,IAAI,8BAA8B,KAAK,MAAM,WAAW,CAAC,CAChE;AACF;AAEA,IAAI,OAAO,sBAAsB,YAC/B,kBACE,4BACA,MAAM,iCAAiC,sBAAsB;CAG1C;CACT,aAAa;CACb,UAAU;CAElB,YAAY,SAAiC;EAC3C,MAAM,OAAO;EACb,KAAK,QAAQ,IAAI,aACf,oBAAoB,SAAS,kBAAkB,WAAW,CAC5D;EACA,KAAK,KAAK,iBAAiB,YAAY,UAAwB;GAC7D,IAAI,MAAM,SAAA,QACR,KAAK,UAAU;EAEnB,CAAC;EACD,IAAI,OAAO,KAAK,KAAK,UAAU,YAC7B,KAAK,KAAK,MAAM;CAEpB;CAEA,QAAQ,QAAmC;EACzC,IAAI,KAAK,SAGP,OAAO;EAET,MAAM,CAAC,SAAS;EAChB,MAAM,QAAQ,QAAQ;EACtB,IAAI,CAAC,SAAS,CAAC,SAAS,MAAM,WAAW,GAEvC,OAAO;EAGT,MAAM,SAAS,MAAM;EACrB,MAAM,eAAe,MAAM;EAC3B,MAAM,QAAQ,IAAI;EAClB,MAAM,EAAE,UAAU;EAClB,MAAM,WAAW,MAAM;EACvB,IAAI,EAAE,eAAe;EAErB,KAAK,IAAI,IAAI,GAAG,IAAI,QAAQ,KAAK,GAAG;GAClC,IAAI,MAAM;GACV,KAAK,IAAI,UAAU,GAAG,UAAU,cAAc,WAAW,GACvD,OAAO,MAAM,QAAQ,GAAG,MAAM;GAEhC,MAAM,cAAc,MAAM;GAC1B,cAAc;GACd,IAAI,eAAe,UAAU;IAE3B,KAAK,KAAK,YAAY,KAAK;IAC3B,aAAa;GACf;EACF;EAEA,KAAK,aAAa;EAClB,OAAO;CACT;AACF,CACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,116 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@avoid.quest/audio",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.1-beta.0",
|
|
4
|
+
"description": "Modular Web Audio, DSP plugin seam, queue state machine, live sync, audio recognition, MIDI, and standalone AudioWorklet primitives built on Effect v4.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"audio-queue",
|
|
7
|
+
"audio-recognition",
|
|
8
|
+
"audio-sync",
|
|
9
|
+
"audioworklet",
|
|
10
|
+
"dsp",
|
|
11
|
+
"effect",
|
|
12
|
+
"hls",
|
|
13
|
+
"midi",
|
|
14
|
+
"web-audio"
|
|
15
|
+
],
|
|
16
|
+
"homepage": "https://github.com/avoid-quest/kit/tree/main/packages/audio#readme",
|
|
17
|
+
"bugs": {
|
|
18
|
+
"url": "https://github.com/avoid-quest/kit/issues"
|
|
19
|
+
},
|
|
20
|
+
"license": "MIT",
|
|
21
|
+
"repository": {
|
|
22
|
+
"type": "git",
|
|
23
|
+
"url": "git+https://github.com/avoid-quest/kit.git",
|
|
24
|
+
"directory": "packages/audio"
|
|
25
|
+
},
|
|
26
|
+
"files": [
|
|
27
|
+
"dist",
|
|
28
|
+
"LICENSE",
|
|
29
|
+
"README.md"
|
|
30
|
+
],
|
|
31
|
+
"type": "module",
|
|
32
|
+
"sideEffects": [
|
|
33
|
+
"./dist/worklets/*.js"
|
|
34
|
+
],
|
|
35
|
+
"exports": {
|
|
36
|
+
".": {
|
|
37
|
+
"types": "./dist/index.d.ts",
|
|
38
|
+
"import": "./dist/index.js"
|
|
39
|
+
},
|
|
40
|
+
"./queue": {
|
|
41
|
+
"types": "./dist/queue/index.d.ts",
|
|
42
|
+
"import": "./dist/queue/index.js"
|
|
43
|
+
},
|
|
44
|
+
"./playback": {
|
|
45
|
+
"types": "./dist/playback/index.d.ts",
|
|
46
|
+
"import": "./dist/playback/index.js"
|
|
47
|
+
},
|
|
48
|
+
"./routing": {
|
|
49
|
+
"types": "./dist/routing/index.d.ts",
|
|
50
|
+
"import": "./dist/routing/index.js"
|
|
51
|
+
},
|
|
52
|
+
"./effects": {
|
|
53
|
+
"types": "./dist/effects/index.d.ts",
|
|
54
|
+
"import": "./dist/effects/index.js"
|
|
55
|
+
},
|
|
56
|
+
"./recognize": {
|
|
57
|
+
"types": "./dist/recognize/index.d.ts",
|
|
58
|
+
"import": "./dist/recognize/index.js"
|
|
59
|
+
},
|
|
60
|
+
"./sync": {
|
|
61
|
+
"types": "./dist/sync/index.d.ts",
|
|
62
|
+
"import": "./dist/sync/index.js"
|
|
63
|
+
},
|
|
64
|
+
"./midi": {
|
|
65
|
+
"types": "./dist/midi/index.d.ts",
|
|
66
|
+
"import": "./dist/midi/index.js"
|
|
67
|
+
},
|
|
68
|
+
"./worklets/couch-live": {
|
|
69
|
+
"types": "./dist/worklets/couch-live.d.ts",
|
|
70
|
+
"import": "./dist/worklets/couch-live.js"
|
|
71
|
+
},
|
|
72
|
+
"./worklets/couch-live.js": "./dist/worklets/couch-live.js",
|
|
73
|
+
"./worklets/meter": {
|
|
74
|
+
"types": "./dist/worklets/meter.d.ts",
|
|
75
|
+
"import": "./dist/worklets/meter.js"
|
|
76
|
+
},
|
|
77
|
+
"./worklets/meter.js": "./dist/worklets/meter.js",
|
|
78
|
+
"./worklets/pcm-capture": {
|
|
79
|
+
"types": "./dist/worklets/pcm-capture.d.ts",
|
|
80
|
+
"import": "./dist/worklets/pcm-capture.js"
|
|
81
|
+
},
|
|
82
|
+
"./worklets/pcm-capture.js": "./dist/worklets/pcm-capture.js"
|
|
83
|
+
},
|
|
84
|
+
"publishConfig": {
|
|
85
|
+
"access": "public"
|
|
86
|
+
},
|
|
87
|
+
"scripts": {
|
|
88
|
+
"build": "tsdown",
|
|
89
|
+
"dev": "tsdown --watch",
|
|
90
|
+
"typecheck": "tsc --noEmit && tsc -p tsconfig.test.json --noEmit",
|
|
91
|
+
"test": "bun test",
|
|
92
|
+
"verify": "bun ../../scripts/verify-pack.ts --exclude-entrypoints ./worklets/couch-live.js ./worklets/meter.js ./worklets/pcm-capture.js"
|
|
93
|
+
},
|
|
94
|
+
"dependencies": {
|
|
95
|
+
"fft.js": "^4.0.4"
|
|
96
|
+
},
|
|
97
|
+
"devDependencies": {
|
|
98
|
+
"@types/bun": "^1.4.5",
|
|
99
|
+
"effect": "^4.1.7",
|
|
100
|
+
"hls.js": "^1.7.4",
|
|
101
|
+
"tsdown": "^0.23.7",
|
|
102
|
+
"typescript": "^7.0.2"
|
|
103
|
+
},
|
|
104
|
+
"peerDependencies": {
|
|
105
|
+
"effect": "^4.1.0",
|
|
106
|
+
"hls.js": "^1.7.0"
|
|
107
|
+
},
|
|
108
|
+
"peerDependenciesMeta": {
|
|
109
|
+
"hls.js": {
|
|
110
|
+
"optional": true
|
|
111
|
+
}
|
|
112
|
+
},
|
|
113
|
+
"engines": {
|
|
114
|
+
"node": ">=22"
|
|
115
|
+
}
|
|
116
|
+
}
|