shithub: opus

Download patch

ref: 0df0eb4c67443e0434368ddc9a979bce626b5ab7
parent: 1b074d6600d0eae3c44abdd354e4059ba36d7f1f
author: Jean-Marc Valin <[email protected]>
date: Wed Feb 13 11:00:10 EST 2008

doing the folding properly.

--- a/libcelt/bands.c
+++ b/libcelt/bands.c
@@ -265,7 +265,7 @@
          q -= 1;
          alpha = 0;
          if (q<0)
-            intra_fold(X+B*eBands[i], B*(eBands[i+1]-eBands[i]), q, norm, P+B*eBands[i], B, eBands[i]);
+            intra_fold(X+B*eBands[i], B*(eBands[i+1]-eBands[i]), norm, P+B*eBands[i], B, eBands[i], eBands[m->nbEBands+1]);
          else
             intra_prediction(X+B*eBands[i], W+B*eBands[i], B*(eBands[i+1]-eBands[i]), q, norm, P+B*eBands[i], B, eBands[i], enc);
       } else {
@@ -321,7 +321,7 @@
          q -= 1;
          alpha = 0;
          if (q<0)
-            intra_fold(X+B*eBands[i], B*(eBands[i+1]-eBands[i]), q, norm, P+B*eBands[i], B, eBands[i]);
+            intra_fold(X+B*eBands[i], B*(eBands[i+1]-eBands[i]), norm, P+B*eBands[i], B, eBands[i], eBands[m->nbEBands+1]);
          else
             intra_unquant(X+B*eBands[i], B*(eBands[i+1]-eBands[i]), q, norm, P+B*eBands[i], B, eBands[i], dec);
       } else {
--- a/libcelt/quant_bands.c
+++ b/libcelt/quant_bands.c
@@ -66,6 +66,7 @@
       //   qi = -2;
       //ec_laplace_encode(enc, qi, i==0?11192:6192);
       //ec_laplace_encode(enc, qi, 8500-i*200);
+      /* If we don't have enough bits to encode all the energy, just assume something safe. */
       if (ec_enc_tell(enc, 0) - bits > budget)
          qi = -1;
       else
@@ -87,6 +88,7 @@
    {
       int q2;
       float offset = (error[i]+.5)*frac[i];
+      /* FIXME: Instead of giving up without warning, we should degrade everything gracefully */
       if (ec_enc_tell(enc, 0) - bits +ec_ilog(frac[i])> budget)
          break;
       q2 = (int)floor(offset);
@@ -124,6 +126,7 @@
       float res;
       float mean = (1-coef)*eMeans[i];
       res = 6.;
+      /* If we didn't have enough bits to encode all the energy, just assume something safe. */
       if (ec_dec_tell(dec, 0) - bits > budget)
          qi = -1;
       else
--- a/libcelt/vq.c
+++ b/libcelt/vq.c
@@ -419,16 +419,28 @@
    }
 }
 
-void intra_fold(float *x, int N, int K, float *Y, float *P, int B, int N0)
+void intra_fold(float *x, int N, float *Y, float *P, int B, int N0, int Nmax)
 {
-   int j;
+   int i, j;
    float E;
    
    E = 1e-10;
-   for (j=0;j<N;j++)
+   if (N0 >= Nmax/2)
    {
-      P[j] = Y[j];
-      E += P[j]*P[j];
+      for (i=0;i<B;i++)
+      {
+         for (j=0;j<N/B;j++)
+         {
+            P[j*B+i] = Y[(Nmax-N0-j-1)*B+i];
+            E += P[j*B+i]*P[j*B+i];
+         }
+      }
+   } else {
+      for (j=0;j<N;j++)
+      {
+         P[j] = Y[j];
+         E += P[j]*P[j];
+      }
    }
    E = 1.f/sqrt(E);
    for (j=0;j<N;j++)
--- a/libcelt/vq.h
+++ b/libcelt/vq.h
@@ -75,6 +75,7 @@
 
 void intra_unquant(float *x, int N, int K, float *Y, float *P, int B, int N0, ec_dec *dec);
 
-void intra_fold(float *x, int N, int K, float *Y, float *P, int B, int N0);
+/** Encode the entire band as a "fold" from other parts of the spectrum. No bits required (only use is case of an emergency!) */
+void intra_fold(float *x, int N, float *Y, float *P, int B, int N0, int Nmax);
 
 #endif /* VQ_H */