History

aacdec: separate out scalefactor dequantization from decoding

Allows to template away dequantization.

Lynne committed 2 years ago

Commit 60b60dd1 parent ed009bf2 files · +63 −17Browse files

Unified · Split

2 files
  1. libavcodec/aacdec.h +1 −0
  2. libavcodec/aacdec_template.c +62 −17
libavcodec/aacdec.h+1−0
@@ -147,6 +147,7 @@ typedef struct SingleChannelElement { · 146 unmodified lines
147 TemporalNoiseShaping tns;147 TemporalNoiseShaping tns;
148 enum BandType band_type[128]; ///< band types148 enum BandType band_type[128]; ///< band types
149 int band_type_run_end[120]; ///< band type run end points149 int band_type_run_end[120]; ///< band type run end points
150 int sfo[120]; ///< scalefactor offsets
150 INTFLOAT_UNION(sf, [120]); ///< scalefactors151 INTFLOAT_UNION(sf, [120]); ///< scalefactors
151 INTFLOAT_ALIGNED_UNION(32, coeffs, 1024); ///< coefficients for IMDCT, maybe processed152 INTFLOAT_ALIGNED_UNION(32, coeffs, 1024); ///< coefficients for IMDCT, maybe processed
152 INTFLOAT_ALIGNED_UNION(32, saved, 1536); ///< overlap153 INTFLOAT_ALIGNED_UNION(32, saved, 1536); ///< overlap
libavcodec/aacdec_template.c+62−17
@@ -1446,7 +1446,8 @@ static int decode_band_types(AACDecContext *ac, enum BandType band_type[120], · 1445 unmodified lines
1446 *1446 *
1447 * @return Returns error status. 0 - OK, !0 - error1447 * @return Returns error status. 0 - OK, !0 - error
1448 */1448 */
1449static int decode_scalefactors(AACDecContext *ac, INTFLOAT sf[120], GetBitContext *gb,1449static int decode_scalefactors(AACDecContext *ac, int sfo[120],
1450 GetBitContext *gb,
1450 unsigned int global_gain,1451 unsigned int global_gain,
1451 IndividualChannelStream *ics,1452 IndividualChannelStream *ics,
1452 enum BandType band_type[120],1453 enum BandType band_type[120],
@@ -1461,7 +1462,7 @@ static int decode_scalefactors(AACDecContext *ac, INTFLOAT sf[120], GetBitContex · 8 unmodified lines
1461 int run_end = band_type_run_end[idx];1462 int run_end = band_type_run_end[idx];
1462 if (band_type[idx] == ZERO_BT) {1463 if (band_type[idx] == ZERO_BT) {
1463 for (; i < run_end; i++, idx++)1464 for (; i < run_end; i++, idx++)
1464 sf[idx] = FIXR(0.);1465 sfo[idx] = 0;
1465 } else if ((band_type[idx] == INTENSITY_BT) ||1466 } else if ((band_type[idx] == INTENSITY_BT) ||
1466 (band_type[idx] == INTENSITY_BT2)) {1467 (band_type[idx] == INTENSITY_BT2)) {
1467 for (; i < run_end; i++, idx++) {1468 for (; i < run_end; i++, idx++) {
@@ -1473,11 +1474,7 @@ static int decode_scalefactors(AACDecContext *ac, INTFLOAT sf[120], GetBitContex · 5 unmodified lines
1473 "Clipped intensity stereo position (%d -> %d)",1474 "Clipped intensity stereo position (%d -> %d)",
1474 offset[2], clipped_offset);1475 offset[2], clipped_offset);
1475 }1476 }
1476#if USE_FIXED1477 sfo[idx] = clipped_offset;
1477 sf[idx] = 100 - clipped_offset;
1478#else
1479 sf[idx] = ff_aac_pow2sf_tab[-clipped_offset + POW_SF2_ZERO];
1480#endif /* USE_FIXED */
1481 }1478 }
1482 } else if (band_type[idx] == NOISE_BT) {1479 } else if (band_type[idx] == NOISE_BT) {
1483 for (; i < run_end; i++, idx++) {1480 for (; i < run_end; i++, idx++) {
@@ -1492,11 +1489,7 @@ static int decode_scalefactors(AACDecContext *ac, INTFLOAT sf[120], GetBitContex · 8 unmodified lines
1492 "Clipped noise gain (%d -> %d)",1489 "Clipped noise gain (%d -> %d)",
1493 offset[1], clipped_offset);1490 offset[1], clipped_offset);
1494 }1491 }
1495#if USE_FIXED1492 sfo[idx] = clipped_offset;
1496 sf[idx] = -(100 + clipped_offset);
1497#else
1498 sf[idx] = -ff_aac_pow2sf_tab[clipped_offset + POW_SF2_ZERO];
1499#endif /* USE_FIXED */
1500 }1493 }
1501 } else {1494 } else {
1502 for (; i < run_end; i++, idx++) {1495 for (; i < run_end; i++, idx++) {
@@ -1506,16 +1499,66 @@ static int decode_scalefactors(AACDecContext *ac, INTFLOAT sf[120], GetBitContex · 3 unmodified lines
1506 "Scalefactor (%d) out of range.\n", offset[0]);1499 "Scalefactor (%d) out of range.\n", offset[0]);
1507 return AVERROR_INVALIDDATA;1500 return AVERROR_INVALIDDATA;
1508 }1501 }
1502 sfo[idx] = offset[0];
1503 }
1504 }
1505 }
1506 }
1507 return 0;
1508}
1509
1510/**
1511 * Convert integer scalefactors to the decoder's native expected
1512 * scalefactor values.
1513 */
1514static void dequant_scalefactors(SingleChannelElement *sce)
1515{
1516 IndividualChannelStream *ics = &sce->ics;
1517 const enum BandType *band_type = sce->band_type;
1518 const int *band_type_run_end = sce->band_type_run_end;
1519 const int *sfo = sce->sfo;
1520 INTFLOAT *sf = sce->AAC_RENAME(sf);
1521
1522 int g, i, idx = 0;
1523 for (g = 0; g < ics->num_window_groups; g++) {
1524 for (i = 0; i < ics->max_sfb;) {
1525 int run_end = band_type_run_end[idx];
1526 switch (band_type[idx]) {
1527 case ZERO_BT:
1528 for (; i < run_end; i++, idx++)
1529 sf[idx] = FIXR(0.);
1530 break;
1531 case INTENSITY_BT: /* fallthrough */
1532 case INTENSITY_BT2:
1533 for (; i < run_end; i++, idx++) {
1509#if USE_FIXED1534#if USE_FIXED
1510 sf[idx] = -offset[0];1535 sf[idx] = 100 - sfo[idx];
1511#else1536#else
1512 sf[idx] = -ff_aac_pow2sf_tab[offset[0] - 100 + POW_SF2_ZERO];1537 sf[idx] = ff_aac_pow2sf_tab[-sfo[idx] + POW_SF2_ZERO];
1513#endif /* USE_FIXED */1538#endif /* USE_FIXED */
1514 }1539 }
1540 break;
1541 case NOISE_BT:
1542 for (; i < run_end; i++, idx++) {
1543#if USE_FIXED
1544 sf[idx] = -(100 + sfo[idx]);
1545#else
1546 sf[idx] = -ff_aac_pow2sf_tab[sfo[idx] + POW_SF2_ZERO];
1547#endif /* USE_FIXED */
1548 }
1549 break;
1550 default:
1551 for (; i < run_end; i++, idx++) {
1552#if USE_FIXED
1553 sf[idx] = -sfo[idx];
1554#else
1555 sf[idx] = -ff_aac_pow2sf_tab[sfo[idx] - 100 + POW_SF2_ZERO];
1556#endif /* USE_FIXED */
1557 }
1558 break;
1515 }1559 }
1516 }1560 }
1517 }1561 }
1518 return 0;
1519}1562}
1520 1563
1521/**1564/**
@@ -2007,10 +2050,12 @@ static int decode_ics(AACDecContext *ac, SingleChannelElement *sce, · 485 unmodified lines
2007 if ((ret = decode_band_types(ac, sce->band_type,2050 if ((ret = decode_band_types(ac, sce->band_type,
2008 sce->band_type_run_end, gb, ics)) < 0)2051 sce->band_type_run_end, gb, ics)) < 0)
2009 goto fail;2052 goto fail;
2010 if ((ret = decode_scalefactors(ac, sce->AAC_RENAME(sf), gb, global_gain, ics,2053 if ((ret = decode_scalefactors(ac, sce->sfo, gb, global_gain, ics,
2011 sce->band_type, sce->band_type_run_end)) < 0)2054 sce->band_type, sce->band_type_run_end)) < 0)
2012 goto fail;2055 goto fail;
2013 2056
2057 dequant_scalefactors(sce);
2058
2014 pulse_present = 0;2059 pulse_present = 0;
2015 if (!scale_flag) {2060 if (!scale_flag) {
2016 if (!eld_syntax && (pulse_present = get_bits1(gb))) {2061 if (!eld_syntax && (pulse_present = get_bits1(gb))) {

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t