diff options
-rw-r--r-- | libspeex/lsp.c | 41 | ||||
-rw-r--r-- | libspeex/lsp.h | 4 | ||||
-rw-r--r-- | libspeex/nb_celp.c | 24 | ||||
-rw-r--r-- | libspeex/sb_celp.c | 11 |
4 files changed, 25 insertions, 55 deletions
diff --git a/libspeex/lsp.c b/libspeex/lsp.c index 69fb569..8078e39 100644 --- a/libspeex/lsp.c +++ b/libspeex/lsp.c @@ -591,13 +591,17 @@ void lsp_to_lpc(spx_lsp_t *freq,spx_coef_t *ak,int lpcrdr, char *stack) #ifdef FIXED_POINT -/*Makes sure the LSPs are stable*/ -void lsp_enforce_margin(spx_lsp_t *lsp, int len, spx_word16_t margin) + +void lsp_interpolate(spx_lsp_t *old_lsp, spx_lsp_t *new_lsp, spx_lsp_t *lsp, int len, int subframe, int nb_subframes, spx_word16_t margin) { int i; spx_word16_t m = margin; spx_word16_t m2 = 25736-margin; - + spx_word16_t tmp = DIV32_16(SHL32(EXTEND32(1 + subframe),14),nb_subframes); + spx_word16_t tmp2 = 16384-tmp; + for (i=0;i<len;i++) + lsp[i] = MULT16_16_P14(tmp2,old_lsp[i]) + MULT16_16_P14(tmp,new_lsp[i]); + /* Enforce margin to sure the LSPs are stable*/ if (lsp[0]<m) lsp[0]=m; if (lsp[len-1]>m2) @@ -612,24 +616,16 @@ void lsp_enforce_margin(spx_lsp_t *lsp, int len, spx_word16_t margin) } } - -void lsp_interpolate(spx_lsp_t *old_lsp, spx_lsp_t *new_lsp, spx_lsp_t *interp_lsp, int len, int subframe, int nb_subframes) -{ - int i; - spx_word16_t tmp = DIV32_16(SHL32(EXTEND32(1 + subframe),14),nb_subframes); - spx_word16_t tmp2 = 16384-tmp; - for (i=0;i<len;i++) - { - interp_lsp[i] = MULT16_16_P14(tmp2,old_lsp[i]) + MULT16_16_P14(tmp,new_lsp[i]); - } -} - #else -/*Makes sure the LSPs are stable*/ -void lsp_enforce_margin(spx_lsp_t *lsp, int len, spx_word16_t margin) + +void lsp_interpolate(spx_lsp_t *old_lsp, spx_lsp_t *new_lsp, spx_lsp_t *lsp, int len, int subframe, int nb_subframes, spx_word16_t margin) { int i; + float tmp = (1.0f + subframe)/nb_subframes; + for (i=0;i<len;i++) + lsp[i] = (1-tmp)*old_lsp[i] + tmp*new_lsp[i]; + /* Enforce margin to sure the LSPs are stable*/ if (lsp[0]<LSP_SCALING*margin) lsp[0]=LSP_SCALING*margin; if (lsp[len-1]>LSP_SCALING*(M_PI-margin)) @@ -644,15 +640,4 @@ void lsp_enforce_margin(spx_lsp_t *lsp, int len, spx_word16_t margin) } } - -void lsp_interpolate(spx_lsp_t *old_lsp, spx_lsp_t *new_lsp, spx_lsp_t *interp_lsp, int len, int subframe, int nb_subframes) -{ - int i; - float tmp = (1.0f + subframe)/nb_subframes; - for (i=0;i<len;i++) - { - interp_lsp[i] = (1-tmp)*old_lsp[i] + tmp*new_lsp[i]; - } -} - #endif diff --git a/libspeex/lsp.h b/libspeex/lsp.h index 648652f..4f8f9e9 100644 --- a/libspeex/lsp.h +++ b/libspeex/lsp.h @@ -57,8 +57,6 @@ int lpc_to_lsp (spx_coef_t *a, int lpcrdr, spx_lsp_t *freq, int nb, spx_word16_t void lsp_to_lpc(spx_lsp_t *freq, spx_coef_t *ak, int lpcrdr, char *stack);
/*Added by JMV*/
-void lsp_enforce_margin(spx_lsp_t *lsp, int len, spx_word16_t margin);
-
-void lsp_interpolate(spx_lsp_t *old_lsp, spx_lsp_t *new_lsp, spx_lsp_t *interp_lsp, int len, int subframe, int nb_subframes);
+void lsp_interpolate(spx_lsp_t *old_lsp, spx_lsp_t *new_lsp, spx_lsp_t *interp_lsp, int len, int subframe, int nb_subframes, spx_word16_t margin);
#endif /* __AK2LSPD__ */
diff --git a/libspeex/nb_celp.c b/libspeex/nb_celp.c index b6083a1..a36da69 100644 --- a/libspeex/nb_celp.c +++ b/libspeex/nb_celp.c @@ -504,9 +504,7 @@ int nb_encode(void *state, void *vin, SpeexBits *bits) for (i=0;i<NB_ORDER;i++) interp_lsp[i] = lsp[i]; else - lsp_interpolate(st->old_lsp, lsp, interp_lsp, NB_ORDER, NB_NB_SUBFRAMES, NB_NB_SUBFRAMES<<1); - - lsp_enforce_margin(interp_lsp, NB_ORDER, LSP_MARGIN); + lsp_interpolate(st->old_lsp, lsp, interp_lsp, NB_ORDER, NB_NB_SUBFRAMES, NB_NB_SUBFRAMES<<1, LSP_MARGIN); /* Compute interpolated LPCs (unquantized) for whole frame*/ lsp_to_lpc(interp_lsp, interp_lpc, NB_ORDER,stack); @@ -558,9 +556,10 @@ int nb_encode(void *state, void *vin, SpeexBits *bits) } /*Compute "real" excitation*/ - SPEEX_COPY(st->exc, st->winBuf, diff); - SPEEX_COPY(st->exc+diff, in, NB_FRAME_SIZE-diff); - fir_mem16(st->exc, interp_lpc, st->exc, NB_FRAME_SIZE, NB_ORDER, st->mem_exc, stack); + /*SPEEX_COPY(st->exc, st->winBuf, diff); + SPEEX_COPY(st->exc+diff, in, NB_FRAME_SIZE-diff);*/ + fir_mem16(st->winBuf, interp_lpc, st->exc, diff, NB_ORDER, st->mem_exc, stack); + fir_mem16(in, interp_lpc, st->exc+diff, NB_FRAME_SIZE-diff, NB_ORDER, st->mem_exc, stack); /* Compute open-loop excitation gain */ { @@ -821,12 +820,8 @@ int nb_encode(void *state, void *vin, SpeexBits *bits) sw=st->sw+offset; /* LSP interpolation (quantized and unquantized) */ - lsp_interpolate(st->old_lsp, lsp, interp_lsp, NB_ORDER, sub, NB_NB_SUBFRAMES); - lsp_interpolate(st->old_qlsp, qlsp, interp_qlsp, NB_ORDER, sub, NB_NB_SUBFRAMES); - - /* Make sure the filters are stable */ - lsp_enforce_margin(interp_lsp, NB_ORDER, LSP_MARGIN); - lsp_enforce_margin(interp_qlsp, NB_ORDER, LSP_MARGIN); + lsp_interpolate(st->old_lsp, lsp, interp_lsp, NB_ORDER, sub, NB_NB_SUBFRAMES, LSP_MARGIN); + lsp_interpolate(st->old_qlsp, qlsp, interp_qlsp, NB_ORDER, sub, NB_NB_SUBFRAMES, LSP_MARGIN); /* Compute interpolated LPCs (quantized and unquantized) */ lsp_to_lpc(interp_lsp, interp_lpc, NB_ORDER,stack); @@ -1773,10 +1768,7 @@ int nb_decode(void *state, SpeexBits *bits, void *vout) exc=st->exc+offset; /* LSP interpolation (quantized and unquantized) */ - lsp_interpolate(st->old_qlsp, qlsp, interp_qlsp, NB_ORDER, sub, NB_NB_SUBFRAMES); - - /* Make sure the LSP's are stable */ - lsp_enforce_margin(interp_qlsp, NB_ORDER, LSP_MARGIN); + lsp_interpolate(st->old_qlsp, qlsp, interp_qlsp, NB_ORDER, sub, NB_NB_SUBFRAMES, LSP_MARGIN); /* Compute interpolated LPCs (unquantized) */ lsp_to_lpc(interp_qlsp, ak, NB_ORDER, stack); diff --git a/libspeex/sb_celp.c b/libspeex/sb_celp.c index a8e95f2..ab7000c 100644 --- a/libspeex/sb_celp.c +++ b/libspeex/sb_celp.c @@ -783,11 +783,8 @@ int sb_encode(void *state, void *vin, SpeexBits *bits) ALLOC(sw, st->subframeSize, spx_word16_t); /* LSP interpolation (quantized and unquantized) */ - lsp_interpolate(st->old_lsp, lsp, interp_lsp, st->lpcSize, sub, st->nbSubframes); - lsp_interpolate(st->old_qlsp, qlsp, interp_qlsp, st->lpcSize, sub, st->nbSubframes); - - lsp_enforce_margin(interp_lsp, st->lpcSize, LSP_MARGIN); - lsp_enforce_margin(interp_qlsp, st->lpcSize, LSP_MARGIN); + lsp_interpolate(st->old_lsp, lsp, interp_lsp, st->lpcSize, sub, st->nbSubframes, LSP_MARGIN); + lsp_interpolate(st->old_qlsp, qlsp, interp_qlsp, st->lpcSize, sub, st->nbSubframes, LSP_MARGIN); lsp_to_lpc(interp_lsp, interp_lpc, st->lpcSize,stack); lsp_to_lpc(interp_qlsp, st->interp_qlpc, st->lpcSize, stack); @@ -1347,9 +1344,7 @@ int sb_decode(void *state, SpeexBits *bits, void *vout) } /* LSP interpolation */ - lsp_interpolate(st->old_qlsp, qlsp, interp_qlsp, st->lpcSize, sub, st->nbSubframes); - - lsp_enforce_margin(interp_qlsp, st->lpcSize, LSP_MARGIN); + lsp_interpolate(st->old_qlsp, qlsp, interp_qlsp, st->lpcSize, sub, st->nbSubframes, LSP_MARGIN); /* LSP to LPC */ lsp_to_lpc(interp_qlsp, ak, st->lpcSize, stack); |