chore(snd): rename some structs
This commit is contained in:
parent
b13444c885
commit
44b605970f
|
@ -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)
|
||||
}
|
||||
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
|
|
22
src/sound.rs
22
src/sound.rs
|
@ -27,7 +27,7 @@ pub(crate) struct Sound {
|
|||
frame_seq_state: FrameSequencerState,
|
||||
div_prev: Option<u8>,
|
||||
|
||||
sender: Option<SampleSender>,
|
||||
sender: Option<AudioSender>,
|
||||
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<ChannelControl> 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<f32>,
|
||||
}
|
||||
|
||||
impl SampleSender {
|
||||
impl AudioSender {
|
||||
fn send_samples(&self, left: f32, right: f32) -> Result<(), TrySendError<f32>> {
|
||||
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<f32>,
|
||||
}
|
||||
|
||||
impl Iterator for SampleReceiver {
|
||||
impl Iterator for AudioReceiver {
|
||||
type Item = f32;
|
||||
|
||||
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> {
|
||||
// A frame changes when the samples rate or
|
||||
// number of channels change. This will never happen, so
|
||||
|
|
Loading…
Reference in New Issue