pub struct ProcessorChain { /* private fields */ }Expand description
Ordered processor chain with all realtime scratch allocated by prepare.
Until prepared (initially and after each push), a chain passes its input through.
Each node’s context is moved back by the latency of the nodes before it, so sample-addressed nodes (fades, automation) after a lookahead act on the audio they receive.
Implementations§
Source§impl ProcessorChain
impl ProcessorChain
Sourcepub fn new(layout: ChannelLayout) -> Self
pub fn new(layout: ChannelLayout) -> Self
Creates an empty chain for a validated layout.
Sourcepub fn push(
&mut self,
processor: impl Processor + 'static,
) -> Result<(), ChainError>
pub fn push( &mut self, processor: impl Processor + 'static, ) -> Result<(), ChainError>
Adds a processor outside the realtime path. The chain passes input through until prepared again.
§Errors
Returns ChainError::MultipleInputs for a processor that reads more than one input per
output.
Sourcepub fn set_bypass(&mut self, bypass: bool)
pub fn set_bypass(&mut self, bypass: bool)
Sets or clears bypass, outside the realtime path.
A bypassed chain plays its input delayed by Self::latency_samples so hosts stay
aligned, and keeps running its nodes so ending the bypass resumes on current audio. The
delayed input record starts with the first call; until it fills, the gap plays silence.
Chains never bypassed keep no record.
Sourcepub fn passes_through(&self) -> bool
pub fn passes_through(&self) -> bool
Whether Self::process would only copy input to output (empty or unprepared), so a host
may skip it.
Sourcepub fn is_prepared(&self) -> bool
pub fn is_prepared(&self) -> bool
Whether the chain has been prepared since its processors last changed.
Sourcepub fn prepare(&mut self, sample_rate: u32, max_block: usize)
pub fn prepare(&mut self, sample_rate: u32, max_block: usize)
Allocates scratch and prepares every node.
Sourcepub fn prepare_nodes(&mut self, sample_rate: u32, max_block: usize)
pub fn prepare_nodes(&mut self, sample_rate: u32, max_block: usize)
Prepares the nodes without allocating chain scratch, for chains run only through
Self::process_in_place. Self::process passes input through until Self::prepare.
Sourcepub fn process_in_place(
&mut self,
ctx: &ProcessCtx,
buffer: &mut [Vec<f32>; 2],
spare: &mut [Vec<f32>; 2],
frames: usize,
)
pub fn process_in_place( &mut self, ctx: &ProcessCtx, buffer: &mut [Vec<f32>; 2], spare: &mut [Vec<f32>; 2], frames: usize, )
Processes the first frames samples of each buffer channel in place without
allocating. spare holds intermediate node output and may swap allocations with buffer;
both need frames samples per layout channel.
Sourcepub fn latency_samples(&self) -> u32
pub fn latency_samples(&self) -> u32
Sum of serial node latencies; zero while unprepared.
Sourcepub fn history_samples(&self) -> u32
pub fn history_samples(&self) -> u32
Sum of serial processor settling horizons, excluding their delays.
Sourcepub fn process(
&mut self,
ctx: &ProcessCtx,
inputs: &[&[f32]],
outputs: &mut [&mut [f32]],
)
pub fn process( &mut self, ctx: &ProcessCtx, inputs: &[&[f32]], outputs: &mut [&mut [f32]], )
Processes one block without allocating, covering the shortest input or output channel.
Blocks longer than max_block run in pieces. With missing layout channels the outputs are
silenced.
Sourcepub fn save_state(&self) -> StateBlob
pub fn save_state(&self) -> StateBlob
Serializes each processor state with length framing, then the bypass record.
Sourcepub fn load_state(&mut self, state: &StateBlob) -> Result<(), ChainStateError>
pub fn load_state(&mut self, state: &StateBlob) -> Result<(), ChainStateError>
Restores a state saved by a chain of the same nodes and preparation, atomically: if a node refuses, earlier nodes are rolled back.
A missing bypass record leaves this chain’s empty; a record this chain does not keep is dropped.
§Errors
Returns where and why the state was refused.
Sourcepub fn node_state(&self, index: usize) -> Option<StateBlob>
pub fn node_state(&self, index: usize) -> Option<StateBlob>
The Processor::save_state of the node at index, for carrying history across a chain
rebuild with Self::load_node_state.
Sourcepub fn load_node_state(
&mut self,
index: usize,
state: &StateBlob,
) -> Result<(), StateError>
pub fn load_node_state( &mut self, index: usize, state: &StateBlob, ) -> Result<(), StateError>
Restores the node at index from Self::node_state, atomically.
§Errors
Returns StateError::Mismatch past the last node, or the node’s own refusal.