shithub: opus

Download patch

ref: 034172baa6880895050b7fcb65bbf7485680b8cf
parent: 5c80391b3529bcb3fc8afd3b83d7562bae4991ae
author: Jean-Marc Valin <[email protected]>
date: Thu Dec 16 09:40:14 EST 2010

Making the encoder fail less often at stupidly low bit-rates

--- a/libcelt/quant_bands.c
+++ b/libcelt/quant_bands.c
@@ -204,13 +204,14 @@
          }
          /* If we don't have enough bits to encode all the energy, just assume something safe.
             We allow slightly busting the budget here */
-         bits_left = budget-(int)ec_enc_tell(enc, 0)-2*C*(end-i);
-         if (bits_left < 24)
+         bits_left = budget-(int)ec_enc_tell(enc, 0)-3*C*(end-i);
+         if (i!=start && bits_left < 30)
          {
-            if (qi > 1)
-               qi = 1;
-            if (qi < -1)
-               qi = -1;
+            qi = IMAX(-1,qi);
+            if (bits_left < 24)
+               qi = IMIN(1, qi);
+            if (bits_left < 16)
+               qi = IMAX(-1, qi);
             if (bits_left<8)
                qi = 0;
          }
@@ -240,7 +241,7 @@
    ec_byte_buffer buf_start_state;
    SAVE_STACK;
 
-   intra = force_intra || (*delayedIntra && nbAvailableBytes > end);
+   intra = force_intra || (*delayedIntra && nbAvailableBytes > end*C);
    if (/*shortBlocks || */intra_decision(eBands, oldEBands, start, effEnd, m->nbEBands, C))
       *delayedIntra = 1;
    else