|
DSPark 1.9.0
Header-only C++20 DSP for real-time and offline audio
|
Functions | |
| bool | runtimeDispatchSupported () noexcept |
| Whether this build carries AVX2+FMA kernels and the CPU can run them. | |
| bool | isRuntimeDispatchActive () noexcept |
| Whether the AVX2+FMA kernels are selected now (see setRuntimeDispatch()). | |
| void | setRuntimeDispatch (bool enabled) noexcept |
| Selects or deselects the AVX2+FMA kernels (on by default where runtimeDispatchSupported()). | |
| void | addWithGain (float *DSPARK_RESTRICT dst, const float *DSPARK_RESTRICT src, float gain, int count) noexcept |
| Adds source samples scaled by a gain factor into a destination buffer. | |
| void | addWithGain (double *DSPARK_RESTRICT dst, const double *DSPARK_RESTRICT src, double gain, int count) noexcept |
| Double overload. | |
| void | applyGain (float *DSPARK_RESTRICT data, float gain, int count) noexcept |
| Multiplies all samples in a buffer by a gain factor. | |
| void | applyGain (double *DSPARK_RESTRICT data, double gain, int count) noexcept |
| Double overload. | |
| float | peakLevel (const float *DSPARK_RESTRICT data, int count) noexcept |
| Returns the peak absolute sample value in a buffer. | |
| double | peakLevel (const double *DSPARK_RESTRICT data, int count) noexcept |
| Double overload. NaN samples are ignored, as in the float version. | |
| float | dotProduct (const float *DSPARK_RESTRICT a, const float *DSPARK_RESTRICT b, int count) noexcept |
| Computes the dot product of two arrays. | |
| double | dotProduct (const double *DSPARK_RESTRICT a, const double *DSPARK_RESTRICT b, int count) noexcept |
| Double overload. | |
| void | dotProduct4 (const double *shared, const double *const *other, int count, double *out) noexcept |
| dotProduct() of one array with four others: out[x] equals dotProduct(shared, other[x], count) bit for bit. The wide kernels load the shared operand once for all four products and share their reductions. | |
| void | dotProductStrided (const double *shared, const double *first, std::ptrdiff_t stride, int count, int outputs, double *out) noexcept |
Dot products of one array with outputs arrays stride elements apart: out[x] = sum_i shared[i] * first[x * stride + i] for x in [0, outputs). | |
| void | add (float *DSPARK_RESTRICT dst, const float *DSPARK_RESTRICT src, int count) noexcept |
| Adds source samples into a destination buffer (no scaling). | |
| void | add (double *DSPARK_RESTRICT dst, const double *DSPARK_RESTRICT src, int count) noexcept |
| Double overload. | |
| void | multiply (float *DSPARK_RESTRICT dst, const float *DSPARK_RESTRICT a, const float *DSPARK_RESTRICT b, int count) noexcept |
| Element-wise product of two buffers into a destination. | |
| void | multiply (double *DSPARK_RESTRICT dst, const double *DSPARK_RESTRICT a, const double *DSPARK_RESTRICT b, int count) noexcept |
| Double overload. | |
| void | copyWithGain (float *DSPARK_RESTRICT dst, const float *DSPARK_RESTRICT src, float gain, int count) noexcept |
| Copies a buffer applying a gain factor (out-of-place). | |
| void | copyWithGain (double *DSPARK_RESTRICT dst, const double *DSPARK_RESTRICT src, double gain, int count) noexcept |
| Double overload. | |
| void | applyGainRamp (float *DSPARK_RESTRICT data, float gainStart, float gainEnd, int count) noexcept |
| In-place linear gain ramp (the canonical click-free fade primitive). | |
| void | applyGainRamp (double *DSPARK_RESTRICT data, double gainStart, double gainEnd, int count) noexcept |
| Double overload. | |
| void | addWithGainRamp (float *DSPARK_RESTRICT dst, const float *DSPARK_RESTRICT src, float gainStart, float gainEnd, int count) noexcept |
| Adds source samples scaled by a linear gain ramp into a destination. | |
| void | addWithGainRamp (double *DSPARK_RESTRICT dst, const double *DSPARK_RESTRICT src, double gainStart, double gainEnd, int count) noexcept |
| Double overload. | |
| float | sumOfSquares (const float *DSPARK_RESTRICT data, int count) noexcept |
| Returns the sum of squared samples (energy). | |
| double | sumOfSquares (const double *DSPARK_RESTRICT data, int count) noexcept |
| Double overload. | |
| void | complexMulAccum (float *DSPARK_RESTRICT accum, const float *DSPARK_RESTRICT a, const float *DSPARK_RESTRICT b, int bins) noexcept |
| Complex multiply-accumulate over interleaved [re, im, ...] spectra. | |
| void | complexMulAccum (double *DSPARK_RESTRICT accum, const double *DSPARK_RESTRICT a, const double *DSPARK_RESTRICT b, int bins) noexcept |
| Double overload: the products and sums of the scalar form, two or four lanes at a time. | |
| void | complexExp (double *data, int bins) noexcept |
| The exponential of each complex bin of an interleaved [re, im, ...] spectrum, in place: e^re (cos im + i sin im). | |
| template<typename T > | |
| void | addWithGainT (T *DSPARK_RESTRICT dst, const T *DSPARK_RESTRICT src, T gain, int count) noexcept |
| template<typename T > | |
| void | applyGainT (T *DSPARK_RESTRICT data, T gain, int count) noexcept |
| template<typename T > | |
| T | peakLevelT (const T *DSPARK_RESTRICT data, int count) noexcept |
| template<typename T > | |
| T | dotProductT (const T *DSPARK_RESTRICT a, const T *DSPARK_RESTRICT b, int count) noexcept |
| template<typename T > | |
| void | addT (T *DSPARK_RESTRICT dst, const T *DSPARK_RESTRICT src, int count) noexcept |
| template<typename T > | |
| void | multiplyT (T *DSPARK_RESTRICT dst, const T *DSPARK_RESTRICT a, const T *DSPARK_RESTRICT b, int count) noexcept |
| template<typename T > | |
| void | copyWithGainT (T *DSPARK_RESTRICT dst, const T *DSPARK_RESTRICT src, T gain, int count) noexcept |
| template<typename T > | |
| T | sumOfSquaresT (const T *DSPARK_RESTRICT data, int count) noexcept |
| template<typename T > | |
| void | applyGainRampT (T *DSPARK_RESTRICT data, T gainStart, T gainEnd, int count) noexcept |
| template<typename T > | |
| void | addWithGainRampT (T *DSPARK_RESTRICT dst, const T *DSPARK_RESTRICT src, T gainStart, T gainEnd, int count) noexcept |
| template<typename T > | |
| void | firCorrelate (const T *x, const T *h, int taps, T *DSPARK_RESTRICT y, int n, T gain) noexcept |
| Block FIR as a valid correlation: y[i] = gain * sum_j h[j] * x[i + j] for i in [0, n), reading x[0 .. n + taps - 1). | |
| template<typename T , int Banks> | |
| void | firCorrelateBank (const T *x, const T *h, int taps, T *const *y, int n) noexcept |
| A bank of block FIRs sharing one input, as valid correlations: y[k][i] = sum_j h[j * Banks + k] * x[i + j] for i in [0, n) and each bank k, reading x[0 .. n + taps - 1). | |
| template<typename T , int Banks> | |
| void | firCorrelateBankSum (const T *m, const T *h, int taps, T *DSPARK_RESTRICT y, int n) noexcept |
| Sum of a bank of block FIRs over interleaved inputs: y[i] = sum_k (sum_j h[j * Banks + k] * m[(i + j) * Banks + k]), the outer sum taken in bank order, reading m[0 .. (n + taps - 1) * Banks). | |
|
inlinenoexcept |
|
inlinenoexcept |
|
noexcept |
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
Adds source samples scaled by a linear gain ramp into a destination.
Same ramp convention as applyGainRamp: sample i uses gainStart + i * (gainEnd - gainStart) / count, spanning [gainStart, gainEnd) across the block, each gain computed from its index (no drift). count <= 0 is a no-op.
|
noexcept |
|
noexcept |
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
In-place linear gain ramp (the canonical click-free fade primitive).
Sample i is scaled by gainStart + i * (gainEnd - gainStart) / count, so the ramp covers [gainStart, gainEnd) across the block: the last sample sits one step below gainEnd. For a continuous fade across consecutive blocks, start the next block at gainEnd. count <= 0 is a no-op.
Every gain is computed from its own index, never accumulated: an accumulated ramp drifted by 1.3e-3 over 4.8M samples and stepped at the seam between the vector body and the scalar tail. Here the vector lanes and the tail evaluate the same expression and agree exactly.
|
noexcept |
|
noexcept |
|
inlinenoexcept |
The exponential of each complex bin of an interleaved [re, im, ...] spectrum, in place: e^re (cos im + i sin im).
What a minimum-phase design does with the spectrum of its cepstrum. The baseline takes each bin from the standard library. Builds and CPUs with AVX2 and FMA (at compile time, or after the run-time check of an x86-64 baseline build: see setRuntimeDispatch()) take four bins at a time by polynomials, within 4e-16 of the library's result relative to the bin's magnitude (measured), and leave to the library any four with a real part beyond +-700, an imaginary part beyond +-1e5 or a value that is not finite.
| data | Interleaved complex bins, overwritten. |
| bins | How many complex bins (none for zero or less). |
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
|
noexcept |
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
dotProduct() of one array with four others: out[x] equals dotProduct(shared, other[x], count) bit for bit. The wide kernels load the shared operand once for all four products and share their reductions.
| shared | The operand common to the four products. |
| other | Four operands (may repeat, may alias the shared one). |
| count | Length of every product. |
| out | Receives the four results. |
|
inlinenoexcept |
Dot products of one array with outputs arrays stride elements apart: out[x] = sum_i shared[i] * first[x * stride + i] for x in [0, outputs).
Each product keeps one accumulator of the widest vector (a multiply-add chain over its vectors), whose lanes are then summed pairwise; the last count % width terms follow one at a time. A result therefore depends only on its own operands: splitting a set of products into calls of any sizes gives the same bits. The shared operand is loaded once for up to eight products, whose chains run side by side, so a set costs well below one dotProduct() per product. Runs on the AVX2+FMA copy when isRuntimeDispatchActive().
| shared | The operand common to every product. |
| first | The first product's other operand. |
| stride | Distance in elements from one product's operand to the next. |
| count | Length of every product. |
| outputs | Number of products (none when below 1). |
| out | Receives the outputs results. |
|
noexcept |
|
noexcept |
Block FIR as a valid correlation: y[i] = gain * sum_j h[j] * x[i + j] for i in [0, n), reading x[0 .. n + taps - 1).
Register-blocked over outputs (four vectors at a time, the taps in the inner loop), so no output pays a horizontal sum: for the 16..256-tap kernels of oversamplers and resamplers it runs several times faster than one dotProduct() per output. y must not overlap x or h. Runs on the AVX2+FMA copy when isRuntimeDispatchActive().
| x | Input, n + taps - 1 samples. |
| h | Kernel, taps coefficients (h[0] meets x[i]). |
| taps | Kernel length. |
| y | Output, n samples. |
| n | Number of outputs. |
| gain | Scale applied to every output. |
|
noexcept |
A bank of block FIRs sharing one input, as valid correlations: y[k][i] = sum_j h[j * Banks + k] * x[i + j] for i in [0, n) and each bank k, reading x[0 .. n + taps - 1).
The coefficients are interleaved by tap, so each input sample is loaded once for all banks. Every output is the multiply-add chain that firCorrelate() with unit gain computes for that bank alone, in the same order, so the results are identical to Banks separate firCorrelate() calls on any target. Outputs must not overlap x or h. Runs on the AVX2+FMA copy when isRuntimeDispatchActive(), like firCorrelate().
| Banks | Number of banks (a multiple of the vector width, or any count). |
| x | Input, n + taps - 1 samples. |
| h | Interleaved kernels, taps * Banks coefficients. |
| taps | Kernel length. |
| y | Banks output pointers, n samples each. |
| n | Number of outputs per bank. |
|
noexcept |
Sum of a bank of block FIRs over interleaved inputs: y[i] = sum_k (sum_j h[j * Banks + k] * m[(i + j) * Banks + k]), the outer sum taken in bank order, reading m[0 .. (n + taps - 1) * Banks).
Each bank's inner sum is one multiply-add chain over the taps, as in firCorrelate(). Inputs and coefficients are both interleaved by bank, so every load is a contiguous vector. y must not overlap m or h. Runs on the AVX2+FMA copy when isRuntimeDispatchActive().
| Banks | Number of banks. |
| m | Interleaved inputs, (n + taps - 1) * Banks samples. |
| h | Interleaved kernels, taps * Banks coefficients. |
| taps | Kernel length. |
| y | Output, n samples. |
| n | Number of outputs. |
|
inlinenoexcept |
Whether the AVX2+FMA kernels are selected now (see setRuntimeDispatch()).
|
inlinenoexcept |
|
inlinenoexcept |
|
noexcept |
|
inlinenoexcept |
|
inlinenoexcept |
|
noexcept |
|
inlinenoexcept |
Whether this build carries AVX2+FMA kernels and the CPU can run them.
True only in x86-64 builds below AVX (see DSPARK_NO_RUNTIME_DISPATCH) on a CPU with AVX2, FMA and OS support for the YMM state. Builds that target AVX2 at compile time use those kernels everywhere and return false here.
|
inlinenoexcept |
Selects or deselects the AVX2+FMA kernels (on by default where runtimeDispatchSupported()).
The two kernel sets round differently (FMA, wider sums), so output can differ between machines in the last bits. Disable it before processing when renders must be bit-identical on every CPU. Enabling it on a CPU without AVX2 and FMA has no effect. Thread-safe; calls in progress finish on the set they began.
|
inlinenoexcept |
|
inlinenoexcept |