mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-12-17 08:56:49 -05:00
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:
parent
57f63feb92
commit
ada39f3048
4 changed files with 43 additions and 20 deletions
|
|
@ -255,6 +255,12 @@ static inline void update_noise_c(struct convert *conv, uint32_t n_samples)
|
||||||
}
|
}
|
||||||
*prev = old;
|
*prev = old;
|
||||||
break;
|
break;
|
||||||
|
case NOISE_METHOD_PATTERN:
|
||||||
|
old = *prev;
|
||||||
|
for (n = 0; n < n_samples; n++)
|
||||||
|
noise[n] = conv->scale * (1-((old++>>10)&1));
|
||||||
|
*prev = old;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -581,7 +581,7 @@ static inline void update_noise_sse2(struct convert *conv, uint32_t n_samples)
|
||||||
{
|
{
|
||||||
uint32_t n;
|
uint32_t n;
|
||||||
const uint32_t *r = SPA_PTR_ALIGN(conv->random, 16, uint32_t);
|
const uint32_t *r = SPA_PTR_ALIGN(conv->random, 16, uint32_t);
|
||||||
const int32_t *p = SPA_PTR_ALIGN(conv->prev, 16, int32_t);
|
int32_t *p = SPA_PTR_ALIGN(conv->prev, 16, int32_t), op;
|
||||||
__m128 scale = _mm_set1_ps(conv->scale);
|
__m128 scale = _mm_set1_ps(conv->scale);
|
||||||
__m128 out[1];
|
__m128 out[1];
|
||||||
float *noise = SPA_PTR_ALIGN(conv->noise, 16, float);
|
float *noise = SPA_PTR_ALIGN(conv->noise, 16, float);
|
||||||
|
|
@ -616,6 +616,12 @@ static inline void update_noise_sse2(struct convert *conv, uint32_t n_samples)
|
||||||
}
|
}
|
||||||
_mm_store_si128((__m128i*)p, old[0]);
|
_mm_store_si128((__m128i*)p, old[0]);
|
||||||
break;
|
break;
|
||||||
|
case NOISE_METHOD_PATTERN:
|
||||||
|
op = *p;
|
||||||
|
for (n = 0; n < n_samples; n++)
|
||||||
|
noise[n] = conv->scale * (1-((op++>>10)&1));
|
||||||
|
*p = op;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -453,9 +453,6 @@ int convert_init(struct convert *conv)
|
||||||
|
|
||||||
conv->scale = 1.0f / (float)(INT32_MAX);
|
conv->scale = 1.0f / (float)(INT32_MAX);
|
||||||
|
|
||||||
if (conv->noise_bits > 0)
|
|
||||||
conv->scale *= (1 << (conv->noise_bits + 1));
|
|
||||||
|
|
||||||
/* disable dither if not needed */
|
/* disable dither if not needed */
|
||||||
if (!need_dither(conv->dst_fmt))
|
if (!need_dither(conv->dst_fmt))
|
||||||
conv->method = DITHER_METHOD_NONE;
|
conv->method = DITHER_METHOD_NONE;
|
||||||
|
|
@ -465,8 +462,21 @@ int convert_init(struct convert *conv)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
conv->noise_method = dinfo->noise_method;
|
conv->noise_method = dinfo->noise_method;
|
||||||
if (conv->noise_bits && conv->noise_method == NOISE_METHOD_NONE)
|
if (conv->noise_bits > 0) {
|
||||||
conv->noise_method = NOISE_METHOD_RECTANGULAR;
|
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)
|
if (conv->noise_method < NOISE_METHOD_TRIANGULAR)
|
||||||
conv->scale *= 0.5f;
|
conv->scale *= 0.5f;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -233,6 +233,7 @@ struct convert {
|
||||||
#define NOISE_METHOD_RECTANGULAR 1
|
#define NOISE_METHOD_RECTANGULAR 1
|
||||||
#define NOISE_METHOD_TRIANGULAR 2
|
#define NOISE_METHOD_TRIANGULAR 2
|
||||||
#define NOISE_METHOD_TRIANGULAR_HF 3
|
#define NOISE_METHOD_TRIANGULAR_HF 3
|
||||||
|
#define NOISE_METHOD_PATTERN 4
|
||||||
uint32_t noise_method;
|
uint32_t noise_method;
|
||||||
float *noise;
|
float *noise;
|
||||||
uint32_t noise_size;
|
uint32_t noise_size;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue