Hello all. I have a simple audio plugin that just produces a continuous sine wave at 261.63hz (C4). To achieve this I have the following members:
float currentPhase = 0.0;
float phasePerSample = 0.0;
float toneFunc (float phase){
return std::sin(phase * juce::MathConstants<float>::twoPi) * 0.025f;
}
In the prepareToPlay function I set phasePerSample as:
phasePerSample = 261.63f / (float)sampleRate;
Then in the processBlock function I have:
for(auto i = 0; i < buffer.getNumSamples(); i++){
const float sampleValue = toneFunc(currentPhase);
for(auto chan = 0; chan < buffer.getNumChannels(); chan++){
buffer.setSample(chan, i, sampleValue);
}
currentPhase += phasePerSample;
}
This is basically my version of a HelloWorld project. Every plugin I’ve made so far (which isn’t many but still done a few) I start with this to verify that everything is building and outputting correctly. And for all the others everything has worked exactly as you’d expect.
However today I’ve run into an odd issue where the pitch of the tone randomly shifts. Usually its within about 2 semitones, but has jumped by as much as 5 semitones (Its never perfectly on note, just within those ranges). The length of time that it holds a particular tone varies from half a second to multiple seconds.
I am completely stumped. I’ve poured over both the editor and processor files, and checked my math. I’ve also made sure that i’m using the same AudioPluginHost to test the plugin as I have for the others. The only change that I have made compared to previous projects is that I’m now using CMake + CLion instead of Projucer + XCode. Surely that can’t be causing this though right? Any help would be massively appreciated!
