fix speed being off by 1% 😭
This commit is contained in:
parent
dd6df41ac2
commit
d001e0d0e2
|
@ -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 {
|
||||
|
|
Loading…
Reference in a new issue