[xiph-cvs] cvs commit: speex/libspeex lsp.c nb_celp.c

Jean-Marc Valin jm at xiph.org
Wed Oct 23 20:59:35 PDT 2002



jm          02/10/23 23:59:35

  Modified:    libspeex lsp.c nb_celp.c
  Log:
  More cleanups, do something more intelligent with LPC->LSP

Revision  Changes    Path
1.14      +14 -23    speex/libspeex/lsp.c

Index: lsp.c
===================================================================
RCS file: /usr/local/cvsroot/speex/libspeex/lsp.c,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- lsp.c	21 Oct 2002 20:39:38 -0000	1.13
+++ lsp.c	24 Oct 2002 03:59:35 -0000	1.14
@@ -72,37 +72,28 @@
 /*  float coef[]  	coefficients of the polynomial to be evaluated 	*/
 /*  float x   		the point where polynomial is to be evaluated 	*/
 /*  int m 		order of the polynomial 			*/
-
-
 {
     int i;
-    float *T,*t,*u,*v,sum;
+    float *T,sum;
+    int m2=m>>1;
 
     /* Allocate memory for chebyshev series formulation */
+    T=PUSH(stack, m2+1);
 
-    T=PUSH(stack, m/2+1);
-
-    /* Initialise pointers */
-
-    t = T;                          	/* T[i-2] 			*/
-    *t++ = 1.0;
-    u = t--;                        	/* T[i-1] 			*/
-    *u++ = x;
-    v = u--;                        	/* T[i] 			*/
+    /* Initialise values */
+    T[0]=1;
+    T[1]=x;
 
     /* Evaluate chebyshev series formulation using iterative approach 	*/
-
-    for(i=2;i<=m/2;i++)
-	*v++ = (2*x)*(*u++) - *t++;  	/* T[i] = 2*x*T[i-1] - T[i-2]	*/
-
-    sum=0.0;                        	/* initialise sum to zero 	*/
-    t = T;                          	/* reset pointer 		*/
-
     /* Evaluate polynomial and return value also free memory space */
-
-    for(i=0;i<=m/2;i++)
-	sum+=coef[(m/2)-i]**t++;
-
+    sum = coef[m2] + coef[m2-1]*x;
+    x *= 2;
+    for(i=2;i<=m2;i++)
+    {
+       T[i] = x*T[i-1] - T[i-2];
+       sum += coef[m2-i] * T[i];
+    }
+    
     return sum;
 }
 

<p><p>1.68      +25 -45    speex/libspeex/nb_celp.c

Index: nb_celp.c
===================================================================
RCS file: /usr/local/cvsroot/speex/libspeex/nb_celp.c,v
retrieving revision 1.67
retrieving revision 1.68
diff -u -r1.67 -r1.68
--- nb_celp.c	23 Oct 2002 19:06:19 -0000	1.67
+++ nb_celp.c	24 Oct 2002 03:59:35 -0000	1.68
@@ -141,6 +141,10 @@
    st->interp_qlsp = speex_alloc(st->lpcSize*sizeof(float));
    st->rc = speex_alloc(st->lpcSize*sizeof(float));
    st->first = 1;
+   for (i=0;i<st->lpcSize;i++)
+   {
+      st->lsp[i]=(M_PI*((float)(i+1)))/(st->lpcSize+1);
+   }
 
    st->mem_sp = speex_alloc(st->lpcSize*sizeof(float));
    st->mem_sw = speex_alloc(st->lpcSize*sizeof(float));
