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
9d52f679
Verified
Commit
9d52f679
authored
2 years ago
by
João Magalhães
Browse files
Options
Downloads
Patches
Plain Diff
feat: initial APU and continuous audio
parent
01c26760
No related branches found
No related tags found
1 merge request
!19
Initial tentative audio support 🔉
Pipeline
#2245
failed
2 years ago
Stage: build
Stage: test
Changes
5
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
frontends/sdl/src/audio.rs
+18
-11
18 additions, 11 deletions
frontends/sdl/src/audio.rs
src/apu.rs
+24
-0
24 additions, 0 deletions
src/apu.rs
src/gb.rs
+3
-2
3 additions, 2 deletions
src/gb.rs
src/lib.rs
+1
-0
1 addition, 0 deletions
src/lib.rs
src/mmu.rs
+8
-2
8 additions, 2 deletions
src/mmu.rs
with
54 additions
and
15 deletions
frontends/sdl/src/audio.rs
+
18
−
11
View file @
9d52f679
use
sdl2
::{
audio
::{
AudioCallback
,
AudioSpecDesired
},
audio
::{
AudioCallback
,
AudioDevice
,
AudioSpecDesired
},
AudioSubsystem
,
Sdl
,
};
use
std
::
time
::
Duration
;
struct
Square
Wave
{
pub
struct
Audio
Wave
{
phase_inc
:
f32
,
phase
:
f32
,
volume
:
f32
,
/// The relative amount of time (as a percentage decimal) the low level
/// is going to be present during a period (cycle).
/// From [Wikipedia](https://en.wikipedia.org/wiki/Duty_cycle).
duty_cycle
:
f32
,
}
impl
AudioCallback
for
Square
Wave
{
impl
AudioCallback
for
Audio
Wave
{
type
Channel
=
f32
;
fn
callback
(
&
mut
self
,
out
:
&
mut
[
f32
])
{
for
x
in
out
.iter_mut
()
{
// this is a square wave with 50% of down
// and 50% of up values
*
x
=
if
self
.phase
<=
0.5
{
*
x
=
if
self
.phase
<
(
1.0
-
self
.duty_cycle
)
{
self
.volume
}
else
{
-
self
.volume
...
...
@@ -28,6 +32,7 @@ impl AudioCallback for SquareWave {
}
pub
struct
Audio
{
pub
device
:
AudioDevice
<
AudioWave
>
,
pub
audio_subsystem
:
AudioSubsystem
,
}
...
...
@@ -42,10 +47,11 @@ impl Audio {
};
let
device
=
audio_subsystem
.open_playback
(
None
,
&
desired_spec
,
|
spec
|
Square
Wave
{
.open_playback
(
None
,
&
desired_spec
,
|
spec
|
Audio
Wave
{
phase_inc
:
440.0
/
spec
.freq
as
f32
,
phase
:
0.0
,
volume
:
0.25
,
duty_cycle
:
0.5
,
})
.unwrap
();
...
...
@@ -53,8 +59,9 @@ impl Audio {
// device's activity
device
.resume
();
std
::
thread
::
sleep
(
Duration
::
from_millis
(
2000
));
Self
{
audio_subsystem
}
Self
{
device
,
audio_subsystem
,
}
}
}
This diff is collapsed.
Click to expand it.
src/apu.rs
0 → 100644
+
24
−
0
View file @
9d52f679
pub
struct
Apu
{
}
impl
Apu
{
pub
fn
new
()
->
Self
{
Self
{}
}
pub
fn
read
(
&
mut
self
,
addr
:
u16
)
->
u8
{
match
addr
{
0xff26
=>
1
as
u8
,
// todo implement this
_
=>
0x00
}
}
pub
fn
write
(
&
mut
self
,
addr
:
u16
,
value
:
u8
)
{
match
addr
{
0xff26
=>
{
// @todo implement the logic here
},
_
=>
{}
}
}
}
This diff is collapsed.
Click to expand it.
src/gb.rs
+
3
−
2
View file @
9d52f679
...
...
@@ -7,7 +7,7 @@ use crate::{
ppu
::{
Ppu
,
PpuMode
,
Tile
,
FRAME_BUFFER_SIZE
},
rom
::
Cartridge
,
timer
::
Timer
,
util
::
read_file
,
util
::
read_file
,
apu
::
Apu
,
};
#[cfg(feature
=
"wasm"
)]
...
...
@@ -57,9 +57,10 @@ impl GameBoy {
#[cfg_attr(feature
=
"wasm"
,
wasm_bindgen(constructor))]
pub
fn
new
()
->
Self
{
let
ppu
=
Ppu
::
new
();
let
apu
=
Apu
::
new
();
let
pad
=
Pad
::
new
();
let
timer
=
Timer
::
new
();
let
mmu
=
Mmu
::
new
(
ppu
,
pad
,
timer
);
let
mmu
=
Mmu
::
new
(
ppu
,
apu
,
pad
,
timer
);
let
cpu
=
Cpu
::
new
(
mmu
);
Self
{
cpu
}
}
...
...
This diff is collapsed.
Click to expand it.
src/lib.rs
+
1
−
0
View file @
9d52f679
#![allow(clippy::uninlined_format_args)]
pub
mod
apu
;
pub
mod
cpu
;
pub
mod
data
;
pub
mod
gb
;
...
...
This diff is collapsed.
Click to expand it.
src/mmu.rs
+
8
−
2
View file @
9d52f679
use
crate
::{
debugln
,
pad
::
Pad
,
ppu
::
Ppu
,
rom
::
Cartridge
,
timer
::
Timer
};
use
crate
::{
debugln
,
pad
::
Pad
,
ppu
::
Ppu
,
rom
::
Cartridge
,
timer
::
Timer
,
apu
::
Apu
};
pub
const
BOOT_SIZE
:
usize
=
2304
;
pub
const
RAM_SIZE
:
usize
=
8192
;
...
...
@@ -13,6 +13,11 @@ pub struct Mmu {
/// some of the access operations.
ppu
:
Ppu
,
/// Reference to the APU (Audio Processing Unit) that is going
/// to be used both for register reading/writing and to forward
/// some of the access operations.
apu
:
Apu
,
/// Reference to the Gamepad structure that is going to control
/// the I/O access to this device.
pad
:
Pad
,
...
...
@@ -44,9 +49,10 @@ pub struct Mmu {
}
impl
Mmu
{
pub
fn
new
(
ppu
:
Ppu
,
pad
:
Pad
,
timer
:
Timer
)
->
Self
{
pub
fn
new
(
ppu
:
Ppu
,
apu
:
Apu
,
pad
:
Pad
,
timer
:
Timer
)
->
Self
{
Self
{
ppu
,
apu
,
pad
,
timer
,
rom
:
Cartridge
::
new
(),
...
...
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