Many, many updates. Better split-VQ search, better handling of pitch for
authorjmvalin <jmvalin@0101bb08-14d6-0310-b084-bc0e0c8e3800>
Tue, 23 Apr 2002 08:12:24 +0000 (08:12 +0000)
committerjmvalin <jmvalin@0101bb08-14d6-0310-b084-bc0e0c8e3800>
Tue, 23 Apr 2002 08:12:24 +0000 (08:12 +0000)
periods shorter than subframe length. Slightly improved multi-pulse
search.

git-svn-id: http://svn.xiph.org/trunk/speex@3253 0101bb08-14d6-0310-b084-bc0e0c8e3800

16 files changed:
libspeex/Makefile.am
libspeex/cb_search.c
libspeex/cb_search.h
libspeex/filters.c
libspeex/filters.h
libspeex/hexc_table.c [new file with mode: 0644]
libspeex/ltp.c
libspeex/ltp.h
libspeex/modes.c
libspeex/modes.h
libspeex/mpulse.c
libspeex/sb_celp.c
libspeex/sb_celp.h
libspeex/speex.c
libspeex/speex.h
libspeex/testenc_sb.c

index 46ee572..326f28e 100644 (file)
@@ -1,6 +1,6 @@
 ## Process this file with automake to produce Makefile.in. -*-Makefile-*-
 
-# $Id: Makefile.am,v 1.21 2002/04/10 07:42:17 jmvalin Exp $
+# $Id: Makefile.am,v 1.22 2002/04/23 08:12:23 jmvalin Exp $
 
 # Disable automatic dependency tracking if using other tools than gcc and gmake
 #AUTOMAKE_OPTIONS = no-dependencies
@@ -32,7 +32,8 @@ libspeex_la_SOURCES = speex.c \
        mpulse.c \
        exc_sb_table.c \
        high_lsp_tables.c \
-       vbr.c
+       vbr.c \
+       hexc_table.c
 
 
 include_HEADERS = speex.h \
index 9e2f56c..23c4ae4 100644 (file)
 #include "vq.h"
 #include "matrix.h"
 
+#define min(a,b) ((a) < (b) ? (a) : (b))
+#define max(a,b) ((a) > (b) ? (a) : (b))
+
+
 static float scal_gains4[16] = {
    0.27713,
    0.49282,
@@ -121,7 +125,7 @@ float *stack
       d += target[i]*resp[i];
       e += resp[i]*resp[i];
     }
-    g = d/(e+.1);
+    g = d/(e+.0001);
     score = g*d;
     /*printf ("score: %f %f %f %f\n", target[0],d,e,score);*/
     if (score >= bscore) {
@@ -315,6 +319,368 @@ float *stack
    POP(stack);
 }
 
+void split_cb_search_nogain(
+float target[],                        /* target vector */
+float ak[],                    /* LPCs for this subframe */
+float awk1[],                  /* Weighted LPCs for this subframe */
+float awk2[],                  /* Weighted LPCs for this subframe */
+void *par,                      /* Codebook/search parameters*/
+int   p,                        /* number of LPC coeffs */
+int   nsf,                      /* number of samples in subframe */
+float *exc,
+FrameBits *bits,
+float *stack
+)
+{
+   int i,j;
+   float *resp;
+   float *t, *r, *e;
+   int *ind;
+   float *shape_cb;
+   int shape_cb_size, subvect_size, nb_subvect;
+   split_cb_params *params;
+
+   params = (split_cb_params *) par;
+   subvect_size = params->subvect_size;
+   nb_subvect = params->nb_subvect;
+   shape_cb_size = 1<<params->shape_bits;
+   shape_cb = params->shape_cb;
+   resp = PUSH(stack, shape_cb_size*subvect_size);
+   t = PUSH(stack, nsf);
+   r = PUSH(stack, nsf);
+   e = PUSH(stack, nsf);
+   ind = (int*)PUSH(stack, nb_subvect);
+
+   for (i=0;i<nsf;i++)
+      t[i]=target[i];
+
+   e[0]=1;
+   for (i=1;i<nsf;i++)
+      e[i]=0;
+   residue_zero(e, awk1, r, nsf, p);
+   syn_filt_zero(r, ak, r, nsf, p);
+   syn_filt_zero(r, awk2, r, nsf,p);
+   
+   /* Pre-compute codewords response and energy */
+   for (i=0;i<shape_cb_size;i++)
+   {
+      float *res = resp+i*subvect_size;
+
+      /* Compute codeword response */
+      int k;
+      for(j=0;j<subvect_size;j++)
+         res[j]=0;
+      for(j=0;j<subvect_size;j++)
+      {
+         for (k=j;k<subvect_size;k++)
+            res[k]+=shape_cb[i*subvect_size+j]*r[k-j];
+      }
+   }
+
+   for (i=0;i<nb_subvect;i++)
+   {
+      int best_index=0, k, m;
+      float g, dist, best_dist=-1;
+      float *a, *b;
+      /* Find best codeword for current sub-vector */
+      for (j=0;j<shape_cb_size;j++)
+      {
+         dist=0;
+         a=resp+j*subvect_size;
+         b=t+subvect_size*i;
+         for (k=0;k<subvect_size;k++)
+            dist += (a[k]-b[k])*(a[k]-b[k]);
+         if (dist<best_dist || j==0)
+         {
+            best_dist=dist;
+            best_index=j;
+         }
+      }
+      /*printf ("best index: %d/%d\n", best_index, shape_cb_size);*/
+      frame_bits_pack(bits,best_index,params->shape_bits);
+
+      ind[i]=best_index;
+      /* Update target for next subvector */
+      for (j=0;j<subvect_size;j++)
+      {
+         g=shape_cb[best_index*subvect_size+j];
+         for (k=subvect_size*i+j,m=0;k<nsf;k++,m++)
+            t[k] -= g*r[m];
+      }
+   }
+   
+   /* Put everything back together */
+   for (i=0;i<nb_subvect;i++)
+      for (j=0;j<subvect_size;j++)
+         e[subvect_size*i+j]=shape_cb[ind[i]*subvect_size+j];
+
+   /* Update excitation */
+   for (j=0;j<nsf;j++)
+      exc[j]+=e[j];
+   
+   /* Update target */
+   residue_zero(e, awk1, r, nsf, p);
+   syn_filt_zero(r, ak, r, nsf, p);
+   syn_filt_zero(r, awk2, r, nsf,p);
+   for (j=0;j<nsf;j++)
+      target[j]-=r[j];
+
+   
+
+
+   POP(stack);
+   POP(stack);
+   POP(stack);
+   POP(stack);
+}
+
+
+
+
+void split_cb_search2(
+float target[],                        /* target vector */
+float ak[],                    /* LPCs for this subframe */
+float awk1[],                  /* Weighted LPCs for this subframe */
+float awk2[],                  /* Weighted LPCs for this subframe */
+void *par,                      /* Codebook/search parameters*/
+int   p,                        /* number of LPC coeffs */
+int   nsf,                      /* number of samples in subframe */
+float *exc,
+FrameBits *bits,
+float *stack
+)
+{
+   int i,j, id;
+   float *resp, *E, q;
+   float *t, *r, *e;
+   float *gains;
+   int *ind;
+   float *shape_cb;
+   int shape_cb_size, subvect_size, nb_subvect;
+   float exc_energy=0;
+   split_cb_params *params;
+
+   params = (split_cb_params *) par;
+   subvect_size = params->subvect_size;
+   nb_subvect = params->nb_subvect;
+   shape_cb_size = 1<<params->shape_bits;
+   shape_cb = params->shape_cb;
+   resp = PUSH(stack, shape_cb_size*subvect_size);
+   E = PUSH(stack, shape_cb_size);
+   t = PUSH(stack, nsf);
+   r = PUSH(stack, nsf);
+   e = PUSH(stack, nsf);
+   gains = PUSH(stack, nb_subvect);
+   ind = (int*)PUSH(stack, nb_subvect);
+
+   /* Compute energy of the "real excitation" */
+   syn_filt_zero(target, awk1, e, nsf, p);
+   residue_zero(e, ak, e, nsf, p);
+   residue_zero(e, awk2, e, nsf, p);
+   for (i=0;i<nsf;i++)
+      exc_energy += e[i]*e[i];
+   exc_energy=sqrt(exc_energy/nb_subvect);
+
+   /* Quantize global ("average") gain */
+   q=log(exc_energy+.1);
+   q=floor(.5+2*(q-2));
+   if (q<0)
+      q=0;
+   if (q>15)
+      q=15;
+   id = (int)q;
+   frame_bits_pack(bits, id, 4);
+   exc_energy=exp(.5*q+2);
+
+
+   for (i=0;i<nsf;i++)
+      t[i]=target[i];
+
+   e[0]=1;
+   for (i=1;i<nsf;i++)
+      e[i]=0;
+   residue_zero(e, awk1, r, nsf, p);
+   syn_filt_zero(r, ak, r, nsf, p);
+   syn_filt_zero(r, awk2, r, nsf,p);
+   
+   /* Pre-compute codewords response and energy */
+   for (i=0;i<shape_cb_size;i++)
+   {
+      float *res = resp+i*subvect_size;
+
+      /* Compute codeword response */
+      int k;
+      for(j=0;j<subvect_size;j++)
+         res[j]=0;
+      for(j=0;j<subvect_size;j++)
+      {
+         for (k=j;k<subvect_size;k++)
+            res[k]+=shape_cb[i*subvect_size+j]*r[k-j];
+      }
+      /* Compute energy of codeword response */
+      E[i]=0;
+      for(j=0;j<subvect_size;j++)
+         E[i]+=res[j]*res[j];
+      E[i]=1/(.001+E[i]);
+   }
+
+   for (i=0;i<nb_subvect;i++)
+   {
+      int best_index[2]={0,0}, k, m;
+      float g, corr, best_gain[2]={0,0}, score, best_score[2]={-1,-1};
+      /* Find best codeword for current sub-vector */
+      for (j=0;j<shape_cb_size;j++)
+      {
+         corr=xcorr(resp+j*subvect_size,t+subvect_size*i,subvect_size);
+         score=corr*corr*E[j];
+         g = corr*E[j];
+         if (score>best_score[0])
+         {
+            best_index[1]=best_index[0];
+            best_score[1]=best_score[0];
+            best_gain[1]=best_gain[0];
+
+            best_index[0]=j;
+            best_score[0]=score;
+            best_gain[0]=g;
+         } else if (score>best_score[1]) {
+            best_index[1]=j;
+            best_score[1]=score;
+            best_gain[1]=g;            
+         }
+      }
+      
+      /* Quantize gain */
+      for (k=0;k<2;k++) {
+         int s=0, best_id;
+         best_gain[k] /= .01+exc_energy;
+         if (best_gain[k]<0)
+         {
+            best_gain[k]=-best_gain[k];
+            s=1;
+         }
+
+         /* Find gain index (it's a scalar but we use the VQ code anyway)*/
+         best_id = vq_index(&best_gain[k], scal_gains4, 1, 8);
+
+         best_gain[k]=scal_gains4[best_id];
+         /*printf ("gain_quant: %f %d %f\n", best_gain, best_id, scal_gains4[best_id]);*/
+         if (s)
+            best_gain[k]=-best_gain[k];
+         best_gain[k] *= exc_energy;
+      }
+
+
+
+      if (i<nb_subvect-1) {
+         int best_index2=0;
+         float best_score2=-1, best_gain2=0;
+         int nbest, best;
+         float err[2]={0,0};
+         float *tt=PUSH(stack,nsf);
+         for (nbest=0;nbest<2;nbest++)
+         {
+            for (j=0;j<nsf;j++)
+               tt[j]=t[j];
+            for (j=0;j<subvect_size;j++)
+            {
+               g=best_gain[nbest]*shape_cb[best_index[nbest]*subvect_size+j];
+               for (k=subvect_size*i+j,m=0;k<nsf;k++,m++)
+                  tt[k] -= g*r[m];
+            }
+            
+
+            for (j=0;j<shape_cb_size;j++)
+            {
+               corr=xcorr(resp+j*subvect_size,tt+subvect_size*(i+1),subvect_size);
+               score=corr*corr*E[j];
+               g = corr*E[j];
+               if (score>best_score2)
+               {
+                  best_index2=j;
+                  best_score2=score;
+                  best_gain2=g;
+               }
+            }
+
+            {
+               int s=0, best_id;
+               best_gain2 /= .01+exc_energy;
+               if (best_gain2<0)
+               {
+                  best_gain2=-best_gain2;
+                  s=1;
+               }
+               best_id = vq_index(&best_gain2, scal_gains4, 1, 8);
+               best_gain2=scal_gains4[best_id];
+               if (s)
+                  best_gain2=-best_gain2;
+               best_gain2 *= exc_energy;
+            }
+
+            for (j=0;j<subvect_size;j++)
+            {
+               g=best_gain2*shape_cb[best_index2*subvect_size+j];
+               for (k=subvect_size*(i+1)+j,m=0;k<nsf;k++,m++)
+                  tt[k] -= g*r[m];
+            }
+            for (j=subvect_size*i;j<subvect_size*(i+2);j++)
+               err[nbest]-=tt[j]*tt[j];
+            
+            best_score[nbest]=err[nbest];
+         }
+
+         if (best_score[1]>best_score[0])
+         {
+            best_index[0]=best_index[1];
+            best_score[0]=best_score[1];
+            best_gain[0]=best_gain[1];
+
+         }
+         POP(stack);
+      }
+
+
+      
+
+      ind[i]=best_index[0];
+      gains[i]=best_gain[0];
+      /* Update target for next subvector */
+      for (j=0;j<subvect_size;j++)
+      {
+         g=best_gain[0]*shape_cb[best_index[0]*subvect_size+j];
+         for (k=subvect_size*i+j,m=0;k<nsf;k++,m++)
+            t[k] -= g*r[m];
+      }
+   }
+   
+   /* Put everything back together */
+   for (i=0;i<nb_subvect;i++)
+      for (j=0;j<subvect_size;j++)
+         e[subvect_size*i+j]=gains[i]*shape_cb[ind[i]*subvect_size+j];
+
+   /* Update excitation */
+   for (j=0;j<nsf;j++)
+      exc[j]+=e[j];
+   
+   /* Update target */
+   residue_zero(e, awk1, r, nsf, p);
+   syn_filt_zero(r, ak, r, nsf, p);
+   syn_filt_zero(r, awk2, r, nsf,p);
+   for (j=0;j<nsf;j++)
+      target[j]-=r[j];
+
+   
+
+
+   POP(stack);
+   POP(stack);
+   POP(stack);
+   POP(stack);
+   POP(stack);
+   POP(stack);
+}
+
 
 
 
index a4658f3..244ff36 100644 (file)
@@ -56,7 +56,7 @@ FrameBits *bits,
 float *stack
 );
 
-void split_cb_search_wb(
+void split_cb_search_nogain(
 float target[],                        /* target vector */
 float ak[],                    /* LPCs for this subframe */
 float awk1[],                  /* Weighted LPCs for this subframe */
@@ -69,6 +69,21 @@ FrameBits *bits,
 float *stack
 );
 
+
+void split_cb_search2(
+float target[],                        /* target vector */
+float ak[],                    /* LPCs for this subframe */
+float awk1[],                  /* Weighted LPCs for this subframe */
+float awk2[],                  /* Weighted LPCs for this subframe */
+void *par,                      /* Codebook/search parameters*/
+int   p,                        /* number of LPC coeffs */
+int   nsf,                      /* number of samples in subframe */
+float *exc,
+FrameBits *bits,
+float *stack
+);
+
+
 void split_cb_unquant(
 float *exc,
 void  *par,                     /* Innovation parameters */
index 0bd77a6..41512e6 100644 (file)
 */
 
 #include "filters.h"
+#include <stdio.h>
 
 #define min(a,b) ((a) < (b) ? (a) : (b))
 
+void print_vec(float *vec, int len, char *name)
+{
+   int i;
+   printf ("%s ", name);
+   for (i=0;i<len;i++)
+      printf (" %f", vec[i]);
+   printf ("\n");
+}
+
 void bw_lpc(float gamma, float *lpc_in, float *lpc_out, int order)
 {
    int i;
index b9d856d..6c7165c 100644 (file)
@@ -20,6 +20,8 @@
 #ifndef FILTERS_H
 #define FILTERS_H
 
+void print_vec(float *vec, int len, char *name);
+
 /* Apply bandwidth expansion on LPC coef */
 void bw_lpc(float gamma, float *lpc_in, float *lpc_out, int order);
 
diff --git a/libspeex/hexc_table.c b/libspeex/hexc_table.c
new file mode 100644 (file)
index 0000000..e4ae5df
--- /dev/null
@@ -0,0 +1,257 @@
+float hexc_table[256][8]={
+{0,0,0,0,0,0,0,0},
+{-0.124633,0.709134,-0.353292,-0.100011,-4.75254,-1.19492,1.91261,3.17703},
+{7.65722,-5.45083,2.63568,-6.4316,-1.89175,-0.466831,-2.62109,1.40504},
+{-0.196422,3.42049,0.110829,2.61755,0.400882,4.91734,-2.27958,-8.22836},
+{2.89899,0.0536774,-2.33267,-2.22652,0.0327518,0.658552,0.677934,-0.108797},
+{3.91754,0.0948733,3.8366,-3.0895,-0.897586,1.40209,-0.0906191,-2.04542},
+{-0.187855,1.00529,0.698786,1.23539,-0.590565,-0.109911,-2.77967,-1.71522},
+{16.4003,13.6469,12.0238,12.0247,8.99906,6.76874,4.56455,2.57654},
+{-0.677238,-1.43921,-1.51191,-2.87916,4.22053,1.78013,3.3326,-0.52691},
+{-1.23192,4.25223,-2.11896,-2.09635,4.56563,-1.64065,-4.1804,3.06229},
+{2.09639,-1.23159,0.996652,-0.291257,0.503392,-0.263715,0.441603,-0.601744},
+{1.61943,0.259319,3.38506,0.477903,0.211131,-4.09897,-6.17992,0.0711276},
+{0.56057,-7.74415,9.78828,-1.98022,2.16269,4.58076,-3.22997,-0.0438142},
+{-7.7953,2.75296,-1.60745,2.3559,3.03604,-2.70062,-1.08142,1.03708},
+{-0.327143,0.508118,-0.284136,0.436241,-0.362498,0.452651,-0.474024,0.0398583},
+{0.395506,0.0990582,0.0973287,-1.03393,-1.13884,3.93053,2.63491,-3.21285},
+{-0.130276,-1.72332,-8.74412,2.16437,-5.05812,4.47607,4.27328,0.105277},
+{-6.89905,-4.37346,-19.6116,-0.803085,-24.817,37.3571,-4.92721,165.926},
+{2.60235,-7.67724,-2.17454,-3.13947,-0.871546,1.46517,3.00854,0.750017},
+{1.38834,2.16419,4.47336,0.396819,1.61154,-0.488036,-2.91986,-3.62602},
+{-0.267722,-1.27928,-1.54815,1.01517,-1.30285,6.2907,-2.37984,1.59779},
+{10.3643,6.58345,10.6146,3.05141,-10.3102,-12.0823,-5.76653,-2.23303},
+{-1.72908,4.27992,-1.23605,3.39782,-1.81781,-0.497225,0.0958252,1.02646},
+{0.465316,1.31008,2.3038,3.39667,4.14734,3.63285,3.41452,3.47548},
+{-0.332034,-1.74162,-8.09007,5.89303,3.739,1.06648,-1.28181,-0.0749382},
+{-0.378037,-0.496624,-0.655122,-0.811612,-0.750057,-0.803675,-0.691355,-0.609482},
+{-1.31898,-1.1015,0.447721,-0.0264966,1.64705,0.545,1.16122,0.890655},
+{1.00374,1.19226,-0.316613,0.205922,-1.52392,-3.18519,1.46116,-0.719755},
+{-0.82755,-5.35645,-2.32557,2.05192,2.1559,2.8016,1.73048,0.579947},
+{-5.74695,1.91548,4.27113,0.170372,-2.87978,-0.575378,4.00891,-0.242333},
+{-1.46014,-2.04408,0.618623,1.04639,2.25926,0.620763,0.0223016,-1.20626},
+{7.85841,7.2316,-4.59772,-13.0927,-2.07305,-5.35862,1.02443,2.91374},
+{-28.9738,-29.9479,-21.1514,-19.3304,-18.753,-15.2387,-13.0793,-6.39139},
+{2.24238,-1.55293,-6.74978,2.10057,-4.79248,-3.31379,3.14321,6.92445},
+{5.46397,-3.92148,-4.93206,4.43525,-1.53189,-0.519818,-2.62037,0.74977},
+{0.751644,0.005855,1.67575,-0.0104025,1.67935,0.245031,3.88256,-9.57539},
+{4.16921,0.233669,-3.91408,-1.47007,1.61097,4.64495,0.233817,-4.06308},
+{0.178042,0.0717345,1.43858,-4.2214,0.109823,1.79668,-1.30346,1.73824},
+{-0.208089,-0.943459,1.74093,1.36887,1.47514,-2.36995,-1.72045,-0.567021},
+{94.9082,72.6546,19.9534,20.8298,20.2464,12.9592,19.406,11.3202},
+{0.211787,-1.00195,1.53093,-0.986428,6.9982,-2.51765,-1.05592,-0.52969},
+{-0.412027,-0.0416657,-0.552586,0.188989,-0.315958,0.319828,-0.782269,4.10457},
+{2.19893,0.627193,0.0905311,2.02512,-3.91528,-10.1151,8.11845,1.90391},
+{8.53607,4.03524,0.444378,9.69537,8.72491,-3.15194,-17.8371,-12.9478},
+{-0.905081,-18.5757,2.73093,4.64838,0.675854,1.76229,3.92953,4.29863},
+{-3.05504,2.51569,2.60605,3.22993,1.89622,-1.24479,-1.89252,-1.05785},
+{0.189815,0.347461,0.583004,0.192732,-0.144563,-0.221409,-0.392779,-0.240286},
+{0.222396,0.725501,1.20206,-3.53847,-9.23962,4.16548,-2.65207,5.82031},
+{-0.0977143,-0.729665,-7.44131,0.868409,3.79825,-1.37507,7.56879,0.358514},
+{0.239891,0.975243,-0.207124,0.245905,-1.64001,-0.4278,-4.42181,3.31454},
+{3.81297,1.15309,-0.615272,0.393898,-0.102674,-0.232687,-1.14651,-2.05614},
+{0.0761315,-0.272116,-0.866704,0.161933,1.52894,1.48026,0.706022,-2.39579},
+{4.09957,-6.64283,3.85977,0.536794,-4.21348,5.37178,-0.953069,-2.16333},
+{-1.372,1.33928,3.53997,0.884164,-1.78364,-1.75854,-0.76074,-0.0875155},
+{2.36904,2.4113,-5.05789,2.00201,-1.79323,-0.192766,-0.00386853,0.715435},
+{6.97471,8.5061,0.133323,-1.20679,-4.4193,0.802588,1.17402,-6.34665},
+{0.0142825,2.68136,-2.30019,0.945289,2.45734,0.25891,-2.05026,-0.992398},
+{0.305972,0.0952337,-0.0896897,0.0121289,0.502184,-1.39021,-0.362368,0.96016},
+{0.0491968,-0.0293672,0.0329259,-0.490325,-0.323103,-0.839378,1.86117,1.13785},
+{-0.350797,-2.32743,6.89907,7.88932,-3.97595,-1.52524,2.0538,-7.85158},
+{-4.65036,-7.01617,4.80323,-0.28348,10.694,-2.75345,5.27919,0.829943},
+{-6.18875,5.15951,-2.62489,-5.14746,2.49968,-5.08069,3.54648,6.4851},
+{0.35778,-0.746433,-1.06582,-0.484774,0.266932,0.572277,0.734908,0.120138},
+{5.54284,1.62255,-1.00522,-4.70178,0.118753,-3.5652,2.23952,-1.86555},
+{-8.61091,-6.08946,-5.65072,-5.46432,-4.59801,-3.56913,-2.30351,-1.59635},
+{-0.304533,0.0443325,-1.02952,-1.48296,0.677945,-2.31357,4.62297,3.86147},
+{16.4093,-3.29112,-4.13596,4.1949,-6.77296,1.33971,0.356506,-5.9223},
+{9.75046,8.33574,10.1556,3.94866,11.9924,2.43735,-6.48726,-45.5453},
+{1.35713,0.226259,-2.40778,-4.63494,-2.24869,2.81727,4.3285,2.31185},
+{2.14669,-0.829122,2.39036,1.71696,-1.7243,0.201098,-0.337368,-2.21057},
+{-0.379367,-1.3162,0.385318,2.49085,-0.588362,1.43544,0.266819,-0.762972},
+{20.1128,12.5953,29.6717,25.7954,17.6684,13.4463,8.80977,5.98823},
+{3.90611,4.13562,-8.27716,-13.7767,7.08054,7.40331,-2.53986,1.35251},
+{-1.62264,1.6546,3.77908,-1.99865,0.738225,2.50548,-5.94721,1.10919},
+{0.0477677,-0.0425041,0.366971,-0.875714,2.04819,-1.27543,0.872946,-0.856728},
+{2.41722,4.13586,2.01805,-0.292185,-3.02575,-1.67243,-2.1895,-1.15785},
+{-3.60578,-1.70102,1.69283,1.97525,-0.284958,-0.100427,0.425959,0.888488},
+{-1.5129,2.82814,1.76809,-2.6816,-0.180332,0.491737,1.63089,-0.763955},
+{-0.0143589,0.399285,-0.0994942,-0.502938,-0.333592,-0.104954,0.233167,0.392239},
+{1.67405,1.73466,1.49446,2.47518,-8.32141,-1.1105,2.44097,-2.20398},
+{-3.61704,-4.57834,-1.02428,-3.68364,-1.85282,2.17452,9.55899,7.43489},
+{0.298172,0.9963,1.04169,-3.52328,-1.45634,-0.639949,-4.20383,32.3458},
+{0.454027,-1.32234,-0.275284,1.59237,-0.2019,-0.992402,0.734051,0.22433},
+{0.0870788,-0.0409921,0.453492,0.186622,0.0253391,0.0125788,0.0514432,-1.93421},
+{0.0949132,-0.279746,0.00773279,2.48065,2.23413,9.7595,-10.9672,-2.69571},
+{-0.42108,1.96556,8.9301,-4.8952,-0.281521,-2.47129,-0.402138,-1.83134},
+{-0.306824,0.254839,-1.25146,0.568873,-1.38831,0.789644,0.976548,0.0492205},
+{0.423627,0.618305,0.612155,0.637545,0.782411,0.769886,0.607862,0.411707},
+{-1.43537,-1.30235,-5.92011,-1.99894,9.87538,-2.4618,1.90621,1.8659},
+{-0.947278,2.56979,1.55118,-0.194945,1.49244,-5.06596,0.170384,-0.249401},
+{-1.36498,-1.99714,-1.13416,-0.22359,-0.104795,0.249995,0.0901003,0.981652},
+{-1.95965,5.37343,-5.07107,4.11164,0.652106,-4.34714,2.8756,-1.56539},
+{-6.22321,-3.27259,-3.38364,-0.188568,2.39983,2.24778,2.68626,2.83561},
+{-2.54959,0.682998,1.09015,-0.612539,-0.98431,1.41871,-0.349726,1.23296},
+{-0.29605,-0.590653,-1.25288,-1.17515,2.94077,0.341683,-0.965384,0.926922},
+{-3.8208,6.64341,2.66736,-8.92415,3.48916,6.72564,-0.203787,-5.66214},
+{-58.0733,-109.568,-120.071,-95.438,-57.8918,-28.9008,-12.8107,-3.5557},
+{-5.66526,-5.14158,3.86487,0.560814,-1.06906,-2.87972,-0.21149,5.99357},
+{3.81596,-2.78815,-1.86367,2.54713,-2.37254,1.91097,1.99671,-2.28994},
+{0.0539667,3.91687,0.449347,3.79675,3.34144,-6.88731,3.66869,-14.6544},
+{1.12497,2.74561,-0.3938,-4.25215,2.84085,0.362278,-1.82594,-2.45511},
+{0.0211127,-1.72793,1.62255,0.105806,-0.283394,0.876935,-0.650737,0.295708},
+{-1.76437,-1.07731,-0.348999,5.69704,0.101825,0.844051,-2.96391,0.760176},
+{88.7141,112.743,89.0107,65.028,57.7858,53.7961,43.3063,22.7663},
+{-0.528845,2.113,2.3194,2.14449,1.86506,-13.362,-3.00807,3.67712},
+{0.838452,-2.53742,-4.28145,-0.437028,-0.609153,0.102954,0.535033,3.00112},
+{0.28854,-0.410248,0.690436,-1.23695,3.64209,-4.82857,5.2072,-2.25672},
+{-0.314126,-0.769524,0.131029,4.24101,3.48463,0.248342,-2.74577,-4.48021},
+{0.555925,-4.62015,0.387454,-0.330363,3.20152,1.70546,-3.81424,4.62474},
+{-3.4213,15.9757,2.73522,0.194243,0.257501,3.12679,-2.41229,-2.04571},
+{0.00165975,0.0244441,-0.00167063,-0.0114329,0.0458509,0.0194235,0.00796441,-0.0137953},
+{0.911365,-1.34234,2.13987,3.29676,-3.64597,0.0999147,-1.81664,2.28563},
+{4.47113,0.559615,-5.53125,-12.234,-11.3373,9.5302,16.0957,3.5127},
+{0.300706,-0.120382,0.670355,2.22102,1.70121,-0.938085,-10.587,6.05266},
+{1.20243,-0.0263491,-0.167586,-0.0951263,-0.208164,-0.0804163,-0.151097,-0.21795},
+{-0.0842739,0.208618,-0.131425,0.2206,0.109082,-0.472402,0.824921,-0.583573},
+{-2.99785,-4.42416,-1.86328,-4.4312,4.51356,15.2835,-2.06858,0.676297},
+{-1.66033,4.95833,3.74878,-0.290086,-7.17661,-5.45601,0.119688,3.60161},
+{2.79034,7.7291,-10.7567,-1.92117,0.0118825,0.920566,-0.236087,-0.402009},
+{7.75002,-2.23395,1.52487,1.78453,1.69059,0.307544,-0.785332,-1.11899},
+{-0.609985,0.889939,-4.84241,-0.818176,1.27978,1.77655,0.829194,0.406604},
+{1.46036,0.779691,0.73605,-1.61776,-0.332832,-5.93634,-1.0418,3.75032},
+{0.481613,-0.146268,0.558567,-1.25947,-1.35794,1.14697,0.539569,-0.0815973},
+{-3.96012,-5.20521,-1.40374,8.51505,1.90713,-5.24493,-1.62459,2.34314},
+{-4.84121,-4.0844,2.31582,2.18638,5.28302,0.714339,-2.19018,-0.429647},
+{-22.8252,-2.32658,-7.38579,0.22799,8.03754,3.36877,5.36252,6.18499},
+{-1.13653,-0.195917,0.969309,0.666294,-0.353006,-0.553089,-0.0866454,0.439218},
+{3.53106,3.47066,-0.880209,-3.06279,-2.98238,-0.871701,0.627605,3.23931},
+{-5.19707,-1.52359,-0.864088,-1.2368,-1.38742,-0.427472,-0.491785,-0.592172},
+{0.198913,1.2229,0.0697973,-1.64807,-2.93506,-2.73168,5.9653,-0.172975},
+{3.75328,0.116182,-2.64952,-3.1486,0.468066,1.72553,-4.66912,1.80205},
+{0.0617427,-3.95373,4.15663,5.77165,-13.7333,13.6662,1.9058,-18.3167},
+{0.803773,-1.72723,-0.391257,-2.33851,1.02508,2.65897,0.364772,0.323266},
+{0.811483,-3.07522,3.14185,-2.6032,2.25004,-0.444016,0.148008,-0.651473},
+{-0.772831,2.65199,-0.032664,0.62535,-0.432513,0.347632,-0.00717036,-1.39254},
+{20.5472,4.83106,4.95877,6.3597,3.27828,4.383,1.58179,1.71363},
+{-0.102586,-0.949736,-0.672078,-7.44841,4.13724,-0.122848,0.970153,2.54162},
+{-0.482255,2.90589,-0.322505,-0.413532,-0.416462,-1.05482,-1.44329,1.27294},
+{0.216043,-0.631032,0.621151,-0.681611,0.372445,-0.255996,0.272085,-0.0369481},
+{1.29719,1.22662,-0.757092,3.65015,-0.641968,-3.70358,-2.10176,0.251901},
+{-0.987225,-2.73038,6.42124,1.57463,0.585071,-0.181883,-0.128151,-0.163688},
+{-4.06935,3.61756,-2.01217,-1.86789,0.657186,0.712952,-0.0182699,1.52881},
+{-1.03555,0.511431,-1.16694,0.233248,0.46962,-0.0405056,0.227786,0.82183},
+{-1.41986,0.211741,-1.43041,-0.247476,-3.51242,2.92859,3.09243,-0.0380268},
+{-1.63231,-1.87559,-2.72054,0.115409,-3.70595,9.96328,3.42132,1.21836},
+{-4.79079,3.68284,-8.09519,9.13098,-13.2031,28.1024,-26.3338,100.784},
+{1.70282,-3.21702,-1.20921,-0.652983,0.933787,-0.643258,1.66499,0.184771},
+{0.863766,0.507668,0.456694,-0.281845,-0.2008,-1.38984,-3.64332,-7.98858},
+{0.285095,-0.297741,-0.305613,0.388166,-0.429425,2.85422,-1.15849,-1.21032},
+{0.217996,3.55512,12.1684,3.06927,-3.11083,-5.75629,-3.04623,2.50726},
+{-2.60503,0.576449,-2.56158,6.55611,-6.59388,3.21817,-1.10895,0.302273},
+{6.65619,5.33674,5.6218,4.76786,3.96142,2.95088,1.95973,0.707597},
+{-5.401,-10.3647,-20.6209,15.6539,6.1057,0.537674,10.0364,-0.469702},
+{1.62284,0.242311,1.0784,-0.554592,-1.38022,-1.59271,-1.5614,-0.148781},
+{-0.323606,-0.794087,-0.48751,0.0514974,0.107547,1.91929,2.47284,2.36645},
+{-0.389985,-0.0747641,0.940271,4.7949,-0.668243,-2.4003,0.963513,-2.26186},
+{-5.30214,-2.66262,0.90595,5.06168,0.167943,4.45965,1.82353,-2.28554},
+{-15.2868,-2.88433,17.3311,-4.69775,-6.38507,2.32581,1.78902,5.02255},
+{-2.45955,0.384635,2.14552,-0.208571,1.18552,1.84719,-0.298183,-2.5892},
+{1.68438,14.4461,-1.91254,-8.25743,-10.7753,-9.27382,9.75762,6.05605},
+{-37.2676,-15.8881,-7.32543,-13.1854,-10.5795,-7.80677,-4.76706,-6.0121},
+{2.32499,-2.1412,-1.13345,-3.01872,-2.38307,-4.11756,-0.80428,11.3435},
+{5.98836,-4.52868,-1.4419,2.06118,-1.0053,-4.54096,1.31057,0.936292},
+{-1.45647,-2.42695,0.874431,1.13838,2.6115,1.45619,5.1732,-3.86706},
+{0.468279,-2.54611,-6.41498,-0.501039,8.16362,8.14442,-0.267457,-7.67813},
+{0.661843,-0.662204,4.04344,-2.32716,-3.35996,-0.362568,-0.204895,1.58793},
+{-0.90881,0.240288,-0.101023,1.84391,0.907318,-0.179726,-0.834737,-0.258053},
+{63.8951,43.0059,24.6095,32.1787,37.6453,26.5148,16.7264,16.7989},
+{-3.40992,0.915236,2.23379,-1.72307,2.4518,-1.41713,-0.750831,2.23796},
+{0.192647,-0.0613659,-0.0900871,-0.119244,-0.359946,0.653171,-1.06137,1.31772},
+{2.49081,-4.2797,5.02398,-0.647238,-1.72162,-5.32287,5.32772,-0.700779},
+{-0.228042,0.62236,1.77143,0.472478,8.83029,-0.396976,-9.51358,-3.43262},
+{3.0112,-11.952,-3.60736,6.29123,4.2449,3.32801,-2.30609,-0.0357611},
+{-3.61862,3.34871,-1.60253,0.161435,5.00982,0.339521,2.046,-3.23407},
+{0.0205111,-0.384494,-0.1446,0.297178,0.82016,0.0744092,-0.379702,-0.236443},
+{5.83001,-0.0348266,5.59311,-0.74714,-7.15472,2.89986,-7.095,1.63435},
+{-1.2942,-0.579663,-2.48986,2.539,-0.869076,-0.549802,4.10337,0.301529},
+{-0.648904,0.378769,-0.968117,0.772411,-1.13077,0.775235,-3.21542,8.34237},
+{3.58267,-0.0915582,-1.0484,0.0884655,1.29556,-1.83501,-0.185002,1.08254},
+{-0.209366,0.69812,-2.16731,3.41955,-1.52321,0.826082,1.01373,-3.39097},
+{-2.26066,-1.40958,5.32075,-0.276717,-2.78494,4.33579,-0.168931,-3.54584},
+{-0.665222,0.665878,1.68574,0.576886,-1.90399,0.00146961,1.48097,-0.63346},
+{3.65043,-0.4308,-1.1678,0.0607685,-2.98668,-0.103246,0.756657,0.380301},
+{7.99375,2.53517,-0.497777,0.770466,-5.04935,-5.17215,-3.43236,0.904961},
+{0.435016,-0.113796,-1.57557,2.18127,2.98135,-2.09224,0.892665,-1.20039},
+{0.871804,-0.447763,1.3428,-0.724864,1.6856,-1.35567,-2.22119,2.29067},
+{0.422004,0.259276,-1.02522,-1.738,-1.21942,-0.313969,0.168196,1.97473},
+{0.79007,2.68486,3.87648,7.03482,-4.62735,-0.455793,-5.21429,-3.62786},
+{-5.87799,-3.98783,-1.28793,10.597,9.6449,3.30147,1.57558,-4.43165},
+{-17.0874,19.9496,-5.57932,4.28525,9.02458,-13.5845,0.710407,0.953128},
+{-0.924992,-0.2889,0.115995,-0.0578672,0.161932,0.731155,0.305014,-0.160134},
+{8.94831,2.87189,-3.85971,-1.09456,3.01356,-2.81641,-3.61115,-2.37473},
+{-16.866,-13.207,-12.2628,-8.86788,-7.27316,-6.35138,-4.16926,-1.30505},
+{0.204318,-1.18495,1.69611,-5.87154,-1.09162,-3.17763,3.81016,5.46422},
+{32.3196,-26.4305,-15.3083,13.389,5.29654,1.3497,-4.56716,-3.0803},
+{1.75226,-2.95783,0.0391654,1.43998,4.32347,4.63445,12.0214,-24.3157},
+{5.73897,1.50275,-2.59347,-9.41519,-2.96615,6.11175,0.653714,-0.566137},
+{2.98372,-2.72632,0.749759,-1.00422,-1.43957,1.27977,-1.67646,0.877245},
+{0.548712,0.597705,0.0164013,1.39439,-1.68985,-0.39492,-0.406022,0.299087},
+{45.7234,23.3769,4.62083,7.01499,9.78483,13.3994,9.72012,5.72552},
+{-2.09919,1.06592,1.32802,-20.703,10.3256,3.93026,-2.9109,9.97675},
+{-0.865733,-0.363424,0.614046,0.788532,1.07512,2.0567,-3.31456,0.769445},
+{1.16772,0.29314,1.08944,-3.30867,0.437565,-1.73196,0.469983,-0.020718},
+{0.804264,8.93642,0.298777,1.65058,-0.278129,-6.2409,-4.30878,-2.51514},
+{1.45749,-5.4972,1.59904,2.36218,0.62901,-0.398502,-0.37127,-0.128095},
+{-1.15142,1.15667,0.533943,-0.638291,0.748438,-0.236054,-0.371887,0.0551342},
+{-0.0134577,0.917125,-0.692473,-1.38295,0.651743,1.16129,-0.16168,-0.353701},
+{3.09101,1.25459,3.52712,-4.66651,-8.30614,1.94741,3.66175,-2.53572},
+{-3.79474,-1.2712,1.5456,-5.77896,-2.15106,5.52802,5.16584,-0.824595},
+{-1.29917,-0.152905,-1.49112,-0.957469,-1.15177,5.20993,-1.30904,16.5467},
+{1.6654,-1.494,-1.42496,1.55172,0.307429,0.349257,-1.20406,0.389077},
+{0.429784,0.608935,0.751754,-0.0494915,0.731098,-1.55255,0.911601,-4.40677},
+{2.00906,1.05476,-0.327177,2.06333,-0.814492,2.24618,-6.00176,-1.77531},
+{4.66946,4.38809,5.58569,-7.918,-0.289225,-3.45762,-4.3845,3.00876},
+{-1.17988,1.13447,-1.68267,1.46021,-1.27858,1.60578,-1.19326,1.0592},
+{2.26378,1.9471,2.2834,2.20481,1.28164,1.31936,0.723912,0.264843},
+{2.59296,-1.12518,-7.86353,-3.44897,3.48369,4.15248,0.678701,3.28794},
+{1.02773,1.39452,1.05653,0.687331,0.512416,-1.20686,-0.451067,-0.726915},
+{-2.20508,-0.946671,-0.383217,-2.59423,-0.127601,0.181709,2.13321,1.07847},
+{5.11053,0.787867,-5.00871,9.78689,-0.698865,-2.33587,4.06018,-6.26019},
+{-3.08775,0.00788429,-1.37288,0.830455,1.50064,3.72122,0.519269,-0.174458},
+{-8.65087,0.420658,4.19734,-2.53148,2.00787,3.44438,0.479103,1.88357},
+{0.670846,0.175748,0.388663,-0.392712,1.34099,0.27084,-2.14573,-0.817875},
+{-3.82491,10.8946,-0.724208,-7.25032,-0.906455,-0.968595,3.10847,-0.953001},
+{-60.2306,-66.0493,-52.769,-28.5048,-18.995,-24.6236,-14.8306,-4.60763},
+{-1.28833,-3.36615,-1.12593,1.72623,2.03918,-3.13427,1.83378,3.2688},
+{-1.41746,-5.77968,2.05356,4.39273,-4.71032,0.525318,4.17257,0.33712},
+{0.489101,0.986629,2.88171,3.26994,4.87412,-7.68866,-0.255392,-5.86123},
+{-0.486568,3.64866,-1.18497,-2.56582,-1.86345,3.97503,-1.60875,-1.51483},
+{0.0224374,0.447103,2.57407,-1.17341,0.0103403,0.097923,-0.588402,-0.3276},
+{-1.50035,-0.588047,-2.79878,2.95604,1.49174,-0.281278,-0.104843,0.95529},
+{43.8765,68.9196,53.5544,18.5602,-7.28795,-6.17145,11.5068,11.8125},
+{1.93415,-0.764005,-3.39096,1.811,5.07884,-5.5778,-3.31742,4.42688},
+{-0.844518,-1.0928,-1.23793,-1.94435,-0.671152,3.08139,1.31817,6.51686},
+{-1.15335,-1.41424,2.53316,-0.165687,0.285124,-2.28472,2.47299,-0.78268},
+{2.00046,-3.08138,-3.03712,0.584362,4.23179,0.551653,-2.76306,-2.11327},
+{-2.29126,-4.45644,2.27253,-1.606,0.427992,2.66471,0.116678,1.07283},
+{-5.0359,6.43669,3.4784,-0.091146,-1.32296,0.266394,-1.44734,-0.928342},
+{0.0439666,-0.483358,-0.0579151,0.242941,-0.230237,0.116684,0.153393,0.37601},
+{0.507153,1.08043,0.560109,0.292706,-3.98339,2.15313,-1.38018,0.420253},
+{-0.13139,-0.382544,-2.22085,-1.24414,-0.845732,1.22189,11.8253,-3.55114},
+{-1.02419,2.41956,1.70631,-0.921757,-1.97945,-8.94564,-21.8953,7.22507},
+{0.959283,0.968234,-1.83562,0.419404,0.0721482,-0.314022,-0.0424927,-0.102174},
+{0.248888,-0.164755,-0.300158,-0.369368,0.229399,-0.207267,3.28298,-1.61728},
+{-1.24941,-0.21401,0.769815,-2.09711,4.46625,5.15347,-2.03265,-1.19599},
+{-3.15887,0.00237708,2.5495,4.70987,-2.47164,-3.74927,2.03071,4.01164},
+{0.525486,4.87947,-3.32576,-1.7101,-1.90991,-0.0993742,1.96111,-1.32008},
+{3.02228,5.57303,0.0510654,-0.70773,1.60367,-0.535712,-0.100697,-0.543199},
+{-0.627222,2.10949,-2.63038,-1.13644,1.7397,-2.35395,1.30674,0.715664},
+{0.657966,-0.930129,1.1111,0.196496,-0.821329,-2.62898,0.905887,2.76431},
+{0.158239,-2.62874,0.887907,-0.0719686,-2.34732,0.274504,1.60437,-0.333946},
+{-0.41052,-4.0426,4.87021,13.4334,-3.81333,-8.63686,-4.28218,-0.323974},
+{-9.14699,-2.17646,7.44449,7.06822,2.33518,1.29543,-4.89149,0.13786},
+{-11.7021,5.09057,1.69011,7.30886,1.32423,0.0720759,3.78273,-0.839777},
+{-3.29212,1.23263,-0.453421,0.690821,0.467484,-0.463127,1.26455,-0.327746},
+{1.33427,1.86117,0.160804,-1.15946,-1.11658,-0.125074,-0.0105876,-0.194273}};
index 44b2da6..c891505 100644 (file)
@@ -327,7 +327,7 @@ float *stack
 
 
 /** Finds the best quantized 3-tap pitch predictor by analysis by synthesis */
-void pitch_search_3tap(
+int pitch_search_3tap(
 float target[],                 /* Target vector */
 float ak[],                     /* LPCs for this subframe */
 float awk1[],                   /* Weighted LPCs #1 for this subframe */
@@ -339,12 +339,14 @@ int   end,                      /* Largest pitch value allowed */
 int   p,                        /* Number of LPC coeffs */
 int   nsf,                      /* Number of samples in subframe */
 FrameBits *bits,
-float *stack
+float *stack,
+float *exc2
 )
 {
    int i,j;
-   float *tmp;
+   float *tmp, *tmp2;
    float *x[3];
+   float *e[3];
    float corr[3];
    float A[3][3];
    float gain[3];
@@ -355,14 +357,20 @@ float *stack
    gain_cdbk=params->gain_cdbk;
    gain_cdbk_size=1<<params->gain_bits;
    tmp = PUSH(stack, 3*nsf);
+   tmp2 = PUSH(stack, 3*nsf);
 
    x[0]=tmp;
    x[1]=tmp+nsf;
    x[2]=tmp+2*nsf;
 
+   e[0]=tmp2;
+   e[1]=tmp2+nsf;
+   e[2]=tmp2+2*nsf;
+
    /* Perform closed-loop 1-tap search*/
+   /* FIXME: Should better handle short (<nsf) pitch periods*/
    overlap_cb_search(target, ak, awk1, awk2,
-                     &exc[-end], end-start+1, gain, &pitch, p,
+                     &exc2[-end], end-start+1, gain, &pitch, p,
                      nsf, stack);
    /* Real pitch value */
    pitch=end-pitch;
@@ -370,7 +378,15 @@ float *stack
    
    for (i=0;i<3;i++)
    {
-      residue_zero(&exc[-pitch-1+i],awk1,x[i],nsf,p);
+      int pp=pitch+1-i;
+      for (j=0;j<nsf;j++)
+      {
+         if (j-pp<0)
+            e[i][j]=exc2[j-pp];
+         else
+            e[i][j]=exc2[j-pp-pitch];
+      }
+      residue_zero(e[i],awk1,x[i],nsf,p);
       syn_filt_zero(x[i],ak,x[i],nsf,p);
       syn_filt_zero(x[i],awk2,x[i],nsf,p);
    }
@@ -404,6 +420,11 @@ float *stack
          ptr = gain_cdbk+12*i;
          for (j=0;j<9;j++)
             sum+=C[j]*ptr[j+3];
+         if (0) {
+            float tot=ptr[0]+ptr[1]+ptr[2];
+            if (tot < 1.1)
+               sum *= 1+.15*tot;
+         }
          if (sum>best_sum || i==0)
          {
             best_sum=sum;
@@ -418,10 +439,8 @@ float *stack
 
    }
    
-   /*FIXME: backward or forward? (ie recursive or not?)*/
-   /*for (i=0;i<nsf;i++)*/
-   for (i=nsf-1;i>=0;i--)
-      exc[i]=gain[0]*exc[i-pitch+1]+gain[1]*exc[i-pitch]+gain[2]*exc[i-pitch-1];
+   for (i=0;i<nsf;i++)
+      exc[i]=gain[0]*e[2][i]+gain[1]*e[1][i]+gain[2]*e[0][i];
 #ifdef DEBUG
    printf ("3-tap pitch = %d, gains = [%f %f %f]\n",pitch, gain[0], gain[1], gain[2]);
    {
@@ -434,6 +453,7 @@ float *stack
       printf ("prediction gain = %f\n",tmp1/(tmp2+1));
    }
 #endif
+   return pitch;
 }
 
 
index 31bd1e2..4c74343 100644 (file)
@@ -50,7 +50,7 @@ float *stack
 
 
 /** Finds the best quantized 3-tap pitch predictor by analysis by synthesis */
-void pitch_search_3tap(
+int pitch_search_3tap(
 float target[],                 /* Target vector */
 float ak[],                     /* LPCs for this subframe */
 float awk1[],                   /* Weighted LPCs #1 for this subframe */
@@ -62,7 +62,8 @@ int   end,                      /* Largest pitch value allowed */
 int   p,                        /* Number of LPC coeffs */
 int   nsf,                      /* Number of samples in subframe */
 FrameBits *bits,
-float *stack
+float *stack,
+float *exc2
 );
 
 /** Finds the best quantized 3-tap pitch predictor by analysis by synthesis */
index 081c799..ecc98cc 100644 (file)
@@ -67,17 +67,17 @@ split_cb_params split_cb_wb = {
 };
 
 mpulse_params mpulse_nb = {
-   12,     /*nb_pulse*/
-   4,      /*nb_tracks*/
-   2.2,    /*gain_coef*/
+   15,     /*nb_pulse*/
+   5,      /*nb_tracks*/
+   4,    /*gain_coef*/
    10
 };
 
 
 mpulse_params mpulse_sb = {
-   50,     /*nb_pulse*/
-   10,      /*nb_tracks*/
-   2.5,    /*gain_coef*/
+   25,     /*nb_pulse*/
+   5,      /*nb_tracks*/
+   3.8,    /*gain_coef*/
    10
 };
 
@@ -205,10 +205,10 @@ SpeexMode mp_sb_mode = {
    640,    /*bufSize*/
    17,     /*pitchStart*/
    144,    /*pitchEnd*/
-   0.9,    /*gamma1*/
+   .9,    /*gamma1*/
    0.6,    /*gamma2*/
    .002,   /*lag_factor*/
-   1.0001, /*lpc_floor*/
+   1.00005, /*lpc_floor*/
    0.0,    /*preemph*/
    /*LSP quantization*/
    lsp_quant_nb,
@@ -219,7 +219,7 @@ SpeexMode mp_sb_mode = {
    &ltp_params_nb,
    /*Innovation quantization*/
 #if 1
-   split_cb_search,
+   split_cb_search2,
    split_cb_unquant,
    &split_cb_sb
 #else
index b3dd0e9..33396b9 100644 (file)
@@ -32,9 +32,9 @@ typedef void (*lsp_unquant_func)(float *, int, FrameBits *);
 
 
 /*Long-term predictor quantization*/
-typedef void (*ltp_quant_func)(float *, float *, float *, 
+typedef int (*ltp_quant_func)(float *, float *, float *, 
                                 float *, float *, void *, int, int, 
-                                int, int, FrameBits*, float *);
+                                int, int, FrameBits*, float *, float *);
 
 /*Long-term un-quantize*/
 typedef void (*ltp_unquant_func)(float *, int, int, void *, int, FrameBits*, float*);
index 26e8f4c..986e24e 100644 (file)
@@ -292,7 +292,7 @@ float *stack
          float dist;
          float *base=t+j;
          /*Fill any track until it's full*/
-         if (nb[j%nb_tracks]==pulses_per_track)
+         if (nb[j%nb_tracks]==pulses_per_track || nb[j%nb_tracks] > (i)/nb_tracks)
               continue;
          /*Constrain search in alternating tracks*/
          /*FIXME: Should get rid of this, it's *really* slow*/
index 60dd073..0933001 100644 (file)
@@ -69,6 +69,7 @@ float quant_high_gain2[8] = {
    2.25160,
 };
 
+
 #if 0
 #define QMF_ORDER 32
 static float h0[32] = {
@@ -191,6 +192,7 @@ void sb_encoder_init(SBEncState *st, SpeexMode *mode)
    st->nbSubframes = st->st_low.nbSubframes;
    st->windowSize = mode->windowSize;
    st->lpcSize=8;
+   st->bufSize=st->st_low.bufSize;
 
    st->lag_factor = .002;
    st->lpc_floor = 1.0001;
@@ -213,8 +215,9 @@ void sb_encoder_init(SBEncState *st, SpeexMode *mode)
    st->g1_mem=calloc(QMF_ORDER, sizeof(float));
 
    st->buf=calloc(st->windowSize, sizeof(float));
-   st->excBuf=calloc(2*st->frame_size, sizeof(float));
-   st->exc=st->excBuf+st->frame_size;
+   st->excBuf=calloc(st->bufSize, sizeof(float));
+   st->exc = st->excBuf + st->bufSize - st->windowSize;
+   /*st->exc=st->excBuf+st->frame_size;*/
 
    st->res=calloc(st->frame_size, sizeof(float));
    st->sw=calloc(st->frame_size, sizeof(float));
@@ -291,6 +294,13 @@ void sb_encoder_destroy(SBEncState *st)
    
 }
 
+extern float hexc_table[];
+split_cb_params split_cb_high = {
+   8,               /*subvect_size*/
+   5,               /*nb_subvect*/
+   hexc_table,       /*shape_cb*/
+   8,               /*shape_bits*/
+};
 
 void sb_encode(SBEncState *st, float *in, FrameBits *bits)
 {
@@ -310,11 +320,13 @@ void sb_encode(SBEncState *st, float *in, FrameBits *bits)
    /* High-band buffering / sync with low band */
    for (i=0;i<st->frame_size;i++)
    {
-      st->excBuf[i]=st->exc[i];
+      /*st->excBuf[i]=st->exc[i];*/
       st->high[i]=st->high[st->frame_size+i];
       st->high[st->frame_size+i]=st->x1d[i];
    }
 
+   memmove(st->excBuf, st->excBuf+st->frame_size, (st->bufSize-st->frame_size)*sizeof(float));
+
    /* Start encoding the high-band */
 
    for (i=0;i<st->windowSize;i++)
@@ -353,8 +365,8 @@ void sb_encode(SBEncState *st, float *in, FrameBits *bits)
       printf (" %f", st->lsp[i]);
       printf ("\n");
    for (i=0;i<st->lpcSize;i++)
-   st->qlsp[i]=st->lsp[i];
-   */
+   st->qlsp[i]=st->lsp[i];*/
+   
 
    if (st->first)
    {
@@ -412,6 +424,7 @@ void sb_encode(SBEncState *st, float *in, FrameBits *bits)
       rh=1/(fabs(rh)+.001);
       /* Compute ratio, will help predict the gain */
       filter_ratio=fabs(.001+rh)/(.001+fabs(rl));
+
       
       if (0) {/* 1 for spectral folding excitation, 0 for stochastic */
          float el=0,eh=0,g;
@@ -420,13 +433,23 @@ void sb_encode(SBEncState *st, float *in, FrameBits *bits)
             mem[i]=st->mem_sp[i];
          /* Compute "real excitation" */
          residue_mem(sp, st->interp_qlpc, exc, st->subframeSize, st->lpcSize, st->mem_sp);
-
+         
+#if 0
          /* Compute energy of low-band and high-band excitation */
          for (i=0;i<st->subframeSize;i++)
             eh+=sqr(exc[i]);
          for (i=0;i<st->subframeSize;i++)
             el+=sqr(st->st_low.exc[offset+i]);
-         
+
+         for (i=0;i<st->subframeSize;i++)
+         {
+            float p=(.1+exc[i])*filter_ratio/(1+sqrt(el/st->subframeSize));
+            if (i%8==0)
+               printf ("\nhexc: ");
+            printf ("%f ", p);
+         }
+         printf ("\n");
+
          /* Gain to use if we want to use the low-band excitation for high-band */
          g=eh/(.01+el);
          g=sqrt(g);
@@ -436,11 +459,10 @@ void sb_encode(SBEncState *st, float *in, FrameBits *bits)
             exc[i]=g*st->st_low.exc[offset+i];
          
          /* FIXME: Should encode the gain here */
-
+#endif
          /* Update the input signal using the non-coded memory */
          syn_filt_mem(exc, st->interp_qlpc, sp, st->subframeSize, st->lpcSize, mem);
-    
-      } else {/* Stochastic split-VQ excitation */
+      } else if (0) {/* Stochastic split-VQ excitation */
          int k,N=4;
          float el=0,eh=0,eb=0,g;
          int *index;
@@ -481,10 +503,14 @@ void sb_encode(SBEncState *st, float *in, FrameBits *bits)
          /* Energy of "real excitation" */
          for (i=0;i<st->subframeSize;i++)
             eh+=sqr(exc[i]);
-         
+
          for (i=0;i<st->subframeSize;i++)
             exc[i]=0;
-         
+         /*
+st->st_low.ltp_quant(target, st->interp_qlpc, st->bw_lpc1, st->bw_lpc2,
+                    exc, st->st_low.ltp_params, st->st_low.min_pitch, st->st_low.max_pitch, 
+                    st->lpcSize, st->subframeSize, bits, st->stack, exc);
+         */
          /* For all sub-vectors, find best gain and codeword/shape */
          for (k=0;k<N;k++)
          {
@@ -556,11 +582,70 @@ void sb_encode(SBEncState *st, float *in, FrameBits *bits)
             /* FIXME: Should we use the "adjusted excitation" in the encoder? */
             for (i=0;i<st->subframeSize/N;i++)
               exc[of+i]=gains[k]*stoc[index[k]+i];
+
          }
          POP(st->stack);
          POP(st->stack);
+
+
+         /*Keep the previous memory*/
+         for (i=0;i<st->lpcSize;i++)
+            mem[i]=st->mem_sp[i];
+         /* Final signal synthesis from excitation */
+         syn_filt_mem(exc, st->interp_qlpc, sp, st->subframeSize, st->lpcSize, st->mem_sp);
          
+         /* Compute weighted signal again, from synthesized speech (not sure it's the right thing) */
+         residue_mem(sp, st->bw_lpc1, sw, st->subframeSize, st->lpcSize, mem);
+         syn_filt_mem(sw, st->bw_lpc2, sw, st->subframeSize, st->lpcSize, st->mem_sw);
+      } else {
+         float el=0;
+         float gc;
+
+         for (i=0;i<st->subframeSize;i++)
+            el+=sqr(st->st_low.exc[offset+i]);
+
+         gc = (.01+filter_ratio)/(1+sqrt(el/st->subframeSize));
+
+         /* Reset excitation */
+         for (i=0;i<st->subframeSize;i++)
+            exc[i]=0;
          
+         /* Compute zero response (ringing) of A(z/g1) / ( A(z/g2) * Aq(z) ) */
+         for (i=0;i<st->lpcSize;i++)
+            mem[i]=st->mem_sp[i];
+         syn_filt_mem(exc, st->interp_qlpc, exc, st->subframeSize, st->lpcSize, mem);
+         for (i=0;i<st->lpcSize;i++)
+            mem[i]=st->mem_sp[i];
+         residue_mem(exc, st->bw_lpc1, res, st->subframeSize, st->lpcSize, mem);
+         for (i=0;i<st->lpcSize;i++)
+            mem[i]=st->mem_sw[i];
+         syn_filt_mem(res, st->bw_lpc2, res, st->subframeSize, st->lpcSize, mem);
+         
+         /* Compute weighted signal */
+         for (i=0;i<st->lpcSize;i++)
+            mem[i]=st->mem_sp[i];
+         residue_mem(sp, st->bw_lpc1, sw, st->subframeSize, st->lpcSize, mem);
+         for (i=0;i<st->lpcSize;i++)
+            mem[i]=st->mem_sw[i];
+         syn_filt_mem(sw, st->bw_lpc2, sw, st->subframeSize, st->lpcSize, mem);
+         
+         /* Compute target signal */
+         for (i=0;i<st->subframeSize;i++)
+            target[i]=gc*(sw[i]-res[i]);
+         
+         /* Reset excitation */
+         for (i=0;i<st->subframeSize;i++)
+            exc[i]=0;
+
+         print_vec(target, st->subframeSize, "\ntarget");
+         split_cb_search_nogain(target, st->interp_qlpc, st->bw_lpc1, st->bw_lpc2, 
+                                &split_cb_high, st->lpcSize, st->subframeSize, 
+                                exc, bits, st->stack);
+         print_vec(target, st->subframeSize, "after");
+
+         for (i=0;i<st->subframeSize;i++)
+            exc[i] *= 1/gc;
+#if 1
          /*Keep the previous memory*/
          for (i=0;i<st->lpcSize;i++)
             mem[i]=st->mem_sp[i];
@@ -570,6 +655,7 @@ void sb_encode(SBEncState *st, float *in, FrameBits *bits)
          /* Compute weighted signal again, from synthesized speech (not sure it's the right thing) */
          residue_mem(sp, st->bw_lpc1, sw, st->subframeSize, st->lpcSize, mem);
          syn_filt_mem(sw, st->bw_lpc2, sw, st->subframeSize, st->lpcSize, st->mem_sw);
+#endif
       }
       
       POP(st->stack);
index adf0c03..372a64c 100644 (file)
@@ -33,6 +33,7 @@ typedef struct SBEncState {
    int    nbSubframes;         /* Number of high-band sub-frames*/
    int    windowSize;          /* Length of high-band LPC window*/
    int    lpcSize;             /* Order of high-band LPC analysis */
+   int    bufSize;             /* Buffer size */
    int    first;               /* First frame? */
    float  lag_factor;          /* Lag-windowing control parameter */
    float  lpc_floor;           /* Controls LPC analysis noise floor */
index 4258c36..156cbf3 100644 (file)
@@ -96,6 +96,9 @@ void encoder_init(EncState *st, SpeexMode *mode)
    st->swBuf = calloc(st->bufSize,sizeof(float));
    st->sw = st->swBuf + st->bufSize - st->windowSize;
 
+   st->exc2Buf = calloc(st->bufSize,sizeof(float));
+   st->exc2 = st->exc2Buf + st->bufSize - st->windowSize;
+
    /* Hanning window */
    st->window = malloc(st->windowSize*sizeof(float));
    for (i=0;i<st->windowSize;i++)
@@ -141,6 +144,7 @@ void encoder_destroy(EncState *st)
    free(st->excBuf);
    free(st->swBuf);
    free(st->os_filt);
+   free(st->exc2Buf);
    free(st->stack);
 
    free(st->window);
@@ -179,6 +183,7 @@ void encode(EncState *st, float *in, FrameBits *bits)
       st->inBuf[st->bufSize-st->frameSize+i] = in[i] - st->preemph*in[i-1];
    st->pre_mem = in[st->frameSize-1];
 
+   memmove(st->exc2Buf, st->exc2Buf+st->frameSize, (st->bufSize-st->frameSize)*sizeof(float));
    memmove(st->excBuf, st->excBuf+st->frameSize, (st->bufSize-st->frameSize)*sizeof(float));
    memmove(st->swBuf, st->swBuf+st->frameSize, (st->bufSize-st->frameSize)*sizeof(float));
 
@@ -237,8 +242,9 @@ void encode(EncState *st, float *in, FrameBits *bits)
    {
       float esig, enoise, snr, tmp;
       int   offset;
-      float *sp, *sw, *res, *exc, *target, *mem;
-      
+      float *sp, *sw, *res, *exc, *target, *mem, *exc2;
+      int pitch;
+
       /* Offset relative to start of frame */
       offset = st->subframeSize*sub;
       /* Original signal */
@@ -247,6 +253,9 @@ void encode(EncState *st, float *in, FrameBits *bits)
       exc=st->exc+offset;
       /* Weighted signal */
       sw=st->sw+offset;
+
+      exc2=st->exc2+offset;
+
       /* Filter response */
       res = PUSH(st->stack, st->subframeSize);
       /* Target signal */
@@ -304,6 +313,8 @@ void encode(EncState *st, float *in, FrameBits *bits)
       /* Reset excitation */
       for (i=0;i<st->subframeSize;i++)
          exc[i]=0;
+      for (i=0;i<st->subframeSize;i++)
+         exc2[i]=0;
 
       /* Compute zero response of A(z/g1) / ( A(z/g2) * Aq(z) ) */
       for (i=0;i<st->lpcSize;i++)
@@ -337,9 +348,9 @@ void encode(EncState *st, float *in, FrameBits *bits)
 
       /* Long-term prediction */
 #if 1
-      st->ltp_quant(target, st->interp_qlpc, st->bw_lpc1, st->bw_lpc2,
+      pitch = st->ltp_quant(target, st->interp_qlpc, st->bw_lpc1, st->bw_lpc2,
                     exc, st->ltp_params, st->min_pitch, st->max_pitch, 
-                    st->lpcSize, st->subframeSize, bits, st->stack);
+                    st->lpcSize, st->subframeSize, bits, st->stack, exc2);
 #else
       {
          float gain[3];
@@ -408,6 +419,25 @@ void encode(EncState *st, float *in, FrameBits *bits)
       residue_mem(sp, st->bw_lpc1, sw, st->subframeSize, st->lpcSize, mem);
       syn_filt_mem(sw, st->bw_lpc2, sw, st->subframeSize, st->lpcSize, st->mem_sw);
 
+#if 0
+      /*for (i=0;i<st->subframeSize;i++)
+        exc2[i]=.75*exc[i]+.2*exc[i-pitch]+.05*exc[i-2*pitch];*/
+      {
+         float max_exc=0;
+         for (i=0;i<st->subframeSize;i++)
+            if (fabs(exc[i])>max_exc)
+               max_exc=fabs(exc[i]);
+         max_exc=1/(max_exc+.01);
+         for (i=0;i<st->subframeSize;i++)
+         {
+            float xx=max_exc*exc[i];
+            exc2[i]=exc[i]*(1-exp(-100*xx*xx));
+         }
+      }
+#else
+      for (i=0;i<st->subframeSize;i++)
+         exc2[i]=exc[i];
+#endif
       POP(st->stack);
       POP(st->stack);
       POP(st->stack);
index aa92284..50e66a9 100644 (file)
@@ -52,6 +52,8 @@ typedef struct EncState {
    float *frame;          /* Start of original frame */
    float *excBuf;         /* Excitation buffer */
    float *exc;            /* Start of excitation frame */
+   float *exc2Buf;           /* "Pitch enhanced" excitation */
+   float *exc2;           /* "Pitch enhanced" excitation */
    float *swBuf;          /* Weighted signal buffer */
    float *sw;             /* Start of weighted signal frame */
    float *window;         /* Temporary (Hanning) window */
index 00887b5..37adc9a 100644 (file)
@@ -59,7 +59,7 @@ int main(int argc, char **argv)
 
       frame_bits_rewind(&bits);
       
-      sb_decode(&dec, &bits, input);
+      /*sb_decode(&dec, &bits, input);*/
 
       frame_bits_reset(&bits);
       for (i=0;i<FRAME_SIZE;i++)