1 #ifdef IIR
2 #define _ output += p->coefs[j] * p->previous_errors[p->pos + j] \
3 - p->coefs[N + j] * p->previous_outputs[p->pos + j], ++j;
4 #else
5 #define _ d -= p->coefs[j] * p->previous_errors[p->pos + j], ++j;
6 #endif
NAME(sox_effect_t * effp,const sox_sample_t * ibuf,sox_sample_t * obuf,size_t * isamp,size_t * osamp)7 static int NAME(sox_effect_t * effp, const sox_sample_t * ibuf,
8 sox_sample_t * obuf, size_t * isamp, size_t * osamp)
9 {
10 priv_t * p = (priv_t *)effp->priv;
11 size_t len = *isamp = *osamp = min(*isamp, *osamp);
12
13 while (len--) {
14 if (p->auto_detect) {
15 p->history = (p->history << 1) +
16 !!(*ibuf & (((unsigned)-1) >> p->prec));
17 if (p->history && p->dither_off) {
18 p->dither_off = sox_false;
19 lsx_debug("flow %" PRIuPTR ": on @ %" PRIu64, effp->flow, p->num_output);
20 } else if (!p->history && !p->dither_off) {
21 p->dither_off = sox_true;
22 memset(p->previous_errors, 0, sizeof(p->previous_errors));
23 memset(p->previous_outputs, 0, sizeof(p->previous_outputs));
24 lsx_debug("flow %" PRIuPTR ": off @ %" PRIu64, effp->flow, p->num_output);
25 }
26 }
27
28 if (!p->dither_off) {
29 int32_t r1 = RANQD1 >> p->prec, r2 = RANQD1 >> p->prec; /* Defer add! */
30 #ifdef IIR
31 double d1, d, output = 0;
32 #else
33 double d1, d = *ibuf++;
34 #endif
35 int i, j = 0;
36 CONVOLVE
37 assert(j == N);
38 p->pos = p->pos? p->pos - 1 : p->pos - 1 + N;
39 #ifdef IIR
40 d = *ibuf++ - output;
41 p->previous_outputs[p->pos + N] = p->previous_outputs[p->pos] = output;
42 #endif
43 d1 = (d + r1 + r2) / (1 << (32 - p->prec));
44 i = d1 < 0? d1 - .5 : d1 + .5;
45 p->previous_errors[p->pos + N] = p->previous_errors[p->pos] =
46 (double)i * (1 << (32 - p->prec)) - d;
47 if (i < (-1 << (p->prec-1)))
48 ++effp->clips, *obuf = SOX_SAMPLE_MIN;
49 else if (i > (int)SOX_INT_MAX(p->prec))
50 ++effp->clips, *obuf = SOX_INT_MAX(p->prec) << (32 - p->prec);
51 else *obuf = i << (32 - p->prec);
52 ++obuf;
53 }
54 else
55 *obuf++ = *ibuf++;
56 ++p->num_output;
57 }
58 return SOX_SUCCESS;
59 }
60 #undef CONVOLVE
61 #undef _
62 #undef NAME
63 #undef N
64