62 
62 
typedef struct AC3Block {

63 
63 
uint8_t **bap; ///< bit allocation pointers (bap)

64 
64 
CoefType **mdct_coef; ///< MDCT coefficients


65 
int32_t **fixed_coef; ///< fixedpoint MDCT coefficients

65 
66 
uint8_t **exp; ///< original exponents

66 
67 
uint8_t **grouped_exp; ///< grouped exponents

67 
68 
int16_t **psd; ///< psd per frequency bin

...  ...  
128 
129 
uint8_t *bap_buffer;

129 
130 
uint8_t *bap1_buffer;

130 
131 
CoefType *mdct_coef_buffer;


132 
int32_t *fixed_coef_buffer;

131 
133 
uint8_t *exp_buffer;

132 
134 
uint8_t *grouped_exp_buffer;

133 
135 
int16_t *psd_buffer;

...  ...  
153 
155 

154 
156 
static int normalize_samples(AC3EncodeContext *s);

155 
157 


158 
static void scale_coefficients(AC3EncodeContext *s);


159 

156 
160 

157 
161 
/**

158 
162 
* LUT for number of exponent groups.

...  ...  
286 
290 
for (blk = 0; blk < AC3_MAX_BLOCKS; blk++) {

287 
291 
AC3Block *block = &s>blocks[blk];

288 
292 
uint8_t *exp = block>exp[ch];

289 

CoefType *coef = block>mdct_coef[ch];


293 
int32_t *coef = block>fixed_coef[ch];

290 
294 
int exp_shift = block>exp_shift[ch];

291 
295 
for (i = 0; i < AC3_MAX_COEFS; i++) {

292 
296 
int e;

293 

int v = abs(SCALE_COEF(coef[i]));


297 
int v = abs(coef[i]);

294 
298 
if (v == 0)

295 
299 
e = 24;

296 
300 
else {

...  ...  
1017 
1021 
/**

1018 
1022 
* Quantize a set of mantissas for a single channel in a single block.

1019 
1023 
*/

1020 

static void quantize_mantissas_blk_ch(AC3EncodeContext *s, CoefType *mdct_coef,


1024 
static void quantize_mantissas_blk_ch(AC3EncodeContext *s, int32_t *fixed_coef,

1021 
1025 
int8_t exp_shift, uint8_t *exp,

1022 
1026 
uint8_t *bap, uint16_t *qmant, int n)

1023 
1027 
{

...  ...  
1025 
1029 

1026 
1030 
for (i = 0; i < n; i++) {

1027 
1031 
int v;

1028 

int c = SCALE_COEF(mdct_coef[i]);


1032 
int c = fixed_coef[i];

1029 
1033 
int e = exp[i]  exp_shift;

1030 
1034 
int b = bap[i];

1031 
1035 
switch (b) {

...  ...  
1122 
1126 
s>qmant1_ptr = s>qmant2_ptr = s>qmant4_ptr = NULL;

1123 
1127 

1124 
1128 
for (ch = 0; ch < s>channels; ch++) {

1125 

quantize_mantissas_blk_ch(s, block>mdct_coef[ch], block>exp_shift[ch],


1129 
quantize_mantissas_blk_ch(s, block>fixed_coef[ch], block>exp_shift[ch],

1126 
1130 
block>exp[ch], block>bap[ch],

1127 
1131 
block>qmant[ch], s>nb_coefs[ch]);

1128 
1132 
}

...  ...  
1390 
1394 

1391 
1395 
apply_mdct(s);

1392 
1396 


1397 
scale_coefficients(s);


1398 

1393 
1399 
process_exponents(s);

1394 
1400 

1395 
1401 
ret = compute_bit_allocation(s);

...  ...  
1420 
1426 
av_freep(&s>bap_buffer);

1421 
1427 
av_freep(&s>bap1_buffer);

1422 
1428 
av_freep(&s>mdct_coef_buffer);


1429 
av_freep(&s>fixed_coef_buffer);

1423 
1430 
av_freep(&s>exp_buffer);

1424 
1431 
av_freep(&s>grouped_exp_buffer);

1425 
1432 
av_freep(&s>psd_buffer);

...  ...  
1430 
1437 
AC3Block *block = &s>blocks[blk];

1431 
1438 
av_freep(&block>bap);

1432 
1439 
av_freep(&block>mdct_coef);


1440 
av_freep(&block>fixed_coef);

1433 
1441 
av_freep(&block>exp);

1434 
1442 
av_freep(&block>grouped_exp);

1435 
1443 
av_freep(&block>psd);

...  ...  
1639 
1647 
}

1640 
1648 
}

1641 
1649 


1650 
if (CONFIG_AC3ENC_FLOAT) {


1651 
FF_ALLOC_OR_GOTO(avctx, s>fixed_coef_buffer, AC3_MAX_BLOCKS * s>channels *


1652 
AC3_MAX_COEFS * sizeof(*s>fixed_coef_buffer), alloc_fail);


1653 
for (blk = 0; blk < AC3_MAX_BLOCKS; blk++) {


1654 
AC3Block *block = &s>blocks[blk];


1655 
FF_ALLOCZ_OR_GOTO(avctx, block>fixed_coef, s>channels *


1656 
sizeof(*block>fixed_coef), alloc_fail);


1657 
for (ch = 0; ch < s>channels; ch++)


1658 
block>fixed_coef[ch] = &s>fixed_coef_buffer[AC3_MAX_COEFS * (blk * s>channels + ch)];


1659 
}


1660 
} else {


1661 
for (blk = 0; blk < AC3_MAX_BLOCKS; blk++) {


1662 
AC3Block *block = &s>blocks[blk];


1663 
FF_ALLOCZ_OR_GOTO(avctx, block>fixed_coef, s>channels *


1664 
sizeof(*block>fixed_coef), alloc_fail);


1665 
for (ch = 0; ch < s>channels; ch++)


1666 
block>fixed_coef[ch] = (int32_t *)block>mdct_coef[ch];


1667 
}


1668 
}


1669 

1642 
1670 
return 0;

1643 
1671 
alloc_fail:

1644 
1672 
return AVERROR(ENOMEM);
