The bit shifting is nothing new or unique, it's documented by many other people. So let's look at an actual case. Here's the coefficients for a 250Hz low pass 2nd order IIR:
Code: Select all
{ //crossML1 250Hz, 31bits, A1/2, B0,B1,B2,A1,A2,BitShift
42517323, // 0.00030935424661235637
85034647, // 0.00061870849322471274
42517323, // 0.00030935424661235637
2093407256, // 0.97481871793958885242
-2041988198, // -0.95087485286562711817
6
},
My MATLAB code looks at the coefficients and determines how many bits are wasted by B0, B1, and B2. If its possible to bit shift by 6 bits, it sets the BitShift field accordingly. My filter "loader" then sets the appropriate data structures to run the bit shift IIR which shifts right the input sample by 6 bits.
This adds resolution since the sample value is going to be something like 0xffffff00 for a 24 bit audio sample and the lower 8 bits are zeros. My crossovers are the second to last operation to be performed on the data prior to going to the DAC's, which means they can be in 0.32 format for highest resolution. The last operation is a MACC for volumes.
Forgot to mention, that you do need a little headroom or the values will overflow from the filter due to a small overshoot sometimes. I reduce the volume by about 1dB earlier in the code.