diff options
author | Jean-Michel Trivi <jmtrivi@google.com> | 2013-08-29 15:17:49 -0700 |
---|---|---|
committer | Jean-Michel Trivi <jmtrivi@google.com> | 2013-09-03 11:44:33 -0700 |
commit | 9f455bea1c38f7275a65ab79be2d41a34428fb8b (patch) | |
tree | 7421f0722c4970d0b463ebcc8499dd6e8652f48a /libAACenc/src | |
parent | dbf96806482b2c48de4ba1da9a03e2bb7516b8c2 (diff) | |
download | fdk-aac-dabplus-9f455bea1c38f7275a65ab79be2d41a34428fb8b.tar.gz fdk-aac-dabplus-9f455bea1c38f7275a65ab79be2d41a34428fb8b.tar.bz2 fdk-aac-dabplus-9f455bea1c38f7275a65ab79be2d41a34428fb8b.zip |
Encoder ELD auto configurator
* AAC-Encoder
- Introduce ELD auto configurator to get predefined configuration at given
bitrate and sampling rate. The configurator selects SBR on/off and if SBR
enabled distinguishes between dualrate and downsampled SBR. In default
configuration the ELD auto configurator is enabled.
Modified file(s):
libAACenc\include\aacenc_lib.h
libAACenc\src\aacenc_lib.cpp
Bug 9428126
Change-Id: I01acc9c37e57c4154b3a818d496d538b7f8b227d
Diffstat (limited to 'libAACenc/src')
-rw-r--r-- | libAACenc/src/aacenc_lib.cpp | 104 |
1 files changed, 102 insertions, 2 deletions
diff --git a/libAACenc/src/aacenc_lib.cpp b/libAACenc/src/aacenc_lib.cpp index 8d32f3d..056958b 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 10 +#define AACENCODER_LIB_VL2 11 #define AACENCODER_LIB_TITLE "AAC Encoder" #define AACENCODER_LIB_BUILD_DATE __DATE__ #define AACENCODER_LIB_BUILD_TIME __TIME__ @@ -235,7 +235,87 @@ struct AACENCODER } ; -//////////////////////////////////////////////////////////////////////////////////// +typedef struct +{ + ULONG samplingRate; /*!< Encoder output sampling rate. */ + ULONG bitrateRange; /*!< Lower bitrate range for config entry. */ + + UCHAR lowDelaySbr; /*!< 0: ELD sbr off, + 1: ELD sbr on */ + + UCHAR downsampledSbr; /*!< 0: ELD with dualrate sbr, + 1: ELD with downsampled sbr */ + +} ELD_SBR_CONFIGURATOR; + +/** + * \brief This table defines ELD/SBR default configurations. + */ +static const ELD_SBR_CONFIGURATOR eldSbrAutoConfigTab[] = +{ + { 48000, 0, 1, 0 }, + { 48000, 64001, 0, 0 }, + + { 44100, 0, 1, 0 }, + { 44100, 64001, 0, 0 }, + + { 32000, 0, 1, 0 }, + { 32000, 28000, 1, 1 }, + { 32000, 56000, 0, 0 }, + + { 24000, 0, 1, 1 }, + { 24000, 40000, 0, 0 }, + + { 16000, 0, 1, 1 }, + { 16000, 28000, 0, 0 } + +}; + +/* + * \brief Configure SBR for ELD configuration. + * + * This function finds default SBR configuration for ELD based on sampling rate and channel bitrate. + * Outputparameters are SBR on/off, and SBR ratio. + * + * \param samplingRate Audio signal sampling rate. + * \param channelMode Channel configuration to be used. + * \param totalBitrate Overall bitrate. + * \param eldSbr Pointer to eldSbr parameter, filled on return. + * \param eldSbrRatio Pointer to eldSbrRatio parameter, filled on return. + * + * \return - AACENC_OK, all fine. + * - AACENC_INVALID_CONFIG, on failure. + */ +static AACENC_ERROR eldSbrConfigurator( + const ULONG samplingRate, + const CHANNEL_MODE channelMode, + const ULONG totalBitrate, + UINT * const eldSbr, + UINT * const eldSbrRatio + ) +{ + AACENC_ERROR err = AACENC_OK; + int i, cfgIdx = -1; + const ULONG channelBitrate = totalBitrate / FDKaacEnc_GetChannelModeConfiguration(channelMode)->nChannelsEff; + + for (i=0; i<(sizeof(eldSbrAutoConfigTab)/sizeof(ELD_SBR_CONFIGURATOR)); i++) { + if ( (samplingRate <= eldSbrAutoConfigTab[i].samplingRate) + && (channelBitrate >= eldSbrAutoConfigTab[i].bitrateRange) ) + { + cfgIdx = i; + } + } + + if (cfgIdx != -1) { + *eldSbr = (eldSbrAutoConfigTab[cfgIdx].lowDelaySbr==0) ? 0 : 1; + *eldSbrRatio = (eldSbrAutoConfigTab[cfgIdx].downsampledSbr==0) ? 2 : 1; + } + else { + err = AACENC_INVALID_CONFIG; /* no default configuration for eld-sbr available. */ + } + + return err; +} static inline INT isSbrActive(const HANDLE_AACENC_CONFIG hAacConfig) { @@ -800,6 +880,26 @@ AACENC_ERROR FDKaacEnc_AdjustEncSettings(HANDLE_AACENCODER hAacEncoder, } /* Initialize SBR parameters */ + if ( (hAacConfig->audioObjectType==AOT_ER_AAC_ELD) + && (config->userSbrEnabled == (UCHAR)-1) && (config->userSbrRatio==0) ) + { + UINT eldSbr = 0; + UINT eldSbrRatio = 0; + + if ( AACENC_OK!=(err=eldSbrConfigurator( + hAacConfig->sampleRate, + hAacConfig->channelMode, + hAacConfig->bitRate, + &eldSbr, + &eldSbrRatio)) ) + { + return err; + } + + hAacConfig->syntaxFlags |= ((eldSbr) ? AC_SBR_PRESENT : 0); + hAacConfig->sbrRatio = eldSbrRatio; + } + else if ( (config->userSbrRatio==0) && (isSbrActive(hAacConfig)) ) { /* Automatic SBR ratio configuration * - downsampled SBR for ELD |