Open
Description
I am using a x86 Linux machine, when trying to use the default device, e.g. using examples/recorder_wav.rs it fails with this output
Running `target/debug/examples/record_wav`
Default input device: default
ALSA lib confmisc.c:767:(parse_card) cannot find card '0'
ALSA lib conf.c:4528:(_snd_config_evaluate) function snd_func_card_driver returned error: No such file or directory
ALSA lib confmisc.c:392:(snd_func_concat) error evaluating strings
ALSA lib conf.c:4528:(_snd_config_evaluate) function snd_func_concat returned error: No such file or directory
ALSA lib confmisc.c:1246:(snd_func_refer) error evaluating name
ALSA lib conf.c:4528:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directory
ALSA lib conf.c:5007:(snd_config_expand) Evaluate error: No such file or directory
ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM default
thread 'main' panicked at 'Failed to get default input format: DeviceNotAvailable', libcore/result.rs:945:5
note: Run with `RUST_BACKTRACE=1` for a backtrace.
The enumerate example works, this is the first few lines of output:
Running `target/debug/examples/enumerate`
Default Input Device:
Some("default")
Default Output Device:
Some("default")
Devices:
1. "default:CARD=AT2020USB"
Default input stream format:
Format { channels: 2, sample_rate: SampleRate(44100), data_type: F32 }
All supported input stream formats:
1.1. SupportedFormat { channels: 1, min_sample_rate: SampleRate(4000), max_sample_rate: SampleRate(4294967295), data_type: I16 }
As a workaround changing the record example to use the first input device and not the default device (which are the same device...), solves this issue, as following:
fn main() {
// Setup the default input device and stream with the default input format.
// ORIGINAL API:
// let device = cpal::default_input_device().expect("Failed to get default input device");
// WORKAROUND:
let device = cpal::devices().nth(0).unwrap();
println!("Default input device: {}", device.name());
let format = device.default_input_format().expect("Failed to get default input format");