From b099c5ec0595cdb2b6f55cc871c6dd4636e94775 Mon Sep 17 00:00:00 2001 From: Arnaud Gourlay Date: Thu, 12 Sep 2024 08:29:23 +0200 Subject: [PATCH] Investigate audio buffer sizing --- src/audio/midi_player.rs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/audio/midi_player.rs b/src/audio/midi_player.rs index 60e3718..ba02062 100644 --- a/src/audio/midi_player.rs +++ b/src/audio/midi_player.rs @@ -200,6 +200,12 @@ fn new_output_stream( format!("Unsupported sample format {}", config.sample_format()) ); let stream_config: cpal::StreamConfig = config.into(); + log::warn!( + "Audio output stream config: {:?} ({} channels, {} Hz)", + stream_config, + stream_config.channels, + stream_config.sample_rate.0 + ); let sample_rate = stream_config.sample_rate.0; let mut synthesizer_guard = synthesizer.lock().unwrap(); @@ -303,11 +309,11 @@ fn new_output_stream( } } // Split buffer for this run between left and right - let channel_len = output.len() / 2; + let mut channel_len = output.len() / 2; if left.len() < channel_len || right.len() < channel_len { - log::info!("Buffer too small, skipping audio rendering"); - return; + log::info!("Buffer too small {}<{}", left.len(), channel_len); + channel_len = left.len() } // Render the waveform.