2 #if defined(TEMPLATE_DITHER_DBL)
3 # define RENAME(N) N ## _double
7 #elif defined(TEMPLATE_DITHER_FLT)
8 # define RENAME(N) N ## _float
12 #elif defined(TEMPLATE_DITHER_S32)
13 # define RENAME(N) N ## _int32
14 # define DELEM int32_t
15 # define CLIP(v) v = FFMAX(FFMIN(v, INT32_MAX), INT32_MIN)
17 #elif defined(TEMPLATE_DITHER_S16)
18 # define RENAME(N) N ## _int16
19 # define DELEM int16_t
20 # define CLIP(v) v = FFMAX(FFMIN(v, INT16_MAX), INT16_MIN)
27 int pos =
s->dither.ns_pos;
29 int taps =
s->dither.ns_taps;
30 float S =
s->dither.ns_scale;
31 float S_1 =
s->dither.ns_scale_1;
34 av_assert2((taps&3) != 3 ||
s->dither.ns_coeffs[taps] == 0);
36 for (ch=0; ch<srcs->ch_count; ch++) {
37 const float *
noise = ((
const float *)noises->ch[ch]) +
s->dither.noise_pos;
38 const DELEM *
src = (
const DELEM*)srcs->ch[ch];
39 DELEM *dst = (DELEM*)dsts->ch[ch];
40 float *ns_errors =
s->dither.ns_errors[ch];
41 const float *ns_coeffs =
s->dither.ns_coeffs;
42 pos =
s->dither.ns_pos;
43 for (i=0; i<
count; i++) {
44 double d1, d = src[i]*S_1;
45 for(j=0; j<taps-2; j+=4) {
46 d -= ns_coeffs[j ] * ns_errors[pos + j ]
47 +ns_coeffs[j + 1] * ns_errors[pos + j + 1]
48 +ns_coeffs[j + 2] * ns_errors[pos + j + 2]
49 +ns_coeffs[j + 3] * ns_errors[pos + j + 3];
52 d -= ns_coeffs[j] * ns_errors[pos + j];
53 pos = pos ? pos - 1 : taps - 1;
54 d1 =
rint(d + noise[i]);
55 ns_errors[pos + taps] = ns_errors[pos] = d1 - d;
62 s->dither.ns_pos = pos;