diff options
Diffstat (limited to 'src/desktop/audio.rs')
-rw-r--r-- | src/desktop/audio.rs | 24 |
1 files changed, 11 insertions, 13 deletions
diff --git a/src/desktop/audio.rs b/src/desktop/audio.rs index c32433b..db15a4f 100644 --- a/src/desktop/audio.rs +++ b/src/desktop/audio.rs @@ -1,7 +1,7 @@ use rodio::{OutputStream, Sink, Source}; use crate::audio::SAMPLE_RATE; -use crate::io::Audio; +use crate::io::{Wave, Audio}; use std::time::Duration; pub struct RodioAudio { @@ -9,29 +9,27 @@ pub struct RodioAudio { _sink: Sink, } -struct RodioWave<W: Iterator + Send + 'static>(W); +struct RodioWave<W: Wave + Send + 'static>(W, usize); -impl<W: Iterator + Send + 'static> Iterator for RodioWave<W> -where - <W as Iterator>::Item: rodio::Sample, +impl<W: Wave + Send + 'static> Iterator for RodioWave<W> { - type Item = W::Item; + type Item = f32; fn next(&mut self) -> Option<Self::Item> { - self.0.next() + self.1 += 1; + let left = self.1 % 2 == 0; + self.0.next(left) } } -impl<W: Iterator + Send + 'static> Source for RodioWave<W> -where - <W as Iterator>::Item: rodio::Sample, +impl<W: Wave + Send + 'static> Source for RodioWave<W> { fn current_frame_len(&self) -> Option<usize> { None } fn channels(&self) -> u16 { - 1 + 2 } fn sample_rate(&self) -> u32 { @@ -44,11 +42,11 @@ where } impl Audio for RodioAudio { - fn new<S: Iterator<Item = f32> + Send + 'static>(wave: S) -> Self { + fn new<S: Wave + Send + 'static>(wave: S) -> Self { let (stream, stream_handle) = OutputStream::try_default().unwrap(); let sink = Sink::try_new(&stream_handle).unwrap(); - sink.append(RodioWave(wave)); + sink.append(RodioWave(wave, 0)); RodioAudio { _stream: stream, |