enumerate/
enumerate.rs

1/* This example aims to produce the same behaviour
2 * as the enumerate example in cpal
3 * by Tom Gowan
4 */
5
6extern crate asio_sys as sys;
7
8// This is the same data that enumerate
9// is trying to find
10// Basically these are stubbed versions
11//
12// Format that each sample has.
13#[derive(Clone, Copy, Debug, PartialEq, Eq)]
14pub enum SampleFormat {
15    // The value 0 corresponds to 0.
16    I16,
17    // The value 0 corresponds to 32768.
18    U16,
19    // The boundaries are (-1.0, 1.0).
20    F32,
21}
22// Number of channels.
23pub type ChannelCount = u16;
24
25// The number of samples processed per second for a single channel of audio.
26pub type SampleRate = u32;
27
28#[derive(Debug, Clone, PartialEq, Eq)]
29pub struct Format {
30    pub channels: ChannelCount,
31    pub sample_rate: SampleRate,
32    pub data_type: SampleFormat,
33}
34
35fn main() {
36    let asio = sys::Asio::new();
37    for name in asio.driver_names() {
38        println!("Driver: {:?}", name);
39        let driver = asio.load_driver(&name).expect("failed to load driver");
40        let channels = driver
41            .channels()
42            .expect("failed to retrieve channel counts");
43        let sample_rate = driver
44            .sample_rate()
45            .expect("failed to retrieve sample rate");
46        let in_fmt = Format {
47            channels: channels.ins as _,
48            sample_rate: sample_rate as _,
49            data_type: SampleFormat::F32,
50        };
51        let out_fmt = Format {
52            channels: channels.outs as _,
53            sample_rate: sample_rate as _,
54            data_type: SampleFormat::F32,
55        };
56        println!("  Input {:?}", in_fmt);
57        println!("  Output {:?}", out_fmt);
58    }
59}