DJ Brake: learn the limiter from its onset, for the whole DSP
Replaying real tracks through a limiter model showed the level during limiting teaches little. One hit now counts for all outputs of a DSP. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
bbe8a73775
commit
6d467d4f2d
2 files changed
+32
-8
No files matched your search
@@ -331,7 +331,7 @@ class App:
|
|||||||
self.dj_rooms: dict = {} # device id -> dB left to the nearest watched limiter, False = nothing watched
|
self.dj_rooms: dict = {} # device id -> dB left to the nearest watched limiter, False = nothing watched
|
||||||
self.dj_avgs: dict = {} # the same for the average level
|
self.dj_avgs: dict = {} # the same for the average level
|
||||||
self.dj_env: dict = {} # "device:output" -> peak and average of the level
|
self.dj_env: dict = {} # "device:output" -> peak and average of the level
|
||||||
self.dj_cal: dict = {} # "device:output" -> dB the limiter sits below its threshold on the meter, learned from hits
|
self.dj_cal: dict = {} # device id -> dB the limiters sit below their threshold on the meter, learned from hits
|
||||||
self.dj_cal_saved = 0.0
|
self.dj_cal_saved = 0.0
|
||||||
self.dj_streams = 0
|
self.dj_streams = 0
|
||||||
self.logo = ""
|
self.logo = ""
|
||||||
@@ -385,8 +385,8 @@ class App:
|
|||||||
self.djbrake = bool(cfg.get("djbrake"))
|
self.djbrake = bool(cfg.get("djbrake"))
|
||||||
self.dj_ignore = clean_dj_ignore(cfg.get("dj_ignore"))
|
self.dj_ignore = clean_dj_ignore(cfg.get("dj_ignore"))
|
||||||
self.dj_margin = clean_dj_margin(cfg.get("dj_margin"))
|
self.dj_margin = clean_dj_margin(cfg.get("dj_margin"))
|
||||||
self.dj_cal = {str(k)[:80]: float(v) for k, v in (cfg.get("dj_cal") if isinstance(cfg.get("dj_cal"), dict) else {}).items()
|
self.dj_cal = {str(k)[:64]: float(v) for k, v in (cfg.get("dj_cal") if isinstance(cfg.get("dj_cal"), dict) else {}).items()
|
||||||
if type(v) in (int, float)}
|
if type(v) in (int, float) and ":" not in str(k)}
|
||||||
self.dj_hint = bool(cfg.get("dj_hint", True))
|
self.dj_hint = bool(cfg.get("dj_hint", True))
|
||||||
self.dj_hint_en = bool(cfg.get("dj_hint_en", True))
|
self.dj_hint_en = bool(cfg.get("dj_hint_en", True))
|
||||||
if "logo" in cfg:
|
if "logo" in cfg:
|
||||||
@@ -970,10 +970,14 @@ class App:
|
|||||||
e["peak"] = max(db, e["peak"] - DJ_PEAK_FALL * dt)
|
e["peak"] = max(db, e["peak"] - DJ_PEAK_FALL * dt)
|
||||||
e["pow"] += (level * level - e["pow"]) * (1 - math.exp(-dt / DJ_AVG_TAU))
|
e["pow"] += (level * level - e["pow"]) * (1 - math.exp(-dt / DJ_AVG_TAU))
|
||||||
thr = P.threshold_to_db(threshold)
|
thr = P.threshold_to_db(threshold)
|
||||||
if limit and e["peak"] > -70: # the limiter acts: this is where it really sits on the meter
|
# 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"]))
|
seen = max(-6.0, min(30.0, thr - e["peak"]))
|
||||||
self.dj_cal[key] = seen if key not in self.dj_cal else self.dj_cal[key] + (seen - self.dj_cal[key]) * (1 - math.exp(-dt))
|
self.dj_cal[dev_id] = (self.dj_cal[dev_id] + seen) / 2 if dev_id in self.dj_cal else seen
|
||||||
top = thr - self.dj_cal.get(key, 0.0) - self.dj_margin
|
e["acting"] = limit
|
||||||
|
top = thr - self.dj_cal.get(dev_id, 0.0) - self.dj_margin
|
||||||
left = 0.0 if limit else max(0.0, top - e["peak"]) if e["peak"] > -70 else None
|
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
|
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)
|
return left, mean, limit or bool(self.dj_margin and db >= top)
|
||||||
|
|||||||
+22
-2
@@ -224,7 +224,7 @@ def test_dj_brake_follows_music():
|
|||||||
assert 10 < app.dj_rooms["x"] < 14
|
assert 10 < app.dj_rooms["x"] < 14
|
||||||
# the limiter acts at -12 on the meter although the threshold says 0: learned, and the distance is true afterwards
|
# the limiter acts at -12 on the meter although the threshold says 0: learned, and the distance is true afterwards
|
||||||
note(-12, 110.0, True)
|
note(-12, 110.0, True)
|
||||||
assert abs(app.dj_cal["x:0"] - 12) < 3 and app.dj_rooms["x"] == 0
|
assert abs(app.dj_cal["x"] - 12) < 3 and app.dj_rooms["x"] == 0
|
||||||
assert app.dj_hit == 110.0
|
assert app.dj_hit == 110.0
|
||||||
for i in range(30):
|
for i in range(30):
|
||||||
note(-30, 120.0 + i)
|
note(-30, 120.0 + i)
|
||||||
@@ -238,7 +238,27 @@ def test_dj_brake_follows_music():
|
|||||||
app.save()
|
app.save()
|
||||||
again = server.App(Path(d) / "c.json")
|
again = server.App(Path(d) / "c.json")
|
||||||
again.load()
|
again.load()
|
||||||
assert abs(again.dj_cal["x:0"] - app.dj_cal["x:0"]) < 0.01
|
assert abs(again.dj_cal["x"] - app.dj_cal["x"]) < 0.01
|
||||||
|
|
||||||
|
|
||||||
|
def test_dj_brake_one_hit_counts_for_the_whole_dsp():
|
||||||
|
import server, tempfile
|
||||||
|
from types import SimpleNamespace
|
||||||
|
with tempfile.TemporaryDirectory() as d:
|
||||||
|
app = server.App(Path(d) / "c.json")
|
||||||
|
out = {"mute": False, "limit": {"threshold": 180}}
|
||||||
|
app.devices["x"] = SimpleNamespace(id="x", demo=True, state={"outputs": [dict(out), dict(out)]}, status="online")
|
||||||
|
lv = lambda db: 10 ** (db / 20)
|
||||||
|
app.dj_ignore = {"x": [1]}
|
||||||
|
app.dj_note({"device": "x", "out": [lv(-12), lv(-40)], "limit": [True, False]}, now=100.0)
|
||||||
|
assert app.dj_cal == {"x": 12.0}
|
||||||
|
# the level the limiter leaves over while it keeps acting teaches nothing
|
||||||
|
app.dj_note({"device": "x", "out": [lv(-20), lv(-40)], "limit": [True, False]}, now=100.2)
|
||||||
|
assert app.dj_cal == {"x": 12.0}
|
||||||
|
# another output of this DSP has never limited, its distance is true anyway
|
||||||
|
app.dj_ignore = {"x": [0]}
|
||||||
|
app.dj_note({"device": "x", "out": [lv(-40), lv(-18)], "limit": [False, False]}, now=101.0)
|
||||||
|
assert abs(app.dj_rooms["x"] - 6) < 0.01
|
||||||
|
|
||||||
|
|
||||||
def test_reset_config():
|
def test_reset_config():
|
||||||
|
|||||||
Reference in new issue
Block a user