Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mumble-voip/speexdsp.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjm <jm@0101bb08-14d6-0310-b084-bc0e0c8e3800>2003-10-08 08:27:52 +0400
committerjm <jm@0101bb08-14d6-0310-b084-bc0e0c8e3800>2003-10-08 08:27:52 +0400
commitb958f5641457cf673ab339b3913e99d4e8292f79 (patch)
tree57cfa5ad2ae6c2b8ea3c466b9229be46f86998c2
parentaa17e8e86addf57c0b6e825661afc5c73a8f862c (diff)
first step in fixed-point port, converted the LPC filters
git-svn-id: http://svn.xiph.org/trunk/speex@5410 0101bb08-14d6-0310-b084-bc0e0c8e3800
-rw-r--r--libspeex/cb_search.c15
-rw-r--r--libspeex/cb_search.h13
-rw-r--r--libspeex/filters.c128
-rw-r--r--libspeex/filters.h15
-rw-r--r--libspeex/lpc.c4
-rw-r--r--libspeex/lpc.h4
-rw-r--r--libspeex/lsp.c77
-rw-r--r--libspeex/lsp.h6
-rw-r--r--libspeex/ltp.c18
-rw-r--r--libspeex/ltp.h14
-rw-r--r--libspeex/misc.h22
-rw-r--r--libspeex/modes.h8
-rw-r--r--libspeex/nb_celp.c47
-rw-r--r--libspeex/nb_celp.h22
-rw-r--r--libspeex/preprocess.c15
-rw-r--r--libspeex/sb_celp.c41
-rw-r--r--libspeex/sb_celp.h22
-rw-r--r--libspeex/testenc.c4
-rw-r--r--src/speexdec.c1
19 files changed, 337 insertions, 139 deletions
diff --git a/libspeex/cb_search.c b/libspeex/cb_search.c
index ce45264..04e775b 100644
--- a/libspeex/cb_search.c
+++ b/libspeex/cb_search.c
@@ -38,9 +38,9 @@
void split_cb_search_shape_sign(
float target[], /* target vector */
-float ak[], /* LPCs for this subframe */
-float awk1[], /* Weighted LPCs for this subframe */
-float awk2[], /* Weighted LPCs for this subframe */
+spx_coef_t ak[], /* LPCs for this subframe */
+spx_coef_t awk1[], /* Weighted LPCs for this subframe */
+spx_coef_t awk2[], /* Weighted LPCs for this subframe */
void *par, /* Codebook/search parameters*/
int p, /* number of LPC coeffs */
int nsf, /* number of samples in subframe */
@@ -136,8 +136,7 @@ int complexity
{
res[j]=0;
for (k=0;k<=j;k++)
- res[j] += shape[k]*r[j-k];
- res[j] *= 0.03125;
+ res[j] += 0.03125*shape[k]*r[j-k];
}
/* Compute codeword energy */
@@ -351,9 +350,9 @@ char *stack
void noise_codebook_quant(
float target[], /* target vector */
-float ak[], /* LPCs for this subframe */
-float awk1[], /* Weighted LPCs for this subframe */
-float awk2[], /* Weighted LPCs for this subframe */
+spx_coef_t ak[], /* LPCs for this subframe */
+spx_coef_t awk1[], /* Weighted LPCs for this subframe */
+spx_coef_t awk2[], /* Weighted LPCs for this subframe */
void *par, /* Codebook/search parameters*/
int p, /* number of LPC coeffs */
int nsf, /* number of samples in subframe */
diff --git a/libspeex/cb_search.h b/libspeex/cb_search.h
index dea5589..415aec1 100644
--- a/libspeex/cb_search.h
+++ b/libspeex/cb_search.h
@@ -34,6 +34,7 @@
#define CB_SEARCH_H
#include "speex_bits.h"
+#include "misc.h"
typedef struct split_cb_params {
int subvect_size;
@@ -46,9 +47,9 @@ typedef struct split_cb_params {
void split_cb_search_shape_sign(
float target[], /* target vector */
-float ak[], /* LPCs for this subframe */
-float awk1[], /* Weighted LPCs for this subframe */
-float awk2[], /* Weighted LPCs for this subframe */
+spx_coef_t ak[], /* LPCs for this subframe */
+spx_coef_t awk1[], /* Weighted LPCs for this subframe */
+spx_coef_t awk2[], /* Weighted LPCs for this subframe */
void *par, /* Codebook/search parameters*/
int p, /* number of LPC coeffs */
int nsf, /* number of samples in subframe */
@@ -70,9 +71,9 @@ char *stack
void noise_codebook_quant(
float target[], /* target vector */
-float ak[], /* LPCs for this subframe */
-float awk1[], /* Weighted LPCs for this subframe */
-float awk2[], /* Weighted LPCs for this subframe */
+spx_coef_t ak[], /* LPCs for this subframe */
+spx_coef_t awk1[], /* Weighted LPCs for this subframe */
+spx_coef_t awk2[], /* Weighted LPCs for this subframe */
void *par, /* Codebook/search parameters*/
int p, /* number of LPC coeffs */
int nsf, /* number of samples in subframe */
diff --git a/libspeex/filters.c b/libspeex/filters.c
index e924ef0..9176e8c 100644
--- a/libspeex/filters.c
+++ b/libspeex/filters.c
@@ -33,9 +33,9 @@
#include "filters.h"
#include "stack_alloc.h"
#include <math.h>
+#include "misc.h"
-
-void bw_lpc(float gamma, float *lpc_in, float *lpc_out, int order)
+void bw_lpc(float gamma, spx_coef_t *lpc_in, spx_coef_t *lpc_out, int order)
{
int i;
float tmp=1;
@@ -46,10 +46,104 @@ void bw_lpc(float gamma, float *lpc_in, float *lpc_out, int order)
}
}
+
+#ifdef FIXED_POINT
+
+
+#define MUL_16_32_R15(a,bh,bl) ((a)*(bh) + ((a)*(bl)>>15))
+
+
+void filter_mem2(float *x, spx_coef_t *num, spx_coef_t *den, float *y, int N, int ord, spx_mem_t *mem)
+{
+ int i,j;
+ int xi,yi;
+ short nums[11], dens[11];
+
+ for (i=0;i<ord+1;i++)
+ {
+ nums[i] = (int)floor(.5+8192*num[i]);
+ dens[i] = (int)floor(.5+8192*den[i]);
+ }
+
+ for (i=0;i<N;i++)
+ {
+ int xh,xl,yh,yl;
+ xi=floor(.5+16384*x[i]);
+ yi = xi + (mem[0]<<2);
+ xh = xi>>15; xl=xi&0x00007fff; yh = yi>>15; yl=yi&0x00007fff;
+ for (j=0;j<ord-1;j++)
+ {
+ mem[j] = mem[j+1] + MUL_16_32_R15(nums[j+1],xh,xl) - MUL_16_32_R15(dens[j+1],yh,yl);
+ }
+ mem[ord-1] = MUL_16_32_R15(nums[ord],xh,xl) - MUL_16_32_R15(dens[ord],yh,yl);
+ y[i] = yi*(1.f/16384.f);
+ }
+}
+
+void iir_mem2(float *x, spx_coef_t *den, float *y, int N, int ord, spx_mem_t *mem)
+{
+ int i,j;
+ int xi,yi;
+ short dens[11];
+
+ for (i=0;i<11;i++)
+ {
+ dens[i] = (int)floor(.5+8192*den[i]);
+ }
+
+ for (i=0;i<N;i++)
+ {
+ int yh,yl;
+ xi=floor(.5+16384*x[i]);
+ yi = xi + (mem[0]<<2);
+ yh = yi>>15; yl=yi&0x00007fff;
+ for (j=0;j<ord-1;j++)
+ {
+ mem[j] = mem[j+1] - MUL_16_32_R15(dens[j+1],yh,yl);
+ }
+ mem[ord-1] = - MUL_16_32_R15(dens[ord],yh,yl);
+ y[i] = yi*(1.f/16384.f);
+ }
+}
+
+
+void fir_mem2(float *x, spx_coef_t *num, float *y, int N, int ord, spx_mem_t *mem)
+{
+ int i,j;
+ int xi,yi;
+ short nums[11];
+
+ for (i=0;i<11;i++)
+ {
+ nums[i] = (int)floor(.5+8192*num[i]);
+ }
+
+ for (i=0;i<N;i++)
+ {
+ int xh,xl;
+ xi=floor(.5+16384*x[i]);
+ yi = xi + (mem[0]<<2);
+ xh = xi>>15; xl=xi&0x00007fff;
+ for (j=0;j<ord-1;j++)
+ {
+ mem[j] = mem[j+1] + MUL_16_32_R15(nums[j+1],xh,xl);
+ }
+ mem[ord-1] = MUL_16_32_R15(nums[ord],xh,xl);
+ y[i] = yi*(1.f/16384.f);
+ }
+
+}
+
+#else
+
+
+
#ifdef _USE_SSE
#include "filters_sse.h"
#else
-void filter_mem2(float *x, float *num, float *den, float *y, int N, int ord, float *mem)
+
+
+void filter_mem2(float *x, spx_coef_t *num, spx_coef_t *den, float *y, int N, int ord, spx_mem_t *mem)
{
int i,j;
float xi,yi;
@@ -67,7 +161,7 @@ void filter_mem2(float *x, float *num, float *den, float *y, int N, int ord, flo
}
-void iir_mem2(float *x, float *den, float *y, int N, int ord, float *mem)
+void iir_mem2(float *x, spx_coef_t *den, float *y, int N, int ord, spx_mem_t *mem)
{
int i,j;
for (i=0;i<N;i++)
@@ -80,9 +174,11 @@ void iir_mem2(float *x, float *den, float *y, int N, int ord, float *mem)
mem[ord-1] = - den[ord]*y[i];
}
}
+
+
#endif
-void fir_mem2(float *x, float *num, float *y, int N, int ord, float *mem)
+void fir_mem2(float *x, spx_coef_t *num, float *y, int N, int ord, spx_mem_t *mem)
{
int i,j;
float xi;
@@ -98,22 +194,26 @@ void fir_mem2(float *x, float *num, float *y, int N, int ord, float *mem)
}
}
-void syn_percep_zero(float *xx, float *ak, float *awk1, float *awk2, float *y, int N, int ord, char *stack)
+
+#endif
+
+
+void syn_percep_zero(float *xx, spx_coef_t *ak, spx_coef_t *awk1, spx_coef_t *awk2, float *y, int N, int ord, char *stack)
{
int i;
- float *mem = PUSH(stack,ord, float);
- for (i=0;i<ord;i++)
- mem[i]=0;
- filter_mem2(xx, awk1, ak, y, N, ord, mem);
+ spx_mem_t *mem = PUSH(stack,ord, spx_mem_t);
for (i=0;i<ord;i++)
mem[i]=0;
- iir_mem2(y, awk2, y, N, ord, mem);
+ iir_mem2(xx, ak, y, N, ord, mem);
+ for (i=0;i<ord;i++)
+ mem[i]=0;
+ filter_mem2(y, awk1, awk2, y, N, ord, mem);
}
-void residue_percep_zero(float *xx, float *ak, float *awk1, float *awk2, float *y, int N, int ord, char *stack)
+void residue_percep_zero(float *xx, spx_coef_t *ak, spx_coef_t *awk1, spx_coef_t *awk2, float *y, int N, int ord, char *stack)
{
int i;
- float *mem = PUSH(stack,ord, float);
+ spx_mem_t *mem = PUSH(stack,ord, spx_mem_t);
for (i=0;i<ord;i++)
mem[i]=0;
filter_mem2(xx, ak, awk1, y, N, ord, mem);
@@ -221,7 +321,7 @@ void comp_filter_mem_init (CombFilterMem *mem)
void comb_filter(
float *exc, /*decoded excitation*/
float *new_exc, /*enhanced excitation*/
-float *ak, /*LPC filter coefs*/
+spx_coef_t *ak, /*LPC filter coefs*/
int p, /*LPC order*/
int nsf, /*sub-frame size*/
int pitch, /*pitch period*/
diff --git a/libspeex/filters.h b/libspeex/filters.h
index ad6dc02..9206b04 100644
--- a/libspeex/filters.h
+++ b/libspeex/filters.h
@@ -33,6 +33,7 @@
#ifndef FILTERS_H
#define FILTERS_H
+#include "misc.h"
typedef struct CombFilterMem {
int last_pitch;
@@ -45,28 +46,28 @@ void qmf_decomp(float *xx, float *aa, float *y1, float *y2, int N, int M, float
void fir_mem_up(float *x, float *a, float *y, int N, int M, float *mem, char *stack);
-void filter_mem2(float *x, float *num, float *den, float *y, int N, int ord, float *mem);
-void fir_mem2(float *x, float *num, float *y, int N, int ord, float *mem);
-void iir_mem2(float *x, float *den, float *y, int N, int ord, float *mem);
+void filter_mem2(float *x, spx_coef_t *num, spx_coef_t *den, float *y, int N, int ord, spx_mem_t *mem);
+void fir_mem2(float *x, spx_coef_t *num, float *y, int N, int ord, spx_mem_t *mem);
+void iir_mem2(float *x, spx_coef_t *den, float *y, int N, int ord, spx_mem_t *mem);
/* Apply bandwidth expansion on LPC coef */
-void bw_lpc(float gamma, float *lpc_in, float *lpc_out, int order);
+void bw_lpc(float gamma, spx_coef_t *lpc_in, spx_coef_t *lpc_out, int order);
/* FIR filter */
void fir_decim_mem(float *x, float *a, float *y, int N, int M, float *mem);
-void syn_percep_zero(float *x, float *ak, float *awk1, float *awk2, float *y, int N, int ord, char *stack);
+void syn_percep_zero(float *x, spx_coef_t *ak, spx_coef_t *awk1, spx_coef_t *awk2, float *y, int N, int ord, char *stack);
-void residue_percep_zero(float *xx, float *ak, float *awk1, float *awk2, float *y, int N, int ord, char *stack);
+void residue_percep_zero(float *xx, spx_coef_t *ak, spx_coef_t *awk1, spx_coef_t *awk2, float *y, int N, int ord, char *stack);
void comp_filter_mem_init (CombFilterMem *mem);
void comb_filter(
float *exc, /*decoded excitation*/
float *new_exc, /*enhanced excitation*/
-float *ak, /*LPC filter coefs*/
+spx_coef_t *ak, /*LPC filter coefs*/
int p, /*LPC order*/
int nsf, /*sub-frame size*/
int pitch, /*pitch period*/
diff --git a/libspeex/lpc.c b/libspeex/lpc.c
index 1094291..c7bbafd 100644
--- a/libspeex/lpc.c
+++ b/libspeex/lpc.c
@@ -65,7 +65,7 @@
/* returns minimum mean square error */
float _spx_lpc(
-float *lpc, /* out: [0...p-1] LPC coefficients */
+spx_coef_t *lpc, /* out: [0...p-1] LPC coefficients */
const float *ac, /* in: [0...p] autocorrelation values */
int p
)
@@ -85,7 +85,7 @@ int p
r = -ac[i + 1];
for (j = 0; j < i; j++)
r -= lpc[j] * ac[i - j];
- r /= error+.004*ac[0];
+ r /= error;
/* Update LPC coefficients and total error */
lpc[i] = r;
diff --git a/libspeex/lpc.h b/libspeex/lpc.h
index 57ca9e7..d95f56f 100644
--- a/libspeex/lpc.h
+++ b/libspeex/lpc.h
@@ -33,6 +33,8 @@
#ifndef LPC_H
#define LPC_H
+#include "misc.h"
+
void _spx_autocorr(
const float * x, /* in: [0...n-1] samples x */
float *ac, /* out: [0...lag-1] ac values */
@@ -40,7 +42,7 @@ void _spx_autocorr(
float /* returns minimum mean square error */
_spx_lpc(
- float * lpc, /* [0...p-1] LPC coefficients */
+ spx_coef_t * lpc, /* [0...p-1] LPC coefficients */
const float * ac, /* in: [0...p] autocorrelation values */
int p
);
diff --git a/libspeex/lsp.c b/libspeex/lsp.c
index 1af762c..939f650 100644
--- a/libspeex/lsp.c
+++ b/libspeex/lsp.c
@@ -112,7 +112,7 @@ static float cheb_poly_eva(float *coef,float x,int m,char *stack)
\*---------------------------------------------------------------------------*/
-int lpc_to_lsp (float *a,int lpcrdr,float *freq,int nb,float delta, char *stack)
+int lpc_to_lsp (spx_coef_t *a,int lpcrdr,float *freq,int nb,float delta, char *stack)
/* float *a lpc coefficients */
/* int lpcrdr order of LPC coefficients (10) */
/* float *freq LSP frequencies in the x domain */
@@ -247,8 +247,8 @@ int lpc_to_lsp (float *a,int lpcrdr,float *freq,int nb,float delta, char *stack)
\*---------------------------------------------------------------------------*/
-
-void lsp_to_lpc(float *freq,float *ak,int lpcrdr, char *stack)
+#if 0
+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 */
/* int lpcrdr order of LPC coefficients */
@@ -307,6 +307,77 @@ void lsp_to_lpc(float *freq,float *ak,int lpcrdr, char *stack)
}
}
+#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 */
+/* int lpcrdr order of LPC coefficients */
+
+
+{
+ 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;
+ 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);
+ pw = Wp;
+
+
+ /* initialise contents of array */
+
+ for(i=0;i<=4*m+1;i++){ /* set contents of buffer to 0 */
+ *pw++ = 0.0;
+ }
+
+ /* Set pointers up */
+
+ pw = Wp;
+ 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
+ LSP coefficient */
+
+ for(j=0;j<=lpcrdr;j++){
+ int i2=0;
+ for(i=0;i<m;i++,i2+=2){
+ n1 = pw+(i*4);
+ 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);
+ xin1 = xout1;
+ xin2 = xout2;
+ }
+ xout1 = xin1 + *(n4+1);
+ xout2 = xin2 - *(n4+2);
+ ak[j] = ((128+xout1 + xout2)>>8)/8192.;
+ *(n4+1) = xin1;
+ *(n4+2) = xin2;
+
+ xin1 = 0.0;
+ xin2 = 0.0;
+ }
+
+}
+#endif
/*Added by JMV
Makes sure the LSPs are stable*/
diff --git a/libspeex/lsp.h b/libspeex/lsp.h
index 1f3b02f..656f9f8 100644
--- a/libspeex/lsp.h
+++ b/libspeex/lsp.h
@@ -47,8 +47,10 @@ Modified by Jean-Marc Valin
#ifndef __AK2LSPD__
#define __AK2LSPD__
-int lpc_to_lsp (float *a, int lpcrdr, float *freq, int nb, float delta, char *stack);
-void lsp_to_lpc(float *freq, float *ak, int lpcrdr, char *stack);
+#include "misc.h"
+
+int lpc_to_lsp (spx_coef_t *a, int lpcrdr, float *freq, int nb, float delta, char *stack);
+void lsp_to_lpc(float *freq, spx_coef_t *ak, int lpcrdr, char *stack);
/*Added by JMV*/
void lsp_enforce_margin(float *lsp, int len, float margin);
diff --git a/libspeex/ltp.c b/libspeex/ltp.c
index 76f5058..f20a77f 100644
--- a/libspeex/ltp.c
+++ b/libspeex/ltp.c
@@ -142,9 +142,9 @@ void open_loop_nbest_pitch(float *sw, int start, int end, int len, int *pitch, f
/** Finds the best quantized 3-tap pitch predictor by analysis by synthesis */
static float pitch_gain_search_3tap(
float target[], /* Target vector */
-float ak[], /* LPCs for this subframe */
-float awk1[], /* Weighted LPCs #1 for this subframe */
-float awk2[], /* Weighted LPCs #2 for this subframe */
+spx_coef_t ak[], /* LPCs for this subframe */
+spx_coef_t awk1[], /* Weighted LPCs #1 for this subframe */
+spx_coef_t awk2[], /* Weighted LPCs #2 for this subframe */
float exc[], /* Excitation */
void *par,
int pitch, /* Pitch value */
@@ -292,9 +292,9 @@ int cdbk_offset
int pitch_search_3tap(
float target[], /* Target vector */
float *sw,
-float ak[], /* LPCs for this subframe */
-float awk1[], /* Weighted LPCs #1 for this subframe */
-float awk2[], /* Weighted LPCs #2 for this subframe */
+spx_coef_t ak[], /* LPCs for this subframe */
+spx_coef_t awk1[], /* Weighted LPCs #1 for this subframe */
+spx_coef_t awk2[], /* Weighted LPCs #2 for this subframe */
float exc[], /* Excitation */
void *par,
int start, /* Smallest pitch value allowed */
@@ -497,9 +497,9 @@ int cdbk_offset
int forced_pitch_quant(
float target[], /* Target vector */
float *sw,
-float ak[], /* LPCs for this subframe */
-float awk1[], /* Weighted LPCs #1 for this subframe */
-float awk2[], /* Weighted LPCs #2 for this subframe */
+spx_coef_t ak[], /* LPCs for this subframe */
+spx_coef_t awk1[], /* Weighted LPCs #1 for this subframe */
+spx_coef_t awk2[], /* Weighted LPCs #2 for this subframe */
float exc[], /* Excitation */
void *par,
int start, /* Smallest pitch value allowed */
diff --git a/libspeex/ltp.h b/libspeex/ltp.h
index fdcac11..dff945a 100644
--- a/libspeex/ltp.h
+++ b/libspeex/ltp.h
@@ -31,7 +31,7 @@
*/
#include "speex_bits.h"
-
+#include "misc.h"
typedef struct ltp_params {
signed char *gain_cdbk;
@@ -47,9 +47,9 @@ void open_loop_nbest_pitch(float *sw, int start, int end, int len, int *pitch, f
int pitch_search_3tap(
float target[], /* Target vector */
float *sw,
-float ak[], /* LPCs for this subframe */
-float awk1[], /* Weighted LPCs #1 for this subframe */
-float awk2[], /* Weighted LPCs #2 for this subframe */
+spx_coef_t ak[], /* LPCs for this subframe */
+spx_coef_t awk1[], /* Weighted LPCs #1 for this subframe */
+spx_coef_t awk2[], /* Weighted LPCs #2 for this subframe */
float exc[], /* Overlapping codebook */
void *par,
int start, /* Smallest pitch value allowed */
@@ -87,9 +87,9 @@ int cdbk_offset
int forced_pitch_quant(
float target[], /* Target vector */
float *sw,
-float ak[], /* LPCs for this subframe */
-float awk1[], /* Weighted LPCs #1 for this subframe */
-float awk2[], /* Weighted LPCs #2 for this subframe */
+spx_coef_t ak[], /* LPCs for this subframe */
+spx_coef_t awk1[], /* Weighted LPCs #1 for this subframe */
+spx_coef_t awk2[], /* Weighted LPCs #2 for this subframe */
float exc[], /* Excitation */
void *par,
int start, /* Smallest pitch value allowed */
diff --git a/libspeex/misc.h b/libspeex/misc.h
index d128da8..21c0ae9 100644
--- a/libspeex/misc.h
+++ b/libspeex/misc.h
@@ -45,6 +45,28 @@
#pragma warning(disable : 4305)
#endif
+
+#ifdef FIXED_POINT
+
+typedef int spx_mem_t;
+typedef float spx_coef_t;
+typedef float spx_sig_t;
+typedef short spx_word16_t;
+typedef int spx_word32_t;
+
+#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))
+
+#else
+
+typedef float spx_mem_t;
+typedef float spx_coef_t;
+typedef float spx_sig_t;
+typedef float spx_word16_t;
+typedef float spx_word32_t;
+
+#endif
+
#ifndef RELEASE
void print_vec(float *vec, int len, char *name);
#endif
diff --git a/libspeex/modes.h b/libspeex/modes.h
index 5a25246..b4ac319 100644
--- a/libspeex/modes.h
+++ b/libspeex/modes.h
@@ -38,7 +38,7 @@
#include "speex.h"
#include "speex_bits.h"
-
+#include "misc.h"
#define NB_SUBMODES 16
#define NB_SUBMODE_BITS 4
@@ -55,8 +55,8 @@ typedef void (*lsp_unquant_func)(float *, int, SpeexBits *);
/** Long-term predictor quantization */
-typedef int (*ltp_quant_func)(float *, float *, float *, float *,
- float *, float *, void *, int, int, float,
+typedef int (*ltp_quant_func)(float *, float *, spx_coef_t *, spx_coef_t *,
+ spx_coef_t *, float *, void *, int, int, float,
int, int, SpeexBits*, char *, float *, float *, int, int);
/** Long-term un-quantize */
@@ -65,7 +65,7 @@ typedef void (*ltp_unquant_func)(float *, int, int, float, void *, int, int *,
/** Innovation quantization function */
-typedef void (*innovation_quant_func)(float *, float *, float *, float *, void *, int, int,
+typedef void (*innovation_quant_func)(float *, spx_coef_t *, spx_coef_t *, spx_coef_t *, void *, int, int,
float *, float *, SpeexBits *, char *, int);
/** Innovation unquantization function */
diff --git a/libspeex/nb_celp.c b/libspeex/nb_celp.c
index dd1f7e8..1b2122b 100644
--- a/libspeex/nb_celp.c
+++ b/libspeex/nb_celp.c
@@ -139,11 +139,11 @@ void *nb_encoder_init(SpeexMode *m)
st->buf2 = PUSH(st->stack, st->windowSize, float);
- st->lpc = PUSH(st->stack, st->lpcSize+1, float);
- st->interp_lpc = PUSH(st->stack, st->lpcSize+1, float);
- st->interp_qlpc = PUSH(st->stack, st->lpcSize+1, float);
- st->bw_lpc1 = PUSH(st->stack, st->lpcSize+1, float);
- st->bw_lpc2 = PUSH(st->stack, st->lpcSize+1, float);
+ st->lpc = PUSH(st->stack, st->lpcSize+1, spx_coef_t);
+ st->interp_lpc = PUSH(st->stack, st->lpcSize+1, spx_coef_t);
+ st->interp_qlpc = PUSH(st->stack, st->lpcSize+1, spx_coef_t);
+ st->bw_lpc1 = PUSH(st->stack, st->lpcSize+1, spx_coef_t);
+ st->bw_lpc2 = PUSH(st->stack, st->lpcSize+1, spx_coef_t);
st->lsp = PUSH(st->stack, st->lpcSize, float);
st->qlsp = PUSH(st->stack, st->lpcSize, float);
@@ -158,10 +158,10 @@ void *nb_encoder_init(SpeexMode *m)
st->lsp[i]=(M_PI*((float)(i+1)))/(st->lpcSize+1);
}
- st->mem_sp = PUSH(st->stack, st->lpcSize, float);
- st->mem_sw = PUSH(st->stack, st->lpcSize, float);
- st->mem_sw_whole = PUSH(st->stack, st->lpcSize, float);
- st->mem_exc = PUSH(st->stack, st->lpcSize, float);
+ st->mem_sp = PUSH(st->stack, st->lpcSize, spx_mem_t);
+ st->mem_sw = PUSH(st->stack, st->lpcSize, spx_mem_t);
+ st->mem_sw_whole = PUSH(st->stack, st->lpcSize, spx_mem_t);
+ st->mem_exc = PUSH(st->stack, st->lpcSize, spx_mem_t);
st->pi_gain = PUSH(st->stack, st->nbSubframes, float);
@@ -201,7 +201,8 @@ int nb_encode(void *state, float *in, SpeexBits *bits)
int ol_pitch;
float ol_pitch_coef;
float ol_gain;
- float *res, *target, *mem;
+ float *res, *target;
+ spx_mem_t *mem;
char *stack;
float *syn_resp;
float lsp_dist=0;
@@ -605,7 +606,7 @@ int nb_encode(void *state, float *in, SpeexBits *bits)
/* Target signal */
target = PUSH(stack, st->subframeSize, float);
syn_resp = PUSH(stack, st->subframeSize, float);
- mem = PUSH(stack, st->lpcSize, float);
+ mem = PUSH(stack, st->lpcSize, spx_mem_t);
orig = PUSH(stack, st->frameSize, float);
for (i=0;i<st->frameSize;i++)
orig[i]=st->frame[i];
@@ -969,11 +970,11 @@ void *nb_decoder_init(SpeexMode *m)
st->excBuf[i]=0;
st->innov = PUSH(st->stack, st->frameSize, float);
- st->interp_qlpc = PUSH(st->stack, st->lpcSize+1, float);
+ st->interp_qlpc = PUSH(st->stack, st->lpcSize+1, spx_coef_t);
st->qlsp = PUSH(st->stack, st->lpcSize, float);
st->old_qlsp = PUSH(st->stack, st->lpcSize, float);
st->interp_qlsp = PUSH(st->stack, st->lpcSize, float);
- st->mem_sp = PUSH(st->stack, 5*st->lpcSize, float);
+ st->mem_sp = PUSH(st->stack, 5*st->lpcSize, spx_mem_t);
st->comb_mem = PUSHS(st->stack, CombFilterMem);
comp_filter_mem_init (st->comb_mem);
@@ -1010,7 +1011,7 @@ void nb_decoder_destroy(void *state)
static void nb_decode_lost(DecState *st, float *out, char *stack)
{
int i, sub;
- float *awk1, *awk2, *awk3;
+ spx_coef_t *awk1, *awk2, *awk3;
float pitch_gain, fact, gain_med;
fact = exp(-.04*st->count_lost*st->count_lost);
@@ -1028,9 +1029,9 @@ static void nb_decode_lost(DecState *st, float *out, char *stack)
speex_move(st->inBuf, st->inBuf+st->frameSize, (st->bufSize-st->frameSize)*sizeof(float));
speex_move(st->excBuf, st->excBuf+st->frameSize, (st->bufSize-st->frameSize)*sizeof(float));
- awk1=PUSH(stack, (st->lpcSize+1), float);
- awk2=PUSH(stack, (st->lpcSize+1), float);
- awk3=PUSH(stack, (st->lpcSize+1), float);
+ awk1=PUSH(stack, (st->lpcSize+1), spx_coef_t);
+ awk2=PUSH(stack, (st->lpcSize+1), spx_coef_t);
+ awk3=PUSH(stack, (st->lpcSize+1), spx_coef_t);
for (sub=0;sub<st->nbSubframes;sub++)
{
@@ -1134,7 +1135,7 @@ int nb_decode(void *state, SpeexBits *bits, float *out)
int wideband;
int m;
char *stack;
- float *awk1, *awk2, *awk3;
+ spx_coef_t *awk1, *awk2, *awk3;
float pitch_average=0;
#ifdef EPIC_48K
int pitch_half[2];
@@ -1246,8 +1247,8 @@ int nb_decode(void *state, SpeexBits *bits, float *out)
/* If null mode (no transmission), just set a couple things to zero*/
if (st->submodes[st->submodeID] == NULL)
{
- float *lpc;
- lpc = PUSH(stack,11, float);
+ spx_coef_t *lpc;
+ lpc = PUSH(stack,11, spx_coef_t);
bw_lpc(.93, st->interp_qlpc, lpc, 10);
/*for (i=0;i<st->frameSize;i++)
st->exc[i]=0;*/
@@ -1340,9 +1341,9 @@ int nb_decode(void *state, SpeexBits *bits, float *out)
}
#endif
- awk1=PUSH(stack, st->lpcSize+1, float);
- awk2=PUSH(stack, st->lpcSize+1, float);
- awk3=PUSH(stack, st->lpcSize+1, float);
+ awk1=PUSH(stack, st->lpcSize+1, spx_coef_t);
+ awk2=PUSH(stack, st->lpcSize+1, spx_coef_t);
+ awk3=PUSH(stack, st->lpcSize+1, spx_coef_t);
if (st->submodeID==1)
{
diff --git a/libspeex/nb_celp.h b/libspeex/nb_celp.h
index 728df0c..b878ce2 100644
--- a/libspeex/nb_celp.h
+++ b/libspeex/nb_celp.h
@@ -86,21 +86,21 @@ typedef struct EncState {
float *buf2; /**< 2nd temporary buffer */
float *autocorr; /**< auto-correlation */
float *lagWindow; /**< Window applied to auto-correlation */
- float *lpc; /**< LPCs for current frame */
+ spx_coef_t *lpc; /**< LPCs for current frame */
float *lsp; /**< LSPs for current frame */
float *qlsp; /**< Quantized LSPs for current frame */
float *old_lsp; /**< LSPs for previous frame */
float *old_qlsp; /**< Quantized LSPs for previous frame */
float *interp_lsp; /**< Interpolated LSPs */
float *interp_qlsp; /**< Interpolated quantized LSPs */
- float *interp_lpc; /**< Interpolated LPCs */
- float *interp_qlpc; /**< Interpolated quantized LPCs */
- float *bw_lpc1; /**< LPCs after bandwidth expansion by gamma1 for perceptual weighting*/
- float *bw_lpc2; /**< LPCs after bandwidth expansion by gamma2 for perceptual weighting*/
- float *mem_sp; /**< Filter memory for signal synthesis */
- float *mem_sw; /**< Filter memory for perceptually-weighted signal */
- float *mem_sw_whole; /**< Filter memory for perceptually-weighted signal (whole frame)*/
- float *mem_exc; /**< Filter memory for excitation (whole frame) */
+ spx_coef_t *interp_lpc; /**< Interpolated LPCs */
+ spx_coef_t *interp_qlpc; /**< Interpolated quantized LPCs */
+ spx_coef_t *bw_lpc1; /**< LPCs after bandwidth expansion by gamma1 for perceptual weighting*/
+ spx_coef_t *bw_lpc2; /**< LPCs after bandwidth expansion by gamma2 for perceptual weighting*/
+ spx_mem_t *mem_sp; /**< Filter memory for signal synthesis */
+ spx_mem_t *mem_sw; /**< Filter memory for perceptually-weighted signal */
+ spx_mem_t *mem_sw_whole; /**< Filter memory for perceptually-weighted signal (whole frame)*/
+ spx_mem_t *mem_exc; /**< Filter memory for excitation (whole frame) */
float *pi_gain; /**< Gain of LPC filter at theta=pi (fe/2) */
VBRState *vbr; /**< State of the VBR data */
@@ -157,8 +157,8 @@ typedef struct DecState {
float *qlsp; /**< Quantized LSPs for current frame */
float *old_qlsp; /**< Quantized LSPs for previous frame */
float *interp_qlsp; /**< Interpolated quantized LSPs */
- float *interp_qlpc; /**< Interpolated quantized LPCs */
- float *mem_sp; /**< Filter memory for synthesis signal */
+ spx_coef_t *interp_qlpc; /**< Interpolated quantized LPCs */
+ spx_mem_t *mem_sp; /**< Filter memory for synthesis signal */
float *pi_gain; /**< Gain of LPC filter at theta=pi (fe/2) */
int last_pitch; /**< Pitch of last correctly decoded frame */
float last_pitch_gain; /**< Pitch gain of last correctly decoded frame */
diff --git a/libspeex/preprocess.c b/libspeex/preprocess.c
index 6de1531..48387ba 100644
--- a/libspeex/preprocess.c
+++ b/libspeex/preprocess.c
@@ -582,7 +582,7 @@ static void update_noise_prob(SpeexPreprocessState *st)
st->Smin[i] = st->Stmp[i] = st->S[i]+100;
}
- if (st->nb_preprocess%100==0)
+ if (st->nb_preprocess%80==0)
{
for (i=1;i<N-1;i++)
{
@@ -670,15 +670,14 @@ int speex_preprocess(SpeexPreprocessState *st, float *x, float *echo)
else
min_gamma *= 4.;
#else
- min_gamma = .1*fabs(mean_prior - mean_post)*fabs(mean_prior - mean_post);
- if (min_gamma>.15)
- min_gamma = .15;
- if (min_gamma<.02)
- min_gamma = .02;
+ min_gamma = .2*fabs(mean_prior - mean_post)*fabs(mean_prior - mean_post);
+ if (min_gamma>.6)
+ min_gamma = .6;
+ if (min_gamma<.01)
+ min_gamma = .01;
#endif
- /*min_gamma = .08;*/
- /*if (gamma<min_gamma)*/
+ if (gamma<min_gamma)
gamma=min_gamma;
for (i=1;i<N;i++)
diff --git a/libspeex/sb_celp.c b/libspeex/sb_celp.c
index b4c7b07..1c01da6 100644
--- a/libspeex/sb_celp.c
+++ b/libspeex/sb_celp.c
@@ -191,22 +191,22 @@ void *sb_encoder_init(SpeexMode *m)
st->lagWindow[i]=exp(-.5*sqr(2*M_PI*st->lag_factor*i));
st->autocorr = PUSH(st->stack, st->lpcSize+1, float);
- st->lpc = PUSH(st->stack, st->lpcSize+1, float);
- st->bw_lpc1 = PUSH(st->stack, st->lpcSize+1, float);
- st->bw_lpc2 = PUSH(st->stack, st->lpcSize+1, float);
+ st->lpc = PUSH(st->stack, st->lpcSize+1, spx_coef_t);
+ st->bw_lpc1 = PUSH(st->stack, st->lpcSize+1, spx_coef_t);
+ st->bw_lpc2 = PUSH(st->stack, st->lpcSize+1, spx_coef_t);
st->lsp = PUSH(st->stack, st->lpcSize, float);
st->qlsp = PUSH(st->stack, st->lpcSize, float);
st->old_lsp = PUSH(st->stack, st->lpcSize, float);
st->old_qlsp = PUSH(st->stack, st->lpcSize, float);
st->interp_lsp = PUSH(st->stack, st->lpcSize, float);
st->interp_qlsp = PUSH(st->stack, st->lpcSize, float);
- st->interp_lpc = PUSH(st->stack, st->lpcSize+1, float);
- st->interp_qlpc = PUSH(st->stack, st->lpcSize+1, float);
+ st->interp_lpc = PUSH(st->stack, st->lpcSize+1, spx_coef_t);
+ st->interp_qlpc = PUSH(st->stack, st->lpcSize+1, spx_coef_t);
st->pi_gain = PUSH(st->stack, st->nbSubframes, float);
- st->mem_sp = PUSH(st->stack, st->lpcSize, float);
- st->mem_sp2 = PUSH(st->stack, st->lpcSize, float);
- st->mem_sw = PUSH(st->stack, st->lpcSize, float);
+ st->mem_sp = PUSH(st->stack, st->lpcSize, spx_mem_t);
+ st->mem_sp2 = PUSH(st->stack, st->lpcSize, spx_mem_t);
+ st->mem_sw = PUSH(st->stack, st->lpcSize, spx_mem_t);
st->vbr_quality = 8;
st->vbr_enabled = 0;
@@ -236,7 +236,8 @@ int sb_encode(void *state, float *in, SpeexBits *bits)
SBEncState *st;
int i, roots, sub;
char *stack;
- float *mem, *innov, *syn_resp;
+ spx_mem_t *mem;
+ float *innov, *syn_resp;
float *low_pi_gain, *low_exc, *low_innov;
SpeexSBMode *mode;
int dtx;
@@ -441,7 +442,7 @@ int sb_encode(void *state, float *in, SpeexBits *bits)
st->old_qlsp[i] = st->qlsp[i];
}
- mem=PUSH(stack, st->lpcSize, float);
+ mem=PUSH(stack, st->lpcSize, spx_mem_t);
syn_resp=PUSH(stack, st->subframeSize, float);
innov = PUSH(stack, st->subframeSize, float);
@@ -700,10 +701,10 @@ void *sb_decoder_init(SpeexMode *m)
st->qlsp = PUSH(st->stack, st->lpcSize, float);
st->old_qlsp = PUSH(st->stack, st->lpcSize, float);
st->interp_qlsp = PUSH(st->stack, st->lpcSize, float);
- st->interp_qlpc = PUSH(st->stack, st->lpcSize+1, float);
+ st->interp_qlpc = PUSH(st->stack, st->lpcSize+1, spx_coef_t);
st->pi_gain = PUSH(st->stack, st->nbSubframes, float);
- st->mem_sp = PUSH(st->stack, 2*st->lpcSize, float);
+ st->mem_sp = PUSH(st->stack, 2*st->lpcSize, spx_mem_t);
st->lpc_enh_enabled=0;
@@ -722,7 +723,7 @@ void sb_decoder_destroy(void *state)
static void sb_decode_lost(SBDecState *st, float *out, int dtx, char *stack)
{
int i;
- float *awk1, *awk2, *awk3;
+ spx_coef_t *awk1, *awk2, *awk3;
int saved_modeid=0;
if (dtx)
@@ -735,9 +736,9 @@ static void sb_decode_lost(SBDecState *st, float *out, int dtx, char *stack)
st->first=1;
- awk1=PUSH(stack, st->lpcSize+1, float);
- awk2=PUSH(stack, st->lpcSize+1, float);
- awk3=PUSH(stack, st->lpcSize+1, float);
+ awk1=PUSH(stack, st->lpcSize+1, spx_coef_t);
+ awk2=PUSH(stack, st->lpcSize+1, spx_coef_t);
+ awk3=PUSH(stack, st->lpcSize+1, spx_coef_t);
if (st->lpc_enh_enabled)
{
@@ -815,7 +816,7 @@ int sb_decode(void *state, SpeexBits *bits, float *out)
int ret;
char *stack;
float *low_pi_gain, *low_exc, *low_innov;
- float *awk1, *awk2, *awk3;
+ spx_coef_t *awk1, *awk2, *awk3;
int dtx;
SpeexSBMode *mode;
@@ -910,9 +911,9 @@ int sb_decode(void *state, SpeexBits *bits, float *out)
st->old_qlsp[i] = st->qlsp[i];
}
- awk1=PUSH(stack, st->lpcSize+1, float);
- awk2=PUSH(stack, st->lpcSize+1, float);
- awk3=PUSH(stack, st->lpcSize+1, float);
+ awk1=PUSH(stack, st->lpcSize+1, spx_coef_t);
+ awk2=PUSH(stack, st->lpcSize+1, spx_coef_t);
+ awk3=PUSH(stack, st->lpcSize+1, spx_coef_t);
for (sub=0;sub<st->nbSubframes;sub++)
{
diff --git a/libspeex/sb_celp.h b/libspeex/sb_celp.h
index b1d7246..3a14924 100644
--- a/libspeex/sb_celp.h
+++ b/libspeex/sb_celp.h
@@ -72,21 +72,21 @@ typedef struct SBEncState {
float *window; /**< LPC analysis window */
float *lagWindow; /**< Auto-correlation window */
float *autocorr; /**< Auto-correlation (for LPC analysis) */
- float *lpc; /**< LPC coefficients */
+ spx_coef_t *lpc; /**< LPC coefficients */
float *lsp; /**< LSP coefficients */
float *qlsp; /**< Quantized LSPs */
float *old_lsp; /**< LSPs of previous frame */
float *old_qlsp; /**< Quantized LSPs of previous frame */
float *interp_lsp; /**< Interpolated LSPs for current sub-frame */
float *interp_qlsp; /**< Interpolated quantized LSPs for current sub-frame */
- float *interp_lpc; /**< Interpolated LPCs for current sub-frame */
- float *interp_qlpc; /**< Interpolated quantized LPCs for current sub-frame */
- float *bw_lpc1; /**< Bandwidth-expanded version of LPCs (#1) */
- float *bw_lpc2; /**< Bandwidth-expanded version of LPCs (#2) */
-
- float *mem_sp; /**< Synthesis signal memory */
- float *mem_sp2;
- float *mem_sw; /**< Perceptual signal memory */
+ spx_coef_t *interp_lpc; /**< Interpolated LPCs for current sub-frame */
+ spx_coef_t *interp_qlpc; /**< Interpolated quantized LPCs for current sub-frame */
+ spx_coef_t *bw_lpc1; /**< Bandwidth-expanded version of LPCs (#1) */
+ spx_coef_t *bw_lpc2; /**< Bandwidth-expanded version of LPCs (#2) */
+
+ spx_mem_t *mem_sp; /**< Synthesis signal memory */
+ spx_mem_t *mem_sp2;
+ spx_mem_t *mem_sw; /**< Perceptual signal memory */
float *pi_gain;
float vbr_quality; /**< Quality setting for VBR encoding */
@@ -131,9 +131,9 @@ typedef struct SBDecState {
float *qlsp;
float *old_qlsp;
float *interp_qlsp;
- float *interp_qlpc;
+ spx_coef_t *interp_qlpc;
- float *mem_sp;
+ spx_mem_t *mem_sp;
float *pi_gain;
int encode_submode;
diff --git a/libspeex/testenc.c b/libspeex/testenc.c
index 5ff804e..877c32a 100644
--- a/libspeex/testenc.c
+++ b/libspeex/testenc.c
@@ -46,9 +46,9 @@ int main(int argc, char **argv)
speex_decoder_ctl(dec, SPEEX_SET_ENH, &tmp);
tmp=0;
speex_encoder_ctl(st, SPEEX_SET_VBR, &tmp);
- tmp=8;
+ tmp=4;
speex_encoder_ctl(st, SPEEX_SET_QUALITY, &tmp);
- tmp=3;
+ tmp=5;
speex_encoder_ctl(st, SPEEX_SET_COMPLEXITY, &tmp);
speex_mode_query(&speex_nb_mode, SPEEX_MODE_FRAME_SIZE, &tmp);
diff --git a/src/speexdec.c b/src/speexdec.c
index 1c1898c..689ea41 100644
--- a/src/speexdec.c
+++ b/src/speexdec.c
@@ -194,7 +194,6 @@ FILE *out_file_open(char *outFile, int rate, int *channels)
#endif
info.play.encoding = AUDIO_ENCODING_SLINEAR;
info.play.precision = 16;
- info.play.sample_rate = rate;
info.play.channels = *channels;
if (ioctl(audio_fd, AUDIO_SETINFO, &info) < 0)