Mercurial > libavcodec.hg
comparison ac3dec.c @ 5336:cc3f5a28aa2a libavcodec
fix the 256-point MDCT
author | jbr |
---|---|
date | Sun, 15 Jul 2007 14:47:39 +0000 |
parents | 8ecef197b08e |
children | 69eac3e47b9a |
comparison
equal
deleted
inserted
replaced
5335:8ecef197b08e | 5336:cc3f5a28aa2a |
---|---|
82 | 82 |
83 static const float clevs[4] = { LEVEL_MINUS_3DB, LEVEL_MINUS_4POINT5DB, | 83 static const float clevs[4] = { LEVEL_MINUS_3DB, LEVEL_MINUS_4POINT5DB, |
84 LEVEL_MINUS_6DB, LEVEL_MINUS_4POINT5DB }; | 84 LEVEL_MINUS_6DB, LEVEL_MINUS_4POINT5DB }; |
85 | 85 |
86 static const float slevs[4] = { LEVEL_MINUS_3DB, LEVEL_MINUS_6DB, LEVEL_ZERO, LEVEL_MINUS_6DB }; | 86 static const float slevs[4] = { LEVEL_MINUS_3DB, LEVEL_MINUS_6DB, LEVEL_ZERO, LEVEL_MINUS_6DB }; |
87 | |
88 #define N 512 /* constant for IMDCT Block size */ | |
89 | 87 |
90 #define BLOCK_SIZE 256 | 88 #define BLOCK_SIZE 256 |
91 | 89 |
92 /* Output and input configurations. */ | 90 /* Output and input configurations. */ |
93 #define AC3_OUTPUT_UNMODIFIED 0x01 | 91 #define AC3_OUTPUT_UNMODIFIED 0x01 |
1377 /* This function performs the imdct on 256 sample transform | 1375 /* This function performs the imdct on 256 sample transform |
1378 * coefficients. | 1376 * coefficients. |
1379 */ | 1377 */ |
1380 static void do_imdct_256(AC3DecodeContext *ctx, int chindex) | 1378 static void do_imdct_256(AC3DecodeContext *ctx, int chindex) |
1381 { | 1379 { |
1382 int k; | 1380 int i, k; |
1383 float x1[128], x2[128]; | 1381 float x[128]; |
1384 float *o_ptr, *d_ptr, *w; | 1382 FFTComplex z[2][64]; |
1385 FFTComplex *ptr1, *ptr2; | 1383 float *o_ptr = ctx->tmp_output; |
1386 | 1384 |
1387 for (k = 0; k < N / 4; k++) { | 1385 for(i=0; i<2; i++) { |
1388 x1[k] = ctx->transform_coeffs[chindex][2 * k]; | 1386 /* de-interleave coefficients */ |
1389 x2[k] = ctx->transform_coeffs[chindex][2 * k + 1]; | 1387 for(k=0; k<128; k++) { |
1390 } | 1388 x[k] = ctx->transform_coeffs[chindex][2*k+i]; |
1391 | 1389 } |
1392 ctx->imdct_256.fft.imdct_calc(&ctx->imdct_256, ctx->tmp_output, x1, ctx->tmp_imdct); | 1390 |
1393 ctx->imdct_256.fft.imdct_calc(&ctx->imdct_256, ctx->tmp_output + 256, x2, ctx->tmp_imdct); | 1391 /* run standard IMDCT */ |
1394 | 1392 ctx->imdct_256.fft.imdct_calc(&ctx->imdct_256, o_ptr, x, ctx->tmp_imdct); |
1395 o_ptr = ctx->output[chindex]; | 1393 |
1396 d_ptr = ctx->delay[chindex]; | 1394 /* reverse the post-rotation & reordering from standard IMDCT */ |
1397 ptr1 = (FFTComplex *)ctx->tmp_output; | 1395 for(k=0; k<32; k++) { |
1398 ptr2 = (FFTComplex *)ctx->tmp_output + 256; | 1396 z[i][32+k].re = -o_ptr[128+2*k]; |
1399 w = ctx->window; | 1397 z[i][32+k].im = -o_ptr[2*k]; |
1400 | 1398 z[i][31-k].re = o_ptr[2*k+1]; |
1401 for (k = 0; k < N / 8; k++) | 1399 z[i][31-k].im = o_ptr[128+2*k+1]; |
1402 { | 1400 } |
1403 o_ptr[2 * k] = -ptr1[k].im * w[2 * k] + d_ptr[2 * k] + 384.0; | 1401 } |
1404 o_ptr[2 * k + 1] = ptr1[N / 8 - k - 1].re * w[2 * k + 1] + 384.0; | 1402 |
1405 o_ptr[N / 4 + 2 * k] = -ptr1[k].re * w[N / 4 + 2 * k] + d_ptr[N / 4 + 2 * k] + 384.0; | 1403 /* apply AC-3 post-rotation & reordering */ |
1406 o_ptr[N / 4 + 2 * k + 1] = ptr1[N / 8 - k - 1].im * w[N / 4 + 2 * k + 1] + d_ptr[N / 4 + 2 * k + 1] + 384.0; | 1404 for(k=0; k<64; k++) { |
1407 d_ptr[2 * k] = ptr2[k].re * w[k / 2 - 2 * k - 1]; | 1405 o_ptr[ 2*k ] = -z[0][ k].im; |
1408 d_ptr[2 * k + 1] = -ptr2[N / 8 - k - 1].im * w[N / 2 - 2 * k - 2]; | 1406 o_ptr[ 2*k+1] = z[0][63-k].re; |
1409 d_ptr[N / 4 + 2 * k] = ptr2[k].im * w[N / 4 - 2 * k - 1]; | 1407 o_ptr[128+2*k ] = -z[0][ k].re; |
1410 d_ptr[N / 4 + 2 * k + 1] = -ptr2[N / 8 - k - 1].re * w[N / 4 - 2 * k - 2]; | 1408 o_ptr[128+2*k+1] = z[0][63-k].im; |
1411 } | 1409 o_ptr[256+2*k ] = -z[1][ k].re; |
1412 } | 1410 o_ptr[256+2*k+1] = z[1][63-k].im; |
1413 | 1411 o_ptr[384+2*k ] = z[1][ k].im; |
1414 /* This function performs the imdct on 512 sample transform | 1412 o_ptr[384+2*k+1] = -z[1][63-k].re; |
1415 * coefficients. | 1413 } |
1416 */ | |
1417 static void do_imdct_512(AC3DecodeContext *ctx, int chindex) | |
1418 { | |
1419 float *ptr; | |
1420 | |
1421 ctx->imdct_512.fft.imdct_calc(&ctx->imdct_512, ctx->tmp_output, | |
1422 ctx->transform_coeffs[chindex], ctx->tmp_imdct); | |
1423 ptr = ctx->output[chindex]; | |
1424 ctx->dsp.vector_fmul_add_add(ptr, ctx->tmp_output, ctx->window, ctx->delay[chindex], 384, BLOCK_SIZE, 1); | |
1425 ptr = ctx->delay[chindex]; | |
1426 ctx->dsp.vector_fmul_reverse(ptr, ctx->tmp_output + 256, ctx->window, BLOCK_SIZE); | |
1427 } | 1414 } |
1428 | 1415 |
1429 /* IMDCT Transform. */ | 1416 /* IMDCT Transform. */ |
1430 static inline void do_imdct(AC3DecodeContext *ctx) | 1417 static inline void do_imdct(AC3DecodeContext *ctx) |
1431 { | 1418 { |
1432 int i; | 1419 int ch; |
1433 | 1420 |
1434 if (ctx->blkoutput & AC3_OUTPUT_LFEON) { | 1421 if (ctx->blkoutput & AC3_OUTPUT_LFEON) { |
1435 do_imdct_512(ctx, 0); | 1422 ctx->imdct_512.fft.imdct_calc(&ctx->imdct_512, ctx->tmp_output, |
1436 } | 1423 ctx->transform_coeffs[0], ctx->tmp_imdct); |
1437 for (i = 0; i < ctx->nfchans; i++) { | 1424 } |
1438 if ((ctx->blksw >> i) & 1) | 1425 for (ch=1; ch<=ctx->nfchans; ch++) { |
1439 do_imdct_256(ctx, i + 1); | 1426 if ((ctx->blksw >> (ch-1)) & 1) |
1427 do_imdct_256(ctx, ch); | |
1440 else | 1428 else |
1441 do_imdct_512(ctx, i + 1); | 1429 ctx->imdct_512.fft.imdct_calc(&ctx->imdct_512, ctx->tmp_output, |
1430 ctx->transform_coeffs[ch], | |
1431 ctx->tmp_imdct); | |
1432 | |
1433 ctx->dsp.vector_fmul_add_add(ctx->output[ch], ctx->tmp_output, | |
1434 ctx->window, ctx->delay[ch], 384, 256, 1); | |
1435 ctx->dsp.vector_fmul_reverse(ctx->delay[ch], ctx->tmp_output+256, | |
1436 ctx->window, 256); | |
1442 } | 1437 } |
1443 } | 1438 } |
1444 | 1439 |
1445 /* Parse the audio block from ac3 bitstream. | 1440 /* Parse the audio block from ac3 bitstream. |
1446 * This function extract the audio block from the ac3 bitstream | 1441 * This function extract the audio block from the ac3 bitstream |