1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
extern crate vorbisfile;
use super::{Source, SourceResult};
use super::SourceResult::{Buffer, StreamError, EndOfStream};
use self::vorbisfile::OVResult;
pub struct VorbisStream<R> {
src: vorbisfile::VorbisFile<R>,
}
impl<R: Reader> VorbisStream<R> {
pub fn open(reader: R) -> OVResult<VorbisStream<R>> {
Ok(VorbisStream {
src: try!(vorbisfile::VorbisFile::new(reader))
})
}
}
impl<R: Reader> Source for VorbisStream<R> {
type Output = f32;
fn next<'a>(&'a mut self) -> SourceResult<'a, f32> {
match self.src.decode() {
Ok(b) => Buffer(b),
Err(vorbisfile::OVError::EndOfStream) => EndOfStream,
Err(e) => StreamError(format!("vorbisfile decoder: {}", e))
}
}
}