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

Jean-Marc Valin jm at xiph.org
Mon Nov 10 11:28:21 PST 2003



jm          03/11/10 14:28:21

  Modified:    libspeex filters.c ltp.c misc.h nb_celp.c
  Log:
  fixed-point: integerized pi_gain, pitch prediction error accumulation in
  64 bits (should make that 32 if possible).

Revision  Changes    Path
1.58      +2 -2      speex/libspeex/filters.c

Index: filters.c
===================================================================
RCS file: /usr/local/cvsroot/speex/libspeex/filters.c,v
retrieving revision 1.57
retrieving revision 1.58
diff -u -r1.57 -r1.58
--- filters.c	10 Nov 2003 17:17:33 -0000	1.57
+++ filters.c	10 Nov 2003 19:28:20 -0000	1.58
@@ -46,8 +46,8 @@
    spx_word16_t tmp=g;
    for (i=1;i<order+1;i++)
    {
-      lpc_out[i] = MULT16_16_Q15(tmp,lpc_in[i]);
-      tmp = MULT16_16_Q15(tmp, g);
+      lpc_out[i] = MULT16_16_P15(tmp,lpc_in[i]);
+      tmp = MULT16_16_P15(tmp, g);
    }
 }
 #else

<p><p>1.95      +4 -4      speex/libspeex/ltp.c

Index: ltp.c
===================================================================
RCS file: /usr/local/cvsroot/speex/libspeex/ltp.c,v
retrieving revision 1.94
retrieving revision 1.95
diff -u -r1.94 -r1.95
--- ltp.c	9 Nov 2003 06:20:33 -0000	1.94
+++ ltp.c	10 Nov 2003 19:28:20 -0000	1.95
@@ -183,7 +183,7 @@
 
 
 /** Finds the best quantized 3-tap pitch predictor by analysis by synthesis */
