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: CProcessor configuration
state: SProcessor state
Implementations§
Source§impl<C, S> Split<PerFrame<C>, S>
impl<C, S> Split<PerFrame<C>, S>
Sourcepub 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>,
)
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>, )
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]]);Sourcepub fn inplace_frames<'a, X, const L: usize>(
&mut self,
xy: ViewMut<'a, X, FrameMajor, L>,
)
pub fn inplace_frames<'a, X, const L: usize>( &mut self, xy: ViewMut<'a, X, FrameMajor, L>, )
Process a frame-major view in place frame by frame.
Source§impl<C, S> Split<C, S>
impl<C, S> Split<C, S>
Sourcepub fn minor<U>(self) -> Split<Minor<C, U>, S>
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.
Sourcepub fn major<U>(self) -> Split<Major<C, U>, S>
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.
Sourcepub fn parallel(self) -> Split<Parallel<C>, S>
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.
Sourcepub fn map(self) -> Split<Map<C>, S>
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.
Sourcepub fn chunk(self) -> Split<Chunk<C>, S>
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.
Sourcepub fn interpolate(self) -> Split<Interpolator<C>, S>
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.
Sourcepub fn decimate(self) -> Split<Decimator<C>, S>
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>.
Sourcepub fn try_decimate(self) -> Split<TryDecimator<C>, S>
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.
Sourcepub fn per_frame(self) -> Split<PerFrame<C>, S>
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]]);Sourcepub fn repeat<const N: usize>(self) -> Split<[C; N], [S; N]>
pub fn repeat<const N: usize>(self) -> Split<[C; N], [S; N]>
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.
Sourcepub fn lanes<const N: usize>(self) -> Split<Lanes<C>, [S; N]>where
S: Clone,
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]);Trait Implementations§
impl<C: Copy, S: Copy> Copy for Split<C, S>
Source§impl<C0, C1, S0, S1> From<(Split<C0, S0>, Split<C1, S1>)> for Split<(C0, C1), (S0, S1)>
Unzip two splits
impl<C0, C1, S0, S1> From<(Split<C0, S0>, Split<C1, S1>)> for Split<(C0, C1), (S0, S1)>
Unzip two splits
Source§impl<C, S, const N: usize> From<[Split<C, S>; N]> for Split<[C; N], [S; N]>
Unzip multiple splits
impl<C, S, const N: usize> From<[Split<C, S>; N]> for Split<[C; N], [S; N]>
Unzip multiple splits