From 0c0b348971ee209679b571977115537daf9288cf Mon Sep 17 00:00:00 2001 From: Tom Barrett Date: Wed, 4 Mar 2020 03:41:04 -0600 Subject: audio works --- src/audio.rs | 21 +++++++++++++++++++++ src/main.rs | 5 +++++ 2 files changed, 26 insertions(+) create mode 100644 src/audio.rs (limited to 'src') diff --git a/src/audio.rs b/src/audio.rs new file mode 100644 index 0000000..bbc3a53 --- /dev/null +++ b/src/audio.rs @@ -0,0 +1,21 @@ +use alto::{Alto, Stereo, StreamingSource}; +use lewton::inside_ogg::OggStreamReader; +use std::fs::File; + +pub fn init() -> StreamingSource { + let mut source = OggStreamReader::new(File::open("data/djbLUETOOTH.ogg").unwrap()).unwrap(); + let alto = Alto::load_default().unwrap(); + let device = alto.open(None).unwrap(); + let audio_context = device.new_context(None).unwrap(); + let mut stream = audio_context.new_streaming_source().unwrap(); + let sample_rate = source.ident_hdr.audio_sample_rate as i32; + + while let Ok(Some(samples)) = source.read_dec_packet_itl() { + let audio_buffer = audio_context + .new_buffer::, _>(&samples, sample_rate) + .unwrap(); + stream.queue_buffer(audio_buffer).unwrap(); + } + + stream +} diff --git a/src/main.rs b/src/main.rs index b3c2e05..81b8585 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,4 @@ +pub mod audio; pub mod constants; pub mod n1ck; pub mod tom; @@ -59,6 +60,10 @@ fn main() { .unwrap() .ignore_warnings(); + // only uncomment if building as release 'cargo run --release' + //let mut stream = audio::init(); + //stream.play(); + let (mut tom, surface) = Tom::new(surface); let (mut n1ck, mut surface) = N1ck::new(surface); -- cgit v1.2.3