File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ * Added PhaseShiftOscillator template
12* Added Biquad allpass filter configuration
23* Fixed Antialiased oscillators (Triangle, SquareWave, Ramp)
34* Added MorphingOscillator
Original file line number Diff line number Diff line change @@ -134,12 +134,41 @@ class OscillatorTemplate : public BaseOscillator {
134134 if (t < dt){
135135 t /= dt;
136136 return t+t - t*t - 1 ;
137- }else if (t > 1 - dt ){
137+ }else if (t + dt > 1 ){
138138 t = (t - 1 ) / dt;
139139 return t*t + t+t + 1 ;
140140 }
141141 return 0 ;
142142 }
143143};
144144
145+ template <class Osc >
146+ class PhaseShiftOscillator : public Osc {
147+ protected:
148+ float phaseshift;
149+ public:
150+ template <typename ... Args>
151+ PhaseShiftOscillator (float phaseshift, Args&&... args) :
152+ Osc (std::forward<Args>(args)...), phaseshift(phaseshift) {}
153+ void setPhase (float phase){
154+ Osc::setPhase (phase + phaseshift);
155+ }
156+ float getPhase (){
157+ return Osc::getPhase () - phaseshift;
158+ }
159+ void reset (){
160+ Osc::setPhase (phaseshift);
161+ }
162+ /* *
163+ * @param phaseshift oscillator phase shift in radians
164+ */
165+ template <typename ... Args>
166+ static PhaseShiftOscillator<Osc>* create (float phaseshift, Args&&... args){
167+ return new PhaseShiftOscillator<Osc>(phaseshift, std::forward<Args>(args)...);
168+ }
169+ static void destroy (PhaseShiftOscillator<Osc>* obj){
170+ Osc::destroy (obj);
171+ }
172+ };
173+
145174#endif /* __Oscillator_h */
You can’t perform that action at this time.
0 commit comments