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

jm at svn.xiph.org jm at svn.xiph.org
Fri Apr 7 04:56:41 PDT 2006


Author: jm
Date: 2006-04-07 04:56:35 -0700 (Fri, 07 Apr 2006)
New Revision: 11102

Modified:
   trunk/speex/libspeex/filters.c
   trunk/speex/libspeex/filters.h
   trunk/speex/libspeex/nb_celp.c
   trunk/speex/libspeex/nb_celp.h
Log:
removed the decoder output buffer -- saving 640 bytes. Synthesis now done with
16-bit precision.


Modified: trunk/speex/libspeex/filters.c
===================================================================
--- trunk/speex/libspeex/filters.c	2006-04-07 08:29:03 UTC (rev 11101)
+++ trunk/speex/libspeex/filters.c	2006-04-07 11:56:35 UTC (rev 11102)
@@ -252,6 +252,26 @@
 #endif
 #endif
 
+void filter_mem16(const spx_word16_t *x, const spx_coef_t *num, const spx_coef_t *den, spx_word16_t *y, int N, int ord, spx_mem_t *mem)
+{
+   int i,j;
+   spx_word16_t xi,yi,nyi;
+
+   for (i=0;i<N;i++)
+   {
+      xi= x[i];
+      yi = EXTRACT16(SATURATE(ADD32(EXTEND32(x[i]),PSHR32(mem[0],LPC_SHIFT)),32767));
+      nyi = NEG16(yi);
+      for (j=0;j<ord-1;j++)
+      {
+         mem[j] = MAC16_16(MAC16_16(mem[j+1], num[j],xi), den[j],nyi);
+      }
+      mem[ord-1] = ADD32(MULT16_16(num[ord-1],xi), MULT16_16(den[ord-1],nyi));
+      y[i] = yi;
+   }
+}
+
+
 #ifndef OVERRIDE_IIR_MEM2
 #ifdef PRECISION16
 void iir_mem2(const spx_sig_t *x, const spx_coef_t *den, spx_sig_t *y, int N, int ord, spx_mem_t *mem)
@@ -293,6 +313,26 @@
 #endif
 #endif
 
+
+void iir_mem16(const spx_word16_t *x, const spx_coef_t *den, spx_word16_t *y, int N, int ord, spx_mem_t *mem)
+{
+   int i,j;
+   spx_word16_t yi,nyi;
+
+   for (i=0;i<N;i++)
+   {
+      yi = EXTRACT16(SATURATE(ADD32(EXTEND32(x[i]),PSHR32(mem[0],LPC_SHIFT)),32767));
+      nyi = NEG16(yi);
+      for (j=0;j<ord-1;j++)
+      {
+         mem[j] = MAC16_16(mem[j+1],den[j],nyi);
+      }
+      mem[ord-1] = MULT16_16(den[ord-1],nyi);
+      y[i] = yi;
+   }
+}
+
+
 #ifndef OVERRIDE_FIR_MEM2
 #ifdef PRECISION16
 void fir_mem2(const spx_sig_t *x, const spx_coef_t *num, spx_sig_t *y, int N, int ord, spx_mem_t *mem)
@@ -432,8 +472,8 @@
          y1[k]=ADD32(y1[k],MULT16_16(a[j],ADD16(x[i+j],x2[i-j])));
          y2[k]=ADD32(y2[k],MULT16_16(a[j],SUB16(x[i+j],x2[i-j])));
       }
-      y1[k] = SHR(y1[k],1);
-      y2[k] = SHR(y2[k],1);
+      y1[k] = SHR32(y1[k],1);
+      y2[k] = SHR32(y2[k],1);
    }
    for (i=0;i<M-1;i++)
      mem[i]=SATURATE(PSHR(xx[N-i-1],1),16383);
@@ -683,7 +723,7 @@
 
 void comb_filter(
 spx_sig_t *exc,          /*decoded excitation*/
-spx_sig_t *new_exc,      /*enhanced excitation*/
+spx_word16_t *_new_exc,      /*enhanced excitation*/
 spx_coef_t *ak,           /*LPC filter coefs*/
 int p,               /*LPC order*/
 int nsf,             /*sub-frame size*/
@@ -698,7 +738,9 @@
    spx_word16_t gain;
    spx_word16_t step;
    spx_word16_t fact;
-
+   /* FIXME: This is a temporary kludge */
+   spx_sig_t new_exc[40];
+   
    /*Compute excitation amplitude prior to enhancement*/
    exc_energy = compute_rms(exc, nsf);
    /*for (i=0;i<nsf;i++)
@@ -781,4 +823,6 @@
       new_exc[i] *= mem->smooth_gain;
    }
 #endif
+   for (i=0;i<nsf;i++)
+      _new_exc[i] = EXTRACT16(PSHR32(new_exc[i],SIG_SHIFT));
 }

Modified: trunk/speex/libspeex/filters.h
===================================================================
--- trunk/speex/libspeex/filters.h	2006-04-07 08:29:03 UTC (rev 11101)
+++ trunk/speex/libspeex/filters.h	2006-04-07 11:56:35 UTC (rev 11102)
@@ -63,6 +63,9 @@
 void fir_mem2(const spx_sig_t *x, const spx_coef_t *num, spx_sig_t *y, int N, int ord, spx_mem_t *mem);
 void iir_mem2(const spx_sig_t *x, const spx_coef_t *den, spx_sig_t *y, int N, int ord, spx_mem_t *mem);
 
+void filter_mem16(const spx_word16_t *x, const spx_coef_t *num, const spx_coef_t *den, spx_word16_t *y, int N, int ord, spx_mem_t *mem);
+void iir_mem16(const spx_word16_t *x, const spx_coef_t *den, spx_word16_t *y, int N, int ord, spx_mem_t *mem);
+
 /* Apply bandwidth expansion on LPC coef */
 void bw_lpc(spx_word16_t , const spx_coef_t *lpc_in, spx_coef_t *lpc_out, int order);
 
@@ -92,7 +95,7 @@
 
 void comb_filter(
 spx_sig_t *exc,          /*decoded excitation*/
-spx_sig_t *new_exc,      /*enhanced excitation*/
+spx_word16_t *new_exc,      /*enhanced excitation*/
 spx_coef_t *ak,           /*LPC filter coefs*/
 int p,               /*LPC order*/
 int nsf,             /*sub-frame size*/

Modified: trunk/speex/libspeex/nb_celp.c
===================================================================
--- trunk/speex/libspeex/nb_celp.c	2006-04-07 08:29:03 UTC (rev 11101)
+++ trunk/speex/libspeex/nb_celp.c	2006-04-07 11:56:35 UTC (rev 11102)
@@ -264,6 +264,7 @@
    speex_free (st->mem_sw);
    speex_free (st->mem_sw_whole);
    speex_free (st->mem_exc);
+   speex_free (st->mem_exc2);
    speex_free (st->pi_gain);
    speex_free (st->pitch);
 
@@ -1063,12 +1064,8 @@
    st->lpc_enh_enabled=0;
 
 
-   st->inBuf = speex_alloc((st->frameSize)*sizeof(spx_sig_t));
-   st->frame = st->inBuf;
    st->excBuf = speex_alloc((st->frameSize + PITCH_PERIODS*st->max_pitch + 1 + 50)*sizeof(spx_sig_t));
    st->exc = st->excBuf + PITCH_PERIODS*st->max_pitch + 1;
-   for (i=0;i<st->frameSize;i++)
-      st->inBuf[i]=0;
    for (i=0;i<st->frameSize + st->max_pitch + 1;i++)
       st->excBuf[i]=0;
    st->innov = speex_alloc((st->frameSize)*sizeof(spx_sig_t));
@@ -1114,7 +1111,6 @@
    speex_free_scratch(st->stack);
 #endif
 
-   speex_free (st->inBuf);
    speex_free (st->excBuf);
    speex_free (st->innov);
    speex_free (st->interp_qlpc);
@@ -1182,11 +1178,12 @@
    for (sub=0;sub<st->nbSubframes;sub++)
    {
       int offset;
-      spx_sig_t *sp, *exc;
+      spx_word16_t *sp;
+      spx_sig_t *exc;
       /* Offset relative to start of frame */
       offset = st->subframeSize*sub;
       /* Original signal */
-      sp=st->frame+offset;
+      sp=out+offset;
       /* Excitation */
       exc=st->exc+offset;
       /* Excitation after post-filter*/
@@ -1226,32 +1223,22 @@
       }
       
       for (i=0;i<st->subframeSize;i++)
-         sp[i]=exc[i];
+         sp[i]=PSHR32(exc[i],SIG_SHIFT);
       
       /* Signal synthesis */
       if (st->lpc_enh_enabled)
       {
-         filter_mem2(sp, awk2, awk1, sp, st->subframeSize, st->lpcSize, 
+         filter_mem16(sp, awk2, awk1, sp, st->subframeSize, st->lpcSize, 
                      st->mem_sp+st->lpcSize);
-         filter_mem2(sp, awk3, st->interp_qlpc, sp, st->subframeSize, st->lpcSize, 
+         filter_mem16(sp, awk3, st->interp_qlpc, sp, st->subframeSize, st->lpcSize, 
                      st->mem_sp);
       } else {
          for (i=0;i<st->lpcSize;i++)
             st->mem_sp[st->lpcSize+i] = 0;
-         iir_mem2(sp, st->interp_qlpc, sp, st->subframeSize, st->lpcSize, 
+         iir_mem16(sp, st->interp_qlpc, sp, st->subframeSize, st->lpcSize, 
                      st->mem_sp);
       }      
    }
-
-   for (i=0;i<st->frameSize;i++)
-   {
-      spx_word32_t sig = PSHR32(st->frame[i],SIG_SHIFT);
-      if (sig>32767)
-         sig = 32767;
-      if (sig<-32767)
-         sig = -32767;
-     out[i]=sig;
-   }
    
    st->first = 0;
    st->count_lost++;
@@ -1406,19 +1393,11 @@
 
       st->first=1;
 
+      for (i=0;i<st->frameSize;i++)
+         out[i] = st->exc[i];
       /* Final signal synthesis from excitation */
-      iir_mem2(st->exc, lpc, st->frame, st->frameSize, st->lpcSize, st->mem_sp);
+      iir_mem16(out, lpc, out, st->frameSize, st->lpcSize, st->mem_sp);
 
-      for (i=0;i<st->frameSize;i++)
-      {
-         spx_word32_t sig = PSHR32(st->frame[i],SIG_SHIFT);
-         if (sig>32767)
-            sig = 32767;
-         if (sig<-32767)
-            sig = -32767;
-         out[i]=sig;
-      }
-
       st->count_lost=0;
       return 0;
    }
@@ -1516,7 +1495,8 @@
    for (sub=0;sub<st->nbSubframes;sub++)
    {
       int offset;
-      spx_sig_t *exc, *sp;
+      spx_sig_t *exc;
+      spx_word16_t *sp;
       spx_word16_t tmp;
 
 #ifdef EPIC_48K
@@ -1534,7 +1514,7 @@
       /* Excitation */
       exc=st->exc+offset;
       /* Original signal */
-      sp=st->frame+offset;
+      sp=out+offset;
 
 
       /* Reset excitation */
@@ -1727,7 +1707,7 @@
       }
 
       for (i=0;i<st->subframeSize;i++)
-         sp[i]=exc[i];
+         sp[i]=PSHR32(exc[i],SIG_SHIFT);
 
       /* Signal synthesis */
       if (st->lpc_enh_enabled && SUBMODE(comb_gain)>0)
@@ -1745,13 +1725,14 @@
    for (sub=0;sub<st->nbSubframes;sub++)
    {
       int offset;
-      spx_sig_t *sp, *exc;
+      spx_word16_t *sp;
+      spx_sig_t *exc;
       spx_word16_t tmp;
 
       /* Offset relative to start of frame */
       offset = st->subframeSize*sub;
       /* Original signal */
-      sp=st->frame+offset;
+      sp=out+offset;
       /* Excitation */
       exc=st->exc+offset;
 
@@ -1791,15 +1772,15 @@
       if (st->lpc_enh_enabled)
       {
          /* Use enhanced LPC filter */
-         filter_mem2(sp, awk2, awk1, sp, st->subframeSize, st->lpcSize, 
+         filter_mem16(sp, awk2, awk1, sp, st->subframeSize, st->lpcSize, 
                      st->mem_sp+st->lpcSize);
-         filter_mem2(sp, awk3, st->interp_qlpc, sp, st->subframeSize, st->lpcSize, 
+         filter_mem16(sp, awk3, st->interp_qlpc, sp, st->subframeSize, st->lpcSize, 
                      st->mem_sp);
       } else {
          /* Use regular filter */
          for (i=0;i<st->lpcSize;i++)
             st->mem_sp[st->lpcSize+i] = 0;
-         iir_mem2(sp, st->interp_qlpc, sp, st->subframeSize, st->lpcSize, 
+         iir_mem16(sp, st->interp_qlpc, sp, st->subframeSize, st->lpcSize, 
                   st->mem_sp);
       }
       
@@ -1807,16 +1788,6 @@
          st->interp_qlpc[i] = ak[i];
 
    }
-   /*Copy output signal*/   
-   for (i=0;i<st->frameSize;i++)
-   {
-      spx_word32_t sig = PSHR32(st->frame[i],SIG_SHIFT);
-      if (sig>32767)
-         sig = 32767;
-      if (sig<-32767)
-         sig = -32767;
-     out[i]=sig;
-   }
 
    /*for (i=0;i<st->frameSize;i++)
      printf ("%d\n", (int)st->frame[i]);*/
@@ -2080,8 +2051,6 @@
             st->mem_sp[i]=0;
          for (i=0;i<st->frameSize + st->max_pitch + 1;i++)
             st->excBuf[i]=0;
-         for (i=0;i<st->frameSize;i++)
-            st->inBuf[i] = 0;
       }
       break;
    case SPEEX_SET_SUBMODE_ENCODING:

Modified: trunk/speex/libspeex/nb_celp.h
===================================================================
--- trunk/speex/libspeex/nb_celp.h	2006-04-07 08:29:03 UTC (rev 11101)
+++ trunk/speex/libspeex/nb_celp.h	2006-04-07 11:56:35 UTC (rev 11102)
@@ -147,8 +147,6 @@
    spx_word16_t  last_ol_gain;   /**< Open-loop gain for previous frame */
 
    char  *stack;          /**< Pseudo-stack allocation for temporary memory */
-   spx_sig_t *inBuf;          /**< Input buffer (original signal) */
-   spx_sig_t *frame;          /**< Start of original frame */
    spx_sig_t *excBuf;         /**< Excitation buffer */
    spx_sig_t *exc;            /**< Start of excitation frame */
    spx_sig_t *innov;          /**< Innovation for the frame */



More information about the commits mailing list