Skip to content

Commit fa334c1

Browse files
committed
Update to Rust master.
1 parent bc15023 commit fa334c1

File tree

4 files changed

+103
-118
lines changed

4 files changed

+103
-118
lines changed

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
[package]
33
name = "ao"
4-
version = "0.3.0"
4+
version = "0.4.0"
55
authors = [ "[email protected]" ]
66
license = "BSD-2-Clause"
77

README.md

+2-31
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Build with `cargo`:
1111

1212
Build documentation with `rustdoc`, rooted at `doc/ao/index.html`:
1313

14-
rustdoc src/lib.rs
14+
cargo doc
1515

1616
Run tests. Tests must not be run in parallel because libao may only be
1717
instantiated once in a given _process_. Running tests concurrently
@@ -20,33 +20,4 @@ test failure:
2020

2121
REST_TEST_TASKS=1 cargo test
2222

23-
Write programs:
24-
25-
extern crate ao;
26-
27-
use ao::{AO, SampleFormat, Native, Device, DriverName};
28-
use std::num::FloatMath;
29-
30-
fn main() {
31-
let lib = AO::init();
32-
let format: SampleFormat<i16> = SampleFormat {
33-
sample_rate: 44100,
34-
channels: 1,
35-
byte_order: Native,
36-
matrix: None
37-
};
38-
let device = Device::file(&lib, DriverName("wav"), &format,
39-
&Path::new("out.wav"), false);
40-
match device {
41-
Ok(d) => {
42-
let samples = Vec::<i16>::from_fn(44100, |i| {
43-
((1.0 / 44100.0 / 440.0 * i as f32).sin() * 32767.0) as i16
44-
});
45-
d.play(samples.as_slice());
46-
}
47-
Err(e) => {
48-
println!("Failed to open output file: {}", e);
49-
}
50-
}
51-
}
52-
23+
Examples are included in the documentation.

src/auto.rs

+19-18
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,15 @@
88
//! ```
99
//! use ao::AO;
1010
//! use ao::auto::{SampleBuffer, AutoFormatDevice};
11+
//! use std::error::Error;
1112
//!
1213
//! struct Stereo(u16, u16);
1314
//!
14-
//! impl<'a> SampleBuffer for &'a [Stereo] {
15-
//! fn channels(&self) -> uint { 2 }
16-
//! fn sample_rate(&self) -> uint { 44100 }
15+
//! impl<'z> SampleBuffer for &'z [Stereo] {
16+
//! fn channels(&self) -> usize { 2 }
17+
//! fn sample_rate(&self) -> usize { 44100 }
1718
//! fn endianness(&self) -> ao::Endianness { ao::Endianness::Native }
18-
//! fn sample_width(&self) -> uint { 16 }
19+
//! fn sample_width(&self) -> usize { 16 }
1920
//! fn data<'a>(&self) -> &'a [u8] {
2021
//! unsafe {
2122
//! ::std::mem::transmute(::std::raw::Slice {
@@ -34,29 +35,29 @@
3435
//! let data = vec![Stereo(16383, -16383)];
3536
//! match device.play(&data.as_slice()) {
3637
//! Ok(_) => (),
37-
//! Err(e) => println!("Playback failed: {}", e)
38+
//! Err(e) => println!("Playback failed: {}", e.description())
3839
//! }
3940
//! }
4041
//! ```
4142
4243
use super::{AoResult, Device, Driver, Sample, SampleFormat};
4344
use super::Endianness;
44-
use std::kinds::marker::InvariantType;
45+
use std::marker::InvariantType;
4546
use std::mem;
4647

4748
/// A buffer containing samples.
4849
///
4950
/// Such buffer always has a defined number of channels and sample rate, in addition to the
5051
/// parameters normally provided in a `SampleFormat` specification.
51-
pub trait SampleBuffer for Sized? {
52+
pub trait SampleBuffer {
5253
/// Number of channels in this buffer.
53-
fn channels(&self) -> uint;
54+
fn channels(&self) -> usize;
5455
/// Sample rate of this buffer, in Hz.
55-
fn sample_rate(&self) -> uint;
56+
fn sample_rate(&self) -> usize;
5657
/// Endianness of samples in this buffer.
5758
fn endianness(&self) -> Endianness;
5859
/// Bit width of samples in this buffer.
59-
fn sample_width(&self) -> uint;
60+
fn sample_width(&self) -> usize;
6061
/// Provides access to the sample data.
6162
///
6263
/// No processing is performed on this data; it is passed straight through to the underlying
@@ -71,19 +72,19 @@ enum DeviceFormat<'a> {
7172
}
7273

7374
impl<'a> DeviceFormat<'a> {
74-
fn sample_width(&self) -> uint {
75+
fn sample_width(&self) -> usize {
7576
match *self {
7677
DeviceFormat::Integer8(_) => 8,
7778
DeviceFormat::Integer16(_) => 16,
7879
DeviceFormat::Integer32(_) => 32,
7980
}
8081
}
8182

82-
fn new(driver: &Driver<'a>, width: uint,
83-
rate: uint, channels: uint, endianness: Endianness,
83+
fn new(driver: &Driver<'a>, width: usize,
84+
rate: usize, channels: usize, endianness: Endianness,
8485
matrix: Option<&str>) -> AoResult<DeviceFormat<'a>> {
8586

86-
fn build_format<S: Sample>(rate: uint, channels: uint, order: Endianness,
87+
fn build_format<S: Sample>(rate: usize, channels: usize, order: Endianness,
8788
matrix: Option<&str>) -> SampleFormat<S, &str> {
8889
SampleFormat {
8990
sample_rate: rate,
@@ -117,8 +118,8 @@ impl<'a> DeviceFormat<'a> {
117118
/// This device adapter can automatically manage the underlying `Device` to ensure it always has
118119
/// the correct sample format, so the format of incoming samples may change at runtime.
119120
pub struct AutoFormatDevice<'a, S> {
120-
channels: uint,
121-
sample_rate: uint,
121+
channels: usize,
122+
sample_rate: usize,
122123
endianness: Endianness,
123124
device: Option<DeviceFormat<'a>>,
124125
driver: Driver<'a>,
@@ -196,13 +197,13 @@ impl<'a, S: Str> AutoFormatDevice<'a, S> {
196197
Ok(())
197198
}
198199

199-
fn open_device(&self, width: uint, rate: uint, channels: uint,
200+
fn open_device(&self, width: usize, rate: usize, channels: usize,
200201
endianness: Endianness) -> AoResult<DeviceFormat<'a>> {
201202
DeviceFormat::new(&self.driver, width, rate, channels, endianness,
202203
self.matrix_for(channels))
203204
}
204205

205-
fn matrix_for(&self, nchannels: uint) -> Option<&str> {
206+
fn matrix_for(&self, nchannels: usize) -> Option<&str> {
206207
if self.matrixes.len() <= nchannels {
207208
None
208209
} else {

0 commit comments

Comments
 (0)