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
This commit is contained in:
Jean-Michel Trivi 2012-10-02 10:16:04 -07:00
parent ed8b5a747e
commit 6ab36997af
21 changed files with 1440 additions and 1387 deletions

File diff suppressed because it is too large Load Diff

View File

@ -632,7 +632,11 @@ endobj
/Filter /FlateDecode
>>
stream
xÚ}UM“Û6 ½ûWè(ͬi,«7w×I·“vÒÄ·´®DYl%R¥¨u¶¿¾à‡d;q;ž±@À@GïWø?¾þqD¢”GÛ¢D%É£ª_ý½Âg4uûW¢ÛÊ1ÆÞ1#å¬Þ<÷$zR«ßà7‡]û¸ë«À?Ww”F4CÅ® ѱ‰Jå»ådëèK¼¯_c&+^'kšãxŸÀßT å—<C3A5>ªòä僬TÍuòÇñg€@„SæƒxÑL¿Ù@L!Y”f[jÁ0/PIà/ï×ÔÇc2`:eð÷I°~ñA%4<>ÏëGÕOHæ-ÙæñÃœM¡Ü«Ø!ÌOâÔ®<0F>uÿcZ .+ëÿvå•Þ»í Û+ŠBV~ñÄ;öMÐï3ãæ\Gv¨Ün³@ÉKD³Â[¾Ól­jÀØÅ|–£f2~ÕL½á'-¸6Ü+>W-ëÌ$O\‹çÏ I£2/ÿ!Äq”©fæÊ…NÈ.®&aÆeéúmUW<55>­›Íù|¶­CBŒ¨¹dƒªæÖ÷÷ù)1ÊËéIŒUÇD¿pù-*ÔÜÛ>ËFéž¡€´Hc¾¦£—jUM=—&ìí8½üÉ« <C38A>Þ„Ä@¯_ž…iÕl¤2¢â(±‡/¶³Ê¤àãC²ÎpKÖ/²ø´  ó¾ÓÈëÛôüœ3;ñãÒÀ«ºZ®¹pMÎc¦¹Ü<>C…šF¯™$øYp:1C¾¼†tSº<53>?jUO• áü‰ÌãJéAÙÆ{?íyüöŒf5ï™þkÆÒþ«]'1È·þÎöNaª±d>[/V3™Ü<>-§Øîºê­p!±QÁÓ³8tL.enhGîšè7¤š{`Â8d¡óè w )ì»Îë5\1f 2¹~µ<>ŽXk÷kp˜67Õn¯ª¥tžFJâazéD5§ [Žk+X®­…æƒk—«ô®XÐOFtâŸY+;“3W`bϵ ;WfÉ™´ÓšÂMÆ;w&4MIQÝúöÎhYgmÓ0«nrOÅ<4F>Æ­2ªRƒ}jÞçd¹þ{Qie¸ë¼f9]v1pÝqt¬Øµß³†qŸƒ5Zõ^‚á ~–α 7ŒÍkyÝÅïäÖ>KMDKŠ2…+»@ðÎú¤?q{¾Š pŠRž®<C5BE>ç~:McH“AI1¡7h‡ãê_Í(?
xÚ}UM“£6½ûWp„ª1<02>Ém2ãÝLj“Úd|Kr<4B>A% !Æ;ùõi}€ñ®“r•iµºûu¿nI(8¸AÿñMàI<>¢$&A^”q™<71> ê7oPŒ2œÚý•h·BÈ9fI9«w/}<ËÍ/ðÃn]Üí*ð÷ÇÍîÆÎâb_$Á± J<14>}“$Žuð[øX¿E
©¨Xm1AácSÍ¥[>Éš‹³“¢5SÑÇc”º0ŸøIQõnv1…dã4˱ACRÄ%ö€?}>|Üb<17>
<EFBFBD>i•™ÇŒ2€uO2Â$¼lŸd?t,JHø…ë÷('áÃœN¡ÜUlæ~n·‡Æ¸ÿŽ®8•ñ¿ƒò†o݉víŠ"Ÿ•[<³Ž~ôÛÌØ•9Û}\æyæéIHã¬p<14>D+0¶1_Ĩ¹ž´[5ÓU¯ÙYq¦4sŠ×ª¥<C2AA>žÄ™ oñòº<C3B2> ¸$åÿ#ø82yƒBõ\ùWQ²«‰ëqAYº~[Õ
²Õzøn·»\.¦u1çcÜ\³  ªÙŽöý}~J“ÒGzæcÕQÞ/\~<7E>š*q¶/¢ª§šK`$-Ò<>û¯nùè¤ZVSÏ„öû^;N§?Yå•Zº/Ð%!Ðë–®[9y!5¯X™ÃšY¥³ñ!Úf( íÙN|Zà°¦š:ßidõmznΩ™øqiમ)Æm“IHsrè#—Óè4“/K N>zcÈ—Õ<E28094>nŠóð³õTiÎ<>HVR Ò4Þ;˜œØ»i'áÉïiEkÖSõ׌¥ÜWÙ:Î|Ô<><6F>í<EFBFBD>ÂdcÈ\¶N¬f2 ¹û$<¶ÌŸb³k«7•ÄFzOÇâÐQ±LD<16>¿= Ä6Ñm9÷@ûqÈ|ç3Ð5
î@æSxì:§WpÅèÑËldêÍ@Zb<5A>ÝÏÞ} JßT¯ªÅxžFœ„Ãtêx5§ [k#®<>…bƒm—­ô¶XÐOšwüŸY˽;3W`bÎÂÚ ú<E2809A>@2*Ì´¦p“±ŽÁ<C5BD> M“W·¾=ƒóÛ´̪ìSq§±C+µ¬ä`žš÷å9Y®ÿžWJšîú§YN—Y Lõ|-+fÍý÷¢`Üç`<60>½“`x¼Ÿ¡slý còZÞb{qÀ;™g© p/T<0E>'.bxg]Ò¿2s¾ñ+pÃω>ÏW6hÖŸæ«^<5E>QoÇÍ¿_])t
endstream
endobj
418 0 obj <<
@ -8985,8 +8989,8 @@ endobj
>> endobj
1416 0 obj <<
/Author()/Title()/Subject()/Creator(LaTeX with hyperref package)/Producer(pdfTeX-1.40.10)/Keywords()
/CreationDate (D:20120817142105+02'00')
/ModDate (D:20120817142105+02'00')
/CreationDate (D:20120927164403+02'00')
/ModDate (D:20120927164403+02'00')
/Trapped /False
/PTEX.Fullbanner (This is pdfTeX, Version 3.1415926-1.40.10-2.2 (TeX Live 2009/Debian) kpathsea version 5.0.0)
>> endobj
@ -10413,7 +10417,7 @@ trailer
<< /Size 1417
/Root 1415 0 R
/Info 1416 0 R
/ID [<09BA174B99D03051E2360592CE4C1DF3> <09BA174B99D03051E2360592CE4C1DF3>] >>
/ID [<6568D5E6D3D414DEC0C8E7A6930872CF> <6568D5E6D3D414DEC0C8E7A6930872CF>] >>
startxref
508901
%%EOF

View File

@ -220,8 +220,9 @@ AAC_DECODER_ERROR aacDecoder_drcSetParam (
else {
/* ref_level must be between 0 and MAX_REFERENCE_LEVEL, inclusive */
self->digitalNorm = 1;
self->progRefLevel = AACDEC_DRC_DEFAULT_REF_LEVEL;
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;
case APPLY_HEAVY_COMPRESSION:
@ -783,6 +784,7 @@ void aacDecoder_drcApply (
{
int band, top, bin, numBands;
int bottom = 0;
int modifyBins = 0;
FIXP_DBL max_mantissa;
INT max_exponent;
@ -937,6 +939,12 @@ void aacDecoder_drcApply (
if (fact_exponent[band] < max_exponent) {
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 (
{
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++)
{
top = fixMin((int)( (pDrcChData->bandTop[band]+1)<<2 ), aacFrameSize); /* ... * DRC_BAND_MULT; */
@ -958,13 +972,12 @@ void aacDecoder_drcApply (
bottom = top;
}
}
/* above topmost DRC band gain factor is 1 */
if (max_exponent > 0) {
FIXP_DBL fact = FL2FXCONST_DBL(0.5f) >> (max_exponent - 1);
for (bin = top; bin < aacFrameSize; bin++) {
pSpectralCoefficient[bin] = fMult(pSpectralCoefficient[bin], fact);
for (bin = bottom; bin < aacFrameSize; bin+=1) {
pSpectralCoefficient[bin] >>= max_exponent;
}
}
@ -980,12 +993,13 @@ void aacDecoder_drcApply (
}
else {
HANDLE_SBRDECODER hSbrDecoder = (HANDLE_SBRDECODER)pSbrDec;
UINT numBands = pDrcChData->numBands;
/* feed factors into SBR decoder for application in QMF domain. */
sbrDecoder_drcFeedChannel (
hSbrDecoder,
ch,
pDrcChData->numBands,
numBands,
fact_mantissa,
max_exponent,
pDrcChData->drcInterpolationScheme,

View File

@ -99,10 +99,7 @@ amm-info@iis.fraunhofer.de
#include "FDK_bitstream.h"
#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 MAX_SBR_SYN_CHAN ( 64 )
#define MAX_SBR_COLS ( 32 )
#define AACDEC_DRC_DFLT_EXPIRY_FRAMES ( 50 ) /* Default DRC data expiry time in AAC frames */
/**
* \brief DRC module setting parameters

View File

@ -865,6 +865,17 @@ LINKSPEC_CPP AAC_DECODER_ERROR CAacDecoder_Init(HANDLE_AACDECODER self, const CS
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;
@ -1565,7 +1576,7 @@ LINKSPEC_CPP AAC_DECODER_ERROR CAacDecoder_DecodeFrame(
self->streamInfo.numChannels = aacChannels;
#ifdef TP_PCE_ENABLE
if (pceRead == 1 || CProgramConfig_IsValid(pce)) {
if (pceRead == 1 && CProgramConfig_IsValid(pce)) {
/* Set matrix mixdown infos if available from PCE. */
pcmDmx_SetMatrixMixdownFromPce ( self->hPcmUtils,
pce->MatrixMixdownIndexPresent,

View File

@ -110,7 +110,7 @@ amm-info@iis.fraunhofer.de
/* Decoder library info */
#define AACDECODER_LIB_VL0 2
#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_BUILD_DATE __DATE__
#define AACDECODER_LIB_BUILD_TIME __TIME__

View File

@ -98,7 +98,7 @@ amm-info@iis.fraunhofer.de
/* Encoder library info */
#define AACENCODER_LIB_VL0 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_BUILD_DATE __DATE__
#define AACENCODER_LIB_BUILD_TIME __TIME__

View File

@ -260,21 +260,21 @@ FDKaacEnc_CalcBandEnergyOptimShort(const FIXP_DBL *RESTRICT mdctSpectrum,
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);
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);
}
bandEnergy[i] = tmp<<1;
bandEnergy[i] = tmp;
}
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) */
scale = fixMin(scale,(DFRACT_BITS-1));
bandEnergy[i] >>= scale;
INT scale = (2*(sfbMaxScaleSpec[i]-3))-1; /* max sfbWidth = 36 ; 2^6=64 => 6/2 = 3 (spc*spc) */
scale = fixMax(fixMin(scale,(DFRACT_BITS-1)),-(DFRACT_BITS-1));
bandEnergy[i] = scaleValueSaturate(bandEnergy[i], -scale);
}
}

View File

@ -122,6 +122,8 @@ void FDKaacEnc_prepareSfbPe(PE_CHANNEL_DATA *peChanData,
avgFormFactorLdData = ((-sfbEnergyLdData[sfbGrp+sfb]>>1) + (CalcLdInt(sfbWidth)>>1))>>1;
peChanData->sfbNLines[sfbGrp+sfb] =
(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 {
peChanData->sfbNLines[sfbGrp+sfb] = 0;

View File

@ -1,93 +0,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"

View File

@ -155,7 +155,6 @@ amm-info@iis.fraunhofer.de
#endif
/* Define preferred Multiplication type */
#if defined(FDK_HIGH_PERFORMANCE) && !defined(FDK_HIGH_QUALITY) /* FDK_HIGH_PERFORMANCE */

View File

@ -100,6 +100,9 @@ amm-info@iis.fraunhofer.de
#elif defined(__mips__) /* cppp replaced: elif */
#include "mips/clz_mips.h"
#elif defined(__x86__) /* cppp replaced: elif */
#include "x86/clz_x86.h"
#endif /* all cores */

View File

@ -108,9 +108,22 @@ inline void cplxMultDiv2( FIXP_DBL *c_Re,
FIXP_DBL b_Im)
{
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;
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;
}
#endif
@ -124,9 +137,23 @@ inline void cplxMult( FIXP_DBL *c_Re,
FIXP_DBL b_Im)
{
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;
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;
}
#endif

View File

@ -100,11 +100,14 @@ amm-info@iis.fraunhofer.de
inline INT fixmuldiv2_DD (const INT a, const INT b)
{
return ((long long) a * b) >> 32;
INT result ;
result = ((long long)a * b)>>32;
return result ;
}
#endif /* (__GNUC__) && defined(__mips__) */
#endif /* __mips__ */
#define FUNCTION_fixmulBitExact_DD
#define fixmulBitExact_DD fixmul_DD

View File

@ -81,16 +81,74 @@ www.iis.fraunhofer.de/amm
amm-info@iis.fraunhofer.de
----------------------------------------------------------------------------------------------------------- */
/******************************** MPEG Audio Encoder **************************
/*************************** Fraunhofer IIS FDK Tools **********************
Initial author: Alex Goeschel
contents/description: Temporal noise shaping
Author(s):
Description: fixed point intrinsics
******************************************************************************/
#ifndef _TNS_PARAM_H
#define _TNS_PARAM_H
#if defined(__GNUC__) && (defined(__x86__) || defined(__x86_64__))
#define FUNCTION_fixnormz_D
#define FUNCTION_fixnorm_D
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))
#endif /* _TNS_PARAM_H */
#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 */

View File

@ -93,7 +93,7 @@ amm-info@iis.fraunhofer.de
/* FDK tools library info */
#define FDK_TOOLS_LIB_VL0 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_BUILD_DATE __DATE__
#define FDK_TOOLS_LIB_BUILD_TIME __TIME__

View File

@ -96,7 +96,7 @@ amm-info@iis.fraunhofer.de
/* Decoder library info */
#define PCMDMX_LIB_VL0 2
#define PCMDMX_LIB_VL1 2
#define PCMDMX_LIB_VL1 3
#define PCMDMX_LIB_VL2 1
#define PCMDMX_LIB_TITLE "PCM Downmix Lib"
#define PCMDMX_LIB_BUILD_DATE __DATE__
@ -107,7 +107,7 @@ amm-info@iis.fraunhofer.de
#define PCM_DMX_MAX_CHANNELS ( 8 )
#define PCM_DMX_MAX_CHANNEL_GROUPS ( 4 )
#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.
* 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)
* @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 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.
* @returns Returns the packed channel mode.
**/
@ -273,7 +272,6 @@ PCM_DMX_CHANNEL_MODE getChannelMode (
const INT numChannels, /* in */
const AUDIO_CHANNEL_TYPE channelType[], /* in */
const UCHAR channelIndices[], /* in */
const UCHAR channelMapping[PCM_DMX_MAX_CHANNELS], /* in */
UCHAR offsetTable[PCM_DMX_MAX_CHANNELS] /* out */
)
{
@ -284,12 +282,12 @@ PCM_DMX_CHANNEL_MODE getChannelMode (
FDK_ASSERT(channelType != NULL);
FDK_ASSERT(channelIndices != NULL);
FDK_ASSERT(channelMapping != NULL);
FDK_ASSERT(offsetTable != NULL);
/* For details see ISO/IEC 13818-7:2005(E), 8.5.3 Channel configuration */
FDKmemclear(numChInGrp, PCM_DMX_MAX_CHANNEL_GROUPS*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 */
for (ch = 0; ch < numChannels; ch += 1) {
@ -335,7 +333,7 @@ PCM_DMX_CHANNEL_MODE getChannelMode (
if (numChInGrp[CH_GROUP_FRONT] & 0x1) {
/* Odd number of front channels -> we have a center channel.
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) {
@ -367,7 +365,7 @@ PCM_DMX_CHANNEL_MODE getChannelMode (
for ( ; ch < numChInGrp[grpIdx]; ch += 1) {
if (ch < maxChannels) {
offsetTable[chMapPos] = channelMapping[chIdx[grpIdx][ch]];
offsetTable[chMapPos] = chIdx[grpIdx][ch];
chMapPos += 1;
} else {
err = -1;
@ -814,7 +812,6 @@ PCMDMX_ERROR pcmDmx_ApplyFrame (
numInChannels,
channelType,
channelIndices,
channelMapping[numInChannels],
inOffsetTable
);
if (inChMode == CH_MODE_UNDEFINED) {

View File

@ -585,6 +585,7 @@ sbr_dec ( HANDLE_SBR_DEC hSbrDec, /*!< handle to Decoder channel */
int maxShift = 0;
if (hSbrDec->sbrDrcChannel.enable != 0) {
if (hSbrDec->sbrDrcChannel.prevFact_exp > maxShift) {
maxShift = hSbrDec->sbrDrcChannel.prevFact_exp;
}
@ -594,6 +595,7 @@ sbr_dec ( HANDLE_SBR_DEC hSbrDec, /*!< handle to Decoder channel */
if (hSbrDec->sbrDrcChannel.nextFact_exp > maxShift) {
maxShift = hSbrDec->sbrDrcChannel.nextFact_exp;
}
}
/* copy DRC data to right channel (with PS both channels use the same DRC gains) */
FDKmemcpy(&hSbrDecRight->sbrDrcChannel, &hSbrDec->sbrDrcChannel, sizeof(SBRDEC_DRC_CHANNEL));

View File

@ -115,17 +115,17 @@ void sbrDecoder_drcInitChannel (
}
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++) {
hDrcData->currFact_mag[band] = (FIXP_DBL)MAXVAL_DBL /*FL2FXCONST_DBL(1.0f)*/;
hDrcData->nextFact_mag[band] = (FIXP_DBL)MAXVAL_DBL /*FL2FXCONST_DBL(1.0f)*/;
hDrcData->currFact_mag[band] = FL2FXCONST_DBL(0.5f);
hDrcData->nextFact_mag[band] = FL2FXCONST_DBL(0.5f);
}
hDrcData->prevFact_exp = 0;
hDrcData->currFact_exp = 0;
hDrcData->nextFact_exp = 0;
hDrcData->prevFact_exp = 1;
hDrcData->currFact_exp = 1;
hDrcData->nextFact_exp = 1;
hDrcData->numBandsCurr = 0;
hDrcData->numBandsNext = 0;
@ -238,7 +238,7 @@ void sbrDecoder_drcApplySlot (
}
else {
if (j >= offset[hDrcData->drcInterpolationSchemeCurr - 1]) {
alphaValue = FL2FXCONST_DBL(1.0f);
alphaValue = (FIXP_DBL)MAXVAL_DBL;
}
}
}
@ -262,7 +262,7 @@ void sbrDecoder_drcApplySlot (
}
else {
if (j >= offset[hDrcData->drcInterpolationSchemeNext - 1]) {
alphaValue = FL2FXCONST_DBL(1.0f);
alphaValue = (FIXP_DBL)MAXVAL_DBL;
}
}
@ -301,7 +301,7 @@ void sbrDecoder_drcApplySlot (
}
else {
if (j >= offset[hDrcData->drcInterpolationSchemeNext - 1]) {
alphaValue = FL2FXCONST_DBL(1.0f);
alphaValue = (FIXP_DBL)MAXVAL_DBL;
}
}
}
@ -322,7 +322,7 @@ void sbrDecoder_drcApplySlot (
for (band = 0; band < (int)numBands; band++) {
int bottomQmf, topQmf;
FIXP_DBL drcFact_mag = FL2FXCONST_DBL(1.0f);
FIXP_DBL drcFact_mag = (FIXP_DBL)MAXVAL_DBL;
topMdct = (bandTop[band]+1) << 2;
@ -361,7 +361,13 @@ void sbrDecoder_drcApplySlot (
}
/* 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 */
qmfRealSlot[bin] = fMult(qmfRealSlot[bin], drcFact_mag);
@ -481,6 +487,15 @@ void sbrDecoder_drcApply (
int col;
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 */
if (hDrcData->prevFact_exp > maxShift) {
maxShift = hDrcData->prevFact_exp;

View File

@ -94,6 +94,7 @@ amm-info@iis.fraunhofer.de
#include "sbrdecoder.h"
#define SBRDEC_MAX_DRC_CHANNELS (6)
#define SBRDEC_MAX_DRC_BANDS ( 16 )

View File

@ -137,7 +137,7 @@ amm-info@iis.fraunhofer.de
/* Decoder library info */
#define SBRDECODER_LIB_VL0 2
#define SBRDECODER_LIB_VL1 1
#define SBRDECODER_LIB_VL2 2
#define SBRDECODER_LIB_VL2 3
#define SBRDECODER_LIB_TITLE "SBR Decoder"
#define SBRDECODER_LIB_BUILD_DATE __DATE__
#define SBRDECODER_LIB_BUILD_TIME __TIME__
@ -818,6 +818,7 @@ SBR_ERROR sbrDecoder_drcFeedChannel ( HANDLE_SBRDECODER self,
USHORT *pBandTop )
{
SBRDEC_DRC_CHANNEL *pSbrDrcChannelData = NULL;
int band, isValidData = 0;
if (self == NULL) {
return SBRDEC_NOT_INITIALIZED;
@ -826,10 +827,21 @@ SBR_ERROR sbrDecoder_drcFeedChannel ( HANDLE_SBRDECODER self,
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 */
pSbrDrcChannelData = sbrDecoder_drcGetChannel( self, ch );
if ( pSbrDrcChannelData != NULL ) {
if ( pSbrDrcChannelData->enable || isValidData )
{ /* Activate processing only with real and valid data */
int i;
pSbrDrcChannelData->enable = 1;
@ -844,6 +856,7 @@ SBR_ERROR sbrDecoder_drcFeedChannel ( HANDLE_SBRDECODER self,
pSbrDrcChannelData->nextFact_mag[i] = pNextFact_mag[i];
}
}
}
return SBRDEC_OK;
}