objc2-avf-audio 0.3.2

Bindings to the AVFAudio framework
Documentation
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
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
//! 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::*;
use objc2_foundation::*;

use crate::*;

/// Types of distance attenuation models
///
/// Distance attenuation is the natural attenuation of sound when traveling from the source to
/// the listener. The different attenuation models listed below describe the drop-off in gain as
/// the source moves away from the listener.
///
/// AVAudioEnvironmentDistanceAttenuationModelExponential
/// distanceGain = (distance / referenceDistance) ^ (-rolloffFactor)
///
/// AVAudioEnvironmentDistanceAttenuationModelInverse
/// distanceGain = referenceDistance /  (referenceDistance + rolloffFactor *
/// (distance – referenceDistance))
///
/// AVAudioEnvironmentDistanceAttenuationModelLinear
/// distanceGain = (1 – rolloffFactor * (distance – referenceDistance) /
/// (maximumDistance – referenceDistance))
///
/// With all the distance models, if the formula can not be evaluated then the source will not
/// be attenuated. For example, if a linear model is being used with referenceDistance equal
/// to maximumDistance, then the gain equation will have a divide-by-zero error in it. In this case,
/// there is no attenuation for that source.
///
/// All the values for distance are specified in meters.
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/avfaudio/avaudioenvironmentdistanceattenuationmodel?language=objc)
// NS_ENUM
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct AVAudioEnvironmentDistanceAttenuationModel(pub NSInteger);
impl AVAudioEnvironmentDistanceAttenuationModel {
    #[doc(alias = "AVAudioEnvironmentDistanceAttenuationModelExponential")]
    pub const Exponential: Self = Self(1);
    #[doc(alias = "AVAudioEnvironmentDistanceAttenuationModelInverse")]
    pub const Inverse: Self = Self(2);
    #[doc(alias = "AVAudioEnvironmentDistanceAttenuationModelLinear")]
    pub const Linear: Self = Self(3);
}

unsafe impl Encode for AVAudioEnvironmentDistanceAttenuationModel {
    const ENCODING: Encoding = NSInteger::ENCODING;
}

unsafe impl RefEncode for AVAudioEnvironmentDistanceAttenuationModel {
    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}

extern_class!(
    /// Parameters specifying the amount of distance attenuation
    ///
    /// A standalone instance of AVAudioEnvironmentDistanceAttenuationParameters cannot be created.
    /// Only an instance vended out by a source object (e.g. AVAudioEnvironmentNode) can be used.
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/avfaudio/avaudioenvironmentdistanceattenuationparameters?language=objc)
    #[unsafe(super(NSObject))]
    #[derive(Debug, PartialEq, Eq, Hash)]
    pub struct AVAudioEnvironmentDistanceAttenuationParameters;
);

extern_conformance!(
    unsafe impl NSObjectProtocol for AVAudioEnvironmentDistanceAttenuationParameters {}
);

impl AVAudioEnvironmentDistanceAttenuationParameters {
    extern_methods!(
        #[unsafe(method(init))]
        #[unsafe(method_family = init)]
        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;

        /// Type of distance attenuation model
        ///
        /// Default:    AVAudioEnvironmentDistanceAttenuationModelInverse
        #[unsafe(method(distanceAttenuationModel))]
        #[unsafe(method_family = none)]
        pub unsafe fn distanceAttenuationModel(&self)
            -> AVAudioEnvironmentDistanceAttenuationModel;

        /// Setter for [`distanceAttenuationModel`][Self::distanceAttenuationModel].
        #[unsafe(method(setDistanceAttenuationModel:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setDistanceAttenuationModel(
            &self,
            distance_attenuation_model: AVAudioEnvironmentDistanceAttenuationModel,
        );

        /// The minimum distance at which attenuation is applied
        ///
        /// Default:    1.0 meter
        /// Models:     AVAudioEnvironmentDistanceAttenuationModelInverse,
        /// AVAudioEnvironmentDistanceAttenuationModelLinear
        #[unsafe(method(referenceDistance))]
        #[unsafe(method_family = none)]
        pub unsafe fn referenceDistance(&self) -> c_float;

