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
65unsafe impl NSCoding for AVAudioFormat {}
66
67unsafe impl NSObjectProtocol for AVAudioFormat {}
68
69unsafe impl NSSecureCoding for AVAudioFormat {}
70
71impl AVAudioFormat {
72 extern_methods!(
73 #[cfg(feature = "objc2-core-audio-types")]
74 /// Initialize from an AudioStreamBasicDescription.
75 ///
76 /// Parameter `asbd`: the AudioStreamBasicDescription
77 ///
78 /// If the format specifies more than 2 channels, this method fails (returns nil).
79 #[unsafe(method(initWithStreamDescription:))]
80 #[unsafe(method_family = init)]
81 pub unsafe fn initWithStreamDescription(
82 this: Allocated<Self>,
83 asbd: NonNull<AudioStreamBasicDescription>,
84 ) -> Option<Retained<Self>>;
85
86 #[cfg(all(feature = "AVAudioChannelLayout", feature = "objc2-core-audio-types"))]
87 /// Initialize from an AudioStreamBasicDescription and optional channel layout.
88 ///
89 /// Parameter `asbd`: the AudioStreamBasicDescription
90 ///
91 /// Parameter `layout`: the channel layout. Can be nil only if asbd specifies 1 or 2 channels.
92 ///
93 /// If the format specifies more than 2 channels, this method fails (returns nil) unless layout
94 /// is non-nil.
95 #[unsafe(method(initWithStreamDescription:channelLayout:))]
96 #[unsafe(method_family = init)]
97 pub unsafe fn initWithStreamDescription_channelLayout(
98 this: Allocated<Self>,
99 asbd: NonNull<AudioStreamBasicDescription>,
100 layout: Option<&AVAudioChannelLayout>,
101 ) -> Option<Retained<Self>>;
102
103 #[cfg(feature = "AVAudioTypes")]
104 /// Initialize to deinterleaved float with the specified sample rate and channel count.
105 ///
106 /// Parameter `sampleRate`: the sample rate
107 ///
108 /// Parameter `channels`: the channel count
109 ///
110 /// If the format specifies more than 2 channels, this method fails (returns nil).
111 #[unsafe(method(initStandardFormatWithSampleRate:channels:))]
112 #[unsafe(method_family = init)]
113 pub unsafe fn initStandardFormatWithSampleRate_channels(
114 this: Allocated<Self>,
115 sample_rate: c_double,
116 channels: AVAudioChannelCount,
117 ) -> Option<Retained<Self>>;
118
119 #[cfg(feature = "AVAudioChannelLayout")]
120 /// Initialize to deinterleaved float with the specified sample rate and channel layout.
121 ///
122 /// Parameter `sampleRate`: the sample rate
123 ///
124 /// Parameter `layout`: the channel layout. must not be nil.
125 #[unsafe(method(initStandardFormatWithSampleRate:channelLayout:))]
126 #[unsafe(method_family = init)]
127 pub unsafe fn initStandardFormatWithSampleRate_channelLayout(
128 this: Allocated<Self>,
129 sample_rate: c_double,
130 layout: &AVAudioChannelLayout,
131 ) -> Retained<Self>;
132
133 #[cfg(feature = "AVAudioTypes")]
134 /// Initialize to float with the specified sample rate, channel count and interleavedness.
135 ///
136 /// Parameter `format`: the common format type
137 ///
138 /// Parameter `sampleRate`: the sample rate
139 ///
140 /// Parameter `channels`: the channel count
141 ///
142 /// Parameter `interleaved`: true if interleaved
143 ///
144 /// If the format specifies more than 2 channels, this method fails (returns nil).
145 #[unsafe(method(initWithCommonFormat:sampleRate:channels:interleaved:))]
146 #[unsafe(method_family = init)]
147 pub unsafe fn initWithCommonFormat_sampleRate_channels_interleaved(
148 this: Allocated<Self>,
149 format: AVAudioCommonFormat,
150 sample_rate: c_double,
151 channels: AVAudioChannelCount,
152 interleaved: bool,
153 ) -> Option<Retained<Self>>;
154
155 #[cfg(feature = "AVAudioChannelLayout")]
156 /// Initialize to float with the specified sample rate, channel layout and interleavedness.
157 ///
158 /// Parameter `format`: the common format type
159 ///
160 /// Parameter `sampleRate`: the sample rate
161 ///
162 /// Parameter `interleaved`: true if interleaved
163 ///
164 /// Parameter `layout`: the channel layout. must not be nil.
165 #[unsafe(method(initWithCommonFormat:sampleRate:interleaved:channelLayout:))]
166 #[unsafe(method_family = init)]
167 pub unsafe fn initWithCommonFormat_sampleRate_interleaved_channelLayout(
168 this: Allocated<Self>,
169 format: AVAudioCommonFormat,
170 sample_rate: c_double,
171 interleaved: bool,
172 layout: &AVAudioChannelLayout,
173 ) -> Retained<Self>;
174
175 /// Initialize using a settings dictionary.
176 ///
177 /// See AVAudioSettings.h. Note that many settings dictionary elements pertain to encoder
178 /// settings, not the basic format, and will be ignored.
179 ///
180 /// Returns nil if a format cannot be constructed with the provided settings, e.g. when:
181 /// - AVNumberOfChannelsKey specifies more than 2 channels, but AVChannelLayoutKey hasn't
182 /// been specified or the layout does not match
183 /// - AVLinearPCMBitDepthKey for linear PCM format specifies less than 8 or greater
184 /// than 32 bits
185 /// - values for the keys are not of the expected types
186 #[unsafe(method(initWithSettings:))]
187 #[unsafe(method_family = init)]
188 pub unsafe fn initWithSettings(
189 this: Allocated<Self>,
190 settings: &NSDictionary<NSString, AnyObject>,
191 ) -> Option<Retained<Self>>;
192
193 #[cfg(feature = "objc2-core-media")]
194 /// initialize from a CMAudioFormatDescriptionRef.
195 ///
196 /// Parameter `formatDescription`: the CMAudioFormatDescriptionRef.
197 ///
198 /// If formatDescription is invalid, this method fails (returns nil).
199 #[unsafe(method(initWithCMAudioFormatDescription:))]
200 #[unsafe(method_family = init)]
201 pub unsafe fn initWithCMAudioFormatDescription(
202 this: Allocated<Self>,
203 format_description: &CMAudioFormatDescription,
204 ) -> Retained<Self>;
205
206 /// Determine whether another format is functionally equivalent.
207 ///
208 /// Parameter `object`: the format to compare against
209 ///
210 /// For PCM, interleavedness is ignored for mono. Differences in the AudioStreamBasicDescription
211 /// alignment and packedness are ignored when they are not significant (e.g. with 1 channel, 2
212 /// bytes per frame and 16 bits per channel, neither alignment, the format is implicitly packed
213 /// and can be interpreted as either high- or low-aligned.)
214 /// For AVAudioChannelLayout, a layout with standard mono/stereo tag is considered to be
215 /// equivalent to a nil layout. Otherwise, the layouts are compared for equality.
216 #[unsafe(method(isEqual:))]
217 #[unsafe(method_family = none)]
218 pub unsafe fn isEqual(&self, object: &AnyObject) -> bool;
219
220 /// Describes whether the format is deinterleaved native-endian float.
221 #[unsafe(method(isStandard))]
222 #[unsafe(method_family = none)]
223 pub unsafe fn isStandard(&self) -> bool;
224
225 /// An `AVAudioCommonFormat` identifying the format
226 #[unsafe(method(commonFormat))]
227 #[unsafe(method_family = none)]
228 pub unsafe fn commonFormat(&self) -> AVAudioCommonFormat;
229
230 #[cfg(feature = "AVAudioTypes")]
231 /// The number of channels of audio data.
232 #[unsafe(method(channelCount))]
233 #[unsafe(method_family = none)]
234 pub unsafe fn channelCount(&self) -> AVAudioChannelCount;
235
236 /// A sampling rate in Hertz.
237 #[unsafe(method(sampleRate))]
238 #[unsafe(method_family = none)]
239 pub unsafe fn sampleRate(&self) -> c_double;
240
241 /// Describes whether the samples are interleaved.
242 ///
243 /// For non-PCM formats, the value is undefined.
244 #[unsafe(method(isInterleaved))]
245 #[unsafe(method_family = none)]
246 pub unsafe fn isInterleaved(&self) -> bool;
247
248 #[cfg(feature = "objc2-core-audio-types")]
249 /// Returns the AudioStreamBasicDescription, for use with lower-level audio API's.
250 #[unsafe(method(streamDescription))]
251 #[unsafe(method_family = none)]
252 pub unsafe fn streamDescription(&self) -> NonNull<AudioStreamBasicDescription>;
253
254 #[cfg(feature = "AVAudioChannelLayout")]
255 /// The underlying AVAudioChannelLayout, if any.
256 ///
257 /// Only formats with more than 2 channels are required to have channel layouts.
258 #[unsafe(method(channelLayout))]
259 #[unsafe(method_family = none)]
260 pub unsafe fn channelLayout(&self) -> Option<Retained<AVAudioChannelLayout>>;
261
262 /// The underlying magic cookie, if any.
263 ///
264 /// A magic cookie contains metadata associated with encoders and decoders.
265 /// Encoders produce a magic cookie, and some decoders require a magic cookie to decode properly.
266 #[unsafe(method(magicCookie))]
267 #[unsafe(method_family = none)]
268 pub unsafe fn magicCookie(&self) -> Option<Retained<NSData>>;
269
270 /// Setter for [`magicCookie`][Self::magicCookie].
271 #[unsafe(method(setMagicCookie:))]
272 #[unsafe(method_family = none)]
273 pub unsafe fn setMagicCookie(&self, magic_cookie: Option<&NSData>);
274
275 /// Returns the format represented as a dictionary with keys from AVAudioSettings.h.
276 #[unsafe(method(settings))]
277 #[unsafe(method_family = none)]
278 pub unsafe fn settings(&self) -> Retained<NSDictionary<NSString, AnyObject>>;
279
280 #[cfg(feature = "objc2-core-media")]
281 /// Converts to a CMAudioFormatDescriptionRef, for use with Core Media API's.
282 #[unsafe(method(formatDescription))]
283 #[unsafe(method_family = none)]
284 pub unsafe fn formatDescription(&self) -> Retained<CMAudioFormatDescription>;
285 );
286}
287
288/// Methods declared on superclass `NSObject`.
289impl AVAudioFormat {
290 extern_methods!(
291 #[unsafe(method(init))]
292 #[unsafe(method_family = init)]
293 pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
294
295 #[unsafe(method(new))]
296 #[unsafe(method_family = new)]
297 pub unsafe fn new() -> Retained<Self>;
298 );
299}