Skip to content

Commit

Permalink
tune av api
Browse files Browse the repository at this point in the history
  • Loading branch information
yury committed Nov 29, 2024
1 parent 690e668 commit 5f7d821
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 16 deletions.
2 changes: 1 addition & 1 deletion cidre/src/av.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ pub use audio::IoNodeInputBlock as AudioIoNodeInputBlock;
pub use audio::MixerNode as AudioMixerNode;
pub use audio::Node as AudioNode;
pub use audio::NodeBus as AudioNodeBus;
pub use audio::NodeCompletionHandler as AudioNodeCompletionHandler;
pub use audio::NodeCh as AudioNodeCompletionHandler;
pub use audio::OutputNode as AudioOutputNode;
pub use audio::PacketCount as AudioPacketCount;
pub use audio::PcmBuf as AudioPcmBuf;
Expand Down
4 changes: 2 additions & 2 deletions cidre/src/av/audio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub use types::ChannelCount;
pub use types::FrameCount;
pub use types::FramePos;
pub use types::NodeBus;
pub use types::NodeCompletionHandler;
pub use types::NodeCh;
pub use types::PacketCount;
pub use types::Point3d;
pub use types::Vector3d;
Expand All @@ -36,7 +36,7 @@ pub use mixer_node::MixerNode;

mod mixing;
pub use mixing::Mixing;
pub use mixing::MixingDestination;
pub use mixing::MixingDst;
pub use mixing::StereoMixing;

mod time;
Expand Down
11 changes: 6 additions & 5 deletions cidre/src/av/audio/mixing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,16 @@ pub trait StereoMixing {

define_obj_type!(
#[doc(alias = "AVAudioMixingDestination")]
pub MixingDestination(ns::Id)
pub MixingDst(ns::Id)
);

impl MixingDestination {
impl MixingDst {
#[objc::msg_send(connectionPoint)]
pub fn connection_point(&self) -> arc::R<av::audio::ConnectionPoint>;
}
impl av::audio::StereoMixing for MixingDestination {}
impl av::audio::Mixing for MixingDestination {}

impl av::audio::StereoMixing for MixingDst {}
impl av::audio::Mixing for MixingDst {}

#[objc::protocol(AVAudioMixing)]
pub trait Mixing: StereoMixing {
Expand All @@ -28,7 +29,7 @@ pub trait Mixing: StereoMixing {
&self,
mixer: av::AudioNode,
bus: av::AudioNodeBus,
) -> Option<arc::R<av::audio::MixingDestination>>;
) -> Option<arc::R<av::audio::MixingDst>>;

#[objc::msg_send(volume)]
fn volume(&self) -> f32;
Expand Down
13 changes: 9 additions & 4 deletions cidre/src/av/audio/player_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,21 @@ define_obj_type!(
);

impl PlayerNode {
/// Schedule playing samples from an [`av::AudioPCMBuf`].
/// Schedule playing samples from an [`av::AudioPcmBuf`].
///
/// Schedules the buffer to be played following any previously scheduled commands.
#[objc::msg_send(scheduleBuffer:completionHandler:)]
pub fn schedule_buf_ch_block(
&mut self,
buffer: &av::AudioPcmBuf,
handler: Option<&mut audio::NodeCompletionHandler<blocks::Esc>>,
handler: Option<&mut audio::NodeCh<blocks::Esc>>,
);

pub fn schedule_buf_ch(&mut self, buffer: &av::AudioPcmBuf, handler: impl FnMut() + 'static) {
let mut block = blocks::EscBlock::new0(handler);
self.schedule_buf_ch_block(buffer, Some(&mut block));
}

pub async fn schedule_buf(&mut self, buffer: &av::AudioPcmBuf) {
let (future, mut block) = blocks::comp0();
self.schedule_buf_ch_block(buffer, Some(&mut block));
Expand All @@ -72,13 +77,13 @@ impl PlayerNode {
pub fn volume(&self) -> f32;

#[objc::msg_send(setVolume:)]
pub fn set_volume(&self, val: f32);
pub fn set_volume(&mut self, val: f32);

#[objc::msg_send(pan)]
pub fn pan(&self) -> f32;

#[objc::msg_send(setPan:)]
pub fn set_pan(&self, val: f32);
pub fn set_pan(&mut self, val: f32);
}

#[link(name = "av", kind = "static")]
Expand Down
19 changes: 15 additions & 4 deletions cidre/src/av/audio/types.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,26 @@
use crate::blocks;

#[doc(alias = "AVAudioFramePosition")]
pub type FramePos = i64;

#[doc(alias = "AVAudioFrameCount")]
pub type FrameCount = u32;

#[doc(alias = "AVAudioPacketCount")]
pub type PacketCount = u32;

#[doc(alias = "AVAudioChannelCount")]
pub type ChannelCount = u32;

/// AVAudioNode objects potentially have multiple input and/or output busses.
/// AVAudioNodeBus represents a bus as a zero-based index.
#[doc(alias = "AVAudioNodeBus")]
pub type NodeBus = usize;

pub type NodeCompletionHandler<Attr> = blocks::Block<fn(), Attr>;
#[doc(alias = "AVAudioNodeCompletionHandler")]
pub type NodeCh<Attr> = blocks::Block<fn(), Attr>;

#[derive(Copy, Clone, Debug)]
#[derive(Copy, Clone, Debug, PartialEq)]
#[repr(C)]
pub struct Point3d {
pub x: f32,
Expand All @@ -19,14 +30,14 @@ pub struct Point3d {

pub type Vector3d = Point3d;

#[derive(Copy, Clone, Debug)]
#[derive(Copy, Clone, Debug, PartialEq)]
#[repr(C)]
pub struct Vector3dOrientation {
pub forward: Vector3d,
pub up: Vector3d,
}

#[derive(Copy, Clone, Debug)]
#[derive(Copy, Clone, Debug, PartialEq)]
#[repr(C)]
pub struct Angular3dOrientation {
pub yaw: f32,
Expand Down

0 comments on commit 5f7d821

Please # to comment.