        /// Setter for [`referenceDistance`][Self::referenceDistance].
        #[unsafe(method(setReferenceDistance:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setReferenceDistance(&self, reference_distance: c_float);

        /// The distance beyond which no further attenuation is applied
        ///
        /// Default:    100000.0 meters
        /// Models:     AVAudioEnvironmentDistanceAttenuationModelLinear
        #[unsafe(method(maximumDistance))]
        #[unsafe(method_family = none)]
        pub unsafe fn maximumDistance(&self) -> c_float;

        /// Setter for [`maximumDistance`][Self::maximumDistance].
        #[unsafe(method(setMaximumDistance:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setMaximumDistance(&self, maximum_distance: c_float);

        /// Determines the attenuation curve
        ///
        /// A higher value results in a steeper attenuation curve.
        /// The rolloff factor should be a value greater than 0.
        /// Default:    1.0
        /// Models:     AVAudioEnvironmentDistanceAttenuationModelExponential
        /// AVAudioEnvironmentDistanceAttenuationModelInverse
        /// AVAudioEnvironmentDistanceAttenuationModelLinear
        #[unsafe(method(rolloffFactor))]
        #[unsafe(method_family = none)]
        pub unsafe fn rolloffFactor(&self) -> c_float;

        /// Setter for [`rolloffFactor`][Self::rolloffFactor].
        #[unsafe(method(setRolloffFactor:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setRolloffFactor(&self, rolloff_factor: c_float);
    );
}

/// Methods declared on superclass `NSObject`.
impl AVAudioEnvironmentDistanceAttenuationParameters {
    extern_methods!(
        #[unsafe(method(new))]
        #[unsafe(method_family = new)]
        pub unsafe fn new() -> Retained<Self>;
    );
}

extern_class!(
    /// Parameters used to control the reverb in AVAudioEnvironmentNode
    ///
    /// Reverberation can be used to simulate the acoustic characteristics of an environment.
    /// AVAudioEnvironmentNode has a built in reverb that describes the space that the listener
    /// is in.
    ///
    /// The reverb also has a single filter that sits at the end of the chain. This filter is useful
    /// to shape the overall sound of the reverb. For instance, one of the reverb presets can be
    /// selected to simulate the general space and then the filter can be used to brighten or darken
    /// the overall sound.
    ///
    /// A standalone instance of AVAudioEnvironmentReverbParameters cannot be created.
    /// Only an instance vended out by a source object (e.g. AVAudioEnvironmentNode) can be used.
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/avfaudio/avaudioenvironmentreverbparameters?language=objc)
    #[unsafe(super(NSObject))]
    #[derive(Debug, PartialEq, Eq, Hash)]
    pub struct AVAudioEnvironmentReverbParameters;
);

extern_conformance!(
    unsafe impl NSObjectProtocol for AVAudioEnvironmentReverbParameters {}
);

impl AVAudioEnvironmentReverbParameters {
    extern_methods!(
        #[unsafe(method(init))]
        #[unsafe(method_family = init)]
        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;

        /// Turns on/off the reverb
        ///
        /// Default:    NO
        #[unsafe(method(enable))]
        #[unsafe(method_family = none)]
        pub unsafe fn enable(&self) -> bool;

        /// Setter for [`enable`][Self::enable].
        #[unsafe(method(setEnable:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setEnable(&self, enable: bool);

        /// Controls the master level of the reverb
        ///
        /// Range:      -40 to 40 dB
        /// Default:    0.0
        #[unsafe(method(level))]
        #[unsafe(method_family = none)]
        pub unsafe fn level(&self) -> c_float;

        /// Setter for [`level`][Self::level].
        #[unsafe(method(setLevel:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setLevel(&self, level: c_float);

        #[cfg(feature = "AVAudioUnitEQ")]
        /// filter that applies to the output of the reverb
        #[unsafe(method(filterParameters))]
        #[unsafe(method_family = none)]
        pub unsafe fn filterParameters(&self) -> Retained<AVAudioUnitEQFilterParameters>;

        #[cfg(feature = "AVAudioUnitReverb")]
        /// Load one of the reverb's factory presets
        ///
        /// Parameter `preset`: Reverb preset to be set.
        ///
        /// Loading a factory reverb preset changes the sound of the reverb. This works independently
        /// of the filter which follows the reverb in the signal chain.
        #[unsafe(method(loadFactoryReverbPreset:))]
        #[unsafe(method_family = none)]
        pub unsafe fn loadFactoryReverbPreset(&self, preset: AVAudioUnitReverbPreset);
    );
}

