Add JP-8000 like "supersaw" waveform

This commit is contained in:
Armin 2026-08-12 20:13:57 +02:00
commit fd1625a4b5
4 changed files with 140 additions and 5 deletions

View file

@ -19,6 +19,7 @@ enum class Waveform {
Sinc,
ExpPulse,
DoubleSine,
SuperSaw,
NumWaveforms
};
@ -28,6 +29,8 @@ public:
this->sampleRate = sampleRate;
phase = 0.0;
phaseIncrement = 0.0;
for (int i = 0; i < numSuperSaws; ++i)
superSawPhase[i] = i * (1.0f / static_cast<float>(numSuperSaws));
}
void setFrequency(float freq) {
@ -106,6 +109,20 @@ public:
output = 0.5f * std::sin(phase * 2.0f * pi)
+ 0.5f * std::sin(phase * 4.0f * pi);
break;
case Waveform::SuperSaw: {
static constexpr int numSaws = 7;
static constexpr float detunes[numSaws] = {
-12.0f, -8.0f, -4.0f, 0.0f, 4.0f, 8.0f, 12.0f
};
output = 0.0f;
for (int i = 0; i < numSaws; ++i) {
superSawPhase[i] += phaseIncrement * std::pow(2.0f, detunes[i] / 1200.0f);
if (superSawPhase[i] >= 1.0f) superSawPhase[i] -= 1.0f;
output += 2.0f * (superSawPhase[i] - 0.5f);
}
output /= static_cast<float>(numSaws);
break;
}
default:
output = 0.0f;
break;
@ -126,10 +143,12 @@ public:
float getCurrentPhase() const { return phase; }
private:
static constexpr int numSuperSaws = 7;
static constexpr float pi = 3.14159265358979323846f;
float frequency = 440.0f;
float phase = 0.0f;
float phaseIncrement = 0.0f;
float superSawPhase[numSuperSaws] = { 0.0f };
float level = 0.7f;
float pan = 0.0f;
float semitoneOffset = 0.0f;