class PCM16Processor extends AudioWorkletProcessor { constructor() { super(); this.buffer = new ArrayBuffer(3200); this.view = new DataView(this.buffer); this.offset = 0; } process(inputs) { const samples = inputs[0]?.[0]; if (!samples) return true; for (const sample of samples) { const value = Math.max(-1, Math.min(1, sample)); this.view.setInt16( this.offset * 2, value < 0 ? value * 32768 : value * 32767, true, ); if (++this.offset === 1600) { this.port.postMessage(this.buffer, [this.buffer]); this.buffer = new ArrayBuffer(3200); this.view = new DataView(this.buffer); this.offset = 0; } } return true; // Output stays silent; no microphone feedback to the speakers. } } registerProcessor("pcm16", PCM16Processor);