Compare commits

..

3 Commits

Author SHA1 Message Date
Rekai Nyangadzayi Musuka db012c7f4b fix(main): remove code unrelated to audio sync
continuous-integration/drone/push Build is passing Details
2021-09-07 02:09:02 -03:00
Rekai Nyangadzayi Musuka e42c87aeb7 fix(apu): quiet gameboy APU 2021-09-07 01:52:02 -03:00
Rekai Nyangadzayi Musuka 9113e95fa0 fix(apu): pass blargg apu sweep tests 2021-09-07 01:17:01 -03:00
2 changed files with 19 additions and 30 deletions

View File

@ -468,22 +468,8 @@ impl Channel1 {
// If this bit is set, a trigger event occurs // If this bit is set, a trigger event occurs
if self.freq_hi.initial() { if self.freq_hi.initial() {
// Envelope Behaviour during trigger event if self.is_dac_enabled() {
self.period_timer = self.envelope.period(); self.enabled = true;
self.current_volume = self.envelope.init_vol();
// Sweep behaviour during trigger event
let sweep_period = self.sweep.period();
let sweep_shift = self.sweep.shift_count();
self.shadow_freq = self.frequency();
self.sweep_timer = if sweep_period == 0 { 8 } else { sweep_period };
if sweep_period != 0 || sweep_shift != 0 {
self.sweep_enabled = true;
}
if sweep_shift != 0 {
let _ = self.calc_sweep_freq();
} }
// Length behaviour during trigger event // Length behaviour during trigger event
@ -491,8 +477,21 @@ impl Channel1 {
self.length_timer = 64; self.length_timer = 64;
} }
if self.is_dac_enabled() { // Envelope Behaviour during trigger event
self.enabled = true; self.period_timer = self.envelope.period();
self.current_volume = self.envelope.init_vol();
// Sweep behaviour during trigger event
let sweep_period = self.sweep.period();
let sweep_shift = self.sweep.shift_count();
self.shadow_freq = self.frequency();
self.sweep_timer = if sweep_period == 0 { 8 } else { sweep_period };
self.sweep_enabled = sweep_period != 0 || sweep_shift != 0;
if sweep_shift != 0 {
let _ = self.calc_sweep_freq();
} }
} }
} }

View File

@ -4,7 +4,6 @@ use gb::{AudioSPSC, Cycle, GB_HEIGHT, GB_WIDTH};
use gilrs::Gilrs; use gilrs::Gilrs;
use pixels::{PixelsBuilder, SurfaceTexture}; use pixels::{PixelsBuilder, SurfaceTexture};
use rodio::{OutputStream, Sink}; use rodio::{OutputStream, Sink};
use std::time::{Duration, Instant};
use winit::dpi::LogicalSize; use winit::dpi::LogicalSize;
use winit::event::{Event, VirtualKeyCode}; use winit::event::{Event, VirtualKeyCode};
use winit::event_loop::{ControlFlow, EventLoop}; use winit::event_loop::{ControlFlow, EventLoop};
@ -71,6 +70,7 @@ fn main() -> Result<()> {
let (prod, cons) = spsc.init(); let (prod, cons) = spsc.init();
let sink = Sink::try_new(&stream_handle)?; let sink = Sink::try_new(&stream_handle)?;
sink.append(cons); sink.append(cons);
sink.set_volume(0.1); // TODO: Is this the right way to go about this?
game_boy.apu_mut().attach_producer(prod); game_boy.apu_mut().attach_producer(prod);
std::thread::spawn(move || { std::thread::spawn(move || {
@ -78,8 +78,6 @@ fn main() -> Result<()> {
}); });
} }
let mut start = Instant::now();
let frame_time = Duration::from_secs_f64(1.0 / 59.73); // 59.73 Hz on Host
let mut cycle_count: Cycle = Default::default(); let mut cycle_count: Cycle = Default::default();
event_loop.run(move |event, _, control_flow| { event_loop.run(move |event, _, control_flow| {
@ -104,15 +102,7 @@ fn main() -> Result<()> {
pixels.resize_surface(size.width, size.height); pixels.resize_surface(size.width, size.height);
} }
let mut diff = Instant::now() - start; cycle_count += gb::emu::run_frame(&mut game_boy, &mut gamepad, &input);
while diff.subsec_nanos() < frame_time.subsec_nanos() {
if cycle_count < gb::emu::CYCLES_IN_FRAME {
cycle_count += gb::emu::run_frame(&mut game_boy, &mut gamepad, &input);
}
diff = Instant::now() - start;
}
start = Instant::now();
if cycle_count >= gb::emu::CYCLES_IN_FRAME { if cycle_count >= gb::emu::CYCLES_IN_FRAME {
cycle_count %= gb::emu::CYCLES_IN_FRAME; cycle_count %= gb::emu::CYCLES_IN_FRAME;