From 28bd3686583ffd7e337f7be9b73057599eafb341 Mon Sep 17 00:00:00 2001 From: Pierre Krieger Date: Sun, 22 Feb 2015 10:31:25 +0100 Subject: [PATCH] Update for rustc --- src/alsa/mod.rs | 2 +- src/lib.rs | 4 ++-- src/samples_formats.rs | 26 +++++++++++++------------- src/wasapi/mod.rs | 5 ++++- 4 files changed, 20 insertions(+), 17 deletions(-) diff --git a/src/alsa/mod.rs b/src/alsa/mod.rs index e0ecf2c..f086e8e 100644 --- a/src/alsa/mod.rs +++ b/src/alsa/mod.rs @@ -19,7 +19,7 @@ impl Voice { let name = ffi::CString::from_slice(b"default"); let mut playback_handle = mem::uninitialized(); - check_errors(alsa::snd_pcm_open(&mut playback_handle, name.as_slice_with_nul().as_ptr(), alsa::SND_PCM_STREAM_PLAYBACK, alsa::SND_PCM_NONBLOCK)).unwrap(); + check_errors(alsa::snd_pcm_open(&mut playback_handle, name.as_ptr(), alsa::SND_PCM_STREAM_PLAYBACK, alsa::SND_PCM_NONBLOCK)).unwrap(); let mut hw_params = mem::uninitialized(); check_errors(alsa::snd_pcm_hw_params_malloc(&mut hw_params)).unwrap(); diff --git a/src/lib.rs b/src/lib.rs index adb57a3..b1ea444 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -87,7 +87,7 @@ pub struct Voice(cpal_impl::Voice); pub type ChannelsCount = u16; /// -#[derive(Show, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)] pub struct SamplesRate(pub u32); /// Represents a buffer that must be filled with audio data. @@ -95,7 +95,7 @@ pub struct SamplesRate(pub u32); /// You should destroy this object as soon as possible. Data is only committed when it /// is destroyed. #[must_use] -pub struct Buffer<'a, T> { +pub struct Buffer<'a, T: 'a> { // also contains something, taken by `Drop` target: Option>, diff --git a/src/samples_formats.rs b/src/samples_formats.rs index 510129c..4209e90 100644 --- a/src/samples_formats.rs +++ b/src/samples_formats.rs @@ -2,7 +2,7 @@ use std::borrow::Cow; use std::mem; /// Format that each sample has. -#[derive(Clone, Copy, Show, PartialEq, Eq)] +#[derive(Clone, Copy, Debug, PartialEq, Eq)] pub enum SampleFormat { /// The value 0 corresponds to 0. I16, @@ -32,11 +32,11 @@ pub trait Sample: Copy + Clone { fn interpolate(self, other: Self) -> Self; /// Turns the data into samples of type `I16`. - fn to_vec_i16(&[Self]) -> Cow, [i16]>; + fn to_vec_i16(&[Self]) -> Cow<[i16]>; /// Turns the data into samples of type `U16`. - fn to_vec_u16(&[Self]) -> Cow, [u16]>; + fn to_vec_u16(&[Self]) -> Cow<[u16]>; /// Turns the data into samples of type `F32`. - fn to_vec_f32(&[Self]) -> Cow, [f32]>; + fn to_vec_f32(&[Self]) -> Cow<[f32]>; } impl Sample for u16 { @@ -48,7 +48,7 @@ impl Sample for u16 { (self + other) / 2 } - fn to_vec_i16(input: &[u16]) -> Cow, [i16]> { + fn to_vec_i16(input: &[u16]) -> Cow<[i16]> { Cow::Owned(input.iter().map(|&value| { if value >= 32768 { (value - 32768) as i16 @@ -58,11 +58,11 @@ impl Sample for u16 { }).collect()) } - fn to_vec_u16(input: &[u16]) -> Cow, [u16]> { + fn to_vec_u16(input: &[u16]) -> Cow<[u16]> { Cow::Borrowed(input) } - fn to_vec_f32(input: &[u16]) -> Cow, [f32]> { + fn to_vec_f32(input: &[u16]) -> Cow<[f32]> { Cow::Owned(Sample::to_vec_f32(Sample::to_vec_i16(input).as_slice()).to_vec()) } } @@ -76,11 +76,11 @@ impl Sample for i16 { (self + other) / 2 } - fn to_vec_i16(input: &[i16]) -> Cow, [i16]> { + fn to_vec_i16(input: &[i16]) -> Cow<[i16]> { Cow::Borrowed(input) } - fn to_vec_u16(input: &[i16]) -> Cow, [u16]> { + fn to_vec_u16(input: &[i16]) -> Cow<[u16]> { Cow::Owned(input.iter().map(|&value| { if value < 0 { (value + 32767) as u16 + 1 @@ -90,7 +90,7 @@ impl Sample for i16 { }).collect()) } - fn to_vec_f32(input: &[i16]) -> Cow, [f32]> { + fn to_vec_f32(input: &[i16]) -> Cow<[f32]> { Cow::Owned(input.iter().map(|&value| { if value > 0 { value as f32 / 32767.0 @@ -110,7 +110,7 @@ impl Sample for f32 { (self + other) / 2.0 } - fn to_vec_i16(input: &[f32]) -> Cow, [i16]> { + fn to_vec_i16(input: &[f32]) -> Cow<[i16]> { Cow::Owned(input.iter().map(|&value| { if value >= 0.0 { (value * 32767.0) as i16 @@ -120,7 +120,7 @@ impl Sample for f32 { }).collect()) } - fn to_vec_u16(input: &[f32]) -> Cow, [u16]> { + fn to_vec_u16(input: &[f32]) -> Cow<[u16]> { Cow::Owned(input.iter().map(|&value| { if value >= 0.0 { ((value * 32767.0) + 32768.0) as u16 @@ -130,7 +130,7 @@ impl Sample for f32 { }).collect()) } - fn to_vec_f32(input: &[f32]) -> Cow, [f32]> { + fn to_vec_f32(input: &[f32]) -> Cow<[f32]> { Cow::Borrowed(input) } } diff --git a/src/wasapi/mod.rs b/src/wasapi/mod.rs index 3810eef..8eab473 100644 --- a/src/wasapi/mod.rs +++ b/src/wasapi/mod.rs @@ -3,6 +3,7 @@ extern crate winapi; extern crate "ole32-sys" as ole32; use std::{slice, mem, ptr}; +use std::marker::PhantomData; // TODO: determine if should be NoSend or not pub struct Voice { @@ -16,11 +17,12 @@ pub struct Voice { playing: bool, } -pub struct Buffer<'a, T> { +pub struct Buffer<'a, T: 'a> { render_client: *mut winapi::IAudioRenderClient, buffer_data: *mut T, buffer_len: usize, frames: winapi::UINT32, + marker: PhantomData<&'a mut T>, } impl Voice { @@ -86,6 +88,7 @@ impl Voice { buffer_data: buffer_data, buffer_len: buffer_len, frames: frames_available, + marker: PhantomData, }; return buffer;