Skip to content

Update coreaudio-rs #943

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 19 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,27 @@ audio_thread_priority = { version = "0.33.0", optional = true }
jack = { version = "0.13.0", optional = true }

[target.'cfg(any(target_os = "macos", target_os = "ios"))'.dependencies]
core-foundation-sys = "0.8.2" # For linking to CoreFoundation.framework and handling device name `CFString`s.
mach2 = "0.4" # For access to mach_timebase type.

[target.'cfg(target_os = "macos")'.dependencies]
coreaudio-rs = { version = "0.11", default-features = false, features = ["audio_unit", "core_audio"] }

[target.'cfg(target_os = "ios")'.dependencies]
coreaudio-rs = { version = "0.11", default-features = false, features = ["audio_unit", "core_audio", "audio_toolbox"] }
[target.'cfg(target_vendor = "apple")'.dependencies]
coreaudio-rs = { version = "0.13.0", default-features = false, features = [
"core_audio",
"audio_toolbox",
] }
objc2-core-audio = { version = "0.3.1", default-features = false, features = [
"std",
"AudioHardware",
"AudioHardwareDeprecated",
] }
objc2-audio-toolbox = { version = "0.3.1", default-features = false, features = [
"std",
"AUComponent",
"AudioUnitProperties",
] }
objc2-core-audio-types = { version = "0.3.1", default-features = false, features = [
"std",
"CoreAudioBaseTypes",
] }

[target.'cfg(target_os = "emscripten")'.dependencies]
wasm-bindgen = { version = "0.2.89" }
Expand Down
13 changes: 4 additions & 9 deletions src/host/coreaudio/ios/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,12 @@
//! buffer size.
//!
extern crate core_foundation_sys;
extern crate coreaudio;

use std::cell::RefCell;

use self::coreaudio::audio_unit::render_callback::data;
use self::coreaudio::audio_unit::{render_callback, AudioUnit, Element, Scope};
use self::coreaudio::sys::{
kAudioOutputUnitProperty_EnableIO, kAudioUnitProperty_StreamFormat, AudioBuffer,
AudioStreamBasicDescription,
};
use coreaudio::audio_unit::render_callback::data;
use coreaudio::audio_unit::{render_callback, AudioUnit, Element, Scope};
use objc2_audio_toolbox::{kAudioOutputUnitProperty_EnableIO, kAudioUnitProperty_StreamFormat};
use objc2_core_audio_types::{AudioBuffer, AudioStreamBasicDescription};

use super::{asbd_from_config, frames_to_duration, host_time_to_stream_instant};
use crate::traits::{DeviceTrait, HostTrait, StreamTrait};
Expand Down
52 changes: 25 additions & 27 deletions src/host/coreaudio/macos/enumerate.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
extern crate coreaudio;

use self::coreaudio::sys::{
use super::{Device, OSStatus};
use crate::{BackendSpecificError, DevicesError, SupportedStreamConfigRange};
use objc2_core_audio::{
kAudioHardwareNoError, kAudioHardwarePropertyDefaultInputDevice,
kAudioHardwarePropertyDefaultOutputDevice, kAudioHardwarePropertyDevices,
kAudioObjectPropertyElementMaster, kAudioObjectPropertyScopeGlobal, kAudioObjectSystemObject,
AudioDeviceID, AudioObjectGetPropertyData, AudioObjectGetPropertyDataSize,
AudioObjectPropertyAddress, OSStatus,
AudioDeviceID, AudioObjectGetPropertyData, AudioObjectGetPropertyDataSize, AudioObjectID,
AudioObjectPropertyAddress,
};
use super::Device;
use crate::{BackendSpecificError, DevicesError, SupportedStreamConfigRange};
use std::mem;
use std::ptr::null;
use std::ptr::{null, NonNull};
use std::vec::IntoIter as VecIntoIter;

unsafe fn audio_devices() -> Result<Vec<AudioDeviceID>, OSStatus> {
Expand All @@ -30,11 +28,11 @@ unsafe fn audio_devices() -> Result<Vec<AudioDeviceID>, OSStatus> {

let data_size = 0u32;
let status = AudioObjectGetPropertyDataSize(
kAudioObjectSystemObject,
&property_address as *const _,
kAudioObjectSystemObject as AudioObjectID,
NonNull::from(&property_address),
0,
null(),
&data_size as *const _ as *mut _,
NonNull::from(&data_size),
);
try_status_or_return!(status);

Expand All @@ -43,12 +41,12 @@ unsafe fn audio_devices() -> Result<Vec<AudioDeviceID>, OSStatus> {
audio_devices.reserve_exact(device_count as usize);

let status = AudioObjectGetPropertyData(
kAudioObjectSystemObject,
&property_address as *const _,
kAudioObjectSystemObject as AudioObjectID,
NonNull::from(&property_address),
0,
null(),
&data_size as *const _ as *mut _,
audio_devices.as_mut_ptr() as *mut _,
NonNull::from(&data_size),
NonNull::new(audio_devices.as_mut_ptr()).unwrap().cast(),
);
try_status_or_return!(status);

Expand Down Expand Up @@ -95,16 +93,16 @@ pub fn default_input_device() -> Option<Device> {
mElement: kAudioObjectPropertyElementMaster,
};

let audio_device_id: AudioDeviceID = 0;
let data_size = mem::size_of::<AudioDeviceID>();
let mut audio_device_id: AudioDeviceID = 0;
let data_size = mem::size_of::<AudioDeviceID>() as u32;
let status = unsafe {
AudioObjectGetPropertyData(
kAudioObjectSystemObject,
&property_address as *const _,
kAudioObjectSystemObject as AudioObjectID,
NonNull::from(&property_address),
0,
null(),
&data_size as *const _ as *mut _,
&audio_device_id as *const _ as *mut _,
NonNull::from(&data_size),
NonNull::from(&mut audio_device_id).cast(),
)
};
if status != kAudioHardwareNoError as i32 {
Expand All @@ -125,16 +123,16 @@ pub fn default_output_device() -> Option<Device> {
mElement: kAudioObjectPropertyElementMaster,
};

let audio_device_id: AudioDeviceID = 0;
let data_size = mem::size_of::<AudioDeviceID>();
let mut audio_device_id: AudioDeviceID = 0;
let data_size = mem::size_of::<AudioDeviceID>() as u32;
let status = unsafe {
AudioObjectGetPropertyData(
kAudioObjectSystemObject,
&property_address as *const _,
kAudioObjectSystemObject as AudioObjectID,
NonNull::from(&property_address),
0,
null(),
&data_size as *const _ as *mut _,
&audio_device_id as *const _ as *mut _,
NonNull::from(&data_size),
NonNull::from(&mut audio_device_id).cast(),
)
};
if status != kAudioHardwareNoError as i32 {
Expand Down
Loading