Skip to content

Commit d0c8f9f

Browse files
author
Martin Klang
committed
fix pwm on block boundary polyblep correction
1 parent ac17121 commit d0c8f9f

1 file changed

Lines changed: 13 additions & 4 deletions

File tree

LibSource/SquareWaveOscillator.h

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,19 @@ class AntialiasedSquareWaveOscillator : public OscillatorTemplate<AntialiasedSqu
6060
return sample;
6161
}
6262
void generate(FloatArray output){
63-
float sample = phase < pw ? 1 : -1;
64-
if(phase < incr){
65-
float t = phase / incr;
66-
sample += t+t - t*t - 1;
63+
float sample;
64+
if(phase < pw){
65+
sample = 1;
66+
if(phase < incr){
67+
float t = phase / incr;
68+
sample += t+t - t*t - 1;
69+
}
70+
}else{
71+
sample = -1;
72+
if(phase-pw < incr){
73+
float t = fmod(phase + 1 - pw, 1) / incr;
74+
sample -= t+t - t*t - 1;
75+
}
6776
}
6877
size_t len = output.getSize();
6978
float* dest = output.getData();

0 commit comments

Comments
 (0)