Add audio test tab with test generator, test fader and output mutes

- switch the DSP's test generator (pink/white noise, sine 20 Hz-20 kHz, command 0x39)
- entering lowers all outputs to -50 dB before the generator starts; one test fader
  raises them together; mute buttons for every output
- presets cannot be stored, recalled, imported or exported while the test runs
- leaving switches the generator off first, then restores every output gain
- a DSP found playing a test signal on connect goes straight into the audio test;
  saved gains survive an app restart (config.json)
- simulator and memory-image support for the test signal

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
GivouandClaude Opus 5.5 committed 2026-11-01 21:33:01 +01:00
1 parent 61400df667
commit 66f988cf08
12 files changed
+280 -12

No files matched your search

+79 -6
View File
@@ -520,7 +520,7 @@ function renderTabs() {
title: paused ? t("Disconnected while demo mode is on") : d.demo ? t("Demo mode – simulated DSP") : `${d.name} · ${where(d)}`,
disabled: paused, onclick: () => { S.cur = id; S.settings = false; store.set("dsp.cur", id); render(); } },
h("span", { class: "dot " + d.status }), h("span", { class: "dn" }, d.name),
d.demo ? h("small", { class: "demo-badge" }, "DEMO") : model ? h("small", {}, model) : null);
testOn(d) ? h("small", { class: "test-badge" }, "TEST") : d.demo ? h("small", { class: "demo-badge" }, "DEMO") : model ? h("small", {}, model) : null);
}));
$("#btn-settings").classList.toggle("on", S.settings);
document.querySelectorAll("#viewtabs button").forEach(b => b.classList.toggle("active", !S.settings && b.dataset.view === S.view));
@@ -712,6 +712,8 @@ function renderStatus() {
const presetSel = h("select", { "aria-label": t("Recall preset") },
h("option", { value: "" }, t("Recall preset…")),
d.presets.map((p, i) => h("option", { value: i, disabled: !p }, `U${String(i + 1).padStart(2, "0")} ${p || "—"}`)));
const testing = testOn(d);
presetSel.disabled = testing;
presetSel.addEventListener("change", async () => {
if (presetSel.value === "") return;
const i = +presetSel.value;
@@ -724,8 +726,8 @@ function renderStatus() {
});
bar.replaceChildren(
h("div", { class: "preset" }, h("small", {}, d.demo ? t("Demo mode · simulated DSP") : `${d.info || d.name} · ${where(d)}`), h("b", {}, d.state.preset_name || "—")),
h("div", { class: "presetrow" }, presetSel, h("button", { onclick: () => storePresetDialog(d) }, t("Save")),
h("button", { onclick: () => presetFileDialog(d), title: t("Export / import preset"), "data-view-ok": "" }, t("File…"))));
h("div", { class: "presetrow" }, presetSel, h("button", { disabled: testing, title: testing ? t("Not possible during the audio test") : "", onclick: () => storePresetDialog(d) }, t("Save")),
h("button", { disabled: testing, onclick: () => presetFileDialog(d), title: testing ? t("Not possible during the audio test") : t("Export / import preset"), "data-view-ok": "" }, t("File…"))));
}
// ------------------------------------------------------------------ mixer
@@ -1396,6 +1398,68 @@ function viewLimiter(d) {
];
}
// ------------------------------------------------------------------ audio test (test generator of the DSP)
const testOn = d => !!(d && d.state && d.state.test && d.state.test.source);
const TEST_SRC = () => [[0, t("Analog input"), t("normal operation")], [1, t("Pink noise"), ""], [2, t("White noise"), ""], [3, t("Sine"), ""]];
const LVL_MIN = -60, LVL_MAX = 0; // test fader range in dB (all outputs at the same level)
async function setTestSignal(d, source, freq) {
try { await api("POST", `/api/devices/${d.id}/test`, { source, freq: freq ?? d.state.test.freq }); }
catch (e) { toast(t("Error: ") + trMsg(e.message)); }
}
// one request in flight at a time, always ending with the latest fader position
function sendTestLevel(d, db) {
sendTestLevel.next = db;
if (sendTestLevel.busy) return;
sendTestLevel.busy = true;
(async () => {
while (sendTestLevel.next != null) {
const v = sendTestLevel.next;
sendTestLevel.next = null;
try { await api("POST", `/api/devices/${d.id}/testlevel`, { db: v }); } catch (e) { toast(trMsg(e.message)); }
}
sendTestLevel.busy = false;
})();
}
function viewTest(d) {
const on = testOn(d), test = d.state.test;
const freqSel = h("select", { "aria-label": t("Sine frequency"), onchange: () => setTestSignal(d, 3, +freqSel.value) },
GEQ_FREQS.map((f, i) => h("option", { value: i, selected: i === test.freq }, f.endsWith("k") ? `${f.slice(0, -1)} kHz` : `${f} Hz`)));
const signalCard = h("div", { class: "card" },
h("h3", {}, t("Input signal")),
h("div", { class: "srcgrid" }, TEST_SRC().map(([v, label, sub]) =>
h("button", { class: "src" + (test.source === v ? " on" : "") + (v ? " noise" : ""), "aria-pressed": String(test.source === v),
onclick: () => test.source !== v && setTestSignal(d, v, v === 3 ? +freqSel.value : test.freq) },
h("b", {}, label), sub ? h("small", {}, sub) : null))),
h("label", { class: "row sinefreq" + (test.source === 3 ? "" : " dim") }, h("span", { class: "grow" }, t("Sine frequency")), freqSel),
h("p", { class: "info" }, t("The test signal replaces the analog inputs of the DSP. When it is switched on, all outputs are lowered to −50 dB first – raise them slowly with the test fader.")));
const lvl = d.test_level ?? -50;
const val = h("div", { class: "testval" }, on ? `${lvl.toFixed(1)} dB` : "—");
const f = fader({ min: 0, max: (LVL_MAX - LVL_MIN) * 2, value: Math.round((lvl - LVL_MIN) * 2), label: t("Test fader"),
ticks: [-60, -50, -40, -30, -20, -10, 0].map(db => [(db - LVL_MIN) * 2, String(db)]),
onInput: v => { const db = LVL_MIN + v / 2; d.test_level = db; val.textContent = `${db.toFixed(1)} dB`; sendTestLevel(d, db); } });
const outs = chans(d, "out").map((ch, i) => {
const m = h("div", { class: "tmeter" + (ch.mute ? " muted" : "") }, ledMeter(d.id, "out", i), h("small", {}, chLabel("out", i)), limLed(d.id, i));
m.append(toggleBtn("MUTE", "out", i, "mute", "mute small", v => m.classList.toggle("muted", v)));
return m;
});
const faderCard = h("div", { class: "card testfader" + (on ? "" : " off") },
h("h3", {}, t("Test fader"), h("span", { class: "info" }, t("all outputs"))),
h("div", { class: "testbody" }, h("div", { class: "tf" }, f, val), h("div", { class: "tmeters" }, outs)),
on ? h("button", { class: "danger-on wide", onclick: () => setTestSignal(d, 0) }, t("Stop test – back to the analog input")) : null,
h("p", { class: "info" }, on
? t("Saving and recalling presets is blocked during the test. Stopping it switches the noise off first and then puts every fader back where it was.")
: t("Choose a test signal above to start.")));
return [
on ? h("div", { class: "testbanner" }, t("Audio test running – the DSP plays {signal} instead of its inputs.", { signal: TEST_SRC()[test.source][1] })) : null,
h("div", { class: "cards testcards" }, signalCard, faderCard),
];
}
// ------------------------------------------------------------------ settings
function deviceForm(d) {
@@ -1616,7 +1680,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 }[S.view] || viewMixer)(d);
else content = ({ mixer: viewMixer, channel: viewChannel, routing: viewRouting, link: viewLink, 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);
@@ -1709,10 +1773,18 @@ function connectEvents() {
S.order.forEach(id => maybeAskUnlock(S.devices[id]));
if (!S.order.length) S.settings = true;
render(); break;
case "device":
case "device": {
if (!S.devices[ev.device]) S.order.push(ev.device);
const was = testOn(S.devices[ev.device]);
S.devices[ev.device] = ev.data;
if (!was && testOn(ev.data) && ev.device === S.cur && !S.settings) S.view = "test"; // e.g. DSP found playing noise
render(); break;
}
case "test": {
const d = S.devices[ev.device];
if (d && d.state) { d.state.test = ev.test; render(); }
break;
}
case "removed":
delete S.devices[ev.device]; S.order = S.order.filter(id => id !== ev.device);
render(); break;
@@ -1736,7 +1808,8 @@ function connectEvents() {
if (JSON.stringify(getPath(ch, ev.param)) === JSON.stringify(ev.value)) break;
setPath(ch, ev.param, ev.value);
showLive(`${ev.device}|${ev.kind}|${ev.idx}|${ev.param}`, ev.value); // even while a fader is held
if (ev.device === S.cur && !S.settings) render();
// the test fader moves every output: the audio test view only shows meters, no need to redraw
if (ev.device === S.cur && !S.settings && !(S.view === "test" && ev.param === "gain")) render();
break;
}
case "lock":