[xiph-commits] r11413 - trunk/speex/libspeex

jm at svn.xiph.org jm at svn.xiph.org
Sat May 20 12:29:45 PDT 2006


Author: jm
Date: 2006-05-20 12:29:37 -0700 (Sat, 20 May 2006)
New Revision: 11413

Modified:
   trunk/speex/libspeex/cb_search.c
   trunk/speex/libspeex/cb_search.h
   trunk/speex/libspeex/filters.c
   trunk/speex/libspeex/filters.h
   trunk/speex/libspeex/ltp.c
   trunk/speex/libspeex/ltp.h
   trunk/speex/libspeex/modes.h
   trunk/speex/libspeex/nb_celp.c
   trunk/speex/libspeex/nb_celp.h
   trunk/speex/libspeex/sb_celp.c
   trunk/speex/libspeex/sb_celp.h
Log:
excitation and target are now 16-bit (were 32) in the encoder


Modified: trunk/speex/libspeex/cb_search.c
===================================================================
--- trunk/speex/libspeex/cb_search.c	2006-05-18 22:06:32 UTC (rev 11412)
+++ trunk/speex/libspeex/cb_search.c	2006-05-20 19:29:37 UTC (rev 11413)
@@ -96,7 +96,7 @@
 
 
 static void split_cb_search_shape_sign_N1(
-spx_sig_t target[],			/* target vector */
+spx_word16_t target[],			/* target vector */
 spx_coef_t ak[],			/* LPCs for this subframe */
 spx_coef_t awk1[],			/* Weighted LPCs for this subframe */
 spx_coef_t awk2[],			/* Weighted LPCs for this subframe */
@@ -154,7 +154,7 @@
    
    /* FIXME: make that adaptive? */
    for (i=0;i<nsf;i++)
-      t[i]=EXTRACT16(PSHR32(target[i],8));
+      t[i]=target[i];
 
    compute_weighted_codebook(shape_cb, r, resp, resp2, E, shape_cb_size, subvect_size, stack);
 
@@ -237,14 +237,14 @@
       ALLOC(r2, nsf, spx_sig_t);
       syn_percep_zero(e, ak, awk1, awk2, r2, nsf,p, stack);
       for (j=0;j<nsf;j++)
-         target[j]=SUB32(target[j],r2[j]);
+         target[j]=SUB16(target[j],EXTRACT16(PSHR32(r2[j],8)));
    }
 }
 
 
 
 void split_cb_search_shape_sign(
-spx_sig_t target[],			/* target vector */
+spx_word16_t target[],			/* target vector */
 spx_coef_t ak[],			/* LPCs for this subframe */
 spx_coef_t awk1[],			/* Weighted LPCs for this subframe */
 spx_coef_t awk2[],			/* Weighted LPCs for this subframe */
@@ -349,7 +349,7 @@
    
    /* FIXME: make that adaptive? */
    for (i=0;i<nsf;i++)
-      t[i]=EXTRACT16(PSHR32(target[i],8));
+      t[i]=target[i];
 
    for (j=0;j<N;j++)
       speex_move(&ot[j][0], t, nsf*sizeof(spx_word16_t));
@@ -504,7 +504,7 @@
    {
       syn_percep_zero(e, ak, awk1, awk2, r2, nsf,p, stack);
       for (j=0;j<nsf;j++)
-         target[j]=SUB32(target[j],r2[j]);
+         target[j]=SUB16(target[j],EXTRACT16(PSHR32(r2[j],8)));
    }
 }
 
@@ -567,7 +567,7 @@
 }
 
 void noise_codebook_quant(
-spx_sig_t target[],			/* target vector */
+spx_word16_t target[],			/* target vector */
 spx_coef_t ak[],			/* LPCs for this subframe */
 spx_coef_t awk1[],			/* Weighted LPCs for this subframe */
 spx_coef_t awk2[],			/* Weighted LPCs for this subframe */
@@ -585,13 +585,14 @@
    int i;
    VARDECL(spx_sig_t *tmp);
    ALLOC(tmp, nsf, spx_sig_t);
-   residue_percep_zero(target, ak, awk1, awk2, tmp, nsf, p, stack);
+   for (i=0;i<nsf;i++)
+      tmp[i]=PSHR32(EXTEND32(target),SIG_SHIFT);
+   residue_percep_zero(tmp, ak, awk1, awk2, tmp, nsf, p, stack);
 
    for (i=0;i<nsf;i++)
       exc[i]+=tmp[i];
    for (i=0;i<nsf;i++)
       target[i]=0;
-
 }
 
 

Modified: trunk/speex/libspeex/cb_search.h
===================================================================
--- trunk/speex/libspeex/cb_search.h	2006-05-18 22:06:32 UTC (rev 11412)
+++ trunk/speex/libspeex/cb_search.h	2006-05-20 19:29:37 UTC (rev 11413)
@@ -49,7 +49,7 @@
 
 
 void split_cb_search_shape_sign(
-spx_sig_t target[],             /* target vector */
+spx_word16_t target[],             /* target vector */
 spx_coef_t ak[],                /* LPCs for this subframe */
 spx_coef_t awk1[],              /* Weighted LPCs for this subframe */
 spx_coef_t awk2[],              /* Weighted LPCs for this subframe */
@@ -74,7 +74,7 @@
 
 
 void noise_codebook_quant(
-spx_sig_t target[],             /* target vector */
+spx_word16_t target[],             /* target vector */
 spx_coef_t ak[],                /* LPCs for this subframe */
 spx_coef_t awk1[],              /* Weighted LPCs for this subframe */
 spx_coef_t awk2[],              /* Weighted LPCs for this subframe */

Modified: trunk/speex/libspeex/filters.c
===================================================================
--- trunk/speex/libspeex/filters.c	2006-05-18 22:06:32 UTC (rev 11412)
+++ trunk/speex/libspeex/filters.c	2006-05-20 19:29:37 UTC (rev 11413)
@@ -75,7 +75,7 @@
    }
 }
 
