From c31a76e4ef116fa9aac28578cd3d92a035b3aafd Mon Sep 17 00:00:00 2001 From: Justin Ruggles Date: Wed, 2 May 2007 20:33:32 +0000 Subject: [PATCH] use downmixing coefficients in dca decoder. reference: Subject: [Ffmpeg-devel] [PATCH] DTS multichannel Date: Wed, 25 Apr 2007 16:25:18 -0400 Originally committed as revision 8875 to svn://svn.ffmpeg.org/ffmpeg/trunk --- libavcodec/dca.c | 53 ++++++++++++++++++++++++++++---------------- libavcodec/dcadata.h | 13 +++++++++++ 2 files changed, 47 insertions(+), 19 deletions(-) diff --git a/libavcodec/dca.c b/libavcodec/dca.c index 5da609ed6c..d5c2a73d49 100644 --- a/libavcodec/dca.c +++ b/libavcodec/dca.c @@ -522,11 +522,19 @@ static int dca_subframe_header(DCAContext * s) } /* Stereo downmix coefficients */ - if (s->prim_channels > 2 && s->downmix) { + if (s->prim_channels > 2) { + if(s->downmix) { for (j = 0; j < s->prim_channels; j++) { s->downmix_coef[j][0] = get_bits(&s->gb, 7); s->downmix_coef[j][1] = get_bits(&s->gb, 7); } + } else { + int am = s->amode & DCA_CHANNEL_MASK; + for (j = 0; j < s->prim_channels; j++) { + s->downmix_coef[j][0] = dca_default_coeffs[am][j][0]; + s->downmix_coef[j][1] = dca_default_coeffs[am][j][1]; + } + } } /* Dynamic range coefficient */ @@ -750,18 +758,18 @@ static void lfe_interpolation_fir(int decimation_select, } /* downmixing routines */ -#define MIX_REAR1(samples, si1) \ - samples[i] += samples[si1]; \ - samples[i+256] += samples[si1]; +#define MIX_REAR1(samples, si1, rs, coef) \ + samples[i] += samples[si1] * coef[rs][0]; \ + samples[i+256] += samples[si1] * coef[rs][1]; -#define MIX_REAR2(samples, si1, si2) \ - samples[i] += samples[si1]; \ - samples[i+256] += samples[si2]; +#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]; -#define MIX_FRONT3(samples) \ +#define MIX_FRONT3(samples, coef) \ t = samples[i]; \ - samples[i] += samples[i+256]; \ - samples[i+256] = samples[i+512] + t; + 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]; #define DOWNMIX_TO_STEREO(op1, op2) \ for(i = 0; i < 256; i++){ \ @@ -769,10 +777,17 @@ static void lfe_interpolation_fir(int decimation_select, op2 \ } -static void dca_downmix(float *samples, int srcfmt) +static void dca_downmix(float *samples, int srcfmt, + int downmix_coef[DCA_PRIM_CHANNELS_MAX][2]) { int i; float t; + float coef[DCA_PRIM_CHANNELS_MAX][2]; + + for(i=0; iprim_channels > dca_channels[s->output & DCA_CHANNEL_MASK]) { - dca_downmix(s->samples, s->amode); + dca_downmix(s->samples, s->amode, s->downmix_coef); } /* Generate LFE samples for this subsubframe FIXME!!! */ diff --git a/libavcodec/dcadata.h b/libavcodec/dcadata.h index c9f2ca747b..5466b37b89 100644 --- a/libavcodec/dcadata.h +++ b/libavcodec/dcadata.h @@ -8361,6 +8361,19 @@ static const float dca_downmix_coeffs[65] = { 0.001412537544623, 0.001000000000000, 0.000501187233627, 0.000251188643151, 0.000000000000000, }; +static const uint8_t dca_default_coeffs[16][5][2] = { + { { 13, 13 }, }, + { { 0, 64 }, { 64, 0 }, }, + { { 0, 64 }, { 64, 0 }, }, + { { 0, 64 }, { 64, 0 }, }, + { { 0, 64 }, { 64, 0 }, }, + { { 6, 6 }, { 0, 25 }, { 25, 0 }, }, + { { 0, 25 }, { 25, 0 }, { 13, 13 }, }, + { { 6, 6 }, { 0, 25 }, { 25, 0 }, { 13, 13 }, }, + { { 0, 25 }, { 25, 0 }, { 0, 13 }, { 13, 0 }, }, + { { 6, 6 }, { 0, 25 }, { 25, 0 }, { 0, 13 }, { 13, 0 }, }, +}; + /* downmix coeffs TABLE 9