coreaudio/audio_unit/
audio_format.rs

1//! Typification of the various AudioFormat codes and flags offered by the Core Audio API.
2//!
3//! See the Core Audio Data Types Reference
4//! [here](https://developer.apple.com/library/mac/documentation/MusicAudio/Reference/CoreAudioDataTypesRef/#//apple_ref/doc/constant_group/Audio_Data_Format_Identifiers) for more info.
5
6use objc2_core_audio_types::{
7    kAppleLosslessFormatFlag_16BitSourceData, kAppleLosslessFormatFlag_20BitSourceData,
8    kAppleLosslessFormatFlag_24BitSourceData, kAppleLosslessFormatFlag_32BitSourceData,
9    kAudioFormat60958AC3, kAudioFormatAC3, kAudioFormatAES3, kAudioFormatALaw, kAudioFormatAMR,
10    kAudioFormatAMR_WB, kAudioFormatAppleIMA4, kAudioFormatAppleLossless, kAudioFormatAudible,
11    kAudioFormatDVIIntelIMA, kAudioFormatFlagIsAlignedHigh, kAudioFormatFlagIsBigEndian,
12    kAudioFormatFlagIsFloat, kAudioFormatFlagIsNonInterleaved, kAudioFormatFlagIsNonMixable,
13    kAudioFormatFlagIsPacked, kAudioFormatFlagIsSignedInteger, kAudioFormatLinearPCM,
14    kAudioFormatMACE3, kAudioFormatMACE6, kAudioFormatMIDIStream, kAudioFormatMPEG4AAC,
15    kAudioFormatMPEG4AAC_ELD, kAudioFormatMPEG4AAC_ELD_SBR, kAudioFormatMPEG4AAC_ELD_V2,
16    kAudioFormatMPEG4AAC_HE, kAudioFormatMPEG4AAC_HE_V2, kAudioFormatMPEG4AAC_LD,
17    kAudioFormatMPEG4AAC_Spatial, kAudioFormatMPEG4CELP, kAudioFormatMPEG4HVXC,
18    kAudioFormatMPEG4TwinVQ, kAudioFormatMPEGLayer1, kAudioFormatMPEGLayer2,
19    kAudioFormatMPEGLayer3, kAudioFormatMicrosoftGSM, kAudioFormatParameterValueStream,
20    kAudioFormatQDesign, kAudioFormatQDesign2, kAudioFormatQUALCOMM, kAudioFormatTimeCode,
21    kAudioFormatULaw, kAudioFormatiLBC, kLinearPCMFormatFlagsSampleFractionMask,
22    kLinearPCMFormatFlagsSampleFractionShift, AudioTimeStampFlags as Objc2AudioTimeStampFlags,
23    MPEG4ObjectID as Objc2MPEG4ObjectID,
24};
25use std::os::raw::c_uint;
26
27/// A type-safe representation of both the `AudioFormatId` and their associated flags.
28#[derive(Copy, Clone, Debug)]
29#[allow(non_camel_case_types)]
30pub enum AudioFormat {
31    /// Linear PCM; a non-compressed audio data format with one frame per packet.
32    ///
33    /// **Available** in OS X v10.0 and later.
34    LinearPCM(LinearPcmFlags),
35    /// An AC-3 codec.
36    ///
37    /// **Available** in OS X v10.2 and later.
38    AC3,
39    /// AC-3 codec that provides data packaged for transport over an IEC 60958 compliant digital
40    /// audio interface.
41    ///
42    /// **Available** in OS X v10.2 and later.
43    F60958AC3(StandardFlags),
44    /// Apple's implementation of the IMA 4:1 ADPCM codec.
45    ///
46    /// **Available** in OS X v10.2 and later.
47    AppleIMA4,
48    /// MPEG-4 AAC codec.
49    ///
50    /// **Available** in OS X v10.2 and later.
51    MPEG4AAC(Mpeg4ObjectId),
52    /// MPEG-4 CELP codec.
53    ///
54    /// **Available** in OS X v10.2 and later.
55    MPEG4CELP(Mpeg4ObjectId),
56    /// MPEG-4 HVXC codec.
57    ///
58    /// **Available** in OS X v10.2 and later.
59    MPEG4HVXC(Mpeg4ObjectId),
60    /// MPEG-4 TwinVQ codec.
61    ///
62    /// **Available** in OS X v10.2 and later.
63    MPEG4TwinVQ(Mpeg4ObjectId),
64    /// MACE 3:1.
65    ///
66    /// **Available** in OS X v10.3 and later.
67    MACE3,
68    /// MACE 6:1.
69    ///
70    /// **Available** in OS X v10.3 and later.
71    MACE6,
72    /// μLaw 2:1.
73    ///
74    /// **Available** in OS X v10.3 and later.
75    ULaw,
76    /// aLaw 2:1.
77    ///
78    /// **Available** in OS X v10.3 and later.
79    ALaw,
80    /// QDesign Music.
81    ///
82    /// **Available** in OS X v10.3 and later.
83    QDesign,
84    /// QDesign2 Music.
85    ///
86    /// **Available** in OS X v10.3 and later.
87    QDesign2,
88    /// QUALCOMM PureVoice.
89    ///
90    /// **Available** in OS X v10.3 and later.
91    QUALCOMM,
92    /// MPEG-1/2, Layer 1 audio.
93    ///
94    /// **Available** in OS X v10.3 and later.
95    MPEGLayer1,
96    /// MPEG-1/2, Layer 2 audio.
97    ///
98    /// **Available** in OS X v10.3 and later.
99    MPEGLayer2,
100    /// MPEG-1/2, Layer 3 audio.
101    ///
102    /// **Available** in OS X v10.3 and later.
103    MPEGLayer3,
104    /// A stream of IOAudioTimeStamp structures.
105    ///
106    /// **Available** in OS X v10.2 and later.
107    TimeCode(AudioTimeStampFlags),
108    /// A stream of MIDIPacketList structures where the time stamps in the MIDIPacket structures
109    /// are sample offsets in the stream. The `sample_rate` field in the **StreamFormat** structure
110    /// is used to describe how time is passed in this kind of stream.
111    ///
112    /// An audio unit that receives or generates this stream can use this sample rate together with
113    /// the number of frames it is rendering.
114    ///
115    /// The sample offsets within the MIDIPacketList can be used to define the time for any MIDI
116    /// event within the list.
117    ///
118    /// **Available** in OS X v10.2 and later.
119    ///
120    /// TODO: Review whether or not this audio format should indicate some fundamental change
121    /// within the **StreamFormat**.
122    MIDIStream,
123    /// A "side-chain" of f32 data that can be fed or generated by an audio unit and that is used
124    /// to send a high density of parameter value control information.
125    ///
126    /// An audio unit typically runs a parameter value stream at either the sample rate of the
127    /// audio unit's audio data, or some integer quotient of this (i.e. a half or a third of the
128    /// sample rate of the audio).
129    ///
130    /// The `sample_rate` field in the **StreamFormat** type describes this relationship.
131    ///
132    /// **Available** in OS X v10.2 and later.
133    ParameterValueStream,
134    /// Apple Lossless format.
135    ///
136    /// **Available** in OS X v10.3 and later.
137    AppleLossless(AppleLosslessFlags),
138    /// MPEG-4 High Efficiency AAC audio object.
139    ///
140    /// **Available** in OS X v10.5 and later.
141    MPEG4AAC_HE,
142    /// MPEG-4 AAC Low Delay audio object.
143    ///
144    /// **Available** in OS X v10.5 and later.
145    MPEG4AAC_LD,
146    /// MPEG-4 AAC Enhanced Low Delay audio object.
147    ///
148    /// **Available** in OS X v10.7 and later.
149    MPEG4AAC_ELD,
150    /// MPEG-4 AAC Enhanced Low Delay audio object with SBR (spectral band replication) extension
151    /// layer.
152    ///
153    /// **Available** in OS X v10.7 and later.
154    MPEG4AAC_ELD_SBR,
155    MPEG4AAC_ELD_V2,
156    /// MPEG-4 High Efficiency AAC Version 2 audio object.
157    ///
158    /// **Available** in OS X v10.5 and later.
159    MPEG4AAC_HE_V2,
160    /// MPEG-4 Apatial Audio audio object.
161    ///
162    /// **Available** in OS X v10.5 and later.
163    MPEG4AAC_Spatial,
164    /// The AMR (adaptive Multi-Rate) narrow band speech codec.
165    ///
166    /// **Available** in OS X v10.5 and later.
167    AMR,
168    AMR_WB,
169    /// The codec used for Audible, Inc. audio books.
170    ///
171    /// **Available** in OS X v10.6 and later.
172    Audible,
173    /// The iLBC (internet Low Bitrate Codec) narrow band cpeech codec.
174    ///
175    /// **Available** in OS X v10.6 and later.
176    iLBC,
177    /// DVI/Intel IMA ADPCM - ACM code 17.
178    ///
179    /// **Available** in OS X v10.6 and later.
180    DVIIntelIMA,
181    /// Microsoft GSM 6.10 - ACM code 49.
182    ///
183    /// **Available** in OS X v10.6 and later.
184    MicrosoftGSM,
185    /// The format defined by the AES3-2003 standard.
186    ///
187    /// Adopted into MXF and MPEG-2 containers and SDTI transport streams with SMPTE specs
188    /// 203M-2002 and 331M-2000.
189    AES3,
190}
191
192impl AudioFormat {
193    /// Convert from the FFI C format and flags to a typesafe Rust enum representation.
194    pub fn from_format_and_flag(format: c_uint, flag: Option<u32>) -> Option<AudioFormat> {
195        match (format, flag) {
196            (_, Some(i)) if format == kAudioFormatLinearPCM => Some(AudioFormat::LinearPCM(
197                LinearPcmFlags::from_bits_truncate(i),
198            )),
199            (_, _) if format == kAudioFormatAC3 => Some(AudioFormat::AC3),
200            (_, Some(i)) if format == kAudioFormat60958AC3 => {
201                Some(AudioFormat::F60958AC3(StandardFlags::from_bits_truncate(i)))
202            }
203            (_, _) if format == kAudioFormatAppleIMA4 => Some(AudioFormat::AppleIMA4),
204            (_, Some(i)) if format == kAudioFormatMPEG4AAC => Some(AudioFormat::MPEG4AAC(
205                Mpeg4ObjectId::from_u32(i).expect("Unknown Mpeg4ObjectId"),
206            )),
207            (_, Some(i)) if format == kAudioFormatMPEG4CELP => Some(AudioFormat::MPEG4CELP(
208                Mpeg4ObjectId::from_u32(i).expect("Unknown Mpeg4ObjectId"),
209            )),
210            (_, Some(i)) if format == kAudioFormatMPEG4HVXC => Some(AudioFormat::MPEG4HVXC(
211                Mpeg4ObjectId::from_u32(i).expect("Unknown Mpeg4ObjectId"),
212            )),
213            (_, Some(i)) if format == kAudioFormatMPEG4TwinVQ => Some(AudioFormat::MPEG4TwinVQ(
214                Mpeg4ObjectId::from_u32(i).expect("Unknown Mpeg4ObjectId"),
215            )),
216            (_, _) if format == kAudioFormatMACE3 => Some(AudioFormat::MACE3),
217            (_, _) if format == kAudioFormatMACE6 => Some(AudioFormat::MACE6),
218            (_, _) if format == kAudioFormatULaw => Some(AudioFormat::ULaw),
219            (_, _) if format == kAudioFormatALaw => Some(AudioFormat::ALaw),
220            (_, _) if format == kAudioFormatQDesign => Some(AudioFormat::QDesign),
221            (_, _) if format == kAudioFormatQDesign2 => Some(AudioFormat::QDesign2),
222            (_, _) if format == kAudioFormatQUALCOMM => Some(AudioFormat::QUALCOMM),
223            (_, _) if format == kAudioFormatMPEGLayer1 => Some(AudioFormat::MPEGLayer1),
224            (_, _) if format == kAudioFormatMPEGLayer2 => Some(AudioFormat::MPEGLayer2),
225            (_, _) if format == kAudioFormatMPEGLayer3 => Some(AudioFormat::MPEGLayer3),
226            (_, Some(i)) if format == kAudioFormatTimeCode => Some(AudioFormat::TimeCode(
227                AudioTimeStampFlags::from_bits_truncate(i),
228            )),
229            (_, _) if format == kAudioFormatMIDIStream => Some(AudioFormat::MIDIStream),
230            (_, _) if format == kAudioFormatParameterValueStream => {
231                Some(AudioFormat::ParameterValueStream)
232            }
233            (_, Some(i)) if format == kAudioFormatAppleLossless => Some(
234                AudioFormat::AppleLossless(AppleLosslessFlags::from_bits_truncate(i)),
235            ),
236            (_, _) if format == kAudioFormatMPEG4AAC_HE => Some(AudioFormat::MPEG4AAC_HE),
237            (_, _) if format == kAudioFormatMPEG4AAC_LD => Some(AudioFormat::MPEG4AAC_LD),
238            (_, _) if format == kAudioFormatMPEG4AAC_ELD => Some(AudioFormat::MPEG4AAC_ELD),
239            (_, _) if format == kAudioFormatMPEG4AAC_ELD_SBR => Some(AudioFormat::MPEG4AAC_ELD_SBR),
240            (_, _) if format == kAudioFormatMPEG4AAC_ELD_V2 => Some(AudioFormat::MPEG4AAC_ELD_V2),
241            (_, _) if format == kAudioFormatMPEG4AAC_HE_V2 => Some(AudioFormat::MPEG4AAC_HE_V2),
242            (_, _) if format == kAudioFormatMPEG4AAC_Spatial => Some(AudioFormat::MPEG4AAC_Spatial),
243            (_, _) if format == kAudioFormatAMR => Some(AudioFormat::AMR),
244            (_, _) if format == kAudioFormatAMR_WB => Some(AudioFormat::AMR_WB),
245            (_, _) if format == kAudioFormatAudible => Some(AudioFormat::Audible),
246            (_, _) if format == kAudioFormatiLBC => Some(AudioFormat::iLBC),
247            (_, _) if format == kAudioFormatDVIIntelIMA => Some(AudioFormat::DVIIntelIMA),
248            (_, _) if format == kAudioFormatMicrosoftGSM => Some(AudioFormat::MicrosoftGSM),
249            (_, _) if format == kAudioFormatAES3 => Some(AudioFormat::AES3),
250            _ => None,
251        }
252    }
253
254    /// Convert from the Rust enum to the C format and flag.
255    pub fn as_format_and_flag(&self) -> (c_uint, Option<u32>) {
256        match *self {
257            AudioFormat::LinearPCM(flag) => (kAudioFormatLinearPCM, Some(flag.bits())),
258            AudioFormat::AC3 => (kAudioFormatAC3, None),
259            AudioFormat::F60958AC3(flag) => (kAudioFormat60958AC3, Some(flag.bits())),
260            AudioFormat::AppleIMA4 => (kAudioFormatAppleIMA4, None),
261            AudioFormat::MPEG4AAC(flag) => (kAudioFormatMPEG4AAC, Some(flag as u32)),
262            AudioFormat::MPEG4CELP(flag) => (kAudioFormatMPEG4CELP, Some(flag as u32)),
263            AudioFormat::MPEG4HVXC(flag) => (kAudioFormatMPEG4HVXC, Some(flag as u32)),
264            AudioFormat::MPEG4TwinVQ(flag) => (kAudioFormatMPEG4TwinVQ, Some(flag as u32)),
265            AudioFormat::MACE3 => (kAudioFormatMACE3, None),
266            AudioFormat::MACE6 => (kAudioFormatMACE6, None),
267            AudioFormat::ULaw => (kAudioFormatULaw, None),
268            AudioFormat::ALaw => (kAudioFormatALaw, None),
269            AudioFormat::QDesign => (kAudioFormatQDesign, None),
270            AudioFormat::QDesign2 => (kAudioFormatQDesign2, None),
271            AudioFormat::QUALCOMM => (kAudioFormatQUALCOMM, None),
272            AudioFormat::MPEGLayer1 => (kAudioFormatMPEGLayer1, None),
273            AudioFormat::MPEGLayer2 => (kAudioFormatMPEGLayer2, None),
274            AudioFormat::MPEGLayer3 => (kAudioFormatMPEGLayer3, None),
275            AudioFormat::TimeCode(flag) => (kAudioFormatTimeCode, Some(flag.bits())),
276            AudioFormat::MIDIStream => (kAudioFormatMIDIStream, None),
277            AudioFormat::ParameterValueStream => (kAudioFormatParameterValueStream, None),
278            AudioFormat::AppleLossless(flag) => (kAudioFormatAppleLossless, Some(flag.bits())),
279            AudioFormat::MPEG4AAC_HE => (kAudioFormatMPEG4AAC_HE, None),
280            AudioFormat::MPEG4AAC_LD => (kAudioFormatMPEG4AAC_LD, None),
281            AudioFormat::MPEG4AAC_ELD => (kAudioFormatMPEG4AAC_ELD, None),
282            AudioFormat::MPEG4AAC_ELD_SBR => (kAudioFormatMPEG4AAC_ELD_SBR, None),
283            AudioFormat::MPEG4AAC_ELD_V2 => (kAudioFormatMPEG4AAC_ELD_V2, None),
284            AudioFormat::MPEG4AAC_HE_V2 => (kAudioFormatMPEG4AAC_HE_V2, None),
285            AudioFormat::MPEG4AAC_Spatial => (kAudioFormatMPEG4AAC_Spatial, None),
286            AudioFormat::AMR => (kAudioFormatAMR, None),
287            AudioFormat::AMR_WB => (kAudioFormatAMR_WB, None),
288            AudioFormat::Audible => (kAudioFormatAudible, None),
289            AudioFormat::iLBC => (kAudioFormatiLBC, None),
290            AudioFormat::DVIIntelIMA => (kAudioFormatDVIIntelIMA, None),
291            AudioFormat::MicrosoftGSM => (kAudioFormatMicrosoftGSM, None),
292            AudioFormat::AES3 => (kAudioFormatAES3, None),
293        }
294    }
295}
296
297bitflags! {
298    /// Standard flags for use in the **F60958AC3** **AudioFormat** variant.
299    ///
300    /// Note: In the original Core Audio API these are consolidated with what we have named the
301    /// **StandardFlags** and **AppleLosslessFlags** types under the `AudioFormatFlag` type. We
302    /// have chosen to separate these for greater type safety and clearer compatibility with
303    /// the **AudioFormat** type.
304    ///
305    /// Original documentation [here](https://developer.apple.com/library/mac/documentation/MusicAudio/Reference/CoreAudioDataTypesRef/#//apple_ref/doc/constant_group/AudioStreamBasicDescription_Flags).
306    #[derive(Copy, Clone, Debug)]
307    pub struct StandardFlags: u32 {
308        /// Set for floating point, clear for integer.
309        ///
310        /// **Available** in OS X v10.2 and later.
311        const IS_FLOAT = kAudioFormatFlagIsFloat;
312        /// Set for big endian, clear for little endian.
313        ///
314        /// **Available** in OS X v10.2 and later.
315        const IS_BIG_ENDIAN = kAudioFormatFlagIsBigEndian;
316        /// Set for signed integer, clear for unsigned integer.
317        ///
318        /// Note: This is only valid if `IS_FLOAT` is clear.
319        ///
320        /// **Available** in OS X v10.2 and later.
321        const IS_SIGNED_INTEGER = kAudioFormatFlagIsSignedInteger;
322        /// Set if the sample bits occupy the entire available bits for the channel, clear if they
323        /// are high- or low-aligned within the channel.
324        ///
325        /// **Available** in OS X v10.2 and later.
326        const IS_PACKED = kAudioFormatFlagIsPacked;
327        /// Set if the sample bits are placed into the high bits of the channel, clear for low bit
328        /// placement.
329        ///
330        /// Note: This is only valid if `IS_PACKED` is clear.
331        ///
332        /// **Available** in OS X v10.2 and later.
333        const IS_ALIGNED_HIGH = kAudioFormatFlagIsAlignedHigh;
334        /// Set if the sample for each channel are located contiguously and the channels are laid
335        /// out end to end.
336        ///
337        /// Clear if the samples for each frame are laid out contiguously and the frames laid out
338        /// end to end.
339        ///
340        /// **Available** in OS X v10.2 and later.
341        const IS_NON_INTERLEAVED = kAudioFormatFlagIsNonInterleaved;
342        /// Set to indicate when a format is nonmixable.
343        ///
344        /// Note: that this flag is only used when interacting with the HAL's stream format
345        /// information. It is **not** valid for any other use.
346        ///
347        /// **Available** in OS X v10.3 and later.
348        const IS_NON_MIXABLE = kAudioFormatFlagIsNonMixable;
349    }
350}
351
352bitflags! {
353    /// Flags for use within the **LinearPCM** **AudioFormat**.
354    ///
355    /// Note: In the original Core Audio API these are consolidated with what we have named the
356    /// **StandardFlags** and **AppleLosslessFlags** types under the `AudioFormatFlag` type. We
357    /// have chosen to separate these for greater type safety and clearer compatibility with
358    /// the **AudioFormat** type.
359    ///
360    /// Original documentation [here](https://developer.apple.com/library/mac/documentation/MusicAudio/Reference/CoreAudioDataTypesRef/#//apple_ref/doc/constant_group/AudioStreamBasicDescription_Flags).
361    #[derive(Copy, Clone, Debug)]
362    pub struct LinearPcmFlags: u32 {
363        /// Synonym for the **IS_FLOAT** **StandardFlags**.
364        ///
365        /// **Available** in OS X v10.0 and later.
366        const IS_FLOAT = kAudioFormatFlagIsFloat;
367        /// Synonym for the **IS_BIG_ENDIAN** **StandardFlags**.
368        ///
369        /// **Available** in OS X v10.0 and later.
370        const IS_BIG_ENDIAN = kAudioFormatFlagIsBigEndian;
371        /// Synonym for the **IS_SIGNED_INTEGER** **StandardFlags**.
372        ///
373        /// **Available** in OS X v10.0 and later.
374        const IS_SIGNED_INTEGER = kAudioFormatFlagIsSignedInteger;
375        /// Synonym for the **IS_PACKED** **StandardFlags**.
376        ///
377        /// **Available** in OS X v10.0 and later.
378        const IS_PACKED = kAudioFormatFlagIsPacked;
379        /// Synonym for the **IS_ALIGNED_HIGH** **StandardFlags**.
380        ///
381        /// **Available** in OS X v10.0 and later.
382        const IS_ALIGNED_HIGH = kAudioFormatFlagIsAlignedHigh;
383        /// Synonym for the **IS_NON_INTERLEAVED** **StandardFlags**.
384        ///
385        /// **Available** in OS X v10.2 and later.
386        const IS_NON_INTERLEAVED = kAudioFormatFlagIsNonInterleaved;
387        /// Synonym for the **IS_NON_MIXABLE** **StandardFlags**.
388        ///
389        /// **Available** in OS X v10.3 and later.
390        const IS_NON_MIXABLE = kAudioFormatFlagIsNonMixable;
391        /// The linear PCM flags contain a 6-bit bitfield indicating that an integer format is to
392        /// be interpreted as fixed point.
393        ///
394        /// The value indicates the number of bits are used to represent the fractional portion of
395        /// each sample value.
396        ///
397        /// This constant indicates the bit position (counting from the right) of the bitfield in
398        /// `mFormatFlags` field.
399        ///
400        /// TODO: Review whether or not this flag indicates that we need to treat LinearPCM format
401        /// uniquely in some way.
402        ///
403        /// **Available** in OS X v10.6 and later.
404        const FLAGS_SAMPLE_FRACTION_SHIFT = kLinearPCMFormatFlagsSampleFractionShift;
405        /// The number of fractional bits.
406        ///
407        /// `== (<other_flags> & FLAGS_SAMPLE_FRACTION_MASK) >> FLAGS_SAMPLE_FRACTION_SHIFT`
408        ///
409        /// **Available** in OS X v10.6 and later.
410        const FLAGS_SAMPLE_FRACTION_MASK = kLinearPCMFormatFlagsSampleFractionMask;
411    }
412}
413
414bitflags! {
415    /// Flags set for Apple Lossless data.
416    ///
417    /// **Available** in OS X v10.3 and later.
418    ///
419    /// Note: In the original Core Audio API these are consolidated with what we have named the
420    /// **StandardFlags** and **AppleLosslessFlags** types under the `AudioFormatFlag` type. We
421    /// have chosen to separate these for greater type safety and clearer compatibility with
422    /// the **AudioFormat** type.
423    ///
424    /// Original documentation [here](https://developer.apple.com/library/mac/documentation/MusicAudio/Reference/CoreAudioDataTypesRef/#//apple_ref/doc/constant_group/AudioStreamBasicDescription_Flags).
425    #[derive(Copy, Clone, Debug)]
426    pub struct AppleLosslessFlags: u32 {
427        /// Sourced from 16 bit native endian signed integer data.
428        const BIT_16_SOURCE_DATA = kAppleLosslessFormatFlag_16BitSourceData;
429        /// Sourced from 20 bit native endian signed integer data aligned high in 24 bits.
430        const BIT_20_SOURCE_DATA = kAppleLosslessFormatFlag_20BitSourceData;
431        /// Sourced from 24 bit native endian signed integer data.
432        const BIT_24_SOURCE_DATA = kAppleLosslessFormatFlag_24BitSourceData;
433        /// Sourced from 32 bit native endian signed integer data.
434        const BIT_32_SOURCE_DATA = kAppleLosslessFormatFlag_32BitSourceData;
435    }
436}
437
438/// "Used in the `mFormatFlags` field of an `AudioStreamBasicDescription` structure that
439/// describes an MPEG-4 audio stream to specify the type of MPEG-4 audio data.
440///
441/// **Available** in OS X v10.3 and later.
442///
443/// **Deprecated** in OS X v10.5.
444///
445/// Note: This type was originally represented using a bitflag field in the original API, however
446/// there is only ever one flag set at a time. Thus, we use an enum as a more accurate,
447/// user-friendly, type-safe representation.
448///
449/// Original documenation
450/// [here](https://developer.apple.com/library/mac/documentation/MusicAudio/Reference/CoreAudioDataTypesRef/#//apple_ref/doc/constant_group/MPEG_4_Audio_Object_Type_Constants).
451#[derive(Copy, Clone, Debug, PartialEq)]
452#[allow(non_camel_case_types)]
453pub enum Mpeg4ObjectId {
454    /// Advanced audio coding; the baisc MPEG-4 technology.
455    AAC_Main = Objc2MPEG4ObjectID::AAC_Main.0 as isize,
456    /// Lossless coding; provides compression with no loss of quality.
457    AAC_LC = Objc2MPEG4ObjectID::AAC_LC.0 as isize,
458    /// Scalable sampling rate; provides different sampling frequencies for different targets.
459    AAC_SSR = Objc2MPEG4ObjectID::AAC_SSR.0 as isize,
460    /// Long term prediction; reduces redundancy in a coded signal.
461    AAC_LTP = Objc2MPEG4ObjectID::AAC_LTP.0 as isize,
462    /// Spectral band replication; reconstructs high-frequency content from lower frequencies
463    /// and side information.
464    AAC_SBR = Objc2MPEG4ObjectID::AAC_SBR.0 as isize,
465    /// Scalable lossless coding.
466    AAC_Scalable = Objc2MPEG4ObjectID::AAC_Scalable.0 as isize,
467    /// Transform-domain weighted interleaved vector quantization; an audio codec optimised for
468    /// audio coding at ultra low bit rates around 8kbit/s.
469    TwinVQ = Objc2MPEG4ObjectID::TwinVQ.0 as isize,
470    /// Code Excited Linear Prediction; a narrow-band/wide-band speech codec.
471    CELP = Objc2MPEG4ObjectID::CELP.0 as isize,
472    /// Harmonic Vector Excitation Coding; a very-low bit-rate parametric speech codec.
473    HVXC = Objc2MPEG4ObjectID::HVXC.0 as isize,
474}
475
476impl Mpeg4ObjectId {
477    /// Create an Mpeg4ObjectId from a u32.
478    pub fn from_u32(u: u32) -> Option<Mpeg4ObjectId> {
479        match u {
480            _ if u == Objc2MPEG4ObjectID::AAC_Main.0 as u32 => Some(Mpeg4ObjectId::AAC_Main),
481            _ if u == Objc2MPEG4ObjectID::AAC_LC.0 as u32 => Some(Mpeg4ObjectId::AAC_LC),
482            _ if u == Objc2MPEG4ObjectID::AAC_SSR.0 as u32 => Some(Mpeg4ObjectId::AAC_SSR),
483            _ if u == Objc2MPEG4ObjectID::AAC_LTP.0 as u32 => Some(Mpeg4ObjectId::AAC_LTP),
484            _ if u == Objc2MPEG4ObjectID::AAC_SBR.0 as u32 => Some(Mpeg4ObjectId::AAC_SBR),
485            _ if u == Objc2MPEG4ObjectID::AAC_Scalable.0 as u32 => {
486                Some(Mpeg4ObjectId::AAC_Scalable)
487            }
488            _ if u == Objc2MPEG4ObjectID::TwinVQ.0 as u32 => Some(Mpeg4ObjectId::TwinVQ),
489            _ if u == Objc2MPEG4ObjectID::CELP.0 as u32 => Some(Mpeg4ObjectId::CELP),
490            _ if u == Objc2MPEG4ObjectID::HVXC.0 as u32 => Some(Mpeg4ObjectId::HVXC),
491            _ => None,
492        }
493    }
494}
495
496bitflags! {
497    /// "These flags indicate the valuid fields in an AudioTimeStamp structure."
498    ///
499    /// **Available** in OS X v10.0 and later.
500    ///
501    /// Original Documentation [here](https://developer.apple.com/library/mac/documentation/MusicAudio/Reference/CoreAudioDataTypesRef/#//apple_ref/doc/constant_group/Audio_Time_Stamp_Flags).
502    #[derive(Copy, Clone, Debug)]
503    pub struct AudioTimeStampFlags: u32 {
504        /// The sample frame time is valid.
505        const SAMPLE_TIME_VALID = Objc2AudioTimeStampFlags::SampleTimeValid.0;
506        /// The host time is valid.
507        const HOST_TIME_VALID = Objc2AudioTimeStampFlags::HostTimeValid.0;
508        /// The rate scalar is valid.
509        const RATE_SCALAR_VALID = Objc2AudioTimeStampFlags::RateScalarValid.0;
510        /// The world clock time is valid.
511        const WORLD_CLOCK_TIME_VALID = Objc2AudioTimeStampFlags::WordClockTimeValid.0;
512        /// The SMPTE time is valid.
513        const SMPTE_TIME_VALID = Objc2AudioTimeStampFlags::SMPTETimeValid.0;
514    }
515}