-void signal_div(const spx_sig_t *x, spx_sig_t *y, spx_word32_t scale, int len)
+void signal_div(const spx_word16_t *x, spx_word16_t *y, spx_word32_t scale, int len)
 {
    int i;
    if (scale > SHL32(EXTEND32(SIG_SCALING), 8))
@@ -85,7 +85,7 @@
       scale_1 = EXTRACT16(PDIV32_16(SHL32(EXTEND32(SIG_SCALING),7),scale));
       for (i=0;i<len;i++)
       {
-         y[i] = PSHR32(MULT16_16(scale_1, EXTRACT16(SHR32(x[i],SIG_SHIFT))),7);
+         y[i] = MULT16_16_P15(scale_1, x[i]);
       }
    } else if (scale > SHR32(EXTEND32(SIG_SCALING), 2)) {
       spx_word16_t scale_1;
@@ -93,7 +93,7 @@
       scale_1 = DIV32_16(SHL32(EXTEND32(SIG_SCALING),3),scale);
       for (i=0;i<len;i++)
       {
-         y[i] = MULT16_16(scale_1, EXTRACT16(SHR32(x[i],SIG_SHIFT-2)));
+         y[i] = PSHR32(MULT16_16(scale_1, SHL16(x[i],2)),8);
       }
    } else {
       spx_word16_t scale_1;
@@ -103,7 +103,7 @@
       scale_1 = DIV32_16(SHL32(EXTEND32(SIG_SCALING),3),scale);
       for (i=0;i<len;i++)
       {
-         y[i] = SHL32(MULT16_16(scale_1, EXTRACT16(SHR32(x[i],SIG_SHIFT-2))),2);
+         y[i] = PSHR32(MULT16_16(scale_1, SHL16(x[i],2)),6);
       }
    }
 }

Modified: trunk/speex/libspeex/filters.h
===================================================================
--- trunk/speex/libspeex/filters.h	2006-05-18 22:06:32 UTC (rev 11412)
+++ trunk/speex/libspeex/filters.h	2006-05-20 19:29:37 UTC (rev 11413)
@@ -40,7 +40,7 @@
 spx_word16_t compute_rms(const spx_sig_t *x, int len);
 spx_word16_t compute_rms16(const spx_word16_t *x, int len);
 void signal_mul(const spx_sig_t *x, spx_sig_t *y, spx_word32_t scale, int len);
-void signal_div(const spx_sig_t *x, spx_sig_t *y, spx_word32_t scale, int len);
+void signal_div(const spx_word16_t *x, spx_word16_t *y, spx_word32_t scale, int len);
 
 #ifdef FIXED_POINT
 

Modified: trunk/speex/libspeex/ltp.c
===================================================================
--- trunk/speex/libspeex/ltp.c	2006-05-18 22:06:32 UTC (rev 11412)
+++ trunk/speex/libspeex/ltp.c	2006-05-20 19:29:37 UTC (rev 11413)
@@ -152,18 +152,18 @@
 #endif
 
 #ifndef OVERRIDE_COMPUTE_PITCH_ERROR
-static inline spx_word32_t compute_pitch_error(spx_word32_t *C, spx_word16_t *g, spx_word16_t pitch_control)
+static inline spx_word32_t compute_pitch_error(spx_word16_t *C, spx_word16_t *g, spx_word16_t pitch_control)
 {
    spx_word32_t sum = 0;
-   sum = ADD32(sum,MULT16_32_Q15(MULT16_16_16(g[0],pitch_control),C[0]));
-   sum = ADD32(sum,MULT16_32_Q15(MULT16_16_16(g[1],pitch_control),C[1]));
-   sum = ADD32(sum,MULT16_32_Q15(MULT16_16_16(g[2],pitch_control),C[2]));
-   sum = SUB32(sum,MULT16_32_Q15(MULT16_16_16(g[0],g[1]),C[3]));
-   sum = SUB32(sum,MULT16_32_Q15(MULT16_16_16(g[2],g[1]),C[4]));
-   sum = SUB32(sum,MULT16_32_Q15(MULT16_16_16(g[2],g[0]),C[5]));
-   sum = SUB32(sum,MULT16_32_Q15(MULT16_16_16(g[0],g[0]),C[6]));
-   sum = SUB32(sum,MULT16_32_Q15(MULT16_16_16(g[1],g[1]),C[7]));
-   sum = SUB32(sum,MULT16_32_Q15(MULT16_16_16(g[2],g[2]),C[8]));
+   sum = ADD32(sum,MULT16_16(MULT16_16_16(g[0],pitch_control),C[0]));
+   sum = ADD32(sum,MULT16_16(MULT16_16_16(g[1],pitch_control),C[1]));
+   sum = ADD32(sum,MULT16_16(MULT16_16_16(g[2],pitch_control),C[2]));
+   sum = SUB32(sum,MULT16_16(MULT16_16_16(g[0],g[1]),C[3]));
+   sum = SUB32(sum,MULT16_16(MULT16_16_16(g[2],g[1]),C[4]));
+   sum = SUB32(sum,MULT16_16(MULT16_16_16(g[2],g[0]),C[5]));
+   sum = SUB32(sum,MULT16_16(MULT16_16_16(g[0],g[0]),C[6]));
+   sum = SUB32(sum,MULT16_16(MULT16_16_16(g[1],g[1]),C[7]));
+   sum = SUB32(sum,MULT16_16(MULT16_16_16(g[2],g[2]),C[8]));
    return sum;
 }
 #endif
