Struct hexodsp::nodes::visual_sampling_filter::VisualSamplingFilter
source · [−]pub struct VisualSamplingFilter {
recalc_state: bool,
write_ptr: usize,
sample_buffer: [f32; 10],
last_output: (f32, f32),
}
Expand description
Accumulates the values for a single visible feedback value, like an LED (crate::Matrix::led_value_for) or the output feedbacks crate::Matrix::out_fb_for from the crate::Matrix.
Fields
recalc_state: bool
Holds a state bit, that is used to check if this filter needs to recalculate or not.
write_ptr: usize
Current write head into the sample buffer.
sample_buffer: [f32; 10]
Holds a set of the most recent samples to calculate the output.
last_output: (f32, f32)
Holds the last output, will only be recalculated when necessary.
Implementations
sourceimpl VisualSamplingFilter
impl VisualSamplingFilter
pub fn new() -> Self
sourcefn needs_recalc(&mut self, recalc_value: bool) -> bool
fn needs_recalc(&mut self, recalc_value: bool) -> bool
Used to check if we need to update this filter.
sourcepub fn get(&mut self, recalc_value: bool, sample: f32) -> (f32, f32)
pub fn get(&mut self, recalc_value: bool, sample: f32) -> (f32, f32)
Retrieves the current output value of the filter.
Negate the input for recalc_value
one each frame,
to reduce access to the retrieve_fn
to be done only
once per frame and per VisualSamplingFilter.
use hexodsp::nodes::visual_sampling_filter::*;
let mut vsf = VisualSamplingFilter::new();
let inputs = [-0.87, -0.8, 0.2, 0.75, 0.5, 0.0, 0.22];
let mut recalc = true;
let mut last_output = (0.0, 0.0);
for ip in inputs {
last_output = vsf.get(recalc, ip);
recalc = !recalc;
}
assert_eq!(last_output, (0.87, 0.75));
Trait Implementations
sourceimpl Clone for VisualSamplingFilter
impl Clone for VisualSamplingFilter
sourcefn clone(&self) -> VisualSamplingFilter
fn clone(&self) -> VisualSamplingFilter
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moresourceimpl Debug for VisualSamplingFilter
impl Debug for VisualSamplingFilter
impl Copy for VisualSamplingFilter
Auto Trait Implementations
impl RefUnwindSafe for VisualSamplingFilter
impl Send for VisualSamplingFilter
impl Sync for VisualSamplingFilter
impl Unpin for VisualSamplingFilter
impl UnwindSafe for VisualSamplingFilter
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more