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

#375: the channel's pitch reaches sounding audio clips and shifted voices at once

FL 2026 /R renders of a PITCH automation step: a sounding Sampler note and a sounding audio clip jump at the step (no glide,
varispeed in Resample). LYNX's audio clips ignored the live pitch until a seek (setChannelPitchNow returned in clip mode).

- Audio clip voices anchor the channel's pitch and follow it (speed, or the shifter's transposition / source speed);
  a clip stretched to the tempo in a stretch mode keeps its pitch (FL's render of that case does not move; Thief renders
  as before).
- A shifted voice whose pitch jumps (>= 50 cents in a block) restarts its shifter where the voice is (restartShift): heard
  in the next block instead of 120-160 ms later; glides and tempo-stretched voices go through the shifter as before.
- A note started before the rack's first pitch call anchors on the next one (it never followed).
- The Sampler page's time-stretching PITCH switches Resample to Auto when the drag ends (FL's StretchTimeWheelRelease),
  so a sounding note follows it while it is dragged.
- src/engine/SamplerPitch190udTest.cpp (offline steps + live engine on a stand-in device), tests/Pitch190udTests.inc.

(cherry picked from commit 91ef8757bde6b7c257af878966c082e4a8149b60)
Ka1-S 2 дней назад
Родитель
Сommit
ceb980b385

+ 1 - 0
CMakeLists.txt

@@ -655,6 +655,7 @@ if(LYNX_BUILD_APP)
         src/engine/ShortExportTest.cpp
         src/engine/ExportParityTest.cpp
         src/engine/InsertRecord190ubTest.cpp
+        src/engine/SamplerPitch190udTest.cpp
         src/engine/DeviceGuard.cpp
         src/engine/RecoveryTest.cpp
         src/engine/SampleZeroTest.cpp

+ 1 - 1
scripts/build-windows-zig.sh

@@ -293,7 +293,7 @@ APP_SOURCES+=(src/core/LiveSession.cpp src/core/LiveCrypto.cpp src/engine/LiveLi
 APP_SOURCES+=(src/core/RemotePlugins.cpp src/engine/LiveRemotePlugins.cpp src/ui/LiveRemoteUi.cpp)
 # round 190c: the device-change and short-export self-tests (issues #134, #138)
 APP_SOURCES+=(src/engine/DeviceChangeTest.cpp src/engine/ShortExportTest.cpp)
-APP_SOURCES+=(src/engine/ExportParityTest.cpp src/engine/InsertRecord190ubTest.cpp src/engine/MidiHotplugTest.cpp src/engine/MidiOutPortTest.cpp src/engine/PadRecordTest.cpp src/engine/ShareMemoryTest.cpp)
+APP_SOURCES+=(src/engine/ExportParityTest.cpp src/engine/InsertRecord190ubTest.cpp src/engine/SamplerPitch190udTest.cpp src/engine/MidiHotplugTest.cpp src/engine/MidiOutPortTest.cpp src/engine/PadRecordTest.cpp src/engine/ShareMemoryTest.cpp)
 # round 190rp: the crash-recovery round trip and the sample-0 start with latency (--selftest "stab190rp", --recoverytest)
 APP_SOURCES+=(src/engine/RecoveryTest.cpp src/engine/SampleZeroTest.cpp src/engine/DeviceGuard.cpp)
 # round 190az: a CLAP plugin deleted on another thread while the message thread is blocked

+ 78 - 12
src/core/Instruments.cpp

@@ -2129,6 +2129,9 @@ struct SamplerVoice
     // the channel's pitch it started with (knob + fine tune + main pitch, cents; NaN = doesn't follow) and how far a
     // live knob or main pitch move has taken it since (round 167a)
     float liveRef = std::numeric_limits<float>::quiet_NaN(), liveApplied = 0.0f;
+    // round 190ud (issue #375): started before the rack first told the instrument the channel's pitch (a note of a
+    // channel built a moment ago): it takes the next value as the one it started with, instead of never following
+    bool liveAnchor = false;
     const SampleData* data = nullptr; // this voice's sample (the chosen zone, in multi-sample)
     float zoneGain = 1.0f;
     double loopStart = 0.0, loopEnd = 0.0; // loopEnd > loopStart: the voice jumps back to the loop start
@@ -2635,7 +2638,14 @@ public:
         voicePan (asClip ? 0.0f : nextPan, target->panL, target->panR);
         target->basePan = asClip ? 0.0f : nextPan;
         target->cents = asClip ? 0.0f : nextCents;
-        target->liveRef = asClip ? std::numeric_limits<float>::quiet_NaN() : pitch.load() * 100.0f + liveRest;
+        // (round 190ud, issue #375: an audio clip follows the channel's PITCH too; FL 2026's render of a clip under a PITCH
+        // automation step moves at the step, with its speed: docs/analise/REA_rodada190ud.md)
+        // A clip on a channel stretched to the tempo in a stretch mode (TIME set, keep pitch) does not follow: FL's render of the same
+        // step on such a clip did not move (REA_rodada190ud.md §1; its Sampler notes did not either, which LYNX's do since
+        // round 167a: unchanged here)
+        const auto follows = ! (asClip && keyShift.load (std::memory_order_relaxed) && warpedTempo.load (std::memory_order_relaxed));
+        target->liveRef = follows ? pitch.load() * 100.0f + liveRest : std::numeric_limits<float>::quiet_NaN();
+        target->liveAnchor = follows && std::isnan (liveRest);
         if (shaper != nullptr)
             shaper->voiceStarted ((int) (target - voices.data()));
 
@@ -2681,6 +2691,7 @@ public:
         double owed = 0.0; // input frames owed to the shifter (n / factor per block, the fraction carried)
         double tempoAt = 1.0; // issue #187: the tempo ratio the shifter's alignment is set for (its priming assumes 1)
         int pos = 0, count = 0;
+        bool reprime = false; // round 190ud: the channel's pitch moved: start the shifter again where the voice is (render)
     };
     // Stretch keeping pitch (round 162, issue #9): a transposed note reads the stretched sample at its own speed, so it
     // lasts as long as at the root key, and its pitch shifter transposes it (FL's Stretch modes: "pitch changes keep
@@ -2764,6 +2775,24 @@ public:
         ks.tempoAt = 1.0;
     }
 
