objc2_avf_audio/generated/AVAudioConverter.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/// values for the primeMethod property. See further discussion under AVAudioConverterPrimeInfo.
11///
12/// See also [Apple's documentation](https://developer.apple.com/documentation/avfaudio/avaudioconverterprimemethod?language=objc)
13// NS_ENUM
14#[repr(transparent)]
15#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
16pub struct AVAudioConverterPrimeMethod(pub NSInteger);
17impl AVAudioConverterPrimeMethod {
18 /// Primes with leading + trailing input frames.
19 #[doc(alias = "AVAudioConverterPrimeMethod_Pre")]
20 pub const Pre: Self = Self(0);
21 /// Only primes with trailing (zero latency). Leading frames are assumed to be silence.
22 #[doc(alias = "AVAudioConverterPrimeMethod_Normal")]
23 pub const Normal: Self = Self(1);
24 /// Acts in "latency" mode. Both leading and trailing frames assumed to be silence.
25 #[doc(alias = "AVAudioConverterPrimeMethod_None")]
26 pub const None: Self = Self(2);
27}
28
29unsafe impl Encode for AVAudioConverterPrimeMethod {
30 const ENCODING: Encoding = NSInteger::ENCODING;
31}
32
33unsafe impl RefEncode for AVAudioConverterPrimeMethod {
34 const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
35}
36
37/// This struct is the value of the primeInfo property and specifies priming information.
38///
39/// When using convertToBuffer:error:withInputFromBlock: (either a single call or a series of calls), some
40/// conversions, particularly involving sample-rate conversion, ideally require a certain
41/// number of input frames previous to the normal start input frame and beyond the end of
42/// the last expected input frame in order to yield high-quality results.
43///
44/// These are expressed in the leadingFrames and trailingFrames members of the structure.
45///
46/// The very first call to convertToBuffer:error:withInputFromBlock:, or first call after
47/// reset, will request additional input frames beyond those normally
48/// expected in the input proc callback to fulfill this first AudioConverterFillComplexBuffer()
49/// request. The number of additional frames requested, depending on the prime method, will
50/// be approximately:
51///
52/// Prime method | Additional frames
53/// ------------------------------------|----------------------
54/// AVAudioConverterPrimeMethod_Pre | leadingFrames + trailingFrames
55/// AVAudioConverterPrimeMethod_Normal | trailingFrames
56/// AVAudioConverterPrimeMethod_None | 0
57///
58/// Thus, in effect, the first input proc callback(s) may provide not only the leading
59/// frames, but also may "read ahead" by an additional number of trailing frames depending
60/// on the prime method.
61///
62/// AVAudioConverterPrimeMethod_None is useful in a real-time application processing live input,
63/// in which case trailingFrames (relative to input sample rate) of through latency will be
64/// seen at the beginning of the output of the AudioConverter. In other real-time
65/// applications such as DAW systems, it may be possible to provide these initial extra
66/// audio frames since they are stored on disk or in memory somewhere and
67/// AVAudioConverterPrimeMethod_Pre may be preferable. The default method is
68/// AVAudioConverterPrimeMethod_Normal, which requires no pre-seeking of the input stream and
69/// generates no latency at the output.
70///
71/// Field: leadingFrames
72/// Specifies the number of leading (previous) input frames, relative to the normal/desired
73/// start input frame, required by the converter to perform a high quality conversion. If
74/// using AVAudioConverterPrimeMethod_Pre, the client should "pre-seek" the input stream provided
75/// through the input proc by leadingFrames. If no frames are available previous to the
76/// desired input start frame (because, for example, the desired start frame is at the very
77/// beginning of available audio), then provide "leadingFrames" worth of initial zero frames
78/// in the input proc. Do not "pre-seek" in the default case of
79/// AVAudioConverterPrimeMethod_Normal or when using AVAudioConverterPrimeMethod_None.
80///
81/// Field: trailingFrames
82/// Specifies the number of trailing input frames (past the normal/expected end input frame)
83/// required by the converter to perform a high quality conversion. The client should be
84/// prepared to provide this number of additional input frames except when using
85/// AVAudioConverterPrimeMethod_None. If no more frames of input are available in the input stream
86/// (because, for example, the desired end frame is at the end of an audio file), then zero
87/// (silent) trailing frames will be synthesized for the client.
88///
89/// See also [Apple's documentation](https://developer.apple.com/documentation/avfaudio/avaudioconverterprimeinfo?language=objc)
90#[cfg(feature = "AVAudioTypes")]
91#[repr(C)]
92#[derive(Clone, Copy, Debug, PartialEq)]
93pub struct AVAudioConverterPrimeInfo {
94 pub leadingFrames: AVAudioFrameCount,
95 pub trailingFrames: AVAudioFrameCount,
96}
97
98#[cfg(feature = "AVAudioTypes")]
99unsafe impl Encode for AVAudioConverterPrimeInfo {
100 const ENCODING: Encoding = Encoding::Struct(
101 "AVAudioConverterPrimeInfo",
102 &[<AVAudioFrameCount>::ENCODING, <AVAudioFrameCount>::ENCODING],
103 );
104}
105
106#[cfg(feature = "AVAudioTypes")]
107unsafe impl RefEncode for AVAudioConverterPrimeInfo {
108 const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
109}
110
111/// You must return one of these codes from your AVAudioConverterInputBlock.
112///
113/// See also [Apple's documentation](https://developer.apple.com/documentation/avfaudio/avaudioconverterinputstatus?language=objc)
114// NS_ENUM
115#[repr(transparent)]
116#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
117pub struct AVAudioConverterInputStatus(pub NSInteger);
118impl AVAudioConverterInputStatus {
119 /// This is the normal case where you supply data to the converter.
120 #[doc(alias = "AVAudioConverterInputStatus_HaveData")]
121 pub const HaveData: Self = Self(0);
122 /// If you are out of data for now, set *ioNumberOfPackets = 0 and return
123 /// AVAudioConverterInputStatus_NoDataNow; it is possible that some of the supplied input data
124 /// may not be converted to output immediately, but instead may be converted to output only
125 /// if/when more input is provided or the end-of-stream is indicated with the
126 /// AVAudioConverterInputStatus_EndOfStream status code.
127 #[doc(alias = "AVAudioConverterInputStatus_NoDataNow")]
128 pub const NoDataNow: Self = Self(1);
129 /// If you are at the end of stream, set *ioNumberOfPackets = 0 and return
130 /// AVAudioConverterInputStatus_EndOfStream.
131 #[doc(alias = "AVAudioConverterInputStatus_EndOfStream")]
132 pub const EndOfStream: Self = Self(2);
133}
134
135unsafe impl Encode for AVAudioConverterInputStatus {
136 const ENCODING: Encoding = NSInteger::ENCODING;
137}
138
139unsafe impl RefEncode for AVAudioConverterInputStatus {
140 const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
141}
142
143/// These values are returned from convertToBuffer:error:withInputFromBlock:
144///
145/// See also [Apple's documentation](https://developer.apple.com/documentation/avfaudio/avaudioconverteroutputstatus?language=objc)
146// NS_ENUM
147#[repr(transparent)]
148#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
149pub struct AVAudioConverterOutputStatus(pub NSInteger);
150impl AVAudioConverterOutputStatus {
151 /// All of the requested data was returned.
152 #[doc(alias = "AVAudioConverterOutputStatus_HaveData")]
153 pub const HaveData: Self = Self(0);
154 /// Not enough input was available to satisfy the request at the current time. The output buffer
155 /// contains as much as could be converted.
156 #[doc(alias = "AVAudioConverterOutputStatus_InputRanDry")]
157 pub const InputRanDry: Self = Self(1);
158 /// The end of stream has been reached. No data was returned.
159 #[doc(alias = "AVAudioConverterOutputStatus_EndOfStream")]
160 pub const EndOfStream: Self = Self(2);
161 /// An error occurred.
162 #[doc(alias = "AVAudioConverterOutputStatus_Error")]
163 pub const Error: Self = Self(3);
164}
165
166unsafe impl Encode for AVAudioConverterOutputStatus {
167 const ENCODING: Encoding = NSInteger::ENCODING;
168}
169
170unsafe impl RefEncode for AVAudioConverterOutputStatus {
171 const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
172}
173
174/// A block which will be called by convertToBuffer:error:withInputFromBlock: to get input data as needed.
175///
176///
177/// Parameter `inNumberOfPackets`: This will be the number of packets required to complete the request. You may supply more or
178/// less that this amount. If less, then the input block will get called again.
179///
180///
181/// Parameter `outStatus`: The block must set the appropriate AVAudioConverterInputStatus enum value.
182///
183/// If you have supplied data, set outStatus to AVAudioConverterInputStatus_HaveData and return
184/// an AVAudioBuffer.
185///
186/// If you are out of data for now, set outStatus to AVAudioConverterInputStatus_NoDataNow and
187/// return nil, and the conversion routine will return as much output as could be converted with
188/// the input already supplied.
189///
190/// If you are at the end of stream, set outStatus to AVAudioConverterInputStatus_EndOfStream,
191/// and return nil.
192///
193///
194/// Returns: An AVAudioBuffer containing data to be converted, or nil if at end of stream or no data is
195/// available. The data in the returned buffer must not be cleared or re-filled until the input
196/// block is called again or the conversion has finished.
197///
198/// convertToBuffer:error:withInputFromBlock: will return as much output as could be converted
199/// with the input already supplied.
200///
201/// See also [Apple's documentation](https://developer.apple.com/documentation/avfaudio/avaudioconverterinputblock?language=objc)
202#[cfg(all(
203 feature = "AVAudioBuffer",
204 feature = "AVAudioTypes",
205 feature = "block2"
206))]
207pub type AVAudioConverterInputBlock = *mut block2::DynBlock<
208 dyn Fn(AVAudioPacketCount, NonNull<AVAudioConverterInputStatus>) -> *mut AVAudioBuffer,
209>;
210
211extern_class!(
212 /// Converts streams of audio between various formats.
213 ///
214 /// See also [Apple's documentation](https://developer.apple.com/documentation/avfaudio/avaudioconverter?language=objc)
215 #[unsafe(super(NSObject))]
216 #[derive(Debug, PartialEq, Eq, Hash)]
217 pub struct AVAudioConverter;
218);
219
220extern_conformance!(
221 unsafe impl NSObjectProtocol for AVAudioConverter {}
222);
223
224impl AVAudioConverter {
225 extern_methods!(
226 #[cfg(feature = "AVAudioFormat")]
227 /// Initialize from input and output formats.
228 ///
229 /// Parameter `fromFormat`: The input format.
230 ///
231 /// Parameter `toFormat`: The output format.
232 ///
233 /// Returns nil if the format conversion is not possible.
234 #[unsafe(method(initFromFormat:toFormat:))]
235 #[unsafe(method_family = init)]
236 pub unsafe fn initFromFormat_toFormat(
237 this: Allocated<Self>,
238 from_format: &AVAudioFormat,
239 to_format: &AVAudioFormat,
240 ) -> Option<Retained<Self>>;
241
242 /// Resets the converter so that a new stream may be converted.
243 #[unsafe(method(reset))]
244 #[unsafe(method_family = none)]
245 pub unsafe fn reset(&self);
246
247 #[cfg(feature = "AVAudioFormat")]
248 /// The format of the input audio stream. (NB. AVAudioFormat includes the channel layout)
249 #[unsafe(method(inputFormat))]
250 #[unsafe(method_family = none)]
251 pub unsafe fn inputFormat(&self) -> Retained<AVAudioFormat>;
252
253 #[cfg(feature = "AVAudioFormat")]
254 /// The format of the output audio stream. (NB. AVAudioFormat includes the channel layout)
255 #[unsafe(method(outputFormat))]
256 #[unsafe(method_family = none)]
257 pub unsafe fn outputFormat(&self) -> Retained<AVAudioFormat>;
258
259 /// An array of integers indicating from which input to derive each output.
260 ///
261 /// The array has size equal to the number of output channels. Each element's value is the input
262 /// channel number, starting with zero, that is to be copied to that output. A negative value
263 /// means that the output channel will have no source and will be silent. Setting a channel map
264 /// overrides channel mapping due to any channel layouts in the input and output formats that
265 /// may have been supplied.
266 #[unsafe(method(channelMap))]
267 #[unsafe(method_family = none)]
268 pub unsafe fn channelMap(&self) -> Retained<NSArray<NSNumber>>;
269
270 /// Setter for [`channelMap`][Self::channelMap].
271 #[unsafe(method(setChannelMap:))]
272 #[unsafe(method_family = none)]
273 pub unsafe fn setChannelMap(&self, channel_map: &NSArray<NSNumber>);
274
275 /// Decoders require some data in the form of a magicCookie in order to decode properly.
276 /// Encoders will produce a magicCookie.
277 #[unsafe(method(magicCookie))]
278 #[unsafe(method_family = none)]
279 pub unsafe fn magicCookie(&self) -> Option<Retained<NSData>>;
280
281 /// Setter for [`magicCookie`][Self::magicCookie].
282 #[unsafe(method(setMagicCookie:))]
283 #[unsafe(method_family = none)]
284 pub unsafe fn setMagicCookie(&self, magic_cookie: Option<&NSData>);
285
286 /// If YES and channel remapping is necessary, then channels will be mixed as
287 /// appropriate instead of remapped. Default value is NO.
288 #[unsafe(method(downmix))]
289 #[unsafe(method_family = none)]
290 pub unsafe fn downmix(&self) -> bool;
291
292 /// Setter for [`downmix`][Self::downmix].
293 #[unsafe(method(setDownmix:))]
294 #[unsafe(method_family = none)]
295 pub unsafe fn setDownmix(&self, downmix: bool);
296
297 /// Setting YES will turn on dither, if dither makes sense in given the current formats
298 /// and settings. Default value is NO.
299 #[unsafe(method(dither))]
300 #[unsafe(method_family = none)]
301 pub unsafe fn dither(&self) -> bool;
302
303 /// Setter for [`dither`][Self::dither].
304 #[unsafe(method(setDither:))]
305 #[unsafe(method_family = none)]
306 pub unsafe fn setDither(&self, dither: bool);
307
308 /// An AVAudioQuality value as defined in AVAudioSettings.h.
309 #[unsafe(method(sampleRateConverterQuality))]
310 #[unsafe(method_family = none)]
311 pub unsafe fn sampleRateConverterQuality(&self) -> NSInteger;
312
313 /// Setter for [`sampleRateConverterQuality`][Self::sampleRateConverterQuality].
314 #[unsafe(method(setSampleRateConverterQuality:))]
315 #[unsafe(method_family = none)]
316 pub unsafe fn setSampleRateConverterQuality(
317 &self,
318 sample_rate_converter_quality: NSInteger,
319 );
320
321 /// An AVSampleRateConverterAlgorithmKey value as defined in AVAudioSettings.h.
322 #[unsafe(method(sampleRateConverterAlgorithm))]
323 #[unsafe(method_family = none)]
324 pub unsafe fn sampleRateConverterAlgorithm(&self) -> Option<Retained<NSString>>;
325
326 /// Setter for [`sampleRateConverterAlgorithm`][Self::sampleRateConverterAlgorithm].
327 #[unsafe(method(setSampleRateConverterAlgorithm:))]
328 #[unsafe(method_family = none)]
329 pub unsafe fn setSampleRateConverterAlgorithm(
330 &self,
331 sample_rate_converter_algorithm: Option<&NSString>,
332 );
333
334 /// Indicates the priming method to be used by the sample rate converter or decoder.
335 #[unsafe(method(primeMethod))]
336 #[unsafe(method_family = none)]
337 pub unsafe fn primeMethod(&self) -> AVAudioConverterPrimeMethod;
338
339 /// Setter for [`primeMethod`][Self::primeMethod].
340 #[unsafe(method(setPrimeMethod:))]
341 #[unsafe(method_family = none)]
342 pub unsafe fn setPrimeMethod(&self, prime_method: AVAudioConverterPrimeMethod);
343
344 #[cfg(feature = "AVAudioTypes")]
345 /// Indicates the the number of priming frames.
346 #[unsafe(method(primeInfo))]
347 #[unsafe(method_family = none)]
348 pub unsafe fn primeInfo(&self) -> AVAudioConverterPrimeInfo;
349
350 #[cfg(feature = "AVAudioTypes")]
351 /// Setter for [`primeInfo`][Self::primeInfo].
352 #[unsafe(method(setPrimeInfo:))]
353 #[unsafe(method_family = none)]
354 pub unsafe fn setPrimeInfo(&self, prime_info: AVAudioConverterPrimeInfo);
355
356 #[cfg(feature = "AVAudioBuffer")]
357 /// Perform a simple conversion. That is, a conversion which does not involve codecs or sample rate conversion.
358 ///
359 /// Parameter `inputBuffer`: The input buffer.
360 ///
361 /// Parameter `outputBuffer`: The output buffer.
362 ///
363 /// Parameter `outError`: An error if the conversion fails.
364 ///
365 /// Returns: YES is returned on success, NO when an error has occurred.
366 ///
367 /// The output buffer's frameCapacity should be at least at large as the inputBuffer's frameLength.
368 /// If the conversion involves a codec or sample rate conversion, you instead must use
369 /// convertToBuffer:error:withInputFromBlock:.
370 #[unsafe(method(convertToBuffer:fromBuffer:error:_))]
371 #[unsafe(method_family = none)]
372 pub unsafe fn convertToBuffer_fromBuffer_error(
373 &self,
374 output_buffer: &AVAudioPCMBuffer,
375 input_buffer: &AVAudioPCMBuffer,
376 ) -> Result<(), Retained<NSError>>;
377
378 #[cfg(all(
379 feature = "AVAudioBuffer",
380 feature = "AVAudioTypes",
381 feature = "block2"
382 ))]
383 /// Perform any supported conversion.
384 ///
385 /// Parameter `inputBlock`: A block which will be called to get input data as needed. See description for AVAudioConverterInputBlock.
386 ///
387 /// Parameter `outputBuffer`: The output buffer.
388 ///
389 /// Parameter `outError`: An error if the conversion fails.
390 ///
391 /// Returns: An AVAudioConverterOutputStatus is returned.
392 ///
393 /// It attempts to fill the buffer to its capacity. On return, the buffer's length indicates the number of
394 /// sample frames successfully converted.
395 #[unsafe(method(convertToBuffer:error:withInputFromBlock:))]
396 #[unsafe(method_family = none)]
397 pub unsafe fn convertToBuffer_error_withInputFromBlock(
398 &self,
399 output_buffer: &AVAudioBuffer,
400 out_error: Option<&mut Option<Retained<NSError>>>,
401 input_block: AVAudioConverterInputBlock,
402 ) -> AVAudioConverterOutputStatus;
403 );
404}
405
406/// Methods declared on superclass `NSObject`.
407impl AVAudioConverter {
408 extern_methods!(
409 #[unsafe(method(init))]
410 #[unsafe(method_family = init)]
411 pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
412
413 #[unsafe(method(new))]
414 #[unsafe(method_family = new)]
415 pub unsafe fn new() -> Retained<Self>;
416 );
417}
418
419/// Encoding.
420impl AVAudioConverter {
421 extern_methods!(
422 /// bitRate in bits per second. Only applies when encoding.
423 #[unsafe(method(bitRate))]
424 #[unsafe(method_family = none)]
425 pub unsafe fn bitRate(&self) -> NSInteger;
426
427 /// Setter for [`bitRate`][Self::bitRate].
428 #[unsafe(method(setBitRate:))]
429 #[unsafe(method_family = none)]
430 pub unsafe fn setBitRate(&self, bit_rate: NSInteger);
431
432 /// When encoding, an AVEncoderBitRateStrategyKey value constant as defined in AVAudioSettings.h. Returns nil if not encoding.
433 #[unsafe(method(bitRateStrategy))]
434 #[unsafe(method_family = none)]
435 pub unsafe fn bitRateStrategy(&self) -> Option<Retained<NSString>>;
436
437 /// Setter for [`bitRateStrategy`][Self::bitRateStrategy].
438 #[unsafe(method(setBitRateStrategy:))]
439 #[unsafe(method_family = none)]
440 pub unsafe fn setBitRateStrategy(&self, bit_rate_strategy: Option<&NSString>);
441
442 /// The maximum size of an output packet, in bytes.
443 ///
444 /// When encoding it is useful to know how large a packet can be in order to allocate a buffer to receive the output.
445 #[unsafe(method(maximumOutputPacketSize))]
446 #[unsafe(method_family = none)]
447 pub unsafe fn maximumOutputPacketSize(&self) -> NSInteger;
448
449 /// When encoding, an NSArray of NSNumber of all bit rates provided by the codec. Returns nil if not encoding.
450 #[unsafe(method(availableEncodeBitRates))]
451 #[unsafe(method_family = none)]
452 pub unsafe fn availableEncodeBitRates(&self) -> Option<Retained<NSArray<NSNumber>>>;
453
454 /// When encoding, an NSArray of NSNumber of bit rates that can be applied based on the current formats and settings. Returns nil if not encoding.
455 #[unsafe(method(applicableEncodeBitRates))]
456 #[unsafe(method_family = none)]
457 pub unsafe fn applicableEncodeBitRates(&self) -> Option<Retained<NSArray<NSNumber>>>;
458
459 /// When encoding, an NSArray of NSNumber of all output sample rates provided by the codec. Returns nil if not encoding.
460 #[unsafe(method(availableEncodeSampleRates))]
461 #[unsafe(method_family = none)]
462 pub unsafe fn availableEncodeSampleRates(&self) -> Option<Retained<NSArray<NSNumber>>>;
463
464 /// When encoding, an NSArray of NSNumber of output sample rates that can be applied based on the current formats and settings. Returns nil if not encoding.
465 #[unsafe(method(applicableEncodeSampleRates))]
466 #[unsafe(method_family = none)]
467 pub unsafe fn applicableEncodeSampleRates(&self) -> Option<Retained<NSArray<NSNumber>>>;
468
469 /// When encoding, an NSArray of NSNumber of all output channel layout tags provided by the codec. Returns nil if not encoding.
470 #[unsafe(method(availableEncodeChannelLayoutTags))]
471 #[unsafe(method_family = none)]
472 pub unsafe fn availableEncodeChannelLayoutTags(
473 &self,
474 ) -> Option<Retained<NSArray<NSNumber>>>;
475 );
476}