Skip to main content

ProcessorChain

Struct ProcessorChain 

Source
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

Source

pub fn new(layout: ChannelLayout) -> Self

Creates an empty chain for a validated layout.

Source

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.

Source

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.

Source

pub fn passes_through(&self) -> bool

Whether Self::process would only copy input to output (empty or unprepared), so a host may skip it.

Source

pub fn is_prepared(&self) -> bool

Whether the chain has been prepared since its processors last changed.

Source

pub fn prepare(&mut self, sample_rate: u32, max_block: usize)

Allocates scratch and prepares every node.

Source

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.

Source

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.

Source

pub fn latency_samples(&self) -> u32

Sum of serial node latencies; zero while unprepared.

Source

pub fn history_samples(&self) -> u32

Sum of serial processor settling horizons, excluding their delays.

Source

pub fn reset(&mut self)

Clears all histories.

Source

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.

Source

pub fn save_state(&self) -> StateBlob

Serializes each processor state with length framing, then the bypass record.

Source

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.

Source

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.

Source

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.

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> 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 = !

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

fn try_from(value: U) -> Result<T, !>

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.