diff options
author | Jean-Michel Trivi <jmtrivi@google.com> | 2016-04-09 05:44:33 +0000 |
---|---|---|
committer | android-build-merger <android-build-merger@google.com> | 2016-04-09 05:44:33 +0000 |
commit | 4a5a256a01c0f6aa0ebd1b94bba77a70fcac75ee (patch) | |
tree | 626b5c026f23b0c8ec4dab155faf86d55cd9d94e /libAACenc | |
parent | 20e8db77ff09cefbe191f1e50815ff8f971a3353 (diff) | |
parent | 125815b0ed558c72bb019a2d36c662e5e7f7c030 (diff) | |
download | fdk-aac-4a5a256a01c0f6aa0ebd1b94bba77a70fcac75ee.tar.gz fdk-aac-4a5a256a01c0f6aa0ebd1b94bba77a70fcac75ee.tar.bz2 fdk-aac-4a5a256a01c0f6aa0ebd1b94bba77a70fcac75ee.zip |
AAC/SBR encoder improvements am: 46ba367
am: 125815b
* commit '125815b0ed558c72bb019a2d36c662e5e7f7c030':
AAC/SBR encoder improvements
Change-Id: I4ef0a1959666e21ace6086f184302aed640043f6
Diffstat (limited to 'libAACenc')
-rw-r--r-- | libAACenc/src/aacenc.h | 5 | ||||
-rw-r--r-- | libAACenc/src/aacenc_lib.cpp | 15 | ||||
-rw-r--r-- | libAACenc/src/aacenc_tns.cpp | 102 | ||||
-rw-r--r-- | libAACenc/src/aacenc_tns.h | 30 | ||||
-rw-r--r-- | libAACenc/src/adj_thr.cpp | 77 | ||||
-rw-r--r-- | libAACenc/src/adj_thr.h | 6 | ||||
-rw-r--r-- | libAACenc/src/adj_thr_data.h | 3 | ||||
-rw-r--r-- | libAACenc/src/bandwidth.cpp | 8 | ||||
-rw-r--r-- | libAACenc/src/pnsparam.cpp | 47 | ||||
-rw-r--r-- | libAACenc/src/psy_main.cpp | 21 | ||||
-rw-r--r-- | libAACenc/src/qc_data.h | 4 | ||||
-rw-r--r-- | libAACenc/src/qc_main.cpp | 20 | ||||
-rw-r--r-- | libAACenc/src/quantize.cpp | 24 | ||||
-rw-r--r-- | libAACenc/src/quantize.h | 8 | ||||
-rw-r--r-- | libAACenc/src/sf_estim.cpp | 73 | ||||
-rw-r--r-- | libAACenc/src/sf_estim.h | 3 | ||||
-rw-r--r-- | libAACenc/src/tns_func.h | 3 |
17 files changed, 281 insertions, 168 deletions
diff --git a/libAACenc/src/aacenc.h b/libAACenc/src/aacenc.h index 61520de..79524b5 100644 --- a/libAACenc/src/aacenc.h +++ b/libAACenc/src/aacenc.h @@ -98,6 +98,11 @@ amm-info@iis.fraunhofer.de #include "sbr_encoder.h" +#define BITRES_MAX_LD 4000 +#define BITRES_MIN_LD 500 +#define BITRATE_MAX_LD 70000 /* Max assumed bitrate for bitres calculation */ +#define BITRATE_MIN_LD 12000 /* Min assumed bitrate for bitres calculation */ + #ifdef __cplusplus extern "C" { #endif diff --git a/libAACenc/src/aacenc_lib.cpp b/libAACenc/src/aacenc_lib.cpp index 9a3b214..2845177 100644 --- a/libAACenc/src/aacenc_lib.cpp +++ b/libAACenc/src/aacenc_lib.cpp @@ -98,7 +98,7 @@ amm-info@iis.fraunhofer.de /* Encoder library info */ #define AACENCODER_LIB_VL0 3 #define AACENCODER_LIB_VL1 4 -#define AACENCODER_LIB_VL2 19 +#define AACENCODER_LIB_VL2 22 #define AACENCODER_LIB_TITLE "AAC Encoder" #ifdef __ANDROID__ #define AACENCODER_LIB_BUILD_DATE "" @@ -813,11 +813,16 @@ AACENC_ERROR FDKaacEnc_AdjustEncSettings(HANDLE_AACENCODER hAacEncoder, switch ( hAacConfig->audioObjectType ) { case AOT_ER_AAC_LD: case AOT_ER_AAC_ELD: - if (config->userBitrateMode==8) { - hAacConfig->bitrateMode = 0; - } if (config->userBitrateMode==0) { - hAacConfig->bitreservoir = 100*config->nChannels; /* default, reduced bitreservoir */ + /* bitreservoir = (maxBitRes-minBitRes)/(maxBitRate-minBitrate)*(bitRate-minBitrate)+minBitRes; */ + if ( isLowDelay(hAacConfig->audioObjectType) ) { + INT bitreservoir; + INT brPerChannel = hAacConfig->bitRate/hAacConfig->nChannels; + brPerChannel = fMin(BITRATE_MAX_LD, fMax(BITRATE_MIN_LD, brPerChannel)); + FIXP_DBL slope = fDivNorm((brPerChannel-BITRATE_MIN_LD), BITRATE_MAX_LD-BITRATE_MIN_LD); /* calc slope for interpolation */ + bitreservoir = fMultI(slope, (INT)(BITRES_MAX_LD-BITRES_MIN_LD)) + BITRES_MIN_LD; /* interpolate */ + hAacConfig->bitreservoir = bitreservoir & ~7; /* align to bytes */ + } } if (hAacConfig->bitrateMode!=0) { return AACENC_INVALID_CONFIG; diff --git a/libAACenc/src/aacenc_tns.cpp b/libAACenc/src/aacenc_tns.cpp index 85aea65..9a07e8f 100644 --- a/libAACenc/src/aacenc_tns.cpp +++ b/libAACenc/src/aacenc_tns.cpp @@ -2,7 +2,7 @@ /* ----------------------------------------------------------------------------------------------------------- Software License for The Fraunhofer FDK AAC Codec Library for Android -© Copyright 1995 - 2013 Fraunhofer-Gesellschaft zur Förderung der angewandten Forschung e.V. +© Copyright 1995 - 2015 Fraunhofer-Gesellschaft zur Förderung der angewandten Forschung e.V. All rights reserved. 1. INTRODUCTION @@ -95,13 +95,7 @@ amm-info@iis.fraunhofer.de #include "aacEnc_rom.h" #include "aacenc_tns.h" -enum { - HIFILT = 0, /* index of higher filter */ - LOFILT = 1 /* index of lower filter */ -}; - - -#define FILTER_DIRECTION 0 +#define FILTER_DIRECTION 0 /* 0 = up, 1 = down */ static const FIXP_DBL acfWindowLong[12+3+1] = { 0x7fffffff,0x7fb80000,0x7ee00000,0x7d780000,0x7b800000,0x78f80000,0x75e00000,0x72380000, @@ -112,20 +106,6 @@ static const FIXP_DBL acfWindowShort[4+3+1] = { 0x7fffffff,0x7e000000,0x78000000,0x6e000000,0x60000000,0x4e000000,0x38000000,0x1e000000 }; - -typedef struct { - INT filterEnabled[MAX_NUM_OF_FILTERS]; - INT threshOn[MAX_NUM_OF_FILTERS]; /* min. prediction gain for using tns TABUL*/ - INT filterStartFreq[MAX_NUM_OF_FILTERS]; /* lowest freq for lpc TABUL*/ - INT tnsLimitOrder[MAX_NUM_OF_FILTERS]; /* Limit for TNS order TABUL*/ - INT tnsFilterDirection[MAX_NUM_OF_FILTERS]; /* Filtering direction, 0=up, 1=down TABUL */ - INT acfSplit[MAX_NUM_OF_FILTERS]; - FIXP_DBL tnsTimeResolution[MAX_NUM_OF_FILTERS]; /* TNS max. time resolution TABUL. Should be fract but MSVC won't compile then */ - INT seperateFiltersAllowed; - -} TNS_PARAMETER_TABULATED; - - typedef struct{ INT bitRateFrom[2]; /* noneSbr=0, useSbr=1 */ INT bitRateTo[2]; /* noneSbr=0, useSbr=1 */ @@ -373,6 +353,7 @@ AAC_ENCODER_ERROR FDKaacEnc_InitTnsConfiguration(INT bitRate, INT channels, INT blockType, INT granuleLength, + INT isLowDelay, INT ldSbrPresent, TNS_CONFIG *tC, PSY_CONFIGURATION *pC, @@ -385,6 +366,8 @@ AAC_ENCODER_ERROR FDKaacEnc_InitTnsConfiguration(INT bitRate, if (channels <= 0) return (AAC_ENCODER_ERROR)1; + tC->isLowDelay = isLowDelay; + /* initialize TNS filter flag, order, and coefficient resolution (in bits per coeff) */ tC->tnsActive = (active) ? TRUE : FALSE; tC->maxOrder = (blockType == SHORT_WINDOW) ? 5 : 12; /* maximum: 7, 20 */ @@ -450,27 +433,14 @@ AAC_ENCODER_ERROR FDKaacEnc_InitTnsConfiguration(INT bitRate, const TNS_PARAMETER_TABULATED* pCfg = FDKaacEnc_GetTnsParam(bitRate, channels, ldSbrPresent); if ( pCfg != NULL ) { + + FDKmemcpy(&(tC->confTab), pCfg, sizeof(tC->confTab)); + tC->lpcStartBand[HIFILT] = FDKaacEnc_FreqToBandWithRounding(pCfg->filterStartFreq[HIFILT], sampleRate, pC->sfbCnt, pC->sfbOffset); tC->lpcStartLine[HIFILT] = pC->sfbOffset[tC->lpcStartBand[HIFILT]]; tC->lpcStartBand[LOFILT] = FDKaacEnc_FreqToBandWithRounding(pCfg->filterStartFreq[LOFILT], sampleRate, pC->sfbCnt, pC->sfbOffset); tC->lpcStartLine[LOFILT] = pC->sfbOffset[tC->lpcStartBand[LOFILT]]; - tC->confTab.threshOn[HIFILT] = pCfg->threshOn[HIFILT]; - tC->confTab.threshOn[LOFILT] = pCfg->threshOn[LOFILT]; - - tC->confTab.tnsLimitOrder[HIFILT] = pCfg->tnsLimitOrder[HIFILT]; - tC->confTab.tnsLimitOrder[LOFILT] = pCfg->tnsLimitOrder[LOFILT]; - - tC->confTab.tnsFilterDirection[HIFILT] = pCfg->tnsFilterDirection[HIFILT]; - tC->confTab.tnsFilterDirection[LOFILT] = pCfg->tnsFilterDirection[LOFILT]; - - tC->confTab.acfSplit[HIFILT] = pCfg->acfSplit[HIFILT]; - tC->confTab.acfSplit[LOFILT] = pCfg->acfSplit[LOFILT]; - - tC->confTab.filterEnabled[HIFILT] = pCfg->filterEnabled[HIFILT]; - tC->confTab.filterEnabled[LOFILT] = pCfg->filterEnabled[LOFILT]; - tC->confTab.seperateFiltersAllowed = pCfg->seperateFiltersAllowed; - FDKaacEnc_CalcGaussWindow(tC->acfWindow[HIFILT], tC->maxOrder+1, sampleRate, granuleLength, pCfg->tnsTimeResolution[HIFILT], TNS_TIMERES_SCALE); FDKaacEnc_CalcGaussWindow(tC->acfWindow[LOFILT], tC->maxOrder+1, sampleRate, granuleLength, pCfg->tnsTimeResolution[LOFILT], TNS_TIMERES_SCALE); } @@ -614,6 +584,7 @@ static inline FIXP_DBL FDKaacEnc_AutoCorrNormFac( static void FDKaacEnc_MergedAutoCorrelation( const FIXP_DBL *spectrum, + const INT isLowDelay, const FIXP_DBL acfWindow[MAX_NUM_OF_FILTERS][TNS_MAX_ORDER+3+1], const INT lpcStartLine[MAX_NUM_OF_FILTERS], const INT lpcStopLine, @@ -633,6 +604,8 @@ static void FDKaacEnc_MergedAutoCorrelation( FDKmemclear(&_rxx1[0], sizeof(FIXP_DBL)*(maxOrder+1)); FDKmemclear(&_rxx2[0], sizeof(FIXP_DBL)*(maxOrder+1)); + idx0 = idx1 = idx2 = idx3 = idx4 = 0; + /* MDCT line indices separating the 1st, 2nd, 3rd, and 4th analysis quarters */ if ( (acfSplit[LOFILT]==-1) || (acfSplit[HIFILT]==-1) ) { /* autocorrelation function for 1st, 2nd, 3rd, and 4th quarter of the spectrum */ @@ -676,17 +649,27 @@ static void FDKaacEnc_MergedAutoCorrelation( /* compute energy normalization factors, i. e. 1/energy (saves some divisions) */ if (rxx1_0 != FL2FXCONST_DBL(0.f)) { - INT sc_fac1 = -1; - FIXP_DBL fac1 = FDKaacEnc_AutoCorrNormFac(rxx1_0, ((-2*sc1)+nsc1), &sc_fac1); - _rxx1[0] = scaleValue(fMult(rxx1_0,fac1),sc_fac1); + INT sc_fac1 = -1; + FIXP_DBL fac1 = FDKaacEnc_AutoCorrNormFac(rxx1_0, ((-2*sc1)+nsc1), &sc_fac1); + _rxx1[0] = scaleValue(fMult(rxx1_0,fac1),sc_fac1); + if (isLowDelay) + { for (lag = 1; lag <= maxOrder; lag++) { /* compute energy-normalized and windowed autocorrelation values at this lag */ + FIXP_DBL x1 = FDKaacEnc_CalcAutoCorrValue(pSpectrum, idx0, idx1, lag, nsc1); + _rxx1[lag] = fMult(scaleValue(fMult(x1,fac1),sc_fac1), acfWindow[LOFILT][lag]); + } + } + else + { + for (lag = 1; lag <= maxOrder; lag++) { if ((3 * lag) <= maxOrder + 3) { FIXP_DBL x1 = FDKaacEnc_CalcAutoCorrValue(pSpectrum, idx0, idx1, lag, nsc1); _rxx1[lag] = fMult(scaleValue(fMult(x1,fac1),sc_fac1), acfWindow[LOFILT][3*lag]); } } + } } /* auto corr over upper 3/4 of spectrum */ @@ -762,8 +745,12 @@ INT FDKaacEnc_TnsDetect( : &tnsData->dataRaw.Long.subBlockInfo; tnsData->filtersMerged = FALSE; - tsbi->tnsActive = FALSE; - tsbi->predictionGain = 1000; + + tsbi->tnsActive[HIFILT] = FALSE; + tsbi->predictionGain[HIFILT] = 1000; + tsbi->tnsActive[LOFILT] = FALSE; + tsbi->predictionGain[LOFILT] = 1000; + tnsInfo->numOfFilters[subBlockNumber] = 0; tnsInfo->coefRes[subBlockNumber] = tC->coefRes; for (i = 0; i < tC->maxOrder; i++) { @@ -779,6 +766,7 @@ INT FDKaacEnc_TnsDetect( FDKaacEnc_MergedAutoCorrelation( spectrum, + tC->isLowDelay, tC->acfWindow, tC->lpcStartLine, tC->lpcStopLine, @@ -788,7 +776,7 @@ INT FDKaacEnc_TnsDetect( rxx2); /* compute higher TNS filter in lattice (ParCor) form with LeRoux-Gueguen algorithm */ - tsbi->predictionGain = FDKaacEnc_AutoToParcor(rxx2, parcor_tmp, tC->confTab.tnsLimitOrder[HIFILT]); + tsbi->predictionGain[HIFILT] = FDKaacEnc_AutoToParcor(rxx2, parcor_tmp, tC->confTab.tnsLimitOrder[HIFILT]); /* non-linear quantization of TNS lattice coefficients with given resolution */ FDKaacEnc_Parcor2Index( @@ -815,9 +803,9 @@ INT FDKaacEnc_TnsDetect( tnsInfo->length[subBlockNumber][HIFILT] = sfbCnt - tC->lpcStartBand[HIFILT]; /* disable TNS if predictionGain is less than 3dB or sumSqrCoef is too small */ - if ((tsbi->predictionGain > tC->confTab.threshOn[HIFILT]) || (sumSqrCoef > (tC->confTab.tnsLimitOrder[HIFILT]/2 + 2))) + if ((tsbi->predictionGain[HIFILT] > tC->confTab.threshOn[HIFILT]) || (sumSqrCoef > (tC->confTab.tnsLimitOrder[HIFILT]/2 + 2))) { - tsbi->tnsActive = TRUE; + tsbi->tnsActive[HIFILT] = TRUE; tnsInfo->numOfFilters[subBlockNumber]++; /* compute second filter for lower quarter; only allowed for long windows! */ @@ -857,6 +845,7 @@ INT FDKaacEnc_TnsDetect( || ( (sumSqrCoef > 9) && (sumSqrCoef < 22 * tC->confTab.tnsLimitOrder[LOFILT]) ) ) { /* compare lower to upper filter; if they are very similar, merge them */ + tsbi->tnsActive[LOFILT] = TRUE; sumSqrCoef = 0; for (i = 0; i < tC->confTab.tnsLimitOrder[LOFILT]; i++) { sumSqrCoef += FDKabs(tnsInfo->coef[subBlockNumber][HIFILT][i] - tnsInfo->coef[subBlockNumber][LOFILT][i]); @@ -884,6 +873,8 @@ INT FDKaacEnc_TnsDetect( tnsInfo->numOfFilters[subBlockNumber]++; } } /* filter lower part */ + tsbi->predictionGain[LOFILT]=predGain; + } /* second filter allowed */ } /* if predictionGain > 1437 ... */ } /* maxOrder > 0 && tnsActive */ @@ -944,7 +935,7 @@ void FDKaacEnc_TnsSync( INT doSync = 1, absDiffSum = 0; /* if TNS is active in at least one channel, check if ParCor coefficients of higher filter are similar */ - if (pSbInfoDestW->tnsActive || pSbInfoSrcW->tnsActive) { + if (pSbInfoDestW->tnsActive[HIFILT] || pSbInfoSrcW->tnsActive[HIFILT]) { for (i = 0; i < tC->maxOrder; i++) { absDiff = FDKabs(tnsInfoDest->coef[w][HIFILT][i] - tnsInfoSrc->coef[w][HIFILT][i]); absDiffSum += absDiff; @@ -957,12 +948,12 @@ void FDKaacEnc_TnsSync( if (doSync) { /* if no significant difference was detected, synchronize coefficient sets */ - if (pSbInfoSrcW->tnsActive) { + if (pSbInfoSrcW->tnsActive[HIFILT]) { /* no dest filter, or more dest than source filters: use one dest filter */ - if ((!pSbInfoDestW->tnsActive) || - ((pSbInfoDestW->tnsActive) && (tnsInfoDest->numOfFilters[w] > tnsInfoSrc->numOfFilters[w]))) + if ((!pSbInfoDestW->tnsActive[HIFILT]) || + ((pSbInfoDestW->tnsActive[HIFILT]) && (tnsInfoDest->numOfFilters[w] > tnsInfoSrc->numOfFilters[w]))) { - pSbInfoDestW->tnsActive = tnsInfoDest->numOfFilters[w] = 1; + pSbInfoDestW->tnsActive[HIFILT] = tnsInfoDest->numOfFilters[w] = 1; } tnsDataDest->filtersMerged = tnsDataSrc->filtersMerged; tnsInfoDest->order [w][HIFILT] = tnsInfoSrc->order [w][HIFILT]; @@ -975,7 +966,7 @@ void FDKaacEnc_TnsSync( } } else - pSbInfoDestW->tnsActive = tnsInfoDest->numOfFilters[w] = 0; + pSbInfoDestW->tnsActive[HIFILT] = tnsInfoDest->numOfFilters[w] = 0; } } @@ -1012,8 +1003,8 @@ INT FDKaacEnc_TnsEncode( { INT i, startLine, stopLine; - if ( ( (blockType == SHORT_WINDOW) && (!tnsData->dataRaw.Short.subBlockInfo[subBlockNumber].tnsActive) ) - || ( (blockType != SHORT_WINDOW) && (!tnsData->dataRaw.Long.subBlockInfo.tnsActive) ) ) + if ( ( (blockType == SHORT_WINDOW) && (!tnsData->dataRaw.Short.subBlockInfo[subBlockNumber].tnsActive[HIFILT]) ) + || ( (blockType != SHORT_WINDOW) && (!tnsData->dataRaw.Long.subBlockInfo.tnsActive[HIFILT]) ) ) { return 1; } @@ -1129,8 +1120,9 @@ static INT FDKaacEnc_AutoToParcor( FIXP_DBL *RESTRICT workBuffer = parcorWorkBuffer; const FIXP_DBL autoCorr_0 = input[0]; + FDKmemclear(reflCoeff,numOfCoeff*sizeof(FIXP_DBL)); + if((FIXP_DBL)input[0] == FL2FXCONST_DBL(0.0)) { - FDKmemclear(reflCoeff,numOfCoeff*sizeof(FIXP_DBL)); return(predictionGain); } diff --git a/libAACenc/src/aacenc_tns.h b/libAACenc/src/aacenc_tns.h index f2b731f..2824cbc 100644 --- a/libAACenc/src/aacenc_tns.h +++ b/libAACenc/src/aacenc_tns.h @@ -2,7 +2,7 @@ /* ----------------------------------------------------------------------------------------------------------- Software License for The Fraunhofer FDK AAC Codec Library for Android -© Copyright 1995 - 2013 Fraunhofer-Gesellschaft zur Förderung der angewandten Forschung e.V. +© Copyright 1995 - 2015 Fraunhofer-Gesellschaft zur Förderung der angewandten Forschung e.V. All rights reserved. 1. INTRODUCTION @@ -117,21 +117,25 @@ amm-info@iis.fraunhofer.de #define MAX_NUM_OF_FILTERS 2 +#define HIFILT 0 /* index of higher filter */ +#define LOFILT 1 /* index of lower filter */ -typedef struct{ /*stuff that is tabulated dependent on bitrate etc. */ - INT filterEnabled[MAX_NUM_OF_FILTERS]; - INT threshOn[MAX_NUM_OF_FILTERS]; /* min. prediction gain for using tns TABUL*/ - INT tnsLimitOrder[MAX_NUM_OF_FILTERS]; /* Limit for TNS order TABUL*/ - INT tnsFilterDirection[MAX_NUM_OF_FILTERS]; /* Filtering direction, 0=up, 1=down TABUL */ - INT acfSplit[MAX_NUM_OF_FILTERS]; - INT seperateFiltersAllowed; - -}TNS_CONFIG_TABULATED; +typedef struct{ /* stuff that is tabulated dependent on bitrate etc. */ + INT filterEnabled[MAX_NUM_OF_FILTERS]; + INT threshOn[MAX_NUM_OF_FILTERS]; /* min. prediction gain for using tns TABUL*/ + INT filterStartFreq[MAX_NUM_OF_FILTERS]; /* lowest freq for lpc TABUL*/ + INT tnsLimitOrder[MAX_NUM_OF_FILTERS]; /* Limit for TNS order TABUL*/ + INT tnsFilterDirection[MAX_NUM_OF_FILTERS]; /* Filtering direction, 0=up, 1=down TABUL */ + INT acfSplit[MAX_NUM_OF_FILTERS]; + FIXP_DBL tnsTimeResolution[MAX_NUM_OF_FILTERS]; /* TNS max. time resolution TABUL. Should be fract but MSVC won't compile then */ + INT seperateFiltersAllowed; +} TNS_PARAMETER_TABULATED; typedef struct { /*assigned at InitTime*/ - TNS_CONFIG_TABULATED confTab; + TNS_PARAMETER_TABULATED confTab; + INT isLowDelay; INT tnsActive; INT maxOrder; /* max. order of tns filter */ INT coefRes; @@ -148,8 +152,8 @@ typedef struct { /*assigned at InitTime*/ typedef struct { - INT tnsActive; - INT predictionGain; + INT tnsActive[MAX_NUM_OF_FILTERS]; + INT predictionGain[MAX_NUM_OF_FILTERS]; } TNS_SUBBLOCK_INFO; typedef struct{ /*changed at runTime*/ diff --git a/libAACenc/src/adj_thr.cpp b/libAACenc/src/adj_thr.cpp index c318843..a79a9ae 100644 --- a/libAACenc/src/adj_thr.cpp +++ b/libAACenc/src/adj_thr.cpp @@ -153,10 +153,10 @@ static const BIT_PE_SFAC S_Bits2PeTab16000[] = { { 24000, 0x23D70A3D, 0x029F16B1, 0x2199999A, 0x07DD4413, 0x23D70A3D, 0x029F16B1, 0x2199999A, 0x07DD4413}, { 32000, 0x247AE148, 0x11B1D92B, 0x23851EB8, 0x01F75105, 0x247AE148, 0x110A137F, 0x23851EB8, 0x01F75105}, { 48000, 0x2D1EB852, 0x6833C600, 0x247AE148, 0x014F8B59, 0x2CCCCCCD, 0x68DB8BAC, 0x247AE148, 0x01F75105}, - { 64000, 0x60000000, 0x00000000, 0x251EB852, 0x154C985F, 0x60000000, 0x00000000, 0x2570A3D7, 0x154C985F}, - { 96000, 0x60000000, 0x00000000, 0x39EB851F, 0x088509C0, 0x60000000, 0x00000000, 0x3A3D70A4, 0x088509C0}, - {128000, 0x60000000, 0x00000000, 0x423D70A4, 0x18A43BB4, 0x60000000, 0x00000000, 0x428F5C29, 0x181E03F7}, - {148000, 0x60000000, 0x00000000, 0x5147AE14, 0x00000000, 0x60000000, 0x00000000, 0x5147AE14, 0x00000000} + { 64000, 0x25c28f40, 0x00000000, 0x251EB852, 0x01480000, 0x25c28f40, 0x00000000, 0x2570A3D7, 0x01480000}, + { 96000, 0x25c28f40, 0x00000000, 0x26000000, 0x01000000, 0x25c28f40, 0x00000000, 0x26000000, 0x01000000}, + {128000, 0x25c28f40, 0x00000000, 0x270a3d80, 0x01000000, 0x25c28f40, 0x00000000, 0x270a3d80, 0x01000000}, + {148000, 0x25c28f40, 0x00000000, 0x28000000, 0x00000000, 0x25c28f40, 0x00000000, 0x28000000, 0x00000000} }; static const BIT_PE_SFAC S_Bits2PeTab22050[] = { @@ -166,8 +166,8 @@ static const BIT_PE_SFAC S_Bits2PeTab22050[] = { { 48000, 0x23d70a3d, 0x014f8b59, 0x2199999a, 0x03eea20a, 0x23d70a3d, 0x14f8b59, 0x2199999a, 0x03eea20a}, { 64000, 0x247ae148, 0x08d8ec96, 0x23851eb8, 0x00fba882, 0x247ae148, 0x88509c0, 0x23851eb8, 0x00fba882}, { 96000, 0x2d1eb852, 0x3419e300, 0x247ae148, 0x00a7c5ac, 0x2ccccccd, 0x346dc5d6, 0x247ae148, 0x00fba882}, - {128000, 0x60000000, 0x00000000, 0x251eb852, 0x029f16b1, 0x60000000, 0x00000000, 0x2570a3d7, 0x009f16b1}, - {148000, 0x60000000, 0x00000000, 0x26b851ec, 0x00000000, 0x60000000, 0x00000000, 0x270a3d71, 0x00000000} + {128000, 0x25c28f40, 0x00000000, 0x251eb852, 0x029f16b1, 0x60000000, 0x25c28f40, 0x2570a3d7, 0x009f16b1}, + {148000, 0x25c28f40, 0x00000000, 0x26b851ec, 0x00000000, 0x60000000, 0x25c28f40, 0x270a3d71, 0x00000000} }; static const BIT_PE_SFAC S_Bits2PeTab24000[] = { @@ -178,21 +178,21 @@ static const BIT_PE_SFAC S_Bits2PeTab24000[] = { { 64000, 0x24cccccd, 0x05e5f30e, 0x22e147ae, 0x01a36e2f, 0x24cccccd, 0x05e5f30e, 0x23333333, 0x014f8b59}, { 96000, 0x2a8f5c29, 0x24b33db0, 0x247ae148, 0x00fba882, 0x2a8f5c29, 0x26fe718b, 0x247ae148, 0x00fba882}, {128000, 0x4e666666, 0x1cd5f99c, 0x2570a3d7, 0x010c6f7a, 0x50a3d70a, 0x192a7371, 0x2570a3d7, 0x010c6f7a}, - {148000, 0x60000000, 0x00000000, 0x26147ae1, 0x00000000, 0x60000000, 0x00000000, 0x26147ae1, 0x00000000} + {148000, 0x25c28f40, 0x00000000, 0x26147ae1, 0x00000000, 0x25c28f40, 0x00000000, 0x26147ae1, 0x00000000} }; static const BIT_PE_SFAC S_Bits2PeTab32000[] = { - { 16000, 0x1199999a, 0x20c49ba6, 0x00000000, 0x4577d955, 0x00000000, 0x60fe4799, 0x00000000, 0x00000000}, - { 24000, 0x1999999a, 0x0fba8827, 0x10f5c28f, 0x1b866e44, 0x17ae147b, 0x0fba8827, 0x00000000, 0x4d551d69}, + { 16000, 0x247ae140, 0xFFFFAC1E, 0x270a3d80, 0xFFFE9B7C, 0x14ccccc0, 0x000110A1, 0x15c28f60, 0xFFFEEF5F}, + { 24000, 0x23333340, 0x0fba8827, 0x21999980, 0x1b866e44, 0x18f5c280, 0x0fba8827, 0x119999a0, 0x4d551d69}, { 32000, 0x1d70a3d7, 0x07357e67, 0x17ae147b, 0x09d49518, 0x1b851eb8, 0x0a7c5ac4, 0x12e147ae, 0x110a137f}, { 48000, 0x20f5c28f, 0x049667b6, 0x1c7ae148, 0x053e2d62, 0x20a3d70a, 0x053e2d62, 0x1b333333, 0x05e5f30e}, { 64000, 0x23333333, 0x029f16b1, 0x1f0a3d71, 0x02f2f987, 0x23333333, 0x029f16b1, 0x1e147ae1, 0x03eea20a}, { 96000, 0x25c28f5c, 0x2c3c9eed, 0x21eb851f, 0x01f75105, 0x25c28f5c, 0x0a7c5ac4, 0x21eb851f, 0x01a36e2f}, {128000, 0x50f5c28f, 0x18a43bb4, 0x23d70a3d, 0x010c6f7a, 0x30000000, 0x168b5cc0, 0x23851eb8, 0x0192a737}, - {148000, 0x60000000, 0x00000000, 0x247ae148, 0x00dfb23b, 0x3dc28f5c, 0x300f4aaf, 0x247ae148, 0x01bf6476}, - {160000, 0x60000000, 0xb15b5740, 0x24cccccd, 0x053e2d62, 0x4f5c28f6, 0xbefd0072, 0x251eb852, 0x04fb1184}, - {200000, 0x00000000, 0x00000000, 0x2b333333, 0x0836be91, 0x00000000, 0x00000000, 0x2b333333, 0x0890390f}, - {320000, 0x00000000, 0x00000000, 0x4947ae14, 0x00000000, 0x00000000, 0x00000000, 0x4a8f5c29, 0x00000000} + {148000, 0x25c28f40, 0x00000000, 0x247ae148, 0x00dfb23b, 0x3dc28f5c, 0x300f4aaf, 0x247ae148, 0x01bf6476}, + {160000, 0x25c28f40, 0xb15b5740, 0x24cccccd, 0x053e2d62, 0x4f5c28f6, 0xbefd0072, 0x251eb852, 0x04fb1184}, + {200000, 0x25c28f40, 0x00000000, 0x2b333333, 0x0836be91, 0x25c28f40, 0x00000000, 0x2b333333, 0x0890390f}, + {320000, 0x25c28f40, 0x00000000, 0x4947ae14, 0x00000000, 0x25c28f40, 0x00000000, 0x4a8f5c29, 0x00000000} }; static const BIT_PE_SFAC S_Bits2PeTab44100[] = { @@ -205,8 +205,8 @@ static const BIT_PE_SFAC S_Bits2PeTab44100[] = { {128000, 0x2ae147ae, 0x1b435265, 0x223d70a4, 0x0192a737, 0x2a3d70a4, 0x1040bfe4, 0x21eb851f, 0x0192a737}, {148000, 0x3b851eb8, 0x2832069c, 0x23333333, 0x00dfb23b, 0x3428f5c3, 0x2054c288, 0x22e147ae, 0x00dfb23b}, {160000, 0x4a3d70a4, 0xc32ebe5a, 0x23851eb8, 0x01d5c316, 0x40000000, 0xcb923a2b, 0x23333333, 0x01d5c316}, - {200000, 0x00000000, 0x00000000, 0x25c28f5c, 0x0713f078, 0x00000000, 0x00000000, 0x2570a3d7, 0x072a4f17}, - {320000, 0x00000000, 0x00000000, 0x3fae147b, 0x00000000, 0x00000000, 0x00000000, 0x3fae147b, 0x00000000} + {200000, 0x25c28f40, 0x00000000, 0x25c28f5c, 0x0713f078, 0x25c28f40, 0x00000000, 0x2570a3d7, 0x072a4f17}, + {320000, 0x25c28f40, 0x00000000, 0x3fae147b, 0x00000000, 0x25c28f40, 0x00000000, 0x3fae147b, 0x00000000} }; static const BIT_PE_SFAC S_Bits2PeTab48000[] = { @@ -219,8 +219,8 @@ static const BIT_PE_SFAC S_Bits2PeTab48000[] = { {128000, 0x28f5c28f, 0x14727dcc, 0x2147ae14, 0x0218def4, 0x2851eb85, 0x0e27e0f0, 0x20f5c28f, 0x0218def4}, {148000, 0x3570a3d7, 0x1cd5f99c, 0x228f5c29, 0x01bf6476, 0x30f5c28f, 0x18777e75, 0x223d70a4, 0x01bf6476}, {160000, 0x40000000, 0xcb923a2b, 0x23333333, 0x0192a737, 0x39eb851f, 0xd08d4bae, 0x22e147ae, 0x0192a737}, - {200000, 0x00000000, 0x00000000, 0x251eb852, 0x06775a1b, 0x00000000, 0x00000000, 0x24cccccd, 0x06a4175a}, - {320000, 0x00000000, 0x00000000, 0x3ccccccd, 0x00000000, 0x00000000, 0x00000000, 0x3d1eb852, 0x00000000} + {200000, 0x25c28f40, 0x00000000, 0x251eb852, 0x06775a1b, 0x25c28f40, 0x00000000, 0x24cccccd, 0x06a4175a}, + {320000, 0x25c28f40, 0x00000000, 0x3ccccccd, 0x00000000, 0x25c28f40, 0x00000000, 0x3d1eb852, 0x00000000} }; static const BITS2PE_CFG_TAB bits2PeConfigTab[] = { @@ -258,6 +258,7 @@ static void FDKaacEnc_InitBits2PeFactor( const INT nChannels, const INT sampleRate, const INT advancedBitsToPe, + const INT dZoneQuantEnable, const INT invQuant ) { @@ -329,7 +330,32 @@ static void FDKaacEnc_InitBits2PeFactor( } /* advancedBitsToPe */ - /* return bits2pe factor */ + if (dZoneQuantEnable) + { + if(bit2PE_m >= (FL2FXCONST_DBL(0.6f))>>bit2PE_e) + { + /* Additional headroom for addition */ + bit2PE_m >>= 1; + bit2PE_e += 1; + } + + /* the quantTendencyCompensator compensates a lower bit consumption due to increasing the tendency to quantize low spectral values to the lower quantizer border for bitrates below a certain bitrate threshold --> see also function calcSfbDistLD in quantize.c */ + if ((bitRate/nChannels > 32000) && (bitRate/nChannels <= 40000)) { + bit2PE_m += (FL2FXCONST_DBL(0.4f))>>bit2PE_e; + } + else if (bitRate/nChannels > 20000) { + bit2PE_m += (FL2FXCONST_DBL(0.3f))>>bit2PE_e; + } + else if (bitRate/nChannels >= 16000) { + bit2PE_m += (FL2FXCONST_DBL(0.3f))>>bit2PE_e; + } + else { + bit2PE_m += (FL2FXCONST_DBL(0.0f))>>bit2PE_e; + } + } + + + /***** 3.) Return bits2pe factor *****/ *bits2PeFactor_m = bit2PE_m; *bits2PeFactor_e = bit2PE_e; } @@ -1649,6 +1675,7 @@ static void FDKaacEnc_adaptThresholdsToPe(CHANNEL_MAPPING* cm, QC_OUT_ELEMENT* qcElement[(8)], PSY_OUT_ELEMENT* psyOutElement[(8)], const INT desiredPe, + const INT maxIter2ndGuess, const INT processElements, const INT elementOffset) { @@ -1733,7 +1760,7 @@ static void FDKaacEnc_adaptThresholdsToPe(CHANNEL_MAPPING* cm, /* Part III: Iterate until bit constraints are met */ /* -------------------------------------------------- */ iter = 0; - while ((fixp_abs(redPeGlobal - desiredPe) > fMultI(FL2FXCONST_DBL(0.05f),desiredPe)) && (iter < 1)) { + while ((fixp_abs(redPeGlobal - desiredPe) > fMultI(FL2FXCONST_DBL(0.05f),desiredPe)) && (iter < maxIter2ndGuess)) { INT desiredPeNoAHGlobal; INT redPeNoAHGlobal = 0; @@ -2225,7 +2252,8 @@ void FDKaacEnc_AdjThrInit( INT nChannelsEff, INT sampleRate, INT advancedBitsToPe, - FIXP_DBL vbrQualFactor + FIXP_DBL vbrQualFactor, + const INT dZoneQuantEnable ) { INT i; @@ -2233,6 +2261,10 @@ void FDKaacEnc_AdjThrInit( FIXP_DBL POINT8 = FL2FXCONST_DBL(0.8f); FIXP_DBL POINT6 = FL2FXCONST_DBL(0.6f); + /* Max number of iterations in second guess is 3 for lowdelay aot and for configurations with + multiple audio elements in general, otherwise iteration value is always 1. */ + hAdjThr->maxIter2ndGuess = (advancedBitsToPe!=0 || nElements>1) ? 3 : 1; + /* common for all elements: */ /* parameters for bitres control */ hAdjThr->bresParamLong.clipSaveLow = (FIXP_DBL)0x1999999a; /* FL2FXCONST_DBL(0.2f); */ @@ -2313,10 +2345,11 @@ void FDKaacEnc_AdjThrInit( FDKaacEnc_InitBits2PeFactor( &atsElem->bits2PeFactor_m, &atsElem->bits2PeFactor_e, - chBitrate, /* bitrate/channel*/ + chBitrate*nChannelsEff, /* overall bitrate */ nChannelsEff, /* number of channels */ sampleRate, advancedBitsToPe, + dZoneQuantEnable, invQuant ); @@ -2545,6 +2578,7 @@ void FDKaacEnc_AdjustThresholds(ATS_ELEMENT* AdjThrStateElement[(8)], QC_OUT* qcOut, PSY_OUT_ELEMENT* psyOutElement[(8)], INT CBRbitrateMode, + INT maxIter2ndGuess, CHANNEL_MAPPING* cm) { int i; @@ -2570,6 +2604,7 @@ void FDKaacEnc_AdjustThresholds(ATS_ELEMENT* AdjThrStateElement[(8)], qcElement, psyOutElement, qcElement[i]->grantedPeCorr, + maxIter2ndGuess, 1, /* Process only 1 element */ i); /* Process exactly THIS element */ diff --git a/libAACenc/src/adj_thr.h b/libAACenc/src/adj_thr.h index 69b1dcc..be68c6e 100644 --- a/libAACenc/src/adj_thr.h +++ b/libAACenc/src/adj_thr.h @@ -2,7 +2,7 @@ /* ----------------------------------------------------------------------------------------------------------- Software License for The Fraunhofer FDK AAC Codec Library for Android -© Copyright 1995 - 2013 Fraunhofer-Gesellschaft zur Förderung der angewandten Forschung e.V. +© Copyright 1995 - 2015 Fraunhofer-Gesellschaft zur Förderung der angewandten Forschung e.V. All rights reserved. 1. INTRODUCTION @@ -118,7 +118,8 @@ void FDKaacEnc_AdjThrInit(ADJ_THR_STATE *hAdjThr, INT nChannelsEff, INT sampleRate, INT advancedBitsToPe, - FIXP_DBL vbrQualFactor); + FIXP_DBL vbrQualFactor, + const INT dZoneQuantEnable); void FDKaacEnc_DistributeBits(ADJ_THR_STATE *adjThrState, @@ -140,6 +141,7 @@ void FDKaacEnc_AdjustThresholds(ATS_ELEMENT* AdjThrStateElement[(8)], QC_OUT* qcOut, PSY_OUT_ELEMENT* psyOutElement[(8)], INT CBRbitrateMode, + INT maxIter2ndGuess, CHANNEL_MAPPING* cm); void FDKaacEnc_AdjThrClose(ADJ_THR_STATE** hAdjThr); diff --git a/libAACenc/src/adj_thr_data.h b/libAACenc/src/adj_thr_data.h index 3eb7678..7c3a191 100644 --- a/libAACenc/src/adj_thr_data.h +++ b/libAACenc/src/adj_thr_data.h @@ -2,7 +2,7 @@ /* ----------------------------------------------------------------------------------------------------------- Software License for The Fraunhofer FDK AAC Codec Library for Android -© Copyright 1995 - 2013 Fraunhofer-Gesellschaft zur Förderung der angewandten Forschung e.V. +© Copyright 1995 - 2015 Fraunhofer-Gesellschaft zur Förderung der angewandten Forschung e.V. All rights reserved. 1. INTRODUCTION @@ -145,6 +145,7 @@ typedef struct { typedef struct { BRES_PARAM bresParamLong, bresParamShort; ATS_ELEMENT* adjThrStateElem[(8)]; + INT maxIter2ndGuess; } ADJ_THR_STATE; #endif diff --git a/libAACenc/src/bandwidth.cpp b/libAACenc/src/bandwidth.cpp index 6fc7d87..6937362 100644 --- a/libAACenc/src/bandwidth.cpp +++ b/libAACenc/src/bandwidth.cpp @@ -2,7 +2,7 @@ /* ----------------------------------------------------------------------------------------------------------- Software License for The Fraunhofer FDK AAC Codec Library for Android -© Copyright 1995 - 2013 Fraunhofer-Gesellschaft zur Förderung der angewandten Forschung e.V. +© Copyright 1995 - 2015 Fraunhofer-Gesellschaft zur Förderung der angewandten Forschung e.V. All rights reserved. 1. INTRODUCTION @@ -127,7 +127,7 @@ static const BANDWIDTH_TAB bandWidthTable_LD_24000[] = { { 8000, 2000, 2000}, {12000, 2000, 2300}, {16000, 2200, 2500}, - {24000, 5650, 6400}, + {24000, 5650, 7200}, {32000, 11600, 12000}, {40000, 12000, 16000}, {48000, 16000, 16000}, @@ -138,10 +138,10 @@ static const BANDWIDTH_TAB bandWidthTable_LD_24000[] = { static const BANDWIDTH_TAB bandWidthTable_LD_32000[] = { { 8000, 2000, 2000}, {12000, 2000, 2000}, - {24000, 4250, 5200}, + {24000, 4250, 7200}, {32000, 8400, 9000}, {40000, 9400, 11300}, - {48000, 11900, 13700}, + {48000, 11900, 14700}, {64000, 14800, 16000}, {76000, 16000, 16000}, {360001, 16000, 16000} diff --git a/libAACenc/src/pnsparam.cpp b/libAACenc/src/pnsparam.cpp index afc5bdd..9d59ddc 100644 --- a/libAACenc/src/pnsparam.cpp +++ b/libAACenc/src/pnsparam.cpp @@ -2,7 +2,7 @@ /* ----------------------------------------------------------------------------------------------------------- Software License for The Fraunhofer FDK AAC Codec Library for Android -© Copyright 1995 - 2013 Fraunhofer-Gesellschaft zur Förderung der angewandten Forschung e.V. +© Copyright 1995 - 2015 Fraunhofer-Gesellschaft zur Förderung der angewandten Forschung e.V. All rights reserved. 1. INTRODUCTION @@ -107,6 +107,7 @@ typedef struct { typedef struct { ULONG brFrom; ULONG brTo; + UCHAR S16000; UCHAR S22050; UCHAR S24000; UCHAR S32000; @@ -115,25 +116,26 @@ typedef struct { } AUTO_PNS_TAB; static const AUTO_PNS_TAB levelTable_mono[]= { - {0, 11999, 1, 1, 1, 1, 1,}, - {12000, 19999, 1, 1, 1, 1, 1,}, - {20000, 28999, 2, 1, 1, 1, 1,}, - {29000, 40999, 4, 4, 4, 2, 2,}, - {41000, 55999, 9, 9, 7, 7, 7,}, - {56000, 79999, 0, 0, 0, 9, 9,}, - {80000, 99999, 0, 0, 0, 0, 0,}, - {100000,999999, 0, 0, 0, 0, 0,}, + {0, 11999, 0, 1, 1, 1, 1, 1,}, + {12000, 19999, 0, 1, 1, 1, 1, 1,}, + {20000, 28999, 0, 2, 1, 1, 1, 1,}, + {29000, 40999, 0, 4, 4, 4, 2, 2,}, + {41000, 55999, 0, 9, 9, 7, 7, 7,}, + {56000, 61999, 0, 0, 0, 0, 9, 9,}, + {62000, 75999, 0, 0, 0, 0, 0, 0,}, + {76000, 92999, 0, 0, 0, 0, 0, 0,}, + {93000, 999999, 0, 0, 0, 0, 0, 0,}, }; static const AUTO_PNS_TAB levelTable_stereo[]= { - {0, 11999, 1, 1, 1, 1, 1,}, - {12000, 19999, 3, 1, 1, 1, 1,}, - {20000, 28999, 3, 3, 3, 2, 2,}, - {29000, 40999, 7, 6, 6, 5, 5,}, - {41000, 55999, 9, 9, 7, 7, 7,}, - {56000, 79999, 0, 0, 0, 0, 0,}, - {80000, 99999, 0, 0, 0, 0, 0,}, - {100000,999999, 0, 0, 0, 0, 0,}, + {0, 11999, 0, 1, 1, 1, 1, 1,}, + {12000, 19999, 0, 3, 1, 1, 1, 1,}, + {20000, 28999, 0, 3, 3, 3, 2, 2,}, + {29000, 40999, 0, 7, 6, 6, 5, 5,}, + {41000, 55999, 0, 9, 9, 7, 7, 7,}, + {56000, 79999, 0, 0, 0, 0, 0, 0,}, + {80000, 99999, 0, 0, 0, 0, 0, 0,}, + {100000,999999, 0, 0, 0, 0, 0, 0,}, }; @@ -160,11 +162,11 @@ static const PNS_INFO_TAB pnsInfoTab[] = { }; static const AUTO_PNS_TAB levelTable_lowComplexity[]= { - {0, 27999, 0, 0, 0, 0, 0,}, - {28000, 31999, 2, 2, 2, 2, 2,}, - {32000, 47999, 3, 3, 3, 3, 3,}, - {48000, 48000, 4, 4, 4, 4, 4,}, - {48001, 999999, 0, 0, 0, 0, 0,}, + {0, 27999, 0, 0, 0, 0, 0, 0,}, + {28000, 31999, 0, 2, 2, 2, 2, 2,}, + {32000, 47999, 0, 3, 3, 3, 3, 3,}, + {48000, 48000, 0, 4, 4, 4, 4, 4,}, + {48001, 999999, 0, 0, 0, 0, 0, 0,}, }; /* conversion of old LC tuning tables to new (LD enc) structure (only entries which are actually used were converted) */ @@ -211,6 +213,7 @@ int FDKaacEnc_lookUpPnsUse (int bitRate, int sampleRate, int numChan, const int } switch (sampleRate) { + case 16000: hUsePns = levelTable[i].S16000; break; case 22050: hUsePns = levelTable[i].S22050; break; case 24000: hUsePns = levelTable[i].S24000; break; case 32000: hUsePns = levelTable[i].S32000; break; diff --git a/libAACenc/src/psy_main.cpp b/libAACenc/src/psy_main.cpp index 3cc9438..446c894 100644 --- a/libAACenc/src/psy_main.cpp +++ b/libAACenc/src/psy_main.cpp @@ -342,6 +342,7 @@ AAC_ENCODER_ERROR FDKaacEnc_psyMainInit(PSY_INTERNAL *hPsy, tnsChannels, LONG_WINDOW, hPsy->granuleLength, + isLowDelay(audioObjectType), (syntaxFlags&AC_SBR_PRESENT)?1:0, &(hPsy->psyConf[0].tnsConf), &hPsy->psyConf[0], @@ -362,6 +363,7 @@ AAC_ENCODER_ERROR FDKaacEnc_psyMainInit(PSY_INTERNAL *hPsy, tnsChannels, SHORT_WINDOW, hPsy->granuleLength, + isLowDelay(audioObjectType), (syntaxFlags&AC_SBR_PRESENT)?1:0, &hPsy->psyConf[1].tnsConf, &hPsy->psyConf[1], @@ -763,7 +765,8 @@ AAC_ENCODER_ERROR FDKaacEnc_psyMain(INT channels, /* Advance psychoacoustics: Tonality and TNS */ if (psyStatic[0]->isLFE) { - tnsData[0]->dataRaw.Long.subBlockInfo.tnsActive = 0; + tnsData[0]->dataRaw.Long.subBlockInfo.tnsActive[HIFILT] = 0; + tnsData[0]->dataRaw.Long.subBlockInfo.tnsActive[LOFILT] = 0; } else { @@ -819,11 +822,15 @@ AAC_ENCODER_ERROR FDKaacEnc_psyMain(INT channels, for(w = 0; w < nWindows[0]; w++) { if (isShortWindow[0]) - tnsActive[w] = tnsData[0]->dataRaw.Short.subBlockInfo[w].tnsActive || - ((channels == 2) ? tnsData[1]->dataRaw.Short.subBlockInfo[w].tnsActive : 0); + tnsActive[w] = tnsData[0]->dataRaw.Short.subBlockInfo[w].tnsActive[HIFILT] || + tnsData[0]->dataRaw.Short.subBlockInfo[w].tnsActive[LOFILT] || + tnsData[channels-1]->dataRaw.Short.subBlockInfo[w].tnsActive[HIFILT] || + tnsData[channels-1]->dataRaw.Short.subBlockInfo[w].tnsActive[LOFILT]; else - tnsActive[w] = tnsData[0]->dataRaw.Long.subBlockInfo.tnsActive || - ((channels == 2) ? tnsData[1]->dataRaw.Long.subBlockInfo.tnsActive : 0); + tnsActive[w] = tnsData[0]->dataRaw.Long.subBlockInfo.tnsActive[HIFILT] || + tnsData[0]->dataRaw.Long.subBlockInfo.tnsActive[LOFILT] || + tnsData[channels-1]->dataRaw.Long.subBlockInfo.tnsActive[HIFILT] || + tnsData[channels-1]->dataRaw.Long.subBlockInfo.tnsActive[LOFILT]; } for(ch = 0; ch < channels; ch++) { @@ -1150,8 +1157,8 @@ AAC_ENCODER_ERROR FDKaacEnc_psyMain(INT channels, psyData[ch]->sfbMaxScaleSpec.Long, sfbTonality[ch], psyOutChannel[ch]->tnsInfo.order[0][0], - tnsData[ch]->dataRaw.Long.subBlockInfo.predictionGain, - tnsData[ch]->dataRaw.Long.subBlockInfo.tnsActive, + tnsData[ch]->dataRaw.Long.subBlockInfo.predictionGain[HIFILT], + tnsData[ch]->dataRaw.Long.subBlockInfo.tnsActive[HIFILT], psyOutChannel[ch]->sfbEnergyLdData, psyOutChannel[ch]->noiseNrg ); } /* !isLFE */ diff --git a/libAACenc/src/qc_data.h b/libAACenc/src/qc_data.h index a9309c8..00d6090 100644 --- a/libAACenc/src/qc_data.h +++ b/libAACenc/src/qc_data.h @@ -2,7 +2,7 @@ /* ----------------------------------------------------------------------------------------------------------- Software License for The Fraunhofer FDK AAC Codec Library for Android -© Copyright 1995 - 2013 Fraunhofer-Gesellschaft zur Förderung der angewandten Forschung e.V. +© Copyright 1995 - 2015 Fraunhofer-Gesellschaft zur Förderung der angewandten Forschung e.V. All rights reserved. 1. INTRODUCTION @@ -269,6 +269,8 @@ typedef struct BITCNTR_STATE *hBitCounter; ADJ_THR_STATE *hAdjThr; + INT dZoneQuantEnable; /* enable dead zone quantizer */ + } QC_STATE; #endif /* _QC_DATA_H */ diff --git a/libAACenc/src/qc_main.cpp b/libAACenc/src/qc_main.cpp index 7503309..9cd73f6 100644 --- a/libAACenc/src/qc_main.cpp +++ b/libAACenc/src/qc_main.cpp @@ -380,7 +380,7 @@ AAC_ENCODER_ERROR FDKaacEnc_QCInit(QC_STATE *hQC, if ( isConstantBitrateMode(hQC->bitrateMode) ) { INT bitresPerChannel = (hQC->bitResTotMax / init->channelMapping->nChannelsEff); /* 0: full bitreservoir, 1: reduced bitreservoir, 2: disabled bitreservoir */ - hQC->bitDistributionMode = (bitresPerChannel>100) ? 0 : (bitresPerChannel>0) ? 1 : 2; + hQC->bitDistributionMode = (bitresPerChannel>BITRES_MIN_LD) ? 0 : (bitresPerChannel>0) ? 1 : 2; } else { hQC->bitDistributionMode = 0; /* full bitreservoir */ @@ -405,6 +405,16 @@ AAC_ENCODER_ERROR FDKaacEnc_QCInit(QC_STATE *hQC, } } + if (init->channelMapping->nChannelsEff == 1 && + (init->bitrate / init->channelMapping->nChannelsEff) < 32000 && + init->advancedBitsToPe != 0 + ) + { + hQC->dZoneQuantEnable = 1; + } else { + hQC->dZoneQuantEnable = 0; + } + FDKaacEnc_AdjThrInit( hQC->hAdjThr, init->meanPe, @@ -414,7 +424,8 @@ AAC_ENCODER_ERROR FDKaacEnc_QCInit(QC_STATE *hQC, init->channelMapping->nChannelsEff, init->sampleRate, /* output sample rate */ init->advancedBitsToPe, /* if set, calc bits2PE factor depending on samplerate */ - hQC->vbrQualFactor + hQC->vbrQualFactor, + hQC->dZoneQuantEnable ); return AAC_ENC_OK; @@ -877,6 +888,7 @@ AAC_ENCODER_ERROR FDKaacEnc_QCMain(QC_STATE* RESTRICT hQC, qcOut[c], psyOut[c]->psyOutElement, isConstantBitrateMode(hQC->bitrateMode), + hQC->hAdjThr->maxIter2ndGuess, cm); } /* -end- sub frame counter */ @@ -904,6 +916,7 @@ AAC_ENCODER_ERROR FDKaacEnc_QCMain(QC_STATE* RESTRICT hQC, FDKaacEnc_EstimateScaleFactors(psyOut[c]->psyOutElement[i]->psyOutChannel, qcElement[c][i]->qcOutChannel, hQC->invQuant, + hQC->dZoneQuantEnable, cm->elInfo[i].nChannelsInEl); @@ -998,7 +1011,8 @@ AAC_ENCODER_ERROR FDKaacEnc_QCMain(QC_STATE* RESTRICT hQC, qcOutCh->mdctSpectrum, qcOutCh->globalGain, qcOutCh->scf, - qcOutCh->quantSpec) ; + qcOutCh->quantSpec, + hQC->dZoneQuantEnable); /*-------------------------------------------- */ if (FDKaacEnc_calcMaxValueInSfb(psyOutCh->sfbCnt, diff --git a/libAACenc/src/quantize.cpp b/libAACenc/src/quantize.cpp index 5380e35..a74da0e 100644 --- a/libAACenc/src/quantize.cpp +++ b/libAACenc/src/quantize.cpp @@ -2,7 +2,7 @@ /* ----------------------------------------------------------------------------------------------------------- Software License for The Fraunhofer FDK AAC Codec Library for Android -© Copyright 1995 - 2013 Fraunhofer-Gesellschaft zur Förderung der angewandten Forschung e.V. +© Copyright 1995 - 2015 Fraunhofer-Gesellschaft zur Förderung der angewandten Forschung e.V. All rights reserved. 1. INTRODUCTION @@ -104,13 +104,19 @@ amm-info@iis.fraunhofer.de static void FDKaacEnc_quantizeLines(INT gain, INT noOfLines, FIXP_DBL *mdctSpectrum, - SHORT *quaSpectrum) + SHORT *quaSpectrum, + INT dZoneQuantEnable) { int line; - FIXP_DBL k = FL2FXCONST_DBL(-0.0946f + 0.5f)>>16; + FIXP_DBL k = FL2FXCONST_DBL(0.0f); FIXP_QTD quantizer = FDKaacEnc_quantTableQ[(-gain)&3]; INT quantizershift = ((-gain)>>2)+1; + const INT kShift=16; + if (dZoneQuantEnable) + k = FL2FXCONST_DBL(0.23f)>>kShift; + else + k = FL2FXCONST_DBL(-0.0946f + 0.5f)>>kShift; for (line = 0; line < noOfLines; line++) { @@ -263,7 +269,8 @@ void FDKaacEnc_QuantizeSpectrum(INT sfbCnt, FIXP_DBL *mdctSpectrum, INT globalGain, INT *scalefactors, - SHORT *quantizedSpectrum) + SHORT *quantizedSpectrum, + INT dZoneQuantEnable) { INT sfbOffs,sfb; @@ -280,7 +287,8 @@ void FDKaacEnc_QuantizeSpectrum(INT sfbCnt, FDKaacEnc_quantizeLines(globalGain - scalefactor, /* QSS */ sfbOffset[sfbOffs+sfb+1] - sfbOffset[sfbOffs+sfb], mdctSpectrum + sfbOffset[sfbOffs+sfb], - quantizedSpectrum + sfbOffset[sfbOffs+sfb]); + quantizedSpectrum + sfbOffset[sfbOffs+sfb], + dZoneQuantEnable); } } @@ -296,7 +304,8 @@ void FDKaacEnc_QuantizeSpectrum(INT sfbCnt, FIXP_DBL FDKaacEnc_calcSfbDist(FIXP_DBL *mdctSpectrum, SHORT *quantSpectrum, INT noOfLines, - INT gain + INT gain, + INT dZoneQuantEnable ) { INT i,scale; @@ -311,7 +320,8 @@ FIXP_DBL FDKaacEnc_calcSfbDist(FIXP_DBL *mdctSpectrum, FDKaacEnc_quantizeLines(gain, 1, &mdctSpectrum[i], - &quantSpectrum[i]); + &quantSpectrum[i], + dZoneQuantEnable); if (fAbs(quantSpectrum[i])>MAX_QUANT) { return FL2FXCONST_DBL(0.0f); diff --git a/libAACenc/src/quantize.h b/libAACenc/src/quantize.h index 975b98e..16d3d4e 100644 --- a/libAACenc/src/quantize.h +++ b/libAACenc/src/quantize.h @@ -2,7 +2,7 @@ /* ----------------------------------------------------------------------------------------------------------- Software License for The Fraunhofer FDK AAC Codec Library for Android -© Copyright 1995 - 2013 Fraunhofer-Gesellschaft zur Förderung der angewandten Forschung e.V. +© Copyright 1995 - 2015 Fraunhofer-Gesellschaft zur Förderung der angewandten Forschung e.V. All rights reserved. 1. INTRODUCTION @@ -102,12 +102,14 @@ void FDKaacEnc_QuantizeSpectrum(INT sfbCnt, INT sfbPerGroup, INT *sfbOffset, FIXP_DBL *mdctSpectrum, INT globalGain, INT *scalefactors, - SHORT *quantizedSpectrum); + SHORT *quantizedSpectrum, + INT dZoneQuantEnable); FIXP_DBL FDKaacEnc_calcSfbDist(FIXP_DBL *mdctSpectrum, SHORT *quantSpectrum, INT noOfLines, - INT gain); + INT gain, + INT dZoneQuantEnable); void FDKaacEnc_calcSfbQuantEnergyAndDist(FIXP_DBL *mdctSpectrum, SHORT *quantSpectrum, diff --git a/libAACenc/src/sf_estim.cpp b/libAACenc/src/sf_estim.cpp index 72b75a6..1cb243b 100644 --- a/libAACenc/src/sf_estim.cpp +++ b/libAACenc/src/sf_estim.cpp @@ -2,7 +2,7 @@ /* ----------------------------------------------------------------------------------------------------------- Software License for The Fraunhofer FDK AAC Codec Library for Android -© Copyright 1995 - 2013 Fraunhofer-Gesellschaft zur Förderung der angewandten Forschung e.V. +© Copyright 1995 - 2015 Fraunhofer-Gesellschaft zur Förderung der angewandten Forschung e.V. All rights reserved. 1. INTRODUCTION @@ -363,7 +363,8 @@ static INT FDKaacEnc_improveScf(FIXP_DBL *spec, INT scf, INT minScf, FIXP_DBL *distLdData, - INT *minScfCalculated + INT *minScfCalculated, + INT dZoneQuantEnable ) { FIXP_DBL sfbDistLdData; @@ -375,7 +376,8 @@ static INT FDKaacEnc_improveScf(FIXP_DBL *spec, sfbDistLdData = FDKaacEnc_calcSfbDist(spec, quantSpec, sfbWidth, - scf); + scf, + dZoneQuantEnable); *minScfCalculated = scf; /* nmr > 1.25 -> try to improve nmr */ if (sfbDistLdData > (threshLdData-distFactorLdData)) { @@ -390,7 +392,8 @@ static INT FDKaacEnc_improveScf(FIXP_DBL *spec, sfbDistLdData = FDKaacEnc_calcSfbDist(spec, quantSpecTmp, sfbWidth, - scf); + scf, + dZoneQuantEnable); if (sfbDistLdData < sfbDistBestLdData) { scfBest = scf; @@ -408,7 +411,8 @@ static INT FDKaacEnc_improveScf(FIXP_DBL *spec, sfbDistLdData = FDKaacEnc_calcSfbDist(spec, quantSpecTmp, sfbWidth, - scf); + scf, + dZoneQuantEnable); if (sfbDistLdData < sfbDistBestLdData) { scfBest = scf; @@ -429,7 +433,8 @@ static INT FDKaacEnc_improveScf(FIXP_DBL *spec, sfbDistLdData = FDKaacEnc_calcSfbDist(spec, quantSpecTmp, sfbWidth, - scf); + scf, + dZoneQuantEnable); if (sfbDistLdData < sfbDistAllowedLdData) { *minScfCalculated = scfBest+1; @@ -454,6 +459,7 @@ static void FDKaacEnc_assimilateSingleScf(PSY_OUT_CHANNEL *psyOutChan, QC_OUT_CHANNEL *qcOutChannel, SHORT *quantSpec, SHORT *quantSpecTmp, + INT dZoneQuantEnable, INT *scf, INT *minScf, FIXP_DBL *sfbDist, @@ -570,7 +576,8 @@ static void FDKaacEnc_assimilateSingleScf(PSY_OUT_CHANNEL *psyOutChan, sfbDistNew = FDKaacEnc_calcSfbDist(qcOutChannel->mdctSpectrum+sfbOffs, quantSpecTmp+sfbOffs, sfbWidth, - scfAct); + scfAct, + dZoneQuantEnable); if (sfbDistNew < sfbDist[sfbAct]) { /* success, replace scf by new one */ @@ -629,6 +636,7 @@ static void FDKaacEnc_assimilateMultipleScf(PSY_OUT_CHANNEL *psyOutChan, QC_OUT_CHANNEL *qcOutChannel, SHORT *quantSpec, SHORT *quantSpecTmp, + INT dZoneQuantEnable, INT *scf, INT *minScf, FIXP_DBL *sfbDist, @@ -724,7 +732,8 @@ static void FDKaacEnc_assimilateMultipleScf(PSY_OUT_CHANNEL *psyOutChan, sfbDistNew[sfb] = FDKaacEnc_calcSfbDist(qcOutChannel->mdctSpectrum+sfbOffs, quantSpecTmp+sfbOffs, sfbWidth, - scfAct); + scfAct, + dZoneQuantEnable); if (sfbDistNew[sfb] >qcOutChannel->sfbThresholdLdData[sfb]) { /* no improvement, skip further dist. calculations */ @@ -768,6 +777,7 @@ static void FDKaacEnc_FDKaacEnc_assimilateMultipleScf2(PSY_OUT_CHANNEL *psyOutCh QC_OUT_CHANNEL *qcOutChannel, SHORT *quantSpec, SHORT *quantSpecTmp, + INT dZoneQuantEnable, INT *scf, INT *minScf, FIXP_DBL *sfbDist, @@ -883,7 +893,8 @@ static void FDKaacEnc_FDKaacEnc_assimilateMultipleScf2(PSY_OUT_CHANNEL *psyOutCh sfbDistNew[sfb] = FDKaacEnc_calcSfbDist(qcOutChannel->mdctSpectrum+sfbOffs[sfb], quantSpecTmp+sfbOffs[sfb], sfbOffs[sfb+1]-sfbOffs[sfb], - scfNew); + scfNew, + dZoneQuantEnable); if (sfbDistNew[sfb] > sfbDistMax[sfb]) { /* no improvement, skip further dist. calculations */ @@ -963,7 +974,8 @@ static void FDKaacEnc_FDKaacEnc_assimilateMultipleScf2(PSY_OUT_CHANNEL *psyOutCh sfbDistNew[sfb] = FDKaacEnc_calcSfbDist(qcOutChannel->mdctSpectrum+sfbOffs[sfb], quantSpecTmp+sfbOffs[sfb], sfbOffs[sfb+1]-sfbOffs[sfb], - scfNew); + scfNew, + dZoneQuantEnable); if (sfbDistNew[sfb] > qcOutChannel->sfbThresholdLdData[sfb]) { /* no improvement, skip further dist. calculations */ @@ -1058,7 +1070,8 @@ FDKaacEnc_FDKaacEnc_EstimateScaleFactorsChannel(QC_OUT_CHANNEL *qcOutChannel, INT *RESTRICT globalGain, FIXP_DBL *RESTRICT sfbFormFactorLdData ,const INT invQuant, - SHORT *RESTRICT quantSpec + SHORT *RESTRICT quantSpec, + const INT dZoneQuantEnable ) { INT i, j, sfb, sfbOffs; @@ -1160,7 +1173,8 @@ FDKaacEnc_FDKaacEnc_EstimateScaleFactorsChannel(QC_OUT_CHANNEL *qcOutChannel, quantSpecTmp+psyOutChannel->sfbOffsets[sfbOffs+sfb], psyOutChannel->sfbOffsets[sfbOffs+sfb+1]-psyOutChannel->sfbOffsets[sfbOffs+sfb], threshLdData, scfInt, minSfMaxQuant[sfbOffs+sfb], - &sfbDistLdData[sfbOffs+sfb], &minScfCalculated[sfbOffs+sfb] + &sfbDistLdData[sfbOffs+sfb], &minScfCalculated[sfbOffs+sfb], + dZoneQuantEnable ); } scf[sfbOffs+sfb] = scfInt; @@ -1187,20 +1201,32 @@ FDKaacEnc_FDKaacEnc_EstimateScaleFactorsChannel(QC_OUT_CHANNEL *qcOutChannel, sfbNRelevantLines); - FDKaacEnc_assimilateSingleScf(psyOutChannel, qcOutChannel, quantSpec, quantSpecTmp, scf, + FDKaacEnc_assimilateSingleScf(psyOutChannel, qcOutChannel, quantSpec, quantSpecTmp, + dZoneQuantEnable, + scf, minSfMaxQuant, sfbDistLdData, sfbConstPePart, sfbFormFactorLdData, sfbNRelevantLines, minScfCalculated, 1); + if(invQuant > 1) { + FDKaacEnc_assimilateMultipleScf(psyOutChannel, qcOutChannel, quantSpec, quantSpecTmp, + dZoneQuantEnable, + scf, + minSfMaxQuant, sfbDistLdData, sfbConstPePart, + sfbFormFactorLdData, sfbNRelevantLines); - FDKaacEnc_assimilateMultipleScf(psyOutChannel, qcOutChannel, quantSpec, quantSpecTmp, scf, - minSfMaxQuant, sfbDistLdData, sfbConstPePart, - sfbFormFactorLdData, sfbNRelevantLines); - + FDKaacEnc_assimilateMultipleScf(psyOutChannel, qcOutChannel, quantSpec, quantSpecTmp, + dZoneQuantEnable, + scf, + minSfMaxQuant, sfbDistLdData, sfbConstPePart, + sfbFormFactorLdData, sfbNRelevantLines); - FDKaacEnc_FDKaacEnc_assimilateMultipleScf2(psyOutChannel, qcOutChannel, quantSpec, quantSpecTmp, scf, - minSfMaxQuant, sfbDistLdData, sfbConstPePart, - sfbFormFactorLdData, sfbNRelevantLines); + FDKaacEnc_FDKaacEnc_assimilateMultipleScf2(psyOutChannel, qcOutChannel, quantSpec, quantSpecTmp, + dZoneQuantEnable, + scf, + minSfMaxQuant, sfbDistLdData, sfbConstPePart, + sfbFormFactorLdData, sfbNRelevantLines); + } } @@ -1223,7 +1249,8 @@ FDKaacEnc_FDKaacEnc_EstimateScaleFactorsChannel(QC_OUT_CHANNEL *qcOutChannel, FDKaacEnc_calcSfbDist(qcOutChannel->mdctSpectrum+psyOutChannel->sfbOffsets[sfbOffs+sfb], quantSpec+psyOutChannel->sfbOffsets[sfbOffs+sfb], psyOutChannel->sfbOffsets[sfbOffs+sfb+1]-psyOutChannel->sfbOffsets[sfbOffs+sfb], - scf[sfbOffs+sfb] + scf[sfbOffs+sfb], + dZoneQuantEnable ); } } @@ -1281,6 +1308,7 @@ void FDKaacEnc_EstimateScaleFactors(PSY_OUT_CHANNEL *psyOutChannel[], QC_OUT_CHANNEL* qcOutChannel[], const int invQuant, + const INT dZoneQuantEnable, const int nChannels) { int ch; @@ -1293,7 +1321,8 @@ FDKaacEnc_EstimateScaleFactors(PSY_OUT_CHANNEL *psyOutChannel[], &qcOutChannel[ch]->globalGain, qcOutChannel[ch]->sfbFormFactorLdData ,invQuant, - qcOutChannel[ch]->quantSpec + qcOutChannel[ch]->quantSpec, + dZoneQuantEnable ); } diff --git a/libAACenc/src/sf_estim.h b/libAACenc/src/sf_estim.h index b5ac000..ef8d366 100644 --- a/libAACenc/src/sf_estim.h +++ b/libAACenc/src/sf_estim.h @@ -2,7 +2,7 @@ /* ----------------------------------------------------------------------------------------------------------- Software License for The Fraunhofer FDK AAC Codec Library for Android -© Copyright 1995 - 2013 Fraunhofer-Gesellschaft zur Förderung der angewandten Forschung e.V. +© Copyright 1995 - 2015 Fraunhofer-Gesellschaft zur Förderung der angewandten Forschung e.V. All rights reserved. 1. INTRODUCTION @@ -110,6 +110,7 @@ void FDKaacEnc_EstimateScaleFactors(PSY_OUT_CHANNEL *psyOutChannel[], QC_OUT_CHANNEL* qcOutChannel[], const int invQuant, + const INT dZoneQuantEnable, const int nChannels); diff --git a/libAACenc/src/tns_func.h b/libAACenc/src/tns_func.h index 6ee0edb..5e5265d 100644 --- a/libAACenc/src/tns_func.h +++ b/libAACenc/src/tns_func.h @@ -2,7 +2,7 @@ /* ----------------------------------------------------------------------------------------------------------- Software License for The Fraunhofer FDK AAC Codec Library for Android -© Copyright 1995 - 2013 Fraunhofer-Gesellschaft zur Förderung der angewandten Forschung e.V. +© Copyright 1995 - 2015 Fraunhofer-Gesellschaft zur Förderung der angewandten Forschung e.V. All rights reserved. 1. INTRODUCTION @@ -100,6 +100,7 @@ AAC_ENCODER_ERROR FDKaacEnc_InitTnsConfiguration(INT bitrate, INT channels, INT blocktype, INT granuleLength, + INT isLowDelay, INT ldSbrPresent, TNS_CONFIG *tnsConfig, PSY_CONFIGURATION *psyConfig, |