Skip to content

Commit

Permalink
Add pause and reset methods to Meter
Browse files Browse the repository at this point in the history
  • Loading branch information
nocarryr committed Jun 23, 2024
1 parent 8ee65cc commit 3200ad7
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions src/lupy/meter.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ def __init__(self, block_size: int, num_channels: int) -> None:
num_channels=num_channels,
gate_size=self.sampler.gate_size,
)
self._paused = False

@property
def paused(self) -> bool:
"""``True`` if processing is currently paused
"""
return self._paused

def can_write(self) -> bool:
"""Whether there is enough room on the internal buffer for at least
Expand All @@ -45,6 +52,8 @@ def can_process(self) -> bool:
"""Whether there are enough samples in the internal buffer for at least
one call to :meth:`process`
"""
if self.paused:
return False
return self.sampler.can_read()

def write(
Expand All @@ -57,6 +66,8 @@ def write(
The input data must be of shape ``(num_channels, block_size)``
"""
if self.paused:
return
self.sampler.write(samples)
if process and self.can_process():
self.process(process_all=process_all)
Expand All @@ -82,6 +93,25 @@ def _do_process():
else:
_do_process()

def reset(self) -> None:
"""Reset all values for :attr:`processor` and clear any buffered input
samples
"""
self.sampler.clear()
self.processor.reset()

def set_paused(self, paused: bool) -> None:
"""Pause or unpause processing
When paused, the current state of the :attr:`processor` is preserved
and any input provided to the :meth:`write` method will be discarded.
"""
if paused is self.paused:
return
self._paused = paused
if paused:
self.sampler.clear()

@property
def integrated_lkfs(self) -> Floating:
"""The current :term:`Integrated Loudness`"""
Expand Down

0 comments on commit 3200ad7

Please sign in to comment.