audioconvert: improve noise bits

Make a new noise method called PATTERN and use it to add a slow (every
1024 samples) repeating pattern of -1, 0.
Only use this method when we don't already use triangular dither.

See #2540
This commit is contained in:
Wim Taymans 2022-07-18 11:39:24 +02:00
parent 57f63feb92
commit ada39f3048
4 changed files with 43 additions and 20 deletions

View file

@ -453,9 +453,6 @@ int convert_init(struct convert *conv)
conv->scale = 1.0f / (float)(INT32_MAX);
if (conv->noise_bits > 0)
conv->scale *= (1 << (conv->noise_bits + 1));
/* disable dither if not needed */
if (!need_dither(conv->dst_fmt))
conv->method = DITHER_METHOD_NONE;
@ -465,8 +462,21 @@ int convert_init(struct convert *conv)
return -EINVAL;
conv->noise_method = dinfo->noise_method;
if (conv->noise_bits && conv->noise_method == NOISE_METHOD_NONE)
conv->noise_method = NOISE_METHOD_RECTANGULAR;
if (conv->noise_bits > 0) {
switch (conv->noise_method) {
case NOISE_METHOD_NONE:
conv->noise_method = NOISE_METHOD_PATTERN;
conv->scale = -1.0f * (1 << (conv->noise_bits-1));
break;
case NOISE_METHOD_RECTANGULAR:
conv->noise_method = NOISE_METHOD_TRIANGULAR;
SPA_FALLTHROUGH;
case NOISE_METHOD_TRIANGULAR:
case NOISE_METHOD_TRIANGULAR_HF:
conv->scale *= (1 << (conv->noise_bits-1));
break;
}
}
if (conv->noise_method < NOISE_METHOD_TRIANGULAR)
conv->scale *= 0.5f;