some optimisation

This commit is contained in:
Alex Janka 2023-10-07 10:10:29 +11:00
parent 8129b9f840
commit 86397d3884
3 changed files with 13 additions and 11 deletions

View file

@ -224,7 +224,7 @@ impl EmulatorHandler {
} }
fn cycle(&mut self) { fn cycle(&mut self) {
if self.since.elapsed() >= Duration::from_millis(10) { if self.since.elapsed() >= UPDATE_INTERVAL {
self.window_manager.update_events(); self.window_manager.update_events();
self.since = Instant::now(); self.since = Instant::now();
} }
@ -234,3 +234,5 @@ impl EmulatorHandler {
} }
} }
} }
const UPDATE_INTERVAL: Duration = Duration::from_millis(1);

View file

@ -16,14 +16,14 @@ mod types;
impl DacSample { impl DacSample {
fn mixed(&self, mixer: &Mixer) -> [f32; 2] { fn mixed(&self, mixer: &Mixer) -> [f32; 2] {
let left = (self.one * mixer.ch1.left.scale()) let left = mixer.ch1.left.gate(self.one)
+ (self.two * mixer.ch2.left.scale()) + mixer.ch2.left.gate(self.two)
+ (self.three * mixer.ch3.left.scale()) + mixer.ch3.left.gate(self.three)
+ (self.four * mixer.ch4.left.scale()); + mixer.ch4.left.gate(self.four);
let right = (self.one * mixer.ch1.right.scale()) let right = mixer.ch1.right.gate(self.one)
+ (self.two * mixer.ch2.right.scale()) + mixer.ch2.right.gate(self.two)
+ (self.three * mixer.ch3.right.scale()) + mixer.ch3.right.gate(self.three)
+ (self.four * mixer.ch4.right.scale()); + mixer.ch4.right.gate(self.four);
[ [
self.mix_channel(left, mixer.vol_left), self.mix_channel(left, mixer.vol_left),
self.mix_channel(right, mixer.vol_right), self.mix_channel(right, mixer.vol_right),

View file

@ -34,10 +34,10 @@ pub(super) enum Volume {
} }
impl Volume { impl Volume {
pub(super) fn scale(&self) -> f32 { pub(super) fn gate(&self, val: f32) -> f32 {
match self { match self {
Volume::Muted => 0., Volume::Muted => 0.,
Volume::Enabled => 1., Volume::Enabled => val,
} }
} }