diff --git a/Cargo.toml b/Cargo.toml index af25193..c37368a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "cpal" -version = "0.0.13" +version = "0.0.15" authors = ["Pierre Krieger "] description = "Cross-platform audio playing library in pure Rust." repository = "https://github.com/tomaka/cpal" 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 6d597dc..80157cc 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -99,7 +99,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 a73f7c1..4209e90 100644 --- a/src/samples_formats.rs +++ b/src/samples_formats.rs @@ -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 538cf67..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; @@ -140,7 +143,7 @@ impl Drop for Voice { impl<'a, T> Buffer<'a, T> { pub fn get_buffer<'b>(&'b mut self) -> &'b mut [T] { unsafe { - slice::from_raw_mut_buf(&self.buffer_data, self.buffer_len) + slice::from_raw_parts_mut(self.buffer_data, self.buffer_len) } } @@ -264,7 +267,7 @@ fn init() -> Result { fn check_result(result: winapi::HRESULT) -> Result<(), String> { if result < 0 { - return Err(::std::os::error_string(result as usize)); // TODO: + return Err(::std::os::error_string(result)); // TODO: } Ok(())