objc2_avf_audio/generated/AVAudioEnvironmentNode.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::*;
6use objc2_foundation::*;
7
8use crate::*;
9
10/// Types of distance attenuation models
11///
12/// Distance attenuation is the natural attenuation of sound when traveling from the source to
13/// the listener. The different attenuation models listed below describe the drop-off in gain as
14/// the source moves away from the listener.
15///
16/// AVAudioEnvironmentDistanceAttenuationModelExponential
17/// distanceGain = (distance / referenceDistance) ^ (-rolloffFactor)
18///
19/// AVAudioEnvironmentDistanceAttenuationModelInverse
20/// distanceGain = referenceDistance / (referenceDistance + rolloffFactor *
21/// (distance – referenceDistance))
22///
23/// AVAudioEnvironmentDistanceAttenuationModelLinear
24/// distanceGain = (1 – rolloffFactor * (distance – referenceDistance) /
25/// (maximumDistance – referenceDistance))
26///
27/// With all the distance models, if the formula can not be evaluated then the source will not
28/// be attenuated. For example, if a linear model is being used with referenceDistance equal
29/// to maximumDistance, then the gain equation will have a divide-by-zero error in it. In this case,
30/// there is no attenuation for that source.
31///
32/// All the values for distance are specified in meters.
33///
34/// See also [Apple's documentation](https://developer.apple.com/documentation/avfaudio/avaudioenvironmentdistanceattenuationmodel?language=objc)
35// NS_ENUM
36#[repr(transparent)]
37#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
38pub struct AVAudioEnvironmentDistanceAttenuationModel(pub NSInteger);
39impl AVAudioEnvironmentDistanceAttenuationModel {
40 #[doc(alias = "AVAudioEnvironmentDistanceAttenuationModelExponential")]
41 pub const Exponential: Self = Self(1);
42 #[doc(alias = "AVAudioEnvironmentDistanceAttenuationModelInverse")]
43 pub const Inverse: Self = Self(2);
44 #[doc(alias = "AVAudioEnvironmentDistanceAttenuationModelLinear")]
45 pub const Linear: Self = Self(3);
46}
47
48unsafe impl Encode for AVAudioEnvironmentDistanceAttenuationModel {
49 const ENCODING: Encoding = NSInteger::ENCODING;
50}
51
52unsafe impl RefEncode for AVAudioEnvironmentDistanceAttenuationModel {
53 const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
54}
55
56extern_class!(
57 /// Parameters specifying the amount of distance attenuation
58 ///
59 /// A standalone instance of AVAudioEnvironmentDistanceAttenuationParameters cannot be created.
60 /// Only an instance vended out by a source object (e.g. AVAudioEnvironmentNode) can be used.
61 ///
62 /// See also [Apple's documentation](https://developer.apple.com/documentation/avfaudio/avaudioenvironmentdistanceattenuationparameters?language=objc)
63 #[unsafe(super(NSObject))]
64 #[derive(Debug, PartialEq, Eq, Hash)]
65 pub struct AVAudioEnvironmentDistanceAttenuationParameters;
66);
67
68unsafe impl NSObjectProtocol for AVAudioEnvironmentDistanceAttenuationParameters {}
69
70impl AVAudioEnvironmentDistanceAttenuationParameters {
71 extern_methods!(
72 #[unsafe(method(init))]
73 #[unsafe(method_family = init)]
74 pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
75
76 /// Type of distance attenuation model
77 ///
78 /// Default: AVAudioEnvironmentDistanceAttenuationModelInverse
79 #[unsafe(method(distanceAttenuationModel))]
80 #[unsafe(method_family = none)]
81 pub unsafe fn distanceAttenuationModel(&self)
82 -> AVAudioEnvironmentDistanceAttenuationModel;
83
84 /// Setter for [`distanceAttenuationModel`][Self::distanceAttenuationModel].
85 #[unsafe(method(setDistanceAttenuationModel:))]
86 #[unsafe(method_family = none)]
87 pub unsafe fn setDistanceAttenuationModel(
88 &self,
89 distance_attenuation_model: AVAudioEnvironmentDistanceAttenuationModel,
90 );
91
92 /// The minimum distance at which attenuation is applied
93 ///
94 /// Default: 1.0 meter
95 /// Models: AVAudioEnvironmentDistanceAttenuationModelInverse,
96 /// AVAudioEnvironmentDistanceAttenuationModelLinear
97 #[unsafe(method(referenceDistance))]
98 #[unsafe(method_family = none)]
99 pub unsafe fn referenceDistance(&self) -> c_float;
100
101 /// Setter for [`referenceDistance`][Self::referenceDistance].
102 #[unsafe(method(setReferenceDistance:))]
103 #[unsafe(method_family = none)]
104 pub unsafe fn setReferenceDistance(&self, reference_distance: c_float);
105
106 /// The distance beyond which no further attenuation is applied
107 ///
108 /// Default: 100000.0 meters
109 /// Models: AVAudioEnvironmentDistanceAttenuationModelLinear
110 #[unsafe(method(maximumDistance))]
111 #[unsafe(method_family = none)]
112 pub unsafe fn maximumDistance(&self) -> c_float;
113
114 /// Setter for [`maximumDistance`][Self::maximumDistance].
115 #[unsafe(method(setMaximumDistance:))]
116 #[unsafe(method_family = none)]
117 pub unsafe fn setMaximumDistance(&self, maximum_distance: c_float);
118
119 /// Determines the attenuation curve
120 ///
121 /// A higher value results in a steeper attenuation curve.
122 /// The rolloff factor should be a value greater than 0.
123 /// Default: 1.0
124 /// Models: AVAudioEnvironmentDistanceAttenuationModelExponential
125 /// AVAudioEnvironmentDistanceAttenuationModelInverse
126 /// AVAudioEnvironmentDistanceAttenuationModelLinear
127 #[unsafe(method(rolloffFactor))]
128 #[unsafe(method_family = none)]
129 pub unsafe fn rolloffFactor(&self) -> c_float;
130
131 /// Setter for [`rolloffFactor`][Self::rolloffFactor].
132 #[unsafe(method(setRolloffFactor:))]
133 #[unsafe(method_family = none)]
134 pub unsafe fn setRolloffFactor(&self, rolloff_factor: c_float);
135 );
136}
137
138/// Methods declared on superclass `NSObject`.
139impl AVAudioEnvironmentDistanceAttenuationParameters {
140 extern_methods!(
141 #[unsafe(method(new))]
142 #[unsafe(method_family = new)]
143 pub unsafe fn new() -> Retained<Self>;
144 );
145}
146
147extern_class!(
148 /// Parameters used to control the reverb in AVAudioEnvironmentNode
149 ///
150 /// Reverberation can be used to simulate the acoustic characteristics of an environment.
151 /// AVAudioEnvironmentNode has a built in reverb that describes the space that the listener
152 /// is in.
153 ///
154 /// The reverb also has a single filter that sits at the end of the chain. This filter is useful
155 /// to shape the overall sound of the reverb. For instance, one of the reverb presets can be
156 /// selected to simulate the general space and then the filter can be used to brighten or darken
157 /// the overall sound.
158 ///
159 /// A standalone instance of AVAudioEnvironmentReverbParameters cannot be created.
160 /// Only an instance vended out by a source object (e.g. AVAudioEnvironmentNode) can be used.
161 ///
162 /// See also [Apple's documentation](https://developer.apple.com/documentation/avfaudio/avaudioenvironmentreverbparameters?language=objc)
163 #[unsafe(super(NSObject))]
164 #[derive(Debug, PartialEq, Eq, Hash)]
165 pub struct AVAudioEnvironmentReverbParameters;
166);
167
168unsafe impl NSObjectProtocol for AVAudioEnvironmentReverbParameters {}
169
170impl AVAudioEnvironmentReverbParameters {
171 extern_methods!(
172 #[unsafe(method(init))]
173 #[unsafe(method_family = init)]
174 pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
175
176 /// Turns on/off the reverb
177 ///
178 /// Default: NO
179 #[unsafe(method(enable))]
180 #[unsafe(method_family = none)]
181 pub unsafe fn enable(&self) -> bool;
182
183 /// Setter for [`enable`][Self::enable].
184 #[unsafe(method(setEnable:))]
185 #[unsafe(method_family = none)]
186 pub unsafe fn setEnable(&self, enable: bool);
187
188 /// Controls the master level of the reverb
189 ///
190 /// Range: -40 to 40 dB
191 /// Default: 0.0
192 #[unsafe(method(level))]
193 #[unsafe(method_family = none)]
194 pub unsafe fn level(&self) -> c_float;
195
196 /// Setter for [`level`][Self::level].
197 #[unsafe(method(setLevel:))]
198 #[unsafe(method_family = none)]
199 pub unsafe fn setLevel(&self, level: c_float);
200
201 #[cfg(feature = "AVAudioUnitEQ")]
202 /// filter that applies to the output of the reverb
203 #[unsafe(method(filterParameters))]
204 #[unsafe(method_family = none)]
205 pub unsafe fn filterParameters(&self) -> Retained<AVAudioUnitEQFilterParameters>;
206
207 #[cfg(feature = "AVAudioUnitReverb")]
208 /// Load one of the reverb's factory presets
209 ///
210 /// Parameter `preset`: Reverb preset to be set.
211 ///
212 /// Loading a factory reverb preset changes the sound of the reverb. This works independently
213 /// of the filter which follows the reverb in the signal chain.
214 #[unsafe(method(loadFactoryReverbPreset:))]
215 #[unsafe(method_family = none)]
216 pub unsafe fn loadFactoryReverbPreset(&self, preset: AVAudioUnitReverbPreset);
217 );
218}
219
220/// Methods declared on superclass `NSObject`.
221impl AVAudioEnvironmentReverbParameters {
222 extern_methods!(
223 #[unsafe(method(new))]
224 #[unsafe(method_family = new)]
225 pub unsafe fn new() -> Retained<Self>;
226 );
227}
228
229/// Types of output for AVAudio3DMixingRenderingAlgorithmAuto
230///
231/// The output type determines the rendering method for any input bus using
232/// AVAudio3DMixingRenderingAlgorithmAuto.
233///
234/// AVAudioEnvironmentOutputTypeAuto
235/// Automatically detect playback route and pick the correct output type when possible.
236/// Wired output defaults to AVAudioEnvironmentOutputTypeHeadphones and Manual Rendering
237/// with a two-channel output layout defaults to AVAudioEnvironmentOutputTypeExternalSpeakers.
238///
239/// AVAudioEnvironmentOutputTypeHeadphones
240/// Render for headphones.
241///
242/// AVAudioEnvironmentOutputTypeBuiltInSpeakers
243/// Render for built-in speakers on the current hardware. The output will not be suitable
244/// for playback on other hardware. On iOS devices, the rendering may be specific to
245/// device orientation. Manual Rendering modes may not provide the intended rendering if
246/// the orientation changes between rendering the audio and playing it back.
247///
248/// AVAudioEnvironmentOutputTypeExternalSpeakers
249/// Render for external speakers based on the environment node's output channel layout.
250///
251/// See also [Apple's documentation](https://developer.apple.com/documentation/avfaudio/avaudioenvironmentoutputtype?language=objc)
252// NS_ENUM
253#[repr(transparent)]
254#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
255pub struct AVAudioEnvironmentOutputType(pub NSInteger);
256impl AVAudioEnvironmentOutputType {
257 #[doc(alias = "AVAudioEnvironmentOutputTypeAuto")]
258 pub const Auto: Self = Self(0);
259 #[doc(alias = "AVAudioEnvironmentOutputTypeHeadphones")]
260 pub const Headphones: Self = Self(1);
261 #[doc(alias = "AVAudioEnvironmentOutputTypeBuiltInSpeakers")]
262 pub const BuiltInSpeakers: Self = Self(2);
263 #[doc(alias = "AVAudioEnvironmentOutputTypeExternalSpeakers")]
264 pub const ExternalSpeakers: Self = Self(3);
265}
266
267unsafe impl Encode for AVAudioEnvironmentOutputType {
268 const ENCODING: Encoding = NSInteger::ENCODING;
269}
270
271unsafe impl RefEncode for AVAudioEnvironmentOutputType {
272 const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
273}
274
275extern_class!(
276 /// Mixer node that simulates a 3D environment
277 ///
278 /// AVAudioEnvironmentNode is a mixer node that simulates a 3D audio environment. Any node that
279 /// conforms to the AVAudioMixing protocol (e.g. AVAudioPlayerNode) can act as a source in this
280 /// environment.
281 ///
282 /// The environment has an implicit "listener". By controlling the listener's position and
283 /// orientation, the application controls the way the user experiences the virtual world.
284 /// In addition, this node also defines properties for distance attenuation and reverberation
285 /// that help characterize the environment.
286 ///
287 /// It is important to note that AVAudio3DMixingSourceMode affects how inputs with different channel
288 /// configurations are rendered. By default, only inputs with a mono channel are spatialized.
289 ///
290 /// In order to set the environment node’s output to a multichannel format, use an AVAudioFormat
291 /// with a desired AudioChannelLayout.
292 ///
293 /// See also [Apple's documentation](https://developer.apple.com/documentation/avfaudio/avaudioenvironmentnode?language=objc)
294 #[unsafe(super(AVAudioNode, NSObject))]
295 #[derive(Debug, PartialEq, Eq, Hash)]
296 #[cfg(feature = "AVAudioNode")]
297 pub struct AVAudioEnvironmentNode;
298);
299
300#[cfg(all(feature = "AVAudioMixing", feature = "AVAudioNode"))]
301unsafe impl AVAudio3DMixing for AVAudioEnvironmentNode {}
302
303#[cfg(all(feature = "AVAudioMixing", feature = "AVAudioNode"))]
304unsafe impl AVAudioMixing for AVAudioEnvironmentNode {}
305
306#[cfg(all(feature = "AVAudioMixing", feature = "AVAudioNode"))]
307unsafe impl AVAudioStereoMixing for AVAudioEnvironmentNode {}
308
309#[cfg(feature = "AVAudioNode")]
310unsafe impl NSObjectProtocol for AVAudioEnvironmentNode {}
311
312#[cfg(feature = "AVAudioNode")]
313impl AVAudioEnvironmentNode {
314 extern_methods!(
315 #[unsafe(method(init))]
316 #[unsafe(method_family = init)]
317 pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
318
319 /// Type of output hardware to be used with AVAudio3DMixingRenderingAlgorithmAuto
320 ///
321 /// Output hardware cannot be automatically determined in Manual Rendering modes or for wired
322 /// output. This property can be used to override the output type if the correct type is known.
323 ///
324 /// Selecting an output type that does not match the actual hardware can produce unexpected
325 /// results, especially with AVAudioEnvironmentOutputTypeBuiltInSpeakers. An app choosing
326 /// a value other than AVAudio3DMixingOutputTypeAuto should listen to route change
327 /// notifications and update the output type accordingly.
328 ///
329 /// Default: AVAudio3DMixingOutputTypeAuto
330 #[unsafe(method(outputType))]
331 #[unsafe(method_family = none)]
332 pub unsafe fn outputType(&self) -> AVAudioEnvironmentOutputType;
333
334 /// Setter for [`outputType`][Self::outputType].
335 #[unsafe(method(setOutputType:))]
336 #[unsafe(method_family = none)]
337 pub unsafe fn setOutputType(&self, output_type: AVAudioEnvironmentOutputType);
338
339 /// The mixer's output volume.
340 ///
341 /// This accesses the mixer's output volume (0.0-1.0, inclusive).
342 #[unsafe(method(outputVolume))]
343 #[unsafe(method_family = none)]
344 pub unsafe fn outputVolume(&self) -> c_float;
345
346 /// Setter for [`outputVolume`][Self::outputVolume].
347 #[unsafe(method(setOutputVolume:))]
348 #[unsafe(method_family = none)]
349 pub unsafe fn setOutputVolume(&self, output_volume: c_float);
350
351 #[cfg(feature = "AVAudioTypes")]
352 /// Find an unused input bus
353 ///
354 /// This will find and return the first input bus to which no other node is connected.
355 #[unsafe(method(nextAvailableInputBus))]
356 #[unsafe(method_family = none)]
357 pub unsafe fn nextAvailableInputBus(&self) -> AVAudioNodeBus;
358
359 #[cfg(feature = "AVAudioTypes")]
360 /// Sets the listener's position in the 3D environment
361 ///
362 /// The coordinates are specified in meters.
363 /// Default:
364 /// The default position of the listener is at the origin.
365 /// x: 0.0
366 /// y: 0.0
367 /// z: 0.0
368 #[unsafe(method(listenerPosition))]
369 #[unsafe(method_family = none)]
370 pub unsafe fn listenerPosition(&self) -> AVAudio3DPoint;
371
372 #[cfg(feature = "AVAudioTypes")]
373 /// Setter for [`listenerPosition`][Self::listenerPosition].
374 #[unsafe(method(setListenerPosition:))]
375 #[unsafe(method_family = none)]
376 pub unsafe fn setListenerPosition(&self, listener_position: AVAudio3DPoint);
377
378 #[cfg(feature = "AVAudioTypes")]
379 /// The listener's orientation in the environment
380 ///
381 /// Changing listenerVectorOrientation will result in a corresponding change in listenerAngularOrientation.
382 /// Default:
383 /// The default orientation is with the listener looking directly along the negative Z axis.
384 /// forward: (0, 0, -1)
385 /// up: (0, 1, 0)
386 #[unsafe(method(listenerVectorOrientation))]
387 #[unsafe(method_family = none)]
388 pub unsafe fn listenerVectorOrientation(&self) -> AVAudio3DVectorOrientation;
389
390 #[cfg(feature = "AVAudioTypes")]
391 /// Setter for [`listenerVectorOrientation`][Self::listenerVectorOrientation].
392 #[unsafe(method(setListenerVectorOrientation:))]
393 #[unsafe(method_family = none)]
394 pub unsafe fn setListenerVectorOrientation(
395 &self,
396 listener_vector_orientation: AVAudio3DVectorOrientation,
397 );
398
399 #[cfg(feature = "AVAudioTypes")]
400 /// The listener's orientation in the environment
401 ///
402 /// Changing listenerAngularOrientation will result in a corresponding change in listenerVectorOrientation.
403 /// All angles are specified in degrees.
404 /// Default:
405 /// The default orientation is with the listener looking directly along the negative Z axis.
406 /// yaw: 0.0
407 /// pitch: 0.0
408 /// roll: 0.0
409 #[unsafe(method(listenerAngularOrientation))]
410 #[unsafe(method_family = none)]
411 pub unsafe fn listenerAngularOrientation(&self) -> AVAudio3DAngularOrientation;
412
413 #[cfg(feature = "AVAudioTypes")]
414 /// Setter for [`listenerAngularOrientation`][Self::listenerAngularOrientation].
415 #[unsafe(method(setListenerAngularOrientation:))]
416 #[unsafe(method_family = none)]
417 pub unsafe fn setListenerAngularOrientation(
418 &self,
419 listener_angular_orientation: AVAudio3DAngularOrientation,
420 );
421
422 /// The distance attenuation parameters for the environment
423 #[unsafe(method(distanceAttenuationParameters))]
424 #[unsafe(method_family = none)]
425 pub unsafe fn distanceAttenuationParameters(
426 &self,
427 ) -> Retained<AVAudioEnvironmentDistanceAttenuationParameters>;
428
429 /// The reverb parameters for the environment
430 #[unsafe(method(reverbParameters))]
431 #[unsafe(method_family = none)]
432 pub unsafe fn reverbParameters(&self) -> Retained<AVAudioEnvironmentReverbParameters>;
433
434 /// Returns an array of AVAudio3DMixingRenderingAlgorithm values based on the current output format
435 ///
436 /// AVAudioEnvironmentNode supports several rendering algorithms per input bus which are defined
437 /// in
438 /// <AVFAudio
439 /// /AVAudioMixing.h>.
440 ///
441 /// Depending on the current output format of the environment node, this method returns
442 /// an immutable array of the applicable rendering algorithms. This is important when the
443 /// environment node has been configured to a multichannel output format because only a subset
444 /// of the available rendering algorithms are designed to render to all of the channels.
445 ///
446 /// This information should be retrieved after a successful connection to the destination node
447 /// via the engine's connect method.
448 #[unsafe(method(applicableRenderingAlgorithms))]
449 #[unsafe(method_family = none)]
450 pub unsafe fn applicableRenderingAlgorithms(&self) -> Retained<NSArray<NSNumber>>;
451
452 /// On capable devices, listener orientation will be automatically rotated based on user's head-orientation if enabled.
453 #[unsafe(method(isListenerHeadTrackingEnabled))]
454 #[unsafe(method_family = none)]
455 pub unsafe fn isListenerHeadTrackingEnabled(&self) -> bool;
456
457 /// Setter for [`isListenerHeadTrackingEnabled`][Self::isListenerHeadTrackingEnabled].
458 #[unsafe(method(setListenerHeadTrackingEnabled:))]
459 #[unsafe(method_family = none)]
460 pub unsafe fn setListenerHeadTrackingEnabled(&self, listener_head_tracking_enabled: bool);
461 );
462}
463
464/// Methods declared on superclass `NSObject`.
465#[cfg(feature = "AVAudioNode")]
466impl AVAudioEnvironmentNode {
467 extern_methods!(
468 #[unsafe(method(new))]
469 #[unsafe(method_family = new)]
470 pub unsafe fn new() -> Retained<Self>;
471 );
472}