|
6 | 6 |
|
7 | 7 | use libc;
|
8 | 8 |
|
9 |
| -pub use self::standard_flags::StandardFlags; |
10 |
| -pub use self::linear_pcm_flags::LinearPCMFlags; |
11 |
| -pub use self::apple_lossless_flags::AppleLosslessFlags; |
12 |
| -pub use self::audio_time_stamp_flags::AudioTimeStampFlags; |
13 |
| - |
14 |
| - |
15 | 9 | /// A type-safe representation of both the `AudioFormatId` and their associated flags.
|
16 | 10 | #[derive(Copy, Clone, Debug)]
|
17 | 11 | #[allow(non_camel_case_types)]
|
18 | 12 | pub enum AudioFormat {
|
19 | 13 | /// Linear PCM; a non-compressed audio data format with one frame per packet.
|
20 | 14 | ///
|
21 | 15 | /// **Available** in OS X v10.0 and later.
|
22 |
| - LinearPCM(LinearPCMFlags), // = 1819304813, |
| 16 | + LinearPCM(LinearPcmFlags), // = 1819304813, |
23 | 17 | /// An AC-3 codec.
|
24 | 18 | ///
|
25 | 19 | /// **Available** in OS X v10.2 and later.
|
@@ -183,7 +177,7 @@ impl AudioFormat {
|
183 | 177 | /// Convert from the FFI C format and flags to a typesafe Rust enum representation.
|
184 | 178 | pub fn from_format_and_flag(format: libc::c_uint, flag: Option<u32>) -> Option<AudioFormat> {
|
185 | 179 | match (format, flag) {
|
186 |
| - (1819304813, Some(i)) => Some(AudioFormat::LinearPCM(LinearPCMFlags::from_bits_truncate(i))), |
| 180 | + (1819304813, Some(i)) => Some(AudioFormat::LinearPCM(LinearPcmFlags::from_bits_truncate(i))), |
187 | 181 | (1633889587, _) => Some(AudioFormat::AC3),
|
188 | 182 | (1667326771, Some(i)) => Some(AudioFormat::F60958AC3(StandardFlags::from_bits_truncate(i))),
|
189 | 183 | (1768775988, _) => Some(AudioFormat::AppleIMA4),
|
@@ -268,155 +262,143 @@ impl AudioFormat {
|
268 | 262 | }
|
269 | 263 |
|
270 | 264 |
|
271 |
| -/// A wrapper around the const **StandardFlags**. |
272 |
| -pub mod standard_flags { |
273 |
| - bitflags! { |
274 |
| - /// Standard flags for use in the **F60958AC3** **AudioFormat** variant. |
| 265 | +bitflags! { |
| 266 | + /// Standard flags for use in the **F60958AC3** **AudioFormat** variant. |
| 267 | + /// |
| 268 | + /// Note: In the original Core Audio API these are consolidated with what we have named the |
| 269 | + /// **StandardFlags** and **AppleLosslessFlags** types under the `AudioFormatFlag` type. We |
| 270 | + /// have chosen to separate these for greater type safety and clearer compatibility with |
| 271 | + /// the **AudioFormat** type. |
| 272 | + /// |
| 273 | + /// Original documentation [here](https://developer.apple.com/library/mac/documentation/MusicAudio/Reference/CoreAudioDataTypesRef/#//apple_ref/doc/constant_group/AudioStreamBasicDescription_Flags). |
| 274 | + pub struct StandardFlags: u32 { |
| 275 | + /// Set for floating point, clear for integer. |
275 | 276 | ///
|
276 |
| - /// Note: In the original Core Audio API these are consolidated with what we have named the |
277 |
| - /// **StandardFlags** and **AppleLosslessFlags** types under the `AudioFormatFlag` type. We |
278 |
| - /// have chosen to separate these for greater type safety and clearer compatibility with |
279 |
| - /// the **AudioFormat** type. |
280 |
| - /// |
281 |
| - /// Original documentation [here](https://developer.apple.com/library/mac/documentation/MusicAudio/Reference/CoreAudioDataTypesRef/#//apple_ref/doc/constant_group/AudioStreamBasicDescription_Flags). |
282 |
| - pub struct StandardFlags: u32 { |
283 |
| - /// Set for floating point, clear for integer. |
284 |
| - /// |
285 |
| - /// **Available** in OS X v10.2 and later. |
286 |
| - const IS_FLOAT = 1; |
287 |
| - /// Set for big endian, clear for little endian. |
288 |
| - /// |
289 |
| - /// **Available** in OS X v10.2 and later. |
290 |
| - const IS_BIG_ENDIAN = 2; |
291 |
| - /// Set for signed integer, clear for unsigned integer. |
292 |
| - /// |
293 |
| - /// Note: This is only valid if `IS_FLOAT` is clear. |
294 |
| - /// |
295 |
| - /// **Available** in OS X v10.2 and later. |
296 |
| - const IS_SIGNED_INTEGER = 4; |
297 |
| - /// Set if the sample bits occupy the entire available bits for the channel, clear if they |
298 |
| - /// are high- or low-aligned within the channel. |
299 |
| - /// |
300 |
| - /// **Available** in OS X v10.2 and later. |
301 |
| - const IS_PACKED = 8; |
302 |
| - /// Set if the sample bits are placed into the high bits of the channel, clear for low bit |
303 |
| - /// placement. |
304 |
| - /// |
305 |
| - /// Note: This is only valid if `IS_PACKED` is clear. |
306 |
| - /// |
307 |
| - /// **Available** in OS X v10.2 and later. |
308 |
| - const IS_ALIGNED_HIGH = 16; |
309 |
| - /// Set if the sample for each channel are located contiguously and the channels are laid |
310 |
| - /// out end to end. |
311 |
| - /// |
312 |
| - /// Clear if the samples for each frame are laid out contiguously and the frames laid out |
313 |
| - /// end to end. |
314 |
| - /// |
315 |
| - /// **Available** in OS X v10.2 and later. |
316 |
| - const IS_NON_INTERLEAVED = 32; |
317 |
| - /// Set to indicate when a format is nonmixable. |
318 |
| - /// |
319 |
| - /// Note: that this flag is only used when interacting with the HAL's stream format |
320 |
| - /// information. It is **not** valid for any other use. |
321 |
| - /// |
322 |
| - /// **Available** in OS X v10.3 and later. |
323 |
| - const IS_NON_MIXABLE = 64; |
324 |
| - } |
325 |
| - } |
326 |
| -} |
327 |
| - |
328 |
| - |
329 |
| -/// A wrapper around the const **LinearPCMFlags**. |
330 |
| -pub mod linear_pcm_flags { |
331 |
| - bitflags! { |
332 |
| - /// Flags for use within the **LinearPCM** **AudioFormat**. |
| 277 | + /// **Available** in OS X v10.2 and later. |
| 278 | + const IS_FLOAT = 1; |
| 279 | + /// Set for big endian, clear for little endian. |
333 | 280 | ///
|
334 |
| - /// Note: In the original Core Audio API these are consolidated with what we have named the |
335 |
| - /// **StandardFlags** and **AppleLosslessFlags** types under the `AudioFormatFlag` type. We |
336 |
| - /// have chosen to separate these for greater type safety and clearer compatibility with |
337 |
| - /// the **AudioFormat** type. |
| 281 | + /// **Available** in OS X v10.2 and later. |
| 282 | + const IS_BIG_ENDIAN = 2; |
| 283 | + /// Set for signed integer, clear for unsigned integer. |
338 | 284 | ///
|
339 |
| - /// Original documentation [here](https://developer.apple.com/library/mac/documentation/MusicAudio/Reference/CoreAudioDataTypesRef/#//apple_ref/doc/constant_group/AudioStreamBasicDescription_Flags). |
340 |
| - pub struct LinearPCMFlags: u32 { |
341 |
| - /// Synonmyn for the **IS_FLOAT** **StandardFlags**. |
342 |
| - /// |
343 |
| - /// **Available** in OS X v10.0 and later. |
344 |
| - const IS_FLOAT = 1; |
345 |
| - /// Synonmyn for the **IS_BIG_ENDIAN** **StandardFlags**. |
346 |
| - /// |
347 |
| - /// **Available** in OS X v10.0 and later. |
348 |
| - const IS_BIG_ENDIAN = 2; |
349 |
| - /// Synonmyn for the **IS_SIGNED_INTEGER** **StandardFlags**. |
350 |
| - /// |
351 |
| - /// **Available** in OS X v10.0 and later. |
352 |
| - const IS_SIGNED_INTEGER = 4; |
353 |
| - /// Synonmyn for the **IS_PACKED** **StandardFlags**. |
354 |
| - /// |
355 |
| - /// **Available** in OS X v10.0 and later. |
356 |
| - const IS_PACKED = 8; |
357 |
| - /// Synonmyn for the **IS_ALIGNED_HIGH** **StandardFlags**. |
358 |
| - /// |
359 |
| - /// **Available** in OS X v10.0 and later. |
360 |
| - const IS_ALIGNED_HIGH = 16; |
361 |
| - /// Synonmyn for the **IS_NON_INTERLEAVED** **StandardFlags**. |
362 |
| - /// |
363 |
| - /// **Available** in OS X v10.2 and later. |
364 |
| - const IS_NON_INTERLEAVED = 32; |
365 |
| - /// Synonmyn for the **IS_NON_MIXABLE** **StandardFlags**. |
366 |
| - /// |
367 |
| - /// **Available** in OS X v10.3 and later. |
368 |
| - const IS_NON_MIXABLE = 64; |
369 |
| - /// The linear PCM flags contain a 6-bit bitfield indicating that an integer format is to |
370 |
| - /// be interpreted as fixed point. |
371 |
| - /// |
372 |
| - /// The value indicates the number of bits are used to represent the fractional portion of |
373 |
| - /// each sample value. |
374 |
| - /// |
375 |
| - /// This constant indicates the bit position (counting from the right) of the bitfield in |
376 |
| - /// `mFormatFlags` field. |
377 |
| - /// |
378 |
| - /// TODO: Review whether or not this flag indicates that we need to treat LinearPCM format |
379 |
| - /// uniquely in some way. |
380 |
| - /// |
381 |
| - /// **Available** in OS X v10.6 and later. |
382 |
| - const FLAGS_SAMPLE_FRACTION_SHIFT = 7; |
383 |
| - /// The number of fractional bits. |
384 |
| - /// |
385 |
| - /// `== (<other_flags> & FLAGS_SAMPLE_FRACTION_MASK) >> FLAGS_SAMPLE_FRACTION_SHIFT` |
386 |
| - /// |
387 |
| - /// **Available** in OS X v10.6 and later. |
388 |
| - const FLAGS_SAMPLE_FRACTION_MASK = 8064; |
389 |
| - } |
| 285 | + /// Note: This is only valid if `IS_FLOAT` is clear. |
| 286 | + /// |
| 287 | + /// **Available** in OS X v10.2 and later. |
| 288 | + const IS_SIGNED_INTEGER = 4; |
| 289 | + /// Set if the sample bits occupy the entire available bits for the channel, clear if they |
| 290 | + /// are high- or low-aligned within the channel. |
| 291 | + /// |
| 292 | + /// **Available** in OS X v10.2 and later. |
| 293 | + const IS_PACKED = 8; |
| 294 | + /// Set if the sample bits are placed into the high bits of the channel, clear for low bit |
| 295 | + /// placement. |
| 296 | + /// |
| 297 | + /// Note: This is only valid if `IS_PACKED` is clear. |
| 298 | + /// |
| 299 | + /// **Available** in OS X v10.2 and later. |
| 300 | + const IS_ALIGNED_HIGH = 16; |
| 301 | + /// Set if the sample for each channel are located contiguously and the channels are laid |
| 302 | + /// out end to end. |
| 303 | + /// |
| 304 | + /// Clear if the samples for each frame are laid out contiguously and the frames laid out |
| 305 | + /// end to end. |
| 306 | + /// |
| 307 | + /// **Available** in OS X v10.2 and later. |
| 308 | + const IS_NON_INTERLEAVED = 32; |
| 309 | + /// Set to indicate when a format is nonmixable. |
| 310 | + /// |
| 311 | + /// Note: that this flag is only used when interacting with the HAL's stream format |
| 312 | + /// information. It is **not** valid for any other use. |
| 313 | + /// |
| 314 | + /// **Available** in OS X v10.3 and later. |
| 315 | + const IS_NON_MIXABLE = 64; |
390 | 316 | }
|
391 | 317 | }
|
392 | 318 |
|
393 |
| - |
394 |
| -/// A wrapper around the const **AppleLosslessFlags**. |
395 |
| -pub mod apple_lossless_flags { |
396 |
| - bitflags! { |
397 |
| - /// Flags set for Apple Lossless data. |
| 319 | +bitflags! { |
| 320 | + /// Flags for use within the **LinearPCM** **AudioFormat**. |
| 321 | + /// |
| 322 | + /// Note: In the original Core Audio API these are consolidated with what we have named the |
| 323 | + /// **StandardFlags** and **AppleLosslessFlags** types under the `AudioFormatFlag` type. We |
| 324 | + /// have chosen to separate these for greater type safety and clearer compatibility with |
| 325 | + /// the **AudioFormat** type. |
| 326 | + /// |
| 327 | + /// Original documentation [here](https://developer.apple.com/library/mac/documentation/MusicAudio/Reference/CoreAudioDataTypesRef/#//apple_ref/doc/constant_group/AudioStreamBasicDescription_Flags). |
| 328 | + pub struct LinearPcmFlags: u32 { |
| 329 | + /// Synonmyn for the **IS_FLOAT** **StandardFlags**. |
| 330 | + /// |
| 331 | + /// **Available** in OS X v10.0 and later. |
| 332 | + const IS_FLOAT = 1; |
| 333 | + /// Synonmyn for the **IS_BIG_ENDIAN** **StandardFlags**. |
| 334 | + /// |
| 335 | + /// **Available** in OS X v10.0 and later. |
| 336 | + const IS_BIG_ENDIAN = 2; |
| 337 | + /// Synonmyn for the **IS_SIGNED_INTEGER** **StandardFlags**. |
| 338 | + /// |
| 339 | + /// **Available** in OS X v10.0 and later. |
| 340 | + const IS_SIGNED_INTEGER = 4; |
| 341 | + /// Synonmyn for the **IS_PACKED** **StandardFlags**. |
| 342 | + /// |
| 343 | + /// **Available** in OS X v10.0 and later. |
| 344 | + const IS_PACKED = 8; |
| 345 | + /// Synonmyn for the **IS_ALIGNED_HIGH** **StandardFlags**. |
| 346 | + /// |
| 347 | + /// **Available** in OS X v10.0 and later. |
| 348 | + const IS_ALIGNED_HIGH = 16; |
| 349 | + /// Synonmyn for the **IS_NON_INTERLEAVED** **StandardFlags**. |
| 350 | + /// |
| 351 | + /// **Available** in OS X v10.2 and later. |
| 352 | + const IS_NON_INTERLEAVED = 32; |
| 353 | + /// Synonmyn for the **IS_NON_MIXABLE** **StandardFlags**. |
398 | 354 | ///
|
399 | 355 | /// **Available** in OS X v10.3 and later.
|
| 356 | + const IS_NON_MIXABLE = 64; |
| 357 | + /// The linear PCM flags contain a 6-bit bitfield indicating that an integer format is to |
| 358 | + /// be interpreted as fixed point. |
400 | 359 | ///
|
401 |
| - /// Note: In the original Core Audio API these are consolidated with what we have named the |
402 |
| - /// **StandardFlags** and **AppleLosslessFlags** types under the `AudioFormatFlag` type. We |
403 |
| - /// have chosen to separate these for greater type safety and clearer compatibility with |
404 |
| - /// the **AudioFormat** type. |
| 360 | + /// The value indicates the number of bits are used to represent the fractional portion of |
| 361 | + /// each sample value. |
405 | 362 | ///
|
406 |
| - /// Original documentation [here](https://developer.apple.com/library/mac/documentation/MusicAudio/Reference/CoreAudioDataTypesRef/#//apple_ref/doc/constant_group/AudioStreamBasicDescription_Flags). |
407 |
| - pub struct AppleLosslessFlags: u32 { |
408 |
| - /// Sourced from 16 bit native endian signed integer data. |
409 |
| - const BIT_16_SOURCE_DATA = 1; |
410 |
| - /// Sourced from 20 bit native endian signed integer data aligned high in 24 bits. |
411 |
| - const BIT_20_SOURCE_DATA = 2; |
412 |
| - /// Sourced from 24 bit native endian signed integer data. |
413 |
| - const BIT_24_SOURCE_DATA = 3; |
414 |
| - /// Sourced from 32 bit native endian signed integer data. |
415 |
| - const BIT_32_SOURCE_DATA = 4; |
416 |
| - } |
| 363 | + /// This constant indicates the bit position (counting from the right) of the bitfield in |
| 364 | + /// `mFormatFlags` field. |
| 365 | + /// |
| 366 | + /// TODO: Review whether or not this flag indicates that we need to treat LinearPCM format |
| 367 | + /// uniquely in some way. |
| 368 | + /// |
| 369 | + /// **Available** in OS X v10.6 and later. |
| 370 | + const FLAGS_SAMPLE_FRACTION_SHIFT = 7; |
| 371 | + /// The number of fractional bits. |
| 372 | + /// |
| 373 | + /// `== (<other_flags> & FLAGS_SAMPLE_FRACTION_MASK) >> FLAGS_SAMPLE_FRACTION_SHIFT` |
| 374 | + /// |
| 375 | + /// **Available** in OS X v10.6 and later. |
| 376 | + const FLAGS_SAMPLE_FRACTION_MASK = 8064; |
417 | 377 | }
|
418 | 378 | }
|
419 | 379 |
|
| 380 | +bitflags! { |
| 381 | + /// Flags set for Apple Lossless data. |
| 382 | + /// |
| 383 | + /// **Available** in OS X v10.3 and later. |
| 384 | + /// |
| 385 | + /// Note: In the original Core Audio API these are consolidated with what we have named the |
| 386 | + /// **StandardFlags** and **AppleLosslessFlags** types under the `AudioFormatFlag` type. We |
| 387 | + /// have chosen to separate these for greater type safety and clearer compatibility with |
| 388 | + /// the **AudioFormat** type. |
| 389 | + /// |
| 390 | + /// Original documentation [here](https://developer.apple.com/library/mac/documentation/MusicAudio/Reference/CoreAudioDataTypesRef/#//apple_ref/doc/constant_group/AudioStreamBasicDescription_Flags). |
| 391 | + pub struct AppleLosslessFlags: u32 { |
| 392 | + /// Sourced from 16 bit native endian signed integer data. |
| 393 | + const BIT_16_SOURCE_DATA = 1; |
| 394 | + /// Sourced from 20 bit native endian signed integer data aligned high in 24 bits. |
| 395 | + const BIT_20_SOURCE_DATA = 2; |
| 396 | + /// Sourced from 24 bit native endian signed integer data. |
| 397 | + const BIT_24_SOURCE_DATA = 3; |
| 398 | + /// Sourced from 32 bit native endian signed integer data. |
| 399 | + const BIT_32_SOURCE_DATA = 4; |
| 400 | + } |
| 401 | +} |
420 | 402 |
|
421 | 403 | /// "Used in the `mFormatFlags` field of an `AudioStreamBasicDescription` structure that
|
422 | 404 | /// describes an MPEG-4 audio stream to specify the type of MPEG-4 audio data.
|
@@ -474,26 +456,22 @@ impl Mpeg4ObjectId {
|
474 | 456 | }
|
475 | 457 | }
|
476 | 458 |
|
477 |
| - |
478 |
| -/// A wrapper around the const **AudioTimeStampFlags**. |
479 |
| -pub mod audio_time_stamp_flags { |
480 |
| - bitflags! { |
481 |
| - /// "These flags indicate the valuid fields in an AudioTimeStamp structure." |
482 |
| - /// |
483 |
| - /// **Available** in OS X v10.0 and later. |
484 |
| - /// |
485 |
| - /// Original Documentation [here](https://developer.apple.com/library/mac/documentation/MusicAudio/Reference/CoreAudioDataTypesRef/#//apple_ref/doc/constant_group/Audio_Time_Stamp_Flags). |
486 |
| - pub struct AudioTimeStampFlags: u32 { |
487 |
| - /// The sample frame time is valid. |
488 |
| - const SAMPLE_TIME_VALID = 1; |
489 |
| - /// The host time is valid. |
490 |
| - const HOST_TIME_VALID = 2; |
491 |
| - /// The rate scalar is valid. |
492 |
| - const RATE_SCALAR_VALID = 4; |
493 |
| - /// The world clock time is valid. |
494 |
| - const WORLD_CLOCK_TIME_VALID = 8; |
495 |
| - /// The SMPTE time is valid. |
496 |
| - const SMPTE_TIME_VALID = 16; |
497 |
| - } |
| 459 | +bitflags! { |
| 460 | + /// "These flags indicate the valuid fields in an AudioTimeStamp structure." |
| 461 | + /// |
| 462 | + /// **Available** in OS X v10.0 and later. |
| 463 | + /// |
| 464 | + /// Original Documentation [here](https://developer.apple.com/library/mac/documentation/MusicAudio/Reference/CoreAudioDataTypesRef/#//apple_ref/doc/constant_group/Audio_Time_Stamp_Flags). |
| 465 | + pub struct AudioTimeStampFlags: u32 { |
| 466 | + /// The sample frame time is valid. |
| 467 | + const SAMPLE_TIME_VALID = 1; |
| 468 | + /// The host time is valid. |
| 469 | + const HOST_TIME_VALID = 2; |
| 470 | + /// The rate scalar is valid. |
| 471 | + const RATE_SCALAR_VALID = 4; |
| 472 | + /// The world clock time is valid. |
| 473 | + const WORLD_CLOCK_TIME_VALID = 8; |
| 474 | + /// The SMPTE time is valid. |
| 475 | + const SMPTE_TIME_VALID = 16; |
498 | 476 | }
|
499 | 477 | }
|
0 commit comments