[xiph-cvs] cvs commit: speex/libspeex cb_search.c lpc.c lsp.c ltp.c misc.h quant_lsp.c
Jean-Marc Valin
jm at xiph.org
Sat Nov 1 21:08:57 PST 2003
jm 03/11/02 00:08:57
Modified: libspeex cb_search.c lpc.c lsp.c ltp.c misc.h quant_lsp.c
Log:
fixed-point: cleaned up operators, removed a couple float ops, fixed a
MULT16_16 that had a 32-bit operand in ltp.c
Revision Changes Path
1.98 +1 -1 speex/libspeex/cb_search.c
Index: cb_search.c
===================================================================
RCS file: /usr/local/cvsroot/speex/libspeex/cb_search.c,v
retrieving revision 1.97
retrieving revision 1.98
diff -u -r1.97 -r1.98
--- cb_search.c 8 Oct 2003 05:11:25 -0000 1.97
+++ cb_search.c 2 Nov 2003 05:08:56 -0000 1.98
@@ -235,7 +235,7 @@
#ifdef FIXED_POINT
g=sign*shape_cb[rind*subvect_size+m];
for (n=subvect_size*(i+1);n<nsf;n++,q++)
- t[n] -= SHR(MULT16_16(g,r[q]),11);
+ t[n] -= MULT16_32_Q11(g,r[q]);
#else
g=sign*0.03125*shape_cb[rind*subvect_size+m];
for (n=subvect_size*(i+1);n<nsf;n++,q++)
<p><p>1.18 +1 -1 speex/libspeex/lpc.c
Index: lpc.c
===================================================================
RCS file: /usr/local/cvsroot/speex/libspeex/lpc.c,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -r1.17 -r1.18
--- lpc.c 8 Oct 2003 05:09:04 -0000 1.17
+++ lpc.c 2 Nov 2003 05:08:56 -0000 1.18
@@ -131,7 +131,7 @@
int shift, ac_shift;
for (j=0;j<n;j++)
- ac0 += MULT16_16(x[j],x[j])/256;
+ ac0 += SHR(MULT16_16(x[j],x[j]),8);
ac0 += n;
shift = 8;
while (shift && ac0<0x40000000)
<p><p>1.35 +7 -0 speex/libspeex/lsp.c
Index: lsp.c
===================================================================
RCS file: /usr/local/cvsroot/speex/libspeex/lsp.c,v
retrieving revision 1.34
retrieving revision 1.35
diff -u -r1.34 -r1.35
--- lsp.c 1 Nov 2003 17:42:22 -0000 1.34
+++ lsp.c 2 Nov 2003 05:08:56 -0000 1.35
@@ -79,8 +79,15 @@
#define ANGLE2X(a) (SHL(cos_32(a),2))
#define X2ANGLE(x) (acos(x)*LSP_SCALING)
+/* maybe we could approximate acos as
+ sqrt(6.7349563814-5.213449731*sqrt(0.6688572663+x))
+*/
#else
+#define C1 0.99940307
+#define C2 -0.49558072
+#define C3 0.03679168
+
#define ANGLE2X(a) (cos(a))
#define X2ANGLE(x) (acos(x))
<p><p>1.92 +3 -3 speex/libspeex/ltp.c
Index: ltp.c
===================================================================
RCS file: /usr/local/cvsroot/speex/libspeex/ltp.c,v
retrieving revision 1.91
retrieving revision 1.92
diff -u -r1.91 -r1.92
--- ltp.c 28 Oct 2003 01:02:17 -0000 1.91
+++ ltp.c 2 Nov 2003 05:08:56 -0000 1.92
@@ -390,12 +390,12 @@
#ifdef FIXED_POINT
for (i=0;i<nsf;i++)
- exc[i]=MULT16_16(sgain[0],SHR(e[2][i],6))+MULT16_16(sgain[1],SHR(e[1][i],6))+MULT16_16(sgain[2],SHR(e[0][i],6));
+ exc[i]=MULT16_32_Q13(SHL(sgain[0],7),e[2][i])+MULT16_32_Q13(SHL(sgain[1],7),e[1][i])+MULT16_32_Q13(SHL(sgain[2],7),e[0][i]);
err=0;
for (i=0;i<nsf;i++)
{
- spx_sig_t perr=target[i]-(MULT16_16(sgain[0],SHR(x[2][i],6))+MULT16_16(sgain[1],SHR(x[1][i],6))+MULT16_16(sgain[2],SHR(x[0][i],6)));
+ 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);
@@ -620,7 +620,7 @@
sgain[1] = 64*gain[1];
sgain[2] = 64*gain[2];
for (i=0;i<nsf;i++)
- exc[i]=MULT16_16(sgain[0],SHR(e[2][i],6))+MULT16_16(sgain[1],SHR(e[1][i],6))+MULT16_16(sgain[2],SHR(e[0][i],6));
+ exc[i]=MULT16_32_Q13(SHL(sgain[0],7),e[2][i])+MULT16_32_Q13(SHL(sgain[1],7),e[1][i])+MULT16_32_Q13(SHL(sgain[2],7),e[0][i]);
}
#else
for (i=0;i<nsf;i++)
<p><p>1.38 +16 -10 speex/libspeex/misc.h
Index: misc.h
===================================================================
RCS file: /usr/local/cvsroot/speex/libspeex/misc.h,v
retrieving revision 1.37
retrieving revision 1.38
diff -u -r1.37 -r1.38
--- misc.h 27 Oct 2003 23:05:53 -0000 1.37
+++ misc.h 2 Nov 2003 05:08:56 -0000 1.38
@@ -59,19 +59,25 @@
#define SHR(a,shift) ((a) >> (shift))
#define SHL(a,shift) ((a) << (shift))
+#define ADD16(a,b) ((a)+(b))
+#define ADD32(a,b) ((a)+(b))
+
/* result fits in 16 bits */
-#define MULT16_16_16(a,b) (((short)(a))*(b))
+#define MULT16_16_16(a,b) (((short)(a))*((short)(b)))
+
+/* Kludge: just making sure results are on 32 bits */
+#define MULT16_16(a,b) (((int)(a))*((short)(b)))
+
+#define MULT16_32_Q11(a,b) ADD32(MULT16_16((a),SHR((b),11)), SHR(MULT16_16((a),((b)&0x000007ff)),11))
+#define MULT16_32_Q13(a,b) ADD32(MULT16_16((a),SHR((b),13)), SHR(MULT16_16((a),((b)&0x00001fff)),13))
+#define MULT16_32_Q14(a,b) ADD32(MULT16_16((a),SHR((b),14)), SHR(MULT16_16((a),((b)&0x00003fff)),14))
+#define MULT16_32_Q15(a,b) ADD32(MULT16_16((a),SHR((b),15)), SHR(MULT16_16((a),((b)&0x00007fff)),15))
-#define MULT16_16(a,b) (((a))*(b))
-#define MULT16_32_Q13(a,b) (((a)*((b)>>13)) + ((a)*((short)((b)&0x00001fff))>>13))
-#define MULT16_32_Q14(a,b) (((a)*((b)>>14)) + ((a)*((short)((b)&0x00003fff))>>14))
-#define MULT16_32_Q15(a,b) (((a)*((b)>>15)) + ((a)*((short)((b)&0x00007fff))>>15))
-
-#define MULT16_16_Q13(a,b) (((short)(a))*(b)>>13)
-#define MULT16_16_Q14(a,b) (((short)(a))*(b)>>14)
-#define MULT16_16_Q15(a,b) (((short)(a))*(b)>>15)
+#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_P14(a,b) ((8192+((short)(a))*(b))>>14)
+#define MULT16_16_P14(a,b) (SHR(ADD16(8192,MULT16_16((a),(b))),14))
#define DIV32_16(a,b) (((signed int)(a))/(b))
<p><p>1.29 +17 -8 speex/libspeex/quant_lsp.c
Index: quant_lsp.c
===================================================================
RCS file: /usr/local/cvsroot/speex/libspeex/quant_lsp.c,v
retrieving revision 1.28
retrieving revision 1.29
diff -u -r1.28 -r1.29
--- quant_lsp.c 1 Nov 2003 17:42:22 -0000 1.28
+++ quant_lsp.c 2 Nov 2003 05:08:56 -0000 1.29
@@ -39,9 +39,18 @@
#ifdef FIXED_POINT
#define LSP_LINEAR(i) (SHL(i+1,11))
+#define LSP_DIV_256(x) (SHL((spx_word16_t)x, 5))
+#define LSP_DIV_512(x) (SHL((spx_word16_t)x, 4))
+#define LSP_DIV_1024(x) (SHL((spx_word16_t)x, 3))
+
#else
+
#define LSP_LINEAR(i) (.25*(i)+.25)
#define LSP_SCALE 256.
+#define LSP_DIV_256(x) (0.0039062*(x))
+#define LSP_DIV_512(x) (0.0019531*(x))
+#define LSP_DIV_1024(x) (0.00097656*(x))
+
#endif
static void compute_quant_weights(spx_lsp_t *qlsp, spx_word16_t *quant_weight, int order)
@@ -188,23 +197,23 @@
id=speex_bits_unpack_unsigned(bits, 6);
for (i=0;i<10;i++)
- lsp[i] += LSP_SCALING*(0.0039062*cdbk_nb[id*10+i]);
+ lsp[i] += LSP_DIV_256(cdbk_nb[id*10+i]);
id=speex_bits_unpack_unsigned(bits, 6);
for (i=0;i<5;i++)
- lsp[i] += LSP_SCALING*(0.0019531 * cdbk_nb_low1[id*5+i]);
+ lsp[i] += LSP_DIV_512(cdbk_nb_low1[id*5+i]);
id=speex_bits_unpack_unsigned(bits, 6);
for (i=0;i<5;i++)
- lsp[i] += LSP_SCALING*(0.00097656 * cdbk_nb_low2[id*5+i]);
+ lsp[i] += LSP_DIV_1024(cdbk_nb_low2[id*5+i]);
id=speex_bits_unpack_unsigned(bits, 6);
for (i=0;i<5;i++)
- lsp[i+5] += LSP_SCALING*(0.0019531 * cdbk_nb_high1[id*5+i]);
+ lsp[i+5] += LSP_DIV_512(cdbk_nb_high1[id*5+i]);
id=speex_bits_unpack_unsigned(bits, 6);
for (i=0;i<5;i++)
- lsp[i+5] += LSP_SCALING*(0.00097656 * cdbk_nb_high2[id*5+i]);
+ lsp[i+5] += LSP_DIV_1024(cdbk_nb_high2[id*5+i]);
}
@@ -258,15 +267,15 @@
id=speex_bits_unpack_unsigned(bits, 6);
for (i=0;i<10;i++)
- lsp[i] += LSP_SCALING*0.0039062*cdbk_nb[id*10+i];
+ lsp[i] += LSP_DIV_256(cdbk_nb[id*10+i]);
id=speex_bits_unpack_unsigned(bits, 6);
for (i=0;i<5;i++)
- lsp[i] += LSP_SCALING*0.0019531*cdbk_nb_low1[id*5+i];
+ lsp[i] += LSP_DIV_512(cdbk_nb_low1[id*5+i]);
id=speex_bits_unpack_unsigned(bits, 6);
for (i=0;i<5;i++)
- lsp[i+5] += LSP_SCALING*0.0019531*cdbk_nb_high1[id*5+i];
+ lsp[i+5] += LSP_DIV_512(cdbk_nb_high1[id*5+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