[xiph-cvs] cvs commit: vorbis/lib lsp.c lookup.c

Monty xiphmont at xiph.org
Wed Jan 3 21:28:15 PST 2001



xiphmont    01/01/03 21:28:14

  Modified:    lib      Tag: monty_branch_20001226 lsp.c lookup.c
  Log:
  finished implementing odd order LSP synthesis
  fixed a typo in lookup.c (x+.5, not x+5.)

Revision  Changes    Path
No                   revision

No                   revision

1.13.2.2  +67 -27    vorbis/lib/lsp.c

Index: lsp.c
===================================================================
RCS file: /usr/local/cvsroot/vorbis/lib/lsp.c,v
retrieving revision 1.13.2.1
retrieving revision 1.13.2.2
diff -u -r1.13.2.1 -r1.13.2.2
--- lsp.c	2001/01/04 04:05:08	1.13.2.1
+++ lsp.c	2001/01/04 05:28:13	1.13.2.2
@@ -12,11 +12,11 @@
  ********************************************************************
 
   function: LSP (also called LSF) conversion routines
-  last mod: $Id: lsp.c,v 1.13.2.1 2001/01/04 04:05:08 xiphmont Exp $
+  last mod: $Id: lsp.c,v 1.13.2.2 2001/01/04 05:28:13 xiphmont Exp $
 
-  The LSP generation code is taken (with minimal modification) from
-  "On the Computation of the LSP Frequencies" by Joseph Rothweiler
-  <rothwlr at altavista.net>, available at:
+  The LSP generation code is taken (with minimal modification and a
+  few bugfixes) from "On the Computation of the LSP Frequencies" by
+  Joseph Rothweiler <rothwlr at altavista.net>, available at:
   
   http://www2.xtdl.com/~rothwlr/lsfpaper/lsfpage.html 
 
@@ -52,8 +52,8 @@
    ARM family. */
 
 /* undefine both for the 'old' but more precise implementation */
-#undef   FLOAT_LOOKUP
-#undef   INT_LOOKUP
+#define   FLOAT_LOOKUP
+#undef    INT_LOOKUP
 
 #ifdef FLOAT_LOOKUP
 #include "lookup.c" /* catch this in the build system; we #include for
@@ -81,12 +81,24 @@
     int c=m>>1;
 
     do{
-      p*=ftmp[0]-w;
-      q*=ftmp[1]-w;
+      q*=ftmp[0]-w;
+      p*=ftmp[1]-w;
       ftmp+=2;
     }while(--c);
 
