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