@@ -282,7 +282,7 @@
 
 /** Finds the best quantized 3-tap pitch predictor by analysis by synthesis */
 static spx_word64_t pitch_gain_search_3tap(
-const spx_sig_t target[],       /* Target vector */
+const spx_word16_t target[],       /* Target vector */
 const spx_coef_t ak[],          /* LPCs for this subframe */
 const spx_coef_t awk1[],        /* Weighted LPCs #1 for this subframe */
 const spx_coef_t awk2[],        /* Weighted LPCs #2 for this subframe */
@@ -293,19 +293,18 @@
 int   nsf,                      /* Number of samples in subframe */
 SpeexBits *bits,
 char *stack,
-const spx_sig_t *exc2,
+const spx_word16_t *exc2,
 const spx_word16_t *r,
-spx_sig_t *new_target,
+spx_word16_t *new_target,
 int  *cdbk_index,
 int cdbk_offset,
 int plc_tuning
 )
 {
    int i,j;
-   VARDECL(spx_sig_t *tmp1);
-   VARDECL(spx_sig_t *tmp2);
-   spx_sig_t *x[3];
-   spx_sig_t *e[3];
+   VARDECL(spx_word16_t *tmp1);
+   VARDECL(spx_word16_t *e);
+   spx_word16_t *x[3];
    spx_word32_t corr[3];
    spx_word32_t A[3][3];
    int   gain_cdbk_size;
@@ -317,125 +316,58 @@
    params = (const ltp_params*) par;
    gain_cdbk_size = 1<<params->gain_bits;
    gain_cdbk = params->gain_cdbk + 3*gain_cdbk_size*cdbk_offset;
-   ALLOC(tmp1, 3*nsf, spx_sig_t);
-   ALLOC(tmp2, 3*nsf, spx_sig_t);
+   ALLOC(tmp1, 3*nsf, spx_word16_t);
+   ALLOC(e, nsf, spx_word16_t);
 
    x[0]=tmp1;
    x[1]=tmp1+nsf;
    x[2]=tmp1+2*nsf;
    
-   e[0]=tmp2;
-   e[1]=tmp2+nsf;
-   e[2]=tmp2+2*nsf;
-   for (i=2;i>=0;i--)
    {
-      int pp=pitch+1-i;
+      int pp=pitch-1;
       for (j=0;j<nsf;j++)
       {
          if (j-pp<0)
-            e[i][j]=exc2[j-pp];
+            e[j]=exc2[j-pp];
          else if (j-pp-pitch<0)
-            e[i][j]=exc2[j-pp-pitch];
+            e[j]=exc2[j-pp-pitch];
          else
-            e[i][j]=0;
+            e[j]=0;
       }
-
-      if (i==2)
-         syn_percep_zero(e[i], ak, awk1, awk2, x[i], nsf, p, stack);
-      else {
-         for (j=0;j<nsf-1;j++)
-            x[i][j+1]=x[i+1][j];
-         x[i][0]=0;
-         for (j=0;j<nsf;j++)
-         {
-            x[i][j]=ADD32(x[i][j],SHL32(MULT16_32_Q15(r[j], e[i][0]),1));
-         }
-      }
+      spx_mem_t mm[p];
+      for (j=0;j<p;j++)
+         mm[j] = 0;
+      iir_mem16(e, ak, e, nsf, p, mm);
+      for (j=0;j<p;j++)
+         mm[j] = 0;
+      filter_mem16(e, awk1, awk2, e, nsf, p, mm);
+      for (j=0;j<nsf;j++)
+         x[2][j] = e[j];
    }
-
-#ifdef FIXED_POINT
+   for (i=1;i>=0;i--)
    {
-      /* If using fixed-point, we need to normalize the signals first */
-      spx_word16_t *y[3];
-      VARDECL(spx_word16_t *ytmp);
-      VARDECL(spx_word16_t *t);
+      spx_word16_t e0=exc2[-pitch-1+i];
+      x[i][0]=MULT16_16_Q14(r[0], e0);
+      for (j=0;j<nsf-1;j++)
+         x[i][j+1]=ADD32(x[i+1][j],MULT16_16_P14(r[j+1], e0));
+   }
 
-      spx_sig_t max_val=1;
-      int sig_shift;
-      
-      ALLOC(ytmp, 3*nsf, spx_word16_t);
-#if 0
-      ALLOC(y[0], nsf, spx_word16_t);
-      ALLOC(y[1], nsf, spx_word16_t);
-      ALLOC(y[2], nsf, spx_word16_t);
-#else
-      y[0] = ytmp;
-      y[1] = ytmp+nsf;
-      y[2] = ytmp+2*nsf;
-#endif
-      ALLOC(t, nsf, spx_word16_t);
-      for (j=0;j<3;j++)
-      {
-         for (i=0;i<nsf;i++)
-         {
-            spx_sig_t tmp = x[j][i];
-            if (tmp<0)
-               tmp = -tmp;
-            if (tmp > max_val)
-               max_val = tmp;
-         }
-      }
-      for (i=0;i<nsf;i++)
-      {
-         spx_sig_t tmp = target[i];
-         if (tmp<0)
-            tmp = -tmp;
-         if (tmp > max_val)
-            max_val = tmp;
-      }
+   for (i=0;i<3;i++)
+      corr[i]=inner_prod(x[i],target,nsf);
+   for (i=0;i<3;i++)
+      for (j=0;j<=i;j++)
+         A[i][j]=A[j][i]=inner_prod(x[i],x[j],nsf);
 
-      sig_shift=0;
-      while (max_val>16384)
-      {
-         sig_shift++;
-         max_val >>= 1;
-      }
-
-      for (j=0;j<3;j++)
-      {
-         for (i=0;i<nsf;i++)
-         {
-            y[j][i] = EXTRACT16(SHR32(x[j][i],sig_shift));
-         }
-      }
-      for (i=0;i<nsf;i++)
-      {
-         t[i] = EXTRACT16(SHR32(target[i],sig_shift));
-      }
-
-      for (i=0;i<3;i++)
-         corr[i]=inner_prod(y[i],t,nsf);
-      
-      for (i=0;i<3;i++)
-         for (j=0;j<=i;j++)
-            A[i][j]=A[j][i]=inner_prod(y[i],y[j],nsf);
-   }
-#else
    {
-      for (i=0;i<3;i++)
-         corr[i]=inner_prod(x[i],target,nsf);
-      
-      for (i=0;i<3;i++)
-         for (j=0;j<=i;j++)
-            A[i][j]=A[j][i]=inner_prod(x[i],x[j],nsf);
-   }
-#endif
-
-   {
       spx_word32_t C[9];
       const signed char *ptr=gain_cdbk;
       int best_cdbk=0;
       spx_word32_t best_sum=0;
+#ifdef FIXED_POINT
+      spx_word16_t C16[9];
+#else
+      spx_word16_t *C16=C;
+#endif      
       C[0]=corr[2];
       C[1]=corr[1];
       C[2]=corr[0];
@@ -459,6 +391,7 @@
       C[3] = SHL32(C[3],1);
       C[4] = SHL32(C[4],1);
       C[5] = SHL32(C[5],1);
+      normalize16(C, C16, 32767, 9);
 #else
       C[0]*=1-.01*plc_tuning;
       C[1]*=1-.01*plc_tuning;
@@ -495,7 +428,7 @@
                pitch_control = 0;
          }
          
