static void mdct512(AC3MDCTContext *mdct, CoefType *out, SampleType *in);
-static void apply_window(SampleType *output, const SampleType *input,
+static void apply_window(DSPContext *dsp, SampleType *output, const SampleType *input,
const SampleType *window, int n);
static int normalize_samples(AC3EncodeContext *s);
AC3Block *block = &s->blocks[blk];
const SampleType *input_samples = &s->planar_samples[ch][blk * AC3_BLOCK_SIZE];
- apply_window(s->windowed_samples, input_samples, s->mdct.window, AC3_WINDOW_SIZE);
+ apply_window(&s->dsp, s->windowed_samples, input_samples, s->mdct.window, AC3_WINDOW_SIZE);
block->exp_shift[ch] = normalize_samples(s);
* Calculate exponent strategies for all blocks in a single channel.
*/
static void compute_exp_strategy_ch(AC3EncodeContext *s, uint8_t *exp_strategy,
- uint8_t **exp)
+ 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] = EXP_NEW;
+ exp += AC3_MAX_COEFS;
for (blk = 1; blk < AC3_MAX_BLOCKS; blk++) {
- exp_diff = s->dsp.sad[0](NULL, exp[blk], exp[blk-1], 16, 16);
+ exp_diff = s->dsp.sad[0](NULL, exp, exp - AC3_MAX_COEFS, 16, 16);
if (exp_diff > EXP_DIFF_THRESHOLD)
exp_strategy[blk] = EXP_NEW;
else
exp_strategy[blk] = EXP_REUSE;
+ exp += AC3_MAX_COEFS;
}
emms_c();
*/
static void compute_exp_strategy(AC3EncodeContext *s)
{
- 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->fbw_channels; ch++) {
- for (blk = 0; blk < AC3_MAX_BLOCKS; blk++) {
- exp1[ch][blk] = s->blocks[blk].exp[ch];
- exp_str1[ch][blk] = s->exp_strategy[ch][blk];
- }
-
- compute_exp_strategy_ch(s, exp_str1[ch], exp1[ch]);
-
- for (blk = 0; blk < AC3_MAX_BLOCKS; blk++)
- s->exp_strategy[ch][blk] = exp_str1[ch][blk];
+ compute_exp_strategy_ch(s, s->exp_strategy[ch], s->blocks[0].exp[ch]);
}
if (s->lfe_on) {
ch = s->lfe_channel;
/**
* Set each encoded exponent in a block to the minimum of itself and the
- * exponent in the same frequency bin of a following block.
- * exp[i] = min(exp[i], exp1[i]
+ * exponents in the same frequency bin of up to 5 following blocks.
*/
-static void exponent_min(uint8_t *exp, uint8_t *exp1, int n)
+static void exponent_min(uint8_t *exp, int num_reuse_blocks, int nb_coefs)
{
- int i;
- for (i = 0; i < n; i++) {
- if (exp1[i] < exp[i])
- exp[i] = exp1[i];
+ int blk, i;
+
+ if (!num_reuse_blocks)
+ return;
+
+ for (i = 0; i < nb_coefs; i++) {
+ uint8_t min_exp = *exp;
+ uint8_t *exp1 = exp + AC3_MAX_COEFS;
+ for (blk = 0; blk < num_reuse_blocks; blk++) {
+ uint8_t next_exp = *exp1;
+ if (next_exp < min_exp)
+ min_exp = next_exp;
+ exp1 += AC3_MAX_COEFS;
+ }
+ *exp++ = min_exp;
}
}
*/
static void encode_exponents(AC3EncodeContext *s)
{
- int blk, blk1, blk2, ch;
- AC3Block *block, *block1, *block2;
+ int blk, blk1, ch;
+ uint8_t *exp, *exp1, *exp_strategy;
+ int nb_coefs, num_reuse_blocks;
for (ch = 0; ch < s->channels; ch++) {
+ exp = s->blocks[0].exp[ch];
+ exp_strategy = s->exp_strategy[ch];
+ nb_coefs = s->nb_coefs[ch];
+
blk = 0;
- block = &s->blocks[0];
while (blk < AC3_MAX_BLOCKS) {
blk1 = blk + 1;
- block1 = block + 1;
- /* for the EXP_REUSE case we select the min of the exponents */
- while (blk1 < AC3_MAX_BLOCKS && s->exp_strategy[ch][blk1] == EXP_REUSE) {
- exponent_min(block->exp[ch], block1->exp[ch], s->nb_coefs[ch]);
+
+ /* count the number of EXP_REUSE blocks after the current block */
+ while (blk1 < AC3_MAX_BLOCKS && exp_strategy[blk1] == EXP_REUSE)
blk1++;
- block1++;
- }
- encode_exponents_blk_ch(block->exp[ch], s->nb_coefs[ch],
- s->exp_strategy[ch][blk]);
+ num_reuse_blocks = blk1 - blk - 1;
+
+ /* for the EXP_REUSE case we select the min of the exponents */
+ exponent_min(exp, num_reuse_blocks, nb_coefs);
+
+ encode_exponents_blk_ch(exp, nb_coefs, exp_strategy[blk]);
+
/* copy encoded exponents for reuse case */
- block2 = block + 1;
- for (blk2 = blk+1; blk2 < blk1; blk2++, block2++) {
- memcpy(block2->exp[ch], block->exp[ch],
- s->nb_coefs[ch] * sizeof(uint8_t));
+ exp1 = exp + AC3_MAX_COEFS;
+ while (blk < blk1-1) {
+ memcpy(exp1, exp, nb_coefs * sizeof(*exp));
+ exp1 += AC3_MAX_COEFS;
+ blk++;
}
blk = blk1;
- block = block1;
+ exp = exp1;
}
}
}
avctx->frame_size = AC3_FRAME_SIZE;
- ac3_common_init();
+ ff_ac3_common_init();
ret = validate_options(avctx, s);
if (ret)