Skip to content

Commit

Permalink
Merge pull request FD-#172 from pallas/mysterious-future
Browse files Browse the repository at this point in the history
Mysterious future
  • Loading branch information
pallas authored Nov 12, 2020
2 parents 394da24 + d8f02ee commit 0317e13
Show file tree
Hide file tree
Showing 36 changed files with 4,700 additions and 1,407 deletions.
111 changes: 61 additions & 50 deletions renderers/fdk-aac/libAACdec/include/aacdecoder_lib.h
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -459,8 +459,8 @@ Where N equals to CStreamInfo::frameSize .
#include "genericStds.h"

#define AACDECODER_LIB_VL0 3
#define AACDECODER_LIB_VL1 0
#define AACDECODER_LIB_VL2 0
#define AACDECODER_LIB_VL1 1
#define AACDECODER_LIB_VL2 2

/**
* \brief AAC decoder error codes.
Expand Down Expand Up @@ -746,66 +746,77 @@ typedef enum {
::CONCEAL_INTER. only some AOTs are
supported). \n */
AAC_DRC_BOOST_FACTOR =
0x0200, /*!< Dynamic Range Control: Scaling factor for boosting gain
values. Defines how the boosting DRC factors (conveyed in the
bitstream) will be applied to the decoded signal. The valid
values range from 0 (don't apply boost factors) to 127 (fully
apply boost factors). Default value is 0. */
AAC_DRC_ATTENUATION_FACTOR =
0x0201, /*!< Dynamic Range Control: Scaling factor for attenuating gain
values. Same as
::AAC_DRC_BOOST_FACTOR but for attenuating DRC factors. */
0x0200, /*!< MPEG-4 / MPEG-D Dynamic Range Control (DRC): Scaling factor
for boosting gain values. Defines how the boosting DRC factors
(conveyed in the bitstream) will be applied to the decoded
signal. The valid values range from 0 (don't apply boost
factors) to 127 (fully apply boost factors). Default value is 0
for MPEG-4 DRC and 127 for MPEG-D DRC. */
AAC_DRC_ATTENUATION_FACTOR = 0x0201, /*!< MPEG-4 / MPEG-D DRC: Scaling factor
for attenuating gain values. Same as
::AAC_DRC_BOOST_FACTOR but for
attenuating DRC factors. */
AAC_DRC_REFERENCE_LEVEL =
0x0202, /*!< Dynamic Range Control (DRC): Target reference level. Defines
the level below full-scale (quantized in steps of 0.25dB) to
which the output audio signal will be normalized to by the DRC
module. The parameter controls loudness normalization for both
MPEG-4 DRC and MPEG-D DRC. The valid values range from 40 (-10
dBFS) to 127 (-31.75 dBFS). Any value smaller than 0 switches
off loudness normalization and MPEG-4 DRC. By default, loudness
normalization and MPEG-4 DRC is switched off. */
0x0202, /*!< MPEG-4 / MPEG-D DRC: Target reference level / decoder target
loudness.\n Defines the level below full-scale (quantized in
steps of 0.25dB) to which the output audio signal will be
normalized to by the DRC module.\n The parameter controls
loudness normalization for both MPEG-4 DRC and MPEG-D DRC. The
valid values range from 40 (-10 dBFS) to 127 (-31.75 dBFS).\n
Example values:\n
124 (-31 dBFS) for audio/video receivers (AVR) or other
devices allowing audio playback with high dynamic range,\n 96
(-24 dBFS) for TV sets or equivalent devices (default),\n 64
(-16 dBFS) for mobile devices where the dynamic range of audio
playback is restricted.\n Any value smaller than 0 switches off
loudness normalization and MPEG-4 DRC. */
AAC_DRC_HEAVY_COMPRESSION =
0x0203, /*!< Dynamic Range Control: En-/Disable DVB specific heavy
compression (aka RF mode). If set to 1, the decoder will apply
the compression values from the DVB specific ancillary data
field. At the same time the MPEG-4 Dynamic Range Control tool
will be disabled. By default, heavy compression is disabled. */
0x0203, /*!< MPEG-4 DRC: En-/Disable DVB specific heavy compression (aka
RF mode). If set to 1, the decoder will apply the compression
values from the DVB specific ancillary data field. At the same
time the MPEG-4 Dynamic Range Control tool will be disabled. By
default, heavy compression is disabled. */
AAC_DRC_DEFAULT_PRESENTATION_MODE =
0x0204, /*!< Dynamic Range Control: Default presentation mode (DRC
parameter handling). \n Defines the handling of the DRC
parameters boost factor, attenuation factor and heavy
compression, if no presentation mode is indicated in the
bitstream.\n For options, see
::AAC_DRC_DEFAULT_PRESENTATION_MODE_OPTIONS.\n Default:
0x0204, /*!< MPEG-4 DRC: Default presentation mode (DRC parameter
handling). \n Defines the handling of the DRC parameters boost
factor, attenuation factor and heavy compression, if no
presentation mode is indicated in the bitstream.\n For options,
see ::AAC_DRC_DEFAULT_PRESENTATION_MODE_OPTIONS.\n Default:
::AAC_DRC_PARAMETER_HANDLING_DISABLED */
AAC_DRC_ENC_TARGET_LEVEL =
0x0205, /*!< Dynamic Range Control: Encoder target level for light (i.e.
not heavy) compression.\n If known, this declares the target
reference level that was assumed at the encoder for calculation
of limiting gains. The valid values range from 0 (full-scale)
to 127 (31.75 dB below full-scale). This parameter is used only
0x0205, /*!< MPEG-4 DRC: Encoder target level for light (i.e. not heavy)
compression.\n If known, this declares the target reference
level that was assumed at the encoder for calculation of
limiting gains. The valid values range from 0 (full-scale) to
127 (31.75 dB below full-scale). This parameter is used only
with ::AAC_DRC_PARAMETER_HANDLING_ENABLED and ignored
otherwise.\n Default: 127 (worst-case assumption).\n */
AAC_UNIDRC_SET_EFFECT = 0x0206, /*!< MPEG-D DRC: Request a DRC effect type for
selection of a DRC set.\n Supported indices
are:\n -1: DRC off. Completely disables
MPEG-D DRC.\n 0: None (default). Disables
MPEG-D DRC, but automatically enables DRC
if necessary to prevent clipping.\n 1: Late
night\n 2: Noisy environment\n 3: Limited
playback range\n 4: Low playback level\n 5:
Dialog enhancement\n 6: General
compression. Used for generally enabling
MPEG-D DRC without particular request.\n */
AAC_UNIDRC_ALBUM_MODE =
0x0207, /*!< MPEG-D DRC: Enable album mode. 0: Disabled (default), 1:
Enabled.\n Disabled album mode leads to application of gain
sequences for fading in and out, if provided in the
bitstream.\n Enabled album mode makes use of dedicated album
loudness information, if provided in the bitstream.\n */
AAC_QMF_LOWPOWER = 0x0300, /*!< Quadrature Mirror Filter (QMF) Bank processing
mode. \n -1: Use internal default. Implies MPEG
Surround partially complex accordingly. \n 0:
Use complex QMF data mode. \n 1: Use real (low
power) QMF data mode. \n */
AAC_TPDEC_CLEAR_BUFFER =
0x0603, /*!< Clear internal bit stream buffer of transport layers. The
decoder will start decoding at new data passed after this event
and any previous data is discarded. */
AAC_UNIDRC_SET_EFFECT = 0x0903 /*!< MPEG-D DRC: Request a DRC effect type for
selection of a DRC set.\n Supported indices
are:\n -1: DRC off. Completely disables
MPEG-D DRC.\n 0: None (default). Disables
MPEG-D DRC, but automatically enables DRC if
necessary to prevent clipping.\n 1: Late
night\n 2: Noisy environment\n 3: Limited
playback range\n 4: Low playback level\n 5:
Dialog enhancement\n 6: General compression.
Used for generally enabling MPEG-D DRC
without particular request.\n */
0x0603 /*!< Clear internal bit stream buffer of transport layers. The
decoder will start decoding at new data passed after this event
and any previous data is discarded. */

} AACDEC_PARAM;

