diff options
author | jm <jm@0101bb08-14d6-0310-b084-bc0e0c8e3800> | 2003-11-27 11:42:07 +0300 |
---|---|---|
committer | jm <jm@0101bb08-14d6-0310-b084-bc0e0c8e3800> | 2003-11-27 11:42:07 +0300 |
commit | 384dd357e17115db9a4bfb6cc7542556d7f1fb5e (patch) | |
tree | 5efe9efd3c22a6748b13da1749f45bfb6236be0e /libspeex | |
parent | 99b852464f4de1d148ae6401502b7c0eb56ada8c (diff) |
fixed-point: bw_lpc and lpc_to_lsp are now done.
git-svn-id: http://svn.xiph.org/trunk/speex@5637 0101bb08-14d6-0310-b084-bc0e0c8e3800
Diffstat (limited to 'libspeex')
-rw-r--r-- | libspeex/arch.h | 2 | ||||
-rw-r--r-- | libspeex/filters.c | 7 | ||||
-rw-r--r-- | libspeex/filters.h | 2 | ||||
-rw-r--r-- | libspeex/lsp.c | 6 | ||||
-rw-r--r-- | libspeex/lsp.h | 2 | ||||
-rw-r--r-- | libspeex/nb_celp.c | 33 | ||||
-rw-r--r-- | libspeex/nb_celp.h | 4 | ||||
-rw-r--r-- | libspeex/sb_celp.c | 26 | ||||
-rw-r--r-- | libspeex/sb_celp.h | 4 |
9 files changed, 45 insertions, 41 deletions
diff --git a/libspeex/arch.h b/libspeex/arch.h index 00a189d..c09edd6 100644 --- a/libspeex/arch.h +++ b/libspeex/arch.h @@ -50,6 +50,7 @@ typedef spx_word32_t spx_sig_t; #define LPC_SCALING 8192 #define SIG_SCALING 16384 #define LSP_SCALING 8192. +#define GAMMA_SCALING 32768. #define LPC_SHIFT 13 #define SIG_SHIFT 14 @@ -179,6 +180,7 @@ typedef float spx_word64_t; #define LPC_SCALING 1. #define SIG_SCALING 1. #define LSP_SCALING 1. +#define GAMMA_SCALING 1. #define LPC_SHIFT 0 #define SIG_SHIFT 0 diff --git a/libspeex/filters.c b/libspeex/filters.c index 28b949f..db1ed09 100644 --- a/libspeex/filters.c +++ b/libspeex/filters.c @@ -38,16 +38,15 @@ #ifdef FIXED_POINT -void bw_lpc(float gamma, spx_coef_t *lpc_in, spx_coef_t *lpc_out, int order) +void bw_lpc(spx_word16_t gamma, spx_coef_t *lpc_in, spx_coef_t *lpc_out, int order) { int i; - spx_word16_t g=gamma*32768; - spx_word16_t tmp=g; + spx_word16_t tmp=gamma; lpc_out[0] = lpc_in[0]; for (i=1;i<order+1;i++) { lpc_out[i] = MULT16_16_P15(tmp,lpc_in[i]); - tmp = MULT16_16_P15(tmp, g); + tmp = MULT16_16_P15(tmp, gamma); } } #else diff --git a/libspeex/filters.h b/libspeex/filters.h index cd858a6..bcb495a 100644 --- a/libspeex/filters.h +++ b/libspeex/filters.h @@ -61,7 +61,7 @@ void fir_mem2(spx_sig_t *x, spx_coef_t *num, spx_sig_t *y, int N, int ord, spx_m void iir_mem2(spx_sig_t *x, spx_coef_t *den, spx_sig_t *y, int N, int ord, spx_mem_t *mem); /* Apply bandwidth expansion on LPC coef */ -void bw_lpc(float gamma, spx_coef_t *lpc_in, spx_coef_t *lpc_out, int order); +void bw_lpc(spx_word16_t gamma, spx_coef_t *lpc_in, spx_coef_t *lpc_out, int order); diff --git a/libspeex/lsp.c b/libspeex/lsp.c index 4cf14ec..9a067f8 100644 --- a/libspeex/lsp.c +++ b/libspeex/lsp.c @@ -204,7 +204,7 @@ static float cheb_poly_eva(spx_word32_t *coef,float x,int m,char *stack) #endif -int lpc_to_lsp (spx_coef_t *a,int lpcrdr,spx_lsp_t *freq,int nb,float delta, char *stack) +int lpc_to_lsp (spx_coef_t *a,int lpcrdr,spx_lsp_t *freq,int nb,spx_word16_t delta, char *stack) /* float *a lpc coefficients */ /* int lpcrdr order of LPC coefficients (10) */ /* float *freq LSP frequencies in the x domain */ @@ -213,7 +213,6 @@ int lpc_to_lsp (spx_coef_t *a,int lpcrdr,spx_lsp_t *freq,int nb,float delta, cha { - spx_word16_t ndelta; spx_word16_t temp_xr,xl,xr,xm=0; spx_word32_t psuml,psumr,psumm,temp_psumr/*,temp_qsumr*/; int i,j,m,flag,k; @@ -229,7 +228,6 @@ int lpc_to_lsp (spx_coef_t *a,int lpcrdr,spx_lsp_t *freq,int nb,float delta, cha flag = 1; /* program is searching for a root when, 1 else has found one */ m = lpcrdr/2; /* order of P'(z) & Q'(z) polynomials */ - ndelta = delta*32768; /* Allocate memory space for polynomials */ Q = PUSH(stack, (m+1), spx_word32_t); @@ -304,7 +302,7 @@ int lpc_to_lsp (spx_coef_t *a,int lpcrdr,spx_lsp_t *freq,int nb,float delta, cha spx_word16_t dd; /* Modified by JMV to provide smaller steps around x=+-1 */ #ifdef FIXED_POINT - dd = MULT16_16_Q15(ndelta,(FREQ_SCALE - MULT16_16_Q14(MULT16_16_Q14(xl,xl),14000))); + dd = MULT16_16_Q15(delta,(FREQ_SCALE - MULT16_16_Q14(MULT16_16_Q14(xl,xl),14000))); if (psuml<512 && psuml>-512) dd = PSHR(dd,1); #else diff --git a/libspeex/lsp.h b/libspeex/lsp.h index d563c9c..5e7b02a 100644 --- a/libspeex/lsp.h +++ b/libspeex/lsp.h @@ -49,7 +49,7 @@ Modified by Jean-Marc Valin #include "misc.h"
-int lpc_to_lsp (spx_coef_t *a, int lpcrdr, spx_lsp_t *freq, int nb, float delta, char *stack);
+int lpc_to_lsp (spx_coef_t *a, int lpcrdr, spx_lsp_t *freq, int nb, spx_word16_t delta, char *stack);
void lsp_to_lpc(spx_lsp_t *freq, spx_coef_t *ak, int lpcrdr, char *stack);
/*Added by JMV*/
diff --git a/libspeex/nb_celp.c b/libspeex/nb_celp.c index 413e560..3b6cb69 100644 --- a/libspeex/nb_celp.c +++ b/libspeex/nb_celp.c @@ -65,7 +65,8 @@ spx_word16_t exc_gain_quant_scal1_bound[1]={14385}; spx_word16_t exc_gain_quant_scal1[2]={11546, 17224}; #define LSP_MARGIN 16 -#define LSP_DELTA +#define LSP_DELTA1 6553 +#define LSP_DELTA2 1638 #else @@ -75,7 +76,8 @@ float exc_gain_quant_scal1_bound[1]={0.87798}; float exc_gain_quant_scal1[2]={0.70469, 1.05127}; #define LSP_MARGIN .002 -#define LSP_DELTA +#define LSP_DELTA1 .2 +#define LSP_DELTA2 .05 #endif @@ -105,8 +107,8 @@ void *nb_encoder_init(SpeexMode *m) st->subframeSize=mode->subframeSize; st->lpcSize = mode->lpcSize; st->bufSize = mode->bufSize; - st->gamma1=mode->gamma1; - st->gamma2=mode->gamma2; + st->gamma1=GAMMA_SCALING*mode->gamma1; + st->gamma2=GAMMA_SCALING*mode->gamma2; st->min_pitch=mode->pitchStart; st->max_pitch=mode->pitchEnd; st->lag_factor=mode->lag_factor; @@ -262,13 +264,13 @@ int nb_encode(void *state, short *in, SpeexBits *bits) st->lpc[0]=(spx_coef_t)LPC_SCALING; /* LPC to LSPs (x-domain) transform */ - roots=lpc_to_lsp (st->lpc, st->lpcSize, st->lsp, 15, 0.2, stack); + roots=lpc_to_lsp (st->lpc, st->lpcSize, st->lsp, 15, LSP_DELTA1, stack); /* Check if we found all the roots */ if (roots!=st->lpcSize) { /* Search again if we can afford it */ if (st->complexity>1) - roots = lpc_to_lsp (st->lpc, st->lpcSize, st->lsp, 11, 0.05, stack); + roots = lpc_to_lsp (st->lpc, st->lpcSize, st->lsp, 11, LSP_DELTA2, stack); if (roots!=st->lpcSize) { /*If we can't find all LSP's, do some damage control and use previous filter*/ @@ -1068,9 +1070,9 @@ static void nb_decode_lost(DecState *st, short *out, char *stack) k1=k2; k3=0; } - bw_lpc(k1, st->interp_qlpc, awk1, st->lpcSize); - bw_lpc(k2, st->interp_qlpc, awk2, st->lpcSize); - bw_lpc(k3, st->interp_qlpc, awk3, st->lpcSize); + bw_lpc(GAMMA_SCALING*k1, st->interp_qlpc, awk1, st->lpcSize); + bw_lpc(GAMMA_SCALING*k2, st->interp_qlpc, awk2, st->lpcSize); + bw_lpc(GAMMA_SCALING*k3, st->interp_qlpc, awk3, st->lpcSize); } /* Make up a plausible excitation */ @@ -1258,7 +1260,7 @@ int nb_decode(void *state, SpeexBits *bits, short *out) { spx_coef_t *lpc; lpc = PUSH(stack,11, spx_coef_t); - bw_lpc(.93, st->interp_qlpc, lpc, 10); + bw_lpc(GAMMA_SCALING*.93, st->interp_qlpc, lpc, 10); /*for (i=0;i<st->frameSize;i++) st->exc[i]=0;*/ { @@ -1427,9 +1429,9 @@ int nb_decode(void *state, SpeexBits *bits, short *out) k1=k2; k3=0; } - bw_lpc(k1, st->interp_qlpc, awk1, st->lpcSize); - bw_lpc(k2, st->interp_qlpc, awk2, st->lpcSize); - bw_lpc(k3, st->interp_qlpc, awk3, st->lpcSize); + bw_lpc(GAMMA_SCALING*k1, st->interp_qlpc, awk1, st->lpcSize); + bw_lpc(GAMMA_SCALING*k2, st->interp_qlpc, awk2, st->lpcSize); + bw_lpc(GAMMA_SCALING*k3, st->interp_qlpc, awk3, st->lpcSize); } @@ -1507,8 +1509,7 @@ int nb_decode(void *state, SpeexBits *bits, short *out) exc[i]*=fact; } - tmp = fabs(pitch_gain[0]+pitch_gain[1]+pitch_gain[2]); - tmp = fabs(pitch_gain[1]); + tmp = ABS(pitch_gain[1]); if (pitch_gain[0]>0) tmp += pitch_gain[0]; else @@ -1516,7 +1517,7 @@ int nb_decode(void *state, SpeexBits *bits, short *out) if (pitch_gain[2]>0) tmp += pitch_gain[2]; else - tmp -= .5*pitch_gain[0]; + tmp -= .5*pitch_gain[2]; pitch_average += tmp; diff --git a/libspeex/nb_celp.h b/libspeex/nb_celp.h index ee6a268..4597c9e 100644 --- a/libspeex/nb_celp.h +++ b/libspeex/nb_celp.h @@ -65,8 +65,8 @@ typedef struct EncState { int lbr_48k; #endif - float gamma1; /**< Perceptual filter: A(z/gamma1) */ - float gamma2; /**< Perceptual filter: A(z/gamma2) */ + spx_word16_t gamma1; /**< Perceptual filter: A(z/gamma1) */ + spx_word16_t gamma2; /**< Perceptual filter: A(z/gamma2) */ float lag_factor; /**< Lag windowing Gaussian width */ float lpc_floor; /**< Noise floor multiplier for A[0] in LPC analysis*/ char *stack; /**< Pseudo-stack allocation for temporary memory */ diff --git a/libspeex/sb_celp.c b/libspeex/sb_celp.c index 6e146f2..6bd0d45 100644 --- a/libspeex/sb_celp.c +++ b/libspeex/sb_celp.c @@ -56,10 +56,14 @@ #ifdef FIXED_POINT spx_word16_t gc_quant_bound[16] = {125, 164, 215, 282, 370, 484, 635, 832, 1090, 1428, 1871, 2452, 3213, 4210, 5516, 7228}; #define LSP_MARGIN 410 +#define LSP_DELTA1 6553 +#define LSP_DELTA2 1638 #else #define LSP_MARGIN .05 +#define LSP_DELTA1 .2 +#define LSP_DELTA2 .05 #endif @@ -193,8 +197,8 @@ void *sb_encoder_init(SpeexMode *m) st->lag_factor = mode->lag_factor; st->lpc_floor = mode->lpc_floor; - st->gamma1=mode->gamma1; - st->gamma2=mode->gamma2; + st->gamma1=GAMMA_SCALING*mode->gamma1; + st->gamma2=GAMMA_SCALING*mode->gamma2; st->first=1; st->x0d=PUSH(st->stack, st->frame_size, spx_sig_t); @@ -348,10 +352,10 @@ int sb_encode(void *state, short *in, SpeexBits *bits) st->lpc[0] = (spx_coef_t)LPC_SCALING; /* LPC to LSPs (x-domain) transform */ - roots=lpc_to_lsp (st->lpc, st->lpcSize, st->lsp, 15, 0.2, stack); + roots=lpc_to_lsp (st->lpc, st->lpcSize, st->lsp, 15, LSP_DELTA1, stack); if (roots!=st->lpcSize) { - roots = lpc_to_lsp (st->lpc, st->lpcSize, st->lsp, 11, 0.02, stack); + roots = lpc_to_lsp (st->lpc, st->lpcSize, st->lsp, 11, LSP_DELTA2, stack); if (roots!=st->lpcSize) { /*If we can't find all LSP's, do some damage control and use a flat filter*/ for (i=0;i<st->lpcSize;i++) @@ -778,7 +782,7 @@ static void sb_decode_lost(SBDecState *st, short *out, int dtx, char *stack) saved_modeid=st->submodeID; st->submodeID=1; } else { - bw_lpc(0.99, st->interp_qlpc, st->interp_qlpc, st->lpcSize); + bw_lpc(GAMMA_SCALING*0.99, st->interp_qlpc, st->interp_qlpc, st->lpcSize); } st->first=1; @@ -806,9 +810,9 @@ static void sb_decode_lost(SBDecState *st, short *out, int dtx, char *stack) k1=k2; k3=0; } - bw_lpc(k1, st->interp_qlpc, awk1, st->lpcSize); - bw_lpc(k2, st->interp_qlpc, awk2, st->lpcSize); - bw_lpc(k3, st->interp_qlpc, awk3, st->lpcSize); + bw_lpc(GAMMA_SCALING*k1, st->interp_qlpc, awk1, st->lpcSize); + bw_lpc(GAMMA_SCALING*k2, st->interp_qlpc, awk2, st->lpcSize); + bw_lpc(GAMMA_SCALING*k3, st->interp_qlpc, awk3, st->lpcSize); /*fprintf (stderr, "%f %f %f\n", k1, k2, k3);*/ } @@ -1004,9 +1008,9 @@ int sb_decode(void *state, SpeexBits *bits, short *out) k1=k2; k3=0; } - bw_lpc(k1, st->interp_qlpc, awk1, st->lpcSize); - bw_lpc(k2, st->interp_qlpc, awk2, st->lpcSize); - bw_lpc(k3, st->interp_qlpc, awk3, st->lpcSize); + bw_lpc(GAMMA_SCALING*k1, st->interp_qlpc, awk1, st->lpcSize); + bw_lpc(GAMMA_SCALING*k2, st->interp_qlpc, awk2, st->lpcSize); + bw_lpc(GAMMA_SCALING*k3, st->interp_qlpc, awk3, st->lpcSize); /*fprintf (stderr, "%f %f %f\n", k1, k2, k3);*/ } diff --git a/libspeex/sb_celp.h b/libspeex/sb_celp.h index 56bc221..8bba658 100644 --- a/libspeex/sb_celp.h +++ b/libspeex/sb_celp.h @@ -54,8 +54,8 @@ typedef struct SBEncState { int first; /**< First frame? */ float lag_factor; /**< Lag-windowing control parameter */ float lpc_floor; /**< Controls LPC analysis noise floor */ - float gamma1; /**< Perceptual weighting coef 1 */ - float gamma2; /**< Perceptual weighting coef 2 */ + spx_word16_t gamma1; /**< Perceptual weighting coef 1 */ + spx_word16_t gamma2; /**< Perceptual weighting coef 2 */ char *stack; /**< Temporary allocation stack */ spx_sig_t *x0d, *x1d; /**< QMF filter signals*/ |