-         sum = compute_pitch_error(C, g, pitch_control);
+         sum = compute_pitch_error(C16, g, pitch_control);
          
          if (sum>best_sum || i==0)
          {
@@ -516,29 +449,36 @@
       *cdbk_index=best_cdbk;
    }
 
-#ifdef FIXED_POINT
    for (i=0;i<nsf;i++)
-     exc[i]=SHL32(ADD32(ADD32(MULT16_32_Q15(SHL16(gain[0],7),e[2][i]), MULT16_32_Q15(SHL16(gain[1],7),e[1][i])),
-                        MULT16_32_Q15(SHL16(gain[2],7),e[0][i])), 2);
-   
+      exc[i]=0;
+   for (i=0;i<3;i++)
+   {
+      int j;
+      int tmp1, tmp3;
+      int pp=pitch+1-i;
+      tmp1=nsf;
+      if (tmp1>pp)
+         tmp1=pp;
+      for (j=0;j<tmp1;j++)
+         exc[j]=MAC16_16(exc[j],SHL16(gain[2-i],7),exc2[j-pp]);
+      tmp3=nsf;
+      if (tmp3>pp+pitch)
+         tmp3=pp+pitch;
+      for (j=tmp1;j<tmp3;j++)
+         exc[j]=MAC16_16(exc[j],SHL16(gain[2-i],7),exc2[j-pp-pitch]);
+   }
    err=0;
+#ifdef FIXED_POINT
    for (i=0;i<nsf;i++)
    {
       spx_word16_t perr2;
-      spx_sig_t tmp = SHL32(ADD32(ADD32(MULT16_32_Q15(SHL16(gain[0],7),x[2][i]),MULT16_32_Q15(SHL16(gain[1],7),x[1][i])),
-                                  MULT16_32_Q15(SHL16(gain[2],7),x[0][i])),2);
-      spx_sig_t perr=SUB32(target[i],tmp);
-      new_target[i] = SUB32(target[i], tmp);
-      perr2 = EXTRACT16(PSHR32(perr,15));
-      err = ADD64(err,MULT16_16(perr2,perr2));
-      
+      spx_word32_t tmp = ADD32(ADD32(MULT16_16(gain[0],x[2][i]),MULT16_16(gain[1],x[1][i])),
+                            MULT16_16(gain[2],x[0][i]));
+      new_target[i] = SUB16(target[i], EXTRACT16(PSHR32(tmp,6)));
    }
+   err = inner_prod(new_target, new_target, nsf);
 #else
    for (i=0;i<nsf;i++)
