aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--documentation/aacDecoder.pdfbin490978 -> 492288 bytes
-rw-r--r--documentation/aacEncoder.pdfbin443728 -> 443831 bytes
-rw-r--r--libAACdec/include/aacdecoder_lib.h2
-rw-r--r--libAACdec/src/aacdecoder.cpp136
-rw-r--r--libAACdec/src/aacdecoder_lib.cpp7
-rw-r--r--libAACdec/src/rvlc.cpp15
-rw-r--r--libAACenc/include/aacenc_lib.h4
-rw-r--r--libAACenc/src/aacenc_lib.cpp7
-rw-r--r--libDRCdec/src/drcDec_reader.cpp4
-rw-r--r--libFDK/include/nlc_dec.h5
-rw-r--r--libFDK/src/autocorr2nd.cpp43
-rw-r--r--libFDK/src/nlc_dec.cpp28
-rw-r--r--libMpegTPDec/src/tpdec_asc.cpp10
-rw-r--r--libMpegTPDec/src/tpdec_latm.cpp41
-rw-r--r--libMpegTPDec/src/tpdec_latm.h4
-rw-r--r--libPCMutils/src/pcmdmx_lib.cpp56
-rw-r--r--libSACdec/src/sac_bitdec.cpp17
-rw-r--r--libSACdec/src/sac_process.cpp20
-rw-r--r--libSACdec/src/sac_reshapeBBEnv.cpp77
-rw-r--r--libSACdec/src/sac_stp.cpp26
-rw-r--r--libSBRdec/src/arm/lpp_tran_arm.cpp159
-rw-r--r--libSBRdec/src/env_calc.cpp31
-rw-r--r--libSBRdec/src/hbe.cpp51
-rw-r--r--libSBRdec/src/lpp_tran.cpp112
-rw-r--r--libSBRdec/src/sbr_dec.cpp24
-rw-r--r--libSBRdec/src/sbrdec_freq_sca.cpp16
-rw-r--r--libSBRdec/src/sbrdecoder.cpp16
27 files changed, 439 insertions, 472 deletions
diff --git a/documentation/aacDecoder.pdf b/documentation/aacDecoder.pdf
index cc7cf41..3d4699e 100644
--- a/documentation/aacDecoder.pdf
+++ b/documentation/aacDecoder.pdf
Binary files differ
diff --git a/documentation/aacEncoder.pdf b/documentation/aacEncoder.pdf
index 77b8f4c..a47708a 100644
--- a/documentation/aacEncoder.pdf
+++ b/documentation/aacEncoder.pdf
Binary files differ
diff --git a/libAACdec/include/aacdecoder_lib.h b/libAACdec/include/aacdecoder_lib.h
index 56f4ec1..d7928c0 100644
--- a/libAACdec/include/aacdecoder_lib.h
+++ b/libAACdec/include/aacdecoder_lib.h
@@ -1032,7 +1032,7 @@ LINKSPEC_H AAC_DECODER_ERROR aacDecoder_Fill(HANDLE_AACDECODER self,
* \param self AAC decoder handle.
* \param pTimeData Pointer to external output buffer where the decoded PCM
* samples will be stored into.
- * \param timeDataSize Size of external output buffer.
+ * \param timeDataSize Size of external output buffer in PCM samples.
* \param flags Bit field with flags for the decoder: \n
* (flags & AACDEC_CONCEAL) == 1: Do concealment. \n
* (flags & AACDEC_FLUSH) == 2: Discard input data. Flush
diff --git a/libAACdec/src/aacdecoder.cpp b/libAACdec/src/aacdecoder.cpp
index c18e5e9..d5f0cea 100644
--- a/libAACdec/src/aacdecoder.cpp
+++ b/libAACdec/src/aacdecoder.cpp
@@ -1,7 +1,7 @@
/* -----------------------------------------------------------------------------
Software License for The Fraunhofer FDK AAC Codec Library for Android
-© Copyright 1995 - 2020 Fraunhofer-Gesellschaft zur Förderung der angewandten
+© Copyright 1995 - 2021 Fraunhofer-Gesellschaft zur Förderung der angewandten
Forschung e.V. All rights reserved.
1. INTRODUCTION
@@ -494,6 +494,75 @@ static AAC_DECODER_ERROR CDataStreamElement_Read(HANDLE_AACDECODER self,
return error;
}
+static INT findElementInstanceTag(
+ INT elementTag, MP4_ELEMENT_ID elementId,
+ CAacDecoderChannelInfo **pAacDecoderChannelInfo, INT nChannels,
+ MP4_ELEMENT_ID *pElementIdTab, INT nElements) {
+ int el, chCnt = 0;
+
+ for (el = 0; el < nElements; el++) {
+ switch (pElementIdTab[el]) {
+ case ID_CPE:
+ case ID_SCE:
+ case ID_LFE:
+ if ((elementTag == pAacDecoderChannelInfo[chCnt]->ElementInstanceTag) &&
+ (elementId == pElementIdTab[el])) {
+ return 1; /* element instance tag found */
+ }
+ chCnt += (pElementIdTab[el] == ID_CPE) ? 2 : 1;
+ break;
+ default:
+ break;
+ }
+ if (chCnt >= nChannels) break;
+ if (pElementIdTab[el] == ID_END) break;
+ }
+
+ return 0; /* element instance tag not found */
+}
+
+static INT validateElementInstanceTags(
+ CProgramConfig *pce, CAacDecoderChannelInfo **pAacDecoderChannelInfo,
+ INT nChannels, MP4_ELEMENT_ID *pElementIdTab, INT nElements) {
+ if (nChannels >= pce->NumChannels) {
+ for (int el = 0; el < pce->NumFrontChannelElements; el++) {
+ if (!findElementInstanceTag(pce->FrontElementTagSelect[el],
+ pce->FrontElementIsCpe[el] ? ID_CPE : ID_SCE,
+ pAacDecoderChannelInfo, nChannels,
+ pElementIdTab, nElements)) {
+ return 0; /* element instance tag not in raw_data_block() */
+ }
+ }
+ for (int el = 0; el < pce->NumSideChannelElements; el++) {
+ if (!findElementInstanceTag(pce->SideElementTagSelect[el],
+ pce->SideElementIsCpe[el] ? ID_CPE : ID_SCE,
+ pAacDecoderChannelInfo, nChannels,
+ pElementIdTab, nElements)) {
+ return 0; /* element instance tag not in raw_data_block() */
+ }
+ }
+ for (int el = 0; el < pce->NumBackChannelElements; el++) {
+ if (!findElementInstanceTag(pce->BackElementTagSelect[el],
+ pce->BackElementIsCpe[el] ? ID_CPE : ID_SCE,
+ pAacDecoderChannelInfo, nChannels,
+ pElementIdTab, nElements)) {
+ return 0; /* element instance tag not in raw_data_block() */
+ }
+ }
+ for (int el = 0; el < pce->NumLfeChannelElements; el++) {
+ if (!findElementInstanceTag(pce->LfeElementTagSelect[el], ID_LFE,
+ pAacDecoderChannelInfo, nChannels,
+ pElementIdTab, nElements)) {
+ return 0; /* element instance tag not in raw_data_block() */
+ }
+ }
+ } else {
+ return 0; /* too less decoded audio channels */
+ }
+
+ return 1; /* all element instance tags found in raw_data_block() */
+}
+
/*!
\brief Read Program Config Element
@@ -1417,11 +1486,7 @@ static void CAacDecoder_AcceptFlags(HANDLE_AACDECODER self,
const CSAudioSpecificConfig *asc,
UINT flags, UINT *elFlags, int streamIndex,
int elementOffset) {
- {
- FDKmemcpy(
- self->elFlags, elFlags,
- sizeof(*elFlags) * (3 * ((8) * 2) + (((8) * 2)) / 2 + 4 * (1) + 1));
- }
+ FDKmemcpy(self->elFlags, elFlags, sizeof(self->elFlags));
self->flags[streamIndex] = flags;
}
@@ -1524,8 +1589,14 @@ CAacDecoder_Init(HANDLE_AACDECODER self, const CSAudioSpecificConfig *asc,
INT flushChannels = 0;
UINT flags;
+ /* elFlags[(3*MAX_CHANNELS + (MAX_CHANNELS)/2 + 4 * (MAX_TRACKS) + 1]
+ where MAX_CHANNELS is (8*2) and MAX_TRACKS is 1 */
UINT elFlags[(3 * ((8) * 2) + (((8) * 2)) / 2 + 4 * (1) + 1)];
+ UCHAR sbrEnabled = self->sbrEnabled;
+ UCHAR sbrEnabledPrev = self->sbrEnabledPrev;
+ UCHAR mpsEnableCurr = self->mpsEnableCurr;
+
if (!self) return AAC_DEC_INVALID_HANDLE;
UCHAR downscaleFactor = self->downscaleFactor;
@@ -1709,7 +1780,7 @@ CAacDecoder_Init(HANDLE_AACDECODER self, const CSAudioSpecificConfig *asc,
asc->m_sc.m_usacConfig.m_usacNumElements;
}
- self->mpsEnableCurr = 0;
+ mpsEnableCurr = 0;
for (int _el = 0;
_el < (int)self->pUsacConfig[streamIndex]->m_usacNumElements;
_el++) {
@@ -1729,7 +1800,7 @@ CAacDecoder_Init(HANDLE_AACDECODER self, const CSAudioSpecificConfig *asc,
self->usacStereoConfigIndex[el] =
asc->m_sc.m_usacConfig.element[_el].m_stereoConfigIndex;
if (self->elements[el] == ID_USAC_CPE) {
- self->mpsEnableCurr |= self->usacStereoConfigIndex[el] ? 1 : 0;
+ mpsEnableCurr |= self->usacStereoConfigIndex[el] ? 1 : 0;
}
}
@@ -1865,7 +1936,7 @@ CAacDecoder_Init(HANDLE_AACDECODER self, const CSAudioSpecificConfig *asc,
self->useLdQmfTimeAlign =
asc->m_sc.m_eldSpecificConfig.m_useLdQmfTimeAlign;
}
- if (self->sbrEnabled != asc->m_sbrPresentFlag) {
+ if (sbrEnabled != asc->m_sbrPresentFlag) {
ascChanged = 1;
}
}
@@ -1881,13 +1952,13 @@ CAacDecoder_Init(HANDLE_AACDECODER self, const CSAudioSpecificConfig *asc,
flags |= (asc->m_sbrPresentFlag) ? AC_SBR_PRESENT : 0;
flags |= (asc->m_psPresentFlag) ? AC_PS_PRESENT : 0;
if (asc->m_sbrPresentFlag) {
- self->sbrEnabled = 1;
- self->sbrEnabledPrev = 1;
+ sbrEnabled = 1;
+ sbrEnabledPrev = 1;
} else {
- self->sbrEnabled = 0;
- self->sbrEnabledPrev = 0;
+ sbrEnabled = 0;
+ sbrEnabledPrev = 0;
}
- if (self->sbrEnabled && asc->m_extensionSamplingFrequency) {
+ if (sbrEnabled && asc->m_extensionSamplingFrequency) {
if (downscaleFactor != 1 && (downscaleFactor)&1) {
return AAC_DEC_UNSUPPORTED_SAMPLINGRATE; /* SBR needs an even downscale
factor */
@@ -1914,7 +1985,7 @@ CAacDecoder_Init(HANDLE_AACDECODER self, const CSAudioSpecificConfig *asc,
flags |= (asc->m_hcrFlag) ? AC_ER_HCR : 0;
if (asc->m_aot == AOT_ER_AAC_ELD) {
- self->mpsEnableCurr = 0;
+ mpsEnableCurr = 0;
flags |= AC_ELD;
flags |= (asc->m_sbrPresentFlag)
? AC_SBR_PRESENT
@@ -1925,7 +1996,7 @@ CAacDecoder_Init(HANDLE_AACDECODER self, const CSAudioSpecificConfig *asc,
? AC_MPS_PRESENT
: 0;
if (self->mpsApplicable) {
- self->mpsEnableCurr = asc->m_sc.m_eldSpecificConfig.m_useLdQmfTimeAlign;
+ mpsEnableCurr = asc->m_sc.m_eldSpecificConfig.m_useLdQmfTimeAlign;
}
}
flags |= (asc->m_aot == AOT_ER_AAC_LD) ? AC_LD : 0;
@@ -2006,7 +2077,7 @@ CAacDecoder_Init(HANDLE_AACDECODER self, const CSAudioSpecificConfig *asc,
/* set AC_USAC_SCFGI3 globally if any usac element uses */
switch (asc->m_aot) {
case AOT_USAC:
- if (self->sbrEnabled) {
+ if (sbrEnabled) {
for (int _el = 0;
_el < (int)self->pUsacConfig[streamIndex]->m_usacNumElements;
_el++) {
@@ -2043,7 +2114,7 @@ CAacDecoder_Init(HANDLE_AACDECODER self, const CSAudioSpecificConfig *asc,
*/
switch (asc->m_aot) {
case AOT_USAC:
- if (self->sbrEnabled) {
+ if (sbrEnabled) {
const UCHAR map_sbrRatio_2_nAnaBands[] = {16, 24, 32};
FDK_ASSERT(asc->m_sc.m_usacConfig.m_sbrRatioIndex > 0);
@@ -2071,11 +2142,11 @@ CAacDecoder_Init(HANDLE_AACDECODER self, const CSAudioSpecificConfig *asc,
}
break;
case AOT_ER_AAC_ELD:
- if (self->mpsEnableCurr &&
+ if (mpsEnableCurr &&
asc->m_sc.m_eldSpecificConfig.m_useLdQmfTimeAlign) {
- SAC_INPUT_CONFIG sac_interface =
- (self->sbrEnabled && self->hSbrDecoder) ? SAC_INTERFACE_QMF
- : SAC_INTERFACE_TIME;
+ SAC_INPUT_CONFIG sac_interface = (sbrEnabled && self->hSbrDecoder)
+ ? SAC_INTERFACE_QMF
+ : SAC_INTERFACE_TIME;
mpegSurroundDecoder_ConfigureQmfDomain(
(CMpegSurroundDecoder *)self->pMpegSurroundDecoder, sac_interface,
(UINT)self->streamInfo.aacSampleRate, asc->m_aot);
@@ -2430,6 +2501,9 @@ CAacDecoder_Init(HANDLE_AACDECODER self, const CSAudioSpecificConfig *asc,
CAacDecoder_AcceptFlags(self, asc, flags, elFlags, streamIndex,
elementOffset);
+ self->sbrEnabled = sbrEnabled;
+ self->sbrEnabledPrev = sbrEnabledPrev;
+ self->mpsEnableCurr = mpsEnableCurr;
/* Update externally visible copy of flags */
self->streamInfo.flags = self->flags[0];
@@ -2968,6 +3042,24 @@ LINKSPEC_CPP AAC_DECODER_ERROR CAacDecoder_DecodeFrame(
} /* while ( (type != ID_END) ... ) */
+ if (!(self->flags[streamIndex] &
+ (AC_USAC | AC_RSVD50 | AC_RSV603DA | AC_BSAC | AC_LD | AC_ELD | AC_ER |
+ AC_SCALABLE)) &&
+ (self->streamInfo.channelConfig == 0) && pce->isValid &&
+ (ErrorStatus == AAC_DEC_OK) && self->frameOK &&
+ !(flags & (AACDEC_CONCEAL | AACDEC_FLUSH))) {
+ /* Check whether all PCE listed element instance tags are present in
+ * raw_data_block() */
+ if (!validateElementInstanceTags(
+ &self->pce, self->pAacDecoderChannelInfo, aacChannels,
+ channel_elements,
+ fMin(channel_element_count, (int)(sizeof(channel_elements) /
+ sizeof(*channel_elements))))) {
+ ErrorStatus = AAC_DEC_DECODE_FRAME_ERROR;
+ self->frameOK = 0;
+ }
+ }
+
if (!(flags & (AACDEC_CONCEAL | AACDEC_FLUSH))) {
/* float decoder checks if bitsLeft is in range 0-7; only prerollAUs are
* byteAligned with respect to the first bit */
diff --git a/libAACdec/src/aacdecoder_lib.cpp b/libAACdec/src/aacdecoder_lib.cpp
index 9d36d10..0c83191 100644
--- a/libAACdec/src/aacdecoder_lib.cpp
+++ b/libAACdec/src/aacdecoder_lib.cpp
@@ -1,7 +1,7 @@
/* -----------------------------------------------------------------------------
Software License for The Fraunhofer FDK AAC Codec Library for Android
-© Copyright 1995 - 2019 Fraunhofer-Gesellschaft zur Förderung der angewandten
+© Copyright 1995 - 2021 Fraunhofer-Gesellschaft zur Förderung der angewandten
Forschung e.V. All rights reserved.
1. INTRODUCTION
@@ -1626,6 +1626,11 @@ LINKSPEC_CPP AAC_DECODER_ERROR aacDecoder_DecodeFrame(HANDLE_AACDECODER self,
/* set params */
sbrDecoder_SetParam(self->hSbrDecoder, SBR_SYSTEM_BITSTREAM_DELAY,
self->sbrParams.bsDelay);
+ sbrDecoder_SetParam(
+ self->hSbrDecoder, SBR_FLUSH_DATA,
+ (flags & AACDEC_FLUSH) |
+ ((self->flushStatus && !(flags & AACDEC_CONCEAL)) ? AACDEC_FLUSH
+ : 0));
sbrDecoder_SetParam(self->hSbrDecoder, SBR_SKIP_QMF, 1);
diff --git a/libAACdec/src/rvlc.cpp b/libAACdec/src/rvlc.cpp
index b7a9be1..0b80364 100644
--- a/libAACdec/src/rvlc.cpp
+++ b/libAACdec/src/rvlc.cpp
@@ -1,7 +1,7 @@
/* -----------------------------------------------------------------------------
Software License for The Fraunhofer FDK AAC Codec Library for Android
-© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
+© Copyright 1995 - 2021 Fraunhofer-Gesellschaft zur Förderung der angewandten
Forschung e.V. All rights reserved.
1. INTRODUCTION
@@ -628,7 +628,7 @@ static void rvlcDecodeBackward(CErRvlcInfo *pRvlc,
SHORT *pScfBwd = pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfBwd;
SHORT *pScfEsc = pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfEsc;
- UCHAR *pEscEscCnt = &(pRvlc->numDecodedEscapeWordsEsc);
+ UCHAR escEscCnt = pRvlc->numDecodedEscapeWordsEsc;
UCHAR *pEscBwdCnt = &(pRvlc->numDecodedEscapeWordsBwd);
pRvlc->pRvlBitCnt_RVL = &(pRvlc->length_of_rvlc_sf_bwd);
@@ -636,7 +636,7 @@ static void rvlcDecodeBackward(CErRvlcInfo *pRvlc,
*pEscBwdCnt = 0;
pRvlc->direction = BWD;
- pScfEsc += *pEscEscCnt - 1; /* set pScfEsc to last entry */
+ pScfEsc += escEscCnt - 1; /* set pScfEsc to last entry */
pRvlc->firstScf = 0;
pRvlc->firstNrg = 0;
pRvlc->firstIs = 0;
@@ -651,7 +651,7 @@ static void rvlcDecodeBackward(CErRvlcInfo *pRvlc,
}
dpcm -= TABLE_OFFSET;
if ((dpcm == MIN_RVL) || (dpcm == MAX_RVL)) {
- if (pRvlc->length_of_rvlc_escapes) {
+ if ((pRvlc->length_of_rvlc_escapes) || (*pEscBwdCnt >= escEscCnt)) {
pRvlc->conceal_min = bnds;
return;
} else {
@@ -694,7 +694,7 @@ static void rvlcDecodeBackward(CErRvlcInfo *pRvlc,
}
dpcm -= TABLE_OFFSET;
if ((dpcm == MIN_RVL) || (dpcm == MAX_RVL)) {
- if (pRvlc->length_of_rvlc_escapes) {
+ if ((pRvlc->length_of_rvlc_escapes) || (*pEscBwdCnt >= escEscCnt)) {
pScfBwd[bnds] = position;
pRvlc->conceal_min = fMax(0, bnds - offset);
return;
@@ -731,7 +731,8 @@ static void rvlcDecodeBackward(CErRvlcInfo *pRvlc,
}
dpcm -= TABLE_OFFSET;
if ((dpcm == MIN_RVL) || (dpcm == MAX_RVL)) {
- if (pRvlc->length_of_rvlc_escapes) {
+ if ((pRvlc->length_of_rvlc_escapes) ||
+ (*pEscBwdCnt >= escEscCnt)) {
pScfBwd[bnds] = noisenrg;
pRvlc->conceal_min = fMax(0, bnds - offset);
return;
@@ -762,7 +763,7 @@ static void rvlcDecodeBackward(CErRvlcInfo *pRvlc,
}
dpcm -= TABLE_OFFSET;
if ((dpcm == MIN_RVL) || (dpcm == MAX_RVL)) {
- if (pRvlc->length_of_rvlc_escapes) {
+ if ((pRvlc->length_of_rvlc_escapes) || (*pEscBwdCnt >= escEscCnt)) {
pScfBwd[bnds] = factor;
pRvlc->conceal_min = fMax(0, bnds - offset);
return;
diff --git a/libAACenc/include/aacenc_lib.h b/libAACenc/include/aacenc_lib.h
index 71f7556..f0f23b4 100644
--- a/libAACenc/include/aacenc_lib.h
+++ b/libAACenc/include/aacenc_lib.h
@@ -1,7 +1,7 @@
/* -----------------------------------------------------------------------------
Software License for The Fraunhofer FDK AAC Codec Library for Android
-© Copyright 1995 - 2019 Fraunhofer-Gesellschaft zur Förderung der angewandten
+© Copyright 1995 - 2021 Fraunhofer-Gesellschaft zur Förderung der angewandten
Forschung e.V. All rights reserved.
1. INTRODUCTION
@@ -1643,7 +1643,7 @@ AACENC_ERROR aacEncEncode(const HANDLE_AACENCODER hAacEncoder,
*
* \return
* - AACENC_OK, on succes.
- * - AACENC_INIT_ERROR, on failure.
+ * - AACENC_INVALID_HANDLE, AACENC_INIT_ERROR, on failure.
*/
AACENC_ERROR aacEncInfo(const HANDLE_AACENCODER hAacEncoder,
AACENC_InfoStruct *pInfo);
diff --git a/libAACenc/src/aacenc_lib.cpp b/libAACenc/src/aacenc_lib.cpp
index caa62c5..c11db27 100644
--- a/libAACenc/src/aacenc_lib.cpp
+++ b/libAACenc/src/aacenc_lib.cpp
@@ -1,7 +1,7 @@
/* -----------------------------------------------------------------------------
Software License for The Fraunhofer FDK AAC Codec Library for Android
-© Copyright 1995 - 2020 Fraunhofer-Gesellschaft zur Förderung der angewandten
+© Copyright 1995 - 2021 Fraunhofer-Gesellschaft zur Förderung der angewandten
Forschung e.V. All rights reserved.
1. INTRODUCTION
@@ -2521,6 +2521,11 @@ AACENC_ERROR aacEncInfo(const HANDLE_AACENCODER hAacEncoder,
AACENC_InfoStruct *pInfo) {
AACENC_ERROR err = AACENC_OK;
+ if ((hAacEncoder == NULL) || (pInfo == NULL)) {
+ err = AACENC_INVALID_HANDLE;
+ goto bail;
+ }
+
FDKmemclear(pInfo, sizeof(AACENC_InfoStruct));
pInfo->confSize = 64; /* pre-initialize */
diff --git a/libDRCdec/src/drcDec_reader.cpp b/libDRCdec/src/drcDec_reader.cpp
index b3ec187..b080f50 100644
--- a/libDRCdec/src/drcDec_reader.cpp
+++ b/libDRCdec/src/drcDec_reader.cpp
@@ -917,7 +917,7 @@ static void _skipEqCoefficients(HANDLE_FDK_BITSTREAM hBs) {
firFilterOrder;
int uniqueEqSubbandGainsCount, eqSubbandGainRepresentation,
eqSubbandGainCount;
- EQ_SUBBAND_GAIN_FORMAT eqSubbandGainFormat;
+ int eqSubbandGainFormat;
eqDelayMaxPresent = FDKreadBits(hBs, 1);
if (eqDelayMaxPresent) {
@@ -958,7 +958,7 @@ static void _skipEqCoefficients(HANDLE_FDK_BITSTREAM hBs) {
uniqueEqSubbandGainsCount = FDKreadBits(hBs, 6);
if (uniqueEqSubbandGainsCount > 0) {
eqSubbandGainRepresentation = FDKreadBits(hBs, 1);
- eqSubbandGainFormat = (EQ_SUBBAND_GAIN_FORMAT)FDKreadBits(hBs, 4);
+ eqSubbandGainFormat = FDKreadBits(hBs, 4);
switch (eqSubbandGainFormat) {
case GF_QMF32:
eqSubbandGainCount = 32;
diff --git a/libFDK/include/nlc_dec.h b/libFDK/include/nlc_dec.h
index cca97f1..aded569 100644
--- a/libFDK/include/nlc_dec.h
+++ b/libFDK/include/nlc_dec.h
@@ -1,7 +1,7 @@
/* -----------------------------------------------------------------------------
Software License for The Fraunhofer FDK AAC Codec Library for Android
-© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
+© Copyright 1995 - 2020 Fraunhofer-Gesellschaft zur Förderung der angewandten
Forschung e.V. All rights reserved.
1. INTRODUCTION
@@ -159,9 +159,6 @@ typedef enum {
#ifndef HUFFDEC_PARAMS
#define HUFFDEC_PARMS
-#define PAIR_SHIFT 4
-#define PAIR_MASK 0xf
-
#define MAX_ENTRIES 168
#define HANDLE_HUFF_NODE const SHORT(*)[MAX_ENTRIES][2]
diff --git a/libFDK/src/autocorr2nd.cpp b/libFDK/src/autocorr2nd.cpp
index 718a555..8c5673c 100644
--- a/libFDK/src/autocorr2nd.cpp
+++ b/libFDK/src/autocorr2nd.cpp
@@ -1,7 +1,7 @@
/* -----------------------------------------------------------------------------
Software License for The Fraunhofer FDK AAC Codec Library for Android
-© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
+© Copyright 1995 - 2020 Fraunhofer-Gesellschaft zur Förderung der angewandten
Forschung e.V. All rights reserved.
1. INTRODUCTION
@@ -102,11 +102,6 @@ amm-info@iis.fraunhofer.de
#include "autocorr2nd.h"
-/* If the accumulator does not provide enough overflow bits,
- products have to be shifted down in the autocorrelation below. */
-#define SHIFT_FACTOR (5)
-#define SHIFT >> (SHIFT_FACTOR)
-
/*!
*
* \brief Calculate second order autocorrelation using 2 accumulators
@@ -126,45 +121,49 @@ INT autoCorr2nd_real(
const FIXP_DBL *realBuf = reBuffer;
+ const int len_scale = fMax(DFRACT_BITS - fNormz((FIXP_DBL)(len / 2)), 1);
/*
r11r,r22r
r01r,r12r
r02r
*/
pReBuf = realBuf - 2;
- accu5 = ((fMultDiv2(pReBuf[0], pReBuf[2]) + fMultDiv2(pReBuf[1], pReBuf[3]))
- SHIFT);
+ accu5 =
+ ((fMultDiv2(pReBuf[0], pReBuf[2]) + fMultDiv2(pReBuf[1], pReBuf[3])) >>
+ len_scale);
pReBuf++;
/* len must be even */
- accu1 = fPow2Div2(pReBuf[0]) SHIFT;
- accu3 = fMultDiv2(pReBuf[0], pReBuf[1]) SHIFT;
+ accu1 = fPow2Div2(pReBuf[0]) >> len_scale;
+ accu3 = fMultDiv2(pReBuf[0], pReBuf[1]) >> len_scale;
pReBuf++;
for (j = (len - 2) >> 1; j != 0; j--, pReBuf += 2) {
- accu1 += ((fPow2Div2(pReBuf[0]) + fPow2Div2(pReBuf[1])) SHIFT);
+ accu1 += ((fPow2Div2(pReBuf[0]) + fPow2Div2(pReBuf[1])) >> len_scale);
- accu3 += ((fMultDiv2(pReBuf[0], pReBuf[1]) +
- fMultDiv2(pReBuf[1], pReBuf[2])) SHIFT);
+ accu3 +=
+ ((fMultDiv2(pReBuf[0], pReBuf[1]) + fMultDiv2(pReBuf[1], pReBuf[2])) >>
+ len_scale);
- accu5 += ((fMultDiv2(pReBuf[0], pReBuf[2]) +
- fMultDiv2(pReBuf[1], pReBuf[3])) SHIFT);
+ accu5 +=
+ ((fMultDiv2(pReBuf[0], pReBuf[2]) + fMultDiv2(pReBuf[1], pReBuf[3])) >>
+ len_scale);
}
- accu2 = (fPow2Div2(realBuf[-2]) SHIFT);
+ accu2 = (fPow2Div2(realBuf[-2]) >> len_scale);
accu2 += accu1;
- accu1 += (fPow2Div2(realBuf[len - 2]) SHIFT);
+ accu1 += (fPow2Div2(realBuf[len - 2]) >> len_scale);
- accu4 = (fMultDiv2(realBuf[-1], realBuf[-2]) SHIFT);
+ accu4 = (fMultDiv2(realBuf[-1], realBuf[-2]) >> len_scale);
accu4 += accu3;
- accu3 += (fMultDiv2(realBuf[len - 1], realBuf[len - 2]) SHIFT);
+ accu3 += (fMultDiv2(realBuf[len - 1], realBuf[len - 2]) >> len_scale);
mScale = CntLeadingZeros(
(accu1 | accu2 | fAbs(accu3) | fAbs(accu4) | fAbs(accu5))) -
1;
- autoCorrScaling = mScale - 1 - SHIFT_FACTOR; /* -1 because of fMultDiv2*/
+ autoCorrScaling = mScale - 1 - len_scale; /* -1 because of fMultDiv2*/
/* Scale to common scale factor */
ac->r11r = accu1 << mScale;
@@ -190,7 +189,7 @@ INT autoCorr2nd_cplx(
const FIXP_DBL *imBuffer, /*!< Pointer to imag part of input samples */
const int len /*!< Number of input samples (should be smaller than 128) */
) {
- int j, autoCorrScaling, mScale, len_scale;
+ int j, autoCorrScaling, mScale;
FIXP_DBL accu0, accu1, accu2, accu3, accu4, accu5, accu6, accu7, accu8;
@@ -199,7 +198,7 @@ INT autoCorr2nd_cplx(
const FIXP_DBL *realBuf = reBuffer;
const FIXP_DBL *imagBuf = imBuffer;
- (len > 64) ? (len_scale = 6) : (len_scale = 5);
+ const int len_scale = fMax(DFRACT_BITS - fNormz((FIXP_DBL)len), 1);
/*
r00r,
r11r,r22r
diff --git a/libFDK/src/nlc_dec.cpp b/libFDK/src/nlc_dec.cpp
index 6e98ce0..3733d98 100644
--- a/libFDK/src/nlc_dec.cpp
+++ b/libFDK/src/nlc_dec.cpp
@@ -1,7 +1,7 @@
/* -----------------------------------------------------------------------------
Software License for The Fraunhofer FDK AAC Codec Library for Android
-© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
+© Copyright 1995 - 2020 Fraunhofer-Gesellschaft zur Förderung der angewandten
Forschung e.V. All rights reserved.
1. INTRODUCTION
@@ -568,12 +568,12 @@ bail:
static ERROR_t huff_decode(HANDLE_FDK_BITSTREAM strm, SCHAR* out_data_1,
SCHAR* out_data_2, DATA_TYPE data_type,
DIFF_TYPE diff_type_1, DIFF_TYPE diff_type_2,
- int num_val, CODING_SCHEME* cdg_scheme, int ldMode) {
+ int num_val, PAIRING* pairing_scheme, int ldMode) {
ERROR_t err = HUFFDEC_OK;
+ CODING_SCHEME coding_scheme = HUFF_1D;
DIFF_TYPE diff_type;
int i = 0;
- ULONG data = 0;
SCHAR pair_vec[28][2];
@@ -596,15 +596,13 @@ static ERROR_t huff_decode(HANDLE_FDK_BITSTREAM strm, SCHAR* out_data_1,
int hufYY;
/* Coding scheme */
- data = FDKreadBits(strm, 1);
- *cdg_scheme = (CODING_SCHEME)(data << PAIR_SHIFT);
+ coding_scheme = (CODING_SCHEME)FDKreadBits(strm, 1);
- if (*cdg_scheme >> PAIR_SHIFT == HUFF_2D) {
+ if (coding_scheme == HUFF_2D) {
if ((out_data_1 != NULL) && (out_data_2 != NULL) && (ldMode == 0)) {
- data = FDKreadBits(strm, 1);
- *cdg_scheme = (CODING_SCHEME)(*cdg_scheme | data);
+ *pairing_scheme = (PAIRING)FDKreadBits(strm, 1);
} else {
- *cdg_scheme = (CODING_SCHEME)(*cdg_scheme | FREQ_PAIR);
+ *pairing_scheme = FREQ_PAIR;
}
}
@@ -613,7 +611,7 @@ static ERROR_t huff_decode(HANDLE_FDK_BITSTREAM strm, SCHAR* out_data_1,
hufYY2 = diff_type_2;
}
- switch (*cdg_scheme >> PAIR_SHIFT) {
+ switch (coding_scheme) {
case HUFF_1D:
p0_flag[0] = (diff_type_1 == DIFF_FREQ);
p0_flag[1] = (diff_type_2 == DIFF_FREQ);
@@ -634,7 +632,7 @@ static ERROR_t huff_decode(HANDLE_FDK_BITSTREAM strm, SCHAR* out_data_1,
case HUFF_2D:
- switch (*cdg_scheme & PAIR_MASK) {
+ switch (*pairing_scheme) {
case FREQ_PAIR:
if (out_data_1 != NULL) {
@@ -843,7 +841,7 @@ ERROR_t EcDataPairDec(DECODER_TYPE DECODER, HANDLE_FDK_BITSTREAM strm,
SCHAR* pDataVec[2] = {NULL, NULL};
DIFF_TYPE diff_type[2] = {DIFF_FREQ, DIFF_FREQ};
- CODING_SCHEME cdg_scheme = HUFF_1D;
+ PAIRING pairing = FREQ_PAIR;
DIRECTION direction = BACKWARDS;
switch (data_type) {
@@ -959,7 +957,7 @@ ERROR_t EcDataPairDec(DECODER_TYPE DECODER, HANDLE_FDK_BITSTREAM strm,
}
/* Huffman decoding */
err = huff_decode(strm, pDataVec[0], pDataVec[1], data_type, diff_type[0],
- diff_type[1], dataBands, &cdg_scheme,
+ diff_type[1], dataBands, &pairing,
(DECODER == SAOC_DECODER));
if (err != HUFFDEC_OK) {
return HUFFDEC_NOTOK;
@@ -986,8 +984,8 @@ ERROR_t EcDataPairDec(DECODER_TYPE DECODER, HANDLE_FDK_BITSTREAM strm,
}
}
- mixed_time_pair = (diff_type[0] != diff_type[1]) &&
- ((cdg_scheme & PAIR_MASK) == TIME_PAIR);
+ mixed_time_pair =
+ (diff_type[0] != diff_type[1]) && (pairing == TIME_PAIR);
if (direction == BACKWARDS) {
if (diff_type[0] == DIFF_FREQ) {
diff --git a/libMpegTPDec/src/tpdec_asc.cpp b/libMpegTPDec/src/tpdec_asc.cpp
index e46cb32..8f77017 100644
--- a/libMpegTPDec/src/tpdec_asc.cpp
+++ b/libMpegTPDec/src/tpdec_asc.cpp
@@ -1694,8 +1694,7 @@ static TRANSPORTDEC_ERROR extElementConfig(CSUsacExtElementConfig *extElement,
const AUDIO_OBJECT_TYPE aot) {
TRANSPORTDEC_ERROR ErrorStatus = TRANSPORTDEC_OK;
- USAC_EXT_ELEMENT_TYPE usacExtElementType =
- (USAC_EXT_ELEMENT_TYPE)escapedValue(hBs, 4, 8, 16);
+ UINT usacExtElementType = escapedValue(hBs, 4, 8, 16);
/* recurve extension elements which are invalid for USAC */
if (aot == AOT_USAC) {
@@ -1712,7 +1711,6 @@ static TRANSPORTDEC_ERROR extElementConfig(CSUsacExtElementConfig *extElement,
}
}
- extElement->usacExtElementType = usacExtElementType;
int usacExtElementConfigLength = escapedValue(hBs, 4, 8, 16);
extElement->usacExtElementConfigLength = (USHORT)usacExtElementConfigLength;
INT bsAnchor;
@@ -1746,8 +1744,10 @@ static TRANSPORTDEC_ERROR extElementConfig(CSUsacExtElementConfig *extElement,
}
} break;
default:
+ usacExtElementType = ID_EXT_ELE_UNKNOWN;
break;
}
+ extElement->usacExtElementType = (USAC_EXT_ELEMENT_TYPE)usacExtElementType;
/* Adjust bit stream position. This is required because of byte alignment and
* unhandled extensions. */
@@ -1776,7 +1776,7 @@ static TRANSPORTDEC_ERROR configExtension(CSUsacConfig *usc,
TRANSPORTDEC_ERROR ErrorStatus = TRANSPORTDEC_OK;
int numConfigExtensions;
- CONFIG_EXT_ID usacConfigExtType;
+ UINT usacConfigExtType;
int usacConfigExtLength;
int loudnessInfoSetIndex =
-1; /* index of loudnessInfoSet config extension. -1 if not contained. */
@@ -1787,7 +1787,7 @@ static TRANSPORTDEC_ERROR configExtension(CSUsacConfig *usc,
for (int confExtIdx = 0; confExtIdx < numConfigExtensions; confExtIdx++) {
INT nbits;
int loudnessInfoSetConfigExtensionPosition = FDKgetValidBits(hBs);
- usacConfigExtType = (CONFIG_EXT_ID)escapedValue(hBs, 4, 8, 16);
+ usacConfigExtType = escapedValue(hBs, 4, 8, 16);
usacConfigExtLength = (int)escapedValue(hBs, 4, 8, 16);
/* Start bit position of config extension */
diff --git a/libMpegTPDec/src/tpdec_latm.cpp b/libMpegTPDec/src/tpdec_latm.cpp
index 3b71db8..c32be54 100644
--- a/libMpegTPDec/src/tpdec_latm.cpp
+++ b/libMpegTPDec/src/tpdec_latm.cpp
@@ -1,7 +1,7 @@
/* -----------------------------------------------------------------------------
Software License for The Fraunhofer FDK AAC Codec Library for Android
-© Copyright 1995 - 2019 Fraunhofer-Gesellschaft zur Förderung der angewandten
+© Copyright 1995 - 2021 Fraunhofer-Gesellschaft zur Förderung der angewandten
Forschung e.V. All rights reserved.
1. INTRODUCTION
@@ -591,6 +591,18 @@ bail:
return (ErrorStatus);
}
+static int CLatmDemux_ReadAuChunkLengthInfo(HANDLE_FDK_BITSTREAM bs) {
+ int len = 0, tmp = 255;
+ int validBytes = (int)FDKgetValidBits(bs) >> 3;
+
+ while (tmp == 255 && validBytes-- > 0) {
+ tmp = (int)FDKreadBits(bs, 8);
+ len += tmp;
+ }
+
+ return ((tmp == 255) ? -1 : (len << 3));
+}
+
TRANSPORTDEC_ERROR CLatmDemux_ReadPayloadLengthInfo(HANDLE_FDK_BITSTREAM bs,
CLatmDemux *pLatmDemux) {
TRANSPORTDEC_ERROR ErrorStatus = TRANSPORTDEC_OK;
@@ -602,11 +614,17 @@ TRANSPORTDEC_ERROR CLatmDemux_ReadPayloadLengthInfo(HANDLE_FDK_BITSTREAM bs,
FDK_ASSERT(pLatmDemux->m_numLayer[prog] <= LATM_MAX_LAYER);
for (UINT lay = 0; lay < pLatmDemux->m_numLayer[prog]; lay++) {
LATM_LAYER_INFO *p_linfo = &pLatmDemux->m_linfo[prog][lay];
+ int auChunkLengthInfo = 0;
switch (p_linfo->m_frameLengthType) {
case 0:
- p_linfo->m_frameLengthInBits = CLatmDemux_ReadAuChunkLengthInfo(bs);
- totalPayloadBits += p_linfo->m_frameLengthInBits;
+ auChunkLengthInfo = CLatmDemux_ReadAuChunkLengthInfo(bs);
+ if (auChunkLengthInfo >= 0) {
+ p_linfo->m_frameLengthInBits = (UINT)auChunkLengthInfo;
+ totalPayloadBits += p_linfo->m_frameLengthInBits;
+ } else {
+ return TRANSPORTDEC_PARSE_ERROR;
+ }
break;
case 3:
case 5:
@@ -627,23 +645,6 @@ TRANSPORTDEC_ERROR CLatmDemux_ReadPayloadLengthInfo(HANDLE_FDK_BITSTREAM bs,
return (ErrorStatus);
}
-int CLatmDemux_ReadAuChunkLengthInfo(HANDLE_FDK_BITSTREAM bs) {
- UCHAR endFlag;
- int len = 0;
-
- do {
- UCHAR tmp = (UCHAR)FDKreadBits(bs, 8);
- endFlag = (tmp < 255);
-
- len += tmp;
-
- } while (endFlag == 0);
-
- len <<= 3; /* convert from bytes to bits */
-
- return len;
-}
-
UINT CLatmDemux_GetFrameLengthInBits(CLatmDemux *pLatmDemux, const UINT prog,
const UINT layer) {
UINT nFrameLenBits = 0;
diff --git a/libMpegTPDec/src/tpdec_latm.h b/libMpegTPDec/src/tpdec_latm.h
index 6af553d..8b8c971 100644
--- a/libMpegTPDec/src/tpdec_latm.h
+++ b/libMpegTPDec/src/tpdec_latm.h
@@ -1,7 +1,7 @@
/* -----------------------------------------------------------------------------
Software License for The Fraunhofer FDK AAC Codec Library for Android
-© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
+© Copyright 1995 - 2021 Fraunhofer-Gesellschaft zur Förderung der angewandten
Forschung e.V. All rights reserved.
1. INTRODUCTION
@@ -151,8 +151,6 @@ typedef struct {
AudioPreRoll */
} CLatmDemux;
-int CLatmDemux_ReadAuChunkLengthInfo(HANDLE_FDK_BITSTREAM bs);
-
TRANSPORTDEC_ERROR CLatmDemux_Read(HANDLE_FDK_BITSTREAM bs,
CLatmDemux *pLatmDemux, TRANSPORT_TYPE tt,
CSTpCallBacks *pTpDecCallbacks,
diff --git a/libPCMutils/src/pcmdmx_lib.cpp b/libPCMutils/src/pcmdmx_lib.cpp
index 2070dbc..fca12ce 100644
--- a/libPCMutils/src/pcmdmx_lib.cpp
+++ b/libPCMutils/src/pcmdmx_lib.cpp
@@ -1,7 +1,7 @@
/* -----------------------------------------------------------------------------
Software License for The Fraunhofer FDK AAC Codec Library for Android
-© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
+© Copyright 1995 - 2021 Fraunhofer-Gesellschaft zur Förderung der angewandten
Forschung e.V. All rights reserved.
1. INTRODUCTION
@@ -494,13 +494,40 @@ static PCM_DMX_CHANNEL_MODE getChMode4Plain(
return plainChMode;
}
-static inline UINT getIdxSum(UCHAR numCh) {
- UINT result = 0;
- int i;
- for (i = 1; i < numCh; i += 1) {
- result += i;
+/** Validates the channel indices of all channels present in the bitstream.
+ * The channel indices have to be consecutive and unique for each audio channel
+ *type.
+ * @param [in] The total number of channels of the given configuration.
+ * @param [in] The total number of channels of the current audio channel type of
+ *the given configuration.
+ * @param [in] Audio channel type to be examined.
+ * @param [in] Array holding the corresponding channel types for each channel.
+ * @param [in] Array holding the corresponding channel type indices for each
+ *channel.
+ * @returns Returns 1 on success, returns 0 on error.
+ **/
+static UINT validateIndices(UINT numChannels, UINT numChannelsPlaneAndGrp,
+ AUDIO_CHANNEL_TYPE aChType,
+ const AUDIO_CHANNEL_TYPE channelType[],
+ const UCHAR channelIndices[]) {
+ for (UINT reqValue = 0; reqValue < numChannelsPlaneAndGrp; reqValue++) {
+ int found = FALSE;
+ for (UINT i = 0; i < numChannels; i++) {
+ if (channelType[i] == aChType) {
+ if (channelIndices[i] == reqValue) {
+ if (found == TRUE) {
+ return 0; /* Found channel index a second time */
+ } else {
+ found = TRUE; /* Found channel index */
+ }
+ }
+ }
+ }
+ if (found == FALSE) {
+ return 0; /* Did not find channel index */
+ }
}
- return result;
+ return 1; /* Successfully validated channel indices */
}
/** Evaluate a given channel configuration and extract a packed channel mode. In
@@ -523,7 +550,6 @@ static PCMDMX_ERROR getChannelMode(
UCHAR offsetTable[(8)], /* out */
PCM_DMX_CHANNEL_MODE *chMode /* out */
) {
- UINT idxSum[(3)][(4)];
UCHAR numCh[(3)][(4)];
UCHAR mapped[(8)];
PCM_DMX_SPEAKER_POSITION spkrPos[(8)];
@@ -538,7 +564,6 @@ static PCMDMX_ERROR getChannelMode(
FDK_ASSERT(chMode != NULL);
/* For details see ISO/IEC 13818-7:2005(E), 8.5.3 Channel configuration */
- FDKmemclear(idxSum, (3) * (4) * sizeof(UINT));
FDKmemclear(numCh, (3) * (4) * sizeof(UCHAR));
FDKmemclear(mapped, (8) * sizeof(UCHAR));
FDKmemclear(spkrPos, (8) * sizeof(PCM_DMX_SPEAKER_POSITION));
@@ -552,19 +577,22 @@ static PCMDMX_ERROR getChannelMode(
(channelType[ch] & 0x0F) - 1,
0); /* Assign all undefined channels (ACT_NONE) to front channels. */
numCh[channelType[ch] >> 4][chGrp] += 1;
- idxSum[channelType[ch] >> 4][chGrp] += channelIndices[ch];
}
- if (numChannels > TWO_CHANNEL) {
+
+ {
int chGrp;
/* Sanity check on the indices */
for (chGrp = 0; chGrp < (4); chGrp += 1) {
int plane;
for (plane = 0; plane < (3); plane += 1) {
- if (idxSum[plane][chGrp] != getIdxSum(numCh[plane][chGrp])) {
+ if (numCh[plane][chGrp] == 0) continue;
+ AUDIO_CHANNEL_TYPE aChType =
+ (AUDIO_CHANNEL_TYPE)((plane << 4) | ((chGrp + 1) & 0xF));
+ if (!validateIndices(numChannels, numCh[plane][chGrp], aChType,
+ channelType, channelIndices)) {
unsigned idxCnt = 0;
for (ch = 0; ch < numChannels; ch += 1) {
- if (channelType[ch] ==
- (AUDIO_CHANNEL_TYPE)((plane << 4) | ((chGrp + 1) & 0xF))) {
+ if (channelType[ch] == aChType) {
channelIndices[ch] = idxCnt++;
}
}
diff --git a/libSACdec/src/sac_bitdec.cpp b/libSACdec/src/sac_bitdec.cpp
index 4485ccf..25b3d9e 100644
--- a/libSACdec/src/sac_bitdec.cpp
+++ b/libSACdec/src/sac_bitdec.cpp
@@ -1,7 +1,7 @@
/* -----------------------------------------------------------------------------
Software License for The Fraunhofer FDK AAC Codec Library for Android
-© Copyright 1995 - 2019 Fraunhofer-Gesellschaft zur Förderung der angewandten
+© Copyright 1995 - 2020 Fraunhofer-Gesellschaft zur Förderung der angewandten
Forschung e.V. All rights reserved.
1. INTRODUCTION
@@ -488,12 +488,17 @@ SACDEC_ERROR SpatialDecParseSpecificConfig(
pSpatialSpecificConfig->freqRes =
(SPATIALDEC_FREQ_RES)freqResTable_LD[bsFreqRes];
- pSpatialSpecificConfig->treeConfig =
- (SPATIALDEC_TREE_CONFIG)FDKreadBits(bitstream, 4);
+ {
+ UINT treeConfig = FDKreadBits(bitstream, 4);
- if (pSpatialSpecificConfig->treeConfig != SPATIALDEC_MODE_RSVD7) {
- err = MPS_UNSUPPORTED_CONFIG;
- goto bail;
+ switch (treeConfig) {
+ case SPATIALDEC_MODE_RSVD7:
+ pSpatialSpecificConfig->treeConfig = (SPATIALDEC_TREE_CONFIG)treeConfig;
+ break;
+ default:
+ err = MPS_UNSUPPORTED_CONFIG;
+ goto bail;
+ }
}
{
diff --git a/libSACdec/src/sac_process.cpp b/libSACdec/src/sac_process.cpp
index 22091a9..33a1647 100644
--- a/libSACdec/src/sac_process.cpp
+++ b/libSACdec/src/sac_process.cpp
@@ -1,7 +1,7 @@
/* -----------------------------------------------------------------------------
Software License for The Fraunhofer FDK AAC Codec Library for Android
-© Copyright 1995 - 2019 Fraunhofer-Gesellschaft zur Förderung der angewandten
+© Copyright 1995 - 2021 Fraunhofer-Gesellschaft zur Förderung der angewandten
Forschung e.V. All rights reserved.
1. INTRODUCTION
@@ -517,12 +517,11 @@ SACDEC_ERROR SpatialDecApplyM2_Mode212_ResidualsPlusPhaseCoding(
maxVal = fAbs(iReal0) | fAbs(iImag0);
maxVal |= fAbs(iReal1);
- s = fMax(CntLeadingZeros(maxVal) - 1, 0);
- s = fMin(s, scale_param_m2);
+ s = fMin(CntLeadingZeros(maxVal) - 2, scale_param_m2);
- mReal0 = iReal0 << s;
- mImag0 = iImag0 << s;
- mReal1 = iReal1 << s;
+ mReal0 = scaleValue(iReal0, s);
+ mImag0 = scaleValue(iImag0, s);
+ mReal1 = scaleValue(iReal1, s);
s = scale_param_m2 - s;
@@ -562,12 +561,11 @@ SACDEC_ERROR SpatialDecApplyM2_Mode212_ResidualsPlusPhaseCoding(
maxVal = fAbs(iReal0) | fAbs(iImag0);
maxVal |= fAbs(iReal1);
- s = fMax(CntLeadingZeros(maxVal) - 1, 0);
- s = fMin(s, scale_param_m2);
+ s = fMin(CntLeadingZeros(maxVal) - 2, scale_param_m2);
- mReal0 = FX_DBL2FX_SGL(iReal0 << s);
- mImag0 = FX_DBL2FX_SGL(iImag0 << s);
- mReal1 = FX_DBL2FX_SGL(iReal1 << s);
+ mReal0 = FX_DBL2FX_SGL(scaleValue(iReal0, s));
+ mImag0 = FX_DBL2FX_SGL(scaleValue(iImag0, s));
+ mReal1 = FX_DBL2FX_SGL(scaleValue(iReal1, s));
s = scale_param_m2 - s;
diff --git a/libSACdec/src/sac_reshapeBBEnv.cpp b/libSACdec/src/sac_reshapeBBEnv.cpp
index 272d009..72f4e58 100644
--- a/libSACdec/src/sac_reshapeBBEnv.cpp
+++ b/libSACdec/src/sac_reshapeBBEnv.cpp
@@ -1,7 +1,7 @@
/* -----------------------------------------------------------------------------
Software License for The Fraunhofer FDK AAC Codec Library for Android
-© Copyright 1995 - 2019 Fraunhofer-Gesellschaft zur Förderung der angewandten
+© Copyright 1995 - 2021 Fraunhofer-Gesellschaft zur Förderung der angewandten
Forschung e.V. All rights reserved.
1. INTRODUCTION
@@ -241,29 +241,56 @@ static inline void combineDryWet(FIXP_DBL *RESTRICT pReal,
}
}
-static inline void slotAmp(FIXP_DBL *RESTRICT slotAmp_dry,
- FIXP_DBL *RESTRICT slotAmp_wet,
- FIXP_DBL *RESTRICT pHybOutputRealDry,
- FIXP_DBL *RESTRICT pHybOutputImagDry,
- FIXP_DBL *RESTRICT pHybOutputRealWet,
- FIXP_DBL *RESTRICT pHybOutputImagWet, INT cplxBands,
- INT hybBands) {
- INT qs;
+static inline void slotAmp(
+ FIXP_DBL *RESTRICT slotAmp_dry, INT *RESTRICT slotAmp_dry_e,
+ FIXP_DBL *RESTRICT slotAmp_wet, INT *RESTRICT slotAmp_wet_e,
+ FIXP_DBL *RESTRICT pHybOutputRealDry, FIXP_DBL *RESTRICT pHybOutputImagDry,
+ FIXP_DBL *RESTRICT pHybOutputRealWet, FIXP_DBL *RESTRICT pHybOutputImagWet,
+ INT cplxBands, INT hybBands) {
+ INT qs, s1, s2, headroom_dry, headroom_wet;
FIXP_DBL dry, wet;
+ /* headroom can be reduced by 1 bit due to use of fPow2Div2 */
+ s1 = DFRACT_BITS - 1 - CntLeadingZeros(hybBands + cplxBands);
+ headroom_dry = fMin(getScalefactor(pHybOutputRealDry, hybBands),
+ getScalefactor(pHybOutputImagDry, cplxBands));
+ headroom_wet = fMin(getScalefactor(pHybOutputRealWet, hybBands),
+ getScalefactor(pHybOutputImagWet, cplxBands));
+
dry = wet = FL2FXCONST_DBL(0.0f);
for (qs = 0; qs < cplxBands; qs++) {
- dry = fAddSaturate(dry, fPow2Div2(pHybOutputRealDry[qs] << (1)) +
- fPow2Div2(pHybOutputImagDry[qs] << (1)));
- wet = fAddSaturate(wet, fPow2Div2(pHybOutputRealWet[qs] << (1)) +
- fPow2Div2(pHybOutputImagWet[qs] << (1)));
+ /* sum up dry part */
+ dry += (fPow2Div2(pHybOutputRealDry[qs] << headroom_dry) >> s1);
+ dry += (fPow2Div2(pHybOutputImagDry[qs] << headroom_dry) >> s1);
+ /* sum up wet part */
+ wet += (fPow2Div2(pHybOutputRealWet[qs] << headroom_wet) >> s1);
+ wet += (fPow2Div2(pHybOutputImagWet[qs] << headroom_wet) >> s1);
}
for (; qs < hybBands; qs++) {
- dry = fAddSaturate(dry, fPow2Div2(pHybOutputRealDry[qs] << (1)));
- wet = fAddSaturate(wet, fPow2Div2(pHybOutputRealWet[qs] << (1)));
+ dry += (fPow2Div2(pHybOutputRealDry[qs] << headroom_dry) >> s1);
+ wet += (fPow2Div2(pHybOutputRealWet[qs] << headroom_wet) >> s1);
+ }
+
+ /* consider fPow2Div2() */
+ s1 += 1;
+
+ /* normalize dry part, ensure that exponent is even */
+ s2 = fixMax(0, CntLeadingZeros(dry) - 1);
+ *slotAmp_dry = dry << s2;
+ *slotAmp_dry_e = s1 - s2 - 2 * headroom_dry;
+ if (*slotAmp_dry_e & 1) {
+ *slotAmp_dry = *slotAmp_dry >> 1;
+ *slotAmp_dry_e += 1;
+ }
+
+ /* normalize wet part, ensure that exponent is even */
+ s2 = fixMax(0, CntLeadingZeros(wet) - 1);
+ *slotAmp_wet = wet << s2;
+ *slotAmp_wet_e = s1 - s2 - 2 * headroom_wet;
+ if (*slotAmp_wet_e & 1) {
+ *slotAmp_wet = *slotAmp_wet >> 1;
+ *slotAmp_wet_e += 1;
}
- *slotAmp_dry = dry >> (2 * (1));
- *slotAmp_wet = wet >> (2 * (1));
}
#if defined(__aarch64__)
@@ -533,6 +560,7 @@ void SpatialDecReshapeBBEnv(spatialDec *self, const SPATIAL_BS_FRAME *frame,
INT ts) {
INT ch, scale;
INT dryFacSF, slotAmpSF;
+ INT slotAmp_dry_e, slotAmp_wet_e;
FIXP_DBL tmp, dryFac, envShape;
FIXP_DBL slotAmp_dry, slotAmp_wet, slotAmp_ratio;
FIXP_DBL envDry[MAX_OUTPUT_CHANNELS], envDmx[2];
@@ -594,22 +622,25 @@ void SpatialDecReshapeBBEnv(spatialDec *self, const SPATIAL_BS_FRAME *frame,
dryFacSF = SF_SHAPE + 2 * dryFacSF;
}
+ slotAmp_dry_e = slotAmp_wet_e = 0;
+
/* calculate slotAmp_dry and slotAmp_wet */
- slotAmp(&slotAmp_dry, &slotAmp_wet, &self->hybOutputRealDry__FDK[ch][6],
+ slotAmp(&slotAmp_dry, &slotAmp_dry_e, &slotAmp_wet, &slotAmp_wet_e,
+ &self->hybOutputRealDry__FDK[ch][6],
&self->hybOutputImagDry__FDK[ch][6],
&self->hybOutputRealWet__FDK[ch][6],
&self->hybOutputImagWet__FDK[ch][6], cplxBands, hybBands);
+ /* exponents must be even due to subsequent square root calculation */
+ FDK_ASSERT(((slotAmp_dry_e & 1) == 0) && ((slotAmp_wet_e & 1) == 0));
+
/* slotAmp_ratio will be scaled by slotAmpSF bits */
if (slotAmp_dry != FL2FXCONST_DBL(0.0f)) {
- sc = fixMax(0, CntLeadingZeros(slotAmp_wet) - 1);
- sc = sc - (sc & 1);
-
- slotAmp_wet = sqrtFixp(slotAmp_wet << sc);
+ slotAmp_wet = sqrtFixp(slotAmp_wet);
slotAmp_dry = invSqrtNorm2(slotAmp_dry, &slotAmpSF);
slotAmp_ratio = fMult(slotAmp_wet, slotAmp_dry);
- slotAmpSF = slotAmpSF - (sc >> 1);
+ slotAmpSF = slotAmpSF + (slotAmp_wet_e >> 1) - (slotAmp_dry_e >> 1);
}
/* calculate common scale factor */
diff --git a/libSACdec/src/sac_stp.cpp b/libSACdec/src/sac_stp.cpp
index b328c82..0e6affa 100644
--- a/libSACdec/src/sac_stp.cpp
+++ b/libSACdec/src/sac_stp.cpp
@@ -1,7 +1,7 @@
/* -----------------------------------------------------------------------------
Software License for The Fraunhofer FDK AAC Codec Library for Android
-© Copyright 1995 - 2020 Fraunhofer-Gesellschaft zur Förderung der angewandten
+© Copyright 1995 - 2021 Fraunhofer-Gesellschaft zur Förderung der angewandten
Forschung e.V. All rights reserved.
1. INTRODUCTION
@@ -229,15 +229,13 @@ inline void combineSignalCplxScale1(FIXP_DBL *hybOutputRealDry,
int n;
FIXP_DBL scaleY;
for (n = bands - 1; n >= 0; n--) {
- scaleY = fMultDiv2(scaleX, *pBP);
+ scaleY = fMult(scaleX, *pBP);
*hybOutputRealDry = SATURATE_LEFT_SHIFT(
- (*hybOutputRealDry >> 1) +
- (fMultDiv2(*hybOutputRealWet, scaleY) << (SF_SCALE + 1)),
- 1, DFRACT_BITS);
+ (*hybOutputRealDry >> SF_SCALE) + fMult(*hybOutputRealWet, scaleY),
+ SF_SCALE, DFRACT_BITS);
*hybOutputImagDry = SATURATE_LEFT_SHIFT(
- (*hybOutputImagDry >> 1) +
- (fMultDiv2(*hybOutputImagWet, scaleY) << (SF_SCALE + 1)),
- 1, DFRACT_BITS);
+ (*hybOutputImagDry >> SF_SCALE) + fMult(*hybOutputImagWet, scaleY),
+ SF_SCALE, DFRACT_BITS);
hybOutputRealDry++, hybOutputRealWet++;
hybOutputImagDry++, hybOutputImagWet++;
pBP++;
@@ -252,12 +250,12 @@ inline void combineSignalCplxScale2(FIXP_DBL *hybOutputRealDry,
int n;
for (n = bands - 1; n >= 0; n--) {
- *hybOutputRealDry =
- *hybOutputRealDry +
- (fMultDiv2(*hybOutputRealWet, scaleX) << (SF_SCALE + 1));
- *hybOutputImagDry =
- *hybOutputImagDry +
- (fMultDiv2(*hybOutputImagWet, scaleX) << (SF_SCALE + 1));
+ *hybOutputRealDry = SATURATE_LEFT_SHIFT(
+ (*hybOutputRealDry >> SF_SCALE) + fMult(*hybOutputRealWet, scaleX),
+ SF_SCALE, DFRACT_BITS);
+ *hybOutputImagDry = SATURATE_LEFT_SHIFT(
+ (*hybOutputImagDry >> SF_SCALE) + fMult(*hybOutputImagWet, scaleX),
+ SF_SCALE, DFRACT_BITS);
hybOutputRealDry++, hybOutputRealWet++;
hybOutputImagDry++, hybOutputImagWet++;
}
diff --git a/libSBRdec/src/arm/lpp_tran_arm.cpp b/libSBRdec/src/arm/lpp_tran_arm.cpp
deleted file mode 100644
index db1948f..0000000
--- a/libSBRdec/src/arm/lpp_tran_arm.cpp
+++ /dev/null
@@ -1,159 +0,0 @@
-/* -----------------------------------------------------------------------------
-Software License for The Fraunhofer FDK AAC Codec Library for Android
-
-© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
-Forschung e.V. All rights reserved.
-
- 1. INTRODUCTION
-The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
-that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
-scheme for digital audio. This FDK AAC Codec software is intended to be used on
-a wide variety of Android devices.
-
-AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
-general perceptual audio codecs. AAC-ELD is considered the best-performing
-full-bandwidth communications codec by independent studies and is widely
-deployed. AAC has been standardized by ISO and IEC as part of the MPEG
-specifications.
-
-Patent licenses for necessary patent claims for the FDK AAC Codec (including
-those of Fraunhofer) may be obtained through Via Licensing
-(www.vialicensing.com) or through the respective patent owners individually for
-the purpose of encoding or decoding bit streams in products that are compliant
-with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
-Android devices already license these patent claims through Via Licensing or
-directly from the patent owners, and therefore FDK AAC Codec software may
-already be covered under those patent licenses when it is used for those
-licensed purposes only.
-
-Commercially-licensed AAC software libraries, including floating-point versions
-with enhanced sound quality, are also available from Fraunhofer. Users are
-encouraged to check the Fraunhofer website for additional applications
-information and documentation.
-
-2. COPYRIGHT LICENSE
-
-Redistribution and use in source and binary forms, with or without modification,
-are permitted without payment of copyright license fees provided that you
-satisfy the following conditions:
-
-You must retain the complete text of this software license in redistributions of
-the FDK AAC Codec or your modifications thereto in source code form.
-
-You must retain the complete text of this software license in the documentation
-and/or other materials provided with redistributions of the FDK AAC Codec or
-your modifications thereto in binary form. You must make available free of
-charge copies of the complete source code of the FDK AAC Codec and your
-modifications thereto to recipients of copies in binary form.
-
-The name of Fraunhofer may not be used to endorse or promote products derived
-from this library without prior written permission.
-
-You may not charge copyright license fees for anyone to use, copy or distribute
-the FDK AAC Codec software or your modifications thereto.
-
-Your modified versions of the FDK AAC Codec must carry prominent notices stating
-that you changed the software and the date of any change. For modified versions
-of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
-must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
-AAC Codec Library for Android."
-
-3. NO PATENT LICENSE
-
-NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
-limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
-Fraunhofer provides no warranty of patent non-infringement with respect to this
-software.
-
-You may use this FDK AAC Codec software or modifications thereto only for
-purposes that are authorized by appropriate patent licenses.
-
-4. DISCLAIMER
-
-This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
-holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
-including but not limited to the implied warranties of merchantability and
-fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
-CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
-or consequential damages, including but not limited to procurement of substitute
-goods or services; loss of use, data, or profits, or business interruption,
-however caused and on any theory of liability, whether in contract, strict
-liability, or tort (including negligence), arising in any way out of the use of
-this software, even if advised of the possibility of such damage.
-
-5. CONTACT INFORMATION
-
-Fraunhofer Institute for Integrated Circuits IIS
-Attention: Audio and Multimedia Departments - FDK AAC LL
-Am Wolfsmantel 33
-91058 Erlangen, Germany
-
-www.iis.fraunhofer.de/amm
-amm-info@iis.fraunhofer.de
------------------------------------------------------------------------------ */
-
-/**************************** SBR decoder library ******************************
-
- Author(s): Arthur Tritthart
-
- Description: (ARM optimised) LPP transposer subroutines
-
-*******************************************************************************/
-
-#if defined(__arm__)
-
-#define FUNCTION_LPPTRANSPOSER_func1
-
-#ifdef FUNCTION_LPPTRANSPOSER_func1
-
-/* Note: This code requires only 43 cycles per iteration instead of 61 on
- * ARM926EJ-S */
-static void lppTransposer_func1(FIXP_DBL *lowBandReal, FIXP_DBL *lowBandImag,
- FIXP_DBL **qmfBufferReal,
- FIXP_DBL **qmfBufferImag, int loops, int hiBand,
- int dynamicScale, int descale, FIXP_SGL a0r,
- FIXP_SGL a0i, FIXP_SGL a1r, FIXP_SGL a1i,
- const int fPreWhitening,
- FIXP_DBL preWhiteningGain,
- int preWhiteningGains_sf) {
- FIXP_DBL real1, real2, imag1, imag2, accu1, accu2;
-
- real2 = lowBandReal[-2];
- real1 = lowBandReal[-1];
- imag2 = lowBandImag[-2];
- imag1 = lowBandImag[-1];
- for (int i = 0; i < loops; i++) {
- accu1 = fMultDiv2(a0r, real1);
- accu2 = fMultDiv2(a0i, imag1);
- accu1 = fMultAddDiv2(accu1, a1r, real2);
- accu2 = fMultAddDiv2(accu2, a1i, imag2);
- real2 = fMultDiv2(a1i, real2);
- accu1 = accu1 - accu2;
- accu1 = accu1 >> dynamicScale;
-
- accu2 = fMultAddDiv2(real2, a1r, imag2);
- real2 = real1;
- imag2 = imag1;
- accu2 = fMultAddDiv2(accu2, a0i, real1);
- real1 = lowBandReal[i];
- accu2 = fMultAddDiv2(accu2, a0r, imag1);
- imag1 = lowBandImag[i];
- accu2 = accu2 >> dynamicScale;
-
- accu1 <<= 1;
- accu2 <<= 1;
- accu1 += (real1 >> descale);
- accu2 += (imag1 >> descale);
- if (fPreWhitening) {
- accu1 = scaleValueSaturate(fMultDiv2(accu1, preWhiteningGain),
- preWhiteningGains_sf);
- accu2 = scaleValueSaturate(fMultDiv2(accu2, preWhiteningGain),
- preWhiteningGains_sf);
- }
- qmfBufferReal[i][hiBand] = accu1;
- qmfBufferImag[i][hiBand] = accu2;
- }
-}
-#endif /* #ifdef FUNCTION_LPPTRANSPOSER_func1 */
-
-#endif /* __arm__ */
diff --git a/libSBRdec/src/env_calc.cpp b/libSBRdec/src/env_calc.cpp
index ad5edfe..cefa612 100644
--- a/libSBRdec/src/env_calc.cpp
+++ b/libSBRdec/src/env_calc.cpp
@@ -1,7 +1,7 @@
/* -----------------------------------------------------------------------------
Software License for The Fraunhofer FDK AAC Codec Library for Android
-© Copyright 1995 - 2020 Fraunhofer-Gesellschaft zur Förderung der angewandten
+© Copyright 1995 - 2021 Fraunhofer-Gesellschaft zur Förderung der angewandten
Forschung e.V. All rights reserved.
1. INTRODUCTION
@@ -664,7 +664,7 @@ static void apply_inter_tes(FIXP_DBL **qmfReal, FIXP_DBL **qmfImag,
gain_sf[i] = mult_sf - total_power_low_sf + sf2;
gain[i] = sqrtFixp_lookup(gain[i], &gain_sf[i]);
if (gain_sf[i] < 0) {
- gain[i] >>= -gain_sf[i];
+ gain[i] >>= fMin(DFRACT_BITS - 1, -gain_sf[i]);
gain_sf[i] = 0;
}
} else {
@@ -683,11 +683,6 @@ static void apply_inter_tes(FIXP_DBL **qmfReal, FIXP_DBL **qmfImag,
/* gain[i] = g_inter[i] */
for (i = 0; i < nbSubsample; ++i) {
- if (gain_sf[i] < 0) {
- gain[i] >>= -gain_sf[i];
- gain_sf[i] = 0;
- }
-
/* calculate: gain[i] = 1.0f + gamma * (gain[i] - 1.0f); */
FIXP_DBL one = (FIXP_DBL)MAXVAL_DBL >>
gain_sf[i]; /* to substract this from gain[i] */
@@ -755,23 +750,15 @@ static void apply_inter_tes(FIXP_DBL **qmfReal, FIXP_DBL **qmfImag,
int gain_adj_sf = gain_adj_2_sf;
for (i = 0; i < nbSubsample; ++i) {
- gain[i] = fMult(gain[i], gain_adj);
- gain_sf[i] += gain_adj_sf;
-
- /* limit gain */
- if (gain_sf[i] > INTER_TES_SF_CHANGE) {
- gain[i] = (FIXP_DBL)MAXVAL_DBL;
- gain_sf[i] = INTER_TES_SF_CHANGE;
- }
- }
-
- for (i = 0; i < nbSubsample; ++i) {
- /* equalize gain[]'s scale factors */
- gain[i] >>= INTER_TES_SF_CHANGE - gain_sf[i];
+ int gain_e = fMax(
+ fMin(gain_sf[i] + gain_adj_sf - INTER_TES_SF_CHANGE, DFRACT_BITS - 1),
+ -(DFRACT_BITS - 1));
+ FIXP_DBL gain_final = fMult(gain[i], gain_adj);
+ gain_final = scaleValueSaturate(gain_final, gain_e);
for (j = lowSubband; j < highSubband; j++) {
- qmfReal[startPos + i][j] = fMult(qmfReal[startPos + i][j], gain[i]);
- qmfImag[startPos + i][j] = fMult(qmfImag[startPos + i][j], gain[i]);
+ qmfReal[startPos + i][j] = fMult(qmfReal[startPos + i][j], gain_final);
+ qmfImag[startPos + i][j] = fMult(qmfImag[startPos + i][j], gain_final);
}
}
} else { /* gamma_idx == 0 */
diff --git a/libSBRdec/src/hbe.cpp b/libSBRdec/src/hbe.cpp
index d210bb6..f2452ea 100644
--- a/libSBRdec/src/hbe.cpp
+++ b/libSBRdec/src/hbe.cpp
@@ -1,7 +1,7 @@
/* -----------------------------------------------------------------------------
Software License for The Fraunhofer FDK AAC Codec Library for Android
-© Copyright 1995 - 2019 Fraunhofer-Gesellschaft zur Förderung der angewandten
+© Copyright 1995 - 2021 Fraunhofer-Gesellschaft zur Förderung der angewandten
Forschung e.V. All rights reserved.
1. INTRODUCTION
@@ -1400,42 +1400,27 @@ void QmfTransposerApply(HANDLE_HBE_TRANSPOSER hQmfTransposer,
if (shift_ov != 0) {
for (i = 0; i < HBE_MAX_OUT_SLOTS; i++) {
- for (band = 0; band < QMF_SYNTH_CHANNELS; band++) {
- if (shift_ov >= 0) {
- hQmfTransposer->qmfHBEBufReal_F[i][band] <<= shift_ov;
- hQmfTransposer->qmfHBEBufImag_F[i][band] <<= shift_ov;
- } else {
- hQmfTransposer->qmfHBEBufReal_F[i][band] >>= (-shift_ov);
- hQmfTransposer->qmfHBEBufImag_F[i][band] >>= (-shift_ov);
- }
- }
+ scaleValuesSaturate(&hQmfTransposer->qmfHBEBufReal_F[i][0],
+ QMF_SYNTH_CHANNELS, shift_ov);
+ scaleValuesSaturate(&hQmfTransposer->qmfHBEBufImag_F[i][0],
+ QMF_SYNTH_CHANNELS, shift_ov);
}
- }
- if ((keepStatesSyncedMode == KEEP_STATES_SYNCED_OFF) && shift_ov != 0) {
- for (i = timeStep * firstSlotOffsset; i < ov_len; i++) {
- for (band = hQmfTransposer->startBand; band < hQmfTransposer->stopBand;
- band++) {
- if (shift_ov >= 0) {
- ppQmfBufferOutReal_F[i][band] <<= shift_ov;
- ppQmfBufferOutImag_F[i][band] <<= shift_ov;
- } else {
- ppQmfBufferOutReal_F[i][band] >>= (-shift_ov);
- ppQmfBufferOutImag_F[i][band] >>= (-shift_ov);
- }
+ if (keepStatesSyncedMode == KEEP_STATES_SYNCED_OFF) {
+ int nBands =
+ fMax(0, hQmfTransposer->stopBand - hQmfTransposer->startBand);
+
+ for (i = timeStep * firstSlotOffsset; i < ov_len; i++) {
+ scaleValuesSaturate(&ppQmfBufferOutReal_F[i][hQmfTransposer->startBand],
+ nBands, shift_ov);
+ scaleValuesSaturate(&ppQmfBufferOutImag_F[i][hQmfTransposer->startBand],
+ nBands, shift_ov);
}
- }
- /* shift lpc filterstates */
- for (i = 0; i < timeStep * firstSlotOffsset + LPC_ORDER; i++) {
- for (band = 0; band < (64); band++) {
- if (shift_ov >= 0) {
- lpcFilterStatesReal[i][band] <<= shift_ov;
- lpcFilterStatesImag[i][band] <<= shift_ov;
- } else {
- lpcFilterStatesReal[i][band] >>= (-shift_ov);
- lpcFilterStatesImag[i][band] >>= (-shift_ov);
- }
+ /* shift lpc filterstates */
+ for (i = 0; i < timeStep * firstSlotOffsset + LPC_ORDER; i++) {
+ scaleValuesSaturate(&lpcFilterStatesReal[i][0], (64), shift_ov);
+ scaleValuesSaturate(&lpcFilterStatesImag[i][0], (64), shift_ov);
}
}
}
diff --git a/libSBRdec/src/lpp_tran.cpp b/libSBRdec/src/lpp_tran.cpp
index 93e1158..68a25bf 100644
--- a/libSBRdec/src/lpp_tran.cpp
+++ b/libSBRdec/src/lpp_tran.cpp
@@ -1,7 +1,7 @@
/* -----------------------------------------------------------------------------
Software License for The Fraunhofer FDK AAC Codec Library for Android
-© Copyright 1995 - 2019 Fraunhofer-Gesellschaft zur Förderung der angewandten
+© Copyright 1995 - 2021 Fraunhofer-Gesellschaft zur Förderung der angewandten
Forschung e.V. All rights reserved.
1. INTRODUCTION
@@ -132,10 +132,6 @@ amm-info@iis.fraunhofer.de
#include "HFgen_preFlat.h"
-#if defined(__arm__)
-#include "arm/lpp_tran_arm.cpp"
-#endif
-
#define LPC_SCALE_FACTOR 2
/*!
@@ -220,19 +216,21 @@ static inline void calc_qmfBufferReal(FIXP_DBL **qmfBufferReal,
const FIXP_DBL *const lowBandReal,
const int startSample,
const int stopSample, const UCHAR hiBand,
- const int dynamicScale, const int descale,
+ const int dynamicScale,
const FIXP_SGL a0r, const FIXP_SGL a1r) {
- FIXP_DBL accu1, accu2;
- int i;
+ const int dynscale = fixMax(0, dynamicScale - 1) + 1;
+ const int rescale = -fixMin(0, dynamicScale - 1) + 1;
+ const int descale =
+ fixMin(DFRACT_BITS - 1, LPC_SCALE_FACTOR + dynamicScale + rescale);
+
+ for (int i = 0; i < stopSample - startSample; i++) {
+ FIXP_DBL accu;
- for (i = 0; i < stopSample - startSample; i++) {
- accu1 = fMultDiv2(a1r, lowBandReal[i]);
- accu1 = (fMultDiv2(a0r, lowBandReal[i + 1]) + accu1);
- accu1 = accu1 >> dynamicScale;
+ accu = fMultDiv2(a1r, lowBandReal[i]) + fMultDiv2(a0r, lowBandReal[i + 1]);
+ accu = (lowBandReal[i + 2] >> descale) + (accu >> dynscale);
- accu1 <<= 1;
- accu2 = (lowBandReal[i + 2] >> descale);
- qmfBufferReal[i + startSample][hiBand] = accu1 + accu2;
+ qmfBufferReal[i + startSample][hiBand] =
+ SATURATE_LEFT_SHIFT(accu, rescale, DFRACT_BITS);
}
}
@@ -529,7 +527,7 @@ void lppTransposer(
if ((scale > 0) && (result >= (FIXP_DBL)MAXVAL_DBL >> scale)) {
resetLPCCoeffs = 1;
} else {
- alphar[1] = FX_DBL2FX_SGL(scaleValue(result, scale));
+ alphar[1] = FX_DBL2FX_SGL(scaleValueSaturate(result, scale));
if ((tmp < FL2FX_DBL(0.0f)) ^ (ac.det < FL2FX_DBL(0.0f))) {
alphar[1] = -alphar[1];
}
@@ -557,7 +555,7 @@ void lppTransposer(
scale)) {
resetLPCCoeffs = 1;
} else {
- alphai[1] = FX_DBL2FX_SGL(scaleValue(result, scale));
+ alphai[1] = FX_DBL2FX_SGL(scaleValueSaturate(result, scale));
if ((tmp < FL2FX_DBL(0.0f)) ^ (ac.det < FL2FX_DBL(0.0f))) {
alphai[1] = -alphai[1];
}
@@ -596,7 +594,7 @@ void lppTransposer(
} else {
INT scale;
FIXP_DBL result = fDivNorm(absTmp, fixp_abs(ac.r11r), &scale);
- alphar[0] = FX_DBL2FX_SGL(scaleValue(result, scale + 1));
+ alphar[0] = FX_DBL2FX_SGL(scaleValueSaturate(result, scale + 1));
if ((tmp > FL2FX_DBL(0.0f)) ^ (ac.r11r < FL2FX_DBL(0.0f)))
alphar[0] = -alphar[0];
@@ -616,7 +614,7 @@ void lppTransposer(
} else {
INT scale;
FIXP_DBL result = fDivNorm(absTmp, fixp_abs(ac.r11r), &scale);
- alphai[0] = FX_DBL2FX_SGL(scaleValue(result, scale + 1));
+ alphai[0] = FX_DBL2FX_SGL(scaleValueSaturate(result, scale + 1));
if ((tmp > FL2FX_DBL(0.0f)) ^ (ac.r11r < FL2FX_DBL(0.0f)))
alphai[0] = -alphai[0];
}
@@ -659,7 +657,7 @@ void lppTransposer(
INT scale;
FIXP_DBL result =
fDivNorm(fixp_abs(ac.r01r), fixp_abs(ac.r11r), &scale);
- k1 = scaleValue(result, scale);
+ k1 = scaleValueSaturate(result, scale);
if (!((ac.r01r < FL2FX_DBL(0.0f)) ^ (ac.r11r < FL2FX_DBL(0.0f)))) {
k1 = -k1;
@@ -771,52 +769,50 @@ void lppTransposer(
} else { /* bw <= 0 */
if (!useLP) {
- int descale =
- fixMin(DFRACT_BITS - 1, (LPC_SCALE_FACTOR + dynamicScale));
-#ifdef FUNCTION_LPPTRANSPOSER_func1
- lppTransposer_func1(
- lowBandReal + LPC_ORDER + startSample,
- lowBandImag + LPC_ORDER + startSample,
- qmfBufferReal + startSample, qmfBufferImag + startSample,
- stopSample - startSample, (int)hiBand, dynamicScale, descale, a0r,
- a0i, a1r, a1i, fPreWhitening, preWhiteningGains[loBand],
- preWhiteningGains_exp[loBand] + 1);
-#else
+ const int dynscale = fixMax(0, dynamicScale - 2) + 1;
+ const int rescale = -fixMin(0, dynamicScale - 2) + 1;
+ const int descale = fixMin(DFRACT_BITS - 1,
+ LPC_SCALE_FACTOR + dynamicScale + rescale);
+
for (i = startSample; i < stopSample; i++) {
FIXP_DBL accu1, accu2;
- accu1 = (fMultDiv2(a0r, lowBandReal[LPC_ORDER + i - 1]) -
- fMultDiv2(a0i, lowBandImag[LPC_ORDER + i - 1]) +
- fMultDiv2(a1r, lowBandReal[LPC_ORDER + i - 2]) -
- fMultDiv2(a1i, lowBandImag[LPC_ORDER + i - 2])) >>
- dynamicScale;
- accu2 = (fMultDiv2(a0i, lowBandReal[LPC_ORDER + i - 1]) +
- fMultDiv2(a0r, lowBandImag[LPC_ORDER + i - 1]) +
- fMultDiv2(a1i, lowBandReal[LPC_ORDER + i - 2]) +
- fMultDiv2(a1r, lowBandImag[LPC_ORDER + i - 2])) >>
- dynamicScale;
-
- accu1 = (lowBandReal[LPC_ORDER + i] >> descale) + (accu1 << 1);
- accu2 = (lowBandImag[LPC_ORDER + i] >> descale) + (accu2 << 1);
+ accu1 = ((fMultDiv2(a0r, lowBandReal[LPC_ORDER + i - 1]) -
+ fMultDiv2(a0i, lowBandImag[LPC_ORDER + i - 1])) >>
+ 1) +
+ ((fMultDiv2(a1r, lowBandReal[LPC_ORDER + i - 2]) -
+ fMultDiv2(a1i, lowBandImag[LPC_ORDER + i - 2])) >>
+ 1);
+ accu2 = ((fMultDiv2(a0i, lowBandReal[LPC_ORDER + i - 1]) +
+ fMultDiv2(a0r, lowBandImag[LPC_ORDER + i - 1])) >>
+ 1) +
+ ((fMultDiv2(a1i, lowBandReal[LPC_ORDER + i - 2]) +
+ fMultDiv2(a1r, lowBandImag[LPC_ORDER + i - 2])) >>
+ 1);
+
+ accu1 =
+ (lowBandReal[LPC_ORDER + i] >> descale) + (accu1 >> dynscale);
+ accu2 =
+ (lowBandImag[LPC_ORDER + i] >> descale) + (accu2 >> dynscale);
if (fPreWhitening) {
- accu1 = scaleValueSaturate(
+ qmfBufferReal[i][hiBand] = scaleValueSaturate(
fMultDiv2(accu1, preWhiteningGains[loBand]),
- preWhiteningGains_exp[loBand] + 1);
- accu2 = scaleValueSaturate(
+ preWhiteningGains_exp[loBand] + 1 + rescale);
+ qmfBufferImag[i][hiBand] = scaleValueSaturate(
fMultDiv2(accu2, preWhiteningGains[loBand]),
- preWhiteningGains_exp[loBand] + 1);
+ preWhiteningGains_exp[loBand] + 1 + rescale);
+ } else {
+ qmfBufferReal[i][hiBand] =
+ SATURATE_LEFT_SHIFT(accu1, rescale, DFRACT_BITS);
+ qmfBufferImag[i][hiBand] =
+ SATURATE_LEFT_SHIFT(accu2, rescale, DFRACT_BITS);
}
- qmfBufferReal[i][hiBand] = accu1;
- qmfBufferImag[i][hiBand] = accu2;
}
-#endif
} else {
FDK_ASSERT(dynamicScale >= 0);
calc_qmfBufferReal(
qmfBufferReal, &(lowBandReal[LPC_ORDER + startSample - 2]),
- startSample, stopSample, hiBand, dynamicScale,
- fMin(DFRACT_BITS - 1, (LPC_SCALE_FACTOR + dynamicScale)), a0r,
- a1r);
+ startSample, stopSample, hiBand, dynamicScale, a0r, a1r);
}
} /* bw <= 0 */
@@ -1066,7 +1062,7 @@ void lppTransposerHBE(
if ((scale > 0) && (result >= (FIXP_DBL)MAXVAL_DBL >> scale)) {
resetLPCCoeffs = 1;
} else {
- alphar[1] = FX_DBL2FX_SGL(scaleValue(result, scale));
+ alphar[1] = FX_DBL2FX_SGL(scaleValueSaturate(result, scale));
if ((tmp < FL2FX_DBL(0.0f)) ^ (ac.det < FL2FX_DBL(0.0f))) {
alphar[1] = -alphar[1];
}
@@ -1092,7 +1088,7 @@ void lppTransposerHBE(
(result >= /*FL2FXCONST_DBL(1.f)*/ (FIXP_DBL)MAXVAL_DBL >> scale)) {
resetLPCCoeffs = 1;
} else {
- alphai[1] = FX_DBL2FX_SGL(scaleValue(result, scale));
+ alphai[1] = FX_DBL2FX_SGL(scaleValueSaturate(result, scale));
if ((tmp < FL2FX_DBL(0.0f)) ^ (ac.det < FL2FX_DBL(0.0f))) {
alphai[1] = -alphai[1];
}
@@ -1121,7 +1117,7 @@ void lppTransposerHBE(
} else {
INT scale;
FIXP_DBL result = fDivNorm(absTmp, fixp_abs(ac.r11r), &scale);
- alphar[0] = FX_DBL2FX_SGL(scaleValue(result, scale + 1));
+ alphar[0] = FX_DBL2FX_SGL(scaleValueSaturate(result, scale + 1));
if ((tmp > FL2FX_DBL(0.0f)) ^ (ac.r11r < FL2FX_DBL(0.0f)))
alphar[0] = -alphar[0];
@@ -1140,7 +1136,7 @@ void lppTransposerHBE(
} else {
INT scale;
FIXP_DBL result = fDivNorm(absTmp, fixp_abs(ac.r11r), &scale);
- alphai[0] = FX_DBL2FX_SGL(scaleValue(result, scale + 1));
+ alphai[0] = FX_DBL2FX_SGL(scaleValueSaturate(result, scale + 1));
if ((tmp > FL2FX_DBL(0.0f)) ^ (ac.r11r < FL2FX_DBL(0.0f))) {
alphai[0] = -alphai[0];
}
diff --git a/libSBRdec/src/sbr_dec.cpp b/libSBRdec/src/sbr_dec.cpp
index b1fb0da..919e9bb 100644
--- a/libSBRdec/src/sbr_dec.cpp
+++ b/libSBRdec/src/sbr_dec.cpp
@@ -1,7 +1,7 @@
/* -----------------------------------------------------------------------------
Software License for The Fraunhofer FDK AAC Codec Library for Android
-© Copyright 1995 - 2019 Fraunhofer-Gesellschaft zur Förderung der angewandten
+© Copyright 1995 - 2020 Fraunhofer-Gesellschaft zur Förderung der angewandten
Forschung e.V. All rights reserved.
1. INTRODUCTION
@@ -713,7 +713,8 @@ void sbr_dec(
} else { /* (flags & SBRDEC_PS_DECODED) */
INT sdiff;
- INT scaleFactorHighBand, scaleFactorLowBand_ov, scaleFactorLowBand_no_ov;
+ INT scaleFactorHighBand, scaleFactorLowBand_ov, scaleFactorLowBand_no_ov,
+ outScalefactor, outScalefactorR, outScalefactorL;
HANDLE_QMF_FILTER_BANK synQmf = &hSbrDec->qmfDomainOutCh->fb;
HANDLE_QMF_FILTER_BANK synQmfRight = &hSbrDecRight->qmfDomainOutCh->fb;
@@ -744,7 +745,7 @@ void sbr_dec(
*/
FDK_ASSERT(hSbrDec->qmfDomainInCh->pGlobalConf->nBandsSynthesis <=
QMF_MAX_SYNTHESIS_BANDS);
- qmfChangeOutScalefactor(synQmfRight, -(8));
+ synQmfRight->outScalefactor = synQmf->outScalefactor;
FDKmemcpy(synQmfRight->FilterStates, synQmf->FilterStates,
9 * hSbrDec->qmfDomainInCh->pGlobalConf->nBandsSynthesis *
sizeof(FIXP_QSS));
@@ -788,9 +789,11 @@ void sbr_dec(
FDKmemcpy(&hSbrDecRight->sbrDrcChannel, &hSbrDec->sbrDrcChannel,
sizeof(SBRDEC_DRC_CHANNEL));
- for (i = 0; i < synQmf->no_col; i++) { /* ----- no_col loop ----- */
+ outScalefactor = maxShift - (8);
+ outScalefactorL = outScalefactorR =
+ sbrInDataHeadroom + 1; /* +1: psDiffScale! (MPEG-PS) */
- INT outScalefactorR, outScalefactorL;
+ for (i = 0; i < synQmf->no_col; i++) { /* ----- no_col loop ----- */
/* qmf timeslot of right channel */
FIXP_DBL *rQmfReal = pWorkBuffer;
@@ -815,27 +818,20 @@ void sbr_dec(
? scaleFactorLowBand_ov
: scaleFactorLowBand_no_ov,
scaleFactorHighBand, synQmf->lsb, synQmf->usb);
-
- outScalefactorL = outScalefactorR =
- 1 + sbrInDataHeadroom; /* psDiffScale! (MPEG-PS) */
}
sbrDecoder_drcApplySlot(/* right channel */
&hSbrDecRight->sbrDrcChannel, rQmfReal,
rQmfImag, i, synQmfRight->no_col, maxShift);
- outScalefactorR += maxShift;
-
sbrDecoder_drcApplySlot(/* left channel */
&hSbrDec->sbrDrcChannel, *(pLowBandReal + i),
*(pLowBandImag + i), i, synQmf->no_col,
maxShift);
- outScalefactorL += maxShift;
-
if (!(flags & SBRDEC_SKIP_QMF_SYN)) {
- qmfChangeOutScalefactor(synQmf, -(8));
- qmfChangeOutScalefactor(synQmfRight, -(8));
+ qmfChangeOutScalefactor(synQmf, outScalefactor);
+ qmfChangeOutScalefactor(synQmfRight, outScalefactor);
qmfSynthesisFilteringSlot(
synQmfRight, rQmfReal, /* QMF real buffer */
diff --git a/libSBRdec/src/sbrdec_freq_sca.cpp b/libSBRdec/src/sbrdec_freq_sca.cpp
index e187656..daa3554 100644
--- a/libSBRdec/src/sbrdec_freq_sca.cpp
+++ b/libSBRdec/src/sbrdec_freq_sca.cpp
@@ -1,7 +1,7 @@
/* -----------------------------------------------------------------------------
Software License for The Fraunhofer FDK AAC Codec Library for Android
-© Copyright 1995 - 2019 Fraunhofer-Gesellschaft zur Förderung der angewandten
+© Copyright 1995 - 2021 Fraunhofer-Gesellschaft zur Förderung der angewandten
Forschung e.V. All rights reserved.
1. INTRODUCTION
@@ -765,9 +765,6 @@ resetFreqBandTables(HANDLE_SBR_HEADER_DATA hHeaderData, const UINT flags) {
sbrdecUpdateLoRes(hFreq->freqBandTable[0], &nBandsLo, hFreq->freqBandTable[1],
nBandsHi);
- hFreq->nSfb[0] = nBandsLo;
- hFreq->nSfb[1] = nBandsHi;
-
/* Check index to freqBandTable[0] */
if (!(nBandsLo > 0) ||
(nBandsLo > (((hHeaderData->numberOfAnalysisBands == 16)
@@ -777,6 +774,9 @@ resetFreqBandTables(HANDLE_SBR_HEADER_DATA hHeaderData, const UINT flags) {
return SBRDEC_UNSUPPORTED_CONFIG;
}
+ hFreq->nSfb[0] = nBandsLo;
+ hFreq->nSfb[1] = nBandsHi;
+
lsb = hFreq->freqBandTable[0][0];
usb = hFreq->freqBandTable[0][nBandsLo];
@@ -814,15 +814,15 @@ resetFreqBandTables(HANDLE_SBR_HEADER_DATA hHeaderData, const UINT flags) {
if (intTemp == 0) intTemp = 1;
+ if (intTemp > MAX_NOISE_COEFFS) {
+ return SBRDEC_UNSUPPORTED_CONFIG;
+ }
+
hFreq->nNfb = intTemp;
}
hFreq->nInvfBands = hFreq->nNfb;
- if (hFreq->nNfb > MAX_NOISE_COEFFS) {
- return SBRDEC_UNSUPPORTED_CONFIG;
- }
-
/* Get noise bands */
sbrdecDownSampleLoRes(hFreq->freqBandTableNoise, hFreq->nNfb,
hFreq->freqBandTable[0], nBandsLo);
diff --git a/libSBRdec/src/sbrdecoder.cpp b/libSBRdec/src/sbrdecoder.cpp
index b101a4a..7718695 100644
--- a/libSBRdec/src/sbrdecoder.cpp
+++ b/libSBRdec/src/sbrdecoder.cpp
@@ -1,7 +1,7 @@
/* -----------------------------------------------------------------------------
Software License for The Fraunhofer FDK AAC Codec Library for Android
-© Copyright 1995 - 2020 Fraunhofer-Gesellschaft zur Förderung der angewandten
+© Copyright 1995 - 2021 Fraunhofer-Gesellschaft zur Förderung der angewandten
Forschung e.V. All rights reserved.
1. INTRODUCTION
@@ -961,8 +961,10 @@ SBR_ERROR sbrDecoder_SetParam(HANDLE_SBRDECODER self, const SBRDEC_PARAM param,
/* Set sync state UPSAMPLING for the corresponding slot.
This switches off bitstream parsing until a new header arrives. */
- hSbrHeader->syncState = UPSAMPLING;
- hSbrHeader->status |= SBRDEC_HDR_STAT_UPDATE;
+ if (hSbrHeader->syncState != SBR_NOT_INITIALIZED) {
+ hSbrHeader->syncState = UPSAMPLING;
+ hSbrHeader->status |= SBRDEC_HDR_STAT_UPDATE;
+ }
}
}
} break;
@@ -1371,7 +1373,9 @@ SBR_ERROR sbrDecoder_Parse(HANDLE_SBRDECODER self, HANDLE_FDK_BITSTREAM hBs,
}
if (headerStatus == HEADER_ERROR) {
/* Corrupt SBR info data, do not decode and switch to UPSAMPLING */
- hSbrHeader->syncState = UPSAMPLING;
+ hSbrHeader->syncState = hSbrHeader->syncState > UPSAMPLING
+ ? UPSAMPLING
+ : hSbrHeader->syncState;
fDoDecodeSbrData = 0;
sbrHeaderPresent = 0;
}
@@ -1610,7 +1614,9 @@ static SBR_ERROR sbrDecoder_DecodeElement(
/* No valid SBR payload available, hence switch to upsampling (in all
* headers) */
for (hdrIdx = 0; hdrIdx < ((1) + 1); hdrIdx += 1) {
- self->sbrHeader[elementIndex][hdrIdx].syncState = UPSAMPLING;
+ if (self->sbrHeader[elementIndex][hdrIdx].syncState > UPSAMPLING) {
+ self->sbrHeader[elementIndex][hdrIdx].syncState = UPSAMPLING;
+ }
}
} else {
/* Move frame pointer to the next slot which is up to be decoded/applied