Skip to content

Commit

Permalink
continue on core audio
Browse files Browse the repository at this point in the history
  • Loading branch information
yury committed Jan 16, 2025
1 parent 3012955 commit 076f244
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 3 deletions.
51 changes: 49 additions & 2 deletions cidre/src/core_audio/hardware.rs
Original file line number Diff line number Diff line change
Expand Up @@ -369,9 +369,16 @@ impl System {
}

#[doc(alias = "kAudioHardwarePropertyClockDeviceList")]
pub fn clock_device_list() -> os::Result<Vec<Clock>> {
pub fn clocks() -> os::Result<Vec<Clock>> {
Self::OBJ.prop_vec(&PropSelector::HARDWARE_CLOCK_DEVICE_LIST.global_addr())
}

/// An array of AudioObjectIds that represent the Process objects for all client processes
/// currently connected to the system.
#[doc(alias = "kAudioHardwarePropertyProcessObjectList")]
pub fn processes() -> os::Result<Vec<Process>> {
Self::OBJ.prop_vec(&PropSelector::HARDWARE_PROCESS_OBJ_LIST.global_addr())
}
}

/// AudioSystemObject Properties
Expand Down Expand Up @@ -424,6 +431,10 @@ impl PropSelector {
/// currently provided by the system.
#[doc(alias = "kAudioHardwarePropertyClockDeviceList")]
pub const HARDWARE_CLOCK_DEVICE_LIST: Self = Self(u32::from_be_bytes(*b"clk#"));

/// An array of AudioObjectIDs that represent the Tap objects on the system.
#[doc(alias = "kAudioHardwarePropertyTapList")]
pub const HARDWARE_TAP_LIST: Self = Self(u32::from_be_bytes(*b"tps#"));
}

/// AudioAggregateDevice Properties
Expand Down Expand Up @@ -548,6 +559,42 @@ impl Device {
self.prop(&PropSelector::DEVICE_TRANSPORT_TYPE.global_addr())
}

/// A f64 that indicates the current actual sample rate of the AudioDevice
/// as measured by its time stamps.
#[doc(alias = "kAudioDevicePropertyActualSampleRate")]
pub fn actual_sample_rate(&self) -> os::Result<f64> {
self.prop(&PropSelector::DEVICE_ACTUAL_SAMPLE_RATE.global_addr())
}

/// A cf::String that contains the UID for the AudioClockDevice that is currently
/// serving as the main time base of the device.
#[doc(alias = "kAudioDevicePropertyClockDevice")]
pub fn clock_uid(&self) -> os::Result<arc::R<cf::String>> {
self.cf_prop(&PropSelector::DEVICE_CLOCK_DEVICE.global_addr())
}

/// Indicates that the current process's audio will be zeroed out by the system.
///
/// Note that this property does not apply to aggregate devices, just real, physical devices.
#[doc(alias = "kAudioDevicePropertyProcessMute")]
pub fn is_process_muted(&self, scope: PropScope) -> os::Result<bool> {
let addr = PropAddr {
selector: PropSelector::DEVICE_PROCESS_MUTE,
scope,
element: PropElement::WILDCARD,
};

self.bool_prop(&addr)
}

pub fn is_process_input_muted(&self) -> os::Result<bool> {
self.is_process_muted(PropScope::INPUT)
}

pub fn is_process_output_muted(&self) -> os::Result<bool> {
self.is_process_muted(PropScope::OUTPUT)
}

#[doc(alias = "AudioDeviceCreateIOProcID")]
pub fn create_io_proc_id<const IN: usize, const ON: usize, T>(
&self,
Expand Down Expand Up @@ -1777,7 +1824,7 @@ mod tests {

#[test]
fn clock() {
let clocks = System::clock_device_list().unwrap();
let clocks = System::clocks().unwrap();
for c in clocks {
assert_eq!(Class::CLOCK, c.class().unwrap());
assert_eq!(Class::OBJECT, c.base_class().unwrap());
Expand Down
13 changes: 12 additions & 1 deletion cidre/src/core_audio/hardware_tapping.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ impl std::ops::Deref for TapGuard {
}
}

impl std::ops::DerefMut for TapGuard {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.0
}
}

impl Drop for TapGuard {
fn drop(&mut self) {
let res = unsafe { AudioHardwareDestroyProcessTap(self.0 .0) };
Expand Down Expand Up @@ -48,6 +54,10 @@ impl Tap {
self.cf_prop(&PropSelector::TAP_DESCRIPTION.global_addr())
}

pub fn set_desc(&mut self, val: arc::R<TapDesc>) -> os::Result {
self.set_prop(&PropSelector::TAP_DESCRIPTION.global_addr(), &val)
}

/// An cat::AudioStreamBasicDesc that describes the current data format for
/// the tap. This is the format of that data that will be accessible in any aggregate
/// device that contains the tap.
Expand Down Expand Up @@ -82,7 +92,8 @@ pub mod tests {
let desc = {
let tap_desc = TapDesc::with_stereo_global_tap_excluding_processes(&ns::Array::new());
println!("{tap_desc:?}");
let tap = tap_desc.create_process_tap().unwrap();
let mut tap = tap_desc.create_process_tap().unwrap();
tap.set_desc(tap_desc).unwrap();
let uid = tap.uid().unwrap();
println!("{uid:?}");
let asbd = tap.asbd();
Expand Down

0 comments on commit 076f244

Please # to comment.