Skip to content

Commit

Permalink
add av::AudioChannelLayout api
Browse files Browse the repository at this point in the history
  • Loading branch information
yury committed Nov 6, 2024
1 parent c6604b4 commit 5df6e92
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 3 deletions.
2 changes: 2 additions & 0 deletions cidre/pomace/av/av.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ Class AV_AUDIO_COMPRESSED_BUFFER;
Class AV_AUDIO_FORMAT;
Class AV_AUDIO_CONVERTER;
Class AV_AUDIO_FILE;
Class AV_AUDIO_CHANNEL_LAYOUT;

Class AV_PLAYER;

Expand Down Expand Up @@ -174,6 +175,7 @@ static void av_initializer(void)
AV_AUDIO_COMPRESSED_BUFFER = [AVAudioCompressedBuffer class];
AV_AUDIO_CONVERTER = [AVAudioConverter class];
AV_AUDIO_FILE = [AVAudioFile class];
AV_AUDIO_CHANNEL_LAYOUT = [AVAudioChannelLayout class];

AV_PLAYER = [AVPlayer class];

Expand Down
2 changes: 2 additions & 0 deletions cidre/src/av.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ pub use asset::AssetImageGeneratorResult;

pub mod audio;
pub use audio::Buf as AudioBuf;
pub use audio::ChannelCount as AudioChannelCount;
pub use audio::ChannelLayout as AudioChannelLayout;
pub use audio::CommonFormat as AudioCommonFormat;
pub use audio::CompressedBuf as AudioCompressedBuf;
pub use audio::Converter as AudioConverter;
Expand Down
54 changes: 52 additions & 2 deletions cidre/src/av/audio/channel_layout.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,53 @@
use crate::{define_obj_type, ns};
use crate::{arc, av, cat, define_cls, define_obj_type, ns, objc};

define_obj_type!(pub ChannelLayout(ns::Id));
define_obj_type!(
#[doc(alias = "AVAudioChannelLayout")]
pub ChannelLayout(ns::Id)
);

impl arc::A<ChannelLayout> {
#[objc::msg_send(initWithLayout:)]
pub fn init_with_layout<const N: usize>(
self,
layout: &cat::AudioChannelLayout<N>,
) -> arc::R<ChannelLayout>;

#[objc::msg_send(initWithLayoutTag:)]
pub fn init_with_layout_tag(self, tag: cat::AudioChannelLayoutTag) -> arc::R<ChannelLayout>;
}

impl ChannelLayout {
define_cls!(AV_AUDIO_CHANNEL_LAYOUT);

pub fn with_layout<const N: usize>(layout: &cat::AudioChannelLayout<N>) -> arc::R<Self> {
Self::alloc().init_with_layout(layout)
}

pub fn with_layout_tag(tag: cat::AudioChannelLayoutTag) -> arc::R<Self> {
Self::alloc().init_with_layout_tag(tag)
}

#[objc::msg_send(layoutTag)]
pub fn layout_tag(&self) -> cat::AudioChannelLayoutTag;

#[objc::msg_send(channelCount)]
pub fn channel_count(&self) -> av::AudioChannelCount;
}

#[link(name = "av", kind = "static")]
extern "C" {
static AV_AUDIO_CHANNEL_LAYOUT: &'static objc::Class<ChannelLayout>;
}

#[cfg(test)]
mod tests {
use crate::{av, cat};

#[test]
fn basics() {
let tag = cat::AudioChannelLayoutTag::STEREO;
let layout = av::AudioChannelLayout::with_layout_tag(tag);
assert_eq!(layout.channel_count(), 2);
assert_eq!(layout.layout_tag(), tag);
}
}
1 change: 1 addition & 0 deletions cidre/src/av/audio/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use crate::blocks;
pub type FramePos = i64;
pub type FrameCount = u32;
pub type PacketCount = u32;
#[doc(alias = "AVAudioChannelCount")]
pub type ChannelCount = u32;
pub type NodeBus = usize;

Expand Down
2 changes: 1 addition & 1 deletion cidre/src/cat/audio/base_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1161,7 +1161,7 @@ impl ChannelCoordinateIndex {
/// Lt - left matrix total. for matrix encoded stereo.
/// Rt - right matrix total. for matrix encoded stereo.
#[doc(alias = "AudioChannelLayoutTag")]
#[derive(Debug, PartialEq, Eq)]
#[derive(Debug, PartialEq, Eq, Copy, Clone)]
#[repr(transparent)]
pub struct ChannelLayoutTag(pub u32);

Expand Down

0 comments on commit 5df6e92

Please # to comment.