Explorar o código

LuxeVerb Space revision 1: levels refitted on the Pro-R 2 captures' time windows

Round 190kw fitted revision 1's open levels on the total level and spectrum only, which let the
early network (1.15 x the displayed time, no rate) carry the tail: long decay rates died early,
short ones rang for seconds, and Ducking left no tail at long rates. Refitted per time window and
band: the late network carries the tail at every rate (a fitted level surface over Space, rate,
Distance and Character on top of the recovered G law), the early network is a short build-up,
Distance takes the early energy (early / 2-line networks and reflections fall with it, plus a
whole-wet trim), and Thickness follows the reference's Thickner: the measured gains act only on a
quiet wet (an impulse's tail moves, a music wet hardly does).

refcap030 Pro-R 2: 323 files 3.30 -> 3.68 (104 up / 203 same / 16 down; 190kw-r2: 3.51,
89 / 191 / 43); refcap182 programme 3.95 -> 4.05; tp172b 3.83 -> 3.75. Revision 0 unchanged (gold
15 / 15). Tests: four parity190lgR2 cases (tail follows the rate, ducked long decay keeps its tail,
distance takes the early energy, thickness acts on a quiet wet only).
Ka1-S hai 2 semanas
pai
achega
045ffc1de6
Modificáronse 2 ficheiros con 171 adicións e 19 borrados
  1. 63 19
      src/core/SpaceVerb.h
  2. 108 0
      tests/Parity190kwR2Tests.inc

+ 63 - 19
src/core/SpaceVerb.h

@@ -249,6 +249,7 @@ public:
         for (auto& f : toneLp) f.clear();
         phase = 0.0;
         duckEnv = duckDb = 0.0;
+        thEnv = 0.0;
         for (auto& c : net1)
             for (auto& l : c) l.clear();
         for (auto& c : two1)
@@ -394,12 +395,30 @@ public:
     // round 190kw, revision 1: the constants fitted on refcap030's Pro-R 2 captures (the laws themselves are below)
     struct Fit1
     {
-        double late = 0.0761;    // the late network's level against the reference (G_late × this)
-        double two = 0.4239;     // the 2-line network's level
-        double early = 0.092;    // the early network's level (parallel lines, no feedback matrix)
-        double earlyMaxSec = 60.0; // … and its longest decay (the law: 1.15 × the displayed time, no cap)
-        double er = 0.2367;      // the early reflections' level …
-        double erSmall = 0.0;    // … and how much louder they get towards Space 0 (fitted: none)
+        // round 190lg: refitted on refcap030's Pro-R 2 captures per time window (0 … 5 ms … 6.4 s) and per band, not on
+        // the total level and spectrum alone (190kw's fit let the early network carry the tail: its level then followed
+        // the displayed time instead of the decay rate, so long rates died early and Ducking left no tail)
+        double late = 0.3439;    // the late network's level against the reference (G_late × this × the surface below)
+        double lateExp = -0.944; // … × (network decay in s)^this …
+        // … × 10^(dB / 20) of a fitted surface over Space S, decay rate r, Distance D and Character c:
+        // lateS (S − ½) + lateS2 (S − ½)² + lateSR (S − ½) log2 r + lateR log2 r + lateD2 (D − ½)² + lateCh (c − 0.3)
+        double lateS = 27.73, lateS2 = 1.57, lateSR = 1.71, lateR = 4.76, lateD2 = -8.51, lateCh = -1.59;
+        double two = 0.15676;    // the 2-line network's level, + twoS (S − ½) + twoD (D − ½) + twoD2 (D − ½)² dB
+        double twoS = 6.7, twoD = -2.3, twoD2 = -1.5;
+        double early = 0.11755;  // the early network's level (parallel lines, no feedback matrix), + earlyS / D / D2 terms (dB)
+        double earlyS = -7.38, earlyD = -10.03, earlyD2 = -6.14;
+        double earlyDecay = 0.3; // … and its decay: this × 1.15 × the displayed time (a short build-up, not a second tail)
+        double er = 0.2367;      // the early reflections' level, + erS (S − ½) + erD (D − ½) + erD2 (D − ½)² dB
+        double erS = -14.04, erD = 0.59, erD2 = -4.57;
+        // the whole wet by Distance (dB at D = 0, ¼, ½, ¾, 1, linear between) + distCh (c − ½) min (2 D, 1): far spaces lose
+        // their early energy in the reference (−30 dB at 0 … 5 ms from D = 0 to 1) and keep their tail
+        std::array<double, 5> distDb { -0.2, -1.17, 0.26, 0.06, 1.0 };
+        double distCh = 1.3;
+        // Thickness (the reference's Thickner): a gain on the body (late, 2-line, early networks; the early reflections too
+        // below 0) that acts only on a quiet wet: in full below thickLo dBFS, none above thickHi (the wet's (l² + r²) / 2,
+        // thickAtt / thickRel s). Measured: an impulse's whole response moves by −13.2 dB per unit below 0 and by
+        // 6.8 (1 − (1 − t)²) dB above (here − 1.12 dB at t = 1), a music wet at −25 dBFS by under 1.5 dB either way
+        double thickNegDb = 13.2, thickPosDb = 5.68, thickLo = -38.0, thickHi = -28.0, thickAtt = 0.02, thickRel = 0.3;
         double cross = 0.5;      // the unresolved factor x of the CrossInput gain 0.5477 · x · min (v / 0.5477, 1)²: the
                                  // left-only impulses across Stereo Width score 2.92 / 3.32 / 3.40 / 3.20 at x = 0 / 0.5 / 1 /
                                  // 1.5, but x = 1 lifts a centred input by 1.7 dB against the fitted levels (grid 3.33 → 2.90)
@@ -407,8 +426,6 @@ public:
         double lpOctaves = -0.75; // the brightness low pass's corner moved by this many octaves (fitted, one pole)
         double shelfDb = 0.0;    // the high shelf that follows the darkness …
         double darkDb = 18.0;    // … and its cut per unit of darkness (fitted on the measured B = 0 / 1 curves)
-        double lateExp = -0.944; // the late level × (network decay in s)^this (the measured level grows slower with T)
-        double thickNeg = 15.6, thickPos = 6.75; // Thickness −1 … +1 → the body (late, early, 2-line) by dB per unit
         std::array<double, 3> styleLate { 1.0, 0.95, 0.6 }, styleEarly { 1.0, 1.145, 1.145 };
         std::array<double, 3> styleLowDb { 0.0, -2.0, -1.0 }, styleHighDb { 0.0, 0.0, -3.0 }, styleLpHz { 0.0, 0.0, 9000.0 };
     };
@@ -465,8 +482,9 @@ private:
                 g2[(std::size_t) c][(std::size_t) j] = gOf (len, t2);
             }
         // the early network: lines without a feedback matrix (each feeds itself back), decaying at 1.15 × the displayed
