ref: fb9d1d265e8cd35a9ca377a78484bcbe87803405
parent: da29a5eefaff382ce76c4f7ff41003b2d5280584
author: menno <menno>
date: Mon Aug 26 14:41:47 EDT 2002
Fixed inverting MDCT/iMDCT Fixed LTP Complete new filterbank code Complete new way of applying scalefactors and inverse quantisation Fixed index bug in MDCT Corrected object types in TNS Fixed point almost working
--- a/common/id3lib/libprj/id3lib.vcproj
+++ b/common/id3lib/libprj/id3lib.vcproj
@@ -66,11 +66,7 @@
CharacterSet="2">
<Tool
Name="VCCLCompilerTool"
- GlobalOptimizations="TRUE"
InlineFunctionExpansion="1"
- EnableIntrinsicFunctions="TRUE"
- FavorSizeOrSpeed="1"
- OptimizeForProcessor="2"
AdditionalIncludeDirectories=".\,..\,..\include,..\include\id3,..\zlib\include,..\win32"
PreprocessorDefinitions="NDEBUG,WIN32,_LIB,_WINDOWS,HAVE_CONFIG_H,ID3LIB_COMPILATION"
StringPooling="TRUE"
@@ -196,10 +192,10 @@
RelativePath="E:\Program Files\Microsoft Visual Studio\VC98\Include\BASETSD.H">
</File>
<File
- RelativePath="..\config.h">
+ RelativePath="..\win32\config.h">
</File>
<File
- RelativePath="..\win32\config.h">
+ RelativePath="..\config.h">
</File>
<File
RelativePath="..\include\id3\error.h">
--- a/common/mp4v2/libmp4v2_st60.dsp
+++ b/common/mp4v2/libmp4v2_st60.dsp
@@ -64,7 +64,7 @@
# PROP Intermediate_Dir "ST_Debug"
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /GX /Z7 /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /YX /FD /c
-# ADD CPP /nologo /W3 /GX /Z7 /Od /I ".\\" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /YX /FD /c
+# ADD CPP /nologo /MTd /W3 /GX /Z7 /Od /I ".\\" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /YX /FD /c
# ADD BASE RSC /l 0x409
# ADD RSC /l 0x409
BSC32=bscmake.exe
--- a/common/mp4v2/libmp4v2_st60.vcproj
+++ b/common/mp4v2/libmp4v2_st60.vcproj
@@ -19,11 +19,7 @@
ATLMinimizesCRunTimeLibraryUsage="FALSE">
<Tool
Name="VCCLCompilerTool"
- GlobalOptimizations="TRUE"
InlineFunctionExpansion="1"
- EnableIntrinsicFunctions="TRUE"
- FavorSizeOrSpeed="1"
- OptimizeForProcessor="2"
AdditionalIncludeDirectories=".\"
PreprocessorDefinitions="WIN32,NDEBUG,_WINDOWS"
StringPooling="TRUE"
@@ -69,7 +65,7 @@
Optimization="0"
AdditionalIncludeDirectories=".\"
PreprocessorDefinitions="WIN32,_DEBUG,_WINDOWS"
- RuntimeLibrary="5"
+ RuntimeLibrary="1"
UsePrecompiledHeader="2"
PrecompiledHeaderFile=".\ST_Debug/libmp4v2_st60.pch"
AssemblerListingLocation=".\ST_Debug/"
--- a/include/faad.h
+++ b/include/faad.h
@@ -16,7 +16,7 @@
** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
**
-** $Id: faad.h,v 1.11 2002/08/13 19:16:07 menno Exp $
+** $Id: faad.h,v 1.12 2002/08/26 18:41:47 menno Exp $
**/
#ifndef __AACDEC_H__
@@ -39,13 +39,14 @@
#define FAAD2_VERSION "1.2 beta"
-#define MAIN 0
-#define LC 1
-#define SSR 2
-#define LTP 3
-#define ER_LC 17
-#define LD 23
-#define DRM_ER_LC 27 /* special object type for DRM */
+#define MAIN 0
+#define LC 1
+#define SSR 2
+#define LTP 3
+#define ER_LC 17
+#define ER_LTP 19
+#define LD 23
+#define DRM_ER_LC 27 /* special object type for DRM */
#define FAAD_FMT_16BIT 1
#define FAAD_FMT_24BIT 2
--- a/libfaad/cfft.c
+++ b/libfaad/cfft.c
@@ -16,7 +16,7 @@
** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
**
-** $Id: cfft.c,v 1.4 2002/08/17 12:27:33 menno Exp $
+** $Id: cfft.c,v 1.5 2002/08/26 18:41:47 menno Exp $
**/
/*
@@ -65,8 +65,8 @@
tr2 = cc[ac] - cc[ac+ido];
ch[ah+1] = cc[ac+1] + cc[ac+1+ido];
ti2 = cc[ac+1] - cc[ac+1+ido];
- ch[ah+l1*ido+1] = MUL(wa1[i],ti2) + isign*MUL(wa1[i+1],tr2);
- ch[ah+l1*ido] = MUL(wa1[i],tr2) - isign*MUL(wa1[i+1],ti2);
+ ch[ah+l1*ido+1] = MUL_R_C(ti2,wa1[i]) + isign*MUL_R_C(tr2,wa1[i+1]);
+ ch[ah+l1*ido] = MUL_R_C(tr2,wa1[i]) - isign*MUL_R_C(ti2,wa1[i+1]);
}
}
}
@@ -76,8 +76,8 @@
static void passf3(uint16_t ido, uint16_t l1, real_t *cc, real_t *ch,
real_t *wa1, real_t *wa2, int8_t isign)
{
- static real_t taur = REAL_CONST(-0.5);
- static real_t taui = REAL_CONST(0.866025403784439);
+ static real_t taur = COEF_CONST(-0.5);
+ static real_t taui = COEF_CONST(0.866025403784439);
uint16_t i, k, ac, ah;
real_t ci2, ci3, di2, di3, cr2, cr3, dr2, dr3, ti2, tr2;
@@ -87,16 +87,16 @@
{
ac = (3*k-2) * ido;
tr2 = cc[ac] + cc[ac+ido];
- cr2 = cc[ac-ido] + MUL(taur,tr2);
+ cr2 = cc[ac-ido] + MUL_R_C(tr2,taur);
ah = (k-1) * ido;
ch[ah] = cc[ac-ido] + tr2;
ti2 = cc[ac+1] + cc[ac+ido+1];
- ci2 = cc[ac-ido+1] + MUL(taur,ti2);
+ ci2 = cc[ac-ido+1] + MUL_R_C(ti2,taur);
ch[ah+1] = cc[ac-ido+1] + ti2;
- cr3 = isign * MUL(taui, (cc[ac] - cc[ac+ido]));
- ci3 = isign * MUL(taui, (cc[ac+1] - cc[ac+ido+1]));
+ cr3 = isign * MUL_R_C((cc[ac] - cc[ac+ido]), taui);
+ ci3 = isign * MUL_R_C((cc[ac+1] - cc[ac+ido+1]), taui);
ch[ah+l1*ido] = cr2 - ci3;
ch[ah+2*l1*ido] = cr2 + ci3;
ch[ah+l1*ido+1] = ci2 + cr3;
@@ -109,22 +109,22 @@
{
ac = i + (3*k-2) * ido;
tr2 = cc[ac] + cc[ac+ido];
- cr2 = cc[ac-ido] + MUL(taur,tr2);
+ cr2 = cc[ac-ido] + MUL_R_C(tr2,taur);
ah = i + (k-1) * ido;
ch[ah] = cc[ac-ido] + tr2;
ti2 = cc[ac+1] + cc[ac+ido+1];
- ci2 = cc[ac-ido+1] + MUL(taur,ti2);
+ ci2 = cc[ac-ido+1] + MUL_R_C(ti2,taur);
ch[ah+1] = cc[ac-ido+1] + ti2;
- cr3 = isign * MUL(taui, (cc[ac] - cc[ac+ido]));
- ci3 = isign * MUL(taui, (cc[ac+1] - cc[ac+ido+1]));
+ cr3 = isign * MUL_R_C((cc[ac] - cc[ac+ido]), taui);
+ ci3 = isign * MUL_R_C((cc[ac+1] - cc[ac+ido+1]), taui);
dr2 = cr2 - ci3;
dr3 = cr2 + ci3;
di2 = ci2 + cr3;
di3 = ci2 - cr3;
- ch[ah+l1*ido+1] = MUL(wa1[i],di2) + isign*MUL(wa1[i+1],dr2);
- ch[ah+l1*ido] = MUL(wa1[i],dr2) - isign*MUL(wa1[i+1],di2);
- ch[ah+2*l1*ido+1] = MUL(wa2[i],di3) + isign*MUL(wa2[i+1],dr3);
- ch[ah+2*l1*ido] = MUL(wa2[i],dr3) - isign*MUL(wa2[i+1],di3);
+ ch[ah+l1*ido+1] = MUL_R_C(di2,wa1[i]) + isign*MUL_R_C(dr2,wa1[i+1]);
+ ch[ah+l1*ido] = MUL_R_C(dr2,wa1[i]) - isign*MUL_R_C(di2,wa1[i+1]);
+ ch[ah+2*l1*ido+1] = MUL_R_C(di3,wa2[i]) + isign*MUL_R_C(dr3,wa2[i+1]);
+ ch[ah+2*l1*ido] = MUL_R_C(dr3,wa2[i]) - isign*MUL_R_C(di3,wa2[i+1]);
}
}
}
@@ -184,12 +184,12 @@
cr4 = tr1 - isign*tr4;
ci2 = ti1 + isign*ti4;
ci4 = ti1 - isign*ti4;
- ch[ah+l1*ido] = MUL(wa1[i],cr2) - isign*MUL(wa1[i+1],ci2);
- ch[ah+l1*ido+1] = MUL(wa1[i],ci2) + isign*MUL(wa1[i+1],cr2);
- ch[ah+2*l1*ido] = MUL(wa2[i],cr3) - isign*MUL(wa2[i+1],ci3);
- ch[ah+2*l1*ido+1] = MUL(wa2[i],ci3) + isign*MUL(wa2[i+1],cr3);
- ch[ah+3*l1*ido] = MUL(wa3[i],cr4) - isign*MUL(wa3[i+1],ci4);
- ch[ah+3*l1*ido+1] = MUL(wa3[i],ci4) + isign*MUL(wa3[i+1],cr4);
+ ch[ah+l1*ido] = MUL_R_C(cr2,wa1[i]) - isign*MUL_R_C(ci2,wa1[i+1]);
+ ch[ah+l1*ido+1] = MUL_R_C(ci2,wa1[i]) + isign*MUL_R_C(cr2,wa1[i+1]);
+ ch[ah+2*l1*ido] = MUL_R_C(cr3,wa2[i]) - isign*MUL_R_C(ci3,wa2[i+1]);
+ ch[ah+2*l1*ido+1] = MUL_R_C(ci3,wa2[i]) + isign*MUL_R_C(cr3,wa2[i+1]);
+ ch[ah+3*l1*ido] = MUL_R_C(cr4,wa3[i]) - isign*MUL_R_C(ci4,wa3[i+1]);
+ ch[ah+3*l1*ido+1] = MUL_R_C(ci4,wa3[i]) + isign*MUL_R_C(cr4,wa3[i+1]);
}
}
}
@@ -200,10 +200,10 @@
real_t *wa1, real_t *wa2, real_t *wa3, real_t *wa4,
int8_t isign)
{
- static real_t tr11 = REAL_CONST(0.309016994374947);
- static real_t ti11 = REAL_CONST(0.951056516295154);
- static real_t tr12 = REAL_CONST(-0.809016994374947);
- static real_t ti12 = REAL_CONST(0.587785252292473);
+ static real_t tr11 = COEF_CONST(0.309016994374947);
+ static real_t ti11 = COEF_CONST(0.951056516295154);
+ static real_t tr12 = COEF_CONST(-0.809016994374947);
+ static real_t ti12 = COEF_CONST(0.587785252292473);
uint16_t i, k, ac, ah;
real_t ci2, ci3, ci4, ci5, di3, di4, di5, di2, cr2, cr3, cr5, cr4,
ti2, ti3, ti4, ti5, dr3, dr4, dr5, dr2, tr2, tr3, tr4, tr5;
@@ -224,14 +224,14 @@
ah = (k-1) * ido;
ch[ah] = cc[ac-ido-1] + tr2 + tr3;
ch[ah+1] = cc[ac-ido] + ti2 + ti3;
- cr2 = cc[ac-ido-1] + MUL(tr11,tr2) + MUL(tr12,tr3);
- ci2 = cc[ac-ido] + MUL(tr11,ti2) + MUL(tr12,ti3);
- cr3 = cc[ac-ido-1] + MUL(tr12,tr2) + MUL(tr11,tr3);
- ci3 = cc[ac-ido] + MUL(tr12,ti2) + MUL(tr11,ti3);
- cr5 = isign * (MUL(ti11,tr5) + MUL(ti12,tr4));
- ci5 = isign * (MUL(ti11,ti5) + MUL(ti12,ti4));
- cr4 = isign * (MUL(ti12,tr5) - MUL(ti11,tr4));
- ci4 = isign * (MUL(ti12,ti5) - MUL(ti11,ti4));
+ cr2 = cc[ac-ido-1] + MUL_R_C(tr2,tr11) + MUL_R_C(tr3,tr12);
+ ci2 = cc[ac-ido] + MUL_R_C(ti2,tr11) + MUL_R_C(ti3,tr12);
+ cr3 = cc[ac-ido-1] + MUL_R_C(tr2,tr12) + MUL_R_C(tr3,tr11);
+ ci3 = cc[ac-ido] + MUL_R_C(ti2,tr12) + MUL_R_C(ti3,tr11);
+ cr5 = isign * (MUL_R_C(tr5,ti11) + MUL_R_C(tr4,ti12));
+ ci5 = isign * (MUL_R_C(ti5,ti11) + MUL_R_C(ti4,ti12));
+ cr4 = isign * (MUL_R_C(tr5,ti12) - MUL_R_C(tr4,ti11));
+ ci4 = isign * (MUL_R_C(ti5,ti12) - MUL_R_C(ti4,ti11));
ch[ah+l1*ido] = cr2 - ci5;
ch[ah+4*l1*ido] = cr2 + ci5;
ch[ah+l1*ido+1] = ci2 + cr5;
@@ -258,14 +258,14 @@
ah = i + (k-1) * ido;
ch[ah] = cc[ac-ido-1] + tr2 + tr3;
ch[ah+1] = cc[ac-ido] + ti2 + ti3;
- cr2 = cc[ac-ido-1] + MUL(tr11,tr2) + MUL(tr12,tr3);
- ci2 = cc[ac-ido] + MUL(tr11,ti2) + MUL(tr12,ti3);
- cr3 = cc[ac-ido-1] + MUL(tr12,tr2) + MUL(tr11,tr3);
- ci3 = cc[ac-ido] + MUL(tr12,ti2) + MUL(tr11,ti3);
- cr5 = isign * (MUL(ti11,tr5) + MUL(ti12,tr4));
- ci5 = isign * (MUL(ti11,ti5) + MUL(ti12,ti4));
- cr4 = isign * (MUL(ti12,tr5) - MUL(ti11,tr4));
- ci4 = isign * (MUL(ti12,ti5) - MUL(ti11,ti4));
+ cr2 = cc[ac-ido-1] + MUL_R_C(tr2,tr11) + MUL_R_C(tr3,tr12);
+ ci2 = cc[ac-ido] + MUL_R_C(ti2,tr11) + MUL_R_C(ti3,tr12);
+ cr3 = cc[ac-ido-1] + MUL_R_C(tr2,tr12) + MUL_R_C(tr3,tr11);
+ ci3 = cc[ac-ido] + MUL_R_C(ti2,tr12) + MUL_R_C(ti3,tr11);
+ cr5 = isign * (MUL_R_C(tr5,ti11) + MUL_R_C(tr4,ti12));
+ ci5 = isign * (MUL_R_C(ti5,ti11) + MUL_R_C(ti4,ti12));
+ cr4 = isign * (MUL_R_C(tr5,ti12) - MUL_R_C(tr4,ti11));
+ ci4 = isign * (MUL_R_C(ti5,ti12) - MUL_R_C(ti4,ti11));
dr3 = cr3 - ci4;
dr4 = cr3 + ci4;
di3 = ci3 + cr4;
@@ -274,14 +274,14 @@
dr2 = cr2 - ci5;
di5 = ci2 - cr5;
di2 = ci2 + cr5;
- ch[ah+l1*ido] = MUL(wa1[i],dr2) - isign*MUL(wa1[i+1],di2);
- ch[ah+l1*ido+1] = MUL(wa1[i],di2) + isign*MUL(wa1[i+1],dr2);
- ch[ah+2*l1*ido] = MUL(wa2[i],dr3) - isign*MUL(wa2[i+1],di3);
- ch[ah+2*l1*ido+1] = MUL(wa2[i],di3) + isign*MUL(wa2[i+1],dr3);
- ch[ah+3*l1*ido] = MUL(wa3[i],dr4) - isign*MUL(wa3[i+1],di4);
- ch[ah+3*l1*ido+1] = MUL(wa3[i],di4) + isign*MUL(wa3[i+1],dr4);
- ch[ah+4*l1*ido] = MUL(wa4[i],dr5) - isign*MUL(wa4[i+1],di5);
- ch[ah+4*l1*ido+1] = MUL(wa4[i],di5) + isign*MUL(wa4[i+1],dr5);
+ ch[ah+l1*ido] = MUL_R_C(dr2,wa1[i]) - isign*MUL_R_C(di2,wa1[i+1]);
+ ch[ah+l1*ido+1] = MUL_R_C(di2,wa1[i]) + isign*MUL_R_C(dr2,wa1[i+1]);
+ ch[ah+2*l1*ido] = MUL_R_C(dr3,wa2[i]) - isign*MUL_R_C(di3,wa2[i+1]);
+ ch[ah+2*l1*ido+1] = MUL_R_C(di3,wa2[i]) + isign*MUL_R_C(dr3,wa2[i+1]);
+ ch[ah+3*l1*ido] = MUL_R_C(dr4,wa3[i]) - isign*MUL_R_C(di4,wa3[i+1]);
+ ch[ah+3*l1*ido+1] = MUL_R_C(di4,wa3[i]) + isign*MUL_R_C(dr4,wa3[i+1]);
+ ch[ah+4*l1*ido] = MUL_R_C(dr5,wa4[i]) - isign*MUL_R_C(di5,wa4[i+1]);
+ ch[ah+4*l1*ido+1] = MUL_R_C(di5,wa4[i]) + isign*MUL_R_C(dr5,wa4[i+1]);
}
}
}
@@ -354,8 +354,8 @@
for (ik = 0; ik < idl1; ik++)
{
- cc[ik+l*idl1] = ch[ik] + MUL(wa[idl-2],ch[ik+idl1]);
- cc[ik+lc*idl1] = isign*MUL(wa[idl-1],ch[ik+(ip-1)*idl1]);
+ cc[ik+l*idl1] = ch[ik] + MUL_R_C(ch[ik+idl1],wa[idl-2]);
+ cc[ik+lc*idl1] = isign * MUL_R_C(ch[ik+(ip-1)*idl1],wa[idl-1]);
}
idlj = idl;
@@ -374,8 +374,8 @@
for (ik = 0; ik < idl1; ik++)
{
- cc[ik+l*idl1] += MUL(war,ch[ik+j*idl1]);
- cc[ik+lc*idl1] += isign*MUL(wai,ch[ik+jc*idl1]);
+ cc[ik+l*idl1] += MUL_R_C(ch[ik+j*idl1],war);
+ cc[ik+lc*idl1] += isign * MUL_R_C(ch[ik+jc*idl1],wai);
}
}
}
@@ -432,10 +432,10 @@
for (k = 0; k < l1; k++)
{
- cc[i-1+(k+j*l1)*ido] = MUL(wa[idij-2], ch[i-1+(k+j*l1)*ido]) -
- isign * MUL(wa[idij-1], ch[i+(k+j*l1)*ido]);
- cc[i+(k+j*l1)*ido] = MUL(wa[idij-2], ch[i+(k+j*l1)*ido]) +
- isign * MUL(wa[idij-1], ch[i-1+(k+j*l1)*ido]);
+ cc[i-1+(k+j*l1)*ido] = MUL_R_C(ch[i-1+(k+j*l1)*ido],wa[idij-2]) -
+ isign * MUL_R_C(ch[i+(k+j*l1)*ido],wa[idij-1]);
+ cc[i+(k+j*l1)*ido] = MUL_R_C(ch[i+(k+j*l1)*ido],wa[idij-2]) +
+ isign * MUL_R_C(ch[i-1+(k+j*l1)*ido],wa[idij-1]);
}
}
}
@@ -453,10 +453,10 @@
for (i = 3; i < ido; i += 2)
{
idij += 2;
- cc[i-1+(k+j*l1)*ido] = MUL(wa[idij-2], ch[i-1+(k+j*l1)*ido]) -
- isign * MUL(wa[idij-1], ch[i+(k+j*l1)*ido]);
- cc[i+(k+j*l1)*ido] = MUL(wa[idij-2], ch[i+(k+j*l1)*ido]) +
- isign * MUL(wa[idij-1], ch[i-1+(k+j*l1)*ido]);
+ cc[i-1+(k+j*l1)*ido] = MUL_R_C(ch[i-1+(k+j*l1)*ido],wa[idij-2]) -
+ isign * MUL_R_C(ch[i+(k+j*l1)*ido],wa[idij-1]);
+ cc[i+(k+j*l1)*ido] = MUL_R_C(ch[i+(k+j*l1)*ido],wa[idij-2]) +
+ isign * MUL_R_C(ch[i-1+(k+j*l1)*ido],wa[idij-1]);
}
}
}
@@ -567,7 +567,7 @@
static void cffti1(uint16_t n, real_t *wa, uint16_t *ifac)
{
static uint16_t ntryh[4] = {3, 4, 2, 5};
- real_t arg, argh, argld, fi;
+ float32_t arg, argh, argld, fi;
uint16_t idot, ntry, i, j;
uint16_t i1, k1, l1, l2, ib;
uint16_t ld, ii, nf, ip, nl, nq, nr;
@@ -610,7 +610,7 @@
ifac[0] = n;
ifac[1] = nf;
- argh = REAL_CONST(2*M_PI / (real_t)n); /* <-- TODO */
+ argh = 2.0*M_PI / (float32_t)n; /* <-- TODO */
i = 1;
l1 = 1;
@@ -636,9 +636,9 @@
{
i += 2;
fi += 1;
- arg = MUL(fi,argld);
- wa[i-1] = REAL_CONST(cos(arg));
- wa[i] = REAL_CONST(sin(arg));
+ arg = fi * argld;
+ wa[i-1] = COEF_CONST(cos(arg));
+ wa[i] = COEF_CONST(sin(arg));
}
if (ip > 5)
--- a/libfaad/common.h
+++ b/libfaad/common.h
@@ -16,7 +16,7 @@
** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
**
-** $Id: common.h,v 1.16 2002/08/17 12:27:33 menno Exp $
+** $Id: common.h,v 1.17 2002/08/26 18:41:47 menno Exp $
**/
#ifndef __COMMON_H__
@@ -59,6 +59,8 @@
/* use double precision */
/* #define USE_DOUBLE_PRECISION */
+/* use fixed point reals */
+//#define FIXED_POINT
//#define SBR
#define ERROR_RESILIENCE
@@ -109,7 +111,7 @@
typedef unsigned long uint32_t;
typedef unsigned short uint16_t;
typedef unsigned char uint8_t;
-typedef long long int32_t;
+typedef long long int64_t;
typedef long int32_t;
typedef short int16_t;
typedef char int8_t;
@@ -124,13 +126,51 @@
#endif
+/* FIXED_POINT doesn't work everywhere yet */
+#ifdef FIXED_POINT
+ #undef MAIN_DEC
+ #undef LTP_DEC
+ #undef LD_DEC
+ #undef SBR
+ #undef USE_FFTW
+#endif
-#ifndef USE_DOUBLE_PRECISION
+#if defined(FIXED_POINT)
+
+ typedef int32_t real_t;
+
+ #include <math.h>
+
+ #include "fixed.h"
+
+#elif defined(USE_DOUBLE_PRECISION)
+
+ typedef double real_t;
+
+ #include <math.h>
+
+ #define MUL(A,B) ((A)*(B))
+ #define MUL_C_C(A,B) ((A)*(B))
+ #define MUL_R_C(A,B) ((A)*(B))
+ #define MUL_R_1(A,B) ((A)*(B))
+
+ #define COEF_CONST_1(A) ((real_t)A)
+ #define REAL_CONST(A) ((real_t)A)
+ #define COEF_CONST(A) ((real_t)A)
+
+#else /* Normal floating point operation */
+
typedef float real_t;
#define MUL(A,B) ((A)*(B))
+ #define MUL_C_C(A,B) ((A)*(B))
+ #define MUL_R_C(A,B) ((A)*(B))
+ #define MUL_R_1(A,B) ((A)*(B))
+
+ #define COEF_CONST_1(A) ((real_t)A)
#define REAL_CONST(A) ((real_t)A)
+ #define COEF_CONST(A) ((real_t)A)
#ifdef __ICL /* only Intel C compiler has fmath ??? */
@@ -171,14 +211,6 @@
#endif
#endif
-
-#else
-
- typedef double real_t;
- #include <math.h>
-
- #define MUL(A,B) ((A)*(B))
- #define REAL_CONST(A) (A)
#endif
--- a/libfaad/decoder.c
+++ b/libfaad/decoder.c
@@ -16,7 +16,7 @@
** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
**
-** $Id: decoder.c,v 1.20 2002/08/17 12:27:33 menno Exp $
+** $Id: decoder.c,v 1.21 2002/08/26 18:41:47 menno Exp $
**/
#include <stdlib.h>
@@ -72,7 +72,6 @@
for (i = 0; i < MAX_CHANNELS; i++)
{
hDecoder->window_shape_prev[i] = 0;
- hDecoder->time_state[i] = NULL;
hDecoder->time_out[i] = NULL;
#ifdef MAIN_DEC
hDecoder->pred_stat[i] = NULL;
@@ -84,12 +83,10 @@
}
hDecoder->drc = drc_init(REAL_CONST(1.0), REAL_CONST(1.0));
-#if IQ_TABLE_SIZE && POW_TABLE_SIZE
- build_tables(hDecoder->iq_table, hDecoder->pow2_table);
-#elif !POW_TABLE_SIZE
- build_tables(hDecoder->iq_table, NULL);
-#endif
+ /* build table for inverse quantization */
+ build_tables(hDecoder->iq_table);
+
return hDecoder;
}
@@ -277,7 +274,7 @@
&hDecoder->aacScalefactorDataResilienceFlag,
&hDecoder->aacSpectralDataResilienceFlag,
&frameLengthFlag);
- if (hDecoder->object_type < 4)
+ if (hDecoder->object_type < 5)
hDecoder->object_type--; /* For AAC differs from MPEG-4 */
if (rc != 0)
{
@@ -304,7 +301,6 @@
for (i = 0; i < MAX_CHANNELS; i++)
{
- if (hDecoder->time_state[i]) free(hDecoder->time_state[i]);
if (hDecoder->time_out[i]) free(hDecoder->time_out[i]);
#ifdef MAIN_DEC
if (hDecoder->pred_stat[i]) free(hDecoder->pred_stat[i]);
@@ -442,13 +438,7 @@
real_t **lt_pred_stat = hDecoder->lt_pred_stat;
#endif
real_t *iq_table = hDecoder->iq_table;
-#if POW_TABLE_SIZE
- real_t *pow2_table = hDecoder->pow2_table;
-#else
- real_t *pow2_table = NULL;
-#endif
uint8_t *window_shape_prev = hDecoder->window_shape_prev;
- real_t **time_state = hDecoder->time_state;
real_t **time_out = hDecoder->time_out;
fb_info *fb = hDecoder->fb;
drc_info *drc = hDecoder->drc;
@@ -631,13 +621,10 @@
ics = &(syntax_elements[i]->ics2);
}
- /* inverse quantization */
- inverse_quantization(spec_coef[ch], spec_data[ch], iq_table,
- frame_len);
+ /* inverse quantization and application of scalefactors */
+ iquant_and_apply_scalefactors(ics, spec_coef[ch], spec_data[ch],
+ iq_table, frame_len);
- /* apply scalefactors */
- apply_scalefactors(ics, spec_coef[ch], pow2_table, frame_len);
-
/* deinterleave short block grouping */
if (ics->window_sequence == EIGHT_SHORT_SEQUENCE)
quant_to_spec(ics, spec_coef[ch], frame_len);
@@ -743,6 +730,7 @@
tns_decode_frame(ics, &(ics->tns), sf_index, object_type,
spec_coef[ch], frame_len);
+#ifndef FIXED_POINT
/* drc decoding */
if (drc->present)
{
@@ -749,29 +737,19 @@
if (!drc->exclude_mask[ch] || !drc->excluded_chns_present)
drc_decode(drc, spec_coef[ch]);
}
+#endif
- if (time_state[ch] == NULL)
- {
- real_t *tp;
-
- time_state[ch] = malloc(frame_len*sizeof(real_t));
- tp = time_state[ch];
- for (i = frame_len/16-1; i >= 0; --i)
- {
- *tp++ = 0; *tp++ = 0; *tp++ = 0; *tp++ = 0;
- *tp++ = 0; *tp++ = 0; *tp++ = 0; *tp++ = 0;
- *tp++ = 0; *tp++ = 0; *tp++ = 0; *tp++ = 0;
- *tp++ = 0; *tp++ = 0; *tp++ = 0; *tp++ = 0;
- }
- }
if (time_out[ch] == NULL)
{
+ uint16_t r;
time_out[ch] = malloc(frame_len*2*sizeof(real_t));
+ for (r = 0; r < frame_len*2; r++)
+ time_out[ch][r] = 0;
}
/* filter bank */
ifilter_bank(fb, ics->window_sequence, ics->window_shape,
- window_shape_prev[ch], spec_coef[ch], time_state[ch],
+ window_shape_prev[ch], spec_coef[ch],
time_out[ch], object_type, frame_len);
/* save window shape for next frame */
window_shape_prev[ch] = ics->window_shape;
@@ -786,7 +764,7 @@
#endif
)
{
- lt_update_state(lt_pred_stat[ch], time_out[ch], time_state[ch],
+ lt_update_state(lt_pred_stat[ch], time_out[ch], time_out[ch]+frame_len,
frame_len, object_type);
}
#endif
--- a/libfaad/decoder.h
+++ b/libfaad/decoder.h
@@ -16,7 +16,7 @@
** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
**
-** $Id: decoder.h,v 1.9 2002/08/17 10:03:12 menno Exp $
+** $Id: decoder.h,v 1.10 2002/08/26 18:41:47 menno Exp $
**/
#ifndef __DECODER_H__
@@ -88,7 +88,6 @@
fb_info *fb;
drc_info *drc;
- real_t *time_state[MAX_CHANNELS];
real_t *time_out[MAX_CHANNELS];
#ifdef MAIN_DEC
@@ -102,9 +101,6 @@
real_t mnt_table[128];
real_t iq_table[IQ_TABLE_SIZE];
-#if POW_TABLE_SIZE
- real_t pow2_table[POW_TABLE_SIZE];
-#endif
/* Configuration data */
faacDecConfiguration config;
--- a/libfaad/drc.c
+++ b/libfaad/drc.c
@@ -16,7 +16,7 @@
** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
**
-** $Id: drc.c,v 1.7 2002/08/17 12:27:33 menno Exp $
+** $Id: drc.c,v 1.8 2002/08/26 18:41:47 menno Exp $
**/
#include "common.h"
@@ -46,6 +46,7 @@
if (drc) free(drc);
}
+#ifndef FIXED_POINT
void drc_decode(drc_info *drc, real_t *spec)
{
uint16_t i, bd, top;
@@ -83,3 +84,4 @@
bottom = top;
}
}
+#endif
--- a/libfaad/filtbank.c
+++ b/libfaad/filtbank.c
@@ -16,12 +16,13 @@
** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
**
-** $Id: filtbank.c,v 1.14 2002/08/17 12:27:33 menno Exp $
+** $Id: filtbank.c,v 1.15 2002/08/26 18:41:47 menno Exp $
**/
#include "common.h"
#include <stdlib.h>
+#include <memory.h>
#include <assert.h>
#include "filtbank.h"
#include "syntax.h"
@@ -36,6 +37,7 @@
#ifdef LD_DEC
uint16_t frame_len_ld = frame_len/2;
#endif
+
fb_info *fb = malloc(sizeof(fb_info));
memset(fb, 0, sizeof(fb_info));
@@ -45,14 +47,24 @@
fb->long_window[0] = malloc(frame_len*sizeof(real_t));
fb->short_window[0] = malloc(nshort*sizeof(real_t));
+#ifndef FIXED_POINT
fb->long_window[1] = kbd_long;
fb->short_window[1] = kbd_short;
+#else
+ fb->long_window[1] = malloc(frame_len*sizeof(real_t));
+ fb->short_window[1] = malloc(nshort*sizeof(real_t));
+ for (i = 0; i < frame_len; i++)
+ fb->long_window[1][i] = COEF_CONST(kbd_long[i]);
+ for (i = 0; i < nshort; i++)
+ fb->short_window[1][i] = COEF_CONST(kbd_short[i]);
+#endif
+
/* calculate the sine windows */
for (i = 0; i < frame_len; i++)
- fb->long_window[0][i] = REAL_CONST(sin(M_PI / (2.0 * (real_t)frame_len) * ((real_t)i + 0.5)));
+ fb->long_window[0][i] = COEF_CONST(sin(M_PI / (2.0 * (float32_t)frame_len) * ((float32_t)i + 0.5)));
for (i = 0; i < nshort; i++)
- fb->short_window[0][i] = REAL_CONST(sin(M_PI / (2.0 * (real_t)nshort) * ((real_t)i + 0.5)));
+ fb->short_window[0][i] = COEF_CONST(sin(M_PI / (2.0 * (float32_t)nshort) * ((float32_t)i + 0.5)));
#ifdef LD_DEC
/* LD */
@@ -63,13 +75,13 @@
/* calculate the sine windows */
for (i = 0; i < frame_len_ld; i++)
- fb->ld_window[0][i] = REAL_CONST(sin(M_PI / (2.0 * frame_len_ld) * (i + 0.5)));
+ fb->ld_window[0][i] = COEF_CONST(sin(M_PI / (2.0 * frame_len_ld) * (i + 0.5)));
/* low overlap window */
for (i = 0; i < 3*(frame_len_ld>>3); i++)
fb->ld_window[1][i] = 0.0;
for (; i < 5*(frame_len_ld>>3); i++)
- fb->ld_window[1][i] = REAL_CONST(sin((i-3*(frame_len_ld>>3)+0.5) * M_PI / (real_t)(frame_len_ld>>1)));
+ fb->ld_window[1][i] = COEF_CONST(sin((i-3*(frame_len_ld>>3)+0.5) * M_PI / (real_t)(frame_len_ld>>1)));
for (; i < frame_len_ld; i++)
fb->ld_window[1][i] = 1.0;
#endif
@@ -84,6 +96,10 @@
if (fb->long_window[0]) free(fb->long_window[0]);
if (fb->short_window[0]) free(fb->short_window[0]);
+#ifdef FIXED_POINT
+ if (fb->long_window[1]) free(fb->long_window[1]);
+ if (fb->short_window[1]) free(fb->short_window[1]);
+#endif
#ifdef LD_DEC
faad_mdct_end(fb->mdct1024);
@@ -95,69 +111,6 @@
if (fb) free(fb);
}
-static INLINE void vcopy(real_t *src, real_t *dest, uint16_t vlen)
-{
- int16_t i;
-
- assert(vlen % 4 == 0);
-
- for (i = vlen/4-1; i >= 0; --i)
- {
- *dest++ = *src++; *dest++ = *src++; *dest++ = *src++; *dest++ = *src++;
- }
-}
-
-static INLINE void vzero(real_t *dest, uint16_t vlen)
-{
- int16_t i;
-
- assert(vlen % 4 == 0);
-
- for (i = vlen/4-1; i >= 0; --i)
- {
- *dest-- = 0; *dest-- = 0; *dest-- = 0; *dest-- = 0;
- }
-}
-
-static INLINE void vmult1(real_t *src1, real_t *src2, real_t *dest, uint16_t vlen)
-{
- int16_t i;
-
- assert(vlen % 4 == 0);
-
- for (i = vlen/4-1; i >= 0 ; --i)
- {
- *dest++ = MUL(*src1++, *src2++); *dest++ = MUL(*src1++, *src2++);
- *dest++ = MUL(*src1++, *src2++); *dest++ = MUL(*src1++, *src2++);
- }
-}
-
-static INLINE void vmult2(real_t *src1, real_t *src2, real_t *dest, uint16_t vlen)
-{
- int16_t i;
-
- assert(vlen % 4 == 0);
-
- for (i = vlen/4-1; i >= 0 ; --i)
- {
- *dest++ = MUL(*src1++, *src2--); *dest++ = MUL(*src1++, *src2--);
- *dest++ = MUL(*src1++, *src2--); *dest++ = MUL(*src1++, *src2--);
- }
-}
-
-static INLINE void vadd(real_t *src1, real_t *src2, real_t *dest, uint16_t vlen)
-{
- int16_t i;
-
- assert(vlen % 4 == 0);
-
- for (i = vlen/4-1; i >= 0; --i)
- {
- *dest++ = *src1++ + *src2++; *dest++ = *src1++ + *src2++;
- *dest++ = *src1++ + *src2++; *dest++ = *src1++ + *src2++;
- }
-}
-
static INLINE void imdct(fb_info *fb, real_t *in_data, real_t *out_data, uint16_t len)
{
mdct_info *mdct;
@@ -195,7 +148,7 @@
mdct = fb->mdct2048;
break;
case 256:
- case 120:
+ case 240:
mdct = fb->mdct256;
break;
#ifdef LD_DEC
@@ -211,22 +164,20 @@
#endif
void ifilter_bank(fb_info *fb, uint8_t window_sequence, uint8_t window_shape,
- uint8_t window_shape_prev, real_t *freq_in, real_t *time_buff,
+ uint8_t window_shape_prev, real_t *freq_in,
real_t *time_out, uint8_t object_type, uint16_t frame_len)
{
- real_t *o_buf, *transf_buf;
- real_t *obuf_temp;
+ int16_t i;
+ real_t *transf_buf;
real_t *window_long;
real_t *window_long_prev;
real_t *window_short;
real_t *window_short_prev;
- real_t *window_short_prev_ptr;
- real_t *fp;
- int8_t win;
uint16_t nlong = frame_len;
uint16_t nshort = frame_len/8;
+ uint16_t trans = nshort/2;
uint16_t nflat_ls = (nlong-nshort)/2;
@@ -247,135 +198,95 @@
}
#endif
- /* pointer to previous window function */
- window_short_prev_ptr = window_short_prev;
-
- vcopy(time_buff, time_out, nlong);
- o_buf = time_out;
-
switch (window_sequence)
{
case ONLY_LONG_SEQUENCE:
- /* inverse transform */
imdct(fb, freq_in, transf_buf, 2*nlong);
-
- /* window function (previous) on first half of the new data */
- vmult1(transf_buf, window_long_prev, transf_buf, nlong);
-
- /* overlap and add second half of the old data with first half
- of the new data */
- vadd(transf_buf, o_buf, o_buf, nlong);
-
- /* reversed window function on second half of the new data */
- vmult2(transf_buf+nlong, window_long+nlong-1, o_buf+nlong, nlong);
+ for (i = nlong-1; i >= 0; i--)
+ {
+ time_out[i] = time_out[nlong+i] + MUL_R_C(transf_buf[i],window_long_prev[i]);
+ time_out[nlong+i] = MUL_R_C(transf_buf[nlong+i],window_long[nlong-1-i]);
+ }
break;
case LONG_START_SEQUENCE:
- /* inverse transform */
imdct(fb, freq_in, transf_buf, 2*nlong);
-
- /* window function (previous) on first half of the new data */
- vmult1(transf_buf, window_long_prev, transf_buf, nlong);
-
- /* overlap and add second half of the old data with first half
- of the new data */
- vadd(transf_buf, o_buf, o_buf, nlong);
-
- /* copy data from nlong upto (3*nlong-nshort)/4; (window function = 1.0) */
- vcopy(transf_buf+nlong, o_buf+nlong, nflat_ls);
-
- /* reversed window function on part of second half of the new data */
- vmult2(transf_buf+nlong+nflat_ls, window_short+nshort-1,
- o_buf+nlong+nflat_ls, nshort);
-
- /* zero rest of the data; (window function = 0.0) */
- vzero(o_buf+2*nlong-1, nflat_ls);
+ for (i = nlong-1; i >= 0; i--)
+ time_out[i] = time_out[nlong+i] + MUL_R_C(transf_buf[i],window_long_prev[i]);
+ for (i = 0; i < nflat_ls; i++)
+ time_out[nlong+i] = transf_buf[nlong+i];
+ for (i = 0; i < nshort; i++)
+ time_out[nlong+nflat_ls+i] = MUL_R_C(transf_buf[nlong+nflat_ls+i],window_short[nshort-i-1]);
+ for (i = 0; i < nflat_ls; i++)
+ time_out[nlong+nflat_ls+nshort+i] = 0;
break;
case EIGHT_SHORT_SEQUENCE:
- obuf_temp = malloc(2*nlong*sizeof(real_t));
- vzero(obuf_temp+2*nlong-1, 2*nlong);
-
- fp = obuf_temp;
- vcopy(time_buff+nflat_ls, fp, nshort);
-
- for (win = 8-1; win >= 0; --win)
+ imdct(fb, freq_in+0*nshort, transf_buf+2*nshort*0, 2*nshort);
+ imdct(fb, freq_in+1*nshort, transf_buf+2*nshort*1, 2*nshort);
+ imdct(fb, freq_in+2*nshort, transf_buf+2*nshort*2, 2*nshort);
+ imdct(fb, freq_in+3*nshort, transf_buf+2*nshort*3, 2*nshort);
+ imdct(fb, freq_in+4*nshort, transf_buf+2*nshort*4, 2*nshort);
+ imdct(fb, freq_in+5*nshort, transf_buf+2*nshort*5, 2*nshort);
+ imdct(fb, freq_in+6*nshort, transf_buf+2*nshort*6, 2*nshort);
+ imdct(fb, freq_in+7*nshort, transf_buf+2*nshort*7, 2*nshort);
+ for (i = 0; i < nflat_ls; i++)
+ time_out[i] = time_out[nlong+i];
+ for(i = nshort-1; i >= 0; i--)
{
- /* inverse transform */
- imdct(fb, freq_in, transf_buf, 2*nshort);
-
- /* window function (previous) on first half of the new data */
- vmult1(transf_buf, window_short_prev_ptr, transf_buf, nshort);
-
- /* overlap and add second half of the old data with first half
- of the new data */
- vadd(transf_buf, fp, fp, nshort);
-
- /* reversed window function on second half of the new data */
- vmult2(transf_buf+nshort, window_short+nshort-1, fp+nshort, nshort);
-
- /* shift to next short block */
- freq_in += nshort;
- fp += nshort;
- window_short_prev_ptr = window_short;
+ time_out[nflat_ls+ i] = time_out[nlong+nflat_ls+ i] + MUL_R_C(transf_buf[nshort*0+i],window_short_prev[i]);
+ time_out[nflat_ls+1*nshort+i] = time_out[nlong+nflat_ls+nshort*1+i] + MUL_R_C(transf_buf[nshort*1+i],window_short[nshort-1-i]) + MUL_R_C(transf_buf[nshort*2+i],window_short[i]);
+ time_out[nflat_ls+2*nshort+i] = time_out[nlong+nflat_ls+nshort*2+i] + MUL_R_C(transf_buf[nshort*3+i],window_short[nshort-1-i]) + MUL_R_C(transf_buf[nshort*4+i],window_short[i]);
+ time_out[nflat_ls+3*nshort+i] = time_out[nlong+nflat_ls+nshort*3+i] + MUL_R_C(transf_buf[nshort*5+i],window_short[nshort-1-i]) + MUL_R_C(transf_buf[nshort*6+i],window_short[i]);
+ if (i < trans)
+ time_out[nflat_ls+4*nshort+i] = time_out[nlong+nflat_ls+nshort*4+i] + MUL_R_C(transf_buf[nshort*7+i],window_short[nshort-1-i]) + MUL_R_C(transf_buf[nshort*8+i],window_short[i]);
+ else
+ time_out[nflat_ls+4*nshort+i] = MUL_R_C(transf_buf[nshort*7+i],window_short[nshort-1-i]) + MUL_R_C(transf_buf[nshort*8+i],window_short[i]);
+ time_out[nflat_ls+5*nshort+i] = MUL_R_C(transf_buf[nshort*9+i],window_short[nshort-1-i]) + MUL_R_C(transf_buf[nshort*10+i],window_short[i]);
+ time_out[nflat_ls+6*nshort+i] = MUL_R_C(transf_buf[nshort*11+i],window_short[nshort-1-i]) + MUL_R_C(transf_buf[nshort*12+i],window_short[i]);
+ time_out[nflat_ls+7*nshort+i] = MUL_R_C(transf_buf[nshort*13+i],window_short[nshort-1-i]) + MUL_R_C(transf_buf[nshort*14+i],window_short[i]);
+ time_out[nflat_ls+8*nshort+i] = MUL_R_C(transf_buf[nshort*15+i],window_short[nshort-1-i]);
}
-
- vcopy(obuf_temp, o_buf + nflat_ls, nlong*2-nflat_ls);
- vzero(o_buf+2*nlong-1, nflat_ls);
-
- free(obuf_temp);
+ for (i = 0; i < nflat_ls; i++)
+ time_out[nlong+nflat_ls+nshort+i] = 0;
break;
case LONG_STOP_SEQUENCE:
- /* inverse transform */
imdct(fb, freq_in, transf_buf, 2*nlong);
-
- /* zero first part of first half of the data (window function = 0.0) */
- vzero(transf_buf+nflat_ls-1, nflat_ls);
-
- /* window function (previous) on part of the first half of
- the new data */
- vmult1(transf_buf+nflat_ls, window_short_prev_ptr,
- transf_buf+nflat_ls, nshort);
-
- /* third part of the stop sequence window is window function = 1,
- so no need to actually apply that */
-
- /* overlap and add second half of the old data with first half
- of the new data */
- vadd(transf_buf, o_buf, o_buf, nlong);
-
- /* reversed window function on second half of the new data */
- vmult2(transf_buf+nlong, window_long+nlong-1, o_buf+nlong, nlong);
+ for (i = 0; i < nflat_ls; i++)
+ time_out[i] = time_out[nlong+i];
+ for (i = 0; i < nshort; i++)
+ time_out[nflat_ls+i] = time_out[nlong+nflat_ls+i] + MUL_R_C(transf_buf[nflat_ls+i],window_short_prev[i]);
+ for (i = 0; i < nflat_ls; i++)
+ time_out[nflat_ls+nshort+i] = time_out[nlong+nflat_ls+nshort+i] + transf_buf[nflat_ls+nshort+i];
+ for (i = nlong-1; i >= 0; i--)
+ time_out[nlong+i] = MUL_R_C(transf_buf[nlong+i],window_long[nlong-1-i]);
break;
}
- /* save second half of data */
- vcopy(o_buf+nlong, time_buff, nlong);
-
free(transf_buf);
}
#ifdef LTP_DEC
-/* only works for LTP -> no overlapping */
+/* only works for LTP -> no overlapping no short blocks */
void filter_bank_ltp(fb_info *fb, uint8_t window_sequence, uint8_t window_shape,
uint8_t window_shape_prev, real_t *in_data, real_t *out_mdct,
uint8_t object_type, uint16_t frame_len)
{
- int8_t win;
+ int16_t i;
real_t *windowed_buf;
- real_t *p_o_buf;
real_t *window_long;
real_t *window_long_prev;
real_t *window_short;
real_t *window_short_prev;
- real_t *window_short_prev_ptr;
uint16_t nlong = frame_len;
uint16_t nshort = frame_len/8;
uint16_t nflat_ls = (nlong-nshort)/2;
+ assert(window_sequence != EIGHT_SHORT_SEQUENCE);
+
windowed_buf = malloc(nlong*2*sizeof(real_t));
#ifdef LD_DEC
@@ -393,44 +304,38 @@
}
#endif
- window_short_prev_ptr = window_short_prev;
-
- p_o_buf = in_data;
-
switch(window_sequence)
{
case ONLY_LONG_SEQUENCE:
- vmult1(p_o_buf, window_long_prev, windowed_buf, nlong);
- vmult2(p_o_buf+nlong, window_long+nlong-1, windowed_buf+nlong, nlong);
+ for (i = nlong-1; i >= 0; i--)
+ {
+ windowed_buf[i] = MUL_R_C(in_data[i], window_long_prev[i]);
+ windowed_buf[i+nlong] = MUL_R_C(in_data[i+nlong], window_long[nlong-1-i]);
+ }
mdct(fb, windowed_buf, out_mdct, 2*nlong);
break;
case LONG_START_SEQUENCE:
- vmult1(p_o_buf, window_long_prev, windowed_buf, nlong);
- vcopy(p_o_buf+nlong, windowed_buf+nlong, nflat_ls);
- vmult2(p_o_buf+nlong+nflat_ls, window_short+nshort-1, windowed_buf+nlong+nflat_ls, nshort);
- vzero(windowed_buf+2*nlong-1, nflat_ls);
+ for (i = 0; i < nlong; i++)
+ windowed_buf[i] = MUL_R_C(in_data[i], window_long_prev[i]);
+ for (i = 0; i < nflat_ls; i++)
+ windowed_buf[i+nlong] = in_data[i+nlong];
+ for (i = 0; i < nshort; i++)
+ windowed_buf[i+nlong+nflat_ls] = MUL_R_C(in_data[i+nlong+nflat_ls], window_short[nshort-1-i]);
+ for (i = 0; i < nflat_ls; i++)
+ windowed_buf[i+nlong+nflat_ls+nshort] = 0;
mdct(fb, windowed_buf, out_mdct, 2*nlong);
break;
- case EIGHT_SHORT_SEQUENCE:
- for (win = 8-1; win >= 0; --win)
- {
- vmult1(p_o_buf, window_short_prev_ptr, windowed_buf, nshort);
- vmult2(p_o_buf+nshort, window_short+nshort-1, windowed_buf+nshort, nshort);
- mdct(fb, windowed_buf, out_mdct, 2*nshort);
-
- out_mdct += nshort;
- p_o_buf += 2*nshort;
- window_short_prev_ptr = window_short;
- }
- break;
-
case LONG_STOP_SEQUENCE:
- vzero(windowed_buf+nflat_ls-1, nflat_ls);
- vmult1(p_o_buf+nflat_ls, window_short_prev_ptr, windowed_buf+nflat_ls, nshort);
- vcopy(p_o_buf+nflat_ls+nshort, windowed_buf+nflat_ls+nshort, nflat_ls);
- vmult2(p_o_buf+nlong, window_long+nlong-1, windowed_buf+nlong, nlong);
+ for (i = 0; i < nflat_ls; i++)
+ windowed_buf[i] = 0;
+ for (i = 0; i < nshort; i++)
+ windowed_buf[i+nflat_ls] = MUL_R_C(in_data[i+nflat_ls], window_short_prev[i]);
+ for (i = 0; i < nflat_ls; i++)
+ windowed_buf[i+nflat_ls+nshort] = in_data[i+nflat_ls+nshort];
+ for (i = 0; i < nlong; i++)
+ windowed_buf[i+nlong] = MUL_R_C(in_data[i+nlong], window_long[nlong-1-i]);
mdct(fb, windowed_buf, out_mdct, 2*nlong);
break;
}
--- a/libfaad/filtbank.h
+++ b/libfaad/filtbank.h
@@ -16,7 +16,7 @@
** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
**
-** $Id: filtbank.h,v 1.8 2002/08/17 10:03:14 menno Exp $
+** $Id: filtbank.h,v 1.9 2002/08/26 18:41:47 menno Exp $
**/
#ifndef __FILTBANK_H__
@@ -63,7 +63,6 @@
uint8_t window_shape,
uint8_t window_shape_prev,
real_t *freq_in,
- real_t *time_buff,
real_t *time_out,
uint8_t object_type,
uint16_t frame_len);
--- a/libfaad/is.c
+++ b/libfaad/is.c
@@ -16,7 +16,7 @@
** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
**
-** $Id: is.c,v 1.7 2002/08/17 12:27:33 menno Exp $
+** $Id: is.c,v 1.8 2002/08/26 18:41:47 menno Exp $
**/
#include "common.h"
@@ -24,11 +24,89 @@
#include "syntax.h"
#include "is.h"
+#ifdef FIXED_POINT
+
+static real_t pow05_table[4] = {
+ COEF_CONST(1.0),
+ COEF_CONST(0.8408964), /* pow(2,-.25) */
+ COEF_CONST(0.7071068), /* pow(2,-.5) */
+ COEF_CONST(0.5946036) /* pow(2,-.75) */
+};
+
void is_decode(ic_stream *ics, ic_stream *icsr, real_t *l_spec, real_t *r_spec,
uint16_t frame_len)
{
uint8_t g, sfb, b;
uint16_t i, k;
+
+ uint16_t nshort = frame_len/8;
+ uint8_t group = 0;
+
+ for (g = 0; g < icsr->num_window_groups; g++)
+ {
+ // Do intensity stereo decoding
+ for (b = 0; b < icsr->window_group_length[g]; b++)
+ {
+ for (sfb = 0; sfb < icsr->max_sfb; sfb++)
+ {
+ if (is_intensity(icsr, g, sfb))
+ {
+ real_t frac;
+
+ // For scalefactor bands coded in intensity stereo the
+ // corresponding predictors in the right channel are
+ // switched to "off".
+ ics->pred.prediction_used[sfb] = 0;
+ icsr->pred.prediction_used[sfb] = 0;
+
+ frac = pow05_table[icsr->scale_factors[g][sfb] & 3];
+
+ if (is_intensity(icsr, g, sfb) != invert_intensity(ics, g, sfb))
+ frac = -frac;
+#if 0
+ float32_t scale = is_intensity(icsr, g, sfb) *
+ invert_intensity(ics, g, sfb) *
+ (real_t)exp(LN05 * (0.25*icsr->scale_factors[g][sfb]));
+#endif
+
+ if (icsr->scale_factors[g][sfb] > 0)
+ {
+ int32_t shift = icsr->scale_factors[g][sfb] >> 2;
+
+ if (shift > 31)
+ shift = 31;
+ for (i = icsr->swb_offset[sfb]; i < icsr->swb_offset[sfb+1]; i++)
+ {
+ k = (group*nshort) + i;
+ r_spec[k] = l_spec[k];
+ r_spec[k] >>= shift;
+ r_spec[k] = MUL_R_C(r_spec[k],frac);
+ }
+ } else {
+ int32_t shift = -(icsr->scale_factors[g][sfb] >> 2);
+
+ for (i = icsr->swb_offset[sfb]; i < icsr->swb_offset[sfb+1]; i++)
+ {
+ k = (group*nshort)+i;
+ r_spec[k] = l_spec[k];
+ r_spec[k] <<= shift;
+ r_spec[k] = MUL_R_C(r_spec[k],frac);
+ }
+ }
+ }
+ }
+ group++;
+ }
+ }
+}
+
+#else
+
+void is_decode(ic_stream *ics, ic_stream *icsr, real_t *l_spec, real_t *r_spec,
+ uint16_t frame_len)
+{
+ uint8_t g, sfb, b;
+ uint16_t i, k;
real_t scale;
uint16_t nshort = frame_len/8;
@@ -50,9 +128,9 @@
ics->pred.prediction_used[sfb] = 0;
icsr->pred.prediction_used[sfb] = 0;
- scale = MUL(is_intensity(icsr, g, sfb),
- MUL(invert_intensity(ics, g, sfb),
- REAL_CONST(exp(LN05 * (0.25*icsr->scale_factors[g][sfb])))));
+ scale = is_intensity(icsr, g, sfb) *
+ invert_intensity(ics, g, sfb) *
+ exp(LN05 * (0.25*icsr->scale_factors[g][sfb]));
/* Scale from left to right channel,
do not touch left channel */
@@ -67,3 +145,5 @@
}
}
}
+
+#endif
--- a/libfaad/kbd_win.h
+++ b/libfaad/kbd_win.h
@@ -16,7 +16,7 @@
** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
**
-** $Id: kbd_win.h,v 1.2 2002/02/18 10:01:05 menno Exp $
+** $Id: kbd_win.h,v 1.3 2002/08/26 18:41:47 menno Exp $
**/
#ifndef __KBD_WIN_H__
@@ -28,9 +28,10 @@
#ifdef _MSC_VER
#pragma warning(disable:4305)
+#pragma warning(disable:4244)
#endif
-real_t kbd_long[] =
+float32_t kbd_long[] =
{
0.00029256153896361,
0.00042998567353047,
@@ -1059,7 +1060,7 @@
};
-real_t kbd_short[] =
+float32_t kbd_short[] =
{
4.3795702929468881e-005,
0.00011867384265436617,
--- a/libfaad/libfaad.vcproj
+++ b/libfaad/libfaad.vcproj
@@ -21,10 +21,10 @@
<Tool
Name="VCCLCompilerTool"
Optimization="0"
- AdditionalIncludeDirectories=""
- PreprocessorDefinitions="_DEBUG,WIN32"
+ AdditionalIncludeDirectories="fftw"
+ PreprocessorDefinitions="_DEBUG,WIN32,_LIB,FFTW_ENABLE_FLOAT"
BasicRuntimeChecks="3"
- RuntimeLibrary="5"
+ RuntimeLibrary="1"
UsePrecompiledHeader="2"
PrecompiledHeaderFile=".\Debug/libfaad.pch"
AssemblerListingLocation=".\Debug/"
@@ -68,9 +68,10 @@
GlobalOptimizations="TRUE"
InlineFunctionExpansion="1"
EnableIntrinsicFunctions="TRUE"
+ FavorSizeOrSpeed="1"
OptimizeForProcessor="2"
AdditionalIncludeDirectories=""
- PreprocessorDefinitions="NDEBUG,WIN32"
+ PreprocessorDefinitions="NDEBUG,WIN32,_LIB"
StringPooling="TRUE"
RuntimeLibrary="4"
EnableFunctionLevelLinking="TRUE"
@@ -124,7 +125,7 @@
RelativePath=".\decoder.c">
</File>
<File
- RelativePath="dither.c">
+ RelativePath=".\dither.c">
</File>
<File
RelativePath=".\drc.c">
@@ -246,6 +247,9 @@
RelativePath=".\common.h">
</File>
<File
+ RelativePath=".\fftw\config.h">
+ </File>
+ <File
RelativePath=".\data.h">
</File>
<File
@@ -252,7 +256,7 @@
RelativePath=".\decoder.h">
</File>
<File
- RelativePath="dither.h">
+ RelativePath=".\dither.h">
</File>
<File
RelativePath=".\drc.h">
@@ -259,6 +263,9 @@
</File>
<File
RelativePath=".\error.h">
+ </File>
+ <File
+ RelativePath=".\fftw\f77_func.h">
</File>
<File
RelativePath=".\filtbank.h">
--- a/libfaad/mdct.c
+++ b/libfaad/mdct.c
@@ -16,7 +16,7 @@
** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
**
-** $Id: mdct.c,v 1.15 2002/08/17 12:27:33 menno Exp $
+** $Id: mdct.c,v 1.16 2002/08/26 18:41:47 menno Exp $
**/
/*
@@ -31,8 +31,7 @@
*
*
* As of April 6th 2002 completely rewritten.
- * Thanks to the FFTW library this (I)MDCT can now be used for any data
- * size n, where n is divisible by 8.
+ * This (I)MDCT can now be used for any data size n, where n is divisible by 8.
*
*/
@@ -55,6 +54,7 @@
mdct_info *faad_mdct_init(uint16_t N)
{
uint16_t k;
+ float32_t scale = sqrt(2.0/(float32_t)N);
mdct_info *mdct = malloc(sizeof(mdct_info));
@@ -72,9 +72,9 @@
for (k = 0; k < N/4; k++)
{
- real_t angle = 2.0 * M_PI * ((real_t)k + 1.0/8.0)/(real_t)N;
- mdct->sincos[k].sin = REAL_CONST(-sin(angle));
- mdct->sincos[k].cos = REAL_CONST(-cos(angle));
+ float32_t angle = 2.0 * M_PI * ((float32_t)k + 0.125)/(float32_t)N;
+ mdct->sincos[k].sin = COEF_CONST(-sin(angle)*scale);
+ mdct->sincos[k].cos = COEF_CONST(-cos(angle)*scale);
}
#ifdef USE_FFTW
@@ -126,8 +126,6 @@
uint16_t N4 = N >> 2;
uint16_t N8 = N >> 3;
- real_t fac = REAL_CONST(2.0/(real_t)N);
-
/* pre-IFFT complex multiplication */
for (k = 0; k < N4; k++)
{
@@ -135,11 +133,11 @@
real_t x0 = X_in[ n];
real_t x1 = X_in[N2 - 1 - n];
#ifdef USE_FFTW
- Z1[k].re = MUL(fac, MUL(x1, sincos[k].cos) - MUL(x0, sincos[k].sin));
- Z1[k].im = MUL(fac, MUL(x0, sincos[k].cos) + MUL(x1, sincos[k].sin));
+ Z1[k].re = MUL_R_C(x1, sincos[k].cos) - MUL_R_C(x0, sincos[k].sin);
+ Z1[k].im = MUL_R_C(x0, sincos[k].cos) + MUL_R_C(x1, sincos[k].sin);
#else
- Z1[n] = MUL(fac, MUL(x1, sincos[k].cos) - MUL(x0, sincos[k].sin));
- Z1[n+1] = MUL(fac, MUL(x0, sincos[k].cos) + MUL(x1, sincos[k].sin));
+ Z1[n] = MUL_R_C(x1, sincos[k].cos) - MUL_R_C(x0, sincos[k].sin);
+ Z1[n+1] = MUL_R_C(x0, sincos[k].cos) + MUL_R_C(x1, sincos[k].sin);
#endif
}
@@ -161,8 +159,8 @@
real_t zr = Z1[n];
real_t zi = Z1[n+1];
#endif
- Z2[k].re = MUL(zr, sincos[k].cos) - MUL(zi, sincos[k].sin);
- Z2[k].im = MUL(zi, sincos[k].cos) + MUL(zr, sincos[k].sin);
+ Z2[k].re = MUL_R_C(zr, sincos[k].cos) - MUL_R_C(zi, sincos[k].sin);
+ Z2[k].im = MUL_R_C(zi, sincos[k].cos) + MUL_R_C(zr, sincos[k].sin);
}
/* reordering */
@@ -169,14 +167,14 @@
for (k = 0; k < N8; k++)
{
uint16_t n = k << 1;
- X_out[ n] = -Z2[N8 + k].im;
- X_out[ 1 + n] = Z2[N8 - 1 - k].re;
- X_out[N4 + n] = -Z2[ k].re;
- X_out[N4 + 1 + n] = Z2[N4 - 1 - k].im;
- X_out[N2 + n] = -Z2[N8 + k].re;
- X_out[N2 + 1 + n] = Z2[N8 - 1 - k].im;
- X_out[N2 + N4 + n] = Z2[ k].im;
- X_out[N2 + N4 + 1 + n] = -Z2[N4 - 1 - k].re;
+ X_out[ n] = Z2[N8 + k].im;
+ X_out[ 1 + n] = -Z2[N8 - 1 - k].re;
+ X_out[N4 + n] = Z2[ k].re;
+ X_out[N4 + 1 + n] = -Z2[N4 - 1 - k].im;
+ X_out[N2 + n] = Z2[N8 + k].re;
+ X_out[N2 + 1 + n] = -Z2[N8 - 1 - k].im;
+ X_out[N2 + N4 + n] = -Z2[ k].im;
+ X_out[N2 + N4 + 1 + n] = Z2[N4 - 1 - k].re;
}
}
@@ -186,8 +184,8 @@
uint16_t k;
#ifdef USE_FFTW
- fftw_complex *Z1 = mdct->Z1;
- fftw_complex *Z2 = mdct->Z2;
+ fftw_complex *Z1 = mdct->Z1;
+ fftw_complex *Z2 = mdct->Z2;
#else
real_t *Z1 = mdct->Z1;
#endif
@@ -198,31 +196,49 @@
uint16_t N4 = N >> 2;
uint16_t N8 = N >> 3;
+#ifdef FIXED_POINT
+ int16_t shift = -5;
+ real_t scale;
+ float32_t NN = N;
+ while (NN >= 0.5)
+ {
+ NN /= 2;
+ shift++;
+ }
+ scale = COEF_CONST(NN);
+#else
+ real_t scale = N;
+#endif
/* pre-FFT complex multiplication */
for (k = 0; k < N8; k++)
{
uint16_t n = k << 1;
- real_t zr = X_in[N - N4 - 1 - n] + X_in[N - N4 + n];
- real_t zi = X_in[ N4 + n] - X_in[ N4 - 1 - n];
+ real_t zr = X_in[N - N4 - 1 - n] + X_in[N - N4 + n];
+ real_t zi = X_in[ N4 + n] - X_in[ N4 - 1 - n];
+#ifdef FIXED_POINT
+ zr <<= 5;
+ zi <<= 5;
+#endif
+
#ifdef USE_FFTW
- Z1[k ].re = -MUL(zr, sincos[k ].cos) - MUL(zi, sincos[k ].sin);
- Z1[k ].im = -MUL(zi, sincos[k ].cos) + MUL(zr, sincos[k ].sin);
+ Z1[k].re = -MUL_R_C(zr, sincos[k].cos) - MUL_R_C(zi, sincos[k].sin);
+ Z1[k].im = -MUL_R_C(zi, sincos[k].cos) + MUL_R_C(zr, sincos[k].sin);
#else
- Z1[n ] = -MUL(zr, sincos[k ].cos) - MUL(zi, sincos[k ].sin);
- Z1[n+1 ] = -MUL(zi, sincos[k ].cos) + MUL(zr, sincos[k ].sin);
+ Z1[n] = -MUL_R_C(zr, sincos[k].cos) - MUL_R_C(zi, sincos[k].sin);
+ Z1[n+1] = -MUL_R_C(zi, sincos[k].cos) + MUL_R_C(zr, sincos[k].sin);
#endif
- zr = X_in[ N2 - 1 - n] - X_in[ n];
- zi = X_in[ N2 + n] + X_in[N - 1 - n];
+ zr = X_in[N2 - 1 - n] - X_in[ n];
+ zi = X_in[N2 + n] + X_in[N - 1 - n];
#ifdef USE_FFTW
- Z1[k + N8].re = -MUL(zr, sincos[k + N8].cos) - MUL(zi, sincos[k + N8].sin);
- Z1[k + N8].im = -MUL(zi, sincos[k + N8].cos) + MUL(zr, sincos[k + N8].sin);
+ Z1[k + N8].re = -MUL_R_C(zr, sincos[k + N8].cos) - MUL_R_C(zi, sincos[k + N8].sin);
+ Z1[k + N8].im = -MUL_R_C(zi, sincos[k + N8].cos) + MUL_R_C(zr, sincos[k + N8].sin);
#else
- Z1[n + N8] = -MUL(zr, sincos[k + N8].cos) - MUL(zi, sincos[k + N8].sin);
- Z1[n+1 + N8] = -MUL(zi, sincos[k + N8].cos) + MUL(zr, sincos[k + N8].sin);
+ Z1[n + N4] = -MUL_R_C(zr, sincos[k + N8].cos) - MUL_R_C(zi, sincos[k + N8].sin);
+ Z1[n+1 + N4] = -MUL_R_C(zi, sincos[k + N8].cos) + MUL_R_C(zr, sincos[k + N8].sin);
#endif
}
@@ -238,17 +254,21 @@
{
uint16_t n = k << 1;
#ifdef USE_FFTW
- real_t zr = 2 * MUL(Z2[k].re, sincos[k].cos) + MUL(Z2[k].im, sincos[k].sin);
- real_t zi = 2 * MUL(Z2[k].im, sincos[k].cos) - MUL(Z2[k].re, sincos[k].sin);
+ real_t zr = MUL_R_C(MUL_R_C(Z2[k].re, sincos[k].cos) + MUL_R_C(Z2[k].im, sincos[k].sin), scale);
+ real_t zi = MUL_R_C(MUL_R_C(Z2[k].im, sincos[k].cos) - MUL_R_C(Z2[k].re, sincos[k].sin), scale);
#else
- real_t zr = 2 * MUL(Z1[n], sincos[k].cos) + MUL(Z1[n+1], sincos[k].sin);
- real_t zi = 2 * MUL(Z1[n+1], sincos[k].cos) - MUL(Z1[n], sincos[k].sin);
+ real_t zr = MUL_R_C(MUL_R_C(Z1[n], sincos[k].cos) + MUL_R_C(Z1[n+1], sincos[k].sin), scale);
+ real_t zi = MUL_R_C(MUL_R_C(Z1[n+1], sincos[k].cos) - MUL_R_C(Z1[n], sincos[k].sin), scale);
#endif
+#ifdef FIXED_POINT
+ zr <<= shift;
+ zi <<= shift;
+#endif
- X_out[ n] = -zr;
- X_out[N2 - 1 - n] = zi;
- X_out[N2 + n] = -zi;
- X_out[N - 1 - n] = zr;
+ X_out[ n] = zr;
+ X_out[N2 - 1 - n] = -zi;
+ X_out[N2 + n] = zi;
+ X_out[N - 1 - n] = -zr;
}
}
#endif
--- a/libfaad/output.c
+++ b/libfaad/output.c
@@ -16,7 +16,7 @@
** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
**
-** $Id: output.c,v 1.10 2002/08/13 19:16:07 menno Exp $
+** $Id: output.c,v 1.11 2002/08/26 18:41:47 menno Exp $
**/
#include "common.h"
@@ -41,6 +41,7 @@
double doubletmp;
+#ifndef FIXED_POINT
void* output_to_PCM(real_t **input, void *sample_buffer, uint8_t channels,
uint16_t frame_len, uint8_t format)
{
@@ -47,7 +48,6 @@
uint8_t ch;
uint16_t i;
- uint8_t *p = (uint8_t*)sample_buffer;
int16_t *short_sample_buffer = (int16_t*)sample_buffer;
int32_t *int_sample_buffer = (int32_t*)sample_buffer;
float32_t *float_sample_buffer = (float32_t*)sample_buffer;
@@ -126,6 +126,31 @@
return sample_buffer;
}
+#else
+void* output_to_PCM(real_t **input, void *sample_buffer, uint8_t channels,
+ uint16_t frame_len, uint8_t format)
+{
+ uint8_t ch;
+ uint16_t i;
+ int16_t *short_sample_buffer = (int16_t*)sample_buffer;
+
+ /* Copy output to a standard PCM buffer */
+ for (ch = 0; ch < channels; ch++)
+ {
+ for(i = 0; i < frame_len; i++)
+ {
+ int32_t tmp = input[ch][i];
+ tmp += (1 << (REAL_BITS-1));
+ tmp >>= REAL_BITS;
+ if (tmp > 0x7fff) tmp = 0x7fff;
+ else if (tmp <= -32768) tmp = -32768;
+ short_sample_buffer[(i*channels)+ch] = (int16_t)tmp;
+ }
+ }
+
+ return sample_buffer;
+}
+#endif
/* Dither output */
static int64_t dither_output(uint8_t dithering, double Sum, uint8_t k)
--- a/libfaad/pns.c
+++ b/libfaad/pns.c
@@ -16,7 +16,7 @@
** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
**
-** $Id: pns.c,v 1.10 2002/08/17 12:27:33 menno Exp $
+** $Id: pns.c,v 1.11 2002/08/26 18:41:47 menno Exp $
**/
#include "common.h"
@@ -74,26 +74,18 @@
static INLINE void gen_rand_vector(real_t *spec, uint16_t scale_factor, uint16_t size)
{
uint16_t i;
- real_t scale;
- for (i = 0; i < size; i++)
- {
- spec[i] = (real_t)random2();
- }
-
/* 14496-3 says:
- scale = 1.0f/(size * (real_t)sqrt(MEAN_NRG));
+ scale = 1.0f/(size * (fftw_real)sqrt(MEAN_NRG));
*/
- scale = REAL_CONST(sqrt(size * MEAN_NRG));
- if (scale != 0.0)
- {
- scale = 1.0/scale; /* <-- TODO */
- scale = MUL(scale, REAL_CONST(exp(LN2 * 0.25 * scale_factor)));
- }
+ float32_t scale = 1.0/(float32_t)sqrt(size * MEAN_NRG);
- /* Scale random vector to desired target energy */
+ scale *= (float32_t)exp(LN2 * 0.25 * scale_factor);
+
for (i = 0; i < size; i++)
- spec[i] = MUL(spec[i], scale);
+ {
+ spec[i] = REAL_CONST(scale*(float32_t)random2());
+ }
}
void pns_decode(ic_stream *ics, real_t *spec, uint16_t frame_len)
--- a/libfaad/reordered_spectral_data.c
+++ b/libfaad/reordered_spectral_data.c
@@ -43,29 +43,29 @@
typedef struct
{
/* bit input */
- uint32_t bufa;
- uint32_t bufb;
- int8_t len;
+ uint32_t bufa;
+ uint32_t bufb;
+ int8_t len;
} bits_t;
-static INLINE uint32_t showbits(bits_t *ld, uint8_t bits) {
-
- if (bits == 0) return 0;
+static INLINE uint32_t showbits(bits_t *ld, uint8_t bits)
+{
+ if (bits == 0) return 0;
if (ld->len <= 32){
- /* huffman_spectral_data_2 needs to read more than may be available, bits maybe
- > ld->len, deliver 0 than */
+ /* huffman_spectral_data_2 needs to read more than may be available, bits maybe
+ > ld->len, deliver 0 than */
if (ld->len >= bits)
- return ((ld->bufa >> (ld->len - bits)) & (0xFFFFFFFF >> (32 - bits)));
+ return ((ld->bufa >> (ld->len - bits)) & (0xFFFFFFFF >> (32 - bits)));
else
- return ((ld->bufa << (bits - ld->len)) & (0xFFFFFFFF >> (32 - bits)));
+ return ((ld->bufa << (bits - ld->len)) & (0xFFFFFFFF >> (32 - bits)));
} else {
- if ((ld->len - bits) < 32) {
-
- return ( (ld->bufb & (0xFFFFFFFF >> (64 - ld->len))) << (bits - ld->len + 32)) |
- (ld->bufa >> (ld->len - bits));
+ if ((ld->len - bits) < 32)
+ {
+ return ( (ld->bufb & (0xFFFFFFFF >> (64 - ld->len))) << (bits - ld->len + 32)) |
+ (ld->bufa >> (ld->len - bits));
} else {
- return ((ld->bufb >> (ld->len - bits - 32)) & (0xFFFFFFFF >> (32 - bits)));
+ return ((ld->bufb >> (ld->len - bits - 32)) & (0xFFFFFFFF >> (32 - bits)));
}
}
}
@@ -73,37 +73,39 @@
/* return 1 if position is outside of buffer, 0 otherwise */
static INLINE int8_t flushbits( bits_t *ld, uint8_t bits)
{
- ld->len -= bits;
-
- if (ld->len <0) {
- ld->len = 0;
- return 1;
- } else
- return 0;
+ ld->len -= bits;
+
+ if (ld->len <0)
+ {
+ ld->len = 0;
+ return 1;
+ } else {
+ return 0;
+ }
}
static INLINE int8_t getbits(bits_t *ld, uint8_t n, uint32_t *result)
{
- *result = showbits(ld, n);
- return flushbits(ld, n);
+ *result = showbits(ld, n);
+ return flushbits(ld, n);
}
static INLINE int8_t get1bit(bits_t *ld, uint8_t *result)
{
- uint32_t res;
+ uint32_t res;
int8_t ret;
-
+
ret = getbits(ld, 1, &res);
*result = res & 1;
return ret;
}
-
+
/* Special version of huffman_spectral_data adapted from huffman.h
- Will not read from a bitfile but a bits_t structure.
- Will keep track of the bits decoded and return the number of bits remaining.
- Do not read more than ld->len, return -1 if codeword would be longer */
-
+Will not read from a bitfile but a bits_t structure.
+Will keep track of the bits decoded and return the number of bits remaining.
+Do not read more than ld->len, return -1 if codeword would be longer */
+
static int8_t huffman_spectral_data_2(uint8_t cb, bits_t *ld, int16_t *sp )
{
uint32_t cw;
@@ -111,8 +113,8 @@
uint8_t extra_bits;
uint8_t i;
uint8_t save_cb = cb;
-
+
switch (cb)
{
case 1: /* 2-step method for data quadruples */
@@ -222,11 +224,11 @@
/* decode huffman escape bits */
if ((cb == ESC_HCB) || (cb >= 16))
{
- uint8_t k;
- for (k=0; k<2; k++){
-
- if ((sp[k] == 16) || (sp[k] == -16)) {
-
+ uint8_t k;
+ for (k = 0; k < 2; k++)
+ {
+ if ((sp[k] == 16) || (sp[k] == -16))
+ {
uint8_t neg, i;
int32_t j, off;
@@ -234,19 +236,19 @@
for (i = 4; ; i++)
{
- uint8_t b;
- if ( get1bit(ld, &b) ) return -1;
+ uint8_t b;
+ if (get1bit(ld, &b))
+ return -1;
if (b == 0)
- {
break;
- }
}
// TODO: here we would need to test "off" if VCB11 is used!
- if ( getbits(ld, i, &off) ) return -1;
+ if (getbits(ld, i, &off))
+ return -1;
j = off + (1<<i);
sp[k] = neg ? -j : j;
- }
- }
+ }
+ }
}
return ld->len;
}
@@ -253,12 +255,13 @@
/* rewind len (max. 32) bits so that the MSB becomes LSB */
-static uint32_t rewind_word( uint32_t W, uint8_t len){
-
- uint8_t i;
+static uint32_t rewind_word( uint32_t W, uint8_t len)
+{
+ uint8_t i;
uint32_t tmp_W=0;
-
- for ( i=0; i<len; i++ ) {
+
+ for ( i=0; i<len; i++ )
+ {
tmp_W<<=1;
if (W & (1<<i)) tmp_W |= 1;
}
@@ -265,29 +268,30 @@
return tmp_W;
}
-static void rewind_lword( uint32_t *highW, uint32_t *lowW, uint8_t len){
-
+static void rewind_lword( uint32_t *highW, uint32_t *lowW, uint8_t len)
+{
uint32_t tmp_lW=0;
- if (len > 32) {
- tmp_lW = rewind_word( (*highW << (64-len)) | (*lowW >> (len-32)), 32);
+ if (len > 32)
+ {
+ tmp_lW = rewind_word( (*highW << (64-len)) | (*lowW >> (len-32)), 32);
*highW = rewind_word( *lowW << (64-len) , 32);
*lowW = tmp_lW;
} else {
- *highW =0;
+ *highW = 0;
*lowW = rewind_word( *lowW, len);
}
}
/* Takes a codeword as stored in r, rewinds the remaining bits and stores it back */
+static void rewind_bits(bits_t * r)
+{
+ uint32_t hw, lw;
-static void rewind_bits(bits_t * r){
+ if (r->len == 0) return;
- uint32_t hw, lw;
-
- if (r->len == 0) return;
-
- if (r->len >32) {
+ if (r->len >32)
+ {
lw = r->bufa;
hw = r->bufb & (0xFFFFFFFF >> (64 - r->len));
rewind_lword( &hw, &lw, r->len );
@@ -298,23 +302,23 @@
lw = showbits(r, r->len );
r->bufa = rewind_word( lw, r->len);
r->bufb = 0;
- }
+ }
}
/* takes codewords from a and b, concatenate them and store them in b */
+static void concat_bits( bits_t * a, bits_t * b)
+{
+ uint32_t hwa, lwa, hwb, lwb;
-static void concat_bits( bits_t * a, bits_t * b) {
-
- uint32_t hwa, lwa, hwb, lwb;
-
if (a->len == 0) return;
- if (a->len >32) {
+ if (a->len >32)
+ {
lwa = a->bufa;
hwa = a->bufb & (0xFFFFFFFF >> (64 - a->len));
} else {
lwa = showbits(a, a->len );
- hwa = 0;
+ hwa = 0;
}
if (b->len >=32) {
lwb = b->bufa;
@@ -321,7 +325,7 @@
hwb = (b->bufb & (0xFFFFFFFF >> (64 - b->len)) ) | ( lwa << (b->len - 32));
} else {
lwb = showbits(b, b->len ) | (lwa << (b->len));
- hwb = (lwa >> (32 - b->len)) | (hwa << (b->len));
+ hwb = (lwa >> (32 - b->len)) | (hwa << (b->len));
}
b->bufa = lwb;
@@ -328,7 +332,7 @@
b->bufb = hwb;
b->len += a->len;
}
-
+
/* 8.5.3.3.1 */
static const uint8_t PresortedCodebook_VCB11[] = { 11, 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 9, 7, 5, 3, 1};
@@ -335,10 +339,10 @@
static const uint8_t PresortedCodebook[] = { 11, 9, 7, 5, 3, 1};
static const uint8_t maxCwLen[32] = {0, 11, 9, 20, 16, 13, 11, 14, 12, 17, 14, 49,
- 0, 0, 0, 0, 14, 17, 21, 21, 25, 25, 29, 29, 29, 29, 33, 33, 33, 37, 37, 41};
+ 0, 0, 0, 0, 14, 17, 21, 21, 25, 25, 29, 29, 29, 29, 33, 33, 33, 37, 37, 41};
-typedef struct {
-
+typedef struct
+{
bits_t bits;
uint8_t decoded;
uint16_t sp_offset;
@@ -349,8 +353,8 @@
#define segmentWidth( codebook ) min( maxCwLen[codebook], ics->length_of_longest_codeword )
uint8_t reordered_spectral_data(ic_stream *ics, bitfile *ld, int16_t *spectral_data,
- uint16_t frame_len, uint8_t aacSectionDataResilienceFlag)
-{
+ uint16_t frame_len, uint8_t aacSectionDataResilienceFlag)
+{
uint16_t sp_offset[8];
uint16_t g,i, presort;
uint16_t NrCodeWords=0, numberOfSegments=0, BitsRead=0;
@@ -357,17 +361,17 @@
uint8_t numberOfSets, set;
codeword_state Codewords[ 1024 ]; // FIXME max length? PCWs are not stored, so index is Codewordnr - numberOfSegments!, maybe malloc()?
bits_t Segment[ 512 ];
-
+
uint8_t PCW_decoded=0;
uint16_t segment_index=0, codeword_index=0;
uint16_t nshort = frame_len/8;
-
+
memset (spectral_data, 0, frame_len*sizeof(uint16_t));
-
- if (ics->length_of_reordered_spectral_data == 0)
- return 0; /* nothing to do */
+ if (ics->length_of_reordered_spectral_data == 0)
+ return 0; /* nothing to do */
+
/* if we have a corrupted bitstream this can happen... */
if ((ics->length_of_longest_codeword == 0) ||
(ics->length_of_reordered_spectral_data <
@@ -376,130 +380,130 @@
return 10; /* this is not good... */
}
- /* store the offset into the spectral data for all the window groups because we can't do it later */
-
+ /* store the offset into the spectral data for all the window groups because we can't do it later */
+
sp_offset[0] = 0;
- for (g=1; g < ics->num_window_groups; g++) {
- sp_offset[g] = sp_offset[g-1] + nshort*ics->window_group_length[g-1];
+ for (g=1; g < ics->num_window_groups; g++)
+ {
+ sp_offset[g] = sp_offset[g-1] + nshort*ics->window_group_length[g-1];
}
-
- /* All data is sorted according to the codebook used */
- for (presort = 0; presort < (aacSectionDataResilienceFlag ? 22 : 6); presort++) {
-
- uint8_t sfb;
- /* next codebook that has to be processed according to presorting */
+
+ /* All data is sorted according to the codebook used */
+ for (presort = 0; presort < (aacSectionDataResilienceFlag ? 22 : 6); presort++)
+ {
+ uint8_t sfb;
+
+ /* next codebook that has to be processed according to presorting */
uint8_t nextCB = aacSectionDataResilienceFlag ? PresortedCodebook_VCB11[ presort ] : PresortedCodebook[ presort ];
-
+
/* Data belonging to the same spectral unit and having the same codebook comes in consecutive codewords.
This is done by scanning all sfbs for possible codewords. For sfbs with more than 4 elements this has to be
repeated */
-
- for (sfb=0; sfb<ics->max_sfb; sfb ++) {
- uint8_t sect_cb, w;
+ for (sfb=0; sfb<ics->max_sfb; sfb ++)
+ {
+ uint8_t sect_cb, w;
- for (w=0; w< (ics->swb_offset[sfb+1] - ics->swb_offset[sfb]); w+=4){
+ for (w=0; w< (ics->swb_offset[sfb+1] - ics->swb_offset[sfb]); w+=4)
+ {
for(g = 0; g < ics->num_window_groups; g++)
{
for (i = 0; i < ics->num_sec[g]; i++)
{
-
-
sect_cb = ics->sect_cb[g][i];
-
+
if (
- /* process only sections that are due now */
- (( sect_cb == nextCB ) || (( nextCB < ESC_HCB ) && ( sect_cb == nextCB+1)) ) &&
+ /* process only sections that are due now */
+ (( sect_cb == nextCB ) || (( nextCB < ESC_HCB ) && ( sect_cb == nextCB+1)) ) &&
- /* process only sfb's that are due now */
- ((ics->sect_start[g][i] <= sfb) && (ics->sect_end[g][i] > sfb))
- ) {
-
-
+ /* process only sfb's that are due now */
+ ((ics->sect_start[g][i] <= sfb) && (ics->sect_end[g][i] > sfb))
+ )
+ {
if ((sect_cb != ZERO_HCB) &&
(sect_cb != NOISE_HCB) &&
(sect_cb != INTENSITY_HCB) &&
(sect_cb != INTENSITY_HCB2))
{
- uint8_t inc = (sect_cb < FIRST_PAIR_HCB) ? QUAD_LEN : PAIR_LEN;
+ uint8_t inc = (sect_cb < FIRST_PAIR_HCB) ? QUAD_LEN : PAIR_LEN;
uint16_t k;
uint32_t hw, lw;
-
for (k=0; (k < (4/inc)*ics->window_group_length[g]) &&
- ( (k+w*ics->window_group_length[g]/inc) < (ics->sect_sfb_offset[g][sfb+1] - ics->sect_sfb_offset[g][sfb])); k++) {
-
+ ( (k+w*ics->window_group_length[g]/inc) < (ics->sect_sfb_offset[g][sfb+1] - ics->sect_sfb_offset[g][sfb])); k++)
+ {
uint16_t sp = sp_offset[g] + ics->sect_sfb_offset[g][sfb] + inc*(k+w*ics->window_group_length[g]/inc);
- if (!PCW_decoded) {
-
- /* if we haven't yet read until the end of the buffer, we can directly decode the so-called PCWs */
- if ((BitsRead + segmentWidth( sect_cb ))<= ics->length_of_reordered_spectral_data) {
+ if (!PCW_decoded)
+ {
+ /* if we haven't yet read until the end of the buffer, we can directly decode the so-called PCWs */
+ if ((BitsRead + segmentWidth( sect_cb ))<= ics->length_of_reordered_spectral_data)
+ {
+ Segment[ numberOfSegments ].len = segmentWidth( sect_cb );
- Segment[ numberOfSegments ].len = segmentWidth( sect_cb );
-
- if (segmentWidth( sect_cb ) > 32) {
+ if (segmentWidth( sect_cb ) > 32)
+ {
Segment[ numberOfSegments ].bufb = faad_showbits(ld, segmentWidth( sect_cb ) - 32);
- faad_flushbits(ld, segmentWidth( sect_cb) - 32);
- Segment[ numberOfSegments ].bufa = faad_showbits(ld, 32),
- faad_flushbits(ld, 32 );
+ faad_flushbits(ld, segmentWidth( sect_cb) - 32);
+ Segment[ numberOfSegments ].bufa = faad_showbits(ld, 32),
+ faad_flushbits(ld, 32 );
} else {
Segment[ numberOfSegments ].bufa = faad_showbits(ld, segmentWidth( sect_cb ));
Segment[ numberOfSegments ].bufb = 0;
- faad_flushbits(ld, segmentWidth( sect_cb) );
+ faad_flushbits(ld, segmentWidth( sect_cb) );
}
-
- huffman_spectral_data_2(sect_cb, &Segment[ numberOfSegments ], &spectral_data[sp]);
+ huffman_spectral_data_2(sect_cb, &Segment[ numberOfSegments ], &spectral_data[sp]);
+
BitsRead += segmentWidth( sect_cb );
/* skip to next segment, but store left bits in new buffer */
- rewind_bits( &Segment[ numberOfSegments ]);
+ rewind_bits( &Segment[ numberOfSegments ]);
numberOfSegments++;
- } else {
-
+ } else {
+
/* the last segment is extended until length_of_reordered_spectral_data */
-
- if (BitsRead < ics->length_of_reordered_spectral_data) {
- uint8_t additional_bits = (ics->length_of_reordered_spectral_data - BitsRead);
+ if (BitsRead < ics->length_of_reordered_spectral_data)
+ {
- if ( additional_bits > 32) {
+ uint8_t additional_bits = (ics->length_of_reordered_spectral_data - BitsRead);
+
+ if ( additional_bits > 32)
+ {
hw = faad_showbits(ld, additional_bits - 32);
- faad_flushbits(ld, additional_bits - 32);
+ faad_flushbits(ld, additional_bits - 32);
lw = faad_showbits(ld, 32);
- faad_flushbits(ld, 32 );
+ faad_flushbits(ld, 32 );
} else {
lw = faad_showbits(ld, additional_bits);
hw = 0;
- faad_flushbits(ld, additional_bits );
+ faad_flushbits(ld, additional_bits );
}
rewind_lword( &hw, &lw, additional_bits + Segment[ numberOfSegments-1 ].len );
- if (Segment[ numberOfSegments-1 ].len > 32) {
-
+ if (Segment[ numberOfSegments-1 ].len > 32)
+ {
Segment[ numberOfSegments-1 ].bufb = hw +
- showbits(&Segment[ numberOfSegments-1 ], Segment[ numberOfSegments-1 ].len - 32);
+ showbits(&Segment[ numberOfSegments-1 ], Segment[ numberOfSegments-1 ].len - 32);
Segment[ numberOfSegments-1 ].bufa = lw +
- showbits(&Segment[ numberOfSegments-1 ], 32);
+ showbits(&Segment[ numberOfSegments-1 ], 32);
} else {
Segment[ numberOfSegments-1 ].bufa = lw +
- showbits(&Segment[ numberOfSegments-1 ], Segment[ numberOfSegments-1 ].len);
- Segment[ numberOfSegments-1 ].bufb = hw;
+ showbits(&Segment[ numberOfSegments-1 ], Segment[ numberOfSegments-1 ].len);
+ Segment[ numberOfSegments-1 ].bufb = hw;
}
- Segment[ numberOfSegments-1 ].len += additional_bits;
-
-
+ Segment[ numberOfSegments-1 ].len += additional_bits;
}
- BitsRead = ics->length_of_reordered_spectral_data;
- PCW_decoded = 1;
+ BitsRead = ics->length_of_reordered_spectral_data;
+ PCW_decoded = 1;
- Codewords[ 0 ].sp_offset = sp;
- Codewords[ 0 ].cb = sect_cb;
- Codewords[ 0 ].decoded = 0;
- Codewords[ 0 ].bits.len = 0;
+ Codewords[ 0 ].sp_offset = sp;
+ Codewords[ 0 ].cb = sect_cb;
+ Codewords[ 0 ].decoded = 0;
+ Codewords[ 0 ].bits.len = 0;
}
} else {
Codewords[ NrCodeWords - numberOfSegments ].sp_offset = sp;
@@ -517,49 +521,53 @@
} /* of w */
} /* of sfb */
} /* of presort */
-
- numberOfSets = NrCodeWords / numberOfSegments;
- /* second step: decode nonPCWs */
-
- for (set = 1; set <= numberOfSets; set++) {
+ numberOfSets = NrCodeWords / numberOfSegments;
- uint16_t trial;
- for (trial = 0; trial < numberOfSegments; trial++) {
-
+ /* second step: decode nonPCWs */
+
+ for (set = 1; set <= numberOfSets; set++)
+ {
+ uint16_t trial;
+
+ for (trial = 0; trial < numberOfSegments; trial++)
+ {
uint16_t codewordBase;
uint16_t set_decoded=numberOfSegments;
-
+
if (set == numberOfSets)
- set_decoded = NrCodeWords - set*numberOfSegments; /* last set is shorter than the rest */
-
- for (codewordBase = 0; codewordBase < numberOfSegments; codewordBase++) {
-
- uint16_t segment_index = (trial + codewordBase) % numberOfSegments;
- uint16_t codeword_index = codewordBase + set*numberOfSegments - numberOfSegments;
-
- if ((codeword_index + numberOfSegments) >= NrCodeWords)
- break;
- if (!Codewords[ codeword_index ].decoded) {
- if ( Segment[ segment_index ].len > 0) {
-
+ set_decoded = NrCodeWords - set*numberOfSegments; /* last set is shorter than the rest */
+
+ for (codewordBase = 0; codewordBase < numberOfSegments; codewordBase++)
+ {
+ uint16_t segment_index = (trial + codewordBase) % numberOfSegments;
+ uint16_t codeword_index = codewordBase + set*numberOfSegments - numberOfSegments;
+
+ if ((codeword_index + numberOfSegments) >= NrCodeWords)
+ break;
+ if (!Codewords[ codeword_index ].decoded)
+ {
+ if ( Segment[ segment_index ].len > 0)
+ {
uint8_t tmplen;
- if (Codewords[ codeword_index ].bits.len != 0) {
- /* on the first trial the data is only stored in Segment[], not in Codewords[].
- On next trials first collect the data stored for this codeword and
- concatenate the new data from Segment[] */
-
- concat_bits( &Codewords[ codeword_index ].bits, &Segment[ segment_index ]);
+
+ if (Codewords[ codeword_index ].bits.len != 0)
+ {
+ /* on the first trial the data is only stored in Segment[], not in Codewords[].
+ On next trials first collect the data stored for this codeword and
+ concatenate the new data from Segment[] */
+
+ concat_bits( &Codewords[ codeword_index ].bits, &Segment[ segment_index ]);
/* Now everthing is stored in Segment[] */
- }
- tmplen = Segment[ segment_index ].len;
- if ( huffman_spectral_data_2(Codewords[ codeword_index ].cb, &Segment[ segment_index ],
- &spectral_data[ Codewords[ codeword_index ].sp_offset ]) >=0) {
-
- /* CW did fit into segment */
+ }
+ tmplen = Segment[ segment_index ].len;
+ if ( huffman_spectral_data_2(Codewords[ codeword_index ].cb, &Segment[ segment_index ],
+ &spectral_data[ Codewords[ codeword_index ].sp_offset ]) >=0)
+ {
+ /* CW did fit into segment */
- Codewords[ codeword_index ].decoded = 1;
- set_decoded--;
+ Codewords[ codeword_index ].decoded = 1;
+ set_decoded--;
} else {
/* CW did not fit, so store for later use */
@@ -568,18 +576,18 @@
Codewords[ codeword_index ].bits.bufa = Segment[ segment_index ].bufa;
Codewords[ codeword_index ].bits.bufb = Segment[ segment_index ].bufb;
}
- }
+ }
}
- } /* of codewordBase */
-
+ } /* of codewordBase */
+
if (set_decoded == 0) break; /* no undecoded codewords left in this set */
-
+
} /* of trial */
-
+
/* rewind all bits in remaining segments with len>0 */
for (i=0; i < numberOfSegments; i++)
- rewind_bits( &Segment[ i ] );
- }
+ rewind_bits( &Segment[ i ] );
+ }
#if 0
{
@@ -586,18 +594,22 @@
int i, r=0, c=0;
for (i=0; i< numberOfSegments; i++)
r += Segment[ i ].len;
- if (r != 0) {
-printf("reordered_spectral_data: %d bits remaining!\n", r);
+ if (r != 0)
+ {
+ printf("reordered_spectral_data: %d bits remaining!\n", r);
}
- for (i=0; i< NrCodeWords - numberOfSegments; i++) {
- if (Codewords[ i ].decoded == 0) {
- c++;
- }
- }
- if (c != 0) {
-printf("reordered_spectral_data: %d Undecoded Codewords remaining!\n",c );
+ for (i=0; i< NrCodeWords - numberOfSegments; i++)
+ {
+ if (Codewords[ i ].decoded == 0)
+ {
+ c++;
+ }
}
- if ((r !=0) || (c!=0)) return 10;
+ if (c != 0)
+ {
+ printf("reordered_spectral_data: %d Undecoded Codewords remaining!\n",c );
+ }
+ if ((r !=0) || (c!=0)) return 10;
}
#endif
--- a/libfaad/specrec.c
+++ b/libfaad/specrec.c
@@ -16,7 +16,7 @@
** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
**
-** $Id: specrec.c,v 1.10 2002/08/20 16:59:58 menno Exp $
+** $Id: specrec.c,v 1.11 2002/08/26 18:41:47 menno Exp $
**/
/*
@@ -241,7 +241,7 @@
}
}
-void build_tables(real_t *iq_table, real_t *pow2_table)
+void build_tables(real_t *iq_table)
{
uint16_t i;
@@ -248,97 +248,71 @@
/* build pow(x, 4/3) table for inverse quantization */
for(i = 0; i < IQ_TABLE_SIZE; i++)
{
- iq_table[i] = (real_t)pow(i, 4.0/3.0);
+ iq_table[i] = REAL_CONST(pow(i, 4.0/3.0));
}
-
- /* build pow(2, 0.25*x) table for scalefactors */
- for(i = 0; i < POW_TABLE_SIZE; i++)
- {
- pow2_table[i] = (real_t)pow(2.0, 0.25 * (i-100));
- }
}
-static INLINE real_t iquant(int16_t q, real_t *iq_table)
-{
- if (q > 0)
- {
- if (q < IQ_TABLE_SIZE)
- return iq_table[q];
- else
- return iq_table[q>>3] * 16;
- } else if (q < 0) {
- q = -q;
- if (q < IQ_TABLE_SIZE)
- return -iq_table[q];
- else
- return -iq_table[q>>3] * 16;
- } else {
- return 0;
- }
-}
+static real_t newpow2_table[4] = {
+ COEF_CONST(1.0),
+ COEF_CONST(1.1892071), /* pow(2,.25) */
+ COEF_CONST(1.4142136), /* pow(2,.5) */
+ COEF_CONST(1.6817928) /* pow(2,.75) */
+};
-void inverse_quantization(real_t *x_invquant, int16_t *x_quant, real_t *iq_table,
- uint16_t frame_len)
+void iquant_and_apply_scalefactors(ic_stream *ics, real_t *x_invquant,
+ int16_t *x_quant, real_t *iq_table,
+ uint16_t frame_len)
{
- int8_t i;
- int16_t *in_ptr = x_quant;
- real_t *out_ptr = x_invquant;
-
- for(i = frame_len/8-1; i >= 0; --i)
- {
- *out_ptr++ = iquant(*in_ptr++, iq_table);
- *out_ptr++ = iquant(*in_ptr++, iq_table);
- *out_ptr++ = iquant(*in_ptr++, iq_table);
- *out_ptr++ = iquant(*in_ptr++, iq_table);
- *out_ptr++ = iquant(*in_ptr++, iq_table);
- *out_ptr++ = iquant(*in_ptr++, iq_table);
- *out_ptr++ = iquant(*in_ptr++, iq_table);
- *out_ptr++ = iquant(*in_ptr++, iq_table);
- }
-}
-
-static INLINE real_t get_scale_factor_gain(uint16_t scale_factor, real_t *pow2_table)
-{
- if (scale_factor < POW_TABLE_SIZE)
- return pow2_table[scale_factor];
- else
- return REAL_CONST(exp(LN2 * 0.25 * (scale_factor - 100)));
-}
-
-void apply_scalefactors(ic_stream *ics, real_t *x_invquant, real_t *pow2_table,
- uint16_t frame_len)
-{
- uint8_t g, sfb;
- uint16_t top;
- real_t *fp, scale;
- uint8_t groups = 0;
+ int16_t i;
+ uint16_t g, sfb, k;
uint16_t nshort = frame_len/8;
+ for (i = 0; i < frame_len; i++)
+ x_invquant[i] = 0;
+
for (g = 0; g < ics->num_window_groups; g++)
{
- uint16_t k = 0;
+ for (sfb = 0, k = 0; sfb < ics->max_sfb; sfb++)
+ {
+ uint16_t top = ics->sect_sfb_offset[g][sfb+1];
+ int16_t scalefactor = ics->scale_factors[g][sfb] - 100;
- /* using this 128*groups doesn't hurt long blocks, because
- long blocks only have 1 group, so that means 'groups' is
- always 0 for long blocks
- */
- fp = x_invquant + (groups*nshort);
+ for ( ; k < top; k++)
+ {
+ real_t dequant;
+ int16_t shift;
+ int16_t q = x_quant[k];
+ if (!q)
+ continue;
- for (sfb = 0; sfb < ics->max_sfb; sfb++)
- {
- top = ics->sect_sfb_offset[g][sfb+1];
+ i = abs(q) << 3;
+ shift = scalefactor >> 2;
- scale = get_scale_factor_gain(ics->scale_factors[g][sfb], pow2_table);
+ while (i < IQ_TABLE_SIZE)
+ {
+ i <<= 3;
+ shift -= 4;
+ }
+ i >>= 3;
+ if (i < IQ_TABLE_SIZE)
+ dequant = iq_table[i];
+ else
+ dequant = iq_table[i>>3] * 16;
- /* minimum size of a sf band is 4 and always a multiple of 4 */
- for ( ; k < top; k+=4)
- {
- *fp = MUL(*fp, scale); fp++;
- *fp = MUL(*fp, scale); fp++;
- *fp = MUL(*fp, scale); fp++;
- *fp = MUL(*fp, scale); fp++;
+ if (shift >= 0)
+ dequant *= (1 << shift);
+ else if (shift >= -31)
+ dequant *= (1 >> -shift);
+ else
+ dequant = 0;
+
+ dequant = MUL_R_C(dequant, newpow2_table[scalefactor & 3]);
+
+ x_invquant[k] = (q > 0) ? dequant : -dequant;
+// x_invquant[k] = (dequant^(q >> (sizeof(int32_t)*8-1))) - (q >> (sizeof(int32_t)*8-1));
}
}
- groups += ics->window_group_length[g];
+ x_invquant += nshort * ics->window_group_length[g];
+ x_quant += nshort * ics->window_group_length[g];
}
}
--- a/libfaad/specrec.h
+++ b/libfaad/specrec.h
@@ -16,7 +16,7 @@
** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
**
-** $Id: specrec.h,v 1.5 2002/06/13 11:03:28 menno Exp $
+** $Id: specrec.h,v 1.6 2002/08/26 18:41:47 menno Exp $
**/
#ifndef __SPECREC_H__
@@ -31,18 +31,14 @@
/* !!!DON'T CHANGE IQ_TABLE_SIZE!!! */
#define IQ_TABLE_SIZE 1026
-#define POW_TABLE_SIZE 200
-
uint8_t window_grouping_info(ic_stream *ics, uint8_t fs_index,
uint8_t object_type, uint16_t frame_len);
void quant_to_spec(ic_stream *ics, real_t *spec_data, uint16_t frame_len);
-void build_tables(real_t *iq_table, real_t *pow2_table);
-void inverse_quantization(real_t *x_invquant, int16_t *x_quant, real_t *iq_table,
- uint16_t frame_len);
-void apply_scalefactors(ic_stream *ics, real_t *x_invquant, real_t *pow2_table,
- uint16_t frame_len);
-
+void build_tables(real_t *iq_table);
+void iquant_and_apply_scalefactors(ic_stream *ics, real_t *x_invquant,
+ int16_t *x_quant, real_t *iq_table,
+ uint16_t frame_len);
#ifdef __cplusplus
}
--- a/libfaad/syntax.h
+++ b/libfaad/syntax.h
@@ -16,7 +16,7 @@
** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
**
-** $Id: syntax.h,v 1.16 2002/08/05 20:33:38 menno Exp $
+** $Id: syntax.h,v 1.17 2002/08/26 18:41:47 menno Exp $
**/
#ifndef __SYNTAX_H__
@@ -28,14 +28,14 @@
#include "bits.h"
-#define MAIN 0
-#define LC 1
-#define SSR 2
-#define LTP 3
-#define LD 23
-#define ER_LC 17
-#define ER_LTP 19
-#define DRM_ER_LC 27 /* special object type for DRM */
+#define MAIN 0
+#define LC 1
+#define SSR 2
+#define LTP 3
+#define LD 23
+#define ER_LC 17
+#define ER_LTP 19
+#define DRM_ER_LC 27 /* special object type for DRM */
/* First object type that has ER */
--- a/libfaad/tns.c
+++ b/libfaad/tns.c
@@ -16,7 +16,7 @@
** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
**
-** $Id: tns.c,v 1.13 2002/08/17 12:27:33 menno Exp $
+** $Id: tns.c,v 1.14 2002/08/26 18:41:47 menno Exp $
**/
#include "common.h"
@@ -132,7 +132,7 @@
uint8_t i, m;
uint8_t coef_res2, s_mask, n_mask;
real_t tmp2[TNS_MAX_ORDER+1], b[TNS_MAX_ORDER+1];
- real_t iqfac;
+ float32_t iqfac;
/* Some internal tables */
static uint8_t sgn_mask[] = { 0x2, 0x4, 0x8 };
@@ -151,14 +151,12 @@
/* Inverse quantization */
if (tmp >= 0)
{
- iqfac = REAL_CONST((1 << (coef_res_bits-1)) -
- REAL_CONST(0.5)) / REAL_CONST(M_PI_2); /* <-- TODO */
+ iqfac = ((1 << (coef_res_bits-1)) - 0.5) / M_PI_2;
} else {
- iqfac = REAL_CONST((1 << (coef_res_bits-1)) +
- REAL_CONST(0.5)) / REAL_CONST(M_PI_2); /* <-- TODO */
+ iqfac = ((1 << (coef_res_bits-1)) + 0.5) / M_PI_2;
}
- tmp2[i] = REAL_CONST(sin(tmp / iqfac));
+ tmp2[i] = COEF_CONST(sin(tmp / iqfac));
}
/* Conversion to LPC coefficients */
@@ -166,7 +164,7 @@
for (m = 1; m <= order; m++)
{
for (i = 1; i < m; i++) /* loop only while i<m */
- b[i] = a[i] + MUL(tmp2[m-1], a[m-i]);
+ b[i] = a[i] + MUL_C_C(tmp2[m-1], a[m-i]);
for (i = 1; i < m; i++) /* loop only while i<m */
a[i] = b[i];
@@ -199,7 +197,7 @@
y = *spectrum;
for (j = 0; j < order; j++)
- y -= MUL(lpc[j+1], state[j]);
+ y -= MUL_R_C(state[j], lpc[j+1]);
for (j = order-1; j > 0; j--)
state[j] = state[j-1];
@@ -234,7 +232,7 @@
y = *spectrum;
for (j = 0; j < order; j++)
- y += MUL(lpc[j+1], state[j]);
+ y += MUL_R_C(state[j], lpc[j+1]);
for (j = order-1; j > 0; j--)
state[j] = state[j-1];
@@ -300,14 +298,15 @@
switch (object_type)
{
case MAIN:
- return 20;
case LTP:
- return 20;
+ case ER_LTP:
#ifdef LD_DEC
case LD:
- return 20;
#endif
+ return 20;
case LC:
+ case ER_LC:
+ case DRM_ER_LC:
case SSR:
return 12;
}