Skip to content

Commit 92dbd58

Browse files
authored
Raspberry Pi 0 fix - Extending usage of "Thread-safe snapshot of correction schedule" (#37)
The Raspberry Pi 0 (variant of the original Raspberry Pi) is a low performant, single-threaded computer. Accordingly, it's a bit more sensitive to some time based issues. You snapshot `self._####_every_n_frames` from what I assume is the same general issue, giving the comment `Thread-safe snapshot of correction schedule` However, the replacement `####_every_n` aren't used in all spots within the loop. This update to use these seems to have resolved the playback issues on the Raspi 0. My issue manifested itself as switching from 7% CPU to 100% CPU and hanging. Identified with `py-spy` and some chatgpt to summary the code.
1 parent 57abe85 commit 92dbd58

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

‎sendspin/audio.py‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -471,11 +471,11 @@ def _audio_callback( # noqa: PLR0915
471471

472472
# Handle correction event if at boundary
473473
if frames_remaining > 0:
474-
if drop_counter <= 0 and self._drop_every_n_frames > 0:
474+
if drop_counter <= 0 and drop_every_n > 0:
475475
# Drop frame: read EXTRA frame to advance cursor faster
476476
_ = self._read_one_input_frame() # Read frame we're replacing
477477
_ = self._read_one_input_frame() # Read frame we're DROPPING
478-
drop_counter = self._drop_every_n_frames
478+
drop_counter = drop_every_n
479479
self._frames_dropped_since_log += 1
480480
# Output last frame instead (don't output either frame we read)
481481
output_buffer[bytes_written : bytes_written + frame_size] = (
@@ -484,10 +484,10 @@ def _audio_callback( # noqa: PLR0915
484484
bytes_written += frame_size
485485
frames_remaining -= 1
486486
insert_counter -= 1
487-
elif insert_counter <= 0 and self._insert_every_n_frames > 0:
487+
elif insert_counter <= 0 and insert_every_n > 0:
488488
# Insert frame: output duplicate WITHOUT reading
489489
# This makes playback catch up to cursor (cursor doesn't advance)
490-
insert_counter = self._insert_every_n_frames
490+
insert_counter = insert_every_n
491491
self._frames_inserted_since_log += 1
492492
output_buffer[bytes_written : bytes_written + frame_size] = (
493493
self._last_output_frame

0 commit comments

Comments
 (0)