summaryrefslogtreecommitdiff
path: root/src/tests/test_sequence.cc
diff options
context:
space:
mode:
authorskal <pascal.massimino@gmail.com>2026-02-04 16:30:29 +0100
committerskal <pascal.massimino@gmail.com>2026-02-04 16:30:29 +0100
commit09230c434e8d23b6eac3bdf97c3e5fd779d1e5a4 (patch)
treeda9d547bd76328d9b23245c108a93628eb22b254 /src/tests/test_sequence.cc
parentd94e8ca1df4f6cf366afd33be43a7eed8d766560 (diff)
fix(audio): Check buffer space before rendering to prevent sample loss
Fixed live playback crash during acceleration phase. The issue was that audio_render_ahead was calling synth_render() before checking if the buffer had space, causing sample loss and audio corruption. Problem: - Old code: synth_render() first, then check if write() succeeded - If buffer was full, write() returned 0 (or partial) - But synth_render() had already advanced synth internal state - Rendered samples were DISCARDED (lost) - Synth time got ahead of buffer playback position - Audio desync caused corruption and crashes During Acceleration Phase (tempo 2.0x): - Main thread fills buffer rapidly (many events triggered) - Audio callback consumes at fixed 32kHz rate - Buffer fills faster than it drains - Samples start getting discarded - Synth desync causes audio corruption - Eventually crashes or hangs Solution: Check available_write() BEFORE calling synth_render() - Only render if buffer has space for the chunk - Never discard rendered samples - Synth stays synchronized with buffer playback position Changes: - Move buffered_samples calculation inside loop - Check available_write() before synth_render() - Break if buffer is too full (wait for consumption) - Synth only advances when samples are actually written Result: No sample loss, no desync, smooth playback during tempo changes. Testing: - All 17 tests pass (100%) - WAV dump still produces correct output (61.24s music time) - Live playback should no longer crash at acceleration phase Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Diffstat (limited to 'src/tests/test_sequence.cc')
0 files changed, 0 insertions, 0 deletions