Expand Down
6 changes: 3 additions & 3 deletions renderers/fdk-aac/libAACdec/src/aacdec_drc.cpp
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -174,9 +174,9 @@ void aacDecoder_drcInit(HANDLE_AAC_DRC self) {
pParams->usrCut = FL2FXCONST_DBL(0.0f);
pParams->boost = FL2FXCONST_DBL(0.0f);
pParams->usrBoost = FL2FXCONST_DBL(0.0f);
pParams->targetRefLevel = -1;
pParams->targetRefLevel = 96;
pParams->expiryFrame = AACDEC_DRC_DFLT_EXPIRY_FRAMES;
pParams->applyDigitalNorm = OFF;
pParams->applyDigitalNorm = ON;
pParams->applyHeavyCompression = OFF;
pParams->usrApplyHeavyCompression = OFF;

Expand Down
3 changes: 3 additions & 0 deletions renderers/fdk-aac/libAACdec/src/aacdec_hcr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1423,6 +1423,9 @@ static INT DecodeEscapeSequence(HANDLE_FDK_BITSTREAM bs, const INT bsAnchor,

sign = (quantSpecCoef >= 0) ? 1 : -1;

if (escapeOnesCounter > 30)
escapeOnesCounter = 30;

quantSpecCoef = sign * (((INT)1 << escapeOnesCounter) + escape_word);

return quantSpecCoef;
Expand Down
5 changes: 4 additions & 1 deletion renderers/fdk-aac/libAACdec/src/aacdecoder.cpp
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -1815,6 +1815,9 @@ CAacDecoder_Init(HANDLE_AACDECODER self, const CSAudioSpecificConfig *asc,
self->useLdQmfTimeAlign =
asc->m_sc.m_eldSpecificConfig.m_useLdQmfTimeAlign;
}
if (self->sbrEnabled != asc->m_sbrPresentFlag) {
ascChanged = 1;
}
}

self->streamInfo.extAot = asc->m_extensionAudioObjectType;
Expand Down
22 changes: 19 additions & 3 deletions renderers/fdk-aac/libAACdec/src/aacdecoder_lib.cpp
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -119,8 +119,8 @@ [email protected]

/* Decoder library info */
#define AACDECODER_LIB_VL0 3
#define AACDECODER_LIB_VL1 0
#define AACDECODER_LIB_VL2 0
#define AACDECODER_LIB_VL1 1
#define AACDECODER_LIB_VL2 2
#define AACDECODER_LIB_TITLE "AAC Decoder Lib"
#ifdef __ANDROID__
#define AACDECODER_LIB_BUILD_DATE ""
Expand Down Expand Up @@ -823,11 +823,15 @@ LINKSPEC_CPP AAC_DECODER_ERROR aacDecoder_SetParam(
case AAC_DRC_ATTENUATION_FACTOR:
/* DRC compression factor (where 0 is no and 127 is max compression) */
errorStatus = aacDecoder_drcSetParam(hDrcInfo, DRC_CUT_SCALE, value);
uniDrcErr = FDK_drcDec_SetParam(self->hUniDrcDecoder, DRC_DEC_COMPRESS,
value * (FL2FXCONST_DBL(0.5f / 127.0f)));
break;

case AAC_DRC_BOOST_FACTOR:
/* DRC boost factor (where 0 is no and 127 is max boost) */
errorStatus = aacDecoder_drcSetParam(hDrcInfo, DRC_BOOST_SCALE, value);
uniDrcErr = FDK_drcDec_SetParam(self->hUniDrcDecoder, DRC_DEC_BOOST,
value * (FL2FXCONST_DBL(0.5f / 127.0f)));
break;

case AAC_DRC_REFERENCE_LEVEL:
Expand Down Expand Up @@ -871,6 +875,11 @@ LINKSPEC_CPP AAC_DECODER_ERROR aacDecoder_SetParam(
uniDrcErr = FDK_drcDec_SetParam(self->hUniDrcDecoder, DRC_DEC_EFFECT_TYPE,
(FIXP_DBL)value);
break;
case AAC_UNIDRC_ALBUM_MODE:
uniDrcErr = FDK_drcDec_SetParam(self->hUniDrcDecoder, DRC_DEC_ALBUM_MODE,
(FIXP_DBL)value);
break;

case AAC_TPDEC_CLEAR_BUFFER:
errTp = transportDec_SetParam(hTpDec, TPDEC_PARAM_RESET, 1);
self->streamInfo.numLostAccessUnits = 0;
Expand Down Expand Up @@ -1669,6 +1678,13 @@ aacDecoder_DecodeFrame(HANDLE_AACDECODER self, INT_PCM *pTimeData_extern,
reverseOutChannelMap[ch] = ch;
}

/* Update sampleRate and frameSize. This may be necessary in case of
* implicit SBR signaling */
FDK_drcDec_SetParam(self->hUniDrcDecoder, DRC_DEC_SAMPLE_RATE,
self->streamInfo.sampleRate);
FDK_drcDec_SetParam(self->hUniDrcDecoder, DRC_DEC_FRAME_SIZE,
self->streamInfo.frameSize);

/* If SBR and/or MPS is active, the DRC gains are aligned to the QMF
domain signal before the QMF synthesis. Therefore the DRC gains
need to be delayed by the QMF synthesis delay. */
Expand Down
2 changes: 1 addition & 1 deletion renderers/fdk-aac/libAACdec/src/usacdec_lpd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1222,7 +1222,7 @@ AAC_DECODER_ERROR CLpdChannelStream_Read(
(INT)(samplingRate * PIT_MIN_12k8 + (FSCALE_DENOM / 2)) / FSCALE_DENOM -
(INT)PIT_MIN_12k8;

if ((samplingRate < FAC_FSCALE_MIN) || (samplingRate > FAC_FSCALE_MAX)) {
if ((samplingRate < 6000) || (samplingRate > 24000)) {
error = AAC_DEC_PARSE_ERROR;
goto bail;
}
Expand Down
6 changes: 5 additions & 1 deletion renderers/fdk-aac/libAACenc/src/aacenc_lib.cpp
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -1761,6 +1761,10 @@ AACENC_ERROR aacEncEncode(const HANDLE_AACENCODER hAacEncoder,
hAacEncoder->inputBuffer +
(hAacEncoder->inputBufferOffset + hAacEncoder->nSamplesRead) /
hAacEncoder->aacConfig.nChannels;
newSamples -=
(newSamples %
hAacEncoder->extParam
.nChannels); /* process multiple samples of input channels */

/* Copy new input samples to internal buffer */
if (inBufDesc->bufElSizes[idx] == (INT)sizeof(INT_PCM)) {
Expand Down
12 changes: 5 additions & 7 deletions renderers/fdk-aac/libAACenc/src/adj_thr.cpp
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -591,13 +591,11 @@ static void FDKaacEnc_initAvoidHoleFlag(
if (sfbEn > avgEn) {
FIXP_DBL tmpMinSnrLdData;
if (psyOutChannel[ch]->lastWindowSequence == LONG_WINDOW)
tmpMinSnrLdData =
fixMax(SnrLdFac + (FIXP_DBL)(avgEnLdData - sfbEnLdData),
(FIXP_DBL)SnrLdMin1);
tmpMinSnrLdData = SnrLdFac + fixMax(avgEnLdData - sfbEnLdData,
SnrLdMin1 - SnrLdFac);
else
tmpMinSnrLdData =
fixMax(SnrLdFac + (FIXP_DBL)(avgEnLdData - sfbEnLdData),
(FIXP_DBL)SnrLdMin3);
tmpMinSnrLdData = SnrLdFac + fixMax(avgEnLdData - sfbEnLdData,
SnrLdMin3 - SnrLdFac);

qcOutChan->sfbMinSnrLdData[sfbGrp + sfb] = fixMin(
qcOutChan->sfbMinSnrLdData[sfbGrp + sfb], tmpMinSnrLdData);
Expand Down
21 changes: 14 additions & 7 deletions renderers/fdk-aac/libAACenc/src/intensity.cpp
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -661,6 +661,7 @@ void FDKaacEnc_IntensityStereoProcessing(
for (sfboffs = 0; sfboffs < maxSfbPerGroup; sfboffs++) {
INT sL, sR;
FIXP_DBL inv_n;
INT mdct_spec_sf = MDCT_SPEC_SF;

msMask[sfb + sfboffs] = 0;
if (isMask[sfb + sfboffs] == 0) {
Expand All @@ -682,6 +683,12 @@ void FDKaacEnc_IntensityStereoProcessing(
}
}

if (sfbOffset[sfb + sfboffs + 1] - sfbOffset[sfb + sfboffs] >
1 << mdct_spec_sf) {
mdct_spec_sf++; /* This is for rare cases where the number of bins in a
scale factor band is > 64 */
}

inv_n = GetInvInt(
(sfbOffset[sfb + sfboffs + 1] - sfbOffset[sfb + sfboffs]) >>
1); // scaled with 2 to compensate fMultDiv2() in subsequent loop
Expand All @@ -707,11 +714,11 @@ void FDKaacEnc_IntensityStereoProcessing(
j++) {
d = ((mdctSpectrumLeft[j] << s0) >> 1) -
((mdctSpectrumRight[j] << s0) >> 1);
ed += fMultDiv2(d, d) >> (MDCT_SPEC_SF - 1);
ed += fMultDiv2(d, d) >> (mdct_spec_sf - 1);
}
msMask[sfb + sfboffs] = 1;
tmp = fDivNorm(sfbEnergyLeft[sfb + sfboffs], ed, &s1);
s2 = (s1) + (2 * s0) - 2 - MDCT_SPEC_SF;
s2 = (s1) + (2 * s0) - 2 - mdct_spec_sf;
if (s2 & 1) {
tmp = tmp >> 1;
s2 = s2 + 1;
Expand Down Expand Up @@ -747,13 +754,13 @@ void FDKaacEnc_IntensityStereoProcessing(
j++) {
s = ((mdctSpectrumLeft[j] << s0) >> 1) +
((mdctSpectrumRight[j] << s0) >> 1);
es = fAddSaturate(es, fMultDiv2(s, s) >>
(MDCT_SPEC_SF -
1)); // scaled 2*(mdctScale - s0 + 1) + MDCT_SPEC_SF
es += fMultDiv2(s, s) >>
(mdct_spec_sf -
1); // scaled 2*(mdctScale - s0 + 1) + mdct_spec_sf
}
msMask[sfb + sfboffs] = 0;
tmp = fDivNorm(sfbEnergyLeft[sfb + sfboffs], es, &s1);
s2 = (s1) + (2 * s0) - 2 - MDCT_SPEC_SF;
s2 = (s1) + (2 * s0) - 2 - mdct_spec_sf;
if (s2 & 1) {
tmp = tmp >> 1;
s2 = s2 + 1;
Expand Down
Loading

0 comments on commit 0317e13

Please sign in to comment.