diff --git a/src/helpers.rs b/src/helpers.rs index 77ddf91..d139701 100644 --- a/src/helpers.rs +++ b/src/helpers.rs @@ -40,11 +40,19 @@ pub fn open_card(card: &str) -> alsa::ctl::Ctl { return ctldev; } -pub fn open_pcm(dev: &str, chans: u32, sample_rate: u32) -> alsa::pcm::PCM { +pub fn open_pcm(dev: &str, chans: u32, mut sample_rate: u32) -> alsa::pcm::PCM { let pcm = alsa::pcm::PCM::new(dev, alsa::Direction::Capture, false).unwrap(); { let params = alsa::pcm::HwParams::any(&pcm).unwrap(); + let rate_max = params.get_rate_max().unwrap(); + let rate_min = params.get_rate_min().unwrap(); + println!("PCM rate: {}..{}", rate_min, rate_max); + + if sample_rate == 0 { + sample_rate = rate_min; + } + params.set_channels(chans).unwrap(); params .set_rate(sample_rate, alsa::ValueOr::Nearest) diff --git a/src/main.rs b/src/main.rs index 3a673f7..6ecf795 100644 --- a/src/main.rs +++ b/src/main.rs @@ -137,8 +137,7 @@ fn main() { let pcm_name = format!("{},{}", device, globals.visense_pcm); // Set up PCM to buffer in V/ISENSE - let pcm: alsa::pcm::PCM = - helpers::open_pcm(&pcm_name, globals.channels.try_into().unwrap(), 48000); + let pcm: alsa::pcm::PCM = helpers::open_pcm(&pcm_name, globals.channels.try_into().unwrap(), 0); let mut buf = Vec::new(); buf.resize(globals.period * globals.channels, 0i16);