Skip to content
4 changes: 2 additions & 2 deletions src/host/coreaudio/macos/enumerate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ pub fn default_input_device() -> Option<Device> {
NonNull::from(&mut audio_device_id).cast(),
)
};
if status != kAudioHardwareNoError as i32 {
if status != kAudioHardwareNoError {
return None;
}

Expand Down Expand Up @@ -135,7 +135,7 @@ pub fn default_output_device() -> Option<Device> {
NonNull::from(&mut audio_device_id).cast(),
)
};
if status != kAudioHardwareNoError as i32 {
if status != kAudioHardwareNoError {
return None;
}

Expand Down
47 changes: 41 additions & 6 deletions src/host/coreaudio/macos/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@ use objc2_core_audio::{
kAudioDevicePropertyAvailableNominalSampleRates, kAudioDevicePropertyBufferFrameSize,
kAudioDevicePropertyBufferFrameSizeRange, kAudioDevicePropertyDeviceIsAlive,
kAudioDevicePropertyNominalSampleRate, kAudioDevicePropertyStreamConfiguration,
kAudioDevicePropertyStreamFormat, kAudioObjectPropertyElementMaster,
kAudioDevicePropertyStreamFormat, kAudioHardwarePropertyDefaultInputDevice,
kAudioHardwarePropertyDefaultOutputDevice, kAudioObjectPropertyElementMaster,
kAudioObjectPropertyScopeGlobal, kAudioObjectPropertyScopeInput,
kAudioObjectPropertyScopeOutput, AudioDeviceID, AudioObjectGetPropertyData,
AudioObjectGetPropertyDataSize, AudioObjectID, AudioObjectPropertyAddress,
AudioObjectPropertyScope, AudioObjectSetPropertyData,
kAudioObjectPropertyScopeOutput, kAudioObjectSystemObject, AudioDeviceID,
AudioObjectGetPropertyData, AudioObjectGetPropertyDataSize, AudioObjectID,
AudioObjectPropertyAddress, AudioObjectPropertyScope, AudioObjectSetPropertyData,
};
use objc2_core_audio_types::{
AudioBuffer, AudioBufferList, AudioStreamBasicDescription, AudioValueRange,
Expand Down Expand Up @@ -164,10 +165,44 @@ impl Device {
/// Construct a new device given its ID.
/// Useful for constructing hidden devices.
pub fn new(audio_device_id: AudioDeviceID) -> Self {
// Get default input device ID.
let mut property_address = AudioObjectPropertyAddress {
mSelector: kAudioHardwarePropertyDefaultInputDevice,
mScope: kAudioObjectPropertyScopeGlobal,
mElement: kAudioObjectPropertyElementMaster,
};

let mut default_input_device_id: AudioDeviceID = 0;
let data_size = mem::size_of::<AudioDeviceID>() as u32;
let input_status = unsafe {
AudioObjectGetPropertyData(
kAudioObjectSystemObject as AudioObjectID,
NonNull::from(&property_address),
0,
null(),
NonNull::from(&data_size),
NonNull::from(&mut default_input_device_id).cast(),
)
};

// Get default output device ID.
property_address.mSelector = kAudioHardwarePropertyDefaultOutputDevice;

let mut default_output_device_id: AudioDeviceID = 0;
let output_status = unsafe {
AudioObjectGetPropertyData(
kAudioObjectSystemObject as AudioObjectID,
NonNull::from(&property_address),
0,
null(),
NonNull::from(&data_size),
NonNull::from(&mut default_output_device_id).cast(),
)
};
Device {
audio_device_id,
// TODO: This could be made to detect the default device properly.
is_default: false,
is_default: (default_input_device_id == audio_device_id && input_status == 0)
|| (default_output_device_id == audio_device_id && output_status == 0),
}
}

Expand Down
1 change: 0 additions & 1 deletion src/host/coreaudio/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ pub use self::macos::{
};

/// Common helper methods used by both macOS and iOS

fn check_os_status(os_status: OSStatus) -> Result<(), BackendSpecificError> {
match coreaudio::Error::from_os_status(os_status) {
Ok(()) => Ok(()),
Expand Down
6 changes: 2 additions & 4 deletions src/samples_formats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,13 @@ pub enum SampleFormat {
/// `u16` with a valid range of `u16::MIN..=u16::MAX` with `1 << 15 == 32768` being the origin.
U16,

/// `U24` with a valid range of '0..16777216' with `1 << 23 == 8388608` being the origin
// /// `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` 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,

Expand Down
Loading