/// Methods declared on superclass `NSObject`.
impl AVAudioEnvironmentReverbParameters {
    extern_methods!(
        #[unsafe(method(new))]
        #[unsafe(method_family = new)]
        pub unsafe fn new() -> Retained<Self>;
    );
}

/// Types of output for AVAudio3DMixingRenderingAlgorithmAuto
///
/// The output type determines the rendering method for any input bus using
/// AVAudio3DMixingRenderingAlgorithmAuto.
///
/// AVAudioEnvironmentOutputTypeAuto
/// Automatically detect playback route and pick the correct output type when possible.
/// Wired output defaults to AVAudioEnvironmentOutputTypeHeadphones and Manual Rendering
/// with a two-channel output layout defaults to AVAudioEnvironmentOutputTypeExternalSpeakers.
///
/// AVAudioEnvironmentOutputTypeHeadphones
/// Render for headphones.
///
/// AVAudioEnvironmentOutputTypeBuiltInSpeakers
/// Render for built-in speakers on the current hardware. The output will not be suitable
/// for playback on other hardware. On iOS devices, the rendering may be specific to
/// device orientation. Manual Rendering modes may not provide the intended rendering if
/// the orientation changes between rendering the audio and playing it back.
///
/// AVAudioEnvironmentOutputTypeExternalSpeakers
/// Render for external speakers based on the environment node's output channel layout.
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/avfaudio/avaudioenvironmentoutputtype?language=objc)
// NS_ENUM
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct AVAudioEnvironmentOutputType(pub NSInteger);
impl AVAudioEnvironmentOutputType {
    #[doc(alias = "AVAudioEnvironmentOutputTypeAuto")]
    pub const Auto: Self = Self(0);
    #[doc(alias = "AVAudioEnvironmentOutputTypeHeadphones")]
    pub const Headphones: Self = Self(1);
    #[doc(alias = "AVAudioEnvironmentOutputTypeBuiltInSpeakers")]
    pub const BuiltInSpeakers: Self = Self(2);
    #[doc(alias = "AVAudioEnvironmentOutputTypeExternalSpeakers")]
    pub const ExternalSpeakers: Self = Self(3);
}

unsafe impl Encode for AVAudioEnvironmentOutputType {
    const ENCODING: Encoding = NSInteger::ENCODING;
}

unsafe impl RefEncode for AVAudioEnvironmentOutputType {
    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}

extern_class!(
    /// Mixer node that simulates a 3D environment
    ///
    /// AVAudioEnvironmentNode is a mixer node that simulates a 3D audio environment. Any node that
    /// conforms to the AVAudioMixing protocol (e.g. AVAudioPlayerNode) can act as a source in this
    /// environment.
    ///
    /// The environment has an implicit "listener". By controlling the listener's position and
    /// orientation, the application controls the way the user experiences the virtual world.
    /// In addition, this node also defines properties for distance attenuation and reverberation
    /// that help characterize the environment.
    ///
    /// It is important to note that AVAudio3DMixingSourceMode affects how inputs with different channel
    /// configurations are rendered. By default, only inputs with a mono channel are spatialized.
    ///
    /// In order to set the environment node’s output to a multichannel format, use an AVAudioFormat
    /// with a desired AudioChannelLayout.
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/avfaudio/avaudioenvironmentnode?language=objc)
    #[unsafe(super(AVAudioNode, NSObject))]
    #[derive(Debug, PartialEq, Eq, Hash)]
    #[cfg(feature = "AVAudioNode")]
    pub struct AVAudioEnvironmentNode;
);

