Commit 6ab36997 authored by Jean-Michel Trivi's avatar Jean-Michel Trivi

Bug 7170947 Update AAC codec

From Fraunhofer:
* AAC Decoder

   - Stick to the written MPEG standard instead of the MPEG reference software
     in terms of reference level normalization. Always set the program reference
     level equal to the target level. This disables level normalization using a
     default level for streams without embedded metadata.
     Modified file(s):
        libAACdec\src\aacdec_drc.cpp

   - Fix downmix channel assignment when using a WAV output channel ordering.
     Modified file(s):
        libPCMutils\src\pcmutils_lib.cpp

   - Retain signal accuracy and prevent LSB alteration when no level correction
     needs to be done.
     Modified file(s):
        libAACdec\src\aacdec_drc.h
        libAACdec\src\aacdec_drc.cpp
        libSBRdec\src\sbrdecoder.cpp
        libSBRdec\src\sbr_dec.cpp
        libSBRdec\src\sbrdec_drc.cpp

   - Align metadata processing with reference implementation.
     Modified file(s):
        libAACdec\src\aacdec_drc.h
        libAACdec\src\aacdecoder.cpp

* AAC-Encoder

   - Prevent potential overflow in energy calculation after TNS processing.
     Modified file(s):
       libAACenc\src\band_nrg.cpp

   - Added saturation for number of relevant lines which are used in pe
     calculation.
     Modified file(s):
       libAACenc\src\line_pe.cpp

   - Removed obsolete files.
     Deleded file(s):
       libAACenc\src\tns_param.h
       libAACenc\src\tns_param.cpp

* FDK-Library

   - Added x86 Count Leading Zeros intrinsic.
     Modified file(s):
        libFDK\include\clz.h
     Added file(s):
        libFDK\include\x86\clz_x86.h

   - Fixed compilation for MIPS GCC-4.4 and higher.
     Modified file(s):
        libFDK\include\mips\cplx_mul.h
        libFDK\include\mips\fixmul_mips.h

