feat(modulation): add envelopes, LFOs and modulation matrix

This commit is contained in:
2026-09-08 14:55:21 +02:00
parent fc9d16b302
commit 44960b9acb
6 changed files with 458 additions and 0 deletions
+63
View File
@@ -0,0 +1,63 @@
#pragma once
#include <JuceHeader.h>
#include "Params.h"
namespace serum
{
// ===========================================================================
// Free-running LFO with tempo sync, seven shapes (sine/tri/saw/square/S&H/
// step-sequencer/freehand), adjustable phase, fade-in and start delay.
// ===========================================================================
class LFO
{
public:
static constexpr int kShapePoints = 64;
void prepare (double sampleRate) { sr = sampleRate; reset(); }
void reset();
void setParams (float rateNorm, bool sync, float beat, int shape, float phase,
float fade, float delay);
void setTempo (double bpm) noexcept { tempo = bpm; }
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 getValue() const noexcept { return value; }
const std::vector<float>& getShapeData() const noexcept { return shapeBuffer; }
int getShapeSteps() const noexcept { return shapeSteps; }
private:
double sr = 44100.0;
double tempo = 120.0;
double phase = 0.0;
double rateHz = 1.0;
float value = 0.0f;
int shape = 0;
bool sync = false;
float beat = 0.25f;
double delaySeconds = 0.0;
double fadeSeconds = 0.0;
double delayCounter = 0.0; // samples remaining before start
double fadeCounter = 0.0; // samples elapsed in fade
float fadeVal = 1.0f;
float prevDelayParam = -1.0f;
float prevFadeParam = -1.0f;
std::vector<float> shapeBuffer;
int shapeSteps = 16;
juce::Random rng;
float holdValue = 0.0f;
double prevPhase = 0.0;
float shapeValue() noexcept;
};
} // namespace serum