From b1228fc3ff7835b3fd0c33489527fc44601c649b Mon Sep 17 00:00:00 2001 From: Alex Butler Date: Sat, 31 Aug 2019 13:33:57 +0100 Subject: [PATCH] Alsa: Set buffer size near to 100ms --- src/host/alsa/mod.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/host/alsa/mod.rs b/src/host/alsa/mod.rs index e030cd1..909c67b 100644 --- a/src/host/alsa/mod.rs +++ b/src/host/alsa/mod.rs @@ -1116,6 +1116,16 @@ unsafe fn set_hw_params_from_format( return Err(format!("channel count could not be set: {}", e)); } + // If this isn't set manually a overlarge buffer may be used causing audio delay + if let Err(e) = check_errors(alsa::snd_pcm_hw_params_set_buffer_time_near( + pcm_handle, + hw_params.0, + &mut 100_000, + &mut 0, + )) { + return Err(format!("buffer time could not be set: {}", e)); + } + if let Err(e) = check_errors(alsa::snd_pcm_hw_params(pcm_handle, hw_params.0)) { return Err(format!("hardware params could not be set: {}", e)); }