mirror of
https://github.com/onyx-and-iris/vban-cmd-python.git
synced 2026-03-02 16:29:11 +00:00
use db levels throughout the package. This is cleaner than converting to db but comparing raw integer values.
This commit is contained in:
parent
d689b3a301
commit
2f3cd0e07f
@ -134,41 +134,41 @@ class VbanPacketNBS0(VbanPacket):
|
|||||||
)
|
)
|
||||||
|
|
||||||
def ldirty(self, strip_cache, bus_cache) -> bool:
|
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 = (
|
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(strip_cache, self.strip_levels)),
|
||||||
tuple(not val for val in comp(bus_cache, self.bus_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
|
@property
|
||||||
def strip_levels(self) -> tuple[int, ...]:
|
def strip_levels(self) -> tuple[float, ...]:
|
||||||
"""Returns raw integer strip levels"""
|
"""Returns strip levels in dB"""
|
||||||
return tuple(
|
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)
|
for i in range(0, len(self._inputLeveldB100), 2)
|
||||||
)
|
)[: self._kind.num_strip_levels]
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def bus_levels(self) -> tuple[int, ...]:
|
def bus_levels(self) -> tuple[float, ...]:
|
||||||
"""Returns raw integer bus levels"""
|
"""Returns bus levels in dB"""
|
||||||
return tuple(
|
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)
|
for i in range(0, len(self._outputLeveldB100), 2)
|
||||||
)
|
)[: self._kind.num_bus_levels]
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def levels(self) -> Levels:
|
def levels(self) -> Levels:
|
||||||
"""Returns strip and bus levels converted to dB"""
|
"""Returns strip and bus levels as a namedtuple"""
|
||||||
|
return Levels(strip=self.strip_levels, bus=self.bus_levels)
|
||||||
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],
|
|
||||||
)
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def stripstate(self) -> tuple:
|
def stripstate(self) -> tuple:
|
||||||
|
|||||||
@ -86,21 +86,15 @@ def script(func):
|
|||||||
|
|
||||||
def comp(t0: tuple, t1: tuple) -> Iterator[bool]:
|
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.
|
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):
|
for a, b in zip(t0, t1):
|
||||||
# Convert to dB-equivalent: higher raw values = quieter audio
|
# If both values are very quiet (below -72dB), ignore small changes
|
||||||
a_db_equiv = ((1 << 16) - 1) - a
|
if a <= -72.0 and b <= -72.0:
|
||||||
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:
|
|
||||||
yield a == b # At least one has significant level, detect changes
|
yield a == b # At least one has significant level, detect changes
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user