diff --git a/examples/mozart_symfony_40.ogg b/examples/mozart_symfony_40.ogg new file mode 100644 index 0000000..0a59e79 Binary files /dev/null and b/examples/mozart_symfony_40.ogg differ diff --git a/examples/music.rs b/examples/music.rs new file mode 100644 index 0000000..59eca8d --- /dev/null +++ b/examples/music.rs @@ -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; + } + } +}