[xiph-commits] r11111 - trunk/speex/libspeex

jm at svn.xiph.org jm at svn.xiph.org
Sat Apr 8 09:35:03 PDT 2006


Author: jm
Date: 2006-04-08 09:34:59 -0700 (Sat, 08 Apr 2006)
New Revision: 11111

Modified:
   trunk/speex/libspeex/ltp.c
Log:
Got rid of ~64 divides per sub-frame and saved 512 bytes of scratch space.


Modified: trunk/speex/libspeex/ltp.c
===================================================================
--- trunk/speex/libspeex/ltp.c	2006-04-08 15:35:07 UTC (rev 11110)
+++ trunk/speex/libspeex/ltp.c	2006-04-08 16:34:59 UTC (rev 11111)
@@ -176,13 +176,11 @@
    spx_word32_t e0;
    VARDECL(spx_word32_t *corr);
    VARDECL(spx_word32_t *energy);
-   VARDECL(spx_word32_t *score);
 
    ALLOC(best_score, N, spx_word32_t);
    ALLOC(best_ener, N, spx_word32_t);
    ALLOC(corr, end-start+1, spx_word32_t);
    ALLOC(energy, end-start+2, spx_word32_t);
-   ALLOC(score, end-start+1, spx_word32_t);
 
    for (i=0;i<N;i++)
    {
@@ -203,33 +201,39 @@
 
    pitch_xcorr(sw, sw-end, corr, len, end-start+1, stack);
 
+   /* FIXME: Fixed-point and floating-point code should be merged */
 #ifdef FIXED_POINT
    {
       VARDECL(spx_word16_t *corr16);
       VARDECL(spx_word16_t *ener16);
       ALLOC(corr16, end-start+1, spx_word16_t);
       ALLOC(ener16, end-start+1, spx_word16_t);
-      normalize16(corr, corr16, 16384, end-start+1);
-      normalize16(energy, ener16, 16384, end-start+1);
+      /* Normalize to 180 so we can square it and it still fits in 16 bits */
+      normalize16(corr, corr16, 180, end-start+1);
+      normalize16(energy, ener16, 180, end-start+1);
 
       for (i=start;i<=end;i++)
       {
-         spx_word16_t g;
-         spx_word32_t tmp;
-         tmp = corr16[i-start];
-         if (tmp>0)
+         spx_word16_t tmp = MULT16_16_16(corr16[i-start],corr16[i-start]);
+         /* Instead of dividing the tmp by the energy, we multiply on the other side */
+         if (MULT16_16(tmp,best_ener[N-1])>MULT16_16(best_score[N-1],ADD16(1,ener16[i-start])))
          {
-            if (SHR16(corr16[i-start],4)>ener16[i-start])
-               tmp = SHL32(EXTEND32(ener16[i-start]),14);
-            else if (-SHR16(corr16[i-start],4)>ener16[i-start])
-               tmp = -SHL32(EXTEND32(ener16[i-start]),14);
-            else
-               tmp = SHL32(tmp,10);
-            g = DIV32_16(tmp, 8+ener16[i-start]);
-            score[i-start] = MULT16_16(corr16[i-start],g);
-         } else
-         {
-            score[i-start] = 1;
+            for (j=0;j<N;j++)
+            {
+               if (MULT16_16(tmp,best_ener[j])>MULT16_16(best_score[j],ADD16(1,ener16[i-start])))
+               {
+                  for (k=N-1;k>j;k--)
+                  {
+                     best_score[k]=best_score[k-1];
+                     best_ener[k]=best_ener[k-1];
+                     pitch[k]=pitch[k-1];
+                  }
+                  best_score[j]=tmp;
+                  best_ener[j]=ener16[i-start]+1;
+                  pitch[j]=i;
+                  break;
+               }
+            }
          }
       }
    }
@@ -259,30 +263,6 @@
    }
 #endif
 
-#ifdef FIXED_POINT
-   /* Extract best scores */
-   for (i=start;i<=end;i++)
-   {
-      if (score[i-start]>best_score[N-1])
-      {
-         for (j=0;j<N;j++)
-         {
-            if (score[i-start] > best_score[j])
-            {
-               for (k=N-1;k>j;k--)
-               {
-                  best_score[k]=best_score[k-1];
-                  pitch[k]=pitch[k-1];
-               }
-               best_score[j]=score[i-start];
-               pitch[j]=i;
-               break;
-            }
-         }
-      }
-   }
-#endif
-
    /* Compute open-loop gain */
    if (gain)
    {



More information about the commits mailing list