Skip to main content

Split

Struct Split 

Source
pub struct Split<C, S> {
    pub config: C,
    pub state: S,
}
Expand description

A stateful processor assembled from split configuration and state.

Split is the bridge between SplitProcess and Process: it stores the immutable configuration and mutable runtime state together so the pair can be passed around as a conventional stateful processor.

Reach for this when a split-state filter needs to be owned as one value, and use lanes(), minor(), or major() when changing how that owned processor is composed.

§Examples

use dsp_process::{Offset, Process, Split};

let mut p = Split::stateless(Offset(3));
assert_eq!(p.process(5), 8);

Fields§

§config: C

Processor configuration

§state: S

Processor state

Implementations§

Source§

impl<C, S> Split<PerFrame<C>, S>

Source

pub fn process_frames<'a, 'b, X, Y, const Q: usize, const R: usize>( &mut self, x: View<'a, X, FrameMajor, Q>, y: ViewMut<'b, Y, FrameMajor, R>, )
where X: Copy, C: SplitProcess<[X; Q], [Y; R], S>,

Process a frame-major view frame by frame.

use dsp_process::{ChunkInOut, FnSplitProcess, Split, View, ViewMut};

let mut p = Split::stateless(ChunkInOut::<_, 2, 1>(FnSplitProcess(
    |_: &mut (), [x0, x1]: [i32; 2]| [x0 + x1],
)))
.per_frame();
let x = View::from_frames(&[[1, 2], [3, 4]]);
let mut y = [[0; 1]; 2];
let yv = ViewMut::from_frames(&mut y);
p.process_frames(x, yv);
assert_eq!(y, [[3], [7]]);
Source

pub fn inplace_frames<'a, X, const L: usize>( &mut self, xy: ViewMut<'a, X, FrameMajor, L>, )
where X: Copy, C: SplitInplace<[X; L], S>,

Process a frame-major view in place frame by frame.

Source§

impl<C, S> Split<C, S>

Source

pub const fn new(config: C, state: S) -> Self

Create a new Split from explicit configuration and state values.

Source

pub const fn assert_process<X: Copy, Y>(&self)
where Self: Process<X, Y>,

Statically assert that this implements Process<X, Y>

Source§

impl<C> Split<C, ()>

Source

pub fn stateless(config: C) -> Self

Create a Split with configuration only and unit state.

Source§

impl<S> Split<(), Unsplit<S>>

Source

pub fn stateful(state: S) -> Self

Create a Split with state only and unit configuration.

Source§

impl<C, S> Split<C, S>

Source

pub fn minor<U>(self) -> Split<Minor<C, U>, S>

Convert to Minor composition.

This keeps the same logical processor but requests sample-by-sample block()/inplace() execution of the wrapped serial composition.

Use this for small fine-grained stages, or when tuple composition must cross an intermediate type and the downstream stage is not SplitInplace for that intermediate. Avoid it when preserving stage-major slice processing is important for cache behavior or SIMD.

Source

pub fn major<U>(self) -> Split<Major<C, U>, S>

Convert to Major composition with an explicit intermediate buffer.

Use this when preserving stage-major slice processing is more important than avoiding an intermediate scratch buffer, especially for larger stages or stages with meaningful block() specializations.

Source

pub fn parallel(self) -> Split<Parallel<C>, S>

Convert to Parallel composition.

This expresses structural branching: each input lane is routed to the matching branch and outputs stay separate unless reduced explicitly.

Source

pub fn map(self) -> Split<Map<C>, S>

Map Option and Result around this processor.

This lifts the processor through outer Option/Result control flow while preserving the current state unchanged.

Source

pub fn chunk(self) -> Split<Chunk<C>, S>

Convert to elementwise fixed-size chunk processing.

This is the basic array-lifting adapter. Use the more specific chunk or rate adapters when samples must be regrouped rather than processed elementwise.

Source

pub fn interpolate(self) -> Split<Interpolator<C>, S>

Convert a scalar optional-input stage into chunk output mode.

This preserves stream phase across one input sample expanded into one output chunk. Prefer this over structural chunk regrouping when the inner stage is naturally Option<X> -> Y.

Source

pub fn decimate(self) -> Split<Decimator<C>, S>

Convert a scalar optional-output stage into unchecked chunk input mode.

This preserves stream phase across one input chunk collapsed into one output sample. Prefer this over structural chunk regrouping when the inner stage is naturally X -> Option<Y>.

Source

pub fn try_decimate(self) -> Split<TryDecimator<C>, S>

Convert a scalar optional-output stage into checked chunk input mode.

This is the checked form of decimate(), returning an error when the inner stage does not tick exactly once per input chunk.

Source

pub fn per_frame(self) -> Split<PerFrame<C>, S>

Treat each frame of a frame-major view as one chunk sample.

This bridges chunk-style processors such as crate::Chunk, crate::ChunkIn, crate::ChunkOut, and crate::ChunkInOut into the typed view API without changing the backing layout.

use dsp_process::{ChunkInOut, FnSplitProcess, Split, View, ViewMut};

let mut p = Split::stateless(ChunkInOut::<_, 2, 1>(FnSplitProcess(
    |_: &mut (), [x0, x1]: [i32; 2]| [x0 + x1],
)))
.per_frame();
let x = View::from_frames(&[[1, 2], [3, 4]]);
let mut y = [[0; 1]; 2];
let yv = ViewMut::from_frames(&mut y);
p.process_frames(x, yv);
assert_eq!(y, [[3], [7]]);
Source

pub fn repeat<const N: usize>(self) -> Split<[C; N], [S; N]>
where C: Clone, S: Clone,

