Skip to content

XP event5x XPListening, games, ratings, comments and chat earn five times the XP

leftLeaderboard

juicewrld-desktopsrc-tauriplugin-testtap-worklet.js

1.4.2Released Nov 21, 2026

tap-worklet.js

82 lines3.3 KBJavaScript
// The test page's tap: records its two inputs (the dry signal and the plugin node's output) side by side, sample for// sample, so the page can measure the latency between them; when asked, the wall-clock time of each render quantum,// which shows how Chromium renders in bursts (the ring's latency has to cover one); and a running check of every// sample for long runs ("verify"): the wet signal must be the dry one, `latency` frames later, times `gain`, exactly.// A quantum of silence where sound was due is a dropout, counted here from the samples themselves."use strict";registerProcessor(  "jw-tap",  class extends AudioWorkletProcessor {    constructor() {      super();      this.rec = null;      this.times = null;      this.port.onmessage = (e) => {        const m = e.data || {};        if (m.type === "record") this.rec = { n: m.frames, at: 0, dry: new Float32Array(m.frames), wet: new Float32Array(m.frames) };        if (m.type === "timing") this.times = { n: m.quanta, at: 0, t: new Float64Array(m.quanta) };        if (m.type === "verify") {          const size = 1 << Math.ceil(Math.log2(m.latency + 256));          this.check = { latency: m.latency, gain: m.gain, size, dry: new Float32Array(size), w: 0, quanta: 0, checked: 0, maxErr: 0, bad: 0, dropouts: 0, firstBad: -1 };        }        if (m.type === "report" && this.check) {          const c = this.check;          this.port.postMessage({ type: "report", quanta: c.quanta, checked: c.checked, seconds: (c.checked * 128) / sampleRate, maxErr: c.maxErr, badQuanta: c.bad, dropouts: c.dropouts, firstBad: c.firstBad });        }      };    }    process(inputs) {      const r = this.rec;      if (r) {        const dry = inputs[0] && inputs[0][0];        const wet = inputs[1] && inputs[1][0];        const n = Math.min(128, r.n - r.at);        if (dry) r.dry.set(dry.subarray(0, n), r.at);        if (wet) r.wet.set(wet.subarray(0, n), r.at);        r.at += n;        if (r.at >= r.n) {          this.port.postMessage({ type: "recorded", dry: r.dry, wet: r.wet }, [r.dry.buffer, r.wet.buffer]);          this.rec = null;        }      }      if (this.check) this.verify(inputs[0] && inputs[0][0], inputs[1] && inputs[1][0]);      const t = this.times;      if (t) {        t.t[t.at++] = Date.now();        if (t.at >= t.n) {          this.port.postMessage({ type: "timing", times: t.t }, [t.t.buffer]);          this.times = null;        }      }      return true;    }    verify(dry, wet) {      const c = this.check;      const mask = c.size - 1;      const q = c.quanta++;      if (!dry || !wet) return;      let err = 0;      let wetEnergy = 0;      let dueEnergy = 0;      const ready = q * 128 >= c.latency + 128;      for (let i = 0; i < 128; i++) {        const due = c.dry[(c.w + i - c.latency) & mask] * c.gain;        if (ready) {          err = Math.max(err, Math.abs(wet[i] - due));          wetEnergy += wet[i] * wet[i];          dueEnergy += due * due;        }      }      for (let i = 0; i < 128; i++) c.dry[(c.w + i) & mask] = dry[i];      c.w = (c.w + 128) & mask;      if (!ready) return;      c.checked++;      c.maxErr = Math.max(c.maxErr, err);      if (err > 1e-5) {        c.bad++;        if (c.firstBad < 0) c.firstBad = q;      }      if (wetEnergy === 0 && dueEnergy > 0) c.dropouts++;    }  },);