diff --git a/CHANGELOG.md b/CHANGELOG.md index d17fb6145..b3f6277db 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,8 @@ # Unreleased -- ALSA(process_output): pass `silent=true` to `PCM.try_recover`, so it doesn't write to stderr. +- ALSA(process_output): Pass `silent=true` to `PCM.try_recover`, so it doesn't write to stderr. - CoreAudio: `Device::supported_configs` now returns a single element containing the available sample rate range when all elements have the same `mMinimum` and `mMaximum` values (which is the most common case). +- CoreAudio: Detect default audio device lazily when building a stream, instead of during device enumeration. - iOS: Fix example by properly activating audio session. - WASAPI: Expose IMMDevice from WASAPI host Device. diff --git a/src/host/coreaudio/macos/enumerate.rs b/src/host/coreaudio/macos/enumerate.rs index 66d500174..806044883 100644 --- a/src/host/coreaudio/macos/enumerate.rs +++ b/src/host/coreaudio/macos/enumerate.rs @@ -81,7 +81,6 @@ impl Iterator for Devices { fn next(&mut self) -> Option { self.0.next().map(|id| Device { audio_device_id: id, - is_default: false, }) } } @@ -109,10 +108,7 @@ pub fn default_input_device() -> Option { return None; } - let device = Device { - audio_device_id, - is_default: true, - }; + let device = Device { audio_device_id }; Some(device) } @@ -139,10 +135,7 @@ pub fn default_output_device() -> Option { return None; } - let device = Device { - audio_device_id, - is_default: true, - }; + let device = Device { audio_device_id }; Some(device) } diff --git a/src/host/coreaudio/macos/mod.rs b/src/host/coreaudio/macos/mod.rs index 3fc5e6f20..c0809fa2f 100644 --- a/src/host/coreaudio/macos/mod.rs +++ b/src/host/coreaudio/macos/mod.rs @@ -159,18 +159,22 @@ impl DeviceTrait for Device { #[derive(Clone, PartialEq, Eq)] pub struct Device { pub(crate) audio_device_id: AudioDeviceID, - is_default: bool, +} + +fn is_default_device(device: &Device) -> bool { + default_input_device() + .map(|d| d.audio_device_id == device.audio_device_id) + .unwrap_or(false) + || default_output_device() + .map(|d| d.audio_device_id == device.audio_device_id) + .unwrap_or(false) } impl Device { /// Construct a new device given its ID. /// Useful for constructing hidden devices. pub fn new(audio_device_id: AudioDeviceID) -> Self { - Device { - audio_device_id, - // TODO: This could be made to detect the default device properly. - is_default: false, - } + Self { audio_device_id } } fn name(&self) -> Result { @@ -523,7 +527,7 @@ where } fn audio_unit_from_device(device: &Device, input: bool) -> Result { - let output_type = if device.is_default && !input { + let output_type = if is_default_device(device) && !input { coreaudio::audio_unit::IOType::DefaultOutput } else { coreaudio::audio_unit::IOType::HalOutput @@ -665,7 +669,7 @@ impl Device { // If we didn't request the default device, stop the stream if the // device disconnects. - if !self.is_default { + if !is_default_device(self) { add_disconnect_listener(&stream, error_callback_disconnect)?; } @@ -770,7 +774,7 @@ impl Device { // If we didn't request the default device, stop the stream if the // device disconnects. - if !self.is_default { + if !is_default_device(self) { add_disconnect_listener(&stream, error_callback_disconnect)?; } diff --git a/src/samples_formats.rs b/src/samples_formats.rs index 27e4fa46f..7888c9d94 100644 --- a/src/samples_formats.rs +++ b/src/samples_formats.rs @@ -48,13 +48,11 @@ pub enum SampleFormat { /// `U24` with a valid range of '0..16777216' with `1 << 23 == 8388608` being the origin // U24, - /// `u32` with a valid range of `u32::MIN..=u32::MAX` with `1 << 31` being the origin. U32, /// `U48` with a valid range of '0..(1 << 48)' with `1 << 47` being the origin // U48, - /// `u64` with a valid range of `u64::MIN..=u64::MAX` with `1 << 63` being the origin. U64,