Skip to content

Commit

Permalink
fix audio bugs
Browse files Browse the repository at this point in the history
- reset buffer even if no device;
- keep audio device on Gameboy::reset
  • Loading branch information
griffi-gh committed Oct 1, 2023
1 parent 3eb8106 commit 0724fb9
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
12 changes: 12 additions & 0 deletions yarge-core/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,18 @@ impl Gameboy {
self.cpu.bus.apu.device = Some(Box::new(device));
}

#[inline] pub fn get_audio_device(&mut self) -> Option<&dyn AudioDevice> {
self.cpu.bus.apu.device.as_ref().map(|x| x.as_ref())
}

#[inline] pub fn get_audio_device_mut(&mut self) -> Option<&mut Box<dyn AudioDevice>> {
self.cpu.bus.apu.device.as_mut()
}

#[inline] pub fn remove_audio_device(&mut self) -> Option<Box<dyn AudioDevice>> {
self.cpu.bus.apu.device.take()
}

#[inline] pub fn has_save_data(&self) -> bool {
self.cpu.bus.cart.has_save_data()
}
Expand Down
2 changes: 1 addition & 1 deletion yarge-core/src/apu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ impl Apu {
if self.buffer.is_full() {
if let Some(device) = self.device.as_mut() {
device.queue_samples(self.buffer.get_buffer());
self.buffer.reset();
}
self.buffer.reset();
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions yarge-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,10 @@ impl Gameboy {
}

pub fn reset(&mut self) {
//MAYBE: option to keep rom?
let device = self.cpu.bus.apu.device.take();
self.cpu = Cpu::new();
self.cpu.bus.apu.device = device;
}

#[cfg(feature = "dbg-logging")]
Expand Down

0 comments on commit 0724fb9

Please sign in to comment.