-    q=frexp(p*p*(1.f+w)+q*q*(1.f-w),&qexp);
+    if(m&1){
+      /* odd order filter; slightly assymetric */
+      /* the last coefficient */
+      q*=ftmp[0]-w;
+      q*=q;
+      p*=p*(1.f-w*w);
+    }else{
+      /* even order filter; still symmetric */
+      q*=q*(1.f+w);
+      p*=p*(1.f-w);
+    }
+
+    q=frexp(p+q,&qexp);
     q=vorbis_fromdBlook(amp*             
                         vorbis_invsqlook(q)*
                         vorbis_invsq2explook(qexp+m)- 
@@ -144,37 +156,68 @@
     int qexp=0,shift;
     long wi=vorbis_coslook_i(k*65536/ln);
 
-    pi*=labs(ilsp[0]-wi);
-    qi*=labs(ilsp[1]-wi);
+    qi*=labs(ilsp[0]-wi);
+    pi*=labs(ilsp[1]-wi);
 
-    for(j=2;j<m;j+=2){
+    for(j=3;j<m;j+=2){
       if(!(shift=MLOOP_1[(pi|qi)>>25]))
         if(!(shift=MLOOP_2[(pi|qi)>>19]))
           shift=MLOOP_3[(pi|qi)>>16];
+      qi=(qi>>shift)*labs(ilsp[j-1]-wi);
       pi=(pi>>shift)*labs(ilsp[j]-wi);
-      qi=(qi>>shift)*labs(ilsp[j+1]-wi);
       qexp+=shift;
     }
     if(!(shift=MLOOP_1[(pi|qi)>>25]))
       if(!(shift=MLOOP_2[(pi|qi)>>19]))
         shift=MLOOP_3[(pi|qi)>>16];
-    pi>>=shift;
-    qi>>=shift;
-    qexp+=shift-7*m;
 
     /* pi,qi normalized collectively, both tracked using qexp */
-
-    /* p*=p(1-w), q*=q(1+w), let normalization drift because it isn't
-       worth tracking step by step */
 
-    pi=((pi*pi)>>16);
-    qi=((qi*qi)>>16);
-    qexp=qexp*2+m;
+    if(m&1){
+      /* odd order filter; slightly assymetric */
+      /* the last coefficient */
+      qi=(qi>>shift)*labs(ilsp[j-1]-wi);
+      pi=(pi>>shift)<<14;
+      qexp+=shift;
 
-    qi*=(1<<14)-wi;
-    pi*=(1<<14)+wi;
+      if(!(shift=MLOOP_1[(pi|qi)>>25]))
+	if(!(shift=MLOOP_2[(pi|qi)>>19]))
+	  shift=MLOOP_3[(pi|qi)>>16];
+      
+      pi>>=shift;
+      qi>>=shift;
+      qexp+=shift-14*((m+1)>>1);
+
+      pi=((pi*pi)>>16);
+      qi=((qi*qi)>>16);
+      qexp=qexp*2+m;
+
+      pi*=(1<<14)-((wi*wi)>>14);
+      qi+=pi>>14;
+
+      //q*=ftmp[0]-w;
+      //q*=q;
+      //p*=p*(1.f-w*w);
+    }else{
+      /* even order filter; still symmetric */
+
+      /* p*=p(1-w), q*=q(1+w), let normalization drift because it isn't
+	 worth tracking step by step */
+      
+      pi>>=shift;
+      qi>>=shift;
+      qexp+=shift-7*m;
+
+      pi=((pi*pi)>>16);
+      qi=((qi*qi)>>16);
+      qexp=qexp*2+m;
+      
+      pi*=(1<<14)-wi;
+      qi*=(1<<14)+wi;
+      qi=(qi+pi)>>14;
+      
+    }
     
-    qi=(qi+pi)>>14;
 
     /* we've let the normalization drift because it wasn't important;
        however, for the lookup, things must be normalized again.  We
@@ -203,15 +246,12 @@
    figure out what the hell this code does, or wants the other
    fraction of a dB precision */
 
-#include <stdio.h>
 /* side effect: changes *lsp to cosines of lsp */
 void vorbis_lsp_to_curve(float *curve,int *map,int n,int ln,float *lsp,int m,
                             float amp,float ampoffset){
   int i;
   float wdel=M_PI/ln;
   for(i=0;i<m;i++)lsp[i]=2.f*cos(lsp[i]);
-
-  fprintf(stderr,"m=%d ",m);
 
   i=0;
   while(i<n){

1.4.2.1   +2 -2      vorbis/lib/lookup.c

Index: lookup.c
===================================================================
RCS file: /usr/local/cvsroot/vorbis/lib/lookup.c,v
retrieving revision 1.4
retrieving revision 1.4.2.1
diff -u -r1.4 -r1.4.2.1
--- lookup.c	2000/12/21 21:04:39	1.4
+++ lookup.c	2001/01/04 05:28:13	1.4.2.1
@@ -12,7 +12,7 @@
  ********************************************************************
 
   function: lookup based functions
-  last mod: $Id: lookup.c,v 1.4 2000/12/21 21:04:39 xiphmont Exp $
+  last mod: $Id: lookup.c,v 1.4.2.1 2001/01/04 05:28:13 xiphmont Exp $
 
  ********************************************************************/
 
@@ -46,7 +46,7 @@
 #include <stdio.h>
 /* interpolated lookup based fromdB function, domain -140dB to 0dB only */
 float vorbis_fromdBlook(float a){
-  int i=vorbis_ftoi(a*((float)(-(1<<FROMdB2_SHIFT)))-5.f);
+  int i=vorbis_ftoi(a*((float)(-(1<<FROMdB2_SHIFT)))-.5f);
   return (i<0)?1.f:
     ((i>=(FROMdB_LOOKUP_SZ<<FROMdB_SHIFT))?0.f:
      FROMdB_LOOKUP[i>>FROMdB_SHIFT]*FROMdB2_LOOKUP[i&FROMdB2_MASK]);

--- >8 ----
List archives:  http://www.xiph.org/archives/
Ogg project homepage: http://www.xiph.org/ogg/
To unsubscribe from this list, send a message to 'cvs-request at xiph.org'
containing only the word 'unsubscribe' in the body.  No subject is needed.
Unsubscribe messages sent to the list will be ignored/filtered.



More information about the commits mailing list