shithub: opus

Download patch

ref: 65d35a35cf5db233ffa347ac5df5fb9fa591e76f
parent: a396e153b94cc9bcfd2c008de6448d52fd376407
author: Jean-Marc Valin <[email protected]>
date: Wed Jan 26 17:04:59 EST 2011

Only allowing silence in non-hybrid mode.

Also defining a 1-byte packet as triggering the PLC/CNG

--- a/libcelt/celt.c
+++ b/libcelt/celt.c
@@ -825,7 +825,7 @@
    int silence=0;
    SAVE_STACK;
 
-   if (nbCompressedBytes<0 || pcm==NULL)
+   if (nbCompressedBytes<2 || pcm==NULL)
      return CELT_BAD_ARG;
 
    for (LM=0;LM<4;LM++)
@@ -924,13 +924,16 @@
          CELT_COPY(pre[c]+COMBFILTER_MAXPERIOD, in+c*(N+st->overlap)+st->overlap, N);
       } while (++c<C);
 
-      ec_enc_bit_logp(enc, silence, 15);
+      if (tell==1)
+         ec_enc_bit_logp(enc, silence, 15);
+      else
+         silence=0;
       if (silence)
       {
          /*In VBR mode there is no need to send more than the minimum. */
          if (vbr_rate>0)
          {
-            effectiveBytes=nbCompressedBytes=nbFilledBytes+2;
+            effectiveBytes=nbCompressedBytes=IMIN(nbCompressedBytes, nbFilledBytes+2);
             total_bits=nbCompressedBytes*8;
             nbAvailableBytes=2;
             ec_byte_shrink(&buf, nbCompressedBytes);
@@ -2019,7 +2022,7 @@
          X[c*N+i] = 0;
    while (++c<C);
 
-   if (data == NULL)
+   if (data == NULL || len<=1)
    {
       celt_decode_lost(st, pcm, N, LM);
       RESTORE_STACK;
@@ -2040,7 +2043,10 @@
    total_bits = len*8;
    tell = ec_dec_tell(dec, 0);
 
-   silence = ec_dec_bit_logp(dec, 15);
+   if (tell==1)
+      silence = ec_dec_bit_logp(dec, 15);
+   else
+      silence = 0;
    if (silence)
    {
       /* Pretend we've read all the remaining bits */