shithub: opus

Download patch

ref: 591b74945dda62afb08d9c964876c11d8ed387f7
parent: 9fd13d60656a54d8e2b04f350b2cd84c6d1c4382
author: Jean-Marc Valin <[email protected]>
date: Sat Oct 8 06:22:10 EDT 2011

Redundancy fixes

No longer encoding the redundancy flag for SILK since we can infer
redundancy from the length of the frame. Also, we skip encoding the
flag for hybrid mode when we know the decoder will not read it.

--- a/src/opus_decoder.c
+++ b/src/opus_decoder.c
@@ -321,10 +321,13 @@
     }
 
     start_band = 0;
-    if (mode != MODE_CELT_ONLY && data != NULL && ec_tell(&dec)+29+8*(st->mode == MODE_HYBRID) < 8*len)
+    if (mode != MODE_CELT_ONLY && data != NULL && ec_tell(&dec)+17+20*(st->mode == MODE_HYBRID) < 8*len)
     {
         /* Check if we have a redundant 0-8 kHz band */
-        redundancy = ec_dec_bit_logp(&dec, 12);
+        if (mode == MODE_HYBRID)
+           redundancy = ec_dec_bit_logp(&dec, 12);
+        else
+           redundancy = 1;
         if (redundancy)
         {
             celt_to_silk = ec_dec_bit_logp(&dec, 1);
--- a/src/opus_encoder.c
+++ b/src/opus_encoder.c
@@ -917,15 +917,19 @@
         }
     }
 
-    if (st->mode != MODE_CELT_ONLY && ec_tell(&enc)+29+8*(st->mode == MODE_HYBRID) < 8*nb_compr_bytes)
+    if ( st->mode != MODE_CELT_ONLY && ec_tell(&enc)+17+20*(st->mode == MODE_HYBRID) < 8*(max_data_bytes-1))
     {
-        /* Check if we have a redundant 0-8 kHz band */
-        ec_enc_bit_logp(&enc, redundancy, 12);
+        /* For SILK mode, the redundancy is inferred from the length */
+        if (st->mode == MODE_HYBRID && (redundancy || ec_tell(&enc)+37 < 8*nb_compr_bytes))
+           ec_enc_bit_logp(&enc, redundancy, 12);
         if (redundancy)
         {
             int max_redundancy;
             ec_enc_bit_logp(&enc, celt_to_silk, 1);
-            max_redundancy = nb_compr_bytes-((ec_tell(&enc)+7)>>3)-(st->mode == MODE_HYBRID);
+            if (st->mode == MODE_HYBRID)
+               max_redundancy = (max_data_bytes-1)-nb_compr_bytes-1;
+            else
+               max_redundancy = (max_data_bytes-1)-((ec_tell(&enc)+7)>>3);
             /* Target the same bit-rate for redundancy as for the rest,
                up to a max of 257 bytes */
             redundancy_bytes = IMIN(max_redundancy, st->bitrate_bps/1600);
@@ -953,7 +957,7 @@
             while(ret>2&&data[ret-1]==0)ret--;
         nb_compr_bytes = ret;
     } else {
-       nb_compr_bytes = IMIN(1275-redundancy_bytes, nb_compr_bytes);
+       nb_compr_bytes = IMIN((max_data_bytes-1)-redundancy_bytes, nb_compr_bytes);
        ec_enc_shrink(&enc, nb_compr_bytes);
     }