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