From 0e447ca05ff0c0fe91ec9a9a9091940680f967ba Mon Sep 17 00:00:00 2001 From: Tom Barrett Date: Wed, 11 Mar 2020 07:15:16 -0500 Subject: waveform is now accurately shown --- src/audio.rs | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) (limited to 'src/audio.rs') diff --git a/src/audio.rs b/src/audio.rs index e51504b..ef92408 100644 --- a/src/audio.rs +++ b/src/audio.rs @@ -14,7 +14,7 @@ pub fn init() -> (StreamingSource, Vec) { 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 waveform = Vec::new(); let mut _track_length = 0.0; @@ -23,16 +23,23 @@ pub fn init() -> (StreamingSource, Vec) { .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::, _>(&samples, sample_rate) .unwrap(); stream.queue_buffer(audio_buffer).unwrap(); - if samples.len() > 1 { - toms_samples.push(samples[0]) - } + _track_length += samples.len() as f32 / sample_channels; + + samples = samples + .into_iter() + .enumerate() + .filter(|(i, _)| i % 2 == 0) + .map(|(_, s)| s) + .collect(); + + waveform.append(&mut samples); } - (stream, toms_samples) + (stream, waveform) } -- cgit v1.2.3