From 8fd0caf583e7def555cfbb595d88d709980ae0a8 Mon Sep 17 00:00:00 2001 From: ashthespy Date: Fri, 2 Nov 2018 15:24:43 +0100 Subject: [PATCH] Explicitly set `start_threshold` and pretty print devices --- playback/src/audio_backend/alsa.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/playback/src/audio_backend/alsa.rs b/playback/src/audio_backend/alsa.rs index 0e18708b..98e7c8f7 100644 --- a/playback/src/audio_backend/alsa.rs +++ b/playback/src/audio_backend/alsa.rs @@ -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> { 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)