From 0e9a90a89b07b78fdc5f2119cec8f274dd722810 Mon Sep 17 00:00:00 2001 From: Armin Date: Wed, 15 Jul 2026 23:46:38 +0200 Subject: [PATCH] Add 11 additional oscillator waveforms --- Source/DSP/Oscillator.h | 62 ++++++++++++++++++++++++++++++++++++++++- Source/PluginEditor.cpp | 8 ++++-- 2 files changed, 67 insertions(+), 3 deletions(-) diff --git a/Source/DSP/Oscillator.h b/Source/DSP/Oscillator.h index 64dd9af..7b0a823 100644 --- a/Source/DSP/Oscillator.h +++ b/Source/DSP/Oscillator.h @@ -2,7 +2,25 @@ #include #include -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; diff --git a/Source/PluginEditor.cpp b/Source/PluginEditor.cpp index f5b9766..7323353 100644 --- a/Source/PluginEditor.cpp +++ b/Source/PluginEditor.cpp @@ -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");