Hi all, first post!
Anyways, I began working with JUCE recently (and have come back to C++ after a good few years). Following on from the sine synth tutorial, I decided to make the wave in stereo and try out some processing on the audi output. The problem with the code below is that the output is distorted and not a clean sine wave. I believe the problem is to do with the same wave not being written to both the left and write channel and so the waves are not smooth sines, however I cannot think of a fix.
Sorry for the n00b question, any suggestions?
for (int channel = 0; channel < bufferToFill.buffer->getNumChannels(); ++channel)
{
// Get a pointer to the start sample in the buffer for this audio output channel
float* const buffer = bufferToFill.buffer->getWritePointer (channel, bufferToFill.startSample);
// Fill the required number of samples with values generated from the sine formula
for (int sample = 0; sample < bufferToFill.numSamples; ++sample)
{
const float currentSample = (float) std::sin (currentAngle);
currentAngle += changeOfAngle;
buffer[sample] = currentSample * 0.125;
}
}
void updateChangeOfAngle()
{
//double frequencyValue = MidiMessage::getMidiNoteInHertz(frequencySlider.getValue());
const double cyclesPerSample = MidiMessage::getMidiNoteInHertz(69 + frequencySlider.getValue()) / currentSampleRate;
changeOfAngle = 2 * double_Pi * cyclesPerSample;
}