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
47ff4f7e
Verified
Commit
47ff4f7e
authored
1 year ago
by
João Magalhães
Browse files
Options
Downloads
Patches
Plain Diff
chore: new audio buffer handling
parent
457cf96a
No related branches found
No related tags found
No related merge requests found
Pipeline
#3176
passed
1 year ago
Stage: build
Stage: test
Stage: deploy
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
frontends/sdl/src/main.rs
+26
-0
26 additions, 0 deletions
frontends/sdl/src/main.rs
with
26 additions
and
0 deletions
frontends/sdl/src/main.rs
+
26
−
0
View file @
47ff4f7e
...
...
@@ -81,6 +81,7 @@ pub struct Emulator {
ram_path
:
String
,
logic_frequency
:
u32
,
visual_frequency
:
f32
,
max_audio_buffer
:
u32
,
next_tick_time
:
f32
,
next_tick_time_i
:
u32
,
features
:
Vec
<&
'static
str
>
,
...
...
@@ -101,6 +102,7 @@ impl Emulator {
ram_path
:
String
::
from
(
"invalid"
),
logic_frequency
:
GameBoy
::
CPU_FREQ
,
visual_frequency
:
GameBoy
::
VISUAL_FREQ
,
max_audio_buffer
:
64
,
next_tick_time
:
0.0
,
next_tick_time_i
:
0
,
features
:
options
...
...
@@ -470,6 +472,30 @@ impl Emulator {
frame_dirty
=
true
;
}
// in case there's new significant new audio data available in
// the emulator we must handle it by sending it to the audio callback
if
self
.system
.audio_buffer
()
.len
()
>
self
.max_audio_buffer
as
usize
{
// in case the audio subsystem is enabled, then the audio buffer
// must be queued into the SDL audio subsystem
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
();
}
// clears the audio buffer to prevent it from
// "exploding" in size, this is required GC operation
self
.system
.clear_audio_buffer
();
}
}
// in case there's pending audio data available in the emulator
// we must handle it by sending it to the audio callback
if
self
.system
.audio_buffer
()
.is_empty
()
{
// in case the audio subsystem is enabled, then the audio buffer
// must be queued into the SDL audio subsystem
if
let
Some
(
audio
)
=
self
.audio
.as_mut
()
{
...
...
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