aboutsummaryrefslogtreecommitdiffstats
path: root/libSBRdec
diff options
context:
space:
mode:
authorMatthias P. Braendli <matthias.braendli@mpb.li>2019-03-04 15:52:49 +0100
committerMatthias P. Braendli <matthias.braendli@mpb.li>2019-03-04 15:52:49 +0100
commitc7f9c2d1d996ac8f67927e9c86b907196ca6a72d (patch)
treea2dcc8e8cd3df5628f43242243fd475562ea4082 /libSBRdec
parentf665ac21b355ebc74c951c09b4774936a74fdca0 (diff)
parent95858d7bd36f19bde4a9595e2bd68f195215b164 (diff)
downloadfdk-aac-c7f9c2d1d996ac8f67927e9c86b907196ca6a72d.tar.gz
fdk-aac-c7f9c2d1d996ac8f67927e9c86b907196ca6a72d.tar.bz2
fdk-aac-c7f9c2d1d996ac8f67927e9c86b907196ca6a72d.zip
Merge remote-tracking branch 'mstorjo/master' into dabplus2
Diffstat (limited to 'libSBRdec')
-rw-r--r--libSBRdec/src/env_calc.cpp22
-rw-r--r--libSBRdec/src/env_dec.cpp17
-rw-r--r--libSBRdec/src/env_extr.cpp17
-rw-r--r--libSBRdec/src/hbe.cpp4
-rw-r--r--libSBRdec/src/lpp_tran.cpp74
-rw-r--r--libSBRdec/src/psbitdec.cpp8
-rw-r--r--libSBRdec/src/psdec.cpp26
-rw-r--r--libSBRdec/src/psdec.h6
-rw-r--r--libSBRdec/src/sbr_dec.cpp2
-rw-r--r--libSBRdec/src/sbrdecoder.cpp12
10 files changed, 127 insertions, 61 deletions
diff --git a/libSBRdec/src/env_calc.cpp b/libSBRdec/src/env_calc.cpp
index d7a8bb5..cb1474f 100644
--- a/libSBRdec/src/env_calc.cpp
+++ b/libSBRdec/src/env_calc.cpp
@@ -626,7 +626,8 @@ static void apply_inter_tes(FIXP_DBL **qmfReal, FIXP_DBL **qmfImag,
total_power_low >>= diff;
total_power_low_sf = new_summand_sf;
} else if (new_summand_sf < total_power_low_sf) {
- new_summand >>= total_power_low_sf - new_summand_sf;
+ new_summand >>=
+ fMin(DFRACT_BITS - 1, total_power_low_sf - new_summand_sf);
}
total_power_low += (new_summand >> preShift2);
@@ -638,7 +639,8 @@ static void apply_inter_tes(FIXP_DBL **qmfReal, FIXP_DBL **qmfImag,
fMin(DFRACT_BITS - 1, new_summand_sf - total_power_high_sf);
total_power_high_sf = new_summand_sf;
} else if (new_summand_sf < total_power_high_sf) {
- new_summand >>= total_power_high_sf - new_summand_sf;
+ new_summand >>=
+ fMin(DFRACT_BITS - 1, total_power_high_sf - new_summand_sf);
}
total_power_high += (new_summand >> preShift2);
@@ -1561,13 +1563,14 @@ void calculateSbrEnvelope(
adjustTimeSlotHQ_GainAndNoise(
&analysBufferReal[j][lowSubband],
&analysBufferImag[j][lowSubband], h_sbr_cal_env, pNrgs,
- lowSubband, noSubbands, scale_change, smooth_ratio, noNoiseFlag,
- filtBufferNoiseShift);
+ lowSubband, noSubbands, fMin(scale_change, DFRACT_BITS - 1),
+ smooth_ratio, noNoiseFlag, filtBufferNoiseShift);
} else {
adjustTimeSlotHQ(&analysBufferReal[j][lowSubband],
&analysBufferImag[j][lowSubband], h_sbr_cal_env,
- pNrgs, lowSubband, noSubbands, scale_change,
- smooth_ratio, noNoiseFlag, filtBufferNoiseShift);
+ pNrgs, lowSubband, noSubbands,
+ fMin(scale_change, DFRACT_BITS - 1), smooth_ratio,
+ noNoiseFlag, filtBufferNoiseShift);
}
} else {
FDK_ASSERT(!iTES_enable); /* not supported */
@@ -1575,13 +1578,14 @@ void calculateSbrEnvelope(
/* FDKmemset(analysBufferReal[j], 0, 64 * sizeof(FIXP_DBL)); */
adjustTimeSlot_EldGrid(&analysBufferReal[j][lowSubband], pNrgs,
&h_sbr_cal_env->harmIndex, lowSubband,
- noSubbands, scale_change, noNoiseFlag,
- &h_sbr_cal_env->phaseIndex,
+ noSubbands,
+ fMin(scale_change, DFRACT_BITS - 1),
+ noNoiseFlag, &h_sbr_cal_env->phaseIndex,
EXP2SCALE(adj_e) - sbrScaleFactor->lb_scale);
} else {
adjustTimeSlotLC(&analysBufferReal[j][lowSubband], pNrgs,
&h_sbr_cal_env->harmIndex, lowSubband, noSubbands,
- scale_change, noNoiseFlag,
+ fMin(scale_change, DFRACT_BITS - 1), noNoiseFlag,
&h_sbr_cal_env->phaseIndex);
}
}
diff --git a/libSBRdec/src/env_dec.cpp b/libSBRdec/src/env_dec.cpp
index 88c92cd..95807c9 100644
--- a/libSBRdec/src/env_dec.cpp
+++ b/libSBRdec/src/env_dec.cpp
@@ -435,8 +435,8 @@ static void leanSbrConcealment(
/* Noisefloor levels are always cleared ... */
h_sbr_data->domain_vec_noise[0] = 1;
- for (i = 0; i < hHeaderData->freqBandData.nNfb; i++)
- h_sbr_data->sbrNoiseFloorLevel[i] = FL2FXCONST_SGL(0.0f);
+ FDKmemclear(h_sbr_data->sbrNoiseFloorLevel,
+ sizeof(h_sbr_data->sbrNoiseFloorLevel));
/* ... and so are the sines */
FDKmemclear(h_sbr_data->addHarmonics,
@@ -506,15 +506,20 @@ static void decodeEnvelope(
*/
for (i = 0; i < hHeaderData->freqBandData.nSfb[1]; i++) {
/* Former Level-Channel will be used for both channels */
- if (h_prev_data->coupling == COUPLING_BAL)
- h_prev_data->sfb_nrg_prev[i] = otherChannel->sfb_nrg_prev[i];
+ if (h_prev_data->coupling == COUPLING_BAL) {
+ h_prev_data->sfb_nrg_prev[i] =
+ (otherChannel != NULL) ? otherChannel->sfb_nrg_prev[i]
+ : (FIXP_SGL)SBR_ENERGY_PAN_OFFSET;
+ }
/* Former L/R will be combined as the new Level-Channel */
- else if (h_sbr_data->coupling == COUPLING_LEVEL)
+ else if (h_sbr_data->coupling == COUPLING_LEVEL &&
+ otherChannel != NULL) {
h_prev_data->sfb_nrg_prev[i] = (h_prev_data->sfb_nrg_prev[i] +
otherChannel->sfb_nrg_prev[i]) >>
1;
- else if (h_sbr_data->coupling == COUPLING_BAL)
+ } else if (h_sbr_data->coupling == COUPLING_BAL) {
h_prev_data->sfb_nrg_prev[i] = (FIXP_SGL)SBR_ENERGY_PAN_OFFSET;
+ }
}
}
}
diff --git a/libSBRdec/src/env_extr.cpp b/libSBRdec/src/env_extr.cpp
index e6ae6dc..c72a7b6 100644
--- a/libSBRdec/src/env_extr.cpp
+++ b/libSBRdec/src/env_extr.cpp
@@ -1145,10 +1145,10 @@ static int sbrGetEnvelope(
\brief Generates frame info for FIXFIXonly frame class used for low delay
version
- \return nothing
+ \return zero for error, one for correct.
****************************************************************************/
-static void generateFixFixOnly(FRAME_INFO *hSbrFrameInfo, int tranPosInternal,
- int numberTimeSlots, const UINT flags) {
+static int generateFixFixOnly(FRAME_INFO *hSbrFrameInfo, int tranPosInternal,
+ int numberTimeSlots, const UINT flags) {
int nEnv, i, tranIdx;
const int *pTable;
@@ -1159,12 +1159,11 @@ static void generateFixFixOnly(FRAME_INFO *hSbrFrameInfo, int tranPosInternal,
case 15:
pTable = FDK_sbrDecoder_envelopeTable_15[tranPosInternal];
break;
- default:
- FDK_ASSERT(0);
- /* fall through */
case 16:
pTable = FDK_sbrDecoder_envelopeTable_16[tranPosInternal];
break;
+ default:
+ return 0;
}
/* look number of envelopes in table */
@@ -1187,6 +1186,8 @@ static void generateFixFixOnly(FRAME_INFO *hSbrFrameInfo, int tranPosInternal,
/* nEnv is always > 1, so nNoiseEnvelopes is always 2 (IEC 14496-3 4.6.19.3.2)
*/
hSbrFrameInfo->nNoiseEnvelopes = 2;
+
+ return 1;
}
/*!
@@ -1230,7 +1231,9 @@ static int extractLowDelayGrid(
}
/* calculate borders according to the transient position */
- generateFixFixOnly(pFrameInfo, temp, numberTimeSlots, flags);
+ if (!generateFixFixOnly(pFrameInfo, temp, numberTimeSlots, flags)) {
+ return 0;
+ }
/* decode freq res: */
for (k = 0; k < pFrameInfo->nEnvelopes; k++) {
diff --git a/libSBRdec/src/hbe.cpp b/libSBRdec/src/hbe.cpp
index 176815b..3310dcd 100644
--- a/libSBRdec/src/hbe.cpp
+++ b/libSBRdec/src/hbe.cpp
@@ -1056,6 +1056,10 @@ SBR_ERROR QmfTransposerReInit(HANDLE_HBE_TRANSPOSER hQmfTransposer,
const FIXP_QTW* tmp_t_sin;
hQmfTransposer->startBand = FreqBandTable[0][0];
+ FDK_ASSERT((!hQmfTransposer->bSbr41 && hQmfTransposer->startBand <= 32) ||
+ (hQmfTransposer->bSbr41 &&
+ hQmfTransposer->startBand <=
+ 16)); /* is checked by resetFreqBandTables() */
hQmfTransposer->stopBand = FreqBandTable[0][NSfb[0]];
hQmfTransposer->synthSize =
diff --git a/libSBRdec/src/lpp_tran.cpp b/libSBRdec/src/lpp_tran.cpp
index aa1fd5d..2ef07eb 100644
--- a/libSBRdec/src/lpp_tran.cpp
+++ b/libSBRdec/src/lpp_tran.cpp
@@ -118,6 +118,10 @@ amm-info@iis.fraunhofer.de
\sa lppTransposer(), main_audio.cpp, sbr_scale.h, \ref documentationOverview
*/
+#ifdef __ANDROID__
+#include "log/log.h"
+#endif
+
#include "lpp_tran.h"
#include "sbr_ram.h"
@@ -295,7 +299,6 @@ void lppTransposer(
int ovLowBandShift;
int lowBandShift;
/* int ovHighBandShift;*/
- int targetStopBand;
alphai[0] = FL2FXCONST_SGL(0.0f);
alphai[1] = FL2FXCONST_SGL(0.0f);
@@ -311,25 +314,34 @@ void lppTransposer(
autoCorrLength = pSettings->nCols + pSettings->overlap;
- /* Set upper subbands to zero:
- This is required in case that the patches do not cover the complete
- highband (because the last patch would be too short). Possible
- optimization: Clearing bands up to usb would be sufficient here. */
- targetStopBand = patchParam[pSettings->noOfPatches - 1].targetStartBand +
- patchParam[pSettings->noOfPatches - 1].numBandsInPatch;
+ if (pSettings->noOfPatches > 0) {
+ /* Set upper subbands to zero:
+ This is required in case that the patches do not cover the complete
+ highband (because the last patch would be too short). Possible
+ optimization: Clearing bands up to usb would be sufficient here. */
+ int targetStopBand =
+ patchParam[pSettings->noOfPatches - 1].targetStartBand +
+ patchParam[pSettings->noOfPatches - 1].numBandsInPatch;
- int memSize = ((64) - targetStopBand) * sizeof(FIXP_DBL);
+ int memSize = ((64) - targetStopBand) * sizeof(FIXP_DBL);
- if (!useLP) {
- for (i = startSample; i < stopSampleClear; i++) {
- FDKmemclear(&qmfBufferReal[i][targetStopBand], memSize);
- FDKmemclear(&qmfBufferImag[i][targetStopBand], memSize);
- }
- } else {
- for (i = startSample; i < stopSampleClear; i++) {
- FDKmemclear(&qmfBufferReal[i][targetStopBand], memSize);
+ if (!useLP) {
+ for (i = startSample; i < stopSampleClear; i++) {
+ FDKmemclear(&qmfBufferReal[i][targetStopBand], memSize);
+ FDKmemclear(&qmfBufferImag[i][targetStopBand], memSize);
+ }
+ } else {
+ for (i = startSample; i < stopSampleClear; i++) {
+ FDKmemclear(&qmfBufferReal[i][targetStopBand], memSize);
+ }
}
}
+#ifdef __ANDROID__
+ else {
+ // Safetynet logging
+ android_errorWriteLog(0x534e4554, "112160868");
+ }
+#endif
/* init bwIndex for each patch */
FDKmemclear(bwIndex, sizeof(bwIndex));
@@ -874,7 +886,6 @@ void lppTransposerHBE(
int ovLowBandShift;
int lowBandShift;
/* int ovHighBandShift;*/
- int targetStopBand;
alphai[0] = FL2FXCONST_SGL(0.0f);
alphai[1] = FL2FXCONST_SGL(0.0f);
@@ -889,19 +900,28 @@ void lppTransposerHBE(
autoCorrLength = pSettings->nCols + pSettings->overlap;
- /* Set upper subbands to zero:
- This is required in case that the patches do not cover the complete
- highband (because the last patch would be too short). Possible
- optimization: Clearing bands up to usb would be sufficient here. */
- targetStopBand = patchParam[pSettings->noOfPatches - 1].targetStartBand +
- patchParam[pSettings->noOfPatches - 1].numBandsInPatch;
+ if (pSettings->noOfPatches > 0) {
+ /* Set upper subbands to zero:
+ This is required in case that the patches do not cover the complete
+ highband (because the last patch would be too short). Possible
+ optimization: Clearing bands up to usb would be sufficient here. */
+ int targetStopBand =
+ patchParam[pSettings->noOfPatches - 1].targetStartBand +
+ patchParam[pSettings->noOfPatches - 1].numBandsInPatch;
- int memSize = ((64) - targetStopBand) * sizeof(FIXP_DBL);
+ int memSize = ((64) - targetStopBand) * sizeof(FIXP_DBL);
- for (i = startSample; i < stopSampleClear; i++) {
- FDKmemclear(&qmfBufferReal[i][targetStopBand], memSize);
- FDKmemclear(&qmfBufferImag[i][targetStopBand], memSize);
+ for (i = startSample; i < stopSampleClear; i++) {
+ FDKmemclear(&qmfBufferReal[i][targetStopBand], memSize);
+ FDKmemclear(&qmfBufferImag[i][targetStopBand], memSize);
+ }
+ }
+#ifdef __ANDROID__
+ else {
+ // Safetynet logging
+ android_errorWriteLog(0x534e4554, "112160868");
}
+#endif
/*
Calc common low band scale factor
diff --git a/libSBRdec/src/psbitdec.cpp b/libSBRdec/src/psbitdec.cpp
index f40a156..82bb65b 100644
--- a/libSBRdec/src/psbitdec.cpp
+++ b/libSBRdec/src/psbitdec.cpp
@@ -312,6 +312,7 @@ int DecodePs(struct PS_DEC *h_ps_d, /*!< PS handle */
if (pBsData->bEnableIid) {
pBsData->bFineIidQ = h_ps_d->specificTo.mpeg.bPrevFrameFineIidQ;
+ pBsData->freqResIid = h_ps_d->specificTo.mpeg.prevFreqResIid;
for (gr = 0; gr < NO_HI_RES_IID_BINS; gr++) {
pBsData->aaIidIndex[pBsData->noEnv - 1][gr] =
h_ps_d->specificTo.mpeg.aIidPrevFrameIndex[gr];
@@ -323,6 +324,7 @@ int DecodePs(struct PS_DEC *h_ps_d, /*!< PS handle */
}
if (pBsData->bEnableIcc) {
+ pBsData->freqResIcc = h_ps_d->specificTo.mpeg.prevFreqResIcc;
for (gr = 0; gr < NO_HI_RES_ICC_BINS; gr++) {
pBsData->aaIccIndex[pBsData->noEnv - 1][gr] =
h_ps_d->specificTo.mpeg.aIccPrevFrameIndex[gr];
@@ -337,6 +339,12 @@ int DecodePs(struct PS_DEC *h_ps_d, /*!< PS handle */
/* Update previous frame Iid quantization */
h_ps_d->specificTo.mpeg.bPrevFrameFineIidQ = pBsData->bFineIidQ;
+ /* Update previous frequency resolution for IID */
+ h_ps_d->specificTo.mpeg.prevFreqResIid = pBsData->freqResIid;
+
+ /* Update previous frequency resolution for ICC */
+ h_ps_d->specificTo.mpeg.prevFreqResIcc = pBsData->freqResIcc;
+
/* Update previous frame index buffers */
for (gr = 0; gr < NO_HI_RES_IID_BINS; gr++) {
h_ps_d->specificTo.mpeg.aIidPrevFrameIndex[gr] =
diff --git a/libSBRdec/src/psdec.cpp b/libSBRdec/src/psdec.cpp
index 13a21bf..b31b310 100644
--- a/libSBRdec/src/psdec.cpp
+++ b/libSBRdec/src/psdec.cpp
@@ -325,11 +325,11 @@ void initSlotBasedRotation(
int env, int usb) {
INT group = 0;
INT bin = 0;
- INT noIidSteps;
+ INT noIidSteps, noFactors;
FIXP_SGL invL;
FIXP_DBL ScaleL, ScaleR;
- FIXP_DBL Alpha, Beta;
+ FIXP_DBL Alpha, Beta, AlphasValue;
FIXP_DBL h11r, h12r, h21r, h22r;
const FIXP_DBL *PScaleFactors;
@@ -337,9 +337,11 @@ void initSlotBasedRotation(
if (h_ps_d->bsData[h_ps_d->processSlot].mpeg.bFineIidQ) {
PScaleFactors = ScaleFactorsFine; /* values are shiftet right by one */
noIidSteps = NO_IID_STEPS_FINE;
+ noFactors = NO_IID_LEVELS_FINE;
} else {
PScaleFactors = ScaleFactors; /* values are shiftet right by one */
noIidSteps = NO_IID_STEPS;
+ noFactors = NO_IID_LEVELS;
}
/* dequantize and decode */
@@ -358,17 +360,23 @@ void initSlotBasedRotation(
/* ScaleR and ScaleL are scaled by 1 shift right */
- ScaleR = PScaleFactors[noIidSteps + h_ps_d->specificTo.mpeg.pCoef
- ->aaIidIndexMapped[env][bin]];
- ScaleL = PScaleFactors[noIidSteps - h_ps_d->specificTo.mpeg.pCoef
- ->aaIidIndexMapped[env][bin]];
-
+ ScaleL = ScaleR = 0;
+ if (noIidSteps + h_ps_d->specificTo.mpeg.pCoef->aaIidIndexMapped[env][bin] >= 0 && noIidSteps + h_ps_d->specificTo.mpeg.pCoef->aaIidIndexMapped[env][bin] < noFactors)
+ ScaleR = PScaleFactors[noIidSteps + h_ps_d->specificTo.mpeg.pCoef
+ ->aaIidIndexMapped[env][bin]];
+ if (noIidSteps - h_ps_d->specificTo.mpeg.pCoef->aaIidIndexMapped[env][bin] >= 0 && noIidSteps - h_ps_d->specificTo.mpeg.pCoef->aaIidIndexMapped[env][bin] < noFactors)
+ ScaleL = PScaleFactors[noIidSteps - h_ps_d->specificTo.mpeg.pCoef
+ ->aaIidIndexMapped[env][bin]];
+
+ AlphasValue = 0;
+ if (h_ps_d->specificTo.mpeg.pCoef->aaIccIndexMapped[env][bin] >= 0)
+ AlphasValue = Alphas[h_ps_d->specificTo.mpeg.pCoef->aaIccIndexMapped[env][bin]];
Beta = fMult(
- fMult(Alphas[h_ps_d->specificTo.mpeg.pCoef->aaIccIndexMapped[env][bin]],
+ fMult(AlphasValue,
(ScaleR - ScaleL)),
FIXP_SQRT05);
Alpha =
- Alphas[h_ps_d->specificTo.mpeg.pCoef->aaIccIndexMapped[env][bin]] >> 1;
+ AlphasValue >> 1;
/* Alpha and Beta are now both scaled by 2 shifts right */
diff --git a/libSBRdec/src/psdec.h b/libSBRdec/src/psdec.h
index 6ae1473..029eac4 100644
--- a/libSBRdec/src/psdec.h
+++ b/libSBRdec/src/psdec.h
@@ -275,7 +275,11 @@ struct PS_DEC {
SCHAR aIccPrevFrameIndex[NO_HI_RES_ICC_BINS]; /*!< The ICC index for
previous frame */
UCHAR
- bPrevFrameFineIidQ; /*!< The IID quantization of the previous frame */
+ bPrevFrameFineIidQ; /*!< The IID quantization of the previous frame */
+ UCHAR prevFreqResIid; /*!< Frequency resolution for IID of the previous
+ frame */
+ UCHAR prevFreqResIcc; /*!< Frequency resolution for ICC of the previous
+ frame */
UCHAR lastUsb; /*!< uppermost WMF delay band of last frame */
FIXP_DBL pHybridAnaStatesLFdmx
diff --git a/libSBRdec/src/sbr_dec.cpp b/libSBRdec/src/sbr_dec.cpp
index 2e18e6c..30611e7 100644
--- a/libSBRdec/src/sbr_dec.cpp
+++ b/libSBRdec/src/sbr_dec.cpp
@@ -1248,7 +1248,7 @@ resetSbrDec(HANDLE_SBR_DEC hSbrDec, HANDLE_SBR_HEADER_DATA hHeaderData,
hSbrDec->savedStates = 0;
- if (flags & SBRDEC_USAC_HARMONICSBR) {
+ if ((flags & SBRDEC_USAC_HARMONICSBR) && applySbrProc) {
sbrError = QmfTransposerReInit(hSbrDec->hHBE,
hHeaderData->freqBandData.freqBandTable,
hHeaderData->freqBandData.nSfb);
diff --git a/libSBRdec/src/sbrdecoder.cpp b/libSBRdec/src/sbrdecoder.cpp
index e2455da..4bc6f69 100644
--- a/libSBRdec/src/sbrdecoder.cpp
+++ b/libSBRdec/src/sbrdecoder.cpp
@@ -1150,6 +1150,11 @@ SBR_ERROR sbrDecoder_Parse(HANDLE_SBRDECODER self, HANDLE_FDK_BITSTREAM hBs,
int lastSlot, lastHdrSlot = 0, thisHdrSlot = 0;
+ if (*count <= 0) {
+ setFrameErrorFlag(self->pSbrElement[elementIndex], FRAME_ERROR);
+ return SBRDEC_OK;
+ }
+
/* SBR sanity checks */
if (self == NULL) {
errorStatus = SBRDEC_NOT_INITIALIZED;
@@ -1677,6 +1682,9 @@ static SBR_ERROR sbrDecoder_DecodeElement(
/* reset */
if (hSbrHeader->status & SBRDEC_HDR_STAT_RESET) {
int ch;
+ int applySbrProc = (hSbrHeader->syncState == SBR_ACTIVE ||
+ (hSbrHeader->frameErrorFlag == 0 &&
+ hSbrHeader->syncState == SBR_HEADER));
for (ch = 0; ch < numElementChannels; ch++) {
SBR_ERROR errorStatusTmp = SBRDEC_OK;
@@ -1688,7 +1696,9 @@ static SBR_ERROR sbrDecoder_DecodeElement(
hSbrHeader->syncState = UPSAMPLING;
}
}
- hSbrHeader->status &= ~SBRDEC_HDR_STAT_RESET;
+ if (applySbrProc) {
+ hSbrHeader->status &= ~SBRDEC_HDR_STAT_RESET;
+ }
}
/* decoding */