diff options
Diffstat (limited to 'src/audio.rs')
-rw-r--r-- | src/audio.rs | 19 |
1 files changed, 13 insertions, 6 deletions
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<i16>) { 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<i16>) { .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]) - } + _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) } |