Skip to content
Snippets Groups Projects
Commit 25dcd182 authored by Justin Ruggles's avatar Justin Ruggles
Browse files

ac3dec: simplify zero-bit mantissa dithering by calculating it

conditionally during mantissa decoding, then only removing it from the
coupling range for coupled channels which do not use dithering.

Originally committed as revision 19588 to svn://svn.ffmpeg.org/ffmpeg/trunk
parent b972c06a
No related branches found
No related tags found
No related merge requests found
...@@ -452,6 +452,7 @@ static void ac3_decode_transform_coeffs_ch(AC3DecodeContext *s, int ch_index, ma ...@@ -452,6 +452,7 @@ static void ac3_decode_transform_coeffs_ch(AC3DecodeContext *s, int ch_index, ma
uint8_t *baps = s->bap[ch_index]; uint8_t *baps = s->bap[ch_index];
int8_t *exps = s->dexps[ch_index]; int8_t *exps = s->dexps[ch_index];
int *coeffs = s->fixed_coeffs[ch_index]; int *coeffs = s->fixed_coeffs[ch_index];
int dither = (ch_index == CPL_CH) || s->dither_flag[ch_index];
GetBitContext *gbc = &s->gbc; GetBitContext *gbc = &s->gbc;
int freq; int freq;
...@@ -460,7 +461,10 @@ static void ac3_decode_transform_coeffs_ch(AC3DecodeContext *s, int ch_index, ma ...@@ -460,7 +461,10 @@ static void ac3_decode_transform_coeffs_ch(AC3DecodeContext *s, int ch_index, ma
int mantissa; int mantissa;
switch(bap){ switch(bap){
case 0: case 0:
if (dither)
mantissa = (av_lfg_get(&s->dith_state) & 0x7FFFFF) - 0x400000; mantissa = (av_lfg_get(&s->dith_state) & 0x7FFFFF) - 0x400000;
else
mantissa = 0;
break; break;
case 1: case 1:
if(m->b1){ if(m->b1){
...@@ -517,33 +521,18 @@ static void ac3_decode_transform_coeffs_ch(AC3DecodeContext *s, int ch_index, ma ...@@ -517,33 +521,18 @@ static void ac3_decode_transform_coeffs_ch(AC3DecodeContext *s, int ch_index, ma
} }
/** /**
* Remove random dithering from coefficients with zero-bit mantissas * Remove random dithering from coupling range coefficients with zero-bit
* mantissas for coupled channels which do not use dithering.
* reference: Section 7.3.4 Dither for Zero Bit Mantissas (bap=0) * reference: Section 7.3.4 Dither for Zero Bit Mantissas (bap=0)
*/ */
static void remove_dithering(AC3DecodeContext *s) { static void remove_dithering(AC3DecodeContext *s) {
int ch, i; int ch, i;
int end=0;
int *coeffs;
uint8_t *bap;
for(ch=1; ch<=s->fbw_channels; ch++) { for(ch=1; ch<=s->fbw_channels; ch++) {
if(!s->dither_flag[ch]) { if(!s->dither_flag[ch] && s->channel_in_cpl[ch]) {
coeffs = s->fixed_coeffs[ch]; for(i = s->start_freq[CPL_CH]; i<s->end_freq[CPL_CH]; i++) {
bap = s->bap[ch]; if(!s->bap[CPL_CH][i])
if(s->channel_in_cpl[ch]) s->fixed_coeffs[ch][i] = 0;
end = s->start_freq[CPL_CH];
else
end = s->end_freq[ch];
for(i=0; i<end; i++) {
if(!bap[i])
coeffs[i] = 0;
}
if(s->channel_in_cpl[ch]) {
bap = s->bap[CPL_CH];
for(; i<s->end_freq[CPL_CH]; i++) {
if(!bap[i])
coeffs[i] = 0;
}
} }
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment