]> code.octet-stream.net Git - m17rt/blob - tools/m17rt-soundcards/src/main.rs
Update crates to 2024 edition
[m17rt] / tools / m17rt-soundcards / src / main.rs
1 use ascii_table::{Align, AsciiTable};
2 use m17app::soundcard::Soundcard;
3 use m17codec2::{rx::Codec2RxAdapter, tx::Codec2TxAdapter};
4
5 fn main() {
6 // On some platforms enumerating devices will emit junk to the terminal:
7 // https://github.com/RustAudio/cpal/issues/384
8 // To minimise the impact, enumerate first and put our output at the end.
9 let soundmodem_in = Soundcard::supported_input_cards();
10 let soundmodem_out = Soundcard::supported_output_cards();
11 let codec2_in = Codec2TxAdapter::supported_input_cards();
12 let codec2_out = Codec2RxAdapter::supported_output_cards();
13
14 println!("\nDetected sound cards compatible with M17 Rust Toolkit:");
15
16 generate_table(
17 "SOUNDMODEM",
18 "INPUT",
19 "OUTPUT",
20 &soundmodem_in,
21 &soundmodem_out,
22 );
23 generate_table("CODEC2 AUDIO", "TX", "RX", &codec2_in, &codec2_out);
24 }
25
26 fn generate_table(
27 heading: &str,
28 input: &str,
29 output: &str,
30 input_cards: &[String],
31 output_cards: &[String],
32 ) {
33 let mut merged: Vec<&str> = input_cards
34 .iter()
35 .chain(output_cards.iter())
36 .map(|s| s.as_str())
37 .collect();
38 merged.sort();
39 merged.dedup();
40 let yes = "OK";
41 let no = "";
42 let data = merged.into_iter().map(|c| {
43 [
44 c,
45 if input_cards.iter().any(|s| s == c) {
46 yes
47 } else {
48 no
49 },
50 if output_cards.iter().any(|s| s == c) {
51 yes
52 } else {
53 no
54 },
55 ]
56 });
57
58 let mut table = AsciiTable::default();
59 table.column(0).set_header(heading).set_align(Align::Left);
60 table.column(1).set_header(input).set_align(Align::Center);
61 table.column(2).set_header(output).set_align(Align::Center);
62 table.print(data);
63 }