MostlyHarmless 0.0.1
 
Loading...
Searching...
No Matches
marvin::dsp::oscillators::OscillatorBase< SampleType > Class Template Referenceabstract

Base class for all single-shape oscillator types. More...

#include <marvin_Oscillator.h>

Inheritance diagram for marvin::dsp::oscillators::OscillatorBase< SampleType >:
marvin::dsp::oscillators::PulseOscillator< SampleType, Bandlimiting::Off > marvin::dsp::oscillators::SawOscillator< SampleType, Bandlimiting::Off > marvin::dsp::oscillators::SquareOscillator< SampleType, Bandlimiting::Off > marvin::dsp::oscillators::TriOscillator< SampleType, Bandlimiting::Off > marvin::dsp::oscillators::NoiseOscillator< SampleType > marvin::dsp::oscillators::PulseOscillator< SampleType, Blep > marvin::dsp::oscillators::SawOscillator< SampleType, Blep > marvin::dsp::oscillators::SineOscillator< SampleType > marvin::dsp::oscillators::SquareOscillator< SampleType, Blep > marvin::dsp::oscillators::TriOscillator< SampleType, Blamp >

Public Member Functions

virtual ~OscillatorBase () noexcept=default
 
virtual void initialise (double sampleRate)
 
virtual SampleType operator() () noexcept=0
 
virtual SampleType operator() (SampleType phase) noexcept=0
 
virtual void reset () noexcept
 
void setFrequency (SampleType newFrequency) noexcept
 
void setPhaseOffset (SampleType newPhaseOffset) noexcept
 

Protected Member Functions

void incrementPhase () noexcept
 

Protected Attributes

double m_sampleRate {}
 
SampleType m_phaseIncrement { static_cast<SampleType>(0.0) }
 
SampleType m_phase { static_cast<SampleType>(0.0) }
 
SampleType m_phaseOffset { static_cast<SampleType>(0.0) }
 

Detailed Description

template<FloatType SampleType>
class marvin::dsp::oscillators::OscillatorBase< SampleType >

Base class for all single-shape oscillator types.

Constructor & Destructor Documentation

◆ ~OscillatorBase()

template<FloatType SampleType>
virtual marvin::dsp::oscillators::OscillatorBase< SampleType >::~OscillatorBase ( )
virtualdefaultnoexcept

Member Function Documentation

◆ incrementPhase()

template<FloatType SampleType>
void marvin::dsp::oscillators::OscillatorBase< SampleType >::incrementPhase ( )
protectednoexcept

Called by subclasses to increment the internal phase according to the frequency set in setFrequency. Unused if using an external value for phase.

◆ initialise()

template<FloatType SampleType>
virtual void marvin::dsp::oscillators::OscillatorBase< SampleType >::initialise ( double sampleRate)
virtual

Initialises the oscillator. Make sure this is called before attempting any audio processing, if relying on internal phase updates!

Parameters
sampleRateThe sample rate the oscillator should run at.

◆ operator()() [1/2]

◆ operator()() [2/2]

template<FloatType SampleType>
virtual SampleType marvin::dsp::oscillators::OscillatorBase< SampleType >::operator() ( SampleType phase)
nodiscardpure virtualnoexcept

Processes the next sample of the wave, using the provided phase - this overload will not update the internal phase of the oscillator, so the caller is entirely responsible for incrementing the phase according to frequency, etc. Does not require you to call initialise beforehand for this reason.

Parameters
phaseThe phase the oscillator should use, between 0 to 1.
Returns
The oscillator's output.

Implemented in marvin::dsp::oscillators::NoiseOscillator< SampleType >, marvin::dsp::oscillators::PulseOscillator< SampleType, Blep >, marvin::dsp::oscillators::PulseOscillator< SampleType, Bandlimiting::Off >, marvin::dsp::oscillators::SawOscillator< SampleType, Blep >, marvin::dsp::oscillators::SawOscillator< SampleType, Bandlimiting::Off >, marvin::dsp::oscillators::SineOscillator< SampleType >, marvin::dsp::oscillators::SquareOscillator< SampleType, Blep >, marvin::dsp::oscillators::SquareOscillator< SampleType, Bandlimiting::Off >, marvin::dsp::oscillators::TriOscillator< SampleType, Blamp >, and marvin::dsp::oscillators::TriOscillator< SampleType, Bandlimiting::Off >.

◆ reset()

template<FloatType SampleType>
virtual void marvin::dsp::oscillators::OscillatorBase< SampleType >::reset ( )
virtualnoexcept

Resets the oscillator to its default state.

◆ setFrequency()

template<FloatType SampleType>
void marvin::dsp::oscillators::OscillatorBase< SampleType >::setFrequency ( SampleType newFrequency)
noexcept

Sets the frequency of the oscillator in Hz. If using the overload of operator() that takes a value for phase, this function will do nothing. The internal phaseIncrement variable this function sets is not atomic, so ensure this is either called on the audio thread, or the audio thread is not running when this function is called.

Parameters
newFrequencyThe frequency to set, in Hz

◆ setPhaseOffset()

template<FloatType SampleType>
void marvin::dsp::oscillators::OscillatorBase< SampleType >::setPhaseOffset ( SampleType newPhaseOffset)
noexcept

Sets a constant value to offset the internal phase by. Useful for using one oscillator as an lfo to control multiple sources. By default, this is set to 0. If using the overload of operator() that takes a value for phase, this function will do nothing.

Parameters
newPhaseOffsetThe phase offset, between 0 and 1.

Member Data Documentation

◆ m_phase

template<FloatType SampleType>
SampleType marvin::dsp::oscillators::OscillatorBase< SampleType >::m_phase { static_cast<SampleType>(0.0) }
protected

◆ m_phaseIncrement

template<FloatType SampleType>
SampleType marvin::dsp::oscillators::OscillatorBase< SampleType >::m_phaseIncrement { static_cast<SampleType>(0.0) }
protected

◆ m_phaseOffset

template<FloatType SampleType>
SampleType marvin::dsp::oscillators::OscillatorBase< SampleType >::m_phaseOffset { static_cast<SampleType>(0.0) }
protected

◆ m_sampleRate

template<FloatType SampleType>
double marvin::dsp::oscillators::OscillatorBase< SampleType >::m_sampleRate {}
protected

The documentation for this class was generated from the following file: