From d50e0ecbacb9eb4da146e2aff772692fb8c683c4 Mon Sep 17 00:00:00 2001 From: Kai Hagseth Date: Sun, 27 Feb 2022 17:12:41 +0100 Subject: [PATCH] fix: follow default output source on mac osx When playing out on default output source, follow the default output source chosen in sound preferences in osx. --- src/host/coreaudio/macos/enumerate.rs | 11 +++++++++-- src/host/coreaudio/macos/mod.rs | 8 +++++++- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/host/coreaudio/macos/enumerate.rs b/src/host/coreaudio/macos/enumerate.rs index 575b740..8d15f18 100644 --- a/src/host/coreaudio/macos/enumerate.rs +++ b/src/host/coreaudio/macos/enumerate.rs @@ -83,6 +83,7 @@ impl Iterator for Devices { fn next(&mut self) -> Option { self.0.next().map(|id| Device { audio_device_id: id, + is_default: false, }) } } @@ -110,7 +111,10 @@ pub fn default_input_device() -> Option { return None; } - let device = Device { audio_device_id }; + let device = Device { + audio_device_id, + is_default: true, + }; Some(device) } @@ -137,7 +141,10 @@ pub fn default_output_device() -> Option { return None; } - let device = Device { audio_device_id }; + let device = Device { + audio_device_id, + is_default: true, + }; Some(device) } diff --git a/src/host/coreaudio/macos/mod.rs b/src/host/coreaudio/macos/mod.rs index 7a96fa6..e96d708 100644 --- a/src/host/coreaudio/macos/mod.rs +++ b/src/host/coreaudio/macos/mod.rs @@ -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 { @@ -421,7 +422,12 @@ struct StreamInner { } fn audio_unit_from_device(device: &Device, input: bool) -> Result { - 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.