From df9844937f23615bd5f44557c0258c68cbd3577d Mon Sep 17 00:00:00 2001 From: Nick Brereton Date: Tue, 27 Jul 2010 21:45:43 +0000 Subject: [PATCH] DCA: fix multichannel -> 2 channel downmix. Patch by Nick Brereton Originally committed as revision 24555 to svn://svn.ffmpeg.org/ffmpeg/trunk --- libavcodec/dca.c | 47 +++++++++++++++++++++++++++++++++-------------- 1 file changed, 33 insertions(+), 14 deletions(-) diff --git a/libavcodec/dca.c b/libavcodec/dca.c index ff44ec78dd..aa576253a6 100644 --- a/libavcodec/dca.c +++ b/libavcodec/dca.c @@ -879,17 +879,19 @@ static void lfe_interpolation_fir(DCAContext *s, int decimation_select, /* downmixing routines */ #define MIX_REAR1(samples, si1, rs, coef) \ - samples[i] += samples[si1] * coef[rs][0]; \ - samples[i+256] += samples[si1] * coef[rs][1]; + samples[i] += (samples[si1] - add_bias) * coef[rs][0]; \ + samples[i+256] += (samples[si1] - add_bias) * coef[rs][1]; #define MIX_REAR2(samples, si1, si2, rs, coef) \ - samples[i] += samples[si1] * coef[rs][0] + samples[si2] * coef[rs+1][0]; \ - samples[i+256] += samples[si1] * coef[rs][1] + samples[si2] * coef[rs+1][1]; + samples[i] += (samples[si1] - add_bias) * coef[rs][0] + (samples[si2] - add_bias) * coef[rs+1][0]; \ + samples[i+256] += (samples[si1] - add_bias) * coef[rs][1] + (samples[si2] - add_bias) * coef[rs+1][1]; #define MIX_FRONT3(samples, coef) \ - t = samples[i]; \ - samples[i] = t * coef[0][0] + samples[i+256] * coef[1][0] + samples[i+512] * coef[2][0]; \ - samples[i+256] = t * coef[0][1] + samples[i+256] * coef[1][1] + samples[i+512] * coef[2][1]; + t = samples[i+c] - add_bias; \ + u = samples[i+l] - add_bias; \ + v = samples[i+r] - add_bias; \ + samples[i] = t * coef[0][0] + u * coef[1][0] + v * coef[2][0] + add_bias; \ + samples[i+256] = t * coef[0][1] + u * coef[1][1] + v * coef[2][1] + add_bias; #define DOWNMIX_TO_STEREO(op1, op2) \ for (i = 0; i < 256; i++){ \ @@ -898,10 +900,12 @@ static void lfe_interpolation_fir(DCAContext *s, int decimation_select, } static void dca_downmix(float *samples, int srcfmt, - int downmix_coef[DCA_PRIM_CHANNELS_MAX][2]) + int downmix_coef[DCA_PRIM_CHANNELS_MAX][2], + const int8_t *channel_mapping, float add_bias) { + int c,l,r,sl,sr,s; int i; - float t; + float t, u, v; float coef[DCA_PRIM_CHANNELS_MAX][2]; for (i=0; iavctx->request_channels == 2 && s->prim_channels > 2) { - dca_downmix(s->samples, s->amode, s->downmix_coef); + dca_downmix(s->samples, s->amode, s->downmix_coef, s->channel_order_tab, s->add_bias); } /* Generate LFE samples for this subsubframe FIXME!!! */