shithub: opus

Download patch

ref: 66ac10210cbae160f225debe1a33c8ad50365a12
parent: d09dc7c7a2108e7173c4e802ca868327b7a2cab2
author: Jean-Marc Valin <[email protected]>
date: Tue May 29 13:01:35 EDT 2012

Fixes some cases where MIN/MAX macros result in duplicated function calls

Also enforces an upper bound of 510 kb/s even for frames that are
smaller than 20 ms. This reduces waste for high bitrate VBR.

--- a/celt/bands.c
+++ b/celt/bands.c
@@ -212,6 +212,7 @@
       int depth;
 #ifdef FIXED_POINT
       int shift;
+      opus_val32 thresh32;
 #endif
 
       N0 = m->eBands[i+1]-m->eBands[i];
@@ -219,7 +220,8 @@
       depth = (1+pulses[i])/((m->eBands[i+1]-m->eBands[i])<<LM);
 
 #ifdef FIXED_POINT
-      thresh = MULT16_32_Q15(QCONST16(0.5f, 15), MIN32(32767,SHR32(celt_exp2(-SHL16(depth, 10-BITRES)),1) ));
+      thresh32 = SHR32(celt_exp2(-SHL16(depth, 10-BITRES)),1);
+      thresh = MULT16_32_Q15(QCONST16(0.5f, 15), MIN32(32767,thresh32));
       {
          opus_val32 t;
          t = N0<<LM;
@@ -252,9 +254,12 @@
 
 #ifdef FIXED_POINT
          if (Ediff < 16384)
-            r = 2*MIN16(16383,SHR32(celt_exp2(-EXTRACT16(Ediff)),1));
-         else
+         {
+            opus_val32 r32 = SHR32(celt_exp2(-EXTRACT16(Ediff)),1);
+            r = 2*MIN16(16383,r32);
+         } else {
             r = 0;
+         }
          if (LM==3)
             r = MULT16_16_Q14(23170, MIN32(23169, r));
          r = SHR16(MIN16(thresh, r),1);
--- a/celt/celt.c
+++ b/celt/celt.c
@@ -1385,6 +1385,9 @@
      opus_int32 min_allowed;
      int lm_diff = st->mode->maxLM - LM;
 
+     /* Don't attempt to use more than 510 kb/s, even for frames smaller than 20 ms.
+        The CELT allocator will just not be able to use more than that anyway. */
+     nbCompressedBytes = IMIN(nbCompressedBytes,1275>>(3-LM));
      target = vbr_rate + (st->vbr_offset>>lm_diff) - ((40*C+20)<<BITRES);
 
      /* Shortblocks get a large boost in bitrate, but since they
--- a/celt/pitch.c
+++ b/celt/pitch.c
@@ -111,10 +111,17 @@
    opus_val16 lpc[4], mem[4]={0,0,0,0};
 #ifdef FIXED_POINT
    int shift;
-   opus_val32 maxabs = MAX32(1, celt_maxabs32(x[0], len));
+   opus_val32 maxabs = celt_maxabs32(x[0], len);
    if (C==2)
-      maxabs = MAX32(maxabs, celt_maxabs32(x[1], len));
-   shift = IMAX(0,celt_ilog2(maxabs)-10);
+   {
+      opus_val32 maxabs_1 = celt_maxabs32(x[1], len);
+      maxabs = MAX32(maxabs, maxabs_1);
+   }
+   if (maxabs<1)
+      maxabs=1;
+   shift = celt_ilog2(maxabs)-10;
+   if (shift<0)
+      shift=0;
    if (C==2)
       shift++;
 #endif
@@ -173,6 +180,7 @@
    VARDECL(opus_val32, xcorr);
 #ifdef FIXED_POINT
    opus_val32 maxcorr=1;
+   opus_val16 xmax, ymax;
    int shift=0;
 #endif
    int offset;
@@ -194,7 +202,9 @@
       y_lp4[j] = y[2*j];
 
 #ifdef FIXED_POINT
-   shift = celt_ilog2(MAX16(1, MAX16(celt_maxabs16(x_lp4, len>>2), celt_maxabs16(y_lp4, lag>>2))))-11;
+   xmax = celt_maxabs16(x_lp4, len>>2);
+   ymax = celt_maxabs16(y_lp4, lag>>2);
+   shift = celt_ilog2(MAX16(1, MAX16(xmax, ymax)))-11;
    if (shift>0)
    {
       for (j=0;j<len>>2;j++)