-        // time without the rate multiplier — what keeps a small space's level when the rate is low
-        const double tEarly = std::min (1.15 * s.decaySec, f.earlyMaxSec);
+        // time without the rate multiplier (the law), shortened by earlyDecay (round 190lg: the time windows of the
+        // reference end its energy with the late network's, at every rate)
+        const double tEarly = 1.15 * s.decaySec * f.earlyDecay;
         for (int c = 0; c < 2; ++c)
             for (int j = 0; j < earlyLines; ++j)
             {
@@ -482,8 +500,7 @@ private:
             for (int q = 0; q < 4; ++q)
                 diff[(std::size_t) c][(std::size_t) q].g = q < st.diffusers ? st.diffuserGain : 0.0;
         const double near = 1.0 - D;
-        erGain = st.erLevel * (0.6 + 4.4 * near * near * near) * (1.0 + 0.8 * std::max (0.0, s.thickness)) * f.er
-                 * (1.0 + f.erSmall * (1.0 - S) * (1.0 - S));
+        erGain = st.erLevel * (0.6 + 4.4 * near * near * near) * (1.0 + 0.8 * std::max (0.0, s.thickness)) * f.er;
         erSpread = (0.55 + 0.9 * near) * (0.5 + 0.5 * S);
         // stereo width W (0 … 1.2): v = √|W − 1|; the input's side scaled by s_in into the two networks; the networks'
         // feedback rotated into each other by v; the output's mid / side by X / Y
@@ -512,12 +529,22 @@ private:
         const double sd = std::sqrt (D);
         const double f10 = 1.0 - ((0.045 * sd + 0.0375) * f4 * sd + (0.0375 * sd + 0.03125) * f4) * f4;
         const double th = std::clamp (s.thickness, -1.0, 1.0);
-        const double body = std::pow (10.0, (th >= 0.0 ? f.thickPos * th : f.thickNeg * th) / 20.0);
+        thickDb = th >= 0.0 ? f.thickPosDb * (1.0 - (1.0 - th) * (1.0 - th)) : f.thickNegDb * th;
         const auto si = (std::size_t) s.style;
+        // round 190lg: the fitted surfaces (dB) over Space, decay rate, Distance and Character, and the whole wet by Distance
+        const double lr2 = std::log2 (std::max (s.rate, 1e-6)), Sc = S - 0.5, Dc = D - 0.5, ch = clamp01 (s.character);
+        const double d4 = 4.0 * D;
+        const int di = std::min ((int) d4, 3);
+        const double distDb = f.distDb[(std::size_t) di] + (f.distDb[(std::size_t) di + 1] - f.distDb[(std::size_t) di]) * (d4 - di)
+                              + f.distCh * (ch - 0.5) * std::min (2.0 * D, 1.0);
+        const double lateDb = f.lateS * Sc + f.lateS2 * Sc * Sc + f.lateSR * Sc * lr2 + f.lateR * lr2 + f.lateD2 * Dc * Dc
+                              + f.lateCh * (ch - 0.3) + distDb;
+        const auto dbg = [] (double db) { return std::pow (10.0, db / 20.0); };
         lateGain = f.late * f.styleLate[si] * std::pow (std::max (bd.mid, 0.05), f.lateExp)
-                   * (std::pow (250.0 / std::max (tMs, 1.0), 0.7) + 1.3) * (1.0 + 0.5 * dk) * f10 * body;
-        twoGain = f.two * (1.0 + 0.5 * dk) * body;
-        earlyGain = f.early * f.styleEarly[si] * (1.0 + 0.5 * dk) * body;
+                   * (std::pow (250.0 / std::max (tMs, 1.0), 0.7) + 1.3) * (1.0 + 0.5 * dk) * f10 * dbg (lateDb);
+        twoGain = f.two * (1.0 + 0.5 * dk) * dbg (f.twoS * Sc + f.twoD * Dc + f.twoD2 * Dc * Dc + distDb);
+        earlyGain = f.early * f.styleEarly[si] * (1.0 + 0.5 * dk) * dbg (f.earlyS * Sc + f.earlyD * Dc + f.earlyD2 * Dc * Dc + distDb);
+        erGain *= dbg (distDb + f.erS * Sc + f.erD * Dc + f.erD2 * Dc * Dc);
         const double wTerm = 0.5 * std::min (1.25 * f.cross, 1.5) * v;
         const double lpHz = std::pow (2.0, 14.136 - 4.0 * dk + f.lpOctaves);
         const double shHz = std::pow (2.0, 13.873 - 2.0 * dk);
@@ -537,6 +564,7 @@ private:
         }
         dryGain = std::cos (clamp01 (s.mix) * pi * 0.5);
         wetGain = std::sin (clamp01 (s.mix) * pi * 0.5);
