[xiph-cvs] cvs commit: speex/libspeex arch.h filters.c filters.h ltp.c ltp.h modes.h nb_celp.c

Jean-Marc Valin jm at xiph.org
Thu Nov 27 21:40:03 PST 2003



jm          03/11/28 00:40:02

  Modified:    libspeex arch.h filters.c filters.h ltp.c ltp.h modes.h
                        nb_celp.c
  Log:
  fixed-point: some work on pitch gain, fixed a packet-loss bug

Revision  Changes    Path
1.5       +4 -0      speex/libspeex/arch.h

Index: arch.h
===================================================================
RCS file: /usr/local/cvsroot/speex/libspeex/arch.h,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- arch.h	27 Nov 2003 08:42:06 -0000	1.4
+++ arch.h	28 Nov 2003 05:39:56 -0000	1.5
@@ -51,6 +51,8 @@
 #define SIG_SCALING  16384
 #define LSP_SCALING  8192.
 #define GAMMA_SCALING 32768.
+#define GAIN_SCALING 64
+#define GAIN_SCALING_1 0.015625
 
 #define LPC_SHIFT    13
 #define SIG_SHIFT    14
@@ -181,6 +183,8 @@
 #define SIG_SCALING  1.
 #define LSP_SCALING  1.
 #define GAMMA_SCALING 1.
+#define GAIN_SCALING 1.
+#define GAIN_SCALING_1 1.
 
 #define LPC_SHIFT    0
 #define SIG_SHIFT    0

<p><p>1.65      +10 -4     speex/libspeex/filters.c

Index: filters.c
===================================================================
RCS file: /usr/local/cvsroot/speex/libspeex/filters.c,v
retrieving revision 1.64
retrieving revision 1.65
diff -u -r1.64 -r1.65
--- filters.c	27 Nov 2003 08:42:06 -0000	1.64
+++ filters.c	28 Nov 2003 05:39:57 -0000	1.65
@@ -50,7 +50,7 @@
    }
 }
 #else
-void bw_lpc(float gamma, spx_coef_t *lpc_in, spx_coef_t *lpc_out, int order)
+void bw_lpc(spx_word16_t gamma, spx_coef_t *lpc_in, spx_coef_t *lpc_out, int order)
 {
    int i;
    float tmp=1;
@@ -94,14 +94,14 @@
 
 #else
 
-void signal_mul(spx_sig_t *x, spx_sig_t *y, float scale, int len)
+void signal_mul(spx_sig_t *x, spx_sig_t *y, spx_word32_t scale, int len)
 {
    int i;
    for (i=0;i<len;i++)
       y[i] = scale*x[i];
 }
 
-void signal_div(spx_sig_t *x, spx_sig_t *y, float scale, int len)
+void signal_div(spx_sig_t *x, spx_sig_t *y, spx_word32_t scale, int len)
 {
    int i;
    float scale_1 = 1/scale;
@@ -455,7 +455,7 @@
 int p,               /*LPC order*/
 int nsf,             /*sub-frame size*/
 int pitch,           /*pitch period*/
-float *pitch_gain,   /*pitch gain (3-tap)*/
+spx_word16_t *spitch_gain,   /*pitch gain (3-tap)*/
 float  comb_gain,    /*gain of comb filter*/
 CombFilterMem *mem
 )
@@ -465,6 +465,12 @@
    float gain;
    float step;
    float fact;
+   float pitch_gain[3];
+
+   pitch_gain[0] = GAIN_SCALING_1*spitch_gain[0];
+   pitch_gain[1] = GAIN_SCALING_1*spitch_gain[1];
+   pitch_gain[2] = GAIN_SCALING_1*spitch_gain[2];
+
    /*Compute excitation energy prior to enhancement*/
    for (i=0;i<nsf;i++)
       exc_energy+=((float)exc[i])*exc[i];

<p><p>1.34      +1 -1      speex/libspeex/filters.h

Index: filters.h
===================================================================
RCS file: /usr/local/cvsroot/speex/libspeex/filters.h,v
retrieving revision 1.33
retrieving revision 1.34
diff -u -r1.33 -r1.34
--- filters.h	27 Nov 2003 08:42:06 -0000	1.33
+++ filters.h	28 Nov 2003 05:39:57 -0000	1.34
@@ -81,7 +81,7 @@
 int p,               /*LPC order*/
 int nsf,             /*sub-frame size*/
 int pitch,           /*pitch period*/
-float *pitch_gain,   /*pitch gain (3-tap)*/
+spx_word16_t *pitch_gain,   /*pitch gain (3-tap)*/
 float  comb_gain,    /*gain of comb filter*/
 CombFilterMem *mem
 );

<p><p>1.101     +11 -10    speex/libspeex/ltp.c

Index: ltp.c
===================================================================
RCS file: /usr/local/cvsroot/speex/libspeex/ltp.c,v
retrieving revision 1.100
retrieving revision 1.101
diff -u -r1.100 -r1.101
--- ltp.c	25 Nov 2003 16:40:25 -0000	1.100
+++ ltp.c	28 Nov 2003 05:39:57 -0000	1.101
@@ -499,7 +499,7 @@
 void *par,
 int   nsf,                      /* Number of samples in subframe */
 int *pitch_val,
-float *gain_val,
+spx_word16_t *gain_val,
 SpeexBits *bits,
 char *stack,
 int count_lost,
@@ -530,9 +530,6 @@
    sgain[0] = 32+(spx_word16_t)gain_cdbk[gain_index*3];
    sgain[1] = 32+(spx_word16_t)gain_cdbk[gain_index*3+1];
    sgain[2] = 32+(spx_word16_t)gain_cdbk[gain_index*3+2];
-   gain[0] = 0.015625*sgain[0];
-   gain[1] = 0.015625*sgain[1];
-   gain[2] = 0.015625*sgain[2];
 #else
    gain[0] = 0.015625*gain_cdbk[gain_index*3]+.5;
    gain[1] = 0.015625*gain_cdbk[gain_index*3+1]+.5;
@@ -542,6 +539,11 @@
    if (count_lost && pitch > subframe_offset)
    {
       float gain_sum;
+#ifdef FIXED_POINT
+      gain[0] = 0.015625*sgain[0];
+      gain[1] = 0.015625*sgain[1];
+      gain[2] = 0.015625*sgain[2];
+#endif
       if (1) {
          float tmp = count_lost < 4 ? last_pitch_gain : 0.4 * last_pitch_gain;
          if (tmp>.95)
@@ -575,10 +577,9 @@
    }
 
    *pitch_val = pitch;
-   /**gain_val = gain[0]+gain[1]+gain[2];*/
-   gain_val[0]=gain[0];
-   gain_val[1]=gain[1];
-   gain_val[2]=gain[2];
+   gain_val[0]=sgain[0];
+   gain_val[1]=sgain[1];
+   gain_val[2]=sgain[2];
 
    {
       spx_sig_t *e[3];
@@ -675,7 +676,7 @@
 void *par,
 int   nsf,                      /* Number of samples in subframe */
 int *pitch_val,
-float *gain_val,
+spx_word16_t *gain_val,
 SpeexBits *bits,
 char *stack,
 int count_lost,
@@ -694,5 +695,5 @@
    }
    *pitch_val = start;
    gain_val[0]=gain_val[2]=0;
-   gain_val[1] = pitch_coef;
+   gain_val[1] = GAIN_SCALING*pitch_coef;
 }

<p><p>1.38      +7 -2      speex/libspeex/ltp.h

Index: ltp.h
===================================================================
RCS file: /usr/local/cvsroot/speex/libspeex/ltp.h,v
retrieving revision 1.37
retrieving revision 1.38
diff -u -r1.37 -r1.38
--- ltp.h	25 Nov 2003 06:58:10 -0000	1.37
+++ ltp.h	28 Nov 2003 05:39:57 -0000	1.38
@@ -39,6 +39,11 @@
    int     pitch_bits;
 } ltp_params;
 
+#ifdef FIXED_POINT
+#define gain_3tap_to_1tap(g) (ABS(g[1]) + (g[0]>0 ? g[0] : -SHR(g[0],1)) + (g[2]>0 ? g[2] : -SHR(g[2],1)))
+#else
+#define gain_3tap_to_1tap(g) (ABS(g[1]) + (g[0]>0 ? g[0] : -.5*g[0]) + (g[2]>0 ? g[2] : -.5*g[2]))
+#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);
 
@@ -74,7 +79,7 @@
 void *par,
 int   nsf,                      /* Number of samples in subframe */
 int *pitch_val,
