aboutsummaryrefslogtreecommitdiff
path: root/src/desktop/audio.rs
diff options
context:
space:
mode:
authorAstatin <[email protected]>2025-07-12 02:45:38 +0200
committerAstatin <[email protected]>2025-07-12 02:45:38 +0200
commit9d24a19cd9a392d5a2067a3e233a5a26a1518c35 (patch)
tree0a47acf10b6a029977ba7bd4c3fad59f5f5f28e2 /src/desktop/audio.rs
parentbfe34191a52e356ce92df8e6b10d3ba2b4598fe8 (diff)
Update audio registers without trigger + add stereo
Diffstat (limited to 'src/desktop/audio.rs')
-rw-r--r--src/desktop/audio.rs24
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,