Merge pull request #13 from tomaka/update-rustc
Update for rust-1.0 alpha
This commit is contained in:
commit
234ccfee63
|
@ -52,11 +52,11 @@ impl Voice {
|
|||
::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 = 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 {
|
||||
channel: self,
|
||||
|
@ -91,7 +91,7 @@ impl<'a, T> Buffer<'a, T> {
|
|||
}
|
||||
|
||||
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 {
|
||||
let result = alsa::snd_pcm_writei(self.channel.channel,
|
||||
|
|
|
@ -18,9 +18,9 @@ pub fn convert_samples_rate<T>(input: &[T], from: ::SamplesRate, to: ::SamplesRa
|
|||
// then we simply skip some samples
|
||||
if from % to == 0 {
|
||||
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) {
|
||||
result.push(element[i as uint]);
|
||||
result.push(element[i as usize]);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
|
@ -31,7 +31,7 @@ pub fn convert_samples_rate<T>(input: &[T], from: ::SamplesRate, to: ::SamplesRa
|
|||
if to == from * 2 {
|
||||
let mut result = Vec::new();
|
||||
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() {
|
||||
for (prev, curr) in previous.into_iter().zip(element.iter()) {
|
||||
result.push(prev.interpolate(*curr));
|
||||
|
@ -68,20 +68,20 @@ pub fn convert_channels<T>(input: &[T], from: ::ChannelsCount, to: ::ChannelsCou
|
|||
{
|
||||
assert!(from != 0);
|
||||
assert!(to != 0);
|
||||
assert!(input.len() % from as uint == 0);
|
||||
assert!(input.len() % from as usize == 0);
|
||||
|
||||
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
|
||||
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
|
||||
if 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()]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
19
src/lib.rs
19
src/lib.rs
|
@ -47,6 +47,7 @@ a conversion on your data.
|
|||
If you have the possibility, you should try to match the format of the voice.
|
||||
|
||||
*/
|
||||
#![allow(unstable)]
|
||||
#![feature(unsafe_destructor)]
|
||||
#![unstable]
|
||||
|
||||
|
@ -167,11 +168,11 @@ impl Voice {
|
|||
/// Panics if `max_elements` is 0 or is not a multiple of `channels`.
|
||||
///
|
||||
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
|
||||
{
|
||||
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_channels = self.0.get_channels();
|
||||
|
@ -183,9 +184,9 @@ impl Voice {
|
|||
if samples_rate != target_samples_rate || channels != target_channels ||
|
||||
source_samples_format != target_samples_format
|
||||
{
|
||||
let max_elements = max_elements * target_channels as uint / channels as uint;
|
||||
let max_elements = max_elements * target_samples_rate.0 as uint /
|
||||
samples_rate.0 as uint;
|
||||
let max_elements = max_elements * target_channels as usize / channels as usize;
|
||||
let max_elements = max_elements * target_samples_rate.0 as usize /
|
||||
samples_rate.0 as usize;
|
||||
let max_elements = max_elements * target_samples_format.get_sample_size() /
|
||||
source_samples_format.get_sample_size();
|
||||
|
||||
|
@ -193,10 +194,10 @@ impl Voice {
|
|||
|
||||
// computing the length of the intermediary buffer
|
||||
let intermediate_buffer_length = target_buffer.get_buffer().len();
|
||||
let intermediate_buffer_length = intermediate_buffer_length * channels as uint /
|
||||
target_channels as uint;
|
||||
let intermediate_buffer_length = intermediate_buffer_length * samples_rate.0 as uint /
|
||||
target_samples_rate.0 as uint;
|
||||
let intermediate_buffer_length = intermediate_buffer_length * channels as usize /
|
||||
target_channels as usize;
|
||||
let intermediate_buffer_length = intermediate_buffer_length * samples_rate.0 as usize /
|
||||
target_samples_rate.0 as usize;
|
||||
let intermediate_buffer_length = intermediate_buffer_length *
|
||||
source_samples_format.get_sample_size() /
|
||||
target_samples_format.get_sample_size();
|
||||
|
|
|
@ -14,7 +14,7 @@ pub enum SampleFormat {
|
|||
|
||||
impl SampleFormat {
|
||||
/// 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 {
|
||||
&SampleFormat::I16 => mem::size_of::<i16>(),
|
||||
&SampleFormat::U16 => mem::size_of::<u16>(),
|
||||
|
|
|
@ -18,7 +18,7 @@ pub struct Voice {
|
|||
pub struct Buffer<'a, T> {
|
||||
render_client: *mut winapi::IAudioRenderClient,
|
||||
buffer_data: *mut T,
|
||||
buffer_len: uint,
|
||||
buffer_len: usize,
|
||||
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 {
|
||||
loop {
|
||||
//
|
||||
|
@ -76,7 +76,7 @@ impl Voice {
|
|||
assert!(!buffer.is_null());
|
||||
|
||||
(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>())
|
||||
};
|
||||
|
||||
|
@ -263,7 +263,7 @@ fn init() -> Result<Voice, String> {
|
|||
|
||||
fn check_result(result: winapi::HRESULT) -> Result<(), String> {
|
||||
if result < 0 {
|
||||
return Err(::std::os::error_string(result as uint)); // TODO:
|
||||
return Err(::std::os::error_string(result as usize)); // TODO:
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
|
Loading…
Reference in New Issue