PageSourceSearch

https://www.covertiger.com/mic-capture-processor.js

js covertiger.com collected 2026-10-08 20:52:09 UTC 1,281 bytes, 49 lines download raw bytes

1// This AudioWorkletProcessor captures mic data and forwards it to the main thread
2// class MicCaptureProcessor extends AudioWorkletProcessor {
3//   constructor() {
4//     super();
5//   }
6
7//   process(inputs) {
8//     const input = inputs[0];
9//     if (input && input[0]) {
10//       // Send Float32Array of channel 0 samples
11//       this.port.postMessage(input[0]);
12//     }
13//     return true;
14//   }
15// }
16
17
18class MicCaptureProcessor extends AudioWorkletProcessor {
19  constructor() {
20    super();
21    this.directPort = null;
22    this.sampleRate = 48000;
23    
24    this.port.onmessage = (e) => {
25      if (e.data.type === 'setup-direct-channel') {
26        this.directPort = e.data.port;
27        this.sampleRate = e.data.sampleRate;
28        console.log('[WORKLET] Direct channel established');
29      }
30    };
31  }
32  
33  process(inputs, outputs) {
34    const input = inputs[0];
35    if (input && input[0] && this.directPort) {
36      const samples = new Float32Array(input[0]);
37      
38      // Send DIRECTLY to worker, bypassing main thread!
39      this.directPort.postMessage({
40        type: 'audio',
41        floats: samples,
42        sampleRate: this.sampleRate
43      }, [samples.buffer]);
44    }
45    return true;
46  }
47}
48
49registerProcessor('mic-capture-processor', MicCaptureProcessor); 

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.