-      exc[i]=gain[0]*e[2][i]+gain[1]*e[1][i]+gain[2]*e[0][i];
-   
-   err=0;
-   for (i=0;i<nsf;i++)
    {
       spx_sig_t tmp = gain[2]*x[0][i]+gain[1]*x[1][i]+gain[0]*x[2][i];
       new_target[i] = target[i] - tmp;
@@ -551,7 +491,7 @@
 
 /** Finds the best quantized 3-tap pitch predictor by analysis by synthesis */
 int pitch_search_3tap(
-spx_sig_t target[],                 /* Target vector */
+spx_word16_t target[],                 /* Target vector */
 spx_word16_t *sw,
 spx_coef_t ak[],                     /* LPCs for this subframe */
 spx_coef_t awk1[],                   /* Weighted LPCs #1 for this subframe */
@@ -565,7 +505,7 @@
 int   nsf,                      /* Number of samples in subframe */
 SpeexBits *bits,
 char *stack,
-spx_sig_t *exc2,
+spx_word16_t *exc2,
 spx_word16_t *r,
 int complexity,
 int cdbk_offset,
@@ -575,8 +515,8 @@
    int i,j;
    int cdbk_index, pitch=0, best_gain_index=0;
    VARDECL(spx_sig_t *best_exc);
-   VARDECL(spx_sig_t *new_target);
-   VARDECL(spx_sig_t *best_target);
+   VARDECL(spx_word16_t *new_target);
+   VARDECL(spx_word16_t *best_target);
    int best_pitch=0;
    spx_word64_t err, best_err=-1;
    int N;
@@ -609,8 +549,8 @@
       nbest[0] = start;
    
    ALLOC(best_exc, nsf, spx_sig_t);
-   ALLOC(new_target, nsf, spx_sig_t);
-   ALLOC(best_target, nsf, spx_sig_t);
+   ALLOC(new_target, nsf, spx_word16_t);
+   ALLOC(best_target, nsf, spx_word16_t);
    
    for (i=0;i<N;i++)
    {
@@ -744,7 +684,7 @@
 
 /** Forced pitch delay and gain */
 int forced_pitch_quant(
-spx_sig_t target[],                 /* Target vector */
+spx_word16_t target[],                 /* Target vector */
 spx_word16_t *sw,
 spx_coef_t ak[],                     /* LPCs for this subframe */
 spx_coef_t awk1[],                   /* Weighted LPCs #1 for this subframe */
@@ -758,7 +698,7 @@
 int   nsf,                      /* Number of samples in subframe */
 SpeexBits *bits,
 char *stack,
-spx_sig_t *exc2,
+spx_word16_t *exc2,
 spx_word16_t *r,
 int complexity,
 int cdbk_offset,
@@ -775,13 +715,17 @@
    if (pitch_coef>.99)
       pitch_coef=.99;
 #endif
-   for (i=0;i<nsf;i++)
+   for (i=0;i<nsf&&i<start;i++)
    {
+      exc[i]=MULT16_16(SHL16(pitch_coef, 7),exc2[i-start]);
+   }
+   for (;i<nsf;i++)
+   {
       exc[i]=MULT16_32_Q15(SHL16(pitch_coef, 9),exc[i-start]);
    }
    syn_percep_zero(exc, ak, awk1, awk2, res, nsf, p, stack);
    for (i=0;i<nsf;i++)
-      target[i]=SATURATE(SUB32(target[i],res[i]),805306368);
+      target[i]=EXTRACT16(SATURATE(SUB32(EXTEND32(target[i]),PSHR32(res[i],SIG_SHIFT-1)),32700));
    return start;
 }
 

Modified: trunk/speex/libspeex/ltp.h
===================================================================
--- trunk/speex/libspeex/ltp.h	2006-05-18 22:06:32 UTC (rev 11412)
+++ trunk/speex/libspeex/ltp.h	2006-05-20 19:29:37 UTC (rev 11413)
@@ -56,7 +56,7 @@
 
 /** Finds the best quantized 3-tap pitch predictor by analysis by synthesis */
 int pitch_search_3tap(
-spx_sig_t target[],                 /* Target vector */
+spx_word16_t target[],                 /* Target vector */
 spx_word16_t *sw,
 spx_coef_t ak[],                     /* LPCs for this subframe */
 spx_coef_t awk1[],                   /* Weighted LPCs #1 for this subframe */
@@ -70,7 +70,7 @@
 int   nsf,                      /* Number of samples in subframe */
 SpeexBits *bits,
 char *stack,
-spx_sig_t *exc2,
+spx_word16_t *exc2,
 spx_word16_t *r,
 int   complexity,
 int   cdbk_offset,
@@ -98,7 +98,7 @@
 
 /** Forced pitch delay and gain */
 int forced_pitch_quant(
-spx_sig_t target[],                 /* Target vector */
+spx_word16_t target[],                 /* Target vector */
 spx_word16_t *sw,
 spx_coef_t ak[],                     /* LPCs for this subframe */
 spx_coef_t awk1[],                   /* Weighted LPCs #1 for this subframe */
@@ -112,7 +112,7 @@
 int   nsf,                      /* Number of samples in subframe */
 SpeexBits *bits,
 char *stack,
-spx_sig_t *exc2,
+spx_word16_t *exc2,
 spx_word16_t *r,
 int complexity,
 int cdbk_offset,

Modified: trunk/speex/libspeex/modes.h
===================================================================
--- trunk/speex/libspeex/modes.h	2006-05-18 22:06:32 UTC (rev 11412)
+++ trunk/speex/libspeex/modes.h	2006-05-20 19:29:37 UTC (rev 11413)
@@ -55,9 +55,9 @@
 
 
 /** Long-term predictor quantization */
-typedef int (*ltp_quant_func)(spx_sig_t *, spx_word16_t *, spx_coef_t *, spx_coef_t *, 
+typedef int (*ltp_quant_func)(spx_word16_t *, spx_word16_t *, spx_coef_t *, spx_coef_t *, 
                               spx_coef_t *, spx_sig_t *, const void *, int, int, spx_word16_t, 
-                              int, int, SpeexBits*, char *, spx_sig_t *, spx_word16_t *, int, int, int);
+                              int, int, SpeexBits*, char *, spx_word16_t *, spx_word16_t *, int, int, int);
 
 /** Long-term un-quantize */
 typedef void (*ltp_unquant_func)(spx_word16_t *, spx_word32_t *, int, int, spx_word16_t, const void *, int, int *,
@@ -65,7 +65,7 @@
 
 
 /** Innovation quantization function */
-typedef void (*innovation_quant_func)(spx_sig_t *, spx_coef_t *, spx_coef_t *, spx_coef_t *, const void *, int, int, 
+typedef void (*innovation_quant_func)(spx_word16_t *, spx_coef_t *, spx_coef_t *, spx_coef_t *, const void *, int, int, 
                                       spx_sig_t *, spx_word16_t *, SpeexBits *, char *, int, int);
 
 /** Innovation unquantization function */

Modified: trunk/speex/libspeex/nb_celp.c
===================================================================
--- trunk/speex/libspeex/nb_celp.c	2006-05-18 22:06:32 UTC (rev 11412)
+++ trunk/speex/libspeex/nb_celp.c	2006-05-20 19:29:37 UTC (rev 11413)
@@ -158,8 +158,8 @@
    /* Allocating input buffer */
    st->winBuf = speex_alloc((st->windowSize-st->frameSize)*sizeof(spx_word16_t));
    /* Allocating excitation buffer */
-   st->excBuf = speex_alloc((mode->frameSize+mode->pitchEnd+1)*sizeof(spx_sig_t));
-   st->exc = st->excBuf + mode->pitchEnd + 1;
+   st->excBuf = speex_alloc((mode->frameSize+mode->pitchEnd+2)*sizeof(spx_word16_t));
+   st->exc = st->excBuf + mode->pitchEnd + 2;
    st->swBuf = speex_alloc((mode->frameSize+mode->pitchEnd+2)*sizeof(spx_word16_t));
    st->sw = st->swBuf + mode->pitchEnd + 2;
 
@@ -278,8 +278,9 @@
    spx_word16_t ol_pitch_coef;
    spx_word32_t ol_gain;
    VARDECL(spx_word16_t *ringing);
-   VARDECL(spx_sig_t *target);
+   VARDECL(spx_word16_t *target);
    VARDECL(spx_sig_t *innov);
+   VARDECL(spx_word32_t *exc32);
    VARDECL(spx_mem_t *mem);
    char *stack;
    VARDECL(spx_word16_t *syn_resp);
@@ -289,13 +290,12 @@
    int ol_pitch_id=0;
 #endif
    spx_word16_t *in = vin;
-   spx_word16_t *exc16_alias;
 
    st=(EncState *)state;
    stack=st->stack;
 
    /* Move signals 1 frame towards the past */
-   speex_move(st->excBuf, st->excBuf+st->frameSize, (st->max_pitch+1)*sizeof(spx_sig_t));
+   speex_move(st->excBuf, st->excBuf+st->frameSize, (st->max_pitch+2)*sizeof(spx_word16_t));
    speex_move(st->swBuf, st->swBuf+st->frameSize, (st->max_pitch+2)*sizeof(spx_word16_t));
 
    {
@@ -410,13 +410,11 @@
       }
       
       /*Compute "real" excitation*/
-      /* FIXME: Are we breaking aliasing rules here? */
-      exc16_alias = (spx_word16_t*)st->exc;
       for (i=0;i<st->windowSize-st->frameSize;i++)
-         exc16_alias[i] = st->winBuf[i];
+         st->exc[i] = st->winBuf[i];
       for (;i<st->frameSize;i++)
-         exc16_alias[i] = in[i-st->windowSize+st->frameSize];
-      fir_mem16(exc16_alias, st->interp_lpc, exc16_alias, st->frameSize, st->lpcSize, st->mem_exc);
+         st->exc[i] = in[i-st->windowSize+st->frameSize];
+      fir_mem16(st->exc, st->interp_lpc, st->exc, st->frameSize, st->lpcSize, st->mem_exc);
 
       /* Compute open-loop excitation gain */
 #ifdef EPIC_48K
@@ -424,8 +422,8 @@
       {
          float ol1=0,ol2=0;
          float ol_gain2;
-         ol1 = compute_rms(st->exc, st->frameSize>>1);
-         ol2 = compute_rms(st->exc+(st->frameSize>>1), st->frameSize>>1);
+         ol1 = compute_rms16(st->exc, st->frameSize>>1);
+         ol2 = compute_rms16(st->exc+(st->frameSize>>1), st->frameSize>>1);
          ol1 *= ol1*(st->frameSize>>1);
          ol2 *= ol2*(st->frameSize>>1);
 
@@ -439,7 +437,7 @@
       } else
 #endif
       {
-         spx_word16_t g = compute_rms16(exc16_alias, st->frameSize);
+         spx_word16_t g = compute_rms16(st->exc, st->frameSize);
          if (ol_pitch>0)
             ol_gain = MULT16_16(g, MULT16_16_Q14(QCONST16(1.1,14),
                                 spx_sqrt(QCONST32(1.,28)-MULT16_32_Q15(QCONST16(.8,15),SHL32(MULT16_16(ol_pitch_coef,ol_pitch_coef),16)))));
@@ -698,8 +696,9 @@
    }
 
    /* Target signal */
-   ALLOC(target, st->subframeSize, spx_sig_t);
+   ALLOC(target, st->subframeSize, spx_word16_t);
    ALLOC(innov, st->subframeSize, spx_sig_t);
+   ALLOC(exc32, st->subframeSize, spx_word32_t);
    ALLOC(ringing, st->subframeSize, spx_word16_t);
    ALLOC(syn_resp, st->subframeSize, spx_word16_t);
    ALLOC(real_exc, st->subframeSize, spx_word16_t);
@@ -710,7 +709,7 @@
    {
       int   offset;
       spx_word16_t *sw;
-      spx_sig_t *exc;
+      spx_word16_t *exc;
       spx_sig_t *innov_save = NULL;
       int pitch;
       int response_bound = st->subframeSize;
@@ -831,7 +830,7 @@
       
       /* Compute target signal */
       for (i=0;i<st->subframeSize;i++)
-         target[i]=SHL32(EXTEND32(SUB16(sw[i],PSHR32(ringing[i],1))),SIG_SHIFT);
+         target[i]=SUB16(sw[i],PSHR32(ringing[i],1));
 
       /* Reset excitation */
       for (i=0;i<st->subframeSize;i++)
@@ -871,7 +870,7 @@
          if (st->lbr_48k)
          {
             pitch = SUBMODE(ltp_quant)(target, sw, st->interp_qlpc, st->bw_lpc1, st->bw_lpc2,
-                                       exc, SUBMODE(ltp_params), pit_min, pit_max, ol_pitch_coef,
+                                       exc32, SUBMODE(ltp_params), pit_min, pit_max, ol_pitch_coef,
                                        st->lpcSize, st->subframeSize, bits, stack, 
                                        exc, syn_resp, st->complexity, ol_pitch_id, st->plc_tuning);
          } else {
@@ -879,7 +878,7 @@
 
          /* Perform pitch search */
          pitch = SUBMODE(ltp_quant)(target, sw, st->interp_qlpc, st->bw_lpc1, st->bw_lpc2,
-                                    exc, SUBMODE(ltp_params), pit_min, pit_max, ol_pitch_coef,
+                                    exc32, SUBMODE(ltp_params), pit_min, pit_max, ol_pitch_coef,
                                     st->lpcSize, st->subframeSize, bits, stack, 
                                     exc, syn_resp, st->complexity, 0, st->plc_tuning);
 #ifdef EPIC_48K
@@ -900,7 +899,7 @@
             innov[i]=0;
          
          for (i=0;i<st->subframeSize;i++)
-            real_exc[i] = SUB16(real_exc[i], EXTRACT16(SHR32(exc[i],SIG_SHIFT)));
+            real_exc[i] = SUB16(real_exc[i], PSHR32(exc32[i],SIG_SHIFT-1));
 
          ener = SHL32(EXTEND32(compute_rms16(real_exc, st->subframeSize)),SIG_SHIFT);
          
@@ -951,7 +950,7 @@
             signal_mul(innov, innov, ener, st->subframeSize);
 
             for (i=0;i<st->subframeSize;i++)
-               exc[i] = ADD32(exc[i],innov[i]);
+               exc[i] = EXTRACT16(PSHR32(ADD32(SHL32(exc32[i],1),innov[i]),SIG_SHIFT));
          } else {
             speex_error("No fixed codebook");
          }
@@ -969,13 +968,13 @@
             for (i=0;i<st->subframeSize;i++)
                innov2[i]=0;
             for (i=0;i<st->subframeSize;i++)
-               target[i]=MULT16_32_Q13(QCONST16(2.2,13), target[i]);
+               target[i]=MULT16_16_P13(QCONST16(2.2,13), target[i]);
             SUBMODE(innovation_quant)(target, st->interp_qlpc, st->bw_lpc1, st->bw_lpc2, 
                                       SUBMODE(innovation_params), st->lpcSize, st->subframeSize, 
                                       innov2, syn_resp, bits, stack, st->complexity, 0);
             signal_mul(innov2, innov2, MULT16_32_Q15(QCONST16(0.454545,15),ener), st->subframeSize);
             for (i=0;i<st->subframeSize;i++)
-               exc[i] = ADD32(exc[i],innov2[i]);
+               exc[i] = ADD32(exc[i],PSHR32(innov2[i],SIG_SHIFT));
             if (innov_save)
             {
                for (i=0;i<st->subframeSize;i++)
@@ -987,7 +986,7 @@
       }
 
       for (i=0;i<st->subframeSize;i++)
-         sw[i] = PSHR32(exc[i], SIG_SHIFT);
+         sw[i] = exc[i];
       /* Final signal synthesis from excitation */
       iir_mem16(sw, st->interp_qlpc, sw, st->subframeSize, st->lpcSize, st->mem_sp);
 
@@ -1668,7 +1667,7 @@
             SUBMODE(innovation_unquant)(innov2, SUBMODE(innovation_params), st->subframeSize, bits, stack);
             signal_mul(innov2, innov2, MULT16_32_Q15(QCONST16(0.454545,15),ener), st->subframeSize);
             for (i=0;i<st->subframeSize;i++)
-               exc[i] = ADD32(exc[i],PSHR32(innov2[i],SIG_SHIFT));
+               exc[i] = ADD16(exc[i],PSHR32(innov2[i],SIG_SHIFT));
             if (innov_save)
             {
                for (i=0;i<st->subframeSize;i++)
@@ -1962,7 +1961,7 @@
          int i;
          spx_word16_t *e = (spx_word16_t*)ptr;
          for (i=0;i<st->frameSize;i++)
-            e[i]=PSHR32(st->exc[i],SIG_SHIFT);
+            e[i]=st->exc[i];
       }
       break;
    case SPEEX_GET_RELATIVE_QUALITY:

Modified: trunk/speex/libspeex/nb_celp.h
===================================================================
--- trunk/speex/libspeex/nb_celp.h	2006-05-18 22:06:32 UTC (rev 11412)
+++ trunk/speex/libspeex/nb_celp.h	2006-05-20 19:29:37 UTC (rev 11413)
@@ -81,8 +81,8 @@
    spx_word16_t  lpc_floor;      /**< Noise floor multiplier for A[0] in LPC analysis*/
    char  *stack;          /**< Pseudo-stack allocation for temporary memory */
    spx_word16_t *winBuf;          /**< Input buffer (original signal) */
-   spx_sig_t *excBuf;         /**< Excitation buffer */
-   spx_sig_t *exc;            /**< Start of excitation frame */
+   spx_word16_t *excBuf;         /**< Excitation buffer */
+   spx_word16_t *exc;            /**< Start of excitation frame */
    spx_word16_t *swBuf;          /**< Weighted signal buffer */
    spx_word16_t *sw;             /**< Start of weighted signal frame */
    const spx_word16_t *window;         /**< Temporary (Hanning) window */

Modified: trunk/speex/libspeex/sb_celp.c
===================================================================
--- trunk/speex/libspeex/sb_celp.c	2006-05-18 22:06:32 UTC (rev 11412)
+++ trunk/speex/libspeex/sb_celp.c	2006-05-20 19:29:37 UTC (rev 11413)
@@ -279,7 +279,6 @@
 
    st->res=speex_alloc((st->frame_size)*sizeof(spx_sig_t));
    st->sw=speex_alloc((st->frame_size)*sizeof(spx_sig_t));
-   st->target=speex_alloc((st->frame_size)*sizeof(spx_sig_t));
    st->window= lpc_window;
 
    st->lagWindow = speex_alloc((st->lpcSize+1)*sizeof(spx_word16_t));
@@ -345,7 +344,6 @@
    speex_free(st->excBuf);
    speex_free(st->res);
    speex_free(st->sw);
-   speex_free(st->target);
    speex_free(st->lagWindow);
 
    speex_free(st->autocorr);
@@ -378,6 +376,7 @@
    char *stack;
    VARDECL(spx_mem_t *mem);
    VARDECL(spx_sig_t *innov);
+   VARDECL(spx_word16_t *target);
    VARDECL(spx_word16_t *syn_resp);
    VARDECL(spx_word32_t *low_pi_gain);
    VARDECL(spx_word16_t *low_exc);
@@ -592,10 +591,11 @@
    ALLOC(mem, st->lpcSize, spx_mem_t);
    ALLOC(syn_resp, st->subframeSize, spx_word16_t);
    ALLOC(innov, st->subframeSize, spx_sig_t);
+   ALLOC(target, st->subframeSize, spx_word16_t);
 
    for (sub=0;sub<st->nbSubframes;sub++)
    {
-      spx_sig_t *exc, *sp, *res, *target, *sw, *innov_save=NULL;
+      spx_sig_t *exc, *sp, *res, *sw, *innov_save=NULL;
       spx_word16_t filter_ratio;
       int offset;
       spx_word32_t rl, rh;
@@ -605,7 +605,6 @@
       sp=st->high+offset;
       exc=st->exc+offset;
       res=st->res+offset;
-      target=st->target+offset;
       sw=st->sw+offset;
       /* Pointer for saving innovation */
       if (st->innov_save)
@@ -749,7 +748,7 @@
 
          /* Compute target signal */
          for (i=0;i<st->subframeSize;i++)
-            target[i]=sw[i]-res[i];
+            target[i]=PSHR32(sw[i]-res[i],SIG_SHIFT);
 
          for (i=0;i<st->subframeSize;i++)
            exc[i]=0;

Modified: trunk/speex/libspeex/sb_celp.h
===================================================================
--- trunk/speex/libspeex/sb_celp.h	2006-05-18 22:06:32 UTC (rev 11412)
+++ trunk/speex/libspeex/sb_celp.h	2006-05-20 19:29:37 UTC (rev 11413)
@@ -68,7 +68,6 @@
    spx_sig_t *exc;                 /**< High-band excitation (for QMF only)*/
    spx_sig_t *res;                 /**< Zero-input response (ringing) */
    spx_sig_t *sw;                  /**< Perceptually weighted signal */
-   spx_sig_t *target;              /**< Weighted target signal (analysis by synthesis) */
    const spx_word16_t *window;              /**< LPC analysis window */
    spx_word16_t *lagWindow;           /**< Auto-correlation window */
    spx_word16_t *autocorr;            /**< Auto-correlation (for LPC analysis) */



More information about the commits mailing list