Hey all,
I’m new to Juce and C++. I’m having some difficulty with this code.
I don’t understand why this sounds extremely noisy. any help would be greatly appreciated.
void SinWavetableAudioProcessor::prepareToPlay (double sampleRate, int samplesPerBlock)
{
frequency = 440;
phase = 0;
wtSize = 1024;
increment = frequency * wtSize / sampleRate;
amplitude = 0.25;
// One cycle of a sine wave
for (int i = 0; i < wtSize; i++) {
wavetable.insert(i, sin(2.0 * double_Pi * i / wtSize));
}
}
void SinWavetableAudioProcessor::processBlock (AudioBuffer& buffer, MidiBuffer& midiMessages)
{
ScopedNoDenormals noDenormals;
auto totalNumInputChannels = getTotalNumInputChannels();
auto totalNumOutputChannels = getTotalNumOutputChannels();
channels.
for (auto i = totalNumInputChannels; i < totalNumOutputChannels; ++i)
buffer.clear (i, 0, buffer.getNumSamples());
for (int channel = 0; channel < totalNumInputChannels; ++channel)
{
auto* samples = buffer.getWritePointer (channel);
for (auto i = 0; i < buffer.getNumSamples(); i++) {
samples[i] = wavetable[int(phase)] * amplitude;
phase = fmod(phase + increment,wtSize);
}
}
}