diff --git a/src/bus.rs b/src/bus.rs index 423f26d..4e64a1c 100644 --- a/src/bus.rs +++ b/src/bus.rs @@ -4,7 +4,7 @@ use crate::interrupt::{Interrupt, InterruptFlag}; use crate::joypad::Joypad; use crate::ppu::{Ppu, PpuMode}; use crate::serial::Serial; -use crate::sound::{SampleSender, Sound}; +use crate::sound::{AudioSender, Sound}; use crate::timer::Timer; use crate::work_ram::{VariableWorkRam, WorkRam}; use std::{fs::File, io::Read}; @@ -66,7 +66,7 @@ impl Bus { self.cartridge.as_ref()?.title() } - pub(crate) fn pass_audio_src(&mut self, sender: SampleSender) { + pub(crate) fn pass_audio_src(&mut self, sender: AudioSender) { self.snd.set_audio_src(sender) } diff --git a/src/cpu.rs b/src/cpu.rs index 9d0a410..5f17b64 100644 --- a/src/cpu.rs +++ b/src/cpu.rs @@ -3,7 +3,7 @@ use crate::instruction::{Cycle, Instruction}; use crate::interrupt::{InterruptEnable, InterruptFlag}; use crate::joypad::Joypad; use crate::ppu::Ppu; -use crate::sound::SampleSender; +use crate::sound::AudioSender; use crate::timer::Timer; use bitfield::bitfield; use std::fmt::{Display, Formatter, Result as FmtResult}; @@ -45,7 +45,7 @@ impl Cpu { }) } - pub fn set_audio_src(&mut self, sender: SampleSender) { + pub fn set_audio_src(&mut self, sender: AudioSender) { self.bus.pass_audio_src(sender) } @@ -125,6 +125,8 @@ impl Cpu { } }; + // FIXME: Regression, this is not a proper fix, + // the FIFO behaves weirdly using this code let pending: u32 = cycles.into(); let mut offset = 0; for _ in 0..(pending + offset) { diff --git a/src/lib.rs b/src/lib.rs index 9713f19..a54ab68 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,6 +1,6 @@ pub use gui::Egui; pub use instruction::Cycle; -pub use sound::AudioSenderReceiver; +pub use sound::AudioMPSC; pub const GB_WIDTH: usize = 160; pub const GB_HEIGHT: usize = 144; diff --git a/src/main.rs b/src/main.rs index 1d03340..adc2fb4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,6 +1,6 @@ use anyhow::{anyhow, Result}; use clap::{crate_authors, crate_description, crate_name, crate_version, App, Arg}; -use gb::{AudioSenderReceiver, Cycle, Egui, GB_HEIGHT, GB_WIDTH}; +use gb::{AudioMPSC, Cycle, Egui, GB_HEIGHT, GB_WIDTH}; use gilrs::Gilrs; use pixels::{Pixels, SurfaceTexture}; use rodio::{OutputStream, Sink}; @@ -66,7 +66,7 @@ fn main() -> Result<()> { (pixels, egui) }; - let (send, recv) = AudioSenderReceiver::new(); + let (send, recv) = AudioMPSC::new(); game_boy.set_audio_src(send); // Initialize Audio diff --git a/src/sound.rs b/src/sound.rs index c705d30..6b973b6 100644 --- a/src/sound.rs +++ b/src/sound.rs @@ -27,7 +27,7 @@ pub(crate) struct Sound { frame_seq_state: FrameSequencerState, div_prev: Option, - sender: Option, + sender: Option, sample_counter: u64, is_mpsc_full: bool, @@ -104,7 +104,7 @@ impl Sound { } } - pub(crate) fn set_audio_src(&mut self, sender: SampleSender) { + pub(crate) fn set_audio_src(&mut self, sender: AudioSender) { self.sender = Some(sender); } @@ -1172,22 +1172,22 @@ impl From for u8 { } } -pub struct AudioSenderReceiver; +pub struct AudioMPSC; -impl AudioSenderReceiver { - pub fn new() -> (SampleSender, SampleReceiver) { +impl AudioMPSC { + pub fn new() -> (AudioSender, AudioReceiver) { let (send, recv) = crossbeam_channel::bounded(AUDIO_BUFFER_LEN * 2); - (SampleSender { inner: send }, SampleReceiver { inner: recv }) + (AudioSender { inner: send }, AudioReceiver { inner: recv }) } } #[derive(Debug, Clone)] -pub struct SampleSender { +pub struct AudioSender { inner: Sender, } -impl SampleSender { +impl AudioSender { fn send_samples(&self, left: f32, right: f32) -> Result<(), TrySendError> { self.inner.try_send(left).and(self.inner.try_send(right))?; Ok(()) @@ -1198,11 +1198,11 @@ impl SampleSender { } } -pub struct SampleReceiver { +pub struct AudioReceiver { inner: Receiver, } -impl Iterator for SampleReceiver { +impl Iterator for AudioReceiver { type Item = f32; fn next(&mut self) -> Option { @@ -1211,7 +1211,7 @@ impl Iterator for SampleReceiver { } } -impl Source for SampleReceiver { +impl Source for AudioReceiver { fn current_frame_len(&self) -> Option { // A frame changes when the samples rate or // number of channels change. This will never happen, so