[xiph-commits] r13581 - trunk/ghost/libghost
jm at svn.xiph.org
jm at svn.xiph.org
Tue Aug 21 08:39:06 PDT 2007
Author: jm
Date: 2007-08-21 08:39:05 -0700 (Tue, 21 Aug 2007)
New Revision: 13581
Modified:
trunk/ghost/libghost/ceft.c
Log:
block-based normalisation
Modified: trunk/ghost/libghost/ceft.c
===================================================================
--- trunk/ghost/libghost/ceft.c 2007-08-20 12:45:47 UTC (rev 13580)
+++ trunk/ghost/libghost/ceft.c 2007-08-21 15:39:05 UTC (rev 13581)
@@ -51,6 +51,80 @@
64 .. 83 (20)
84 .. 127 (42)
*/
+
+#define NBANDS 23 /*or 22 if we discard the small last band*/
+int qbank[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 14, 16, 20, 24, 28, 36, 44, 52, 68, 84, 116, 128};
+
+#if 0
+void compute_bank(float *ps, float *bank)
+{
+ int i;
+ for (i=0;i<NBANDS;i++)
+ {
+ int j;
+ bank[i]=0;
+ for (j=qbank[i];j<qbank[i+1];j++)
+ bank[i] += ps[j];
+ bank[i] = sqrt(bank[i]/(qbank[i+1]-qbank[i]));
+ }
+}
+#else
+void compute_bank(float *X, float *bank)
+{
+ int i;
+ bank[0] = 1e-10+fabs(X[0]);
+ for (i=1;i<NBANDS;i++)
+ {
+ int j;
+ bank[i] = 1e-10;
+ for (j=qbank[i];j<qbank[i+1];j++)
+ {
+ bank[i] += X[j*2-1]*X[j*2-1];
+ bank[i] += X[j*2]*X[j*2];
+ }
+ bank[i] = sqrt(.5*bank[i]/(qbank[i+1]-qbank[i]));
+ }
+ //FIXME: Kludge
+ X[255] = 1;
+}
+#endif
+
+void normalise_bank(float *X, float *bank)
+{
+ int i;
+ X[0] /= bank[0];
+ for (i=1;i<NBANDS;i++)
+ {
+ int j;
+ float x = 1.f/bank[i];
+ for (j=qbank[i];j<qbank[i+1];j++)
+ {
+ X[j*2-1] *= x;
+ X[j*2] *= x;
+ }
+ }
+ //FIXME: Kludge
+ X[255] = 0;
+}
+
+void denormalise_bank(float *X, float *bank)
+{
+ int i;
+ X[0] *= bank[0];
+ for (i=1;i<NBANDS;i++)
+ {
+ int j;
+ float x = bank[i];
+ for (j=qbank[i];j<qbank[i+1];j++)
+ {
+ X[j*2-1] *= x;
+ X[j*2] *= x;
+ }
+ }
+ //FIXME: Kludge
+ X[255] = 0;
+}
+
#define BARK_BANDS 20
struct CEFTState_ {
@@ -81,8 +155,14 @@
for (i=1;i<st->length>>1;i++)
Xps[i] = .1+X[2*i-1]*X[2*i-1] + X[2*i]*X[2*i];
+#if 1
+ float bank[NBANDS];
+ compute_bank(X, bank);
+ normalise_bank(X, bank);
+#else
filterbank_compute_bank(st->bank, Xps, bark);
filterbank_compute_psd(st->bank, bark, Xps);
+
for(i=0;i<st->length>>1;i++)
Xps[i] = sqrt(Xps[i]);
X[0] /= Xps[0];
@@ -92,6 +172,7 @@
X[2*i] /= Xps[i];
}
X[st->length-1] /= Xps[(st->length>>1)-1];
+#endif
/*for(i=0;i<st->length;i++)
printf ("%f ", X[i]);
@@ -101,20 +182,23 @@
for(i=0;i<st->length;i++)
{
float q = 4;
- if (i<16)
+ if (i<10)
q = 8;
- else if (i<32)
+ else if (i<20)
q = 4;
- else if (i<48)
+ else if (i<30)
q = 2;
+ else if (i<50)
+ q = 1;
else
- q = 1;
- q=1;
+ q = .5;
+ //q=1;
int sq = floor(.5+q*X[i]);
- //printf ("%d ", sq);
- X[i] = (1.f/q)*sq;
+ printf ("%d ", sq);
+ X[i] = (1.f/q)*(sq);
}
- //printf ("\n");
+ printf ("\n");
+#if 0
X[0] *= Xps[0];
for (i=1;i<st->length>>1;i++)
{
@@ -122,6 +206,15 @@
X[2*i] *= Xps[i];
}
X[st->length-1] *= Xps[(st->length>>1)-1];
+#else
+ float bank2[NBANDS];
+ compute_bank(X, bank2);
+ normalise_bank(X, bank2);
+
+ denormalise_bank(X, bank);
+#endif
+
+
#if 0
for(i=0;i<BARK_BANDS;i++)
{
More information about the commits
mailing list