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

Up to MaxSections second-order sections in series, run in one pass. More...

#include <BiquadCascade.h>

Public Member Functions

 BiquadCascade () noexcept
 
void setNumSections (int count) noexcept
 Sets how many sections the cascade has.
 
int getNumSections () const noexcept
 Number of sections in the cascade.
 
void setCoeffs (int section, const BiquadCoeffs &c) noexcept
 Makes a coefficient set a section's own from the next sample.
 
void rampCoeffs (int section, const BiquadCoeffs &target, int samples) noexcept
 Moves a section's five coefficients linearly to a set.
 
void rampToBypass (int section, int samples) noexcept
 Takes a section out of the path without a click.
 
BiquadCoeffs getCoeffs (int section) const noexcept
 The coefficients a section is using now (mid ramp, where the ramp is).
 
BiquadCoeffs getTargetCoeffs (int section) const noexcept
 The coefficients a section is heading to (its own when it is not ramping).
 
bool isRamping (int section) const noexcept
 Whether a section's coefficients are moving.
 
bool isRamping () const noexcept
 Whether any section's coefficients are moving.
 
void setSectionEnabled (int section, bool on) noexcept
 Switches a section in or out of the path.
 
bool isSectionEnabled (int section) const noexcept
 Whether a section is computed.
 
void reset () noexcept
 Clears the memory of every node. Coefficients and ramps are kept.
 
void processBlock (AudioBufferView< T > buffer) noexcept
 Runs a block through the cascade, in place.
 
double processSample (double input, int channel) noexcept
 One sample of one channel through the cascade, in double.
 
double processSample (double input, int channel, std::uint64_t skip) noexcept
 As processSample(), leaving some sections out for this call.
 
void turnPairMemory (int first, int second, bool back) noexcept
 Rewrites the memory of a pair of channels as its middle and its sides, or back.
 
void advanceRamps (int samples) noexcept
 Moves every ramp on by a number of samples (for processSample() callers).
 

Static Public Attributes

static constexpr int kGroup = 4
 Sections run together in one pass over the samples.
 

Detailed Description

template<typename T, int MaxSections = 8, int MaxChannels = 8>
class dspark::BiquadCascade< T, MaxSections, MaxChannels >

Up to MaxSections second-order sections in series, run in one pass.

Template Parameters
TSample type of the buffers (float or double). The recursion and its memory are double either way.
MaxSectionsLargest number of sections.
MaxChannelsLargest number of channels.

Definition at line 77 of file BiquadCascade.h.

Constructor & Destructor Documentation

◆ BiquadCascade()

template<typename T , int MaxSections = 8, int MaxChannels = 8>
dspark::BiquadCascade< T, MaxSections, MaxChannels >::BiquadCascade ( )
inlinenoexcept

Definition at line 83 of file BiquadCascade.h.

Member Function Documentation

◆ advanceRamps()

template<typename T , int MaxSections = 8, int MaxChannels = 8>
void dspark::BiquadCascade< T, MaxSections, MaxChannels >::advanceRamps ( int  samples)
inlinenoexcept

Moves every ramp on by a number of samples (for processSample() callers).

Parameters
samplesSamples gone by; a ramp with fewer left lands on its target.

Definition at line 407 of file BiquadCascade.h.

◆ getCoeffs()

template<typename T , int MaxSections = 8, int MaxChannels = 8>
BiquadCoeffs dspark::BiquadCascade< T, MaxSections, MaxChannels >::getCoeffs ( int  section) const
inlinenoexcept

The coefficients a section is using now (mid ramp, where the ramp is).

Definition at line 179 of file BiquadCascade.h.

◆ getNumSections()

template<typename T , int MaxSections = 8, int MaxChannels = 8>
int dspark::BiquadCascade< T, MaxSections, MaxChannels >::getNumSections ( ) const
inlinenoexcept

Number of sections in the cascade.

Definition at line 111 of file BiquadCascade.h.

◆ getTargetCoeffs()

