jenkins af45190bfb bstein: serve the phone sound source and 30-minute RCT microphone detector
Vendor the web assets from Lesavka a5758755. The RCT browser performs signal recognition and sends numeric observations through the existing receipt service.
2026-12-03 12:11:53 -06:00

36 lines
1.3 KiB
JavaScript

import {AcousticDetector} from './acoustic-detector.js';
class AcousticProbe extends AudioWorkletProcessor {
constructor() {
super();
this.detector = new AcousticDetector(sampleRate);
this.next = currentFrame;
this.deadline = currentFrame + sampleRate * 35 * 60;
this.ack = currentFrame;
this.credit = true;
this.stopped = false;
this.port.onmessage = ({data}) => {
if (data === 'stop') this.stopped = true;
if (data === 'ack') { this.credit = true; this.ack = currentFrame; }
};
}
process(inputs, outputs) {
if (this.stopped) return false;
if (currentFrame >= this.deadline || currentFrame - this.ack > 10 * sampleRate) {
this.port.postMessage({expired:true});
return false;
}
const size = outputs[0][0].length;
this.detector.process(inputs[0]?.[0], currentFrame, size);
if (this.credit && currentFrame >= this.next) {
const sample = this.detector.summary((currentFrame + size) * 1000 / sampleRate);
this.port.postMessage(sample);
if (sample.complete) return false;
this.next = currentFrame + sampleRate;
this.credit = false;
}
return true;
}
}
registerProcessor('acoustic-probe', AcousticProbe);