// AudioWorklet processor: batches mono input samples into ~512-sample chunks // and posts them to the main thread. Outputs silence (it is connected to the // destination only so the graph keeps pulling audio through it). class CaptureProcessor extends AudioWorkletProcessor { constructor() { super(); this.buf = new Float32Array(512); this.n = 0; } process(inputs) { const ch = inputs[0] && inputs[0][0]; if (ch) { let i = 0; while (i < ch.length) { const take = Math.min(ch.length - i, this.buf.length - this.n); this.buf.set(ch.subarray(i, i + take), this.n); this.n += take; i += take; if (this.n === this.buf.length) { this.port.postMessage(this.buf.slice()); this.n = 0; } } } return true; } } registerProcessor('capture', CaptureProcessor);