4
0
Эх сурвалжийг харах

Tests and notes for round 190ik: warp engines and the Beats detector gate

- tests/Warp190ikTests.inc: Complex Pro length / pitch / no clicks / formants by amount /
  determinism / warp map / Classic law, Texture grains / flux / transposition / Classic
  law and keys, the detector gate on the onset bank (no category worse), the .als round
  trip, Clip View transposes, render-ahead bit-exact with both engines.
- tests/OnsetBank190ik.h: a LYNX-made labelled onset bank (drums, bass, plucks, legato,
  glides, bass-range glides, sung, chords; 44.1 / 48 kHz).
- 190gx / 190fm tests follow the new defaults.
- docs/analise/REA_rodada190ik.md: facts, engines, scores before / after vs Live, gate,
  law proof, CPU.
Ka1-S 2 долоо хоног өмнө
parent
commit
d4fb2ff5e6

+ 170 - 0
docs/analise/REA_rodada190ik.md

@@ -0,0 +1,170 @@
+# Round 190ik — warp engine finish: Complex Pro, Texture, pitch-aware Beats (LYNX SHARE 0.1.30, BUILD-LIST 8)
+
+Evidence: black-box renders of Ableton Live 12.4 Trial only — round 190gu's W1 set (80 clips) and this round's W2 set (108
+clips: Complex Pro at −12…+12 st and 0.8 / 1.0 / 1.5× speed with Formants 0 / 50 / 100 and Envelope 32…256, Texture at
+0.5…2× with Flux 0…100 and Grain Size 10…150, Beats on a tonal source). Sources: Live's Core Library vocal and the 190ei
+drum loop as test stimuli (not shipped), plus two LYNX-made additive sources whose spectral envelope is known exactly (a
+sung vowel with steps, a glide, vibrato, a re-articulation and a vowel change; four piano-like chords). No code, preset or
+sample of Live is in the repo; the engines are LYNX's own (`src/core/WarpEngines.{h,cpp}`), on top of the Signalsmith
+Stretch already vendored (MIT). Rubber Band was not used (GPL; nothing to gain over the measured approach below).
+
+Work folder: `/mnt/e/lynx-work/warp190ik` (`live/` set + renders, `p/` harnesses, `ana/` analysis, `HANDOFF.md`).
+
+## 1. Method
+
+- `p/wrun.cpp`: LYNX's offline warp (`lynx::timeStretch`) set up as the .als importer sets a channel up; a clip transpose
+  in a mode that does not render it offline goes through the sampler's real-time `VoicePitchShifter`, as in the app.
+- `ana/m.py`: Live vs LYNX at 48 kHz mono over the clip's span — level, 10 ms envelope correlation / deviation, long-term
+  spectrum deviation (24 log bands), frame log-spectral distance (40 bands, 2048/512), **formant shift** (the log-frequency
+  lag that best aligns the two cepstrally smoothed envelopes, semitones) and, on drums / Beats, **transient sharpness**
+  (peak in 0…12 ms over the 22 ms before each Live onset).
+- Texture with Flux > 0 is random in Live and in LYNX: sample-wise metrics compare two random draws, so it is also judged
+  by statistics (`ana/texstat.py`: the envelope's modulation depth around its 200 ms trend, the long-term spectrum).
+
+## 2. Complex Pro
+
+Facts (W2):
+- No transposition: Complex Pro renders as Complex (Live vs Live: envelope 1.000, spectrum 0.07…0.56 dB). LYNX keeps
+  Complex's render there.
+- **Formants is linear in the shift**: on the vowel at +7 st the envelope moves 7.1 st with Formants 0, 3.4 with 50,
+  0.1 with 100 (voice: 6.7 / 3.4 / 0.0).
+- **Envelope is the envelope's resolution**: vowel +7, formants kept 4.8 / 1.2 / 0.1 / 0.1 st short of the source at
+  Envelope 32 / 64 / 128 / 256 (chords, denser partials: 5.0 / 4.9 / 3.6 / 0.1).
+- **Only pitched sound is corrected**: drums at +7 with Formants 100 vs 0 differ by 0.03 dB level, 0.78 dB spectrum (the
+  voice by 1.4 / 3.9 dB).
+- Up-shifted harmonics land within ±3 dB of the formant-kept spectrum; down-shifted ones keep the first formants but stay
+  15…25 dB under it above them (a raise is limited).
+
+Engine (`proStretch` + `warpengine::keepFormants`), warpLaw Measured only:
+1. Signalsmith Stretch to `outFrames × 2^(st/12)` (100 ms blocks, overlap 4 — the voice shifter's analysis; 90 ms Complex
+   blocks matched Live's Formants 0 renders less well: chords +7 spectrum 1.02 → 0.58 dB), along the warp map scaled by the
+   transposition when there is one;
+2. band-limited resampling back to `outFrames` (Kaiser sinc, cut-off lowered when read faster);
+3. formant correction per 46 ms frame (quarter hop): the cepstral **true envelope** (Röbel & Rodet) of the mono power,
+   lifter = Envelope / 4 samples at 44.1 kHz, the envelope read back at `bin × factor^(Formants/100)`; gain limited to
+   −40 dB … +6 dB (up) / +12 dB (down); held at the frame's fundamental below it; scaled by how pitched the frame is (the
+   normalised autocorrelation peak at 1…16.7 ms, 0.4 → 0 … 0.75 → 1).
+
+The lifter, the raise limits and the block were chosen by a grid on the 40 transposed r1.0 cells (`ana/grid*.txt`: score =
+spectrum + LSD/2 + formant shift + |level|/2; before 10.70, chosen 7.34; lifter Envelope/2 9.19, no raise 8.26, ±24 dB
+7.46, resample-before-stretch 7.56).
+
+| Complex Pro (W1 + W2) | cases | \|level\| dB | env corr | env dev dB | spectrum dB | LSD dB | formant shift st | cells better / worse |
+|---|---|---|---|---|---|---|---|---|
+| transposed (Formants > 0) | 60 | 1.74 → 1.73 | 0.87 → 0.88 | 2.52 → 2.62 | 3.87 → 2.62 | 6.24 → 4.59 | 3.21 → 1.30 | 204 / 129 |
+| Formants 0 | 8 | 0.20 → 0.11 | 0.98 → 0.99 | 1.35 → 1.02 | 0.53 → 0.43 | 3.00 → 2.68 | 0.58 → 0.44 | 27 / 6 |
+| no transposition | 8 | unchanged (Complex) | | | | | | 0 / 0 |
+
+Worse cells, by kind: level / envelope deviation where LYNX's corrected level differs from Live's (voice +7: +4.7 dB vs
+Live's −1.4 dB from the source), and the chords at −12 st (spectrum 6.2 → 11.7 dB: Live's octave-down chords keep more
+high partials than a formant correction gives). Complex Pro transposes offline now: no real-time shifter runs for it.
+
+## 3. Texture
+
+Facts (W1 / W2, `ana/grains.py`, `gmodel.py`, `lvl.py`, `fluxfit*.py`):
+- **Granular at the source's own speed**: with Flux 0 each grain k is anchored at (k + ½)·Grain Size ms of output and reads
+  the source from where the warp puts the anchor (the voice's grain starts sit at 32.5 + 65 k ms within 0.05 ms at both
+  speeds); grains are sine windows two periods long, not normalised (two overlap everywhere, their squares add to 1).
+  That model renders Live's flux-0 voice at sample correlation 0.996 / 0.998 and the same level (±0.01 dB).
+- **Flux scatters each grain's source position**; 25, 50 and 100 scatter alike (the spectrogram decorrelation from the
+  flux-0 grains is 0.931…0.934 for all three), about ⅛ of the grain period from Grain Size 65 up, relatively less below.
+  Between 0 and 25 the law is assumed linear (not rendered).
+- A transposed Texture clip resamples its grains (its formants move: vowel +7 shifts 6.6 st).
+
+Engine (`warpengine::texture`, warpLaw Measured): the model above; the scatter is a fixed pseudo-random sequence per
+source (renders repeat exactly); a transposition reads each grain `2^(st/12)` faster, rendered offline.
+
+| Texture (W1 + W2) | cases | \|level\| dB | env corr | env dev dB | spectrum dB | LSD dB | formant shift st | cells better / worse |
+|---|---|---|---|---|---|---|---|---|
+| Flux 0 | 8 | 0.60 → 0.04 | 0.89 → 0.99 | 2.73 → 0.19 | 1.07 → 0.08 | 3.66 → 0.34 | 0.86 → 0.04 | 45 / 0 |
+| Flux > 0 (random) | 48 | 0.42 → 0.32 | 0.90 → 0.88 | 2.44 → 2.39 | 1.44 → 1.21 | 4.41 → 3.96 | 1.09 → 0.88 | 133 / 92 |
+
+Flux > 0, statistics: the envelope's modulation depth is off Live's by 1.45 → 0.21 dB on average (48 cells), the long-term
+spectrum 1.44 → 1.21 dB (the spectral stretcher had almost no grain modulation). Worse cells there are envelope correlation / deviation of two random draws (e.g. vowel r0.8 flux 50: env corr
+0.79 → 0.59 while its modulation depth goes 0.84 → 2.43 dB against Live's 2.17).
+
+## 4. Beats: the pitch-aware detector (beatsLaw PitchAware)
+
+`warpengine::pitchAwareCuts` on top of the Measured law's cuts:
+1. YIN pitch track (decimated to ~11 kHz, 35 ms window, 5 ms hop, 60…1000 Hz);
+2. a level cut is dropped when the plain level rises < 6 dB and the pitch moves around it (a glide or vibrato, not an
+   attack);
+3. legato pitch steps are added: the median pitch 15…60 ms after differs from the one before by ≥ 0.8 st, both windows are
+   flat (a glide still moves inside them), the change lasts (60…150 ms either side), happens within 60 ms, and the level
+   holds (not a fading end); the cut is where the pitch crosses the step's middle (12 ms YIN lag removed);
+4. re-articulations of a held pitched sound are added: a ≥ 12 dB dip under a steady level that is back within 60 ms.
+
+Gate — LYNX-made labelled bank (`tests/OnsetBank190ik.h`, 32 cases, 44.1 / 48 kHz, ±30 ms, one-to-one matching):
+
+| category (cases) | Classic F (tp/fp/fn) | Measured F | PitchAware F |
+|---|---|---|---|
+| drums (4) | 1.000 (63/0/0) | 1.000 (63/0/0) | 1.000 (63/0/0) |
+| drumbass (4) | 0.667 (49/39/10) | 0.653 (48/40/11) | 0.697 (54/42/5) |
+| plucks (4) | 0.934 (57/1/7) | 0.934 (57/1/7) | 0.938 (60/4/4) |
+| chords (4) | 1.000 (28/0/0) | 1.000 (28/0/0) | 1.000 (28/0/0) |
+| legato (4) | 0.167 (4/0/40) | 0.167 (4/0/40) | 0.989 (43/0/1) |
+| sung (4) | 0.533 (8/0/14) | 0.533 (8/0/14) | 1.000 (22/0/0) |
+| glides (4) | 1.000 (4/0/0) | 1.000 (4/0/0) | 1.000 (4/0/0) |
+| lowglide (4) | 0.421 (4/11/0) | 0.421 (4/11/0) | 0.800 (4/2/0) |
+| **all (32)** | **0.781** (217/51/71) | **0.777** (216/52/72) | **0.906** (278/48/10) |
+
+Nothing worse in any category; the bass-range glides' false cuts drop from 11 to 2.
+
+Live's own Beats cuts on the voice (from the env-0 gaps, ms of source): 4274 5966 6082 6392 6510 6558 6747 6800 6979
+7032 7930. Measured finds 2 of them (4271, 7924; plus 3700); PitchAware 4 (adds 5951, 6077; plus 209 and 3700). On the
+vowel PitchAware cuts at the legato step (1506; Live 1496), the step down (5505; Live 5488) and once in the glide (2664,
+where YIN jumps an octave: a known gap). Effect on the W1 / W2 Beats renders vs Live: 48 cells better, 14 worse (drums
+identical; voice env corr r1.5 0.40 → 0.58, r0.8 Loop Off 0.69 → 0.81; vowel r1.5 −0.20 → 0.91; worse: voice spectrum /
+LSD by 0.1…0.7 dB).
+
+## 5. Old projects (law switch)
+
+- `WarpModeSettings::beatsLaw` gains PitchAware (2, the default); `warpLaw` (new) Classic | Measured (default Measured)
+  covers Texture and Complex Pro. The `.lynx` list gets an eleventh number; every save writes the mark `warpLaw190ik`; a
+  project without it loads Beats Measured (or Classic, 190gx's rule) and the Classic Texture / Complex Pro; the Clip View
+  shows a law chooser only for such channels (Beats: Classic / Measured / Pitch-aware; Texture and Complex Pro: Classic /
+  Measured beside the Flux / Envelope label).
+- **Proof**: every W1 / W2 case rendered by the pre-190ik code and by the new code on the old laws (Beats Classic and
+  Measured, Texture / Complex Pro Classic): **216 of 216 renders identical** (SHA-256 of the samples; `ana/prove.py`,
+  `prove-final.txt`).
+- Cache keys: Measured Beats keeps its empty key (PitchAware adds `|pa`); granular Texture `|gx<grain>f<flux>`; Complex Pro
+  `|pro<formants>,<envelope>` and its own engine print; Classic Texture keeps 190fm's keys.
+
+## 6. .als
+
+Import: Complex Pro (6) and Texture (2) clips with a transpose render it offline with the stretch (`stretchPitch`, ±48 st;
+the clip plays untransposed), as Beats did; Formants / Envelope / Flux play (the "kept for export, not rendered" report
+lines are gone). Export writes the offline transposition back as the clip's PitchCoarse / PitchFine.
+
+## 7. CPU (offline renders, single thread, 10 s stereo, ×1.25)
+
+Realtime factor = render time / output length (lower is better; load average ~16 on the machine while measured):
+
+| mode | 44.1 kHz | 48 kHz |
+|---|---|---|
+| Complex (unchanged) | 0.037 | 0.042 |
+| Complex Pro +7 st, 190ik (transposition + formants offline) | 0.153 | 0.158 |
+| Complex Pro +7 st, Classic (stretch only; the transposition then costs a real-time shifter per voice) | 0.039 | 0.051 |
+| Texture, 190ik granular | 0.0043 | 0.0055 |
+| Texture, Classic (spectral) | 0.046 | 0.043 |
+| Beats Measured | 0.0018 | 0.0019 |
+| Beats PitchAware (pitch track) | 0.013 | 0.015 |
+| Tones (unchanged) | 0.034 | 0.038 |
+
+Everything new runs in `timeStretch` (the stretch cache: loader threads / message thread), never on the audio thread; a
+transposed Complex Pro or Texture clip no longer runs a real-time pitch shifter per voice (≈ 2 % of a core each).
+
+## 8. Left out / live checks
+
+- Flux between 0 and 25 (assumed linear); Grain Size below 10 not measured with the new model (g2 buzzes differently:
+  spectrum 6.8 → 7.7 dB, the one Texture setting that got worse on spectrum).
+- Complex Pro levels: LYNX's corrected level is off Live's by 1.7 dB on average (unchanged); octave-down chords.
+- The Beats detector does not follow Live's cuts at vibrato / vowel changes (Live cuts there; the brief asked for glides
+  and vibrato not to cut). An octave error of the pitch track can still cut a glide.
+- The real-time clip pitch of Playlist clips (FL layout) on a Complex Pro / Texture channel stays the voice shifter.
+
+## 9. Best way?
+
+FL has no Complex Pro / Texture counterparts (its stretch modes map to LYNX's General / Transients / Mono). Live's
+behaviour is matched where measured; the detector deliberately goes beyond Live (glides and vibrato do not cut) because
+the brief asked for it; a project saved before 0.1.30 keeps its Measured cuts (chooser in the Clip View).

+ 14 - 9
tests/BeatsLaw190gxTests.inc

@@ -9,17 +9,22 @@ TEST (beatslaw190gx_defaults_lists_and_cache_keys)
 {
     using namespace lynx;
     const WarpModeSettings fresh;
-    CHECK (fresh.beatsLaw == WarpModeSettings::beatsLawMeasured);
-    // the .lynx list: a 190fm list had nine numbers (Classic), the tenth is the law
+    CHECK (fresh.beatsLaw == WarpModeSettings::beatsLawPitchAware); // (round 190ik's default; Measured before it)
+    // the .lynx list: a 190fm list had nine numbers (Classic), the tenth is the law (round 190ik: the eleventh the
+    // Texture / Complex Pro law)
     const std::array<double, 9> nine { 6, 2, 100, 30, 65, 25, 100, 128, 0 };
     CHECK (warpmodes::fromList (nine, nine.size()).beatsLaw == WarpModeSettings::beatsLawClassic);
-    auto ten = warpmodes::toList (fresh);
-    CHECK (ten.size() == 10 && ten[9] == 1.0 && warpmodes::fromList (ten, ten.size()) == fresh);
-    ten[9] = 0.0;
-    CHECK (warpmodes::fromList (ten, ten.size()).beatsLaw == WarpModeSettings::beatsLawClassic);
-    // the stretch caches tell the laws apart (Beats only), the Measured defaults keep the empty key
+    auto list = warpmodes::toList (fresh);
+    CHECK (list.size() == 11 && list[9] == 2.0 && list[10] == 1.0 && warpmodes::fromList (list, list.size()) == fresh);
+    list[9] = 1.0;
+    CHECK (warpmodes::fromList (list, list.size()).beatsLaw == WarpModeSettings::beatsLawMeasured);
+    list[9] = 0.0;
+    CHECK (warpmodes::fromList (list, list.size()).beatsLaw == WarpModeSettings::beatsLawClassic);
+    // the stretch caches tell the laws apart (Beats only), the Measured law keeps the empty key it had as the default
     StretchOptions measured, classic;
+    measured.modes.beatsLaw = WarpModeSettings::beatsLawMeasured;
     classic.modes.beatsLaw = WarpModeSettings::beatsLawClassic;
+    CHECK (stretchOptionsKey (StretchOptions {}, StretchMethod::beats) == "|pa");
     CHECK (stretchOptionsKey (measured, StretchMethod::beats).empty());
     CHECK (stretchOptionsKey (classic, StretchMethod::beats) == "|classic");
     CHECK (stretchOptionsKey (classic, StretchMethod::complex).empty());
@@ -44,7 +49,7 @@ TEST (beatslaw190gx_other_methods_ignore_the_law)
         CHECK (timeStretch (in, 1.25, m, 0.0, classic)->left == timeStretch (in, 1.25, m)->left);
 }
 
-TEST (beatslaw190gx_als_import_gets_the_measured_law)
+TEST (beatslaw190gx_als_import_gets_the_newest_law)
 {
     using namespace lynx;
     auto song = clipenv190gi::dcSong();
@@ -59,7 +64,7 @@ TEST (beatslaw190gx_als_import_gets_the_measured_law)
             if (c.instrument == InstrumentKind::audioClip)
             {
                 any = true;
-                CHECK (c.sampler.warpModes.beatsLaw == WarpModeSettings::beatsLawMeasured);
+                CHECK (c.sampler.warpModes.beatsLaw == WarpModeSettings::beatsLawPitchAware); // (round 190ik: the pitch-aware law)
             }
     CHECK (any);
 }

+ 325 - 0
tests/OnsetBank190ik.h

@@ -0,0 +1,325 @@
+#pragma once
+
+// Round 190ik: a labelled onset bank made by LYNX's own code (additive synthesis and noise, nothing recorded), for the Beats
+// transient detector's gate (before / after F-measure, per category). Each case knows exactly where its onsets are:
+//  drums    kick / snare / hat patterns at changing levels;
+//  drumbass drums over a plucked bass line;
+//  plucks   plucked harmonic notes (fast attack, exponential decay);
+//  legato   one sustained tone whose pitch steps (5…20 ms transitions) with light vibrato — tonal onsets, no level change;
+//  glides   one sustained tone with slow glides and wide vibrato — no onset after the first;
+//  lowglide the same in a bass range (70…130 Hz), where the level detector's envelope wobbles;
+//  sung     steps, glides, re-articulations (a 40 ms dip) and slow vibrato together;
+//  chords   polyphonic plucked chords.
+// Deterministic (fixed seeds), 44.1 and 48 kHz.
+
+#include <algorithm>
+#include <cmath>
+#include <cstdint>
+#include <string>
+#include <vector>
+
+namespace onsetbank190ik
+{
+struct Case
+{
+    std::string name, category;
+    double sampleRate = 44100.0;
+    std::vector<float> signal;
+    std::vector<double> onsets; // seconds
+};
+
+struct Lcg
+{
+    std::uint32_t s;
+    double next() { s = s * 1664525u + 1013904223u; return (double) (s >> 8) / 16777216.0; } // 0…1
+    double range (double a, double b) { return a + (b - a) * next(); }
+};
+
+constexpr double pi = 3.141592653589793;
+
+// a harmonic tone along a pitch track (Hz per frame) and a level track, with a fixed vowel-like spectral envelope
+inline void addTone (std::vector<float>& y, double sr, const std::vector<double>& f0, const std::vector<double>& amp, double brightness = 1.0)
+{
+    double phase = 0.0;
+    const auto n = y.size();
+    std::vector<double> acc (n, 0.0);
+    std::vector<double> ph (n);
+    for (std::size_t i = 0; i < n; ++i)
+    {
+        phase += 2.0 * pi * f0[i] / sr;
+        if (phase > 2.0 * pi * 1e6)
+            phase = std::fmod (phase, 2.0 * pi);
+        ph[i] = phase;
+    }
+    for (int k = 1; k <= 40; ++k)
+        for (std::size_t i = 0; i < n; ++i)
+        {
+            const auto f = k * f0[i];
+            if (f > 0.45 * sr || amp[i] == 0.0)
+                continue;
+            const auto taper = std::clamp ((0.45 * sr - f) / (0.1 * sr), 0.0, 1.0); // (no partial pops in at the top)
+            const auto formant = 1.0 / (1.0 + std::pow ((f - 800.0) / 500.0, 2.0)) + 0.4 / (1.0 + std::pow ((f - 2400.0) / 700.0, 2.0)) + 0.05;
+            acc[i] += amp[i] * taper * std::pow (1.0 / k, brightness) * formant * std::sin (k * ph[i]);
+        }
+    for (std::size_t i = 0; i < n; ++i)
+        y[i] += (float) acc[i];
+}
+
+inline void addPluck (std::vector<float>& y, double sr, double at, double hz, double level, double decay, int harmonics = 20)
+{
+    const auto start = (std::size_t) (at * sr);
+    for (std::size_t i = start; i < y.size(); ++i)
+    {
+        const auto t = (double) (i - start) / sr;
+        if (t > decay * 7.0)
+            break;
+        const auto env = level * std::exp (-t / decay) * std::min (1.0, t / 0.002);
+        double v = 0.0;
+        for (int k = 1; k <= harmonics && k * hz < 0.45 * sr; ++k)
+            v += std::exp (-t * 1.5 * k / decay * 0.1) / k * std::sin (2.0 * pi * k * hz * t);
+        y[i] += (float) (env * v);
+    }
+}
+
+inline void addDrum (std::vector<float>& y, double sr, double at, int kind, double level, Lcg& rnd)
+{
+    const auto start = (std::size_t) (at * sr);
+    double lp = 0.0, prev = 0.0, phase = 0.0;
+    for (std::size_t i = start; i < y.size(); ++i)
+    {
+        const auto t = (double) (i - start) / sr;
+        if (t > 0.6)
+            break;
+        double v = 0.0;
+        const auto noise = rnd.range (-1.0, 1.0);
+        if (kind == 0) // kick: falling sine
+        {
+            phase += 2.0 * pi * (50.0 + 90.0 * std::exp (-t / 0.03)) / sr;
+            v = std::sin (phase) * std::exp (-t / 0.18) + 0.3 * noise * std::exp (-t / 0.004);
+        }
+        else if (kind == 1) // snare: tone + noise
+        {
+            lp += 0.5 * (noise - lp);
+            v = 0.5 * std::sin (2.0 * pi * 190.0 * t) * std::exp (-t / 0.06) + 0.8 * lp * std::exp (-t / 0.12);
+        }
+        else // hat: high-passed noise
+        {
+            const auto hp = noise - prev;
+            prev = noise;
+            v = 0.5 * hp * std::exp (-t / 0.035);
+        }
+        y[i] += (float) (level * v * std::min (1.0, t / 0.0005));
+    }
+}
+
+inline std::vector<Case> bank()
+{
+    std::vector<Case> cases;
+    for (int variant = 0; variant < 4; ++variant)
+    {
+        const auto sr = variant % 2 == 0 ? 44100.0 : 48000.0;
+        Lcg rnd { 190u + 977u * (std::uint32_t) variant };
+        const auto seconds = 6.0;
+        const auto n = (std::size_t) (seconds * sr);
+        const auto tag = std::to_string (variant);
+
+        { // drums
+            Case c { "drums" + tag, "drums", sr, std::vector<float> (n, 0.0f), {} };
+            const auto step = 60.0 / rnd.range (90.0, 140.0) / 2.0;
+            for (double t = 0.1; t < seconds - 0.6; t += step)
+            {
+                const auto beat = (int) std::lround ((t - 0.1) / step);
+                const auto kind = beat % 4 == 0 ? 0 : beat % 4 == 2 ? 1 : 2;
+                if (kind == 2 && rnd.next() < 0.3)
+                    continue;
+                addDrum (c.signal, sr, t, kind, rnd.range (0.25, 0.8), rnd);
+                c.onsets.push_back (t);
+            }
+            cases.push_back (std::move (c));
+        }
+        { // drums over a plucked bass line
+            Case c { "drumbass" + tag, "drumbass", sr, std::vector<float> (n, 0.0f), {} };
+            const auto step = 60.0 / rnd.range (90.0, 130.0) / 2.0;
+            for (double t = 0.1; t < seconds - 0.6; t += step)
+            {
+                const auto beat = (int) std::lround ((t - 0.1) / step);
+                const auto hit = beat % 2 == 0, bass = hit || rnd.next() < 0.5;
+                if (hit)
+                    addDrum (c.signal, sr, t, beat % 4 == 0 ? 0 : 1, rnd.range (0.3, 0.7), rnd);
+                if (bass)
+                {
+                    addPluck (c.signal, sr, t, 55.0 * std::pow (2.0, (double) (int) rnd.range (0.0, 12.0) / 12.0), 0.35, 0.25, 8);
+                    c.onsets.push_back (t);
+                }
+            }
+            cases.push_back (std::move (c));
+        }
+        { // plucks
+            Case c { "plucks" + tag, "plucks", sr, std::vector<float> (n, 0.0f), {} };
+            for (double t = 0.1; t < seconds - 0.8; t += rnd.range (0.15, 0.5))
+            {
+                addPluck (c.signal, sr, t, 220.0 * std::pow (2.0, (double) (int) rnd.range (-7.0, 12.0) / 12.0), rnd.range (0.15, 0.4), rnd.range (0.2, 0.6));
+                c.onsets.push_back (t);
+            }
+            cases.push_back (std::move (c));
+        }
+        { // legato steps
+            Case c { "legato" + tag, "legato", sr, std::vector<float> (n, 0.0f), { 0.1 } };
+            std::vector<double> f0 (n), amp (n, 0.0);
+            auto note = rnd.range (-5.0, 5.0);
+            double t = 0.1, next = t + rnd.range (0.3, 0.7), from = note, to = note, moveStart = 0.0, moveLen = 0.0;
+            for (std::size_t i = 0; i < n; ++i)
+            {
+                const auto ti = (double) i / sr;
+                if (ti >= next && next < seconds - 0.4)
+                {
+                    from = to;
+                    to = from + (from > 5.0 ? -1.0 : from < -7.0 ? 1.0 : rnd.next() < 0.5 ? -1.0 : 1.0) * (double) (int) rnd.range (1.0, 8.0);
+                    moveStart = ti;
+                    moveLen = rnd.range (0.005, 0.020);
+                    c.onsets.push_back (ti + 0.5 * moveLen);
+                    next = ti + rnd.range (0.3, 0.7);
+                }
+                const auto u = moveLen > 0.0 ? std::clamp ((ti - moveStart) / moveLen, 0.0, 1.0) : 1.0;
+                const auto st = from + (to - from) * u + 0.15 * std::sin (2.0 * pi * 5.5 * ti);
+                f0[i] = 220.0 * std::pow (2.0, st / 12.0);
+                amp[i] = ti < t ? 0.0 : 0.1 * std::min (1.0, (ti - t) / 0.01) * std::min (1.0, (seconds - ti) / 0.05);
+            }
+            addTone (c.signal, sr, f0, amp);
+            cases.push_back (std::move (c));
+        }
+        { // glides and vibrato (only the first onset)
+            Case c { "glides" + tag, "glides", sr, std::vector<float> (n, 0.0f), { 0.1 } };
+            std::vector<double> f0 (n), amp (n, 0.0);
+            double from = rnd.range (-4.0, 4.0), to = from, moveStart = 0.0, moveLen = 1.0, next = 0.5;
+            for (std::size_t i = 0; i < n; ++i)
+            {
+                const auto ti = (double) i / sr;
+                if (ti >= next && next < seconds - 1.0)
+                {
+                    from = to;
+                    to = from + (from > 2.0 ? -1.0 : from < -2.0 ? 1.0 : rnd.next() < 0.5 ? -1.0 : 1.0) * rnd.range (2.0, 9.0);
+                    moveStart = ti;
+                    moveLen = rnd.range (0.15, 0.5);
+                    next = ti + moveLen + rnd.range (0.4, 0.9);
+                }
+                const auto u = std::clamp ((ti - moveStart) / moveLen, 0.0, 1.0);
+                const auto shape = 0.5 - 0.5 * std::cos (pi * u);
+                const auto vib = (std::fmod (ti, 2.0) > 1.0 ? 0.5 : 0.2) * std::sin (2.0 * pi * 5.0 * ti);
+                f0[i] = 220.0 * std::pow (2.0, (from + (to - from) * shape + vib) / 12.0);
+                amp[i] = ti < 0.1 ? 0.0 : 0.1 * std::min (1.0, (ti - 0.1) / 0.01) * std::min (1.0, (seconds - ti) / 0.05);
+            }
+            addTone (c.signal, sr, f0, amp);
+            cases.push_back (std::move (c));
+        }
+        { // low glides: a bass voice / cello range (70…130 Hz) gliding with vibrato — the level detector's derivative
+          // envelope wobbles with the waveform here (only the first onset counts)
+            Case c { "lowglide" + tag, "lowglide", sr, std::vector<float> (n, 0.0f), { 0.1 } };
+            std::vector<double> f0 (n), amp (n, 0.0);
+            double from = rnd.range (-2.0, 2.0), to = from, moveStart = 0.0, moveLen = 1.0, next = 0.5;
+            for (std::size_t i = 0; i < n; ++i)
+            {
+                const auto ti = (double) i / sr;
+                if (ti >= next && next < seconds - 1.0)
+                {
+                    from = to;
+                    to = from + (from > 2.0 ? -1.0 : from < -2.0 ? 1.0 : rnd.next() < 0.5 ? -1.0 : 1.0) * rnd.range (2.0, 7.0);
+                    moveStart = ti;
+                    moveLen = rnd.range (0.15, 0.5);
+                    next = ti + moveLen + rnd.range (0.4, 0.9);
+                }
+                const auto u = std::clamp ((ti - moveStart) / moveLen, 0.0, 1.0);
+                const auto shape = 0.5 - 0.5 * std::cos (pi * u);
+                const auto vib = 0.4 * std::sin (2.0 * pi * 5.0 * ti);
+                f0[i] = 98.0 * std::pow (2.0, (from + (to - from) * shape + vib) / 12.0);
+                amp[i] = ti < 0.1 ? 0.0 : 0.1 * std::min (1.0, (ti - 0.1) / 0.01) * std::min (1.0, (seconds - ti) / 0.05);
+            }
+            addTone (c.signal, sr, f0, amp);
+            cases.push_back (std::move (c));
+        }
+        { // sung: steps, glides, re-articulations, vibrato
+            Case c { "sung" + tag, "sung", sr, std::vector<float> (n, 0.0f), { 0.1 } };
+            std::vector<double> f0 (n), amp (n, 0.0);
+            double from = rnd.range (-3.0, 3.0), to = from, moveStart = 0.0, moveLen = 1.0, next = 0.6, dip = -1.0;
+            for (std::size_t i = 0; i < n; ++i)
+            {
+                const auto ti = (double) i / sr;
+                if (ti >= next && next < seconds - 0.5)
+                {
+                    const auto kind = (int) rnd.range (0.0, 3.0);
+                    from = to;
+                    if (kind == 0) // step
+                    {
+                        to = from + (from > 3.0 ? -1.0 : from < -3.0 ? 1.0 : rnd.next() < 0.5 ? -1.0 : 1.0) * (double) (int) rnd.range (1.0, 6.0);
+                        moveStart = ti;
+                        moveLen = rnd.range (0.006, 0.02);
+                        c.onsets.push_back (ti + 0.5 * moveLen);
+                    }
+                    else if (kind == 1) // glide
+                    {
+                        to = from + (from > 3.0 ? -1.0 : from < -3.0 ? 1.0 : rnd.next() < 0.5 ? -1.0 : 1.0) * rnd.range (2.0, 7.0);
+                        moveStart = ti;
+                        moveLen = rnd.range (0.15, 0.35);
+                    }
+                    else // re-articulation: a 40 ms dip, same pitch
+                    {
+                        dip = ti;
+                        c.onsets.push_back (ti + 0.040);
+                    }
+                    next = ti + std::max (moveLen, 0.05) + rnd.range (0.35, 0.7);
+                }
+                const auto u = std::clamp ((ti - moveStart) / moveLen, 0.0, 1.0);
+                const auto shape = moveLen < 0.05 ? u : 0.5 - 0.5 * std::cos (pi * u);
+                f0[i] = 220.0 * std::pow (2.0, (from + (to - from) * shape + 0.2 * std::sin (2.0 * pi * 5.2 * ti)) / 12.0);
+                double a = ti < 0.1 ? 0.0 : 0.1 * std::min (1.0, (ti - 0.1) / 0.01) * std::min (1.0, (seconds - ti) / 0.05);
+                if (dip >= 0.0 && ti >= dip && ti < dip + 0.050)
+                    a *= ti < dip + 0.030 ? 1.0 - 0.95 * (ti - dip) / 0.030 : 0.05 + 0.95 * (ti - dip - 0.030) / 0.020;
+                amp[i] = a;
+            }
+            addTone (c.signal, sr, f0, amp);
+            cases.push_back (std::move (c));
+        }
+        { // chords
+            Case c { "chords" + tag, "chords", sr, std::vector<float> (n, 0.0f), {} };
+            for (double t = 0.1; t < seconds - 1.0; t += rnd.range (0.5, 1.1))
+            {
+                const auto root = (double) (int) rnd.range (-6.0, 6.0);
+                for (const auto interval : { 0.0, 4.0, 7.0, 12.0 })
+                    addPluck (c.signal, sr, t, 196.0 * std::pow (2.0, (root + interval) / 12.0), 0.12, rnd.range (0.4, 0.9));
+                c.onsets.push_back (t);
+            }
+            cases.push_back (std::move (c));
+        }
+    }
+    return cases;
+}
+
+// one-to-one matching within ±tolerance: true positives, false positives, false negatives
+struct Score
+{
+    int tp = 0, fp = 0, fn = 0;
+    double f() const { return tp == 0 ? 0.0 : 2.0 * tp / (2.0 * tp + fp + fn); }
+};
+inline Score score (const std::vector<double>& truth, const std::vector<double>& found, double tolerance = 0.030)
+{
+    Score s;
+    std::vector<bool> used (found.size(), false);
+    for (const auto t : truth)
+    {
+        int best = -1;
+        for (std::size_t j = 0; j < found.size(); ++j)
+            if (! used[j] && std::abs (found[j] - t) <= tolerance && (best < 0 || std::abs (found[j] - t) < std::abs (found[(std::size_t) best] - t)))
+                best = (int) j;
+        if (best >= 0)
+        {
+            used[(std::size_t) best] = true;
+            ++s.tp;
+        }
+        else
+            ++s.fn;
+    }
+    for (const auto u : used)
+        s.fp += u ? 0 : 1;
+    return s;
+}
+} // namespace onsetbank190ik

+ 454 - 0
tests/Warp190ikTests.inc

@@ -0,0 +1,454 @@
+// Round 190ik (BUILD-LIST 8): Complex Pro (formant-keeping transposition, offline), Texture (granular, Grain Size and Flux)
+// and the pitch-aware Beats detector, fitted black-box on Ableton Live 12.4's renders (/mnt/e/lynx-work/warp190ik,
+// docs/analise/REA_rodada190ik.md). Old projects keep the old laws bit for bit (warpLaw / beatsLaw Classic and Measured).
+
+#include "OnsetBank190ik.h"
+#include "core/TimeStretch.h"
+#include "core/WarpEngines.h"
+#include "core/WarpModes.h"
+
+namespace warp190ik
+{
+constexpr double twoPi = 2.0 * 3.141592653589793;
+
+inline lynx::SampleData sine (double hz, double seconds, double rate = 44100.0, double level = 0.5)
+{
+    lynx::SampleData d;
+    d.sampleRate = rate;
+    for (long i = 0; i < (long) (seconds * rate); ++i)
+        d.left.push_back ((float) (level * std::sin (twoPi * hz * (double) i / rate)));
+    d.right = d.left;
+    return d;
+}
+
+// a sung-like tone at 200 Hz whose spectral envelope has formants at 700 and 1200 Hz
+inline lynx::SampleData vowel (double seconds = 2.0, double rate = 44100.0)
+{
+    lynx::SampleData d;
+    d.sampleRate = rate;
+    const auto envelope = [] (double f) {
+        return 1.0 / (1.0 + std::pow ((f - 700.0) / 60.0, 2.0)) + 0.5 / (1.0 + std::pow ((f - 1200.0) / 70.0, 2.0)) + 0.01;
+    };
+    for (long i = 0; i < (long) (seconds * rate); ++i)
+    {
+        double v = 0.0;
+        for (int k = 1; k * 200.0 < 5000.0; ++k)
+            v += envelope (k * 200.0) * std::sin (twoPi * 200.0 * k * (double) i / rate);
+        d.left.push_back ((float) (0.2 * v));
+    }
+    d.right = d.left;
+    return d;
+}
+
+// frequency from the zero crossings of x[from, to)
+inline double frequency (const std::vector<float>& x, long from, long to, double rate)
+{
+    double first = -1.0, last = -1.0;
+    int crossings = 0;
+    for (long i = from + 1; i < to; ++i)
+        if (x[(std::size_t) i - 1] < 0.0f && x[(std::size_t) i] >= 0.0f)
+        {
+            const auto t = (double) (i - 1) + (double) x[(std::size_t) i - 1] / (double) (x[(std::size_t) i - 1] - x[(std::size_t) i]);
+            if (first < 0.0)
+                first = t;
+            last = t;
+            ++crossings;
+        }
+    return crossings > 1 ? (crossings - 1) * rate / (last - first) : 0.0;
+}
+
+inline double cents (double a, double b) { return 1200.0 * std::log2 (a / b); }
+
+// the largest step between neighbouring samples in x[from, to), relative to a sine of `hz` at `level`'s steepest step
+inline double roughness (const std::vector<float>& x, long from, long to, double hz, double rate, double level)
+{
+    double worst = 0.0;
+    for (long i = from + 1; i < to; ++i)
+        worst = std::max (worst, (double) std::abs (x[(std::size_t) i] - x[(std::size_t) i - 1]));
+    return worst / (level * twoPi * hz / rate);
+}
+
+// the amplitude-weighted mean frequency of the harmonics of f0 (200…5000 Hz) over x[from, from + n)
+inline double centroid (const std::vector<float>& x, long from, long n, double f0, double rate)
+{
+    double num = 0.0, den = 0.0;
+    for (int k = 1; k * f0 < 5000.0; ++k)
+    {
+        double re = 0.0, im = 0.0;
+        for (long i = 0; i < n; ++i)
+        {
+            const auto w = 0.5 - 0.5 * std::cos (twoPi * (double) i / (double) n);
+            const auto ph = twoPi * k * f0 * (double) i / rate;
+            re += w * x[(std::size_t) (from + i)] * std::cos (ph);
+            im += w * x[(std::size_t) (from + i)] * std::sin (ph);
+        }
+        const auto p = re * re + im * im;
+        num += k * f0 * p;
+        den += p;
+    }
+    return den > 0.0 ? num / den : 0.0;
+}
+
+inline lynx::StretchOptions pro (float formants = 100.0f, float envelope = 128.0f)
+{
+    lynx::StretchOptions o;
+    o.modes.complexPro = true;
+    o.modes.proFormants = formants;
+    o.modes.proEnvelope = envelope;
+    return o;
+}
+
+inline lynx::StretchOptions texture (float grain = 65.0f, float flux = 25.0f)
+{
+    lynx::StretchOptions o;
+    o.modes.textureGrain = grain;
+    o.modes.textureFlux = flux;
+    return o;
+}
+} // namespace warp190ik
+
+TEST (warp190ik_complex_pro_length_pitch_and_no_clicks)
+{
+    using namespace lynx;
+    using namespace warp190ik;
+    for (const auto rate : { 44100.0, 48000.0 })
+        for (const auto ratio : { 0.8, 1.0, 1.5 })
+            for (const auto st : { -5.0, 7.0 })
+            {
+                const auto in = sine (330.0, 2.0, rate);
+                const auto out = timeStretch (in, ratio, StretchMethod::complex, st, pro());
+                const auto expected = (long) std::llround ((double) in.frames() * ratio);
+                CHECK ((long) out->frames() == expected);
+                const auto n = (long) out->frames();
+                const auto f = frequency (out->left, n / 4, 3 * n / 4, rate);
+                CHECK (std::abs (cents (f, 330.0 * std::pow (2.0, st / 12.0))) < 3.0);
+                CHECK (roughness (out->left, (long) (0.1 * rate), n - (long) (0.1 * rate), 330.0 * std::pow (2.0, st / 12.0), rate, 0.5) < 1.6);
+            }
+}
+
+TEST (warp190ik_complex_pro_keeps_the_formants_by_the_formants_amount)
+{
+    using namespace lynx;
+    using namespace warp190ik;
+    const auto in = vowel();
+    const auto rate = in.sampleRate;
+    const long from = 22050, n = 22050;
+    const auto source = centroid (in.left, from, n, 200.0, rate);
+    const auto up = std::pow (2.0, 7.0 / 12.0);
+    const auto kept = timeStretch (in, 1.0, StretchMethod::complex, 7.0, pro (100.0f));
+    const auto moved = timeStretch (in, 1.0, StretchMethod::complex, 7.0, pro (0.0f));
+    const auto half = timeStretch (in, 1.0, StretchMethod::complex, 7.0, pro (50.0f));
+    const auto cKept = centroid (kept->left, from, n, 200.0 * up, rate);
+    const auto cMoved = centroid (moved->left, from, n, 200.0 * up, rate);
+    const auto cHalf = centroid (half->left, from, n, 200.0 * up, rate);
+    CHECK (std::abs (cKept / source - 1.0) < 0.15);  // Formants 100: the envelope stays
+    CHECK (cMoved / source > 1.35);                   // Formants 0: it moves with the pitch (×1.5)
+    CHECK (cHalf > cKept && cHalf < cMoved);          // 50: between
+    // a coarse Envelope (8) keeps less of the formants than the default
+    const auto coarse = timeStretch (in, 1.0, StretchMethod::complex, 7.0, pro (100.0f, 8.0f));
+    CHECK (centroid (coarse->left, from, n, 200.0 * up, rate) > cKept);
+}
+
+TEST (warp190ik_complex_pro_is_deterministic_and_mapped)
+{
+    using namespace lynx;
+    using namespace warp190ik;
+    const auto in = vowel (1.5);
+    const auto a = timeStretch (in, 1.3, StretchMethod::complex, 4.0, pro());
+    const auto b = timeStretch (in, 1.3, StretchMethod::complex, 4.0, pro());
+    CHECK (a->left == b->left && a->right == b->right);
+    // along a warp map: the map's length, and the same pitch
+    const auto frames = (double) in.frames();
+    const StretchMap map { { 0.0, 0.0 }, { frames * 0.5, frames * 0.4 }, { frames, frames * 1.2 } };
+    const auto m = timeStretchMapped (in, map, StretchMethod::complex, 4.0, pro());
+    CHECK ((long) m->frames() == (long) std::llround (frames * 1.2));
+    const auto pure = timeStretchMapped (sine (330.0, 1.5), map, StretchMethod::complex, 4.0, pro());
+    CHECK (std::abs (cents (frequency (pure->left, 20000, 50000, 44100.0), 330.0 * std::pow (2.0, 4.0 / 12.0))) < 5.0);
+}
+
+TEST (warp190ik_complex_pro_classic_law_is_complex_with_the_old_real_time_pitch)
+{
+    using namespace lynx;
+    using namespace warp190ik;
+    const auto in = vowel (1.0);
+    auto classic = pro();
+    classic.modes.warpLaw = WarpModeSettings::warpLawClassic;
+    // Classic: the transposition is not rendered offline (the voice shifts it, as before 190ik), so the stretch is Complex's
+    CHECK (! stretchBakesPitch (StretchMethod::complex, classic.modes));
+    CHECK (stretchBakesPitch (StretchMethod::complex, pro().modes) && ! stretchBakesPitch (StretchMethod::complex, StretchOptions {}.modes));
+    CHECK (timeStretch (in, 1.25, StretchMethod::complex, 5.0, classic)->left == timeStretch (in, 1.25, StretchMethod::complex)->left);
+    // no transposition: Complex Pro stretches as Complex (Live: the two render alike, W2 cpro-def vs W1 cplx-def)
+    CHECK (timeStretch (in, 1.25, StretchMethod::complex, 0.0, pro())->left == timeStretch (in, 1.25, StretchMethod::complex)->left);
+}
+
+TEST (warp190ik_texture_grains_flux_and_determinism)
+{
+    using namespace lynx;
+    using namespace warp190ik;
+    for (const auto rate : { 44100.0, 48000.0 })
+    {
+        // at the source's speed with no flux the grains read where they play: the source back, its level raised by the
+        // two sine windows' sum (1 … √2, as Live's renders: power kept for uncorrelated grains)
+        const auto in = sine (440.0, 1.0, rate);
+        const auto same = timeStretch (in, 1.0, StretchMethod::texture, 0.0, texture (65.0f, 0.0f));
+        CHECK (same->frames() == in.frames());
+        double worst = 0.0;
+        const auto period = 0.065 * rate;
+        for (long i = (long) period; i < (long) in.left.size() - (long) period; ++i)
+        {
+            const auto u = std::fmod ((double) i, period) / (2.0 * period); // (where the later of the two grains is)
+            const auto gain = std::sin (3.141592653589793 * u) + std::cos (3.141592653589793 * u);
+            worst = std::max (worst, std::abs ((double) same->left[(std::size_t) i] - gain * in.left[(std::size_t) i]));
+        }
+        CHECK (worst < 1e-3);
+        for (const auto ratio : { 0.5, 1.5 })
+            for (const auto grain : { 10.0f, 65.0f, 263.0f })
+            {
+                const auto out = timeStretch (in, ratio, StretchMethod::texture, 0.0, texture (grain, 50.0f));
+                const auto n = (long) out->frames();
+                CHECK (n == (long) std::llround ((double) in.frames() * ratio));
+                // the pitch stays (grains read at the source's own speed); a grain's window never steps
+                CHECK (std::abs (cents (frequency (out->left, n / 4, 3 * n / 4, rate), 440.0)) < 4.0);
+                CHECK (roughness (out->left, 0, n, 440.0, rate, 0.5) < 1.6);
+                const auto again = timeStretch (in, ratio, StretchMethod::texture, 0.0, texture (grain, 50.0f));
+                CHECK (again->left == out->left);
+            }
+    }
+    // a transposition resamples each grain (Live's transposed Texture): the pitch moves, the length stays
+    {
+        const auto in = sine (440.0, 1.0);
+        const auto up = timeStretch (in, 1.25, StretchMethod::texture, 7.0, texture (65.0f, 0.0f));
+        const auto n = (long) up->frames();
+        CHECK (n == (long) std::llround ((double) in.frames() * 1.25));
+        CHECK (std::abs (cents (frequency (up->left, n / 4, 3 * n / 4, 44100.0), 440.0 * std::pow (2.0, 7.0 / 12.0))) < 4.0);
+        CHECK (stretchBakesPitch (StretchMethod::texture, texture().modes));
+    }
+    // Flux scatters the grains (another render), Grain Size changes them
+    const auto in = vowel (1.0);
+    const auto f0 = timeStretch (in, 1.5, StretchMethod::texture, 0.0, texture (65.0f, 0.0f));
+    const auto f100 = timeStretch (in, 1.5, StretchMethod::texture, 0.0, texture (65.0f, 100.0f));
+    const auto g30 = timeStretch (in, 1.5, StretchMethod::texture, 0.0, texture (30.0f, 0.0f));
+    CHECK (f0->left != f100->left && f0->left != g30->left);
+    CHECK (std::abs (warpengine::textureGrainPeriodMs (65.0) - 65.0) < 1e-9 && warpengine::textureFluxSpreadMs (65.0, 0.0) == 0.0);
+}
+
+TEST (warp190ik_texture_classic_law_is_the_spectral_stretch_as_before)
+{
+    using namespace lynx;
+    using namespace warp190ik;
+    const auto in = vowel (1.0);
+    auto classic = texture (80.0f, 60.0f);
+    classic.modes.warpLaw = WarpModeSettings::warpLawClassic;
+    const auto preset = stretchdetail::presetFor (StretchMethod::texture, classic.modes);
+    CHECK (timeStretch (in, 1.3, StretchMethod::texture, 0.0, classic)->left == stretchdetail::stretchWith (in, 1.3, preset)->left);
+    // keys: the Classic law keeps 190fm's, the Measured one keys grain and flux; Complex Pro its Formants / Envelope
+    StretchOptions oldDefault;
+    oldDefault.modes.warpLaw = WarpModeSettings::warpLawClassic;
+    CHECK (stretchOptionsKey (oldDefault, StretchMethod::texture).empty());
+    CHECK (stretchOptionsKey (StretchOptions {}, StretchMethod::texture) == "|gx65f25");
+    CHECK (stretchOptionsKey (pro (30.0f, 64.0f), StretchMethod::complex) == "|pro30,64");
+    CHECK (stretchOptionsKey (StretchOptions {}, StretchMethod::complex).empty());
+}
+
+TEST (warp190ik_pitch_aware_detector_gate_on_the_onset_bank)
+{
+    using namespace lynx;
+    std::map<std::string, std::array<onsetbank190ik::Score, 3>> per;
+    for (const auto& c : onsetbank190ik::bank())
+        for (int law = 0; law < 3; ++law)
+        {
+            const auto cuts = stretchdetail::beatsCutsOfLaw (c.signal.data(), (long) c.signal.size(), c.sampleRate, law);
+            std::vector<double> t;
+            for (const auto x : cuts)
+                t.push_back ((double) x / c.sampleRate);
+            const auto s = onsetbank190ik::score (c.onsets, t);
+            auto& p = per[c.category][(std::size_t) law];
+            p.tp += s.tp;
+            p.fp += s.fp;
+            p.fn += s.fn;
+            // the older laws are the older cuts
+            if (law < 2)
+                CHECK (cuts == stretchdetail::beatsCuts (c.signal.data(), (long) c.signal.size(), c.sampleRate, law == 1));
+        }
+    // the gate: nothing worse in any category, the tonal ones much better
+    for (const auto& [category, s] : per)
+        CHECK (s[2].f() >= s[1].f());
+    CHECK (per["legato"][2].f() >= 0.9 && per["legato"][2].f() > per["legato"][1].f() + 0.3);
+    CHECK (per["sung"][2].f() > per["sung"][1].f());
+    CHECK (per["glides"][2].fp <= per["glides"][1].fp);
+    CHECK (per["lowglide"][2].fp < per["lowglide"][1].fp); // (glides no longer cut where the level detector's envelope wobbles)
+    CHECK (per["drums"][2].f() == 1.0);
+}
+
+TEST (warp190ik_beats_pitch_aware_law_cuts_a_legato_step)
+{
+    using namespace lynx;
+    // one held tone that steps a fifth up at 0.6 s: the Measured law hears no attack there, PitchAware cuts it
+    constexpr double rate = 44100.0;
+    std::vector<float> x ((std::size_t) (1.2 * rate));
+    double phase = 0.0;
+    for (std::size_t i = 0; i < x.size(); ++i)
+    {
+        const auto t = (double) i / rate;
+        phase += 2.0 * 3.141592653589793 * (t < 0.6 ? 220.0 : 330.0) / rate;
+        double v = 0.0;
+        for (int k = 1; k <= 8; ++k)
+            v += std::sin (k * phase) / k;
+        x[i] = (float) (0.2 * v * std::min (1.0, t / 0.01));
+    }
+    const auto measured = stretchdetail::beatsCutsOfLaw (x.data(), (long) x.size(), rate, WarpModeSettings::beatsLawMeasured);
+    const auto aware = stretchdetail::beatsCutsOfLaw (x.data(), (long) x.size(), rate, WarpModeSettings::beatsLawPitchAware);
+    const auto near = [&] (const std::vector<long>& cuts) {
+        return std::any_of (cuts.begin(), cuts.end(), [&] (long c) { return std::abs ((double) c / rate - 0.6) < 0.025; });
+    };
+    CHECK (! near (measured));
+    CHECK (near (aware));
+    // the Beats render follows its law's cuts: the two laws differ only on such material
+    SampleData in;
+    in.sampleRate = rate;
+    in.left = x;
+    in.right = x;
+    StretchOptions m, a;
+    m.modes.beatsLaw = WarpModeSettings::beatsLawMeasured;
+    CHECK (timeStretch (in, 1.3, StretchMethod::beats, 0.0, m)->left != timeStretch (in, 1.3, StretchMethod::beats, 0.0, a)->left);
+}
+
+TEST (warp190ik_als_complex_pro_transposes_offline_and_round_trips)
+{
+    using namespace lynx;
+    auto xml = als175a::richSet(); // (its audio clip: WarpMode 4, PitchCoarse 2)
+    const std::string from = "</FileRef></SampleRef></AudioClip>";
+    const std::string oldMode = "<WarpMode Value=\"4\" />";
+    const auto at = xml.find (from), m = xml.find (oldMode);
+    CHECK (at != std::string::npos && m != std::string::npos);
+    if (at == std::string::npos || m == std::string::npos)
+        return;
+    xml.replace (at, from.size(), "</FileRef><DefaultDuration Value=\"96000\" /><DefaultSampleRate Value=\"48000\" /></SampleRef></AudioClip>");
+    xml.replace (m, oldMode.size(), "<WarpMode Value=\"6\" />" + als175a::v ("ComplexProFormants", "40") + als175a::v ("ComplexProEnvelope", "96")
+                                        + als175a::v ("FluctuationTexture", "70"));
+    FlpImportReport report;
+    const auto bytes = als175a::bytesOf (xml);
+    const auto song = importAls (gzip::compressStored (bytes.data(), bytes.size()), als175a::options (&report), nullptr);
+    CHECK (song.has_value());
+    if (! song)
+        return;
+    const Clip* clip = nullptr;
+    for (const auto& c : song->playlist)
+        if (c.kind == ClipKind::audio)
+            clip = &c;
+    CHECK (clip != nullptr);
+    if (clip == nullptr)
+        return;
+    const auto& ch = song->channels[(std::size_t) clip->channel];
+    // the transposition is the channel's offline one (formants kept), the clip plays untransposed
+    CHECK (ch.sampler.warpModes.complexPro && ch.sampler.warpModes.warpLaw == WarpModeSettings::warpLawMeasured);
+    CHECK (ch.sampler.stretchPitch == 2.0f && clip->pitch == 0.0f && ch.sampler.bakesPitch());
+    CHECK (ch.sampler.warpModes.proFormants == 40.0f && ch.sampler.warpModes.proEnvelope == 96.0f && ch.sampler.warpModes.textureFlux == 70.0f);
+    CHECK (report.partialEffects.empty() || report.partialEffects.count ("Warp mode Complex Pro (plays as Complex; Formants and Envelope kept for export)") == 0);
+    const auto out = exportAls (*song);
+    for (const auto* member : { "<WarpMode Value=\"6\"", "<PitchCoarse Value=\"2\"", "<ComplexProFormants Value=\"40\"", "<ComplexProEnvelope Value=\"96\"",
+                                "<FluctuationTexture Value=\"70\"" })
+        CHECK (out.xml.find (member) != std::string::npos);
+}
+
+TEST (warp190ik_clip_view_transposes_complex_pro_offline)
+{
+    using namespace lynx;
+    Song song;
+    ChannelDef ch;
+    ch.instrument = InstrumentKind::audioClip;
+    ch.sampler.keepPitch = true;
+    ch.sampler.stretchBeats = 8.0f;
+    song.channels.push_back (ch);
+    Clip clip;
+    clip.kind = ClipKind::audio;
+    clip.channel = 0;
+    clip.length = 8 * ppq;
+    launcher::setClip (song, 0, 0, clip);
+    launcher::ensureGrid (song).scenes.resize (1);
+    CHECK (warpmodes::gridAudioClip (song, 0, 0) != nullptr);
+    if (warpmodes::gridAudioClip (song, 0, 0) == nullptr)
+        return;
+    CHECK (warpmodes::setComplexPro (song, 0));
+    CHECK (warpmodes::setClipTranspose (song, 0, 0, 0, 5.0f));
+    CHECK (song.channels[0].sampler.stretchPitch == 5.0f && warpmodes::gridAudioClip (song, 0, 0)->pitch == 0.0f);
+    // back to Classic (a project saved before 190ik): the transposition plays in real time again (the Pitch knob)
+    CHECK (warpmodes::setWarpLaw (song, 0, 0) && song.channels[0].sampler.stretchPitch == 0.0f && song.channels[0].sampler.pitch == 5.0f);
+    CHECK (warpmodes::setClipTranspose (song, 0, 0, 0, 3.0f) && warpmodes::gridAudioClip (song, 0, 0)->pitch == 3.0f);
+    // Texture transposes offline too (its grains resampled); a mode that does not (Tones) gets the transposition on its knob
+    CHECK (warpmodes::setWarpLaw (song, 0, 1) && warpmodes::setClipTranspose (song, 0, 0, 0, 4.0f) && song.channels[0].sampler.stretchPitch == 4.0f);
+    CHECK (warpmodes::setMode (song, 0, (int) StretchMethod::texture) && song.channels[0].sampler.stretchPitch == 4.0f);
+    CHECK (warpmodes::setMode (song, 0, (int) StretchMethod::tones) && song.channels[0].sampler.stretchPitch == 0.0f);
+}
+
+// Render-ahead (round 190gq) stays bit-exact with the new engines in the part rendered ahead: a Complex Pro channel with an
+// offline transposition and a granular Texture channel, stretched through the rack's stretch factory.
+TEST (warp190ik_render_ahead_is_bit_exact_with_complex_pro_and_texture)
+{
+    using namespace lynx;
+    auto song = ra190gq::makeSong (4);
+    const auto firstAudio = (int) song.channels.size();
+    for (int k = 0; k < 2; ++k)
+    {
+        ChannelDef c;
+        c.name = k == 0 ? "Pro" : "Texture";
+        c.instrument = InstrumentKind::audioClip;
+        c.samplePath = k == 0 ? "pro.wav" : "tex.wav";
+        c.mixerTrack = 5 + k;
+        c.volume = 0.3f;
+        c.sampler.keepPitch = true;
+        c.sampler.stretchBeats = 6.0f;
+        if (k == 0)
+        {
+            c.sampler.stretchMethod = StretchMethod::complex;
+            c.sampler.warpModes.complexPro = true;
+            c.sampler.stretchPitch = 5.0f;
+        }
+        else
+            c.sampler.stretchMethod = StretchMethod::texture;
+        song.channels.push_back (c);
+        Clip clip;
+        clip.kind = ClipKind::audio;
+        clip.channel = firstAudio + k;
+        clip.track = 6 + k;
+        clip.length = ppq * 6;
+        song.playlist.push_back (clip);
+    }
+    RackState::Factories factories;
+    factories.samples = [] (const std::string& path) {
+        auto d = std::make_shared<SampleData>();
+        d->sampleRate = 44100.0;
+        const auto f = path == "pro.wav" ? 220.0 : 330.0;
+        for (int i = 0; i < 44100 * 3; ++i)
+            d->left.push_back ((float) (0.5 * std::sin (2.0 * 3.141592653589793 * f * i / 44100.0) * std::exp (-(i % 11025) / 4000.0)));
+        d->right = d->left;
+        return std::shared_ptr<const SampleData> (d);
+    };
+    factories.stretchedSamples = [&factories] (const std::string& path, double ratio, StretchMethod method, double semitones, const StretchMap& map,
+                                               const StretchOptions& options) {
+        const auto data = factories.samples (path);
+        return std::shared_ptr<const SampleData> (map.empty() ? timeStretch (*data, ratio, method, semitones, options)
+                                                              : timeStretchMapped (*data, map, method, semitones, options));
+    };
+    const int blocks = 1400;
+    auto state = RackState::build (song, nullptr, 44100.0, factories);
+    RackRenderer plain;
+    plain.prepare (44100.0, 2048);
+    MeterBank meters;
+    LiveEventQueue live;
+    ra190gq::Callback cb0 (song, 64, 0.0);
+    std::vector<float> l0, r0, l1, r1;
+    cb0.run (blocks, l0, r0, [&] (double start, int n, double, float* a, float* b, int) {
+        plain.process (state.get(), true, start, n, a, b, &live, &meters, nullptr);
+    });
+    ra190gq::AheadRig rig (song, 0, {});
+    rig.exchange.publish (RackState::build (song, nullptr, 44100.0, factories));
+    ra190gq::Callback cb1 (song, 64, 0.0);
+    cb1.run (blocks, l1, r1, [&] (double start, int n, double tps, float* a, float* b, int) {
+        std::this_thread::sleep_for (std::chrono::microseconds (100));
+        rig.block (cb1, start, n, tps, a, b);
+    });
+    CHECK (ra190gq::same (l0, l1) && ra190gq::same (r0, r1));
+    CHECK (rig.ahead.stats().engagements.load() >= 1);
+    CHECK (ra190gq::energy (l0.data() + 44100, 44100) > 1.0);
+}

+ 2 - 1
tests/WarpModes190fmTests.inc

@@ -276,7 +276,8 @@ TEST (warp190fm_als_round_trip)
         CHECK (w.textureFlux == 60.0f && w.proFormants == 30.0f && w.proEnvelope == 64.0f);
         CHECK (w.complexPro == (mode[0] == '6'));
         CHECK (ch->sampler.stretchMethod == (mode[0] == '6' ? StretchMethod::complex : StretchMethod::beats));
-        CHECK ((report.partialEffects.count ("Warp mode Complex Pro (plays as Complex; Formants and Envelope kept for export)") > 0) == (mode[0] == '6'));
+        // (round 190ik: Complex Pro's Formants / Envelope play, nothing is reported as left out)
+        CHECK (report.partialEffects.count ("Warp mode Complex Pro (plays as Complex; Formants and Envelope kept for export)") == 0);
         const auto out = exportAls (*song);
         for (const auto* member : { "<GranularityTones Value=\"12\"", "<GranularityTexture Value=\"80\"", "<FluctuationTexture Value=\"60\"",
                                     "<TransientResolution Value=\"3\"", "<TransientLoopMode Value=\"1\"", "<TransientEnvelope Value=\"40\"",

+ 1 - 0
tests/tests.cpp

@@ -17803,3 +17803,4 @@ TEST (fl_low_lifter_matches_fl_engine)
 #include "U190heLinkTests.inc" // round 190he (issue #152 item 2: linkable LYNX instruments, knobs that follow links)
 #include "PluginDrop190hfTests.inc" // issue #152 point 6: plugins dropped on the tracks (FL and Live layouts)
 #include "Rollup028Tests.inc" // round 190fv: semantic interactions of the 0.1.28 rollup
+#include "Warp190ikTests.inc" // round 190ik: Complex Pro, granular Texture, the pitch-aware Beats detector