+    // Round 190ud (issue #375): a shifted voice whose transposition (or, for a clip's own shift, its speed) the channel's
+    // pitch moved. The shifter only hears the change in the source it reads next, which comes out after its latency (100 ms
+    // analysis blocks: the step was heard 120-160 ms late, FL moves a sounding note at the step), so it starts again from
+    // where the voice is, primed with the new value, as a note starting there would. One priming (~1 ms), from the render's
+    // budget (a voice past it keeps its old shift for one more block).
+    void restartShift (const SamplerVoice& v, KeyShift& ks) noexcept
+    {
+        const auto kernel = ks.ahead.kernel; // (a wide clip shift's own interpolation, startKeyShift)
+        ks.ahead = v;
+        ks.ahead.kernel = kernel;
+        ks.ahead.pitchMul = 1.0;
+        ks.primed = false;
+        ks.pos = ks.count = 0;
+        ks.owed = 0.0;
+        ks.tempoAt = 1.0;
+        ks.reprime = false;
+    }
+
     // the transposition the shifter applies now: the note's (gliding), the pitch envelope / LFO and the pitch wheel
     double shiftFactor (const SamplerVoice& v, const KeyShift& ks) const noexcept
     {
@@ -2942,23 +2971,52 @@ public:
 
     // FL's channel PITCH knob is its pitch bend (Misc › pitch bend range): a sounding note follows it, and the main
     // pitch (round 167a, REA_rodada167a §1). A stretched voice that keeps its length moves its transposition instead.
+    // Round 190ud (issue #375, FL 2026 renders of a PITCH automation step, REA_rodada190ud.md): audio clips follow it too
+    // (FL's clip, like its Sampler note, jumps at the step and plays faster / slower: varispeed); no glide in FL either.
+    // Audio thread (the rack calls it before each render); voices only, no lock.
     void setChannelPitchNow (float knob, float rest) noexcept override
     {
         liveRest = rest;
         const auto now = knob + rest;
-        if (clipMode || ! std::isfinite (now))
+        if (! std::isfinite (now))
             return;
+        const auto shiftsTransposition = keyShift.load (std::memory_order_relaxed);
         for (auto& v : voices)
-            if (v.active && ! std::isnan (v.liveRef))
-                if (const auto want = now - v.liveRef; want != v.liveApplied)
+        {
+            if (! v.active)
+                continue;
+            if (v.liveAnchor) // (started before the first call: what it plays now is where it started)
+            {
+                v.liveAnchor = false;
+                v.liveRef = now;
+                v.liveApplied = 0.0f;
+                continue;
+            }
+            if (std::isnan (v.liveRef))
+                continue;
+            if (const auto want = now - v.liveRef; want != v.liveApplied)
+            {
+                const auto ratio = std::exp2 ((double) (want - v.liveApplied) / 1200.0);
+                const auto before = v.liveApplied;
+                v.liveApplied = want;
+                auto& ks = shifts[(std::size_t) (&v - voices.data())];
+                if (ks.on && shiftsTransposition) // (keep length: the shifter transposes)
+                    ks.factor *= ratio;
+                else
                 {
-                    const auto ratio = std::exp2 ((double) (want - v.liveApplied) / 1200.0);
-                    v.liveApplied = want;
-                    if (auto& ks = shifts[(std::size_t) (&v - voices.data())]; ks.on)
-                        ks.factor *= ratio;
-                    else
-                        v.rate *= ratio;
+                    v.rate *= ratio;
+                    if (ks.on) // (an audio clip's own shift, its speed the channel's: the shifter's source reads at it too)
+                        ks.ahead.rate *= ratio;
                 }
+                // a jump (a step, a click on the knob: 50 cents or more in one block) is heard at once (restartShift in
+                // render); a glide (a knob drag, an automation ramp: small moves every block) goes through the shifter
+                // as it always did, smoothly, a shifter's latency late — restarting it every block would chop the sound
+                // and cost a priming per block. A voice stretched to the tempo (TIME set) keeps that too: FL's render
+                // moved such a voice not at all (REA_rodada190ud.md §1), and FL's Thief automates one (808 Snare)
+                if (ks.on && std::abs ((double) (want - before)) >= 50.0 && ! warpedTempo.load (std::memory_order_relaxed))
+                    ks.reprime = true;
+            }
+        }
     }
 
     // a VFX changes a sounding note (round 164b): its fine pitch, pan or volume
@@ -3456,8 +3514,13 @@ public:
             auto primeBudget = offlineRendering() ? keyShiftVoices : 2;
             for (auto& v : voices)
                 if (v.active && v.data != nullptr && v.flVoice)
-                    if (auto& ks = shifts[(std::size_t) (&v - voices.data())]; ! ks.on || primeKeyShift (v, ks, primeBudget))
+                {
+                    auto& ks = shifts[(std::size_t) (&v - voices.data())];
+                    if (ks.on && ks.reprime && (! ks.primed || primeBudget > 0)) // (round 190ud: the channel's pitch moved)
+                        restartShift (v, ks);
+                    if (! ks.on || primeKeyShift (v, ks, primeBudget))
                         renderFl (v, left, right, n, chanVol, chanPan);
+                }
         }
 
         // the project's triangular panning law (round 167k: FL's render of FPC pads and the decompiled audio clip mixer
