Hello I’m a newbie here and I can’t seem to even create a proper sinewave generator.
Could someone please point out what’s wrong with my code? It sort of works but always produces a horrible buzzing sound. The sliders and variables are all setup properly. So I’m thinking it has something to do with my getNextAudioBlock function:
void MainComponent::getNextAudioBlock (const AudioSourceChannelInfo& bufferToFill)
{
bufferToFill.clearActiveBufferRegion();
for (int channel = 0; channel < bufferToFill.buffer->getNumChannels(); ++channel){
auto* buffer = bufferToFill.buffer->getWritePointer(channel,bufferToFill.startSample);
for (auto sample = 0; sample < bufferToFill.numSamples; ++sample) {
buffer[sample] = std::sin( sample * MathConstants<double>::twoPi * frequencySlider.getValue() / currentSampleRate ) * ( volumeSlider.getValue() / 100 );
}
}
}