Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
boytacean
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
João Magalhães
boytacean
Commits
17184e23
Verified
Commit
17184e23
authored
1 year ago
by
João Magalhães
Browse files
Options
Downloads
Patches
Plain Diff
fix: issue with global audio memory
parent
99b7c4e9
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
frontends/libretro/src/lib.rs
+27
-16
27 additions, 16 deletions
frontends/libretro/src/lib.rs
src/apu.rs
+4
-0
4 additions, 0 deletions
src/apu.rs
with
31 additions
and
16 deletions
frontends/libretro/src/lib.rs
+
27
−
16
View file @
17184e23
...
@@ -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
();
...
...
This diff is collapsed.
Click to expand it.
src/apu.rs
+
4
−
0
View file @
17184e23
...
@@ -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
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment