diff --git a/gb-emu/src/main.rs b/gb-emu/src/main.rs index afb33ba..71fa74d 100644 --- a/gb-emu/src/main.rs +++ b/gb-emu/src/main.rs @@ -224,7 +224,7 @@ impl EmulatorHandler { } fn cycle(&mut self) { - if self.since.elapsed() >= Duration::from_millis(10) { + if self.since.elapsed() >= UPDATE_INTERVAL { self.window_manager.update_events(); self.since = Instant::now(); } @@ -234,3 +234,5 @@ impl EmulatorHandler { } } } + +const UPDATE_INTERVAL: Duration = Duration::from_millis(1); diff --git a/lib/src/processor/memory/mmio/apu.rs b/lib/src/processor/memory/mmio/apu.rs index 93e1394..6d3d28c 100644 --- a/lib/src/processor/memory/mmio/apu.rs +++ b/lib/src/processor/memory/mmio/apu.rs @@ -16,14 +16,14 @@ mod types; impl DacSample { fn mixed(&self, mixer: &Mixer) -> [f32; 2] { - let left = (self.one * mixer.ch1.left.scale()) - + (self.two * mixer.ch2.left.scale()) - + (self.three * mixer.ch3.left.scale()) - + (self.four * mixer.ch4.left.scale()); - let right = (self.one * mixer.ch1.right.scale()) - + (self.two * mixer.ch2.right.scale()) - + (self.three * mixer.ch3.right.scale()) - + (self.four * mixer.ch4.right.scale()); + let left = mixer.ch1.left.gate(self.one) + + mixer.ch2.left.gate(self.two) + + mixer.ch3.left.gate(self.three) + + mixer.ch4.left.gate(self.four); + let right = mixer.ch1.right.gate(self.one) + + mixer.ch2.right.gate(self.two) + + mixer.ch3.right.gate(self.three) + + mixer.ch4.right.gate(self.four); [ self.mix_channel(left, mixer.vol_left), self.mix_channel(right, mixer.vol_right), diff --git a/lib/src/processor/memory/mmio/apu/types.rs b/lib/src/processor/memory/mmio/apu/types.rs index bc66005..1e3a87b 100644 --- a/lib/src/processor/memory/mmio/apu/types.rs +++ b/lib/src/processor/memory/mmio/apu/types.rs @@ -34,10 +34,10 @@ pub(super) enum Volume { } impl Volume { - pub(super) fn scale(&self) -> f32 { + pub(super) fn gate(&self, val: f32) -> f32 { match self { Volume::Muted => 0., - Volume::Enabled => 1., + Volume::Enabled => val, } }