Hello I’m new here and I just coded my first sinewave generator and I came across this weird situation.
for (auto sample = 0; sample < bufferToFill.numSamples; ++sample) {
double x = MathConstants<double>::twoPi*frequency.getValue() / currentSampleRate;
//CODE v1:
buffer[sample] = std::sin(currentIteration*x)*(volume.getValue() / 100);
currentIteration += 1;
//CODE v2:
buffer[sample] = std::sin(currentAngle)*(volume.getValue() / 100);
currentAngle += x;
}
The above is in my getNextAudioBlock() function. v1 and v2 both do the same thing, except v1 multiplies by x in the buffer[sample] statement while v2 multiplies by x in the currentAngle variable.
For some reason although they do the same thing, v1 generates a buzz everytime the frequency slider is moved while v2 doesn’t. Could anyone explain to me why that happens? And/or those lines of code are not actually equivalent?