comparison ac3dec.c @ 6031:9d3f52380cb3 libavcodec

Revert commit made in revision 11228. I'm getting some strange results in the downmixed output that I can't quite figure out.
author jbr
date Mon, 17 Dec 2007 01:03:19 +0000
parents a165936f0d9e
children f74202e7e896
comparison
equal deleted inserted replaced
6030:fb99890ee609 6031:9d3f52380cb3
748 } 748 }
749 749
750 /** 750 /**
751 * Downmix the output to mono or stereo. 751 * Downmix the output to mono or stereo.
752 */ 752 */
753 static void ac3_downmix(float samples[][256], int fbw_channels, 753 static void ac3_downmix(float samples[AC3_MAX_CHANNELS][256], int fbw_channels,
754 int output_mode, float coef[AC3_MAX_CHANNELS][2], 754 int output_mode, float coef[AC3_MAX_CHANNELS][2])
755 int ch_offset)
756 { 755 {
757 int i, j; 756 int i, j;
758 float v0, v1, s0, s1; 757 float v0, v1, s0, s1;
759 758
760 for(i=0; i<256; i++) { 759 for(i=0; i<256; i++) {
761 v0 = v1 = s0 = s1 = 0.0f; 760 v0 = v1 = s0 = s1 = 0.0f;
762 for(j=ch_offset; j<fbw_channels+ch_offset; j++) { 761 for(j=0; j<fbw_channels; j++) {
763 v0 += samples[j][i] * coef[j-ch_offset][0]; 762 v0 += samples[j][i] * coef[j][0];
764 v1 += samples[j][i] * coef[j-ch_offset][1]; 763 v1 += samples[j][i] * coef[j][1];
765 s0 += coef[j-ch_offset][0]; 764 s0 += coef[j][0];
766 s1 += coef[j-ch_offset][1]; 765 s1 += coef[j][1];
767 } 766 }
768 v0 /= s0; 767 v0 /= s0;
769 v1 /= s1; 768 v1 /= s1;
770 if(output_mode == AC3_CHMODE_MONO) { 769 if(output_mode == AC3_CHMODE_MONO) {
771 samples[ch_offset][i] = (v0 + v1) * LEVEL_MINUS_3DB; 770 samples[0][i] = (v0 + v1) * LEVEL_MINUS_3DB;
772 } else if(output_mode == AC3_CHMODE_STEREO) { 771 } else if(output_mode == AC3_CHMODE_STEREO) {
773 samples[ch_offset][i] = v0; 772 samples[0][i] = v0;
774 samples[ch_offset+1][i] = v1; 773 samples[1][i] = v1;
775 } 774 }
776 } 775 }
777 } 776 }
778 777
779 /** 778 /**
784 int fbw_channels = ctx->fbw_channels; 783 int fbw_channels = ctx->fbw_channels;
785 int channel_mode = ctx->channel_mode; 784 int channel_mode = ctx->channel_mode;
786 int i, bnd, seg, ch; 785 int i, bnd, seg, ch;
787 GetBitContext *gb = &ctx->gb; 786 GetBitContext *gb = &ctx->gb;
788 uint8_t bit_alloc_stages[AC3_MAX_CHANNELS]; 787 uint8_t bit_alloc_stages[AC3_MAX_CHANNELS];
789 int any_block_switching = 0;
790 int num_channels_bak, fbw_channels_bak;
791 788
792 memset(bit_alloc_stages, 0, AC3_MAX_CHANNELS); 789 memset(bit_alloc_stages, 0, AC3_MAX_CHANNELS);
793 790
794 /* block switch flags */ 791 /* block switch flags */
795 for (ch = 1; ch <= fbw_channels; ch++) { 792 for (ch = 1; ch <= fbw_channels; ch++)
796 ctx->block_switch[ch] = get_bits1(gb); 793 ctx->block_switch[ch] = get_bits1(gb);
797 any_block_switching |= ctx->block_switch[ch];
798 }
799 794
800 /* dithering flags */ 795 /* dithering flags */
801 ctx->dither_all = 1; 796 ctx->dither_all = 1;
802 for (ch = 1; ch <= fbw_channels; ch++) { 797 for (ch = 1; ch <= fbw_channels; ch++) {
803 ctx->dither_flag[ch] = get_bits1(gb); 798 ctx->dither_flag[ch] = get_bits1(gb);
1065 for(i=0; i<ctx->end_freq[ch]; i++) { 1060 for(i=0; i<ctx->end_freq[ch]; i++) {
1066 ctx->transform_coeffs[ch][i] *= gain; 1061 ctx->transform_coeffs[ch][i] *= gain;
1067 } 1062 }
1068 } 1063 }
1069 1064
1070 /* if no block switching is used, downmixing can be done before IMDCT */
1071 num_channels_bak = ctx->channels;
1072 fbw_channels_bak = ctx->fbw_channels;
1073 if(!any_block_switching) {
1074 if(ctx->channels != ctx->out_channels && !((ctx->output_mode & AC3_OUTPUT_LFEON) &&
1075 ctx->fbw_channels == ctx->out_channels)) {
1076 ac3_downmix(ctx->transform_coeffs, ctx->fbw_channels,
1077 ctx->output_mode, ctx->downmix_coeffs, 1);
1078 ctx->channels = ctx->out_channels;
1079 ctx->fbw_channels = ctx->channels - (ctx->output_mode & AC3_OUTPUT_LFEON);
1080 }
1081 }
1082
1083 do_imdct(ctx); 1065 do_imdct(ctx);
1084 1066
1085 /* downmix output now if it wasn't done before IMDCT */ 1067 /* downmix output if needed */
1086 if(ctx->channels != ctx->out_channels && !((ctx->output_mode & AC3_OUTPUT_LFEON) && 1068 if(ctx->channels != ctx->out_channels && !((ctx->output_mode & AC3_OUTPUT_LFEON) &&
1087 ctx->fbw_channels == ctx->out_channels)) { 1069 ctx->fbw_channels == ctx->out_channels)) {
1088 ac3_downmix(ctx->output, ctx->fbw_channels, ctx->output_mode, 1070 ac3_downmix(ctx->output, ctx->fbw_channels, ctx->output_mode,
1089 ctx->downmix_coeffs, 0); 1071 ctx->downmix_coeffs);
1090 } 1072 }
1091 1073
1092 /* convert float to 16-bit integer */ 1074 /* convert float to 16-bit integer */
1093 for(ch=0; ch<ctx->out_channels; ch++) { 1075 for(ch=0; ch<ctx->out_channels; ch++) {
1094 for(i=0; i<256; i++) { 1076 for(i=0; i<256; i++) {
1095 ctx->output[ch][i] += ctx->add_bias; 1077 ctx->output[ch][i] += ctx->add_bias;
1096 } 1078 }
1097 ctx->dsp.float_to_int16(ctx->int_output[ch], ctx->output[ch], 256); 1079 ctx->dsp.float_to_int16(ctx->int_output[ch], ctx->output[ch], 256);
1098 } 1080 }
1099
1100 ctx->channels = num_channels_bak;
1101 ctx->fbw_channels = fbw_channels_bak;
1102 1081
1103 return 0; 1082 return 0;
1104 } 1083 }
1105 1084
1106 /** 1085 /**