summaryrefslogtreecommitdiffstats
path: root/fdk-aac/libAACenc/src/aacenc.cpp
diff options
context:
space:
mode:
authorMatthias P. Braendli <matthias.braendli@mpb.li>2021-06-01 14:42:00 +0200
committerMatthias P. Braendli <matthias.braendli@mpb.li>2021-06-01 14:42:00 +0200
commite0835d4cbde8e3b61b0c965afcd41f8f4b7ac121 (patch)
treef49619fc806249da71afaf2ac14f99e088d24153 /fdk-aac/libAACenc/src/aacenc.cpp
parent5ad4acef6721a67b8156cd6f7b45ad59849ca09b (diff)
downloadODR-AudioEnc-e0835d4cbde8e3b61b0c965afcd41f8f4b7ac121.tar.gz
ODR-AudioEnc-e0835d4cbde8e3b61b0c965afcd41f8f4b7ac121.tar.bz2
ODR-AudioEnc-e0835d4cbde8e3b61b0c965afcd41f8f4b7ac121.zip
Update fdk to v2.0.2
Diffstat (limited to 'fdk-aac/libAACenc/src/aacenc.cpp')
-rw-r--r--fdk-aac/libAACenc/src/aacenc.cpp53
1 files changed, 47 insertions, 6 deletions
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 */