[xiph-cvs] cvs commit: speex/libspeex sb_celp.c sb_celp.h nb_celp.c nb_celp.h

Jean-Marc Valin jm at xiph.org
Fri Nov 14 11:16:23 PST 2003



jm          03/11/14 14:16:23

  Modified:    libspeex sb_celp.c sb_celp.h nb_celp.c nb_celp.h
  Log:
  fixed-point: integerized pi_gain's

Revision  Changes    Path
1.155     +36 -37    speex/libspeex/sb_celp.c

Index: sb_celp.c
===================================================================
RCS file: /usr/local/cvsroot/speex/libspeex/sb_celp.c,v
retrieving revision 1.154
retrieving revision 1.155
diff -u -r1.154 -r1.155
--- sb_celp.c	14 Nov 2003 18:46:29 -0000	1.154
+++ sb_celp.c	14 Nov 2003 19:16:22 -0000	1.155
@@ -237,7 +237,7 @@
    st->interp_qlsp = PUSH(st->stack, st->lpcSize, spx_lsp_t);
    st->interp_lpc = PUSH(st->stack, st->lpcSize+1, spx_coef_t);
    st->interp_qlpc = PUSH(st->stack, st->lpcSize+1, spx_coef_t);
-   st->pi_gain = PUSH(st->stack, st->nbSubframes, float);
+   st->pi_gain = PUSH(st->stack, st->nbSubframes, spx_word32_t);
 
    st->mem_sp = PUSH(st->stack, st->lpcSize, spx_mem_t);
    st->mem_sp2 = PUSH(st->stack, st->lpcSize, spx_mem_t);
@@ -273,7 +273,7 @@
    char *stack;
    spx_mem_t *mem;
    spx_sig_t *innov, *syn_resp;
-   float *low_pi_gain;
+   spx_word32_t *low_pi_gain;
    spx_sig_t *low_exc, *low_innov;
    SpeexSBMode *mode;
    int dtx;
@@ -307,7 +307,7 @@
    speex_move(st->excBuf, st->excBuf+st->frame_size, (st->bufSize-st->frame_size)*sizeof(spx_sig_t));
 
 
-   low_pi_gain = PUSH(stack, st->nbSubframes, float);
+   low_pi_gain = PUSH(stack, st->nbSubframes, spx_word32_t);
    low_exc = PUSH(stack, st->frame_size, spx_sig_t);
    low_innov = PUSH(stack, st->frame_size, spx_sig_t);
    speex_encoder_ctl(st->st_low, SPEEX_GET_PI_GAIN, low_pi_gain);
@@ -496,7 +496,7 @@
       float tmp;
       spx_word16_t filter_ratio;
       int offset;
-      float rl, rh;
+      spx_word32_t rl, rh;
       spx_word16_t eh=0;
 
       offset = st->subframeSize*sub;
@@ -521,24 +521,21 @@
 
       /* Compute mid-band (4000 Hz for wideband) response of low-band and high-band
          filters */
-      rl=rh=0;
-      tmp=1;
-      st->pi_gain[sub]=0;
-      for (i=0;i<=st->lpcSize;i++)
-      {
-         rh += tmp*st->interp_qlpc[i];
-         tmp = -tmp;
-         st->pi_gain[sub]+=st->interp_qlpc[i];
+      st->pi_gain[sub]=LPC_SCALING;
+      rh = LPC_SCALING;
+      for (i=1;i<=st->lpcSize;i+=2)
+      {
+         rh += st->interp_qlpc[i+1] - st->interp_qlpc[i];
+         st->pi_gain[sub] += st->interp_qlpc[i] + st->interp_qlpc[i+1];
       }
-      rh /= LPC_SCALING;
-      st->pi_gain[sub] /= LPC_SCALING;
-
+      
       rl = low_pi_gain[sub];
 #ifdef FIXED_POINT
-      filter_ratio=DIV32_16((spx_word32_t)(32768*(rl+.01)),(spx_word16_t)(256*(.01+rh)));
+      filter_ratio=DIV32_16(SHL(rl+82,2),SHR(82+rh,5));
 #else
       filter_ratio=(rl+.01)/(rh+.01);
 #endif
+      
       /* Compute "real excitation" */
       fir_mem2(sp, st->interp_qlpc, exc, st->subframeSize, st->lpcSize, st->mem_sp2);
       /* Compute energy of low-band and high-band excitation */
@@ -748,7 +745,7 @@
    st->interp_qlsp = PUSH(st->stack, st->lpcSize, spx_lsp_t);
    st->interp_qlpc = PUSH(st->stack, st->lpcSize+1, spx_coef_t);
 
-   st->pi_gain = PUSH(st->stack, st->nbSubframes, float);
+   st->pi_gain = PUSH(st->stack, st->nbSubframes, spx_word32_t);
    st->mem_sp = PUSH(st->stack, 2*st->lpcSize, spx_mem_t);
    
    st->lpc_enh_enabled=0;
@@ -859,7 +856,7 @@
    int wideband;
    int ret;
    char *stack;
-   float *low_pi_gain;
+   spx_word32_t *low_pi_gain;
    spx_sig_t *low_exc, *low_innov;
    spx_coef_t *awk1, *awk2, *awk3;
    int dtx;
@@ -948,7 +945,7 @@
    for (i=0;i<st->frame_size;i++)
       st->exc[i]=0;
 
-   low_pi_gain = PUSH(stack, st->nbSubframes, float);
+   low_pi_gain = PUSH(stack, st->nbSubframes, spx_word32_t);
    low_exc = PUSH(stack, st->frame_size, spx_sig_t);
    low_innov = PUSH(stack, st->frame_size, spx_sig_t);
    speex_decoder_ctl(st->st_low, SPEEX_GET_PI_GAIN, low_pi_gain);
@@ -970,9 +967,9 @@
    for (sub=0;sub<st->nbSubframes;sub++)
    {
       spx_sig_t *exc, *sp;
-      float tmp, filter_ratio, el=0;
+      float filter_ratio, el=0;
       int offset;
-      float rl=0,rh=0;
+      spx_word32_t rl=0,rh=0;
       
       offset = st->subframeSize*sub;
       sp=st->high+offset;
@@ -1011,22 +1008,21 @@
       /* Calculate reponse ratio between the low and high filter in the middle
          of the band (4000 Hz) */
       
-         tmp=1;
-         st->pi_gain[sub]=0;
-         for (i=0;i<=st->lpcSize;i++)
+         st->pi_gain[sub]=LPC_SCALING;
+         rh = LPC_SCALING;
+         for (i=1;i<=st->lpcSize;i+=2)
          {
-            rh += tmp*st->interp_qlpc[i];
-            tmp = -tmp;
-            st->pi_gain[sub]+=st->interp_qlpc[i];
+            rh += st->interp_qlpc[i+1] - st->interp_qlpc[i];
+            st->pi_gain[sub] += st->interp_qlpc[i] + st->interp_qlpc[i+1];
          }
-         rh /= LPC_SCALING;
-         st->pi_gain[sub] /= LPC_SCALING;
 
          rl = low_pi_gain[sub];
-         rl=1/(fabs(rl)+.01);
-         rh=1/(fabs(rh)+.01);
-         filter_ratio=fabs(.01+rh)/(.01+fabs(rl));
-      
+#ifdef FIXED_POINT
+         filter_ratio=DIV32_16(SHL(rl+82,2),SHR(82+rh,5));
+         filter_ratio /= 128.;
+#else
+         filter_ratio=(rl+.01)/(rh+.01);
+#endif
       
       for (i=0;i<st->subframeSize;i++)
          exc[i]=0;
@@ -1051,9 +1047,12 @@
 
          el = compute_rms(low_exc+offset, st->subframeSize);
 
-         gc = exp((1/3.7)*qgc-2);
+         gc = exp((1/3.7)*qgc-0.15556);
+
+         if (st->subframeSize==80)
+            gc *= 1.4142;
 
-         scale = gc*(1+el*sqrt(st->subframeSize))/filter_ratio;
+         scale = gc*(1+el)/filter_ratio;
 
          SUBMODE(innovation_unquant)(exc, SUBMODE(innovation_params), st->subframeSize, 
                                 bits, stack);
@@ -1273,7 +1272,7 @@
    case SPEEX_GET_PI_GAIN:
       {
          int i;
-         float *g = (float*)ptr;
+         spx_word32_t *g = (spx_word32_t*)ptr;
          for (i=0;i<st->nbSubframes;i++)
             g[i]=st->pi_gain[i];
       }
@@ -1387,7 +1386,7 @@
    case SPEEX_GET_PI_GAIN:
       {
          int i;
-         float *g = (float*)ptr;
+         spx_word32_t *g = (spx_word32_t*)ptr;
          for (i=0;i<st->nbSubframes;i++)
             g[i]=st->pi_gain[i];
       }

<p><p>1.49      +2 -2      speex/libspeex/sb_celp.h

Index: sb_celp.h
===================================================================
RCS file: /usr/local/cvsroot/speex/libspeex/sb_celp.h,v
retrieving revision 1.48
retrieving revision 1.49
diff -u -r1.48 -r1.49
--- sb_celp.h	14 Nov 2003 17:48:58 -0000	1.48
+++ sb_celp.h	14 Nov 2003 19:16:22 -0000	1.49
@@ -88,7 +88,7 @@
    spx_mem_t *mem_sp;              /**< Synthesis signal memory */
    spx_mem_t *mem_sp2;
    spx_mem_t *mem_sw;              /**< Perceptual signal memory */
-   float *pi_gain;
+   spx_word32_t *pi_gain;
 
    float  vbr_quality;         /**< Quality setting for VBR encoding */
    int    vbr_enabled;         /**< 1 for enabling VBR, 0 otherwise */
@@ -135,7 +135,7 @@
    spx_coef_t *interp_qlpc;
 
    spx_mem_t *mem_sp;
-   float *pi_gain;
+   spx_word32_t *pi_gain;
 
    int    encode_submode;
    SpeexSubmode **submodes;

<p><p>1.153     +6 -6      speex/libspeex/nb_celp.c

Index: nb_celp.c
===================================================================
RCS file: /usr/local/cvsroot/speex/libspeex/nb_celp.c,v
retrieving revision 1.152
retrieving revision 1.153
diff -u -r1.152 -r1.153
--- nb_celp.c	14 Nov 2003 18:46:29 -0000	1.152
+++ nb_celp.c	14 Nov 2003 19:16:22 -0000	1.153
@@ -174,7 +174,7 @@
    st->mem_sw_whole = PUSH(st->stack, st->lpcSize, spx_mem_t);
    st->mem_exc = PUSH(st->stack, st->lpcSize, spx_mem_t);
 
-   st->pi_gain = PUSH(st->stack, st->nbSubframes, float);
+   st->pi_gain = PUSH(st->stack, st->nbSubframes, spx_word32_t);
 
    st->pitch = PUSH(st->stack, st->nbSubframes, int);
 
@@ -665,7 +665,7 @@
          {
             pi_g += -st->interp_qlpc[i] +  st->interp_qlpc[i+1];
          }
-         st->pi_gain[sub] = (float)pi_g / LPC_SCALING;
+         st->pi_gain[sub] = pi_g;
       }
 
 
@@ -970,7 +970,7 @@
    st->comb_mem = PUSHS(st->stack, CombFilterMem);
    comb_filter_mem_init (st->comb_mem);
 
-   st->pi_gain = PUSH(st->stack, st->nbSubframes, float);
+   st->pi_gain = PUSH(st->stack, st->nbSubframes, spx_word32_t);
    st->last_pitch = 40;
    st->count_lost=0;
    st->pitch_gain_buf[0] = st->pitch_gain_buf[1] = st->pitch_gain_buf[2] = 0;
@@ -1428,7 +1428,7 @@
          {
             pi_g += -st->interp_qlpc[i] +  st->interp_qlpc[i+1];
          }
-         st->pi_gain[sub] = (float)pi_g / LPC_SCALING;
+         st->pi_gain[sub] = pi_g;
       }
 
       /* Reset excitation */
