Closed bw3 closed 3 years ago
Thanks for the PR! This algorithm was borrowed from the AidaDSP library, which this library is based on. May I ask how you figured this out, or where you found the algorithm that confirms your conclusion?
I tried to set up a low pass filter with a gain of -20db, and the volume was not reduced as expected, when I added the parenthesis, the volume was reduced, and the audio sounded low-passed as expected.
I used this page to figure out the correct formula: http://shepazu.github.io/Audio-EQ-Cookbook/audio-eq-cookbook.html
Equations 2 and 3 show that b0
b1
and b2
should be multiplied by the overall gain value.
A bit further down, we see the formula for a low pass filter (LPF) are as follows:
a0 = 1 + alpha
a1 = -2 * cos(w0)
a2 = 1 - alpha
b0 = (1 - cos(w0)) / 2
b1 = 1 - cos(w0)
b2 = (1 - cos(w0)) / 2
Combined, this gives us:
a0 = 1 + alpha
a1 = -2 * cos(w0)
a2 = 1 - alpha
b0 = (1 - cos(w0)) / 2 * gainLinear
b1 = (1 - cos(w0)) * gainLinear
b2 = (1 - cos(w0)) / 2 * gainLinear
If the overall gain is not being used, it would be 0 db, giving a gainLinear of 1. So if an overall gain is not being applied, b1 is still calculated correctly without the fix.
Awesome, thanks for the explaination!
Without this fix, a gain other than 0db will cause significant distortion.