comparison ac3dec.c @ 5388:1bdaa3c03526 libavcodec

change some bit masks to arrays
author jbr
date Mon, 23 Jul 2007 22:16:15 +0000
parents 1194da3349cb
children cf99cf2d3af9
comparison
equal deleted inserted replaced
5387:1194da3349cb 5388:1bdaa3c03526
91 uint8_t acmod; 91 uint8_t acmod;
92 uint8_t cmixlev; 92 uint8_t cmixlev;
93 uint8_t surmixlev; 93 uint8_t surmixlev;
94 uint8_t dsurmod; 94 uint8_t dsurmod;
95 95
96 uint8_t blksw; 96 uint8_t blksw[AC3_MAX_CHANNELS];
97 uint8_t dithflag; 97 uint8_t dithflag[AC3_MAX_CHANNELS];
98 uint8_t cplinu; 98 uint8_t cplinu;
99 uint8_t chincpl; 99 uint8_t chincpl[AC3_MAX_CHANNELS];
100 uint8_t phsflginu; 100 uint8_t phsflginu;
101 uint8_t cplbegf; 101 uint8_t cplbegf;
102 uint8_t cplendf; 102 uint8_t cplendf;
103 uint8_t cplcoe; 103 uint8_t cplcoe;
104 uint32_t cplbndstrc; 104 uint32_t cplbndstrc;
105 uint8_t rematstr; 105 uint8_t rematstr;
106 uint8_t rematflg; 106 uint8_t rematflg[AC3_MAX_CHANNELS];
107 uint8_t cplexpstr; 107 uint8_t cplexpstr;
108 uint8_t lfeexpstr; 108 uint8_t lfeexpstr;
109 uint8_t chexpstr[5]; 109 uint8_t chexpstr[5];
110 uint8_t sdcycod; 110 uint8_t sdcycod;
111 uint8_t fdcycod; 111 uint8_t fdcycod;
125 uint8_t deltbae[5]; 125 uint8_t deltbae[5];
126 uint8_t cpldeltnseg; 126 uint8_t cpldeltnseg;
127 uint8_t cpldeltoffst[8]; 127 uint8_t cpldeltoffst[8];
128 uint8_t cpldeltlen[8]; 128 uint8_t cpldeltlen[8];
129 uint8_t cpldeltba[8]; 129 uint8_t cpldeltba[8];
130 uint8_t deltnseg[5]; 130 int deltnseg[5];
131 uint8_t deltoffst[5][8]; 131 uint8_t deltoffst[5][8];
132 uint8_t deltlen[5][8]; 132 uint8_t deltlen[5][8];
133 uint8_t deltba[5][8]; 133 uint8_t deltba[5][8];
134 134
135 /* Derived Attributes. */ 135 /* Derived Attributes. */
506 while (start < end) { 506 while (start < end) {
507 tbap = bap[start]; 507 tbap = bap[start];
508 switch(tbap) { 508 switch(tbap) {
509 case 0: 509 case 0:
510 for (ch = 0; ch < ctx->nfchans; ch++) 510 for (ch = 0; ch < ctx->nfchans; ch++)
511 if (((ctx->chincpl) >> ch) & 1) { 511 if (ctx->chincpl[ch]) {
512 if ((ctx->dithflag >> ch) & 1) { 512 if (ctx->dithflag[ch]) {
513 cplcoeff = (av_random(&ctx->dith_state) & 0xFFFF) * scale_factors[exps[start]]; 513 cplcoeff = (av_random(&ctx->dith_state) & 0xFFFF) * scale_factors[exps[start]];
514 ctx->transform_coeffs[ch + 1][start] = cplcoeff * cplcos[ch] * LEVEL_MINUS_3DB; 514 ctx->transform_coeffs[ch + 1][start] = cplcoeff * cplcos[ch] * LEVEL_MINUS_3DB;
515 } else 515 } else
516 ctx->transform_coeffs[ch + 1][start] = 0; 516 ctx->transform_coeffs[ch + 1][start] = 0;
517 } 517 }
559 559
560 default: 560 default:
561 cplcoeff = (get_sbits(gb, qntztab[tbap]) << (16 - qntztab[tbap])) * scale_factors[exps[start]]; 561 cplcoeff = (get_sbits(gb, qntztab[tbap]) << (16 - qntztab[tbap])) * scale_factors[exps[start]];
562 } 562 }
563 for (ch = 0; ch < ctx->nfchans; ch++) 563 for (ch = 0; ch < ctx->nfchans; ch++)
564 if ((ctx->chincpl >> ch) & 1) 564 if (ctx->chincpl[ch])
565 ctx->transform_coeffs[ch + 1][start] = cplcoeff * cplcos[ch]; 565 ctx->transform_coeffs[ch + 1][start] = cplcoeff * cplcos[ch];
566 start++; 566 start++;
567 } 567 }
568 } 568 }
569 569
582 582
583 for (i = 0; i < 25; i++) 583 for (i = 0; i < 25; i++)
584 factors[i] = scale_factors[i] * ctx->chcoeffs[ch_index]; 584 factors[i] = scale_factors[i] * ctx->chcoeffs[ch_index];
585 585
586 if (ch_index != -1) { /* fbw channels */ 586 if (ch_index != -1) { /* fbw channels */
587 dithflag = (ctx->dithflag >> ch_index) & 1; 587 dithflag = ctx->dithflag[ch_index];
588 exps = ctx->dexps[ch_index]; 588 exps = ctx->dexps[ch_index];
589 bap = ctx->bap[ch_index]; 589 bap = ctx->bap[ch_index];
590 coeffs = ctx->transform_coeffs[ch_index + 1]; 590 coeffs = ctx->transform_coeffs[ch_index + 1];
591 end = ctx->endmant[ch_index]; 591 end = ctx->endmant[ch_index];
592 } else if (ch_index == -1) { 592 } else if (ch_index == -1) {
676 for (i = 0; i < ctx->nfchans; i++) { 676 for (i = 0; i < ctx->nfchans; i++) {
677 /* transform coefficients for individual channel */ 677 /* transform coefficients for individual channel */
678 if (get_transform_coeffs_ch(ctx, i, &m)) 678 if (get_transform_coeffs_ch(ctx, i, &m))
679 return -1; 679 return -1;
680 /* tranform coefficients for coupling channels */ 680 /* tranform coefficients for coupling channels */
681 if ((ctx->chincpl >> i) & 1) { 681 if (ctx->chincpl[i]) {
682 if (!got_cplchan) { 682 if (!got_cplchan) {
683 if (get_transform_coeffs_cpling(ctx, &m)) { 683 if (get_transform_coeffs_cpling(ctx, &m)) {
684 av_log(NULL, AV_LOG_ERROR, "error in decoupling channels\n"); 684 av_log(NULL, AV_LOG_ERROR, "error in decoupling channels\n");
685 return -1; 685 return -1;
686 } 686 }
723 int bnd1 = 13, bnd2 = 25, bnd3 = 37, bnd4 = 61; 723 int bnd1 = 13, bnd2 = 25, bnd3 = 37, bnd4 = 61;
724 int end, bndend; 724 int end, bndend;
725 725
726 end = FFMIN(ctx->endmant[0], ctx->endmant[1]); 726 end = FFMIN(ctx->endmant[0], ctx->endmant[1]);
727 727
728 if (ctx->rematflg & 1) 728 if (ctx->rematflg[0])
729 do_rematrixing1(ctx, bnd1, bnd2); 729 do_rematrixing1(ctx, bnd1, bnd2);
730 730
731 if (ctx->rematflg & 2) 731 if (ctx->rematflg[1])
732 do_rematrixing1(ctx, bnd2, bnd3); 732 do_rematrixing1(ctx, bnd2, bnd3);
733 733
734 bndend = bnd4; 734 bndend = bnd4;
735 if (bndend > end) { 735 if (bndend > end) {
736 bndend = end; 736 bndend = end;
737 if (ctx->rematflg & 4) 737 if (ctx->rematflg[2])
738 do_rematrixing1(ctx, bnd3, bndend); 738 do_rematrixing1(ctx, bnd3, bndend);
739 } else { 739 } else {
740 if (ctx->rematflg & 4) 740 if (ctx->rematflg[2])
741 do_rematrixing1(ctx, bnd3, bnd4); 741 do_rematrixing1(ctx, bnd3, bnd4);
742 if (ctx->rematflg & 8) 742 if (ctx->rematflg[3])
743 do_rematrixing1(ctx, bnd4, end); 743 do_rematrixing1(ctx, bnd4, end);
744 } 744 }
745 } 745 }
746 746
747 /* This function sets the normalized channel coefficients. 747 /* This function sets the normalized channel coefficients.
1285 if (ctx->blkoutput & AC3_OUTPUT_LFEON) { 1285 if (ctx->blkoutput & AC3_OUTPUT_LFEON) {
1286 ctx->imdct_512.fft.imdct_calc(&ctx->imdct_512, ctx->tmp_output, 1286 ctx->imdct_512.fft.imdct_calc(&ctx->imdct_512, ctx->tmp_output,
1287 ctx->transform_coeffs[0], ctx->tmp_imdct); 1287 ctx->transform_coeffs[0], ctx->tmp_imdct);
1288 } 1288 }
1289 for (ch=1; ch<=ctx->nfchans; ch++) { 1289 for (ch=1; ch<=ctx->nfchans; ch++) {
1290 if ((ctx->blksw >> (ch-1)) & 1) 1290 if (ctx->blksw[ch-1])
1291 do_imdct_256(ctx, ch); 1291 do_imdct_256(ctx, ch);
1292 else 1292 else
1293 ctx->imdct_512.fft.imdct_calc(&ctx->imdct_512, ctx->tmp_output, 1293 ctx->imdct_512.fft.imdct_calc(&ctx->imdct_512, ctx->tmp_output,
1294 ctx->transform_coeffs[ch], 1294 ctx->transform_coeffs[ch],
1295 ctx->tmp_imdct); 1295 ctx->tmp_imdct);
1315 int bit_alloc_flags = 0; 1315 int bit_alloc_flags = 0;
1316 uint8_t *dexps; 1316 uint8_t *dexps;
1317 int mstrcplco, cplcoexp, cplcomant; 1317 int mstrcplco, cplcoexp, cplcomant;
1318 int dynrng, chbwcod, ngrps, cplabsexp, skipl; 1318 int dynrng, chbwcod, ngrps, cplabsexp, skipl;
1319 1319
1320 ctx->blksw = 0;
1321 for (i = 0; i < nfchans; i++) /*block switch flag */ 1320 for (i = 0; i < nfchans; i++) /*block switch flag */
1322 ctx->blksw |= get_bits1(gb) << i; 1321 ctx->blksw[i] = get_bits1(gb);
1323 1322
1324 ctx->dithflag = 0;
1325 for (i = 0; i < nfchans; i++) /* dithering flag */ 1323 for (i = 0; i < nfchans; i++) /* dithering flag */
1326 ctx->dithflag |= get_bits1(gb) << i; 1324 ctx->dithflag[i] = get_bits1(gb);
1327 1325
1328 if (get_bits1(gb)) { /* dynamic range */ 1326 if (get_bits1(gb)) { /* dynamic range */
1329 dynrng = get_sbits(gb, 8); 1327 dynrng = get_sbits(gb, 8);
1330 ctx->dynrng = ((((dynrng & 0x1f) | 0x20) << 13) * scale_factors[3 - (dynrng >> 5)]); 1328 ctx->dynrng = ((((dynrng & 0x1f) | 0x20) << 13) * scale_factors[3 - (dynrng >> 5)]);
1331 } else if(blk == 0) { 1329 } else if(blk == 0) {
1344 get_downmix_coeffs(ctx); 1342 get_downmix_coeffs(ctx);
1345 1343
1346 if (get_bits1(gb)) { /* coupling strategy */ 1344 if (get_bits1(gb)) { /* coupling strategy */
1347 ctx->cplinu = get_bits1(gb); 1345 ctx->cplinu = get_bits1(gb);
1348 ctx->cplbndstrc = 0; 1346 ctx->cplbndstrc = 0;
1349 ctx->chincpl = 0;
1350 if (ctx->cplinu) { /* coupling in use */ 1347 if (ctx->cplinu) { /* coupling in use */
1351 for (i = 0; i < nfchans; i++) 1348 for (i = 0; i < nfchans; i++)
1352 ctx->chincpl |= get_bits1(gb) << i; 1349 ctx->chincpl[i] = get_bits1(gb);
1353 1350
1354 if (acmod == 0x02) 1351 if (acmod == 0x02)
1355 ctx->phsflginu = get_bits1(gb); //phase flag in use 1352 ctx->phsflginu = get_bits1(gb); //phase flag in use
1356 1353
1357 ctx->cplbegf = get_bits(gb, 4); 1354 ctx->cplbegf = get_bits(gb, 4);
1368 for (i = 0; i < ctx->ncplsubnd - 1; i++) /* coupling band structure */ 1365 for (i = 0; i < ctx->ncplsubnd - 1; i++) /* coupling band structure */
1369 if (get_bits1(gb)) { 1366 if (get_bits1(gb)) {
1370 ctx->cplbndstrc |= 1 << i; 1367 ctx->cplbndstrc |= 1 << i;
1371 ctx->ncplbnd--; 1368 ctx->ncplbnd--;
1372 } 1369 }
1370 } else {
1371 for (i = 0; i < nfchans; i++)
1372 ctx->chincpl[i] = 0;
1373 } 1373 }
1374 } 1374 }
1375 1375
1376 if (ctx->cplinu) { 1376 if (ctx->cplinu) {
1377 ctx->cplcoe = 0; 1377 ctx->cplcoe = 0;
1378 1378
1379 for (i = 0; i < nfchans; i++) 1379 for (i = 0; i < nfchans; i++)
1380 if ((ctx->chincpl) >> i & 1) 1380 if (ctx->chincpl[i])
1381 if (get_bits1(gb)) { /* coupling co-ordinates */ 1381 if (get_bits1(gb)) { /* coupling co-ordinates */
1382 ctx->cplcoe |= 1 << i; 1382 ctx->cplcoe |= 1 << i;
1383 mstrcplco = 3 * get_bits(gb, 2); 1383 mstrcplco = 3 * get_bits(gb, 2);
1384 for (bnd = 0; bnd < ctx->ncplbnd; bnd++) { 1384 for (bnd = 0; bnd < ctx->ncplbnd; bnd++) {
1385 cplcoexp = get_bits(gb, 4); 1385 cplcoexp = get_bits(gb, 4);
1399 } 1399 }
1400 1400
1401 if (acmod == 0x02) {/* rematrixing */ 1401 if (acmod == 0x02) {/* rematrixing */
1402 ctx->rematstr = get_bits1(gb); 1402 ctx->rematstr = get_bits1(gb);
1403 if (ctx->rematstr) { 1403 if (ctx->rematstr) {
1404 ctx->rematflg = 0;
1405
1406 if (!(ctx->cplinu) || ctx->cplbegf > 2) 1404 if (!(ctx->cplinu) || ctx->cplbegf > 2)
1407 for (rbnd = 0; rbnd < 4; rbnd++) 1405 for (rbnd = 0; rbnd < 4; rbnd++)
1408 ctx->rematflg |= get_bits1(gb) << rbnd; 1406 ctx->rematflg[rbnd] = get_bits1(gb);
1409 if (ctx->cplbegf > 0 && ctx->cplbegf <= 2 && ctx->cplinu) 1407 if (ctx->cplbegf > 0 && ctx->cplbegf <= 2 && ctx->cplinu)
1410 for (rbnd = 0; rbnd < 3; rbnd++) 1408 for (rbnd = 0; rbnd < 3; rbnd++)
1411 ctx->rematflg |= get_bits1(gb) << rbnd; 1409 ctx->rematflg[rbnd] = get_bits1(gb);
1412 if (ctx->cplbegf == 0 && ctx->cplinu) 1410 if (ctx->cplbegf == 0 && ctx->cplinu)
1413 for (rbnd = 0; rbnd < 2; rbnd++) 1411 for (rbnd = 0; rbnd < 2; rbnd++)
1414 ctx->rematflg |= get_bits1(gb) << rbnd; 1412 ctx->rematflg[rbnd] = get_bits1(gb);
1415 } 1413 }
1416 } 1414 }
1417 1415
1418 ctx->cplexpstr = EXP_REUSE; 1416 ctx->cplexpstr = EXP_REUSE;
1419 ctx->lfeexpstr = EXP_REUSE; 1417 ctx->lfeexpstr = EXP_REUSE;
1424 if (ctx->lfeon) /* lfe exponent strategy */ 1422 if (ctx->lfeon) /* lfe exponent strategy */
1425 ctx->lfeexpstr = get_bits1(gb); 1423 ctx->lfeexpstr = get_bits1(gb);
1426 1424
1427 for (i = 0; i < nfchans; i++) /* channel bandwidth code */ 1425 for (i = 0; i < nfchans; i++) /* channel bandwidth code */
1428 if (ctx->chexpstr[i] != EXP_REUSE) { 1426 if (ctx->chexpstr[i] != EXP_REUSE) {
1429 if ((ctx->chincpl >> i) & 1) 1427 if (ctx->chincpl[i])
1430 ctx->endmant[i] = ctx->cplstrtmant; 1428 ctx->endmant[i] = ctx->cplstrtmant;
1431 else { 1429 else {
1432 chbwcod = get_bits(gb, 6); 1430 chbwcod = get_bits(gb, 6);
1433 if (chbwcod > 60) { 1431 if (chbwcod > 60) {
1434 av_log(NULL, AV_LOG_ERROR, "chbwcod = %d > 60", chbwcod); 1432 av_log(NULL, AV_LOG_ERROR, "chbwcod = %d > 60", chbwcod);
1548 ctx->bit_alloc_params.dbknee = ff_dbkneetab[ctx->dbpbcod]; 1546 ctx->bit_alloc_params.dbknee = ff_dbkneetab[ctx->dbpbcod];
1549 ctx->bit_alloc_params.floor = ff_floortab[ctx->floorcod]; 1547 ctx->bit_alloc_params.floor = ff_floortab[ctx->floorcod];
1550 ctx->bit_alloc_params.cplfleak = ctx->cplfleak; 1548 ctx->bit_alloc_params.cplfleak = ctx->cplfleak;
1551 ctx->bit_alloc_params.cplsleak = ctx->cplsleak; 1549 ctx->bit_alloc_params.cplsleak = ctx->cplsleak;
1552 1550
1553 if (ctx->chincpl && (bit_alloc_flags & 64)) 1551 if (ctx->cplinu && (bit_alloc_flags & 64))
1554 do_bit_allocation(ctx, 5); 1552 do_bit_allocation(ctx, 5);
1555 for (i = 0; i < nfchans; i++) 1553 for (i = 0; i < nfchans; i++)
1556 if ((bit_alloc_flags >> i) & 1) 1554 if ((bit_alloc_flags >> i) & 1)
1557 do_bit_allocation(ctx, i); 1555 do_bit_allocation(ctx, i);
1558 if (ctx->lfeon && (bit_alloc_flags & 32)) 1556 if (ctx->lfeon && (bit_alloc_flags & 32))
1571 av_log(NULL, AV_LOG_ERROR, "Error in routine get_transform_coeffs\n"); 1569 av_log(NULL, AV_LOG_ERROR, "Error in routine get_transform_coeffs\n");
1572 return -1; 1570 return -1;
1573 } 1571 }
1574 1572
1575 /* recover coefficients if rematrixing is in use */ 1573 /* recover coefficients if rematrixing is in use */
1576 if (ctx->rematflg) 1574 if(ctx->acmod == AC3_ACMOD_STEREO)
1577 do_rematrixing(ctx); 1575 do_rematrixing(ctx);
1578 1576
1579 do_downmix(ctx); 1577 do_downmix(ctx);
1580 1578
1581 do_imdct(ctx); 1579 do_imdct(ctx);