Revision 7e0a284b
libavcodec/ac3enc.c | ||
---|---|---|
78 | 78 |
int16_t **band_psd; ///< psd per critical band |
79 | 79 |
int16_t **mask; ///< masking curve |
80 | 80 |
uint16_t **qmant; ///< quantized mantissas |
81 |
int8_t exp_shift[AC3_MAX_CHANNELS]; ///< exponent shift values
|
|
81 |
int8_t coeff_shift[AC3_MAX_CHANNELS]; ///< fixed-point coefficient shift values
|
|
82 | 82 |
uint8_t new_rematrixing_strategy; ///< send new rematrixing flags in this block |
83 | 83 |
uint8_t rematrixing_flags[4]; ///< rematrixing flags |
84 | 84 |
} AC3Block; |
... | ... | |
269 | 269 |
|
270 | 270 |
apply_window(&s->dsp, s->windowed_samples, input_samples, s->mdct.window, AC3_WINDOW_SIZE); |
271 | 271 |
|
272 |
block->exp_shift[ch] = normalize_samples(s);
|
|
272 |
block->coeff_shift[ch] = normalize_samples(s);
|
|
273 | 273 |
|
274 | 274 |
mdct512(&s->mdct, block->mdct_coef[ch], s->windowed_samples); |
275 | 275 |
} |
... | ... | |
416 | 416 |
AC3Block *block = &s->blocks[blk]; |
417 | 417 |
uint8_t *exp = block->exp[ch]; |
418 | 418 |
int32_t *coef = block->fixed_coef[ch]; |
419 |
int exp_shift = block->exp_shift[ch]; |
|
420 | 419 |
for (i = 0; i < AC3_MAX_COEFS; i++) { |
421 | 420 |
int e; |
422 | 421 |
int v = abs(coef[i]); |
423 | 422 |
if (v == 0) |
424 | 423 |
e = 24; |
425 | 424 |
else { |
426 |
e = 23 - av_log2(v) + exp_shift;
|
|
425 |
e = 23 - av_log2(v); |
|
427 | 426 |
if (e >= 24) { |
428 | 427 |
e = 24; |
429 | 428 |
coef[i] = 0; |
... | ... | |
1139 | 1138 |
* Quantize a set of mantissas for a single channel in a single block. |
1140 | 1139 |
*/ |
1141 | 1140 |
static void quantize_mantissas_blk_ch(AC3EncodeContext *s, int32_t *fixed_coef, |
1142 |
int8_t exp_shift, uint8_t *exp,
|
|
1141 |
uint8_t *exp, |
|
1143 | 1142 |
uint8_t *bap, uint16_t *qmant, int n) |
1144 | 1143 |
{ |
1145 | 1144 |
int i; |
... | ... | |
1147 | 1146 |
for (i = 0; i < n; i++) { |
1148 | 1147 |
int v; |
1149 | 1148 |
int c = fixed_coef[i]; |
1150 |
int e = exp[i] - exp_shift;
|
|
1149 |
int e = exp[i]; |
|
1151 | 1150 |
int b = bap[i]; |
1152 | 1151 |
switch (b) { |
1153 | 1152 |
case 0: |
... | ... | |
1243 | 1242 |
s->qmant1_ptr = s->qmant2_ptr = s->qmant4_ptr = NULL; |
1244 | 1243 |
|
1245 | 1244 |
for (ch = 0; ch < s->channels; ch++) { |
1246 |
quantize_mantissas_blk_ch(s, block->fixed_coef[ch], block->exp_shift[ch],
|
|
1245 |
quantize_mantissas_blk_ch(s, block->fixed_coef[ch], |
|
1247 | 1246 |
block->exp[ch], block->bap[ch], |
1248 | 1247 |
block->qmant[ch], s->nb_coefs[ch]); |
1249 | 1248 |
} |
libavcodec/ac3enc_fixed.c | ||
---|---|---|
295 | 295 |
|
296 | 296 |
|
297 | 297 |
/** |
298 |
* Shift each value in an array by a specified amount. |
|
299 |
* @param src input array |
|
300 |
* @param n number of values in the array |
|
301 |
* @param shift shift amount (negative=right, positive=left) |
|
302 |
*/ |
|
303 |
static void shift_int32(int32_t *src, int n, int shift) |
|
304 |
{ |
|
305 |
int i; |
|
306 |
|
|
307 |
if (shift > 0) { |
|
308 |
for (i = 0; i < n; i++) |
|
309 |
src[i] <<= shift; |
|
310 |
} else if (shift < 0) { |
|
311 |
shift = -shift; |
|
312 |
for (i = 0; i < n; i++) |
|
313 |
src[i] >>= shift; |
|
314 |
} |
|
315 |
} |
|
316 |
|
|
317 |
|
|
318 |
/** |
|
298 | 319 |
* Normalize the input samples to use the maximum available precision. |
299 |
* This assumes signed 16-bit input samples. Exponents are reduced by 9 to |
|
300 |
* match the 24-bit internal precision for MDCT coefficients. |
|
320 |
* This assumes signed 16-bit input samples. |
|
301 | 321 |
* |
302 |
* @return exponent shift
|
|
322 |
* @return coefficient shift
|
|
303 | 323 |
*/ |
304 | 324 |
static int normalize_samples(AC3EncodeContext *s) |
305 | 325 |
{ |
306 | 326 |
int v = 14 - log2_tab(s, s->windowed_samples, AC3_WINDOW_SIZE); |
307 | 327 |
lshift_tab(s->windowed_samples, AC3_WINDOW_SIZE, v); |
308 |
return v - 9;
|
|
328 |
return 9 - v;
|
|
309 | 329 |
} |
310 | 330 |
|
311 | 331 |
|
312 | 332 |
/** |
313 |
* Scale MDCT coefficients from float to fixed-point.
|
|
333 |
* Scale MDCT coefficients to 24-bit fixed-point.
|
|
314 | 334 |
*/ |
315 | 335 |
static void scale_coefficients(AC3EncodeContext *s) |
316 | 336 |
{ |
317 |
/* scaling/conversion is obviously not needed for the fixed-point encoder |
|
318 |
since the coefficients are already fixed-point. */ |
|
319 |
return; |
|
337 |
int blk, ch; |
|
338 |
|
|
339 |
for (blk = 0; blk < AC3_MAX_BLOCKS; blk++) { |
|
340 |
AC3Block *block = &s->blocks[blk]; |
|
341 |
for (ch = 0; ch < s->channels; ch++) { |
|
342 |
shift_int32(block->mdct_coef[ch], AC3_MAX_COEFS, |
|
343 |
block->coeff_shift[ch]); |
|
344 |
} |
|
345 |
} |
|
320 | 346 |
} |
321 | 347 |
|
322 | 348 |
|
tests/ref/acodec/ac3_fixed | ||
---|---|---|
1 |
07bd593823ebd721b3a32ef298bdfc20 *./tests/data/acodec/ac3.rm
|
|
1 |
5f1255da35a4ed00a2e932887c9aef77 *./tests/data/acodec/ac3.rm
|
|
2 | 2 |
98751 ./tests/data/acodec/ac3.rm |
Also available in: Unified diff