summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorskal <pascal.massimino@gmail.com>2026-02-09 12:57:22 +0100
committerskal <pascal.massimino@gmail.com>2026-02-09 12:57:22 +0100
commit807c6f5097897fac92428b939df020cdb70aae77 (patch)
treee79322ab6a62b08a95cb3ecc7c7a24a962808f6c /src
parent655d0a627c17b598562616a269e53bf06124d43f (diff)
fix: Audio startup hiccup - use fill_audio_buffer for pre-fill
- Added target_fill parameter to audio_render_ahead() for explicit control - Pre-fill now uses fill_audio_buffer() (same logic as main loop) - Ensures consistent tempo scaling and time advancement - Reduced pre-fill from 400ms to 100ms (was blocking visuals) - All 33 tests passing handoff(Claude): Fixed audio startup silence/suspension issue
Diffstat (limited to 'src')
-rw-r--r--src/audio/audio.cc6
-rw-r--r--src/audio/audio.h3
-rw-r--r--src/main.cc8
-rw-r--r--src/test_demo.cc6
4 files changed, 11 insertions, 12 deletions
diff --git a/src/audio/audio.cc b/src/audio/audio.cc
index 2f485a6..c5bd3d9 100644
--- a/src/audio/audio.cc
+++ b/src/audio/audio.cc
@@ -65,9 +65,11 @@ void audio_start() {
g_audio_backend->start();
}
-void audio_render_ahead(float music_time, float dt) {
+void audio_render_ahead(float music_time, float dt, float target_fill) {
// Target: maintain look-ahead buffer
- const float target_lookahead = (float)RING_BUFFER_LOOKAHEAD_MS / 1000.0f;
+ const float target_lookahead = (target_fill < 0.0f)
+ ? (float)RING_BUFFER_LOOKAHEAD_MS / 1000.0f
+ : target_fill;
// Render in small chunks to keep synth time synchronized with tracker
// Chunk size: one frame's worth of audio (~16.6ms @ 60fps)
diff --git a/src/audio/audio.h b/src/audio/audio.h
index e063a57..778d312 100644
--- a/src/audio/audio.h
+++ b/src/audio/audio.h
@@ -24,7 +24,8 @@ void audio_init();
void audio_start(); // Starts the audio device callback
// Ring buffer audio rendering (main thread fills buffer)
-void audio_render_ahead(float music_time, float dt);
+// target_fill: Target buffer fill time in seconds (default: RING_BUFFER_LOOKAHEAD_MS/1000)
+void audio_render_ahead(float music_time, float dt, float target_fill = -1.0f);
// Get current playback time (in seconds) based on samples consumed
// This is the ring buffer READ position (what's being played NOW)
diff --git a/src/main.cc b/src/main.cc
index 4c44a78..59001fb 100644
--- a/src/main.cc
+++ b/src/main.cc
@@ -160,13 +160,9 @@ int main(int argc, char** argv) {
}
#endif /* !defined(STRIP_ALL) */
- // PRE-FILL: Fill ring buffer with initial 200ms before starting audio device
- // This prevents underrun on first callback
- g_audio_engine.update(g_music_time, 1.0f / 60.0f);
- audio_render_ahead(g_music_time,
- 1.0f / 60.0f); // Fill buffer with lookahead
+ // Pre-fill using same pattern as main loop (100ms)
+ fill_audio_buffer(0.1f, 0.0);
- // Start audio (or render to WAV file)
audio_start();
g_last_audio_time = audio_get_playback_time(); // Initialize after start
diff --git a/src/test_demo.cc b/src/test_demo.cc
index 749ef01..b8e9381 100644
--- a/src/test_demo.cc
+++ b/src/test_demo.cc
@@ -266,9 +266,9 @@ int main(int argc, char** argv) {
audio_render_ahead(g_music_time, audio_dt * g_tempo_scale);
};
- // Pre-fill audio buffer
- g_audio_engine.update(g_music_time, 1.0f / 60.0f);
- audio_render_ahead(g_music_time, 1.0f / 60.0f);
+ // Pre-fill using same pattern as main loop (100ms)
+ fill_audio_buffer(0.1f, 0.0);
+
audio_start();
g_last_audio_time = audio_get_playback_time();