Pass block references to the block smoother
So you can't mess this up by passing the maximum block size instead.
This commit is contained in:
parent
dffddfaf04
commit
3122c0cb41
|
@ -2,6 +2,8 @@ use atomic_float::AtomicF32;
|
||||||
use parking_lot::{MappedMutexGuard, Mutex, MutexGuard};
|
use parking_lot::{MappedMutexGuard, Mutex, MutexGuard};
|
||||||
use std::sync::atomic::{AtomicI32, Ordering};
|
use std::sync::atomic::{AtomicI32, Ordering};
|
||||||
|
|
||||||
|
use crate::buffer::Block;
|
||||||
|
|
||||||
/// Controls if and how parameters gets smoothed.
|
/// Controls if and how parameters gets smoothed.
|
||||||
pub enum SmoothingStyle {
|
pub enum SmoothingStyle {
|
||||||
/// No smoothing is applied. The parameter's `value` field contains the latest sample value
|
/// No smoothing is applied. The parameter's `value` field contains the latest sample value
|
||||||
|
@ -140,9 +142,9 @@ impl Smoother<f32> {
|
||||||
///
|
///
|
||||||
/// Returns a `None` value if the block length exceed's the allocated capacity.
|
/// Returns a `None` value if the block length exceed's the allocated capacity.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn next_block(&self, block_len: usize) -> Option<MappedMutexGuard<[f32]>> {
|
pub fn next_block(&self, block: &Block) -> Option<MappedMutexGuard<[f32]>> {
|
||||||
let mut block_values = self.block_values.lock();
|
let mut block_values = self.block_values.lock();
|
||||||
if block_values.len() < block_len {
|
if block_values.len() < block.len() {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -150,10 +152,10 @@ impl Smoother<f32> {
|
||||||
// unsmoothed parts. Another worthwhile optimization would be to remember if the
|
// 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.
|
// 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.
|
// 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| {
|
Some(MutexGuard::map(block_values, |values| {
|
||||||
&mut values[..block_len]
|
&mut values[..block.len()]
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue