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

jm at motherfish-iii.xiph.org jm at motherfish-iii.xiph.org
Thu Feb 3 14:18:36 PST 2005


Author: jm
Date: 2005-02-03 14:18:32 -0800 (Thu, 03 Feb 2005)
New Revision: 8827

Modified:
   trunk/speex/libspeex/cb_search.c
   trunk/speex/libspeex/cb_search.h
   trunk/speex/libspeex/ltp.c
   trunk/speex/libspeex/modes.h
   trunk/speex/libspeex/nb_celp.c
   trunk/speex/libspeex/sb_celp.c
Log:
Removed redundent filtering calls, added complexity 0 (even more shortcuts)


Modified: trunk/speex/libspeex/cb_search.c
===================================================================
--- trunk/speex/libspeex/cb_search.c	2005-02-03 10:47:37 UTC (rev 8826)
+++ trunk/speex/libspeex/cb_search.c	2005-02-03 22:18:32 UTC (rev 8827)
@@ -91,7 +91,8 @@
 spx_sig_t *r,
 SpeexBits *bits,
 char *stack,
-int   complexity
+int   complexity,
+int   update_target
 )
 {
    int i,j,k,m,n,q;
@@ -121,7 +122,9 @@
    N=complexity;
    if (N>10)
       N=10;
-
+   if (N<1)
+      N=1;
+   
    ot=PUSH(stack, N, spx_word16_t*);
    nt=PUSH(stack, N, spx_word16_t*);
    oind=PUSH(stack, N, int*);
@@ -350,11 +353,13 @@
    for (j=0;j<nsf;j++)
       exc[j]+=e[j];
    
-   /* Update target */
-   syn_percep_zero(e, ak, awk1, awk2, r2, nsf,p, stack);
-   for (j=0;j<nsf;j++)
-      target[j]-=r2[j];
-
+   /* Update target: only update target if necessary */
+   if (update_target)
+   {
+      syn_percep_zero(e, ak, awk1, awk2, r2, nsf,p, stack);
+      for (j=0;j<nsf;j++)
+         target[j]-=r2[j];
+   }
 }
 
 
@@ -426,7 +431,8 @@
 spx_sig_t *r,
 SpeexBits *bits,
 char *stack,
-int   complexity
+int   complexity,
+int   update_target
 )
 {
    int i;

Modified: trunk/speex/libspeex/cb_search.h
===================================================================
--- trunk/speex/libspeex/cb_search.h	2005-02-03 10:47:37 UTC (rev 8826)
+++ trunk/speex/libspeex/cb_search.h	2005-02-03 22:18:32 UTC (rev 8827)
@@ -57,7 +57,8 @@
 spx_sig_t *r,
 SpeexBits *bits,
 char *stack,
-int   complexity
+int   complexity,
+int   update_target
 );
 
 void split_cb_shape_sign_unquant(
@@ -81,7 +82,8 @@
 spx_sig_t *r,
 SpeexBits *bits,
 char *stack,
-int   complexity
+int   complexity,
+int   update_target
 );
 
 

Modified: trunk/speex/libspeex/ltp.c
===================================================================
--- trunk/speex/libspeex/ltp.c	2005-02-03 10:47:37 UTC (rev 8826)
+++ trunk/speex/libspeex/ltp.c	2005-02-03 22:18:32 UTC (rev 8827)
@@ -207,6 +207,7 @@
 char *stack,
 spx_sig_t *exc2,
 spx_sig_t *r,
+spx_sig_t *new_target,
 int  *cdbk_index,
 int cdbk_offset
 )
