217#include "../Core/DryWetMixer.h"
218#include "../Core/DspMath.h"
219#include "../Core/AudioSpec.h"
220#include "../Core/AudioBuffer.h"
221#include "../Core/DenormalGuard.h"
222#include "../Core/Biquad.h"
223#include "../Core/BiquadCascade.h"
224#include "../Core/FilterDesign.h"
225#include "../Core/StateBlob.h"
226#include "../Core/SimdOps.h"
227#include "../Core/KeyEqualizer.h"
228#include "../Core/TailShaper.h"
248template <FloatType T>
332 for (
int b = 0; b < 2; ++b)
334 const auto s =
static_cast<std::size_t
>(b);
340 p.d1[s].prepare(p.lD1[s] + 1);
341 p.ap2[s].prepare(p.lAp2[s] + 1);
342 p.d2[s].prepare(p.lD2[s] + 1);
344 p.loopSec = 0.5 * (p.lAp1[0] + p.lD1[0] + p.lAp2[0] + p.lD2[0] + p.lAp1[1] + p.lD1[1] + p.lAp2[1] + p.lD2[1]) / sr;
348 const auto s =
static_cast<std::size_t
>(j);
354 while (size <
static_cast<int>(2.0 *
kShimmerMaxMs * 0.001 * sr) + 8) size <<= 1;
355 shimBuf_.assign(
static_cast<size_t>(size), T(0));
364 std::memory_order_relaxed);
366 std::memory_order_relaxed);
368 const auto samples = [sr](
double ms) {
return static_cast<int>(ms * sr / 1000.0) + 8; };
369 for (
int c = 0; c < 2; ++c)
396 const double fc = 0.9 * sr / (2.0 *
springK_);
397 const double qs[2] = { 0.5411961001461970, 1.3065629648763764 };
398 for (
int k = 0; k < 2; ++k)
401 springLP_[k] = {
static_cast<T
>(c.b0),
static_cast<T
>(c.b1),
static_cast<T
>(c.b2),
402 static_cast<T
>(c.a1),
static_cast<T
>(c.a2) };
424 toneDirty_.store(
true, std::memory_order_relaxed);
443 const int nCh = std::min(buffer.getNumChannels(), 2);
444 const int nS = buffer.getNumSamples();
445 if (nCh == 0 || nS == 0 || !
prepared_)
return;
458 for (
int ch = 0; ch < nCh; ++ch)
460 T* d = buffer.getChannel(ch);
461 for (
int i = 0; i < nS; ++i)
462 if (!std::isfinite(d[i])) d[i] = T(0);
470 T* chL = buffer.getChannel(0);
471 T* chR = nCh >= 2 ? buffer.getChannel(1) :
nullptr;
472 alignas(64) T outL[
kChunk];
473 alignas(64) T outR[
kChunk];
474 for (
int start = 0; start < nS; start +=
kChunk)
476 const int n = std::min(
kChunk, nS - start);
477 processChunk(chL + start, (chR ? chR : chL) + start, outL, outR, n);
480 std::copy(outL, outL + n, chL + start);
481 std::copy(outR, outR + n, chR + start);
485 for (
int i = 0; i < n; ++i)
486 chL[start + i] = (outL[i] + outR[i]) * T(0.5);
497 for (
int i = 0; i < nS; ++i)
500 for (
int ch = 0; ch < nCh; ++ch) frame[ch] = buffer.getChannel(ch)[i];
502 for (
int ch = 0; ch < nCh; ++ch) buffer.getChannel(ch)[i] = frame[ch];
511 T* l = buffer.getChannel(0);
512 T* r = nCh >= 2 ? buffer.getChannel(1) :
nullptr;
513 for (
int i = 0; i < nS; ++i)
515 T a = l[i], b = r ? r[i] : l[i];
522 mixer_.mixWet(buffer,
mix_.load(std::memory_order_relaxed));
542 if (!std::isfinite(input)) input = T(0);
543 T outL = T(0), outR = T(0);
547 T frame[2] = { outL, outR };
555 return { outL, outR };
564 for (
int c = 0; c < 2; ++c)
568 for (
auto& ap :
inAP_[c]) ap.clear();
569 for (
auto& ap :
outAP_[c]) ap.clear();
587 for (
auto& v :
airHist_) v.fill(T(0));
589 for (
auto& z :
dqZ1_) z.fill(T(0));
590 for (
auto& z :
dqZ2_) z.fill(T(0));
605 for (
int b = 0; b < 2; ++b)
607 plate_.
ap1[
static_cast<std::size_t
>(b)].clear();
608 plate_.
d1[
static_cast<std::size_t
>(b)].clear();
609 plate_.
ap2[
static_cast<std::size_t
>(b)].clear();
610 plate_.
d2[
static_cast<std::size_t
>(b)].clear();
624 const T rate =
modRate_.load(std::memory_order_relaxed);
670 const int t = std::clamp(
static_cast<int>(type), 0,
672 type_.store(
static_cast<Type>(t), std::memory_order_relaxed);
708 std::memory_order_relaxed);
723 if (!std::isfinite(seconds))
return;
724 decayTime_.store(std::clamp(seconds, T(0.1), T(30)),
725 std::memory_order_relaxed);
740 if (!std::isfinite(dryWet))
return;
741 mix_.store(std::clamp(dryWet, T(0), T(1)), std::memory_order_relaxed);
757 if (!std::isfinite(size))
return;
758 size_.store(std::clamp(size, T(0.01), T(1)), std::memory_order_relaxed);
771 if (!std::isfinite(amount))
return;
772 T clamped = std::clamp(amount, T(0), T(1));
773 damping_.store(clamped, std::memory_order_relaxed);
774 highDecayMult_.store(T(1) - clamped * T(0.9), std::memory_order_relaxed);
783 if (!std::isfinite(ms))
return;
785 preDelayMs_.store(clamped, std::memory_order_relaxed);
799 if (!std::isfinite(amount))
return;
800 diffusion_.store(std::clamp(amount, T(0), T(1)), std::memory_order_relaxed);
812 if (!std::isfinite(amount))
return;
813 modDepth_.store(std::clamp(amount, T(0), T(1)), std::memory_order_relaxed);
829 if (!std::isfinite(width))
return;
830 width_.store(std::clamp(width, T(0), T(2)), std::memory_order_relaxed);
836 if (!std::isfinite(ms))
return;
838 erToLateMs_.store(clamped, std::memory_order_relaxed);
859 if (!std::isfinite(mult))
return;
860 T clamped = std::clamp(mult, T(0.05), T(1));
862 damping_.store(std::clamp((T(1) - clamped) / T(0.9), T(0), T(1)),
863 std::memory_order_relaxed);
880 if (!std::isfinite(mult))
return;
882 std::memory_order_relaxed);
902 if (!std::isfinite(hz))
return;
904 std::memory_order_relaxed);
936 if (!std::isfinite(amount))
return;
937 airAbsorption_.store(std::clamp(amount, T(0), T(2)), std::memory_order_relaxed);
954 if (!std::isfinite(hz))
return;
956 std::memory_order_relaxed);
974 if (!std::isfinite(dB))
return;
982 if (!std::isfinite(dB))
return;
990 if (!std::isfinite(hz))
return;
991 modRate_.store(std::clamp(hz, T(0.1), T(5)), std::memory_order_relaxed);
1005 if (!std::isfinite(hz))
return;
1007 toneDirty_.store(
true, std::memory_order_release);
1019 if (!std::isfinite(hz))
return;
1021 toneDirty_.store(
true, std::memory_order_release);
1046 auto& d =
decayBands_[
static_cast<size_t>(index)];
1047 d.shape.store(std::clamp(
static_cast<int>(band.shape), 0, 3), std::memory_order_relaxed);
1048 if (std::isfinite(band.frequency)) d.frequency.store(std::clamp(band.frequency, T(20), T(20000)), std::memory_order_relaxed);
1049 if (std::isfinite(band.q)) d.q.store(std::clamp(band.q, T(0.1), T(10)), std::memory_order_relaxed);
1050 if (std::isfinite(band.multiplier)) d.multiplier.store(std::clamp(band.multiplier, T(0.1), T(4)), std::memory_order_relaxed);
1059 const auto& d =
decayBands_[
static_cast<size_t>(index)];
1060 b.
shape =
static_cast<DecayShape>(d.shape.load(std::memory_order_relaxed));
1061 b.
frequency = d.frequency.load(std::memory_order_relaxed);
1062 b.
q = d.q.load(std::memory_order_relaxed);
1063 b.
multiplier = d.multiplier.load(std::memory_order_relaxed);
1093 if (!std::isfinite(ms))
return;
1094 gateHoldMs_.store(std::clamp(ms, T(0), T(4000)), std::memory_order_relaxed);
1112 if (!std::isfinite(amount))
return;
1113 sourceDepth_.store(std::clamp(amount, T(0), T(1)), std::memory_order_relaxed);
1129 if (std::isfinite(amount))
tankLeveling_.store(std::clamp(amount, T(0), T(1)), std::memory_order_relaxed);
1138 if (!std::isfinite(bpm))
return;
1139 tempo_.store(std::clamp(bpm, T(20), T(400)), std::memory_order_relaxed);
1147 preNote_.store(std::clamp(
static_cast<int>(note), 0, 6), std::memory_order_relaxed);
1148 preFeel_.store(std::clamp(
static_cast<int>(feel), 0, 2), std::memory_order_relaxed);
1155 gateNote_.store(std::clamp(
static_cast<int>(note), 0, 6), std::memory_order_relaxed);
1156 gateFeel_.store(std::clamp(
static_cast<int>(feel), 0, 2), std::memory_order_relaxed);
1167 if (std::isfinite(width))
inputWidth_.store(std::clamp(width, T(0), T(1)), std::memory_order_relaxed);
1178 widthLaw_.store(std::clamp(
static_cast<int>(law), 0, 1), std::memory_order_relaxed);
1213 modStyle_.store(std::clamp(
static_cast<int>(style), 0, 1), std::memory_order_relaxed);
1225 layout_.store(std::clamp(
static_cast<int>(layout), 0, 1), std::memory_order_relaxed);
1244 plateTank_.store(on, std::memory_order_relaxed);
1262 if (!std::isfinite(amount))
return;
1263 doubleSlope_.store(std::clamp(amount, T(0), T(1)), std::memory_order_relaxed);
1280 if (std::isfinite(hz))
bandLimit_.store(hz <= T(0) ? T(0) : std::max(hz, T(1000)), std::memory_order_relaxed);
1294 if (std::isfinite(amount))
shimmer_.store(std::clamp(amount, T(0), T(1)), std::memory_order_relaxed);
1304 [[nodiscard]] T
getTempo() const noexcept {
return tempo_.load(std::memory_order_relaxed); }
1323 [[nodiscard]] T
getMix() const noexcept {
return mix_.load(std::memory_order_relaxed); }
1324 [[nodiscard]] T
getSize() const noexcept {
return size_.load(std::memory_order_relaxed); }
1333 [[nodiscard]] T
getWidth() const noexcept {
return width_.load(std::memory_order_relaxed); }
1345 w.
write(
"type",
static_cast<int32_t
>(
type_.load(std::memory_order_relaxed)));
1346 w.
write(
"quality",
static_cast<int32_t
>(
quality_.load(std::memory_order_relaxed)));
1347 w.
write(
"decay",
static_cast<float>(
decayTime_.load(std::memory_order_relaxed)));
1348 w.
write(
"size",
static_cast<float>(
size_.load(std::memory_order_relaxed)));
1349 w.
write(
"damping",
static_cast<float>(
damping_.load(std::memory_order_relaxed)));
1350 w.
write(
"diffusion",
static_cast<float>(
diffusion_.load(std::memory_order_relaxed)));
1351 w.
write(
"modDepth",
static_cast<float>(
modDepth_.load(std::memory_order_relaxed)));
1352 w.
write(
"modRate",
static_cast<float>(
modRate_.load(std::memory_order_relaxed)));
1353 w.
write(
"preDelay",
static_cast<float>(
preDelayMs_.load(std::memory_order_relaxed)));
1354 w.
write(
"erToLate",
static_cast<float>(
erToLateMs_.load(std::memory_order_relaxed)));
1355 w.
write(
"mix",
static_cast<float>(
mix_.load(std::memory_order_relaxed)));
1356 w.
write(
"width",
static_cast<float>(
width_.load(std::memory_order_relaxed)));
1363 w.
write(
"toneLowCut",
static_cast<float>(
toneLowCutHz_.load(std::memory_order_relaxed)));
1364 w.
write(
"toneHighCut",
static_cast<float>(
toneHighCutHz_.load(std::memory_order_relaxed)));
1369 std::snprintf(key,
sizeof(key),
"db%d.shape", b); w.
write(key,
static_cast<int32_t
>(band.
shape));
1370 std::snprintf(key,
sizeof(key),
"db%d.freq", b); w.
write(key,
static_cast<float>(band.
frequency));
1371 std::snprintf(key,
sizeof(key),
"db%d.q", b); w.
write(key,
static_cast<float>(band.
q));
1372 std::snprintf(key,
sizeof(key),
"db%d.mult", b); w.
write(key,
static_cast<float>(band.
multiplier));
1383 w.
write(
"preNote",
preNote_.load(std::memory_order_relaxed));
1384 w.
write(
"preFeel",
preFeel_.load(std::memory_order_relaxed));
1390 w.
write(
"layout",
layout_.load(std::memory_order_relaxed));
1432 std::snprintf(key,
sizeof(key),
"db%d.shape", b); band.
shape =
static_cast<DecayShape>(r.
read(key, 0));
1433 std::snprintf(key,
sizeof(key),
"db%d.freq", b); band.
frequency =
static_cast<T
>(r.
read(key, 1000.0f));
1434 std::snprintf(key,
sizeof(key),
"db%d.q", b); band.
q =
static_cast<T
>(r.
read(key, 0.7071f));
1435 std::snprintf(key,
sizeof(key),
"db%d.mult", b); band.
multiplier =
static_cast<T
>(r.
read(key, 1.0f));
1524 static T
allpassCoeff(
double d)
noexcept {
return static_cast<T
>((1.0 - d) / (1.0 + d)); }
1542 44.5, 46.5, 49.7, 52.3, 56.1, 58.9, 61.9, 65.2,
1543 68.6, 73.7, 76.2, 79.8, 86.4, 89.8, 95.7, 101.2,
1544 105.4, 112.5, 116.7, 126.4, 132.1, 140.6, 146.9, 154.1,
1545 162.9, 175.8, 184.1, 192.8, 204.0, 218.5, 224.2, 240.1
1551 3.55, 1.47, 3.80, 1.96, 1.84, 2.33, 4.41, 4.90,
1552 1.10, 1.35, 4.29, 3.43, 4.16, 4.53, 2.08, 3.06,
1553 1.22, 2.94, 3.92, 3.18, 2.57, 4.04, 4.65, 2.45,
1554 2.69, 4.78, 3.67, 1.71, 2.20, 1.59, 2.82, 3.31
1562 { 0.36, 0.69, 1.10, 1.65 },
1563 { 0.43, 0.80, 1.20, 1.79 }
1579 7.14, 3.31, 0.76, 0.25, 5.86, 2.04, 4.84, 5.35,
1580 5.61, 6.88, 0.00, 7.65, 2.80, 1.02, 7.90, 1.53,
1581 1.27, 4.33, 6.63, 2.55, 3.06, 6.12, 5.10, 6.37,
1582 3.82, 1.78, 3.57, 7.39, 2.29, 0.51, 4.08, 4.59
1585 1, 1, -1, 1, -1, 1, 1, -1,
1586 -1, 1, 1, -1, 1, -1, 1, 1,
1587 1, 1, 1, -1, 1, 1, 1, 1,
1588 1, -1, 1, 1, -1, 1, -1, -1
1594 -1, -1, 1, -1, -1, 1, 1, 1,
1595 -1, -1, 1, 1, -1, -1, -1, 1,
1596 -1, -1, 1, -1, -1, 1, 1, -1,
1597 1, 1, -1, -1, -1, -1, -1, 1
1600 -1, 1, 1, 1, -1, -1, 1, -1,
1601 -1, 1, 1, -1, -1, 1, -1, -1,
1602 -1, 1, 1, 1, -1, -1, 1, 1,
1603 1, -1, -1, 1, -1, 1, -1, -1
1617 return 33.0 + 27.0 * s / (
kSprings - 1) + 1.3 * (
hash01(s, 90) - 0.5);
1636 while (size < maxDelay + 2) size <<= 1;
1637 buf.assign(
static_cast<std::size_t
>(size), T(0));
1642 [[nodiscard]] T
at(
int k)
const noexcept {
return buf[
static_cast<std::size_t
>((
w - k) &
mask)]; }
1643 void push(T x)
noexcept {
buf[
static_cast<std::size_t
>(
w)] = x;
w = (
w + 1) &
mask; }
1662 while (
size < maxDelay + 2)
size <<= 1;
1667 stride =
size + 64 /
static_cast<int>(
sizeof(T));
1668 buf.assign(
static_cast<std::size_t
>(
stride) *
static_cast<std::size_t
>(numLines), T(0));
1672 [[nodiscard]] T
at(
int i,
int k)
const noexcept
1673 {
return buf[
static_cast<std::size_t
>(i *
stride + ((
w - k) &
mask))]; }
1695 step = 1.0 / (0.02 * sampleRate);
1696 for (
auto& b :
bank)
1708 for (
auto& b :
bank) b.reset();
1718 if (want > 0.0) want = std::min(want, 0.4 *
rate);
1719 if (want ==
hz ||
fade < 1.0)
return;
1741 const double x[2] = {
static_cast<double>(l),
static_cast<double>(r) };
1742 double to[2] = { x[0], x[1] };
1747 double from[2] = { x[0], x[1] };
1751 for (
int c = 0; c < 2; ++c) to[c] = from[c] +
fade * (to[c] - from[c]);
1753 l =
static_cast<T
>(to[0]);
1754 r =
static_cast<T
>(to[1]);
1773 std::array<int, kLines>
len {};
1784 static constexpr double kRate = 29761.0;
1785 static constexpr std::array<int, 2>
kAp1 { 672, 908 },
kD1 { 4453, 4217 },
kAp2 { 1800, 2656 },
kD2 { 3720, 3163 };
1797 [[nodiscard]]
int at(
double samples29k)
const noexcept {
return std::max(1,
static_cast<int>(std::lround(samples29k *
scale))); }
1805 static constexpr std::array<double, SecondSlope::kLines>
kSecondMs { 23.3, 29.1, 37.9, 44.7 };
1819 void prepare(
double sr, T rate, uint32_t seed)
noexcept
1821 phaseInc_ =
static_cast<double>(rate) / sr;
1822 state_ = seed ? seed : 1;
1823 h0_ = nextRandom();
h1_ = nextRandom();
1824 h2_ = nextRandom();
h3_ = nextRandom();
1842 const double c1 = 0.5 * (
h2_ -
h0_);
1843 const double c2 =
h0_ - 2.5 *
h1_ + 2.0 *
h2_ - 0.5 *
h3_;
1844 const double c3 = 0.5 * (
h3_ -
h0_) + 1.5 * (
h1_ -
h2_);
1845 return static_cast<T
>(((c3 * d + c2) * d + c1) * d +
h1_);
1849 double nextRandom() noexcept
1854 return static_cast<double>(
state_) /
static_cast<double>(0xFFFFFFFFu) * 2.0 - 1.0;
1873 state = seed ? seed : 1;
1878 double next(
int stride,
double rateHz,
double sr)
noexcept
1885 const double seconds = (0.5 + random()) / std::max(rateHz, 0.01);
1889 const double move =
step *
static_cast<double>(stride);
1894 const double dt =
static_cast<double>(stride) / sr;
1895 const double w = std::min(2.0 * 3.14159265358979323846 * std::clamp(2.0 * rateHz, 0.2, 20.0), 0.5 / dt);
1902 double random() noexcept
1907 return static_cast<double>(
state) / 4294967296.0;
1913 return T(0.71) + T(0.063) *
static_cast<T
>(i);
1917 return static_cast<uint32_t
>(i) * 7919u + 1u;
1922 return T(0.83) + T(0.051) *
static_cast<T
>(i);
1926 return static_cast<uint32_t
>(i) * 104729u + 7u;
1932 const double v = std::sin(
static_cast<double>(k) * 12.9898
1933 +
static_cast<double>(s) * 78.233) * 43758.5453;
1934 return v - std::floor(v);
1940 return static_cast<T
>(20.0 * std::log10(std::max(
static_cast<double>(gain), 1e-6)));
1945 return static_cast<int>(
static_cast<T
>(
spec_.
sampleRate) * ms / T(1000));
1958 std::array<std::array<Line, kInStages>, 2>
inAP_;
1963 std::array<std::array<Line, kOutStages>, 2>
outAP_;
1974 std::array<std::array<T, kMaxERSlots>, 2>
erGain_ {};
1981 std::array<std::array<T, kERGroups>, 2>
erLP_ {};
1993 std::array<double, kMaxLines>
pos_ {};
2005 std::array<SmoothRandomLFO, kMaxLines>
lfo_;
2009 alignas(64) std::array<T, kMaxLines / 2>
rotC_ {};
2010 alignas(64) std::array<T, kMaxLines / 2>
rotS_ {};
2050 for (
auto& v : t[0]) v = T(1);
2163 std::atomic<T>
q { T(0.7071) };
2197 std::array<SegmentLfo, kMaxLines>
seg_ {};
2219 &&
qualityDirty_.exchange(
false, std::memory_order_acquire))
2232 &&
presetDirty_.exchange(
false, std::memory_order_acquire))
2240 &&
paramsDirty_.exchange(
false, std::memory_order_acquire))
2256 const T d =
sourceDepth_.load(std::memory_order_relaxed);
2268 static T
glideTo(T cur, T target, T amount)
noexcept
2270 const T next = cur + amount * (target - cur);
2271 return std::abs(target - next) <= T(1e-6) * std::max(T(1), std::abs(target)) ? target : next;
2276 if (!(
toneDirty_.load(std::memory_order_acquire)
2277 &&
toneDirty_.exchange(
false, std::memory_order_acquire)))
2280 const T hpHz =
toneLowCutHz_.load(std::memory_order_relaxed);
2285 toneHPTargetHz_ =
static_cast<double>(std::clamp(hpHz, T(20), T(500)));
2299 toneLPTargetHz_ =
static_cast<double>(std::clamp(lpHz, T(2000), T(16000)));
2311 static void glideHz(
double& cur,
double target,
double amount)
noexcept
2313 const double ratio = target / cur;
2314 if (std::abs(ratio - 1.0) < 1e-4) cur = target;
2315 else cur *= std::pow(ratio, amount);
2325 const double a =
static_cast<double>(amount);
2386 * (T(1) - T(0.8) * d));
2402 for (
int k = 0; k < n / 2; ++k)
2408 rotC_[k] =
static_cast<T
>(std::cos(
static_cast<double>(theta)));
2409 rotS_[k] =
static_cast<T
>(std::sin(
static_cast<double>(theta)));
2413 const double rate =
static_cast<double>(
modRate_.load(std::memory_order_relaxed));
2421 for (
int i = 0; i < n; ++i)
2425 for (
int i = 0; i < n; ++i)
2433 const T wander = segments
2434 ? ((i & 1) ? T(0) :
static_cast<T
>(
seg_[i].next(
kCtrl, rate *
static_cast<double>(
lfoRateFactor(i)), sr)))
2436 const auto aim = [&](T length) {
2438 return std::clamp(
static_cast<double>(length) +
static_cast<double>(m),
2447 bool moving =
false;
2448 for (
int i = 0; i < n; ++i)
2451 if (std::abs(diff) < T(0.01))
2472 for (
int i = 0; i <
nLines_; ++i)
2474 const auto l =
static_cast<std::size_t
>(i);
2490 bool allpassesMoved =
false;
2491 for (
int i = 0; i <
nLines_; ++i)
2493 const auto l =
static_cast<std::size_t
>(i);
2510 if constexpr (M > 1)
2514 [x]<std::size_t... I>(std::index_sequence<I...>) {
2516 const T a = x[I], b = x[I + M / 2];
2518 x[I + M / 2] = a - b;
2520 }(std::make_index_sequence<M / 2> {});
2526 template <
int N,
int W,
typename O>
2529 using V =
typename O::V;
2530 for (
int b = 0; b < N; b += W)
2531 hadamardSmall<W>(x + b);
2532 for (
int h = W; h < N; h <<= 1)
2533 for (
int i = 0; i < N; i += h << 1)
2534 for (
int j = i; j < i + h; j += W)
2536 const V a = O::load(x + j), b = O::load(x + j + h);
2537 O::store(x + j, O::add(a, b));
2538 O::store(x + j + h, O::sub(a, b));
2549 void runFdn(T& lateL, T& lateR,
int injLag, T loopAPCoeff, T inGain, T extra)
noexcept
2551 constexpr int W = std::min(simd::kVecWidth<T>, N);
2552 using O = simd::Vec<T, W>;
2553 using V =
typename O::V;
2554 static_assert(N % W == 0,
"line count must be a multiple of the SIMD width");
2556 alignas(64) std::array<T, N + 1> r;
2557 alignas(64) std::array<T, N> v;
2558 alignas(64) std::array<T, N> tmp;
2559 alignas(64) std::array<int, N> idx;
2565 for (
int i = 0; i < N; ++i)
2568 const int M =
static_cast<int>(p -
kApLow);
2572 for (
int i = 0; i < N; ++i)
2577 for (
int i = 0; i < N; i += W)
2579 const V y = O::madd(O::load(v.data() + i),
2580 O::sub(O::load(r.data() + i), O::load(
apY1_.data() + i)),
2581 O::load(tmp.data() + i));
2582 O::store(
apY1_.data() + i, y);
2583 O::store(r.data() + i, y);
2588 const T fadeNew = fading ?
static_cast<T
>(std::sin(1.5707963267948966 *
fadeAt_)) : T(0);
2589 const T fadeOld = fading ?
static_cast<T
>(std::cos(1.5707963267948966 *
fadeAt_)) : T(1);
2590 if (fading) [[unlikely]]
2591 for (
int i = 0; i < N; ++i)
2594 const int M =
static_cast<int>(p -
kApLow);
2597 r[i] = fadeOld * r[i] + fadeNew * y;
2603 for (
int i = 0; i < N; i += W)
2605 const V x = O::load(r.data() + i);
2606 const V j = O::sub(O::madd(O::load(
jotB0_.data() + i), x,
2607 O::mul(O::load(
jotB1_.data() + i), O::load(
jotX1_.data() + i))),
2608 O::mul(O::load(
jotA1_.data() + i), O::load(
jotY1_.data() + i)));
2609 O::store(
jotX1_.data() + i, x);
2610 O::store(
jotY1_.data() + i, j);
2611 const V b = O::sub(O::madd(O::load(
bassB0_.data() + i), j,
2612 O::mul(O::load(
bassB1_.data() + i), O::load(
bassX1_.data() + i))),
2613 O::mul(O::load(
bassA1_.data() + i), O::load(
bassY1_.data() + i)));
2614 O::store(
bassX1_.data() + i, j);
2615 O::store(
bassY1_.data() + i, b);
2616 O::store(r.data() + i, b);
2620 const int at =
airW_;
2621 T*
const now =
airHist_[
static_cast<std::size_t
>(at)].data();
2622 for (
int i = 0; i < N; i += W) O::store(now + i, O::load(r.data() + i));
2623 for (
int i = 0; i < N; i += W)
2625 V acc = O::mul(O::load(
airTap_[0].data() + i), O::load(now + i));
2627 acc = O::madd(O::load(
airTap_[
static_cast<std::size_t
>(n)].data() + i),
2628 O::load(
airHist_[
static_cast<std::size_t
>((at - n) & (
kAirTaps - 1))].data() + i), acc);
2629 O::store(r.data() + i, acc);
2633 if (
dqCount_ > 0) applyDecayBands<N, W, O>(r.data());
2640 V aL = O::set1(T(0)), aR = aL;
2641 for (
int i = 0; i < N; i += W)
2643 const V x = O::load(r.data() + i);
2644 aL = O::madd(O::load(
outSignL_.data() + i), x, aL);
2645 aR = O::madd(O::load(
outSignR_.data() + i), x, aR);
2647 alignas(64) std::array<T, W> sumL, sumR;
2648 O::store(sumL.data(), aL);
2649 O::store(sumR.data(), aR);
2650 for (
int k = 0; k < W; ++k) { lateL += sumL[k]; lateR += sumR[k]; }
2654 const V norm = O::set1(T(1) / std::sqrt(
static_cast<T
>(N)));
2655 fwht<N, W, O>(r.data());
2657 for (
int i = 0; i < N; i += W)
2658 O::store(v.data() + i, O::mul(norm, O::load(r.data() + i + 1)));
2665 static_assert(
kRotPairStride == 4 && N % 8 == 0,
"rotation pairs are (i, i + 4) in blocks of 8");
2666 for (
int blk = 0; blk < N; blk += 8)
2668 T* lo = v.data() + blk;
2670 const T* c =
rotC_.data() + blk / 2;
2671 const T* sn =
rotS_.data() + blk / 2;
2672 for (
int q = 0; q < 4; ++q)
2674 const T a = lo[q], b = hi[q];
2675 lo[q] = c[q] * a - sn[q] * b;
2676 hi[q] = sn[q] * a + c[q] * b;
2681 if (fading) [[unlikely]]
2683 for (
int i = 0; i < N; ++i)
2688 for (
int i = 0; i < N; ++i)
2690 const int k =
static_cast<int>(
loopAPCur_[i]);
2691 const T f =
loopAPCur_[i] -
static_cast<T
>(k);
2693 tmp[i] = a + f * (
loopAP_.
at(i, k + 1) - a);
2698 for (
int i = 0; i < N; ++i)
2701 const V g = O::set1(loopAPCoeff);
2702 for (
int i = 0; i < N; i += W)
2704 const V d = O::load(tmp.data() + i);
2705 const V w = O::madd(g, d, O::load(v.data() + i));
2706 O::store(v.data() + i, O::sub(d, O::mul(g, w)));
2707 O::store(tmp.data() + i, w);
2709 for (
int i = 0; i < N; ++i)
2714 for (
int i = 0; i < N; ++i)
2722 x = std::copysign(
kSoftLimit + over / (T(1) + over), x);
2736 void designPlate(
double decay,
double t60H,
double crossoverHz)
noexcept
2743 for (
int b = 0; b < 2; ++b)
2745 const auto s =
static_cast<std::size_t
>(b);
2746 const double L =
static_cast<double>(p.lAp1[s] + p.lD1[s] + p.lAp2[s] + p.lD2[s]);
2747 p.gain[s] =
static_cast<T
>(std::pow(0.001, L / (decay * sr)));
2751 const double q = std::pow(0.001, L / sr * (1.0 / t60H - 1.0 / decay));
2754 const double c = std::cos(2.0 * 3.14159265358979323846 * crossoverHz / sr), q2 = q * q;
2755 const double A = 1.0 - q2, B = 1.0 - q2 * c;
2756 damp = std::max(damp, (B - std::sqrt(std::max(0.0, B * B - A * A))) / A);
2759 p.damp =
static_cast<T
>(std::clamp(damp, 0.0, 0.99));
2761 p.phaseStep =
static_cast<double>(
modRate_.load(std::memory_order_relaxed)) / sr;
2763 const double tail = 1.0 / -std::expm1(-std::min(2.0 * 6.907755278982137 * p.loopSec / std::max(1e-3, decay), 50.0));
2768 void runPlate(T& lateL, T& lateR,
int injLag, T inGain, T extra)
noexcept
2771 const T in = T(0.5) * (
ring_[0].at(injLag + 1) +
ring_[1].at(injLag + 1)) * inGain + extra;
2773 const std::array<T, 2> ends { p.
d2[0].at(p.lD2[0]), p.d2[1].at(p.lD2[1]) };
2774 p.phase += p.phaseStep;
2775 if (p.phase >= 1.0) p.phase -= 1.0;
2776 for (
int b = 0; b < 2; ++b)
2778 const auto s =
static_cast<std::size_t
>(b);
2779 T x = in + ends[1 - s];
2782 const double turn = p.phase + 0.25 * b;
2783 const double pos =
static_cast<double>(p.lAp1[s])
2784 + p.excursion *
static_cast<double>(
fastSin(
static_cast<T
>(6.283185307179586 * (turn - std::floor(turn)) - 3.141592653589793)));
2785 const int k =
static_cast<int>(pos);
2786 const T fr =
static_cast<T
>(pos - k);
2787 const T dl = p.ap1[s].at(k) + fr * (p.ap1[s].at(k + 1) - p.ap1[s].at(k));
2791 const T v = p.d1[s].at(p.lD1[s]);
2794 const T damp = p.damp * (T(1) - hold);
2795 p.lp[s] = v + damp * (p.lp[s] - v);
2796 x = p.lp[s] * (p.gain[s] + (T(1) - p.gain[s]) * hold);
2797 const T d2 = p.ap2[s].at(p.lAp2[s]);
2803 auto tap = [&p](
const Line& l,
double at29k) {
return l.
at(p.at(at29k)); };
2804 lateL += T(0.6) * (tap(p.d1[1], 266) + tap(p.d1[1], 2974) - tap(p.ap2[1], 1913) + tap(p.d2[1], 1996)
2805 - tap(p.d1[0], 1990) - tap(p.ap2[0], 187) - tap(p.d2[0], 1066));
2806 lateR += T(0.6) * (tap(p.d1[0], 353) + tap(p.d1[0], 3627) - tap(p.ap2[0], 1228) + tap(p.d2[0], 2673)
2807 - tap(p.d1[1], 2111) - tap(p.ap2[1], 335) - tap(p.d2[1], 121));
2825 const auto l =
static_cast<std::size_t
>(j);
2826 const double M =
static_cast<double>(s.len[l]);
2828 const double gM = std::pow(0.001, M / (d2 * sr));
2829 const double gH = std::min(std::pow(0.001, M / (h2 * sr)), gM);
2830 const double ratio = std::sqrt(gM / gH);
2831 const double a = Kh * ratio, b = Kh / ratio, inv = 1.0 / (1.0 + b);
2832 s.b0[l] =
static_cast<T
>(gH * (1.0 + a) * inv);
2833 s.b1[l] =
static_cast<T
>(gH * (a - 1.0) * inv);
2834 s.a1[l] =
static_cast<T
>((b - 1.0) * inv);
2837 const double amount =
static_cast<double>(
doubleSlope_.load(std::memory_order_relaxed));
2838 s.on = amount > 0.0 && !
spring_;
2847 const auto tail = [](
double loopSec,
double t60) {
return 1.0 / std::expm1(std::min(2.0 * 6.907755278982137 * loopSec / std::max(1e-3, t60), 50.0)); };
2849 s.gain =
static_cast<T
>(std::sqrt(share / ((1.0 - share) * own)));
2850 s.keep =
static_cast<T
>(std::sqrt(1.0 - share));
2857 constexpr T kGlide = T(0.001);
2858 s.gainNow += kGlide * (s.gain - s.gainNow);
2859 s.keepNow += kGlide * (s.keep - s.keepNow);
2863 const auto l =
static_cast<std::size_t
>(j);
2864 const T x = s.line[l].at(s.len[l]);
2865 const T v = s.b0[l] * x + s.b1[l] * s.x1[l] - s.a1[l] * s.y1[l];
2870 const T outL = y[0] - y[1] + y[2] - y[3];
2871 const T outR = y[0] + y[1] - y[2] - y[3];
2872 hadamardSmall<SecondSlope::kLines>(y);
2875 const auto l =
static_cast<std::size_t
>(j);
2876 const T feed =
ring_[
static_cast<std::size_t
>(j & 1)].at(injLag + 1 + 7 * j);
2877 s.line[l].push(T(0.5) * (y[j] + ((j & 2) ? -feed : feed)));
2879 lateL = s.keepNow * lateL + s.gainNow * outL;
2880 lateR = s.keepNow * lateR + s.gainNow * outR;
2894 template <
int N,
int W,
typename O>
2897 using V =
typename O::V;
2900 const auto b =
static_cast<std::size_t
>(
dqList_[
static_cast<std::size_t
>(k)]);
2901 T* z1 =
dqZ1_[b].data();
2902 T* z2 =
dqZ2_[b].data();
2903 const T* b0 =
dqB0_[b].data();
2904 const T* b1 =
dqB1_[b].data();
2905 const T* b2 =
dqB2_[b].data();
2906 const T* a1 =
dqA1_[b].data();
2907 const T* a2 =
dqA2_[b].data();
2908 for (
int i = 0; i < N; i += W)
2910 const V x = O::load(r + i);
2911 const V y = O::madd(O::load(b0 + i), x, O::load(z1 + i));
2912 O::store(z1 + i, O::sub(O::madd(O::load(b1 + i), x, O::load(z2 + i)), O::mul(O::load(a1 + i), y)));
2913 O::store(z2 + i, O::sub(O::mul(O::load(b2 + i), x), O::mul(O::load(a2 + i), y)));
2936 template <
int Springs,
int Stages>
2942 constexpr int NW = simd::kVecNarrowWidth<T>;
2943 constexpr int W = (Springs % NW == 0) ? NW : 1;
2944 using O = simd::Vec<T, W>;
2945 using V =
typename O::V;
2948 const int mask = P - 1;
2953 const T drive[2] = { T(0.75) * raw[0] + T(0.25) * raw[1],
2954 T(0.25) * raw[0] + T(0.75) * raw[1] };
2959 const T fadeNew = fading ?
static_cast<T
>(std::sin(1.5707963267948966 *
fadeAt_)) : T(0);
2960 const T fadeOld = fading ?
static_cast<T
>(std::cos(1.5707963267948966 *
fadeAt_)) : T(1);
2961 alignas(64) std::array<T, Springs> x;
2962 for (
int s = 0; s < Springs; ++s)
2965 const int M =
static_cast<int>(p -
kApLow);
2966 const T eta =
allpassCoeff(p -
static_cast<double>(M));
2970 if (fading) [[unlikely]]
2973 const int M2 =
static_cast<int>(p2 -
kApLow);
2976 x[s] = fadeOld * y + fadeNew * y2;
2983 const std::size_t stageStride =
static_cast<std::size_t
>(P) *
kSprings;
2984 const std::size_t wOff =
static_cast<std::size_t
>(iw) *
kSprings;
2985 const std::size_t kOff =
static_cast<std::size_t
>(ik) *
kSprings;
2986 for (
int g = 0; g < Springs; g += W)
2988 V xv = O::load(x.data() + g);
2990 for (
int m = 0; m < Stages; ++m, hin += stageStride)
2992 O::store(hin + wOff, xv);
2993 xv = O::madd(a, O::sub(xv, O::load(hin + stageStride + kOff)), O::load(hin + kOff));
2995 O::store(hin + wOff, xv);
2996 O::store(x.data() + g, xv);
3000 for (
int k = 0; k < 2; ++k)
3002 const auto& c =
springLP_[
static_cast<std::size_t
>(k)];
3003 const V b0 = O::set1(c[0]), b1 = O::set1(c[1]), b2 = O::set1(c[2]);
3004 const V a1 = O::set1(c[3]), a2 = O::set1(c[4]);
3006 T* s2 =
springLPState_[
static_cast<std::size_t
>(2 * k + 1)].data();
3007 for (
int g = 0; g < Springs; g += W)
3009 const V xv = O::load(x.data() + g);
3010 const V y = O::madd(b0, xv, O::load(s1 + g));
3011 O::store(s1 + g, O::sub(O::madd(b1, xv, O::load(s2 + g)), O::mul(a1, y)));
3012 O::store(s2 + g, O::sub(O::mul(b2, xv), O::mul(a2, y)));
3013 O::store(x.data() + g, y);
3017 T out[2] = { T(0), T(0) };
3018 for (
int s = 0; s < Springs; ++s) out[s & 1] += x[s];
3021 for (
int g = 0; g < Springs; g += W)
3023 const V xv = O::load(x.data() + g);
3024 const V j = O::sub(O::madd(O::load(
jotB0_.data() + g), xv,
3025 O::mul(O::load(
jotB1_.data() + g), O::load(
jotX1_.data() + g))),
3026 O::mul(O::load(
jotA1_.data() + g), O::load(
jotY1_.data() + g)));
3027 O::store(
jotX1_.data() + g, xv);
3028 O::store(
jotY1_.data() + g, j);
3029 const V b = O::sub(O::madd(O::load(
bassB0_.data() + g), j,
3030 O::mul(O::load(
bassB1_.data() + g), O::load(
bassX1_.data() + g))),
3031 O::mul(O::load(
bassA1_.data() + g), O::load(
bassY1_.data() + g)));
3032 O::store(
bassX1_.data() + g, j);
3033 O::store(
bassY1_.data() + g, b);
3034 O::store(x.data() + g, b);
3036 if (
dqCount_ > 0) applyDecayBands<Springs, W, O>(x.data());
3037 for (
int s = 0; s < Springs; ++s)
3043 v = std::copysign(
kSoftLimit + over / (T(1) + over), v);
3049 const T og =
kSpringOutGain / std::sqrt(
static_cast<T
>(Springs / 2));
3050 lateL += out[0] * og;
3051 lateR += out[1] * og;
3063 static void addTap(T* acc,
const Line& l,
int lag0, T gain,
int count)
noexcept
3067 const T* b = l.buf.data();
3068 const int start = (l.w - lag0) & l.mask;
3069 const int first = std::min(count, l.mask + 1 - start);
3078 for (
int s = 0; s < count;)
3080 const int m = std::min(count - s, l.mask + 1 - l.w);
3081 T* DSPARK_RESTRICT dst = l.buf.data() + l.w;
3082 for (
int k = 0; k < m; ++k) dst[k] = src[s + k];
3083 l.w = (l.w + m) & l.mask;
3097 static void diffuseSpans(
Line& ap,
int len, T g0, T gDelta,
const T* ramp, T* x,
int count)
noexcept
3099 const int size = ap.mask + 1;
3100 const int delay = std::max(1, len);
3101 for (
int s = 0; s < count;)
3103 const int readAt = (ap.w - delay) & ap.mask;
3104 const int m = std::max(1, std::min({ delay, count - s, size - readAt, size - ap.w, size - delay }));
3105 const T* DSPARK_RESTRICT rd = ap.buf.data() + readAt;
3106 T* DSPARK_RESTRICT wr = ap.buf.data() + ap.w;
3107 T* DSPARK_RESTRICT xs = x + s;
3108 const T* rs = ramp + s;
3109 for (
int k = 0; k < m; ++k)
3111 const T g = g0 + gDelta * rs[k];
3113 const T w = xs[k] + g * d;
3117 ap.w = (ap.w + m) & ap.mask;
3129 void processChunk(
const T* inL,
const T* inR, T* outL, T* outR,
int count)
noexcept
3133 const int last = count - 1;
3139 const std::array<T, kInStages> inAP0 =
inAPCoeff_;
3146 T toneHP0 = T(0), toneLP0 = T(0);
3152 const T rampStep = T(1) /
static_cast<T
>(count);
3162 const bool absorbRamp =
holdNow_ != hold0 || absorbMoved;
3173 for (
int n = 0; n < count; ++n) peak = std::max(peak, std::max(std::abs(inL[n]), std::abs(inR[n])));
3176 const bool holding =
holdNow_ != T(0) || hold0 != T(0);
3177 const T in0 = T(1) - hold0, in1 = T(1) -
holdNow_;
3180 alignas(64) T narrowL[
kChunk];
3181 alignas(64) T narrowR[
kChunk];
3185 for (
int n = 0; n < count; ++n)
3187 const T mid = (inL[n] + inR[n]) * T(0.5), side = (inL[n] - inR[n]) * T(0.5) * w;
3188 narrowL[n] = mid + side;
3189 narrowR[n] = mid - side;
3201 const double hd =
static_cast<double>(
highDecayMult_.load(std::memory_order_relaxed));
3202 const double darkness =
static_cast<double>(d) * (1.25 - 0.5 * hd);
3203 const double fc = std::min(18000.0 * std::exp2(-3.0 * darkness), 0.45 *
spec_.
sampleRate);
3209 alignas(64) T raw[2][
kChunk];
3210 for (
int c = 0; c < 2; ++c)
3213 const T* in = c == 0 ? inL : inR;
3214 for (
int n = 0; n < count; ++n) pre.
push(in[n]);
3215 std::fill(raw[c], raw[c] + count, T(0));
3216 addTap(raw[c], pre, pd + 1 + last, T(1), count);
3223 const double slope = 1.0 / ratio - 1.0;
3224 constexpr double kThreshold = -30.0, kKnee = 24.0;
3225 const double makeup = -slope * 12.0;
3227 for (
int n = 0; n < count; ++n)
3229 const double peak = std::max(
static_cast<double>(raw[0][n]) * raw[0][n],
3230 static_cast<double>(raw[1][n]) * raw[1][n]);
3231 const double over = 10.0 * std::log10(0.5 * peak + 1e-30) - kThreshold;
3232 const double gr = over <= -0.5 * kKnee ? 0.0
3233 : over >= 0.5 * kKnee ? slope * over
3234 : slope * (over + 0.5 * kKnee) * (over + 0.5 * kKnee) / (2.0 * kKnee);
3244 const T g =
static_cast<T
>(std::pow(10.0, (
levelGr_ + makeup) / 20.0));
3245 for (
int c = 0; c < 2; ++c)
3247 T x = raw[c][n] * g;
3248 if (saturate) x = std::tanh(T(1.5) * x) * T(1.0 / 1.5);
3259 alignas(64) T ramp[
kChunk];
3260 for (
int n = 0; n < count; ++n) ramp[n] = static_cast<T>(n + 1) * rampStep;
3261 for (
int c = 0; c < 2; ++c)
3264 std::copy_n(raw[c], count, x);
3265 auto& aps =
inAP_[
static_cast<std::size_t
>(c)];
3268 const T g0 = inAP0[
static_cast<std::size_t
>(st)];
3269 diffuseSpans(aps[
static_cast<std::size_t
>(st)],
inAPLen_[
static_cast<std::size_t
>(c)][
static_cast<std::size_t
>(st)],
3270 g0,
inAPCoeff_[
static_cast<std::size_t
>(st)] - g0, ramp, x, count);
3278 for (
int s = 0; s < 2; ++s)
3289 alignas(64) T early[2][
kChunk];
3290 for (
int s = 0; s < 2; ++s)
3292 const Line* src[4] = { &
ring_[
static_cast<std::size_t
>(s)], &
ring_[
static_cast<std::size_t
>(1 - s)],
3293 &
preDelay_[
static_cast<std::size_t
>(s)], &
preDelay_[
static_cast<std::size_t
>(1 - s)] };
3294 const int lagOff[4] = { last, last, pd + last, pd + last };
3295 std::fill(early[s], early[s] + count, T(0));
3296 auto& lp =
erLP_[
static_cast<std::size_t
>(s)];
3302 for (
auto& a : acc) std::fill(a, a + count, T(0));
3309 constexpr T hf =
static_cast<T
>(
kShadowHF) - T(1);
3310 T z =
erShadowLP_[
static_cast<std::size_t
>(s)][
static_cast<std::size_t
>(g)];
3311 for (
int n = 0; n < count; ++n)
3313 const T x = acc[1][n];
3315 acc[0][n] += x + hf * (x - z);
3317 erShadowLP_[
static_cast<std::size_t
>(s)][
static_cast<std::size_t
>(g)] = z;
3323 const T hg =
erShelfGain_[
static_cast<std::size_t
>(g)];
3325 for (
int n = 0; n < count; ++n)
3327 const T x = acc[0][n];
3329 early[s][n] += y + hg * (x - y);
3335 for (
int n = 0; n < count; ++n)
3342 T lateL = T(0), lateR = T(0);
3343 const T a =
static_cast<T
>(n + 1) * rampStep;
3344 const T inGain = holding ? in0 + (in1 - in0) * a : T(1);
3347 const T rawN[2] = { raw[0][n] * inGain, raw[1][n] * inGain };
3348 if (
eco_) runSprings<kEcoSprings, kEcoSpringStages>(lateL, lateR, rawN);
3349 else runSprings<kSprings, kSpringStages>(lateL, lateR, rawN);
3353 const T loopG = loopAP0 + (
loopAPCoeff_ - loopAP0) * a;
3356 else if (
eco_) runFdn<kEcoLines>(lateL, lateR, gap + last - n, loopG, inGain, extra);
3357 else runFdn<kMaxLines>(lateL, lateR, gap + last - n, loopG, inGain, extra);
3362 const T earlyNow = early0 + (
earlyCur_ - early0) * a;
3363 auto [yl, yr] =
outputStage(lateL, lateR, early[0][n], early[1][n],
3364 holding ? earlyNow * inGain : earlyNow,
3370 if (
tail_.isActive())
3372 const T g =
tail_.next(std::max(std::abs(inL[n]), std::abs(inR[n])));
3392 T sum = T(0), weight = T(0);
3393 for (
int h = 0; h < 2; ++h)
3395 const auto hh =
static_cast<std::size_t
>(h);
3397 const double len =
shimLen_[hh] * sr;
3400 const double delay = 1.0 + len * (1.0 - ph);
3401 const int di =
static_cast<int>(delay);
3402 const T f =
static_cast<T
>(delay - di);
3405 const T w =
static_cast<T
>(0.5 - 0.5 * std::cos(6.283185307179586 * ph));
3406 sum += w * (s0 + f * (s1 - s0));
3418 return weight > T(0.25) ? sum / weight : sum * T(4);
3426 const double u =
static_cast<double>(
shimRng_) / 4294967296.0;
3438 for (
const T b :
airNow_) most = std::max(most, b);
3439 const double b =
static_cast<double>(most);
3440 double t = 1.0, sum = 1.0;
3444 t *= b /
static_cast<double>(count);
3445 if (t <= 1e-7 * (sum + t))
break;
3450 for (
int i = 0; i < kMaxLines; ++i) setAirTaps(static_cast<std::size_t>(i));
3458 const double b =
static_cast<double>(
airNow_[l]);
3460 double t = 1.0, sum = 0.0;
3463 if (n > 0) t *= b /
static_cast<double>(n);
3467 for (
int n = 0; n < kAirTaps; ++n) airTap_[static_cast<std::size_t>(n)][l] =
static_cast<T
>(taps[n] / sum);
3473 const T f =
holdNow_, k = T(1) - f;
3476 const auto l =
static_cast<std::size_t
>(i);
3486 const auto b =
static_cast<std::size_t
>(
dqList_[
static_cast<std::size_t
>(q)]);
3504 const auto b =
static_cast<std::size_t
>(
dqList_[
static_cast<std::size_t
>(q)]);
3514 const auto ramp = [perSample](
auto& now,
auto& from,
auto& step) {
3515 for (std::size_t i = 0; i < now.size(); ++i)
3517 step[i] = (now[i] - from[i]) * perSample;
3528 const auto b =
static_cast<std::size_t
>(
dqList_[
static_cast<std::size_t
>(q)]);
3538 const auto add = [](
auto& now,
const auto& step) {
3539 for (std::size_t i = 0; i < now.size(); ++i) now[i] += step[i];
3544 for (
int n = 0; n < kAirTaps; ++n) add(airTap_[static_cast<std::size_t>(n)],
airTapStep_[
static_cast<std::size_t
>(n)]);
3547 const auto b =
static_cast<std::size_t
>(
dqList_[
static_cast<std::size_t
>(q)]);
3556 T earlyLevel, T lateLevel, T width,
3557 T toneHPMix, T toneLPMix, T outAPCoeff)
noexcept
3560 const T lateLvl = lateLevel *
kOutGain;
3566 T* lr[2] = { &lateL, &lateR };
3567 const T g = outAPCoeff;
3568 for (
int c = 0; c < 2; ++c)
3573 Line& ap =
outAP_[
static_cast<std::size_t
>(c)][
static_cast<std::size_t
>(k)];
3574 const T d = ap.
at(
outAPLen_[
static_cast<std::size_t
>(c)][
static_cast<std::size_t
>(k)]);
3575 const T w = x + g * d;
3589 T mid = (lateL + lateR) * T(0.5);
3590 T side = (lateL - lateR) * T(0.5);
3592 side =
static_cast<T
>(hp *
static_cast<double>(width));
3598 T out[2] = { earlyL * earlyLevel + lateL,
3599 earlyR * earlyLevel + lateR };
3600 for (
int c = 0; c < 2; ++c)
3603 for (
int c = 0; c < 2; ++c)
3605 T& z =
distLp_[
static_cast<std::size_t
>(c)];
3612 for (
int c = 0; c < 2; ++c)
3615 out[c] = toneHPMix == T(1) ? f : out[c] + toneHPMix * (f - out[c]);
3618 for (
int c = 0; c < 2; ++c)
3621 out[c] = toneLPMix == T(1) ? f : out[c] + toneLPMix * (f - out[c]);
3623 return { out[0], out[1] };
3645 return T(0.35) + T(0.65) *
size_.load(std::memory_order_relaxed);
3651 const double sz =
static_cast<double>(
sizeFactor());
3652 const auto ms = [sr](
double v) {
return std::max(1,
static_cast<int>(v * sr / 1000.0)); };
3653 const bool geometric =
layout_.load(std::memory_order_relaxed) == 1;
3661 const double baseMs = geometric
3663 static_cast<double>(src) / (
kMaxLines - 1))
3680 const double springScale = 0.6 + 2.0 *
static_cast<double>(
size_.load(std::memory_order_relaxed));
3681 for (
int s = 0; s <
nLines_; ++s)
3684 for (
int c = 0; c < 2; ++c)
3686 inAPLen_[
static_cast<std::size_t
>(c)][
static_cast<std::size_t
>(st)]
3692 const double diff =
static_cast<double>(
diffusion_.load(std::memory_order_relaxed));
3695 const double dist =
static_cast<double>(
sourceDepth_.load(std::memory_order_relaxed));
3698 ?
static_cast<T
>(std::min(0.8,
kInDiffCoeffs_[st] * diff + 0.25 * dist * dist))
3708 const double aRef = 0.3 + 0.5 * diff;
3710 const double f = 72.0 /
springStages_ * (1.0 + aRef) / (1.0 - aRef);
3711 springA_ =
static_cast<T
>((f - 1.0) / (f + 1.0));
3718 const T rate =
modRate_.load(std::memory_order_relaxed);
3753 const double t60H = std::max(0.05, decay *
static_cast<double>(
3755 const double t60B = std::max(0.05, decay *
static_cast<double>(
3757 const double kPi = 3.14159265358979323846;
3758 const double fh = std::clamp(
static_cast<double>(
3759 highCrossover_.load(std::memory_order_relaxed)), 100.0, 0.45 * sr);
3760 const double fb = std::clamp(
static_cast<double>(
3761 bassCrossover_.load(std::memory_order_relaxed)), 10.0, 0.45 * sr);
3762 const double Kh = std::tan(kPi * fh / sr);
3763 const double Kb = std::tan(kPi * fb / sr);
3764 const double air =
static_cast<double>(
airAbsorption_.load(std::memory_order_relaxed));
3765 double loopSum = 0.0;
3775 * (1.0 -
static_cast<double>(
springA_)) / (1.0 +
static_cast<double>(
springA_))
3777 const double gM = std::pow(0.001, M / (decay * sr));
3778 if (i <
nLines_) loopSum += M;
3779 const double gH = std::min(std::pow(0.001, M / (t60H * sr)), gM);
3782 const double gB = std::min(std::pow(0.001, M / (t60B * sr)), 0.9995);
3785 const double ratio = std::sqrt(gM / gH);
3786 const double a = Kh * ratio, b = Kh / ratio, inv = 1.0 / (1.0 + b);
3787 jotB0_[i] =
static_cast<T
>(gH * (1.0 + a) * inv);
3788 jotB1_[i] =
static_cast<T
>(gH * (a - 1.0) * inv);
3789 jotA1_[i] =
static_cast<T
>((b - 1.0) * inv);
3792 const double sq = std::sqrt(gB / gM);
3793 const double a = Kb * sq, b = Kb / sq, inv = 1.0 / (1.0 + b);
3794 bassB0_[i] =
static_cast<T
>((1.0 + a) * inv);
3795 bassB1_[i] =
static_cast<T
>((a - 1.0) * inv);
3796 bassA1_[i] =
static_cast<T
>((b - 1.0) * inv);
3803 const auto l =
static_cast<std::size_t
>(i);
3807 const auto prevList =
dqList_;
3824 double longest = std::max({ decay, t60H, t60B });
3827 const auto b =
static_cast<std::size_t
>(
dqList_[
static_cast<std::size_t
>(q)]);
3828 longest = std::max(longest, decay *
static_cast<double>(
getDecayBand(
static_cast<int>(b)).multiplier));
3829 const bool known = std::find(prevList.begin(), prevList.begin() + prevCount,
static_cast<int>(b))
3830 != prevList.begin() + prevCount;
3831 if (!known && !empty)
3835 const auto l =
static_cast<std::size_t
>(i);
3837 for (
int r = 1; r < 5; ++r) dqBase_[static_cast<std::size_t>(r)][b][l] = T(0);
3858 const auto b =
static_cast<std::size_t
>(
dqList_[
static_cast<std::size_t
>(q)]);
3859 for (
int r = 0; r < 5; ++r)
3860 dqBase_[
static_cast<std::size_t
>(r)][b] =
dqGoal_[
static_cast<std::size_t
>(r)][b];
3870 bool moving =
false;
3871 const auto step = [&](T& cur, T goal) {
3873 moving = moving || cur != goal;
3875 for (
int r = 0; r < 3; ++r)
3878 const auto rr =
static_cast<std::size_t
>(r), l =
static_cast<std::size_t
>(i);
3883 step(
airBase_[
static_cast<std::size_t
>(i)],
airGoal_[
static_cast<std::size_t
>(i)]);
3887 const auto l =
static_cast<std::size_t
>(i);
3892 const auto b =
static_cast<std::size_t
>(
dqList_[
static_cast<std::size_t
>(q)]);
3893 for (
int r = 0; r < 5; ++r)
3895 step(
dqBase_[
static_cast<std::size_t
>(r)][b][
static_cast<std::size_t
>(i)],
3896 dqGoal_[
static_cast<std::size_t
>(r)][b][
static_cast<std::size_t
>(i)]);
3910 const auto l =
static_cast<std::size_t
>(i);
3915 for (
auto& v :
airHist_) v.fill(T(0));
3937 const double t = 293.15, t0 = 293.15, t01 = 273.16, hr = 50.0;
3938 const double psat = std::pow(10.0, -6.8346 * std::pow(t01 / t, 1.261) + 4.6151);
3939 const double h = hr * psat;
3940 const double frO = 24.0 + 4.04e4 * h * (0.02 + h) / (0.391 + h);
3941 const double frN = std::pow(t / t0, -0.5) * (9.0 + 280.0 * h * std::exp(-4.170 * (std::pow(t / t0, -1.0 / 3.0) - 1.0)));
3942 const double f2 = hz * hz;
3943 return 8.686 * f2 * (1.84e-11 * std::sqrt(t / t0)
3944 + std::pow(t / t0, -2.5) * (0.01275 * std::exp(-2239.1 / t) / (frO + f2 / frO)
3945 + 0.1068 * std::exp(-3352.0 / t) / (frN + f2 / frN)));
3953 [[nodiscard]]
static double airDepth(
double amount,
double loopSeconds,
double sr)
noexcept
3955 if (!(amount > 0.0) || !(loopSeconds > 0.0))
return 0.0;
3956 const double hz = std::min(
kAirFitHz, 0.4 * sr);
3958 const double x = 1.0 - std::cos(2.0 * 3.14159265358979323846 * hz / sr);
3959 return std::min(lossDb / (8.685889638065037 * x),
kAirMaxDepth);
3963 [[nodiscard]]
static double shelfGain(
double a,
double b,
double w)
noexcept
3965 const double c = std::cos(w), sn = std::sin(w);
3966 const double nr = (1.0 + a) + (a - 1.0) * c, ni = -(a - 1.0) * sn;
3967 const double dr = (1.0 + b) + (b - 1.0) * c, di = -(b - 1.0) * sn;
3968 return std::sqrt((nr * nr + ni * ni) / (dr * dr + di * di));
3985 [[nodiscard]]
double heardTailEnergy(
double decay,
double t60H,
double t60B,
double Kh,
double Kb)
const noexcept
3988 constexpr int kPoints = 24;
3989 const double top = std::min(16000.0, 0.45 * sr);
3990 double sum = 0.0, weight = 0.0;
3991 for (
int p = 0; p < kPoints; ++p)
3993 const double f = 31.25 * std::pow(top / 31.25,
static_cast<double>(p) / (kPoints - 1));
3994 const double f2 = f * f, f4 = f2 * f2, hp = f4 / (f4 + 38.0 * 38.0 * 38.0 * 38.0);
3995 const double heard = hp * (1.0 + 1.51 * f2 / (f2 + 1700.0 * 1700.0));
3996 const double w = 2.0 * kPi * f / sr;
3997 double t60 = 0.0, firstPass = 0.0;
3998 for (
int i = 0; i <
nLines_; ++i)
4000 const auto l =
static_cast<std::size_t
>(i);
4003 * (1.0 -
static_cast<double>(
springA_)) / (1.0 +
static_cast<double>(
springA_))
4005 const double gM = std::pow(0.001, M / (decay * sr));
4006 const double gH = std::min(std::pow(0.001, M / (t60H * sr)), gM);
4007 const double gB = std::min(std::pow(0.001, M / (t60B * sr)), 0.9995);
4008 const double rh = std::sqrt(gM / gH), rb = std::sqrt(gB / gM);
4010 * std::exp(-
static_cast<double>(
airGoal_[l]) * (1.0 - std::cos(w)));
4013 const auto b =
static_cast<std::size_t
>(
dqList_[
static_cast<std::size_t
>(k)]);
4015 c.
b0 =
static_cast<double>(
dqGoal_[0][b][l]);
4016 c.
b1 =
static_cast<double>(
dqGoal_[1][b][l]);
4017 c.
b2 =
static_cast<double>(
dqGoal_[2][b][l]);
4018 c.
a1 =
static_cast<double>(
dqGoal_[3][b][l]);
4019 c.
a2 =
static_cast<double>(
dqGoal_[4][b][l]);
4022 g = std::clamp(g, 1e-9, 0.9999999);
4023 t60 += -3.0 * M / (sr * std::log10(g));
4026 t60 /=
static_cast<double>(std::max(1,
nLines_));
4027 firstPass /=
static_cast<double>(std::max(1,
nLines_));
4028 const double x = std::min(2.0 * 6.907755278982137 *
meanLoopSec_ / std::max(1e-3, t60), 50.0);
4029 sum += heard * (
spring_ ? 1.0 + 1.0 / std::expm1(x) : firstPass / -std::expm1(-x));
4032 return sum / weight;
4047 return { 0.0, 0.0 };
4057 if (!(window[1] > window[0]) ||
meanLoopSec_ <= 0.0)
return 0.0;
4058 const double tau =
static_cast<double>(
decayTime_.load(std::memory_order_relaxed)) / (2.0 * 6.907755278982137);
4062 * (std::exp(-(window[0] * 1e-3 - tInj) / tau) - std::exp(-(window[1] * 1e-3 - tInj) / tau));
4068 const double c1 = std::cos(w), s1 = std::sin(w), c2 = std::cos(2.0 * w), s2 = std::sin(2.0 * w);
4069 const double nr = q.b0 + q.b1 * c1 + q.b2 * c2, ni = -(q.b1 * s1 + q.b2 * s2);
4070 const double dr = 1.0 + q.a1 * c1 + q.a2 * c2, di = -(q.a1 * s1 + q.a2 * s2);
4071 return std::sqrt((nr * nr + ni * ni) / std::max(1e-300, dr * dr + di * di));
4084 std::array<DecayBand, kDecayBands> bands {};
4089 bands[
static_cast<std::size_t
>(
dqCount_)] = b;
4094 constexpr int kGrid = 32;
4095 std::array<double, kGrid> grid {};
4096 for (
int g = 0; g < kGrid; ++g)
4097 grid[
static_cast<std::size_t
>(g)] = 2.0 * 3.14159265358979323846
4098 * 20.0 * std::pow(0.45 * sr / 20.0,
static_cast<double>(g) / (kGrid - 1)) / sr;
4103 * (1.0 -
static_cast<double>(
springA_)) / (1.0 +
static_cast<double>(
springA_))
4105 const double gM = std::pow(0.001, M / (decay * sr));
4106 const double gH = std::min(std::pow(0.001, M / (t60H * sr)), gM);
4107 const double gB = std::min(std::pow(0.001, M / (t60B * sr)), 0.9995);
4108 const double rh = std::sqrt(gM / gH), rb = std::sqrt(gB / gM);
4109 const auto loopGain = [&](
double w) {
return gH *
shelfGain(Kh * rh, Kh / rh, w) *
shelfGain(Kb * rb, Kb / rb, w); };
4111 std::array<double, kDecayBands> gains {};
4114 const DecayBand& b = bands[
static_cast<std::size_t
>(k)];
4117 : loopGain(2.0 * 3.14159265358979323846 *
static_cast<double>(b.
frequency) / sr);
4118 gains[
static_cast<std::size_t
>(k)] = 20.0 * std::log10(std::clamp(ref, 1e-6, 0.999999))
4119 * (1.0 /
static_cast<double>(b.
multiplier) - 1.0);
4121 std::array<BiquadCoeffs, kDecayBands> coeffs {};
4122 const auto design = [&](
double boostScale) {
4125 const DecayBand& b = bands[
static_cast<std::size_t
>(k)];
4126 double g = gains[
static_cast<std::size_t
>(k)];
4127 if (g > 0.0) g *= boostScale;
4128 const double f = std::min(
static_cast<double>(b.
frequency), 0.45 * sr);
4129 coeffs[
static_cast<std::size_t
>(k)] =
4135 const auto peakLoop = [&]() {
4137 for (
double w : grid)
4139 double v = loopGain(w);
4140 for (
int k = 0; k < dqCount_; ++k) v *= biquadGain(coeffs[static_cast<std::size_t>(k)], w);
4141 top = std::max(top, v);
4148 double lo = 0.0, hi = 1.0;
4149 for (
int it = 0; it < 12; ++it)
4151 const double mid = 0.5 * (lo + hi);
4159 const auto b =
static_cast<std::size_t
>(
dqList_[
static_cast<std::size_t
>(k)]);
4160 const auto l =
static_cast<std::size_t
>(i);
4161 const BiquadCoeffs& c = coeffs[
static_cast<std::size_t
>(k)];
4162 dqGoal_[0][b][l] =
static_cast<T
>(c.
b0);
4163 dqGoal_[1][b][l] =
static_cast<T
>(c.
b1);
4164 dqGoal_[2][b][l] =
static_cast<T
>(c.
b2);
4165 dqGoal_[3][b][l] =
static_cast<T
>(c.
a1);
4166 dqGoal_[4][b][l] =
static_cast<T
>(c.
a2);
4174 const int note =
preNote_.load(std::memory_order_relaxed);
4175 if (note == 0)
return static_cast<double>(
preDelayMs_.load(std::memory_order_relaxed));
4187 const int note =
gateNote_.load(std::memory_order_relaxed);
4188 const double ms = note == 0 ?
static_cast<double>(
gateHoldMs_.load(std::memory_order_relaxed))
4189 : std::min(
noteMs(note,
gateFeel_.load(std::memory_order_relaxed)), 4000.0);
4190 tail_.setGateHold(
static_cast<T
>(ms));
4194 [[nodiscard]]
double noteMs(
int note,
int feel)
const noexcept
4196 static constexpr double kBeats[7] = { 0.0, 4.0, 2.0, 1.0, 0.5, 0.25, 0.125 };
4197 const double beat = 60000.0 /
static_cast<double>(
tempo_.load(std::memory_order_relaxed));
4198 const double factor = feel == 1 ? 1.5 : feel == 2 ? 2.0 / 3.0 : 1.0;
4199 return beat * kBeats[
static_cast<std::size_t
>(std::clamp(note, 0, 6))] * factor;
4221 const double target =
static_cast<double>(
decayTime_.load(std::memory_order_relaxed));
4222 if (!(sr > 0.0) ||
nLines_ < 1)
return target;
4223 const double hd =
static_cast<double>(
highDecayMult_.load(std::memory_order_relaxed));
4224 const double bd =
static_cast<double>(
bassDecayMult_.load(std::memory_order_relaxed));
4225 const double kPi = 3.14159265358979323846;
4226 const double Kh = std::tan(kPi * std::clamp(
static_cast<double>(
4227 highCrossover_.load(std::memory_order_relaxed)), 100.0, 0.45 * sr) / sr);
4228 const double Kb = std::tan(kPi * std::clamp(
static_cast<double>(
4229 bassCrossover_.load(std::memory_order_relaxed)), 10.0, 0.45 * sr) / sr);
4230 auto loopLen = [&](
int i) {
4233 * (1.0 -
static_cast<double>(
springA_)) / (1.0 +
static_cast<double>(
springA_))
4238 auto shelf = [](
double a,
double b,
double w) {
4239 const double c = std::cos(w), sn = std::sin(w);
4240 const double nr = (1.0 + a) + (a - 1.0) * c, ni = -(a - 1.0) * sn;
4241 const double dr = (1.0 + b) + (b - 1.0) * c, di = -(b - 1.0) * sn;
4242 return std::sqrt((nr * nr + ni * ni) / (dr * dr + di * di));
4247 auto t60At = [&](
double d,
double hz) {
4248 const double w = 2.0 * kPi * hz / sr;
4251 for (
int i = 0; i <
nLines_; ++i)
4253 const double M = loopLen(i);
4254 if (!(M > 0.0))
continue;
4255 const double gM = std::pow(0.001, M / (d * sr));
4256 const double gH = std::min(std::pow(0.001, M / (std::max(0.05, d * hd) * sr)), gM);
4257 const double gB = std::min(std::pow(0.001, M / (std::max(0.05, d * bd) * sr)), 0.9995);
4258 const double rh = std::sqrt(gM / gH), rb = std::sqrt(gB / gM);
4259 const double g = gH * shelf(Kh * rh, Kh / rh, w) * shelf(Kb * rb, Kb / rb, w);
4260 if (!(g > 0.0 && g < 1.0))
continue;
4261 rate += -sr * std::log10(g) / (3.0 * M);
4264 return (used > 0 && rate > 0.0) ? used / rate : d;
4267 for (
int it = 0; it < 4; ++it)
4269 const double tm = 0.5 * (t60At(d, 500.0) + t60At(d, 1000.0));
4270 if (!(tm > 0.0))
break;
4273 return std::clamp(d, 0.05, 120.0);
4320 constexpr double p = 1.6;
4323 const int discrete = 1 +
static_cast<int>(std::lround(
4326 const double decay =
static_cast<double>(
decayTime_.load(std::memory_order_relaxed));
4327 constexpr double kLn1000 = 6.907755278982137;
4330 struct Tap {
double ms;
int chan;
int bin;
double gain;
bool candidate;
bool raw; };
4331 std::array<std::array<Tap, kMaxERTaps>, 2> taps {};
4332 std::array<int, 2> used { 0, 0 };
4333 for (
int c = 0; c < 2; ++c)
4335 std::array<double,
kMaxERTaps / 2> gv {}, msv {}, lat {};
4337 for (
int k = 0; k < R; ++k)
4339 const double u = (k + 0.15 + 0.7 *
hash01(k, c + 20)) / R;
4342 const double w = 0.3 * u + 0.7 * std::pow(u, 1.0 / p);
4343 msv[k] = minMs + (maxMs - minMs) * w;
4344 const double density = 1.0 / (0.3 + 0.7 / p * std::pow(std::max(u, 1e-3), 1.0 / p - 1.0));
4345 const double sign = k < 4 ||
hash01(k, c + 40) < 0.5 ? 1.0 : -1.0;
4350 gv[k] = sign * std::exp(-kLn1000 * msv[k] * 1e-3 / decay) / std::sqrt(density);
4351 if (k >= discrete) dcSum += gv[k];
4358 const double side =
hash01(k, c + 50) < 0.92 - 0.42 * w ? 1.0 : -1.0;
4359 lat[k] = k < 2 ? 0.5 : side * (0.25 + 0.75 *
hash01(k, c + 60));
4364 for (
int k = discrete; k < R; ++k) gv[k] -= dcSum / (R - discrete);
4365 double energy = 0.0;
4366 for (
int k = 0; k < R; ++k) energy += gv[k] * gv[k];
4373 const double tau = decay / (2.0 * kLn1000);
4374 const double tInj =
static_cast<double>(
erToLateSamples_.load(std::memory_order_relaxed)) / sr
4376 const double target =
static_cast<double>(
kOutGain) *
static_cast<double>(
kOutGain)
4378 * (std::exp(-(minMs * 1e-3 - tInj) / tau) - std::exp(-(maxMs * 1e-3 - tInj) / tau));
4379 const double norm = std::sqrt(0.5 * target / energy);
4385 for (
int e = 0; e < 2; ++e)
4387 for (
int k = 0; k < R; ++k)
4389 const double x = e == c ? lat[k] : -lat[k];
4390 const double phi = std::asin(std::min(1.0, std::abs(x)));
4391 const double itdMs = x < 0.0 ? 1000.0 * 0.0875 / 343.0 * (phi + std::sin(phi)) : 0.0;
4392 const int bin = x < -0.3 ? 1 : 0;
4393 const double ild = x > 0.0 ? 1.0 + 0.2 * x : 1.0 + 0.5 * x;
4394 taps[e][used[e]++] = { msv[k] + itdMs, e == c ? 0 : 1, bin, gv[k] * norm * ild,
4399 for (
int e = 0; e < 2; ++e)
4402 std::sort(taps[e].begin(), taps[e].begin() + used[e],
4403 [](
const Tap& a,
const Tap& b) {
return a.ms < b.ms; });
4407 int slot = 0, group = 1;
4409 for (
int k = 0; k < used[e]; ++k)
4413 const Tap& t = taps[e][k];
4414 const int lag = std::max(1,
static_cast<int>(t.ms * sr / 1000.0));
4415 const auto put = [&](
int chan,
double gain) {
4424 put(t.chan + 2, t.raw ? t.gain : 0.0);
4425 put(t.chan, t.raw ? 0.0 : t.gain);
4429 put(t.chan, t.gain);
4438 const double fh = std::clamp(
static_cast<double>(
highCrossover_.load(std::memory_order_relaxed)),
4440 erShelfCoeff_ =
static_cast<T
>(1.0 - std::exp(-6.283185307179586 * fh / sr));
4442 *
static_cast<double>(
highDecayMult_.load(std::memory_order_relaxed)));
4449 for (
int e = 0; e < 2; ++e)
4457 if (second)
continue;
4458 tSum +=
erTap_[e][k] / sr;
4462 const double t = cnt > 0 ? tSum / cnt : 0.0;
4463 erShelfGainTarget_[g] =
static_cast<T
>(std::pow(10.0, -3.0 * t * std::max(0.0, 1.0 / t60H - 1.0 / decay)));
4472 static const std::vector<uint8_t> sieve = []
4478 if (s[
static_cast<size_t>(i)])
4480 s[
static_cast<size_t>(j)] = 0;
4489 if (n <= 2)
return 2;
4497 if (n % 2 == 0) ++n;
4500 bool isPrime =
true;
4501 for (
int d = 3; d * d <= n; d += 2)
4502 if (n % d == 0) { isPrime =
false;
break; }
4503 if (isPrime)
return n;
4521 const uint32_t m =
userParamMask_.load(std::memory_order_acquire);
4522 if (!(m &
kUserSize))
size_.store(p.size, std::memory_order_relaxed);
4527 damping_.store(std::clamp((T(1) - p.hdMult) / T(0.9), T(0), T(1)),
4528 std::memory_order_relaxed);
4541 std::memory_order_relaxed);
4552 return { T(0.22), T(0.5), T(0.40), T(1.1), T(5000), T(250),
4553 T(0.72), T(0.07), T(0.5), T(1), T(0.8), T(0) };
4555 return { T(0.68), T(2.2), T(0.32), T(1.3), T(4500), T(200),
4556 T(0.84), T(0.10), T(0.55), T(1), T(1), T(15) };
4558 return { T(0.38), T(1.2), T(0.38), T(1.1), T(5000), T(250),
4559 T(0.78), T(0.08), T(0.6), T(1), T(0.9), T(8) };
4561 return { T(0.14), T(1.5), T(0.55), T(0.8), T(7000), T(150),
4562 T(0.94), T(0.16), T(1.4), T(0), T(1), T(0) };
4564 return { T(0.11), T(0.9), T(0.28), T(1.0), T(4000), T(200),
4565 T(0.6), T(0.08), T(0.35), T(0.5), T(1), T(0) };
4569 return { T(0.98), T(5.0), T(0.24), T(1.5), T(3500), T(150),
4570 T(0.91), T(0.12), T(0.35), T(1), T(1), T(25) };
True-stereo 32-line FDN reverb with exact per-band decay and 6 presets.
static constexpr T rotRateFactor(int i) noexcept
std::array< std::array< T, kMaxLines >, kDecayBands > dqB2_
void setGateRelease(T ms) noexcept
Release of the gate, 5 to 4000 ms (default 150).
bool isTailHeld() const noexcept
void setBandLimit(T hz) noexcept
Limits the band of the wet signal, as early digital reverbs did: an elliptic wall (order 12,...
std::atomic< int > preNote_
std::atomic< T > inputWidth_
static constexpr double kOutDiffMs_[2][kOutStages]
void setSpaceLayout(SpaceLayout layout) noexcept
How the line lengths are laid out: Prime (the default) takes the tuned base lengths; Geometric spaces...
static double shelfGain(double a, double b, double w) noexcept
Quality
Engine quality / CPU cost trade-off (see setQuality()).
@ Eco
Reduced 8-line engine, about 3x cheaper. For constrained targets.
@ Full
Complete 32-line engine. Default.
void runSprings(T &lateL, T &lateR, const T(&raw)[2]) noexcept
One sample of the spring tanks (Type::Spring): six springs per side (one in Eco), all of different le...
std::array< T, kMaxLines > airNow_
std::array< int, kMaxLines > loopAPFrom_
std::array< std::array< T, kERGroups >, 2 > erShadowLP_
T getHighDecayMultiplier() const noexcept
KeyEqualizer< T, 2 > postEq_
static constexpr double kLoopApMs_[kMaxLines]
std::atomic< T > modDepth_
static void hadamardSmall(T *x) noexcept
T sizeFactor() const noexcept
Size factor: size 0 -> 0.35, size 1 -> 1.
std::array< PublishedDecayBand, kDecayBands > decayBands_
T getWidth() const noexcept
double quietSamples_
samples since input last entered the tank
std::array< int, kMaxLines > loopAPLen_
in-loop allpass target lengths
std::pair< T, T > outputStage(T lateL, T lateR, T earlyL, T earlyR, T earlyLevel, T lateLevel, T width, T toneHPMix, T toneLPMix, T outAPCoeff) noexcept
double meanLoopSec_
mean FDN round trip (s), for the early/late energy match
T getTankLeveling() const noexcept
std::atomic< int > erToLateSamples_
void setWidthLaw(WidthLaw law) noexcept
How setWidth() acts on the tail: Side (the default) scales the side; PowerKept also raises the middle...
void processChunk(const T *inL, const T *inR, T *outL, T *outR, int count) noexcept
Core processing of up to kChunk samples: stereo in, wet stereo out.
T erGlidePerSample_
glide rate of the two (1 / samples)
static constexpr double kAirFitHz
void setTankLeveling(T amount) noexcept
Leveling of the tank, 0 to 1 (0, the default, is off): a compressor on the tank's input (ratio 1 + 3 ...
void beginSizeFade() noexcept
Opens the second read head of every line at the new lengths (with the wander the first one carries) a...
std::array< T, kERGroups > erShelfGainTarget_
static constexpr double kSecondRatio
its decay times, as a share of the tank's
void holdAbsorption() noexcept
The loop gains as they stand, kept for the ramp of a chunk.
static constexpr double kInjectMs_[kMaxLines]
void endSizeFade() noexcept
The fade is over: the second heads become the first.
static constexpr double kMaxInjectMs
T wetLevel_
the wet signal's level against the decay (see updateDecayParams())
static constexpr int kShadowBins
head-shadow classes of the early taps (open, shadowed)
static constexpr int kInStages
input diffusers per channel feeding the late field (Full)
static constexpr double kSpringCutHz
dispersion band edge (transition frequency)
std::array< T, kInStages > inAPCoeffTarget_
inAPCoeff_ glides here (setDiffusion)
void snapGlides() noexcept
Puts every gliding parameter (levels, width, diffusion, tone) at its target.
std::array< std::array< std::array< T, kMaxLines >, kDecayBands >, 5 > dqGoal_
std::atomic< T > gateHoldMs_
void applyHoldShelves() noexcept
The shelves and decay bands of applyHoldCoeffs().
T getInputWidth() const noexcept
std::array< std::array< T, kMaxLines >, 6 > absFrom_
The loop gains' ramp across a chunk: where they stood and their step per sample.
std::atomic< T > toneHighCutHz_
static constexpr double kMaxErToLateMs
void drainTone() noexcept
void setSourceDepth(T amount) noexcept
Depth of the source in the room, 0 to 1 (0, the default, is off): one control that moves the balance ...
std::array< T, kMaxLines/2 > rotC_
std::array< std::array< T, kERGroups >, 2 > erLP_
std::array< T, kMaxLines > bassY1_
std::array< T, kMaxLines > airGoal_
std::array< double, kMaxLines > posInc_
per-sample ramp
void setTailHold(bool on) noexcept
Holds the tail: the input to the tank and the early field fade out over about 20 ms while every loop'...
static constexpr double kInDiffCoeffs_[kInStages]
static constexpr double kInDiffMs_[2][kInStages]
std::atomic< int > widthLaw_
static void diffuseSpans(Line &ap, int len, T g0, T gDelta, const T *ramp, T *x, int count) noexcept
One Schroeder allpass stage over a chunk: w = x + g d, out = d - g w, with g = g0 + gDelta ramp[n] at...
std::atomic< T > lateLevel_
std::array< T, kMaxLines > airBase_
void runPlate(T &lateL, T &lateR, int injLag, T inGain, T extra) noexcept
One sample of the plate tank: the late pair, from the diffused feed.
static double hash01(int k, int s) noexcept
Deterministic hash in [0, 1) for the early-reflection layout.
void setQuality(Quality q) noexcept
Selects the engine quality / CPU cost trade-off.
Type getType() const noexcept
static void glideHz(double &cur, double target, double amount) noexcept
One glide step of a running cutoff toward its target (log domain).
std::atomic< T > modRate_
std::array< T, 2 > distLp_
static constexpr AirTaps identityAirTaps() noexcept
static constexpr uint32_t rotSeed(int i) noexcept
NoteValue getPreDelayNote() const noexcept
std::array< std::array< T, kMaxLines >, kAirTaps > AirTaps
std::array< int, kMaxLines > lenTarget_
prime line lengths (samples)
static constexpr int kMaxERSlots
static void fwht(T *x) noexcept
std::atomic< T > doubleSlope_
std::array< std::array< int, kMaxERSlots >, 2 > erBin_
std::array< std::array< T, kMaxLines >, 3 > bassGoal_
void setTankSaturation(bool on) noexcept
Soft saturation after the leveling compressor (off by default).
NoteValue
A note value for the tempo-synced times.
void setToneHighCut(T hz) noexcept
Sets a post-reverb high-cut filter on the wet signal (12 dB/oct).
static constexpr double kMaxInDiffMs
static constexpr double kMaxGlideSpeed
max length change per sample (4% Doppler)
static constexpr double kMaxDecayLoopGain
Highest loop gain the decay bands may reach.
static constexpr double kSizeFadeSeconds
the cross-fade of the two read heads
static constexpr double kPlateEnergy
The plate's tail energy over the tail formula (measured, 1.5 to 8 s: within 0.25 dB).
std::atomic< T > highDecayMult_
double calibratedMidDecay() const noexcept
The loop's DC decay that puts the ISO 3382 mid-frequency reverberation time on the decay setting.
void applyPreset(Type type) noexcept
static const std::vector< uint8_t > & getPrimeSieve() noexcept
std::array< T, kMaxLines > lenCur_
gliding length
std::pair< T, T > processSample(T input) noexcept
Processes a single mono sample and returns the wet stereo pair.
void generateERTapsForType(Type type) noexcept
Regenerates the early-reflection taps for a reverb type (Eco caps the count).
void refreshCachedParams() noexcept
Pulls the atomic parameters into the block-local cache (audio thread).
static constexpr int kPrimeTableMax
void setDiffusion(T amount) noexcept
Diffusion (0 - 1): the strength of the input, in-loop and output allpass diffusers,...
void refreshAirInUse() noexcept
void setType(Type type) noexcept
Loads the selected preset baseline.
std::array< double, kMaxLines > posInc2_
void setGateHoldNote(NoteValue note, NoteFeel feel=NoteFeel::Straight) noexcept
Gate hold as a note value at the tempo (Off, the default, uses setGateHold()); up to 4 s.
static constexpr int kEcoSprings
static constexpr double kMaxPreDelayMs
std::atomic< bool > tailHold_
std::array< double, kMaxLines > pos2_
double tankEmptyAfter_
quiet samples after which the tank is under -120 dB
static constexpr double kApLow
void setEarlyLevel(T dB) noexcept
Early reflections level in dB (-60 to +6). 0 dB is the physical balance: the early field then carries...
static constexpr int kMaxERTaps
early taps per output side: 64 reflections per input (Full)
Quality getQuality() const noexcept
std::array< T, kMaxLines > outSignR_
Biquad< T, 2 > toneLPBiquad_
static constexpr double kMeanInjectMs
mean of kInjectMs_
static constexpr int kOutSignR_[kMaxLines]
std::atomic< int > modStyle_
static constexpr double kWetCalibrationSpring
static constexpr int kSpringStages
dispersion allpasses per spring (Full)
std::atomic< int > preFeel_
void setGate(T thresholdDb) noexcept
Gate on the wet signal (see TailShaper): it closes once the dry signal has stayed thresholdDb under i...
double drawShimmerLength() noexcept
std::array< std::array< std::array< T, kMaxLines >, kDecayBands >, 5 > dqBase_
T getErToLateDelay() const noexcept
std::array< T, kMaxLines > jotB1_
std::atomic< bool > plateTank_
static constexpr T kOutGain
bool isThicknessSaturated() const noexcept
DecayBand getDecayBand(int index) const noexcept
T getEffectivePreDelay() const noexcept
std::array< double, kMaxLines > pos_
current read position
static constexpr double kShadowHz
head-shadow corner of the early taps
void updateAll() noexcept
std::atomic< bool > tankSat_
static constexpr int kOutStages
int airTapCount_
taps that carry more than 1e-7 of the largest b's sum
std::array< std::array< T, kMaxLines >, kDecayBands > dqA2_
static constexpr int kChunk
sparse-FIR processing chunk (samples)
T toneHPMix_
share of the filtered signal
T getDecay() const noexcept
T getSize() const noexcept
static constexpr std::array< double, SecondSlope::kLines > kSecondMs
std::array< T, kMaxLines > jotA1_
int levelHoldSamples_
Tank leveling: hold left and its length.
static constexpr int kMaxLines
std::atomic< bool > paramsDirty_
void runSecondSlope(T &lateL, T &lateR, int injLag) noexcept
One sample of the second slope, added to the late pair.
std::array< T, kInStages > inAPCoeff_
std::array< T, kMaxLines/2 > rotS_
Biquad< T, 1 > coherenceFilter_
std::array< std::array< T, 5 >, 2 > springLP_
b0 b1 b2 a1 a2, two sections
std::array< std::array< T, kMaxLines >, kDecayBands > dqB0_
std::atomic< T > toneLowCutHz_
std::array< T, kMaxLines > apY1_
allpass interpolator state
void controlTick() noexcept
Control-rate update: glides the line lengths toward their targets, draws the next modulation values a...
static constexpr double kCoherenceQ
static constexpr T rotRate() noexcept
void glideAbsorption(T gc) noexcept
std::array< std::array< T, kMaxLines >, 3 > jotBase_
std::array< T, kMaxLines > outSignL_
std::array< T, kMaxLines > lenNew_
T erShelfCoeff_
one-pole coefficient at the high crossover
static int nearestPrime(int n) noexcept
Smallest prime >= n (lengths only grow by a few samples).
void rampAbsorption(T perSample) noexcept
T getBassDecayMultiplier() const noexcept
T shimmerStep(T input) noexcept
One sample of the octave-up shimmer: two read heads, half a window apart, sweep the recent input at t...
double earlyEnergy() const noexcept
The energy of the early field in the tail's units: the tail's own energy flow over the early window (...
void setModulation(T amount) noexcept
Modulation depth (0 - 1) of the delay-line wander. It smears the tail's resonances; 0 is fully static...
void setAirAbsorption(T amount) noexcept
The absorption of the air inside the tank, on top of the walls' (opt-in; the network types).
T getSourceDepth() const noexcept
void setDryDip(T dB) noexcept
Dips the wet signal under the dry one while it plays (see TailShaper): by up to dB (0 to 48; 0,...
T getHighCrossover() const noexcept
T getModulation() const noexcept
static constexpr double kBaseDelaysMs_[kMaxLines]
static double biquadGain(const BiquadCoeffs &q, double w) noexcept
static double airDepth(double amount, double loopSeconds, double sr) noexcept
The b of a line: its loss in decibels, 8.686 b (1 - cos w), at kAirFitHz is the air's over a round tr...
static constexpr uint32_t lfoSeed(int i) noexcept
static constexpr int kDecayBands
Bands of the decay equalizer.
std::array< std::array< Line, kOutStages >, 2 > outAP_
late-field output diffusers
static T levelDb(T gain) noexcept
Linear gain to dB (a zero gain, a preset's muted early field, reads -120 dB).
std::atomic< T > erToLateMs_
std::atomic< T > bandLimit_
void setBassCrossover(T hz) noexcept
Frequency where the bass decay transition is centered.
std::array< std::array< T, kMaxLines >, 3 > bassBase_
static constexpr int kInjectSign_[kMaxLines]
T getEarlyLevel() const noexcept
Early reflections level in dB (as set, or the preset's).
void setPreDelay(T ms) noexcept
Pre-delay before the early reflections, in ms (0 - 500); a note value set by setPreDelayNote() takes ...
T getPreDelay() const noexcept
static constexpr T kSpringOutGain
std::array< T, kERGroups > erShelfGain_
HF gain of each absorption group.
void setPreDelayNote(NoteValue note, NoteFeel feel=NoteFeel::Straight) noexcept
Pre-delay as a note value at the tempo (Off, the default, uses setPreDelay()); up to 500 ms.
ModulationStyle getModulationStyle() const noexcept
std::array< std::array< int, kInStages >, 2 > inAPLen_
void updateDelayLengths() noexcept
static constexpr double kShimmerMaxMs
Longest window of the shimmer's heads.
Biquad< T, 2 > subsonicFilter_
std::array< std::array< T, kMaxLines >, kDecayBands > dqA1_
void setMix(T dryWet) noexcept
Dry/wet mix (0 = dry, 1 = wet). The wet signal is calibrated to the dry one's level: on pink noise at...
T getModRate() const noexcept
void drainPendingChanges() noexcept
Drains deferred parameter changes on the audio thread.
std::array< SegmentLfo, kMaxLines > seg_
int msToSamples(T ms) const noexcept
void setGateHold(T ms) noexcept
Hold of the gate, 0 to 4000 ms (default 100); a note value set by setGateHoldNote() takes its place.
void updateDiffCoeffs() noexcept
static constexpr double kWetCalibration
static constexpr int kEcoSpringStages
void setShimmer(T amount) noexcept
Octave-up shimmer, 0 to 1 (0, the default, is off): the tail is pitched up an octave by two read head...
void reset() noexcept
Clears all delay lines and filter states and restarts the modulation, snapping any length glide to it...
static constexpr int kCtrl
modulation control period (samples)
std::atomic< T > earlyLevel_
double effectivePreDelayMs() const noexcept
The pre-delay in ms: the note value's time at the tempo, or the one set.
std::array< std::array< T, kMaxERSlots >, 2 > erGain_
current (gliding) tap gains
std::array< std::array< int, kMaxERSlots >, 2 > erChan_
bool fresh_
no sample processed since prepare()/reset()
static constexpr T kShimmerFeed
Share of the shimmer fed back at full amount.
std::array< std::array< std::array< T, kMaxLines >, kDecayBands >, 5 > dqStep_
std::array< T, kMaxLines > bassX1_
static constexpr T lfoRateFactor(int i) noexcept
std::atomic< int > gateFeel_
static constexpr double kSpringJitterMs
bool setState(const uint8_t *data, size_t size)
Restores parameters from a blob (tolerant; rejects foreign ids).
T getBassCrossover() const noexcept
void updateModulation() noexcept
std::array< std::array< T, kSprings >, 4 > springLPState_
[section * 2 + state][spring]
Biquad< T, 2 > toneHPBiquad_
static constexpr int kRotPairStride
void setInputWidth(T width) noexcept
Width of the input, 0 to 1 (1, the default, is the input as it is): the side of the input is scaled b...
void runFdn(T &lateL, T &lateR, int injLag, T loopAPCoeff, T inGain, T extra) noexcept
One sample of the N-line FDN (compile-time N so the per-line stages vectorize): allpass-interpolated ...
std::array< T, kMaxLines > loopAPCur_
gliding lengths after a size change
static constexpr std::array< double, 2 > earlyWindow(Type type) noexcept
The early reflections' window of a type, in ms (none: both zero).
T getGateRelease() const noexcept
std::atomic< T > tankLeveling_
std::array< T, kMaxLines > injGain_
sign / sqrt(lines)
std::array< std::array< Line, kInStages >, 2 > inAP_
std::atomic< int > layout_
static constexpr double kSecondShare
its share of the tail's energy at 1
void setLateLevel(T dB) noexcept
Late tail level in dB (-60 to +6). Changes glide over about 20 ms.
T getMix() const noexcept
void setModulationStyle(ModulationStyle style) noexcept
How the line lengths wander: Smooth (the default) is the smooth random modulation of every line; Segm...
DecayShape
Shape of a band of the decay equalizer (setDecayBand()).
void snapTone() noexcept
Puts the tone filters at their targets at once (prepare, reset).
SpaceLayout
How the line lengths are laid out (setSpaceLayout()).
void setToneLowCut(T hz) noexcept
Sets a post-reverb low-cut filter on the wet signal (12 dB/oct).
std::vector< uint8_t > getState() const
Serializes the parameter state (setup/UI threads; allocates).
std::array< T, kMaxLines > bassA1_
static double springBaseMs(int s) noexcept
std::array< T, kMaxLines > bassB1_
WidthLaw
How the output width acts (setWidthLaw()).
T getGateHold() const noexcept
T getLateLevel() const noexcept
Late tail level in dB (as set, or the preset's).
void snapAbsorption() noexcept
The absorption at its design at once (no glide).
CachedParams cachedParams_
bool airInUse_
any line's b, designed, gliding or in use, above 0
std::atomic< T > bassDecayMult_
std::array< int, kDecayBands > dqList_
std::atomic< bool > toneDirty_
void setPostEqBand(int index, const typename KeyEqualizer< T, 2 >::Band &band) noexcept
One band of the wet signal's equalizer (KeyEqualizer bands).
std::vector< T > springHist_
void designPlate(double decay, double t60H, double crossoverHz) noexcept
The plate tank's decay and damping. A branch takes its gain once a pass, from its own length; the dam...
static constexpr int kPostBands
Bands of the wet equalizer.
std::array< T, kMaxLines > bassB0_
std::array< int, kMaxLines > loopAPTo_
static constexpr double kMaxErMs
std::atomic< T > diffusion_
double noteMs(int note, int feel) const noexcept
A note value's time at the tempo, in ms.
static constexpr int kERGroups
absorption groups (early -> late)
void setDamping(T amount) noexcept
Sets high-frequency damping (0 = bright, 1 = dark).
std::array< std::array< T, kMaxLines >, kDecayBands > dqZ1_
static T glideTo(T cur, T target, T amount) noexcept
void setErToLateDelay(T ms) noexcept
Extra gap between the early reflections and the late tail, in ms (0 - 200).
void processBlock(AudioBufferView< T > buffer) noexcept
Processes an audio block in place with zero allocations.
T getAirAbsorption() const noexcept
static constexpr double kAirMaxDepth
void markUserParam(uint32_t bit) noexcept
T getDryDip() const noexcept
std::array< std::array< int, kOutStages >, 2 > outAPLen_
static constexpr T kMinReadPos
static constexpr double kRotRateHz
std::atomic< uint32_t > userParamMask_
void setSize(T size) noexcept
Room size (0.01 - 1). Scales the delay lines from 36% to 100% of their base lengths....
double heardTailEnergy(double decay, double t60H, double t60B, double Kh, double Kb) const noexcept
The energy of the tail for a unit of energy injected, as heard. At each frequency the first pass leav...
void designSecondSlope(double decay, double t60H, double Kh) noexcept
The second slope's absorption and shares. Fed and summed as the tank is (unit energy in,...
bool getPostEqLoudness() const noexcept
bool isPlateTank() const noexcept
std::array< std::array< int, kERGroups+1 >, 2 > erGroupStart_
slot index per side
std::atomic< bool > presetDirty_
void commitPreset(const PresetValues &p) noexcept
std::array< SmoothRandomLFO, kMaxLines/2 > rotLfo_
static constexpr double kSubsonicHz
wet-output high-pass (2nd order): no room rings below it
std::atomic< T > shimmer_
void setDoubleSlope(T amount) noexcept
A second slope, 0 to 1 (0, the default, is off): beside the tank, four lines of its own decay in 0....
std::atomic< T > decayTime_
void setModRate(T hz) noexcept
Modulation rate in Hz (0.1 - 5); each line wanders at its own multiple.
int numERTaps_
reflections per output side
void stepAbsorption() noexcept
One sample of the loop gains' ramp.
std::array< std::array< int, kMaxERSlots >, 2 > erTap_
T getTempo() const noexcept
NoteFeel
The feel of a note value.
static constexpr double kSizeFadeOver
a length change beyond this share cross-fades two read heads
static constexpr int kSprings
std::array< SmoothRandomLFO, kMaxLines > lfo_
void updateDecayParams() noexcept
Per-line absorption: Jot mid/high shelf and bass shelf.
SpaceLayout getSpaceLayout() const noexcept
std::array< std::array< T, kMaxERSlots >, 2 > erGainTarget_
gains for the current size/decay
std::array< std::array< T, kMaxLines >, 6 > absStep_
T getGate() const noexcept
void setDecayBand(int index, const DecayBand &band) noexcept
One band of the decay equalizer: the decay time in a band of frequencies, as a multiple of what the o...
void applyDecayBands(T *r) noexcept
The decay bands in the loop, one TDF-II biquad per line and band (the per-line arithmetic runs across...
static constexpr double kSoundSpeed
void setWidth(T width) noexcept
Sets stereo width of the late reverb tail.
@ Chamber
Recording studio chamber, warm, balanced.
@ Spring
Spring reverb, bouncy vintage character.
@ Cathedral
Large cathedral, immense decay, vast space.
@ Hall
Concert hall, spacious, long smooth tail.
@ Plate
Metal plate, dense shimmer, no early reflections.
@ Room
Small room, short decay, dense close reflections.
double levelRelease_
Tank leveling: the reduction (dB) and its release.
std::atomic< T > bassCrossover_
void setAirTaps(std::size_t l) noexcept
static constexpr double kShimmerMinMs
Shortest window of the shimmer's heads.
T getDiffusion() const noexcept
~AlgorithmicReverb()=default
KeyEqualizer< T, 2 >::Band getPostEqBand(int index) const noexcept
std::array< std::array< T, kMaxLines >, 3 > jotGoal_
std::atomic< T > damping_
void setHighDecayMultiplier(T mult) noexcept
Sets HF decay as a multiplier of mid decay time.
T getDoubleSlope() const noexcept
std::array< std::array< T, kMaxLines >, kDecayBands > dqZ2_
std::array< Line, 2 > preDelay_
void setPlateTank(bool on) noexcept
The plate's own tank (off by default; Type::Plate only): the figure-eight of Dattorro's plate instead...
void generateERTaps(double minMs, double maxMs, int numTaps) noexcept
Velvet-noise early field (Valimaki et al.): numTaps sparse +-1 impulses per side between minMs and ma...
std::array< Line, 2 > ring_
allpass-diffused input, feeds the late field
void setPostEqLoudness(bool on) noexcept
Keeps the loudness of the wet signal through its equalizer (off by default; see KeyEqualizer::setLoud...
std::atomic< T > airAbsorption_
std::atomic< T > sourceDepth_
static T allpassCoeff(double d) noexcept
static constexpr double kCoherenceHz
side high-pass of the late field (2nd order, Q 0.74)
std::array< std::array< T, kMaxLines >, kDecayBands > dqB1_
std::atomic< Quality > quality_
static constexpr int kAirTaps
static void addTap(T *acc, const Line &l, int lag0, T gain, int count) noexcept
T getShimmer() const noexcept
void refreshTopology() noexcept
Line count of the active engine: the springs, or the FDN size.
static constexpr int kMaxDiscreteER
std::array< T, kMaxLines > jotX1_
void applyHoldCoeffs() noexcept
The absorption and decay bands in use: the designed ones moved toward unity by the tail hold.
void setHighCrossover(T hz) noexcept
Frequency where the HF decay transition is centered.
static constexpr double kModMaxMs
void prepare(const AudioSpec &spec)
Prepares the reverberation engine and allocates required memory.
std::array< T, kMaxLines > jotY1_
std::array< T, kMaxLines > jotB0_
WidthLaw getWidthLaw() const noexcept
void setDecay(T seconds) noexcept
Mid-frequency reverberation time in seconds (0.1 - 30).
static constexpr double kShadowHF
high-frequency gain of a shadowed (far-ear) tap
void designDecayBands(double decay, double t60H, double t60B, double Kh, double Kb) noexcept
Designs the decay bands per line (audio thread at the drain, or prepare()): each band's gain from the...
static constexpr int kEcoLines
int numERSlots_
tap slots per output side (see kMaxERSlots)
double fadeStep_
the fade, 0 to 1, and its step per sample
std::atomic< T > highCrossover_
std::atomic< int > gateNote_
T getDamping() const noexcept
std::array< double, 2 > shimPhase_
static void writeSpan(Line &l, const T *src, int count) noexcept
Pushes count samples into a line, in pieces that stop at its end.
std::vector< T > shimBuf_
std::atomic< Type > type_
ModulationStyle
How the lines' lengths wander (setModulationStyle()).
std::array< T, kMaxLines > apY2_
static double airAttenuationDbPerMetre(double hz) noexcept
The air's attenuation in dB per metre at 20 degrees C, 50 % relative humidity and one atmosphere (ISO...
void applyTopology(Type type) noexcept
void advanceTone(T amount, T &hp0, T &lp0) noexcept
void refreshGateHold() noexcept
void refreshPreDelay() noexcept
std::array< double, 2 > shimLen_
std::array< std::array< std::array< T, kMaxLines >, kDecayBands >, 5 > dqFrom_
NoteValue getGateHoldNote() const noexcept
bool toneLPActive_
filter running (on, or still fading out)
static constexpr int kOutSignL_[kMaxLines]
void setBassDecayMultiplier(T mult) noexcept
Sets bass decay as a multiplier of mid decay time.
std::atomic< bool > qualityDirty_
std::array< int, kMaxLines > injTap_
static constexpr T kSoftLimit
in-loop safety limiter threshold
static PresetValues presetValues(Type type) noexcept
The parameter values of each preset.
std::atomic< int > preDelaySamples_
T getBandLimit() const noexcept
static constexpr double kGlideMs
size-change glide time constant
void setTempo(T bpm) noexcept
Tempo for the note values, 20 to 400 BPM (default 120).
std::atomic< T > preDelayMs_
static constexpr double kRotMaxRad
peak rotation angle at modulation 1 (rad)
void advanceSizeFade() noexcept
One sample of a size fade; at its end the second heads become the first.
static constexpr double kMaxLoopApMs
static constexpr int kEcoERTaps
Non-owning view over audio channel data.
void reset() noexcept
Clears the memory of every node. Coefficients and ramps are kept.
Biquad filter using Transposed Direct Form II (TDF-II) with thread-safe updates.
void setCoeffsNow(const BiquadCoeffs &c) noexcept
Stream-owner direct set: makes c the active set immediately.
void reset() noexcept
Resets all per-channel filter states to zero to avoid ringing/clicks.
T processSample(T input, int channel) noexcept
Processes a single sample for a specific channel.
double processSampleCore(double input, int channel) noexcept
One recursion step in the core's own precision (double).
RAII scope guard to disable denormalised (subnormal) floating-point numbers.
Pre-allocated, SIMD-friendly dry/wet blender for real-time audio.
static AnalogCascade ellipticHighCut(double hz, int order=12, double rippleDb=0.05, double stopDb=100.0) noexcept
Elliptic high cut: flat to the corner within the ripple, then a wall down to the stop level.
static BiquadCoeffs bilinear(const AnalogSection §ion, double sampleRate, double exactHz) noexcept
The bilinear transform of a section, with one frequency mapped exactly.
Six bands of cuts, bells, shelves and tilts over the key of a dynamics processor.
void setLoudnessCompensation(bool on) noexcept
Keeps the loudness (off by default): the bands' change of the K-weighted level of pink noise (as BS....
bool getLoudnessCompensation() const noexcept
void writeState(StateWriter &w, const char *prefix) const
Writes the bands under keys that start with a prefix ("<prefix><band>.shape", ".freq",...
bool sync() noexcept
Takes the settings published since the last call.
void processFrame(T *frame, int channels) noexcept
One frame of the key, every channel of it, in place.
void advance(int samples) noexcept
Moves the equalizer on in time: the coefficients between two designs, the bands on the move to their ...
void reset() noexcept
Clears the memory of the filters (settings and glides are kept).
void readState(const StateReader &r, const char *prefix) noexcept
Reads the bands writeState() wrote (a band that is missing reads as Off, a placement that is missing ...
Band getBand(int band) const noexcept
The published settings of a band (a band out of range reads as Off).
void setBand(int band, const Band &settings) noexcept
Publishes the settings of a band.
void prepare(double sampleRate) noexcept
Prepares the equalizer for a sample rate and clears its memory.
Tolerant reader: missing keys yield defaults, unknown keys are skipped.
float read(const char *key, float defaultValue) const
Reads a float, or defaultValue when the key is absent.
bool isValid() const noexcept
uint32_t processorId() const noexcept
Serializes key/value parameters into a versioned blob.
std::vector< uint8_t > blob() const
Finalizes and returns the blob.
void write(const char *key, float value)
Writes a float parameter.
A dip and a relative gate driven by the dry signal.
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.
Main namespace for the DSPark framework.
T decibelsToGain(T dB, T minusInfinityDb=T(-100)) noexcept
Converts a value in decibels to linear gain.
T fastSin(T x) noexcept
Fast sine approximation (degree-9 odd minimax polynomial).
constexpr uint32_t stateId(const char(&tag)[5]) noexcept
Builds a FOURCC processor id, e.g. dspark::stateId("COMP").
Block-cached copies of the atomics read in the sample loop.
One band of the decay equalizer.
T q
Width of a bell, 0.1 to 10 (the shelves ignore it).
T multiplier
Decay time in the band against the rest, 0.1 to 4.
T frequency
Centre or corner, 20 Hz to 20 kHz.
Equal-size delay lines in one contiguous buffer sharing a write index (every line is written once per...
void prepare(int numLines, int maxDelay)
void write(int i, T x) noexcept
T at(int i, int k) const noexcept
Power-of-two circular delay line: at(k) is the sample pushed k samples ago.
void prepare(int maxDelay)
T at(int k) const noexcept
static constexpr std::array< int, 2 > kAp1
static constexpr double kExcursion
Of the modulated all-passes at full modulation.
static constexpr T kDiffusion1
static constexpr std::array< int, 2 > kD2
std::array< int, 2 > lAp2
double scale
The rate over Dattorro's.
double loopSec
Mean branch length.
static constexpr double kRate
std::array< Line, 2 > ap1
static constexpr std::array< int, 2 > kAp2
static constexpr std::array< int, 2 > kD1
std::array< Line, 2 > ap2
std::array< int, 2 > lAp1
static constexpr T kDiffusion2
int at(double samples29k) const noexcept
std::atomic< T > multiplier
std::atomic< T > frequency
std::array< T, kLines > b1
std::array< int, kLines > len
std::array< T, kLines > y1
std::array< T, kLines > b0
double loopSec
mean loop length
std::array< T, kLines > a1
T keep
its share of the output, what the tank keeps (targets)
static constexpr int kLines
std::array< T, kLines > x1
std::array< Line, kLines > line
T keepNow
where they are now (they glide)
Modulation by segments: a straight move toward the other side, a random share (0.3 to 0....
void prepare(uint32_t seed) noexcept
double next(int stride, double rateHz, double sr) noexcept
void setRate(T rate, double sr) noexcept
T nextStride(int stride) noexcept
void prepare(double sr, T rate, uint32_t seed) noexcept
Hermite-interpolated random noise generator for organic modulation.
void retarget(double want) noexcept
The corner wanted now (0 = off); a fade under way finishes first.
void prepare(double sampleRate)
bool active() const noexcept
void frame(T &l, T &r) noexcept
static constexpr int kSections
Up to kMaxSections analog sections in series.
std::array< AnalogSection, kMaxSections > sections
Describes the audio environment for a DSP processor.
constexpr bool isValid() const noexcept
Checks if the specification contains valid, processable parameters.
int numChannels
Number of audio channels (e.g., 1 = mono, 2 = stereo).
int maxBlockSize
Maximum number of samples per processing block.
double sampleRate
Sample rate in Hz.
Stores normalised biquad coefficients (b0, b1, b2, a1, a2), always double.
static BiquadCoeffs makeHighPass(double sampleRate, double freq, double Q=0.7071067811865476) noexcept
High-pass filter.
static BiquadCoeffs makePeak(double sampleRate, double freq, double Q, double gainDb) noexcept
Peak (parametric EQ) filter.
static BiquadCoeffs makeLowPass(double sampleRate, double freq, double Q=0.7071067811865476) noexcept
Low-pass filter.
static BiquadCoeffs makeLowShelf(double sampleRate, double freq, double gainDb, double slope=1.0) noexcept
Low-shelf filter.
static BiquadCoeffs makeHighShelf(double sampleRate, double freq, double gainDb, double slope=1.0) noexcept
High-shelf filter.
The settings of one band.