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

Multi-band compressor: crossover split, per-band compression, sum. More...

#include <MultibandCompressor.h>

Public Member Functions

void prepare (const AudioSpec &spec)
 Prepares the multiband compressor and internal buffers for processing.
 
void processBlock (AudioBufferView< T > buffer) noexcept
 Processes audio through the multi-band compressor.
 
void setNumBands (int n) noexcept
 Sets the number of active frequency bands.
 
void setNumBandsKeepingSplits (int n) noexcept
 Sets the number of active bands keeping the split frequencies (see CrossoverFilter::setNumBandsKeepingSplits()). Safe from any thread.
 
void setCrossoverFrequency (int index, T freqHz) noexcept
 Sets the crossover frequency for a specific split point.
 
void setOrder (int order) noexcept
 Sets the crossover slope in dB/oct: 12, 24 or 48.
 
void setCrossoverMode (typename CrossoverFilter< T, MaxBands >::FilterMode mode) noexcept
 Sets the phase/processing mode of the crossover (IIR or linear-phase).
 
void setCrossoverStructure (typename CrossoverFilter< T, MaxBands >::Structure structure) noexcept
 How the sections of the minimum-phase crossover are realised (see CrossoverFilter::setStructure(); any thread).
 
void setCrossoverTopology (typename CrossoverFilter< T, MaxBands >::Topology topology) noexcept
 Cascade or balanced arrangement of the minimum-phase splits (see CrossoverFilter::setTopology(); any thread).
 
Compressor< T > & getBandCompressor (int band) noexcept
 Direct access to a band's compressor for full configuration.
 
const Compressor< T > & getBandCompressor (int band) const noexcept
 Direct constant access to a band's compressor for state queries.
 
void setMix (T amount) noexcept
 The mix of every band at once, 0 (dry) to 1 (any thread).
 
void setBandThreshold (int band, T dB) noexcept
 Sets the threshold for a specific band.
 
void setBandRatio (int band, T ratio) noexcept
 Sets the ratio for a specific band.
 
void setBandAttack (int band, T ms) noexcept
 Sets the attack time for a specific band.
 
void setBandRelease (int band, T ms) noexcept
 Sets the release time for a specific band.
 
T getBandGainReductionDb (int band) const noexcept
 Gets the current gain reduction applied to a specific band.
 
int getNumBands () const noexcept
 Returns the current number of active bands.
 
T getCrossoverFrequency (int index) const noexcept
 Returns the target frequency of split point index in Hz.
 
int getOrder () const noexcept
 Returns the crossover slope in dB/oct (12, 24 or 48).
 
CrossoverFilter< T, MaxBands >::FilterMode getCrossoverMode () const noexcept
 Returns the crossover processing mode (IIR or linear-phase).
 
CrossoverFilter< T, MaxBands >::Structure getCrossoverStructure () const noexcept
 Returns the structure of the minimum-phase crossover.
 
CrossoverFilter< T, MaxBands >::Topology getCrossoverTopology () const noexcept
 Returns the arrangement of the minimum-phase splits.
 
int getLatency () const noexcept
 Returns the total latency of the multi-band system.
 
void reset () noexcept
 Resets all internal states (envelopes, delay lines, etc.).
 
std::vector< uint8_t > getState () const
 Serializes crossover topology and per-band compressor states.
 
bool setState (const uint8_t *data, size_t size)
 Restores topology and band compressors from a blob.
 

Detailed Description

template<FloatType T, int MaxBands = 12>
class dspark::MultibandCompressor< T, MaxBands >

Multi-band compressor: crossover split, per-band compression, sum.

Template Parameters
TSample type (float or double).
MaxBandsMaximum number of bands (compile-time, default 12).

Definition at line 59 of file MultibandCompressor.h.

Member Function Documentation

◆ getBandCompressor() [1/2]

template<FloatType T, int MaxBands = 12>
const Compressor< T > & dspark::MultibandCompressor< T, MaxBands >::getBandCompressor ( int  band) const
inlinenoexcept

Direct constant access to a band's compressor for state queries.

Parameters
bandBand index. Clamped safely to valid range in release mode.
Returns
Const reference to the requested Compressor.

Definition at line 272 of file MultibandCompressor.h.

◆ getBandCompressor() [2/2]

template<FloatType T, int MaxBands = 12>
Compressor< T > & dspark::MultibandCompressor< T, MaxBands >::getBandCompressor ( int  band)
inlinenoexcept

Direct access to a band's compressor for full configuration.

Parameters
bandBand index. Clamped safely to valid range in release mode.
Returns
Reference to the requested Compressor.

Definition at line 260 of file MultibandCompressor.h.

◆ getBandGainReductionDb()

template<FloatType T, int MaxBands = 12>
T dspark::MultibandCompressor< T, MaxBands >::getBandGainReductionDb ( int  band) const
inlinenoexcept

Gets the current gain reduction applied to a specific band.

Metering read, safe from any thread. Bands that are currently disabled report the value frozen from when they were last active.

