51 for(
size_t i=0; i<output.
getSize(); ++i)
54 [[deprecated(
"use generate() instead.")]]
56 [[deprecated(
"use generate() instead.")]]
58 [[deprecated(
"use generate() instead.")]]
62 [[deprecated(
"use generate() instead.")]]
68 template<
class T,
class BaseOscillator=Oscillator,
typename Sample=
float>
77 mul = (T::end_phase - T::begin_phase)/sr;
81 return (T::end_phase - T::begin_phase)/
mul;
90 phase = (T::end_phase - T::begin_phase)*ph/(2*
M_PI) + T::begin_phase;
94 return (
phase - T::begin_phase)*2*
M_PI/(T::end_phase - T::begin_phase);
97 phase = T::begin_phase;
100 Sample sample =
static_cast<T*
>(
this)->getSample();
102 if(
phase >= T::end_phase)
103 phase -= (T::end_phase - T::begin_phase);
107 Sample sample =
static_cast<T*
>(
this)->getSample();
109 phase +=
incr + (T::end_phase - T::begin_phase)*fm;
110 if(
phase >= T::end_phase)
111 phase -= (T::end_phase - T::begin_phase);
114 using BaseOscillator::generate;
117 obj->setSampleRate(sr);
136 return t+t - t*t - 1;
137 }
else if(t + dt > 1){
139 return t*t + t+t + 1;
150 template <
typename... Args>
165 template <
typename... Args>
This class contains useful methods for manipulating arrays of floats.
void setFrequency(float freq)
Set oscillator frequency in Hertz.
static float polyblep(float t, float dt)
Calculate poly blep antialiasing compensation on normalised (to range [0, 1]) phase and phase increme...
Sample generate(float fm)
Produce a sample with frequency modulation.
void setPhase(float ph)
Set current oscillator phase in radians.
float getFrequency()
Get oscillator frequency in Hertz.
void reset()
Reset oscillator (typically resets phase)
static T * create(float sr)
void setSampleRate(float sr)
Set oscillator sample rate.
float getPhase()
Get current oscillator phase in radians.
static void destroy(T *osc)
Sample generate()
Produce the next consecutive sample.
An Oscillator is a SignalGenerator that operates at a given frequency and that can be frequency modul...
virtual void reset()=0
Reset oscillator (typically resets phase)
void getSamples(FloatArray output, FloatArray fm)
virtual float getFrequency()=0
Get oscillator frequency in Hertz.
virtual void generate(FloatArray output, FloatArray fm)
Produce a block of samples with frequency modulation.
virtual float generate(float fm)=0
Produce a sample with frequency modulation.
virtual void setPhase(float phase)=0
Set current oscillator phase in radians.
float getNextSample(float fm)
void getSamples(FloatArray output)
virtual void setFrequency(float value)=0
Set oscillator frequency in Hertz.
virtual float generate()
Produce the next consecutive sample.
virtual void setSampleRate(float value)
Set oscillator sample rate.
virtual float getPhase()=0
Get current oscillator phase in radians.
void setPhase(float phase)
PhaseShiftOscillator(float phaseshift, Args &&... args)
static PhaseShiftOscillator< Osc > * create(float phaseshift, Args &&... args)
static void destroy(PhaseShiftOscillator< Osc > *obj)
Base class for signal generators such as Oscillators.
virtual float generate()
Produce the next consecutive sample.