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

WIP: wrapper pan steps, REA notes

Ka1-S 3 недель назад
Родитель
Сommit
a0d2ff1bd9
4 измененных файлов с 109 добавлено и 3 удалено
  1. 87 0
      docs/analise/REA_rodada190ad.md
  2. 3 2
      src/core/RackRenderer.cpp
  3. 5 1
      tests/FlpExport171eTests.inc
  4. 14 0
      tests/PlugLevel190adTests.inc

+ 87 - 0
docs/analise/REA_rodada190ad.md

@@ -0,0 +1,87 @@
+# Round 190ad — hosted plugins of an FL project played 3 dB under FL [DECOMP][DOC][FL render][TEST]
+
+Round 190x (issue #143) measured Surge XT (VST3 in FL's wrapper) 3 dB quieter in LYNX than in FL's render of the same
+project, cut group or not. This round finds the law and fixes it.
+
+Binaries: FL Studio 2026, `Plugins/Fruity/Generators/Fruity Wrapper/Fruity Wrapper_x64.dll` (Ghidra project
+~/ghproj/r134w/fw, as round 188g). Queries and decompilations: `/mnt/e/lynx-work/pluglevel190ad/rea/` (q1 … q11).
+Third-party plugins were only rendered (black box).
+
+## 1. The wrapper's output gain **[DECOMP]**
+
+- The wrapper's plugin VMT (`0x868840`): slot 5 ProcessEvent `0x878ef0`, slot 8 Gen_Render `0x879810`, slot 9
+  TriggerVoice `0x879a00`.
+- **ProcessEvent** (`0x878ef0`): event 2 (the SDK's FPE_MIDI_Pan) stores its integer pan (−64…64) at `+0x5108`; event 3
+  (FPE_MIDI_Vol) stores **`vol × 2.0`** at `+0x50f0` (`vol` = the event's normalised float, the constant `0x8f4f40` =
+  2.0f). Both then call `0x878e60`, which asks the host for the gains: host slot 3, `ComputeLRVol (&L, &R, pan, vol)`
+  with the integer pan — FL's pan kernel (`FLEngine` `FUN_006a3a00`, REA_rodada30 §1.3 / REA_rodada167j §1: pan / 64,
+  circular `L = vol·cos((1 + p)·π/4)`, `R = vol·sin(…)`; triangular project law: the louder side `vol·0.70710677`,
+  the other falls linearly). The wrapper starts at pan 0 (`0x878cf0`).
+- **Gen_Render** (`0x879810` → `0x8790a0`): the plugin processes into its own buffers, then `0x776680` (float) /
+  `0x7763e0` (double) add every output bus to the host's buffer with those two gains, ramped from the previous block's
+  (`0x61cbb0`). "Use fixed size buffers" (`0x8794f0` → `0x879770`) runs the same call into a ring and copies it out at
+  unity. No MIDI CC 7 / CC 10 is sent to the plugin (the base ProcessEvent `0x870790` handles only the tempo).
+
+So a hosted generator's output is scaled by **L = 2·f(v)·cos((1 + p)·π/4), R = 2·f(v)·sin((1 + p)·π/4)**, with f the
+channel volume curve `(11^v − 1) / 10` (the renders of §3 fix `vol` = f(v)): **√2·f(v) at the centre**, 2·f(v) on the
+side panned to. FL's native voice generators get the same kernel without the 2 (REA_rodada169l).
+
+**[DOC]** Image-Line's manual (Levels, Mixing & Clipping) says the same: VST instruments get 6 dB of compensation, so at
+the default channel settings a VST at 0 dB comes out 2.2 dB lower, "instead of the 8.2 dB for FL native plugins"
+(6.02 − 3.01 − 5.21 = −2.20 dB). <https://www.image-line.com/fl-studio-learning-content/fl-studio-online-manual/html/mixer_levelsandmixing.htm>
+
+LYNX's channel law (`panGains`, RackRenderer.cpp) is `f(v)·√2·cos / sin`: f(v) at the centre for every instrument,
+hosted plugins included — 1 / √2 of FL's wrapper, **−3.01 dB**, at every volume and pan.
+
+## 2. The wrapper's note velocity **[DECOMP]**
+
+TriggerVoice (`0x879a00`): MIDI velocity = `Round (velocity · 128.0)` (single precision product, `0x40c3c0` =
+cvtsd2si, ties to even), clamped to 0…127, with `velocity` the note's own (`FPV_GetVelocity`). (With the wrapper
+setting at `+0x44` set, the velocity comes from Init.Vol instead; off in every project seen.) An .flp note's velocity
+byte b is b / 128 in LYNX, and LYNX sent JUCE's `round (127 v)`: 100 went out as 99, 127 as 126.
+
+## 3. FL's renders
+
+`/mnt/e/lynx-work/pluglevel190ad` (`flp/`, FL's renders `flr/`, LYNX's `lx/`; `tools/mkflp.py` patches round 190x's
+`probe/cut0.flp`: Surge XT VST3 at its default patch on insert 1, a 4-beat note on key 48). RMS of each side over
+0.5…2.0 s, dBFS; LYNX − FL in dB. Surge's oscillators start at a random phase: ±0.05 dB between runs; the R / L ratio
+of one render is exact (the patch is mono).
+
+@@TABLE@@
+
+## 4. Change
+
+- `Song::flPluginLevels` (saved as `"pluginLevels": "fl"`): the project's hosted plugin channels follow Fruity Wrapper.
+  The .flp import sets it. `RackRenderer::renderChannel` gives such a channel FL's kernel of (pan, 2·f(v)), with the
+  project's panning law (`flWrapperGains`); `PluginInstrument` sends `Round (128 v)` (`hostpitch::flWrapperVelocity`;
+  a note on never goes below 1).
+- **Projects saved before keep their sound**: without the property a project keeps LYNX's own law (f(v) at the centre,
+  JUCE's velocity). New LYNX projects and .als imports (Live plays a plugin at unity = volume 100 % under LYNX's own
+  law) are unchanged too. Non-plugin channels are untouched in both cases.
+- `.flp` export: a project with LYNX's own law writes the plugin channel's volume that sounds the same in FL
+  (f(v′) = f(v) / √2; before, FL played such an export 3 dB louder than LYNX); a project with FL's levels writes the
+  knob as it is. `.als` export: a plugin track's gain is × √2 in a project with FL's levels.
+- Tests: `tests/PlugLevel190adTests.inc`.
+
+## 5. Best way?
+
+- **FL:** the wrapper adds 6 dB to a VST and the channel's law takes 3 dB at the centre and 5.2 dB at the default
+  78 % — a VST sits 2.2 dB under its own output on a new channel (§1, DECOMP + DOC + renders).
+- **Ableton:** a plugin device plays at unity; the track fader starts at 0 dB (ALS_FORMAT.md; LYNX's .als import maps
+  it to channel volume 100 %).
+- **Users:** Image-Line's support calls the 78 % default "headroom"; plugin developers notice the wrapper's hidden
+  level when they compare hosts (<https://forum.juce.com/t/flstudio-levels-issue/59509>).
+- **Verdict:** an FL project must play at FL's level, so the import follows the wrapper exactly. Whether **new** LYNX
+  projects should also adopt FL's wrapper level (a plugin 3 dB louder than in 0.1.25 at the same knob) is a product
+  choice: not changed here, sent to the coordinator (recommended: yes, for new projects only, as the flag already
+  keeps old ones).
+
+## 6. Not verified
+
+- A plugin generator inside a Patcher (FLEngine's own copy of the host): its level law was not measured; unchanged.
+- VST2 and CLAP wrapper channels: the same wrapper class and Gen_Render (inferred, only VST3 rendered).
+- Notes played live from a MIDI keyboard into a project with FL's levels also go through `Round (128 v)` (LYNX keeps
+  a played velocity as byte / 127, so byte 100 goes out as 101); what FL's wrapper gets for a played note was not
+  probed.
+- `.flp` export of a project with LYNX's own law compensates the knob only; a channel-volume automation of a hosted
+  plugin is written as it is.

+ 3 - 2
src/core/RackRenderer.cpp

@@ -1659,10 +1659,11 @@ void panGains (float pan, float gain, float& left, float& right) noexcept
 // A hosted plugin channel in a project with FL's levels (Song::flPluginLevels, REA_rodada190ad.md): Fruity Wrapper's
 // A hosted plugin channel in a project with FL's levels (Song::flPluginLevels, REA_rodada190ad.md): Fruity Wrapper's
 // output gains are the host's ComputeLRVol of (the channel's pan, 2 × its volume curve) — FL's pan kernel (circular
 // output gains are the host's ComputeLRVol of (the channel's pan, 2 × its volume curve) — FL's pan kernel (circular
 // cos/sin, or the project's triangular law: the louder side keeps v/√2, the other falls linearly), so the centre is
 // cos/sin, or the project's triangular law: the louder side keeps v/√2, the other falls linearly), so the centre is
-// √2 × the curve and the side panned to 2 ×.
+// √2 × the curve and the side panned to 2 ×. The wrapper gets the pan as an integer, −64…64 (FL's renders: a channel
+// pan of 1.5 / 64 and 2.5 / 64 play as 1 / 64 and 2 / 64, 0.4 / 64 as the centre), so the pan moves in steps of 1 / 64.
 void flWrapperGains (float pan, float gain, bool triangular, float& left, float& right) noexcept
 void flWrapperGains (float pan, float gain, bool triangular, float& left, float& right) noexcept
 {
 {
-    const auto p = std::clamp (pan, -1.0f, 1.0f);
+    const auto p = std::trunc (std::clamp (pan, -1.0f, 1.0f) * 64.0f) / 64.0f;
     const auto vol = gain * 2.0f;
     const auto vol = gain * 2.0f;
     if (triangular)
     if (triangular)
     {
     {

+ 5 - 1
tests/FlpExport171eTests.inc

@@ -299,7 +299,11 @@ TEST (flpexport171e_song_round_trips_through_the_importer)
         for (std::size_t i = 0; i < song.channels.size(); ++i)
         for (std::size_t i = 0; i < song.channels.size(); ++i)
         {
         {
             CHECK (back.channels[i].name == song.channels[i].name);
             CHECK (back.channels[i].name == song.channels[i].name);
-            CHECK (fx171e::near (back.channels[i].volume, song.channels[i].volume, 0.001));
+            // (a hosted plugin under LYNX's own law is written at the knob that sounds the same in FL, round 190ad)
+            const auto wrapped = song.channels[i].instrument == InstrumentKind::plugin && ! song.flPluginLevels;
+            const auto volume = wrapped ? std::log (10.0 * channelGain (song.channels[i].volume) * 0.70710678 + 1.0) / std::log (11.0)
+                                        : (double) song.channels[i].volume;
+            CHECK (fx171e::near (back.channels[i].volume, volume, 0.001));
             CHECK (fx171e::near (back.channels[i].pan, song.channels[i].pan, 0.001));
             CHECK (fx171e::near (back.channels[i].pan, song.channels[i].pan, 0.001));
             CHECK (back.channels[i].mixerTrack == song.channels[i].mixerTrack);
             CHECK (back.channels[i].mixerTrack == song.channels[i].mixerTrack);
         }
         }

+ 14 - 0
tests/PlugLevel190adTests.inc

@@ -100,7 +100,21 @@ TEST (plug190ad_fl_projects_play_hosted_plugins_at_the_wrapper_level)
         CHECK (plug190ad::close (l, 2.0f * g * std::cos (3.14159265f / 8.0f)));
         CHECK (plug190ad::close (l, 2.0f * g * std::cos (3.14159265f / 8.0f)));
         CHECK (plug190ad::close (r, 2.0f * g * std::sin (3.14159265f / 8.0f)));
         CHECK (plug190ad::close (r, 2.0f * g * std::sin (3.14159265f / 8.0f)));
     }
     }
+    // the wrapper's pan is an integer −64…64 (FL's renders: R / L = 1.0249 at 1.5 / 64, 1.0503 at 2.5 / 64, 1 at 0.4 / 64)
+    {
+        CHECK (plug190ad::gains (true, 0.78f, 1.5f / 64.0f) == plug190ad::gains (true, 0.78f, 1.0f / 64.0f));
+        CHECK (plug190ad::gains (true, 0.78f, 2.5f / 64.0f) == plug190ad::gains (true, 0.78f, 2.0f / 64.0f));
+        CHECK (plug190ad::gains (true, 0.78f, 0.4f / 64.0f) == plug190ad::gains (true, 0.78f, 0.0f));
+        CHECK (plug190ad::gains (true, 0.78f, -1.5f / 64.0f) == plug190ad::gains (true, 0.78f, -1.0f / 64.0f));
+        const auto [l, r] = plug190ad::gains (true, 0.78f, 1.5f / 64.0f);
+        CHECK (std::abs (r / l - 1.0249f) < 0.0002f);
+        const auto [l2, r2] = plug190ad::gains (true, 0.78f, 2.5f / 64.0f);
+        CHECK (std::abs (r2 / l2 - 1.0503f) < 0.0002f);
+        const auto [l3, r3] = plug190ad::gains (true, 0.78f, -0.5f);
+        CHECK (std::abs (r3 / l3 - 0.4142f) < 0.0002f); // (FL: 0.4142 at half left)
+    }
     // the project's triangular law: the louder side keeps the centre level, the other falls linearly
     // the project's triangular law: the louder side keeps the centre level, the other falls linearly
+    // (FL's render at half left: L at the centre's level, R / L = 0.5000)
     {
     {
         const auto [l, r] = plug190ad::gains (true, 0.78f, -0.5f, true);
         const auto [l, r] = plug190ad::gains (true, 0.78f, -0.5f, true);
         CHECK (plug190ad::close (l, g * sqrt2));
         CHECK (plug190ad::close (l, g * sqrt2));