Change-Id: I4be65f07f88d412224c7fddc3f054e8f451176cc
parent ed8b5a74
This diff is collapsed.
...@@ -220,8 +220,9 @@ AAC_DECODER_ERROR aacDecoder_drcSetParam ( ...@@ -220,8 +220,9 @@ AAC_DECODER_ERROR aacDecoder_drcSetParam (
else { else {
/* ref_level must be between 0 and MAX_REFERENCE_LEVEL, inclusive */ /* ref_level must be between 0 and MAX_REFERENCE_LEVEL, inclusive */
self->digitalNorm = 1; self->digitalNorm = 1;
self->progRefLevel = AACDEC_DRC_DEFAULT_REF_LEVEL;
self->params.targetRefLevel = value; self->params.targetRefLevel = value;
self->progRefLevel = (SCHAR)value; /* Set the program reference level equal to the target
level according to 4.5.2.7.3 of ISO/IEC 14496-3. */
} }
break; break;
case APPLY_HEAVY_COMPRESSION: case APPLY_HEAVY_COMPRESSION:
...@@ -783,6 +784,7 @@ void aacDecoder_drcApply ( ...@@ -783,6 +784,7 @@ void aacDecoder_drcApply (
{ {
int band, top, bin, numBands; int band, top, bin, numBands;
int bottom = 0; int bottom = 0;
int modifyBins = 0;
FIXP_DBL max_mantissa; FIXP_DBL max_mantissa;
INT max_exponent; INT max_exponent;
...@@ -937,6 +939,12 @@ void aacDecoder_drcApply ( ...@@ -937,6 +939,12 @@ void aacDecoder_drcApply (
if (fact_exponent[band] < max_exponent) { if (fact_exponent[band] < max_exponent) {
fact_mantissa[band] >>= max_exponent - fact_exponent[band]; fact_mantissa[band] >>= max_exponent - fact_exponent[band];
} }
if (fact_mantissa[band] != FL2FXCONST_DBL(0.5f)) {
modifyBins = 1;
}
}
if (max_exponent != 1) {
modifyBins = 1;
} }
} }
...@@ -948,6 +956,12 @@ void aacDecoder_drcApply ( ...@@ -948,6 +956,12 @@ void aacDecoder_drcApply (
{ {
bottom = 0; bottom = 0;
if (!modifyBins) {
/* We don't have to modify the spectral bins because the fractional part of all factors is 0.5.
In order to keep accurancy we don't apply the factor but decrease the exponent instead. */
max_exponent -= 1;
} else
{
for (band = 0; band < numBands; band++) for (band = 0; band < numBands; band++)
{ {
top = fixMin((int)( (pDrcChData->bandTop[band]+1)<<2 ), aacFrameSize); /* ... * DRC_BAND_MULT; */ top = fixMin((int)( (pDrcChData->bandTop[band]+1)<<2 ), aacFrameSize); /* ... * DRC_BAND_MULT; */
...@@ -958,13 +972,12 @@ void aacDecoder_drcApply ( ...@@ -958,13 +972,12 @@ void aacDecoder_drcApply (
bottom = top; bottom = top;
} }
}
/* above topmost DRC band gain factor is 1 */ /* above topmost DRC band gain factor is 1 */
if (max_exponent > 0) { if (max_exponent > 0) {
FIXP_DBL fact = FL2FXCONST_DBL(0.5f) >> (max_exponent - 1); for (bin = bottom; bin < aacFrameSize; bin+=1) {
pSpectralCoefficient[bin] >>= max_exponent;
for (bin = top; bin < aacFrameSize; bin++) {
pSpectralCoefficient[bin] = fMult(pSpectralCoefficient[bin], fact);
} }
} }
...@@ -980,12 +993,13 @@ void aacDecoder_drcApply ( ...@@ -980,12 +993,13 @@ void aacDecoder_drcApply (
} }
else { else {
HANDLE_SBRDECODER hSbrDecoder = (HANDLE_SBRDECODER)pSbrDec; HANDLE_SBRDECODER hSbrDecoder = (HANDLE_SBRDECODER)pSbrDec;
UINT numBands = pDrcChData->numBands;
/* feed factors into SBR decoder for application in QMF domain. */ /* feed factors into SBR decoder for application in QMF domain. */
sbrDecoder_drcFeedChannel ( sbrDecoder_drcFeedChannel (
hSbrDecoder, hSbrDecoder,
ch, ch,
pDrcChData->numBands, numBands,
fact_mantissa, fact_mantissa,
max_exponent, max_exponent,
pDrcChData->drcInterpolationScheme, pDrcChData->drcInterpolationScheme,
......
...@@ -99,10 +99,7 @@ amm-info@iis.fraunhofer.de ...@@ -99,10 +99,7 @@ amm-info@iis.fraunhofer.de
#include "FDK_bitstream.h" #include "FDK_bitstream.h"
#define AACDEC_DRC_DEFAULT_REF_LEVEL ( 108 ) /* -27 dB below full scale (typical for movies) */ #define AACDEC_DRC_DEFAULT_REF_LEVEL ( 108 ) /* -27 dB below full scale (typical for movies) */
#define AACDEC_DRC_DFLT_EXPIRY_FRAMES ( 40 ) /* Default DRC data expiry time in AAC frames */ #define AACDEC_DRC_DFLT_EXPIRY_FRAMES ( 50 ) /* Default DRC data expiry time in AAC frames */
#define MAX_SBR_SYN_CHAN ( 64 )
#define MAX_SBR_COLS ( 32 )
/** /**
* \brief DRC module setting parameters * \brief DRC module setting parameters
......
...@@ -865,6 +865,17 @@ LINKSPEC_CPP AAC_DECODER_ERROR CAacDecoder_Init(HANDLE_AACDECODER self, const CS ...@@ -865,6 +865,17 @@ LINKSPEC_CPP AAC_DECODER_ERROR CAacDecoder_Init(HANDLE_AACDECODER self, const CS
self->chMapping[ch] = 255; self->chMapping[ch] = 255;
} }
} }
#ifdef TP_PCE_ENABLE
else {
if (CProgramConfig_IsValid(&asc->m_progrConfigElement)) {
/* Set matrix mixdown infos if available from PCE. */
pcmDmx_SetMatrixMixdownFromPce ( self->hPcmUtils,
asc->m_progrConfigElement.MatrixMixdownIndexPresent,
asc->m_progrConfigElement.MatrixMixdownIndex,
asc->m_progrConfigElement.PseudoSurroundEnable );
}
}
#endif
self->streamInfo.channelConfig = asc->m_channelConfiguration; self->streamInfo.channelConfig = asc->m_channelConfiguration;
...@@ -1565,7 +1576,7 @@ LINKSPEC_CPP AAC_DECODER_ERROR CAacDecoder_DecodeFrame( ...@@ -1565,7 +1576,7 @@ LINKSPEC_CPP AAC_DECODER_ERROR CAacDecoder_DecodeFrame(
self->streamInfo.numChannels = aacChannels; self->streamInfo.numChannels = aacChannels;
#ifdef TP_PCE_ENABLE #ifdef TP_PCE_ENABLE
if (pceRead == 1 || CProgramConfig_IsValid(pce)) { if (pceRead == 1 && CProgramConfig_IsValid(pce)) {
/* Set matrix mixdown infos if available from PCE. */ /* Set matrix mixdown infos if available from PCE. */
pcmDmx_SetMatrixMixdownFromPce ( self->hPcmUtils, pcmDmx_SetMatrixMixdownFromPce ( self->hPcmUtils,
pce->MatrixMixdownIndexPresent, pce->MatrixMixdownIndexPresent,
......
...@@ -110,7 +110,7 @@ amm-info@iis.fraunhofer.de ...@@ -110,7 +110,7 @@ amm-info@iis.fraunhofer.de
/* Decoder library info */ /* Decoder library info */
#define AACDECODER_LIB_VL0 2 #define AACDECODER_LIB_VL0 2
#define AACDECODER_LIB_VL1 4 #define AACDECODER_LIB_VL1 4
#define AACDECODER_LIB_VL2 5 #define AACDECODER_LIB_VL2 7
#define AACDECODER_LIB_TITLE "AAC Decoder Lib" #define AACDECODER_LIB_TITLE "AAC Decoder Lib"
#define AACDECODER_LIB_BUILD_DATE __DATE__ #define AACDECODER_LIB_BUILD_DATE __DATE__
#define AACDECODER_LIB_BUILD_TIME __TIME__ #define AACDECODER_LIB_BUILD_TIME __TIME__
......
...@@ -98,7 +98,7 @@ amm-info@iis.fraunhofer.de ...@@ -98,7 +98,7 @@ amm-info@iis.fraunhofer.de
/* Encoder library info */ /* Encoder library info */
#define AACENCODER_LIB_VL0 3 #define AACENCODER_LIB_VL0 3
#define AACENCODER_LIB_VL1 3 #define AACENCODER_LIB_VL1 3
#define AACENCODER_LIB_VL2 2 #define AACENCODER_LIB_VL2 3
#define AACENCODER_LIB_TITLE "AAC Encoder" #define AACENCODER_LIB_TITLE "AAC Encoder"
#define AACENCODER_LIB_BUILD_DATE __DATE__ #define AACENCODER_LIB_BUILD_DATE __DATE__
#define AACENCODER_LIB_BUILD_TIME __TIME__ #define AACENCODER_LIB_BUILD_TIME __TIME__
......
...@@ -260,21 +260,21 @@ FDKaacEnc_CalcBandEnergyOptimShort(const FIXP_DBL *RESTRICT mdctSpectrum, ...@@ -260,21 +260,21 @@ FDKaacEnc_CalcBandEnergyOptimShort(const FIXP_DBL *RESTRICT mdctSpectrum,
for(i=0; i<numBands; i++) for(i=0; i<numBands; i++)
{ {
int leadingBits = fixMax(0,sfbMaxScaleSpec[i]-4); /* max sfbWidth = 96 ; 2^7=128 => 7/2 = 4 (spc*spc) */ int leadingBits = sfbMaxScaleSpec[i]-3; /* max sfbWidth = 36 ; 2^6=64 => 6/2 = 3 (spc*spc) */
FIXP_DBL tmp = FL2FXCONST_DBL(0.0); FIXP_DBL tmp = FL2FXCONST_DBL(0.0);
for (j=bandOffset[i];j<bandOffset[i+1];j++) for (j=bandOffset[i];j<bandOffset[i+1];j++)
{ {
FIXP_DBL spec = mdctSpectrum[j]<<leadingBits; FIXP_DBL spec = scaleValue(mdctSpectrum[j],leadingBits);
tmp = fPow2AddDiv2(tmp, spec); tmp = fPow2AddDiv2(tmp, spec);
} }
bandEnergy[i] = tmp<<1; bandEnergy[i] = tmp;
} }
for(i=0; i<numBands; i++) for(i=0; i<numBands; i++)
{ {
INT scale = 2*fixMax(0,sfbMaxScaleSpec[i]-4); /* max sfbWidth = 96 ; 2^7=128 => 7/2 = 4 (spc*spc) */ INT scale = (2*(sfbMaxScaleSpec[i]-3))-1; /* max sfbWidth = 36 ; 2^6=64 => 6/2 = 3 (spc*spc) */
scale = fixMin(scale,(DFRACT_BITS-1)); scale = fixMax(fixMin(scale,(DFRACT_BITS-1)),-(DFRACT_BITS-1));
bandEnergy[i] >>= scale; bandEnergy[i] = scaleValueSaturate(bandEnergy[i], -scale);
} }
} }
......
...@@ -122,6 +122,8 @@ void FDKaacEnc_prepareSfbPe(PE_CHANNEL_DATA *peChanData, ...@@ -122,6 +122,8 @@ void FDKaacEnc_prepareSfbPe(PE_CHANNEL_DATA *peChanData,
avgFormFactorLdData = ((-sfbEnergyLdData[sfbGrp+sfb]>>1) + (CalcLdInt(sfbWidth)>>1))>>1; avgFormFactorLdData = ((-sfbEnergyLdData[sfbGrp+sfb]>>1) + (CalcLdInt(sfbWidth)>>1))>>1;
peChanData->sfbNLines[sfbGrp+sfb] = peChanData->sfbNLines[sfbGrp+sfb] =
(INT)CalcInvLdData( (sfbFormFactorLdData[sfbGrp+sfb] + formFacScaling) + avgFormFactorLdData); (INT)CalcInvLdData( (sfbFormFactorLdData[sfbGrp+sfb] + formFacScaling) + avgFormFactorLdData);
/* Make sure sfbNLines is never greater than sfbWidth due to unaccuracies (e.g. sfbEnergyLdData[sfbGrp+sfb] = 0x80000000) */
peChanData->sfbNLines[sfbGrp+sfb] = fMin(sfbWidth, peChanData->sfbNLines[sfbGrp+sfb]);
} }
else { else {
peChanData->sfbNLines[sfbGrp+sfb] = 0; peChanData->sfbNLines[sfbGrp+sfb] = 0;
......
/* -----------------------------------------------------------------------------------------------------------
Software License for The Fraunhofer FDK AAC Codec Library for Android
© Copyright 1995 - 2012 Fraunhofer-Gesellschaft zur Förderung der angewandten Forschung e.V.
All rights reserved.
1. INTRODUCTION
The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software that implements
the MPEG Advanced Audio Coding ("AAC") encoding and decoding scheme for digital audio.
This FDK AAC Codec software is intended to be used on a wide variety of Android devices.
AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient general perceptual
audio codecs. AAC-ELD is considered the best-performing full-bandwidth communications codec by
independent studies and is widely deployed. AAC has been standardized by ISO and IEC as part
of the MPEG specifications.
Patent licenses for necessary patent claims for the FDK AAC Codec (including those of Fraunhofer)
may be obtained through Via Licensing (www.vialicensing.com) or through the respective patent owners
individually for the purpose of encoding or decoding bit streams in products that are compliant with
the ISO/IEC MPEG audio standards. Please note that most manufacturers of Android devices already license
these patent claims through Via Licensing or directly from the patent owners, and therefore FDK AAC Codec
software may already be covered under those patent licenses when it is used for those licensed purposes only.
Commercially-licensed AAC software libraries, including floating-point versions with enhanced sound quality,
are also available from Fraunhofer. Users are encouraged to check the Fraunhofer website for additional
applications information and documentation.
2. COPYRIGHT LICENSE
Redistribution and use in source and binary forms, with or without modification, are permitted without
payment of copyright license fees provided that you satisfy the following conditions:
You must retain the complete text of this software license in redistributions of the FDK AAC Codec or
your modifications thereto in source code form.
You must retain the complete text of this software license in the documentation and/or other materials
provided with redistributions of the FDK AAC Codec or your modifications thereto in binary form.
You must make available free of charge copies of the complete source code of the FDK AAC Codec and your
modifications thereto to recipients of copies in binary form.
The name of Fraunhofer may not be used to endorse or promote products derived from this library without
prior written permission.
You may not charge copyright license fees for anyone to use, copy or distribute the FDK AAC Codec
software or your modifications thereto.
Your modified versions of the FDK AAC Codec must carry prominent notices stating that you changed the software
and the date of any change. For modified versions of the FDK AAC Codec, the term
"Fraunhofer FDK AAC Codec Library for Android" must be replaced by the term
"Third-Party Modified Version of the Fraunhofer FDK AAC Codec Library for Android."
3. NO PATENT LICENSE
NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without limitation the patents of Fraunhofer,
ARE GRANTED BY THIS SOFTWARE LICENSE. Fraunhofer provides no warranty of patent non-infringement with
respect to this software.
You may use this FDK AAC Codec software or modifications thereto only for purposes that are authorized
by appropriate patent licenses.
4. DISCLAIMER
This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright holders and contributors
"AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, including but not limited to the implied warranties
of merchantability and fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary, or consequential damages,
including but not limited to procurement of substitute goods or services; loss of use, data, or profits,
or business interruption, however caused and on any theory of liability, whether in contract, strict
liability, or tort (including negligence), arising in any way out of the use of this software, even if
advised of the possibility of such damage.
5. CONTACT INFORMATION
Fraunhofer Institute for Integrated Circuits IIS
Attention: Audio and Multimedia Departments - FDK AAC LL
Am Wolfsmantel 33
91058 Erlangen, Germany
www.iis.fraunhofer.de/amm
amm-info@iis.fraunhofer.de
----------------------------------------------------------------------------------------------------------- */
/******************************** MPEG Audio Encoder **************************
Initial author: M.Werner
contents/description: TNS parameters
******************************************************************************/
#include "tns_param.h"
...@@ -155,7 +155,6 @@ amm-info@iis.fraunhofer.de ...@@ -155,7 +155,6 @@ amm-info@iis.fraunhofer.de
#endif #endif
/* Define preferred Multiplication type */ /* Define preferred Multiplication type */
#if defined(FDK_HIGH_PERFORMANCE) && !defined(FDK_HIGH_QUALITY) /* FDK_HIGH_PERFORMANCE */ #if defined(FDK_HIGH_PERFORMANCE) && !defined(FDK_HIGH_QUALITY) /* FDK_HIGH_PERFORMANCE */
......
...@@ -100,6 +100,9 @@ amm-info@iis.fraunhofer.de ...@@ -100,6 +100,9 @@ amm-info@iis.fraunhofer.de
#elif defined(__mips__) /* cppp replaced: elif */ #elif defined(__mips__) /* cppp replaced: elif */
#include "mips/clz_mips.h" #include "mips/clz_mips.h"
#elif defined(__x86__) /* cppp replaced: elif */
#include "x86/clz_x86.h"
#endif /* all cores */ #endif /* all cores */
......
...@@ -108,9 +108,22 @@ inline void cplxMultDiv2( FIXP_DBL *c_Re, ...@@ -108,9 +108,22 @@ inline void cplxMultDiv2( FIXP_DBL *c_Re,
FIXP_DBL b_Im) FIXP_DBL b_Im)
{ {
INT result; INT result;
result = (((long long)a_Re * b_Re) - ((long long) a_Im * b_Im)) >> 32;
__asm__ ("mult %[a_Re], %[b_Re];\n"
"msub %[a_Im], %[b_Im];\n"
"mfhi %[result];\n"
: [result]"=r"(result)
: [a_Re]"d"(a_Re), [b_Re]"d"(b_Re), [a_Im]"d"(a_Im), [b_Im]"d"(b_Im)
: "lo");
*c_Re = result; *c_Re = result;
result = (((long long)a_Re * b_Im) - ((long long) a_Im * b_Re)) >> 32;
__asm__ ("mult %[a_Re], %[b_Im];\n"
"madd %[a_Im], %[b_Re];\n"
"mfhi %[result];\n"
: [result]"=r"(result)
: [a_Re]"r"(a_Re), [b_Im]"r"(b_Im), [a_Im]"r"(a_Im), [b_Re]"r"(b_Re)
: "lo");
*c_Im = result; *c_Im = result;
} }
#endif #endif
...@@ -124,9 +137,23 @@ inline void cplxMult( FIXP_DBL *c_Re, ...@@ -124,9 +137,23 @@ inline void cplxMult( FIXP_DBL *c_Re,
FIXP_DBL b_Im) FIXP_DBL b_Im)
{ {
INT result; INT result;
result = (((long long)a_Re * b_Re) - ((long long) a_Im * b_Im)) >> 32;
__asm__ ("mult %[a_Re], %[b_Re];\n"
"msub %[a_Im], %[b_Im];\n"
"mfhi %[result];\n"
//"extr_w %[result], 31;\n"
: [result]"=r"(result)
: [a_Re]"r"(a_Re), [b_Re]"r"(b_Re), [a_Im]"r"(a_Im), [b_Im]"r"(b_Im)
: "lo");
*c_Re = result<<1; *c_Re = result<<1;
result = (((long long)a_Re * b_Im) - ((long long) a_Im * b_Re)) >> 32;
__asm__ ("mult %[a_Re], %[b_Im];\n"
"madd %[a_Im], %[b_Re];\n"
"mfhi %[result];\n"
//"extr_w %[result], 31;\n"
: [result]"=r"(result)
: [a_Re]"r"(a_Re), [b_Im]"r"(b_Im), [a_Im]"r"(a_Im), [b_Re]"r"(b_Re)
: "lo");
*c_Im = result<<1; *c_Im = result<<1;
} }
#endif #endif
......
...@@ -100,11 +100,14 @@ amm-info@iis.fraunhofer.de ...@@ -100,11 +100,14 @@ amm-info@iis.fraunhofer.de
inline INT fixmuldiv2_DD (const INT a, const INT b) inline INT fixmuldiv2_DD (const INT a, const INT b)
{ {
INT result ;
return ((long long) a * b) >> 32; result = ((long long)a * b)>>32;
return result ;
} }
#endif /* (__GNUC__) && defined(__mips__) */ #endif /* (__GNUC__) && defined(__mips__) */
#endif /* __mips__ */ #endif /* __mips__ */
#define FUNCTION_fixmulBitExact_DD
#define fixmulBitExact_DD fixmul_DD
...@@ -81,16 +81,74 @@ www.iis.fraunhofer.de/amm ...@@ -81,16 +81,74 @@ www.iis.fraunhofer.de/amm
amm-info@iis.fraunhofer.de amm-info@iis.fraunhofer.de
----------------------------------------------------------------------------------------------------------- */ ----------------------------------------------------------------------------------------------------------- */
/******************************** MPEG Audio Encoder ************************** /*************************** Fraunhofer IIS FDK Tools **********************
Initial author: Alex Goeschel Author(s):
contents/description: Temporal noise shaping Description: fixed point intrinsics
******************************************************************************/ ******************************************************************************/
#ifndef _TNS_PARAM_H #if defined(__GNUC__) && (defined(__x86__) || defined(__x86_64__))
#define _TNS_PARAM_H
#define FUNCTION_fixnormz_D
#define FUNCTION_fixnorm_D
#endif /* _TNS_PARAM_H */ inline INT fixnormz_D(LONG value)
{
INT result;
if (value != 0) {
result = __builtin_clz(value);
} else {
result = 32;
}
return result;
}
inline INT fixnorm_D(LONG value)
{
INT result;
if (value == 0) {
return 0;
}
if (value < 0) {
value = ~value;
}
result = fixnormz_D(value);
return result - 1;
}
#elif defined(_MSC_VER) && (defined(_M_IX86) || defined(_M_X64))
#include <intrin.h>
#define FUNCTION_fixnormz_D
#define FUNCTION_fixnorm_D
inline INT fixnormz_D(LONG value)
{
unsigned long result = 0;
unsigned char err;
err = _BitScanReverse(&result, value);
if (err) {
return 31 - result;
} else {
return 32;
}
}
inline INT fixnorm_D(LONG value)
{
INT result;
if (value == 0) {
return 0;
}
if (value < 0) {
value = ~value;
}
result = fixnormz_D(value);
return result - 1;
}
#endif /* toolchain */
...@@ -93,7 +93,7 @@ amm-info@iis.fraunhofer.de ...@@ -93,7 +93,7 @@ amm-info@iis.fraunhofer.de
/* FDK tools library info */ /* FDK tools library info */
#define FDK_TOOLS_LIB_VL0 2 #define FDK_TOOLS_LIB_VL0 2
#define FDK_TOOLS_LIB_VL1 2 #define FDK_TOOLS_LIB_VL1 2
#define FDK_TOOLS_LIB_VL2 7 #define FDK_TOOLS_LIB_VL2 8
#define FDK_TOOLS_LIB_TITLE "FDK Tools" #define FDK_TOOLS_LIB_TITLE "FDK Tools"
#define FDK_TOOLS_LIB_BUILD_DATE __DATE__ #define FDK_TOOLS_LIB_BUILD_DATE __DATE__
#define FDK_TOOLS_LIB_BUILD_TIME __TIME__ #define FDK_TOOLS_LIB_BUILD_TIME __TIME__
......
...@@ -96,7 +96,7 @@ amm-info@iis.fraunhofer.de ...@@ -96,7 +96,7 @@ amm-info@iis.fraunhofer.de
/* Decoder library info */ /* Decoder library info */
#define PCMDMX_LIB_VL0 2 #define PCMDMX_LIB_VL0 2
#define PCMDMX_LIB_VL1 2 #define PCMDMX_LIB_VL1 3
#define PCMDMX_LIB_VL2 1 #define PCMDMX_LIB_VL2 1
#define PCMDMX_LIB_TITLE "PCM Downmix Lib" #define PCMDMX_LIB_TITLE "PCM Downmix Lib"
#define PCMDMX_LIB_BUILD_DATE __DATE__ #define PCMDMX_LIB_BUILD_DATE __DATE__
...@@ -107,7 +107,7 @@ amm-info@iis.fraunhofer.de ...@@ -107,7 +107,7 @@ amm-info@iis.fraunhofer.de
#define PCM_DMX_MAX_CHANNELS ( 8 ) #define PCM_DMX_MAX_CHANNELS ( 8 )
#define PCM_DMX_MAX_CHANNEL_GROUPS ( 4 ) #define PCM_DMX_MAX_CHANNEL_GROUPS ( 4 )
#define PCM_DMX_MAX_CHANNELS_PER_GROUP ( 3 ) /* The maximum over all groups */ #define PCM_DMX_MAX_CHANNELS_PER_GROUP ( 3 ) /* The maximum over all groups */
#define PCMDMX_DFLT_EXPIRY_FRAME ( 40 ) /* At least 400ms (FL 960 @ 96kHz) */ #define PCMDMX_DFLT_EXPIRY_FRAME ( 50 ) /* At least 500ms (FL 960 @ 96kHz) */
/* Fixed and unique channel group indices. /* Fixed and unique channel group indices.
* The last group index has to be smaller than PCM_DMX_MAX_CHANNEL_GROUPS. */ * The last group index has to be smaller than PCM_DMX_MAX_CHANNEL_GROUPS. */
...@@ -264,7 +264,6 @@ C_ALLOC_MEM_STATIC(PcmDmxInstance, struct PCM_DMX_INSTANCE, 1) ...@@ -264,7 +264,6 @@ C_ALLOC_MEM_STATIC(PcmDmxInstance, struct PCM_DMX_INSTANCE, 1)
* @param [in] The total number of channels of the given configuration. * @param [in] The total number of channels of the given configuration.
* @param [in] Array holding the corresponding channel types for each channel. * @param [in] Array holding the corresponding channel types for each channel.
* @param [in] Array holding the corresponding channel type indices for each channel. * @param [in] Array holding the corresponding channel type indices for each channel.
* @param [in] Array containing the channel mapping to be used (From MPEG PCE ordering to whatever is required).
* @param [out] Array where the buffer offsets for each channel are stored into. * @param [out] Array where the buffer offsets for each channel are stored into.
* @returns Returns the packed channel mode. * @returns Returns the packed channel mode.
**/ **/
...@@ -273,7 +272,6 @@ PCM_DMX_CHANNEL_MODE getChannelMode ( ...@@ -273,7 +272,6 @@ PCM_DMX_CHANNEL_MODE getChannelMode (
const INT numChannels, /* in */ const INT numChannels, /* in */
const AUDIO_CHANNEL_TYPE channelType[], /* in */ const AUDIO_CHANNEL_TYPE channelType[], /* in */
const UCHAR channelIndices[], /* in */ const UCHAR channelIndices[], /* in */
const UCHAR channelMapping[PCM_DMX_MAX_CHANNELS], /* in */
UCHAR offsetTable[PCM_DMX_MAX_CHANNELS] /* out */ UCHAR offsetTable[PCM_DMX_MAX_CHANNELS] /* out */
) )
{ {
...@@ -284,12 +282,12 @@ PCM_DMX_CHANNEL_MODE getChannelMode ( ...@@ -284,12 +282,12 @@ PCM_DMX_CHANNEL_MODE getChannelMode (
FDK_ASSERT(channelType != NULL); FDK_ASSERT(channelType != NULL);
FDK_ASSERT(channelIndices != NULL); FDK_ASSERT(channelIndices != NULL);
FDK_ASSERT(channelMapping != NULL);
FDK_ASSERT(offsetTable != NULL); FDK_ASSERT(offsetTable != NULL);
/* For details see ISO/IEC 13818-7:2005(E), 8.5.3 Channel configuration */ /* For details see ISO/IEC 13818-7:2005(E), 8.5.3 Channel configuration */
FDKmemclear(numChInGrp, PCM_DMX_MAX_CHANNEL_GROUPS*sizeof(UCHAR)); FDKmemclear(numChInGrp, PCM_DMX_MAX_CHANNEL_GROUPS*sizeof(UCHAR));
FDKmemset(offsetTable, 255, PCM_DMX_MAX_CHANNELS*sizeof(UCHAR)); FDKmemset(offsetTable, 255, PCM_DMX_MAX_CHANNELS*sizeof(UCHAR));
FDKmemset(chIdx, 255, PCM_DMX_MAX_CHANNEL_GROUPS*PCM_DMX_MAX_CHANNELS_PER_GROUP*sizeof(UCHAR));
/* Categorize channels */ /* Categorize channels */
for (ch = 0; ch < numChannels; ch += 1) { for (ch = 0; ch < numChannels; ch += 1) {
...@@ -335,7 +333,7 @@ PCM_DMX_CHANNEL_MODE getChannelMode ( ...@@ -335,7 +333,7 @@ PCM_DMX_CHANNEL_MODE getChannelMode (
if (numChInGrp[CH_GROUP_FRONT] & 0x1) { if (numChInGrp[CH_GROUP_FRONT] & 0x1) {
/* Odd number of front channels -> we have a center channel. /* Odd number of front channels -> we have a center channel.
In MPEG-4 the center has the index 0. */ In MPEG-4 the center has the index 0. */
offsetTable[CENTER_FRONT_CHANNEL] = channelMapping[chIdx[CH_GROUP_FRONT][0]]; offsetTable[CENTER_FRONT_CHANNEL] = chIdx[CH_GROUP_FRONT][0];
} }
for (grpIdx = 0; grpIdx < PCM_DMX_MAX_CHANNEL_GROUPS; grpIdx += 1) { for (grpIdx = 0; grpIdx < PCM_DMX_MAX_CHANNEL_GROUPS; grpIdx += 1) {
...@@ -367,7 +365,7 @@ PCM_DMX_CHANNEL_MODE getChannelMode ( ...@@ -367,7 +365,7 @@ PCM_DMX_CHANNEL_MODE getChannelMode (
for ( ; ch < numChInGrp[grpIdx]; ch += 1) { for ( ; ch < numChInGrp[grpIdx]; ch += 1) {
if (ch < maxChannels) { if (ch < maxChannels) {
offsetTable[chMapPos] = channelMapping[chIdx[grpIdx][ch]]; offsetTable[chMapPos] = chIdx[grpIdx][ch];
chMapPos += 1; chMapPos += 1;
} else { } else {
err = -1; err = -1;
...@@ -814,7 +812,6 @@ PCMDMX_ERROR pcmDmx_ApplyFrame ( ...@@ -814,7 +812,6 @@ PCMDMX_ERROR pcmDmx_ApplyFrame (
numInChannels, numInChannels,
channelType, channelType,
channelIndices, channelIndices,
channelMapping[numInChannels],
inOffsetTable inOffsetTable
); );
if (inChMode == CH_MODE_UNDEFINED) { if (inChMode == CH_MODE_UNDEFINED) {
......
...@@ -585,6 +585,7 @@ sbr_dec ( HANDLE_SBR_DEC hSbrDec, /*!< handle to Decoder channel */ ...@@ -585,6 +585,7 @@ sbr_dec ( HANDLE_SBR_DEC hSbrDec, /*!< handle to Decoder channel */
int maxShift = 0; int maxShift = 0;
if (hSbrDec->sbrDrcChannel.enable != 0) {
if (hSbrDec->sbrDrcChannel.prevFact_exp > maxShift) { if (hSbrDec->sbrDrcChannel.prevFact_exp > maxShift) {
maxShift = hSbrDec->sbrDrcChannel.prevFact_exp; maxShift = hSbrDec->sbrDrcChannel.prevFact_exp;
} }
...@@ -594,6 +595,7 @@ sbr_dec ( HANDLE_SBR_DEC hSbrDec, /*!< handle to Decoder channel */ ...@@ -594,6 +595,7 @@ sbr_dec ( HANDLE_SBR_DEC hSbrDec, /*!< handle to Decoder channel */
if (hSbrDec->sbrDrcChannel.nextFact_exp > maxShift) { if (hSbrDec->sbrDrcChannel.nextFact_exp > maxShift) {
maxShift = hSbrDec->sbrDrcChannel.nextFact_exp; maxShift = hSbrDec->sbrDrcChannel.nextFact_exp;
} }
}
/* copy DRC data to right channel (with PS both channels use the same DRC gains) */ /* copy DRC data to right channel (with PS both channels use the same DRC gains) */
FDKmemcpy(&hSbrDecRight->sbrDrcChannel, &hSbrDec->sbrDrcChannel, sizeof(SBRDEC_DRC_CHANNEL)); FDKmemcpy(&hSbrDecRight->sbrDrcChannel, &hSbrDec->sbrDrcChannel, sizeof(SBRDEC_DRC_CHANNEL));
......
...@@ -115,17 +115,17 @@ void sbrDecoder_drcInitChannel ( ...@@ -115,17 +115,17 @@ void sbrDecoder_drcInitChannel (
} }
for (band = 0; band < (64); band++) { for (band = 0; band < (64); band++) {
hDrcData->prevFact_mag[band] = (FIXP_DBL)MAXVAL_DBL /*FL2FXCONST_DBL(1.0f)*/; hDrcData->prevFact_mag[band] = FL2FXCONST_DBL(0.5f);
} }
for (band = 0; band < SBRDEC_MAX_DRC_BANDS; band++) { for (band = 0; band < SBRDEC_MAX_DRC_BANDS; band++) {
hDrcData->currFact_mag[band] = (FIXP_DBL)MAXVAL_DBL /*FL2FXCONST_DBL(1.0f)*/; hDrcData->currFact_mag[band] = FL2FXCONST_DBL(0.5f);
hDrcData->nextFact_mag[band] = (FIXP_DBL)MAXVAL_DBL /*FL2FXCONST_DBL(1.0f)*/; hDrcData->nextFact_mag[band] = FL2FXCONST_DBL(0.5f);
} }
hDrcData->prevFact_exp = 0; hDrcData->prevFact_exp = 1;
hDrcData->currFact_exp = 0; hDrcData->currFact_exp = 1;
hDrcData->nextFact_exp = 0; hDrcData->nextFact_exp = 1;
hDrcData->numBandsCurr = 0; hDrcData->numBandsCurr = 0;
hDrcData->numBandsNext = 0; hDrcData->numBandsNext = 0;
...@@ -238,7 +238,7 @@ void sbrDecoder_drcApplySlot ( ...@@ -238,7 +238,7 @@ void sbrDecoder_drcApplySlot (
} }
else { else {
if (j >= offset[hDrcData->drcInterpolationSchemeCurr - 1]) { if (j >= offset[hDrcData->drcInterpolationSchemeCurr - 1]) {
alphaValue = FL2FXCONST_DBL(1.0f); alphaValue = (FIXP_DBL)MAXVAL_DBL;
} }
} }
} }
...@@ -262,7 +262,7 @@ void sbrDecoder_drcApplySlot ( ...@@ -262,7 +262,7 @@ void sbrDecoder_drcApplySlot (
} }
else { else {
if (j >= offset[hDrcData->drcInterpolationSchemeNext - 1]) { if (j >= offset[hDrcData->drcInterpolationSchemeNext - 1]) {
alphaValue = FL2FXCONST_DBL(1.0f); alphaValue = (FIXP_DBL)MAXVAL_DBL;
} }
} }
...@@ -301,7 +301,7 @@ void sbrDecoder_drcApplySlot ( ...@@ -301,7 +301,7 @@ void sbrDecoder_drcApplySlot (
} }
else { else {
if (j >= offset[hDrcData->drcInterpolationSchemeNext - 1]) { if (j >= offset[hDrcData->drcInterpolationSchemeNext - 1]) {
alphaValue = FL2FXCONST_DBL(1.0f); alphaValue = (FIXP_DBL)MAXVAL_DBL;
} }
} }
} }
...@@ -322,7 +322,7 @@ void sbrDecoder_drcApplySlot ( ...@@ -322,7 +322,7 @@ void sbrDecoder_drcApplySlot (
for (band = 0; band < (int)numBands; band++) { for (band = 0; band < (int)numBands; band++) {
int bottomQmf, topQmf; int bottomQmf, topQmf;
FIXP_DBL drcFact_mag = FL2FXCONST_DBL(1.0f); FIXP_DBL drcFact_mag = (FIXP_DBL)MAXVAL_DBL;
topMdct = (bandTop[band]+1) << 2; topMdct = (bandTop[band]+1) << 2;
...@@ -361,7 +361,13 @@ void sbrDecoder_drcApplySlot ( ...@@ -361,7 +361,13 @@ void sbrDecoder_drcApplySlot (
} }
/* interpolate */ /* interpolate */
drcFact_mag = fMult(alphaValue, drcFact2_mag) + fMult((FL2FXCONST_DBL(1.0f) - alphaValue), drcFact1_mag); if (alphaValue == (FIXP_DBL)0) {
drcFact_mag = drcFact1_mag;
} else if (alphaValue == (FIXP_DBL)MAXVAL_DBL) {
drcFact_mag = drcFact2_mag;
} else {
drcFact_mag = fMult(alphaValue, drcFact2_mag) + fMult(((FIXP_DBL)MAXVAL_DBL - alphaValue), drcFact1_mag);
}
/* apply scaling */ /* apply scaling */
qmfRealSlot[bin] = fMult(qmfRealSlot[bin], drcFact_mag); qmfRealSlot[bin] = fMult(qmfRealSlot[bin], drcFact_mag);
...@@ -481,6 +487,15 @@ void sbrDecoder_drcApply ( ...@@ -481,6 +487,15 @@ void sbrDecoder_drcApply (
int col; int col;
int maxShift = 0; int maxShift = 0;
if (hDrcData == NULL) {
return;
}
if ( (hDrcData->enable == 0)
|| ((hDrcData->numBandsCurr == 0) && (hDrcData->numBandsNext == 0))
) {
return; /* Avoid changing the scaleFactor even though the processing is disabled. */
}
/* get max scale factor */ /* get max scale factor */
if (hDrcData->prevFact_exp > maxShift) { if (hDrcData->prevFact_exp > maxShift) {
maxShift = hDrcData->prevFact_exp; maxShift = hDrcData->prevFact_exp;
......
...@@ -94,6 +94,7 @@ amm-info@iis.fraunhofer.de ...@@ -94,6 +94,7 @@ amm-info@iis.fraunhofer.de
#include "sbrdecoder.h" #include "sbrdecoder.h"
#define SBRDEC_MAX_DRC_CHANNELS (6) #define SBRDEC_MAX_DRC_CHANNELS (6)
#define SBRDEC_MAX_DRC_BANDS ( 16 ) #define SBRDEC_MAX_DRC_BANDS ( 16 )
......
...@@ -137,7 +137,7 @@ amm-info@iis.fraunhofer.de ...@@ -137,7 +137,7 @@ amm-info@iis.fraunhofer.de
/* Decoder library info */ /* Decoder library info */
#define SBRDECODER_LIB_VL0 2 #define SBRDECODER_LIB_VL0 2
#define SBRDECODER_LIB_VL1 1 #define SBRDECODER_LIB_VL1 1
#define SBRDECODER_LIB_VL2 2 #define SBRDECODER_LIB_VL2 3
#define SBRDECODER_LIB_TITLE "SBR Decoder" #define SBRDECODER_LIB_TITLE "SBR Decoder"
#define SBRDECODER_LIB_BUILD_DATE __DATE__ #define SBRDECODER_LIB_BUILD_DATE __DATE__
#define SBRDECODER_LIB_BUILD_TIME __TIME__ #define SBRDECODER_LIB_BUILD_TIME __TIME__
...@@ -818,6 +818,7 @@ SBR_ERROR sbrDecoder_drcFeedChannel ( HANDLE_SBRDECODER self, ...@@ -818,6 +818,7 @@ SBR_ERROR sbrDecoder_drcFeedChannel ( HANDLE_SBRDECODER self,
USHORT *pBandTop ) USHORT *pBandTop )
{ {
SBRDEC_DRC_CHANNEL *pSbrDrcChannelData = NULL; SBRDEC_DRC_CHANNEL *pSbrDrcChannelData = NULL;
int band, isValidData = 0;
if (self == NULL) { if (self == NULL) {
return SBRDEC_NOT_INITIALIZED; return SBRDEC_NOT_INITIALIZED;
...@@ -826,10 +827,21 @@ SBR_ERROR sbrDecoder_drcFeedChannel ( HANDLE_SBRDECODER self, ...@@ -826,10 +827,21 @@ SBR_ERROR sbrDecoder_drcFeedChannel ( HANDLE_SBRDECODER self,
return SBRDEC_SET_PARAM_FAIL; return SBRDEC_SET_PARAM_FAIL;
} }
/* Search for gain values different to 1.0f */
for (band = 0; band < numBands; band += 1) {
if ( !((pNextFact_mag[band] == FL2FXCONST_DBL(0.5)) && (nextFact_exp == 1))
&& !((pNextFact_mag[band] == (FIXP_DBL)MAXVAL_DBL) && (nextFact_exp == 0)) ) {
isValidData = 1;
break;
}
}
/* Find the right SBR channel */ /* Find the right SBR channel */
pSbrDrcChannelData = sbrDecoder_drcGetChannel( self, ch ); pSbrDrcChannelData = sbrDecoder_drcGetChannel( self, ch );
if ( pSbrDrcChannelData != NULL ) { if ( pSbrDrcChannelData != NULL ) {
if ( pSbrDrcChannelData->enable || isValidData )
{ /* Activate processing only with real and valid data */
int i; int i;
pSbrDrcChannelData->enable = 1; pSbrDrcChannelData->enable = 1;
...@@ -844,6 +856,7 @@ SBR_ERROR sbrDecoder_drcFeedChannel ( HANDLE_SBRDECODER self, ...@@ -844,6 +856,7 @@ SBR_ERROR sbrDecoder_drcFeedChannel ( HANDLE_SBRDECODER self,
pSbrDrcChannelData->nextFact_mag[i] = pNextFact_mag[i]; pSbrDrcChannelData->nextFact_mag[i] = pNextFact_mag[i];
} }
} }
}
return SBRDEC_OK; return SBRDEC_OK;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment