Skip to content

Commit ee7d954

Browse files
committed
Clamping the wavetable position
1 parent 18d5ed4 commit ee7d954

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

Sources/CSoundpipeAudioKit/Generators/MorphingOscillatorDSP.mm

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,19 @@ void reset() override {
6262
sp_oscmorph_init(sp, oscmorph, ft_array, 4, 0);
6363
}
6464

65+
float clamp(float x) {
66+
if (x > 1) { x = 1; }
67+
if (x < 0) { x = 0; }
68+
return x;
69+
}
70+
6571
void process(FrameRange range) override {
6672

6773
for (int i : range) {
6874

6975
oscmorph->freq = frequencyRamp.getAndStep() * detuningMultiplierRamp.getAndStep() + detuningOffsetRamp.getAndStep();
7076
oscmorph->amp = amplitudeRamp.getAndStep();
71-
oscmorph->wtpos = indexRamp.getAndStep() / 3.f;
77+
oscmorph->wtpos = clamp(indexRamp.getAndStep() / 3.f);
7278

7379
sp_oscmorph_compute(sp, oscmorph, nil, &outputSample(0, i));
7480
}

0 commit comments

Comments
 (0)