FIR DSP 408: own memory layout and FIR tab (filters, coefficient files, tap budget)
Layout and commands derived from the behaviour of its control software, tested against the simulator only. No GEQ on this model; dynamic EQs are left untouched. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
f7d5e22bb0
commit
5597fae3f3
13 files changed
+622
-35
No files matched your search
+173
-9
@@ -58,7 +58,7 @@ const S = {
|
||||
devices: {}, order: [], cur: store.get("dsp.cur"),
|
||||
view: store.get("dsp.view") || "mixer", settings: false,
|
||||
sel: { kind: "in", idx: 0 }, band: 0, busy: false, dirty: false,
|
||||
routeOpen: null, es: null, linkSel: { in: [], out: [] }, linkEdit: { in: null, out: null },
|
||||
routeOpen: null, es: null, linkSel: { in: [], out: [] }, linkEdit: { in: null, out: null }, firSel: { kind: "out", idx: 0 }, firDraft: null, firCoef: {},
|
||||
lim: { amps: [], assign: {}, ref: {} },
|
||||
demo: { enabled: false, model: "408" },
|
||||
muteAll: false,
|
||||
@@ -625,6 +625,7 @@ function renderTabs() {
|
||||
$("#btn-settings").classList.toggle("on", S.settings);
|
||||
$("#btn-settings").disabled = testLock;
|
||||
document.querySelectorAll("#viewtabs button").forEach(b => {
|
||||
if (b.dataset.view === "fir") b.hidden = !(dev() && dev().fir);
|
||||
b.classList.toggle("active", !S.settings && b.dataset.view === S.view);
|
||||
b.disabled = testLock && b.dataset.view !== "test";
|
||||
});
|
||||
@@ -938,6 +939,156 @@ function viewMixer(d) {
|
||||
h("p", { class: "info hint" }, t("Drag a fader by its knob · snaps at 0 dB · double-tap the knob = 0 dB · tap the dB value to type one · tap the name = edit channel"))];
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------ FIR filters (FIR DSP 408)
|
||||
|
||||
const FIR_TYPES = () => [t("Bypass"), t("Low-pass"), t("High-pass"), t("Band-pass"), t("From file")];
|
||||
const FIR_WINDOWS = ["Rectangle", "Bartlett", "Hanning", "Hamming", "Blackman", "Sine", "Sinc", "Nuttall", "Kaiser", "Blackman-Nuttall", "Blackman-Harris"];
|
||||
const firTapCount = i => 256 + 32 * i;
|
||||
const firKey = (d, kind, i) => `${d.id}|${kind}${i}`;
|
||||
const firMax = kind => (kind === "in" ? 2048 : 1024);
|
||||
function firTapsOf(ch) { const f = ch.fir; return "type" in f ? (f.type ? firTapCount(f.taps) : 0) : (f.bypass ? 0 : f.taps); }
|
||||
const firUsed = d => [...chans(d, "in"), ...chans(d, "out")].reduce((s, ch) => s + firTapsOf(ch), 0);
|
||||
|
||||
function firWindow(kind, n, N) {
|
||||
const x = N > 1 ? n / (N - 1) : 0, c = k => Math.cos(2 * Math.PI * k * x);
|
||||
const sum = a => a.reduce((s, v, k) => s + (k % 2 ? -v : v) * c(k), 0);
|
||||
switch (kind) {
|
||||
case 1: return 1 - Math.abs(2 * x - 1);
|
||||
case 2: return 0.5 - 0.5 * c(1);
|
||||
case 3: return 0.54 - 0.46 * c(1);
|
||||
case 4: return sum([0.42, 0.5, 0.08]);
|
||||
case 5: return Math.sin(Math.PI * x);
|
||||
case 6: { const u = 2 * x - 1; return u ? Math.sin(Math.PI * u) / (Math.PI * u) : 1; }
|
||||
case 7: return sum([0.355768, 0.487396, 0.144232, 0.012604]);
|
||||
case 8: { const i0 = v => { let s = 1, e = 1; for (let k = 1; k < 30; k++) { e *= (v / (2 * k)) ** 2; s += e; } return s; };
|
||||
const u = 2 * x - 1; return i0(8.6 * Math.sqrt(Math.max(0, 1 - u * u))) / i0(8.6); }
|
||||
case 9: return sum([0.3635819, 0.4891775, 0.1365995, 0.0106411]);
|
||||
case 10: return sum([0.35875, 0.48829, 0.14128, 0.01168]);
|
||||
default: return 1;
|
||||
}
|
||||
}
|
||||
// windowed sinc, only for the preview: the DSP calculates the filter itself from type, window, cut-offs and taps
|
||||
function firDesign(f) {
|
||||
const N = firTapCount(f.taps), M = (N - 1) / 2, lp = c => n => { const v = n - M, w = 2 * c / FS; return v ? Math.sin(Math.PI * w * v) / (Math.PI * v) : w; };
|
||||
const lo = lp(f.low), hi = lp(f.high), out = new Float64Array(N);
|
||||
for (let n = 0; n < N; n++) {
|
||||
const ideal = f.type === 1 ? hi(n) : f.type === 2 ? (n === M ? 1 : 0) - lo(n) : hi(n) - lo(n);
|
||||
out[n] = ideal * firWindow(f.window, n, N);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
function firResponseDb(h, hz) {
|
||||
const w = -2 * Math.PI * hz / FS; let re = 0, im = 0;
|
||||
for (let n = 0; n < h.length; n++) { re += h[n] * Math.cos(w * n); im += h[n] * Math.sin(w * n); }
|
||||
return 10 * Math.log10(re * re + im * im || 1e-12);
|
||||
}
|
||||
function drawFir(canvas, h) {
|
||||
const dpr = window.devicePixelRatio || 1, W = canvas.clientWidth, H = canvas.clientHeight;
|
||||
if (!W || !H) return;
|
||||
canvas.width = W * dpr; canvas.height = H * dpr;
|
||||
const c = canvas.getContext("2d"); c.scale(dpr, dpr);
|
||||
const x = hz => W * Math.log(hz / 20) / Math.log(1000), y = db => H * (6 - db) / 86;
|
||||
c.font = "10px sans-serif"; c.lineWidth = 1;
|
||||
for (const hz of [20, 50, 100, 200, 500, 1000, 2000, 5000, 10000, 20000]) {
|
||||
c.strokeStyle = "#2a303a"; c.beginPath(); c.moveTo(x(hz), 0); c.lineTo(x(hz), H); c.stroke();
|
||||
c.fillStyle = "#7b8594"; c.fillText(hz >= 1000 ? hz / 1000 + "k" : hz, Math.min(x(hz) + 3, W - 22), H - 4);
|
||||
}
|
||||
for (const db of [0, -20, -40, -60]) {
|
||||
c.strokeStyle = db ? "#2a303a" : "#46505e"; c.beginPath(); c.moveTo(0, y(db)); c.lineTo(W, y(db)); c.stroke();
|
||||
c.fillStyle = "#7b8594"; c.fillText(db + " dB", 3, y(db) - 3);
|
||||
}
|
||||
if (!h) return;
|
||||
c.strokeStyle = "#38bdf8"; c.lineWidth = 2; c.beginPath();
|
||||
for (let px = 0; px <= W; px += 2) {
|
||||
const py = y(Math.max(-80, firResponseDb(h, 20 * 1000 ** (px / W))));
|
||||
px ? c.lineTo(px, py) : c.moveTo(px, py);
|
||||
}
|
||||
c.stroke();
|
||||
}
|
||||
|
||||
function parseFirFile(text) {
|
||||
const parts = text.split(/[\s,;]+/).filter(Boolean);
|
||||
const values = parts.map(Number);
|
||||
if (!values.length || values.some(v => !Number.isFinite(v))) throw new Error(t("This is not a list of FIR coefficients"));
|
||||
return values;
|
||||
}
|
||||
|
||||
async function importFir(d, kind, i) {
|
||||
let f;
|
||||
try { f = await openFile(".txt,.csv,text/plain,text/csv"); } catch (e) { return toast(trMsg(e.message)); }
|
||||
if (!f) return;
|
||||
let coeffs;
|
||||
try { coeffs = parseFirFile(atob(f.b64)); } catch (e) { return toast(e.message); }
|
||||
if (coeffs.length > firMax(kind)) return toast(t("Too many coefficients: {n}, at most {max} here", { n: coeffs.length, max: firMax(kind) }));
|
||||
const name = cleanName(f.name.replace(/\.[^.]*$/, "")).trim().slice(0, 8);
|
||||
if (!await askConfirm(t("Load FIR filter"), t("Send {n} coefficients from {file} to {ch}? This changes the sound immediately – keep the amplifiers low.",
|
||||
{ n: coeffs.length, file: f.name, ch: chTitle(d, kind, i) }), t("Send"))) return;
|
||||
S.firBusy = true; render();
|
||||
try {
|
||||
await api("POST", `/api/devices/${d.id}/fir`, { kind, idx: i, coeffs, name });
|
||||
S.firCoef[firKey(d, kind, i)] = Float64Array.from(coeffs);
|
||||
toast(t("FIR filter loaded"));
|
||||
} catch (e) { toast(t("Error: ") + trMsg(e.message)); }
|
||||
S.firBusy = false; S.firDraft = null; render();
|
||||
}
|
||||
|
||||
function viewFir(d) {
|
||||
if (S.firSel.idx >= chans(d, S.firSel.kind).length) S.firSel = { kind: "out", idx: 0 };
|
||||
const { kind, idx } = S.firSel, ch = chans(d, kind)[idx], key = firKey(d, kind, idx), isOut = kind === "out";
|
||||
const used = firUsed(d), loaded = S.firCoef[key];
|
||||
const canvas = h("canvas", { class: "fircurve" });
|
||||
const pick = (k, i) => { S.firSel = { kind: k, idx: i }; S.firDraft = null; render(); };
|
||||
const chip = (k, i) => h("button", { class: "firch" + (k === kind && i === idx ? " on" : "") + (firTapsOf(chans(d, k)[i]) ? " used" : ""), "data-view-ok": "", onclick: () => pick(k, i) },
|
||||
h("b", {}, chLabel(k, i)), h("small", {}, firTapsOf(chans(d, k)[i]) ? `${firTapsOf(chans(d, k)[i])} ${t("taps")}` : t("off")));
|
||||
const picker = h("div", { class: "card wide" }, h("h3", {}, h("span", { class: "grow" }, t("FIR filters")),
|
||||
h("span", { class: "firuse" + (used > 4096 ? " over" : "") }, t("{used} of 4096 taps in use", { used }))),
|
||||
h("div", { class: "firmeter" }, h("span", { style: `width:${Math.min(100, used / 40.96)}%` })),
|
||||
h("div", { class: "firchs" }, chans(d, "in").map((_, i) => chip("in", i)), h("span", { class: "firsep" }), chans(d, "out").map((_, i) => chip("out", i))));
|
||||
|
||||
let settings, preview = null, note = "";
|
||||
if (isOut) {
|
||||
if (!S.firDraft || S.firDraft.key !== key) S.firDraft = { key, ...ch.fir };
|
||||
const f = S.firDraft, external = f.type === 4, changed = ["type", "window", "low", "high", "taps"].some(k => f[k] !== ch.fir[k]);
|
||||
const others = used - firTapsOf(ch), needed = f.type ? firTapCount(f.taps) : 0, over = others + needed > 4096;
|
||||
const set = (k, v) => { f[k] = v; render(); };
|
||||
const select = (label, k, items) => h("label", {}, label, h("select", { onchange: e => set(k, +e.target.value) },
|
||||
items.map((o, i) => h("option", { value: i, selected: f[k] === i }, o))));
|
||||
const hz = (label, k) => h("label", {}, label, h("input", { type: "number", min: 150, max: 20000, value: f[k],
|
||||
onchange: e => set(k, clamp(Math.round(+e.target.value) || f[k], 150, 20000)) }));
|
||||
settings = h("div", { class: "card" }, h("h3", {}, chTitle(d, kind, idx)),
|
||||
h("div", { class: "form firform" },
|
||||
select(t("Type"), "type", FIR_TYPES()),
|
||||
f.type && !external ? select(t("Window"), "window", FIR_WINDOWS) : null,
|
||||
f.type && !external ? select(t("Taps"), "taps", Array.from({ length: 25 }, (_, i) => String(firTapCount(i)))) : null,
|
||||
f.type === 2 || f.type === 3 ? hz(t("Low cut (Hz)"), "low") : null,
|
||||
f.type === 1 || f.type === 3 ? hz(t("High cut (Hz)"), "high") : null),
|
||||
f.type === 3 && f.low >= f.high ? h("p", { class: "err" }, t("The low cut must be below the high cut.")) : null,
|
||||
over ? h("p", { class: "err" }, t("Not enough taps left: {free} free, this needs {need}.", { free: 4096 - others, need: needed })) : null,
|
||||
f.type && !external && needed > 512 ? h("p", { class: "info" }, t("More than 512 taps add noticeable delay (over 10 ms at 1024).")) : null,
|
||||
external
|
||||
? [h("p", { class: "info" }, ch.fir.type === 4 && ch.fir.name ? t("Loaded: {name}", { name: ch.fir.name }) : t("Choose a file with up to {max} coefficients (txt or csv).", { max: 1024 })),
|
||||
h("div", { class: "row" }, h("button", { class: "on", disabled: S.firBusy, onclick: () => importFir(d, kind, idx) }, S.firBusy ? t("Sending…") : t("Load file…")))]
|
||||
: h("div", { class: "row lkactions" }, h("button", { class: "on", disabled: !changed || over || (f.type === 3 && f.low >= f.high), onclick: () => {
|
||||
setParam(kind, idx, "fir", { type: f.type, window: f.window, low: f.low, high: f.high, taps: f.taps, name: ch.fir.name }); toast(t("FIR filter set")); render();
|
||||
} }, t("Apply")), changed ? h("button", { onclick: () => { S.firDraft = null; render(); } }, t("Cancel")) : null));
|
||||
if (external) { preview = loaded; note = loaded ? "" : t("The DSP can't send coefficients back, so the curve only appears after loading a file here."); }
|
||||
else if (f.type) { preview = firDesign(f); note = t("Calculated by this app – the DSP calculates the filter itself, so details can differ."); }
|
||||
else note = t("Filter is off.");
|
||||
} else {
|
||||
settings = h("div", { class: "card" }, h("h3", {}, chTitle(d, kind, idx)),
|
||||
h("p", { class: "info" }, ch.fir.taps ? t("Loaded: {name} ({n} taps)", { name: ch.fir.name || "–", n: ch.fir.taps }) : t("Inputs only take filters from a file: up to {max} coefficients (txt or csv).", { max: 2048 })),
|
||||
h("div", { class: "row lkactions" },
|
||||
h("button", { class: "on", disabled: S.firBusy, onclick: () => importFir(d, kind, idx) }, S.firBusy ? t("Sending…") : t("Load file…")),
|
||||
ch.fir.taps ? toggleBtn("Bypass", kind, idx, "fir.bypass", "bypass", () => render()) : null),
|
||||
ch.fir.taps > 512 ? h("p", { class: "info" }, t("More than 512 taps add noticeable delay (over 10 ms at 1024).")) : null);
|
||||
preview = ch.fir.bypass ? null : loaded;
|
||||
note = ch.fir.bypass ? t("Filter is off.") : loaded ? "" : t("The DSP can't send coefficients back, so the curve only appears after loading a file here.");
|
||||
}
|
||||
requestAnimationFrame(() => drawFir(canvas, preview));
|
||||
return h("div", { class: "cards" }, picker, settings,
|
||||
h("div", { class: "card" }, h("h3", {}, t("Frequency response")), canvas, note ? h("p", { class: "info" }, note) : null));
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------ filter response (for the PEQ curve)
|
||||
|
||||
const FS = 96000;
|
||||
@@ -994,7 +1145,7 @@ function bessel(n, s) {
|
||||
return b(s);
|
||||
}
|
||||
function xoverH(filter, f, high) {
|
||||
if (!filter.slope) return [1, 0];
|
||||
if (!filter || !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); }
|
||||
@@ -1204,7 +1355,7 @@ function peqCard(d, kind, idx) {
|
||||
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(); }),
|
||||
d.fir ? null : 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) => {
|
||||
@@ -1294,11 +1445,24 @@ function viewChannel(d) {
|
||||
const xo = (title, key) => h("div", { class: "xo" },
|
||||
h("div", { class: "row" }, h("span", { class: "sub" }, title), paramSelect(k, i, key + ".slope", SLOPES, () => { redrawPeq(); render(); }, title)),
|
||||
chans(d, k)[i][key].slope ? paramSlider(t("Frequency"), k, i, key + ".freq", "freq", redrawPeq) : h("p", { class: "info off" }, t("Off (bypass)")));
|
||||
const xover = h("div", { class: "card" }, h("h3", {}, t("High- / low-pass")),
|
||||
xo(t("High-pass"), "hp"), xo(t("Low-pass"), "lp"));
|
||||
const xover = ch.hp ? h("div", { class: "card" }, h("h3", {}, t("High- / low-pass")),
|
||||
xo(t("High-pass"), "hp"), xo(t("Low-pass"), "lp")) : null;
|
||||
|
||||
const cards = [basics, xover];
|
||||
if (k === "in") {
|
||||
const cards = [basics, xover].filter(Boolean);
|
||||
const dynCard = (title, key, thresh) => h("div", { class: "card" }, h("h3", {}, title),
|
||||
paramSlider("Threshold", k, i, key + ".threshold", thresh),
|
||||
paramSlider("Ratio", k, i, key + ".ratio", "ratio"),
|
||||
paramSlider("Attack", k, i, key + ".attack", "attack"),
|
||||
paramSlider("Release", k, i, key + ".release", "release"),
|
||||
paramSlider("Knee", k, i, key + ".knee", "knee"));
|
||||
if (d.fir && k === "in") {
|
||||
cards.push(h("div", { class: "card" }, h("h3", {}, "Noise Gate"),
|
||||
paramSlider("Threshold", k, i, "gate.threshold", "gthresh"),
|
||||
paramSlider("Attack", k, i, "gate.attack", "attack"),
|
||||
paramSlider("Hold", k, i, "gate.hold", "hold"),
|
||||
paramSlider("Release", k, i, "gate.release", "release")));
|
||||
cards.push(dynCard(t("Compressor"), "comp", "thresh"), peqCard(d, k, i));
|
||||
} else if (k === "in") {
|
||||
cards.push(h("div", { class: "card" }, h("h3", {}, "Noise Gate"),
|
||||
paramSlider("Threshold", k, i, "gate.threshold", "gthresh"),
|
||||
paramSlider("Attack", k, i, "gate.attack", "attack"),
|
||||
@@ -1307,7 +1471,7 @@ function viewChannel(d) {
|
||||
cards.push(peqCard(d, k, i), geqCard(d, i));
|
||||
} else {
|
||||
cards.push(routingCard(d, i), peqCard(d, k, i));
|
||||
cards.push(h("div", { class: "card" }, h("h3", {}, t("Compressor")),
|
||||
if (ch.comp) cards.push(h("div", { class: "card" }, h("h3", {}, t("Compressor")),
|
||||
paramSlider("Threshold", k, i, "comp.threshold", "thresh"),
|
||||
paramSlider("Ratio", k, i, "comp.ratio", "ratio"),
|
||||
paramSlider("Attack", k, i, "comp.attack", "attack"),
|
||||
@@ -2271,7 +2435,7 @@ function render() {
|
||||
: d.status === "locked" ? h("div", {}, h("p", {}, t("This DSP is locked with a code.")),
|
||||
h("button", { class: "on", onclick: () => unlockDialog(d) }, t("Enter code")))
|
||||
: S.demo.enabled && !d.demo ? t("Disconnected while demo mode is on") : t("Not connected."));
|
||||
else content = ({ mixer: viewMixer, channel: viewChannel, routing: viewRouting, link: viewLink, limiter: viewLimiter, test: viewTest }[S.view] || viewMixer)(d);
|
||||
else content = ({ mixer: viewMixer, channel: viewChannel, routing: viewRouting, link: viewLink, fir: d.fir ? viewFir : viewMixer, limiter: viewLimiter, test: viewTest }[S.view] || viewMixer)(d);
|
||||
main.replaceChildren(...[content].flat().filter(Boolean));
|
||||
main.querySelectorAll(H_SCROLL).forEach((e, i) => { if (xs[i]) e.scrollLeft = xs[i]; });
|
||||
window.scrollTo(0, y);
|
||||
|
||||
Reference in new issue
Block a user