| 1 | // static/pcmWorkletProcessor.js |
| 2 | class PCMWorkletProcessor extends AudioWorkletProcessor { |
| 3 | process(inputs) { |
| 4 | const in32 = inputs[0][0]; |
| 5 | if (in32) { |
| 6 | // convert Float32 → Int16 in the worklet |
| 7 | const int16 = new Int16Array(in32.length); |
| 8 | for (let i = 0; i < in32.length; i++) { |
| 9 | let s = in32[i]; |
| 10 | s = s < -1 ? -1 : s > 1 ? 1 : s; |
| 11 | int16[i] = s < 0 ? s * 0x8000 : s * 0x7FFF; |
| 12 | } |
| 13 | // send raw ArrayBuffer, transferable |
| 14 | this.port.postMessage(int16.buffer, [int16.buffer]); |
| 15 | } |
| 16 | return true; |
| 17 | } |
| 18 | } |
| 19 | |
| 20 | registerProcessor('pcm-worklet-processor', PCMWorkletProcessor); |
nothing calls this directly
no outgoing calls
no test coverage detected