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:
@@ -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)
|
||||
|
||||
@@ -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')
|
||||
|
||||
|
||||
Reference in New Issue
Block a user