Commit 99a7ef29 authored by Jean-Marc Valin's avatar Jean-Marc Valin
Browse files

Merged lsp_interpolate() with lsp_enforce_margin()

parent dc31cc4b
...@@ -591,13 +591,17 @@ void lsp_to_lpc(spx_lsp_t *freq,spx_coef_t *ak,int lpcrdr, char *stack) ...@@ -591,13 +591,17 @@ void lsp_to_lpc(spx_lsp_t *freq,spx_coef_t *ak,int lpcrdr, char *stack)
#ifdef FIXED_POINT #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; int i;
spx_word16_t m = margin; spx_word16_t m = margin;
spx_word16_t m2 = 25736-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) if (lsp[0]<m)
lsp[0]=m; lsp[0]=m;
if (lsp[len-1]>m2) if (lsp[len-1]>m2)
...@@ -612,24 +616,16 @@ void lsp_enforce_margin(spx_lsp_t *lsp, int len, spx_word16_t margin) ...@@ -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 #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; 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) if (lsp[0]<LSP_SCALING*margin)
lsp[0]=LSP_SCALING*margin; lsp[0]=LSP_SCALING*margin;
if (lsp[len-1]>LSP_SCALING*(M_PI-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) ...@@ -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 #endif
...@@ -57,8 +57,6 @@ int lpc_to_lsp (spx_coef_t *a, int lpcrdr, spx_lsp_t *freq, int nb, spx_word16_t ...@@ -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); void lsp_to_lpc(spx_lsp_t *freq, spx_coef_t *ak, int lpcrdr, char *stack);
/*Added by JMV*/ /*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, 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);
#endif /* __AK2LSPD__ */ #endif /* __AK2LSPD__ */
...@@ -504,9 +504,7 @@ int nb_encode(void *state, void *vin, SpeexBits *bits) ...@@ -504,9 +504,7 @@ int nb_encode(void *state, void *vin, SpeexBits *bits)
for (i=0;i<NB_ORDER;i++) for (i=0;i<NB_ORDER;i++)
interp_lsp[i] = lsp[i]; interp_lsp[i] = lsp[i];
else else
lsp_interpolate(st->old_lsp, lsp, interp_lsp, NB_ORDER, NB_NB_SUBFRAMES, NB_NB_SUBFRAMES<<1); lsp_interpolate(st->old_lsp, lsp, interp_lsp, NB_ORDER, NB_NB_SUBFRAMES, NB_NB_SUBFRAMES<<1, LSP_MARGIN);
lsp_enforce_margin(interp_lsp, NB_ORDER, LSP_MARGIN);
/* Compute interpolated LPCs (unquantized) for whole frame*/ /* Compute interpolated LPCs (unquantized) for whole frame*/
lsp_to_lpc(interp_lsp, interp_lpc, NB_ORDER,stack); lsp_to_lpc(interp_lsp, interp_lpc, NB_ORDER,stack);
...@@ -558,9 +556,10 @@ int nb_encode(void *state, void *vin, SpeexBits *bits) ...@@ -558,9 +556,10 @@ int nb_encode(void *state, void *vin, SpeexBits *bits)
} }
/*Compute "real" excitation*/ /*Compute "real" excitation*/
SPEEX_COPY(st->exc, st->winBuf, diff); /*SPEEX_COPY(st->exc, st->winBuf, diff);
SPEEX_COPY(st->exc+diff, in, NB_FRAME_SIZE-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); 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 */ /* Compute open-loop excitation gain */
{ {
...@@ -821,12 +820,8 @@ int nb_encode(void *state, void *vin, SpeexBits *bits) ...@@ -821,12 +820,8 @@ int nb_encode(void *state, void *vin, SpeexBits *bits)
sw=st->sw+offset; sw=st->sw+offset;
/* LSP interpolation (quantized and unquantized) */ /* LSP interpolation (quantized and unquantized) */
lsp_interpolate(st->old_lsp, lsp, interp_lsp, NB_ORDER, sub, NB_NB_SUBFRAMES); 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_interpolate(st->old_qlsp, qlsp, interp_qlsp, NB_ORDER, sub, NB_NB_SUBFRAMES, LSP_MARGIN);
/* Make sure the filters are stable */
lsp_enforce_margin(interp_lsp, NB_ORDER, LSP_MARGIN);
lsp_enforce_margin(interp_qlsp, NB_ORDER, LSP_MARGIN);
/* Compute interpolated LPCs (quantized and unquantized) */ /* Compute interpolated LPCs (quantized and unquantized) */
lsp_to_lpc(interp_lsp, interp_lpc, NB_ORDER,stack); lsp_to_lpc(interp_lsp, interp_lpc, NB_ORDER,stack);
...@@ -1773,10 +1768,7 @@ int nb_decode(void *state, SpeexBits *bits, void *vout) ...@@ -1773,10 +1768,7 @@ int nb_decode(void *state, SpeexBits *bits, void *vout)
exc=st->exc+offset; exc=st->exc+offset;
/* LSP interpolation (quantized and unquantized) */ /* LSP interpolation (quantized and unquantized) */
lsp_interpolate(st->old_qlsp, qlsp, interp_qlsp, NB_ORDER, sub, NB_NB_SUBFRAMES); lsp_interpolate(st->old_qlsp, qlsp, interp_qlsp, NB_ORDER, sub, NB_NB_SUBFRAMES, LSP_MARGIN);
/* Make sure the LSP's are stable */
lsp_enforce_margin(interp_qlsp, NB_ORDER, LSP_MARGIN);
/* Compute interpolated LPCs (unquantized) */ /* Compute interpolated LPCs (unquantized) */
lsp_to_lpc(interp_qlsp, ak, NB_ORDER, stack); lsp_to_lpc(interp_qlsp, ak, NB_ORDER, stack);
......
...@@ -783,11 +783,8 @@ int sb_encode(void *state, void *vin, SpeexBits *bits) ...@@ -783,11 +783,8 @@ int sb_encode(void *state, void *vin, SpeexBits *bits)
ALLOC(sw, st->subframeSize, spx_word16_t); ALLOC(sw, st->subframeSize, spx_word16_t);
/* LSP interpolation (quantized and unquantized) */ /* LSP interpolation (quantized and unquantized) */
lsp_interpolate(st->old_lsp, lsp, interp_lsp, st->lpcSize, sub, st->nbSubframes); 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_interpolate(st->old_qlsp, qlsp, interp_qlsp, st->lpcSize, sub, st->nbSubframes, LSP_MARGIN);
lsp_enforce_margin(interp_lsp, st->lpcSize, LSP_MARGIN);
lsp_enforce_margin(interp_qlsp, st->lpcSize, LSP_MARGIN);
lsp_to_lpc(interp_lsp, interp_lpc, st->lpcSize,stack); lsp_to_lpc(interp_lsp, interp_lpc, st->lpcSize,stack);
lsp_to_lpc(interp_qlsp, st->interp_qlpc, 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) ...@@ -1347,9 +1344,7 @@ int sb_decode(void *state, SpeexBits *bits, void *vout)
} }
/* LSP interpolation */ /* LSP interpolation */
lsp_interpolate(st->old_qlsp, qlsp, interp_qlsp, st->lpcSize, sub, st->nbSubframes); lsp_interpolate(st->old_qlsp, qlsp, interp_qlsp, st->lpcSize, sub, st->nbSubframes, LSP_MARGIN);
lsp_enforce_margin(interp_qlsp, st->lpcSize, LSP_MARGIN);
/* LSP to LPC */ /* LSP to LPC */
lsp_to_lpc(interp_qlsp, ak, st->lpcSize, stack); lsp_to_lpc(interp_qlsp, ak, st->lpcSize, stack);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment