[xiph-cvs] cvs commit: speex/libspeex cb_search.c ltp.c misc.h nb_celp.c quant_lsp.c sb_celp.c smallft.c

Jean-Marc Valin jm at xiph.org
Tue Oct 7 22:11:25 PDT 2003



jm          03/10/08 01:11:25

  Modified:    libspeex cb_search.c ltp.c misc.h nb_celp.c quant_lsp.c
                        sb_celp.c smallft.c
  Log:
  fixed-point: rounding for shifts

Revision  Changes    Path
1.97      +2 -1      speex/libspeex/cb_search.c

Index: cb_search.c
===================================================================
RCS file: /usr/local/cvsroot/speex/libspeex/cb_search.c,v
retrieving revision 1.96
retrieving revision 1.97
diff -u -r1.96 -r1.97
--- cb_search.c	8 Oct 2003 04:52:27 -0000	1.96
+++ cb_search.c	8 Oct 2003 05:11:25 -0000	1.97
@@ -117,7 +117,8 @@
       for (j=0;j<nb_subvect;j++)
          nind[i][j]=oind[i][j]=-1;
    }
-
+   
+   /* FIXME: make that adaptive? */
    for (i=0;i<nsf;i++)
       t[i]=SHR(target[i],6);
 

<p><p>1.85      +9 -9      speex/libspeex/ltp.c

Index: ltp.c
===================================================================
RCS file: /usr/local/cvsroot/speex/libspeex/ltp.c,v
retrieving revision 1.84
retrieving revision 1.85
diff -u -r1.84 -r1.85
--- ltp.c	8 Oct 2003 05:09:04 -0000	1.84
+++ ltp.c	8 Oct 2003 05:11:25 -0000	1.85
@@ -313,15 +313,15 @@
          g2=ptr[2]+32;
 
          /* FIXME: check for possible overflows on sum and MULT16_32 */
