[FFmpeg-cvslog] swresample/rematrix: Use error diffusion to avoid error in the DC component of the matrix
Michael Niedermayer
git at videolan.org
Sun Jun 5 03:16:42 CEST 2016
ffmpeg | branch: release/3.0 | Michael Niedermayer <michael at niedermayer.cc> | Sun May 15 18:33:09 2016 +0200| [f6586db165da1007e347bfa2822d0e183dd841a5] | committer: Michael Niedermayer
swresample/rematrix: Use error diffusion to avoid error in the DC component of the matrix
This fixes the sum of the integer coefficients ending up summing to a value
larger than the value representing unity.
This issue occurs with qN0.dts when converting to stereo
Signed-off-by: Michael Niedermayer <michael at niedermayer.cc>
(cherry picked from commit 7fe81bc4f8ba684626fa08f7bef46da3e8abe373)
Signed-off-by: Michael Niedermayer <michael at niedermayer.cc>
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=f6586db165da1007e347bfa2822d0e183dd841a5
---
libswresample/rematrix.c | 12 +++++++++---
1 file changed, 9 insertions(+), 3 deletions(-)
diff --git a/libswresample/rematrix.c b/libswresample/rematrix.c
index 932088f..f18c9f6 100644
--- a/libswresample/rematrix.c
+++ b/libswresample/rematrix.c
@@ -371,9 +371,15 @@ av_cold int swri_rematrix_init(SwrContext *s){
s->native_one = av_mallocz(sizeof(int));
if (!s->native_matrix || !s->native_one)
return AVERROR(ENOMEM);
- for (i = 0; i < nb_out; i++)
- for (j = 0; j < nb_in; j++)
- ((int*)s->native_matrix)[i * nb_in + j] = lrintf(s->matrix[i][j] * 32768);
+ for (i = 0; i < nb_out; i++) {
+ double rem = 0;
+
+ for (j = 0; j < nb_in; j++) {
+ double target = s->matrix[i][j] * 32768 + rem;
+ ((int*)s->native_matrix)[i * nb_in + j] = lrintf(target);
+ rem += target - ((int*)s->native_matrix)[i * nb_in + j];
+ }
+ }
*((int*)s->native_one) = 32768;
s->mix_1_1_f = (mix_1_1_func_type*)copy_s16;
s->mix_2_1_f = (mix_2_1_func_type*)sum2_s16;
More information about the ffmpeg-cvslog
mailing list