Skip to content

Commit d4e7b01

Browse files
committed
Remove unnecessary lifetimes. Fix deprecation warnings.
1 parent 18e607f commit d4e7b01

File tree

4 files changed

+25
-27
lines changed

4 files changed

+25
-27
lines changed

examples/sine.rs

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -39,22 +39,20 @@ fn run() -> Result<(), coreaudio::Error> {
3939
// For this example, our sine wave expects `f32` data.
4040
assert!(SampleFormat::F32 == stream_format.sample_format);
4141

42-
try!(audio_unit.set_render_callback(move |args| callback(args, &mut samples)));
42+
type Args = render_callback::Args<data::NonInterleaved<f32>>;
43+
try!(audio_unit.set_render_callback(move |args| {
44+
let Args { num_frames, mut data, .. } = args;
45+
for i in 0..num_frames {
46+
let sample = samples.next().unwrap();
47+
for channel in data.channels_mut() {
48+
channel[i] = sample;
49+
}
50+
}
51+
Ok(())
52+
}));
4353
try!(audio_unit.start());
4454

45-
std::thread::sleep_ms(3000);
46-
47-
Ok(())
48-
}
55+
std::thread::sleep(std::time::Duration::from_millis(3000));
4956

50-
type Args<'a> = render_callback::Args<'a, data::NonInterleaved<'a, f32>>;
51-
fn callback<'a, I: Iterator<Item=f32>>(args: Args<'a>, samples: &mut I) -> Result<(), ()> {
52-
let Args { num_frames, mut data, .. } = args;
53-
for i in 0..num_frames {
54-
let sample = samples.next().unwrap();
55-
for channel in data.channels_mut() {
56-
channel[i] = sample;
57-
}
58-
}
5957
Ok(())
6058
}

src/audio_unit/mod.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,11 +277,13 @@ impl AudioUnit {
277277
}
278278

279279

280+
unsafe impl Send for AudioUnit {}
281+
282+
280283
impl Drop for AudioUnit {
281284
fn drop(&mut self) {
282285
unsafe {
283286
use error;
284-
use std::error::Error;
285287

286288
// We don't want to panic in `drop`, so we'll ignore returned errors.
287289
//

src/audio_unit/render_callback.rs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use bindings::audio_unit as au;
22
use error::{self, Error};
33
use libc;
4-
use std::marker::PhantomData;
54
use super::{AudioUnit, Element, Scope};
65

76
pub use self::action_flags::ActionFlags;
@@ -26,7 +25,7 @@ pub struct InputProcFnWrapper {
2625

2726
/// Arguments given to the render callback function.
2827
#[derive(Copy, Clone)]
29-
pub struct Args<'a, D> {
28+
pub struct Args<D> {
3029
/// A type wrapping the the buffer that matches the expected audio format.
3130
pub data: D,
3231
/// Timing information for the callback.
@@ -41,7 +40,6 @@ pub struct Args<'a, D> {
4140
pub bus_number: u32,
4241
/// The number of frames in the buffer as `usize` for easier indexing.
4342
pub num_frames: usize,
44-
callback_lifetime: PhantomData<&'a ()>,
4543
}
4644

4745
/// Format specific render callback data.
@@ -120,7 +118,7 @@ pub mod data {
120118
// }
121119

122120
/// A wrapper around the pointer to the `mBuffers` array.
123-
pub struct NonInterleaved<'a, S: 'a> {
121+
pub struct NonInterleaved<S> {
124122
/// A pointer to the first buffer.
125123
///
126124
/// TODO: Work out why this works and `&'a mut [au::AudioBuffer]` does not!
@@ -129,7 +127,7 @@ pub mod data {
129127
num_buffers: usize,
130128
/// The number of frames in each channel.
131129
frames: usize,
132-
sample_format: PhantomData<&'a S>,
130+
sample_format: PhantomData<S>,
133131
}
134132

135133
/// An iterator produced by a `NoneInterleaved`, yielding a reference to each channel.
@@ -146,6 +144,8 @@ pub mod data {
146144
sample_format: PhantomData<S>,
147145
}
148146

147+
unsafe impl<S> Send for NonInterleaved<S> where S: Send {}
148+
149149
impl<'a, S> Iterator for Channels<'a, S> {
150150
type Item = &'a [S];
151151
#[allow(non_snake_case)]
@@ -170,7 +170,7 @@ pub mod data {
170170
}
171171
}
172172

173-
impl<'a, S> NonInterleaved<'a, S> {
173+
impl<S> NonInterleaved<S> {
174174

175175
/// An iterator yielding a reference to each channel in the array.
176176
pub fn channels(&self) -> Channels<S> {
@@ -193,11 +193,11 @@ pub mod data {
193193
}
194194

195195
// Implementation for a non-interleaved linear PCM audio format.
196-
impl<'a, S> Data for NonInterleaved<'a, S>
196+
impl<S> Data for NonInterleaved<S>
197197
where S: Sample,
198198
{
199199
fn does_stream_format_match(format: &StreamFormat) -> bool {
200-
// TODO: This is never set, in though the default ABSD on OS X is non-interleaved!
200+
// TODO: This is never set, even though the default ABSD on OS X is non-interleaved!
201201
// Should really investigate why this is.
202202
// format.flags.contains(linear_pcm_flags::IS_NON_INTERLEAVED) &&
203203
S::sample_format().does_match_flags(format.flags)
@@ -303,7 +303,7 @@ impl AudioUnit {
303303

304304
/// Pass a render callback (aka "Input Procedure") to the **AudioUnit**.
305305
pub fn set_render_callback<F, D>(&mut self, mut f: F) -> Result<(), Error>
306-
where F: for<'a> FnMut(Args<'a, D>) -> Result<(), ()> + 'static,
306+
where F: FnMut(Args<D>) -> Result<(), ()> + 'static,
307307
D: Data,
308308
{
309309
// First, we'll retrieve the stream format so that we can ensure that the given callback
@@ -336,7 +336,6 @@ impl AudioUnit {
336336
flags: flags,
337337
bus_number: in_bus_number as u32,
338338
num_frames: in_number_frames as usize,
339-
callback_lifetime: PhantomData,
340339
}
341340
};
342341

src/lib.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@
99
//! eventually we'd like to cover at least the majority of the C API.
1010
1111
#[macro_use] extern crate bitflags;
12-
extern crate coreaudio_sys;
13-
pub use coreaudio_sys as bindings;
12+
pub extern crate coreaudio_sys as bindings;
1413

1514
extern crate libc;
1615

0 commit comments

Comments
 (0)