Merge pull request #13 from tomaka/update-rustc

Update for rust-1.0 alpha
This commit is contained in:
tomaka 2015-01-09 22:51:39 +01:00
commit 234ccfee63
5 changed files with 25 additions and 24 deletions

View File

@ -52,11 +52,11 @@ impl Voice {
::SampleFormat::U16 ::SampleFormat::U16
} }
pub fn append_data<'a, T>(&'a mut self, max_elements: uint) -> Buffer<'a, T> where T: Clone { pub fn append_data<'a, T>(&'a mut self, max_elements: usize) -> Buffer<'a, T> where T: Clone {
let available = unsafe { alsa::snd_pcm_avail(self.channel) }; let available = unsafe { alsa::snd_pcm_avail(self.channel) };
let available = available * self.num_channels as alsa::snd_pcm_sframes_t; let available = available * self.num_channels as alsa::snd_pcm_sframes_t;
let elements = ::std::cmp::min(available as uint, max_elements); let elements = ::std::cmp::min(available as usize, max_elements);
Buffer { Buffer {
channel: self, channel: self,
@ -91,7 +91,7 @@ impl<'a, T> Buffer<'a, T> {
} }
pub fn finish(self) { pub fn finish(self) {
let written = (self.buffer.len() / self.channel.num_channels as uint) as alsa::snd_pcm_uframes_t; let written = (self.buffer.len() / self.channel.num_channels as usize) as alsa::snd_pcm_uframes_t;
unsafe { unsafe {
let result = alsa::snd_pcm_writei(self.channel.channel, let result = alsa::snd_pcm_writei(self.channel.channel,

View File

@ -18,9 +18,9 @@ pub fn convert_samples_rate<T>(input: &[T], from: ::SamplesRate, to: ::SamplesRa
// then we simply skip some samples // then we simply skip some samples
if from % to == 0 { if from % to == 0 {
let mut result = Vec::new(); let mut result = Vec::new();
for element in input.chunks(channels as uint * (from / to) as uint) { for element in input.chunks(channels as usize * (from / to) as usize) {
for i in range(0, channels) { for i in range(0, channels) {
result.push(element[i as uint]); result.push(element[i as usize]);
} }
} }
return result; return result;
@ -31,7 +31,7 @@ pub fn convert_samples_rate<T>(input: &[T], from: ::SamplesRate, to: ::SamplesRa
if to == from * 2 { if to == from * 2 {
let mut result = Vec::new(); let mut result = Vec::new();
let mut previous: Option<Vec<T>> = None; let mut previous: Option<Vec<T>> = None;
for element in input.chunks(channels as uint) { for element in input.chunks(channels as usize) {
if let Some(previous) = previous.take() { if let Some(previous) = previous.take() {
for (prev, curr) in previous.into_iter().zip(element.iter()) { for (prev, curr) in previous.into_iter().zip(element.iter()) {
result.push(prev.interpolate(*curr)); result.push(prev.interpolate(*curr));
@ -68,20 +68,20 @@ pub fn convert_channels<T>(input: &[T], from: ::ChannelsCount, to: ::ChannelsCou
{ {
assert!(from != 0); assert!(from != 0);
assert!(to != 0); assert!(to != 0);
assert!(input.len() % from as uint == 0); assert!(input.len() % from as usize == 0);
let mut result = Vec::new(); let mut result = Vec::new();
for element in input.chunks(from as uint) { for element in input.chunks(from as usize) {
// copying the common channels // copying the common channels
for i in range(0, ::std::cmp::min(from, to)) { for i in range(0, ::std::cmp::min(from, to)) {
result.push(element[i as uint]); result.push(element[i as usize]);
} }
// adding extra ones // adding extra ones
if to > from { if to > from {
for i in range(0, to - from) { for i in range(0, to - from) {
result.push(element[i as uint % element.len()]); result.push(element[i as usize % element.len()]);
} }
} }
} }

View File

@ -47,6 +47,7 @@ a conversion on your data.
If you have the possibility, you should try to match the format of the voice. If you have the possibility, you should try to match the format of the voice.
*/ */
#![allow(unstable)]
#![feature(unsafe_destructor)] #![feature(unsafe_destructor)]
#![unstable] #![unstable]
@ -167,11 +168,11 @@ impl Voice {
/// Panics if `max_elements` is 0 or is not a multiple of `channels`. /// Panics if `max_elements` is 0 or is not a multiple of `channels`.
/// ///
pub fn append_data<'a, T>(&'a mut self, channels: ChannelsCount, pub fn append_data<'a, T>(&'a mut self, channels: ChannelsCount,
samples_rate: SamplesRate, max_elements: uint) samples_rate: SamplesRate, max_elements: usize)
-> Buffer<'a, T> where T: Sample + Clone -> Buffer<'a, T> where T: Sample + Clone
{ {
assert!(max_elements != 0); assert!(max_elements != 0);
assert!(max_elements % channels as uint == 0); assert!(max_elements % channels as usize == 0);
let target_samples_rate = self.0.get_samples_rate(); let target_samples_rate = self.0.get_samples_rate();
let target_channels = self.0.get_channels(); let target_channels = self.0.get_channels();
@ -183,9 +184,9 @@ impl Voice {
if samples_rate != target_samples_rate || channels != target_channels || if samples_rate != target_samples_rate || channels != target_channels ||
source_samples_format != target_samples_format source_samples_format != target_samples_format
{ {
let max_elements = max_elements * target_channels as uint / channels as uint; let max_elements = max_elements * target_channels as usize / channels as usize;
let max_elements = max_elements * target_samples_rate.0 as uint / let max_elements = max_elements * target_samples_rate.0 as usize /
samples_rate.0 as uint; samples_rate.0 as usize;
let max_elements = max_elements * target_samples_format.get_sample_size() / let max_elements = max_elements * target_samples_format.get_sample_size() /
source_samples_format.get_sample_size(); source_samples_format.get_sample_size();
@ -193,10 +194,10 @@ impl Voice {
// computing the length of the intermediary buffer // computing the length of the intermediary buffer
let intermediate_buffer_length = target_buffer.get_buffer().len(); let intermediate_buffer_length = target_buffer.get_buffer().len();
let intermediate_buffer_length = intermediate_buffer_length * channels as uint / let intermediate_buffer_length = intermediate_buffer_length * channels as usize /
target_channels as uint; target_channels as usize;
let intermediate_buffer_length = intermediate_buffer_length * samples_rate.0 as uint / let intermediate_buffer_length = intermediate_buffer_length * samples_rate.0 as usize /
target_samples_rate.0 as uint; target_samples_rate.0 as usize;
let intermediate_buffer_length = intermediate_buffer_length * let intermediate_buffer_length = intermediate_buffer_length *
source_samples_format.get_sample_size() / source_samples_format.get_sample_size() /
target_samples_format.get_sample_size(); target_samples_format.get_sample_size();

View File

@ -14,7 +14,7 @@ pub enum SampleFormat {
impl SampleFormat { impl SampleFormat {
/// Returns the size in bytes of a sample of this format. /// Returns the size in bytes of a sample of this format.
pub fn get_sample_size(&self) -> uint { pub fn get_sample_size(&self) -> usize {
match self { match self {
&SampleFormat::I16 => mem::size_of::<i16>(), &SampleFormat::I16 => mem::size_of::<i16>(),
&SampleFormat::U16 => mem::size_of::<u16>(), &SampleFormat::U16 => mem::size_of::<u16>(),

View File

@ -18,7 +18,7 @@ pub struct Voice {
pub struct Buffer<'a, T> { pub struct Buffer<'a, T> {
render_client: *mut winapi::IAudioRenderClient, render_client: *mut winapi::IAudioRenderClient,
buffer_data: *mut T, buffer_data: *mut T,
buffer_len: uint, buffer_len: usize,
frames: winapi::UINT32, frames: winapi::UINT32,
} }
@ -42,7 +42,7 @@ impl Voice {
} }
} }
pub fn append_data<'a, T>(&'a mut self, max_elements: uint) -> Buffer<'a, T> { pub fn append_data<'a, T>(&'a mut self, max_elements: usize) -> Buffer<'a, T> {
unsafe { unsafe {
loop { loop {
// //
@ -76,7 +76,7 @@ impl Voice {
assert!(!buffer.is_null()); assert!(!buffer.is_null());
(buffer as *mut T, (buffer as *mut T,
frames_available as uint * self.bytes_per_frame as uint frames_available as usize * self.bytes_per_frame as usize
/ mem::size_of::<T>()) / mem::size_of::<T>())
}; };
@ -263,7 +263,7 @@ fn init() -> Result<Voice, String> {
fn check_result(result: winapi::HRESULT) -> Result<(), String> { fn check_result(result: winapi::HRESULT) -> Result<(), String> {
if result < 0 { if result < 0 {
return Err(::std::os::error_string(result as uint)); // TODO: return Err(::std::os::error_string(result as usize)); // TODO:
} }
Ok(()) Ok(())