@@ -397,7 +398,9 @@
    err=0;
    for (i=0;i<nsf;i++)
    {
-      spx_sig_t perr=target[i]-SHL((MULT16_32_Q15(SHL(gain[0],7),x[2][i])+MULT16_32_Q15(SHL(gain[1],7),x[1][i])+MULT16_32_Q15(SHL(gain[2],7),x[0][i])),2);
+      spx_sig_t tmp = SHL((MULT16_32_Q15(SHL(gain[0],7),x[2][i])+MULT16_32_Q15(SHL(gain[1],7),x[1][i])+MULT16_32_Q15(SHL(gain[2],7),x[0][i])),2);
+      spx_sig_t perr=target[i]-tmp;
+      new_target[i] = target[i] - tmp;
       spx_word16_t perr2 = PSHR(perr,15);
       err = ADD64(err,MULT16_16(perr2,perr2));
       
@@ -440,7 +443,7 @@
 {
    int i,j;
    int cdbk_index, pitch=0, best_gain_index=0;
-   spx_sig_t *best_exc;
+   spx_sig_t *best_exc, *new_target, *best_target;
    int best_pitch=0;
    spx_word64_t err, best_err=-1;
    int N;
@@ -451,12 +454,14 @@
    N=complexity;
    if (N>10)
       N=10;
+   if (N<1)
+      N=1;
 
    nbest=PUSH(stack, N, int);
    gains = PUSH(stack, N, spx_word16_t);
    params = (ltp_params*) par;
 
-   if (N==0 || end<start)
+   if (end<start)
    {
       speex_bits_pack(bits, 0, params->pitch_bits);
       speex_bits_pack(bits, 0, params->gain_bits);
@@ -466,6 +471,8 @@
    }
    
    best_exc=PUSH(stack,nsf, spx_sig_t);
+   new_target=PUSH(stack,nsf, spx_sig_t);
+   best_target=PUSH(stack,nsf, spx_sig_t);
    
    if (N>end-start+1)
       N=end-start+1;
@@ -476,11 +483,13 @@
       for (j=0;j<nsf;j++)
          exc[j]=0;
       err=pitch_gain_search_3tap(target, ak, awk1, awk2, exc, par, pitch, p, nsf,
-                                 bits, stack, exc2, r, &cdbk_index, cdbk_offset);
+                                 bits, stack, exc2, r, new_target, &cdbk_index, cdbk_offset);
       if (err<best_err || best_err<0)
       {
          for (j=0;j<nsf;j++)
             best_exc[j]=exc[j];
+         for (j=0;j<nsf;j++)
+            best_target[j]=new_target[j];
          best_err=err;
          best_pitch=pitch;
          best_gain_index=cdbk_index;
@@ -493,6 +502,8 @@
    /*printf ("encode pitch: %d %d\n", best_pitch, best_gain_index);*/
    for (i=0;i<nsf;i++)
       exc[i]=best_exc[i];
+   for (i=0;i<nsf;i++)
+      target[i]=best_target[i];
 
    return pitch;
 }

Modified: trunk/speex/libspeex/modes.h
===================================================================
--- trunk/speex/libspeex/modes.h	2005-02-03 10:47:37 UTC (rev 8826)
+++ trunk/speex/libspeex/modes.h	2005-02-03 22:18:32 UTC (rev 8827)
@@ -66,7 +66,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, 
-                                      spx_sig_t *, spx_sig_t *, SpeexBits *, char *, int);
+                                      spx_sig_t *, spx_sig_t *, SpeexBits *, char *, int, int);
 
 /** Innovation unquantization function */
 typedef void (*innovation_unquant_func)(spx_sig_t *, const void *, int, SpeexBits*, char *);

Modified: trunk/speex/libspeex/nb_celp.c
===================================================================
--- trunk/speex/libspeex/nb_celp.c	2005-02-03 10:47:37 UTC (rev 8826)
+++ trunk/speex/libspeex/nb_celp.c	2005-02-03 22:18:32 UTC (rev 8827)
@@ -231,6 +231,7 @@
    char *stack;
    spx_sig_t *syn_resp;
    spx_sig_t *orig;
+   spx_sig_t *real_exc;
 #ifdef EPIC_48K
    int pitch_half[2];
    int ol_pitch_id=0;
@@ -629,6 +630,7 @@
    /* Target signal */
    target = PUSH(stack, st->subframeSize, spx_sig_t);
    syn_resp = PUSH(stack, st->subframeSize, spx_sig_t);
+   real_exc = PUSH(stack, st->subframeSize, spx_sig_t);
    mem = PUSH(stack, st->lpcSize, spx_mem_t);
    orig = PUSH(stack, st->frameSize, spx_sig_t);
    for (i=0;i<st->frameSize;i++)
@@ -698,12 +700,21 @@
             st->bw_lpc2[i]=0;
       }
 
+      for (i=0;i<st->subframeSize;i++)
+         real_exc[i] = exc[i];
+      
       /* Compute impulse response of A(z/g1) / ( A(z)*A(z/g2) )*/
       for (i=0;i<st->subframeSize;i++)
          exc[i]=VERY_SMALL;
       exc[0]=SIG_SCALING;
-      syn_percep_zero(exc, st->interp_qlpc, st->bw_lpc1, st->bw_lpc2, syn_resp, st->subframeSize, st->lpcSize, stack);
-
+      if (st->complexity==0)
+      {
+         syn_percep_zero(exc, st->interp_qlpc, st->bw_lpc1, st->bw_lpc2, syn_resp, st->subframeSize>>1, st->lpcSize, stack);
+         for (i=st->subframeSize>>1;i<st->subframeSize;i++)
+            syn_resp[i]=0;
+      } else {
+         syn_percep_zero(exc, st->interp_qlpc, st->bw_lpc1, st->bw_lpc2, syn_resp, st->subframeSize, st->lpcSize, stack);
+      }
       /* Reset excitation */
       for (i=0;i<st->subframeSize;i++)
          exc[i]=VERY_SMALL;
@@ -713,12 +724,25 @@
       /* Compute zero response of A(z/g1) / ( A(z/g2) * A(z) ) */
       for (i=0;i<st->lpcSize;i++)
          mem[i]=st->mem_sp[i];
-      iir_mem2(exc, st->interp_qlpc, exc, st->subframeSize, st->lpcSize, mem);
+      if (st->complexity==0)
+      {
+         iir_mem2(exc, st->interp_qlpc, exc, st->subframeSize>>1, st->lpcSize, mem);
+         for (i=st->subframeSize>>1;i<st->subframeSize;i++)
+            exc[i]=0;
+      } else {
+         iir_mem2(exc, st->interp_qlpc, exc, st->subframeSize, st->lpcSize, mem);
+      }
       
       for (i=0;i<st->lpcSize;i++)
          mem[i]=st->mem_sw[i];
-      filter_mem2(exc, st->bw_lpc1, st->bw_lpc2, res, st->subframeSize, st->lpcSize, mem);
-      
+      if (st->complexity==0)
+      {
+         filter_mem2(exc, st->bw_lpc1, st->bw_lpc2, res, st->subframeSize>>1, st->lpcSize, mem);
+         for (i=st->subframeSize>>1;i<st->subframeSize;i++)
+            res[i]=0;
+      } else {
+         filter_mem2(exc, st->bw_lpc1, st->bw_lpc2, res, st->subframeSize, st->lpcSize, mem);
+      }
       /* Compute weighted signal */
       for (i=0;i<st->lpcSize;i++)
          mem[i]=st->mem_sw[i];
@@ -786,11 +810,11 @@
       }
 
       /* Update target for adaptive codebook contribution */
-      syn_percep_zero(exc, st->interp_qlpc, st->bw_lpc1, st->bw_lpc2, res, st->subframeSize, st->lpcSize, stack);
+      /* FIXME: We shouldn't have to apply the filter again (compute directly in the pitch quantizer) */
+      /*syn_percep_zero(exc, st->interp_qlpc, st->bw_lpc1, st->bw_lpc2, res, st->subframeSize, st->lpcSize, stack);
       for (i=0;i<st->subframeSize;i++)
          target[i]=SATURATE(SUB32(target[i],res[i]),805306368);
-
-
+      */
       /* Quantization of innovation */
       {
          spx_sig_t *innov;
@@ -801,7 +825,10 @@
          for (i=0;i<st->subframeSize;i++)
             innov[i]=0;
          
-         residue_percep_zero(target, st->interp_qlpc, st->bw_lpc1, st->bw_lpc2, st->buf2, st->subframeSize, st->lpcSize, stack);
+         /*FIXME: Check that I'm really allowed to replace the residue_percep_zero */
+         for (i=0;i<st->subframeSize;i++)
+            st->buf2[i] = real_exc[i] - exc[i];
+         /*residue_percep_zero(target, st->interp_qlpc, st->bw_lpc1, st->bw_lpc2, st->buf2, st->subframeSize, st->lpcSize, stack);*/
 
          ener = SHL((spx_word32_t)compute_rms(st->buf2, st->subframeSize),SIG_SHIFT);
 
@@ -850,7 +877,7 @@
             /* Codebook search */
             SUBMODE(innovation_quant)(target, st->interp_qlpc, st->bw_lpc1, st->bw_lpc2, 
                                       SUBMODE(innovation_params), st->lpcSize, st->subframeSize, 
-                                      innov, syn_resp, bits, stack, st->complexity);
+                                      innov, syn_resp, bits, stack, st->complexity, SUBMODE(double_codebook));
             
             /* De-normalize innovation and update excitation */
             signal_mul(innov, innov, ener, st->subframeSize);
