From 0b60fc94aab63b80b3a898c744da50758215bc9c Mon Sep 17 00:00:00 2001 From: Michael Niedermayer Date: Thu, 10 Jan 2013 00:27:04 +0100 Subject: [PATCH] swr: reorder the operations in the noise shaping code Signed-off-by: Michael Niedermayer --- libswresample/dither.c | 1 + libswresample/dither_template.c | 5 +++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/libswresample/dither.c b/libswresample/dither.c index c3bb5609ed..66bf184310 100644 --- a/libswresample/dither.c +++ b/libswresample/dither.c @@ -118,6 +118,7 @@ int swri_dither_init(SwrContext *s, enum AVSampleFormat out_fmt, enum AVSampleFo if (s->dither.method > SWR_DITHER_NS) { s->dither.noise.bps = 4; s->dither.noise.fmt = AV_SAMPLE_FMT_FLTP; + s->dither.noise_scale = 1; } return 0; diff --git a/libswresample/dither_template.c b/libswresample/dither_template.c index ffa5bdd664..3388aadc56 100644 --- a/libswresample/dither_template.c +++ b/libswresample/dither_template.c @@ -34,12 +34,13 @@ void RENAME(swri_noise_shaping)(SwrContext *s, AudioData *srcs, AudioData *noise DELEM *data = (DELEM*)srcs->ch[ch]; pos = s->dither.ns_pos; for (i=0; idither.ns_coeffs[j] * s->dither.ns_errors[ch][pos + j]; pos = pos ? pos - 1 : pos - 1 + taps; - d1 = rint((d + noise[i]) * S_1)*S; + d1 = rint(d + noise[i]); s->dither.ns_errors[ch][pos + taps] = s->dither.ns_errors[ch][pos] = d1 - d; + d1 *= S; CLIP(d1); data[i] = d1; }