#[cfg(all(feature = "AVAudioMixing", feature = "AVAudioNode"))]
extern_conformance!(
    unsafe impl AVAudio3DMixing for AVAudioEnvironmentNode {}
);

#[cfg(all(feature = "AVAudioMixing", feature = "AVAudioNode"))]
extern_conformance!(
    unsafe impl AVAudioMixing for AVAudioEnvironmentNode {}
);

#[cfg(all(feature = "AVAudioMixing", feature = "AVAudioNode"))]
extern_conformance!(
    unsafe impl AVAudioStereoMixing for AVAudioEnvironmentNode {}
);

#[cfg(feature = "AVAudioNode")]
extern_conformance!(
    unsafe impl NSObjectProtocol for AVAudioEnvironmentNode {}
);

#[cfg(feature = "AVAudioNode")]
impl AVAudioEnvironmentNode {
    extern_methods!(
        #[unsafe(method(init))]
        #[unsafe(method_family = init)]
        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;

        /// Type of output hardware to be used with AVAudio3DMixingRenderingAlgorithmAuto
        ///
        /// Output hardware cannot be automatically determined in Manual Rendering modes or for wired
        /// output. This property can be used to override the output type if the correct type is known.
        ///
        /// Selecting an output type that does not match the actual hardware can produce unexpected
        /// results, especially with AVAudioEnvironmentOutputTypeBuiltInSpeakers. An app choosing
        /// a value other than AVAudio3DMixingOutputTypeAuto should listen to route change
        /// notifications and update the output type accordingly.
        ///
        /// Default:    AVAudio3DMixingOutputTypeAuto
        #[unsafe(method(outputType))]
        #[unsafe(method_family = none)]
        pub unsafe fn outputType(&self) -> AVAudioEnvironmentOutputType;

        /// Setter for [`outputType`][Self::outputType].
        #[unsafe(method(setOutputType:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setOutputType(&self, output_type: AVAudioEnvironmentOutputType);

        /// The mixer's output volume.
        ///
        /// This accesses the mixer's output volume (0.0-1.0, inclusive).
        #[unsafe(method(outputVolume))]
        #[unsafe(method_family = none)]
        pub unsafe fn outputVolume(&self) -> c_float;

        /// Setter for [`outputVolume`][Self::outputVolume].
        #[unsafe(method(setOutputVolume:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setOutputVolume(&self, output_volume: c_float);

        #[cfg(feature = "AVAudioTypes")]
        /// Find an unused input bus
        ///
        /// This will find and return the first input bus to which no other node is connected.
        #[unsafe(method(nextAvailableInputBus))]
        #[unsafe(method_family = none)]
        pub unsafe fn nextAvailableInputBus(&self) -> AVAudioNodeBus;

        #[cfg(feature = "AVAudioTypes")]
        /// Sets the listener's position in the 3D environment
        ///
        /// The coordinates are specified in meters.
        /// Default:
        /// The default position of the listener is at the origin.
        /// x: 0.0
        /// y: 0.0
        /// z: 0.0
        #[unsafe(method(listenerPosition))]
        #[unsafe(method_family = none)]
        pub unsafe fn listenerPosition(&self) -> AVAudio3DPoint;

        #[cfg(feature = "AVAudioTypes")]
        /// Setter for [`listenerPosition`][Self::listenerPosition].
        #[unsafe(method(setListenerPosition:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setListenerPosition(&self, listener_position: AVAudio3DPoint);

        #[cfg(feature = "AVAudioTypes")]
        /// The listener's orientation in the environment
        ///
        /// Changing listenerVectorOrientation will result in a corresponding change in listenerAngularOrientation.
        /// Default:
        /// The default orientation is with the listener looking directly along the negative Z axis.
        /// forward: (0, 0, -1)
        /// up:      (0, 1, 0)
        #[unsafe(method(listenerVectorOrientation))]
        #[unsafe(method_family = none)]
        pub unsafe fn listenerVectorOrientation(&self) -> AVAudio3DVectorOrientation;

        #[cfg(feature = "AVAudioTypes")]
        /// Setter for [`listenerVectorOrientation`][Self::listenerVectorOrientation].
        #[unsafe(method(setListenerVectorOrientation:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setListenerVectorOrientation(
            &self,
            listener_vector_orientation: AVAudio3DVectorOrientation,
        );

