Basic FIR Filtering with audio buffer in C++
Your implementation of the delay line is flawed.  It's just copying the second last sample over each element.

Try this instead:

    for (int i = 7; i &gt;=0; i--) { // delayLine being 9 values long
        delayLine[i + 1] = delayLine[i];
    }




Previous answer below

Your filter seems to be a lossy low pass filter --- even the passband has -15dB attenuation.

Try using these coefficients instead:

0.01156111 0.05773286 0.12773940 0.19304879 0.21983567 0.19304879 0.12773940 0.05773286 0.01156111


They are obtained by normalizing the sum of the coefficients you provided.

Your filter has this response:



The normalized coefficients give this response:





R Code Below

 #30506
filterTaps &lt;- c(0.002385,
0.011910,
0.026352,
0.039825,
0.045351,
0.039825,
0.026352,
0.011910,
0.002385)

filterTaps2 &lt;- filterTaps / sum(filterTaps)

freqz(filterTaps)


freqz(filterTaps2)

getNumSamples &lt;- 1000

reader &lt;- rnorm(getNumSamples,0,1)
writeback &lt;- 0*reader

delayLine &lt;- 0*filterTaps
result &lt;- 0; # initialisation to 0 of the result
for (sample in seq(1,getNumSamples)) 
{ # for each sample

    # moving the samples in the delay line
    for (i in seq(8,1,-1)) 
    { # delayLine being 9 values long
        delayLine[i + 1] = delayLine[i];
    }
    delayLine[1] = reader[sample];

    result = 0;
    for (i in seq(1,9)) 
    { # for each tap
          result = result + delayLine[i] * filterTaps[i]; # multiply     
    }
    writeback[sample] &lt;- result; # output
}