[xiph-commits] r13233 - trunk/ghost/libghost

jm at svn.xiph.org jm at svn.xiph.org
Fri Jul 6 06:44:30 PDT 2007


Author: jm
Date: 2007-07-06 06:44:29 -0700 (Fri, 06 Jul 2007)
New Revision: 13233

Modified:
   trunk/ghost/libghost/sinusoids.c
Log:
Basis functions computed as rotations instead of explicit sin/cos calls.


Modified: trunk/ghost/libghost/sinusoids.c
===================================================================
--- trunk/ghost/libghost/sinusoids.c	2007-07-06 05:54:45 UTC (rev 13232)
+++ trunk/ghost/libghost/sinusoids.c	2007-07-06 13:44:29 UTC (rev 13233)
@@ -181,15 +181,29 @@
    {
       float tmp1=0, tmp2=0;
       float tmp3=0, tmp4=0;
+      float rotR, rotI;
+      rotR = cos(w[i]);
+      rotI = sin(w[i]);
+      /* Computing sin/cos table using complex rotations */
+      cos_table[i][0] = cos(.5*w[i]);
+      sin_table[i][0] = sin(.5*w[i]);
+      for (j=1;j<L2;j++)
+      {
+         float re, im;
+         re = cos_table[i][j-1]*rotR - sin_table[i][j-1]*rotI;
+         im = sin_table[i][j-1]*rotR + cos_table[i][j-1]*rotI;
+         cos_table[i][j] = re;
+         sin_table[i][j] = im;
+      }
       /* Only need to compute the tables for half the length because of the symmetry.
          Eventually, we'll have to replace the cos/sin with rotations */
       for (j=0;j<L2;j++)
       {
          float jj = j+.5;
-         cos_table[i][j] = cos(w[i]*jj)*window[j];
-         sin_table[i][j] = sin(w[i]*jj)*window[j];
-         tcos_table[i][j] = ((jj))*cos_table[i][j];
-         tsin_table[i][j] = ((jj))*sin_table[i][j];
+         /*cos_table[i][j] = cos(w[i]*jj)*window[j];
+         sin_table[i][j] = sin(w[i]*jj)*window[j];*/
+         tcos_table[i][j] = jj*cos_table[i][j];
+         tsin_table[i][j] = jj*sin_table[i][j];
          /* The sinusoidal terms */
          tmp1 += cos_table[i][j]*cos_table[i][j];
          tmp2 += sin_table[i][j]*sin_table[i][j];
@@ -197,7 +211,9 @@
          tmp3 += tcos_table[i][j]*tcos_table[i][j];
          tmp4 += tsin_table[i][j]*tsin_table[i][j];
       }
-      /* double the energy because we only computed one half */
+      /* Double the energy because we only computed one half.
+         Eventually, we should be computing/tabulating these values directly
+         as a function of w[i]. */
       cosE[i] = sqrt(2*tmp1);
       sinE[i] = sqrt(2*tmp2);
       costE[i] = sqrt(2*tmp3);
@@ -217,7 +233,7 @@
    for (j=0;j<len;j++)
       e[j] = x[j];
    /* Split the error into a symmetric component and an anti-symmetric component. 
-      This speeds every thing up by a factor of 2 */
+      This speeds everything up by a factor of 2 */
    for (j=0;j<L2;j++)
    {
       sym[j] = e[j+L2]+e[L2-j-1];



More information about the commits mailing list