Parameters
bandTarget band index.
Returns
Gain reduction in decibels (typically <= 0.0).

Definition at line 349 of file MultibandCompressor.h.

◆ getCrossoverFrequency()

template<FloatType T, int MaxBands = 12>
T dspark::MultibandCompressor< T, MaxBands >::getCrossoverFrequency ( int  index) const
inlinenoexcept

Returns the target frequency of split point index in Hz.

Definition at line 359 of file MultibandCompressor.h.

◆ getCrossoverMode()

template<FloatType T, int MaxBands = 12>
CrossoverFilter< T, MaxBands >::FilterMode dspark::MultibandCompressor< T, MaxBands >::getCrossoverMode ( ) const
inlinenoexcept

Returns the crossover processing mode (IIR or linear-phase).

Definition at line 368 of file MultibandCompressor.h.

◆ getCrossoverStructure()

template<FloatType T, int MaxBands = 12>
CrossoverFilter< T, MaxBands >::Structure dspark::MultibandCompressor< T, MaxBands >::getCrossoverStructure ( ) const
inlinenoexcept

Returns the structure of the minimum-phase crossover.

Definition at line 374 of file MultibandCompressor.h.

◆ getCrossoverTopology()

template<FloatType T, int MaxBands = 12>
CrossoverFilter< T, MaxBands >::Topology dspark::MultibandCompressor< T, MaxBands >::getCrossoverTopology ( ) const
inlinenoexcept

Returns the arrangement of the minimum-phase splits.

Definition at line 380 of file MultibandCompressor.h.

◆ getLatency()

template<FloatType T, int MaxBands = 12>
int dspark::MultibandCompressor< T, MaxBands >::getLatency ( ) const
inlinenoexcept

Returns the total latency of the multi-band system.

Definition at line 386 of file MultibandCompressor.h.

◆ getNumBands()

template<FloatType T, int MaxBands = 12>
int dspark::MultibandCompressor< T, MaxBands >::getNumBands ( ) const
inlinenoexcept

Returns the current number of active bands.

Definition at line 356 of file MultibandCompressor.h.

◆ getOrder()

template<FloatType T, int MaxBands = 12>
int dspark::MultibandCompressor< T, MaxBands >::getOrder ( ) const
inlinenoexcept

Returns the crossover slope in dB/oct (12, 24 or 48).

Definition at line 365 of file MultibandCompressor.h.

◆ getState()

template<FloatType T, int MaxBands = 12>
std::vector< uint8_t > dspark::MultibandCompressor< T, MaxBands >::getState ( ) const
inline

Serializes crossover topology and per-band compressor states.

Definition at line 406 of file MultibandCompressor.h.

◆ prepare()

template<FloatType T, int MaxBands = 12>
void dspark::MultibandCompressor< T, MaxBands >::prepare ( const AudioSpec &  spec)
inline

Prepares the multiband compressor and internal buffers for processing.

Invalid specs (non-positive/non-finite rate, block size or channel count) are ignored: the previous state is kept and an unprepared instance stays pass-through. May allocate; setup thread only.

Parameters
specThe audio specification (sample rate, max block size, channels).

Definition at line 75 of file MultibandCompressor.h.

◆ processBlock()

template<FloatType T, int MaxBands = 12>
void dspark::MultibandCompressor< T, MaxBands >::processBlock ( AudioBufferView< T >  buffer)
inlinenoexcept

Processes audio through the multi-band compressor.

Pass-through until prepare() succeeds. A block longer than the prepared maxBlockSize is processed in consecutive chunks of that size (the tail of an oversized block used to be left unprocessed: dry, unfiltered); channels beyond the prepared count pass through.

Parameters
bufferIn/Out audio buffer view.

Definition at line 102 of file MultibandCompressor.h.

◆ reset()

template<FloatType T, int MaxBands = 12>
void dspark::MultibandCompressor< T, MaxBands >::reset ( )
inlinenoexcept

Resets all internal states (envelopes, delay lines, etc.).

Definition at line 398 of file MultibandCompressor.h.

◆ setBandAttack()

template<FloatType T, int MaxBands = 12>
void dspark::MultibandCompressor< T, MaxBands >::setBandAttack ( int  band,
T  ms 
)
inlinenoexcept

Sets the attack time for a specific band.

Parameters
bandTarget band index.
msAttack time in milliseconds.

Definition at line 321 of file MultibandCompressor.h.

◆ setBandRatio()

template<FloatType T, int MaxBands = 12>
void dspark::MultibandCompressor< T, MaxBands >::setBandRatio ( int  band,
T  ratio 
)
inlinenoexcept

Sets the ratio for a specific band.

Parameters
bandTarget band index.
ratioCompression ratio (e.g., 4.0 for 4:1).

Definition at line 310 of file MultibandCompressor.h.

◆ setBandRelease()

template<FloatType T, int MaxBands = 12>
void dspark::MultibandCompressor< T, MaxBands >::setBandRelease ( int  band,
T  ms 
)
inlinenoexcept

