shithub: opus

Download patch

ref: 5bdb7dbafc1b07d0dcea2715f84b8096f4a95112
parent: 37546cc3f60fd52880663d26f3e1cc0915f19538
author: Timothy B. Terriberry <[email protected]>
date: Tue Jul 27 09:33:55 EDT 2010

Eliminate the loop when encoding the split angle.

Use a closed-form formula for the codebook parameters instead.

--- a/libcelt/bands.c
+++ b/libcelt/bands.c
@@ -655,20 +655,12 @@
             ft = ((1<<qb>>1)+1)*((1<<qb>>1)+1);
             if (encode)
             {
-               int j;
-               int fl=0;
-               j=0;
-               while(1)
-               {
-                  if (j==itheta)
-                     break;
-                  fl+=fs;
-                  if (j<(1<<qb>>1))
-                     fs++;
-                  else
-                     fs--;
-                  j++;
-               }
+               int fl;
+
+               fs = itheta <= (1<<qb>>1) ? itheta + 1 : (1<<qb) + 1 - itheta;
+               fl = itheta <= (1<<qb>>1) ? itheta*(itheta + 1)>>1 :
+                ft - (((1<<qb) + 1 - itheta)*((1<<qb) + 2 - itheta)>>1);
+
                ec_encode((ec_enc*)ec, fl, fl+fs, ft);
             } else {
                int fl=0;