Просмотр исходного кода

Sampler: FL's global channel LFOs (one phase per song tick) for native sampler voices

Ka1-S 1 месяц назад
Родитель
Сommit
623efdd354
3 измененных файлов с 29 добавлено и 2 удалено
  1. 8 2
      docs/analise/REA_rodada76.md
  2. 6 0
      src/core/Instruments.cpp
  3. 15 0
      tests/tests.cpp

+ 8 - 2
docs/analise/REA_rodada76.md

@@ -185,6 +185,13 @@ The project event 0x17 holds FL's pan law: 0 = the circular sin/cos law (§3), 2
 appended as the 90th value of `SamplerSettings::flChannel` (89-value projects keep the circular law). The pan law of
 the mixer and of the other generators is unchanged (**not checked**).
 
+## 10. Global LFOs **[EXEC: FL render `g1`]**
+
+A channel LFO with the global flag (0x20; here the volume LFO, amount 80, speed 24000, notes at ticks 0, 100, 300)
+has one phase for the channel: at song tick k it is `(k + 1)·increment` (32-bit wrap), whatever the note's start.
+With `k·increment` or `(k − 1)·increment` LYNX is off by up to 2 % of the peak; with `(k + 1)` every note is ±1 code.
+LYNX sets the global phase of the channel's records from the voice's song tick before stepping it (`flTick`).
+
 ## Where I stopped / next steps
 
 - State (2026-10-16): branch feature/sampler76 (= origin/wip/sampler76) has the port, origin/main merged, the
@@ -192,8 +199,7 @@ the mixer and of the other generators is unchanged (**not checked**).
   (log `tmp/r76/build3.log`) when the round was paused. Next: confirm 0 failures, Windows build, selftest, land
   (`tmp/coord/land.sh sampler76` under the merge lock).
 
-- Global LFOs (flag 0x20) of the native sampler are stepped per voice (FL keeps a global phase); the velocity/release
-  cross-modulation table and layer parents are not ported.
+- The velocity/release cross-modulation table and layer parents are not ported.
 - Other sample rates (end-fade length, rate ratio) are unverified: FL's command-line render uses 44.1 kHz here.
 - FL's command-line render forwards to a running FL instance and then writes nothing; `fl.sh` waits until no
   `FL64.exe` runs and retries.

+ 6 - 0
src/core/Instruments.cpp

@@ -2004,6 +2004,12 @@ public:
     {
         const auto& S = modulation.fl;
         auto& pr = v.flProc;
+        // global LFOs (flag 0x20): one phase for the whole channel, advanced on every song tick — at tick k it is
+        // (k + 1)·increment (EXEC: FL's render of a global volume LFO, REA_rodada76 §10)
+        if (S.hasGlobal)
+            for (auto& r : modulation.fl.recs)
+                if ((r.flags & 0x20) != 0)
+                    r.globalPhase = (std::uint32_t) ((std::uint64_t) (v.tickIndex + 1) * (std::uint64_t) r.lfoInc);
         pr.control (S);
         const auto finalVol = v.initVol * chanVol, finalPan = v.notePan + chanPan;
         float tL, tR;

+ 15 - 0
tests/tests.cpp

@@ -2459,6 +2459,21 @@ TEST (fl_native_sampler_voice_matches_fl_renders)
         const int R[] = { -1, -203, 29, -298, 97, 0, 0, 0, 0, -60, 9, -88, 29, 0, 0, 0, -1, -203, 29, -2, 0, 0, 0, 0 };
         CHECK (check (out, L, R) == 0);
     }
+    {
+        // a global volume LFO (flag 0x20, amount 80, speed 24000): one phase for the channel, (k + 1)·increment at song
+        // tick k (notes on ticks 0, 100, 300)
+        auto vol = volPlain;
+        vol[0] = 4 | 0x20, vol[11] = 80, vol[12] = 24000;
+        const auto out = render (records (vol, plain, plain), { 256, 0, 0 },
+                                 { { 0, 22050, 100.0f / 128, 0.0f }, { 22969, 45019, 80.0f / 128, 0.0f }, { 68906, 90956, 100.0f / 128, 0.0f } },
+                                 noise, chan);
+        const int pos[] = { 500, 3000, 7000, 12000, 23469, 26000, 30000, 69406, 72000, 80000 };
+        const int gold[] = { 1149, 765, 374, 4530, 846, -911, -646, 1160, 2316, 727 };
+        int bad = 0;
+        for (int k = 0; k < 10; ++k)
+            bad += std::abs ((int) std::lround (out.first[(std::size_t) pos[k]] * 32767.0f) - gold[k]) > 1;
+        CHECK (bad == 0);
+    }
     {
         // a sample with its own loop (WAV smpl 4410…8819): FL loops it while the note lasts and fades it out over 10 ms
         // after the note-off (no volume envelope)