DSPark 1.8.0
Header-only C++20 DSP for real-time and offline audio
Loading...
Searching...
No Matches
dspark::ProcessorChain< T, Processors > Class Template Reference

Compile-time chain of audio processors. More...

#include <ProcessorChain.h>

Public Member Functions

void prepare (const AudioSpec &spec)
 Prepares all processors in order.
 
void processBlock (AudioBufferView< T > buffer) noexcept
 Processes a buffer through all non-bypassed processors in order.
 
void reset () noexcept
 Resets the internal state of all processors (e.g., clearing delay lines).
 
template<std::size_t Index>
auto & get () noexcept
 Accesses the processor at the given index.
 
template<std::size_t Index>
const auto & get () const noexcept
 Const access to the processor at the given index.
 
int getLatency () const noexcept
 Returns the total latency in samples across all processors.
 
template<std::size_t Index>
void setBypassed (bool bypassed) noexcept
 Toggles bypass for a processor (control thread; the relaxed atomic word is adopted by the next processBlock()).
 
template<std::size_t Index>
bool isBypassed () const noexcept
 Reads the bypass state (lock-free readout, any thread).
 

Static Public Member Functions

static constexpr std::size_t size () noexcept
 Returns the number of processors in the chain.
 

Detailed Description

template<typename T, typename... Processors>
class dspark::ProcessorChain< T, Processors >

Compile-time chain of audio processors.

Processors are stored in a std::tuple and invoked in order. Access individual processors via get<Index>() to configure parameters.

Threading (SPSC model, see docs/threading.md): prepare()/reset() are setup-time (never concurrent with processing); processBlock() belongs to the audio thread; setBypassed<I>() belongs to the control thread (one independent relaxed atomic word per slot, adopted at the next processBlock()); isBypassed<I>() and getLatency() are lock-free readouts callable from any thread (each slot's getLatency() must itself be a lock-free readout, as the framework processors' are). get<I>() returns a reference whose thread contract is the slot processor's own.

Template Parameters
TSample type (float or double).
ProcessorsProcessor types. Must be greater than 0.

Definition at line 52 of file ProcessorChain.h.

Member Function Documentation

◆ get() [1/2]

template<typename T , typename... Processors>
template<std::size_t Index>
const auto & dspark::ProcessorChain< T, Processors >::get ( ) const
inlinenoexcept

Const access to the processor at the given index.

Template Parameters
IndexZero-based index into the chain.
Returns
Const reference to the processor.

Definition at line 110 of file ProcessorChain.h.

◆ get() [2/2]

template<typename T , typename... Processors>
template<std::size_t Index>
auto & dspark::ProcessorChain< T, Processors >::get ( )
inlinenoexcept

Accesses the processor at the given index.

Template Parameters
IndexZero-based index into the chain.
Returns
Reference to the processor.

Definition at line 97 of file ProcessorChain.h.

◆ getLatency()

template<typename T , typename... Processors>
int dspark::ProcessorChain< T, Processors >::getLatency ( ) const
inlinenoexcept

Returns the total latency in samples across all processors.

Reporters are detected at compile time via requires expressions and summed at runtime. Only processors providing a const getLatency() convertible to int contribute; a non-const getLatency() is a compile error rather than a silent zero.

Note
Latency is summed over ALL slots regardless of per-slot bypass, so the reported value stays constant when toggling bypass at runtime. This is deliberate: a fluctuating latency would force the host to re-issue plugin delay compensation on every bypass change.

Definition at line 137 of file ProcessorChain.h.

◆ isBypassed()

template<typename T , typename... Processors>
template<std::size_t Index>
bool dspark::ProcessorChain< T, Processors >::isBypassed ( ) const
inlinenoexcept

Reads the bypass state (lock-free readout, any thread).

Definition at line 167 of file ProcessorChain.h.

◆ prepare()

template<typename T , typename... Processors>
void dspark::ProcessorChain< T, Processors >::prepare ( const AudioSpec &  spec)
inline

Prepares all processors in order.

Parameters
specAudio specification.

Definition at line 64 of file ProcessorChain.h.

◆ processBlock()

template<typename T , typename... Processors>
void dspark::ProcessorChain< T, Processors >::processBlock ( AudioBufferView< T >  buffer)
inlinenoexcept

Processes a buffer through all non-bypassed processors in order.

Parameters
bufferAudio buffer (modified in-place by each processor).

Definition at line 75 of file ProcessorChain.h.

◆ reset()

template<typename T , typename... Processors>
void dspark::ProcessorChain< T, Processors >::reset ( )
inlinenoexcept

Resets the internal state of all processors (e.g., clearing delay lines).

Definition at line 83 of file ProcessorChain.h.

◆ setBypassed()

template<typename T , typename... Processors>
template<std::size_t Index>
void dspark::ProcessorChain< T, Processors >::setBypassed ( bool  bypassed)
inlinenoexcept

Toggles bypass for a processor (control thread; the relaxed atomic word is adopted by the next processBlock()).

Warning
This is a hard bypass. Toggling this during live playback will cause audio clicks/pops and phase discontinuities if the processor introduces latency. For real-time clickless bypass, prefer using dry/wet controls within the specific processor itself.
Template Parameters
IndexZero-based index into the chain.
Parameters
bypassedTrue to bypass, false to enable.

Definition at line 157 of file ProcessorChain.h.

◆ size()

template<typename T , typename... Processors>
static constexpr std::size_t dspark::ProcessorChain< T, Processors >::size ( )
inlinestaticconstexprnoexcept

Returns the number of processors in the chain.

Definition at line 119 of file ProcessorChain.h.


The documentation for this class was generated from the following file: