shithub: opus

Download patch

ref: f400a3c573ae50c1f4b7b19815700bfe12f0add5
parent: 64209a3edf1b9d00f26775bc54b62ae3de5f4113
author: Jean-Marc Valin <[email protected]>
date: Mon Apr 5 19:58:44 EDT 2010

Caching log2_frac(N, BITRES) in the more data to save some CPU

--- a/libcelt/dump_modes.c
+++ b/libcelt/dump_modes.c
@@ -121,6 +121,14 @@
       fprintf(file, "#endif\n");
       fprintf(file, "\n");
 
+      fprintf(file, "#ifndef DEF_LOGN%d_%d\n", mode->Fs, mode->mdctSize);
+      fprintf(file, "#define DEF_LOGN%d_%d\n", mode->Fs, mode->mdctSize);
+      fprintf (file, "static const celt_int16 logN%d_%d[%d] = {\n", mode->Fs, mode->mdctSize, mode->nbEBands);
+      for (j=0;j<mode->nbEBands;j++)
+         fprintf (file, "%d, ", mode->logN[j]);
+      fprintf (file, "};\n");
+      fprintf(file, "#endif\n");
+      fprintf(file, "\n");
 
       fprintf(file, "static const CELTMode mode%d_%d_%d = {\n", mode->Fs, mode->mdctSize, mode->overlap);
       fprintf(file, "0x%x,\t/* marker */\n", 0xa110ca7e);
@@ -141,6 +149,7 @@
       fprintf(file, "{%d, 0, 0},\t/* shortMdct */\n", 2*mode->mdctSize);
       fprintf(file, "window%d,\t/* shortWindow */\n", mode->overlap);
       fprintf(file, "0,\t/* prob */\n");
+      fprintf(file, "logN%d_%d,\t/* logN */\n", mode->Fs, mode->mdctSize);
       fprintf(file, "0x%x,\t/* marker */\n", 0xa110ca7e);
       fprintf(file, "};\n");
    }
--- a/libcelt/modes.c
+++ b/libcelt/modes.c
@@ -273,6 +273,7 @@
    int res;
    CELTMode *mode=NULL;
    celt_word16 *window;
+   celt_int16 *logN;
    ALLOC_STACK;
 #if !defined(VAR_ARRAYS) && !defined(USE_ALLOCA)
    if (global_stack==NULL)
@@ -367,6 +368,13 @@
    if (mode->bits==NULL)
       goto failure;
 
+   logN = (celt_int16*)celt_alloc(mode->nbEBands*sizeof(celt_int16));
+   if (logN==NULL)
+      goto failure;
+
+   for (i=0;i<mode->nbEBands;i++)
+      logN[i] = log2_frac(mode->eBands[i+1]-mode->eBands[i], BITRES);
+   mode->logN = logN;
 #endif /* !STATIC_MODES */
 
    clt_mdct_init(&mode->mdct, 2*mode->mdctSize);
--- a/libcelt/modes.h
+++ b/libcelt/modes.h
@@ -106,6 +106,7 @@
    const celt_word16 *shortWindow;
 
    int *prob;
+   const celt_int16 *logN;
    celt_uint32 marker_end;
 };
 
--- a/libcelt/rate.c
+++ b/libcelt/rate.c
@@ -148,7 +148,7 @@
       N=m->eBands[j+1]-m->eBands[j]; 
       /* Compensate for the extra DoF in stereo */
       d=(C*N+ ((C==2 && N>2) ? 1 : 0))<<BITRES; 
-      offset = FINE_OFFSET - log2_frac(N, BITRES);
+      offset = FINE_OFFSET - m->logN[j];
       /* Offset for the number of fine bits compared to their "fair share" of total/N */
       offset = bits[j]-offset*N*C;
       /* Compensate for the prediction gain in stereo */