summaryrefslogtreecommitdiff
path: root/src/audio.rs
diff options
context:
space:
mode:
authorTom Barrett <tom@tombarrett.xyz>2020-03-04 03:41:04 -0600
committerTom Barrett <tom@tombarrett.xyz>2020-03-04 03:41:04 -0600
commit0c0b348971ee209679b571977115537daf9288cf (patch)
treec2a4a1bd6296fa81bc615137083f6912929bf08a /src/audio.rs
parentaf5e8f365478f62bc5108217317e70a6ee1accf4 (diff)
audio works
Diffstat (limited to 'src/audio.rs')
-rw-r--r--src/audio.rs21
1 files changed, 21 insertions, 0 deletions
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::<Stereo<i16>, _>(&samples, sample_rate)
+ .unwrap();
+ stream.queue_buffer(audio_buffer).unwrap();
+ }
+
+ stream
+}