[speex-dev] patch for libspeex

Bernard Blackham b-speex at blackham.com.au
Fri Dec 13 22:03:42 PST 2002


I have a patch for libspeex, which optimises some of the loops in
vq_nbest and vq_nbest_sign that speeds up encoding - my results:

test file: 10s wav file at 16000 Hz, mono
encoding with wideband --quality 3, --comp 3
machine: PIII-900Mhz, 256MB RAM

before: 2.78s after: 2.38s

I'm still trying to grasp the code (I'm just a coder, no background
in sound processing), and just optimised some loops. Should I be
sending the patch straight to Jean-Marc? Or is here the right place?
It's small so attached anyway for now. Patch is against CVS 14-Dec.

Regards,

Bernard.


-- 
 Bernard Blackham
 bernard at blackham dot com dot au
 Australian Linux Technical Conference 2003: http://www.linux.conf.au/


-------------- next part --------------
--- speex/libspeex/vq.c	2002-12-14 13:53:57.000000000 +0800
+++ speexme/libspeex/vq.c	2002-12-14 13:53:10.000000000 +0800
@@ -59,7 +59,8 @@
 /*Finds the indices of the n-best entries in a codebook*/
 void vq_nbest(float *in, float *codebook, int len, int entries, float *E, int N, int *nbest, float *best_dist)
 {
-   int i,j,k;
+   int i,j,k,used;
+   used = 0;
    for (i=0;i<entries;i++)
    {
       float dist=.5*E[i];
@@ -67,21 +68,14 @@
          dist -= in[j]**codebook++;
       if (i<N || dist<best_dist[N-1])
       {
-
-         for (j=0;j<N;j++)
+         for (k=N-1; (k >= 1) && (k > used || dist < best_dist[k-1]); k--)
          {
-            if (j >= i || dist < best_dist[j])
-            {
-               for (k=N-1;k>j;k--)
-               {
-                  best_dist[k]=best_dist[k-1];
-                  nbest[k] = nbest[k-1];
-               }
-               best_dist[j]=dist;
-               nbest[j]=i;
-               break;
-            }
+            best_dist[k]=best_dist[k-1];
+            nbest[k] = nbest[k-1];
          }
+         best_dist[k]=dist;
+         nbest[k]=i;
+		 used++;
       }
    }
 }
@@ -89,7 +83,7 @@
 /*Finds the indices of the n-best entries in a codebook with sign*/
 void vq_nbest_sign(float *in, float *codebook, int len, int entries, float *E, int N, int *nbest, float *best_dist)
 {
-   int i,j,k, sign;
+   int i,j,k, sign, used;
    for (i=0;i<entries;i++)
    {
       float dist=0;
@@ -106,23 +100,16 @@
       dist += .5*E[i];
       if (i<N || dist<best_dist[N-1])
       {
-
-         for (j=0;j<N;j++)
+         for (k=N-1; (k >= 1) && (k > used || dist < best_dist[k-1]); k--)
          {
-            if (j >= i || dist < best_dist[j])
-            {
-               for (k=N-1;k>j;k--)
-               {
-                  best_dist[k]=best_dist[k-1];
-                  nbest[k] = nbest[k-1];
-               }
-               best_dist[j]=dist;
-               nbest[j]=i;
-               if (sign)
-                  nbest[j]+=entries;
-               break;
-            }
+            best_dist[k]=best_dist[k-1];
+            nbest[k] = nbest[k-1];
          }
+         best_dist[k]=dist;
+         nbest[k]=i;
+		 used++;
+         if (sign)
+            nbest[k]+=entries;
       }
    }
 }

-------------- next part --------------
A non-text attachment was scrubbed...
Name: part
Type: application/pgp-signature
Size: 190 bytes
Desc: not available
Url : http://lists.xiph.org/pipermail/speex-dev/attachments/20021214/a4c73dfc/part.pgp


More information about the Speex-dev mailing list