Skip to content

Commit

Permalink
Investigate audio buffer sizing
Browse files Browse the repository at this point in the history
  • Loading branch information
agourlay committed Sep 12, 2024
1 parent 21de214 commit b099c5e
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/audio/midi_player.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit b099c5e

Please sign in to comment.