I'm working on a simple dithering algorithm, but the background noise is too loud for me. I wish to improve the algorithm so that the background noise is below -100dB.
Code: Select all
const float noise = ((rand() + rand() + rand() + rand() + rand() + rand() - 0.5f * 6.0f) / 2.0f) * 0.0001f;
int step1 = static_cast<int>((noise + input + 1.0f) * 32767.5f); //float to 16bit int
step1 += quantizationError;
if(step1 < 0) step1 = 0;
else if (step1 > 65535) step1 = 65535;
const int step2 = step1 >> 4; //shift from 16 to 12 bits
quantizationError = step1 - (step2 << 4);
const float step3 = ((float)step2) / 2047.5f; //back to float
return (step3 - 1.0f) - noise;
Thanks,
Luca