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:
GivouandClaude Opus 5.5 committed 2026-11-02 17:11:46 +01:00
1 parent f7d5e22bb0
commit 5597fae3f3
13 files changed
+622 -35

No files matched your search

+223 -5
View File
@@ -46,6 +46,11 @@ CMD_LIMIT = 0x3F
CMD_MIX = 0x41
CMD_GEQ = 0x48
CMD_LINK = 0x3B # [ch][u16 link mask], see link_masks()
# FIR DSP 408 only
CMD_FIR = 0x4B # [ch][type][window][u16 low Hz][u16 high Hz][u16 taps index] (outputs)
CMD_FIR_COEF = 0x4E # [ch][packet][u16 total][up to 12 floats, most significant byte first]
CMD_FIR_BYPASS = 0x4F # [ch][1 = bypassed] (inputs)
CMD_FIR_NAME = 0x5B # [ch][8 characters]
CHUNK_SIZE = 50
TEST_SOURCES = ("analog", "pink", "white", "sine")
@@ -209,15 +214,16 @@ class Model:
name: str
n_in: int
n_out: int
beta: bool = False # layout assumed from the other models, never seen on a real device; only selectable by hand
beta: bool = False # never seen on a real device; only selectable by hand
fir: bool = False # FIR DSP 408: own memory layout, see _parse_fir
@property
def in_size(self) -> int:
return 140
return 138 if self.fir else 140
@property
def out_size(self) -> int:
return 96 + 2 * self.n_in
return 108 if self.fir else 96 + 2 * self.n_in
@property
def out_base(self) -> int:
@@ -234,6 +240,8 @@ class Model:
@property
def size(self) -> int:
if self.fir:
return 0x625
return self.globals_base + 4 + 2 * self.n_in + 2 * self.n_out + 12
@property
@@ -249,7 +257,10 @@ class Model:
MODELS = {"204": Model("DSP 204", 2, 4), "408": Model("DSP 408", 4, 8),
"206": Model("DSP 206", 2, 6, beta=True), "408fir": Model("FIR DSP 408", 4, 8, beta=True)}
"206": Model("DSP 206", 2, 6, beta=True), "408fir": Model("FIR DSP 408", 4, 8, beta=True, fir=True)}
FIR_MAX_IN, FIR_MAX_OUT, FIR_MAX_TOTAL = 2048, 1024, 4096 # taps per input / output, all channels together
FIR_PACKET = 12 # coefficients per CMD_FIR_COEF frame
def detect_model(info: str) -> str | None:
@@ -289,6 +300,8 @@ def _peq(buf: bytes, off: int, n: int) -> list[dict]:
def parse_state(model: Model, buf: bytes) -> dict:
"""Decode the reassembled config dump into a JSON friendly dict (raw values)."""
if model.fir:
return _parse_fir(model, buf)
u16 = lambda off: struct.unpack_from("<H", buf, off)[0]
g = model.globals_base
in_mute, out_mute = u16(g), u16(g + 2)
@@ -339,8 +352,207 @@ def parse_state(model: Model, buf: bytes) -> dict:
return {"preset_name": _name(buf[2:16]), "inputs": inputs, "outputs": outputs, "test": test}
# ---------------------------------------------------------------- FIR DSP 408
#
# Layout: header 0x10, inputs of 138 bytes, outputs of 108, then the mute masks, one word per channel with
# the bypassed PEQ bands, 8 characters of FIR name per channel and 17 bytes of other settings.
# Inputs: name, gate, 3 dynamic EQs (not used here), 8 PEQ bands, compressor, FIR taps + bypass, gain ...
# Outputs: name, matrix, mix, HP/LP (with own bypass bytes), FIR, 9 PEQ bands, limiter, gain ...
def _fir_slope(index: int, bypass: int) -> int:
"""This model keeps slope and bypass apart, the state uses one value (0 = bypass) like the other models."""
return 0 if bypass else min(index + 1, 20)
def _fir_filter(buf: bytes, freq_off: int, slope_off: int) -> dict:
return {"freq": struct.unpack_from("<H", buf, freq_off)[0], "slope": _fir_slope(buf[slope_off], buf[slope_off + 2])}
def _parse_fir(model: Model, buf: bytes) -> dict:
u16 = lambda off: struct.unpack_from("<H", buf, off)[0]
g = model.globals_base
in_mute, out_mute = u16(g), u16(g + 2)
fir_name = lambda c: _name(buf[0x5B4 + 8 * c : 0x5BC + 8 * c])
def bands(off: int, n: int, mask: int) -> list[dict]:
out = _peq(buf, off, n)
for j, b in enumerate(out):
b["bypass"] = bool(mask >> j & 1)
return out
inputs = []
for i in range(model.n_in):
o = 0x10 + i * model.in_size
comp = dict(zip(("ratio", "attack", "release", "knee", "threshold", "eq_freq"), struct.unpack_from("<6H", buf, o + 112)))
inputs.append({
"name": _name(buf[o : o + 8]),
"gate": dict(zip(("attack", "release", "hold", "threshold"), struct.unpack_from("<4H", buf, o + 8))),
"peq": bands(o + 64, 8, u16(g + 4 + 2 * i)),
"comp": {**comp, "eq_type": buf[o + 124], "eq_bypass": buf[o + 125]},
"fir": {"taps": u16(o + 126), "bypass": bool(u16(o + 128)), "name": fir_name(i)},
"gain": u16(o + 130), "polarity": u16(o + 132) != 0, "delay": u16(o + 134), "link": u16(o + 136),
"mute": bool(in_mute >> i & 1),
})
outputs = []
for i in range(model.n_out):
o = model.out_base + i * model.out_size
typ, win, low, high, taps = struct.unpack_from("<BBHHH", buf, o + 28)
outputs.append({
"name": _name(buf[o : o + 8]),
"matrix": u16(o + 8),
"mix": list(struct.unpack_from(f"<{model.n_in}H", buf, o + 10)),
"hp": _fir_filter(buf, o + 20, o + 24),
"lp": _fir_filter(buf, o + 22, o + 25),
"fir": {"type": typ, "window": win, "low": low, "high": high, "taps": taps, "name": fir_name(model.channel("out", i))},
"peq": bands(o + 36, 9, u16(g + 12 + 2 * i)),
"limit": dict(zip(("ratio", "attack", "release", "knee", "threshold"), struct.unpack_from("<5H", buf, o + 90))),
"gain": u16(o + 100), "polarity": u16(o + 102) != 0, "delay": u16(o + 104), "link": u16(o + 106),
"mute": bool(out_mute >> i & 1),
})
return {"preset_name": _name(buf[2:16]), "inputs": inputs, "outputs": outputs, "test": {"source": 0, "freq": 0}}
def _build_fir(model: Model, state: dict) -> bytearray:
buf = bytearray(model.chunks * CHUNK_SIZE)
pad = lambda s, n: s.encode("latin1")[:n].ljust(n, b" ")
buf[0:2] = b"\xff\xff"
buf[2:16] = pad(state["preset_name"], 14)
g = model.globals_base
def put_bands(off: int, bands: list[dict]) -> int:
for j, b in enumerate(bands):
struct.pack_into("<HHBB", buf, off + j * 6, b["gain"], b["freq"], b["q"], b["type"])
return sum(int(b.get("bypass", False)) << j for j, b in enumerate(bands))
in_mute = out_mute = 0
for i, ch in enumerate(state["inputs"]):
o = 0x10 + i * model.in_size
buf[o : o + 8] = pad(ch["name"], 8)
gt, c = ch["gate"], ch["comp"]
struct.pack_into("<4H", buf, o + 8, gt["attack"], gt["release"], gt["hold"], gt["threshold"])
struct.pack_into("<H", buf, g + 4 + 2 * i, put_bands(o + 64, ch["peq"]))
struct.pack_into("<6HBB", buf, o + 112, c["ratio"], c["attack"], c["release"], c["knee"], c["threshold"],
c["eq_freq"], c["eq_type"], c["eq_bypass"])
struct.pack_into("<6H", buf, o + 126, ch["fir"]["taps"], int(ch["fir"]["bypass"]), ch["gain"],
int(ch["polarity"]), ch["delay"], ch.get("link", 1 << i))
buf[0x5B4 + 8 * i : 0x5BC + 8 * i] = pad(ch["fir"]["name"], 8)
in_mute |= int(ch["mute"]) << i
for i, ch in enumerate(state["outputs"]):
o = model.out_base + i * model.out_size
buf[o : o + 8] = pad(ch["name"], 8)
struct.pack_into("<H", buf, o + 8, ch["matrix"])
struct.pack_into(f"<{model.n_in}H", buf, o + 10, *ch["mix"])
hp, lp, f, lim = ch["hp"], ch["lp"], ch["fir"], ch["limit"]
struct.pack_into("<HHBBBB", buf, o + 20, hp["freq"], lp["freq"], max(hp["slope"] - 1, 0), max(lp["slope"] - 1, 0),
int(not hp["slope"]), int(not lp["slope"]))
struct.pack_into("<BBHHH", buf, o + 28, f["type"], f["window"], f["low"], f["high"], f["taps"])
struct.pack_into("<H", buf, g + 12 + 2 * i, put_bands(o + 36, ch["peq"]))
struct.pack_into("<5H", buf, o + 90, lim["ratio"], lim["attack"], lim["release"], lim["knee"], lim["threshold"])
struct.pack_into("<4H", buf, o + 100, ch["gain"], int(ch["polarity"]), ch["delay"], ch.get("link", 1 << i))
c = model.channel("out", i)
buf[0x5B4 + 8 * c : 0x5BC + 8 * c] = pad(f["name"], 8)
out_mute |= int(ch["mute"]) << i
struct.pack_into("<HH", buf, g, in_mute, out_mute)
return buf
def _default_fir(model: Model) -> dict:
peq = lambda n: [{"gain": 120, "freq": 50 + i * 25, "q": 32, "type": 0, "bypass": False} for i in range(n)]
return {
"preset_name": "Default",
"inputs": [{
"name": f"In{chr(65 + i)}", "gate": {"attack": 0, "release": 99, "hold": 99, "threshold": 0}, "peq": peq(8),
"comp": {"ratio": 0, "attack": 49, "release": 99, "knee": 0, "threshold": 120, "eq_freq": 150, "eq_type": 0, "eq_bypass": 1},
"fir": {"taps": 0, "bypass": True, "name": ""},
"gain": 280, "polarity": False, "delay": 0, "mute": False, "link": 1 << i,
} for i in range(model.n_in)],
"outputs": [{
"name": f"Out{i + 1}", "matrix": 1 << (i % model.n_in), "mix": [280] * model.n_in,
"hp": {"freq": 0, "slope": 0}, "lp": {"freq": 300, "slope": 0},
"fir": {"type": 0, "window": 3, "low": 150, "high": 20000, "taps": 8, "name": ""},
"peq": peq(9), "limit": {"ratio": 0, "attack": 49, "release": 99, "knee": 0, "threshold": 200},
"gain": 280, "polarity": False, "delay": 0, "mute": False, "link": 1 << i,
} for i in range(model.n_out)],
"test": {"source": 0, "freq": 0},
}
def fir_channel_taps(ch: dict) -> int:
"""How many of the shared FIR taps a channel takes."""
f = ch["fir"]
if "type" in f:
return 256 + 32 * f["taps"] if f["type"] else 0
return 0 if f["bypass"] else f["taps"]
def clean_fir(value, cur: dict) -> dict:
"""FIR settings of an output limited to valid values; anything missing stays as it is."""
value = value if isinstance(value, dict) else {}
def num(key, lo, hi):
try:
return min(hi, max(lo, int(value.get(key, cur[key]))))
except (TypeError, ValueError):
return cur[key]
return {"type": num("type", 0, 4), "window": num("window", 0, 10), "low": num("low", 20, 20000),
"high": num("high", 20, 20000), "taps": num("taps", 0, 24), "name": cur.get("name", "")}
def fir_coef_frames(channel: int, coeffs: list[float]) -> list[bytes]:
"""Payloads of the CMD_FIR_COEF frames for one channel."""
n = len(coeffs)
return [bytes([channel, p]) + struct.pack("<H", n)
+ b"".join(struct.pack(">f", c) for c in coeffs[p * FIR_PACKET : (p + 1) * FIR_PACKET])
for p in range(-(-n // FIR_PACKET))]
def _fir_command(c: int, kind: str, ch: dict, top: str, rest: list[str]) -> tuple[int, bytes] | None:
if top in ("hp", "lp"):
f = ch[top]
return (CMD_HIGH_PASS if top == "hp" else CMD_LOW_PASS), bytes([c]) + _w(f["freq"]) + bytes([max(f["slope"] - 1, 0), int(not f["slope"])])
if top == "limit" and kind == "out":
return CMD_LIMIT, bytes([c]) + b"".join(_w(ch["limit"][k]) for k in ("ratio", "attack", "release", "knee", "threshold"))
if top == "comp" and kind == "in":
g = ch["comp"]
return CMD_COMP, bytes([c]) + b"".join(_w(g[k]) for k in ("ratio", "attack", "release", "knee", "threshold", "eq_freq")) + bytes([g["eq_type"], g["eq_bypass"]])
if top == "fir" and kind == "out":
f = ch["fir"]
return CMD_FIR, bytes([c, f["type"], f["window"]]) + _w(f["low"]) + _w(f["high"]) + _w(f["taps"])
if top == "fir" and kind == "in":
return CMD_FIR_BYPASS, bytes([c, int(ch["fir"]["bypass"])])
return None
def _apply_fir(ch: dict, cmd: int, p: bytes) -> bool:
"""Set commands of this model (simulator). False: handled like on the other models."""
w = lambda o: struct.unpack_from("<H", p, o)[0]
if cmd in (CMD_HIGH_PASS, CMD_LOW_PASS):
ch["hp" if cmd == CMD_HIGH_PASS else "lp"] = {"freq": w(1), "slope": _fir_slope(p[3], p[4])}
elif cmd == CMD_LIMIT:
ch["limit"] = dict(zip(("ratio", "attack", "release", "knee", "threshold"), struct.unpack_from("<5H", p, 1)))
elif cmd == CMD_COMP:
ch["comp"] = {**dict(zip(("ratio", "attack", "release", "knee", "threshold", "eq_freq"), struct.unpack_from("<6H", p, 1))),
"eq_type": p[13], "eq_bypass": p[14]}
elif cmd == CMD_FIR:
ch["fir"].update(type=p[1], window=p[2], low=w(3), high=w(5), taps=w(7))
elif cmd == CMD_FIR_BYPASS:
ch["fir"]["bypass"] = bool(p[1])
elif cmd == CMD_FIR_NAME:
ch["fir"]["name"] = _name(p[1:9])
elif cmd == CMD_FIR_COEF:
if "bypass" in ch["fir"]:
ch["fir"]["taps"] = w(2)
else:
return False
return True
def build_state_buffer(model: Model, state: dict) -> bytearray:
"""Inverse of parse_state (used by the simulator)."""
if model.fir:
return _build_fir(model, state)
buf = bytearray(model.chunks * CHUNK_SIZE)
pad = lambda s, n: s.encode("latin1")[:n].ljust(n, b" ")
buf[0:2] = b"\xff\xff"
@@ -389,6 +601,8 @@ def build_state_buffer(model: Model, state: dict) -> bytearray:
def default_state(model: Model) -> dict:
if model.fir:
return _default_fir(model)
peq = lambda n: [{"gain": 120, "freq": 50 + i * 25, "q": 32, "type": 0, "bypass": False}
for i in range(n)]
return {
@@ -471,6 +685,8 @@ def param_command(model: Model, kind: str, idx: int, ch: dict, param: str) -> tu
"""
c = model.channel(kind, idx)
top, *rest = param.split(".")
if model.fir and (fir := _fir_command(c, kind, ch, top, rest)):
return fir
if top == "gain":
return CMD_GAIN, bytes([c]) + _w(ch["gain"])
if top == "mute":
@@ -541,7 +757,9 @@ def apply_command(model: Model, state: dict, cmd: int, p: bytes):
return
ch = chans[idx]
w = lambda o: struct.unpack_from("<H", p, o)[0]
if cmd == CMD_PEQ_BYPASS:
if model.fir and _apply_fir(ch, cmd, p):
pass
elif cmd == CMD_PEQ_BYPASS:
ch["peq_bypass"] = bool(p[1])
elif cmd == CMD_GEQ_BYPASS:
ch["geq_bypass"] = bool(p[1])