diff --git a/src/host/alsa/mod.rs b/src/host/alsa/mod.rs index bce4549ed..baddd37b5 100644 --- a/src/host/alsa/mod.rs +++ b/src/host/alsa/mod.rs @@ -869,7 +869,7 @@ fn set_hw_params_from_format<'a>( config: &StreamConfig, sample_format: SampleFormat, ) -> Result, BackendSpecificError> { - let mut hw_params = alsa::pcm::HwParams::any(pcm_handle)?; + let hw_params = alsa::pcm::HwParams::any(pcm_handle)?; hw_params.set_access(alsa::pcm::Access::RWInterleaved)?; let sample_format = if cfg!(target_endian = "big") { @@ -890,12 +890,10 @@ fn set_hw_params_from_format<'a>( hw_params.set_rate(config.sample_rate.0, alsa::ValueOr::Nearest)?; hw_params.set_channels(config.channels as u32)?; - // If this isn't set manually a overlarge buffer may be used causing audio delay - let mut hw_params_copy = hw_params.clone(); - if let Err(_) = hw_params.set_buffer_time_near(100_000, alsa::ValueOr::Nearest) { - // Swap out the params with errors for a snapshot taken before the error was introduced. - mem::swap(&mut hw_params_copy, &mut hw_params); - } + // These values together represent a moderate latency and wakeup interval. + // Without them we are at the mercy of the device + hw_params.set_period_time_near(25_000, alsa::ValueOr::Nearest)?; + hw_params.set_buffer_time_near(100_000, alsa::ValueOr::Nearest)?; pcm_handle.hw_params(&hw_params)?;