From b40211ff676da07be3a01c7ae810052da15a0913 Mon Sep 17 00:00:00 2001 From: Justin Ruggles Date: Sun, 16 Dec 2007 04:25:50 +0000 Subject: [PATCH] downmix before the IMDCT if no block switching is used Originally committed as revision 11228 to svn://svn.ffmpeg.org/ffmpeg/trunk --- libavcodec/ac3dec.c | 47 ++++++++++++++++++++++++++++++++------------- 1 file changed, 34 insertions(+), 13 deletions(-) diff --git a/libavcodec/ac3dec.c b/libavcodec/ac3dec.c index 33f87ab7ff..1a7cfc1241 100644 --- a/libavcodec/ac3dec.c +++ b/libavcodec/ac3dec.c @@ -750,27 +750,28 @@ static inline void do_imdct(AC3DecodeContext *ctx) /** * Downmix the output to mono or stereo. */ -static void ac3_downmix(float samples[AC3_MAX_CHANNELS][256], int fbw_channels, - int output_mode, float coef[AC3_MAX_CHANNELS][2]) +static void ac3_downmix(float samples[][256], int fbw_channels, + int output_mode, float coef[AC3_MAX_CHANNELS][2], + int ch_offset) { int i, j; float v0, v1, s0, s1; for(i=0; i<256; i++) { v0 = v1 = s0 = s1 = 0.0f; - for(j=0; jgb; uint8_t bit_alloc_stages[AC3_MAX_CHANNELS]; + int any_block_switching = 0; + int num_channels_bak, fbw_channels_bak; memset(bit_alloc_stages, 0, AC3_MAX_CHANNELS); /* block switch flags */ - for (ch = 1; ch <= fbw_channels; ch++) + for (ch = 1; ch <= fbw_channels; ch++) { ctx->block_switch[ch] = get_bits1(gb); + any_block_switching |= ctx->block_switch[ch]; + } /* dithering flags */ ctx->dither_all = 1; @@ -1062,13 +1067,26 @@ static int ac3_parse_audio_block(AC3DecodeContext *ctx, int blk) } } + /* if no block switching is used, downmixing can be done before IMDCT */ + num_channels_bak = ctx->channels; + fbw_channels_bak = ctx->fbw_channels; + if(!any_block_switching) { + if(ctx->channels != ctx->out_channels && !((ctx->output_mode & AC3_OUTPUT_LFEON) && + ctx->fbw_channels == ctx->out_channels)) { + ac3_downmix(ctx->transform_coeffs, ctx->fbw_channels, + ctx->output_mode, ctx->downmix_coeffs, 1); + ctx->channels = ctx->out_channels; + ctx->fbw_channels = ctx->channels - (ctx->output_mode & AC3_OUTPUT_LFEON); + } + } + do_imdct(ctx); - /* downmix output if needed */ + /* downmix output now if it wasn't done before IMDCT */ if(ctx->channels != ctx->out_channels && !((ctx->output_mode & AC3_OUTPUT_LFEON) && ctx->fbw_channels == ctx->out_channels)) { ac3_downmix(ctx->output, ctx->fbw_channels, ctx->output_mode, - ctx->downmix_coeffs); + ctx->downmix_coeffs, 0); } /* convert float to 16-bit integer */ @@ -1079,6 +1097,9 @@ static int ac3_parse_audio_block(AC3DecodeContext *ctx, int blk) ctx->dsp.float_to_int16(ctx->int_output[ch], ctx->output[ch], 256); } + ctx->channels = num_channels_bak; + ctx->fbw_channels = fbw_channels_bak; + return 0; }