From 3122c0cb418f70a02b6b76b3cf75423e34c99af6 Mon Sep 17 00:00:00 2001 From: Robbert van der Helm Date: Tue, 1 Mar 2022 17:33:22 +0100 Subject: [PATCH] Pass block references to the block smoother So you can't mess this up by passing the maximum block size instead. --- src/param/smoothing.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/param/smoothing.rs b/src/param/smoothing.rs index d358b8ed..9b0938b9 100644 --- a/src/param/smoothing.rs +++ b/src/param/smoothing.rs @@ -2,6 +2,8 @@ use atomic_float::AtomicF32; use parking_lot::{MappedMutexGuard, Mutex, MutexGuard}; use std::sync::atomic::{AtomicI32, Ordering}; +use crate::buffer::Block; + /// Controls if and how parameters gets smoothed. pub enum SmoothingStyle { /// No smoothing is applied. The parameter's `value` field contains the latest sample value @@ -140,9 +142,9 @@ impl Smoother { /// /// Returns a `None` value if the block length exceed's the allocated capacity. #[inline] - pub fn next_block(&self, block_len: usize) -> Option> { + pub fn next_block(&self, block: &Block) -> Option> { let mut block_values = self.block_values.lock(); - if block_values.len() < block_len { + if block_values.len() < block.len() { return None; } @@ -150,10 +152,10 @@ impl Smoother { // unsmoothed parts. Another worthwhile optimization would be to remember if the // buffer is already filled with the target value and [Self::is_smoothing()] is false. // In that case we wouldn't need to do anything ehre. - (&mut block_values[..block_len]).fill_with(|| self.next()); + (&mut block_values[..block.len()]).fill_with(|| self.next()); Some(MutexGuard::map(block_values, |values| { - &mut values[..block_len] + &mut values[..block.len()] })) }