Duplicate the processor by cloning both configuration and current state.

The current state is copied as-is. Use this only when duplicating the existing state is intentional, for example when seeding several identical branches from a known starting point.

Source

pub fn lanes<const N: usize>(self) -> Split<Lanes<C>, [S; N]>
where S: Clone,

Share one configuration across multiple cloned states via Lanes.

This is usually preferable to repeat() when the configuration should be shared but each lane needs its own mutable runtime state. For lane-major view processing, pair this with crate::View using crate::LaneMajor.

use dsp_process::{LaneMajor, Offset, Split, View, ViewMut, ViewProcess};

let mut p = Split::stateless(Offset(3)).lanes::<2>();
let x = View::<_, LaneMajor, 2>::from_flat(&[1, 2, 3, 10, 20, 30], 3);
let mut y = [0; 6];
let yv = ViewMut::<_, LaneMajor, 2>::from_flat(&mut y, 3);
ViewProcess::process_view(&mut p, x, yv);
assert_eq!(y, [4, 5, 6, 13, 23, 33]);
Source

pub fn by_lane(self) -> Split<ByLane<C>, S>

Convert to ByLane view semantics.

Scalar process() is unchanged. Use this when parallel branches should process lane-major views as long contiguous per-lane slices.

Source§

impl<C, S, U> Split<Minor<C, U>, S>

Source

pub fn inter(self) -> Split<C, S>

Strip minor

Source§

impl<C, S> Split<Parallel<C>, S>

Source

pub fn inter(self) -> Split<C, S>

Convert to serial

Source§

impl<C, S> Split<PerFrame<C>, S>

Source

pub fn inter(self) -> Split<C, S>

Remove per-frame view adaptation.

Source§

impl<C, S> Split<ByLane<C>, S>

Source

pub fn inter(self) -> Split<C, S>

Convert to ordinary view semantics.

Source§

impl<C, S, B> Split<Major<C, B>, S>

Source

pub fn inter(self) -> Split<C, S>

Remove major intermediate buffering

Source§

impl<C0, C1, S0, S1> Split<(C0, C1), (S0, S1)>

Source

pub fn zip(self) -> (Split<C0, S0>, Split<C1, S1>)

Zip up a split

Source§

impl<C, S, const N: usize> Split<[C; N], [S; N]>

Source

pub fn zip(self) -> [Split<C, S>; N]

Zip up a split

Trait Implementations§

Source§

impl<C0, C1, S0, S1> Add<Split<C1, S1>> for Split<C0, S0>

Unzip two splits into one parallel

Source§

type Output = Split<Parallel<(C0, C1)>, (S0, S1)>

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Split<C1, S1>) -> Self::Output

Performs the + operation. Read more
Source§

impl<C: Clone, S: Clone> Clone for Split<C, S>

Source§

fn clone(&self) -> Split<C, S>

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<C: Copy, S: Copy> Copy for Split<C, S>

Source§

impl<C: Debug, S: Debug> Debug for Split<C, S>

Source§

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

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

impl<C: Default, S: Default> Default for Split<C, S>

Source§

fn default() -> Split<C, S>

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

impl<C0, C1, S0, S1> From<(Split<C0, S0>, Split<C1, S1>)> for Split<(C0, C1), (S0, S1)>

Unzip two splits

Source§

fn from(value: (Split<C0, S0>, Split<C1, S1>)) -> Self

Converts to this type from the input type.
Source§

impl<C, S, const N: usize> From<[Split<C, S>; N]> for Split<[C; N], [S; N]>

Unzip multiple splits

Source§

fn from(splits: [Split<C, S>; N]) -> Self

Converts to this type from the input type.
Source§

impl<X: Copy, S, C: SplitInplace<X, S>> Inplace<X> for Split<C, S>

Source§

fn inplace(&mut self, xy: &mut [X])

Process an input block into the same data as output
Source§

impl<C0, C1, S0, S1> Mul<Split<C1, S1>> for Split<C0, S0>

Unzip two splits into one

Source§

type Output = Split<(C0, C1), (S0, S1)>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Split<C1, S1>) -> Self::Output

Performs the * operation. Read more
Source§

impl<X: Copy, Y, S, C: SplitProcess<X, Y, S>> Process<X, Y> for Split<C, S>

Source§

fn process(&mut self, x: X) -> Y

Update the state with a new input and obtain an output
Source§

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

Process a block of inputs into a block of outputs Read more
Source§

impl<X, C, S> ViewInplace<X> for Split<C, S>
where C: SplitViewInplace<X, S>,

Source§

fn inplace_view(&mut self, xy: X)

Process one typed view in place.
Source§

impl<X, Y, C, S> ViewProcess<X, Y> for Split<C, S>
where C: SplitViewProcess<X, Y, S>,

Source§

fn process_view(&mut self, x: X, y: Y)

Process one typed input view into one typed output view.

Auto Trait Implementations§

§

impl<C, S> Freeze for Split<C, S>
where C: Freeze, S: Freeze,

§

impl<C, S> RefUnwindSafe for Split<C, S>

§

impl<C, S> Send for Split<C, S>
where C: Send, S: Send,

§

impl<C, S> Sync for Split<C, S>
where C: Sync, S: Sync,

§

impl<C, S> Unpin for Split<C, S>
where C: Unpin, S: Unpin,

§

impl<C, S> UnsafeUnpin for Split<C, S>
where C: UnsafeUnpin, S: UnsafeUnpin,

§

impl<C, S> UnwindSafe for Split<C, S>
where C: UnwindSafe, S: UnwindSafe,

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<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.