From 9a8e4117be8d30109229600346e7d9561c52a3e3 Mon Sep 17 00:00:00 2001 From: Astatin Date: Thu, 3 Apr 2025 18:35:03 +0200 Subject: Separate core from desktop target --- src/audio.rs | 51 +++++++++++++++++++-------------------------------- 1 file changed, 19 insertions(+), 32 deletions(-) (limited to 'src/audio.rs') diff --git a/src/audio.rs b/src/audio.rs index 0a152a6..3e36790 100644 --- a/src/audio.rs +++ b/src/audio.rs @@ -1,12 +1,11 @@ // You are entering a very scary territory of magic numbers and arbitrary math operations. // I don't remember why I did all of this but it works I guess :3 -use rodio::{OutputStream, Sink, Source}; +use crate::io::Audio; use std::sync::{Arc, Mutex}; -use std::time::Duration; -const SAMPLE_RATE: u32 = 65536; +pub const SAMPLE_RATE: u32 = 65536; const SAMPLE_AVERAGING: usize = 5; //20; @@ -381,24 +380,6 @@ impl Iterator for MutableWave { } } -impl Source for MutableWave { - fn current_frame_len(&self) -> Option { - None - } - - fn channels(&self) -> u16 { - 1 - } - - fn sample_rate(&self) -> u32 { - SAMPLE_RATE - } - - fn total_duration(&self) -> Option { - None - } -} - pub struct AudioSquareChannel { wave: Arc>>, @@ -453,6 +434,10 @@ impl AudioSquareChannel { } } } + + pub fn get_wave_mutex(&self) -> Arc>> { + return self.wave.clone(); + } } pub struct AudioCustomChannel { @@ -499,6 +484,10 @@ impl AudioCustomChannel { } } } + + pub fn get_wave_mutex(&self) -> Arc>> { + return self.wave.clone(); + } } pub struct AudioNoiseChannel { @@ -549,11 +538,14 @@ impl AudioNoiseChannel { } } } + + pub fn get_wave_mutex(&self) -> Arc>> { + return self.wave.clone(); + } } -pub struct Audio { - _stream: OutputStream, - _sink: Sink, +pub struct Channels { + _audio: A, pub ch1: AudioSquareChannel, pub ch2: AudioSquareChannel, @@ -561,18 +553,15 @@ pub struct Audio { pub ch4: AudioNoiseChannel, } -impl Audio { +impl Channels { pub fn new() -> Self { - let (stream, stream_handle) = OutputStream::try_default().unwrap(); - - let sink = Sink::try_new(&stream_handle).unwrap(); let wave_ch1 = Arc::new(Mutex::new(None)); let wave_ch2 = Arc::new(Mutex::new(None)); let wave_ch3 = Arc::new(Mutex::new(None)); let wave_ch4 = Arc::new(Mutex::new(None)); - sink.append(MutableWave::new( + let audio = A::new(MutableWave::new( wave_ch1.clone(), wave_ch2.clone(), wave_ch3.clone(), @@ -580,9 +569,7 @@ impl Audio { )); Self { - _stream: stream, - _sink: sink, - + _audio: audio, ch1: AudioSquareChannel::new(wave_ch1), ch2: AudioSquareChannel::new(wave_ch2), ch3: AudioCustomChannel::new(wave_ch3), -- cgit v1.2.3-70-g09d2