From 2f3cd0e07f56ab8b5f11da8bd70eaf668691dcbd Mon Sep 17 00:00:00 2001 From: onyx-and-iris Date: Sun, 1 Mar 2026 01:08:02 +0000 Subject: [PATCH] use db levels throughout the package. This is cleaner than converting to db but comparing raw integer values. --- vban_cmd/packet.py | 40 ++++++++++++++++++++-------------------- vban_cmd/util.py | 14 ++++---------- 2 files changed, 24 insertions(+), 30 deletions(-) diff --git a/vban_cmd/packet.py b/vban_cmd/packet.py index 70baeeb..b7c045b 100644 --- a/vban_cmd/packet.py +++ b/vban_cmd/packet.py @@ -134,41 +134,41 @@ class VbanPacketNBS0(VbanPacket): ) def ldirty(self, strip_cache, bus_cache) -> bool: + """True iff any level has changed, ignoring changes when levels are very quiet""" self._strip_comp, self._bus_comp = ( tuple(not val for val in comp(strip_cache, self.strip_levels)), tuple(not val for val in comp(bus_cache, self.bus_levels)), ) - return any(any(li) for li in (self._strip_comp, self._bus_comp)) + return any(self._strip_comp) or any(self._bus_comp) @property - def strip_levels(self) -> tuple[int, ...]: - """Returns raw integer strip levels""" + def strip_levels(self) -> tuple[float, ...]: + """Returns strip levels in dB""" return tuple( - int.from_bytes(self._inputLeveldB100[i : i + 2], 'little') + round( + int.from_bytes(self._inputLeveldB100[i : i + 2], 'little', signed=True) + * 0.01, + 1, + ) for i in range(0, len(self._inputLeveldB100), 2) - ) + )[: self._kind.num_strip_levels] @property - def bus_levels(self) -> tuple[int, ...]: - """Returns raw integer bus levels""" + def bus_levels(self) -> tuple[float, ...]: + """Returns bus levels in dB""" return tuple( - int.from_bytes(self._outputLeveldB100[i : i + 2], 'little') + round( + int.from_bytes(self._outputLeveldB100[i : i + 2], 'little', signed=True) + * 0.01, + 1, + ) for i in range(0, len(self._outputLeveldB100), 2) - ) + )[: self._kind.num_bus_levels] @property def levels(self) -> Levels: - """Returns strip and bus levels converted to dB""" - - def to_db(raw_levels: tuple[int, ...]) -> tuple[float, ...]: - return tuple( - round((((1 << 16) - 1) - level) * -0.01, 1) for level in raw_levels - ) - - return Levels( - strip=to_db(self.strip_levels)[: self._kind.num_strip_levels], - bus=to_db(self.bus_levels)[: self._kind.num_bus_levels], - ) + """Returns strip and bus levels as a namedtuple""" + return Levels(strip=self.strip_levels, bus=self.bus_levels) @property def stripstate(self) -> tuple: diff --git a/vban_cmd/util.py b/vban_cmd/util.py index 576eb58..506fba0 100644 --- a/vban_cmd/util.py +++ b/vban_cmd/util.py @@ -86,21 +86,15 @@ def script(func): def comp(t0: tuple, t1: tuple) -> Iterator[bool]: """ - Generator function, accepts two tuples. + Generator function, accepts two tuples of dB values. Evaluates equality of each member in both tuples. - Only ignores changes when levels are very quiet (below noise floor). + Only ignores changes when levels are very quiet (below -72 dB). """ for a, b in zip(t0, t1): - # Convert to dB-equivalent: higher raw values = quieter audio - a_db_equiv = ((1 << 16) - 1) - a - b_db_equiv = ((1 << 16) - 1) - b - - # If both values are very quiet (> -72dB equivalent), ignore small changes - if a_db_equiv > 7200 and b_db_equiv > 7200: - yield True # Both very quiet, ignore changes - else: + # If both values are very quiet (below -72dB), ignore small changes + if a <= -72.0 and b <= -72.0: yield a == b # At least one has significant level, detect changes