ref: 36cc2a77dc286bd596f59166f6737ffb4a5e2e85
parent: a2440ab0bd731c9d7aac5701a15d4cb34bba2127
author: robs <robs>
date: Mon Jan 5 19:00:49 EST 2009
fix [2487589] Glitch dither -s
--- a/src/dither_fir.h
+++ b/src/dither_fir.h
@@ -4,7 +4,6 @@
{
priv_t * p = (priv_t *)effp->priv;
size_t len = *isamp = *osamp = min(*isamp, *osamp);
- int dummy = 0;
while (len--) {
double r = p->am0 * RANQD1 + p->am1 * RANQD1;
@@ -12,7 +11,9 @@
int j = 0;
CONVOLVE
assert(j == N);
- *obuf = SOX_ROUND_CLIP_COUNT(d + r, dummy);
+ *obuf = d + r < 0? d + r <= SOX_SAMPLE_MIN - .5? SOX_SAMPLE_MIN: d + r - .5
+ : d + r >= SOX_SAMPLE_MAX - (1 << (31-PREC)) + 0.5?
+ SOX_SAMPLE_MAX - (1 << (31-PREC)): d + r + .5;
error = ((*obuf++ + (1 << (31-PREC))) & (-1 << (32-PREC))) - d;
p->pos = p->pos? p->pos - 1 : p->pos - 1 + N;
p->previous_errors[p->pos + N] = p->previous_errors[p->pos] = error;
--- a/src/dither_iir.h
+++ b/src/dither_iir.h
@@ -5,7 +5,6 @@
{
priv_t * p = (priv_t *)effp->priv;
size_t len = *isamp = *osamp = min(*isamp, *osamp);
- int dummy = 0;
while (len--) {
double r = p->am0 * RANQD1 + p->am1 * RANQD1;
@@ -14,7 +13,9 @@
CONVOLVE
assert(j == N);
d = *ibuf++ - output;
- *obuf = SOX_ROUND_CLIP_COUNT(d + r, dummy);
+ *obuf = d + r < 0? d + r <= SOX_SAMPLE_MIN - .5? SOX_SAMPLE_MIN: d + r - .5
+ : d + r >= SOX_SAMPLE_MAX - (1 << (31-PREC)) + 0.5?
+ SOX_SAMPLE_MAX - (1 << (31-PREC)): d + r + .5;
error = ((*obuf++ + (1 << (31-PREC))) & (-1 << (32-PREC))) - d;
p->pos = p->pos? p->pos - 1 : p->pos - 1 + N;
p->previous_errors[p->pos + N] = p->previous_errors[p->pos] = error;