Strange Fragments in Sine Synth

dsp_module

#1

Hey there!
I just started programming with Juce and tried to create a simple sine synth as a AU. But i keep getting these strange fragments. Link to a Audio Example First i thought it might be some kind of imprecisely casting or something but i cant find a solution.
Here is the algorithm in the processBlock:

auto* channelData = buffer.getWritePointer (0);
auto* channelData2 = buffer.getWritePointer (1);
for(int i = 0; i < buffer.getNumSamples(); i++) {
    auto currentSample = (float) std::sin(phase);
    phase += (synthPitch / getSampleRate()) * 2.0f * float_Pi;
    channelData[i] = (float) currentSample * synthVol;
    channelData2[i] = (float) currentSample * synthVol;
}

#2

Take a look at the waveform of your audio-file. The phase is reseted every 1024 samples, which I guess was your buffersize. The phase of a synth is part of its internal state, which has to be persistent over all processBlock calls. Simply create a member variable called phase and you should be fine :slight_smile:


#3

Thank you for the quick answer! It worked like a charm.