Add draft for example music playing

This commit is contained in:
Pierre Krieger 2014-12-15 13:01:37 +01:00
parent 9089246b4d
commit 27c91645ad
2 changed files with 22 additions and 0 deletions

Binary file not shown.

22
examples/music.rs Normal file
View File

@ -0,0 +1,22 @@
extern crate cpal;
extern crate vorbis;
use std::io::BufReader;
fn main() {
let mut channel = cpal::Channel::new();
let mut decoder = vorbis::Decoder::new(BufReader::new(include_bin!("mozart_symfony_40.ogg")))
.unwrap();
for packet in decoder.packets() {
let packet = packet.unwrap();
let mut buffer = channel.append_data(packet.channels, cpal::SamplesRate(packet.rate as u32));
// FIXME: data loss
for (i, o) in packet.data.into_iter().zip(buffer.iter_mut()) {
*o = i as u16;
}
}
}