diff options
author | Jean-Michel Trivi <jmtrivi@google.com> | 2016-04-04 16:06:48 -0700 |
---|---|---|
committer | Jean-Michel Trivi <jmtrivi@google.com> | 2016-04-04 17:25:36 -0700 |
commit | e1c78ed73faa51f2c7fcb0c4a17a92be9cc747f5 (patch) | |
tree | a8dc54ef8dba931c72627e7bbebf1844b81a31f7 /libAACenc/src | |
parent | ef30836651bf059c3120c03dd11e08b6aafdae13 (diff) | |
download | fdk-aac-e1c78ed73faa51f2c7fcb0c4a17a92be9cc747f5.tar.gz fdk-aac-e1c78ed73faa51f2c7fcb0c4a17a92be9cc747f5.tar.bz2 fdk-aac-e1c78ed73faa51f2c7fcb0c4a17a92be9cc747f5.zip |
SBR/AAC encoder updates, code clean up
* SBR-Encoder
- Prevent noise level overflow in noise floor detection.
- Saturate threshold calculation in transient detection.
Modified file(s):
libSBRenc/src/nf_est.cpp
libSBRenc/src/sbr_encoder.cpp
libSBRenc/src/tran_det.cpp
* AAC-Encoder
- Expand input data range of GetInvInt() function. There was an encoder
assert observed in non-default bitrate configuration.
Modified file(s):
libAACenc/src/aacenc_lib.cpp
libAACenc/src/intensity.cpp
libFDK/include/fixpoint_math.h
libFDK/src/FDK_core.cpp
libFDK/src/FDK_tools_rom.cpp
- Make sure that the encoder is stable with regard to very low audio bandwidth
confguration parameter value.
- Fix lowdelay blending for low audio bandwidth.
Modified file(s):
libAACenc/src/aacenc.cpp
libAACenc/src/aacenc_lib.cpp
libAACenc/src/adj_thr.cpp
libAACenc/src/psy_configuration.cpp
libAACenc/src/psy_main.cpp
- Disable pseudo surround flag in case metadata matrix mixdown index is
present in program config element.
Modified file(s):
libAACenc/src/aacenc_lib.cpp
- Enable variable bitrate mode in encoder api.
- Add AACENC_PEAK_BITRATE parameter to encoder api.
- Add AACENC_AUDIOMUXVER parameter to encoder api.
Modified file(s):
libAACenc/include/aacenc_lib.h
libAACenc/src/aacenc.cpp
libAACenc/src/aacenc.h
libAACenc/src/aacenc_lib.cpp
libAACenc/src/qc_main.cpp
libMpegTPEnc/src/tpenc_latm.cpp
libMpegTPEnc/src/version
* FDK-Sources
- Code clean up. Remove unneeded pseudo audio object types and transport types.
Modified file(s):
libAACdec/src/aacdecoder.cpp
libAACdec/src/aacdecoder_lib.cpp
libAACenc/include/aacenc_lib.h
libAACenc/src/aacenc.cpp
libAACenc/src/aacenc_lib.cpp
libFDK/src/FDK_tools_rom.cpp
libMpegTPDec/src/tpdec_lib.cpp
libMpegTPDec/src/version
libMpegTPEnc/src/tpenc_latm.cpp
libMpegTPEnc/src/version
libSBRdec/src/sbrdecoder.cpp
libSBRenc/src/sbr_encoder.cpp
libSYS/include/FDK_audio.h
libSYS/src/genericStds.cpp
Change-Id: I807a53cb7f48c9ee7563cb8da1d0c52221576ca6
Diffstat (limited to 'libAACenc/src')
-rw-r--r-- | libAACenc/src/aacenc.cpp | 83 | ||||
-rw-r--r-- | libAACenc/src/aacenc.h | 34 | ||||
-rw-r--r-- | libAACenc/src/aacenc_lib.cpp | 101 | ||||
-rw-r--r-- | libAACenc/src/adj_thr.cpp | 2 | ||||
-rw-r--r-- | libAACenc/src/intensity.cpp | 3 | ||||
-rw-r--r-- | libAACenc/src/psy_configuration.cpp | 5 | ||||
-rw-r--r-- | libAACenc/src/psy_main.cpp | 2 | ||||
-rw-r--r-- | libAACenc/src/qc_main.cpp | 4 |
8 files changed, 151 insertions, 83 deletions
diff --git a/libAACenc/src/aacenc.cpp b/libAACenc/src/aacenc.cpp index c47e882..5e8c08d 100644 --- a/libAACenc/src/aacenc.cpp +++ b/libAACenc/src/aacenc.cpp @@ -107,6 +107,39 @@ amm-info@iis.fraunhofer.de #define MIN_BUFSIZE_PER_EFF_CHAN 6144 +INT FDKaacEnc_CalcBitsPerFrame( + const INT bitRate, + const INT frameLength, + const INT samplingRate + ) +{ + int shift = 0; + while ((frameLength & ~((1 << (shift + 1)) - 1)) == frameLength + && (samplingRate & ~((1 << (shift + 1)) - 1)) == samplingRate) + { + shift++; + } + + return (bitRate*(frameLength>>shift)) / (samplingRate>>shift); +} + +INT FDKaacEnc_CalcBitrate( + const INT bitsPerFrame, + const INT frameLength, + const INT samplingRate + ) +{ + int shift = 0; + while ((frameLength & ~((1 << (shift + 1)) - 1)) == frameLength + && (samplingRate & ~((1 << (shift + 1)) - 1)) == samplingRate) + { + shift++; + } + + return (bitsPerFrame * (samplingRate>>shift)) / ( frameLength>>shift) ; + +} + static AAC_ENCODER_ERROR FDKaacEnc_InitCheckAncillary(INT bitRate, INT framelength, INT ancillaryRate, @@ -220,21 +253,19 @@ INT FDKaacEnc_GetVBRBitrate(INT bitrateMode, CHANNEL_MODE channelMode) /** * \brief Convert encoder bitreservoir value for transport library. * - * \param bitrateMode Bitratemode used in current encoder instance. Se ::AACENC_BITRATE_MODE - * \param bitresTotal Encoder bitreservoir level in bits. + * \param hAacEnc Encoder handle * * \return Corrected bitreservoir level used in transport library. */ static INT FDKaacEnc_EncBitresToTpBitres( - const AACENC_BITRATE_MODE bitrateMode, - const INT bitresTotal + const HANDLE_AAC_ENC hAacEnc ) { INT transporBitreservoir = 0; - switch (bitrateMode) { + switch (hAacEnc->bitrateMode) { case AACENC_BR_MODE_CBR: - transporBitreservoir = bitresTotal; /* encoder bitreservoir level */ + transporBitreservoir = hAacEnc->qcKernel->bitResTot; /* encoder bitreservoir level */ break; case AACENC_BR_MODE_VBR_1: case AACENC_BR_MODE_VBR_2: @@ -253,6 +284,10 @@ static INT FDKaacEnc_EncBitresToTpBitres( FDK_ASSERT(0); } + if (hAacEnc->config->audioMuxVersion==2) { + transporBitreservoir = MIN_BUFSIZE_PER_EFF_CHAN * hAacEnc->channelMapping.nChannelsEff; + } + return transporBitreservoir; } @@ -289,6 +324,7 @@ void FDKaacEnc_AacInitDefaultConfig(AACENC_CONFIG *config) config->minBitsPerFrame = -1; /* minum number of bits in each AU */ config->maxBitsPerFrame = -1; /* minum number of bits in each AU */ config->bitreservoir = -1; /* default, uninitialized value */ + config->audioMuxVersion = -1; /* audio mux version not configured */ /* init tabs in fixpoint_math */ InitLdInt(); @@ -564,7 +600,10 @@ AAC_ENCODER_ERROR FDKaacEnc_Initialize(HANDLE_AAC_ENC hAacEnc, qcInit.averageBits = (averageBitsPerFrame+7)&~7; qcInit.bitRes = MIN_BUFSIZE_PER_EFF_CHAN*cm->nChannelsEff; qcInit.maxBits = MIN_BUFSIZE_PER_EFF_CHAN*cm->nChannelsEff; - qcInit.minBits = 0; + qcInit.maxBits = (config->maxBitsPerFrame!=-1) ? fixMin(qcInit.maxBits, config->maxBitsPerFrame) : qcInit.maxBits; + qcInit.maxBits = fixMax(qcInit.maxBits, (averageBitsPerFrame+7)&~7); + qcInit.minBits = (config->minBitsPerFrame!=-1) ? config->minBitsPerFrame : 0; + qcInit.minBits = fixMin(qcInit.minBits, averageBitsPerFrame&~7); } else { @@ -575,9 +614,11 @@ AAC_ENCODER_ERROR FDKaacEnc_Initialize(HANDLE_AAC_ENC hAacEnc, qcInit.maxBits = fixMin(MIN_BUFSIZE_PER_EFF_CHAN*cm->nChannelsEff, ((averageBitsPerFrame+7)&~7)+qcInit.bitRes); qcInit.maxBits = (config->maxBitsPerFrame!=-1) ? fixMin(qcInit.maxBits, config->maxBitsPerFrame) : qcInit.maxBits; + qcInit.maxBits = fixMin(MIN_BUFSIZE_PER_EFF_CHAN*cm->nChannelsEff, fixMax(qcInit.maxBits, (averageBitsPerFrame+7+8)&~7)); qcInit.minBits = fixMax(0, ((averageBitsPerFrame-1)&~7)-qcInit.bitRes-transportEnc_GetStaticBits(hTpEnc, ((averageBitsPerFrame+7)&~7)+qcInit.bitRes)); qcInit.minBits = (config->minBitsPerFrame!=-1) ? fixMax(qcInit.minBits, config->minBitsPerFrame) : qcInit.minBits; + qcInit.minBits = fixMin(qcInit.minBits, (averageBitsPerFrame - transportEnc_GetStaticBits(hTpEnc, qcInit.maxBits))&~7); } qcInit.sampleRate = config->sampleRate; @@ -585,11 +626,9 @@ AAC_ENCODER_ERROR FDKaacEnc_Initialize(HANDLE_AAC_ENC hAacEnc, qcInit.nSubFrames = config->nSubFrames; qcInit.padding.paddingRest = config->sampleRate; - /* Calc meanPe */ - bw_ratio = fDivNorm((FIXP_DBL)hAacEnc->bandwidth90dB, (FIXP_DBL)(config->sampleRate>>1), &qbw); - qbw = DFRACT_BITS-1-qbw; - /* qcInit.meanPe = 10.0f * FRAME_LEN_LONG * hAacEnc->bandwidth90dB/(config->sampleRate/2.0f); */ - qcInit.meanPe = fMult(bw_ratio, (FIXP_DBL)((10*config->framelength)<<16)) >> (qbw-15); + /* Calc meanPe: qcInit.meanPe = 10.0f * FRAME_LEN_LONG * hAacEnc->bandwidth90dB/(config->sampleRate/2.0f); */ + bw_ratio = fDivNorm((FIXP_DBL)(10*config->framelength*hAacEnc->bandwidth90dB), (FIXP_DBL)(config->sampleRate), &qbw); + qcInit.meanPe = FDKmax((INT)scaleValue(bw_ratio, qbw+1-(DFRACT_BITS-1)), 1); /* Calc maxBitFac */ mbfac = fDivNorm((MIN_BUFSIZE_PER_EFF_CHAN-744)*cm->nChannelsEff, qcInit.averageBits/qcInit.nSubFrames, &qmbfac); @@ -651,23 +690,7 @@ AAC_ENCODER_ERROR FDKaacEnc_Initialize(HANDLE_AAC_ENC hAacEnc, if (ErrorStatus != AAC_ENC_OK) goto bail; - /* Map virtual aot's to intern aot used in bitstream writer. */ - switch (hAacEnc->config->audioObjectType) { - case AOT_MP2_AAC_LC: - case AOT_DABPLUS_AAC_LC: - hAacEnc->aot = AOT_AAC_LC; - break; - case AOT_MP2_SBR: - case AOT_DABPLUS_SBR: - hAacEnc->aot = AOT_SBR; - break; - case AOT_MP2_PS: - case AOT_DABPLUS_PS: - hAacEnc->aot = AOT_PS; - break; - default: - hAacEnc->aot = hAacEnc->config->audioObjectType; - } + hAacEnc->aot = hAacEnc->config->audioObjectType; /* common things */ @@ -932,7 +955,7 @@ AAC_ENCODER_ERROR FDKaacEnc_EncodeFrame( HANDLE_AAC_ENC hAacEnc, transportEnc_WriteAccessUnit( hTpEnc, totalBits, - FDKaacEnc_EncBitresToTpBitres(hAacEnc->bitrateMode, hAacEnc->qcKernel->bitResTot), + FDKaacEnc_EncBitresToTpBitres(hAacEnc), cm->nChannelsEff); /* write bitstream */ diff --git a/libAACenc/src/aacenc.h b/libAACenc/src/aacenc.h index 87fc3e8..61520de 100644 --- a/libAACenc/src/aacenc.h +++ b/libAACenc/src/aacenc.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 @@ -204,6 +204,8 @@ struct AACENC_CONFIG { INT maxBitsPerFrame; /* maximum number of bits in AU */ INT bitreservoir; /* size of bitreservoir */ + INT audioMuxVersion; /* audio mux version in loas/latm transport format */ + UINT sbrRatio; /* sbr sampling rate ratio: dual- or single-rate */ UCHAR useTns; /* flag: use temporal noise shaping */ @@ -223,6 +225,36 @@ typedef struct { typedef struct AAC_ENC *HANDLE_AAC_ENC; /** + * \brief Calculate framesize in bits for given bit rate, frame length and sampling rate. + * + * \param bitRate Ttarget bitrate in bits per second. + * \param frameLength Number of audio samples in one frame. + * \param samplingRate Sampling rate in Hz. + * + * \return Framesize in bits per frame. +*/ +INT FDKaacEnc_CalcBitsPerFrame( + const INT bitRate, + const INT frameLength, + const INT samplingRate + ); + +/** + * \brief Calculate bitrate in bits per second for given framesize, frame length and sampling rate. + * + * \param bitsPerFrame Framesize in bits per frame. + * \param frameLength Number of audio samples in one frame. + * \param samplingRate Sampling rate in Hz. + * + * \return Bitrate in bits per second. +*/ +INT FDKaacEnc_CalcBitrate( + const INT bitsPerFrame, + const INT frameLength, + const INT samplingRate + ); + +/** * \brief Limit given bit rate to a valid value * \param hTpEnc transport encoder handle * \param coreSamplingRate the sample rate to be used for the AAC encoder diff --git a/libAACenc/src/aacenc_lib.cpp b/libAACenc/src/aacenc_lib.cpp index 02f83bf..9a3b214 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 14 +#define AACENCODER_LIB_VL2 19 #define AACENCODER_LIB_TITLE "AAC Encoder" #ifdef __ANDROID__ #define AACENCODER_LIB_BUILD_DATE "" @@ -153,6 +153,7 @@ typedef struct { UINT userAfterburner; UINT userFramelength; UINT userAncDataRate; + UINT userPeakBitrate; UCHAR userTns; /*!< Use TNS coding. */ UCHAR userPns; /*!< Use PNS coding. */ @@ -326,10 +327,7 @@ static inline INT isSbrActive(const HANDLE_AACENC_CONFIG hAacConfig) { INT sbrUsed = 0; - if ( (hAacConfig->audioObjectType==AOT_SBR) || (hAacConfig->audioObjectType==AOT_PS) - || (hAacConfig->audioObjectType==AOT_MP2_SBR) || (hAacConfig->audioObjectType==AOT_MP2_PS) - || (hAacConfig->audioObjectType==AOT_DABPLUS_SBR) || (hAacConfig->audioObjectType==AOT_DABPLUS_PS) - || (hAacConfig->audioObjectType==AOT_DRM_SBR) || (hAacConfig->audioObjectType==AOT_DRM_MPEG_PS) ) + if ( (hAacConfig->audioObjectType==AOT_SBR) || (hAacConfig->audioObjectType==AOT_PS) ) { sbrUsed = 1; } @@ -345,10 +343,7 @@ static inline INT isPsActive(const AUDIO_OBJECT_TYPE audioObjectType) { INT psUsed = 0; - if ( (audioObjectType==AOT_PS) - || (audioObjectType==AOT_MP2_PS) - || (audioObjectType==AOT_DABPLUS_PS) - || (audioObjectType==AOT_DRM_MPEG_PS) ) + if ( (audioObjectType==AOT_PS) ) { psUsed = 1; } @@ -373,8 +368,7 @@ static SBR_PS_SIGNALING getSbrSignalingMode( sbrSignaling = SIG_IMPLICIT; /* default: implicit signaling */ } - if ((audioObjectType==AOT_AAC_LC) || (audioObjectType==AOT_SBR) || (audioObjectType==AOT_PS) || - (audioObjectType==AOT_MP2_AAC_LC) || (audioObjectType==AOT_MP2_SBR) || (audioObjectType==AOT_MP2_PS) ) { + if ( (audioObjectType==AOT_AAC_LC) || (audioObjectType==AOT_SBR) || (audioObjectType==AOT_PS) ) { switch (transportType) { case TT_MP4_ADIF: case TT_MP4_ADTS: @@ -430,22 +424,7 @@ static void FDKaacEnc_MapConfig( cc->flags = 0; - /* Map virtual aot to transport aot. */ - switch (hAacConfig->audioObjectType) { - case AOT_MP2_AAC_LC: - transport_AOT = AOT_AAC_LC; - break; - case AOT_MP2_SBR: - transport_AOT = AOT_SBR; - cc->flags |= CC_SBR; - break; - case AOT_MP2_PS: - transport_AOT = AOT_PS; - cc->flags |= CC_SBR; - break; - default: - transport_AOT = hAacConfig->audioObjectType; - } + transport_AOT = hAacConfig->audioObjectType; if (hAacConfig->audioObjectType == AOT_ER_AAC_ELD) { cc->flags |= (hAacConfig->syntaxFlags & AC_SBR_PRESENT) ? CC_SBR : 0; @@ -511,16 +490,7 @@ static void FDKaacEnc_MapConfig( cc->samplingRate = hAacConfig->sampleRate; /* Mpeg-4 signaling for transport library. */ - switch ( hAacConfig->audioObjectType ) { - case AOT_MP2_AAC_LC: - case AOT_MP2_SBR: - case AOT_MP2_PS: - cc->flags &= ~CC_MPEG_ID; /* Required for ADTS. */ - cc->extAOT = AOT_NULL_OBJECT; - break; - default: - cc->flags |= CC_MPEG_ID; - } + cc->flags |= CC_MPEG_ID; /* ER-tools signaling. */ cc->flags |= (hAacConfig->syntaxFlags & AC_ER_VCB11) ? CC_VCB11 : 0; @@ -585,6 +555,7 @@ AAC_ENCODER_ERROR aacEncDefaultConfig(HANDLE_AACENC_CONFIG hAacConfig, config->userChannelMode = hAacConfig->channelMode; config->userBitrate = hAacConfig->bitRate; config->userBitrateMode = hAacConfig->bitrateMode; + config->userPeakBitrate = (UINT)-1; config->userBandwidth = hAacConfig->bandWidth; config->userTns = hAacConfig->useTns; config->userPns = hAacConfig->usePns; @@ -792,12 +763,15 @@ AACENC_ERROR FDKaacEnc_AdjustEncSettings(HANDLE_AACENCODER hAacEncoder, hAacConfig->syntaxFlags = 0; hAacConfig->epConfig = -1; + if (config->userTpType==TT_MP4_LATM_MCP1 || config->userTpType==TT_MP4_LATM_MCP0 || config->userTpType==TT_MP4_LOAS) { + hAacConfig->audioMuxVersion = config->userTpAmxv; + } + else { + hAacConfig->audioMuxVersion = -1; + } + /* Adapt internal AOT when necessary. */ switch ( hAacConfig->audioObjectType ) { - case AOT_MP2_AAC_LC: - case AOT_MP2_SBR: - case AOT_MP2_PS: - hAacConfig->usePns = 0; case AOT_AAC_LC: case AOT_SBR: case AOT_PS: @@ -884,6 +858,18 @@ AACENC_ERROR FDKaacEnc_AdjustEncSettings(HANDLE_AACENCODER hAacEncoder, } } + if ((hAacConfig->bitrateMode >= 0) && (hAacConfig->bitrateMode <= 5)) { + if ((INT)config->userPeakBitrate != -1) { + hAacConfig->maxBitsPerFrame = (FDKaacEnc_CalcBitsPerFrame(fMax(hAacConfig->bitRate, (INT)config->userPeakBitrate), hAacConfig->framelength, hAacConfig->sampleRate) + 7)&~7; + } + else { + hAacConfig->maxBitsPerFrame = -1; + } + if (hAacConfig->audioMuxVersion==2) { + hAacConfig->minBitsPerFrame = fMin(32*8, FDKaacEnc_CalcBitsPerFrame(hAacConfig->bitRate, hAacConfig->framelength, hAacConfig->sampleRate))&~7; + } + } + /* Initialize SBR parameters */ if ( (hAacConfig->audioObjectType==AOT_ER_AAC_ELD) && (config->userSbrEnabled == (UCHAR)-1) && (config->userSbrRatio==0) ) @@ -1139,7 +1125,7 @@ static AACENC_ERROR aacEncInit(HANDLE_AACENCODER hAacEncoder, hAacConfig); /* create flags for transport encoder */ - if (config->userTpAmxv == 1) { + if (config->userTpAmxv != 0) { flags |= TP_FLAG_LATM_AMV; } /* Clear output buffer */ @@ -1569,7 +1555,7 @@ AACENC_ERROR aacEncEncode( && ((hAacEncoder->extParam.userChannelMode==MODE_1_2_2)||(hAacEncoder->extParam.userChannelMode==MODE_1_2_2_1)) ) { /* Set matrix mixdown coefficient. */ - UINT pceValue = (UINT)( (1<<3) | ((matrix_mixdown_idx&0x3)<<1) | 1 ); + UINT pceValue = (UINT)( (0<<3) | ((matrix_mixdown_idx&0x3)<<1) | 1 ); if (hAacEncoder->extParam.userPceAdditions != pceValue) { hAacEncoder->extParam.userPceAdditions = pceValue; hAacEncoder->InitFlags |= AACENC_INIT_TRANSPORT; @@ -1785,19 +1771,16 @@ AACENC_ERROR aacEncoder_SetParam( /* check if AOT matches the allocated modules */ switch ( value ) { case AOT_PS: - case AOT_MP2_PS: if (!(hAacEncoder->encoder_modis & (ENC_MODE_FLAG_PS))) { err = AACENC_INVALID_CONFIG; goto bail; } case AOT_SBR: - case AOT_MP2_SBR: if (!(hAacEncoder->encoder_modis & (ENC_MODE_FLAG_SBR))) { err = AACENC_INVALID_CONFIG; goto bail; } case AOT_AAC_LC: - case AOT_MP2_AAC_LC: case AOT_ER_AAC_LD: case AOT_ER_AAC_ELD: if (!(hAacEncoder->encoder_modis & (ENC_MODE_FLAG_AAC))) { @@ -1823,6 +1806,7 @@ AACENC_ERROR aacEncoder_SetParam( if (settings->userBitrateMode != value) { switch ( value ) { case 0: + case 1: case 2: case 3: case 4: case 5: case 8: settings->userBitrateMode = value; hAacEncoder->InitFlags |= AACENC_INIT_CONFIG | AACENC_INIT_TRANSPORT; @@ -1973,6 +1957,16 @@ AACENC_ERROR aacEncoder_SetParam( hAacEncoder->InitFlags |= AACENC_INIT_TRANSPORT; } break; + case AACENC_AUDIOMUXVER: + if (settings->userTpAmxv != value) { + if ( !((value==0) || (value==1) || (value==2)) ) { + err = AACENC_INVALID_CONFIG; + break; + } + settings->userTpAmxv = value; + hAacEncoder->InitFlags |= AACENC_INIT_TRANSPORT; + } + break; case AACENC_TPSUBFRAMES: if (settings->userTpNsubFrames != value) { if (! ( (value>=1) && (value<=4) ) ) { @@ -2006,6 +2000,12 @@ AACENC_ERROR aacEncoder_SetParam( hAacEncoder->InitFlags |= AACENC_INIT_CONFIG; } break; + case AACENC_PEAK_BITRATE: + if (settings->userPeakBitrate != value) { + settings->userPeakBitrate = value; + hAacEncoder->InitFlags |= AACENC_INIT_CONFIG | AACENC_INIT_TRANSPORT; + } + break; default: err = AACENC_UNSUPPORTED_PARAMETER; break; @@ -2076,6 +2076,9 @@ UINT aacEncoder_GetParam( case AACENC_HEADER_PERIOD: value = (UINT)hAacEncoder->coderConfig.headerPeriod; break; + case AACENC_AUDIOMUXVER: + value = (UINT)hAacEncoder->aacConfig.audioMuxVersion; + break; case AACENC_TPSUBFRAMES: value = (UINT)settings->userTpNsubFrames; break; @@ -2088,6 +2091,12 @@ UINT aacEncoder_GetParam( case AACENC_METADATA_MODE: value = (hAacEncoder->metaDataAllowed==0) ? 0 : (UINT)settings->userMetaDataMode; break; + case AACENC_PEAK_BITRATE: + value = (UINT)-1; /* peak bitrate parameter is meaningless */ + if ( ((INT)hAacEncoder->extParam.userPeakBitrate!=-1) ) { + value = (UINT)(fMax((INT)hAacEncoder->extParam.userPeakBitrate, hAacEncoder->aacConfig.bitRate)); /* peak bitrate parameter is in use */ + } + break; default: //err = MPS_INVALID_PARAMETER; break; diff --git a/libAACenc/src/adj_thr.cpp b/libAACenc/src/adj_thr.cpp index 69a70b4..c318843 100644 --- a/libAACenc/src/adj_thr.cpp +++ b/libAACenc/src/adj_thr.cpp @@ -2138,7 +2138,7 @@ static FIXP_DBL FDKaacEnc_bitresCalcBitFac(const INT bitresBits, bresParam->clipSpendLow, bresParam->clipSpendHigh, bresParam->minBitSpend, bresParam->maxBitSpend, bitspend_slope); - pe_pers = fDivNorm(pex - adjThrChan->peMin, adjThrChan->peMax - adjThrChan->peMin); + pe_pers = (pex > adjThrChan->peMin) ? fDivNorm(pex - adjThrChan->peMin, adjThrChan->peMax - adjThrChan->peMin) : 0; tmp_fix = fMult(((FIXP_DBL)bitSpend + (FIXP_DBL)bitSave), pe_pers); bitresFac_fix = (UNITY>>1) - ((FIXP_DBL)bitSave>>1) + (tmp_fix>>1); qbres = (DFRACT_BITS-2); diff --git a/libAACenc/src/intensity.cpp b/libAACenc/src/intensity.cpp index 6d807f7..b45b27b 100644 --- a/libAACenc/src/intensity.cpp +++ b/libAACenc/src/intensity.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 @@ -325,7 +325,6 @@ FDKaacEnc_prepareIntensityDecision(const FIXP_DBL *sfbEnergyLeft, channelCorr[sfb + sfboffs] = FL2FXCONST_DBL(0.0f); - FDK_ASSERT(50 >= 49); /* max width of scalefactorband is 96; width's are always even */ /* inv_n is scaled with factor 2 to compensate fMultDiv2() in subsequent loops */ inv_n = GetInvInt((sfbOffset[sfb + sfboffs + 1] - sfbOffset[sfb + sfboffs])>>1); diff --git a/libAACenc/src/psy_configuration.cpp b/libAACenc/src/psy_configuration.cpp index 4393fa1..9a72c68 100644 --- a/libAACenc/src/psy_configuration.cpp +++ b/libAACenc/src/psy_configuration.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 @@ -634,13 +634,14 @@ AAC_ENCODER_ERROR FDKaacEnc_InitPsyConfiguration(INT bitrate, if (psyConf->sfbOffset[sfb] >= psyConf->lowpassLine) break; } - psyConf->sfbActive = sfb; + psyConf->sfbActive = FDKmax(sfb, 1); for (sfb = 0; sfb < psyConf->sfbCnt; sfb++){ if (psyConf->sfbOffset[sfb] >= psyConf->lowpassLineLFE) break; } psyConf->sfbActiveLFE = sfb; + psyConf->sfbActive = FDKmax(psyConf->sfbActive, psyConf->sfbActiveLFE); /* calculate minSnr */ FDKaacEnc_initMinSnr(bitrate, diff --git a/libAACenc/src/psy_main.cpp b/libAACenc/src/psy_main.cpp index 1c593f8..3cc9438 100644 --- a/libAACenc/src/psy_main.cpp +++ b/libAACenc/src/psy_main.cpp @@ -621,7 +621,7 @@ AAC_ENCODER_ERROR FDKaacEnc_psyMain(INT channels, FDKmemclear(&psyData[ch]->mdctSpectrum[psyData[ch]->lowpassLine+wOffset], (windowLength[ch]-psyData[ch]->lowpassLine)*sizeof(FIXP_DBL)); - if (hPsyConfLong->filterbank != FB_LC) { + if ( (hPsyConfLong->filterbank != FB_LC) && (psyData[ch]->lowpassLine >= FADE_OUT_LEN) ) { /* Do blending to reduce gibbs artifacts */ for (int i=0; i<FADE_OUT_LEN; i++) { psyData[ch]->mdctSpectrum[psyData[ch]->lowpassLine+wOffset - FADE_OUT_LEN + i] = fMult(psyData[ch]->mdctSpectrum[psyData[ch]->lowpassLine+wOffset - FADE_OUT_LEN + i], fadeOutFactor[i]); diff --git a/libAACenc/src/qc_main.cpp b/libAACenc/src/qc_main.cpp index 278bcb2..7503309 100644 --- a/libAACenc/src/qc_main.cpp +++ b/libAACenc/src/qc_main.cpp @@ -1248,6 +1248,8 @@ AAC_ENCODER_ERROR FDKaacEnc_updateFillBits(CHANNEL_MAPPING* cm, case QCDATA_BR_MODE_VBR_4: case QCDATA_BR_MODE_VBR_5: qcOut[0]->totFillBits = (qcOut[0]->grantedDynBits - qcOut[0]->usedDynBits)&7; /* precalculate alignment bits */ + qcOut[0]->totalBits = qcOut[0]->staticBits + qcOut[0]->usedDynBits + qcOut[0]->totFillBits + qcOut[0]->elementExtBits + qcOut[0]->globalExtBits; + qcOut[0]->totFillBits += ( fixMax(0, qcKernel->minBitsPerFrame - qcOut[0]->totalBits) + 7) & ~7; break; case QCDATA_BR_MODE_CBR: @@ -1257,6 +1259,8 @@ AAC_ENCODER_ERROR FDKaacEnc_updateFillBits(CHANNEL_MAPPING* cm, /* processing fill-bits */ INT deltaBitRes = qcOut[0]->grantedDynBits - qcOut[0]->usedDynBits ; qcOut[0]->totFillBits = fixMax((deltaBitRes&7), (deltaBitRes - (fixMax(0,bitResSpace-7)&~7))); + qcOut[0]->totalBits = qcOut[0]->staticBits + qcOut[0]->usedDynBits + qcOut[0]->totFillBits + qcOut[0]->elementExtBits + qcOut[0]->globalExtBits; + qcOut[0]->totFillBits += ( fixMax(0, qcKernel->minBitsPerFrame - qcOut[0]->totalBits) + 7) & ~7; break; } /* switch (qcKernel->bitrateMode) */ |