/ proof-of-concept / phase-perception-2
Sign in
proof-of-concept / phase-perception-2
phase-perception-2 / src / recorder-worklet.ts
19 lines · 546 BBlameHistoryRaw
1/** AudioWorklet processor that forwards raw input samples to the main thread. */
3declare function registerProcessor(name: string, ctor: unknown): void
4declare class AudioWorkletProcessor {
5 readonly port: MessagePort
6}
8class PcmRecorder extends AudioWorkletProcessor {
9 process(inputs: Float32Array[][]): boolean {
10 const ch = inputs[0]?.[0]
11 if (ch && ch.length > 0) {
12 const copy = new Float32Array(ch)
13 this.port.postMessage(copy, [copy.buffer])
14 }
15 return true
16 }
19registerProcessor('pcm-recorder', PcmRecorder)
↑↓ move↵openescclose