mirror of
https://codeberg.org/armin/chromaflock.git
synced 2026-09-01 04:10:47 +02:00
Add 11 additional oscillator waveforms
This commit is contained in:
parent
c5a624f559
commit
0e9a90a89b
2 changed files with 67 additions and 3 deletions
|
|
@ -2,7 +2,25 @@
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <algorithm>
|
#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 {
|
class Oscillator {
|
||||||
public:
|
public:
|
||||||
|
|
@ -46,6 +64,48 @@ public:
|
||||||
case Waveform::Noise:
|
case Waveform::Noise:
|
||||||
output = random.nextFloat() * 2.0f - 1.0f;
|
output = random.nextFloat() * 2.0f - 1.0f;
|
||||||
break;
|
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:
|
default:
|
||||||
output = 0.0f;
|
output = 0.0f;
|
||||||
break;
|
break;
|
||||||
|
|
|
||||||
|
|
@ -431,14 +431,18 @@ MainContentComponent::MainContentComponent(ChromaFlockProcessor& p)
|
||||||
};
|
};
|
||||||
|
|
||||||
setupLabel(osc1Label, "OSC 1");
|
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(osc1OctKnob, osc1OctAttach, "osc1Oct", "OCT");
|
||||||
setupParam(osc1SemiKnob, osc1SemiAttach, "osc1Semi", "SEMI");
|
setupParam(osc1SemiKnob, osc1SemiAttach, "osc1Semi", "SEMI");
|
||||||
setupParam(osc1FineKnob, osc1FineAttach, "osc1Fine", "FINE");
|
setupParam(osc1FineKnob, osc1FineAttach, "osc1Fine", "FINE");
|
||||||
setupParam(osc1LevelKnob, osc1LevelAttach, "osc1Level", "LEVEL");
|
setupParam(osc1LevelKnob, osc1LevelAttach, "osc1Level", "LEVEL");
|
||||||
|
|
||||||
setupLabel(osc2Label, "OSC 2");
|
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(osc2OctKnob, osc2OctAttach, "osc2Oct", "OCT");
|
||||||
setupParam(osc2SemiKnob, osc2SemiAttach, "osc2Semi", "SEMI");
|
setupParam(osc2SemiKnob, osc2SemiAttach, "osc2Semi", "SEMI");
|
||||||
setupParam(osc2FineKnob, osc2FineAttach, "osc2Fine", "FINE");
|
setupParam(osc2FineKnob, osc2FineAttach, "osc2Fine", "FINE");
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue