summaryrefslogtreecommitdiff
path: root/src/audio.rs
diff options
context:
space:
mode:
authorTom Barrett <tom@tombarrett.xyz>2020-03-11 07:15:16 -0500
committerTom Barrett <tom@tombarrett.xyz>2020-03-11 07:15:16 -0500
commit0e447ca05ff0c0fe91ec9a9a9091940680f967ba (patch)
tree38e8dade3674b2965a0e85b24567338fa61d9fb9 /src/audio.rs
parent79cb6caee1513c6b70a1f2201b73c222af3ec007 (diff)
waveform is now accurately shown
Diffstat (limited to 'src/audio.rs')
-rw-r--r--src/audio.rs19
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)
}