Skip to content

Commit d5ed8c2

Browse files
author
Martin Klang
committed
added PhaseShiftOscillator template
1 parent 883d32d commit d5ed8c2

2 files changed

Lines changed: 31 additions & 1 deletion

File tree

HISTORY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
* Added PhaseShiftOscillator template
12
* Added Biquad allpass filter configuration
23
* Fixed Antialiased oscillators (Triangle, SquareWave, Ramp)
34
* Added MorphingOscillator

LibSource/Oscillator.h

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff 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 */

0 commit comments

Comments
 (0)