perf: do not hold the audio buffer lock during disk writes

_flush_buffer_to_file wrote (and for FLAC, encoded) every chunk while
holding buffer_lock, blocking the capture callback for the duration of
each disk flush. Swap the buffer out under the lock and write outside.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
2026-06-10 12:29:21 +02:00
parent 8e496ec2c4
commit fa055fc80a
+4 -3
View File
@@ -714,11 +714,12 @@ class SoundcardRecorder(BaseRecorder):
if self.current_file is None:
return
# Swap the buffer under the lock, write outside it — disk writes (and
# FLAC encoding) must not block the capture callback.
with self.buffer_lock:
if self.audio_buffer:
for data in self.audio_buffer:
buffered, self.audio_buffer = self.audio_buffer, []
for data in buffered:
self.current_file.write(data)
self.audio_buffer.clear()
def close_current_file(self):
"""Flush any buffered audio, then close the current recording file."""