template<typename T , int MaxSections = 8, int MaxChannels = 8>
BiquadCoeffs dspark::BiquadCascade< T, MaxSections, MaxChannels >::getTargetCoeffs ( int  section) const
inlinenoexcept

The coefficients a section is heading to (its own when it is not ramping).

Definition at line 185 of file BiquadCascade.h.

◆ isRamping() [1/2]

template<typename T , int MaxSections = 8, int MaxChannels = 8>
bool dspark::BiquadCascade< T, MaxSections, MaxChannels >::isRamping ( ) const
inlinenoexcept

Whether any section's coefficients are moving.

Definition at line 197 of file BiquadCascade.h.

◆ isRamping() [2/2]

template<typename T , int MaxSections = 8, int MaxChannels = 8>
bool dspark::BiquadCascade< T, MaxSections, MaxChannels >::isRamping ( int  section) const
inlinenoexcept

Whether a section's coefficients are moving.

Definition at line 191 of file BiquadCascade.h.

◆ isSectionEnabled()

template<typename T , int MaxSections = 8, int MaxChannels = 8>
bool dspark::BiquadCascade< T, MaxSections, MaxChannels >::isSectionEnabled ( int  section) const
inlinenoexcept

Whether a section is computed.

Definition at line 222 of file BiquadCascade.h.

◆ processBlock()

template<typename T , int MaxSections = 8, int MaxChannels = 8>
void dspark::BiquadCascade< T, MaxSections, MaxChannels >::processBlock ( AudioBufferView< T >  buffer)
inlinenoexcept

Runs a block through the cascade, in place.

Channels beyond MaxChannels are left untouched. A memory that a non-finite sample has reached is cleared at the end of the block, so the channel recovers on the next one.

Parameters
bufferAudio to filter.

Definition at line 243 of file BiquadCascade.h.

◆ processSample() [1/2]

template<typename T , int MaxSections = 8, int MaxChannels = 8>
double dspark::BiquadCascade< T, MaxSections, MaxChannels >::processSample ( double  input,
int  channel 
)
inlinenoexcept

One sample of one channel through the cascade, in double.

Uses the coefficients as they are: ramps advance in processBlock(), or by the caller's advanceRamps() once per frame.

Precondition
channel in [0, MaxChannels).
Parameters
inputInput sample.
channelChannel index.
Returns
Output of the last enabled section.

Definition at line 302 of file BiquadCascade.h.

◆ processSample() [2/2]

template<typename T , int MaxSections = 8, int MaxChannels = 8>
double dspark::BiquadCascade< T, MaxSections, MaxChannels >::processSample ( double  input,
int  channel,
std::uint64_t  skip 
)
inlinenoexcept

As processSample(), leaving some sections out for this call.

A section whose bit is set in skip (bit s for section s) is not computed for this sample: what reaches it goes on to the next section and its own memory for the channel stays as it was. A cascade whose sections act on some channels only (an equalizer with bands for the middle or for the sides of a pair) passes each channel the mask of the sections that are not for it, the same mask on every sample.

Precondition
channel in [0, MaxChannels); MaxSections of 64 at most.
Parameters
inputInput sample.
channelChannel index.
skipSections to leave out, one bit each.
Returns
Output of the last enabled section that was not left out.

Definition at line 342 of file BiquadCascade.h.

◆ rampCoeffs()

template<typename T , int MaxSections = 8, int MaxChannels = 8>
void dspark::BiquadCascade< T, MaxSections, MaxChannels >::rampCoeffs ( int  section,
const BiquadCoeffs &  target,
int  samples 
)
inlinenoexcept

Moves a section's five coefficients linearly to a set.

The ramp starts from the coefficients in use (wherever a ramp in flight has brought them) and lands exactly on the target after samples samples.

Parameters
sectionSection index in [0, MaxSections); others are ignored.
targetCoefficients to arrive at.
samplesLength of the ramp in samples; 0 or less sets the target at once.

