From 747caeee38adbe974f4d8f7aa1dc8a3cbf430b9d Mon Sep 17 00:00:00 2001 From: mitchmindtree Date: Thu, 27 Jun 2019 21:29:06 +1000 Subject: [PATCH] Get asio-sys examples working with latest API updates --- asio-sys/examples/enumerate.rs | 47 +++++++++++----------------------- asio-sys/examples/test.rs | 9 +++---- 2 files changed, 18 insertions(+), 38 deletions(-) diff --git a/asio-sys/examples/enumerate.rs b/asio-sys/examples/enumerate.rs index df29ce4..bcbc95b 100644 --- a/asio-sys/examples/enumerate.rs +++ b/asio-sys/examples/enumerate.rs @@ -34,39 +34,22 @@ pub struct Format { } fn main() { - let driver_list = sys::get_driver_list(); - - let format = Format { - channels: 0, - sample_rate: SampleRate(0), - // TODO Not sure about how to set the data type - data_type: SampleFormat::F32, - }; - if driver_list.len() > 0 { - let format = match sys::get_channels(&driver_list[0]) { - Ok(channels) => Format { - channels: channels.ins as u16, - sample_rate: format.sample_rate, - data_type: format.data_type, - }, - Err(e) => { - println!("Error retrieving channels: {}", e); - format - } + for name in sys::get_driver_list() { + println!("Driver: {:?}", name); + let driver = sys::Drivers::load(&name).expect("failed to load driver"); + let channels = driver.get_channels(); + let sample_rate = driver.get_sample_rate(); + let in_fmt = Format { + channels: channels.ins as _, + sample_rate: SampleRate(sample_rate.rate as _), + data_type: SampleFormat::F32, }; - - let format = match sys::get_sample_rate(&driver_list[0]) { - Ok(sample_rate) => Format { - channels: format.channels, - sample_rate: SampleRate(sample_rate.rate), - data_type: format.data_type, - }, - Err(e) => { - println!("Error retrieving sample rate: {}", e); - format - } + let out_fmt = Format { + channels: channels.outs as _, + sample_rate: SampleRate(sample_rate.rate as _), + data_type: SampleFormat::F32, }; - - println!("Format {:?}", format); + println!(" Input {:?}", in_fmt); + println!(" Output {:?}", out_fmt); } } diff --git a/asio-sys/examples/test.rs b/asio-sys/examples/test.rs index 88d532e..a9d77d9 100644 --- a/asio-sys/examples/test.rs +++ b/asio-sys/examples/test.rs @@ -5,12 +5,9 @@ fn main() { for driver in &driver_list { println!("Driver: {}", driver); - } - if driver_list.len() > 0 { - match sys::get_channels(&driver_list[0]) { - Ok(channels) => println!("Channels: {:?}", channels), - Err(e) => println!("Error retrieving channels: {}", e), - } + let driver = sys::Drivers::load(driver).expect("failed to load drivers"); + println!(" Channels: {:?}", driver.get_channels()); + println!(" Sample rate: {:?}", driver.get_sample_rate()); } }