Add phase view, channel overlays and PEQ/GEQ master bypass

- EQ curve computed as complex response: PEQ biquads (now incl. all-pass),
  crossover filters from Butterworth/Bessel/Linkwitz-Riley prototypes
- Mag/Phase switch; phase wraps at +-180 degrees like the original software
- overlay any other channel of the device in the curve (e.g. sub/top crossover)
- EQ Bypass (0x3C) for all PEQ bands, GEQ Bypass (0x49) for the inputs,
  read from the bit masks at the end of the memory image; preset import aware

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
GivouandClaude Opus 5.5 committed 2026-11-01 21:47:15 +01:00
1 parent 66f988cf08
commit ae9a20fdf8
9 files changed
+215 -50

No files matched your search

+139 -40
View File
@@ -768,7 +768,14 @@ function viewMixer(d) {
// ------------------------------------------------------------------ filter response (for the PEQ curve)
const FS = 96000;
function biquadMag(type, f0, dbGain, q, f) {
// complex numbers as [re, im]
const cmul = (a, b) => [a[0] * b[0] - a[1] * b[1], a[0] * b[1] + a[1] * b[0]];
const cdiv = (a, b) => { const n = b[0] * b[0] + b[1] * b[1]; return [(a[0] * b[0] + a[1] * b[1]) / n, (a[1] * b[0] - a[0] * b[1]) / n]; };
const cdb = h => 10 * Math.log10(h[0] * h[0] + h[1] * h[1] || 1e-30);
const cdeg = h => Math.atan2(h[1], h[0]) * 180 / Math.PI;
// PEQ band as a digital biquad (RBJ cookbook), complex response at f
function biquadH(type, f0, dbGain, q, f) {
const A = Math.pow(10, dbGain / 40), w0 = 2 * Math.PI * f0 / FS, cs = Math.cos(w0), sn = Math.sin(w0);
const alpha = sn / (2 * q);
let b0, b1, b2, a0, a1, a2;
@@ -783,75 +790,155 @@ function biquadMag(type, f0, dbGain, q, f) {
case 4: b0 = (1 + cs) / 2; b1 = -(1 + cs); b2 = (1 + cs) / 2; a0 = 1 + alpha; a1 = -2 * cs; a2 = 1 - alpha; break;
case 5: { const k = Math.tan(w0 / 2); b0 = k; b1 = k; b2 = 0; a0 = 1 + k; a1 = k - 1; a2 = 0; break; }
case 6: b0 = (1 - cs) / 2; b1 = 1 - cs; b2 = (1 - cs) / 2; a0 = 1 + alpha; a1 = -2 * cs; a2 = 1 - alpha; break;
default: return 0;
case 7: { const k = Math.tan(w0 / 2), a = (k - 1) / (k + 1); b0 = a; b1 = 1; b2 = 0; a0 = 1; a1 = a; a2 = 0; break; } // allpass 1st order
case 8: b0 = 1 - alpha; b1 = -2 * cs; b2 = 1 + alpha; a0 = 1 + alpha; a1 = -2 * cs; a2 = 1 - alpha; break; // allpass 2nd order
default: return [1, 0];
}
const w = 2 * Math.PI * f / FS, c1 = Math.cos(w), s1 = Math.sin(w), c2 = Math.cos(2 * w), s2 = Math.sin(2 * w);
const nr = b0 + b1 * c1 + b2 * c2, ni = -(b1 * s1 + b2 * s2), dr = a0 + a1 * c1 + a2 * c2, di = -(a1 * s1 + a2 * s2);
return 10 * Math.log10((nr * nr + ni * ni) / (dr * dr + di * di));
return cdiv([b0 + b1 * c1 + b2 * c2, -(b1 * s1 + b2 * s2)], [a0 + a1 * c1 + a2 * c2, -(a1 * s1 + a2 * s2)]);
}
function xoverMag(filter, f, high) {
if (!filter.slope) return 0;
const name = SLOPES[filter.slope], order = parseInt(name.split("-")[1], 10) / 6, fc = freqHz(filter.freq);
const r = high ? fc / f : f / fc;
if (name.startsWith("LK")) return -20 * Math.log10(1 + Math.pow(r, order));
return -10 * Math.log10(1 + Math.pow(r, 2 * order));
// crossover filters from their analog prototypes (Butterworth, Bessel, Linkwitz-Riley = Butterworth squared)
function butterworth(n, s) {
let hh = [1, 0];
for (let k = 1; k <= n; k++) {
const a = (2 * k - 1) * Math.PI / (2 * n), p = [-Math.sin(a), Math.cos(a)];
hh = cmul(hh, cdiv([-p[0], -p[1]], [s[0] - p[0], s[1] - p[1]]));
}
return hh;
}
const besselCache = {};
function bessel(n, s) {
let b = besselCache[n];
if (!b) { // reverse Bessel polynomial, frequency scaled to −3 dB at 1
const fact = k => k < 2 ? 1 : k * fact(k - 1);
const a = Array.from({ length: n + 1 }, (_, k) => fact(2 * n - k) / (2 ** (n - k) * fact(k) * fact(n - k)));
const at = (sc, x) => { let den = [0, 0], pw = [1, 0]; const z = cmul(x, [sc, 0]); for (const c of a) { den = [den[0] + c * pw[0], den[1] + c * pw[1]]; pw = cmul(pw, z); } return cdiv([a[0], 0], den); };
let lo = 0.1, hi = 10;
for (let i = 0; i < 60; i++) { const m = (lo + hi) / 2; cdb(at(m, [0, 1])) > -3.0103 ? (lo = m) : (hi = m); }
b = besselCache[n] = x => at((lo + hi) / 2, x);
}
return b(s);
}
function xoverH(filter, f, high) {
if (!filter.slope) return [1, 0];
const [kind, db] = SLOPES[filter.slope].split(" -"), n = +db / 6, x = f / freqHz(filter.freq);
const s = high ? [0, -1 / x] : [0, x]; // high pass: s -> 1/s
if (kind === "LK") { const b = butterworth(n / 2, s); return cmul(b, b); }
return kind === "BL" ? bessel(n, s) : butterworth(n, s);
}
const bandH = (b, f) => biquadH(b.type, freqHz(b.freq), eqDb(b.gain), Q_TABLE[b.q], f);
function channelH(ch, f) {
let hh = cmul(xoverH(ch.hp, f, true), xoverH(ch.lp, f, false));
if (!ch.peq_bypass) for (const b of ch.peq) if (!b.bypass) hh = cmul(hh, bandH(b, f));
return hh;
}
const hasGain = type => type <= 2;
const hasQ = type => [0, 4, 6, 7, 8].includes(type);
const OUT_COLORS = ["#f97316", "#facc15", "#4ade80", "#e879f9", "#60a5fa", "#fb7185", "#2dd4bf", "#c084fc"];
const chColor = (kind, i) => kind === "in" ? IN_COLORS[i] : OUT_COLORS[i];
function drawCurve(canvas, ch, selBand) {
// opts: { mode: "mag" | "phase", overlays: [{ ch, color }] }
function drawCurve(canvas, ch, selBand, opts = canvas.curveOpts ? canvas.curveOpts() : {}) {
const dpr = window.devicePixelRatio || 1, W = canvas.clientWidth, H = canvas.clientHeight;
if (!W || !H) return null;
canvas.width = W * dpr; canvas.height = H * dpr;
const g = canvas.getContext("2d");
g.scale(dpr, dpr);
const phase = opts.mode === "phase";
const fx = f => Math.log(f / 20) / Math.log(1000) * W;
const dy = db => H / 2 - db / 15 * (H / 2 - 10);
const py = deg => H / 2 - deg / 180 * (H / 2 - 10);
g.font = "10px system-ui"; g.fillStyle = "#5b6673"; g.lineWidth = 1;
for (const f of [30, 50, 100, 200, 500, 1000, 2000, 5000, 10000]) {
g.strokeStyle = [100, 1000, 10000].includes(f) ? "#252d37" : "#1a2028";
g.beginPath(); g.moveTo(fx(f), 0); g.lineTo(fx(f), H); g.stroke();
g.fillText(f >= 1000 ? f / 1000 + "k" : f, fx(f) + 3, H - 4);
}
for (const db of [-12, -6, 0, 6, 12]) {
g.strokeStyle = db === 0 ? "#3a4552" : "#1a2028";
g.beginPath(); g.moveTo(0, dy(db)); g.lineTo(W, dy(db)); g.stroke();
g.fillText((db > 0 ? "+" : "") + db, 3, dy(db) - 3);
for (const v of phase ? [-180, -90, 0, 90, 180] : [-12, -6, 0, 6, 12]) {
const y = phase ? py(v) : dy(v);
g.strokeStyle = v === 0 ? "#3a4552" : "#1a2028";
g.beginPath(); g.moveTo(0, y); g.lineTo(W, y); g.stroke();
g.fillText((v > 0 ? "+" : "") + v + (phase ? "°" : ""), 3, y + (v === 180 ? 11 : -3));
}
const resp = f => {
let s = xoverMag(ch.hp, f, true) + xoverMag(ch.lp, f, false);
for (const b of ch.peq) if (!b.bypass) s += biquadMag(b.type, freqHz(b.freq), eqDb(b.gain), Q_TABLE[b.q], f);
return s;
const fAt = x => 20 * Math.pow(1000, x / W);
// a curve as polyline segments; the phase wraps at ±180°, so it is broken there instead of drawing a jump
const trace = hf => {
const segs = [[]];
let last = null;
for (let x = 0; x <= W; x += 2) {
const hh = hf(fAt(x));
if (phase) {
const deg = cdeg(hh);
if (last !== null && Math.abs(deg - last) > 180) segs.push([]);
last = deg;
segs[segs.length - 1].push([x, py(deg)]);
} else segs[0].push([x, clamp(dy(cdb(hh)), 0, H)]);
}
return segs;
};
// selected band's own contribution, filled
const stroke = (segs, color, width) => {
g.strokeStyle = color; g.lineWidth = width; g.lineJoin = "round";
for (const sg of segs) { g.beginPath(); sg.forEach(([x, y], i) => i ? g.lineTo(x, y) : g.moveTo(x, y)); g.stroke(); }
};
for (const o of opts.overlays || []) stroke(trace(f => channelH(o.ch, f)), o.color + "cc", 1.5);
const sb = ch.peq[selBand];
if (sb && !sb.bypass) {
if (!phase && sb && !sb.bypass && !ch.peq_bypass) { // selected band's own contribution, filled
g.beginPath(); g.moveTo(0, dy(0));
for (let x = 0; x <= W; x += 3) g.lineTo(x, clamp(dy(biquadMag(sb.type, freqHz(sb.freq), eqDb(sb.gain), Q_TABLE[sb.q], 20 * Math.pow(1000, x / W))), 0, H));
for (let x = 0; x <= W; x += 3) g.lineTo(x, clamp(dy(cdb(bandH(sb, fAt(x)))), 0, H));
g.lineTo(W, dy(0)); g.closePath(); g.fillStyle = "#f59e0b22"; g.fill();
}
const pts = [];
for (let x = 0; x <= W; x += 2) pts.push([x, clamp(dy(resp(20 * Math.pow(1000, x / W))), 0, H)]);
g.beginPath(); g.moveTo(0, H); pts.forEach(([x, y]) => g.lineTo(x, y)); g.lineTo(W, H); g.closePath();
const grad = g.createLinearGradient(0, 0, 0, H); grad.addColorStop(0, "#38bdf833"); grad.addColorStop(1, "#38bdf800");
g.fillStyle = grad; g.fill();
g.strokeStyle = "#38bdf8"; g.lineWidth = 2; g.beginPath();
pts.forEach(([x, y], i) => i ? g.lineTo(x, y) : g.moveTo(x, y));
g.stroke();
const segs = trace(f => channelH(ch, f));
if (!phase) {
g.beginPath(); g.moveTo(0, H); segs[0].forEach(([x, y]) => g.lineTo(x, y)); g.lineTo(W, H); g.closePath();
const grad = g.createLinearGradient(0, 0, 0, H); grad.addColorStop(0, "#38bdf833"); grad.addColorStop(1, "#38bdf800");
g.fillStyle = grad; g.fill();
}
stroke(segs, "#38bdf8", 2);
const off = !!ch.peq_bypass;
ch.peq.forEach((b, i) => {
const x = fx(freqHz(b.freq)), y = dy(hasGain(b.type) ? eqDb(b.gain) : 0);
const x = fx(freqHz(b.freq)), y = phase || !hasGain(b.type) ? dy(0) : dy(eqDb(b.gain));
g.beginPath(); g.arc(x, y, i === selBand ? 10 : 7, 0, 2 * Math.PI);
g.fillStyle = b.bypass ? "#2a333d" : i === selBand ? "#f59e0b" : "#38bdf8cc"; g.fill();
g.fillStyle = b.bypass ? "#6b7682" : "#0b0c0f"; g.font = "bold 10px system-ui"; g.textAlign = "center"; g.textBaseline = "middle";
g.fillStyle = b.bypass || off ? "#2a333d" : i === selBand ? "#f59e0b" : "#38bdf8cc"; g.fill();
g.fillStyle = b.bypass || off ? "#6b7682" : "#0b0c0f"; g.font = "bold 10px system-ui"; g.textAlign = "center"; g.textBaseline = "middle";
g.fillText(i + 1, x, y + 0.5); g.textAlign = "start"; g.textBaseline = "alphabetic";
});
return { fx, dy, W, H };
if (off) { // master bypass: written across the curve
g.font = "bold 34px system-ui"; g.textAlign = "center"; g.textBaseline = "middle"; g.fillStyle = "#ef444499";
g.fillText("BYPASS", W / 2, H / 3); g.textAlign = "start"; g.textBaseline = "alphabetic";
}
return { fx, dy, W, H, phase };
}
// other channels drawn into the curve (per device, remembered in the browser)
const overlayKey = d => "dsp.overlay." + d.id;
const overlaySet = d => new Set((store.get(overlayKey(d)) || "").split(",").filter(Boolean));
function overlayChips(d, kind, idx, onChange) {
const sel = overlaySet(d);
const all = [...chans(d, "in").map((_, i) => ["in", i]), ...chans(d, "out").map((_, i) => ["out", i])]
.filter(([k, i]) => !(k === kind && i === idx));
return h("div", { class: "chips overlay" }, h("span", { class: "sub" }, t("Overlay")),
all.map(([k, i]) => {
const key = `${k}${i}`, on = sel.has(key);
return h("button", { class: "chip ov" + (on ? " on" : ""), style: `--oc:${chColor(k, i)}`, "aria-pressed": String(on),
title: chTitle(d, k, i),
onclick: () => { on ? sel.delete(key) : sel.add(key); store.set(overlayKey(d), [...sel].join(",")); onChange(); } },
h("i", {}), chLabel(k, i));
}));
}
function overlaysFor(d, kind, idx) {
return [...overlaySet(d)].map(key => {
const k = key.startsWith("in") ? "in" : "out", i = +key.replace(/\D/g, "");
const list = chans(d, k);
return i < list.length && !(k === kind && i === idx) ? { ch: list[i], color: chColor(k, i) } : null;
}).filter(Boolean);
}
function peqCard(d, kind, idx) {
const ch = chans(d, kind)[idx];
S.band = Math.min(S.band, ch.peq.length - 1);
const canvas = h("canvas", { class: "curve", "aria-label": t("EQ curve – drag the points") });
canvas.curveOpts = () => ({ mode: store.get("dsp.curve") === "phase" ? "phase" : "mag", overlays: overlaysFor(dev(), kind, idx) });
const redraw = () => drawCurve(canvas, chans(dev(), kind)[idx], S.band);
const body = h("div", { class: "bandparams" });
const bandBtns = h("div", { class: "bands", role: "tablist" });
@@ -882,7 +969,7 @@ function peqCard(d, kind, idx) {
let best = -1, bd = 1600;
c.peq.forEach((b, i) => {
const dx = geo.fx(freqHz(b.freq)) - (e.clientX - r.left);
const dyy = geo.dy(hasGain(b.type) ? eqDb(b.gain) : 0) - (e.clientY - r.top);
const dyy = geo.dy(hasGain(b.type) && !geo.phase ? eqDb(b.gain) : 0) - (e.clientY - r.top);
if (dx * dx + dyy * dyy < bd) { bd = dx * dx + dyy * dyy; best = i; }
});
if (best < 0) return;
@@ -896,7 +983,7 @@ function peqCard(d, kind, idx) {
const x = clamp(e.clientX - r.left, 0, geo.W);
const f = hzFreq(20 * Math.pow(1000, x / geo.W));
if (f !== b.freq) setParam(kind, idx, `peq.${S.band}.freq`, f);
if (hasGain(b.type)) {
if (hasGain(b.type) && !geo.phase) { // the phase view only moves the frequency
const db = (geo.H / 2 - (e.clientY - r.top)) / (geo.H / 2 - 10) * 15;
let g = clamp(Math.round(db * 10 + 120), 0, 240);
g = detent(g, 120, 300, geo.H - 20, 8);
@@ -910,8 +997,16 @@ function peqCard(d, kind, idx) {
renderBand();
requestAnimationFrame(redraw);
new ResizeObserver(redraw).observe(canvas);
return h("div", { class: "card wide" },
h("h3", {}, h("span", { class: "grow" }, t("Parametric EQ")),
const modeSeg = h("div", { class: "seg small" });
const setMode = m => {
store.set("dsp.curve", m);
modeSeg.replaceChildren(...[["mag", "Mag"], ["phase", t("Phase")]].map(([k, label]) =>
h("button", { class: (store.get("dsp.curve") || "mag") === k ? "on" : "", "data-view-ok": "", onclick: () => { setMode(k); redraw(); } }, label)));
};
setMode(store.get("dsp.curve") || "mag");
const card = h("div", { class: "card wide" + (ch.peq_bypass ? " eq-off" : "") },
h("h3", {}, h("span", { class: "grow" }, t("Parametric EQ")), modeSeg,
toggleBtn("EQ Bypass", kind, idx, "peq_bypass", "small bypass", v => { card.classList.toggle("eq-off", v); renderBand(); redraw(); }),
h("button", { class: "small", onclick: async () => {
if (!await askConfirm(t("Reset EQ"), t("Set all PEQ bands of this channel to 0 dB and clear bypass?"), t("All flat"))) return;
chans(dev(), kind)[idx].peq.forEach((bb, i) => {
@@ -920,7 +1015,9 @@ function peqCard(d, kind, idx) {
});
renderBand(); redraw(); toast(t("All bands flat"));
} }, t("All flat"))),
canvas, h("p", { class: "info" }, t("Drag the points in the curve · gain snaps at 0 dB")), bandBtns, body);
canvas, overlayChips(d, kind, idx, redraw),
h("p", { class: "info" }, t("Drag the points in the curve · gain snaps at 0 dB")), bandBtns, body);
return card;
}
function geqCard(d, idx) {
@@ -934,14 +1031,16 @@ function geqCard(d, idx) {
faders.push([f, lbl]);
return h("div", { class: "gb" }, lbl, f, h("span", { class: "gf" }, GEQ_FREQS[b]));
});
const geqBox = h("div", { class: "geq" + (ch.geq_bypass ? " bypassed" : "") }, bands);
return h("div", { class: "card wide" },
h("h3", {}, h("span", { class: "grow" }, t("Graphic EQ · 31 bands")),
toggleBtn("GEQ Bypass", "in", idx, "geq_bypass", "small bypass", v => geqBox.classList.toggle("bypassed", v)),
h("button", { class: "small", onclick: async () => {
if (!await askConfirm(t("Reset GEQ"), t("Set all 31 bands to 0 dB?"), t("Reset"))) return;
chans(dev(), "in")[idx].geq.forEach((g, b) => { if (g !== 120) setParam("in", idx, `geq.${b}`, 120); });
faders.forEach(([f, l]) => { f.setValue(120); l.textContent = "0.0"; l.classList.remove("nz"); });
} }, t("All flat"))),
h("div", { class: "geq" }, bands),
geqBox,
h("p", { class: "info" }, t("Snaps at 0 dB · double-tap the knob = 0 dB")));
}