8
8
//! ```
9
9
//! use ao::AO;
10
10
//! use ao::auto::{SampleBuffer, AutoFormatDevice};
11
+ //! use std::error::Error;
11
12
//!
12
13
//! struct Stereo(u16, u16);
13
14
//!
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 }
17
18
//! fn endianness(&self) -> ao::Endianness { ao::Endianness::Native }
18
- //! fn sample_width(&self) -> uint { 16 }
19
+ //! fn sample_width(&self) -> usize { 16 }
19
20
//! fn data<'a>(&self) -> &'a [u8] {
20
21
//! unsafe {
21
22
//! ::std::mem::transmute(::std::raw::Slice {
34
35
//! let data = vec![Stereo(16383, -16383)];
35
36
//! match device.play(&data.as_slice()) {
36
37
//! Ok(_) => (),
37
- //! Err(e) => println!("Playback failed: {}", e)
38
+ //! Err(e) => println!("Playback failed: {}", e.description() )
38
39
//! }
39
40
//! }
40
41
//! ```
41
42
42
43
use super :: { AoResult , Device , Driver , Sample , SampleFormat } ;
43
44
use super :: Endianness ;
44
- use std:: kinds :: marker:: InvariantType ;
45
+ use std:: marker:: InvariantType ;
45
46
use std:: mem;
46
47
47
48
/// A buffer containing samples.
48
49
///
49
50
/// Such buffer always has a defined number of channels and sample rate, in addition to the
50
51
/// parameters normally provided in a `SampleFormat` specification.
51
- pub trait SampleBuffer for Sized ? {
52
+ pub trait SampleBuffer {
52
53
/// Number of channels in this buffer.
53
- fn channels ( & self ) -> uint ;
54
+ fn channels ( & self ) -> usize ;
54
55
/// Sample rate of this buffer, in Hz.
55
- fn sample_rate ( & self ) -> uint ;
56
+ fn sample_rate ( & self ) -> usize ;
56
57
/// Endianness of samples in this buffer.
57
58
fn endianness ( & self ) -> Endianness ;
58
59
/// Bit width of samples in this buffer.
59
- fn sample_width ( & self ) -> uint ;
60
+ fn sample_width ( & self ) -> usize ;
60
61
/// Provides access to the sample data.
61
62
///
62
63
/// No processing is performed on this data; it is passed straight through to the underlying
@@ -71,19 +72,19 @@ enum DeviceFormat<'a> {
71
72
}
72
73
73
74
impl < ' a > DeviceFormat < ' a > {
74
- fn sample_width ( & self ) -> uint {
75
+ fn sample_width ( & self ) -> usize {
75
76
match * self {
76
77
DeviceFormat :: Integer8 ( _) => 8 ,
77
78
DeviceFormat :: Integer16 ( _) => 16 ,
78
79
DeviceFormat :: Integer32 ( _) => 32 ,
79
80
}
80
81
}
81
82
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 ,
84
85
matrix : Option < & str > ) -> AoResult < DeviceFormat < ' a > > {
85
86
86
- fn build_format < S : Sample > ( rate : uint , channels : uint , order : Endianness ,
87
+ fn build_format < S : Sample > ( rate : usize , channels : usize , order : Endianness ,
87
88
matrix : Option < & str > ) -> SampleFormat < S , & str > {
88
89
SampleFormat {
89
90
sample_rate : rate,
@@ -117,8 +118,8 @@ impl<'a> DeviceFormat<'a> {
117
118
/// This device adapter can automatically manage the underlying `Device` to ensure it always has
118
119
/// the correct sample format, so the format of incoming samples may change at runtime.
119
120
pub struct AutoFormatDevice < ' a , S > {
120
- channels : uint ,
121
- sample_rate : uint ,
121
+ channels : usize ,
122
+ sample_rate : usize ,
122
123
endianness : Endianness ,
123
124
device : Option < DeviceFormat < ' a > > ,
124
125
driver : Driver < ' a > ,
@@ -196,13 +197,13 @@ impl<'a, S: Str> AutoFormatDevice<'a, S> {
196
197
Ok ( ( ) )
197
198
}
198
199
199
- fn open_device ( & self , width : uint , rate : uint , channels : uint ,
200
+ fn open_device ( & self , width : usize , rate : usize , channels : usize ,
200
201
endianness : Endianness ) -> AoResult < DeviceFormat < ' a > > {
201
202
DeviceFormat :: new ( & self . driver , width, rate, channels, endianness,
202
203
self . matrix_for ( channels) )
203
204
}
204
205
205
- fn matrix_for ( & self , nchannels : uint ) -> Option < & str > {
206
+ fn matrix_for ( & self , nchannels : usize ) -> Option < & str > {
206
207
if self . matrixes . len ( ) <= nchannels {
207
208
None
208
209
} else {
0 commit comments