feat(dsp): add core synthesizer oscillators, wavetable and voice engine

This commit is contained in:
2026-09-08 14:55:21 +02:00
parent 6e2859a1f6
commit fc9d16b302
12 changed files with 1473 additions and 0 deletions
+39
View File
@@ -0,0 +1,39 @@
#include "SubOscillator.h"
namespace serum
{
void SubOscillator::noteOn (double freqHz, int octaveShift)
{
// octaveShift: -2, -1 or 0 (from the subOct param).
const double mult = (octaveShift == -2) ? 0.25 : (octaveShift == -1) ? 0.5 : 1.0;
(void) freqHz;
(void) mult;
phase = 0.0;
}
void SubOscillator::processAdd (double freqHz, int shape, float level, float& out) noexcept
{
if (level <= 0.0f || freqHz <= 0.0)
return;
// The octave shift is baked into freqHz by the voice; here we just phase-accumulate.
const double inc = kTwoPi * freqHz / sr;
phase += inc;
phase -= std::floor (phase * (1.0 / kTwoPi)) * kTwoPi;
float s = 0.0f;
if (shape == (int) SubShape::Triangle)
{
const float p = (float) (phase * (1.0 / kTwoPi));
s = 1.0f - 4.0f * std::abs (p - 0.5f);
}
else
{
s = (float) std::sin (phase);
}
out += s * level;
}
} // namespace serum