I have been trying to learn about Q31 format (as well as Q15), but I am having trouble understanding how it works.
So my CODEC is giving me 24-bit two's complement data. I have converted this data successfully to 32-bit two's complement data and back. I would like to so some math on this data using Q31 format. For starters, hopefully something like attenuation. I am using a PIC32MZ series processor. Here is some of the code I am working with.
#define Q31 int
#define Q63 long long
Q31 Q31multQ31 (Q31 a, Q31 b){
Q63 y;
y = (Q63) a * (Q63) b;
y >> 31;
return ((Q31) y);
}
// Super basic attenuation (hopefully)
left_output = Q31multQ31(left_input,0b00000000001111111111111111111111);
This seems to give me awful noise. left_input and left_output are int (signed 32-bit). Is there some sort of conversion I am missing to use these as Q31?
0x80000000
) inclusive and $1-2^{-31}$ (represented by0x7fffffff
) inclusive? $\endgroup$ – Olli Niemitalo Nov 9 '16 at 7:380x8000000
by itself, but that's not your problem here. How do you do the conversions? $\endgroup$ – Olli Niemitalo Nov 9 '16 at 16:44