dont fully reinitialise if u dont need to

This commit is contained in:
Alex Janka 2023-03-08 15:41:17 +11:00
parent 11dec11079
commit 0f919c612c
4 changed files with 34 additions and 13 deletions

View file

@ -112,6 +112,13 @@ impl Plugin for GameboyEmu {
verbose: false,
cycle_count: false,
};
if let Some(ref mut vars) = self.vars {
let (output, rx) = AudioOutput::new_unfilled(buffer_config.sample_rate, false);
vars.emulator_core.replace_output(output);
vars.rx = rx;
} else {
let (sender, receiver) = channel::<EmulatorMessage>();
let (output, rx) = AudioOutput::new_unfilled(buffer_config.sample_rate, false);
@ -130,6 +137,7 @@ impl Plugin for GameboyEmu {
sender,
emulator_core,
});
}
true
}

View file

@ -124,6 +124,10 @@ impl<ColourFormat: From<Colour> + Clone> EmulatorCore<ColourFormat> {
}
}
pub fn replace_output(&mut self, new: AudioOutput) {
self.cpu.memory.replace_output(new);
}
pub fn run(&mut self) {
self.process_messages();
self.cycle_num += 1;

View file

@ -226,6 +226,10 @@ impl<ColourFormat: From<Colour> + Clone> Memory<ColourFormat> {
pub fn is_audio_buffer_full(&self) -> bool {
self.apu.is_buffer_full()
}
pub fn replace_output(&mut self, new: AudioOutput) {
self.apu.replace_output(new);
}
}
impl<ColourFormat: From<Colour> + Clone> Cpu<ColourFormat> {

View file

@ -64,6 +64,11 @@ impl Apu {
}
}
pub fn replace_output(&mut self, new: AudioOutput) {
self.converter = Downsampler::new(new.sample_rate);
self.output = new;
}
pub fn div_apu_tick(&mut self) {
self.div_apu = self.div_apu.wrapping_add(1);
if self.div_apu % 8 == 0 {