Definition at line 145 of file BiquadCascade.h.

◆ rampToBypass()

template<typename T , int MaxSections = 8, int MaxChannels = 8>
void dspark::BiquadCascade< T, MaxSections, MaxChannels >::rampToBypass ( int  section,
int  samples 
)
inlinenoexcept

Takes a section out of the path without a click.

Ramps the numerator of the section to its denominator: the poles and the memory keep running and what the section adds to its input dies away. Once the ramp is over the section passes its input (to rounding) and can be disabled.

Parameters
sectionSection index.
samplesLength of the ramp in samples.

Definition at line 172 of file BiquadCascade.h.

◆ reset()

template<typename T , int MaxSections = 8, int MaxChannels = 8>
void dspark::BiquadCascade< T, MaxSections, MaxChannels >::reset ( )
inlinenoexcept

Clears the memory of every node. Coefficients and ramps are kept.

Definition at line 228 of file BiquadCascade.h.

◆ setCoeffs()

template<typename T , int MaxSections = 8, int MaxChannels = 8>
void dspark::BiquadCascade< T, MaxSections, MaxChannels >::setCoeffs ( int  section,
const BiquadCoeffs &  c 
)
inlinenoexcept

Makes a coefficient set a section's own from the next sample.

Ends any ramp of the section. The state is signal, so the section carries on from what it has played; a large change is still a step in its response (use rampCoeffs() to glide).

Parameters
sectionSection index in [0, MaxSections); others are ignored.
cThe coefficients.

Definition at line 123 of file BiquadCascade.h.

◆ setNumSections()

template<typename T , int MaxSections = 8, int MaxChannels = 8>
void dspark::BiquadCascade< T, MaxSections, MaxChannels >::setNumSections ( int  count)
inlinenoexcept

Sets how many sections the cascade has.

Sections from the new count on are left out of the path as they are (their coefficients are kept); a section that comes into the path starts from the history of its input.

Parameters
countNumber of sections, clamped to [0, MaxSections].

Definition at line 99 of file BiquadCascade.h.

◆ setSectionEnabled()

template<typename T , int MaxSections = 8, int MaxChannels = 8>
void dspark::BiquadCascade< T, MaxSections, MaxChannels >::setSectionEnabled ( int  section,
bool  on 
)
inlinenoexcept

Switches a section in or out of the path.

A switch, not a fade: disable a section once it is transparent (after rampToBypass(), or while its coefficients are a bypassed() set) and it leaves without a trace. A disabled section is not computed. Enabled again it starts from the history of its input, so enabling a transparent section is silent too.

Parameters
sectionSection index in [0, MaxSections); others are ignored.
onTrue to compute the section.

Definition at line 211 of file BiquadCascade.h.

◆ turnPairMemory()

template<typename T , int MaxSections = 8, int MaxChannels = 8>
void dspark::BiquadCascade< T, MaxSections, MaxChannels >::turnPairMemory ( int  first,
int  second,
bool  back 
)
inlinenoexcept

Rewrites the memory of a pair of channels as its middle and its sides, or back.

The memory of the cascade is signal. A caller that has been giving the cascade the two channels of a pair and goes on to give it, in the same two channels, their half sum and their half difference can take the memory with it: every node of the first channel becomes the half sum of the two and every node of the second their half difference, and the sections carry on as if they had been fed that way all along (exact for the sections that run both channels, which share their coefficients). The way back is the sum and the difference.

Parameters
firstChannel that holds the left, or the middle.
secondChannel that holds the right, or the sides.
backFalse: left and right become middle and sides. True: the other way.

Definition at line 386 of file BiquadCascade.h.

Member Data Documentation

◆ kGroup

template<typename T , int MaxSections = 8, int MaxChannels = 8>
constexpr int dspark::BiquadCascade< T, MaxSections, MaxChannels >::kGroup = 4
staticconstexpr

Sections run together in one pass over the samples.

Definition at line 81 of file BiquadCascade.h.


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