@@ -871,22 +898,22 @@
                target[i]*=2.2;
             SUBMODE(innovation_quant)(target, st->interp_qlpc, st->bw_lpc1, st->bw_lpc2, 
                                       SUBMODE(innovation_params), st->lpcSize, st->subframeSize, 
-                                      innov2, syn_resp, bits, tmp_stack, st->complexity);
+                                      innov2, syn_resp, bits, tmp_stack, st->complexity, 0);
             signal_mul(innov2, innov2, (spx_word32_t) (ener*(1/2.2)), st->subframeSize);
             for (i=0;i<st->subframeSize;i++)
                exc[i] += innov2[i];
          }
 
-         signal_mul(target, target, ener, st->subframeSize);
+         /* FIXME: I can remove that, right? */
+         /*signal_mul(target, target, ener, st->subframeSize);*/
       }
 
-      /*Keep the previous memory*/
-      for (i=0;i<st->lpcSize;i++)
-         mem[i]=st->mem_sp[i];
+      /* FIXME: Should simplify that, at least for complexity==0 */
       /* Final signal synthesis from excitation */
       iir_mem2(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) */
+      /* FIXME: Should simplify that, at least for complexity==0 */
       filter_mem2(sp, st->bw_lpc1, st->bw_lpc2, sw, st->subframeSize, st->lpcSize, st->mem_sw);
       for (i=0;i<st->subframeSize;i++)
          exc2[i]=exc[i];
@@ -1744,8 +1771,8 @@
       break;
    case SPEEX_SET_COMPLEXITY:
       st->complexity = (*(int*)ptr);
-      if (st->complexity<1)
-         st->complexity=1;
+      if (st->complexity<0)
+         st->complexity=0;
       break;
    case SPEEX_GET_COMPLEXITY:
       (*(int*)ptr) = st->complexity;

Modified: trunk/speex/libspeex/sb_celp.c
===================================================================
--- trunk/speex/libspeex/sb_celp.c	2005-02-03 10:47:37 UTC (rev 8826)
+++ trunk/speex/libspeex/sb_celp.c	2005-02-03 22:18:32 UTC (rev 8827)
@@ -671,7 +671,7 @@
          /*print_vec(target, st->subframeSize, "\ntarget");*/
          SUBMODE(innovation_quant)(target, st->interp_qlpc, st->bw_lpc1, st->bw_lpc2, 
                                    SUBMODE(innovation_params), st->lpcSize, st->subframeSize, 
-                                   innov, syn_resp, bits, stack, (st->complexity+1)>>1);
+                                   innov, syn_resp, bits, stack, (st->complexity+1)>>1, SUBMODE(double_codebook));
          /*print_vec(target, st->subframeSize, "after");*/
 
          signal_mul(innov, innov, scale, st->subframeSize);
@@ -688,7 +688,7 @@
                target[i]*=2.5;
             SUBMODE(innovation_quant)(target, st->interp_qlpc, st->bw_lpc1, st->bw_lpc2, 
                                       SUBMODE(innovation_params), st->lpcSize, st->subframeSize, 
-                                      innov2, syn_resp, bits, tmp_stack, (st->complexity+1)>>1);
+                                      innov2, syn_resp, bits, tmp_stack, (st->complexity+1)>>1, 0);
             for (i=0;i<st->subframeSize;i++)
                innov2[i]*=scale*(1/2.5)/SIG_SCALING;
             for (i=0;i<st->subframeSize;i++)



More information about the commits mailing list