Sets the release time for a specific band.

Parameters
bandTarget band index.
msRelease time in milliseconds.

Definition at line 332 of file MultibandCompressor.h.

◆ setBandThreshold()

template<FloatType T, int MaxBands = 12>
void dspark::MultibandCompressor< T, MaxBands >::setBandThreshold ( int  band,
T  dB 
)
inlinenoexcept

Sets the threshold for a specific band.

Parameters
bandTarget band index.
dBThreshold in decibels.

Definition at line 299 of file MultibandCompressor.h.

◆ setCrossoverFrequency()

template<FloatType T, int MaxBands = 12>
void dspark::MultibandCompressor< T, MaxBands >::setCrossoverFrequency ( int  index,
T  freqHz 
)
inlinenoexcept

Sets the crossover frequency for a specific split point.

Parameters
indexSplit point index (0 is between band 0 and 1).
freqHzTarget frequency in Hertz (non-finite values are ignored).

Definition at line 205 of file MultibandCompressor.h.

◆ setCrossoverMode()

template<FloatType T, int MaxBands = 12>
void dspark::MultibandCompressor< T, MaxBands >::setCrossoverMode ( typename CrossoverFilter< T, MaxBands >::FilterMode  mode)
inlinenoexcept

Sets the phase/processing mode of the crossover (IIR or linear-phase).

Linear phase adds the crossover's fixed latency (3072 samples at 48 kHz, whatever the block size; see CrossoverFilter::getLatency()), which getLatency() includes.

Parameters
modeSelected filter mode from the CrossoverFilter enum.

Definition at line 228 of file MultibandCompressor.h.

◆ setCrossoverStructure()

template<FloatType T, int MaxBands = 12>
void dspark::MultibandCompressor< T, MaxBands >::setCrossoverStructure ( typename CrossoverFilter< T, MaxBands >::Structure  structure)
inlinenoexcept

How the sections of the minimum-phase crossover are realised (see CrossoverFilter::setStructure(); any thread).

Parameters
structureDirectForm (default) or Ladder.

Definition at line 238 of file MultibandCompressor.h.

◆ setCrossoverTopology()

template<FloatType T, int MaxBands = 12>
void dspark::MultibandCompressor< T, MaxBands >::setCrossoverTopology ( typename CrossoverFilter< T, MaxBands >::Topology  topology)
inlinenoexcept

Cascade or balanced arrangement of the minimum-phase splits (see CrossoverFilter::setTopology(); any thread).

Parameters
topologyCascade (default) or Balanced.

Definition at line 248 of file MultibandCompressor.h.

◆ setMix()

template<FloatType T, int MaxBands = 12>
void dspark::MultibandCompressor< T, MaxBands >::setMix ( T  amount)
inlinenoexcept

The mix of every band at once, 0 (dry) to 1 (any thread).

Each band blends with itself as the crossover leaves it, so the sum is the programme through the crossover's phase blended with the compressed bands: a mix of one half is as flat as the crossover is. It sets each band's Compressor::setMix().

Definition at line 287 of file MultibandCompressor.h.

◆ setNumBands()

template<FloatType T, int MaxBands = 12>
void dspark::MultibandCompressor< T, MaxBands >::setNumBands ( int  n)
inlinenoexcept

Sets the number of active frequency bands.

Safe from any thread. A live change fades over (see CrossoverFilter::setNumBands) and re-initialises ALL split frequencies to the crossover's log-spaced defaults - reapply custom frequencies afterwards, or use setNumBandsKeepingSplits(). Compressors of newly enabled bands are reset on the audio thread so they start clean.

Parameters
nNumber of bands (clamped between 2 and MaxBands - a crossover needs at least one split point).

Definition at line 185 of file MultibandCompressor.h.

◆ setNumBandsKeepingSplits()

template<FloatType T, int MaxBands = 12>
void dspark::MultibandCompressor< T, MaxBands >::setNumBandsKeepingSplits ( int  n)
inlinenoexcept

Sets the number of active bands keeping the split frequencies (see CrossoverFilter::setNumBandsKeepingSplits()). Safe from any thread.

Parameters
nNumber of bands (clamped between 2 and MaxBands).

Definition at line 195 of file MultibandCompressor.h.

◆ setOrder()

template<FloatType T, int MaxBands = 12>
void dspark::MultibandCompressor< T, MaxBands >::setOrder ( int  order)
inlinenoexcept

Sets the crossover slope in dB/oct: 12, 24 or 48.

Parameters
orderSlope in dB/oct; other values are ignored (see CrossoverFilter::setOrder).

Definition at line 214 of file MultibandCompressor.h.

◆ setState()

template<FloatType T, int MaxBands = 12>
bool dspark::MultibandCompressor< T, MaxBands >::setState ( const uint8_t *  data,
size_t  size 
)
inline

Restores topology and band compressors from a blob.

Definition at line 430 of file MultibandCompressor.h.


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