@@ -3500,7 +3563,10 @@ public:
         {
             if (! v.active || v.data == nullptr || v.flVoice)
                 continue;
-            if (auto& ks = shifts[(std::size_t) (&v - voices.data())]; ks.on && ! primeKeyShift (v, ks, primeBudget))
+            auto& voiceShift = shifts[(std::size_t) (&v - voices.data())];
+            if (voiceShift.on && voiceShift.reprime && (! voiceShift.primed || primeBudget > 0)) // (round 190ud: the channel's pitch moved)
+                restartShift (v, voiceShift);
+            if (voiceShift.on && ! primeKeyShift (v, voiceShift, primeBudget))
                 continue; // (its shifter primes in the next block)
 
             const auto* l = v.data->leftData();

+ 16 - 6
src/core/SamplerPage.h

@@ -117,13 +117,13 @@ inline void selectMode (SamplerSettings& s, int index) noexcept
 // as the .flp import adds it, so a turn moves both by the same step. FL (StretchTimeWheelRelease 0xf67130 for the PITCH
 // wheel): in Resample mode a PITCH away from 0 switches the mode to Auto (FL mode 5) — LYNX's General engine, FL's Auto
 // on the way back to a .flp.
-inline void turnStretchPitch (SamplerSettings& s, int cents) noexcept
+// Round 190ud (issue #375): FL switches the mode when the wheel is let go (StretchTimeWheelRelease); while the knob is dragged
+// (`released` false) the channel stays in Resample, so a sounding note follows the pitch at once like the header's PITCH
+// knob (the mode switch builds the channel's instrument again, which ends its sounding notes). A wheel notch, a typed
+// value or a reset switches at once, as before.
+inline void releaseStretchPitch (SamplerSettings& s) noexcept
 {
-    cents = std::clamp (cents, -1200, 1200);
-    const auto before = s.pitch;
-    s.pitch = std::clamp (s.pitch + (float) (cents - s.flStretchPitch) / 100.0f, -24.0f, 24.0f);
-    s.flStretchPitch += (int) std::lround ((s.pitch - before) * 100.0f); // (what the ±24 st clamp let through)
-    if (! s.keepPitch && cents != 0)
+    if (! s.keepPitch && s.flStretchPitch != 0)
     {
         s.keepPitch = true;
         s.stretchMethod = StretchMethod::general;
@@ -131,6 +131,16 @@ inline void turnStretchPitch (SamplerSettings& s, int cents) noexcept
     }
 }
 
+inline void turnStretchPitch (SamplerSettings& s, int cents, bool released = true) noexcept
+{
+    cents = std::clamp (cents, -1200, 1200);
+    const auto before = s.pitch;
+    s.pitch = std::clamp (s.pitch + (float) (cents - s.flStretchPitch) / 100.0f, -24.0f, 24.0f);
+    s.flStretchPitch += (int) std::lround ((s.pitch - before) * 100.0f); // (what the ±24 st clamp let through)
+    if (released && cents != 0)
+        releaseStretchPitch (s);
+}
+
 // ---- Precomputed effects: SMP START and LENGTH ----
 
 // LENGTH (FL's SmpEndWheel, 0…16384, default 16384): the played part of what follows SMP START (REA round 167h §2)

+ 4 - 0
src/engine/AudioEngine.h

@@ -1431,6 +1431,10 @@ public:
     // Round 190ub (issue #371): armed inserts record the audio routed into them with no input device, each take equal to its
     // insert's export and placed to the sample (src/engine/InsertRecord190ubTest.cpp; --round190ubtest, --selftest "round190ub")
     static juce::String insertRecord190ubSelfTest (const std::function<void (const juce::String&)>& log = {});
+    // Round 190ud (issue #375): the channel's PITCH reaches what already sounds — Sampler notes, audio clips, keep-length
+    // notes on their shifter — offline (an automation step) and live (the knobs, on a stand-in device)
+    // (src/engine/SamplerPitch190udTest.cpp; --round190udtest, --selftest "round190ud")
+    static juce::String samplerPitch190udSelfTest (const std::function<void (const juce::String&)>& log = {});
     // Round 190jb: exports with the live engine's plugin instances (engine/Exporter.h LiveExportHold), on a stand-in device:
     // LYNX's own units render the same with and without the hold; a hosted plugin whose sound depends on its instance
     // (`plugins`: VST3 / CLAP files, e.g. the LYNX Test Synth with LYNX_TEST_SYNTH_SEED=1, Surge XT) exports what

+ 409 - 0
src/engine/SamplerPitch190udTest.cpp

@@ -0,0 +1,409 @@
+// Round 190ud (issue #375, HalanoSiblee: "changing the sampler's pitch while it plays is only heard after a seek"): FL 2026
+// moves a sounding Sampler note AND a sounding audio clip at once when the channel's PITCH changes (FL /R renders of a
+// PITCH automation step: the step lands inside the 10 ms window it falls in, no glide; the clip, like the note, plays
+// faster / slower: varispeed). LYNX's audio clips ignored the live pitch (SamplerInstrument::setChannelPitchNow returned
+// at once in clip mode), and a note that started before the rack first handed the instrument the channel's pitch never
+// followed it. docs/analise/REA_rodada190ud.md.
+//
+// The check renders through the real paths:
+//  1. offline (ExportJob, the export path) a PITCH automation step 0 -> +2 st at 1 s and +2 -> -5 st at 2 s on a held
+//     440 Hz sine: a Sampler note (resampled), an audio clip, a "keep length" Sampler note at G5 (its pitch shifter moves
+//     the transposition and its length stays: it ends where the same note without the steps ends) and an audio clip
+//     with a pitch of its own (+3 st, its own shifter; the channel's pitch is its speed, so it ends sooner). The new
+//     pitch must be there in the window that starts one block (512 samples) after each step.
+//  2. live: the engine on a stand-in device (callbacks of 512 samples from its own thread), Play, then the channel
+//     header's PITCH knob edit (AudioEngine::editSong, as the knob does) while a Sampler note / an audio clip sounds:
+//     the new pitch must be heard within two device blocks of the edit, and the sound must go on.
+
+#include "engine/AudioEngine.h"
+
+#include "core/SamplerPage.h"
+#include "engine/Exporter.h"
+
+namespace lynx
+{
+namespace
+{
+constexpr double rate190ud = 48000.0;
+constexpr int block190ud = 512;
+
+// the stand-in device: plays the engine from its own thread and keeps what the engine wrote (left channel)
+struct PitchDevice final : juce::AudioIODevice, private juce::Thread
+{
+    PitchDevice() : juce::AudioIODevice ("Pitch test device", "Sampler pitch test"), juce::Thread ("pitch test device") {}
+    ~PitchDevice() override { close(); }
+
+    static inline std::vector<float>* capture = nullptr; // (sized by the test before Play; the device thread fills it)
+    static inline std::atomic<int> captured { 0 };       // frames written into it while the transport plays
+    static inline std::atomic<bool> recording { false };
+
+    juce::StringArray getOutputChannelNames() override { return { "Out 1", "Out 2" }; }
+    juce::StringArray getInputChannelNames() override { return {}; }
+    juce::Array<double> getAvailableSampleRates() override { return { rate190ud }; }
+    juce::Array<int> getAvailableBufferSizes() override { return { block190ud }; }
+    int getDefaultBufferSize() override { return block190ud; }
+    juce::String open (const juce::BigInteger&, const juce::BigInteger& outs, double, int) override
+    {
+        close();
+        outsNow = outs;
+        outsNow.setRange (2, juce::jmax (0, outsNow.getHighestBit() - 1), false);
+        data.setSize (2, block190ud);
+        opened = true;
+        startThread();
+        return {};
+    }
+    void close() override
+    {
+        stop();
+        stopThread (10000);
+        opened = false;
+    }
+    bool isOpen() override { return opened; }
+    void start (juce::AudioIODeviceCallback* cb) override
+    {
+        if (! opened || cb == nullptr)
+            return;
+        cb->audioDeviceAboutToStart (this);
+        const juce::ScopedLock sl (callbackLock);
+        callback = cb;
+    }
+    void stop() override
+    {
+        juce::AudioIODeviceCallback* old = nullptr;
+        {
+            const juce::ScopedLock sl (callbackLock);
+            old = std::exchange (callback, nullptr);
+        }
+        if (old != nullptr)
+            old->audioDeviceStopped();
+    }
+    bool isPlaying() override { return callback != nullptr; }
+    juce::String getLastError() override { return {}; }
+    int getCurrentBufferSizeSamples() override { return block190ud; }
+    double getCurrentSampleRate() override { return rate190ud; }
+    int getCurrentBitDepth() override { return 32; }
+    juce::BigInteger getActiveOutputChannels() const override { return outsNow; }
+    juce::BigInteger getActiveInputChannels() const override { return {}; }
+    int getOutputLatencyInSamples() override { return block190ud; }
+    int getInputLatencyInSamples() override { return 0; }
+
+private:
+    void run() override
+    {
+        while (! threadShouldExit())
+        {
+            {
+                const juce::ScopedLock sl (callbackLock);
+                if (callback != nullptr)
+                {
+                    callback->audioDeviceIOCallbackWithContext (nullptr, 0, data.getArrayOfWritePointers(), data.getNumChannels(), block190ud, {});
+                    if (recording.load() && capture != nullptr)
+                    {
+                        const auto at = captured.load();
+                        const auto n = juce::jmin (block190ud, (int) capture->size() - at);
+                        if (n > 0)
+                        {
+                            std::copy (data.getReadPointer (0), data.getReadPointer (0) + n, capture->begin() + at);
+                            captured.store (at + n);
+                        }
+                    }
+                }
+            }
+            juce::Thread::sleep (2);
+        }
+    }
+
+    juce::BigInteger outsNow;
+    juce::AudioBuffer<float> data;
+    juce::CriticalSection callbackLock;
+    juce::AudioIODeviceCallback* callback = nullptr;
+    bool opened = false;
+};
+
+struct PitchType final : juce::AudioIODeviceType
+{
+    PitchType() : juce::AudioIODeviceType ("Sampler pitch test") {}
+    void scanForDevices() override {}
+    juce::StringArray getDeviceNames (bool input) const override { return input ? juce::StringArray() : juce::StringArray ("Pitch test device"); }
+    int getDefaultDeviceIndex (bool input) const override { return input ? -1 : 0; }
+    int getIndexOfDevice (juce::AudioIODevice* d, bool input) const override { return d != nullptr && ! input ? 0 : -1; }
+    bool hasSeparateInputsAndOutputs() const override { return false; }
+    juce::AudioIODevice* createDevice (const juce::String& out, const juce::String&) override
+    {
+        return out == "Pitch test device" ? new PitchDevice() : nullptr;
+    }
+};
+
+bool writeSine (const juce::File& file, double seconds)
+{
+    juce::AudioBuffer<float> b (1, (int) (seconds * rate190ud));
+    for (int i = 0; i < b.getNumSamples(); ++i)
+        b.setSample (0, i, (float) (0.5 * std::sin (2.0 * juce::MathConstants<double>::pi * 440.0 * i / rate190ud)));
+    file.deleteFile();
+    juce::WavAudioFormat wav;
+    std::unique_ptr<juce::AudioFormatWriter> w (wav.createWriterFor (file.createOutputStream().release(), rate190ud, 1, 32, {}, 0));
+    return w != nullptr && w->writeFromAudioSampleBuffer (b, 0, b.getNumSamples());
+}
+
+std::vector<float> readLeft (const juce::File& file)
+{
+    juce::WavAudioFormat wav;
+    std::unique_ptr<juce::AudioFormatReader> reader (wav.createReaderFor (file.createInputStream().release(), true));
+    if (reader == nullptr)
+        return {};
+    juce::AudioBuffer<float> b ((int) reader->numChannels, (int) reader->lengthInSamples);
+    reader->read (&b, 0, b.getNumSamples(), 0, true, true);
+    return { b.getReadPointer (0), b.getReadPointer (0) + b.getNumSamples() };
+}
+
+// the pitch of a (near) pure tone in [from, from + n), cents from 440 Hz, by interpolated upward zero crossings; NaN when
+// the window has too few
+double centsAt (const std::vector<float>& x, int from, int n)
+{
+    std::vector<double> t;
+    for (int i = juce::jmax (0, from); i + 1 < juce::jmin ((int) x.size(), from + n); ++i)
+        if (x[(std::size_t) i] <= 0.0f && x[(std::size_t) i + 1] > 0.0f)
+            t.push_back (i + (double) x[(std::size_t) i] / ((double) x[(std::size_t) i] - (double) x[(std::size_t) i + 1]));
+    if (t.size() < 4)
+        return std::numeric_limits<double>::quiet_NaN();
+    const auto hz = (double) (t.size() - 1) * rate190ud / (t.back() - t.front());
+    return 1200.0 * std::log2 (hz / 440.0);
+}
+
+// where the tone ends: its last upward zero crossing (an audio clip holds its last value after its file, so the level
+// alone does not end)
+int soundEnd (const std::vector<float>& x)
+{
+    for (int i = (int) x.size() - 2; i >= 0; --i)
+        if (x[(std::size_t) i] <= 0.0f && x[(std::size_t) i + 1] > 0.0f && std::abs (x[(std::size_t) i + 1] - x[(std::size_t) i]) > 0.001f)
+            return i;
+    return -1;
+}
+
+float stepValue (double semitones) { return (float) (0.5 + semitones / 96.0); } // (channelPitchSemitones' range: ±48)
+} // namespace
+
+juce::String AudioEngine::samplerPitch190udSelfTest (const std::function<void (const juce::String&)>& log)
+{
+    auto say = [&log] (const juce::String& line) {
+        if (log)
+            log (line);
+    };
+    const auto folder = juce::File::getSpecialLocation (juce::File::tempDirectory)
+                            .getChildFile ("lynx-pitch190ud-" + juce::String::toHexString (juce::Random::getSystemRandom().nextInt64()));
+    folder.createDirectory();
+    struct Cleanup
+    {
+        juce::File f;
+        ~Cleanup()
+        {
+            f.deleteRecursively();
+            PitchDevice::capture = nullptr;
+            PitchDevice::recording = false;
+        }
+    } cleanup { folder };
+    const auto sine = folder.getChildFile ("sine440.wav"), shortSine = folder.getChildFile ("sine440-3s.wav");
+    if (! writeSine (sine, 8.0) || ! writeSine (shortSine, 3.0))
+        return "ERROR can't write the test samples in " + folder.getFullPathName();
+
+    juce::StringArray errors;
+    int checks = 0;
+    auto check = [&] (const juce::String& what, bool ok, const juce::String& detail = {}) {
+        ++checks;
+        say ((ok ? "ok   " : "FAIL ") + what + (detail.isNotEmpty() ? " (" + detail + ")" : juce::String()));
+        if (! ok)
+            errors.add (what + (detail.isNotEmpty() ? " (" + detail + ")" : juce::String()));
+    };
+    auto cents = [] (double c) { return std::isnan (c) ? juce::String ("none") : juce::String (c, 1) + " cents"; };
+    auto near = [] (double c, double want, double tolerance) { return ! std::isnan (c) && std::abs (c - want) <= tolerance; };
+
+    // a song: one channel (a Sampler note held 3 bars, or an audio clip of 3 bars) at 120 BPM; `steps`: the PITCH
+    // automation step 0 -> +2 at 1 s and +2 -> -5 at 2 s
+    struct Case
+    {
+        const char* name;
+        bool clip = false, keep = false, steps = true, shortSample = false;
+        int key = 60;
+        float clipPitch = 0.0f;
+    };
+    auto makeSong = [&] (const Case& k) {
+        Song s;
+        s.bpm = 120.0;
+        s.mixer = Song::defaultMixer (2);
+        s.mixer[0].effects.clear();
+        const auto bar = s.barTicks();
+        ChannelDef c;
+        c.instrument = k.clip ? InstrumentKind::audioClip : InstrumentKind::sampler;
+        c.samplePath = (k.shortSample ? shortSine : sine).getFullPathName().toStdString();
+        c.name = k.name;
+        c.mixerTrack = 0;
+        c.sampler.keepPitch = k.keep;
+        s.channels.push_back (c);
+        auto& p = s.patterns.emplace_back();
+        p.lengthTicks = 4 * bar;
+        if (! k.clip)
+        {
+            p.notes.push_back ({ 0, 3 * bar, 0, k.key, 0.8f });
+            Clip pc;
+            pc.kind = ClipKind::pattern;
+            pc.pattern = 0;
+            pc.length = 4 * bar;
+            s.playlist.push_back (pc);
+        }
+        else
+        {
+            Clip ac;
+            ac.kind = ClipKind::audio;
+            ac.channel = 0;
+            ac.length = 3 * bar;
+            ac.pitch = k.clipPitch;
+            s.playlist.push_back (ac);
+        }
+        if (k.steps)
+        {
+            Automation a;
+            a.name = "Pitch";
+            a.target = { AutomationTargetKind::channelParam, 0, 0, channelPitchParam };
+            const auto t1 = bar / 2, t2 = bar; // 1 s, 2 s
+            a.points = { { 0, stepValue (0), 0.0f }, { t1, stepValue (0), 0.0f }, { t1 + 1, stepValue (2), 0.0f }, { t2, stepValue (2), 0.0f },
+                         { t2 + 1, stepValue (-5), 0.0f }, { 4 * bar, stepValue (-5), 0.0f } };
+            s.automations.push_back (a);
+            Clip ac;
+            ac.kind = ClipKind::automation;
+            ac.automation = 0;
+            ac.track = 2;
+            ac.length = 4 * bar;
+            s.playlist.push_back (ac);
+        }
+        s.mode = PlayMode::song;
+        return s;
+    };
+    exportopts::Options options;
+    options.format = exportopts::Format::wav;
+    options.wavBits = 32;
+    options.sampleRate = rate190ud;
+    options.tail = exportopts::TailMode::leave;
+    options.pluginWarmUp = false;
+    auto render = [&] (const Case& k) {
+        const auto file = folder.getChildFile (juce::String (k.name) + (k.steps ? "" : "-plain") + ".wav");
+        ExportJob job (makeSong (k), options, file);
+        job.setExactFrames ((std::int64_t) (7.0 * rate190ud));
+        juce::String error;
+        if (! job.run ({}, error))
+        {
+            errors.add (juce::String (k.name) + ": " + error);
+            return std::vector<float>();
+        }
+        return readLeft (file);
+    };
+
+    // --- 1. offline: the automation step is heard one block after it --------------------------------------------------
+    const int s1 = (int) rate190ud, s2 = (int) (2.0 * rate190ud), w = 2048;
+    for (const auto& k : { Case { "Sampler note" }, Case { "audio clip", true }, Case { "keep length note at G5", false, true, true, true, 67 },
+                           Case { "audio clip with its own +3 st", true, false, true, true, 60, 3.0f } })
+    {
+        const auto out = render (k);
+        const auto base = (k.clip ? (double) k.clipPitch : (double) (k.key - 60)) * 100.0;
+        const auto before = centsAt (out, s1 - block190ud - w, w), after1 = centsAt (out, s1 + block190ud, w),
+                   after2 = centsAt (out, s2 + block190ud, w);
+        // (a voice on a pitch shifter: its restarted shifter settles within a few cents in its first blocks, then exact)
+        const auto shifted = k.keep || k.clipPitch != 0.0f;
+        const auto first = shifted ? 5.0 : 2.0;
+        const auto settled1 = centsAt (out, s1 + 10 * block190ud, 4096), settled2 = centsAt (out, s2 + 10 * block190ud, 4096);
+        check (juce::String ("offline, ") + k.name + ": before the step", near (before, base, 2.0), cents (before));
+        check (juce::String ("offline, ") + k.name + ": +2 st one block after the step", near (after1, base + 200.0, first), cents (after1));
+        check (juce::String ("offline, ") + k.name + ": -5 st one block after the second step", near (after2, base - 500.0, first), cents (after2));
+        check (juce::String ("offline, ") + k.name + ": exact 10 blocks after each step", near (settled1, base + 200.0, 1.0) && near (settled2, base - 500.0, 1.0),
+               cents (settled1) + ", " + cents (settled2));
+        if (k.shortSample) // the length: kept by the shifter of a keep-length note; a clip's speed follows the channel's pitch
+        {
+            const auto plain = render ({ k.name, k.clip, k.keep, false, true, k.key, k.clipPitch });
+            const auto endSteps = soundEnd (out), endPlain = soundEnd (plain);
+            const auto moved = (endSteps - endPlain) / rate190ud;
+            if (k.keep)
+                check (juce::String ("offline, ") + k.name + ": its length stays (the shifter moves the transposition)", std::abs (moved) < 0.01,
+                       juce::String (moved, 4) + " s");
+            else
+            {
+                // the clip read 1 s at x1, 1 s at 2^(2/12), the rest at 2^(-5/12): 3 s of file end at 1 + 1 + (3 - 1 - 1.1225) / 0.7492 s
+                const auto expect = 2.0 + (3.0 - 1.0 - std::exp2 (2.0 / 12.0)) / std::exp2 (-5.0 / 12.0) - 3.0;
+                check (juce::String ("offline, ") + k.name + ": its speed follows the channel's pitch (it ends where the file runs out)",
+                       std::abs (moved - expect) < 0.01, juce::String (moved, 4) + " s, expected " + juce::String (expect, 4));
+            }
+        }
+    }
+
+    // --- 2. live: the header's PITCH knob while a note / a clip sounds --------------------------------------------------
+    auto live = [&] (const Case& k, const std::function<void (Song&)>& edit, const juce::String& what) {
+        AudioEngine engine (false);
+        engine.player.setProcessor (&engine.graph);
+        engine.deviceManager.addAudioDeviceType (std::make_unique<PitchType>());
+        if (const auto e = engine.deviceManager.initialise (0, 2, nullptr, true); e.isNotEmpty())
+        {
+            errors.add ("open the stand-in device: " + e);
+            return;
+        }
+        engine.deviceManager.addAudioCallback (&engine);
+        engine.setSong (makeSong (k));
+        for (int i = 0; i < 20; ++i) // (the rack is built and published by the engine's timer)
+        {
+            engine.timerCallback();
+            juce::Thread::sleep (10);
+        }
+        std::vector<float> out ((std::size_t) (2.0 * rate190ud), 0.0f);
+        PitchDevice::capture = &out;
+        PitchDevice::captured = 0;
+        engine.stop();
+        engine.rewind();
+        engine.timerCallback();
+        PitchDevice::recording = true;
+        engine.startPlayback();
+        auto waitFor = [&] (int frames) {
+            const auto since = juce::Time::getMillisecondCounter();
+            while (PitchDevice::captured.load() < frames && juce::Time::getMillisecondCounter() - since < 30000)
+            {
+                engine.timerCallback();
+                juce::Thread::sleep (1);
+            }
+        };
+        waitFor ((int) (0.6 * rate190ud));
+        const auto editAt = PitchDevice::captured.load();
+        engine.editSong (edit); // (as the header knob: ChannelHeaderControls' FrameKnob)
+        waitFor ((int) out.size());
+        PitchDevice::recording = false;
+        engine.stop();
+        for (int i = 0; i < 10; ++i)
+        {
+            engine.timerCallback();
+            juce::Thread::sleep (5);
+        }
+        engine.deviceManager.removeAudioCallback (&engine);
+        engine.deviceManager.closeAudioDevice();
+        PitchDevice::capture = nullptr;
+
+        const auto before = centsAt (out, editAt - 4096, 4096);
+        // the first block after the edit whose pitch is the new one
+        int heardAfter = -1;
+        for (int b = 0; b < 40 && heardAfter < 0; ++b)
+            if (near (centsAt (out, editAt + b * block190ud, 1024), 200.0, 3.0))
+                heardAfter = b;
+        const auto settled = centsAt (out, editAt + 8 * block190ud, 4096);
+        const auto tail = centsAt (out, (int) out.size() - 4096, 4096);
+        check ("live, " + what + ": before the edit", near (before, 0.0, 2.0), cents (before));
+        check ("live, " + what + ": the new pitch is heard within two device blocks of the edit", heardAfter >= 0 && heardAfter <= 2,
+               heardAfter < 0 ? juce::String ("never") : "block " + juce::String (heardAfter) + " after the edit");
+        check ("live, " + what + ": it stays there and the sound goes on", near (settled, 200.0, 2.0) && near (tail, 200.0, 2.0),
+               cents (settled) + ", at the end " + cents (tail));
+    };
+    auto knob = [] (Song& s) { s.channels[0].sampler.pitch = 2.0f; }; // (the PITCH knob: ChannelSettings headerKnob "Pitch")
+    live ({ "live note", false, false, false }, knob, "Sampler note, the channel's PITCH knob");
+    live ({ "live clip", true, false, false }, knob, "audio clip, the channel's PITCH knob");
+    // the Sampler page's time-stretching PITCH knob while it is dragged (samplerpage::turnStretchPitch, ChannelSettings'
+    // stretchPitchKnob; FL switches Resample to Auto when the drag ends)
+    live ({ "live note stretch knob", false, false, false }, [] (Song& s) { samplerpage::turnStretchPitch (s.channels[0].sampler, 200, false); },
+          "Sampler note, the Sampler page's PITCH knob (dragged)");
+
+    say ("checks: " + juce::String (checks) + ", failed: " + juce::String (errors.size()));
+    return errors.isEmpty() ? "OK " + juce::String (checks) + " checks" : "FAIL: " + errors.joinIntoString ("; ");
+}
+} // namespace lynx

+ 7 - 2
src/ui/ChannelSettings.cpp

@@ -3566,6 +3566,7 @@ public:
         // ---- Time stretching (form StretchPanel) ----
         knob (stretchPitchKnob, stretchPitchLabel, TR_NOOP ("Pitch"), TR_NOOP ("Pitch shift"), -1200.0, 1200.0, 1.0, 0.0);
         stretchPitchKnob.textFromValueFunction = [] (double v) { return tr ("{0} cents", { (v > 0.5 ? "+" : "") + juce::String (juce::roundToInt (v)) }); };
+        stretchPitchKnob.onDragEnd = [this] { apply (&stretchPitchRelease); }; // (round 190ud: FL's StretchTimeWheelRelease)
         knob (mulKnob, mulLabel, TR_NOOP ("Mul"), TR_NOOP ("Time stretch (multiplicator)"), -20000.0, 20000.0, 1.0, 0.0);
         // (live check 190ew SMP-5: FL's hint reads "105.70%")
         mulKnob.textFromValueFunction = [] (double v) { return juce::String (samplerpage::mulText ((int) v)); };
@@ -4161,7 +4162,7 @@ private:
         const auto* c = current();
         const juce::File now (c != nullptr ? juce::String::fromUTF8 (c->samplePath.c_str()) : juce::String());
         sampleChooser = lynx::ui::makeFileChooser (tr ("Load sample file..."), now.existsAsFile() ? now : juce::File(),
-                                                   "*.wav;*.aif;*.aiff;*.flac;*.ogg;*.mp3");
+                                                   "*.wav;*.aif;*.aiff;*.flac;*.ogg;*.mp3;*.m4a;*.aac");
         lynx::ui::launchChooser (sampleChooser, juce::FileBrowserComponent::openMode | juce::FileBrowserComponent::canSelectFiles,
                                  [safe = juce::Component::SafePointer<SettingsPanel> (this)] (const juce::FileChooser& fc) {
                                      if (safe != nullptr && fc.getResult() != juce::File())
@@ -4594,7 +4595,10 @@ private:
                 cutOn = cutChanged = true;
         }
         else if (changed == &pingPong) p.pingPong = on (changed);
-        else if (changed == &stretchPitchKnob) samplerpage::turnStretchPitch (s, juce::roundToInt (value (changed)));
+        else if (changed == &stretchPitchKnob) // (round 190ud: FL switches Resample to Auto when the drag ends)
+            samplerpage::turnStretchPitch (s, juce::roundToInt (value (changed)), ! stretchPitchKnob.isMouseButtonDown());
+        else if (changed == &stretchPitchRelease)
+            samplerpage::releaseStretchPitch (s);
         else if (changed == &mulKnob)
         {
             const auto sample = sampleOf (*c);
@@ -4775,6 +4779,7 @@ private:
     std::int64_t shownFrames = 0;
     // Time stretching
     MenuSlider stretchPitchKnob, mulKnob, stretch;
+    juce::Component stretchPitchRelease; // (round 190ud: apply()'s tag for the end of a drag of stretchPitchKnob; never shown)
     juce::Label stretchPitchLabel, mulLabel, stretchLabel, modeLabel;
     juce::ComboBox stretchMethod;
     // Precomputed effects (and FL's legacy panel)

+ 140 - 0
tests/Pitch190udTests.inc

@@ -0,0 +1,140 @@
+// Round 190ud (issue #375, HalanoSiblee): the channel's PITCH reaches what already sounds (FL 2026 /R renders of a PITCH
+// step: a Sampler note and an audio clip jump at the step, no glide; docs/analise/REA_rodada190ud.md). The rack is
+// rendered block by block and the knob moved between two blocks, as an edit does.
+
+namespace pitch190ud
+{
+using namespace lynx;
+
+// cents from 440 Hz in [from, from + n) by interpolated upward zero crossings (9999: too few)
+inline double centsAt (const std::vector<float>& x, int from, int n)
+{
+    std::vector<double> t;
+    for (int i = std::max (0, from); i + 1 < std::min ((int) x.size(), from + n); ++i)
+        if (x[(std::size_t) i] <= 0.0f && x[(std::size_t) i + 1] > 0.0f)
+            t.push_back (i + (double) x[(std::size_t) i] / ((double) x[(std::size_t) i] - (double) x[(std::size_t) i + 1]));
+    if (t.size() < 4)
+        return 9999.0;
+    return 1200.0 * std::log2 ((double) (t.size() - 1) * 48000.0 / (t.back() - t.front()) / 440.0);
+}
+
+// 2 s of a channel playing a 4 s 440 Hz sine (a Sampler note at `key`, or an audio clip, with `clipPitch` of its own),
+// its PITCH knob moved by `knob` semitones between the blocks around 1 s
+inline std::vector<float> render (bool clip, bool keep, int key, float clipPitch, float knob)
+{
+    auto data = std::make_shared<SampleData>();
+    const int total = 48000 * 4;
+    data->sampleRate = 48000.0;
+    data->left.resize ((std::size_t) total);
+    data->right.resize ((std::size_t) total);
+    for (int i = 0; i < total; ++i)
+        data->left[(std::size_t) i] = data->right[(std::size_t) i] = 0.5f * (float) std::sin (2.0 * 3.141592653589793 * 440.0 * i / 48000.0);
+    Song song;
+    song.bpm = 120.0;
+    song.mixer = Song::defaultMixer (1);
+    ChannelDef ch;
+    ch.instrument = clip ? InstrumentKind::audioClip : InstrumentKind::sampler;
+    ch.samplePath = "/pitch190ud/sine.wav";
+    ch.mixerTrack = 1;
+    ch.sampler.keepPitch = keep;
+    song.channels.push_back (ch);
+    if (clip)
+    {
+        Clip c;
+        c.kind = ClipKind::audio;
+        c.channel = 0;
+        c.length = 8 * ppq;
+        c.pitch = clipPitch;
+        song.playlist.push_back (c);
+    }
+    else
+    {
+        auto& p = song.patterns.emplace_back();
+        p.lengthTicks = 16 * ppq;
+        p.notes.push_back ({ 0, 8 * ppq, 0, key, 0.8f });
+        Clip c;
+        c.kind = ClipKind::pattern;
+        c.pattern = 0;
+        c.length = 16 * ppq;
+        song.playlist.push_back (c);
+    }
+    song.mode = PlayMode::song;
+    const auto provide = [&] (const std::string&) { return std::shared_ptr<const SampleData> (data); };
+    std::shared_ptr<const RackState> state = RackState::build (song, nullptr, 48000.0, provide);
+    RackRenderer renderer;
+    renderer.prepare (48000.0, 512);
+    const auto tps = ticksPerSample (song.bpm, 48000.0);
+    std::vector<float> out, l (512), r (512);
+    for (int pos = 0; pos < 96000; pos += 512)
+    {
+        if (pos == 48128 && knob != 0.0f) // (block 94 starts at 48128 samples: the move lands just after 1 s)
+        {
+            song.channels[0].sampler.pitch += knob;
+            state = RackState::build (song, state.get(), 48000.0, provide);
+        }
+        renderer.process (state.get(), true, pos * tps, 512, l.data(), r.data());
+        out.insert (out.end(), l.begin(), l.end());
+    }
+    return out;
+}
+} // namespace pitch190ud
+
+// an audio clip follows the channel's PITCH while it plays (LYNX ignored it until a seek); a Sampler note did already
+TEST (pitch190ud_a_playing_audio_clip_follows_the_channel_pitch)
+{
+    using namespace pitch190ud;
+    const auto clip = render (true, false, 60, 0.0f, 2.0f);
+    CHECK (std::abs (centsAt (clip, 40000, 4096)) < 1.0);
+    CHECK (std::abs (centsAt (clip, 48128 + 512, 4096) - 200.0) < 1.0); // (one block after the move)
+    const auto note = render (false, false, 60, 0.0f, 2.0f);
+    CHECK (std::abs (centsAt (note, 48128 + 512, 4096) - 200.0) < 1.0);
+    // nothing moves: exactly what it played before
+    const auto a = render (true, false, 60, 0.0f, 0.0f), b = render (true, false, 60, 0.0f, 0.0f);
+    CHECK (a == b);
+    CHECK (std::abs (centsAt (a, 48128 + 512, 4096)) < 1.0);
+}
+
+// a voice on its pitch shifter (keep length) hears the move at once: its shifter starts again where the voice is (before,
+// the move came out after the shifter's ~100 ms latency); an audio clip with a pitch of its own (its own shifter) too
+TEST (pitch190ud_a_shifted_voice_hears_the_move_within_a_block)
+{
+    using namespace pitch190ud;
+    // (the restarted shifter settles within a few cents in its first blocks: ±5 cents one block after the move, exact
+    // ±1 cent 10 blocks after; before, the old pitch played on for 120-160 ms)
+    const auto keep = render (false, true, 67, 0.0f, 2.0f);
+    CHECK (std::abs (centsAt (keep, 40000, 4096) - 700.0) < 2.0);
+    const auto keepAfter = centsAt (keep, 48128 + 512, 2048), keepLater = centsAt (keep, 48128 + 10 * 512, 4096);
+    if (std::abs (keepAfter - 900.0) >= 5.0 || std::abs (keepLater - 900.0) >= 1.0)
+        std::printf ("  keep length: %.1f cents one block after the move, %.1f ten blocks after\n", keepAfter, keepLater);
+    CHECK (std::abs (keepAfter - 900.0) < 5.0);
+    CHECK (std::abs (keepLater - 900.0) < 1.0);
+    const auto own = render (true, false, 60, 3.0f, 2.0f);
+    CHECK (std::abs (centsAt (own, 40000, 4096) - 300.0) < 2.0);
+    const auto ownAfter = centsAt (own, 48128 + 512, 2048), ownLater = centsAt (own, 48128 + 10 * 512, 4096);
+    if (std::abs (ownAfter - 500.0) >= 5.0 || std::abs (ownLater - 500.0) >= 1.0)
+        std::printf ("  clip with its own pitch: %.1f cents one block after the move, %.1f ten blocks after\n", ownAfter, ownLater);
+    CHECK (std::abs (ownAfter - 500.0) < 5.0);
+    CHECK (std::abs (ownLater - 500.0) < 1.0);
+}
+
+// the Sampler page's time-stretching PITCH: while dragged it stays in Resample (a sounding note follows it), the end of the
+// drag switches Resample to keep length (FL's StretchTimeWheelRelease); a notch / typed value switches at once (as before)
+TEST (pitch190ud_the_stretch_pitch_switches_the_mode_when_the_drag_ends)
+{
+    using namespace lynx;
+    SamplerSettings s;
+    samplerpage::turnStretchPitch (s, 300, false);
+    CHECK (! s.keepPitch && s.flStretchPitch == 300 && std::abs (s.pitch - 3.0f) < 1.0e-5f);
+    samplerpage::turnStretchPitch (s, 500, false);
+    CHECK (! s.keepPitch && s.flStretchPitch == 500 && std::abs (s.pitch - 5.0f) < 1.0e-5f);
+    samplerpage::releaseStretchPitch (s);
+    CHECK (s.keepPitch && s.stretchMethod == StretchMethod::general && s.flStretchMode == 5);
+    SamplerSettings back;
+    samplerpage::turnStretchPitch (back, 200, false);
+    samplerpage::turnStretchPitch (back, 0, false);
+    samplerpage::releaseStretchPitch (back); // (back at 0: the mode stays)
+    CHECK (! back.keepPitch);
+    SamplerSettings notch;
+    samplerpage::turnStretchPitch (notch, 100); // (a notch: at once)
+    CHECK (notch.keepPitch);
+}

+ 1 - 0
tests/tests.cpp

@@ -18258,6 +18258,7 @@ TEST (fl_low_lifter_matches_fl_engine)
 #include "Sleep190tsTests.inc" // round 190ts (0.1.33 block E): sleep while stopped (Patcher graphs, built-in effects)
 #include "MixFx190toTests.inc" // round 190to (0.1.33, QUEUE item 96): FL's per-insert effects switch; the Master's arm tap
 #include "InsRec190ubTests.inc" // round 190ub (0.1.33, issue #371): armed inserts record their routed audio without an input device
+#include "Pitch190udTests.inc" // round 190ud (0.1.33, issue #375): the channel's PITCH reaches sounding audio clips and shifted voices
 #include "Tempo190tvTests.inc" // round 190tv (0.1.33, QUEUE item 99 / issue #364): FL's tempo digits, the number wheel, History rows
 #include "UxTracks190tpTests.inc" // round 190tp (issues #365 / #366): the header drag that moves a track, Ctrl+V of copied files
 #include "SlotCopy190uaTests.inc" // round 190ua (issue #370): an effect dragged from a mixer slot onto another insert is copied