refactor(lfo): advance by sample count and separate phase offset

Add advance(numSamples) so the engine can step LFOs per sub-block
instead of calling process() in a sample loop. process() now
delegates to advance(1).

Split phaseOffset from phase so setParams doesn't overwrite the
running phase; getPhase() adds the offset and wraps. Fix sync mode
to divide by beat multiplier instead of multiplying. Move SampleHold
randomization into advance() based on cycle count. Validate shape
data in setShapeData with isfinite and jlimit.
This commit is contained in:
2026-09-09 14:33:13 +02:00
parent e2e66457c2
commit 40dc0d4105
2 changed files with 40 additions and 25 deletions
+4 -2
View File
@@ -15,6 +15,7 @@ class LFO
public:
static constexpr int kShapePoints = 64;
LFO() { reset(); }
void prepare (double sampleRate) { sr = sampleRate; reset(); }
void reset();
@@ -24,7 +25,8 @@ public:
void setShapeData (const std::vector<float>& data, int steps);
float process() noexcept; // advance and return current value
float getPhase() const noexcept { return (float) phase; }
float advance (int numSamples) noexcept;
float getPhase() const noexcept { return (float) (phase + phaseOffset - std::floor (phase + phaseOffset)); }
float getValue() const noexcept { return value; }
const std::vector<float>& getShapeData() const noexcept { return shapeBuffer; }
@@ -35,6 +37,7 @@ private:
double tempo = 120.0;
double phase = 0.0;
double phaseOffset = 0.0;
double rateHz = 1.0;
float value = 0.0f;
@@ -55,7 +58,6 @@ private:
juce::Random rng;
float holdValue = 0.0f;
double prevPhase = 0.0;
float shapeValue() noexcept;
};