Γ-W1-T2 review: one restart funnel, tighter ceiling proof, effective-gain meter

Fold setLimiterEnabled's restart request into setInstrumentParams so every writer
keeps the host's latency report in sync. Pin the window-sizing identity, drop the
per-sample modulo, tighten the ceiling tolerance, publish the blended gain.
This commit is contained in:
2026-08-01 19:34:08 -04:00
parent 3baf4ee50b
commit 0612abbddb
5 changed files with 77 additions and 26 deletions
+14 -5
View File
@@ -114,18 +114,22 @@ float Limiter::detectTruePeak(float xl, float xr, bool stereo) {
float Limiter::smoothGain(float target) {
// Sliding minimum over `window_` via a monotonic wedge. Expiring the front BEFORE the push
// is what bounds the wedge to `window_` entries — pushing first can lap the ring.
// is what bounds the wedge to `window_` entries — pushing first can lap the ring. Wraps by
// compare-and-subtract, matching delayPos_/avgPos_: window_ is not a power of two, so `%`
// would not strength-reduce on this per-sample path.
while (wedgeCount_ > 0 &&
wedgeIdx_[static_cast<std::size_t>(wedgeHead_)] <= pushIndex_ - window_) {
wedgeHead_ = (wedgeHead_ + 1) % window_;
wedgeHead_ = (wedgeHead_ + 1 == window_) ? 0 : wedgeHead_ + 1;
--wedgeCount_;
}
while (wedgeCount_ > 0) {
const int back = (wedgeHead_ + wedgeCount_ - 1) % window_;
const int backSum = wedgeHead_ + wedgeCount_ - 1;
const int back = (backSum >= window_) ? backSum - window_ : backSum;
if (wedgeVal_[static_cast<std::size_t>(back)] < target) break;
--wedgeCount_;
}
const int slot = (wedgeHead_ + wedgeCount_) % window_;
const int slotSum = wedgeHead_ + wedgeCount_;
const int slot = (slotSum >= window_) ? slotSum - window_ : slotSum;
wedgeVal_[static_cast<std::size_t>(slot)] = target;
wedgeIdx_[static_cast<std::size_t>(slot)] = pushIndex_;
++wedgeCount_;
@@ -171,7 +175,6 @@ float Limiter::process(float* left, float* right, int frames) {
const float peak = detectTruePeak(dryL, dryR, stereo);
const float targetGain = peak > ceiling_ ? ceiling_ / peak : 1.f;
const float gain = smoothGain(targetGain);
if (gain < blockMin) blockMin = gain;
const std::size_t slot = static_cast<std::size_t>(delayPos_);
const float wetL = delayL_[slot] * gain;
@@ -184,6 +187,12 @@ float Limiter::process(float* left, float* right, int frames) {
// dry + (wet - dry) * 1.0f is not wet in floating point. At m <= 0 the buffer is left
// untouched, which is the dry sample already in it.
const float m = mix_;
// The reported minimum is the gain actually reaching the output, not the limiter's raw
// target — mid-crossfade only a fraction `m` of the reduction is audible, so the meter
// (whose contract is "smallest gain APPLIED") must blend the same way the signal does:
// unity at m=0, `gain` at m=1, linear between.
const float effectiveGain = 1.f - m + m * gain;
if (effectiveGain < blockMin) blockMin = effectiveGain;
if (m >= 1.f) {
left[i] = wetL;
if (stereo) right[i] = wetR;
+8 -3
View File
@@ -14,7 +14,9 @@ namespace reasampler::instrument::engine {
// The BAKED ceiling. A safety device with no configurable controls, so this is not a
// parameter. dBTP is a TRUE-peak target, which is why the detector oversamples and the
// signal path never does.
// signal path never does — though the bound is on the detector's 4x-oversampled ESTIMATE,
// not infinite-resolution true peak (normal for any practical TP limiter, and part of why
// this ceiling sits at -0.3 rather than 0).
inline constexpr double kLimiterCeilingDbTp = -0.3;
// The total delay the limiter imposes while engaged, and therefore the plugin's whole reported
@@ -67,8 +69,11 @@ public:
bool enabled() const { return target_.load(std::memory_order_relaxed); }
// Applies the limiter in place over `frames` of `left` (and `right`, which may be null for
// a mono buffer). Returns the SMALLEST gain applied in this block — 1.0 for none, and the
// value a settled bypass returns.
// a mono buffer). Returns the SMALLEST gain actually applied to the output this block — 1.0
// for none (a settled bypass, or wherever the engage/disengage crossfade sits at dry). Mid
// crossfade this is the target gain blended by the same fraction `mix_` blends the signal,
// not the limiter's raw target — the two must agree, or the meter over-reports reduction
// that is only partially audible.
float process(float* left, float* right, int frames);
private: