Add 11 additional oscillator waveforms

This commit is contained in:
Armin 2026-07-15 23:46:38 +02:00
commit 0e9a90a89b
2 changed files with 67 additions and 3 deletions

View file

@ -2,7 +2,25 @@
#include <cmath>
#include <algorithm>
enum class Waveform { Sine = 0, Saw, Square, Triangle, Noise, NumWaveforms };
enum class Waveform {
Sine = 0,
Saw,
Square,
Triangle,
Noise,
Pulse25,
Pulse12,
ReverseSaw,
FullRectSine,
HalfRectSine,
Stair4,
Stair8,
SoftSine,
Sinc,
ExpPulse,
DoubleSine,
NumWaveforms
};
class Oscillator {
public:
@ -46,6 +64,48 @@ public:
case Waveform::Noise:
output = random.nextFloat() * 2.0f - 1.0f;
break;
case Waveform::Pulse25:
output = (phase < 0.25f) ? 1.0f : -1.0f;
break;
case Waveform::Pulse12:
output = (phase < 0.12f) ? 1.0f : -1.0f;
break;
case Waveform::ReverseSaw:
output = 2.0f * phase - 1.0f;
break;
case Waveform::FullRectSine:
output = std::fabs(std::sin(phase * 2.0f * pi));
break;
case Waveform::HalfRectSine:
output = std::max(0.0f, std::sin(phase * 2.0f * pi));
break;
case Waveform::Stair4: {
float s = std::floor(phase * 4.0f);
output = -1.0f + 2.0f * ((s + 0.5f) / 4.0f);
break;
}
case Waveform::Stair8: {
float s = std::floor(phase * 8.0f);
output = -1.0f + 2.0f * ((s + 0.5f) / 8.0f);
break;
}
case Waveform::SoftSine:
output = std::tanh(3.0f * std::sin(phase * 2.0f * pi)) / std::tanh(3.0f);
break;
case Waveform::Sinc: {
float x = phase * 2.0f * pi * 6.0f;
output = (x != 0.0f) ? std::sin(x) / x : 1.0f;
break;
}
case Waveform::ExpPulse:
output = (phase < 0.5f)
? std::exp(-phase * 10.0f)
: -std::exp(-(phase - 0.5f) * 10.0f);
break;
case Waveform::DoubleSine:
output = 0.5f * std::sin(phase * 2.0f * pi)
+ 0.5f * std::sin(phase * 4.0f * pi);
break;
default:
output = 0.0f;
break;

View file

@ -431,14 +431,18 @@ MainContentComponent::MainContentComponent(ChromaFlockProcessor& p)
};
setupLabel(osc1Label, "OSC 1");
setupCB(osc1WaveBox, osc1WaveAttach, "osc1Wave", {"Sine", "Saw", "Square", "Triangle", "Noise"});
setupCB(osc1WaveBox, osc1WaveAttach, "osc1Wave", {"Sine", "Saw", "Square", "Triangle", "Noise",
"Pulse 25%", "Pulse 12%", "Rev Saw", "Full Rect", "Half Rect",
"Stair 4", "Stair 8", "Soft Sine", "Sinc", "Exp Pulse", "Double Sine"});
setupParam(osc1OctKnob, osc1OctAttach, "osc1Oct", "OCT");
setupParam(osc1SemiKnob, osc1SemiAttach, "osc1Semi", "SEMI");
setupParam(osc1FineKnob, osc1FineAttach, "osc1Fine", "FINE");
setupParam(osc1LevelKnob, osc1LevelAttach, "osc1Level", "LEVEL");
setupLabel(osc2Label, "OSC 2");
setupCB(osc2WaveBox, osc2WaveAttach, "osc2Wave", {"Sine", "Saw", "Square", "Triangle", "Noise"});
setupCB(osc2WaveBox, osc2WaveAttach, "osc2Wave", {"Sine", "Saw", "Square", "Triangle", "Noise",
"Pulse 25%", "Pulse 12%", "Rev Saw", "Full Rect", "Half Rect",
"Stair 4", "Stair 8", "Soft Sine", "Sinc", "Exp Pulse", "Double Sine"});
setupParam(osc2OctKnob, osc2OctAttach, "osc2Oct", "OCT");
setupParam(osc2SemiKnob, osc2SemiAttach, "osc2Semi", "SEMI");
setupParam(osc2FineKnob, osc2FineAttach, "osc2Fine", "FINE");