aboutsummaryrefslogtreecommitdiffstats
path: root/libFDK
diff options
context:
space:
mode:
Diffstat (limited to 'libFDK')
-rw-r--r--libFDK/include/scale.h8
-rw-r--r--libFDK/src/FDK_decorrelate.cpp80
-rw-r--r--libFDK/src/dct.cpp18
-rw-r--r--libFDK/src/qmf.cpp45
-rw-r--r--libFDK/src/scale.cpp26
5 files changed, 72 insertions, 105 deletions
diff --git a/libFDK/include/scale.h b/libFDK/include/scale.h
index 655ccaf..a58614e 100644
--- a/libFDK/include/scale.h
+++ b/libFDK/include/scale.h
@@ -129,15 +129,13 @@ void scaleCplxValues(FIXP_DBL *r_dst, FIXP_DBL *i_dst, const FIXP_DBL *r_src,
void scaleValuesWithFactor(FIXP_DBL *vector, FIXP_DBL factor, INT len,
INT scalefactor);
void scaleValuesSaturate(FIXP_DBL *vector, INT len, INT scalefactor);
-void scaleValuesSaturate(FIXP_DBL *dst, FIXP_DBL *src, INT len,
+void scaleValuesSaturate(FIXP_DBL *dst, const FIXP_DBL *src, INT len,
INT scalefactor);
-void scaleValuesSaturate(FIXP_SGL *dst, FIXP_DBL *src, INT len,
+void scaleValuesSaturate(FIXP_SGL *dst, const FIXP_DBL *src, INT len,
INT scalefactor);
-void scaleValuesSaturate(INT_PCM *dst, FIXP_DBL *src, INT len, INT scalefactor);
void scaleValuesSaturate(FIXP_SGL *vector, INT len, INT scalefactor);
-void scaleValuesSaturate(FIXP_SGL *dst, FIXP_SGL *src, INT len,
+void scaleValuesSaturate(FIXP_SGL *dst, const FIXP_SGL *src, INT len,
INT scalefactor);
-void scaleValuesSaturate(INT_PCM *dst, INT_PCM *src, INT len, INT scalefactor);
INT getScalefactorShort(const SHORT *vector, INT len);
INT getScalefactorPCM(const INT_PCM *vector, INT len, INT stride);
INT getScalefactor(const FIXP_DBL *vector, INT len);
diff --git a/libFDK/src/FDK_decorrelate.cpp b/libFDK/src/FDK_decorrelate.cpp
index c5de79a..324983a 100644
--- a/libFDK/src/FDK_decorrelate.cpp
+++ b/libFDK/src/FDK_decorrelate.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 - 2019 Fraunhofer-Gesellschaft zur Förderung der angewandten
Forschung e.V. All rights reserved.
1. INTRODUCTION
@@ -227,7 +227,7 @@ static inline int SpatialDecGetQmfBand(int paramBand, const UCHAR *tab) {
}
#define DUCKER_MAX_NRG_SCALE (24)
-#define DUCKER_HEADROOM_BITS (3)
+#define DUCKER_HEADROOM_BITS (2)
#define FILTER_SF (2)
@@ -606,10 +606,6 @@ static INT DecorrFilterApplyPASS(DECORR_FILTER_INSTANCE const filter[],
dataImagIn += start;
dataRealOut += start;
dataImagOut += start;
-#ifdef FUNCTION_DecorrFilterApplyPASS_func1
- DecorrFilterApplyPASS_func1(i, dataRealIn, dataImagIn, dataRealOut,
- dataImagOut, pDelayBuffer, offset);
-#else
do {
FIXP_DBL delay_re, delay_im, real, imag;
@@ -623,7 +619,6 @@ static INT DecorrFilterApplyPASS(DECORR_FILTER_INSTANCE const filter[],
*dataImagOut++ = delay_im;
pDelayBuffer += offset;
} while (--i != 0);
-#endif
}
}
@@ -1061,24 +1056,15 @@ static INT DuckerCalcEnergy(DUCKER_INSTANCE *const self,
FIXP_DBL maxVal = FL2FXCONST_DBL(-1.0f);
if (maxVal == FL2FXCONST_DBL(-1.0f)) {
-#ifdef FUNCTION_DuckerCalcEnergy_func2
- maxVal = DuckerCalcEnergy_func2(inputReal, inputImag, startHybBand,
- maxHybBand, maxHybridBand);
-#else
- FIXP_DBL localMaxVal = FL2FXCONST_DBL(0.0f);
- for (qs = startHybBand; qs <= maxHybBand; qs++) {
- localMaxVal |= fAbs(inputReal[qs]);
- localMaxVal |= fAbs(inputImag[qs]);
- }
- for (; qs <= maxHybridBand; qs++) {
- localMaxVal |= fAbs(inputReal[qs]);
- }
- maxVal = localMaxVal;
-#endif
+ clz = fMin(getScalefactor(&inputReal[startHybBand],
+ fMax(0, maxHybridBand - startHybBand + 1)),
+ getScalefactor(&inputImag[startHybBand],
+ fMax(0, maxHybBand - startHybBand + 1)));
+ } else {
+ clz = CntLeadingZeros(maxVal) - 1;
}
- clz = fixMax(0, CntLeadingZeros(maxVal) - DUCKER_HEADROOM_BITS);
- clz = fixMin(clz, DUCKER_MAX_NRG_SCALE);
+ clz = fMin(fMax(0, clz - DUCKER_HEADROOM_BITS), DUCKER_MAX_NRG_SCALE);
*nrgScale = (SCHAR)clz << 1;
/* Initialize pb since it would stay uninitialized for the case startHybBand
@@ -1086,9 +1072,10 @@ static INT DuckerCalcEnergy(DUCKER_INSTANCE *const self,
pb = SpatialDecGetProcessingBand(maxHybBand, self->mapHybBands2ProcBands);
for (qs = startHybBand; qs <= maxHybBand; qs++) {
pb = SpatialDecGetProcessingBand(qs, self->mapHybBands2ProcBands);
- energy[pb] =
- fAddSaturate(energy[pb], fPow2Div2(inputReal[qs] << clz) +
- fPow2Div2(inputImag[qs] << clz));
+ energy[pb] = SATURATE_LEFT_SHIFT(
+ (energy[pb] >> 1) + (fPow2Div2(inputReal[qs] << clz) >> 1) +
+ (fPow2Div2(inputImag[qs] << clz) >> 1),
+ 1, DFRACT_BITS);
}
pb++;
@@ -1112,43 +1099,29 @@ static INT DuckerCalcEnergy(DUCKER_INSTANCE *const self,
maxVal = inputMaxVal;
if (maxVal == FL2FXCONST_DBL(-1.0f)) {
-#ifdef FUNCTION_DuckerCalcEnergy_func2
- maxVal = DuckerCalcEnergy_func2(inputReal, inputImag, startHybBand,
- maxHybBand, maxHybridBand);
-#else
- FIXP_DBL localMaxVal = FL2FXCONST_DBL(0.0f);
- for (qs = startHybBand; qs <= maxHybBand; qs++) {
- localMaxVal |= fAbs(inputReal[qs]);
- localMaxVal |= fAbs(inputImag[qs]);
- }
- for (; qs <= maxHybridBand; qs++) {
- localMaxVal |= fAbs(inputReal[qs]);
- }
- maxVal = localMaxVal;
-#endif
+ clz = fMin(getScalefactor(&inputReal[startHybBand],
+ fMax(0, maxHybridBand - startHybBand + 1)),
+ getScalefactor(&inputImag[startHybBand],
+ fMax(0, maxHybBand - startHybBand + 1)));
+ } else {
+ clz = CntLeadingZeros(maxVal) - 1;
}
- clz = fixMax(0, CntLeadingZeros(maxVal) - DUCKER_HEADROOM_BITS);
- clz = fixMin(clz, DUCKER_MAX_NRG_SCALE);
+ clz = fMin(fMax(0, clz - DUCKER_HEADROOM_BITS), DUCKER_MAX_NRG_SCALE);
*nrgScale = (SCHAR)clz << 1;
-#ifdef FUNCTION_DuckerCalcEnergy_func4
- DuckerCalcEnergy_func4(inputReal, inputImag, energy,
- self->mapHybBands2ProcBands, clz, startHybBand,
- maxHybBand, maxHybridBand);
-#else
for (qs = startHybBand; qs <= maxHybBand; qs++) {
int pb = SpatialDecGetProcessingBand(qs, self->mapHybBands2ProcBands);
- energy[pb] =
- fAddSaturate(energy[pb], fPow2Div2(inputReal[qs] << clz) +
- fPow2Div2(inputImag[qs] << clz));
+ energy[pb] = SATURATE_LEFT_SHIFT(
+ (energy[pb] >> 1) + (fPow2Div2(inputReal[qs] << clz) >> 1) +
+ (fPow2Div2(inputImag[qs] << clz) >> 1),
+ 1, DFRACT_BITS);
}
for (; qs <= maxHybridBand; qs++) {
int pb = SpatialDecGetProcessingBand(qs, self->mapHybBands2ProcBands);
energy[pb] = fAddSaturate(energy[pb], fPow2Div2(inputReal[qs] << clz));
}
-#endif /* FUNCTION_DuckerCalcEnergy_func4 */
}
{
@@ -1295,10 +1268,6 @@ static INT DuckerApply(DUCKER_INSTANCE *const self,
}
}
-#ifdef FUNCTION_DuckerApply_func1
- qs = DuckerApply_func1(qs, hybBands, qs_next, outputReal, outputImag,
- duckGain);
-#else
/* general gain*output section */
if (qs < hybBands) { /* true for about 39% */
for (; qs < qs_next; qs++) { /* runs about 2 times */
@@ -1310,7 +1279,6 @@ static INT DuckerApply(DUCKER_INSTANCE *const self,
outputReal[qs] = fMultDiv2(outputReal[qs], duckGain) << 2;
}
}
-#endif
} /* pb */
self->headroomSmoothDirRevNrg =
diff --git a/libFDK/src/dct.cpp b/libFDK/src/dct.cpp
index 776493e..bd26736 100644
--- a/libFDK/src/dct.cpp
+++ b/libFDK/src/dct.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 - 2019 Fraunhofer-Gesellschaft zur Förderung der angewandten
Forschung e.V. All rights reserved.
1. INTRODUCTION
@@ -489,18 +489,18 @@ void dst_IV(FIXP_DBL *pDat, int L, int *pDat_e) {
for (i = 0; i < M - 1; i += 2, pDat_0 += 2, pDat_1 -= 2) {
FIXP_DBL accu1, accu2, accu3, accu4;
- accu1 = pDat_1[1];
- accu2 = -pDat_0[0];
- accu3 = pDat_0[1];
- accu4 = -pDat_1[0];
+ accu1 = pDat_1[1] >> 1;
+ accu2 = -(pDat_0[0] >> 1);
+ accu3 = pDat_0[1] >> 1;
+ accu4 = -(pDat_1[0] >> 1);
cplxMultDiv2(&accu1, &accu2, accu1, accu2, twiddle[i]);
cplxMultDiv2(&accu3, &accu4, accu4, accu3, twiddle[i + 1]);
- pDat_0[0] = accu2 >> 1;
- pDat_0[1] = accu1 >> 1;
- pDat_1[0] = accu4 >> 1;
- pDat_1[1] = -(accu3 >> 1);
+ pDat_0[0] = accu2;
+ pDat_0[1] = accu1;
+ pDat_1[0] = accu4;
+ pDat_1[1] = -accu3;
}
if (M & 1) {
FIXP_DBL accu1, accu2;
diff --git a/libFDK/src/qmf.cpp b/libFDK/src/qmf.cpp
index 69f7e05..19f1ea1 100644
--- a/libFDK/src/qmf.cpp
+++ b/libFDK/src/qmf.cpp
@@ -609,9 +609,9 @@ inline static void qmfInverseModulationLP_even(
FIXP_DBL *RESTRICT tImag = pTimeOut + L;
/* Move input to output vector with offset */
- scaleValues(&tReal[0], &qmfReal[0], synQmf->lsb, (int)scaleFactorLowBand);
- scaleValues(&tReal[0 + synQmf->lsb], &qmfReal[0 + synQmf->lsb],
- synQmf->usb - synQmf->lsb, (int)scaleFactorHighBand);
+ scaleValuesSaturate(&tReal[0], &qmfReal[0], synQmf->lsb, scaleFactorLowBand);
+ scaleValuesSaturate(&tReal[0 + synQmf->lsb], &qmfReal[0 + synQmf->lsb],
+ synQmf->usb - synQmf->lsb, scaleFactorHighBand);
FDKmemclear(&tReal[0 + synQmf->usb], (L - synQmf->usb) * sizeof(FIXP_DBL));
/* Dct type-2 transform */
@@ -662,9 +662,9 @@ inline static void qmfInverseModulationLP_odd(
int shift = 0;
/* Move input to output vector with offset */
- scaleValues(pTimeOut + M, qmfReal, synQmf->lsb, scaleFactorLowBand);
- scaleValues(pTimeOut + M + synQmf->lsb, qmfReal + synQmf->lsb,
- synQmf->usb - synQmf->lsb, scaleFactorHighBand);
+ scaleValuesSaturate(pTimeOut + M, qmfReal, synQmf->lsb, scaleFactorLowBand);
+ scaleValuesSaturate(pTimeOut + M + synQmf->lsb, qmfReal + synQmf->lsb,
+ synQmf->usb - synQmf->lsb, scaleFactorHighBand);
FDKmemclear(pTimeOut + M + synQmf->usb, (L - synQmf->usb) * sizeof(FIXP_DBL));
dct_IV(pTimeOut + M, L, &shift);
@@ -698,26 +698,27 @@ inline static void qmfInverseModulationHQ(
FIXP_DBL *RESTRICT tImag = pWorkBuffer + L;
if (synQmf->flags & QMF_FLAG_CLDFB) {
- for (i = 0; i < synQmf->lsb; i++) {
- cplxMult(&tImag[i], &tReal[i], scaleValue(qmfImag[i], scaleFactorLowBand),
- scaleValue(qmfReal[i], scaleFactorLowBand), synQmf->t_cos[i],
- synQmf->t_sin[i]);
- }
- for (; i < synQmf->usb; i++) {
- cplxMult(&tImag[i], &tReal[i],
- scaleValue(qmfImag[i], scaleFactorHighBand),
- scaleValue(qmfReal[i], scaleFactorHighBand), synQmf->t_cos[i],
- synQmf->t_sin[i]);
+ for (i = 0; i < synQmf->usb; i++) {
+ cplxMultDiv2(&tImag[i], &tReal[i], qmfImag[i], qmfReal[i],
+ synQmf->t_cos[i], synQmf->t_sin[i]);
}
+ scaleValuesSaturate(&tReal[0], synQmf->lsb, scaleFactorLowBand + 1);
+ scaleValuesSaturate(&tReal[0 + synQmf->lsb], synQmf->usb - synQmf->lsb,
+ scaleFactorHighBand + 1);
+ scaleValuesSaturate(&tImag[0], synQmf->lsb, scaleFactorLowBand + 1);
+ scaleValuesSaturate(&tImag[0 + synQmf->lsb], synQmf->usb - synQmf->lsb,
+ scaleFactorHighBand + 1);
}
if ((synQmf->flags & QMF_FLAG_CLDFB) == 0) {
- scaleValues(&tReal[0], &qmfReal[0], synQmf->lsb, (int)scaleFactorLowBand);
- scaleValues(&tReal[0 + synQmf->lsb], &qmfReal[0 + synQmf->lsb],
- synQmf->usb - synQmf->lsb, (int)scaleFactorHighBand);
- scaleValues(&tImag[0], &qmfImag[0], synQmf->lsb, (int)scaleFactorLowBand);
- scaleValues(&tImag[0 + synQmf->lsb], &qmfImag[0 + synQmf->lsb],
- synQmf->usb - synQmf->lsb, (int)scaleFactorHighBand);
+ scaleValuesSaturate(&tReal[0], &qmfReal[0], synQmf->lsb,
+ scaleFactorLowBand);
+ scaleValuesSaturate(&tReal[0 + synQmf->lsb], &qmfReal[0 + synQmf->lsb],
+ synQmf->usb - synQmf->lsb, scaleFactorHighBand);
+ scaleValuesSaturate(&tImag[0], &qmfImag[0], synQmf->lsb,
+ scaleFactorLowBand);
+ scaleValuesSaturate(&tImag[0 + synQmf->lsb], &qmfImag[0 + synQmf->lsb],
+ synQmf->usb - synQmf->lsb, scaleFactorHighBand);
}
FDKmemclear(&tReal[synQmf->usb],
diff --git a/libFDK/src/scale.cpp b/libFDK/src/scale.cpp
index 24a8a5b..6192170 100644
--- a/libFDK/src/scale.cpp
+++ b/libFDK/src/scale.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 - 2019 Fraunhofer-Gesellschaft zur Förderung der angewandten
Forschung e.V. All rights reserved.
1. INTRODUCTION
@@ -250,10 +250,10 @@ void scaleValuesSaturate(FIXP_DBL *vector, /*!< Vector */
*/
#define FUNCTION_scaleValuesSaturate_DBL_DBL
SCALE_INLINE
-void scaleValuesSaturate(FIXP_DBL *dst, /*!< Output */
- FIXP_DBL *src, /*!< Input */
- INT len, /*!< Length */
- INT scalefactor /*!< Scalefactor */
+void scaleValuesSaturate(FIXP_DBL *dst, /*!< Output */
+ const FIXP_DBL *src, /*!< Input */
+ INT len, /*!< Length */
+ INT scalefactor /*!< Scalefactor */
) {
INT i;
@@ -285,10 +285,10 @@ void scaleValuesSaturate(FIXP_DBL *dst, /*!< Output */
*/
#define FUNCTION_scaleValuesSaturate_SGL_DBL
SCALE_INLINE
-void scaleValuesSaturate(FIXP_SGL *dst, /*!< Output */
- FIXP_DBL *src, /*!< Input */
- INT len, /*!< Length */
- INT scalefactor) /*!< Scalefactor */
+void scaleValuesSaturate(FIXP_SGL *dst, /*!< Output */
+ const FIXP_DBL *src, /*!< Input */
+ INT len, /*!< Length */
+ INT scalefactor) /*!< Scalefactor */
{
INT i;
scalefactor = fixmax_I(fixmin_I(scalefactor, (INT)DFRACT_BITS - 1),
@@ -345,10 +345,10 @@ void scaleValuesSaturate(FIXP_SGL *vector, /*!< Vector */
*/
#define FUNCTION_scaleValuesSaturate_SGL_SGL
SCALE_INLINE
-void scaleValuesSaturate(FIXP_SGL *dst, /*!< Output */
- FIXP_SGL *src, /*!< Input */
- INT len, /*!< Length */
- INT scalefactor /*!< Scalefactor */
+void scaleValuesSaturate(FIXP_SGL *dst, /*!< Output */
+ const FIXP_SGL *src, /*!< Input */
+ INT len, /*!< Length */
+ INT scalefactor /*!< Scalefactor */
) {
INT i;