Skip to main content

Downsample

Struct Downsample 

Source
pub struct Downsample(pub u32);
Expand description

Scalar downsampler with explicit tick phase.

The first input sample produces Some(x), then rate input samples produce None, and the pattern repeats. This matches the phase convention used by crate::Decimator when wrapping a scalar X -> Option<Y> processor into a chunked one.

Use this when the stream is still scalar and phase must be tracked across time. It does not by itself turn a chunk [X; N] into one output Y; pair it with Decimator or TryDecimator for that.

Together with crate::Hold, this forms the scalar optional-sample pair: Downsample removes samples by emitting None, while Hold fills those gaps again by repeating the last present sample.

Compare with:

  • crate::Rate: stateless chunk-slot conversion
  • Decimator: chunk adapter over a scalar X -> Option<Y> stage

State is the current countdown and should usually be initialized to 0.

§Examples

use dsp_process::{Downsample, SplitProcess};

let ds = Downsample(2);
let mut state = 0;
assert_eq!(ds.process(&mut state, 10), Some(10));
assert_eq!(ds.process(&mut state, 11), None);
assert_eq!(ds.process(&mut state, 12), None);
assert_eq!(ds.process(&mut state, 13), Some(13));

Tuple Fields§

§0: u32

Trait Implementations§

Source§

impl Clone for Downsample

Source§

fn clone(&self) -> Downsample

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for Downsample

Source§

impl Debug for Downsample

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Downsample

Source§

fn default() -> Downsample

Returns the “default value” for a type. Read more
Source§

impl<X: Copy> SplitProcess<X, Option<X>, u32> for Downsample

Source§

fn process(&self, state: &mut u32, x: X) -> Option<X>

Process an input into an output Read more
Source§

fn block(&self, state: &mut S, x: &[X], y: &mut [Y])

Process a block of inputs Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<'a, 'b, X, Y, S, T, const L: usize> SplitViewProcess<View<'a, X, FrameMajor, L>, ViewMut<'b, Y, FrameMajor, L>, S> for T
where X: Copy, T: SplitProcess<X, Y, S>, S: ?Sized,

Source§

fn process_view( &self, state: &mut S, x: View<'a, X, FrameMajor, L>, y: ViewMut<'b, Y, FrameMajor, L>, )

Process one typed input view into one typed output view.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.