Is this implementation of a feedforward comb filter (FFCF) correct?

148 Views Asked by At

I'm trying to implement a feedforward comb filter (for use in a reverb) as described here: https://ccrma.stanford.edu/~jos/pasp/Feedforward_Comb_Filters.html

This is my code:

int delay = 1051;
int arraySize = delay + 1;
int n = 0;
double gain = 0.7;
double buffer = new double[arraySize];

double doDelay(double x) {
    buffer[n] = x;
    double y = buffer[(n + delay) % arraySize];
    y += x * gain;
    n--;
    if (n < 0) n += arraySize;
    return y;
}

// per-sample processing function (called for every sample)
void processSample(double& sample) {
    sample = doDelay(sample);
}

Aside from it not being the most elegant code, is the application of a feedforward comb filter correct? I suspect I might be missing something.

Thank you.

0

There are 0 best solutions below