---
libavcodec/ac3enc.c | 112 +++++++++++++++++++++++++-------------------------
1 files changed, 56 insertions(+), 56 deletions(-)
diff --git libavcodec/ac3enc.c libavcodec/ac3enc.c
index a32acc8..26178ca 100644
--- libavcodec/ac3enc.c
+++ libavcodec/ac3enc.c
@@ -262,43 +262,43 @@ static void compute_exp_strategy(uint8_t exp_strategy[AC3_MAX_BLOCKS][AC3_MAX_CH
uint8_t exp[AC3_MAX_BLOCKS][AC3_MAX_CHANNELS][AC3_MAX_COEFS],
int ch, int is_lfe)
{
- int i, j;
+ 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;
- for (i = 1; i < AC3_MAX_BLOCKS; i++) {
- exp_diff = calc_exp_diff(exp[i][ch], exp[i-1][ch], AC3_MAX_COEFS);
+ for (blk = 1; blk < AC3_MAX_BLOCKS; blk++) {
+ exp_diff = calc_exp_diff(exp[blk][ch], exp[blk-1][ch], AC3_MAX_COEFS);
dprintf(NULL, "exp_diff=%d\n", exp_diff);
if (exp_diff > EXP_DIFF_THRESHOLD)
- exp_strategy[i][ch] = EXP_NEW;
+ exp_strategy[blk][ch] = EXP_NEW;
else
- exp_strategy[i][ch] = EXP_REUSE;
+ exp_strategy[blk][ch] = EXP_REUSE;
}
if (is_lfe)
return;
/* now select the encoding strategy type : if exponents are often
recoded, we use a coarse encoding */
- i = 0;
- while (i < AC3_MAX_BLOCKS) {
- j = i + 1;
- while (j < AC3_MAX_BLOCKS && exp_strategy[j][ch] == EXP_REUSE)
- j++;
- switch(j - i) {
+ blk = 0;
+ while (blk < AC3_MAX_BLOCKS) {
+ blk1 = blk + 1;
+ while (blk1 < AC3_MAX_BLOCKS && exp_strategy[blk1][ch] == EXP_REUSE)
+ blk1++;
+ switch(blk1 - blk) {
case 1:
- exp_strategy[i][ch] = EXP_D45;
+ exp_strategy[blk][ch] = EXP_D45;
break;
case 2:
case 3:
- exp_strategy[i][ch] = EXP_D25;
+ exp_strategy[blk][ch] = EXP_D25;
break;
default:
- exp_strategy[i][ch] = EXP_D15;
+ exp_strategy[blk][ch] = EXP_D15;
break;
}
- i = j;
+ blk = blk1;
}
}
@@ -464,22 +464,22 @@ static int bit_alloc(AC3EncodeContext *s,
uint8_t bap[AC3_MAX_BLOCKS][AC3_MAX_CHANNELS][AC3_MAX_COEFS],
int frame_bits, int coarse_snr_offset, int fine_snr_offset)
{
- int i, ch;
+ int blk, ch;
int snr_offset;
snr_offset = (((coarse_snr_offset - 15) << 4) + fine_snr_offset) << 2;
/* compute size */
- for (i = 0; i < AC3_MAX_BLOCKS; i++) {
+ for (blk = 0; blk < AC3_MAX_BLOCKS; blk++) {
s->mant1_cnt = 0;
s->mant2_cnt = 0;
s->mant4_cnt = 0;
for (ch = 0; ch < s->channels; ch++) {
- ff_ac3_bit_alloc_calc_bap(mask[i][ch], psd[i][ch], 0,
+ ff_ac3_bit_alloc_calc_bap(mask[blk][ch], psd[blk][ch], 0,
s->nb_coefs[ch], snr_offset,
s->bit_alloc.floor, ff_ac3_bap_tab,
- bap[i][ch]);
- frame_bits += compute_mantissa_size(s, bap[i][ch], s->nb_coefs[ch]);
+ bap[blk][ch]);
+ frame_bits += compute_mantissa_size(s, bap[blk][ch], s->nb_coefs[ch]);
}
}
#if 0
@@ -498,7 +498,7 @@ static int compute_bit_allocation(AC3EncodeContext *s,
uint8_t exp_strategy[AC3_MAX_BLOCKS][AC3_MAX_CHANNELS],
int frame_bits)
{
- int i, ch;
+ int blk, ch;
int coarse_snr_offset, fine_snr_offset;
uint8_t bap1[AC3_MAX_BLOCKS][AC3_MAX_CHANNELS][AC3_MAX_COEFS];
int16_t psd[AC3_MAX_BLOCKS][AC3_MAX_CHANNELS][AC3_MAX_COEFS];
@@ -528,17 +528,17 @@ static int compute_bit_allocation(AC3EncodeContext *s,
frame_bits += frame_bits_inc[s->channel_mode];
/* audio blocks */
- for (i = 0; i < AC3_MAX_BLOCKS; i++) {
+ for (blk = 0; blk < AC3_MAX_BLOCKS; blk++) {
frame_bits += s->fbw_channels * 2 + 2; /* blksw * c, dithflag * c, dynrnge, cplstre */
if (s->channel_mode == AC3_CHMODE_STEREO) {
frame_bits++; /* rematstr */
- if (i == 0) frame_bits += 4;
+ if (blk == 0) frame_bits += 4;
}
frame_bits += 2 * s->fbw_channels; /* chexpstr[2] * c */
if (s->lfe_on)
frame_bits++; /* lfeexpstr */
for (ch = 0; ch < s->fbw_channels; ch++) {
- if (exp_strategy[i][ch] != EXP_REUSE)
+ if (exp_strategy[blk][ch] != EXP_REUSE)
frame_bits += 6 + 2; /* chbwcod[6], gainrng[2] */
}
frame_bits++; /* baie */
@@ -603,9 +603,8 @@ static int compute_bit_allocation(AC3EncodeContext *s,
s->fine_snr_offset[ch] = fine_snr_offset;
#ifdef DEBUG_BITALLOC
{
- int blk;
-
- for (blk = 0; blk < AC3_MAX_BLOCKS; i++) {
+ int i;
+ for (blk = 0; blk < AC3_MAX_BLOCKS; blk++) {
for (ch = 0; ch < s->channels; ch++) {
dprintf(s->avctx, "bap[blk=%d][ch=%d]=", blk, ch);
for (i = 0; i < s->nb_coefs[ch]; i++)
@@ -1184,7 +1183,7 @@ static int AC3_encode_frame(AVCodecContext *avctx,
unsigned char *frame, int buf_size, void *data)
{
AC3EncodeContext *s = avctx->priv_data;
- int i, j, k, v, ch;
+ int blk, i, v, ch;
int32_t mdct_coef[AC3_MAX_BLOCKS][AC3_MAX_CHANNELS][AC3_MAX_COEFS];
uint8_t exp[AC3_MAX_BLOCKS][AC3_MAX_CHANNELS][AC3_MAX_COEFS];
uint8_t exp_strategy[AC3_MAX_BLOCKS][AC3_MAX_CHANNELS];
@@ -1197,40 +1196,40 @@ static int AC3_encode_frame(AVCodecContext *avctx,
frame_bits = 0;
for (ch = 0; ch < s->channels; ch++) {
/* fixed mdct to the six sub blocks & exponent computation */
- for (i = 0; i < AC3_MAX_BLOCKS; i++) {
- int16_t *input_samples = &s->planar_samples[ch][i * AC3_BLOCK_SIZE];
+ for (blk = 0; blk < AC3_MAX_BLOCKS; blk++) {
+ int16_t *input_samples = &s->planar_samples[ch][blk * AC3_BLOCK_SIZE];
/* apply the MDCT window */
- for (j = 0; j < AC3_BLOCK_SIZE; j++) {
- s->windowed_samples[j] = MUL16(input_samples[j],
- ff_ac3_window[j]) >> 15;
- s->windowed_samples[AC3_BLOCK_SIZE*2-j-1] = MUL16(input_samples[AC3_BLOCK_SIZE*2-j-1],
- ff_ac3_window[j]) >> 15;
+ for (i = 0; i < AC3_BLOCK_SIZE; i++) {
+ s->windowed_samples[i] = MUL16(input_samples[i],
+ ff_ac3_window[i]) >> 15;
+ s->windowed_samples[AC3_BLOCK_SIZE*2-i-1] = MUL16(input_samples[AC3_BLOCK_SIZE*2-i-1],
+ ff_ac3_window[i]) >> 15;
}
/* Normalize the samples to use the maximum available precision */
v = 14 - log2_tab(s->windowed_samples, AC3_BLOCK_SIZE*2);
v = FFMAX(0, v);
- exp_shift[i][ch] = v - 9;
+ exp_shift[blk][ch] = v - 9;
lshift_tab(s->windowed_samples, AC3_BLOCK_SIZE*2, v);
/* do the MDCT */
- mdct512(mdct_coef[i][ch], s->windowed_samples);
+ mdct512(mdct_coef[blk][ch], s->windowed_samples);
/* compute "exponents". We take into account the normalization there */
- for (j = 0; j < AC3_MAX_COEFS; j++) {
+ for (i = 0; i < AC3_MAX_COEFS; i++) {
int e;
- v = abs(mdct_coef[i][ch][j]);
+ v = abs(mdct_coef[blk][ch][i]);
if (v == 0)
e = 24;
else {
- e = 23 - av_log2(v) + exp_shift[i][ch];
+ e = 23 - av_log2(v) + exp_shift[blk][ch];
if (e >= 24) {
e = 24;
- mdct_coef[i][ch][j] = 0;
+ mdct_coef[blk][ch][i] = 0;
}
}
- exp[i][ch][j] = e;
+ exp[blk][ch][i] = e;
}
}
@@ -1239,21 +1238,22 @@ static int AC3_encode_frame(AVCodecContext *avctx,
/* compute the exponents as the decoder will see them. The
EXP_REUSE case must be handled carefully : we select the
min of the exponents */
- i = 0;
- while (i < AC3_MAX_BLOCKS) {
- j = i + 1;
- while (j < AC3_MAX_BLOCKS && exp_strategy[j][ch] == EXP_REUSE) {
- exponent_min(exp[i][ch], exp[j][ch], s->nb_coefs[ch]);
- j++;
+ blk = 0;
+ while (blk < AC3_MAX_BLOCKS) {
+ int blk2;
+ int blk1 = blk + 1;
+ while (blk1 < AC3_MAX_BLOCKS && exp_strategy[blk1][ch] == EXP_REUSE) {
+ exponent_min(exp[blk][ch], exp[blk1][ch], s->nb_coefs[ch]);
+ blk1++;
}
- frame_bits += encode_exp(exp[i][ch], s->nb_coefs[ch],
- exp_strategy[i][ch]);
+ frame_bits += encode_exp(exp[blk][ch], s->nb_coefs[ch],
+ exp_strategy[blk][ch]);
/* copy encoded exponents for reuse case */
- for (k = i+1; k < j; k++) {
- memcpy(exp[k][ch], exp[i][ch],
+ for (blk2 = blk+1; blk2 < blk1; blk2++) {
+ memcpy(exp[blk2][ch], exp[blk][ch],
s->nb_coefs[ch] * sizeof(uint8_t));
}
- i = j;
+ blk = blk1;
}
}
@@ -1270,9 +1270,9 @@ static int AC3_encode_frame(AVCodecContext *avctx,
/* everything is known... let's output the frame */
output_frame_header(s, frame);
- for (i = 0; i < AC3_MAX_BLOCKS; i++) {
- output_audio_block(s, exp_strategy[i], exp[i], bap[i],
- mdct_coef[i], exp_shift[i], i);
+ for (blk = 0; blk < AC3_MAX_BLOCKS; blk++) {
+ output_audio_block(s, exp_strategy[blk], exp[blk], bap[blk],
+ mdct_coef[blk], exp_shift[blk], blk);
}
return output_frame_end(s);
}
_______________________________________________
FFmpeg-soc mailing list
[email protected]
https://lists.mplayerhq.hu/mailman/listinfo/ffmpeg-soc