Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ALSA: fix buffer size / period size configuration #1

Closed
wants to merge 1 commit into from
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
11 changes: 7 additions & 4 deletions src/host/alsa/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1061,16 +1061,19 @@ fn set_hw_params_from_format(
hw_params.set_rate(config.sample_rate.0, alsa::ValueOr::Nearest)?;
hw_params.set_channels(config.channels as u32)?;

const NPERIODS: u32 = 2;
match config.buffer_size {
BufferSize::Fixed(v) => {
hw_params.set_period_size_near((v / 4) as alsa::pcm::Frames, alsa::ValueOr::Nearest)?;
hw_params.set_buffer_size(v as alsa::pcm::Frames)?;
hw_params.set_period_size_near(v as alsa::pcm::Frames, alsa::ValueOr::Nearest)?;
hw_params.set_buffer_size((NPERIODS * v) as alsa::pcm::Frames)?;
}
BufferSize::Default => {
// 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)?;
const DEFAULT_PERIOD_SIZE: u32 = 1024;
const DEFAULT_BUFFER_SIZE: u32 = NPERIODS * DEFAULT_PERIOD_SIZE;
hw_params.set_period_time_near(DEFAULT_PERIOD_SIZE, alsa::ValueOr::Nearest)?;
hw_params.set_buffer_time_near(DEFAULT_BUFFER_SIZE, alsa::ValueOr::Nearest)?;
}
}

Expand Down