Skip to content

Commit 2ce6744

Browse files
committed
Convert time stamp flags and mpeg4objectid to bitflags
1 parent fd54c44 commit 2ce6744

File tree

3 files changed

+61
-60
lines changed

3 files changed

+61
-60
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,6 @@ homepage = "https://github.com/RustAudio/coreaudio-rs"
1515
num = "0.1.27"
1616

1717
[dependencies]
18+
bitflags = "0.3.2"
1819
coreaudio-sys = "0.1.1"
1920
libc = "0.1.10"

src/audio_unit/audio_format.rs

Lines changed: 59 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ pub enum AudioFormat {
1414
AC3, // = 1633889587,
1515
F60958AC3(Option<StandardFlag>), // = 1667326771,
1616
AppleIMA4, // = 1768775988,
17-
MPEG4AAC(Option<Mpeg4Object>), // = 1633772320,
18-
MPEG4CELP(Option<Mpeg4Object>), // = 1667591280,
19-
MPEG4HVXC(Option<Mpeg4Object>), // = 1752594531,
20-
MPEG4TwinVQ(Option<Mpeg4Object>), // = 1953986161,
17+
MPEG4AAC(Option<Mpeg4ObjectId>), // = 1633772320,
18+
MPEG4CELP(Option<Mpeg4ObjectId>), // = 1667591280,
19+
MPEG4HVXC(Option<Mpeg4ObjectId>), // = 1752594531,
20+
MPEG4TwinVQ(Option<Mpeg4ObjectId>), // = 1953986161,
2121
MACE3, // = 1296122675,
2222
MACE6, // = 1296122678,
2323
ULaw, // = 1970037111,
@@ -57,10 +57,10 @@ impl AudioFormat {
5757
(1633889587, _) => Some(AudioFormat::AC3),
5858
(1667326771, Some(i)) => Some(AudioFormat::F60958AC3(StandardFlag::from_u32(i))),
5959
(1768775988, _) => Some(AudioFormat::AppleIMA4),
60-
(1633772320, Some(i)) => Some(AudioFormat::MPEG4AAC(Mpeg4Object::from_u32(i))),
61-
(1667591280, Some(i)) => Some(AudioFormat::MPEG4CELP(Mpeg4Object::from_u32(i))),
62-
(1752594531, Some(i)) => Some(AudioFormat::MPEG4HVXC(Mpeg4Object::from_u32(i))),
63-
(1953986161, Some(i)) => Some(AudioFormat::MPEG4TwinVQ(Mpeg4Object::from_u32(i))),
60+
(1633772320, Some(i)) => Some(AudioFormat::MPEG4AAC(Mpeg4ObjectId::from_bits(i as isize))),
61+
(1667591280, Some(i)) => Some(AudioFormat::MPEG4CELP(Mpeg4ObjectId::from_bits(i as isize))),
62+
(1752594531, Some(i)) => Some(AudioFormat::MPEG4HVXC(Mpeg4ObjectId::from_bits(i as isize))),
63+
(1953986161, Some(i)) => Some(AudioFormat::MPEG4TwinVQ(Mpeg4ObjectId::from_bits(i as isize))),
6464
(1296122675, _) => Some(AudioFormat::MACE3),
6565
(1296122678, _) => Some(AudioFormat::MACE6),
6666
(1970037111, _) => Some(AudioFormat::ULaw),
@@ -71,7 +71,7 @@ impl AudioFormat {
7171
(778924081, _) => Some(AudioFormat::MPEGLayer1),
7272
(778924082, _) => Some(AudioFormat::MPEGLayer2),
7373
(778924083, _) => Some(AudioFormat::MPEGLayer3),
74-
(1953066341, Some(i)) => Some(AudioFormat::TimeCode(AudioTimeStampFlag::from_u32(i))),
74+
(1953066341, Some(i)) => Some(AudioFormat::TimeCode(AudioTimeStampFlag::from_bits(i))),
7575
(1835623529, _) => Some(AudioFormat::MIDIStream),
7676
(1634760307, _) => Some(AudioFormat::ParameterValueStream),
7777
(1634492771, _) => Some(AudioFormat::AppleLossless),
@@ -100,10 +100,10 @@ impl AudioFormat {
100100
AudioFormat::AC3 => (1633889587, None),
101101
AudioFormat::F60958AC3(flag) => (1667326771, flag.map(|flag| flag as u32)),
102102
AudioFormat::AppleIMA4 => (1768775988, None),
103-
AudioFormat::MPEG4AAC(flag) => (1633772320, flag.map(|flag| flag as u32)),
104-
AudioFormat::MPEG4CELP(flag) => (1667591280, flag.map(|flag| flag as u32)),
105-
AudioFormat::MPEG4HVXC(flag) => (1752594531, flag.map(|flag| flag as u32)),
106-
AudioFormat::MPEG4TwinVQ(flag) => (1953986161, flag.map(|flag| flag as u32)),
103+
AudioFormat::MPEG4AAC(flag) => (1633772320, flag.map(|flag| flag.bits() as u32)),
104+
AudioFormat::MPEG4CELP(flag) => (1667591280, flag.map(|flag| flag.bits() as u32)),
105+
AudioFormat::MPEG4HVXC(flag) => (1752594531, flag.map(|flag| flag.bits() as u32)),
106+
AudioFormat::MPEG4TwinVQ(flag) => (1953986161, flag.map(|flag| flag.bits() as u32)),
107107
AudioFormat::MACE3 => (1296122675, None),
108108
AudioFormat::MACE6 => (1296122678, None),
109109
AudioFormat::ULaw => (1970037111, None),
@@ -114,7 +114,7 @@ impl AudioFormat {
114114
AudioFormat::MPEGLayer1 => (778924081, None),
115115
AudioFormat::MPEGLayer2 => (778924082, None),
116116
AudioFormat::MPEGLayer3 => (778924083, None),
117-
AudioFormat::TimeCode(flag) => (1953066341, flag.map(|flag| flag as u32)),
117+
AudioFormat::TimeCode(flag) => (1953066341, flag.map(|flag| flag.bits())),
118118
AudioFormat::MIDIStream => (1835623529, None),
119119
AudioFormat::ParameterValueStream => (1634760307, None),
120120
AudioFormat::AppleLossless => (1634492771, None),
@@ -213,57 +213,56 @@ impl AppleLosslessFlag {
213213
}
214214
}
215215

216-
#[derive(Copy, Clone, Debug)]
217-
#[allow(non_camel_case_types)]
218-
pub enum Mpeg4Object {
219-
AAC_Main = 1,
220-
AAC_LC = 2,
221-
AAC_SSR = 3,
222-
AAC_LTP = 4,
223-
AAC_SBR = 5,
224-
AAC_Scalable = 6,
225-
TwinVQ = 7,
226-
CELP = 8,
227-
HVXC = 9,
228-
}
229216

230-
impl Mpeg4Object {
231-
pub fn from_u32(i: u32) -> Option<Mpeg4Object> {
232-
match i {
233-
1 => Some(Mpeg4Object::AAC_Main),
234-
2 => Some(Mpeg4Object::AAC_LC),
235-
3 => Some(Mpeg4Object::AAC_SSR),
236-
4 => Some(Mpeg4Object::AAC_LTP),
237-
5 => Some(Mpeg4Object::AAC_SBR),
238-
6 => Some(Mpeg4Object::AAC_Scalable),
239-
7 => Some(Mpeg4Object::TwinVQ),
240-
8 => Some(Mpeg4Object::CELP),
241-
9 => Some(Mpeg4Object::HVXC),
242-
_ => None,
243-
}
217+
bitflags! {
218+
/// "Used in the `mFormatFlags` field of an `AudioStreamBasicDescription` structure that
219+
/// describes an MPEG-4 audio stream to specify the type of MPEG-4 audio data.
220+
///
221+
/// **Available** in OSX v10.3 and later.
222+
///
223+
/// **Deprecated** in OSX v10.5.
224+
flags Mpeg4ObjectId: isize {
225+
/// Advanced audio coding; the baisc MPEG-4 technology.
226+
const AAC_MAIN = 1,
227+
/// Lossless coding; provides compression with no loss of quality.
228+
const AAC_LC = 2,
229+
/// Scalable sampling rate; provides different sampling frequencies for different targets.
230+
const AAC_SSR = 3,
231+
/// Long term prediction; reduces redundancy in a coded signal.
232+
const AAC_LTP = 4,
233+
/// Spectral band replication; reconstructs high-frequency content from lower frequencies
234+
/// and side information.
235+
const AAC_SBR = 5,
236+
/// Scalable lossless coding.
237+
const AAC_SCALABLE = 6,
238+
/// Transform-domain weighted interleaved vector quantization; an audio codec optimised for
239+
/// audio coding at ultra low bit rates around 8kbit/s.
240+
const TWIN_VQ = 7,
241+
/// Code Excited Linear Prdiction; a narrow-band/wide-band speech codec.
242+
const CELP = 8,
243+
/// Harmonic Vector Excitation Coding; a very-low bit-rate parametric speech codec.
244+
const HVXC = 9,
244245
}
245246
}
246247

247-
#[derive(Copy, Clone, Debug)]
248-
#[allow(non_camel_case_types)]
249-
pub enum AudioTimeStampFlag {
250-
SampleTimeValid = 1,
251-
HostTimeValid = 2,
252-
RateScalarValid = 4,
253-
WordClockTimeValid = 8,
254-
SMPTETimeValid = 16,
255-
}
256248

257-
impl AudioTimeStampFlag {
258-
pub fn from_u32(i: u32) -> Option<AudioTimeStampFlag> {
259-
match i {
260-
1 => Some(AudioTimeStampFlag::SampleTimeValid),
261-
2 => Some(AudioTimeStampFlag::HostTimeValid),
262-
4 => Some(AudioTimeStampFlag::RateScalarValid),
263-
8 => Some(AudioTimeStampFlag::WordClockTimeValid),
264-
16 => Some(AudioTimeStampFlag::SMPTETimeValid),
265-
_ => None
266-
}
249+
bitflags! {
250+
/// "These flags indicate the valuid fields in an AudioTimeStamp structure."
251+
///
252+
/// Original Documentation [here](https://developer.apple.com/library/mac/documentation/MusicAudio/Reference/CoreAudioDataTypesRef/#//apple_ref/doc/constant_group/Audio_Time_Stamp_Flags).
253+
///
254+
/// Available in OSX v10.0 and later.
255+
flags AudioTimeStampFlag: u32 {
256+
/// The sample frame time is valid.
257+
const SAMPLE_TIME_VALID = 1,
258+
/// The host time is valid.
259+
const HOST_TIME_VALID = 2,
260+
/// The rate scalar is valid.
261+
const RATE_SCALAR_VALID = 4,
262+
/// The world clock time is valid.
263+
const WORLD_CLOCK_TIME_VALID = 8,
264+
/// The SMPTE time is valid.
265+
const SMPTE_TIME_VALID = 16,
267266
}
268267
}
269268

src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
//! Currently, work has only been started on the [audio_unit](./audio_unit/index.html) module, but
99
//! eventually we'd like to cover at least the majority of the C API.
1010
11+
#[macro_use] extern crate bitflags;
1112
extern crate coreaudio_sys;
1213
pub use coreaudio_sys as bindings;
1314

0 commit comments

Comments
 (0)