Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions src/host/alsa/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -869,7 +869,7 @@ fn set_hw_params_from_format<'a>(
config: &StreamConfig,
sample_format: SampleFormat,
) -> Result<alsa::pcm::HwParams<'a>, 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") {
Expand All @@ -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)?;

Expand Down