Skip to content

Commit f598fa1

Browse files
Merge pull request #57 from mitchmindtree/update_sys
Update to coreaudio-sys 0.2. Rename reexport from bindings to sys. Publish 0.8.
2 parents 735d7c3 + 53f0c16 commit f598fa1

File tree

7 files changed

+111
-115
lines changed

7 files changed

+111
-115
lines changed

Cargo.toml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "coreaudio-rs"
3-
version = "0.7.0"
3+
version = "0.8.0"
44
authors = ["mitchmindtree <mitchell.nordine@gmail.com>", "yupferris <jake@fusetools.com>"]
55
description = "A friendly rust interface for Apple's CoreAudio API."
66
keywords = ["core", "audio", "unit", "osx", "ios"]
@@ -14,5 +14,4 @@ name = "coreaudio"
1414

1515
[dependencies]
1616
bitflags = "1.0"
17-
coreaudio-sys = "0.1"
18-
libc = "0.2"
17+
coreaudio-sys = "0.2"

src/audio_unit/audio_format.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
//! See the Core Audio Data Types Reference
44
//! [here](https://developer.apple.com/library/mac/documentation/MusicAudio/Reference/CoreAudioDataTypesRef/#//apple_ref/doc/constant_group/Audio_Data_Format_Identifiers) for more info.
55
6-
7-
use libc;
6+
use std::os::raw::c_uint;
87

