objc2_audio_toolbox/generated/
AudioConverter.rs

1//! This file has been automatically generated by `objc2`'s `header-translator`.
2//! DO NOT EDIT
3use core::cell::UnsafeCell;
4use core::ffi::*;
5use core::marker::{PhantomData, PhantomPinned};
6use core::ptr::NonNull;
7use objc2::__framework_prelude::*;
8#[cfg(feature = "objc2-core-audio-types")]
9use objc2_core_audio_types::*;
10
11use crate::*;
12
13/// [Apple's documentation](https://developer.apple.com/documentation/audiotoolbox/opaqueaudioconverter?language=objc)
14#[repr(C)]
15#[derive(Debug)]
16pub struct OpaqueAudioConverter {
17    inner: [u8; 0],
18    _p: UnsafeCell<PhantomData<(*const UnsafeCell<()>, PhantomPinned)>>,
19}
20
21unsafe impl RefEncode for OpaqueAudioConverter {
22    const ENCODING_REF: Encoding =
23        Encoding::Pointer(&Encoding::Struct("OpaqueAudioConverter", &[]));
24}
25
26/// A reference to an AudioConverter object.
27///
28/// See also [Apple's documentation](https://developer.apple.com/documentation/audiotoolbox/audioconverterref?language=objc)
29pub type AudioConverterRef = *mut OpaqueAudioConverter;
30
31/// [Apple's documentation](https://developer.apple.com/documentation/audiotoolbox/audioconverterpropertyid?language=objc)
32pub type AudioConverterPropertyID = u32;
33
34/// [Apple's documentation](https://developer.apple.com/documentation/audiotoolbox/kaudioconverterpropertyminimuminputbuffersize?language=objc)
35pub const kAudioConverterPropertyMinimumInputBufferSize: AudioConverterPropertyID = 0x6d696273;
36/// [Apple's documentation](https://developer.apple.com/documentation/audiotoolbox/kaudioconverterpropertyminimumoutputbuffersize?language=objc)
37pub const kAudioConverterPropertyMinimumOutputBufferSize: AudioConverterPropertyID = 0x6d6f6273;
38/// [Apple's documentation](https://developer.apple.com/documentation/audiotoolbox/kaudioconverterpropertymaximuminputpacketsize?language=objc)
39pub const kAudioConverterPropertyMaximumInputPacketSize: AudioConverterPropertyID = 0x78697073;
40/// [Apple's documentation](https://developer.apple.com/documentation/audiotoolbox/kaudioconverterpropertymaximumoutputpacketsize?language=objc)
41pub const kAudioConverterPropertyMaximumOutputPacketSize: AudioConverterPropertyID = 0x786f7073;
42/// [Apple's documentation](https://developer.apple.com/documentation/audiotoolbox/kaudioconverterpropertycalculateinputbuffersize?language=objc)
43pub const kAudioConverterPropertyCalculateInputBufferSize: AudioConverterPropertyID = 0x63696273;
44/// [Apple's documentation](https://developer.apple.com/documentation/audiotoolbox/kaudioconverterpropertycalculateoutputbuffersize?language=objc)
45pub const kAudioConverterPropertyCalculateOutputBufferSize: AudioConverterPropertyID = 0x636f6273;
46/// [Apple's documentation](https://developer.apple.com/documentation/audiotoolbox/kaudioconverterpropertyinputcodecparameters?language=objc)
47pub const kAudioConverterPropertyInputCodecParameters: AudioConverterPropertyID = 0x69636470;
48/// [Apple's documentation](https://developer.apple.com/documentation/audiotoolbox/kaudioconverterpropertyoutputcodecparameters?language=objc)
49pub const kAudioConverterPropertyOutputCodecParameters: AudioConverterPropertyID = 0x6f636470;
50/// [Apple's documentation](https://developer.apple.com/documentation/audiotoolbox/kaudioconvertersamplerateconvertercomplexity?language=objc)
51pub const kAudioConverterSampleRateConverterComplexity: AudioConverterPropertyID = 0x73726361;
52/// [Apple's documentation](https://developer.apple.com/documentation/audiotoolbox/kaudioconvertersamplerateconverterquality?language=objc)
53pub const kAudioConverterSampleRateConverterQuality: AudioConverterPropertyID = 0x73726371;
54/// [Apple's documentation](https://developer.apple.com/documentation/audiotoolbox/kaudioconvertersamplerateconverterinitialphase?language=objc)
55pub const kAudioConverterSampleRateConverterInitialPhase: AudioConverterPropertyID = 0x73726370;
56/// [Apple's documentation](https://developer.apple.com/documentation/audiotoolbox/kaudioconvertercodecquality?language=objc)
57pub const kAudioConverterCodecQuality: AudioConverterPropertyID = 0x63647175;
58/// [Apple's documentation](https://developer.apple.com/documentation/audiotoolbox/kaudioconverterprimemethod?language=objc)
59pub const kAudioConverterPrimeMethod: AudioConverterPropertyID = 0x70726d6d;
60/// [Apple's documentation](https://developer.apple.com/documentation/audiotoolbox/kaudioconverterprimeinfo?language=objc)
61pub const kAudioConverterPrimeInfo: AudioConverterPropertyID = 0x7072696d;
62/// [Apple's documentation](https://developer.apple.com/documentation/audiotoolbox/kaudioconverterchannelmap?language=objc)
63pub const kAudioConverterChannelMap: AudioConverterPropertyID = 0x63686d70;
64/// [Apple's documentation](https://developer.apple.com/documentation/audiotoolbox/kaudioconverterdecompressionmagiccookie?language=objc)
65pub const kAudioConverterDecompressionMagicCookie: AudioConverterPropertyID = 0x646d6763;
66/// [Apple's documentation](https://developer.apple.com/documentation/audiotoolbox/kaudioconvertercompressionmagiccookie?language=objc)
67pub const kAudioConverterCompressionMagicCookie: AudioConverterPropertyID = 0x636d6763;
68/// [Apple's documentation](https://developer.apple.com/documentation/audiotoolbox/kaudioconverterencodebitrate?language=objc)
69pub const kAudioConverterEncodeBitRate: AudioConverterPropertyID = 0x62726174;
70/// [Apple's documentation](https://developer.apple.com/documentation/audiotoolbox/kaudioconverterencodeadjustablesamplerate?language=objc)
71pub const kAudioConverterEncodeAdjustableSampleRate: AudioConverterPropertyID = 0x616a7372;
72/// [Apple's documentation](https://developer.apple.com/documentation/audiotoolbox/kaudioconverterinputchannellayout?language=objc)
73pub const kAudioConverterInputChannelLayout: AudioConverterPropertyID = 0x69636c20;
74/// [Apple's documentation](https://developer.apple.com/documentation/audiotoolbox/kaudioconverteroutputchannellayout?language=objc)
75pub const kAudioConverterOutputChannelLayout: AudioConverterPropertyID = 0x6f636c20;
76/// [Apple's documentation](https://developer.apple.com/documentation/audiotoolbox/kaudioconverterapplicableencodebitrates?language=objc)
77pub const kAudioConverterApplicableEncodeBitRates: AudioConverterPropertyID = 0x61656272;
78/// [Apple's documentation](https://developer.apple.com/documentation/audiotoolbox/kaudioconverteravailableencodebitrates?language=objc)
79pub const kAudioConverterAvailableEncodeBitRates: AudioConverterPropertyID = 0x76656272;
80/// [Apple's documentation](https://developer.apple.com/documentation/audiotoolbox/kaudioconverterapplicableencodesamplerates?language=objc)
81pub const kAudioConverterApplicableEncodeSampleRates: AudioConverterPropertyID = 0x61657372;
82/// [Apple's documentation](https://developer.apple.com/documentation/audiotoolbox/kaudioconverteravailableencodesamplerates?language=objc)
83pub const kAudioConverterAvailableEncodeSampleRates: AudioConverterPropertyID = 0x76657372;
84/// [Apple's documentation](https://developer.apple.com/documentation/audiotoolbox/kaudioconverteravailableencodechannellayouttags?language=objc)
85pub const kAudioConverterAvailableEncodeChannelLayoutTags: AudioConverterPropertyID = 0x6165636c;
86/// [Apple's documentation](https://developer.apple.com/documentation/audiotoolbox/kaudioconvertercurrentoutputstreamdescription?language=objc)
87pub const kAudioConverterCurrentOutputStreamDescription: AudioConverterPropertyID = 0x61636f64;
88/// [Apple's documentation](https://developer.apple.com/documentation/audiotoolbox/kaudioconvertercurrentinputstreamdescription?language=objc)
89pub const kAudioConverterCurrentInputStreamDescription: AudioConverterPropertyID = 0x61636964;
90/// [Apple's documentation](https://developer.apple.com/documentation/audiotoolbox/kaudioconverterpropertysettings?language=objc)
91pub const kAudioConverterPropertySettings: AudioConverterPropertyID = 0x61637073;
92/// [Apple's documentation](https://developer.apple.com/documentation/audiotoolbox/kaudioconverterpropertybitdepthhint?language=objc)
93pub const kAudioConverterPropertyBitDepthHint: AudioConverterPropertyID = 0x61636264;
94/// [Apple's documentation](https://developer.apple.com/documentation/audiotoolbox/kaudioconverterpropertyformatlist?language=objc)
95pub const kAudioConverterPropertyFormatList: AudioConverterPropertyID = 0x666c7374;
96/// [Apple's documentation](https://developer.apple.com/documentation/audiotoolbox/kaudioconverterpropertyperformdownmix?language=objc)
97pub const kAudioConverterPropertyPerformDownmix: AudioConverterPropertyID = 0x646d6978;
98/// [Apple's documentation](https://developer.apple.com/documentation/audiotoolbox/kaudioconverterpropertychannelmixmap?language=objc)
99pub const kAudioConverterPropertyChannelMixMap: AudioConverterPropertyID = 0x6d6d6170;
100
101/// [Apple's documentation](https://developer.apple.com/documentation/audiotoolbox/kaudioconverterpropertydithering?language=objc)
102pub const kAudioConverterPropertyDithering: AudioConverterPropertyID = 0x64697468;
103/// [Apple's documentation](https://developer.apple.com/documentation/audiotoolbox/kaudioconverterpropertyditherbitdepth?language=objc)
104pub const kAudioConverterPropertyDitherBitDepth: AudioConverterPropertyID = 0x64626974;
105
106/// [Apple's documentation](https://developer.apple.com/documentation/audiotoolbox/kditheralgorithm_tpdf?language=objc)
107pub const kDitherAlgorithm_TPDF: u32 = 1;
108/// [Apple's documentation](https://developer.apple.com/documentation/audiotoolbox/kditheralgorithm_noiseshaping?language=objc)
109pub const kDitherAlgorithm_NoiseShaping: u32 = 2;
110
111/// [Apple's documentation](https://developer.apple.com/documentation/audiotoolbox/kaudioconverterquality_max?language=objc)
112pub const kAudioConverterQuality_Max: u32 = 0x7F;
113/// [Apple's documentation](https://developer.apple.com/documentation/audiotoolbox/kaudioconverterquality_high?language=objc)
114pub const kAudioConverterQuality_High: u32 = 0x60;
115/// [Apple's documentation](https://developer.apple.com/documentation/audiotoolbox/kaudioconverterquality_medium?language=objc)
116pub const kAudioConverterQuality_Medium: u32 = 0x40;
117/// [Apple's documentation](https://developer.apple.com/documentation/audiotoolbox/kaudioconverterquality_low?language=objc)
118pub const kAudioConverterQuality_Low: u32 = 0x20;
119/// [Apple's documentation](https://developer.apple.com/documentation/audiotoolbox/kaudioconverterquality_min?language=objc)
120pub const kAudioConverterQuality_Min: u32 = 0;
121
122/// [Apple's documentation](https://developer.apple.com/documentation/audiotoolbox/kaudioconvertersamplerateconvertercomplexity_linear?language=objc)
123pub const kAudioConverterSampleRateConverterComplexity_Linear: u32 = 0x6c696e65;
124/// [Apple's documentation](https://developer.apple.com/documentation/audiotoolbox/kaudioconvertersamplerateconvertercomplexity_normal?language=objc)
125pub const kAudioConverterSampleRateConverterComplexity_Normal: u32 = 0x6e6f726d;
126/// [Apple's documentation](https://developer.apple.com/documentation/audiotoolbox/kaudioconvertersamplerateconvertercomplexity_mastering?language=objc)
127pub const kAudioConverterSampleRateConverterComplexity_Mastering: u32 = 0x62617473;
128/// [Apple's documentation](https://developer.apple.com/documentation/audiotoolbox/kaudioconvertersamplerateconvertercomplexity_minimumphase?language=objc)
129pub const kAudioConverterSampleRateConverterComplexity_MinimumPhase: u32 = 0x6d696e70;
130
131/// [Apple's documentation](https://developer.apple.com/documentation/audiotoolbox/kconverterprimemethod_pre?language=objc)
132pub const kConverterPrimeMethod_Pre: u32 = 0;
133/// [Apple's documentation](https://developer.apple.com/documentation/audiotoolbox/kconverterprimemethod_normal?language=objc)
134pub const kConverterPrimeMethod_Normal: u32 = 1;
135/// [Apple's documentation](https://developer.apple.com/documentation/audiotoolbox/kconverterprimemethod_none?language=objc)
136pub const kConverterPrimeMethod_None: u32 = 2;
137
138/// Specifies priming information.
139///
140/// When using AudioConverterFillComplexBuffer() (either a single call or a series of calls), some
141/// conversions, particularly involving sample-rate conversion, ideally require a certain
142/// number of input frames previous to the normal start input frame and beyond the end of
143/// the last expected input frame in order to yield high-quality results.
144///
145/// These are expressed in the leadingFrames and trailingFrames members of the structure.
146///
147/// The very first call to AudioConverterFillComplexBuffer(), or first call after
148/// AudioConverterReset(), will request additional input frames beyond those normally
149/// expected in the input proc callback to fulfill this first AudioConverterFillComplexBuffer()
150/// request. The number of additional frames requested, depending on the prime method, will
151/// be approximately:
152///
153/// Prime method                  | Additional frames
154/// ------------------------------|----------------------
155/// kConverterPrimeMethod_Pre     | leadingFrames + trailingFrames
156/// kConverterPrimeMethod_Normal  | trailingFrames
157/// kConverterPrimeMethod_None    | 0
158///
159/// Thus, in effect, the first input proc callback(s) may provide not only the leading
160/// frames, but also may "read ahead" by an additional number of trailing frames depending
161/// on the prime method.
162///
163/// kConverterPrimeMethod_None is useful in a real-time application processing live input,
164/// in which case trailingFrames (relative to input sample rate) of through latency will be
165/// seen at the beginning of the output of the AudioConverter.  In other real-time
166/// applications such as DAW systems, it may be possible to provide these initial extra
167/// audio frames since they are stored on disk or in memory somewhere and
168/// kConverterPrimeMethod_Pre may be preferable.  The default method is
169/// kConverterPrimeMethod_Normal, which requires no pre-seeking of the input stream and
170/// generates no latency at the output.
171///
172///
173/// Specifies the number of leading (previous) input frames, relative to the normal/desired
174/// start input frame, required by the converter to perform a high quality conversion. If
175/// using kConverterPrimeMethod_Pre, the client should "pre-seek" the input stream provided
176/// through the input proc by leadingFrames. If no frames are available previous to the
177/// desired input start frame (because, for example, the desired start frame is at the very
178/// beginning of available audio), then provide "leadingFrames" worth of initial zero frames
179/// in the input proc.  Do not "pre-seek" in the default case of
180/// kConverterPrimeMethod_Normal or when using kConverterPrimeMethod_None.
181///
182///
183/// Specifies the number of trailing input frames (past the normal/expected end input frame)
184/// required by the converter to perform a high quality conversion.  The client should be
185/// prepared to provide this number of additional input frames except when using
186/// kConverterPrimeMethod_None. If no more frames of input are available in the input stream
187/// (because, for example, the desired end frame is at the end of an audio file), then zero
188/// (silent) trailing frames will be synthesized for the client.
189///
190/// See also [Apple's documentation](https://developer.apple.com/documentation/audiotoolbox/audioconverterprimeinfo?language=objc)
191#[repr(C)]
192#[derive(Clone, Copy, Debug, PartialEq)]
193pub struct AudioConverterPrimeInfo {
194    pub leadingFrames: u32,
195    pub trailingFrames: u32,
196}
197
198unsafe impl Encode for AudioConverterPrimeInfo {
199    const ENCODING: Encoding = Encoding::Struct(
200        "AudioConverterPrimeInfo",
201        &[<u32>::ENCODING, <u32>::ENCODING],
202    );
203}
204
205unsafe impl RefEncode for AudioConverterPrimeInfo {
206    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
207}
208
209/// This is an option for AudioConverterNewWithOptions which removes unnecessary
210/// buffering, both for input and internally to the converter, saving memory
211/// at the cost of reduced format support and usage restrictions:
212///
213/// - Input and output formats must be constant bit-rate, non-zero bytes per packet
214/// (e.g. linear PCM, a-law, etc.) with the same sample rate and frames per packet.
215/// - AudioConverterFillBuffer cannot be used.
216/// - AudioConverterFillComplexBuffer cannot be used.
217///
218/// See also [Apple's documentation](https://developer.apple.com/documentation/audiotoolbox/audioconverteroptions?language=objc)
219// NS_OPTIONS
220#[repr(transparent)]
221#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
222pub struct AudioConverterOptions(pub u32);
223bitflags::bitflags! {
224    impl AudioConverterOptions: u32 {
225        #[doc(alias = "kAudioConverterOption_Unbuffered")]
226        const Unbuffered = 1<<16;
227    }
228}
229
230unsafe impl Encode for AudioConverterOptions {
231    const ENCODING: Encoding = u32::ENCODING;
232}
233
234unsafe impl RefEncode for AudioConverterOptions {
235    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
236}
237
238/// [Apple's documentation](https://developer.apple.com/documentation/audiotoolbox/kaudioconvertererr_formatnotsupported?language=objc)
239pub const kAudioConverterErr_FormatNotSupported: OSStatus = 0x666d743f;
240/// [Apple's documentation](https://developer.apple.com/documentation/audiotoolbox/kaudioconvertererr_operationnotsupported?language=objc)
241pub const kAudioConverterErr_OperationNotSupported: OSStatus = 0x6F703F3F;
242/// [Apple's documentation](https://developer.apple.com/documentation/audiotoolbox/kaudioconvertererr_propertynotsupported?language=objc)
243pub const kAudioConverterErr_PropertyNotSupported: OSStatus = 0x70726f70;
244/// [Apple's documentation](https://developer.apple.com/documentation/audiotoolbox/kaudioconvertererr_invalidinputsize?language=objc)
245pub const kAudioConverterErr_InvalidInputSize: OSStatus = 0x696e737a;
246/// [Apple's documentation](https://developer.apple.com/documentation/audiotoolbox/kaudioconvertererr_invalidoutputsize?language=objc)
247pub const kAudioConverterErr_InvalidOutputSize: OSStatus = 0x6f74737a;
248/// [Apple's documentation](https://developer.apple.com/documentation/audiotoolbox/kaudioconvertererr_unspecifiederror?language=objc)
249pub const kAudioConverterErr_UnspecifiedError: OSStatus = 0x77686174;
250/// [Apple's documentation](https://developer.apple.com/documentation/audiotoolbox/kaudioconvertererr_badpropertysizeerror?language=objc)
251pub const kAudioConverterErr_BadPropertySizeError: OSStatus = 0x2173697a;
252/// [Apple's documentation](https://developer.apple.com/documentation/audiotoolbox/kaudioconvertererr_requirespacketdescriptionserror?language=objc)
253pub const kAudioConverterErr_RequiresPacketDescriptionsError: OSStatus = 0x21706b64;
254/// [Apple's documentation](https://developer.apple.com/documentation/audiotoolbox/kaudioconvertererr_inputsamplerateoutofrange?language=objc)
255pub const kAudioConverterErr_InputSampleRateOutOfRange: OSStatus = 0x21697372;
256/// [Apple's documentation](https://developer.apple.com/documentation/audiotoolbox/kaudioconvertererr_outputsamplerateoutofrange?language=objc)
257pub const kAudioConverterErr_OutputSampleRateOutOfRange: OSStatus = 0x216f7372;
258
259extern "C-unwind" {
260    /// Optimizes the subsequent creation of audio converters by the current process.
261    ///
262    /// This function performs its work asynchronously.  The optional completion block,
263    /// if provided, is executed once preparation is complete.
264    /// Although a best effort is made to ensure future audio converters will be created quickly,
265    /// there are no guarantees.
266    ///
267    ///
268    /// Parameter `inFlags`: Reserved for future use.  Pass 0.
269    ///
270    /// Parameter `ioReserved`: Reserved for future use.  Pass NULL.
271    ///
272    /// Parameter `inCompletionBlock`: Optional block to execute once preparation is complete.  May be NULL.
273    /// The block is given the OSStatus result of the preparation.
274    ///
275    /// # Safety
276    ///
277    /// `io_reserved` must be a valid pointer or null.
278    #[cfg(feature = "block2")]
279    pub fn AudioConverterPrepare(
280        in_flags: u32,
281        io_reserved: *mut c_void,
282        in_completion_block: Option<&block2::DynBlock<dyn Fn(OSStatus)>>,
283    );
284}
285
286extern "C-unwind" {
287    /// Create a new AudioConverter.
288    ///
289    ///
290    /// Parameter `inSourceFormat`: The format of the source audio to be converted.
291    ///
292    /// Parameter `inDestinationFormat`: The destination format to which the audio is to be converted.
293    ///
294    /// Parameter `outAudioConverter`: On successful return, points to a new AudioConverter instance.
295    ///
296    /// Returns: An OSStatus result code.
297    ///
298    /// For a pair of linear PCM formats, the following conversions
299    /// are supported:
300    ///
301    /// <ul>
302    /// <li>
303    /// addition and removal of channels, when the stream descriptions'
304    /// mChannelsPerFrame does not match. Channels may also be reordered and removed
305    /// using the kAudioConverterChannelMap property.
306    /// </li>
307    /// <li>
308    /// sample rate conversion
309    /// </li>
310    /// <li>
311    /// interleaving/deinterleaving, when the stream descriptions' (mFormatFlags
312    /// &
313    /// kAudioFormatFlagIsNonInterleaved) does not match.
314    /// </li>
315    /// <li>
316    /// conversion between any pair of the following formats:
317    /// </li>
318    /// <ul>
319    /// <li>
320    /// 8 bit integer, signed or unsigned
321    /// </li>
322    /// <li>
323    /// 16, 24, or 32-bit integer, big- or little-endian. Other integral
324    /// bit depths, if high-aligned and non-packed, are also supported
325    /// </li>
326    /// <li>
327    /// 32 and 64-bit float, big- or little-endian.
328    /// </li>
329    /// </ul>
330    /// </ul>
331    ///
332    /// Also, encoding and decoding between linear PCM and compressed formats is
333    /// supported. Functions in AudioToolbox/AudioFormat.h return information about the
334    /// supported formats. When using a codec, you can use any supported PCM format (as
335    /// above); the converter will perform any necessary additional conversion between
336    /// your PCM format and the one created or consumed by the codec.
337    ///
338    /// Note that AudioConverter may change the formats to correct any
339    /// inconsistent or erroneous values.  The actual formats expected and used
340    /// by the newly created AudioConverter can be obtained by getting the
341    /// properties `kAudioConverterCurrentInputStreamDescription` and
342    /// `kAudioConverterCurrentOutputStreamDescription` from it.
343    ///
344    /// # Safety
345    ///
346    /// - `in_source_format` must be a valid pointer.
347    /// - `in_destination_format` must be a valid pointer.
348    /// - `out_audio_converter` must be a valid pointer.
349    #[cfg(feature = "objc2-core-audio-types")]
350    pub fn AudioConverterNew(
351        in_source_format: NonNull<AudioStreamBasicDescription>,
352        in_destination_format: NonNull<AudioStreamBasicDescription>,
353        out_audio_converter: NonNull<AudioConverterRef>,
354    ) -> OSStatus;
355}
356
357extern "C-unwind" {
358    /// Create a new AudioConverter using specific codecs.
359    ///
360    ///
361    /// Parameter `inSourceFormat`: The format of the source audio to be converted.
362    ///
363    /// Parameter `inDestinationFormat`: The destination format to which the audio is to be converted.
364    ///
365    /// Parameter `inNumberClassDescriptions`: The number of class descriptions.
366    ///
367    /// Parameter `inClassDescriptions`: AudioClassDescriptions specifiying the codec to instantiate.
368    ///
369    /// Parameter `outAudioConverter`: On successful return, points to a new AudioConverter instance.
370    ///
371    /// Returns: An OSStatus result code.
372    ///
373    /// This function is identical to AudioConverterNew(), except that the client may
374    /// explicitly choose which codec to instantiate if there is more than one choice.
375    ///
376    /// # Safety
377    ///
378    /// - `in_source_format` must be a valid pointer.
379    /// - `in_destination_format` must be a valid pointer.
380    /// - `in_class_descriptions` must be a valid pointer.
381    /// - `out_audio_converter` must be a valid pointer.
382    #[cfg(feature = "objc2-core-audio-types")]
383    pub fn AudioConverterNewSpecific(
384        in_source_format: NonNull<AudioStreamBasicDescription>,
385        in_destination_format: NonNull<AudioStreamBasicDescription>,
386        in_number_class_descriptions: u32,
387        in_class_descriptions: NonNull<AudioClassDescription>,
388        out_audio_converter: NonNull<AudioConverterRef>,
389    ) -> OSStatus;
390}
391
392extern "C-unwind" {
393    /// Create a new AudioConverter with one or more options enabled.
394    ///
395    ///
396    /// Parameter `inSourceFormat`: The format of the source audio to be converted.
397    ///
398    /// Parameter `inDestinationFormat`: The destination format to which the audio is to be converted.
399    ///
400    /// Parameter `inOptions`: Flags selecting one or more optional configurations for the AudioConverter.
401    ///
402    /// Parameter `outAudioConverter`: On successful return, points to a new AudioConverter instance.
403    ///
404    /// Returns: An OSStatus result code.
405    ///
406    /// This is an alternative to AudioConverterNew which supports enabling
407    /// one or more optional configurations for the new AudioConverter.
408    ///
409    /// # Safety
410    ///
411    /// - `in_source_format` must be a valid pointer.
412    /// - `in_destination_format` must be a valid pointer.
413    /// - `out_audio_converter` must be a valid pointer.
414    #[cfg(feature = "objc2-core-audio-types")]
415    pub fn AudioConverterNewWithOptions(
416        in_source_format: NonNull<AudioStreamBasicDescription>,
417        in_destination_format: NonNull<AudioStreamBasicDescription>,
418        in_options: AudioConverterOptions,
419        out_audio_converter: NonNull<AudioConverterRef>,
420    ) -> OSStatus;
421}
422
423extern "C-unwind" {
424    /// Destroy an AudioConverter.
425    ///
426    ///
427    /// Parameter `inAudioConverter`: The AudioConverter to dispose.
428    ///
429    /// Returns: An OSStatus result code.
430    ///
431    /// # Safety
432    ///
433    /// `in_audio_converter` must be a valid pointer.
434    pub fn AudioConverterDispose(in_audio_converter: AudioConverterRef) -> OSStatus;
435}
436
437extern "C-unwind" {
438    /// Reset an AudioConverter
439    ///
440    ///
441    /// Parameter `inAudioConverter`: The AudioConverter to reset.
442    ///
443    /// Returns: An OSStatus result code.
444    ///
445    /// Should be called whenever there is a discontinuity in the source audio stream
446    /// being provided to the converter. This will flush any internal buffers in the
447    /// converter.
448    ///
449    /// # Safety
450    ///
451    /// `in_audio_converter` must be a valid pointer.
452    pub fn AudioConverterReset(in_audio_converter: AudioConverterRef) -> OSStatus;
453}
454
455extern "C-unwind" {
456    /// Returns information about an AudioConverter property.
457    ///
458    ///
459    /// Parameter `inAudioConverter`: The AudioConverter to query.
460    ///
461    /// Parameter `inPropertyID`: The property to query.
462    ///
463    /// Parameter `outSize`: If non-null, on exit, the maximum size of the property value in bytes.
464    ///
465    /// Parameter `outWritable`: If non-null, on exit, indicates whether the property value is writable.
466    ///
467    /// Returns: An OSStatus result code.
468    ///
469    /// # Safety
470    ///
471    /// - `in_audio_converter` must be a valid pointer.
472    /// - `out_size` must be a valid pointer or null.
473    /// - `out_writable` must be a valid pointer or null.
474    pub fn AudioConverterGetPropertyInfo(
475        in_audio_converter: AudioConverterRef,
476        in_property_id: AudioConverterPropertyID,
477        out_size: *mut u32,
478        out_writable: *mut Boolean,
479    ) -> OSStatus;
480}
481
482extern "C-unwind" {
483    /// Returns an AudioConverter property value.
484    ///
485    ///
486    /// Parameter `inAudioConverter`: The AudioConverter to query.
487    ///
488    /// Parameter `inPropertyID`: The property to fetch.
489    ///
490    /// Parameter `ioPropertyDataSize`: On entry, the size of the memory pointed to by outPropertyData. On
491    /// successful exit, the size of the property value.
492    ///
493    /// Parameter `outPropertyData`: On exit, the property value.
494    ///
495    /// Returns: An OSStatus result code.
496    ///
497    /// # Safety
498    ///
499    /// - `in_audio_converter` must be a valid pointer.
500    /// - `io_property_data_size` must be a valid pointer.
501    /// - `out_property_data` must be a valid pointer.
502    pub fn AudioConverterGetProperty(
503        in_audio_converter: AudioConverterRef,
504        in_property_id: AudioConverterPropertyID,
505        io_property_data_size: NonNull<u32>,
506        out_property_data: NonNull<c_void>,
507    ) -> OSStatus;
508}
509
510extern "C-unwind" {
511    /// Sets an AudioConverter property value.
512    ///
513    ///
514    /// Parameter `inAudioConverter`: The AudioConverter to modify.
515    ///
516    /// Parameter `inPropertyID`: The property to set.
517    ///
518    /// Parameter `inPropertyDataSize`: The size in bytes of the property value.
519    ///
520    /// Parameter `inPropertyData`: Points to the new property value.
521    ///
522    /// Returns: An OSStatus result code.
523    ///
524    /// # Safety
525    ///
526    /// - `in_audio_converter` must be a valid pointer.
527    /// - `in_property_data` must be a valid pointer.
528    pub fn AudioConverterSetProperty(
529        in_audio_converter: AudioConverterRef,
530        in_property_id: AudioConverterPropertyID,
531        in_property_data_size: u32,
532        in_property_data: NonNull<c_void>,
533    ) -> OSStatus;
534}
535
536extern "C-unwind" {
537    /// Converts data from an input buffer to an output buffer.
538    ///
539    ///
540    /// Parameter `inAudioConverter`: The AudioConverter to use.
541    ///
542    /// Parameter `inInputDataSize`: The size of the buffer inInputData.
543    ///
544    /// Parameter `inInputData`: The input audio data buffer.
545    ///
546    /// Parameter `ioOutputDataSize`: On entry, the size of the buffer outOutputData. On exit, the number of bytes
547    /// written to outOutputData.
548    ///
549    /// Parameter `outOutputData`: The output data buffer.
550    ///
551    /// Returns: Produces a buffer of output data from an AudioConverter, using the supplied
552    /// input buffer.
553    ///
554    /// WARNING: this function will fail for any conversion where there is a
555    /// variable relationship between the input and output data buffer sizes. This
556    /// includes sample rate conversions and most compressed formats. In these cases,
557    /// use AudioConverterFillComplexBuffer. Generally this function is only appropriate for
558    /// PCM-to-PCM conversions where there is no sample rate conversion.
559    ///
560    /// # Safety
561    ///
562    /// - `in_audio_converter` must be a valid pointer.
563    /// - `in_input_data` must be a valid pointer.
564    /// - `io_output_data_size` must be a valid pointer.
565    /// - `out_output_data` must be a valid pointer.
566    pub fn AudioConverterConvertBuffer(
567        in_audio_converter: AudioConverterRef,
568        in_input_data_size: u32,
569        in_input_data: NonNull<c_void>,
570        io_output_data_size: NonNull<u32>,
571        out_output_data: NonNull<c_void>,
572    ) -> OSStatus;
573}
574
575/// Callback function for supplying input data to AudioConverterFillComplexBuffer.
576///
577///
578/// Parameter `inAudioConverter`: The AudioConverter requesting input.
579///
580/// Parameter `ioNumberDataPackets`: On entry, the minimum number of packets of input audio data the converter
581/// would like in order to fulfill its current FillBuffer request. On exit, the
582/// number of packets of audio data actually being provided for input, or 0 if
583/// there is no more input.
584///
585/// Parameter `ioData`: This points to an audio buffer list to be filled in by the callback to refer to the
586/// buffer(s) provided by the callback.
587/// On exit, the members of ioData should be set to point to the audio data
588/// being provided for input.
589///
590/// Parameter `outDataPacketDescription`: If non-null, on exit, the callback is expected to fill this in with
591/// an AudioStreamPacketDescription for each packet of input data being provided.
592///
593/// Parameter `inUserData`: The inInputDataProcUserData parameter passed to AudioConverterFillComplexBuffer().
594///
595/// Returns: An OSStatus result code.
596///
597/// This callback function supplies input to AudioConverterFillComplexBuffer.
598///
599/// The AudioConverter requests a minimum number of packets (*ioNumberDataPackets).
600/// The callback may return one or more packets. If this is less than the minimum,
601/// the callback will simply be called again in the near future. Note that ioNumberDataPackets counts
602/// packets in terms of the converter's input format (not its output format).
603/// Also note that the callback must provide a whole number of packets.
604///
605/// The callback may be asked to provide multiple input packets in a single call, even for compressed
606/// formats.  The callback must update the number of packets pointed to by ioNumberDataPackets
607/// to indicate the number of packets actually being provided, and if the packets require packet
608/// descriptions, these must be filled into the array pointed to by outDataPacketDescription, one
609/// packet description per packet.
610///
611/// The callback is given an audio buffer list pointed to by ioData.  This buffer list may refer to
612/// existing buffers owned and allocated by the audio converter, in which case the callback may
613/// use them and copy input audio data into them.  However, the buffer list may also be empty
614/// (mDataByteSize == 0 and/or mData == NULL), in which case the callback must provide its own
615/// buffers.  The callback manipulates the members of ioData to point to one or more buffers
616/// of audio data (multiple buffers are used with non-interleaved PCM data). The
617/// callback is responsible for not freeing or altering this buffer until it is called again.
618///
619/// For input data that varies from one packet to another in either size (bytes per packet)
620/// or duration (frames per packet), such as when decoding compressed audio, the callback
621/// should expect outDataPacketDescription to be non-null and point to array of packet descriptions,
622/// which the callback must fill in, one for every packet provided by the callback.  Each packet must
623/// have a valid packet description, regardless of whether or not these descriptions are different
624/// from each other.  Packet descriptions are required even if there is only one packet.
625///
626/// If the callback returns an error, it must return zero packets of data.
627/// AudioConverterFillComplexBuffer will stop producing output and return whatever
628/// output has already been produced to its caller, along with the error code. This
629/// mechanism can be used when an input proc has temporarily run out of data, but
630/// has not yet reached end of stream.
631///
632/// See also [Apple's documentation](https://developer.apple.com/documentation/audiotoolbox/audioconvertercomplexinputdataproc?language=objc)
633#[cfg(feature = "objc2-core-audio-types")]
634pub type AudioConverterComplexInputDataProc = Option<
635    unsafe extern "C-unwind" fn(
636        AudioConverterRef,
637        NonNull<u32>,
638        NonNull<AudioBufferList>,
639        *mut *mut AudioStreamPacketDescription,
640        *mut c_void,
641    ) -> OSStatus,
642>;
643
644/// Realtime-safe variant of AudioConverterComplexInputDataProc.
645///
646/// See the discussions of AudioConverterComplexInputDataProc and AudioConverterFillComplexBuffer.
647///
648/// See also [Apple's documentation](https://developer.apple.com/documentation/audiotoolbox/audioconvertercomplexinputdataprocrealtimesafe?language=objc)
649#[cfg(feature = "objc2-core-audio-types")]
650pub type AudioConverterComplexInputDataProcRealtimeSafe = Option<
651    unsafe extern "C-unwind" fn(
652        AudioConverterRef,
653        NonNull<u32>,
654        NonNull<AudioBufferList>,
655        *mut *mut AudioStreamPacketDescription,
656        *mut c_void,
657    ) -> OSStatus,
658>;
659
660extern "C-unwind" {
661    /// Converts data supplied by an input callback function, supporting non-interleaved
662    /// and packetized formats.
663    ///
664    ///
665    /// Parameter `inAudioConverter`: The AudioConverter to use.
666    ///
667    /// Parameter `inInputDataProc`: A callback function which supplies the input data.
668    ///
669    /// Parameter `inInputDataProcUserData`: A value for the use of the callback function.
670    ///
671    /// Parameter `ioOutputDataPacketSize`: On entry, the capacity of outOutputData expressed in packets in the
672    /// converter's output format. On exit, the number of packets of converted
673    /// data that were written to outOutputData.
674    ///
675    /// Parameter `outOutputData`: The converted output data is written to this buffer. On entry, the buffers'
676    /// mDataByteSize fields (which must all be the same) reflect buffer capacity.
677    /// On exit, mDataByteSize is set to the number of bytes written.
678    ///
679    /// Parameter `outPacketDescription`: If non-null, and the converter's output uses packet descriptions, then
680    /// packet descriptions are written to this array. It must point to a memory
681    /// block capable of holding *ioOutputDataPacketSize packet descriptions.
682    /// (See AudioFormat.h for ways to determine whether an audio format
683    /// uses packet descriptions).
684    ///
685    /// Returns: An OSStatus result code.
686    ///
687    /// Produces a buffer list of output data from an AudioConverter. The supplied input
688    /// callback function is called whenever necessary.
689    ///
690    /// If the output format uses packet descriptions, such as most compressed formats where packets
691    /// vary in size or duration, the caller is expected to provide a buffer for holding packet descriptions,
692    /// pointed to by outPacketDescription.  The array must have the capacity to hold a packet description
693    /// for each output packet that may be written.  A packet description array is expected even if only
694    /// a single output packet is to be written.
695    ///
696    /// # Safety
697    ///
698    /// - `in_audio_converter` must be a valid pointer.
699    /// - `in_input_data_proc` must be implemented correctly.
700    /// - `in_input_data_proc_user_data` must be a valid pointer or null.
701    /// - `io_output_data_packet_size` must be a valid pointer.
702    /// - `out_output_data` must be a valid pointer.
703    /// - `out_packet_description` must be a valid pointer or null.
704    #[cfg(feature = "objc2-core-audio-types")]
705    pub fn AudioConverterFillComplexBuffer(
706        in_audio_converter: AudioConverterRef,
707        in_input_data_proc: AudioConverterComplexInputDataProc,
708        in_input_data_proc_user_data: *mut c_void,
709        io_output_data_packet_size: NonNull<u32>,
710        out_output_data: NonNull<AudioBufferList>,
711        out_packet_description: *mut AudioStreamPacketDescription,
712    ) -> OSStatus;
713}
714
715extern "C-unwind" {
716    /// Identical to AudioConverterFillComplexBuffer, with the addition of a realtime-safety
717    /// guarantee.
718    ///
719    /// Conversions involving only PCM formats -- interleaving, deinterleaving, channel count changes,
720    /// sample rate conversions -- are realtime-safe. Such conversions may use this API in order to
721    /// obtain compiler checks involving the `CA_REALTIME_API` attributes.
722    ///
723    /// At runtime, this function returns `kAudioConverterErr_OperationNotSupported` if the conversion
724    /// requires non-realtime-safe functionality.
725    ///
726    /// # Safety
727    ///
728    /// - `in_audio_converter` must be a valid pointer.
729    /// - `in_input_data_proc` must be implemented correctly.
730    /// - `in_input_data_proc_user_data` must be a valid pointer or null.
731    /// - `io_output_data_packet_size` must be a valid pointer.
732    /// - `out_output_data` must be a valid pointer.
733    /// - `out_packet_description` must be a valid pointer or null.
734    #[cfg(feature = "objc2-core-audio-types")]
735    pub fn AudioConverterFillComplexBufferRealtimeSafe(
736        in_audio_converter: AudioConverterRef,
737        in_input_data_proc: AudioConverterComplexInputDataProcRealtimeSafe,
738        in_input_data_proc_user_data: *mut c_void,
739        io_output_data_packet_size: NonNull<u32>,
740        out_output_data: NonNull<AudioBufferList>,
741        out_packet_description: *mut AudioStreamPacketDescription,
742    ) -> OSStatus;
743}
744
745extern "C-unwind" {
746    /// Converts audio data supplied by a callback function, supporting non-interleaved and
747    /// packetized formats, and also supporting packet dependency descriptions.
748    ///
749    /// For output formats that use packet dependency descriptions, this must be used instead of
750    /// AudioConverterFillComplexBuffer, which will return an error for such formats.
751    ///
752    /// Parameter `inAudioConverter`: The audio converter to use for format conversion.
753    ///
754    /// Parameter `inInputDataProc`: A callback function that supplies audio data to convert.
755    /// This callback is invoked repeatedly as the converter is ready for
756    /// new input data.
757    ///
758    /// Parameter `inInputDataProcUserData`: Custom data for use by your application when receiving a
759    /// callback invocation.
760    ///
761    /// Parameter `ioOutputDataPacketSize`: On input, the size of the output buffer (in the `outOutputData`
762    /// parameter), expressed in number packets in the audio converter’s
763    /// output format.  On output, the number of packets of converted data
764    /// that were written to the output buffer.
765    ///
766    /// Parameter `outOutputData`: The converted output data is written to this buffer. On entry, the
767    /// buffers' `mDataByteSize` fields (which must all be the same) reflect
768    /// buffer capacity.  On exit, `mDataByteSize` is set to the number of
769    /// bytes written.
770    ///
771    /// Parameter `outPacketDescriptions`: If not `NULL`, and if the audio converter's output format uses packet
772    /// descriptions, this must point to a block of memory capable of holding
773    /// the number of packet descriptions specified in the `ioOutputDataPacketSize`
774    /// parameter.  (See _Audio Format Services Reference_ for functions that
775    /// let you determine whether an audio format uses packet descriptions).
776    /// If not `NULL` on output and if the audio converter's output format
777    /// uses packet descriptions, then this parameter contains an array of
778    /// packet descriptions.
779    ///
780    /// Parameter `outPacketDependencies`: Should point to a memory block capable of holding the number of
781    /// packet dependency description structures specified in the
782    /// `ioOutputDataPacketSize` parameter.  Must not be `NULL`.  This array
783    /// will be filled out only by encoders that produce a format which has a
784    /// non-zero value for `kAudioFormatProperty_FormatEmploysDependentPackets`.
785    ///
786    /// Returns: A result code.
787    ///
788    /// # Safety
789    ///
790    /// - `in_audio_converter` must be a valid pointer.
791    /// - `in_input_data_proc` must be implemented correctly.
792    /// - `in_input_data_proc_user_data` must be a valid pointer or null.
793    /// - `io_output_data_packet_size` must be a valid pointer.
794    /// - `out_output_data` must be a valid pointer.
795    /// - `out_packet_descriptions` must be a valid pointer or null.
796    /// - `out_packet_dependencies` must be a valid pointer.
797    #[cfg(feature = "objc2-core-audio-types")]
798    pub fn AudioConverterFillComplexBufferWithPacketDependencies(
799        in_audio_converter: AudioConverterRef,
800        in_input_data_proc: AudioConverterComplexInputDataProc,
801        in_input_data_proc_user_data: *mut c_void,
802        io_output_data_packet_size: NonNull<u32>,
803        out_output_data: NonNull<AudioBufferList>,
804        out_packet_descriptions: *mut AudioStreamPacketDescription,
805        out_packet_dependencies: NonNull<AudioStreamPacketDependencyDescription>,
806    ) -> OSStatus;
807}
808
809extern "C-unwind" {
810    /// Converts PCM data from an input buffer list to an output buffer list.
811    ///
812    ///
813    /// Parameter `inAudioConverter`: The AudioConverter to use.
814    ///
815    /// Parameter `inNumberPCMFrames`: The number of PCM frames to convert.
816    ///
817    /// Parameter `inInputData`: The source audio buffer list.
818    ///
819    /// Parameter `outOutputData`: The converted output data is written to this buffer list.
820    ///
821    /// Returns: An OSStatus result code.
822    ///
823    ///
824    /// Warning: This function will fail for any conversion where there is a
825    /// variable relationship between the input and output data buffer sizes. This
826    /// includes sample rate conversions and most compressed formats. In these cases,
827    /// use AudioConverterFillComplexBuffer. Generally this function is only appropriate for
828    /// PCM-to-PCM conversions where there is no sample rate conversion.
829    ///
830    /// # Safety
831    ///
832    /// - `in_audio_converter` must be a valid pointer.
833    /// - `in_input_data` must be a valid pointer.
834    /// - `out_output_data` must be a valid pointer.
835    #[cfg(feature = "objc2-core-audio-types")]
836    pub fn AudioConverterConvertComplexBuffer(
837        in_audio_converter: AudioConverterRef,
838        in_number_pcm_frames: u32,
839        in_input_data: NonNull<AudioBufferList>,
840        out_output_data: NonNull<AudioBufferList>,
841    ) -> OSStatus;
842}
843
844/// [Apple's documentation](https://developer.apple.com/documentation/audiotoolbox/kaudioconverterpropertymaximuminputbuffersize?language=objc)
845pub const kAudioConverterPropertyMaximumInputBufferSize: AudioConverterPropertyID = 0x78696273;
846/// [Apple's documentation](https://developer.apple.com/documentation/audiotoolbox/kaudioconvertersamplerateconverteralgorithm?language=objc)
847pub const kAudioConverterSampleRateConverterAlgorithm: AudioConverterPropertyID = 0x73726369;
848
849/// Callback function for supplying input data to AudioConverterFillBuffer.
850///
851///
852/// Parameter `inAudioConverter`: The AudioConverter requesting input.
853///
854/// Parameter `ioDataSize`: On entry, the minimum number of bytes of audio data the converter
855/// would like in order to fulfill its current FillBuffer request.
856/// On exit, the number of bytes of audio data actually being provided
857/// for input, or 0 if there is no more input.
858///
859/// Parameter `outData`: On exit, *outData should point to the audio data being provided
860/// for input.
861///
862/// Parameter `inUserData`: The inInputDataProcUserData parameter passed to AudioConverterFillBuffer().
863///
864/// Returns: An OSStatus result code.
865///
866/// This callback function supplies input to AudioConverterFillBuffer.
867///
868/// The AudioConverter requests a minimum amount of data (*ioDataSize). The callback
869/// may return any amount of data. If it is less than than the minimum, the callback
870/// will simply be called again in the near future.
871///
872/// The callback supplies a pointer to a buffer of audio data. The callback is
873/// responsible for not freeing or altering this buffer until it is called again.
874///
875/// If the callback returns an error, it must return zero bytes of data.
876/// AudioConverterFillBuffer will stop producing output and return whatever output
877/// has already been produced to its caller, along with the error code. This
878/// mechanism can be used when an input proc has temporarily run out of data, but
879/// has not yet reached end of stream.
880///
881/// See also [Apple's documentation](https://developer.apple.com/documentation/audiotoolbox/audioconverterinputdataproc?language=objc)
882pub type AudioConverterInputDataProc = Option<
883    unsafe extern "C-unwind" fn(
884        AudioConverterRef,
885        NonNull<u32>,
886        NonNull<NonNull<c_void>>,
887        *mut c_void,
888    ) -> OSStatus,
889>;
890
891extern "C-unwind" {
892    /// # Safety
893    ///
894    /// - `in_audio_converter` must be a valid pointer.
895    /// - `in_input_data_proc` must be implemented correctly.
896    /// - `in_input_data_proc_user_data` must be a valid pointer or null.
897    /// - `io_output_data_size` must be a valid pointer.
898    /// - `out_output_data` must be a valid pointer.
899    #[deprecated = "no longer supported"]
900    pub fn AudioConverterFillBuffer(
901        in_audio_converter: AudioConverterRef,
902        in_input_data_proc: AudioConverterInputDataProc,
903        in_input_data_proc_user_data: *mut c_void,
904        io_output_data_size: NonNull<u32>,
905        out_output_data: NonNull<c_void>,
906    ) -> OSStatus;
907}