OpenWareLaboratory
VariableShapeOscillator.h
Go to the documentation of this file.
1 #ifndef __VariableShapeOscillator_h
2 #define __VariableShapeOscillator_h
3 
4 #include "Oscillator.h"
5 
9 class VariableShapeOscillator : public OscillatorTemplate<VariableShapeOscillator> {
10 protected:
11  float waveshape = 0;
12  float pw = 0.5f;
13 public:
14  static constexpr float begin_phase = 0;
15  static constexpr float end_phase = 1;
19  void setWaveshape(float value){
20  waveshape = value;
21  }
25  void setPulseWidth(float value){
26  pw = value;
27  }
28  float getSample(){
29  float square = phase < pw ? 0 : 1;
30  float saw = phase;
31  float sample = saw + (square - saw) * waveshape;
32  return sample * 2 - 1;
33  }
34 };
35 
36 #endif /* __VariableShapeOscillator_h */
Oscillator with a waveshape that is variable from saw to square, with adjustable pulse width.
static constexpr float end_phase
void setWaveshape(float value)
Set pulse width to a value between 0 (for saw) and 1 (for square)
void setPulseWidth(float value)
Set pulse width to a value between 0 and 1.
static constexpr float begin_phase