Skip to content

Commit

Permalink
Merge pull request RustAudio#648 from kaihagseth/fix/follow-default-osx
Browse files Browse the repository at this point in the history
fix: follow default output source on mac osx
  • Loading branch information
est31 authored Feb 28, 2022
2 parents bf026fe + d50e0ec commit 9748543
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
11 changes: 9 additions & 2 deletions src/host/coreaudio/macos/enumerate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ impl Iterator for Devices {
fn next(&mut self) -> Option<Device> {
self.0.next().map(|id| Device {
audio_device_id: id,
is_default: false,
})
}
}
Expand Down Expand Up @@ -110,7 +111,10 @@ pub fn default_input_device() -> Option<Device> {
return None;
}

let device = Device { audio_device_id };
let device = Device {
audio_device_id,
is_default: true,
};
Some(device)
}

Expand All @@ -137,7 +141,10 @@ pub fn default_output_device() -> Option<Device> {
return None;
}

let device = Device { audio_device_id };
let device = Device {
audio_device_id,
is_default: true,
};
Some(device)
}

Expand Down
8 changes: 7 additions & 1 deletion src/host/coreaudio/macos/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ impl DeviceTrait for Device {
#[derive(Clone, PartialEq, Eq)]
pub struct Device {
pub(crate) audio_device_id: AudioDeviceID,
is_default: bool,
}

impl Device {
Expand Down Expand Up @@ -421,7 +422,12 @@ struct StreamInner {
}

fn audio_unit_from_device(device: &Device, input: bool) -> Result<AudioUnit, coreaudio::Error> {
let mut audio_unit = AudioUnit::new(coreaudio::audio_unit::IOType::HalOutput)?;
let output_type = if device.is_default && !input {
coreaudio::audio_unit::IOType::DefaultOutput
} else {
coreaudio::audio_unit::IOType::HalOutput
};
let mut audio_unit = AudioUnit::new(output_type)?;

if input {
// Enable input processing.
Expand Down

0 comments on commit 9748543

Please sign in to comment.