objc2_avf_audio/generated/
AVAudioFormat.rs

1//! This file has been automatically generated by `objc2`'s `header-translator`.
2//! DO NOT EDIT
3use core::ffi::*;
4use core::ptr::NonNull;
5use objc2::__framework_prelude::*;
6#[cfg(feature = "objc2-core-audio-types")]
7use objc2_core_audio_types::*;
8#[cfg(feature = "objc2-core-media")]
9use objc2_core_media::*;
10use objc2_foundation::*;
11
12use crate::*;
13
14/// A format other than one of the common ones below.
15///
16/// Native-endian floats (this is the standard format).
17///
18/// Native-endian doubles.
19///
20/// Signed 16-bit native-endian integers.
21///
22/// Signed 32-bit native-endian integers.
23///
24/// See also [Apple's documentation](https://developer.apple.com/documentation/avfaudio/avaudiocommonformat?language=objc)
25// NS_ENUM
26#[repr(transparent)]
27#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
28pub struct AVAudioCommonFormat(pub NSUInteger);
29impl AVAudioCommonFormat {
30    #[doc(alias = "AVAudioOtherFormat")]
31    pub const OtherFormat: Self = Self(0);
32    #[doc(alias = "AVAudioPCMFormatFloat32")]
33    pub const PCMFormatFloat32: Self = Self(1);
34    #[doc(alias = "AVAudioPCMFormatFloat64")]
35    pub const PCMFormatFloat64: Self = Self(2);
36    #[doc(alias = "AVAudioPCMFormatInt16")]
37    pub const PCMFormatInt16: Self = Self(3);
38    #[doc(alias = "AVAudioPCMFormatInt32")]
39    pub const PCMFormatInt32: Self = Self(4);
40}
41
42unsafe impl Encode for AVAudioCommonFormat {
43    const ENCODING: Encoding = NSUInteger::ENCODING;
44}
45
46unsafe impl RefEncode for AVAudioCommonFormat {
47    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
48}
49
50extern_class!(
51    /// A representation of an audio format.
52    ///
53    /// AVAudioFormat wraps a Core Audio AudioStreamBasicDescription struct, with convenience
54    /// initializers and accessors for common formats, including Core Audio's standard deinterleaved
55    /// 32-bit floating point.
56    ///
57    /// Instances of this class are immutable.
58    ///
59    /// See also [Apple's documentation](https://developer.apple.com/documentation/avfaudio/avaudioformat?language=objc)
60    #[unsafe(super(NSObject))]
61    #[derive(Debug, PartialEq, Eq, Hash)]
62    pub struct AVAudioFormat;
63);
64
65extern_conformance!(
66    unsafe impl NSCoding for AVAudioFormat {}
67);
68
69extern_conformance!(
70    unsafe impl NSObjectProtocol for AVAudioFormat {}
71);
72
73extern_conformance!(
74    unsafe impl NSSecureCoding for AVAudioFormat {}
75);
76
77impl AVAudioFormat {
78    extern_methods!(
79        #[cfg(feature = "objc2-core-audio-types")]
80        /// Initialize from an AudioStreamBasicDescription.
81        ///
82        /// Parameter `asbd`: the AudioStreamBasicDescription
83        ///
84        /// If the format specifies more than 2 channels, this method fails (returns nil).
85        #[unsafe(method(initWithStreamDescription:))]
86        #[unsafe(method_family = init)]
87        pub unsafe fn initWithStreamDescription(
88            this: Allocated<Self>,
89            asbd: NonNull<AudioStreamBasicDescription>,
90        ) -> Option<Retained<Self>>;
91
92        #[cfg(all(feature = "AVAudioChannelLayout", feature = "objc2-core-audio-types"))]
93        /// Initialize from an AudioStreamBasicDescription and optional channel layout.
94        ///
95        /// Parameter `asbd`: the AudioStreamBasicDescription
96        ///
97        /// Parameter `layout`: the channel layout. Can be nil only if asbd specifies 1 or 2 channels.
98        ///
99        /// If the format specifies more than 2 channels, this method fails (returns nil) unless layout
100        /// is non-nil.
101        #[unsafe(method(initWithStreamDescription:channelLayout:))]
102        #[unsafe(method_family = init)]
103        pub unsafe fn initWithStreamDescription_channelLayout(
104            this: Allocated<Self>,
105            asbd: NonNull<AudioStreamBasicDescription>,
106            layout: Option<&AVAudioChannelLayout>,
107        ) -> Option<Retained<Self>>;
108
109        #[cfg(feature = "AVAudioTypes")]
110        /// Initialize to deinterleaved float with the specified sample rate and channel count.
111        ///
112        /// Parameter `sampleRate`: the sample rate
113        ///
114        /// Parameter `channels`: the channel count
115        ///
116        /// If the format specifies more than 2 channels, this method fails (returns nil).
117        #[unsafe(method(initStandardFormatWithSampleRate:channels:))]
118        #[unsafe(method_family = init)]
119        pub unsafe fn initStandardFormatWithSampleRate_channels(
120            this: Allocated<Self>,
121            sample_rate: c_double,
122            channels: AVAudioChannelCount,
123        ) -> Option<Retained<Self>>;
124
125        #[cfg(feature = "AVAudioChannelLayout")]
126        /// Initialize to deinterleaved float with the specified sample rate and channel layout.
127        ///
128        /// Parameter `sampleRate`: the sample rate
129        ///
130        /// Parameter `layout`: the channel layout. must not be nil.
131        #[unsafe(method(initStandardFormatWithSampleRate:channelLayout:))]
132        #[unsafe(method_family = init)]
133        pub unsafe fn initStandardFormatWithSampleRate_channelLayout(
134            this: Allocated<Self>,
135            sample_rate: c_double,
136            layout: &AVAudioChannelLayout,
137        ) -> Retained<Self>;
138
139        #[cfg(feature = "AVAudioTypes")]
140        /// Initialize to float with the specified sample rate, channel count and interleavedness.
141        ///
142        /// Parameter `format`: the common format type
143        ///
144        /// Parameter `sampleRate`: the sample rate
145        ///
146        /// Parameter `channels`: the channel count
147        ///
148        /// Parameter `interleaved`: true if interleaved
149        ///
150        /// If the format specifies more than 2 channels, this method fails (returns nil).
151        #[unsafe(method(initWithCommonFormat:sampleRate:channels:interleaved:))]
152        #[unsafe(method_family = init)]
153        pub unsafe fn initWithCommonFormat_sampleRate_channels_interleaved(
154            this: Allocated<Self>,
155            format: AVAudioCommonFormat,
156            sample_rate: c_double,
157            channels: AVAudioChannelCount,
158            interleaved: bool,
159        ) -> Option<Retained<Self>>;
160
161        #[cfg(feature = "AVAudioChannelLayout")]
162        /// Initialize to float with the specified sample rate, channel layout and interleavedness.
163        ///
164        /// Parameter `format`: the common format type
165        ///
166        /// Parameter `sampleRate`: the sample rate
167        ///
168        /// Parameter `interleaved`: true if interleaved
169        ///
170        /// Parameter `layout`: the channel layout. must not be nil.
171        #[unsafe(method(initWithCommonFormat:sampleRate:interleaved:channelLayout:))]
172        #[unsafe(method_family = init)]
173        pub unsafe fn initWithCommonFormat_sampleRate_interleaved_channelLayout(
174            this: Allocated<Self>,
175            format: AVAudioCommonFormat,
176            sample_rate: c_double,
177            interleaved: bool,
178            layout: &AVAudioChannelLayout,
179        ) -> Retained<Self>;
180
181        /// Initialize using a settings dictionary.
182        ///
183        /// See AVAudioSettings.h. Note that many settings dictionary elements pertain to encoder
184        /// settings, not the basic format, and will be ignored.
185        ///
186        /// Returns nil if a format cannot be constructed with the provided settings, e.g. when:
187        /// - AVNumberOfChannelsKey specifies more than 2 channels, but AVChannelLayoutKey hasn't
188        /// been specified or the layout does not match
189        /// - AVLinearPCMBitDepthKey for linear PCM format specifies less than 8 or greater
190        /// than 32 bits
191        /// - values for the keys are not of the expected types
192        #[unsafe(method(initWithSettings:))]
193        #[unsafe(method_family = init)]
194        pub unsafe fn initWithSettings(
195            this: Allocated<Self>,
196            settings: &NSDictionary<NSString, AnyObject>,
197        ) -> Option<Retained<Self>>;
198
199        #[cfg(feature = "objc2-core-media")]
200        /// initialize from a CMAudioFormatDescriptionRef.
201        ///
202        /// Parameter `formatDescription`: the CMAudioFormatDescriptionRef.
203        ///
204        /// If formatDescription is invalid, this method fails (returns nil).
205        #[unsafe(method(initWithCMAudioFormatDescription:))]
206        #[unsafe(method_family = init)]
207        pub unsafe fn initWithCMAudioFormatDescription(
208            this: Allocated<Self>,
209            format_description: &CMAudioFormatDescription,
210        ) -> Retained<Self>;
211
212        /// Determine whether another format is functionally equivalent.
213        ///
214        /// Parameter `object`: the format to compare against
215        ///
216        /// For PCM, interleavedness is ignored for mono. Differences in the AudioStreamBasicDescription
217        /// alignment and packedness are ignored when they are not significant (e.g. with 1 channel, 2
218        /// bytes per frame and 16 bits per channel, neither alignment, the format is implicitly packed
219        /// and can be interpreted as either high- or low-aligned.)
220        /// For AVAudioChannelLayout, a layout with standard mono/stereo tag is considered to be
221        /// equivalent to a nil layout. Otherwise, the layouts are compared for equality.
222        #[unsafe(method(isEqual:))]
223        #[unsafe(method_family = none)]
224        pub unsafe fn isEqual(&self, object: &AnyObject) -> bool;
225
226        /// Describes whether the format is deinterleaved native-endian float.
227        #[unsafe(method(isStandard))]
228        #[unsafe(method_family = none)]
229        pub unsafe fn isStandard(&self) -> bool;
230
231        /// An `AVAudioCommonFormat` identifying the format
232        #[unsafe(method(commonFormat))]
233        #[unsafe(method_family = none)]
234        pub unsafe fn commonFormat(&self) -> AVAudioCommonFormat;
235
236        #[cfg(feature = "AVAudioTypes")]
237        /// The number of channels of audio data.
238        #[unsafe(method(channelCount))]
239        #[unsafe(method_family = none)]
240        pub unsafe fn channelCount(&self) -> AVAudioChannelCount;
241
242        /// A sampling rate in Hertz.
243        #[unsafe(method(sampleRate))]
244        #[unsafe(method_family = none)]
245        pub unsafe fn sampleRate(&self) -> c_double;
246
247        /// Describes whether the samples are interleaved.
248        ///
249        /// For non-PCM formats, the value is undefined.
250        #[unsafe(method(isInterleaved))]
251        #[unsafe(method_family = none)]
252        pub unsafe fn isInterleaved(&self) -> bool;
253
254        #[cfg(feature = "objc2-core-audio-types")]
255        /// Returns the AudioStreamBasicDescription, for use with lower-level audio API's.
256        #[unsafe(method(streamDescription))]
257        #[unsafe(method_family = none)]
258        pub unsafe fn streamDescription(&self) -> NonNull<AudioStreamBasicDescription>;
259
260        #[cfg(feature = "AVAudioChannelLayout")]
261        /// The underlying AVAudioChannelLayout, if any.
262        ///
263        /// Only formats with more than 2 channels are required to have channel layouts.
264        #[unsafe(method(channelLayout))]
265        #[unsafe(method_family = none)]
266        pub unsafe fn channelLayout(&self) -> Option<Retained<AVAudioChannelLayout>>;
267
268        /// The underlying magic cookie, if any.
269        ///
270        /// A magic cookie contains metadata associated with encoders and decoders.
271        /// Encoders produce a magic cookie, and some decoders require a magic cookie to decode properly.
272        #[unsafe(method(magicCookie))]
273        #[unsafe(method_family = none)]
274        pub unsafe fn magicCookie(&self) -> Option<Retained<NSData>>;
275
276        /// Setter for [`magicCookie`][Self::magicCookie].
277        #[unsafe(method(setMagicCookie:))]
278        #[unsafe(method_family = none)]
279        pub unsafe fn setMagicCookie(&self, magic_cookie: Option<&NSData>);
280
281        /// Returns the format represented as a dictionary with keys from AVAudioSettings.h.
282        #[unsafe(method(settings))]
283        #[unsafe(method_family = none)]
284        pub unsafe fn settings(&self) -> Retained<NSDictionary<NSString, AnyObject>>;
285
286        #[cfg(feature = "objc2-core-media")]
287        /// Converts to a CMAudioFormatDescriptionRef, for use with Core Media API's.
288        #[unsafe(method(formatDescription))]
289        #[unsafe(method_family = none)]
290        pub unsafe fn formatDescription(&self) -> Retained<CMAudioFormatDescription>;
291    );
292}
293
294/// Methods declared on superclass `NSObject`.
295impl AVAudioFormat {
296    extern_methods!(
297        #[unsafe(method(init))]
298        #[unsafe(method_family = init)]
299        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
300
301        #[unsafe(method(new))]
302        #[unsafe(method_family = new)]
303        pub unsafe fn new() -> Retained<Self>;
304    );
305}