Skip to content
Snippets Groups Projects
Verified Commit 17184e23 authored by João Magalhães's avatar João Magalhães :rocket:
Browse files

fix: issue with global audio memory

parent 99b7c4e9
No related branches found
No related tags found
No related merge requests found
...@@ -30,6 +30,8 @@ use crate::consts::{REGION_NTSC, RETRO_API_VERSION}; ...@@ -30,6 +30,8 @@ use crate::consts::{REGION_NTSC, RETRO_API_VERSION};
static mut EMULATOR: Option<GameBoy> = None; static mut EMULATOR: Option<GameBoy> = None;
static mut KEY_STATES: Option<HashMap<RetroJoypad, bool>> = None; static mut KEY_STATES: Option<HashMap<RetroJoypad, bool>> = None;
static mut FRAME_BUFFER: [u8; FRAME_BUFFER_RGB155_SIZE] = [0x00; FRAME_BUFFER_RGB155_SIZE]; static mut FRAME_BUFFER: [u8; FRAME_BUFFER_RGB155_SIZE] = [0x00; FRAME_BUFFER_RGB155_SIZE];
static mut AUDIO_BUFFER: Option<Vec<i16>> = None;
static mut PENDING_CYCLES: u32 = 0_u32; static mut PENDING_CYCLES: u32 = 0_u32;
static mut ENVIRONMENT_CALLBACK: Option<extern "C" fn(u32, *const c_void) -> bool> = None; static mut ENVIRONMENT_CALLBACK: Option<extern "C" fn(u32, *const c_void) -> bool> = None;
...@@ -187,8 +189,8 @@ pub unsafe extern "C" fn retro_get_system_av_info(info: *mut RetroSystemAvInfo) ...@@ -187,8 +189,8 @@ pub unsafe extern "C" fn retro_get_system_av_info(info: *mut RetroSystemAvInfo)
debugln!("retro_get_system_av_info()"); debugln!("retro_get_system_av_info()");
(*info).geometry.base_width = DISPLAY_WIDTH as u32; (*info).geometry.base_width = DISPLAY_WIDTH as u32;
(*info).geometry.base_height = DISPLAY_HEIGHT as u32; (*info).geometry.base_height = DISPLAY_HEIGHT as u32;
(*info).geometry.max_width = DISPLAY_WIDTH as u32; (*info).geometry.max_width = DISPLAY_WIDTH as u32 * 64;
(*info).geometry.max_height = DISPLAY_HEIGHT as u32; (*info).geometry.max_height = DISPLAY_HEIGHT as u32 * 64;
(*info).geometry.aspect_ratio = DISPLAY_WIDTH as f32 / DISPLAY_HEIGHT as f32; (*info).geometry.aspect_ratio = DISPLAY_WIDTH as f32 / DISPLAY_HEIGHT as f32;
(*info).timing.fps = GameBoy::VISUAL_FREQ as f64; (*info).timing.fps = GameBoy::VISUAL_FREQ as f64;
(*info).timing.sample_rate = EMULATOR.as_ref().unwrap().audio_sampling_rate() as f64; (*info).timing.sample_rate = EMULATOR.as_ref().unwrap().audio_sampling_rate() as f64;
...@@ -258,20 +260,29 @@ pub extern "C" fn retro_run() { ...@@ -258,20 +260,29 @@ pub extern "C" fn retro_run() {
last_frame = emulator.ppu_frame(); last_frame = emulator.ppu_frame();
} }
// obtains the audio buffer reference and queues it // in case there's new audio data available in the emulator
// in a batch manner using the audio callback at the // we must handle it by sending it to the audio callback
// the end of the operation clears the buffer if !emulator.audio_buffer().is_empty() {
let audio_buffer = emulator // obtains the audio buffer reference and queues it
.audio_buffer() // in a batch manner using the audio callback at the
.iter() // the end of the operation clears the buffer
.map(|v| *v as i16 * 256) let audio_buffer = emulator
.collect::<Vec<i16>>(); .audio_buffer()
.iter()
sample_batch_cb( .map(|v| *v as i16 * 256)
audio_buffer.as_ptr(), .collect::<Vec<i16>>();
audio_buffer.len() / channels as usize,
); unsafe {
emulator.clear_audio_buffer(); AUDIO_BUFFER = Some(audio_buffer.to_vec());
let audio_buffer_ref = AUDIO_BUFFER.as_ref().unwrap();
sample_batch_cb(
audio_buffer_ref.as_ptr(),
audio_buffer_ref.len() / channels as usize,
);
}
emulator.clear_audio_buffer();
}
} }
input_poll_cb(); input_poll_cb();
......
...@@ -749,6 +749,10 @@ impl Apu { ...@@ -749,6 +749,10 @@ impl Apu {
self.audio_buffer.clear(); self.audio_buffer.clear();
} }
pub fn audio_buffer_max(&self) -> usize {
self.audio_buffer_max
}
pub fn clock_freq(&self) -> u32 { pub fn clock_freq(&self) -> u32 {
self.clock_freq self.clock_freq
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment