This commit is contained in:
Pierre Krieger 2015-03-25 11:21:10 +01:00
parent f7c2949549
commit 84326cb4a7
6 changed files with 12 additions and 14 deletions

View File

@ -1,7 +1,7 @@
[package] [package]
name = "cpal" name = "cpal"
version = "0.0.15" version = "0.0.16"
authors = ["Pierre Krieger <pierre.krieger1708@gmail.com>"] authors = ["Pierre Krieger <pierre.krieger1708@gmail.com>"]
description = "Cross-platform audio playing library in pure Rust." description = "Cross-platform audio playing library in pure Rust."
repository = "https://github.com/tomaka/cpal" repository = "https://github.com/tomaka/cpal"

View File

@ -1,7 +1,7 @@
[package] [package]
name = "alsa-sys" name = "alsa-sys"
version = "0.0.4" version = "0.0.5"
authors = ["Pierre Krieger <pierre.krieger1708@gmail.com>"] authors = ["Pierre Krieger <pierre.krieger1708@gmail.com>"]
build = "build.rs" build = "build.rs"
description = "Bindings for the ALSA project (Advanced Linux Sound Architecture)" description = "Bindings for the ALSA project (Advanced Linux Sound Architecture)"
@ -11,4 +11,4 @@ license = "MIT"
libc = "*" libc = "*"
[build-dependencies] [build-dependencies]
pkg-config = "^0.1.1" pkg-config = "0.3"

View File

@ -1,15 +1,13 @@
#![feature(core, old_io)]
extern crate cpal; extern crate cpal;
extern crate vorbis; extern crate vorbis;
use std::old_io::BufReader; use std::io::Cursor;
fn main() { fn main() {
let mut channel = cpal::Voice::new(); let mut channel = cpal::Voice::new();
channel.play(); channel.play();
let mut decoder = vorbis::Decoder::new(BufReader::new(include_bytes!("music.ogg"))) let mut decoder = vorbis::Decoder::new(Cursor::new(&include_bytes!("music.ogg")[..]))
.unwrap(); .unwrap();
'main: for packet in decoder.packets() { 'main: for packet in decoder.packets() {

View File

@ -19,7 +19,7 @@ pub fn convert_samples_rate<T>(input: &[T], from: ::SamplesRate, to: ::SamplesRa
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 usize * (from / to) as usize) { for element in input.chunks(channels as usize * (from / to) as usize) {
for i in range(0, channels) { for i in (0 .. channels) {
result.push(element[i as usize]); result.push(element[i as usize]);
} }
} }
@ -74,13 +74,13 @@ pub fn convert_channels<T>(input: &[T], from: ::ChannelsCount, to: ::ChannelsCou
for element in input.chunks(from as usize) { 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 (0 .. ::std::cmp::min(from, to)) {
result.push(element[i as usize]); 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 (0 .. to - from) {
result.push(element[i as usize % element.len()]); result.push(element[i as usize % element.len()]);
} }
} }
@ -113,7 +113,7 @@ mod test {
} }
#[test] #[test]
#[should_fail] #[should_panic]
fn convert_channels_wrong_data_len() { fn convert_channels_wrong_data_len() {
convert_channels(&[1u16, 2, 3], 2, 1); convert_channels(&[1u16, 2, 3], 2, 1);
} }

View File

@ -83,7 +83,7 @@ impl Sample for i16 {
fn to_vec_u16(input: &[i16]) -> Cow<[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 + 1) as u16
} else { } else {
(value as u16) + 32768 (value as u16) + 32768
} }

View File

@ -60,7 +60,7 @@ impl Voice {
if frames_available == 0 { if frames_available == 0 {
// TODO: // TODO:
::std::old_io::timer::sleep(::std::time::duration::Duration::milliseconds(1)); ::std::thread::sleep(::std::time::duration::Duration::milliseconds(1));
continue; continue;
} }
@ -267,7 +267,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)); // TODO: return Err(format!("Error in winapi call")); // TODO:
} }
Ok(()) Ok(())