98
/// A type-safe representation of both the `AudioFormatId` and their associated flags.
109
#[derive(Copy, Clone, Debug)]
@@ -175,7 +174,7 @@ pub enum AudioFormat {
175174
impl AudioFormat {
176175

177176
/// Convert from the FFI C format and flags to a typesafe Rust enum representation.
178-
pub fn from_format_and_flag(format: libc::c_uint, flag: Option<u32>) -> Option<AudioFormat> {
177+
pub fn from_format_and_flag(format: c_uint, flag: Option<u32>) -> Option<AudioFormat> {
179178
match (format, flag) {
180179
(1819304813, Some(i)) => Some(AudioFormat::LinearPCM(LinearPcmFlags::from_bits_truncate(i))),
181180
(1633889587, _) => Some(AudioFormat::AC3),
@@ -218,7 +217,7 @@ impl AudioFormat {
218217
}
219218

220219
/// Convert from the Rust enum to the C format and flag.
221-
pub fn to_format_and_flag(&self) -> (libc::c_uint, Option<u32>) {
220+
pub fn to_format_and_flag(&self) -> (c_uint, Option<u32>) {
222221
match *self {
223222
AudioFormat::LinearPCM(flag) => (1819304813, Some(flag.bits())),
224223
AudioFormat::AC3 => (1633889587, None),

src/audio_unit/mod.rs

Lines changed: 34 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@
1919
//! fixes!
2020
2121

22-
use bindings::audio_unit as au;
2322
use error::Error;
24-
use libc;
2523
use std::mem;
2624
use std::ptr;
25+
use std::os::raw::{c_uint, c_void};
26+
use sys;
2727

2828
pub use self::audio_format::AudioFormat;
2929
pub use self::sample_format::{SampleFormat, Sample};
@@ -52,8 +52,14 @@ pub mod types;
5252
/// and [here](https://developer.apple.com/library/mac/documentation/MusicAudio/Conceptual/AudioUnitProgrammingGuide/TheAudioUnit/TheAudioUnit.html).
5353
#[derive(Copy, Clone, Debug)]
5454
pub enum Scope {
55-
Output = 0,
55+
Global = 0,
5656
Input = 1,
57+
Output = 2,
58+
Group = 3,
59+
Part = 4,
60+
Note = 5,
61+
Layer = 6,
62+
LayerItem = 7,
5763
}
5864

5965
/// Represents the **Input** and **Output** **Element**s.
@@ -66,11 +72,11 @@ pub enum Element {
6672
}
6773

6874

69-
/// A rust representation of the au::AudioUnit, including a pointer to the current rendering callback.
75+
/// A rust representation of the sys::AudioUnit, including a pointer to the current rendering callback.
7076
///
7177
/// Find the original Audio Unit Programming Guide [here](https://developer.apple.com/library/mac/documentation/MusicAudio/Conceptual/AudioUnitProgrammingGuide/TheAudioUnit/TheAudioUnit.html).
7278
pub struct AudioUnit {
73-
instance: au::AudioUnit,
79+
instance: sys::AudioUnit,
7480
maybe_callback: Option<*mut render_callback::InputProcFnWrapper>
7581
}
7682

@@ -112,17 +118,17 @@ impl AudioUnit {
112118
pub fn new_with_flags<T>(ty: T, flags: u32, mask: u32) -> Result<AudioUnit, Error>
113119
where T: Into<Type>,
114120
{
115-
const MANUFACTURER_IDENTIFIER: u32 = au::kAudioUnitManufacturer_Apple;
121+
const MANUFACTURER_IDENTIFIER: u32 = sys::kAudioUnitManufacturer_Apple;
116122
let au_type: Type = ty.into();
117123
let sub_type_u32 = match au_type.to_subtype_u32() {
118124
Some(u) => u,
119125
None => return Err(Error::NoKnownSubtype),
120126
};
121127

122128
// A description of the audio unit we desire.
123-
let desc = au::AudioComponentDescription {
124-
componentType: au_type.to_u32() as libc::c_uint,
125-
componentSubType: sub_type_u32 as libc::c_uint,
129+
let desc = sys::AudioComponentDescription {
130+
componentType: au_type.to_u32() as c_uint,
131+
componentSubType: sub_type_u32 as c_uint,
126132
componentManufacturer: MANUFACTURER_IDENTIFIER,
127133
componentFlags: flags,
128134
componentFlagsMask: mask,
@@ -137,19 +143,19 @@ impl AudioUnit {
137143
// find the first system audio unit matching the description, using a system-defined
138144
// ordering. If you instead pass a previously found audio unit reference in this
139145
// parameter, the function locates the next audio unit matching the description.
140-
let component = au::AudioComponentFindNext(ptr::null_mut(), &desc as *const _);
146+
let component = sys::AudioComponentFindNext(ptr::null_mut(), &desc as *const _);
141147
if component.is_null() {
142148
return Err(Error::NoMatchingDefaultAudioUnitFound);
143149
}
144150

145151
// Create an instance of the default audio unit using the component.
146-
let mut instance: au::AudioUnit = mem::uninitialized();
152+
let mut instance: sys::AudioUnit = mem::uninitialized();
147153
try_os_status!(
148-
au::AudioComponentInstanceNew(component, &mut instance as *mut au::AudioUnit)
154+
sys::AudioComponentInstanceNew(component, &mut instance as *mut sys::AudioUnit)
149155
);
150156

151157
// Initialise the audio unit!
152-
try_os_status!(au::AudioUnitInitialize(instance));
158+
try_os_status!(sys::AudioUnitInitialize(instance));
153159
Ok(AudioUnit {
154160
instance: instance,
155161
maybe_callback: None
@@ -178,14 +184,14 @@ impl AudioUnit {
178184
-> Result<(), Error>
179185
{
180186
let (data_ptr, size) = maybe_data.map(|data| {
181-
let ptr = data as *const _ as *const libc::c_void;
187+
let ptr = data as *const _ as *const c_void;
182188
let size = ::std::mem::size_of::<T>() as u32;
183189
(ptr, size)
184190
}).unwrap_or_else(|| (::std::ptr::null(), 0));
185-
let scope = scope as libc::c_uint;
186-
let elem = elem as libc::c_uint;
191+
let scope = scope as c_uint;
192+
let elem = elem as c_uint;
187193
unsafe {
188-
try_os_status!(au::AudioUnitSetProperty(self.instance, id, scope, elem, data_ptr, size))
194+
try_os_status!(sys::AudioUnitSetProperty(self.instance, id, scope, elem, data_ptr, size))
189195
}
190196
Ok(())
191197
}
@@ -201,15 +207,15 @@ impl AudioUnit {
201207
/// - **scope**: The audio unit scope for the property.
202208
/// - **elem**: The audio unit element for the property.
203209
pub fn get_property<T>(&self, id: u32, scope: Scope, elem: Element) -> Result<T, Error> {
204-
let scope = scope as libc::c_uint;
205-
let elem = elem as libc::c_uint;
210+
let scope = scope as c_uint;
211+
let elem = elem as c_uint;
206212
let mut size = ::std::mem::size_of::<T>() as u32;
207213
unsafe {
208214
let mut data: T = ::std::mem::uninitialized();
209-
let data_ptr = &mut data as *mut _ as *mut libc::c_void;
215+
let data_ptr = &mut data as *mut _ as *mut c_void;
210216
let size_ptr = &mut size as *mut _;
211217
try_os_status!(
212-
au::AudioUnitGetProperty(self.instance, id, scope, elem, data_ptr, size_ptr)
218+
sys::AudioUnitGetProperty(self.instance, id, scope, elem, data_ptr, size_ptr)
213219
);
214220
Ok(data)
215221
}
@@ -220,7 +226,7 @@ impl AudioUnit {
220226
///
221227
/// **Available** in OS X v10.0 and later.
222228
pub fn start(&mut self) -> Result<(), Error> {
223-
unsafe { try_os_status!(au::AudioOutputUnitStart(self.instance)); }
229+
unsafe { try_os_status!(sys::AudioOutputUnitStart(self.instance)); }
224230
Ok(())
225231
}
226232

@@ -229,21 +235,21 @@ impl AudioUnit {
229235
///
230236
/// **Available** in OS X v10.0 and later.
231237
pub fn stop(&mut self) -> Result<(), Error> {
232-
unsafe { try_os_status!(au::AudioOutputUnitStop(self.instance)); }
238+
unsafe { try_os_status!(sys::AudioOutputUnitStop(self.instance)); }
233239
Ok(())
234240
}
235241

236242
/// Set the **AudioUnit**'s sample rate.
237243
///
238244
/// **Available** in iOS 2.0 and later.
239245
pub fn set_sample_rate(&mut self, sample_rate: f64) -> Result<(), Error> {
240-
let id = au::kAudioUnitProperty_SampleRate;
246+
let id = sys::kAudioUnitProperty_SampleRate;
241247
self.set_property(id, Scope::Input, Element::Output, Some(&sample_rate))
242248
}
243249

244250
/// Get the **AudioUnit**'s sample rate.
245251
pub fn sample_rate(&self) -> Result<f64, Error> {
246-
let id = au::kAudioUnitProperty_SampleRate;
252+
let id = sys::kAudioUnitProperty_SampleRate;
247253
self.get_property(id, Scope::Input, Element::Output)
248254
}
249255

@@ -262,14 +268,14 @@ impl AudioUnit {
262268
/// > - Mac audio units and other audio processing: Noninterleaved linear PCM with 32-bit
263269
/// floating-point
264270
pub fn set_stream_format(&mut self, stream_format: StreamFormat) -> Result<(), Error> {
265-
let id = au::kAudioUnitProperty_StreamFormat;
271+
let id = sys::kAudioUnitProperty_StreamFormat;
266272
let asbd = stream_format.to_asbd();
267273
self.set_property(id, Scope::Input, Element::Output, Some(&asbd))
268274
}
269275

270276
/// Return the current Stream Format for the AudioUnit.
271277
pub fn stream_format(&self) -> Result<StreamFormat, Error> {
272-
let id = au::kAudioUnitProperty_StreamFormat;
278+
let id = sys::kAudioUnitProperty_StreamFormat;
273279
let asbd = try!(self.get_property(id, Scope::Output, Element::Output));
274280
StreamFormat::from_asbd(asbd)
275281
}
@@ -290,7 +296,7 @@ impl Drop for AudioUnit {
290296
// A user should explicitly terminate the `AudioUnit` if they want to handle errors (we
291297
// still need to provide a way to actually do that).
292298
self.stop().ok();
293-
error::Error::from_os_status(au::AudioUnitUninitialize(self.instance)).ok();
299+
error::Error::from_os_status(sys::AudioUnitUninitialize(self.instance)).ok();
294300

295301
self.free_render_callback();
296302
}

0 commit comments

Comments
 (0)