-static float pitch_gain_search_3tap(
+static spx_word64_t pitch_gain_search_3tap(
 spx_sig_t target[],                 /* Target vector */
 spx_coef_t ak[],                     /* LPCs for this subframe */
 spx_coef_t awk1[],                   /* Weighted LPCs #1 for this subframe */
@@ -211,7 +211,7 @@
    int   gain_cdbk_size;
    signed char *gain_cdbk;
    spx_word16_t sgain[3];
-   float err;
+   spx_word64_t err;
 
    ltp_params *params;
    params = (ltp_params*) par;
@@ -403,7 +403,7 @@
    {
       spx_sig_t perr=target[i]-(MULT16_32_Q13(SHL(sgain[0],7),x[2][i])+MULT16_32_Q13(SHL(sgain[1],7),x[1][i])+MULT16_32_Q13(SHL(sgain[2],7),x[0][i]));
       spx_word16_t perr2 = SHR(perr,15);
-      err += MULT16_16(perr2,perr2);
+      err = ADD64(err,MULT16_16(perr2,perr2));
       
    }
 #else
@@ -446,7 +446,7 @@
    int cdbk_index, pitch=0, best_gain_index=0;
    spx_sig_t *best_exc;
    int best_pitch=0;
-   float err, best_err=-1;
+   spx_word64_t err, best_err=-1;
    int N;
    ltp_params *params;
    int *nbest;

<p><p>1.44      +8 -0      speex/libspeex/misc.h

Index: misc.h
===================================================================
RCS file: /usr/local/cvsroot/speex/libspeex/misc.h,v
retrieving revision 1.43
retrieving revision 1.44
diff -u -r1.43 -r1.44
--- misc.h	10 Nov 2003 08:57:27 -0000	1.43
+++ misc.h	10 Nov 2003 19:28:20 -0000	1.44
@@ -43,6 +43,7 @@
 
 typedef signed short spx_word16_t;
 typedef signed int   spx_word32_t;
+typedef long long    spx_word64_t;
 typedef spx_word32_t spx_mem_t;
 typedef spx_word16_t spx_coef_t;
 typedef spx_word16_t spx_lsp_t;
@@ -68,6 +69,7 @@
 #define ADD16(a,b) (spx_mips++,(a)+(b))
 #define SUB16(a,b) (spx_mips++,(a)-(b))
 #define ADD32(a,b) (spx_mips++,(a)+(b))
+#define ADD64(a,b) (spx_mips++,(a)+(b))
 #define SUB32(a,b) (spx_mips++,(a)-(b))
 #define MULT16_16_16(a,b)     (spx_mips++,((short)(a))*((short)(b)))
 
@@ -90,6 +92,7 @@
 #define SUB16(a,b) ((a)-(b))
 #define ADD32(a,b) ((a)+(b))
 #define SUB32(a,b) ((a)-(b))
+#define ADD64(a,b) ((a)+(b))
 
 /* result fits in 16 bits */
 #define MULT16_16_16(a,b)     (((short)(a))*((short)(b)))
@@ -126,11 +129,14 @@
 #define MULT16_32_Q15(a,b) ADD32(MULT16_16((a),SHR((b),15)), SHR(MULT16_16((a),((b)&0x00007fff)),15))
 #endif
 
+
 #define MULT16_16_Q13(a,b) (SHR(MULT16_16((a),(b)),13))
 #define MULT16_16_Q14(a,b) (SHR(MULT16_16((a),(b)),14))
 #define MULT16_16_Q15(a,b) (SHR(MULT16_16((a),(b)),15))
 
+#define MULT16_16_P13(a,b) (SHR(ADD16(4096,MULT16_16((a),(b))),13))
 #define MULT16_16_P14(a,b) (SHR(ADD16(8192,MULT16_16((a),(b))),14))
+#define MULT16_16_P15(a,b) (SHR(ADD16(16384,MULT16_16((a),(b))),15))
 
 #define MUL_16_32_R15(a,bh,bl) ADD32(MULT16_16((a),(bh)), SHR(MULT16_16((a),(bl)),15))
 
@@ -146,6 +152,7 @@
 typedef float spx_sig_t;
 typedef float spx_word16_t;
 typedef float spx_word32_t;
+typedef float spx_word64_t;
 
 #define LPC_SCALING  1.
 #define SIG_SCALING  1.
@@ -161,6 +168,7 @@
 #define SUB16(a,b) ((a)-(b))
 #define ADD32(a,b) ((a)+(b))
 #define SUB32(a,b) ((a)-(b))
+#define ADD64(a,b) ((a)+(b))
 #define MULT16_16_16(a,b)     ((a)*(b))
 #define MULT16_16(a,b)     ((a)*(b))
 

<p><p>1.146     +16 -18    speex/libspeex/nb_celp.c

Index: nb_celp.c
===================================================================
RCS file: /usr/local/cvsroot/speex/libspeex/nb_celp.c,v
retrieving revision 1.145
retrieving revision 1.146
diff -u -r1.145 -r1.146
--- nb_celp.c	10 Nov 2003 08:57:27 -0000	1.145
+++ nb_celp.c	10 Nov 2003 19:28:20 -0000	1.146
@@ -199,7 +199,6 @@
    spx_mem_t *mem;
    char *stack;
    spx_sig_t *syn_resp;
-   float lsp_dist=0;
    spx_sig_t *orig;
 #ifdef EPIC_48K
    int pitch_half[2];
@@ -259,10 +258,6 @@
    }
 
 
-   lsp_dist=0;
-   for (i=0;i<st->lpcSize;i++)
-      lsp_dist += (st->old_lsp[i] - st->lsp[i])*(st->old_lsp[i] - st->lsp[i]);
-   lsp_dist /= LSP_SCALING*LSP_SCALING;
 
    /* Whole frame analysis (open-loop estimation of pitch and excitation gain) */
    {
@@ -359,6 +354,10 @@
    /*VBR stuff*/
    if (st->vbr && (st->vbr_enabled||st->vad_enabled))
    {
+      float lsp_dist=0;
+      for (i=0;i<st->lpcSize;i++)
+         lsp_dist += (st->old_lsp[i] - st->lsp[i])*(st->old_lsp[i] - st->lsp[i]);
+      lsp_dist /= LSP_SCALING*LSP_SCALING;
       
       if (st->abr_enabled)
       {
@@ -593,7 +592,6 @@
    /* Loop on sub-frames */
    for (sub=0;sub<st->nbSubframes;sub++)
    {
-      float tmp;
       int   offset;
       spx_sig_t *sp, *sw, *exc, *exc2;
       int pitch;
@@ -634,14 +632,14 @@
       lsp_to_lpc(st->interp_qlsp, st->interp_qlpc, st->lpcSize, stack);
 
       /* Compute analysis filter gain at w=pi (for use in SB-CELP) */
-      tmp=1;
-      st->pi_gain[sub]=0;
-      for (i=0;i<=st->lpcSize;i++)
       {
-         st->pi_gain[sub] += tmp*st->interp_qlpc[i];
-         tmp = -tmp;
+         spx_word32_t pi_g=st->interp_qlpc[0];
+         for (i=1;i<=st->lpcSize;i+=2)
+         {
+            pi_g += -st->interp_qlpc[i] +  st->interp_qlpc[i+1];
+         }
+         st->pi_gain[sub] = (float)pi_g / LPC_SCALING;
       }
-      st->pi_gain[sub] /= LPC_SCALING;
 
 
       /* Compute bandwidth-expanded (unquantized) LPCs for perceptual weighting */
@@ -1395,14 +1393,14 @@
       }
 
       /* Compute analysis filter at w=pi */
-      tmp=1;
-      st->pi_gain[sub]=0;
-      for (i=0;i<=st->lpcSize;i++)
       {
-         st->pi_gain[sub] += tmp*st->interp_qlpc[i];
-         tmp = -tmp;
+         spx_word32_t pi_g=st->interp_qlpc[0];
+         for (i=1;i<=st->lpcSize;i+=2)
+         {
+            pi_g += -st->interp_qlpc[i] +  st->interp_qlpc[i+1];
+         }
+         st->pi_gain[sub] = (float)pi_g / LPC_SCALING;
       }
-      st->pi_gain[sub] /= LPC_SCALING;
 
       /* Reset excitation */
       for (i=0;i<st->subframeSize;i++)

<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