Mercurial > libavcodec.hg
comparison ac3dec.c @ 5393:c001b06c0ac5 libavcodec
simplify snr offset and bit allocation
author | jbr |
---|---|
date | Tue, 24 Jul 2007 02:08:27 +0000 |
parents | 1f48e25e8d1e |
children | 3f6a6dda6b2d |
comparison
equal
deleted
inserted
replaced
5392:1f48e25e8d1e | 5393:c001b06c0ac5 |
---|---|
105 int rematstr; | 105 int rematstr; |
106 int rematflg[AC3_MAX_CHANNELS]; | 106 int rematflg[AC3_MAX_CHANNELS]; |
107 int cplexpstr; | 107 int cplexpstr; |
108 int lfeexpstr; | 108 int lfeexpstr; |
109 int chexpstr[5]; | 109 int chexpstr[5]; |
110 int csnroffst; | 110 int cplsnroffst; |
111 int cplfsnroffst; | 111 int cplfgain; |
112 int cplfgaincod; | 112 int snroffst[5]; |
113 int fsnroffst[5]; | 113 int fgain[5]; |
114 int fgaincod[5]; | 114 int lfesnroffst; |
115 int lfefsnroffst; | 115 int lfefgain; |
116 int lfefgaincod; | |
117 int cpldeltbae; | 116 int cpldeltbae; |
118 int deltbae[5]; | 117 int deltbae[5]; |
119 int cpldeltnseg; | 118 int cpldeltnseg; |
120 uint8_t cpldeltoffst[8]; | 119 uint8_t cpldeltoffst[8]; |
121 uint8_t cpldeltlen[8]; | 120 uint8_t cpldeltlen[8]; |
419 for(i=0; i<ngrps*3; i++) { | 418 for(i=0; i<ngrps*3; i++) { |
420 prevexp = av_clip(prevexp + dexp[i]-2, 0, 24); | 419 prevexp = av_clip(prevexp + dexp[i]-2, 0, 24); |
421 for(j=0; j<grpsize; j++) { | 420 for(j=0; j<grpsize; j++) { |
422 dexps[(i*grpsize)+j] = prevexp; | 421 dexps[(i*grpsize)+j] = prevexp; |
423 } | 422 } |
424 } | |
425 } | |
426 | |
427 /* Performs bit allocation. | |
428 * This function performs bit allocation for the requested chanenl. | |
429 */ | |
430 static void do_bit_allocation(AC3DecodeContext *ctx, int chnl) | |
431 { | |
432 int fgain, snroffset; | |
433 | |
434 if (chnl == 5) { | |
435 fgain = ff_fgaintab[ctx->cplfgaincod]; | |
436 snroffset = (((ctx->csnroffst - 15) << 4) + ctx->cplfsnroffst) << 2; | |
437 ac3_parametric_bit_allocation(&ctx->bit_alloc_params, ctx->cplbap, | |
438 ctx->dcplexps, ctx->cplstrtmant, | |
439 ctx->cplendmant, snroffset, fgain, 0, | |
440 ctx->cpldeltbae, ctx->cpldeltnseg, | |
441 ctx->cpldeltoffst, ctx->cpldeltlen, | |
442 ctx->cpldeltba); | |
443 } | |
444 else if (chnl == 6) { | |
445 fgain = ff_fgaintab[ctx->lfefgaincod]; | |
446 snroffset = (((ctx->csnroffst - 15) << 4) + ctx->lfefsnroffst) << 2; | |
447 ac3_parametric_bit_allocation(&ctx->bit_alloc_params, ctx->lfebap, | |
448 ctx->dlfeexps, 0, 7, snroffset, fgain, 1, | |
449 DBA_NONE, 0, NULL, NULL, NULL); | |
450 } | |
451 else { | |
452 fgain = ff_fgaintab[ctx->fgaincod[chnl]]; | |
453 snroffset = (((ctx->csnroffst - 15) << 4) + ctx->fsnroffst[chnl]) << 2; | |
454 ac3_parametric_bit_allocation(&ctx->bit_alloc_params, ctx->bap[chnl], | |
455 ctx->dexps[chnl], 0, ctx->endmant[chnl], | |
456 snroffset, fgain, 0, ctx->deltbae[chnl], | |
457 ctx->deltnseg[chnl], ctx->deltoffst[chnl], | |
458 ctx->deltlen[chnl], ctx->deltba[chnl]); | |
459 } | 423 } |
460 } | 424 } |
461 | 425 |
462 typedef struct { /* grouped mantissas for 3-level 5-leve and 11-level quantization */ | 426 typedef struct { /* grouped mantissas for 3-level 5-leve and 11-level quantization */ |
463 int16_t l3_quantizers[3]; | 427 int16_t l3_quantizers[3]; |
1461 ctx->bit_alloc_params.dbknee = ff_dbkneetab[get_bits(gb, 2)]; | 1425 ctx->bit_alloc_params.dbknee = ff_dbkneetab[get_bits(gb, 2)]; |
1462 ctx->bit_alloc_params.floor = ff_floortab[get_bits(gb, 3)]; | 1426 ctx->bit_alloc_params.floor = ff_floortab[get_bits(gb, 3)]; |
1463 } | 1427 } |
1464 | 1428 |
1465 if (get_bits1(gb)) { /* snroffset */ | 1429 if (get_bits1(gb)) { /* snroffset */ |
1430 int csnr; | |
1466 bit_alloc_flags = 127; | 1431 bit_alloc_flags = 127; |
1467 ctx->csnroffst = get_bits(gb, 6); | 1432 csnr = (get_bits(gb, 6) - 15) << 4; |
1468 if (ctx->cplinu) { /* coupling fine snr offset and fast gain code */ | 1433 if (ctx->cplinu) { /* coupling fine snr offset and fast gain code */ |
1469 ctx->cplfsnroffst = get_bits(gb, 4); | 1434 ctx->cplsnroffst = (csnr + get_bits(gb, 4)) << 2; |
1470 ctx->cplfgaincod = get_bits(gb, 3); | 1435 ctx->cplfgain = ff_fgaintab[get_bits(gb, 3)]; |
1471 } | 1436 } |
1472 for (i = 0; i < nfchans; i++) { /* channel fine snr offset and fast gain code */ | 1437 for (i = 0; i < nfchans; i++) { /* channel fine snr offset and fast gain code */ |
1473 ctx->fsnroffst[i] = get_bits(gb, 4); | 1438 ctx->snroffst[i] = (csnr + get_bits(gb, 4)) << 2; |
1474 ctx->fgaincod[i] = get_bits(gb, 3); | 1439 ctx->fgain[i] = ff_fgaintab[get_bits(gb, 3)]; |
1475 } | 1440 } |
1476 if (ctx->lfeon) { /* lfe fine snr offset and fast gain code */ | 1441 if (ctx->lfeon) { /* lfe fine snr offset and fast gain code */ |
1477 ctx->lfefsnroffst = get_bits(gb, 4); | 1442 ctx->lfesnroffst = (csnr + get_bits(gb, 4)) << 2; |
1478 ctx->lfefgaincod = get_bits(gb, 3); | 1443 ctx->lfefgain = ff_fgaintab[get_bits(gb, 3)]; |
1479 } | 1444 } |
1480 } | 1445 } |
1481 | 1446 |
1482 if (ctx->cplinu && get_bits1(gb)) { /* coupling leak information */ | 1447 if (ctx->cplinu && get_bits1(gb)) { /* coupling leak information */ |
1483 bit_alloc_flags |= 64; | 1448 bit_alloc_flags |= 64; |
1531 } | 1496 } |
1532 } | 1497 } |
1533 | 1498 |
1534 if (bit_alloc_flags) { | 1499 if (bit_alloc_flags) { |
1535 if (ctx->cplinu && (bit_alloc_flags & 64)) | 1500 if (ctx->cplinu && (bit_alloc_flags & 64)) |
1536 do_bit_allocation(ctx, 5); | 1501 ac3_parametric_bit_allocation(&ctx->bit_alloc_params, ctx->cplbap, |
1502 ctx->dcplexps, ctx->cplstrtmant, | |
1503 ctx->cplendmant, ctx->cplsnroffst, | |
1504 ctx->cplfgain, 0, | |
1505 ctx->cpldeltbae, ctx->cpldeltnseg, | |
1506 ctx->cpldeltoffst, ctx->cpldeltlen, | |
1507 ctx->cpldeltba); | |
1537 for (i = 0; i < nfchans; i++) | 1508 for (i = 0; i < nfchans; i++) |
1538 if ((bit_alloc_flags >> i) & 1) | 1509 if ((bit_alloc_flags >> i) & 1) |
1539 do_bit_allocation(ctx, i); | 1510 ac3_parametric_bit_allocation(&ctx->bit_alloc_params, |
1511 ctx->bap[i], ctx->dexps[i], 0, | |
1512 ctx->endmant[i], ctx->snroffst[i], | |
1513 ctx->fgain[i], 0, ctx->deltbae[i], | |
1514 ctx->deltnseg[i], ctx->deltoffst[i], | |
1515 ctx->deltlen[i], ctx->deltba[i]); | |
1540 if (ctx->lfeon && (bit_alloc_flags & 32)) | 1516 if (ctx->lfeon && (bit_alloc_flags & 32)) |
1541 do_bit_allocation(ctx, 6); | 1517 ac3_parametric_bit_allocation(&ctx->bit_alloc_params, ctx->lfebap, |
1518 ctx->dlfeexps, 0, 7, ctx->lfesnroffst, | |
1519 ctx->lfefgain, 1, | |
1520 DBA_NONE, 0, NULL, NULL, NULL); | |
1542 } | 1521 } |
1543 | 1522 |
1544 if (get_bits1(gb)) { /* unused dummy data */ | 1523 if (get_bits1(gb)) { /* unused dummy data */ |
1545 skipl = get_bits(gb, 9); | 1524 skipl = get_bits(gb, 9); |
1546 while(skipl--) | 1525 while(skipl--) |