Here is the algorithm for an audio delay. I want a slight amount of noise to be added to fedback signals.
So I use an if statement to make sure to only add noise if there is a signal, or the plugin would just constantly generate noise. But that's just what it does. It seems to completely ignore the if statement and just indiscriminately add noise.
void samDelay::processReplacing (float **inputs, float **outputs, long sampleFrames)
float *inLeft = inputs [chLeft];
float *inRight = inputs [chRight];
float *outLeft = outputs [chLeft];
float *outRight = outputs [chRight];
float fedBack [nChannels];
while(--sampleFrames >= 0)
fedBack [chLeft] = xFade (bufRetrieve (chRight), bufRetrieve (chLeft), crossover) * feedback;
fedBack [chRight] = xFade (bufRetrieve (chLeft), bufRetrieve (chRight), crossover) * feedback;
if (fedBack [chLeft])
fedBack [chLeft] += noise (0.2f);
if (fedBack [chRight])
fedBack [chRight] += noise (0.2f);
// Output = input + output from delay lines * feedback:
*outLeft = (*inLeft++ + fedBack [chLeft]);
*outRight = (*inRight++ + fedBack [chRight]);
// Feed it back into the delay line:
bufInsert (chLeft, *outLeft++);
bufInsert (chRight, *outRight++);
bufMove (); // Next indices.
The delay lines are initialised to 0 at the start, so there's no possibility of any non-zero values causing noise to be added when not wanted.
What could be the cause?