Revision 7e0a284b libavcodec/ac3enc_fixed.c

View differences:

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

  

Also available in: Unified diff