shithub: opus

Download patch

ref: d38d6b9aa1a85830022343606a0d9b5d79bd3323
parent: 828da91d66f155c31bc1753e9f6ae158d0e2671c
author: Jean-Marc Valin <[email protected]>
date: Sat Aug 7 05:21:32 EDT 2010

Implemented variable spreading amount in the decoder

Decision not yet implemented in the encoder

--- a/libcelt/bands.c
+++ b/libcelt/bands.c
@@ -819,7 +819,6 @@
    VARDECL(celt_norm, _norm);
    int B;
    int M;
-   int spread;
    celt_int32 seed;
    celt_norm *lowband;
    int update_lowband = 1;
@@ -828,7 +827,6 @@
 
    M = 1<<LM;
    B = shortBlocks ? M : 1;
-   spread = fold ? B : 0;
    ALLOC(_norm, M*eBands[m->nbEBands], celt_norm);
    norm = _norm;
 
--- a/libcelt/celt.c
+++ b/libcelt/celt.c
@@ -808,7 +808,8 @@
       (first symbols in the stream) */
    ec_enc_bit_prob(enc, intra_ener, 8192);
    ec_enc_bit_prob(enc, shortBlocks!=0, 8192);
-   ec_enc_bit_prob(enc, has_fold, 57344);
+   ec_enc_bit_prob(enc, has_fold>>1, 8192);
+   ec_enc_bit_prob(enc, has_fold&1, (has_fold>>1) ? 32768 : 49152);
 
    if (shortBlocks)
    {
@@ -1610,7 +1611,8 @@
    /* Decode the global flags (first symbols in the stream) */
    intra_ener = ec_dec_bit_prob(dec, 8192);
    isTransient = ec_dec_bit_prob(dec, 8192);
-   has_fold = ec_dec_bit_prob(dec, 57344);
+   has_fold = ec_dec_bit_prob(dec, 8192)<<1;
+   has_fold |= ec_dec_bit_prob(dec, (has_fold>>1) ? 32768 : 49152);
 
    if (isTransient)
       shortBlocks = M;
--- a/libcelt/vq.c
+++ b/libcelt/vq.c
@@ -74,12 +74,13 @@
    }
 }
 
-static void exp_rotation(celt_norm *X, int len, int dir, int stride, int K)
+static void exp_rotation(celt_norm *X, int len, int dir, int stride, int K, int spread)
 {
    int i;
    celt_word16 c, s;
    celt_word16 gain, theta;
    int stride2=0;
+   int factor;
    /*int i;
    if (len>=30)
    {
@@ -88,9 +89,16 @@
       X[14] = 1;
       K=5;
    }*/
-   if (2*K>=len)
+   if (2*K>=len || spread==0)
       return;
-   gain = celt_div((celt_word32)MULT16_16(Q15_ONE,len),(celt_word32)(len+10*K));
+   if (spread==1)
+      factor=10;
+   else if (spread==2)
+      factor=5;
+   else
+      factor=15;
+
+   gain = celt_div((celt_word32)MULT16_16(Q15_ONE,len),(celt_word32)(len+factor*K));
    /* FIXME: Make that HALF16 instead of HALF32 */
    theta = HALF32(MULT16_16_Q15(gain,gain));
 
@@ -196,8 +204,7 @@
    ALLOC(signx, N, celt_word16);
    N_1 = 512/N;
    
-   if (spread)
-      exp_rotation(X, N, 1, B, K);
+   exp_rotation(X, N, 1, B, K, spread);
 
    /* Get rid of the sign */
    sum = 0;
@@ -332,8 +339,7 @@
    if (resynth)
    {
       normalise_residual(iy, X, N, K, EXTRACT16(SHR32(yy,2*yshift)));
-      if (spread)
-         exp_rotation(X, N, -1, B, K);
+      exp_rotation(X, N, -1, B, K, spread);
    }
    RESTORE_STACK;
 }
@@ -374,8 +380,7 @@
       Ryy = MAC16_16(Ryy, iy[i], iy[i]);
    } while (++i < N);
    normalise_residual(iy, X, N, K, Ryy);
-   if (spread)
-      exp_rotation(X, N, -1, B, K);
+   exp_rotation(X, N, -1, B, K, spread);
    RESTORE_STACK;
 }