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
This commit is contained in:
2020-12-05 19:46:23 +01:00
parent d2671bf534
commit 57b92b2864
2 changed files with 7 additions and 5 deletions

View File

@@ -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)

View File

@@ -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')