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
147147 TemporalNoiseShaping tns;
148148 enum BandType band_type[128]; ///< band types
149149 int band_type_run_end[120]; ///< band type run end points
150+ int sfo[120]; ///< scalefactor offsets
150151 INTFLOAT_UNION(sf, [120]); ///< scalefactors
151152 INTFLOAT_ALIGNED_UNION(32, coeffs, 1024); ///< coefficients for IMDCT, maybe processed
152153 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
14461446 *
14471447 * @return Returns error status. 0 - OK, !0 - error
14481448 */
1449−static int decode_scalefactors(AACDecContext *ac, INTFLOAT sf[120], GetBitContext *gb,
1449+static int decode_scalefactors(AACDecContext *ac, int sfo[120],
1450+ GetBitContext *gb,
14501451 unsigned int global_gain,
14511452 IndividualChannelStream *ics,
14521453 enum BandType band_type[120],
@@ -1461,7 +1462,7 @@ static int decode_scalefactors(AACDecContext *ac, INTFLOAT sf[120], GetBitContex · 8 unmodified lines
14611462 int run_end = band_type_run_end[idx];
14621463 if (band_type[idx] == ZERO_BT) {
14631464 for (; i < run_end; i++, idx++)
1464− sf[idx] = FIXR(0.);
1465+ sfo[idx] = 0;
14651466 } else if ((band_type[idx] == INTENSITY_BT) ||
14661467 (band_type[idx] == INTENSITY_BT2)) {
14671468 for (; i < run_end; i++, idx++) {
@@ -1473,11 +1474,7 @@ static int decode_scalefactors(AACDecContext *ac, INTFLOAT sf[120], GetBitContex · 5 unmodified lines
14731474 "Clipped intensity stereo position (%d -> %d)",
14741475 offset[2], clipped_offset);
14751476 }
1476−#if USE_FIXED
1477− sf[idx] = 100 - clipped_offset;
1478−#else
1479− sf[idx] = ff_aac_pow2sf_tab[-clipped_offset + POW_SF2_ZERO];
1480−#endif /* USE_FIXED */
1477+ sfo[idx] = clipped_offset;
14811478 }
14821479 } else if (band_type[idx] == NOISE_BT) {
14831480 for (; i < run_end; i++, idx++) {
@@ -1492,11 +1489,7 @@ static int decode_scalefactors(AACDecContext *ac, INTFLOAT sf[120], GetBitContex · 8 unmodified lines
14921489 "Clipped noise gain (%d -> %d)",
14931490 offset[1], clipped_offset);
14941491 }
1495−#if USE_FIXED
1496− sf[idx] = -(100 + clipped_offset);
1497−#else
1498− sf[idx] = -ff_aac_pow2sf_tab[clipped_offset + POW_SF2_ZERO];
1499−#endif /* USE_FIXED */
1492+ sfo[idx] = clipped_offset;
15001493 }
15011494 } else {
15021495 for (; i < run_end; i++, idx++) {
@@ -1506,16 +1499,66 @@ static int decode_scalefactors(AACDecContext *ac, INTFLOAT sf[120], GetBitContex · 3 unmodified lines
15061499 "Scalefactor (%d) out of range.\n", offset[0]);
15071500 return AVERROR_INVALIDDATA;
15081501 }
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+ */
1514+static 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++) {
15091534 #if USE_FIXED
1510− sf[idx] = -offset[0];
1535+ sf[idx] = 100 - sfo[idx];
15111536 #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];
15131538 #endif /* USE_FIXED */
15141539 }
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;
15151559 }
15161560 }
15171561 }
1518− return 0;
15191562 }
15201563
15211564 /**
@@ -2007,10 +2050,12 @@ static int decode_ics(AACDecContext *ac, SingleChannelElement *sce, · 485 unmodified lines
20072050 if ((ret = decode_band_types(ac, sce->band_type,
20082051 sce->band_type_run_end, gb, ics)) < 0)
20092052 goto fail;
2010− if ((ret = decode_scalefactors(ac, sce->AAC_RENAME(sf), gb, global_gain, ics,
2011− sce->band_type, sce->band_type_run_end)) < 0)
2053+ if ((ret = decode_scalefactors(ac, sce->sfo, gb, global_gain, ics,
2054+ sce->band_type, sce->band_type_run_end)) < 0)
20122055 goto fail;
20132056
2057+ dequant_scalefactors(sce);
2058+
20142059 pulse_present = 0;
20152060 if (!scale_flag) {
20162061 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