DJ Brake: use the offset measured on a real DSP 204

Measured: limiter threshold minus output meter is about 26 dB when the limiter
starts (25.1 to 27.7, one DSP 204, one output, one piece of music), and the meter
is after the output gain. So the distance is right before the first hit.
The limiter flag also stayed on after raising a threshold, which would have
taught a false value: only limiters starting by themselves teach now.
The measuring tool no longer draws conclusions the data doesn't carry.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
GivouandClaude Opus 5.5 committed 2026-11-02 21:54:29 +01:00
1 parent 4cd771eb5c
commit 63b3c17fb7
5 files changed
+106 -24

No files matched your search

+26 -8
View File
@@ -217,6 +217,11 @@ DJ_HOLD = 1.5 # s the light of /djbrake stays on after a limiter acted, so it d
DJ_PEAK_HOLD = 1.5 # s the peak marker stays, then it falls ...
DJ_PEAK_FALL = 3.0 # ... this many dB/s: the display follows the music, not every single beat
DJ_AVG_TAU = 3.0 # s time constant of the average level
# dB between the limiter threshold and the output meter when a limiter starts, until real hits say otherwise. Measured with
# tools/dsp_measure.py: one DSP 204 (V0104P), one output, one piece of music: 25.1 to 27.7 in five rounds, with and without
# -6 dB gain. It holds a share of the music's peaks the meter doesn't catch, so other music can differ by a few dB.
DJ_METER_OFFSET = {"204": 26.0}
DJ_LEARN_QUIET = 6.0 # s after a jump of a threshold the limiter flag teaches nothing: it was seen on for 4 s at +20 dB
def clean_dj_margin(value) -> int:
@@ -958,7 +963,14 @@ class App:
# ------------------------------------------------------------ events
def dj_track(self, key: str, level: float, limit: bool, threshold: int, now: float) -> tuple:
def dj_offset(self, dev) -> float:
"""Learned from this DSP's hits, else what was measured on this model. The simulator has no such offset."""
if dev.id in self.dj_cal:
return self.dj_cal[dev.id]
real = "SIM" not in getattr(dev, "info", "") and not getattr(dev, "demo", False)
return DJ_METER_OFFSET.get(getattr(dev, "model_name", ""), 0.0) if real else 0.0
def dj_track(self, dev, key: str, level: float, limit: bool, threshold: int, now: float) -> tuple:
"""One meter reading of a watched output: (dB left by the peak, dB left by the average, warn now)."""
e = self.dj_env.setdefault(key, {"peak": -120.0, "until": 0.0, "pow": 0.0, "t": now})
dt = min(now - e["t"], 1.0)
@@ -972,12 +984,18 @@ class App:
thr = P.threshold_to_db(threshold)
# the moment a limiter starts is where it really sits on the meter. Later the level is what the limiter
# left of it. One DSP has one meter, so this counts for all its outputs
dev_id = key.rsplit(":", 1)[0]
if limit and not e.get("acting") and e["peak"] > -70:
seen = max(-6.0, min(30.0, thr - e["peak"]))
self.dj_cal[dev_id] = (self.dj_cal[dev_id] + seen) / 2 if dev_id in self.dj_cal else seen
e["acting"] = limit
top = thr - self.dj_cal.get(dev_id, 0.0) - self.dj_margin
# only a limiter that starts by itself counts: not after a threshold jumped, up or down, and not
# while it flickers on and off in the middle of limiting
if thr > e.get("thr", thr) or thr < e.get("thr", thr) - 2:
e["jumped"] = now
e["thr"] = thr
if limit and now - e.get("last_on", -1e9) > 3 and now - e.get("jumped", -1e9) > DJ_LEARN_QUIET and e["peak"] > -70:
seen = max(-6.0, min(40.0, thr - e["peak"]))
known = self.dj_offset(dev)
self.dj_cal[dev.id] = (known * 3 + seen) / 4 if known or dev.id in self.dj_cal else seen
if limit:
e["last_on"] = now
top = thr - self.dj_offset(dev) - self.dj_margin
left = 0.0 if limit else max(0.0, top - e["peak"]) if e["peak"] > -70 else None
mean = max(0.0, top - 10 * math.log10(e["pow"])) if e["pow"] > 1e-7 else None
return left, mean, limit or bool(self.dj_margin and db >= top)
@@ -994,7 +1012,7 @@ class App:
if i in ignore or ch["mute"]:
self.dj_env.pop(key, None)
continue
left, mean, warn = self.dj_track(key, level, limit, ch["limit"]["threshold"], now)
left, mean, warn = self.dj_track(dev, key, level, limit, ch["limit"]["threshold"], now)
if warn:
self.dj_hit = now
room = left if room is False or room is None else room if left is None else min(room, left)