From 57b92b286435b57f96e50ac2a81187493c136af8 Mon Sep 17 00:00:00 2001 From: Rick Rongen Date: Sat, 5 Dec 2020 19:46:23 +0100 Subject: [PATCH] feat: Improvements for audio subsystem Increased minimum space in buffer for audio write When not playing audio, decrease update rate Decreased priority of other tasks --- control/audio.py | 8 +++++--- tickworker.py | 4 ++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/control/audio.py b/control/audio.py index d11641a..5defe5e 100644 --- a/control/audio.py +++ b/control/audio.py @@ -14,7 +14,8 @@ logger = logging.getLogger(__name__) CHUNK_SIZE = 1024 INTERVAL_QUEUE = 0.1 -INTERVAL_STREAM = 0.0001 +INTERVAL_STREAM_FAST = 0.0001 +INTERVAL_STREAM_SLOW = 0.001 class PlayEntry: @@ -96,11 +97,12 @@ class AudioSystem: raise e def fill_streams(self): - self.scheduler.enter(INTERVAL_STREAM, 1, self.fill_streams) + self.scheduler.enter(INTERVAL_STREAM_FAST if len(self.playing) > 0 else INTERVAL_STREAM_SLOW, + 1, self.fill_streams) finished_streams = [] for stream_id, entry in self.playing.items(): # type: uuid.UUID, PlayEntry try: - if entry.stream.get_write_available() < CHUNK_SIZE: + if entry.stream.get_write_available() < (CHUNK_SIZE * 1.5): continue # not enough space in buffer, wait for next iteration try: data = entry.get_actual_data(CHUNK_SIZE) diff --git a/tickworker.py b/tickworker.py index 1659e10..a96d189 100644 --- a/tickworker.py +++ b/tickworker.py @@ -56,11 +56,11 @@ walle.setup() def walle_tick(): - scheduler.enter(INTERVAL_TICK, 1, walle_tick) + scheduler.enter(INTERVAL_TICK, 3, walle_tick) walle.tick() -scheduler.enter(INTERVAL_TICK, 1, walle_tick) +scheduler.enter(INTERVAL_TICK, 3, walle_tick) audio.queue_sound('walle.boot')