PageSourceSearch

https://vrew.ai/worklet/volume-processor.js

js vrew.ai collected 2026-10-02 05:04:05 UTC 696 bytes, 23 lines download raw bytes

1class VolumeProcessor extends AudioWorkletProcessor {
2  SMOOTHING_FACTOR = 0.95;
3  volume = 0;
4
5  process(inputs) {
6    const [left, right] = inputs[0];
7    const mixedSamples = !right
8      ? left
9      : right.map((each, idx) => (each + left[idx]) / 2);
10    if (mixedSamples !== undefined && mixedSamples.length !== 0) {
11      const squaredSum = mixedSamples.reduce(
12        (acc, sample) => acc + sample ** 2,
13        0,
14      );
15      const rms = Math.sqrt(squaredSum / mixedSamples.length);
16      this.volume = Math.max(rms, this.volume * this.SMOOTHING_FACTOR);
17      this.port.postMessage(this.volume);
18    }
19    return true;
20  }
21}
22
23registerProcessor('volume-processor', VolumeProcessor);

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.