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

+16 -1
View File
@@ -25,6 +25,7 @@ CMD_PRESET_NAME = 0x29
CMD_PRESET_COUNT = 0x2C # answer: [time lock][4 bytes time lock data][device lock] (see device_locked)
CMD_UNLOCK = 0x2D # [0][code 4] -> answer [0][1 = unlocked, 0 = wrong code]
CMD_SET_LOCK_CODE = 0x2F # [code 4]
CMD_TEST_SIGNAL = 0x39 # [source][freq index]: 0 = analog input, 1 = pink noise, 2 = white noise, 3 = sine
CMD_METER = 0x40
# Parameter commands
@@ -45,6 +46,7 @@ CMD_GEQ = 0x48
CMD_LINK = 0x3B # [ch][u16 link mask], see link_masks()
CHUNK_SIZE = 50
TEST_SOURCES = ("analog", "pink", "white", "sine")
LOCK_CODE = re.compile(r"[A-Z0-9]{4}") # device lock code: 4 characters, digits and upper-case letters
@@ -222,6 +224,11 @@ class Model:
def globals_base(self) -> int:
return self.out_base + self.n_out * self.out_size
@property
def test_base(self) -> int:
"""Test signal (source, sine frequency index), after the mute masks and one word per channel."""
return self.globals_base + 4 + 2 * self.n_in + 2 * self.n_out
@property
def size(self) -> int:
return self.globals_base + 4 + 2 * self.n_in + 2 * self.n_out + 12
@@ -315,7 +322,9 @@ def parse_state(model: Model, buf: bytes) -> dict:
"link": u16(p + 84),
"mute": bool(out_mute >> i & 1),
})
return {"preset_name": _name(buf[2:16]), "inputs": inputs, "outputs": outputs}
source, freq = struct.unpack_from("<HH", buf, model.test_base)
test = {"source": source if source < len(TEST_SOURCES) else 0, "freq": freq if freq < 31 else 0}
return {"preset_name": _name(buf[2:16]), "inputs": inputs, "outputs": outputs, "test": test}
def build_state_buffer(model: Model, state: dict) -> bytearray:
@@ -359,6 +368,8 @@ def build_state_buffer(model: Model, state: dict) -> bytearray:
struct.pack_into("<4H", buf, p + 78, ch["gain"], int(ch["polarity"]), ch["delay"], ch.get("link", 1 << i))
out_mute |= int(ch["mute"]) << i
struct.pack_into("<HH", buf, model.globals_base, in_mute, out_mute)
test = state.get("test") or {}
struct.pack_into("<HH", buf, model.test_base, test.get("source", 0), test.get("freq", 0))
return buf
@@ -380,6 +391,7 @@ def default_state(model: Model) -> dict:
"limit": {"attack": 49, "release": 499, "knee": 0, "threshold": 220},
"gain": 280, "polarity": False, "delay": 0, "mute": False, "link": 1 << i,
} for i in range(model.n_out)],
"test": {"source": 0, "freq": 17},
}
@@ -500,6 +512,9 @@ def apply_command(model: Model, state: dict, cmd: int, p: bytes):
"""Update state from an incoming set command (used by the simulator)."""
if not p:
return
if cmd == CMD_TEST_SIGNAL:
state["test"] = {"source": p[0], "freq": p[1] if len(p) > 1 else 0}
return
c = p[0]
kind, idx = ("in", c) if c < model.n_in else ("out", c - model.n_in)
chans = state["inputs" if kind == "in" else "outputs"]