+        thA = std::exp (-1.0 / (f.thickAtt * sr)); thR = std::exp (-1.0 / (f.thickRel * sr));
     }
 
     void process1 (float* left, float* right, int n) noexcept
@@ -639,18 +667,34 @@ private:
                 two1[1][(std::size_t) j].push (rot2C * b - rot2S * a + (j == 0 ? dIn[1] : -dIn[1]));
             }
             std::array<double, 2> w {};
+            // thickness: the body (late, 2-line, early networks) × the gain the wet's level allows (the
+            // envelope of the previous output sample); the early reflections only below 0 (a cut)
+            double thG = 1.0, thE = 1.0;
+            if (thickDb != 0.0)
+            {
+                const double lv = 10.0 * std::log10 (thEnv + 1e-30);
+                const double wv = std::clamp ((fit1().thickHi - lv) / (fit1().thickHi - fit1().thickLo), 0.0, 1.0);
+                thG = std::exp (thickDb * wv * 0.11512925464970229);
+                if (thickDb < 0.0) thE = thG;
+            }
             for (int c = 0; c < 2; ++c)
             {
-                double y = o[(std::size_t) c] * lateGain + e[(std::size_t) c] * erGain + t[(std::size_t) c] * twoGain
-                           + eo[(std::size_t) c] * earlyGain;
+                double y = (o[(std::size_t) c] * lateGain + t[(std::size_t) c] * twoGain + eo[(std::size_t) c] * earlyGain) * thG
+                           + e[(std::size_t) c] * erGain * thE;
                 for (auto& fl : out1[(std::size_t) c]) y = fl.run (y);
                 w[(std::size_t) c] = y;
             }
