180template <
typename SampleType>
197 for (
int n =
size; n > 1; n >>= 1) ++log2_size_;
198 reversed_.resize(
static_cast<std::size_t
>(
size));
199 for (
int i = 0;
i <
size; ++
i) {
201 for (
int b = 0; b < log2_size_; ++b)
202 if (
i & (1 << b)) r |= 1 << (log2_size_ - 1 - b);
203 reversed_[
static_cast<std::size_t
>(
i)] = r;
208 twiddles_.resize(
static_cast<std::size_t
>(std::max(1,
size / 2)));
209 constexpr double two_pi = 6.283185307179586476925286766559;
210 for (
int i = 0;
i <
size / 2; ++
i) {
211 const double angle = -two_pi *
static_cast<double>(
i) /
static_cast<double>(
size);
212 twiddles_[
static_cast<std::size_t
>(
i)] = {
static_cast<SampleType
>(std::cos(angle)),
213 static_cast<SampleType
>(std::sin(angle))};
217 int size()
const {
return size_; }
226 static_cast<long>(log2_size_) *
static_cast<long>(size_ / 2) *
kButterflyCost;
289 const int n = plan.size_;
294 if (take <= 0)
return spent;
296 const std::size_t src =
298 static_cast<std::size_t
>(plan.reversed_[
static_cast<std::size_t
>(
i)])) &
308 const int total = n / 2;
310 if (take <= 0)
return spent;
311 const int len = 1 <<
stage;
312 const int half = len / 2;
313 const int step = n / len;
317 const int group = b >> (
stage - 1);
318 const int j = b & (half - 1);
319 const int i = group * len;
320 const auto& tw = plan.twiddles_[
static_cast<std::size_t
>(j * step)];
322 const auto u = data[
i + j];
323 const auto v = data[
i + j + half] * w;
325 data[
i + j + half] =
u - v;
332 if (
stage > plan.log2_size_)
339 if (take <= 0)
return spent;
341 data[
i] = std::conj(data[
i]);
349 if (take <= 0)
return spent;
351 const int j = plan.reversed_[
static_cast<std::size_t
>(
i)];
352 if (
i < j) std::swap(data[
i], data[j]);
361 if (take <= 0)
return spent;
362 const SampleType inv_n = SampleType{1} /
static_cast<SampleType
>(n);
364 data[
i] = std::conj(data[
i]) * inv_n;
366 spent +=
static_cast<long>(take) *
kScaleCost;
378 static int affordable(
long budget,
long unit_cost,
int remaining) {
379 if (budget <= 0 || remaining <= 0)
return 0;
380 return static_cast<int>(std::min<long>(budget / unit_cost, remaining));
387 std::complex<SampleType>* dst)
const {
388 for (
int i = 0;
i < size_; ++
i) {
389 const int r = reversed_[
static_cast<std::size_t
>(
i)];
390 const double v = r < src_len ? src[r] : 0.0;
391 dst[
i] = {
static_cast<SampleType
>(v), SampleType{0}};
393 for (
int stage = 1; stage <= log2_size_; ++stage) {
394 const int len = 1 << stage;
395 const int half = len / 2;
396 const int step = size_ / len;
397 for (
int i = 0;
i < size_;
i += len) {
398 for (
int j = 0; j < half; ++j) {
399 const auto& tw = twiddles_[
static_cast<std::size_t
>(j * step)];
401 const auto u = dst[
i + j];
402 const auto v = dst[
i + j + half] * w;
404 dst[
i + j + half] =
u - v;
413 std::vector<int> reversed_;
414 std::vector<std::complex<SampleType>> twiddles_;
492 double destination_rate,
int taps_per_phase)
noexcept {
493 if (source_length <= 0 || taps_per_phase <= 0 ||
494 !std::isfinite(source_rate) || source_rate <= 0.0 ||
495 !std::isfinite(destination_rate) || destination_rate <= 0.0)
497 constexpr double int_max =
static_cast<double>(std::numeric_limits<int>::max());
498 const double ratio = destination_rate / source_rate;
499 if (!std::isfinite(
ratio) ||
ratio <= 0.0)
return false;
501 const double destination_length =
502 std::ceil(
static_cast<double>(source_length) *
ratio);
503 if (!std::isfinite(destination_length) || destination_length < 1.0 ||
504 destination_length > int_max)
507 const double cutoff = std::min(1.0,
ratio);
508 const double half_width = 0.5 *
static_cast<double>(taps_per_phase) / cutoff;
509 const double reach = std::ceil(half_width) + 1.0;
510 if (!std::isfinite(half_width) || !std::isfinite(reach) || reach < 1.0 ||
517 return reach <= int_max -
static_cast<double>(source_length);
544template <
typename SampleType>
556 std::vector<std::vector<std::complex<SampleType>>>
spectra;
558 std::vector<std::vector<std::complex<SampleType>>>
ir_spectra;
559 std::vector<std::vector<std::complex<SampleType>>>
accum;
560 std::vector<std::vector<SampleType>>
emit;
561 std::vector<std::vector<SampleType>>
ready;
575 for (
auto& s :
spectra) std::fill(s.begin(), s.end(), std::complex<SampleType>{});
576 for (
auto&
a :
accum) std::fill(
a.begin(),
a.end(), std::complex<SampleType>{});
577 for (
auto&
e :
emit) std::fill(
e.begin(),
e.end(), SampleType{0});
578 for (
auto& r :
ready) std::fill(r.begin(), r.end(), SampleType{0});
591template <
typename SampleType>
Resumable in-place radix-2 complex FFT (Cooley & Tukey 1965).
Definition zero_latency_convolver_support.hpp:181
void transform_real_padded(const double *src, int src_len, std::complex< SampleType > *dst) const
Blocking forward transform of a contiguous real buffer, zero-padded to size().
Definition zero_latency_convolver_support.hpp:386
long forward_cost() const
Metered cost of one complete forward transform (permuted gather plus all butterfly stages) and of one...
Definition zero_latency_convolver_support.hpp:224
static constexpr long kConjugateCost
Definition zero_latency_convolver_support.hpp:190
static constexpr long kButterflyCost
Definition zero_latency_convolver_support.hpp:189
static constexpr long kMacCost
Definition zero_latency_convolver_support.hpp:192
static constexpr long kScaleCost
Definition zero_latency_convolver_support.hpp:191
int log2_size() const
Definition zero_latency_convolver_support.hpp:218
int size() const
Definition zero_latency_convolver_support.hpp:217
static constexpr long kGatherCost
Definition zero_latency_convolver_support.hpp:188
long inverse_cost() const
Definition zero_latency_convolver_support.hpp:228
void prepare(int size)
Definition zero_latency_convolver_support.hpp:194
Round-2 effect-wave vocabulary.
Definition analysis_frontends.hpp:50
Definition additive_bank.hpp:218
@ peak
Sample peak. Literal, fastest-responding.
Definition feedforward_compressor.hpp:119
IrNormalizeMode
IR amplitude policy applied at load, after resampling and tail trim.
Definition zero_latency_convolver_support.hpp:157
@ energy
sum h^2 = 1 per output ear (default; convolution reverb).
Definition zero_latency_convolver_support.hpp:160
@ ratio
base_frequency_hz * ratio.
Definition fm_operator_engine.hpp:20
@ a
Definition formant_filter_bank.hpp:20
@ u
Definition formant_filter_bank.hpp:20
@ i
Definition formant_filter_bank.hpp:20
@ e
Definition formant_filter_bank.hpp:20
@ none
Definition dither.hpp:17
Hardware flush-to-zero RAII guard for the audio callback boundary.
Zero-latency non-uniform partitioned convolution engine.
Definition zero_latency_convolver_support.hpp:422
static constexpr double kWidthPercentMax
Definition zero_latency_convolver_support.hpp:465
static constexpr double kWidthPercentMin
Definition zero_latency_convolver_support.hpp:464
static constexpr double kResampKaiserBeta
House Kaiser window shape, fixed by the series contract's oversampling / resampling law — not a tunab...
Definition zero_latency_convolver_support.hpp:522
static constexpr double kPredelayMsMin
Definition zero_latency_convolver_support.hpp:441
static constexpr double kTailTrimDbMin
Definition zero_latency_convolver_support.hpp:470
static constexpr int kResampTapsPerPhaseMax
Definition zero_latency_convolver_support.hpp:485
static constexpr double kHighcutHzDefault
Definition zero_latency_convolver_support.hpp:458
static constexpr double kTailFadeMsDefault
Raised-cosine fade applied to the last part of the kept IR so the truncation cannot click.
Definition zero_latency_convolver_support.hpp:475
static constexpr double kDryPercentDefault
Definition zero_latency_convolver_support.hpp:446
static constexpr double kTailTrimDbDefault
IR truncation floor on the Schroeder backward-energy curve.
Definition zero_latency_convolver_support.hpp:469
static constexpr double kBlockCostSlackMax
Definition zero_latency_convolver_support.hpp:531
static constexpr double kLowcutHzMin
Definition zero_latency_convolver_support.hpp:456
static constexpr int kHeadLenMax
Definition zero_latency_convolver_support.hpp:431
static constexpr double kIrGainDbDefault
IR trim on the convolved path. [dp, default 0 dB, range -24..+24 dB].
Definition zero_latency_convolver_support.hpp:434
static constexpr double kTailTrimDbMax
Definition zero_latency_convolver_support.hpp:471
static constexpr double kHighcutHzMin
Definition zero_latency_convolver_support.hpp:459
static constexpr int kResampTapsPerPhaseMin
Definition zero_latency_convolver_support.hpp:484
static constexpr int kResampTapsPerPhaseDefault
Resampler kernel width, in taps per polyphase branch.
Definition zero_latency_convolver_support.hpp:483
static constexpr double kSilenceEpsilon
Below this, energies are treated as zero.
Definition zero_latency_convolver_support.hpp:536
static constexpr double kIrGainDbMin
Definition zero_latency_convolver_support.hpp:435
static constexpr double kBlockCostSlackDefault
Peak-to-mean per-block cost slack the distributed schedule is allowed.
Definition zero_latency_convolver_support.hpp:529
static constexpr double kPredelayMsMax
Definition zero_latency_convolver_support.hpp:442
static constexpr double kHighcutHzMax
Definition zero_latency_convolver_support.hpp:460
static constexpr double kLowcutHzMax
Definition zero_latency_convolver_support.hpp:457
static constexpr double kBlockCostSlackMin
Definition zero_latency_convolver_support.hpp:530
static constexpr double kTailFadeMsMin
Definition zero_latency_convolver_support.hpp:476
static constexpr double kLowcutHzDefault
Send-EQ corners.
Definition zero_latency_convolver_support.hpp:455
static bool valid_resample_geometry(int source_length, double source_rate, double destination_rate, int taps_per_phase) noexcept
Proves every resampler geometry value is finite and representable before the ingest path casts it to ...
Definition zero_latency_convolver_support.hpp:491
static constexpr double kWidthPercentDefault
Mid/side width of the wet output. [dp, default 100 %, range 0..200 %].
Definition zero_latency_convolver_support.hpp:463
static constexpr double kIrGainDbMax
Definition zero_latency_convolver_support.hpp:436
static constexpr int kHeadLenMin
Head length N0, in taps.
Definition zero_latency_convolver_support.hpp:430
static constexpr double kTailFadeMsMax
Definition zero_latency_convolver_support.hpp:477
static constexpr double kPredelayMsDefault
Pre-IR delay of the wet path.
Definition zero_latency_convolver_support.hpp:440
static constexpr double kWetPercentDefault
Wet / dry mix, in percent. [dp, defaults 100 % / 0 %, range 0..100 %].
Definition zero_latency_convolver_support.hpp:445
Cursor over one transform.
Definition zero_latency_convolver_support.hpp:241
std::size_t gather_mask
Definition zero_latency_convolver_support.hpp:250
void begin_forward_from_ring(const SampleType *ring, std::size_t base, std::size_t mask)
Forward transform of ring[(base + i) & mask], i in [0, size).
Definition zero_latency_convolver_support.hpp:255
long advance(const SlicedFftPlanT &plan, std::complex< SampleType > *data, long budget)
Definition zero_latency_convolver_support.hpp:287
void begin_inverse_in_place()
Inverse transform of whatever already sits in data, computed as conj(fft(conj(x)))/N.
Definition zero_latency_convolver_support.hpp:277
Phase
Definition zero_latency_convolver_support.hpp:242
@ scale
Definition zero_latency_convolver_support.hpp:242
@ permute
Definition zero_latency_convolver_support.hpp:242
@ gather
Definition zero_latency_convolver_support.hpp:242
@ butterflies
Definition zero_latency_convolver_support.hpp:242
@ conjugate
Definition zero_latency_convolver_support.hpp:242
@ idle
Definition zero_latency_convolver_support.hpp:242
const SampleType * gather_src
Definition zero_latency_convolver_support.hpp:248
bool inverse
Definition zero_latency_convolver_support.hpp:247
int stage
Definition zero_latency_convolver_support.hpp:246
int cursor
Definition zero_latency_convolver_support.hpp:245
Phase phase
Definition zero_latency_convolver_support.hpp:244
void cancel()
Definition zero_latency_convolver_support.hpp:285
bool done() const
Definition zero_latency_convolver_support.hpp:252
std::size_t gather_base
Definition zero_latency_convolver_support.hpp:249
void begin_forward_in_place()
Forward transform of the already gathered natural-order data in data, using the in-place permutation ...
Definition zero_latency_convolver_support.hpp:267
Definition zero_latency_convolver_support.hpp:592
int ir_channel
Definition zero_latency_convolver_support.hpp:595
std::vector< SampleType > head_reversed
Definition zero_latency_convolver_support.hpp:600
int dst
Definition zero_latency_convolver_support.hpp:594
int src
Definition zero_latency_convolver_support.hpp:593
double l1
Definition zero_latency_convolver_support.hpp:596
std::vector< SampleType > head
Definition zero_latency_convolver_support.hpp:597
Definition zero_latency_convolver_support.hpp:545
typename SlicedFftPlanT< SampleType >::Cursor FftCursor
Definition zero_latency_convolver_support.hpp:546
int ir_start
Definition zero_latency_convolver_support.hpp:549
bool has_result
Definition zero_latency_convolver_support.hpp:572
int job_cursor
Definition zero_latency_convolver_support.hpp:569
detail::SlicedFftPlanT< SampleType > plan
Definition zero_latency_convolver_support.hpp:553
int fft_size
Definition zero_latency_convolver_support.hpp:548
FftCursor fft
Definition zero_latency_convolver_support.hpp:570
void reset()
Definition zero_latency_convolver_support.hpp:574
int slot
Definition zero_latency_convolver_support.hpp:551
std::size_t frame_base
Definition zero_latency_convolver_support.hpp:566
std::vector< std::vector< std::complex< SampleType > > > accum
Definition zero_latency_convolver_support.hpp:559
int job
Definition zero_latency_convolver_support.hpp:567
std::vector< std::vector< SampleType > > emit
Definition zero_latency_convolver_support.hpp:560
long total_cost
Definition zero_latency_convolver_support.hpp:564
long granted
Definition zero_latency_convolver_support.hpp:565
int block_len
Definition zero_latency_convolver_support.hpp:547
std::vector< std::vector< std::complex< SampleType > > > ir_spectra
Definition zero_latency_convolver_support.hpp:558
bool armed
Definition zero_latency_convolver_support.hpp:571
std::vector< std::vector< std::complex< SampleType > > > spectra
Definition zero_latency_convolver_support.hpp:556
int num_partitions
Definition zero_latency_convolver_support.hpp:550
std::vector< std::vector< SampleType > > ready
Definition zero_latency_convolver_support.hpp:561
int job_step
Definition zero_latency_convolver_support.hpp:568
Definition zero_latency_convolver_support.hpp:603
double prev_x
Definition zero_latency_convolver_support.hpp:605
double z
Definition zero_latency_convolver_support.hpp:604
The real-unit vocabulary shared by every DSP block in the catalog.
Shared Kaiser-windowed-sinc FIR design helpers.