#include "SubOscillator.h" namespace serum { void SubOscillator::noteOn() { 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 = juce::MathConstants::twoPi * freqHz / sr; phase += inc; phase -= std::floor (phase * (1.0 / juce::MathConstants::twoPi)) * juce::MathConstants::twoPi; float s = 0.0f; if (shape == (int) SubShape::Triangle) { const float p = (float) (phase * (1.0 / juce::MathConstants::twoPi)); s = 1.0f - 4.0f * std::abs (p - 0.5f); } else { s = (float) std::sin (phase); } out += s * level; } } // namespace serum