Update for rustc

This commit is contained in:
Pierre Krieger 2015-02-22 10:31:25 +01:00
parent ff63e283d5
commit 28bd368658
4 changed files with 20 additions and 17 deletions

View File

@ -19,7 +19,7 @@ impl Voice {
let name = ffi::CString::from_slice(b"default"); let name = ffi::CString::from_slice(b"default");
let mut playback_handle = mem::uninitialized(); 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(); let mut hw_params = mem::uninitialized();
check_errors(alsa::snd_pcm_hw_params_malloc(&mut hw_params)).unwrap(); check_errors(alsa::snd_pcm_hw_params_malloc(&mut hw_params)).unwrap();

View File

@ -87,7 +87,7 @@ pub struct Voice(cpal_impl::Voice);
pub type ChannelsCount = u16; 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); pub struct SamplesRate(pub u32);
/// Represents a buffer that must be filled with audio data. /// 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 /// You should destroy this object as soon as possible. Data is only committed when it
/// is destroyed. /// is destroyed.
#[must_use] #[must_use]
pub struct Buffer<'a, T> { pub struct Buffer<'a, T: 'a> {
// also contains something, taken by `Drop` // also contains something, taken by `Drop`
target: Option<cpal_impl::Buffer<'a, T>>, target: Option<cpal_impl::Buffer<'a, T>>,

View File

@ -2,7 +2,7 @@ use std::borrow::Cow;
use std::mem; use std::mem;
/// Format that each sample has. /// Format that each sample has.
#[derive(Clone, Copy, Show, PartialEq, Eq)] #[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum SampleFormat { pub enum SampleFormat {
/// The value 0 corresponds to 0. /// The value 0 corresponds to 0.
I16, I16,
@ -32,11 +32,11 @@ pub trait Sample: Copy + Clone {
fn interpolate(self, other: Self) -> Self; fn interpolate(self, other: Self) -> Self;
/// Turns the data into samples of type `I16`. /// Turns the data into samples of type `I16`.
fn to_vec_i16(&[Self]) -> Cow<Vec<i16>, [i16]>; fn to_vec_i16(&[Self]) -> Cow<[i16]>;
/// Turns the data into samples of type `U16`. /// Turns the data into samples of type `U16`.
fn to_vec_u16(&[Self]) -> Cow<Vec<u16>, [u16]>; fn to_vec_u16(&[Self]) -> Cow<[u16]>;
/// Turns the data into samples of type `F32`. /// Turns the data into samples of type `F32`.
fn to_vec_f32(&[Self]) -> Cow<Vec<f32>, [f32]>; fn to_vec_f32(&[Self]) -> Cow<[f32]>;
} }
impl Sample for u16 { impl Sample for u16 {
@ -48,7 +48,7 @@ impl Sample for u16 {
(self + other) / 2 (self + other) / 2
} }
fn to_vec_i16(input: &[u16]) -> Cow<Vec<i16>, [i16]> { fn to_vec_i16(input: &[u16]) -> Cow<[i16]> {
Cow::Owned(input.iter().map(|&value| { Cow::Owned(input.iter().map(|&value| {
if value >= 32768 { if value >= 32768 {
(value - 32768) as i16 (value - 32768) as i16
@ -58,11 +58,11 @@ impl Sample for u16 {
}).collect()) }).collect())
} }
fn to_vec_u16(input: &[u16]) -> Cow<Vec<u16>, [u16]> { fn to_vec_u16(input: &[u16]) -> Cow<[u16]> {
Cow::Borrowed(input) Cow::Borrowed(input)
} }
fn to_vec_f32(input: &[u16]) -> Cow<Vec<f32>, [f32]> { fn to_vec_f32(input: &[u16]) -> Cow<[f32]> {
Cow::Owned(Sample::to_vec_f32(Sample::to_vec_i16(input).as_slice()).to_vec()) 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 (self + other) / 2
} }
fn to_vec_i16(input: &[i16]) -> Cow<Vec<i16>, [i16]> { fn to_vec_i16(input: &[i16]) -> Cow<[i16]> {
Cow::Borrowed(input) Cow::Borrowed(input)
} }
fn to_vec_u16(input: &[i16]) -> Cow<Vec<u16>, [u16]> { fn to_vec_u16(input: &[i16]) -> Cow<[u16]> {
Cow::Owned(input.iter().map(|&value| { Cow::Owned(input.iter().map(|&value| {
if value < 0 { if value < 0 {
(value + 32767) as u16 + 1 (value + 32767) as u16 + 1
@ -90,7 +90,7 @@ impl Sample for i16 {
}).collect()) }).collect())
} }
fn to_vec_f32(input: &[i16]) -> Cow<Vec<f32>, [f32]> { fn to_vec_f32(input: &[i16]) -> Cow<[f32]> {
Cow::Owned(input.iter().map(|&value| { Cow::Owned(input.iter().map(|&value| {
if value > 0 { if value > 0 {
value as f32 / 32767.0 value as f32 / 32767.0
@ -110,7 +110,7 @@ impl Sample for f32 {
(self + other) / 2.0 (self + other) / 2.0
} }
fn to_vec_i16(input: &[f32]) -> Cow<Vec<i16>, [i16]> { fn to_vec_i16(input: &[f32]) -> Cow<[i16]> {
Cow::Owned(input.iter().map(|&value| { Cow::Owned(input.iter().map(|&value| {
if value >= 0.0 { if value >= 0.0 {
(value * 32767.0) as i16 (value * 32767.0) as i16
@ -120,7 +120,7 @@ impl Sample for f32 {
}).collect()) }).collect())
} }
fn to_vec_u16(input: &[f32]) -> Cow<Vec<u16>, [u16]> { fn to_vec_u16(input: &[f32]) -> Cow<[u16]> {
Cow::Owned(input.iter().map(|&value| { Cow::Owned(input.iter().map(|&value| {
if value >= 0.0 { if value >= 0.0 {
((value * 32767.0) + 32768.0) as u16 ((value * 32767.0) + 32768.0) as u16
@ -130,7 +130,7 @@ impl Sample for f32 {
}).collect()) }).collect())
} }
fn to_vec_f32(input: &[f32]) -> Cow<Vec<f32>, [f32]> { fn to_vec_f32(input: &[f32]) -> Cow<[f32]> {
Cow::Borrowed(input) Cow::Borrowed(input)
} }
} }

View File

@ -3,6 +3,7 @@ extern crate winapi;
extern crate "ole32-sys" as ole32; extern crate "ole32-sys" as ole32;
use std::{slice, mem, ptr}; use std::{slice, mem, ptr};
use std::marker::PhantomData;
// TODO: determine if should be NoSend or not // TODO: determine if should be NoSend or not
pub struct Voice { pub struct Voice {
@ -16,11 +17,12 @@ pub struct Voice {
playing: bool, playing: bool,
} }
pub struct Buffer<'a, T> { pub struct Buffer<'a, T: 'a> {
render_client: *mut winapi::IAudioRenderClient, render_client: *mut winapi::IAudioRenderClient,
buffer_data: *mut T, buffer_data: *mut T,
buffer_len: usize, buffer_len: usize,
frames: winapi::UINT32, frames: winapi::UINT32,
marker: PhantomData<&'a mut T>,
} }
impl Voice { impl Voice {
@ -86,6 +88,7 @@ impl Voice {
buffer_data: buffer_data, buffer_data: buffer_data,
buffer_len: buffer_len, buffer_len: buffer_len,
frames: frames_available, frames: frames_available,
marker: PhantomData,
}; };
return buffer; return buffer;