summaryrefslogtreecommitdiff
path: root/libavcodec/ac3enc.c
diff options
context:
space:
mode:
authorJustin Ruggles <justin.ruggles@gmail.com>2010-12-14 14:53:17 +0000
committerJustin Ruggles <justin.ruggles@gmail.com>2010-12-14 14:53:17 +0000
commitd7da80806cc4ea91e4de37feae49fc2ac202bd20 (patch)
treea14614871c90be1ae5e1c15e60698e71395adf0e /libavcodec/ac3enc.c
parent67d979fedef3b302693da10bcadf0dee3f6cda99 (diff)
Reverse the exponent & exponent strategy array arrangement to simplify the
per-channel exponent strategy decision. This will also make it easier to plug-in other exponent strategy algorithms. Originally committed as revision 25995 to svn://svn.ffmpeg.org/ffmpeg/trunk
Diffstat (limited to 'libavcodec/ac3enc.c')
-rw-r--r--libavcodec/ac3enc.c45
1 files changed, 29 insertions, 16 deletions
diff --git a/libavcodec/ac3enc.c b/libavcodec/ac3enc.c
index ca201604b3..34fc9a4ebc 100644
--- a/libavcodec/ac3enc.c
+++ b/libavcodec/ac3enc.c
@@ -485,38 +485,34 @@ static int calc_exp_diff(uint8_t *exp1, uint8_t *exp2, int n)
/**
* Calculate exponent strategies for all blocks in a single channel.
*/
-static void compute_exp_strategy_ch(uint8_t exp_strategy[AC3_MAX_BLOCKS][AC3_MAX_CHANNELS],
- uint8_t exp[AC3_MAX_BLOCKS][AC3_MAX_CHANNELS][AC3_MAX_COEFS],
- int ch, int is_lfe)
+static void compute_exp_strategy_ch(uint8_t *exp_strategy, uint8_t **exp)
{
int blk, blk1;
int exp_diff;
/* estimate if the exponent variation & decide if they should be
reused in the next frame */
- exp_strategy[0][ch] = EXP_NEW;
+ exp_strategy[0] = EXP_NEW;
for (blk = 1; blk < AC3_MAX_BLOCKS; blk++) {
- exp_diff = calc_exp_diff(exp[blk][ch], exp[blk-1][ch], AC3_MAX_COEFS);
+ exp_diff = calc_exp_diff(exp[blk], exp[blk-1], AC3_MAX_COEFS);
if (exp_diff > EXP_DIFF_THRESHOLD)
- exp_strategy[blk][ch] = EXP_NEW;
+ exp_strategy[blk] = EXP_NEW;
else
- exp_strategy[blk][ch] = EXP_REUSE;
+ exp_strategy[blk] = EXP_REUSE;
}
- if (is_lfe)
- return;
/* now select the encoding strategy type : if exponents are often
recoded, we use a coarse encoding */
blk = 0;
while (blk < AC3_MAX_BLOCKS) {
blk1 = blk + 1;
- while (blk1 < AC3_MAX_BLOCKS && exp_strategy[blk1][ch] == EXP_REUSE)
+ while (blk1 < AC3_MAX_BLOCKS && exp_strategy[blk1] == EXP_REUSE)
blk1++;
switch (blk1 - blk) {
- case 1: exp_strategy[blk][ch] = EXP_D45; break;
+ case 1: exp_strategy[blk] = EXP_D45; break;
case 2:
- case 3: exp_strategy[blk][ch] = EXP_D25; break;
- default: exp_strategy[blk][ch] = EXP_D15; break;
+ case 3: exp_strategy[blk] = EXP_D25; break;
+ default: exp_strategy[blk] = EXP_D15; break;
}
blk = blk1;
}
@@ -525,15 +521,32 @@ static void compute_exp_strategy_ch(uint8_t exp_strategy[AC3_MAX_BLOCKS][AC3_MAX
/**
* Calculate exponent strategies for all channels.
+ * Array arrangement is reversed to simplify the per-channel calculation.
*/
static void compute_exp_strategy(AC3EncodeContext *s,
uint8_t exp_strategy[AC3_MAX_BLOCKS][AC3_MAX_CHANNELS],
uint8_t exp[AC3_MAX_BLOCKS][AC3_MAX_CHANNELS][AC3_MAX_COEFS])
{
- int ch;
+ uint8_t *exp1[AC3_MAX_CHANNELS][AC3_MAX_BLOCKS];
+ uint8_t exp_str1[AC3_MAX_CHANNELS][AC3_MAX_BLOCKS];
+ int ch, blk;
- for (ch = 0; ch < s->channels; ch++) {
- compute_exp_strategy_ch(exp_strategy, exp, ch, ch == s->lfe_channel);
+ for (ch = 0; ch < s->fbw_channels; ch++) {
+ for (blk = 0; blk < AC3_MAX_BLOCKS; blk++) {
+ exp1[ch][blk] = exp[blk][ch];
+ exp_str1[ch][blk] = exp_strategy[blk][ch];
+ }
+
+ compute_exp_strategy_ch(exp_str1[ch], exp1[ch]);
+
+ for (blk = 0; blk < AC3_MAX_BLOCKS; blk++)
+ exp_strategy[blk][ch] = exp_str1[ch][blk];
+ }
+ if (s->lfe_on) {
+ ch = s->lfe_channel;
+ exp_strategy[0][ch] = EXP_D15;
+ for (blk = 1; blk < 5; blk++)
+ exp_strategy[blk][ch] = EXP_REUSE;
}
}