]>
code.octet-stream.net Git - m17rt/blob - m17codec2/src/soundcards.rs
1 //! Utilities for selecting suitable sound cards.
4 traits
::{DeviceTrait
, HostTrait
},
8 /// List sound cards supported for audio output.
10 /// M17RT will handle any card with 1 or 2 channels and 16-bit output.
11 pub fn supported_output_cards() -> Vec
<String
> {
13 let host
= cpal
::default_host();
14 let Ok(output_devices
) = host
.output_devices() else {
17 for d
in output_devices
{
18 let Ok(mut configs
) = d
.supported_output_configs() else {
21 if configs
.any(|config
| {
22 (config
.channels() == 1 || config
.channels() == 2)
23 && config
.sample_format() == SampleFormat
::I16
25 let Ok(name
) = d
.name() else {
35 /// List sound cards supported for audio input.
38 /// M17RT will handle any card with 1 or 2 channels and 16-bit output.
39 pub fn supported_input_cards() -> Vec
<String
> {
41 let host
= cpal
::default_host();
42 let Ok(input_devices
) = host
.inp
ut
_dev
ices
() else {
45 for d
in input_devices
{
46 let Ok(mut configs
) = d
.supported_input_configs() else {
49 if configs
.any(|config
| {
50 (config
.channels() == 1 || config
.channels() == 2)
51 && config
.sample_format() == SampleFormat
::I16
53 let Ok(name
) = d
.name() else {