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

+50 -2
View File
@@ -12,6 +12,7 @@ import errno
import hashlib
import json
import logging
import math
import mimetypes
import re
import secrets
@@ -385,6 +386,8 @@ class App:
return {"ok": True}
async def device_online(self, dev: Device):
if dev.model.fir and dev.test_saved is not None: # its test signal can't be read back: make sure it is off
await dev.set_test_signal(0, 0)
await self.check_audio_test(dev)
if not self.mute_all["active"] and self.mute_all["restore"].get(dev.id):
self.unmute_device(dev) # released while this DSP was offline
@@ -421,6 +424,44 @@ class App:
self.broadcast({"type": "muteall", "data": self.mute_all_info()})
return self.mute_all_info()
# ------------------------------------------------------------ FIR filters (FIR DSP 408)
@staticmethod
def check_fir_param(dev: Device, idx: int, value) -> dict:
value = P.clean_fir(value, dev.state["outputs"][idx]["fir"])
if value["type"] and dev.fir_taps_used(skip=("out", idx)) + 256 + 32 * value["taps"] > P.FIR_MAX_TOTAL:
raise RuntimeError("Out of FIR taps: all channels together have 4096")
return value
async def upload_fir(self, dev: Device, body: dict) -> dict:
kind = "in" if body.get("kind") == "in" else "out"
idx = int(body.get("idx", 0))
if not dev.state or not dev.model.fir or not 0 <= idx < len(dev.state["inputs" if kind == "in" else "outputs"]):
raise RuntimeError("DSP is not connected")
raw = body.get("coeffs")
limit = P.FIR_MAX_IN if kind == "in" else P.FIR_MAX_OUT
if not isinstance(raw, list) or not 1 <= len(raw) <= limit:
raise RuntimeError(f"Too many FIR coefficients: at most {limit} here")
try:
coeffs = [float(c) for c in raw]
except (TypeError, ValueError):
raise RuntimeError("Not valid FIR coefficients") from None
if not all(math.isfinite(c) for c in coeffs):
raise RuntimeError("Not valid FIR coefficients")
name = str(body.get("name") or "")
if kind == "out":
taps = max(0, -((256 - len(coeffs)) // 32)) # taps index that holds them
cur = dev.state["outputs"][idx]["fir"]
dev.set_param("out", idx, "fir", self.check_fir_param(dev, idx, {**cur, "type": 4, "taps": taps}))
elif dev.fir_taps_used(skip=("in", idx)) + len(coeffs) > P.FIR_MAX_TOTAL:
raise RuntimeError("Out of FIR taps: all channels together have 4096")
failed = await dev.upload_fir(kind, idx, coeffs, name)
if kind == "in" and dev.state["inputs"][idx]["fir"]["bypass"]:
dev.set_param("in", idx, "fir.bypass", False)
if failed:
raise RuntimeError(f"The DSP did not answer {failed} frames")
return {"ok": True, "count": len(coeffs)}
# ------------------------------------------------------------ copy channel settings
def copy_settings(self, body: dict) -> dict:
@@ -453,10 +494,13 @@ class App:
if kind == "in":
params += ["geq_bypass"] + [f"geq.{b}" for b in range(31)]
if "dynamics" in groups:
params += ["gate"] if kind == "in" else ["comp", "limit"]
params += ["gate", "comp"] if kind == "in" else ["comp", "limit"]
if "routing" in groups and kind == "out":
params += [f"mix.{k}" for k in range(min(len(sch["mix"]), len(tch["mix"])))]
for p in params:
top = p.split(".")[0]
if top not in sch or top not in tch or (isinstance(sch[top], dict) and sch[top].keys() != tch[top].keys()):
continue # a setting only one of the two models has
v = copy.deepcopy(self._get(sch, p))
if p == "gain":
v = dev.gain_cap(kind, idx, v)
@@ -791,7 +835,7 @@ class App:
if dev.demo and (method in ("DELETE", "PUT") or action in ("unlock", "lockcode")):
raise RuntimeError("Not available for the demo device")
# during the audio test only the test controls work: generator, test fader, output mutes
if dev.test_active and (action in ("preset/recall", "preset/store", "export", "import", "undo", "link")
if dev.test_active and (action in ("preset/recall", "preset/store", "export", "import", "undo", "link", "fir")
or action == "set" and body.get("param") != "mute"):
raise RuntimeError("Audio test is on – switch it off first")
if self.demo["enabled"] and not dev.demo and action == "connect":
@@ -837,8 +881,12 @@ class App:
kind, idx, value = body["kind"], int(body["idx"]), body["value"]
if body["param"] == "gain" and not body.get("force"): # force: confirmed twice in the app
value = dev.gain_cap(kind, idx, int(value)) # software max level
if body["param"] == "fir" and dev.state:
value = self.check_fir_param(dev, int(body["idx"]), value)
dev.set_param(kind, idx, body["param"], value)
return {"ok": True, "value": value}
if action == "fir":
return await self.upload_fir(dev, body)
if action == "maxgain": # app-side setting, the DSP doesn't know it
dev.maxgain = clean_maxgain(body.get("maxgain"))
self.save()