class FluidSynthBridge extends AudioWorkletProcessor { constructor() { super(); this.leftQ = []; this.rightQ = []; this.port.onmessage = (e) => { const d = e.data; if (d.type === 'PCM') { this.leftQ.push(d.L); this.rightQ.push(d.R); } }; } process(inputs, outputs) { const out = outputs[0]; if (!out) return true; const len = out[0].length; const l = this.leftQ; const r = this.rightQ; let ri = 0; for (let i = 0; i < len; i++) { if (ri >= l.length) { out[0][i] = 0; out[1][i] = 0; continue; } out[0][i] = l[ri]; out[1][i] = r[ri]; ri++; } if (ri > 0) { this.leftQ.splice(0, ri); this.rightQ.splice(0, ri); } return true; } } registerProcessor('fluidsynth-bridge', FluidSynthBridge);