Clip 16-bit resampled signal as there's no room for filter overshoots

This commit is contained in:
Alexandre Ratchov 2021-01-11 14:46:32 +01:00
parent 2996dcdc03
commit 21580f56b5
2 changed files with 28 additions and 0 deletions

View File

@ -453,6 +453,20 @@ resamp_do(struct resamp *p, adata_t *in, adata_t *out, int icnt, int ocnt)
for (c = nch; c > 0; c--) {
s = f[c] >> RESAMP_BITS;
s = (int64_t)s * p->filt_cutoff >> RESAMP_BITS;
#if ADATA_BITS == 16
/*
* In 16-bit mode, we've no room for filter
* overshoots, so we need to clip the signal
* to avoid 16-bit integers to wrap around.
* In 24-bit mode, samples may exceed the
* [-1:1] range. Later, cmap_add() will clip
* them, so no need to clip them here as well.
*/
if (s >= ADATA_UNIT)
s = ADATA_UNIT - 1;
else if (s < -ADATA_UNIT)
s = -ADATA_UNIT;
#endif
*odata++ = s;
}

View File

@ -345,6 +345,20 @@ resamp_do(struct resamp *p, adata_t *in, adata_t *out, int todo)
for (c = nch; c > 0; c--) {
s = f[c] >> RESAMP_BITS;
s = (int64_t)s * p->filt_cutoff >> RESAMP_BITS;
#if ADATA_BITS == 16
/*
* In 16-bit mode, we've no room for filter
* overshoots, so we need to clip the signal
* to avoid 16-bit integers to wrap around.
* In 24-bit mode, samples may exceed the
* [-1:1] range. Later, cmap_add() will clip
* them, so no need to clip them here as well.
*/
if (s >= ADATA_UNIT)
s = ADATA_UNIT - 1;
else if (s < -ADATA_UNIT)
s = -ADATA_UNIT;
#endif
*odata++ = s;
}
diff += iblksz;