@@ -1798,7 +1798,7 @@
    case SPEEX_GET_PI_GAIN:
       {
          int i;
-         float *g = (float*)ptr;
+         spx_word32_t *g = (spx_word32_t*)ptr;
          for (i=0;i<st->nbSubframes;i++)
             g[i]=st->pi_gain[i];
       }
@@ -1898,7 +1898,7 @@
    case SPEEX_GET_PI_GAIN:
       {
          int i;
-         float *g = (float*)ptr;
+         spx_word32_t *g = (spx_word32_t*)ptr;
          for (i=0;i<st->nbSubframes;i++)
             g[i]=st->pi_gain[i];
       }

<p><p>1.60      +2 -2      speex/libspeex/nb_celp.h

Index: nb_celp.h
===================================================================
RCS file: /usr/local/cvsroot/speex/libspeex/nb_celp.h,v
retrieving revision 1.59
retrieving revision 1.60
diff -u -r1.59 -r1.60
--- nb_celp.h	12 Nov 2003 07:30:18 -0000	1.59
+++ nb_celp.h	14 Nov 2003 19:16:22 -0000	1.60
@@ -98,7 +98,7 @@
    spx_mem_t *mem_sw;         /**< Filter memory for perceptually-weighted signal */
    spx_mem_t *mem_sw_whole;   /**< Filter memory for perceptually-weighted signal (whole frame)*/
    spx_mem_t *mem_exc;        /**< Filter memory for excitation (whole frame) */
-   float *pi_gain;        /**< Gain of LPC filter at theta=pi (fe/2) */
+   spx_word32_t *pi_gain;        /**< Gain of LPC filter at theta=pi (fe/2) */
 
    VBRState *vbr;         /**< State of the VBR data */
    float  vbr_quality;    /**< Quality setting for VBR encoding */
@@ -154,7 +154,7 @@
    spx_lsp_t *interp_qlsp;    /**< Interpolated quantized LSPs */
    spx_coef_t *interp_qlpc;    /**< Interpolated quantized LPCs */
    spx_mem_t *mem_sp;         /**< Filter memory for synthesis signal */
-   float *pi_gain;        /**< Gain of LPC filter at theta=pi (fe/2) */
+   spx_word32_t *pi_gain;        /**< Gain of LPC filter at theta=pi (fe/2) */
    int    last_pitch;     /**< Pitch of last correctly decoded frame */
    float  last_pitch_gain; /**< Pitch gain of last correctly decoded frame */
    float  pitch_gain_buf[3];  /**< Pitch gain of last decoded frames */

<p><p>--- >8 ----
List archives:  http://www.xiph.org/archives/
Ogg project homepage: http://www.xiph.org/ogg/
To unsubscribe from this list, send a message to 'cvs-request at xiph.org'
containing only the word 'unsubscribe' in the body.  No subject is needed.
Unsubscribe messages sent to the list will be ignored/filtered.



More information about the commits mailing list