chore(snd): rename some structs

This commit is contained in:
Rekai Nyangadzayi Musuka 2021-07-12 10:03:45 -05:00
parent b13444c885
commit 44b605970f
5 changed files with 20 additions and 18 deletions

View File

@ -4,7 +4,7 @@ use crate::interrupt::{Interrupt, InterruptFlag};
use crate::joypad::Joypad; use crate::joypad::Joypad;
use crate::ppu::{Ppu, PpuMode}; use crate::ppu::{Ppu, PpuMode};
use crate::serial::Serial; use crate::serial::Serial;
use crate::sound::{SampleSender, Sound}; use crate::sound::{AudioSender, Sound};
use crate::timer::Timer; use crate::timer::Timer;
use crate::work_ram::{VariableWorkRam, WorkRam}; use crate::work_ram::{VariableWorkRam, WorkRam};
use std::{fs::File, io::Read}; use std::{fs::File, io::Read};
@ -66,7 +66,7 @@ impl Bus {
self.cartridge.as_ref()?.title() 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) self.snd.set_audio_src(sender)
} }

View File

@ -3,7 +3,7 @@ use crate::instruction::{Cycle, Instruction};
use crate::interrupt::{InterruptEnable, InterruptFlag}; use crate::interrupt::{InterruptEnable, InterruptFlag};
use crate::joypad::Joypad; use crate::joypad::Joypad;
use crate::ppu::Ppu; use crate::ppu::Ppu;
use crate::sound::SampleSender; use crate::sound::AudioSender;
use crate::timer::Timer; use crate::timer::Timer;
use bitfield::bitfield; use bitfield::bitfield;
use std::fmt::{Display, Formatter, Result as FmtResult}; 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) 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 pending: u32 = cycles.into();
let mut offset = 0; let mut offset = 0;
for _ in 0..(pending + offset) { for _ in 0..(pending + offset) {

View File

@ -1,6 +1,6 @@
pub use gui::Egui; pub use gui::Egui;
pub use instruction::Cycle; pub use instruction::Cycle;
pub use sound::AudioSenderReceiver; pub use sound::AudioMPSC;
pub const GB_WIDTH: usize = 160; pub const GB_WIDTH: usize = 160;
pub const GB_HEIGHT: usize = 144; pub const GB_HEIGHT: usize = 144;

View File

@ -1,6 +1,6 @@
use anyhow::{anyhow, Result}; use anyhow::{anyhow, Result};
use clap::{crate_authors, crate_description, crate_name, crate_version, App, Arg}; 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 gilrs::Gilrs;
use pixels::{Pixels, SurfaceTexture}; use pixels::{Pixels, SurfaceTexture};
use rodio::{OutputStream, Sink}; use rodio::{OutputStream, Sink};
@ -66,7 +66,7 @@ fn main() -> Result<()> {
(pixels, egui) (pixels, egui)
}; };
let (send, recv) = AudioSenderReceiver::new(); let (send, recv) = AudioMPSC::new();
game_boy.set_audio_src(send); game_boy.set_audio_src(send);
// Initialize Audio // Initialize Audio

View File

@ -27,7 +27,7 @@ pub(crate) struct Sound {
frame_seq_state: FrameSequencerState, frame_seq_state: FrameSequencerState,
div_prev: Option<u8>, div_prev: Option<u8>,
sender: Option<SampleSender>, sender: Option<AudioSender>,
sample_counter: u64, sample_counter: u64,
is_mpsc_full: bool, 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); self.sender = Some(sender);
} }
@ -1172,22 +1172,22 @@ impl From<ChannelControl> for u8 {
} }
} }
pub struct AudioSenderReceiver; pub struct AudioMPSC;
impl AudioSenderReceiver { impl AudioMPSC {
pub fn new() -> (SampleSender, SampleReceiver) { pub fn new() -> (AudioSender, AudioReceiver) {
let (send, recv) = crossbeam_channel::bounded(AUDIO_BUFFER_LEN * 2); 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)] #[derive(Debug, Clone)]
pub struct SampleSender { pub struct AudioSender {
inner: Sender<f32>, inner: Sender<f32>,
} }
impl SampleSender { impl AudioSender {
fn send_samples(&self, left: f32, right: f32) -> Result<(), TrySendError<f32>> { fn send_samples(&self, left: f32, right: f32) -> Result<(), TrySendError<f32>> {
self.inner.try_send(left).and(self.inner.try_send(right))?; self.inner.try_send(left).and(self.inner.try_send(right))?;
Ok(()) Ok(())
@ -1198,11 +1198,11 @@ impl SampleSender {
} }
} }
pub struct SampleReceiver { pub struct AudioReceiver {
inner: Receiver<f32>, inner: Receiver<f32>,
} }
impl Iterator for SampleReceiver { impl Iterator for AudioReceiver {
type Item = f32; type Item = f32;
fn next(&mut self) -> Option<Self::Item> { fn next(&mut self) -> Option<Self::Item> {
@ -1211,7 +1211,7 @@ impl Iterator for SampleReceiver {
} }
} }
impl Source for SampleReceiver { impl Source for AudioReceiver {
fn current_frame_len(&self) -> Option<usize> { fn current_frame_len(&self) -> Option<usize> {
// A frame changes when the samples rate or // A frame changes when the samples rate or
// number of channels change. This will never happen, so // number of channels change. This will never happen, so