Prototype

This commit is contained in:
Armin 2026-08-05 23:12:17 +02:00
commit 4271fc34bb
14 changed files with 950 additions and 169 deletions

View file

@ -13,8 +13,12 @@ public:
{
Waveform waveA = Waveform::saw;
Waveform waveB = Waveform::square;
float detuneRatio = 1.0f;
float mix = 0.5f;
float osc1Coarse = 0.0f;
float osc2Coarse = 0.0f;
float osc1Fine = 0.0f;
float osc2Fine = 0.0f;
float osc1Phase = 0.0f;
float osc2Phase = 0.0f;
float cutoff = 7000.0f;
float resonance = 0.15f;
float attack = 0.005f;
@ -23,11 +27,22 @@ public:
float release = 0.4f;
float glide = 0.12f;
float master = 0.9f;
float drive = 0.0f;
float ringMod = 0.0f;
float detuneRatio = 1.0f;
float mix = 0.5f;
};
void addPhase (float phaseOffset)
{
phaseA = frac (phaseA + phaseOffset);
phaseB = frac (phaseB + phaseOffset);
}
void prepare (double sr)
{
sampleRate = (float) sr;
accentSmoothCoef = 1.0f - std::exp (-1.0f / (0.003f * sampleRate));
reset();
}
@ -40,12 +55,16 @@ public:
env = 0.0f;
envStage = Stage::idle;
gate = false;
accentLevel = 1.0f;
accentSmooth = 1.0f;
}
void setParams (const Params& p) { params = p; }
bool isActive() const { return gate; }
void setAccentLevel (float level) { accentLevel = level; }
void noteOn (float freqHz, bool legato)
{
targetFreq = freqHz;
@ -153,6 +172,9 @@ private:
updateEnvelope();
updateGlide();
// Smooth the accent gain so it ramps in/out instead of clicking.
accentSmooth += (accentLevel - accentSmooth) * accentSmoothCoef;
const float incA = currentFreq / sampleRate;
const float incB = (currentFreq * params.detuneRatio) / sampleRate;
@ -164,9 +186,24 @@ private:
float out = (1.0f - params.mix) * a + params.mix * b;
if (params.ringMod > 0.0f)
out = (1.0f - params.ringMod) * out + params.ringMod * (a * b);
const float preFilter = out;
out = processFilter (out);
return out * env * params.master;
// Accented steps also get a touch of the unfiltered signal so they cut
// through the mix (presence), not just a volume bump.
if (accentSmooth > 1.0f)
out += (accentSmooth - 1.0f) * 0.2f * preFilter;
if (params.drive > 0.0f)
{
const float wet = std::tanh (out * (1.0f + params.drive * 9.0f));
out = (1.0f - params.drive) * out + params.drive * wet;
}
return out * env * params.master * accentSmooth;
}
float sampleRate = 44100.0f;
@ -184,6 +221,9 @@ private:
float env = 0.0f;
Stage envStage = Stage::idle;
bool gate = false;
float accentLevel = 1.0f;
float accentSmooth = 1.0f;
float accentSmoothCoef = 0.01f;
};
} // namespace monostep