Le sam 14/12/2002 à 01:03, Bernard Blackham a écrit :> 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:Thanks for the patch. I applied it and it give me up to 15% in speed. Doesn't seem to change the results, which is a good thing (though you originally forgot a "used=0" in vq_nbest_sign). I'll check a thing or two and I'll apply to CVS.> 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.38sStrange... on my PIII, encoding a 10 sec file with --comp 3 --quality 3 takes less than a second (your patch is still a bit faster). How did you get these timings?> 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.Sending it to the list is a good idea I think. If you want to know what the code does... it's simply calculating the distance between an input vector and a list of vectors (codebook) and it returns the id's of the N closest (n-best) codebook vectors. Jean-Marc -- Jean-Marc Valin, M.Sc.A. LABORIUS (http://www.gel.usherb.ca/laborius) Université de Sherbrooke, Québec, Canada -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 242 bytes Desc: signature.asc Url : http://lists.xiph.org/pipermail/speex-dev/attachments/20021214/6ef90172/signature-0001.pgp
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-0001.pgp
On Sat, Dec 14, 2002 at 01:46:19AM -0500, Jean-Marc Valin wrote:> Thanks for the patch. I applied it and it give me up to 15% in speed. > Doesn't seem to change the results, which is a good thing (though you > originally forgot a "used=0" in vq_nbest_sign). I'll check a thing or > two and I'll apply to CVS.D'oh. My carelessness, sorry! :)> Strange... on my PIII, encoding a 10 sec file with --comp 3 --quality 3 > takes less than a second (your patch is still a bit faster). How did you > get these timings?Using zsh's time function (gives real and user time - which are pretty similar on this unloaded machine). I've put my sample wave file at http://dagobah.ucc.asn.au/speextest/sample.wav if anybody wants to compare times. I'm curious now why my machine is slower - perhaps it's something about the way I've compiled it. (Compiles by default with -O2, and I can slice another .07 seconds off by compiling with -O999 :)> Sending it to the list is a good idea I think. If you want to know what > the code does... it's simply calculating the distance between an input > vector and a list of vectors (codebook) and it returns the id's of the N > closest (n-best) codebook vectors.Thanks. I'm beginning to grasp it piece by piece. Currently looking at the codebook search - next culprit on the list as given by gprof (and OPTIMIZE :) Cheers, Bernard. -- Bernard Blackham bernard at blackham dot com dot au Australian Linux Technical Conference 2003: http://www.linux.conf.au/ ^----- presentations will be recorded with speex :) -------------- 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/682dae7f/part-0001.pgp