File tree 3 files changed +22
-4
lines changed
3 files changed +22
-4
lines changed Original file line number Diff line number Diff line change 1
1
# APU - Audio Processing Unit
2
2
3
-
4
-
5
-
6
3
Rust libs:
4
+
7
5
- synthesis, has osc for common wavs.. will it work well to generate one for each register?
8
6
https://docs.rs/twang/latest/twang/
9
7
- SDL2 can play sounds
10
8
- ex of squarewave: https://github.com/Rust-SDL2/rust-sdl2/blob/master/examples/audio-queue-squarewave.rs
11
9
- can play multiple sounds with mixer:
12
10
- https://rust-sdl2.github.io/rust-sdl2/sdl2/mixer/index.html
13
11
- usage ex: https://github.com/Rust-SDL2/rust-sdl2/blob/master/examples/mixer-demo.rs
12
+ - https://nicktasios.nl/posts/making-sounds-using-sdl-and-visualizing-them-on-a-simulated-oscilloscope.html
14
13
15
- Combing wave forms:
14
+ Combining wave forms:
16
15
https://0xc45.com/blog/digital-audio-synthesizer-in-rust/
17
16
18
17
Other synthesizer examples:
Original file line number Diff line number Diff line change @@ -14,18 +14,35 @@ pub struct Apu {
14
14
dmc : [ u8 ; 4 ] ,
15
15
status : u8 ,
16
16
frame_counter : u8 ,
17
+
18
+ cpu_cycles : usize ,
19
+ is_between_apu_cycle : bool ,
17
20
}
18
21
19
22
impl Apu {
20
23
pub fn new ( ) -> Self {
21
24
Self {
25
+ // TODO: Pulse2 differs from Pulse1 slightly.
26
+ // Known diff is how in APU sweep "Calculating the target period"
22
27
pulse1 : PulseRegister :: new ( ) ,
23
28
pulse2 : PulseRegister :: new ( ) ,
24
29
triangle : [ 0 ; 4 ] ,
25
30
noise : [ 0 ; 4 ] ,
26
31
dmc : [ 0 ; 4 ] ,
27
32
status : 0 ,
28
33
frame_counter : 0 ,
34
+
35
+ cpu_cycles : 0 ,
36
+ is_between_apu_cycle : false ,
37
+ }
38
+ }
39
+
40
+ /// tick tracks CPU cycles. APU cycles occur every 2 CPU cycles
41
+ pub fn tick_cpu_cycles ( & mut self , cycles : usize ) {
42
+ for _ in 0 ..cycles {
43
+ self . cpu_cycles += 1 ;
44
+ // or just cpu_cycles %2
45
+ self . is_between_apu_cycle = !self . is_between_apu_cycle
29
46
}
30
47
}
31
48
}
Original file line number Diff line number Diff line change @@ -52,6 +52,8 @@ impl<'a> Bus<'a> {
52
52
if should_rerender {
53
53
( self . gameloop_callback ) ( & self . ppu , & mut self . gamepad1 , & mut self . gamepad2 )
54
54
}
55
+
56
+ self . apu . tick_cpu_cycles ( cycles) ;
55
57
}
56
58
57
59
pub fn poll_nmi_interrupt ( & mut self ) -> bool {
You can’t perform that action at this time.
0 commit comments