accept lower sample rates if 16k not avail
parent
53e675b9a0
commit
4c80247ab9
|
|
@ -96,13 +96,22 @@ impl Listener {
|
|||
filter(|device| device.name().unwrap() == self.device_name).
|
||||
collect::<Vec<_>>();
|
||||
let device = devices.first().unwrap();
|
||||
let cfg = device.supported_input_configs()
|
||||
let mut sample_rate = 15_500;
|
||||
let mut cfgs: Vec<_> = device.supported_input_configs()
|
||||
.unwrap()
|
||||
.filter(|x| x.sample_format() == cpal::SampleFormat::F32)
|
||||
.filter(|x| x.min_sample_rate() >= cpal::SampleRate(15_500))
|
||||
.nth(0)
|
||||
.unwrap()
|
||||
.with_max_sample_rate();
|
||||
.filter(|x| x.min_sample_rate() >= cpal::SampleRate(sample_rate))
|
||||
.collect();
|
||||
while cfgs.len() == 0 && sample_rate > 0 {
|
||||
sample_rate /= 2;
|
||||
cfgs = device.supported_input_configs()
|
||||
.unwrap()
|
||||
.filter(|x| x.sample_format() == cpal::SampleFormat::F32)
|
||||
.filter(|x| x.min_sample_rate() >= cpal::SampleRate(sample_rate))
|
||||
.collect();
|
||||
}
|
||||
assert!(cfgs.len() > 0);
|
||||
let cfg = cfgs[0].clone().with_max_sample_rate();
|
||||
|
||||
let downsample_ratio = cfg.channels() as f32 * (cfg.sample_rate().0 as f32 / 16_000.0);
|
||||
let stream = device.build_input_stream(
|
||||
|
|
|
|||
Loading…
Reference in New Issue