aboutsummaryrefslogtreecommitdiff
path: root/client-web/public/assets/rnnoise/rnnoise-processor.js
blob: 72cf7365c9ce1fba1ba2b1eb88173c1da05f5a51 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
"use strict";
{
  let b, d;
  registerProcessor(
    "rnnoise",
    class extends AudioWorkletProcessor {
      constructor(a) {
        super({
          ...a,
          numberOfInputs: 1,
          numberOfOutputs: 1,
          outputChannelCount: [1],
        });
        b ||
          (d = new Float32Array(
            (b = new WebAssembly.Instance(a.processorOptions.module)
              .exports).memory.buffer
          ));
        this.state = b.newState();
        this.alive = !0;
        this.port.onmessage = ({ data: a }) => {
          this.alive &&
            (a
              ? this.port.postMessage({ vadProb: b.getVadProb(this.state) })
              : ((this.alive = !1), b.deleteState(this.state)));
        };
      }
      process(a, c, _e) {
        if (!a[0][0]) return 1
        if (this.alive)
          return (
            d.set(a[0][0], b.getInput(this.state) / 4),
            (a = c[0][0]),
            (c = b.pipe(this.state, a.length) / 4) &&
            a.set(d.subarray(c, c + a.length)),
            !0
          );
      }
    }
  );
}