-            const double wm = 0.5 * (w[0] + w[1]) * outX * duckGain, ws = 0.5 * (w[0] - w[1]) * outY * duckGain;
+            double wm = 0.5 * (w[0] + w[1]) * outX * duckGain, ws = 0.5 * (w[0] - w[1]) * outY * duckGain;
+            if (thickDb != 0.0)
+            {
+                const double e2 = wm * wm + ws * ws; // (l² + r²) / 2 of the wet
+                thEnv = e2 > thEnv ? e2 + thA * (thEnv - e2) : e2 + thR * (thEnv - e2);
+            }
             left[i] = (float) (inL * dryGain + (wm + ws) * wetGain);
             right[i] = (float) (inR * dryGain + (wm - ws) * wetGain);
         }
     }
+    double thickDb = 0.0, thEnv = 0.0, thA = 0.0, thR = 0.0;
 
     std::array<std::array<detail::Delay, lines1>, 2> net1;
     std::array<std::array<detail::Delay, 2>, 2> two1;

+ 108 - 0
tests/Parity190kwR2Tests.inc

@@ -170,3 +170,111 @@ TEST (parity190kwR2_space0_level_and_brightness_law)
     CHECK (b100 < b50 + 4.0 && b100 > b50 - 4.0);
     CHECK (b0 < b50 - 2.0);
 }
