MCPcopy Create free account
hub / github.com/KoljaB/RealtimeVoiceChat / PCMWorkletProcessor

Class PCMWorkletProcessor

code/static/pcmWorkletProcessor.js:2–18  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1// static/pcmWorkletProcessor.js
2class 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
20registerProcessor('pcm-worklet-processor', PCMWorkletProcessor);

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected