diff --git a/lib/src/processor/memory/mmio/apu/downsampler.rs b/lib/src/processor/memory/mmio/apu/downsampler.rs index d7ba281..926483a 100644 --- a/lib/src/processor/memory/mmio/apu/downsampler.rs +++ b/lib/src/processor/memory/mmio/apu/downsampler.rs @@ -1,7 +1,5 @@ use crate::{connect::DownsampleType, constants::CLOCK_SPEED}; -const TIME_PER_CYCLE: f32 = 1. / CLOCK_SPEED as f32; - struct Averager { accum: [f32; 2], num: usize, @@ -48,7 +46,7 @@ pub(super) struct Downsampler { impl Downsampler { pub fn new(sample_rate: f32, algo: DownsampleType) -> Self { Self { - ratio: 1. / sample_rate, + ratio: CLOCK_SPEED as f32 / sample_rate, time_accum: 0., average: match algo { DownsampleType::Linear => Some(Averager::default()), @@ -60,12 +58,12 @@ impl Downsampler { pub fn process(&mut self, signal: Vec<[f32; 2]>) -> Vec<[f32; 2]> { let mut output = vec![]; for ref val in signal { - self.time_accum += TIME_PER_CYCLE; + self.time_accum += 1.; if let Some(ref mut averager) = self.average { averager.push(val); } if self.time_accum >= self.ratio { - self.time_accum = 0.; + self.time_accum -= self.ratio; output.push(if let Some(ref mut averager) = self.average { averager.finish() } else {