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

jm at svn.xiph.org jm at svn.xiph.org
Sat Apr 8 08:12:50 PDT 2006


Author: jm
Date: 2006-04-08 08:12:45 -0700 (Sat, 08 Apr 2006)
New Revision: 11109

Modified:
   trunk/speex/libspeex/filters.c
   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
Log:
weighted signal now in 16-bit precision, saving 500 bytes in the encoder state
and the same in scratch space.


Modified: trunk/speex/libspeex/filters.c
===================================================================
--- trunk/speex/libspeex/filters.c	2006-04-08 14:11:43 UTC (rev 11108)
+++ trunk/speex/libspeex/filters.c	2006-04-08 15:12:45 UTC (rev 11109)
@@ -256,7 +256,10 @@
 {
    int i,j;
    spx_word16_t xi,yi,nyi;
-
+#ifndef PRECISION16
+   for (i=0;i<ord;i++)
+      mem[i] = SHL32(mem[i],1);   
+#endif
    for (i=0;i<N;i++)
    {
       xi= x[i];
@@ -269,6 +272,10 @@
       mem[ord-1] = ADD32(MULT16_16(num[ord-1],xi), MULT16_16(den[ord-1],nyi));
       y[i] = yi;
    }
+#ifndef PRECISION16
+   for (i=0;i<ord;i++)
+      mem[i] = SHR32(mem[i],1);   
+#endif
 }
 
 

Modified: trunk/speex/libspeex/ltp.c
===================================================================
--- trunk/speex/libspeex/ltp.c	2006-04-08 14:11:43 UTC (rev 11108)
+++ trunk/speex/libspeex/ltp.c	2006-04-08 15:12:45 UTC (rev 11109)
@@ -168,7 +168,7 @@
 }
 #endif
 
