summaryrefslogtreecommitdiff
path: root/src/audio.rs
diff options
context:
space:
mode:
authorJustin Worthe <justin@worthe-it.co.za>2017-07-05 20:25:48 +0200
committerJustin Worthe <justin@worthe-it.co.za>2017-07-05 20:25:48 +0200
commit4048c4f9bfeea1827ed004ae9d1961bd0a78a1bb (patch)
treebaae31b5f5afaaadeb177fc53c9319476bd4aa4d /src/audio.rs
parent85ac457388422c3a3f0ed8155ca6506276e3efd1 (diff)
Started listening on default microphone on startup
Diffstat (limited to 'src/audio.rs')
-rw-r--r--src/audio.rs12
1 files changed, 11 insertions, 1 deletions
diff --git a/src/audio.rs b/src/audio.rs
index 9a5ea0e..c7cea54 100644
--- a/src/audio.rs
+++ b/src/audio.rs
@@ -24,6 +24,11 @@ pub fn get_device_list(pa: &pa::PortAudio) -> Result<Vec<(u32, String)>, pa::Err
Ok(list)
}
+pub fn get_default_device(pa: &pa::PortAudio) -> Result<u32, pa::Error> {
+ let pa::DeviceIndex(default_input_index) = pa.default_input_device()?;
+ Ok(default_input_index)
+}
+
#[test]
#[ignore]
fn get_device_list_returns_devices() {
@@ -35,8 +40,13 @@ fn get_device_list_returns_devices() {
assert!(devices.len() > 0);
}
+pub fn start_listening_default(pa: &pa::PortAudio, sender: Sender<Vec<f64>>) -> Result<pa::Stream<pa::NonBlocking, pa::Input<f32>>, pa::Error> {
+ let default = get_default_device(&pa)?;
+ start_listening(&pa, default, sender)
+}
+
pub fn start_listening(pa: &pa::PortAudio, device_index: u32,
- sender: Sender<Vec<f64>>) -> Result<pa::Stream<pa::NonBlocking, pa::Input<f32>>, pa::Error> {
+ sender: Sender<Vec<f64>>) -> Result<pa::Stream<pa::NonBlocking, pa::Input<f32>>, pa::Error> {
let device_info = try!(pa.device_info(pa::DeviceIndex(device_index)));
let latency = device_info.default_low_input_latency;