Spaces:
Sleeping
Sleeping
| class PCMRecorderProcessor extends AudioWorkletProcessor { | |
| process(inputs) { | |
| const input = inputs[0]; | |
| if (!input || !input[0]) { | |
| return true; | |
| } | |
| const samples = input[0]; | |
| const pcm16 = new Int16Array(samples.length); | |
| for (let i = 0; i < samples.length; i += 1) { | |
| const value = Math.max(-1, Math.min(1, samples[i])); | |
| pcm16[i] = value < 0 ? value * 32768 : value * 32767; | |
| } | |
| this.port.postMessage(pcm16.buffer, [pcm16.buffer]); | |
| return true; | |
| } | |
| } | |
| registerProcessor("pcm-recorder", PCMRecorderProcessor); | |