-void open_loop_nbest_pitch(spx_sig_t *sw, int start, int end, int len, int *pitch, spx_word16_t *gain, int N, char *stack)
+void open_loop_nbest_pitch(spx_word16_t *sw, int start, int end, int len, int *pitch, spx_word16_t *gain, int N, char *stack)
 {
    int i,j,k;
    VARDECL(spx_word32_t *best_score);
@@ -177,8 +177,6 @@
    VARDECL(spx_word32_t *corr);
    VARDECL(spx_word32_t *energy);
    VARDECL(spx_word32_t *score);
-   VARDECL(spx_word16_t *swn2);
-   spx_word16_t *swn;
 
    ALLOC(best_score, N, spx_word32_t);
    ALLOC(best_ener, N, spx_word32_t);
@@ -186,14 +184,6 @@
    ALLOC(energy, end-start+2, spx_word32_t);
    ALLOC(score, end-start+1, spx_word32_t);
 
-#ifdef FIXED_POINT
-   ALLOC(swn2, end+len, spx_word16_t);
-   normalize16(sw-end, swn2, 16384, end+len);
-   swn = swn2 + end;
-#else
-   swn = sw;
-#endif
-
    for (i=0;i<N;i++)
    {
         best_score[i]=-1;
@@ -201,18 +191,17 @@
         pitch[i]=start;
    }
 
-
-   energy[0]=inner_prod(swn-start, swn-start, len);
-   e0=inner_prod(swn, swn, len);
+   energy[0]=inner_prod(sw-start, sw-start, len);
+   e0=inner_prod(sw, sw, len);
    for (i=start;i<end;i++)
    {
       /* Update energy for next pitch*/
-      energy[i-start+1] = SUB32(ADD32(energy[i-start],SHR32(MULT16_16(swn[-i-1],swn[-i-1]),6)), SHR32(MULT16_16(swn[-i+len-1],swn[-i+len-1]),6));
+      energy[i-start+1] = SUB32(ADD32(energy[i-start],SHR32(MULT16_16(sw[-i-1],sw[-i-1]),6)), SHR32(MULT16_16(sw[-i+len-1],sw[-i+len-1]),6));
       if (energy[i-start+1] < 0)
          energy[i-start+1] = 0;
    }
 
-   pitch_xcorr(swn, swn-end, corr, len, end-start+1, stack);
+   pitch_xcorr(sw, sw-end, corr, len, end-start+1, stack);
 
 #ifdef FIXED_POINT
    {
@@ -584,7 +573,7 @@
 /** Finds the best quantized 3-tap pitch predictor by analysis by synthesis */
 int pitch_search_3tap(
 spx_sig_t target[],                 /* Target vector */
-spx_sig_t *sw,
+spx_word16_t *sw,
 spx_coef_t ak[],                     /* LPCs for this subframe */
 spx_coef_t awk1[],                   /* Weighted LPCs #1 for this subframe */
 spx_coef_t awk2[],                   /* Weighted LPCs #2 for this subframe */
@@ -776,7 +765,7 @@
 /** Forced pitch delay and gain */
 int forced_pitch_quant(
 spx_sig_t target[],                 /* Target vector */
-spx_sig_t *sw,
+spx_word16_t *sw,
 spx_coef_t ak[],                     /* LPCs for this subframe */
 spx_coef_t awk1[],                   /* Weighted LPCs #1 for this subframe */
 spx_coef_t awk2[],                   /* Weighted LPCs #2 for this subframe */

Modified: trunk/speex/libspeex/ltp.h
===================================================================
--- trunk/speex/libspeex/ltp.h	2006-04-08 14:11:43 UTC (rev 11108)
+++ trunk/speex/libspeex/ltp.h	2006-04-08 15:12:45 UTC (rev 11109)
@@ -51,13 +51,13 @@
 spx_word32_t inner_prod(const spx_word16_t *x, const spx_word16_t *y, int len);
 void pitch_xcorr(const spx_word16_t *_x, const spx_word16_t *_y, spx_word32_t *corr, int len, int nb_pitch, char *stack);
 
-void open_loop_nbest_pitch(spx_sig_t *sw, int start, int end, int len, int *pitch, spx_word16_t *gain, int N, char *stack);
+void open_loop_nbest_pitch(spx_word16_t *sw, int start, int end, int len, int *pitch, spx_word16_t *gain, int N, char *stack);
 
 
 /** Finds the best quantized 3-tap pitch predictor by analysis by synthesis */
 int pitch_search_3tap(
 spx_sig_t target[],                 /* Target vector */
-spx_sig_t *sw,
+spx_word16_t *sw,
 spx_coef_t ak[],                     /* LPCs for this subframe */
 spx_coef_t awk1[],                   /* Weighted LPCs #1 for this subframe */
 spx_coef_t awk2[],                   /* Weighted LPCs #2 for this subframe */
@@ -98,7 +98,7 @@
 /** Forced pitch delay and gain */
 int forced_pitch_quant(
 spx_sig_t target[],                 /* Target vector */
-spx_sig_t *sw,
+spx_word16_t *sw,
 spx_coef_t ak[],                     /* LPCs for this subframe */
 spx_coef_t awk1[],                   /* Weighted LPCs #1 for this subframe */
 spx_coef_t awk2[],                   /* Weighted LPCs #2 for this subframe */

Modified: trunk/speex/libspeex/modes.h
===================================================================
--- trunk/speex/libspeex/modes.h	2006-04-08 14:11:43 UTC (rev 11108)
+++ trunk/speex/libspeex/modes.h	2006-04-08 15:12:45 UTC (rev 11109)
@@ -55,7 +55,7 @@
 
 
 /** Long-term predictor quantization */
-typedef int (*ltp_quant_func)(spx_sig_t *, spx_sig_t *, spx_coef_t *, spx_coef_t *, 
+typedef int (*ltp_quant_func)(spx_sig_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);
 

Modified: trunk/speex/libspeex/nb_celp.c
===================================================================
--- trunk/speex/libspeex/nb_celp.c	2006-04-08 14:11:43 UTC (rev 11108)
+++ trunk/speex/libspeex/nb_celp.c	2006-04-08 15:12:45 UTC (rev 11109)
@@ -158,7 +158,7 @@
    /* Allocating excitation buffer */
    st->excBuf = speex_alloc((mode->frameSize+mode->pitchEnd+1)*sizeof(spx_sig_t));
    st->exc = st->excBuf + mode->pitchEnd + 1;
-   st->swBuf = speex_alloc((mode->frameSize+mode->pitchEnd+1)*sizeof(spx_sig_t));
+   st->swBuf = speex_alloc((mode->frameSize+mode->pitchEnd+1)*sizeof(spx_word16_t));
    st->sw = st->swBuf + mode->pitchEnd + 1;
 
    st->innov = speex_alloc((st->frameSize)*sizeof(spx_sig_t));
@@ -293,7 +293,7 @@
 
    /* 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->swBuf, st->swBuf+st->frameSize, (st->max_pitch+1)*sizeof(spx_sig_t));
+   speex_move(st->swBuf, st->swBuf+st->frameSize, (st->max_pitch+1)*sizeof(spx_word16_t));
 
    {
       VARDECL(spx_word16_t *w_sig);
@@ -360,10 +360,10 @@
          bw_lpc(st->gamma2, st->interp_lpc, st->bw_lpc2, st->lpcSize);
          
          for (i=0;i<st->windowSize-st->frameSize;i++)
-            st->sw[i] = SHL32(st->winBuf[i],SIG_SHIFT);
+            st->sw[i] = st->winBuf[i];
          for (;i<st->frameSize;i++)
-            st->sw[i] = SHL32(in[i-st->windowSize+st->frameSize],SIG_SHIFT);
-         filter_mem2(st->sw, st->bw_lpc1, st->bw_lpc2, st->sw, st->frameSize, st->lpcSize, st->mem_sw_whole);
+            st->sw[i] = in[i-st->windowSize+st->frameSize];
+         filter_mem16(st->sw, st->bw_lpc1, st->bw_lpc2, st->sw, st->frameSize, st->lpcSize, st->mem_sw_whole);
 
          open_loop_nbest_pitch(st->sw, st->min_pitch, st->max_pitch, st->frameSize, 
                                nol_pitch, nol_pitch_coef, 6, stack);
@@ -695,7 +695,8 @@
    for (sub=0;sub<st->nbSubframes;sub++)
    {
       int   offset;
-      spx_sig_t *sw, *exc;
+      spx_word16_t *sw;
+      spx_sig_t *exc;
       int pitch;
       int response_bound = st->subframeSize;
 #ifdef EPIC_48K
@@ -764,13 +765,19 @@
       for (i=0;i<st->subframeSize;i++)
          real_exc[i] = exc[i];
       {
-         /*FIXME: This is a kludge that will break eventually */
+         /*FIXME: This is a kludge that will break if we change the window size */
          if (sub==0)
+         {
             for (i=0;i<st->subframeSize;i++)
-               sw[i] = real_exc[i] = SHL32(st->winBuf[i],SIG_SHIFT);
-         else
+               real_exc[i] = SHL32(st->winBuf[i],SIG_SHIFT);
             for (i=0;i<st->subframeSize;i++)
-               sw[i] = real_exc[i] = SHL32(in[i+((sub-1)*st->subframeSize)],SIG_SHIFT);
+               sw[i] = st->winBuf[i];
+         } else {
+            for (i=0;i<st->subframeSize;i++)
+               real_exc[i] = SHL32(in[i+((sub-1)*st->subframeSize)],SIG_SHIFT);
+            for (i=0;i<st->subframeSize;i++)
+               sw[i] = in[i+((sub-1)*st->subframeSize)];
+         }
       }
       fir_mem2(real_exc, st->interp_qlpc, real_exc, st->subframeSize, st->lpcSize, st->mem_exc2);
       
@@ -804,7 +811,7 @@
       /* Compute weighted signal */
       for (i=0;i<st->lpcSize;i++)
          mem[i]=st->mem_sw[i];
-      filter_mem2(sw, st->bw_lpc1, st->bw_lpc2, sw, st->subframeSize, st->lpcSize, mem);
+      filter_mem16(sw, st->bw_lpc1, st->bw_lpc2, sw, st->subframeSize, st->lpcSize, mem);
       
       if (st->complexity==0)
          for (i=0;i<st->lpcSize;i++)
@@ -812,7 +819,7 @@
       
       /* Compute target signal */
       for (i=0;i<st->subframeSize;i++)
-         target[i]=sw[i]-res[i];
+         target[i]=SHL32(sw[i],SIG_SHIFT)-res[i];
 
       for (i=0;i<st->subframeSize;i++)
          exc[i]=0;
@@ -962,9 +969,11 @@
       /* Final signal synthesis from excitation */
       iir_mem2(exc, st->interp_qlpc, res, st->subframeSize, st->lpcSize, st->mem_sp);
 
+      for (i=0;i<st->subframeSize;i++)
+         sw[i] = PSHR32(res[i], SIG_SHIFT);
       /* Compute weighted signal again, from synthesized speech (not sure it's the right thing) */
       if (st->complexity!=0)
-         filter_mem2(res, st->bw_lpc1, st->bw_lpc2, sw, st->subframeSize, st->lpcSize, st->mem_sw);
+         filter_mem16(sw, st->bw_lpc1, st->bw_lpc2, sw, st->subframeSize, st->lpcSize, st->mem_sw);
       
    }
 

Modified: trunk/speex/libspeex/nb_celp.h
===================================================================
--- trunk/speex/libspeex/nb_celp.h	2006-04-08 14:11:43 UTC (rev 11108)
+++ trunk/speex/libspeex/nb_celp.h	2006-04-08 15:12:45 UTC (rev 11109)
@@ -82,8 +82,8 @@
    spx_word16_t *winBuf;          /**< Input buffer (original signal) */
    spx_sig_t *excBuf;         /**< Excitation buffer */
    spx_sig_t *exc;            /**< Start of excitation frame */
-   spx_sig_t *swBuf;          /**< Weighted signal buffer */
-   spx_sig_t *sw;             /**< Start of weighted signal frame */
+   spx_word16_t *swBuf;          /**< Weighted signal buffer */
+   spx_word16_t *sw;             /**< Start of weighted signal frame */
    spx_sig_t *innov;          /**< Innovation for the frame */
    const spx_word16_t *window;         /**< Temporary (Hanning) window */
    spx_word16_t *autocorr;       /**< auto-correlation */



More information about the commits mailing list