-         sum += MULT16_32_Q14(MULT16_16(g0,64),C[0]);
-         sum += MULT16_32_Q14(MULT16_16(g1,64),C[1]);
-         sum += MULT16_32_Q14(MULT16_16(g2,64),C[2]);
-         sum -= MULT16_32_Q14(MULT16_16(g0,g1),C[3]);
-         sum -= MULT16_32_Q14(MULT16_16(g2,g1),C[4]);
-         sum -= MULT16_32_Q14(MULT16_16(g2,g0),C[5]);
-         sum -= MULT16_32_Q15(MULT16_16(g0,g0),C[6]);
-         sum -= MULT16_32_Q15(MULT16_16(g1,g1),C[7]);
-         sum -= MULT16_32_Q15(MULT16_16(g2,g2),C[8]);
+         sum += MULT16_32_Q14(MULT16_16_16(g0,64),C[0]);
+         sum += MULT16_32_Q14(MULT16_16_16(g1,64),C[1]);
+         sum += MULT16_32_Q14(MULT16_16_16(g2,64),C[2]);
+         sum -= MULT16_32_Q14(MULT16_16_16(g0,g1),C[3]);
+         sum -= MULT16_32_Q14(MULT16_16_16(g2,g1),C[4]);
+         sum -= MULT16_32_Q14(MULT16_16_16(g2,g0),C[5]);
+         sum -= MULT16_32_Q15(MULT16_16_16(g0,g0),C[6]);
+         sum -= MULT16_32_Q15(MULT16_16_16(g1,g1),C[7]);
+         sum -= MULT16_32_Q15(MULT16_16_16(g2,g2),C[8]);
 
          /* If 1, force "safe" pitch values to handle packet loss better */
          if (0) {

<p><p>1.34      +8 -2      speex/libspeex/misc.h

Index: misc.h
===================================================================
RCS file: /usr/local/cvsroot/speex/libspeex/misc.h,v
retrieving revision 1.33
retrieving revision 1.34
diff -u -r1.33 -r1.34
--- misc.h	8 Oct 2003 05:01:18 -0000	1.33
+++ misc.h	8 Oct 2003 05:11:25 -0000	1.34
@@ -41,8 +41,8 @@
 
 #ifdef FIXED_POINT
 
-typedef short        spx_word16_t;
-typedef int          spx_word32_t;
+typedef signed short spx_word16_t;
+typedef signed int   spx_word32_t;
 typedef spx_word32_t spx_mem_t;
 typedef spx_word16_t spx_coef_t;
 typedef spx_word32_t spx_sig_t;
@@ -53,9 +53,13 @@
 #define LPC_SHIFT    13
 #define SIG_SHIFT    14
 
+#define PSHR(a,shift) (((a)+(1<<((shift)-1))) >> (shift))
 #define SHR(a,shift) ((a) >> (shift))
 #define SHL(a,shift) ((a) << (shift))
 
+/* result fits in 16 bits */
+#define MULT16_16_16(a,b)     (((short)(a))*(b))
+
 #define MULT16_16(a,b)     (((signed int)(a))*(b))
 #define MULT16_32_Q13(a,b) (((a)*((b)>>13)) + ((a)*((signed int)((b)&0x00001fff))>>13))
 #define MULT16_32_Q14(a,b) (((a)*((b)>>14)) + ((a)*((signed int)((b)&0x00003fff))>>14))
@@ -84,8 +88,10 @@
 #define LPC_SHIFT    0
 #define SIG_SHIFT    0
 
+#define PSHR(a,shift)       (a)
 #define SHR(a,shift)       (a)
 #define SHL(a,shift)       (a)
+#define MULT16_16_16(a,b)     ((a)*(b))
 #define MULT16_16(a,b)     ((a)*(b))
 
 #define MULT16_32_Q13(a,b)     ((a)*(b))

<p><p>1.137     +4 -4      speex/libspeex/nb_celp.c

Index: nb_celp.c
===================================================================
RCS file: /usr/local/cvsroot/speex/libspeex/nb_celp.c,v
retrieving revision 1.136
retrieving revision 1.137
diff -u -r1.136 -r1.137
--- nb_celp.c	8 Oct 2003 05:06:01 -0000	1.136
+++ nb_celp.c	8 Oct 2003 05:11:25 -0000	1.137
@@ -890,7 +890,7 @@
 
    /* Replace input by synthesized speech */
    for (i=0;i<st->frameSize;i++)
-     in[i]=SHR(st->frame[i],SIG_SHIFT);
+     in[i]=PSHR(st->frame[i],SIG_SHIFT);
 
    if (SUBMODE(innovation_quant) == noise_codebook_quant || st->submodeID==0)
       st->bounded_pitch = 1;
@@ -1087,7 +1087,7 @@
    }
 
    for (i=0;i<st->frameSize;i++)
-      out[i]=SHR(st->frame[i],SIG_SHIFT);
+      out[i]=PSHR(st->frame[i],SIG_SHIFT);
    
    st->first = 0;
    st->count_lost++;
@@ -1247,7 +1247,7 @@
       iir_mem2(st->exc, lpc, st->frame, st->frameSize, st->lpcSize, st->mem_sp);
 
       for (i=0;i<st->frameSize;i++)
-         out[i]=SHR(st->frame[i],SIG_SHIFT);
+         out[i]=PSHR(st->frame[i],SIG_SHIFT);
       st->count_lost=0;
       return 0;
    }
@@ -1599,7 +1599,7 @@
    
    /*Copy output signal*/
    for (i=0;i<st->frameSize;i++)
-     out[i]=SHR(st->frame[i],SIG_SHIFT);
+     out[i]=PSHR(st->frame[i],SIG_SHIFT);
 
    /*for (i=0;i<st->frameSize;i++)
      printf ("%d\n", (int)st->frame[i]);*/

<p><p>1.25      +15 -5     speex/libspeex/quant_lsp.c

Index: quant_lsp.c
===================================================================
RCS file: /usr/local/cvsroot/speex/libspeex/quant_lsp.c,v
retrieving revision 1.24
retrieving revision 1.25
diff -u -r1.24 -r1.25
--- quant_lsp.c	8 Oct 2003 05:06:01 -0000	1.24
+++ quant_lsp.c	8 Oct 2003 05:11:25 -0000	1.25
@@ -34,8 +34,6 @@
 #include <math.h>
 #include "misc.h"
 
-extern int lsp_nb_vqid[64];
-
 /* FIXME: Get rid of this kludge quick before someone gets hurt */
 static spx_word16_t quant_weight[MAX_LSP_SIZE];
 
@@ -134,9 +132,13 @@
    for (i=0;i<order;i++)
       qlsp[i]-=(.25*i+.25);
 