@@ -211,7 +215,6 @@
 {
    EncState *st;
    int i, sub, roots;
-   float error;
    int ol_pitch;
    float ol_pitch_coef;
    float ol_gain;
@@ -251,30 +254,33 @@
       st->autocorr[i] *= st->lagWindow[i];
 
    /* Levinson-Durbin */
-   error = wld(st->lpc+1, st->autocorr, st->rc, st->lpcSize);
+   wld(st->lpc+1, st->autocorr, st->rc, st->lpcSize);
    st->lpc[0]=1;
 
    /* LPC to LSPs (x-domain) transform */
    roots=lpc_to_lsp (st->lpc, st->lpcSize, st->lsp, 15, 0.2, stack);
-   if (roots!=st->lpcSize)
+   if (roots==st->lpcSize)
    {
-      roots = lpc_to_lsp (st->lpc, st->lpcSize, st->lsp, 11, 0.02, stack);
-      if (roots!=st->lpcSize) {
-         /*fprintf (stderr, "roots!=st->lpcSize (found only %d roots)\n", roots);*/
-
-         /*If we can't find all LSP's, do some damage control and use a flat filter*/
+      /* LSP x-domain to angle domain*/
+      for (i=0;i<st->lpcSize;i++)
+         st->lsp[i] = acos(st->lsp[i]);
+   } else {
+      if (st->complexity>1)
+         roots = lpc_to_lsp (st->lpc, st->lpcSize, st->lsp, 11, 0.05, stack);
+      if (roots==st->lpcSize) 
+      {
+         /* LSP x-domain to angle domain*/
+         for (i=0;i<st->lpcSize;i++)
+            st->lsp[i] = acos(st->lsp[i]);
+      } else {
+         /*If we can't find all LSP's, do some damage control and use previous filter*/
          for (i=0;i<st->lpcSize;i++)
          {
-            st->lsp[i]=cos(M_PI*((float)(i+1))/(st->lpcSize+1));
+            st->lsp[i]=st->old_lsp[i];
          }
       }
    }
 
-
-   /* LSP x-domain to angle domain*/
-   for (i=0;i<st->lpcSize;i++)
-      st->lsp[i] = acos(st->lsp[i]);
-   /*print_vec(st->lsp, 10, "LSP:");*/
    /* LSP Quantization */
    if (st->first)
    {
@@ -303,7 +309,6 @@
 
 
       /*Open-loop pitch*/
-      /*if (SUBMODE(lbr_pitch) != -1 || st->vbr_enabled || SUBMODE(forced_pitch_gain))*/
       if (!st->submodes[st->submodeID] || st->vbr_enabled || SUBMODE(forced_pitch_gain) ||
           SUBMODE(lbr_pitch) != -1)
       {
@@ -453,7 +458,7 @@
    /* Loop on sub-frames */
    for (sub=0;sub<st->nbSubframes;sub++)
    {
-      float esig, enoise, snr, tmp;
+      float tmp;
       int   offset;
       float *sp, *sw, *exc, *exc2;
       int pitch;
@@ -528,19 +533,14 @@
          mem[i]=st->mem_sp[i];
       iir_mem2(exc, st->interp_qlpc, exc, st->subframeSize, st->lpcSize, mem);
       
-
       for (i=0;i<st->lpcSize;i++)
          mem[i]=st->mem_sw[i];
       filter_mem2(exc, st->bw_lpc1, st->bw_lpc2, res, st->subframeSize, st->lpcSize, mem);
-
+      
       /* Compute weighted signal */
       for (i=0;i<st->lpcSize;i++)
          mem[i]=st->mem_sw[i];
       filter_mem2(sp, st->bw_lpc1, st->bw_lpc2, sw, st->subframeSize, st->lpcSize, mem);
-
-      esig=0;
-      for (i=0;i<st->subframeSize;i++)
-         esig+=sw[i]*sw[i];
       
       /* Compute target signal */
       for (i=0;i<st->subframeSize;i++)
@@ -593,16 +593,6 @@
       for (i=0;i<st->subframeSize;i++)
         target[i]-=res[i];
 
-      /* Compute noise energy and SNR */
-      enoise=0;
-      for (i=0;i<st->subframeSize;i++)
-         enoise += target[i]*target[i];
-      snr = 10*log10((esig+1)/(enoise+1));
-      /*st->pitch[sub]=(int)snr;*/
-#ifdef DEBUG
-      printf ("pitch SNR = %f\n", snr);
-#endif
-
 
       /* Quantization of innovation */
       {
@@ -694,15 +684,6 @@
 
       }
 
-      /* Compute weighted noise energy and SNR */
-      enoise=0;
-      for (i=0;i<st->subframeSize;i++)
-         enoise += target[i]*target[i];
-      snr = 10*log10((esig+1)/(enoise+1));
-#ifdef DEBUG
-      printf ("seg SNR = %f\n", snr);
-#endif
-
       /*Keep the previous memory*/
       for (i=0;i<st->lpcSize;i++)
          mem[i]=st->mem_sp[i];
@@ -1036,6 +1017,7 @@
          st->interp_qlsp[i] = cos(st->interp_qlsp[i]);
       lsp_to_lpc(st->interp_qlsp, st->interp_qlpc, st->lpcSize, stack);
 
+      /* Compute enhanced synthesis filter */
       {
          float r=.9;
          
@@ -1071,6 +1053,7 @@
       if (SUBMODE(ltp_unquant))
       {
          int pit_min, pit_max;
+         /* Handle pitch constraints if any */
          if (SUBMODE(lbr_pitch) != -1)
          {
             int margin;
@@ -1091,6 +1074,7 @@
             pit_max = st->max_pitch;
          }
 
+         /* Pitch synthesis */
          SUBMODE(ltp_unquant)(exc, pit_min, pit_max, ol_pitch_coef, SUBMODE(ltp_params), 
                               st->subframeSize, &pitch, &pitch_gain[0], bits, stack, st->count_lost);
          
@@ -1098,10 +1082,6 @@
          if (tmp>best_pitch_gain)
          {
             best_pitch = pitch;
-            /*while (best_pitch+pitch<st->max_pitch)
-            {
-               best_pitch+=pitch;
-               }*/
             best_pitch_gain = tmp*.9;
             if (best_pitch_gain>.85)
                best_pitch_gain=.85;

<p><p>--- >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