+
+// Round 190lg: revision 1's levels refitted on the captures' energy per time window (0 … 5 ms … 6.4 s) and band. The late
+// network carries the tail at every decay rate (190kw's fit had let the 1.15 × displayed-time early network carry it, so
+// long rates died early and a ducked long decay left no tail), far Distances lose their early energy, and Thickness acts
+// on a quiet wet only (the reference's Thickner: an impulse moves by −13.2 dB per unit, a loud wet hardly at all).
+namespace p190lgr2t
+{
+// a Pro-R 2 state (Modern, 100 % wet): Space, Decay Rate (−1 … 1), Distance, Thickness (−1 … 1), Ducking (dB)
+inline lynx::EffectSlot state (float space, float rate, float distance, float thick, float duckDb)
+{
+    std::vector<float> v (136, 0.0f);
+    v[0] = space; v[1] = rate; v[2] = distance; v[3] = 0.5f; v[5] = 0.3f; v[6] = thick; v[7] = 0.7f; v[8] = duckDb; v[9] = 100.0f;
+    auto slot = lynx::makeEffectSlot (lynx::EffectKind::luxeVerb);
+    if (const auto st = lynx::fabfilter::parseState (p190kwr2t::ffbs (v))) lynx::fabfilter::fromProR2 (*st, slot);
+    return slot;
+}
+// renders `in` (mono, both channels) through the slot; returns the left + right sum
+inline std::vector<double> render (const lynx::EffectSlot& slot, const std::vector<float>& in, double sr = 48000.0)
+{
+    std::vector<float> l (in), r (in);
+    auto fx = lynx::makeEffect (slot);
+    fx->prepare (sr);
+    const int n = (int) in.size();
+    for (int off = 0; off < n; off += 512)
+        fx->process (l.data() + off, r.data() + off, std::min (512, n - off), slot.params, 120.0);
+    std::vector<double> m ((std::size_t) n);
+    for (std::size_t i = 0; i < m.size(); ++i) m[i] = (double) l[i] + r[i];
+    return m;
+}
+inline double db (const std::vector<double>& x, double t0, double t1, double sr = 48000.0)
+{
+    double e = 0.0;
+    for (std::size_t i = (std::size_t) (t0 * sr); i < std::min (x.size(), (std::size_t) (t1 * sr)); ++i) e += x[i] * x[i];
+    return 10.0 * std::log10 (e + 1e-30);
+}
+inline std::vector<float> impulse (double seconds, double sr = 48000.0)
+{
+    std::vector<float> x ((std::size_t) (seconds * sr), 0.0f);
+    x[100] = 0.5f;
+    return x;
+}
+inline std::vector<float> noise (double seconds, double from, double to, float amp, double sr = 48000.0)
+{
+    std::vector<float> x ((std::size_t) (seconds * sr), 0.0f);
+    unsigned s = 12345u;
+    for (std::size_t i = (std::size_t) (from * sr); i < (std::size_t) (to * sr); ++i)
+    {
+        s = s * 1664525u + 1013904223u;
+        x[i] = amp * (float) ((double) (s >> 8) / 8388608.0 - 1.0);
+    }
+    return x;
+}
+} // namespace p190lgr2t
+
+TEST (parity190lgR2_the_tail_follows_the_decay_rate)
+{
+    using namespace p190lgr2t;
+    // Space 50 % (2.5 s): Decay Rate −100 % (× 0.25) is gone by 1.6 s (the reference: −150 dB in 1.6 … 3.2 s), +100 %
+    // (× 4) still rings there (−18.5 dB against −14.0 in 0.2 … 0.4 s)
+    const auto shortRate = render (state (0.5f, -1.0f, 0.5f, 0.0f, 0.0f), impulse (4.0));
+    const auto longRate = render (state (0.5f, 1.0f, 0.5f, 0.0f, 0.0f), impulse (4.0));
+    const double s1 = db (shortRate, 0.2, 0.4) - db (shortRate, 1.6, 3.2), l1 = db (longRate, 0.2, 0.4) - db (longRate, 1.6, 3.2);
+    std::printf ("  0.2 … 0.4 s over 1.6 … 3.2 s: rate × 0.25 %.1f dB, × 4 %.1f dB\n", s1, l1);
+    CHECK (s1 > 60.0);
+    CHECK (l1 < 12.0);
+}
+
+TEST (parity190lgR2_ducking_a_long_decay_leaves_its_tail)
+{
+    using namespace p190lgr2t;
+    // a 0.3 s noise burst, Decay Rate +100 %: with Ducking at 48 dB the wet dips while the burst plays and its tail
+    // comes back once the input stops (the reference: 0.5 … 1.5 s after the burst within ~3 dB of the un-ducked tail)
+    const auto in = noise (3.0, 0.1, 0.4, 0.3f);
+    const auto dry = render (state (0.25f, 1.0f, 0.5f, 0.0f, 0.0f), in), duck = render (state (0.25f, 1.0f, 0.5f, 0.0f, 48.0f), in);
+    const double during = db (duck, 0.15, 0.4) - db (dry, 0.15, 0.4), after = db (duck, 0.9, 1.9) - db (dry, 0.9, 1.9);
+    std::printf ("  ducked − plain: during the burst %.1f dB, 0.5 … 1.5 s after %.1f dB\n", during, after);
+    CHECK (during < -20.0);
+    CHECK (after > -4.0);
+}
+
+TEST (parity190lgR2_distance_takes_the_early_energy)
+{
+    using namespace p190lgr2t;
+    // Distance 0 → 100 %: the reference's first 20 ms fall by ~25 dB, its tail (0.2 … 1 s) stays within ~2 dB
+    const auto nearS = render (state (0.25f, 0.0f, 0.0f, 0.0f, 0.0f), impulse (1.5)), farS = render (state (0.25f, 0.0f, 1.0f, 0.0f, 0.0f), impulse (1.5));
+    const double early = db (farS, 0.0, 0.0225) - db (nearS, 0.0, 0.0225), tail = db (farS, 0.2, 1.0) - db (nearS, 0.2, 1.0);
+    std::printf ("  far − near: first 20 ms %.1f dB, 0.2 … 1 s %.1f dB\n", early, tail);
+    CHECK (early < -10.0);
+    CHECK (std::abs (tail) < 4.0);
+}
+
+TEST (parity190lgR2_thickness_acts_on_a_quiet_wet_only)
+{
+    using namespace p190lgr2t;
+    // Thickness −100 % / +100 % against 0: an impulse's response by about −13 / +6 dB, a loud noise's wet (≈ −20 dBFS) by
+    // under 2 dB (the reference: −13.2 / +6.6 dB and a music wet within 1.4 dB)
+    const auto ir = impulse (1.5), loud = noise (1.5, 0.0, 1.5, 0.5f);
+    const double i0 = db (render (state (0.25f, 0.0f, 0.5f, 0.0f, 0.0f), ir), 0.0, 1.5);
+    const double iN = db (render (state (0.25f, 0.0f, 0.5f, -1.0f, 0.0f), ir), 0.0, 1.5) - i0;
+    const double iP = db (render (state (0.25f, 0.0f, 0.5f, 1.0f, 0.0f), ir), 0.0, 1.5) - i0;
+    const double n0 = db (render (state (0.25f, 0.0f, 0.5f, 0.0f, 0.0f), loud), 0.5, 1.5);
+    const double nN = db (render (state (0.25f, 0.0f, 0.5f, -1.0f, 0.0f), loud), 0.5, 1.5) - n0;
+    const double nP = db (render (state (0.25f, 0.0f, 0.5f, 1.0f, 0.0f), loud), 0.5, 1.5) - n0;
+    std::printf ("  thickness −1 / +1: impulse %.1f / %+.1f dB, loud noise %.1f / %+.1f dB\n", iN, iP, nN, nP);
+    CHECK (iN < -10.0 && iN > -16.0);
+    CHECK (iP > 3.0 && iP < 8.0);
+    CHECK (std::abs (nN) < 2.0 && std::abs (nP) < 2.0);
+}