        #[cfg(feature = "AVAudioTypes")]
        /// The listener's orientation in the environment
        ///
        /// Changing listenerAngularOrientation will result in a corresponding change in listenerVectorOrientation.
        /// All angles are specified in degrees.
        /// Default:
        /// The default orientation is with the listener looking directly along the negative Z axis.
        /// yaw: 0.0
        /// pitch: 0.0
        /// roll: 0.0
        #[unsafe(method(listenerAngularOrientation))]
        #[unsafe(method_family = none)]
        pub unsafe fn listenerAngularOrientation(&self) -> AVAudio3DAngularOrientation;

        #[cfg(feature = "AVAudioTypes")]
        /// Setter for [`listenerAngularOrientation`][Self::listenerAngularOrientation].
        #[unsafe(method(setListenerAngularOrientation:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setListenerAngularOrientation(
            &self,
            listener_angular_orientation: AVAudio3DAngularOrientation,
        );

        /// The distance attenuation parameters for the environment
        #[unsafe(method(distanceAttenuationParameters))]
        #[unsafe(method_family = none)]
        pub unsafe fn distanceAttenuationParameters(
            &self,
        ) -> Retained<AVAudioEnvironmentDistanceAttenuationParameters>;

        /// The reverb parameters for the environment
        #[unsafe(method(reverbParameters))]
        #[unsafe(method_family = none)]
        pub unsafe fn reverbParameters(&self) -> Retained<AVAudioEnvironmentReverbParameters>;

        /// Returns an array of AVAudio3DMixingRenderingAlgorithm values based on the current output format
        ///
        /// AVAudioEnvironmentNode supports several rendering algorithms per input bus which are defined
        /// in
        /// <AVFAudio
        /// /AVAudioMixing.h>.
        ///
        /// Depending on the current output format of the environment node, this method returns
        /// an immutable array of the applicable rendering algorithms. This is important when the
        /// environment node has been configured to a multichannel output format because only a subset
        /// of the available rendering algorithms are designed to render to all of the channels.
        ///
        /// This information should be retrieved after a successful connection to the destination node
        /// via the engine's connect method.
        #[unsafe(method(applicableRenderingAlgorithms))]
        #[unsafe(method_family = none)]
        pub unsafe fn applicableRenderingAlgorithms(&self) -> Retained<NSArray<NSNumber>>;

        /// On capable devices, listener orientation will be automatically rotated based on user's head-orientation if enabled.
        #[unsafe(method(isListenerHeadTrackingEnabled))]
        #[unsafe(method_family = none)]
        pub unsafe fn isListenerHeadTrackingEnabled(&self) -> bool;

        /// Setter for [`isListenerHeadTrackingEnabled`][Self::isListenerHeadTrackingEnabled].
        #[unsafe(method(setListenerHeadTrackingEnabled:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setListenerHeadTrackingEnabled(&self, listener_head_tracking_enabled: bool);
    );
}

/// Methods declared on superclass `NSObject`.
#[cfg(feature = "AVAudioNode")]
impl AVAudioEnvironmentNode {
    extern_methods!(
        #[unsafe(method(new))]
        #[unsafe(method_family = new)]
        pub unsafe fn new() -> Retained<Self>;
    );
}