Strange discontinuity with MPESynthesiser noteReleased()

This is the second forum post i’ve made about some strange behaviour ive envountered with the MPESynthesiser class:

I started testing with a sinewave today and found something very odd.
edit:^ this picture has a highpass filter on it, in reality the click is all 0 samples.
When i trigger a note off, there is a disconinuity in the waveform that results in a very nasty click. To my knowledge, I have not done anything to cause this.
I have not modified MPESynthesiser::noteReleased(), the expected voice triggers the note off, and in my voice’s noteStopped(), I do nothing (i,e. im not reseting the sample position or anything). This is because the sample must finish playing even after the note has been released.

void MyVoice::noteStopped(bool allowTailOff) {

void MyVoice::renderNextBlock(juce::AudioBuffer<float> &outputBuffer, int startSample, int numSamples){
     //update pitch still gets the correct pitch value after the note has stopped
     //i have tried disabling the envelope, no luck
    envelope.update(fadeIn, fadeOut, sample->sampleLength, smoothedPitch.getCurrentValue());
    for (int32_t i = startSample; i < numSamples; i++) {
        //and then update sample position
        sourceSamplePosition += smoothedPitch.getNextValue();
        //sample has finished playing, so now stop
        if(sourceSamplePosition >= endIndex)
            sourceSamplePosition = 0;
            sampleIsPlaying = false;

I have tried removing multiple moving parts of code in order to figure out why this is happening but have come up emty handed.

what am I missing?


I have tested a constant DC offset to see what happens, so in my render next block:

void AmigoSampleVoice::renderNextBlock(juce::AudioBuffer<float> &outputBuffer, int startSample, int numSamples){
    float* outL = outputBuffer.getWritePointer(0, startSample);
    float* outR = outputBuffer.getNumChannels(1, startSample);
    for (int32_t i = startSample; i < numSamples; i++) {

        outL[i] += 0.4f;
        outR[i] += 0.4f;

And this is the output I get. This is the exact moment the noteoff gets triggered, a series of 0 samples. The only thing I can think is that there must be some delay due to the startsample/numsamples interface of render next block.

It looks like the rendering gets interrupted for a short number of samples, anyone know what I can do to debug?


Your code is wrong
outputBuffer.getWritePointer(0, startSample);
already start at startSample
so your
for (int32_t i = startSample; i < numSamples; i++) {
should start at 0

ahh of course, good spot! I’m not sure what I was thinking haha. Was getting tunnel vision looking for this bug.