mirror of
https://github.com/SrIzan10/vdo.ninja.git
synced 2026-05-01 11:05:24 +00:00
25 lines
756 B
JavaScript
25 lines
756 B
JavaScript
class MeterProcessor extends AudioWorkletProcessor {
|
|
constructor() {
|
|
super();
|
|
this._rms = 0;
|
|
this._smoothingFactor = 0.980;
|
|
}
|
|
|
|
process(inputs, outputs, parameters) {
|
|
const input = inputs[0];
|
|
if (input.length > 0) {
|
|
const channelData = input[0];
|
|
let sum = 0;
|
|
for (let i = 0; i < channelData.length; ++i) {
|
|
sum += channelData[i] * channelData[i];
|
|
}
|
|
const rms = Math.sqrt(sum / channelData.length)*1.2;
|
|
this._rms = Math.max(rms, this._rms * this._smoothingFactor);
|
|
this.port.postMessage(this._rms);
|
|
}
|
|
return true;
|
|
}
|
|
}
|
|
|
|
registerProcessor('meter', MeterProcessor);
|