-float *gain_val,
+spx_word16_t *gain_val,
 SpeexBits *bits,
 char *stack,
 int lost,
@@ -114,7 +119,7 @@
 void *par,
 int   nsf,                      /* Number of samples in subframe */
 int *pitch_val,
-float *gain_val,
+spx_word16_t *gain_val,
 SpeexBits *bits,
 char *stack,
 int lost,

<p><p>1.48      +1 -1      speex/libspeex/modes.h

Index: modes.h
===================================================================
RCS file: /usr/local/cvsroot/speex/libspeex/modes.h,v
retrieving revision 1.47
retrieving revision 1.48
diff -u -r1.47 -r1.48
--- modes.h	9 Oct 2003 03:54:37 -0000	1.47
+++ modes.h	28 Nov 2003 05:39:57 -0000	1.48
@@ -61,7 +61,7 @@
 
 /** Long-term un-quantize */
 typedef void (*ltp_unquant_func)(spx_sig_t *, int, int, float, void *, int, int *,
-                                 float *, SpeexBits*, char*, int, int, float, int);
+                                 spx_word16_t *, SpeexBits*, char*, int, int, float, int);
 
 
 /** Innovation quantization function */

<p><p>1.157     +7 -19     speex/libspeex/nb_celp.c

Index: nb_celp.c
===================================================================
RCS file: /usr/local/cvsroot/speex/libspeex/nb_celp.c,v
retrieving revision 1.156
retrieving revision 1.157
diff -u -r1.156 -r1.157
--- nb_celp.c	27 Nov 2003 08:42:06 -0000	1.156
+++ nb_celp.c	28 Nov 2003 05:39:57 -0000	1.157
@@ -1082,7 +1082,7 @@
       {
          float innov_gain=0;
          for (i=0;i<st->frameSize;i++)
-            innov_gain += st->innov[i]*st->innov[i];
+            innov_gain += 1.0*st->innov[i]*st->innov[i];
          innov_gain=sqrt(innov_gain/st->frameSize);
       for (i=0;i<st->subframeSize;i++)
       {
@@ -1137,17 +1137,17 @@
    DecState *st;
    int i, sub;
    int pitch;
-   float pitch_gain[3];
+   spx_word16_t pitch_gain[3];
    spx_word32_t ol_gain=0;
    int ol_pitch=0;
    float ol_pitch_coef=0;
    int best_pitch=40;
-   float best_pitch_gain=0;
+   spx_word16_t best_pitch_gain=0;
    int wideband;
    int m;
    char *stack;
    spx_coef_t *awk1, *awk2, *awk3;
-   float pitch_average=0;
+   spx_word16_t pitch_average=0;
 #ifdef EPIC_48K
    int pitch_half[2];
    int ol_pitch_id=0;
@@ -1385,7 +1385,7 @@
    {
       int offset;
       spx_sig_t *sp, *exc;
-      float tmp;
+      spx_word16_t tmp;
 
 #ifdef EPIC_48K
       if (st->lbr_48k)
@@ -1509,25 +1509,13 @@
                exc[i]*=fact;
          }
 
-         tmp = ABS(pitch_gain[1]);
-         if (pitch_gain[0]>0)
-            tmp += pitch_gain[0];
-         else
-            tmp -= .5*pitch_gain[0];
-         if (pitch_gain[2]>0)
-            tmp += pitch_gain[2];
-         else
-            tmp -= .5*pitch_gain[2];
-
+         tmp = gain_3tap_to_1tap(pitch_gain);
 
          pitch_average += tmp;
          if (tmp>best_pitch_gain)
          {
             best_pitch = pitch;
             best_pitch_gain = tmp;
-	    /*            best_pitch_gain = tmp*.9;
-	                if (best_pitch_gain>.85)
-                        best_pitch_gain=.85;*/
          }
       } else {
          speex_error("No pitch prediction, what's wrong");
@@ -1666,7 +1654,7 @@
    st->first = 0;
    st->count_lost=0;
    st->last_pitch = best_pitch;
-   st->last_pitch_gain = .25*pitch_average;
+   st->last_pitch_gain = .25*GAIN_SCALING_1*pitch_average;
    st->pitch_gain_buf[st->pitch_gain_buf_idx++] = st->last_pitch_gain;
    if (st->pitch_gain_buf_idx > 2) /* rollover */
       st->pitch_gain_buf_idx = 0;

<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