diff options
author | Tom Barrett <tom@tombarrett.xyz> | 2020-03-10 10:15:01 -0500 |
---|---|---|
committer | Tom Barrett <tom@tombarrett.xyz> | 2020-03-10 10:15:01 -0500 |
commit | 79cb6caee1513c6b70a1f2201b73c222af3ec007 (patch) | |
tree | 1463f16d4bfcc026ae1ce458663db4208faaea64 /src/audio.rs | |
parent | f57de5cd6075c071fe89bb7af898072b0a8daab6 (diff) |
plots *a waveform*, not timed correctly
Diffstat (limited to 'src/audio.rs')
-rw-r--r-- | src/audio.rs | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/src/audio.rs b/src/audio.rs index ac6bc12..e51504b 100644 --- a/src/audio.rs +++ b/src/audio.rs @@ -4,24 +4,35 @@ use std::fs::File; use crate::constants; -pub fn init() -> StreamingSource { +pub fn init() -> (StreamingSource, Vec<i16>) { 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; + let sample_channels = + source.ident_hdr.audio_channels as f32 * source.ident_hdr.audio_sample_rate as f32; + + let mut toms_samples = Vec::new(); + + let mut _track_length = 0.0; while let Ok(Some(mut samples)) = source.read_dec_packet_itl() { samples = samples .into_iter() .map(|s| (s as f32 * constants::VOLUME) as i16) .collect(); + _track_length += samples.len() as f32 / sample_channels; let audio_buffer = audio_context .new_buffer::<Stereo<i16>, _>(&samples, sample_rate) .unwrap(); stream.queue_buffer(audio_buffer).unwrap(); + + if samples.len() > 1 { + toms_samples.push(samples[0]) + } } - stream + (stream, toms_samples) } |