#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