79 assert(sampleRate > 0.0);
80 if (!(sampleRate > 0.0))
return;
82 sampleRate_ = sampleRate;
101 delay_[
static_cast<size_t>(writePos_)] = input;
102 delay_[
static_cast<size_t>(writePos_ + kTaps)] = input;
106 const T* window = delay_.data() + writePos_ + 1;
114 const T re = window[kCenter];
116 writePos_ = (writePos_ + 1 == kTaps) ? 0 : (writePos_ + 1);
127 std::span<T> outReal,
128 std::span<T> outImag)
noexcept
131 assert(outReal.size() >= input.size() && outImag.size() >= input.size());
134 const size_t numSamples =
135 std::min(input.size(), std::min(outReal.size(), outImag.size()));
136 for (
size_t i = 0; i < numSamples; ++i)
138 const auto res =
process(input[i]);
139 outReal[i] = res.real;
140 outImag[i] = res.imag;
157 static constexpr int kTaps = 191;
158 static constexpr int kCenter = kTaps / 2;
163 [[nodiscard]]
static const std::array<T, kTaps>& reversedKernel() noexcept
165 static const std::array<T, kTaps> kernel = []
167 std::array<T, kTaps> k {};
168 constexpr double kPi = 3.14159265358979323846;
169 for (
int i = 0; i < kTaps; ++i)
173 const int n = i - kCenter;
174 double ideal = ((n == 0) || (n % 2 == 0)) ? 0.0 : (2.0 / (kPi * static_cast<double>(n)));
176 - 0.5 * std::cos(2.0 * kPi *
static_cast<double>(i) /
static_cast<double>(kTaps - 1))
177 + 0.08 * std::cos(4.0 * kPi *
static_cast<double>(i) /
static_cast<double>(kTaps - 1));
178 k[
static_cast<size_t>(kTaps - 1 - i)] =
static_cast<T
>(ideal * w);
185 double sampleRate_ = 0.0;
186 bool isPrepared_ =
false;
191 const T* kernelData_ = reversedKernel().data();
196 std::array<T, kTaps * 2> delay_{};
RAII scope guard that disables denormal (subnormal) float arithmetic.
Core mathematical utilities for digital signal processing.
SIMD-accelerated buffer operations for real-time audio processing.
RAII scope guard to disable denormalised (subnormal) floating-point numbers.
90-degree phase-differencing network (analytic-signal generator).
static constexpr int getLatencySamples() noexcept
FIR group-delay latency applied to both outputs, in samples.
void reset() noexcept
Resets the delay line. Mandatory when seeking or starting playback.
void prepare(double sampleRate) noexcept
Prepares the transformer. The FIR kernel is sample-rate independent; sampleRate is accepted for API s...
Result process(T input) noexcept
Processes one sample, returning the analytic signal {real, imag}.
void processBlock(std::span< const T > input, std::span< T > outReal, std::span< T > outImag) noexcept
Processes a block of samples. Optimized for CPU cache.
float dotProduct(const float *DSPARK_RESTRICT a, const float *DSPARK_RESTRICT b, int count) noexcept
Computes the dot product of two arrays.
Main namespace for the DSPark framework.
T real
In-phase component (input delayed by the FIR group delay).
T imag
Quadrature component (90-deg shifted).