From e0835d4cbde8e3b61b0c965afcd41f8f4b7ac121 Mon Sep 17 00:00:00 2001 From: "Matthias P. Braendli" Date: Tue, 1 Jun 2021 14:42:00 +0200 Subject: Update fdk to v2.0.2 --- fdk-aac/libAACenc/include/aacenc_lib.h | 90 +++++++++++++--------------------- fdk-aac/libAACenc/src/aacEnc_ram.cpp | 4 +- fdk-aac/libAACenc/src/aacEnc_ram.h | 4 +- fdk-aac/libAACenc/src/aacenc.cpp | 53 +++++++++++++++++--- fdk-aac/libAACenc/src/aacenc.h | 15 +++++- fdk-aac/libAACenc/src/aacenc_lib.cpp | 39 +++++++++++++-- fdk-aac/libAACenc/src/adj_thr.cpp | 8 --- fdk-aac/libAACenc/src/bandwidth.cpp | 12 ++--- fdk-aac/libAACenc/src/qc_main.cpp | 64 +++++++++--------------- 9 files changed, 165 insertions(+), 124 deletions(-) (limited to 'fdk-aac/libAACenc') diff --git a/fdk-aac/libAACenc/include/aacenc_lib.h b/fdk-aac/libAACenc/include/aacenc_lib.h index 231bbb4..193c6a5 100644 --- a/fdk-aac/libAACenc/include/aacenc_lib.h +++ b/fdk-aac/libAACenc/include/aacenc_lib.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 - 2019 Fraunhofer-Gesellschaft zur Förderung der angewandten Forschung e.V. All rights reserved. 1. INTRODUCTION @@ -149,12 +149,6 @@ All API header files are located in the folder /include of the release package. All header files are provided for usage in C/C++ programs. The AAC encoder library API functions are located in aacenc_lib.h. -In binary releases the encoder core resides in statically linkable libraries -called for example libAACenc.a/libFDK.a (LINUX) or FDK_fastaaclib.lib (MS Visual -C++) for the plain AAC-LC core encoder and libSBRenc.a (LINUX) or -FDK_sbrEncLib.lib (MS Visual C++) for the SBR (Spectral Band Replication) and PS -(Parametric Stereo) modules. - \section CallingSequence Calling Sequence For encoding of ISO/MPEG-2/4 AAC bitstreams the following sequence is mandatory. @@ -326,25 +320,19 @@ input buffer, simulating a modulo buffer: \code if (outargs.numInSamples>0) { \endcode \section writeOutData Output Bitstream Data -If any AAC bitstream data is available, write it to output file or device. This -can be done once the following condition is true: \code if -(outargs.numOutBytes>0) { - +If any AAC bitstream data is available, write it to output file or device as +follows. \code if (outargs.numOutBytes>0) { FDKfwrite(outputBuffer, +outargs.numOutBytes, 1, pOutFile); } \endcode -If you use file I/O then for example call mpegFileWrite_Write() from the library -libMpegFileWrite \code mpegFileWrite_Write(hMpegFile, outputBuffer, -outargs.numOutBytes, aacEncoder_GetParam(hAacEncoder, AACENC_GRANULE_LENGTH)); -\endcode - \section cfgMetaData Meta Data Configuration If the present library is configured with Metadata support, it is possible to insert meta data side info into the generated audio bitstream while encoding. To work with meta data the encoder instance has to be \ref encOpen "allocated" -with meta data support. The meta data mode must be be configured with the +with meta data support. The meta data mode must be configured with the ::AACENC_METADATA_MODE parameter and aacEncoder_SetParam() function. \code aacEncoder_SetParam(hAacEncoder, AACENC_METADATA_MODE, 0-3); \endcode @@ -427,7 +415,7 @@ switch (nChannels) { return chMode; \endcode -\subsection bitreservoir Bitreservoir Configuration +\subsection peakbitrate Peak Bitrate Configuration In AAC, the default bitreservoir configuration depends on the chosen bitrate per frame and the number of effective channels. The size can be determined as below. \f[ @@ -436,17 +424,10 @@ bitreservoir = nEffChannels*6144 - (bitrate*framelength/samplerate) Due to audio quality concerns it is not recommended to change the bitreservoir size to a lower value than the default setting! However, for minimizing the delay for streaming applications or for achieving a constant size of the -bitstream packages in each frame, it may be necessaray to change the -bitreservoir size. This can be done with the ::AACENC_PEAK_BITRATE parameter. -\code +bitstream packages in each frame, it may be necessaray to limit the maximum bits +per frame size. This can be done with the ::AACENC_PEAK_BITRATE parameter. \code aacEncoder_SetParam(hAacEncoder, AACENC_PEAK_BITRATE, value); \endcode -By setting ::AACENC_BITRATEMODE to fixed framing, the bitreservoir is disabled. -A disabled bitreservoir results in a constant size for each bitstream package. -Please note that especially at lower bitrates a disabled bitreservoir can -downgrade the audio quality considerably! The default bitreservoir configuration -can be achieved as follows. \code aacEncoder_SetParam(hAacEncoder, -AACENC_BITRESERVOIR, -1); \endcode To achieve acceptable audio quality with a reduced bitreservoir size setting at least 1000 bits per audio channel is recommended. For a multichannel audio file @@ -455,31 +436,32 @@ audio quality. \subsection vbrmode Variable Bitrate Mode -The encoder provides various Variable Bitrate Modes that differ in audio quality -and average overall bitrate. The given values are averages over time, different -encoder settings and strongly depend on the type of audio signal. The VBR -configurations can be adjusted via ::AACENC_BITRATEMODE encoder parameter. +The variable bitrate (VBR) mode coding adapts the bit consumption to the +psychoacoustic requirements of the signal. The encoder ignores the user-defined +bit rate and selects a suitable pre-defined configuration based on the provided +AOT. The VBR mode 1 is tuned for HE-AACv2, for VBR mode 2, HE-AACv1 should be +used. VBR modes 3-5 should be used with Low-Complexity AAC. When encoding +AAC-ELD, the best mode is selected automatically. + +The bitrates given in the table are averages over time and different encoder +settings. They strongly depend on the type of audio signal. The VBR +configurations can be adjusted with the ::AACENC_BITRATEMODE encoder parameter. \verbatim --------------------------------------------- - VBR_MODE | Approx. Bitrate in kbps/channel - | AAC-LC | AAC-LD/AC_ELD -----------+---------------+----------------- - VBR_1 | 32 - 48 | 32 - 56 - VBR_2 | 40 - 56 | 40 - 64 - VBR_3 | 48 - 64 | 48 - 72 - VBR_4 | 64 - 80 | 64 - 88 - VBR_5 | 96 - 120 | 112 - 144 +----------------------------------------------- + VBR_MODE | Approx. Bitrate in kbps for stereo + | AAC-LC | AAC-ELD +----------+---------------+-------------------- + VBR_1 | 32 (HE-AACv2) | 48 + VBR_2 | 72 (HE-AACv1) | 56 + VBR_3 | 112 | 72 + VBR_4 | 148 | 148 + VBR_5 | 228 | 224 -------------------------------------------- \endverbatim -The bitrate ranges apply for individual audio channels. In case of multichannel -configurations the average bitrate might be estimated by multiplying with the -number of effective channels. This corresponds to all audio input channels -exclusively the low frequency channel. At configurations which are making use of -downmix modules the AAC core channels respectively downmix channels shall be -considered. For ::AACENC_AOT which are using SBR, the average bitrate can be -estimated by using the ratio of 0.5 for dualrate SBR and 0.75 for downsampled -SBR configurations. - +Note that these figures are valid for stereo encoding only. VBR modes 2-5 will +yield much lower bit rates when encoding single-channel input. For +configurations which are making use of downmix modules the AAC core channels +respectively downmix channels shall be considered. \subsection encQual Audio Quality Considerations The default encoder configuration is suggested to be used. Encoder tools such as @@ -967,9 +949,7 @@ in this Fraunhofer IIS AAC encoder. AAC has been designed in that way. \subsection BEHAVIOUR_ESTIM_AVG_FRAMESIZES Estimating Average Frame Sizes -A HE-AAC v1 or v2 audio frame contains 2048 PCM samples per channel (there is -also one mode with 1920 samples per channel but this is only for special -purposes such as DAB+ digital radio). +A HE-AAC v1 or v2 audio frame contains 2048 PCM samples per channel. The number of HE-AAC frames \f$N\_FRAMES\f$ per second at 44.1 kHz is: @@ -1027,7 +1007,7 @@ internally. #define AACENCODER_LIB_VL0 4 #define AACENCODER_LIB_VL1 0 -#define AACENCODER_LIB_VL2 0 +#define AACENCODER_LIB_VL2 1 /** * AAC encoder error codes. @@ -1086,9 +1066,7 @@ typedef struct AACENCODER *HANDLE_AACENCODER; typedef struct { UINT maxOutBufBytes; /*!< Maximum number of encoder bitstream bytes within one frame. Size depends on maximum number of supported - channels in encoder instance. For superframing (as - used for example in DAB+), size has to be a multiple - accordingly. */ + channels in encoder instance. */ UINT maxAncBytes; /*!< Maximum number of ancillary data bytes which can be inserted into bitstream within one frame. */ diff --git a/fdk-aac/libAACenc/src/aacEnc_ram.cpp b/fdk-aac/libAACenc/src/aacEnc_ram.cpp index 77b1131..25e2aec 100644 --- a/fdk-aac/libAACenc/src/aacEnc_ram.cpp +++ b/fdk-aac/libAACenc/src/aacEnc_ram.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 @@ -204,5 +204,5 @@ QC_OUT_CHANNEL *GetRam_aacEnc_QCchannel(int n, UCHAR *dynamic_RAM) { * (dynamic_RAM + P_BUF_0 + n*sizeof(QC_OUT_CHANNEL)) is sufficiently aligned, * so the cast is safe */ return reinterpret_cast(reinterpret_cast( - dynamic_RAM + P_BUF_0 + n * sizeof(QC_OUT_CHANNEL))); + dynamic_RAM + P_BUF_0 + n * ALIGN_SIZE(sizeof(QC_OUT_CHANNEL)))); } diff --git a/fdk-aac/libAACenc/src/aacEnc_ram.h b/fdk-aac/libAACenc/src/aacEnc_ram.h index 0775aae..f24eef1 100644 --- a/fdk-aac/libAACenc/src/aacEnc_ram.h +++ b/fdk-aac/libAACenc/src/aacEnc_ram.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 - 2019 Fraunhofer-Gesellschaft zur Förderung der angewandten Forschung e.V. All rights reserved. 1. INTRODUCTION @@ -198,7 +198,7 @@ struct AAC_ENC { +++++++++++++++++++++++++++++++++++++++++++++++++++++ */ -#define BUF_SIZE_0 (ALIGN_SIZE(sizeof(QC_OUT_CHANNEL) * (8))) +#define BUF_SIZE_0 (ALIGN_SIZE(sizeof(QC_OUT_CHANNEL)) * (8)) #define BUF_SIZE_1 \ (ALIGN_SIZE(maxSize(maxSize(sizeof(PSY_DYNAMIC), \ (BIT_LOOK_UP_SIZE + MERGE_GAIN_LOOK_UP_SIZE)), \ diff --git a/fdk-aac/libAACenc/src/aacenc.cpp b/fdk-aac/libAACenc/src/aacenc.cpp index 372df31..42755ab 100644 --- a/fdk-aac/libAACenc/src/aacenc.cpp +++ b/fdk-aac/libAACenc/src/aacenc.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 @@ -114,6 +114,8 @@ amm-info@iis.fraunhofer.de #include "genericStds.h" +#define BITRES_MIN \ + 300 /* default threshold for using reduced/disabled bitres mode */ #define BITRES_MAX_LD 4000 #define BITRES_MIN_LD 500 #define BITRATE_MAX_LD 70000 /* Max assumed bitrate for bitres calculation */ @@ -244,6 +246,46 @@ INT FDKaacEnc_GetVBRBitrate(AACENC_BITRATE_MODE bitrateMode, return bitrate; } +/*----------------------------------------------------------------------------- + + functionname: FDKaacEnc_AdjustVBRBitrateMode + description: Adjust bitrate mode to given bitrate parameter + input params: int vbrQuality (VBR0, VBR1, VBR2) + bitrate + channelMode + returns: vbr bitrate mode + + ------------------------------------------------------------------------------*/ +AACENC_BITRATE_MODE FDKaacEnc_AdjustVBRBitrateMode( + AACENC_BITRATE_MODE bitrateMode, INT bitrate, CHANNEL_MODE channelMode) { + AACENC_BITRATE_MODE newBitrateMode = bitrateMode; + + if (bitrate != -1) { + const INT monoStereoMode = + (FDKaacEnc_GetMonoStereoMode(channelMode) == EL_MODE_STEREO) ? 1 : 0; + const INT nChannelsEff = + FDKaacEnc_GetChannelModeConfiguration(channelMode)->nChannelsEff; + newBitrateMode = AACENC_BR_MODE_INVALID; + + for (int idx = (int)(sizeof(configTabVBR) / sizeof(*configTabVBR)) - 1; + idx >= 0; idx--) { + if (bitrate >= + configTabVBR[idx].chanBitrate[monoStereoMode] * nChannelsEff) { + if (configTabVBR[idx].chanBitrate[monoStereoMode] * nChannelsEff < + FDKaacEnc_GetVBRBitrate(bitrateMode, channelMode)) { + newBitrateMode = configTabVBR[idx].bitrateMode; + } else { + newBitrateMode = bitrateMode; + } + break; + } + } + } + + return AACENC_BR_MODE_IS_VBR(newBitrateMode) ? newBitrateMode + : AACENC_BR_MODE_INVALID; +} + /** * \brief Convert encoder bitreservoir value for transport library. * @@ -396,7 +438,6 @@ AAC_ENCODER_ERROR FDKaacEnc_Initialize( FIXP_DBL mbfac, bw_ratio; QC_INIT qcInit; INT averageBitsPerFrame = 0; - int bitresMin = 0; /* the bitreservoir is always big for AAC-LC */ const CHANNEL_MODE prevChannelMode = hAacEnc->encoderMode; if (config == NULL) return AAC_ENC_INVALID_HANDLE; @@ -582,7 +623,7 @@ AAC_ENCODER_ERROR FDKaacEnc_Initialize( (config->minBitsPerFrame != -1) ? config->minBitsPerFrame : 0; qcInit.minBits = fixMin(qcInit.minBits, averageBitsPerFrame & ~7); } else { - INT bitreservoir = -1; /* default bitrservoir size*/ + INT bitreservoir = -1; /* default bitreservoir size*/ if (isLowDelay(config->audioObjectType)) { INT brPerChannel = config->bitRate / config->nChannels; brPerChannel = fMin(BITRATE_MAX_LD, fMax(BITRATE_MIN_LD, brPerChannel)); @@ -596,7 +637,6 @@ AAC_ENCODER_ERROR FDKaacEnc_Initialize( bitreservoir = fMultI(slope, (INT)(BITRES_MAX_LD - BITRES_MIN_LD)) + BITRES_MIN_LD; /* interpolate */ bitreservoir = bitreservoir & ~7; /* align to bytes */ - bitresMin = BITRES_MIN_LD; } int maxBitres; @@ -633,9 +673,10 @@ AAC_ENCODER_ERROR FDKaacEnc_Initialize( qcInit.nSubFrames = config->nSubFrames; qcInit.padding.paddingRest = config->sampleRate; - if (qcInit.bitRes >= bitresMin * config->nChannels) { + if (qcInit.maxBits - qcInit.averageBits >= + ((qcInit.isLowDelay) ? BITRES_MIN_LD : BITRES_MIN) * config->nChannels) { qcInit.bitResMode = AACENC_BR_MODE_FULL; /* full bitreservoir */ - } else if (qcInit.bitRes > 0) { + } else if (qcInit.maxBits > qcInit.averageBits) { qcInit.bitResMode = AACENC_BR_MODE_REDUCED; /* reduced bitreservoir */ } else { qcInit.bitResMode = AACENC_BR_MODE_DISABLED; /* disabled bitreservoir */ diff --git a/fdk-aac/libAACenc/src/aacenc.h b/fdk-aac/libAACenc/src/aacenc.h index 291ea54..2d95abb 100644 --- a/fdk-aac/libAACenc/src/aacenc.h +++ b/fdk-aac/libAACenc/src/aacenc.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 @@ -334,6 +334,19 @@ INT FDKaacEnc_GetBitReservoirState(const HANDLE_AAC_ENC hAacEncoder); INT FDKaacEnc_GetVBRBitrate(AACENC_BITRATE_MODE bitrateMode, CHANNEL_MODE channelMode); +/*----------------------------------------------------------------------------- + + functionname: FDKaacEnc_AdjustVBRBitrateMode + description: Adjust bitrate mode to given bitrate parameter + input params: int vbrQuality (VBR0, VBR1, VBR2) + bitrate + channelMode + returns: vbr bitrate mode + + ------------------------------------------------------------------------------*/ +AACENC_BITRATE_MODE FDKaacEnc_AdjustVBRBitrateMode( + AACENC_BITRATE_MODE bitrateMode, INT bitrate, CHANNEL_MODE channelMode); + /*----------------------------------------------------------------------------- functionname: FDKaacEnc_AacInitDefaultConfig diff --git a/fdk-aac/libAACenc/src/aacenc_lib.cpp b/fdk-aac/libAACenc/src/aacenc_lib.cpp index 4eaa662..fbaf407 100644 --- a/fdk-aac/libAACenc/src/aacenc_lib.cpp +++ b/fdk-aac/libAACenc/src/aacenc_lib.cpp @@ -110,9 +110,9 @@ amm-info@iis.fraunhofer.de /* Encoder library info */ #define AACENCODER_LIB_VL0 4 #define AACENCODER_LIB_VL1 0 -#define AACENCODER_LIB_VL2 0 +#define AACENCODER_LIB_VL2 1 #define AACENCODER_LIB_TITLE "AAC Encoder" -#ifdef __ANDROID__ +#ifdef SUPPRESS_BUILD_DATE_INFO #define AACENCODER_LIB_BUILD_DATE "" #define AACENCODER_LIB_BUILD_TIME "" #else @@ -451,6 +451,24 @@ static SBR_PS_SIGNALING getSbrSignalingMode( return sbrSignaling; } +static inline INT getAssociatedChElement(SBR_ELEMENT_INFO *elInfoSbr, + CHANNEL_MAPPING *channelMapping) { + ELEMENT_INFO *elInfo = channelMapping->elInfo; + INT nElements = channelMapping->nElements; + INT associatedChElement = -1; + int i; + + for (i = 0; i < nElements; i++) { + if (elInfoSbr->elType == elInfo[i].elType && + elInfoSbr->instanceTag == elInfo[i].instanceTag) { + associatedChElement = i; + break; + } + } + + return associatedChElement; +} + /**************************************************************************** Allocate Encoder ****************************************************************************/ @@ -1055,6 +1073,13 @@ static AACENC_ERROR FDKaacEnc_AdjustEncSettings(HANDLE_AACENCODER hAacEncoder, case AACENC_BR_MODE_VBR_3: case AACENC_BR_MODE_VBR_4: case AACENC_BR_MODE_VBR_5: + /* Adjust bitrate mode in case given peak bitrate is lower than expected + * VBR bitrate. */ + if ((INT)config->userPeakBitrate != -1) { + hAacConfig->bitrateMode = FDKaacEnc_AdjustVBRBitrateMode( + hAacConfig->bitrateMode, config->userPeakBitrate, + hAacConfig->channelMode); + } /* Get bitrate in VBR configuration */ /* In VBR mode; SBR-modul depends on bitrate, core encoder on bitrateMode. */ @@ -1982,7 +2007,15 @@ AACENC_ERROR aacEncEncode(const HANDLE_AACENCODER hAacEncoder, { hAacEncoder->extPayload[nExtensions].dataSize = hAacEncoder->pSbrPayload->dataSize[nPayload][i]; - hAacEncoder->extPayload[nExtensions].associatedChElement = i; + hAacEncoder->extPayload[nExtensions].associatedChElement = + getAssociatedChElement( + &hAacEncoder->hEnvEnc->sbrElement[i]->elInfo, + &hAacEncoder->hAacEnc->channelMapping); + if (hAacEncoder->extPayload[nExtensions].associatedChElement == + -1) { + err = AACENC_ENCODE_ERROR; + goto bail; + } } hAacEncoder->extPayload[nExtensions].dataType = EXT_SBR_DATA; /* Once SBR Encoder supports SBR CRC set diff --git a/fdk-aac/libAACenc/src/adj_thr.cpp b/fdk-aac/libAACenc/src/adj_thr.cpp index 226d003..239abd0 100644 --- a/fdk-aac/libAACenc/src/adj_thr.cpp +++ b/fdk-aac/libAACenc/src/adj_thr.cpp @@ -1302,14 +1302,6 @@ static void FDKaacEnc_reduceThresholdsVBR( if (sfbThrReducedLdData < FL2FXCONST_DBL(-0.5f)) sfbThrReducedLdData = FL2FXCONST_DBL(-1.f); - /* minimum of 29 dB Ratio for Thresholds */ - if ((sfbEnLdData + FL2FXCONST_DBL(1.0f)) > - FL2FXCONST_DBL(9.6336206 / LD_DATA_SCALING)) { - sfbThrReducedLdData = fixMax( - sfbThrReducedLdData, - sfbEnLdData - FL2FXCONST_DBL(9.6336206 / LD_DATA_SCALING)); - } - sfbThrReducedLdData = fixMax(MIN_LDTHRESH, sfbThrReducedLdData); qcOutChan->sfbThresholdLdData[sfbGrp + sfb] = sfbThrReducedLdData; diff --git a/fdk-aac/libAACenc/src/bandwidth.cpp b/fdk-aac/libAACenc/src/bandwidth.cpp index 36cd64d..e814f05 100644 --- a/fdk-aac/libAACenc/src/bandwidth.cpp +++ b/fdk-aac/libAACenc/src/bandwidth.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 @@ -151,11 +151,11 @@ typedef struct { static const BANDWIDTH_TAB_VBR bandWidthTableVBR[] = { {AACENC_BR_MODE_CBR, 0, 0}, - {AACENC_BR_MODE_VBR_1, 13050, 13050}, - {AACENC_BR_MODE_VBR_2, 13050, 13050}, - {AACENC_BR_MODE_VBR_3, 14260, 14260}, - {AACENC_BR_MODE_VBR_4, 15500, 15500}, - {AACENC_BR_MODE_VBR_5, 48000, 48000}, + {AACENC_BR_MODE_VBR_1, 13000, 13000}, + {AACENC_BR_MODE_VBR_2, 13000, 13000}, + {AACENC_BR_MODE_VBR_3, 15750, 15750}, + {AACENC_BR_MODE_VBR_4, 16500, 16500}, + {AACENC_BR_MODE_VBR_5, 19293, 19293}, {AACENC_BR_MODE_SFR, 0, 0}, {AACENC_BR_MODE_FF, 0, 0} diff --git a/fdk-aac/libAACenc/src/qc_main.cpp b/fdk-aac/libAACenc/src/qc_main.cpp index 0bf234c..b4c38af 100644 --- a/fdk-aac/libAACenc/src/qc_main.cpp +++ b/fdk-aac/libAACenc/src/qc_main.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 @@ -121,20 +121,15 @@ typedef struct { static const TAB_VBR_QUAL_FACTOR tableVbrQualFactor[] = { {QCDATA_BR_MODE_VBR_1, - FL2FXCONST_DBL(0.160f)}, /* Approx. 32 - 48 (AC-LC), 32 - 56 - (AAC-LD/ELD) kbps/channel */ + FL2FXCONST_DBL(0.150f)}, /* Approx. 32 kbps mono AAC-LC + SBR + PS */ {QCDATA_BR_MODE_VBR_2, - FL2FXCONST_DBL(0.148f)}, /* Approx. 40 - 56 (AC-LC), 40 - 64 - (AAC-LD/ELD) kbps/channel */ + FL2FXCONST_DBL(0.162f)}, /* Approx. 64 kbps stereo AAC-LC + SBR */ {QCDATA_BR_MODE_VBR_3, - FL2FXCONST_DBL(0.135f)}, /* Approx. 48 - 64 (AC-LC), 48 - 72 - (AAC-LD/ELD) kbps/channel */ + FL2FXCONST_DBL(0.176f)}, /* Approx. 96 kbps stereo AAC-LC */ {QCDATA_BR_MODE_VBR_4, - FL2FXCONST_DBL(0.111f)}, /* Approx. 64 - 80 (AC-LC), 64 - 88 - (AAC-LD/ELD) kbps/channel */ + FL2FXCONST_DBL(0.120f)}, /* Approx. 128 kbps stereo AAC-LC */ {QCDATA_BR_MODE_VBR_5, - FL2FXCONST_DBL(0.070f)} /* Approx. 96 - 120 (AC-LC), 112 - 144 - (AAC-LD/ELD) kbps/channel */ + FL2FXCONST_DBL(0.070f)} /* Approx. 192 kbps stereo AAC-LC */ }; static INT isConstantBitrateMode(const QCDATA_BR_MODE bitrateMode) { @@ -378,13 +373,8 @@ AAC_ENCODER_ERROR FDKaacEnc_QCInit(QC_STATE* hQC, struct QC_INIT* init, hQC->invQuant = init->invQuant; hQC->maxIterations = init->maxIterations; - if (isConstantBitrateMode(hQC->bitrateMode)) { - /* 0: full bitreservoir, 1: reduced bitreservoir, 2: disabled bitreservoir - */ - hQC->bitResMode = init->bitResMode; - } else { - hQC->bitResMode = AACENC_BR_MODE_FULL; /* full bitreservoir */ - } + /* 0: full bitreservoir, 1: reduced bitreservoir, 2: disabled bitreservoir */ + hQC->bitResMode = init->bitResMode; hQC->padding.paddingRest = init->padding.paddingRest; @@ -806,10 +796,15 @@ AAC_ENCODER_ERROR FDKaacEnc_QCMain(QC_STATE* RESTRICT hQC, PSY_OUT** psyOut, INT avgTotalDynBits = 0; /* maximal allowed dynamic bits for all frames */ INT totalAvailableBits = 0; INT nSubFrames = 1; + const INT isCBRAdjustment = (isConstantBitrateMode(hQC->bitrateMode) || + (hQC->bitResMode != AACENC_BR_MODE_FULL)) + ? 1 + : 0; /*-------------------------------------------- */ /* redistribute total bitreservoir to elements */ - ErrorStatus = FDKaacEnc_BitResRedistribution(hQC, cm, avgTotalBits); + ErrorStatus = FDKaacEnc_BitResRedistribution( + hQC, cm, (isCBRAdjustment == 0) ? hQC->maxBitsPerFrame : avgTotalBits); if (ErrorStatus != AAC_ENC_OK) { return ErrorStatus; } @@ -837,33 +832,22 @@ AAC_ENCODER_ERROR FDKaacEnc_QCMain(QC_STATE* RESTRICT hQC, PSY_OUT** psyOut, /*-------------------------------------------- */ /*-------------------------------------------- */ - if (isConstantBitrateMode(hQC->bitrateMode)) { - /* calc granted dynamic bits for sub frame and - distribute it to each element */ - ErrorStatus = FDKaacEnc_prepareBitDistribution( - hQC, psyOut, qcOut, cm, qcElement, avgTotalBits, &totalAvailableBits, - &avgTotalDynBits); - - if (ErrorStatus != AAC_ENC_OK) { - return ErrorStatus; - } - } else { - qcOut[0]->grantedDynBits = - ((hQC->maxBitsPerFrame - (hQC->globHdrBits)) & ~7) - - (qcOut[0]->globalExtBits + qcOut[0]->staticBits + - qcOut[0]->elementExtBits); - qcOut[0]->maxDynBits = qcOut[0]->grantedDynBits; - - totalAvailableBits = hQC->maxBitsPerFrame; - avgTotalDynBits = 0; + /* calc granted dynamic bits for sub frame and + distribute it to each element */ + ErrorStatus = FDKaacEnc_prepareBitDistribution( + hQC, psyOut, qcOut, cm, qcElement, + (isCBRAdjustment == 0) ? hQC->maxBitsPerFrame : avgTotalBits, + &totalAvailableBits, &avgTotalDynBits); + + if (ErrorStatus != AAC_ENC_OK) { + return ErrorStatus; } /* for ( all sub frames ) ... */ for (c = 0; c < nSubFrames; c++) { /* for CBR and VBR mode */ FDKaacEnc_AdjustThresholds(hQC->hAdjThr, qcElement[c], qcOut[c], - psyOut[c]->psyOutElement, - isConstantBitrateMode(hQC->bitrateMode), cm); + psyOut[c]->psyOutElement, isCBRAdjustment, cm); } /* -end- sub frame counter */ -- cgit v1.2.3