From 5df6e92ce43e900fb08a69b6e2e00e59362ae613 Mon Sep 17 00:00:00 2001 From: Yury Date: Wed, 6 Nov 2024 16:04:34 +0300 Subject: [PATCH] add av::AudioChannelLayout api --- cidre/pomace/av/av.h | 2 ++ cidre/src/av.rs | 2 ++ cidre/src/av/audio/channel_layout.rs | 54 ++++++++++++++++++++++++++-- cidre/src/av/audio/types.rs | 1 + cidre/src/cat/audio/base_types.rs | 2 +- 5 files changed, 58 insertions(+), 3 deletions(-) diff --git a/cidre/pomace/av/av.h b/cidre/pomace/av/av.h index 7d601595..8146393f 100644 --- a/cidre/pomace/av/av.h +++ b/cidre/pomace/av/av.h @@ -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; @@ -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]; diff --git a/cidre/src/av.rs b/cidre/src/av.rs index 6ecd168a..3b44ad77 100644 --- a/cidre/src/av.rs +++ b/cidre/src/av.rs @@ -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; diff --git a/cidre/src/av/audio/channel_layout.rs b/cidre/src/av/audio/channel_layout.rs index 9fb5a468..5ae2a217 100644 --- a/cidre/src/av/audio/channel_layout.rs +++ b/cidre/src/av/audio/channel_layout.rs @@ -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 { + #[objc::msg_send(initWithLayout:)] + pub fn init_with_layout( + self, + layout: &cat::AudioChannelLayout, + ) -> arc::R; + + #[objc::msg_send(initWithLayoutTag:)] + pub fn init_with_layout_tag(self, tag: cat::AudioChannelLayoutTag) -> arc::R; +} + +impl ChannelLayout { + define_cls!(AV_AUDIO_CHANNEL_LAYOUT); + + pub fn with_layout(layout: &cat::AudioChannelLayout) -> arc::R { + Self::alloc().init_with_layout(layout) + } + + pub fn with_layout_tag(tag: cat::AudioChannelLayoutTag) -> arc::R { + 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; +} + +#[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); + } +} diff --git a/cidre/src/av/audio/types.rs b/cidre/src/av/audio/types.rs index 18c9d2e3..9971c8b6 100644 --- a/cidre/src/av/audio/types.rs +++ b/cidre/src/av/audio/types.rs @@ -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; diff --git a/cidre/src/cat/audio/base_types.rs b/cidre/src/cat/audio/base_types.rs index f4a46431..2c148a5f 100644 --- a/cidre/src/cat/audio/base_types.rs +++ b/cidre/src/cat/audio/base_types.rs @@ -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);