audiocovert: improve dither setup

The quantize is the amount of bits we want to keep from the original
signal, subtract the amount of bits for noise. Clamp this to 0 (all
noise).
Calculate the scale factor better with powf() and avoid overflows.

Fixes #2479
This commit is contained in:
Wim Taymans 2022-06-28 10:11:46 +02:00
parent 67c2202044
commit b7e26002be
3 changed files with 9 additions and 11 deletions

View file

@ -79,10 +79,7 @@ int dither_init(struct dither *d)
if (info == NULL)
return -ENOTSUP;
if (d->quantize >= 32)
return -EINVAL;
d->scale = 1.0f / (1ULL << (63 - d->quantize));
d->scale = 1.0f / powf(2.0f, 31 + d->quantize);
d->dither_size = DITHER_SIZE;
d->dither = calloc(d->dither_size + DITHER_OPS_MAX_OVERREAD +