shithub: opus

Download patch

ref: 2ed5e67a2ea66902cadb2a7a031690019c00a363
parent: 525d7cfdc4489a2ce0a3108a813f54a929aad25d
author: Jean-Marc Valin <[email protected]>
date: Tue Jul 13 12:50:11 EDT 2010

Handling the start band and end band in tf encoding

--- a/libcelt/celt.c
+++ b/libcelt/celt.c
@@ -638,17 +638,17 @@
    return tf_select;
 }
 
-static void tf_encode(int len, int isTransient, int *tf_res, int nbCompressedBytes, int LM, int tf_select, ec_enc *enc)
+static void tf_encode(int start, int end, int isTransient, int *tf_res, int nbCompressedBytes, int LM, int tf_select, ec_enc *enc)
 {
    int curr, i;
    if (8*nbCompressedBytes - ec_enc_tell(enc, 0) < 100)
    {
-      for (i=0;i<len;i++)
+      for (i=start;i<end;i++)
          tf_res[i] = isTransient;
    } else {
-      ec_enc_bit_prob(enc, tf_res[0], isTransient ? 16384 : 4096);
-      curr = tf_res[0];
-      for (i=1;i<len;i++)
+      ec_enc_bit_prob(enc, tf_res[start], isTransient ? 16384 : 4096);
+      curr = tf_res[start];
+      for (i=start+1;i<end;i++)
       {
          ec_enc_bit_prob(enc, tf_res[i] ^ curr, isTransient ? 4096 : 2048);
          curr = tf_res[i];
@@ -655,21 +655,21 @@
       }
    }
    ec_enc_bits(enc, tf_select, 1);
-   for (i=0;i<len;i++)
+   for (i=start;i<end;i++)
       tf_res[i] = tf_select_table[LM][4*isTransient+2*tf_select+tf_res[i]];
 }
 
-static void tf_decode(int len, int C, int isTransient, int *tf_res, int nbCompressedBytes, int LM, ec_dec *dec)
+static void tf_decode(int start, int end, int C, int isTransient, int *tf_res, int nbCompressedBytes, int LM, ec_dec *dec)
 {
    int i, curr, tf_select;
    if (8*nbCompressedBytes - ec_dec_tell(dec, 0) < 100)
    {
-      for (i=0;i<len;i++)
+      for (i=start;i<end;i++)
          tf_res[i] = isTransient;
    } else {
-      tf_res[0] = ec_dec_bit_prob(dec, isTransient ? 16384 : 4096);
-      curr = tf_res[0];
-      for (i=1;i<len;i++)
+      tf_res[start] = ec_dec_bit_prob(dec, isTransient ? 16384 : 4096);
+      curr = tf_res[start];
+      for (i=start+1;i<end;i++)
       {
          tf_res[i] = ec_dec_bit_prob(dec, isTransient ? 4096 : 2048) ^ curr;
          curr = tf_res[i];
@@ -676,7 +676,7 @@
       }
    }
    tf_select = ec_dec_bits(dec, 1);
-   for (i=0;i<len;i++)
+   for (i=start;i<end;i++)
       tf_res[i] = tf_select_table[LM][4*isTransient+2*tf_select+tf_res[i]];
 }
 
@@ -1027,7 +1027,7 @@
      ec_byte_shrink(&buf, nbCompressedBytes);
    }
 
-   tf_encode(st->mode->nbEBands, isTransient, tf_res, nbAvailableBytes, LM, tf_select, enc);
+   tf_encode(st->start, st->end, isTransient, tf_res, nbAvailableBytes, LM, tf_select, enc);
 
    ALLOC(offsets, st->mode->nbEBands, int);
    ALLOC(fine_priority, st->mode->nbEBands, int);
@@ -1766,7 +1766,7 @@
    unquant_coarse_energy(st->mode, st->start, st->end, bandE, st->oldBandE, nbFilledBytes*8+nbAvailableBytes*4-8, intra_ener, st->mode->prob, dec, C);
 
    ALLOC(tf_res, st->mode->nbEBands, int);
-   tf_decode(st->mode->nbEBands, C, isTransient, tf_res, nbAvailableBytes, LM, dec);
+   tf_decode(st->start, st->end, C, isTransient, tf_res, nbAvailableBytes, LM, dec);
 
    ALLOC(pulses, st->mode->nbEBands, int);
    ALLOC(offsets, st->mode->nbEBands, int);