|
DSPark 1.9.0
Header-only C++20 DSP for real-time and offline audio
|
Linkwitz-Riley crossover with 2-12 bands: 6, 12, 24, 36 or 48 dB per octave. More...
#include <CrossoverFilter.h>
Public Types | |
| enum class | FilterMode { MinimumPhase , LinearPhase } |
| Filter processing mode. More... | |
| enum class | Structure { DirectForm , Ladder } |
| How the minimum-phase sections are realised (see setStructure()). More... | |
| enum class | Topology { Cascade , Balanced } |
| How the splits of the minimum-phase engine are arranged (see setTopology()). More... | |
Public Member Functions | |
| CrossoverFilter () | |
| void | prepare (const AudioSpec &spec) |
| Prepares the crossover for processing. | |
| int | processBlock (AudioBufferView< T > input, AudioBufferView< T > *bandOutputs, int numOutputBands) noexcept |
| Splits input into separate band outputs. | |
| void | setNumBands (int n) noexcept |
| Sets the number of output bands (2..MaxBands). | |
| void | setNumBandsKeepingSplits (int n) noexcept |
| Sets the number of output bands (2..MaxBands) and keeps the splits. | |
| void | setCrossoverFrequency (int index, T freqHz) noexcept |
| Sets a crossover frequency. Automatically maintains sorting. | |
| void | setOrder (int order) noexcept |
| Sets the crossover slope: 6, 12, 24, 36 or 48 (dB/oct). Other values are ignored. | |
| void | setFilterMode (FilterMode mode) noexcept |
| Sets the processing mode. A live switch resets filter state (transient). | |
| void | setStructure (Structure structure) noexcept |
| Chooses how the sections of the minimum-phase engine are realised. | |
| Structure | getStructure () const noexcept |
| The structure set by setStructure(). | |
| void | setTopology (Topology topology) noexcept |
| Arranges the splits of the minimum-phase engine. | |
| Topology | getTopology () const noexcept |
| The arrangement set by setTopology(). | |
| int | getNumBands () const noexcept |
| int | getOrder () const noexcept |
| FilterMode | getFilterMode () const noexcept |
| T | getCrossoverFrequency (int index) const noexcept |
Returns the target frequency of split point index. | |
| int | getLatency () const noexcept |
| Returns latency in samples: 0 for IIR; for linear-phase, three quarters of the FIR (3072 at 48 kHz), whatever the block size. | |
| void | reset () noexcept |
| std::vector< uint8_t > | getState () const |
| Serializes the split topology (setup/UI threads; allocates). | |
| bool | setState (const uint8_t *data, size_t size) |
| Restores the split topology from a blob. | |
Linkwitz-Riley crossover with 2-12 bands: 6, 12, 24, 36 or 48 dB per octave.
| T | Sample type (float or double). |
| MaxBands | Maximum number of output bands (compile-time, default 12). |
Definition at line 149 of file CrossoverFilter.h.
|
strong |
Filter processing mode.
| Enumerator | |
|---|---|
| MinimumPhase | IIR biquads with allpass phase correction (zero latency). |
| LinearPhase | FFT-based FIR crossover (introduces latency, zero phase distortion, introduces pre-ringing). |
Definition at line 153 of file CrossoverFilter.h.
|
strong |
How the minimum-phase sections are realised (see setStructure()).
| Enumerator | |
|---|---|
| DirectForm | Direct form with a double memory, all sections in one pass (default). |
| Ladder | Normalized ladders: passive under any movement of the splits. |
Definition at line 556 of file CrossoverFilter.h.
|
strong |
How the splits of the minimum-phase engine are arranged (see setTopology()).
| Enumerator | |
|---|---|
| Cascade | Each split takes what the one below left above it (default). |
| Balanced | The middle split first, each half divided the same way. |
Definition at line 592 of file CrossoverFilter.h.
|
inline |
Definition at line 159 of file CrossoverFilter.h.
|
inlinenoexcept |
Returns the target frequency of split point index.
Definition at line 632 of file CrossoverFilter.h.
|
inlinenoexcept |
Definition at line 629 of file CrossoverFilter.h.
|
inlinenoexcept |
Returns latency in samples: 0 for IIR; for linear-phase, three quarters of the FIR (3072 at 48 kHz), whatever the block size.
Reports the linear-phase latency only when the engine actually exists (see prepare()); if linear-phase mode fell back to IIR, this returns 0.
Definition at line 645 of file CrossoverFilter.h.
|
inlinenoexcept |
Definition at line 627 of file CrossoverFilter.h.
|
inlinenoexcept |
Definition at line 628 of file CrossoverFilter.h.
|
inline |
Serializes the split topology (setup/UI threads; allocates).
Definition at line 681 of file CrossoverFilter.h.
|
inlinenoexcept |
The structure set by setStructure().
Definition at line 589 of file CrossoverFilter.h.
|
inlinenoexcept |
The arrangement set by setTopology().
Definition at line 623 of file CrossoverFilter.h.
|
inline |
Prepares the crossover for processing.
Configured split frequencies, band count, order and mode are preserved across prepare() calls (configure-then-prepare is fully supported). The linear-phase engine is always allocated (so a later mode switch works); its size depends on the sample rate and channel count only.
| spec | Audio environment (sample rate, block size, channels). Invalid specs are ignored (previous state is kept). |
Definition at line 177 of file CrossoverFilter.h.
|
inlinenoexcept |
Splits input into separate band outputs.
The processed span is clamped to the prepared maxBlockSize and to the shortest output view. The linear-phase engine buffers internally, so any block size up to maxBlockSize gives the same output. Input channels beyond the prepared/16-channel limit are passed through on band 0 (remaining bands silent) so the band sum still reconstructs the input.
| input | Input audio buffer. |
| bandOutputs | Array of AudioBufferView, one per band. |
| numOutputBands | Number of output bands (must match getNumBands(); fewer bands re-purpose the first splits only in IIR mode and is not a supported configuration). |
Definition at line 334 of file CrossoverFilter.h.
|
inlinenoexcept |
Definition at line 651 of file CrossoverFilter.h.
|
inlinenoexcept |
Sets a crossover frequency. Automatically maintains sorting.
Non-finite frequencies are ignored; values are floored to 1 Hz here and clamped to [20, 0.499 * sampleRate] at design time.
Definition at line 485 of file CrossoverFilter.h.
|
inlinenoexcept |
Sets the processing mode. A live switch resets filter state (transient).
Definition at line 547 of file CrossoverFilter.h.
|
inlinenoexcept |
Sets the number of output bands (2..MaxBands).
Definition at line 443 of file CrossoverFilter.h.
|
inlinenoexcept |
Sets the number of output bands (2..MaxBands) and keeps the splits.
The split frequencies do not depend on the band count: the count only says how many of the splits are used. A split that stays keeps its frequency (and, in the minimum-phase engine, its memory); a split that comes back takes the frequency it had, or, when that is not above the split below it, the point halfway in octaves between that split and 20 kHz. The change itself goes over as setNumBands() describes. Thread-safe.
Definition at line 462 of file CrossoverFilter.h.
|
inlinenoexcept |
Sets the crossover slope: 6, 12, 24, 36 or 48 (dB/oct). Other values are ignored.
12 to 48 are Linkwitz-Riley splits (the bands sum to an allpass of the input; each branch is 6 dB down at the split). 6 is a first-order low-pass and its complement (the bands sum to the input itself; each branch is 3 dB down at the split in the minimum-phase engine and 6 dB in the linear-phase one).
Definition at line 536 of file CrossoverFilter.h.
|
inline |
Restores the split topology from a blob.
Definition at line 700 of file CrossoverFilter.h.
|
inlinenoexcept |
Chooses how the sections of the minimum-phase engine are realised.
Ladder runs every section of the splits and of the phase correction as a normalized ladder (NormalizedLadder): the same band responses (to 4e-9), and a memory that can only lose energy however its coefficients move. During a glide the ladders' coefficients ramp linearly from one refresh of the 32-sample grid to the next instead of stepping. Measured on four bands in stereo it costs 2.4 to 6.3 times the direct form. The 5 ms glide of the splits already keeps the direct form's memory consistent with its coefficients: with a split jumping between 100 Hz and 10 kHz every 64 samples, the band sum of 0.3 of noise peaks at 0.65 either way at LR24 (0.70 ladder, 0.64 direct at LR48), so the ladder is for those who want the guarantee rather than a lower peak. The ladders are allocated by prepare() on the heap, so the switch itself never allocates. Thread-safe; the switch restarts the sections' memory at the next block, which may click: choose it before playback. The linear-phase engine is unaffected.
| structure | DirectForm (default) or Ladder. |
Definition at line 582 of file CrossoverFilter.h.
|
inlinenoexcept |
Arranges the splits of the minimum-phase engine.
Cascade splits the lowest band off first and passes what is left on; each band then takes the phase correction of every split above it, S(S-1)/2 chains for S splits (10 with 6 bands, 55 with 12). Balanced splits at the middle split first and divides each half the same way; each branch takes the corrections of the splits of the other half once, before it is divided (6 chains with 6 bands, 22 with 12). The bands still sum to the same allpass, but their skirts differ: a band carries the slopes of the splits on its way down the tree rather than every split below it, so some skirts fall faster and others slower than in the cascade. A live change goes over without a step (both arrangements run for 20 ms on separate memories and the bands move from one to the other). Thread-safe. The linear-phase engine is unaffected.
| topology | Cascade (default) or Balanced. |
Definition at line 616 of file CrossoverFilter.h.