#ifndef __VariableShapeOscillator_h
#define __VariableShapeOscillator_h
#include "Oscillator.h"
class VariableShapeOscillator : public OscillatorTemplate<VariableShapeOscillator> {
protected:
float waveshape = 0;
float pw = 0.5f;
public:
static constexpr float begin_phase = 0;
static constexpr float end_phase = 1;
void setWaveshape(float value){
waveshape = value;
}
void setPulseWidth(float value){
pw = value;
}
float getSample(){
float square = phase < pw ? 0 : 1;
float saw = phase;
float sample = saw + (square - saw) * waveshape;
return sample * 2 - 1;
}
};
#endif