mirror of
https://github.com/ivabus/speakersafetyd
synced 2024-11-22 16:25:06 +03:00
Automatically select the sample rate if zero
This allows the sense PCM to be opened at the correct current rate if playback is active, or otherwise arbitrarily picks the lowest rate. Signed-off-by: Hector Martin <marcan@marcan.st>
This commit is contained in:
parent
21b3e49456
commit
5c47bc3e94
2 changed files with 10 additions and 3 deletions
|
@ -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)
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
Loading…
Reference in a new issue