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

Fix Linux issue with libretro audio

parent d2bc2be6
No related branches found
No related tags found
1 merge request!30Fix Linux issue with libretro audio
...@@ -219,7 +219,7 @@ pub extern "C" fn retro_set_controller_port_device() { ...@@ -219,7 +219,7 @@ pub extern "C" fn retro_set_controller_port_device() {
pub extern "C" fn retro_run() { pub extern "C" fn retro_run() {
let emulator = unsafe { EMULATOR.as_mut().unwrap() }; let emulator = unsafe { EMULATOR.as_mut().unwrap() };
let video_refresh_cb = unsafe { VIDEO_REFRESH_CALLBACK.as_ref().unwrap() }; let video_refresh_cb = unsafe { VIDEO_REFRESH_CALLBACK.as_ref().unwrap() };
let sample_cb = unsafe { AUDIO_SAMPLE_CALLBACK.as_ref().unwrap() }; let sample_batch_cb = unsafe { AUDIO_SAMPLE_BATCH_CALLBACK.as_ref().unwrap() };
let input_poll_cb = unsafe { INPUT_POLL_CALLBACK.as_ref().unwrap() }; let input_poll_cb = unsafe { INPUT_POLL_CALLBACK.as_ref().unwrap() };
let input_state_cb = unsafe { INPUT_STATE_CALLBACK.as_ref().unwrap() }; let input_state_cb = unsafe { INPUT_STATE_CALLBACK.as_ref().unwrap() };
let key_states = unsafe { KEY_STATES.as_mut().unwrap() }; let key_states = unsafe { KEY_STATES.as_mut().unwrap() };
...@@ -265,20 +265,13 @@ pub extern "C" fn retro_run() { ...@@ -265,20 +265,13 @@ pub extern "C" fn retro_run() {
// in case there's new audio data available in the emulator // in case there's new audio data available in the emulator
// we must handle it by sending it to the audio callback // we must handle it by sending it to the audio callback
if !emulator.audio_buffer().is_empty() { if emulator.audio_buffer().len() >= 64 {
// obtains the audio buffer reference and queues it
// in a batch manner using the audio callback at the
// the end of the operation clears the buffer
let audio_buffer = emulator let audio_buffer = emulator
.audio_buffer() .audio_buffer()
.iter() .iter()
.map(|v| *v as i16 * 256) .map(|v| *v as i16 * 256)
.collect::<Vec<i16>>(); .collect::<Vec<i16>>();
sample_batch_cb(audio_buffer.as_ptr(), audio_buffer.len() / 2_usize);
for chunk in audio_buffer.chunks_exact(2) {
sample_cb(chunk[0], chunk[1]);
}
emulator.clear_audio_buffer(); emulator.clear_audio_buffer();
} }
} }
......
...@@ -474,7 +474,7 @@ impl Emulator { ...@@ -474,7 +474,7 @@ impl Emulator {
// in case there's new significant new audio data available in // in case there's new significant new audio data available in
// the emulator we must handle it, sending it to the audio callback // the emulator we must handle it, sending it to the audio callback
if self.system.audio_buffer().len() > self.max_audio_buffer as usize { if self.system.audio_buffer().len() >= self.max_audio_buffer as usize {
if let Some(audio) = self.audio.as_mut() { if let Some(audio) = self.audio.as_mut() {
let audio_buffer = self let audio_buffer = self
.system .system
...@@ -488,21 +488,6 @@ impl Emulator { ...@@ -488,21 +488,6 @@ impl Emulator {
} }
} }
// in case there's pending audio data available in the emulator
// we must handle it, sending it to the audio callback
if self.system.audio_buffer().is_empty() {
if let Some(audio) = self.audio.as_mut() {
let audio_buffer = self
.system
.audio_buffer()
.iter()
.map(|v| *v as f32 / VOLUME)
.collect::<Vec<f32>>();
audio.device.queue_audio(&audio_buffer).unwrap();
}
self.system.clear_audio_buffer();
}
// in case there's at least one new frame that was drawn during // in case there's at least one new frame that was drawn during
// during the current tick, then we need to flush it to the canvas, // during the current tick, then we need to flush it to the canvas,
// this separation between texture creation and canvas flush prevents // this separation between texture creation and canvas flush prevents
......
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