+#ifdef FIXED_POINT
+   for (i=0;i<order;i++)
+      nlsp[i]=floor(.5+qlsp[i]*LSP_SCALE);
+#else
    for (i=0;i<order;i++)
       nlsp[i] = LSP_SCALE*qlsp[i];
-
+#endif
    id = lsp_quant(nlsp, cdbk_nb, NB_CDBK_SIZE, order);
    speex_bits_pack(bits, id, 6);
 
@@ -223,9 +225,13 @@
 
    for (i=0;i<order;i++)
       qlsp[i]-=(.25*i+.25);
+#ifdef FIXED_POINT
+   for (i=0;i<order;i++)
+      nlsp[i]=floor(.5+qlsp[i]*LSP_SCALE);
+#else
    for (i=0;i<order;i++)
       nlsp[i]=qlsp[i]*LSP_SCALE;
-   
+#endif   
    id = lsp_quant(nlsp, cdbk_nb, NB_CDBK_SIZE, order);
    speex_bits_pack(bits, id, 6);
 
@@ -292,9 +298,13 @@
 
    for (i=0;i<order;i++)
       qlsp[i]-=(.3125*i+.75);
+#ifdef FIXED_POINT
+   for (i=0;i<order;i++)
+      nlsp[i] = floor(.5+qlsp[i]*LSP_SCALE);
+#else
    for (i=0;i<order;i++)
       nlsp[i] = qlsp[i]*LSP_SCALE;
-
+#endif
    id = lsp_quant(nlsp, high_lsp_cdbk, 64, order);
    speex_bits_pack(bits, id, 6);
 

<p><p>1.139     +3 -3      speex/libspeex/sb_celp.c

Index: sb_celp.c
===================================================================
RCS file: /usr/local/cvsroot/speex/libspeex/sb_celp.c,v
retrieving revision 1.138
retrieving revision 1.139
diff -u -r1.138 -r1.139
--- sb_celp.c	8 Oct 2003 05:06:01 -0000	1.138
+++ sb_celp.c	8 Oct 2003 05:11:25 -0000	1.139
@@ -814,7 +814,7 @@
 
 #ifdef FIXED_POINT
    for (i=0;i<st->full_frame_size;i++)
-      out[i]=SHR(st->y0[i]-st->y1[i],SIG_SHIFT-1);
+      out[i]=PSHR(st->y0[i]-st->y1[i],SIG_SHIFT-1);
 #else
    for (i=0;i<st->full_frame_size;i++)
       out[i]=2*(st->y0[i]-st->y1[i]);   
@@ -917,7 +917,7 @@
 
 #ifdef FIXED_POINT
       for (i=0;i<st->full_frame_size;i++)
-         out[i]=SHR(st->y0[i]-st->y1[i],SIG_SHIFT-1);
+         out[i]=PSHR(st->y0[i]-st->y1[i],SIG_SHIFT-1);
 #else
       for (i=0;i<st->full_frame_size;i++)
          out[i]=2*(st->y0[i]-st->y1[i]);   
@@ -1084,7 +1084,7 @@
 
 #ifdef FIXED_POINT
    for (i=0;i<st->full_frame_size;i++)
-      out[i]=SHR(st->y0[i]-st->y1[i],SIG_SHIFT-1);
+      out[i]=PSHR(st->y0[i]-st->y1[i],SIG_SHIFT-1);
 #else
    for (i=0;i<st->full_frame_size;i++)
       out[i]=2*(st->y0[i]-st->y1[i]);   

<p><p>1.18      +0 -0      speex/libspeex/smallft.c

Index: smallft.c
===================================================================
RCS file: /usr/local/cvsroot/speex/libspeex/smallft.c,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -r1.17 -r1.18
--- smallft.c	8 Oct 2003 05:09:04 -0000	1.17
+++ smallft.c	8 Oct 2003 05:11:25 -0000	1.18
@@ -11,7 +11,7 @@
  ********************************************************************
 
  function: *unnormalized* fft transform
- last mod: $Id: smallft.c,v 1.17 2003/10/08 05:09:04 jm Exp $
+ last mod: $Id: smallft.c,v 1.18 2003/10/08 05:11:25 jm Exp $
 
  ********************************************************************/
 

<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