Explicitly set start_threshold and pretty print devices

This commit is contained in:
ashthespy 2018-11-02 15:24:43 +01:00
parent cc6c9b2dc4
commit 8fd0caf583

View file

@ -14,7 +14,12 @@ fn list_outputs() {
let i = HintIter::new(None, &*CString::new(*t).unwrap()).unwrap();
for a in i {
if let Some(Direction::Playback) = a.direction {
println!("{}\n\t{}", a.name.unwrap(), a.desc.unwrap());
// mimic aplay -L
println!(
"{}\n\t{}\n",
a.name.unwrap(),
a.desc.unwrap().replace("\n", "\n\t")
);
}
}
}
@ -37,8 +42,11 @@ fn open_device(dev_name: &str) -> Result<(PCM), Box<Error>> {
hwp.set_rate(44100, ValueOr::Nearest)?;
hwp.set_channels(2)?;
hwp.set_buffer_size_near(22050)?; // ~ 0.5s latency
pcm.hw_params(&hwp)?;
let swp = pcm.sw_params_current()?;
swp.set_start_threshold(hwp.get_buffer_size()? - hwp.get_period_size()?)?;
pcm.sw_params(&swp)?;
}
Ok(pcm)