[xiph-cvs] cvs commit: speex/libspeex lsp.c misc.h
Jean-Marc Valin
jm at xiph.org
Tue Oct 7 21:29:00 PDT 2003
jm 03/10/08 00:29:00
Modified: libspeex lsp.c misc.h
Log:
fixed-point work on LSP's
Revision Changes Path
1.25 +87 -37 speex/libspeex/lsp.c
Index: lsp.c
===================================================================
RCS file: /usr/local/cvsroot/speex/libspeex/lsp.c,v
retrieving revision 1.24
retrieving revision 1.25
diff -u -r1.24 -r1.25
--- lsp.c 8 Oct 2003 04:27:51 -0000 1.24
+++ lsp.c 8 Oct 2003 04:29:00 -0000 1.25
@@ -68,7 +68,59 @@
\*---------------------------------------------------------------------------*/
+#ifdef FIXED_POINT
+#define SCALE1 8192.
+#define SCALE2 16384.
+#define SCALE 16384.
+
+#include <stdio.h>
+
+
+static float cheb_poly_eva(float *coef,float x,int m,char *stack)
+/* float coef[] coefficients of the polynomial to be evaluated */
+/* float x the point where polynomial is to be evaluated */
+/* int m order of the polynomial */
+{
+ int i;
+ spx_word16_t *T;
+ spx_word32_t sum;
+ int m2=m>>1;
+ spx_word16_t xn;
+ spx_word16_t *coefn;
+
+ /* Allocate memory for Chebyshev series formulation */
+ T=PUSH(stack, m2+1, spx_word16_t);
+ coefn=PUSH(stack, m2+1, spx_word16_t);
+
+ xn = floor(.5+x*16384);
+
+ for (i=0;i<m2+1;i++)
+ {
+ coefn[i] = floor(.5+1024*coef[i]);
+ /*printf ("%f ", coef[i]);*/
+ }
+ /*printf ("\n");*/
+
+ /* Initialise values */
+ T[0]=16384;
+ T[1]=xn;
+
+ /* Evaluate Chebyshev series formulation using iterative approach */
+ /* Evaluate polynomial and return value also free memory space */
+ sum = coefn[m2] + MULT16_16_P14(coefn[m2-1],xn);
+ /*x *= 2;*/
+ for(i=2;i<=m2;i++)
+ {
+ T[i] = MULT16_16_Q13(xn,T[i-1]) - T[i-2];
+ sum += MULT16_16_P14(coefn[m2-i],T[i]);
+ /*printf ("%f ", sum);*/
+ }
+
+ /*printf ("\n");*/
+ return sum;
+}
+#else
static float cheb_poly_eva(float *coef,float x,int m,char *stack)
/* float coef[] coefficients of the polynomial to be evaluated */
/* float x the point where polynomial is to be evaluated */
@@ -97,7 +149,7 @@
return sum;
}
-
+#endif
/*---------------------------------------------------------------------------*\
@@ -247,7 +299,8 @@
\*---------------------------------------------------------------------------*/
-#if 0
+#if FIXED_POINT
+
void lsp_to_lpc(float *freq,spx_coef_t *ak,int lpcrdr, char *stack)
/* float *freq array of LSP frequencies in the x domain */
/* float *ak array of LPC coefficients */
@@ -256,14 +309,20 @@
{
int i,j;
- float xout1,xout2,xin1,xin2;
- float *Wp;
- float *pw,*n1,*n2,*n3,*n4=NULL;
+ spx_word32_t xout1,xout2,xin1,xin2;
+ spx_word32_t *Wp;
+ spx_word32_t *pw,*n1,*n2,*n3,*n4=NULL;
+ spx_word16_t *freqn;
int m = lpcrdr/2;
+
+ freqn = PUSH(stack, lpcrdr, spx_word16_t);
+ for (i=0;i<lpcrdr;i++)
+ freqn[i] = freq[i]*32768.;
- Wp = PUSH(stack, 4*m+2, float);
+ Wp = PUSH(stack, 4*m+2, spx_word32_t);
pw = Wp;
+
/* initialise contents of array */
for(i=0;i<=4*m+1;i++){ /* set contents of buffer to 0 */
@@ -273,8 +332,8 @@
/* Set pointers up */
pw = Wp;
- xin1 = 1.0;
- xin2 = 1.0;
+ xin1 = 1048576;
+ xin2 = 1048576;
/* reconstruct P(z) and Q(z) by cascading second order
polynomials in form 1 - 2xz(-1) +z(-2), where x is the
@@ -287,18 +346,18 @@
n2 = n1 + 1;
n3 = n2 + 1;
n4 = n3 + 1;
- xout1 = xin1 - 2*(freq[i2]) * *n1 + *n2;
- xout2 = xin2 - 2*(freq[i2+1]) * *n3 + *n4;
- *n2 = *n1;
- *n4 = *n3;
- *n1 = xin1;
- *n3 = xin2;
+ xout1 = xin1 - MULT16_32_Q14(freqn[i2],*n1) + *n2;
+ xout2 = xin2 - MULT16_32_Q14(freqn[i2+1],*n3) + *n4;
+ *n2 = floor(.5+*n1);
+ *n4 = floor(.5+*n3);
+ *n1 = floor(.5+xin1);
+ *n3 = floor(.5+xin2);
xin1 = xout1;
xin2 = xout2;
}
xout1 = xin1 + *(n4+1);
xout2 = xin2 - *(n4+2);
- ak[j] = (xout1 + xout2)*0.5;
+ ak[j] = ((128+xout1 + xout2)>>8)/8192.;
*(n4+1) = xin1;
*(n4+2) = xin2;
@@ -309,9 +368,6 @@
}
#else
-#define MULT16_32_Q14(a,b) (((a)*((b)>>14)) + ((a)*((signed int)((b)&0x00003fff))>>14))
-#define MULT16_32_Q15(a,b) (((a)*((b)>>15)) + ((a)*((signed int)((b)&0x00007fff))>>15))
-
void lsp_to_lpc(float *freq,spx_coef_t *ak,int lpcrdr, char *stack)
/* float *freq array of LSP frequencies in the x domain */
/* float *ak array of LPC coefficients */
@@ -320,20 +376,14 @@
{
int i,j;
- spx_word32_t xout1,xout2,xin1,xin2;
- spx_word32_t *Wp;
- spx_word32_t *pw,*n1,*n2,*n3,*n4=NULL;
- spx_word16_t *freqn;
+ float xout1,xout2,xin1,xin2;
+ float *Wp;
+ float *pw,*n1,*n2,*n3,*n4=NULL;
int m = lpcrdr/2;
-
- freqn = PUSH(stack, lpcrdr, spx_word16_t);
- for (i=0;i<lpcrdr;i++)
- freqn[i] = freq[i]*32768.;
- Wp = PUSH(stack, 4*m+2, spx_word32_t);
+ Wp = PUSH(stack, 4*m+2, float);
pw = Wp;
-
/* initialise contents of array */
for(i=0;i<=4*m+1;i++){ /* set contents of buffer to 0 */
@@ -343,8 +393,8 @@
/* Set pointers up */
pw = Wp;
- xin1 = 1048576;
- xin2 = 1048576;
+ xin1 = 1.0;
+ xin2 = 1.0;
/* reconstruct P(z) and Q(z) by cascading second order
polynomials in form 1 - 2xz(-1) +z(-2), where x is the
@@ -357,18 +407,18 @@
n2 = n1 + 1;
n3 = n2 + 1;
n4 = n3 + 1;
- xout1 = xin1 - MULT16_32_Q14(freqn[i2],*n1) + *n2;
- xout2 = xin2 - MULT16_32_Q14(freqn[i2+1],*n3) + *n4;
- *n2 = floor(.5+*n1);
- *n4 = floor(.5+*n3);
- *n1 = floor(.5+xin1);
- *n3 = floor(.5+xin2);
+ xout1 = xin1 - 2*(freq[i2]) * *n1 + *n2;
+ xout2 = xin2 - 2*(freq[i2+1]) * *n3 + *n4;
+ *n2 = *n1;
+ *n4 = *n3;
+ *n1 = xin1;
+ *n3 = xin2;
xin1 = xout1;
xin2 = xout2;
}
xout1 = xin1 + *(n4+1);
xout2 = xin2 - *(n4+2);
- ak[j] = ((128+xout1 + xout2)>>8)/8192.;
+ ak[j] = (xout1 + xout2)*0.5;
*(n4+1) = xin1;
*(n4+2) = xin2;
<p><p>1.22 +6 -0 speex/libspeex/misc.h
Index: misc.h
===================================================================
RCS file: /usr/local/cvsroot/speex/libspeex/misc.h,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -r1.21 -r1.22
--- misc.h 8 Oct 2003 04:27:51 -0000 1.21
+++ misc.h 8 Oct 2003 04:29:00 -0000 1.22
@@ -57,6 +57,12 @@
#define MULT16_32_Q14(a,b) (((a)*((b)>>14)) + ((a)*((signed int)((b)&0x00003fff))>>14))
#define MULT16_32_Q15(a,b) (((a)*((b)>>15)) + ((a)*((signed int)((b)&0x00007fff))>>15))
+#define MULT16_16_Q13(a,b) (((signed int)(a))*(b)>>13)
+#define MULT16_16_Q14(a,b) (((signed int)(a))*(b)>>14)
+#define MULT16_16_Q15(a,b) (((signed int)(a))*(b)>>15)
+
+#define MULT16_16_P14(a,b) ((8192+((signed int)(a))*(b))>>14)
+
#else
typedef float spx_mem_t;
<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