📄 phi_lpc.c
字号:
/* Interpolation Procedure on LSPs */
/*------------------------------------------------------------------*/
for(s = 0; s < (int)n_subframes; s++)
{
for(k = 0; k < (int)lpc_order; k++)
{
register float tmp;
tmp = (((float)((int)n_subframes - s - 1) * PHI_Priv->previous_q_lsf_8_dec[k])
+ ((float)(1 + s) * PHI_Priv->current_q_lsf_8_dec[k]))/(float)n_subframes;
int_lsf[k] = tmp;
}
/*--------------------------------------------------------------*/
/*Compute corresponding a-parameters */
/*--------------------------------------------------------------*/
lsf2pc(tmp_lpc_coefficients, int_lsf, lpc_order);
for( k = 0; k < lpc_order; k++)
{
int_Qlpc_coefficients[s*(int)lpc_order + k] = -tmp_lpc_coefficients[k+1];
}
}
/* -----------------------------------------------------------------*/
/* Save memory */
/* -----------------------------------------------------------------*/
for(k=0; k < (int)lpc_order; k++)
{
PHI_Priv->previous_q_lsf_8_dec[k] = PHI_Priv->current_q_lsf_8_dec[k];
PHI_Priv->current_q_lsf_8_dec[k] = PHI_Priv->next_q_lsf_8_dec[k];
}
PHI_Priv->PHI_dec_prev_interpolation_flag = interpolation_flag;
/* -----------------------------------------------------------------*/
/*FREE the malloc'd arrays */
/* -----------------------------------------------------------------*/
free(int_lsf);
free(tmp_lpc_coefficients);
}
else
{ /* 16 khz */
float *int_lsf;
int s,k;
float *tmp_lpc_coefficients;
if (Wideband_VQ == Scalable_VQ)
{
/* 16 khz Scalable VQ */
/*------------------------------------------------------------------*/
/* Allocate space for current_rfc and current lar */
/*------------------------------------------------------------------*/
if
(
(( int_lsf = (float *)malloc((unsigned int)lpc_order * sizeof(float))) == NULL )
)
{
printf("MALLOC FAILURE in Routine abs_lpc_quantizer \n");
exit(1);
}
if((tmp_lpc_coefficients=(float *)calloc(lpc_order+1, sizeof(float)))==NULL) {
printf("\n Memory allocation error in abs_lpc_quantizer\n");
exit(4);
}
if (interpolation_flag)
{
/*----------------------------------------------------------*/
/* Compute LSP coeffs of the next frame */
/*----------------------------------------------------------*/
mod_nb_abs_lsp_decode(lpc_indices, PHI_Priv->previous_q_lsf_8_dec,
PHI_Priv->next_q_lsf_8_dec,
lpc_order/2, 5);
mod_nec_bws_lsp_decoder( lpc_indices + 5, PHI_Priv->next_q_lsf_8_dec,
PHI_Priv->next_q_lsf_16_dec,
lpc_order, lpc_order/2, 6, PHI_Priv->blsp_dec, PHI_Priv);
/*------------------------------------------------------------------*/
/* Interpolate LSP coeffs to obtain coeficients of cuurent frame */
/*------------------------------------------------------------------*/
for(k = 0; k < (int)lpc_order; k++)
{
PHI_Priv->current_q_lsf_16_dec[k] =
(float)0.5 * (PHI_Priv->previous_q_lsf_16_dec[k] + PHI_Priv->next_q_lsf_16_dec[k]);
}
}
else
{
if (PHI_Priv->PHI_dec_prev_interpolation_flag == 0)
{
/*--------------------------------------------------------------*/
/* Compute LSP coeffs of the current frame */
/*--------------------------------------------------------------*/
mod_nb_abs_lsp_decode(lpc_indices, PHI_Priv->previous_q_lsf_8_dec,
PHI_Priv->current_q_lsf_8_dec,
lpc_order/2, 5);
mod_nec_bws_lsp_decoder( lpc_indices + 5, PHI_Priv->current_q_lsf_8_dec,
PHI_Priv->current_q_lsf_16_dec,
lpc_order, lpc_order/2, 6, PHI_Priv->blsp_dec, PHI_Priv);
}
else
{
/* LSPs received in the previous frame: do nothing */
;
}
}
/*------------------------------------------------------------------*/
/* Interpolation Procedure on LSPs */
/*------------------------------------------------------------------*/
for(s = 0; s < (int)n_subframes; s++)
{
for(k = 0; k < (int)lpc_order; k++)
{
register float tmp;
tmp = (((float)((int)n_subframes - s - 1) * PHI_Priv->previous_q_lsf_16_dec[k])
+ ((float)(1 + s) * PHI_Priv->current_q_lsf_16_dec[k]))/(float)n_subframes;
int_lsf[k] = tmp;
}
/*--------------------------------------------------------------*/
/*Compute corresponding a-parameters */
/*--------------------------------------------------------------*/
lsf2pc(tmp_lpc_coefficients, int_lsf, lpc_order);
for( k = 0; k < lpc_order; k++)
{
int_Qlpc_coefficients[s*(int)lpc_order + k] = -tmp_lpc_coefficients[k+1];
}
}
/* -----------------------------------------------------------------*/
/* Save memory */
/* -----------------------------------------------------------------*/
for(k=0; k < (int)lpc_order/2; k++)
{
PHI_Priv->previous_q_lsf_8_dec[k] = PHI_Priv->current_q_lsf_8_dec[k];
PHI_Priv->current_q_lsf_8_dec[k] = PHI_Priv->next_q_lsf_8_dec[k];
}
for(k=0; k < (int)lpc_order; k++)
{
PHI_Priv->previous_q_lsf_16_dec[k] = PHI_Priv->current_q_lsf_16_dec[k];
PHI_Priv->current_q_lsf_16_dec[k] = PHI_Priv->next_q_lsf_16_dec[k];
}
PHI_Priv->PHI_dec_prev_interpolation_flag = interpolation_flag;
/* -----------------------------------------------------------------*/
/*FREE the malloc'd arrays */
/* -----------------------------------------------------------------*/
FREE(int_lsf);
FREE(tmp_lpc_coefficients);
}
else
{ /* 16 khz Optimized VQ */
float *int_lsf;
int s,k;
float *tmp_lpc_coefficients;
/*------------------------------------------------------------------*/
/* Allocate space for current_rfc and current lar */
/*------------------------------------------------------------------*/
if
(
(( int_lsf = (float *)malloc((unsigned int)lpc_order * sizeof(float))) == NULL )
)
{
printf("MALLOC FAILURE in Routine abs_lpc_quantizer \n");
exit(1);
}
if((tmp_lpc_coefficients=(float *)calloc(lpc_order+1, sizeof(float)))==NULL) {
printf("\n Memory allocation error in abs_lpc_quantizer\n");
exit(4);
}
if (interpolation_flag)
{
/*----------------------------------------------------------*/
/* Compute LSP coeffs of the next frame */
/*----------------------------------------------------------*/
mod_wb_celp_lsp_decode(lpc_indices, PHI_Priv->previous_q_lsf_16_dec,
PHI_Priv->next_q_lsf_16_dec, lpc_order,
num_lpc_indices);
/*------------------------------------------------------------------*/
/* Interpolate LSP coeffs to obtain coeficients of cuurent frame */
/*------------------------------------------------------------------*/
for(k = 0; k < (int)lpc_order; k++)
{
PHI_Priv->current_q_lsf_16_dec[k] =
(float)0.5 * (PHI_Priv->previous_q_lsf_16_dec[k] + PHI_Priv->next_q_lsf_16_dec[k]);
}
}
else
{
if (PHI_Priv->PHI_dec_prev_interpolation_flag == 0)
{
/*--------------------------------------------------------------*/
/* Compute LSP coeffs of the current frame */
/*--------------------------------------------------------------*/
mod_wb_celp_lsp_decode(lpc_indices,
PHI_Priv->previous_q_lsf_16_dec,
PHI_Priv->current_q_lsf_16_dec,
lpc_order, num_lpc_indices);
}
else
{
/* LSPs received in the previous frame: do nothing */
;
}
}
/*------------------------------------------------------------------*/
/* Interpolation Procedure on LSPs */
/*------------------------------------------------------------------*/
for(s = 0; s < (int)n_subframes; s++)
{
for(k = 0; k < (int)lpc_order; k++)
{
register float tmp;
tmp = (((float)((int)n_subframes - s - 1) * PHI_Priv->previous_q_lsf_16_dec[k])
+ ((float)(1 + s) * PHI_Priv->current_q_lsf_16_dec[k]))/(float)n_subframes;
int_lsf[k] = tmp;
}
/*--------------------------------------------------------------*/
/*Compute corresponding a-parameters */
/*--------------------------------------------------------------*/
lsf2pc(tmp_lpc_coefficients, int_lsf, lpc_order);
for( k = 0; k < lpc_order; k++)
{
int_Qlpc_coefficients[s*(int)lpc_order + k] = -tmp_lpc_coefficients[k+1];
}
}
/* -----------------------------------------------------------------*/
/* Save memory */
/* -----------------------------------------------------------------*/
for(k=0; k < (int)lpc_order; k++)
{
PHI_Priv->previous_q_lsf_16_dec[k] = PHI_Priv->current_q_lsf_16_dec[k];
PHI_Priv->current_q_lsf_16_dec[k] = PHI_Priv->next_q_lsf_16_dec[k];
}
PHI_Priv->PHI_dec_prev_interpolation_flag = interpolation_flag;
/* -----------------------------------------------------------------*/
/*FREE the malloc'd arrays */
/* -----------------------------------------------------------------*/
FREE (int_lsf);
FREE (tmp_lpc_coefficients);
}
}
}
/*======================================================================*/
/* Function Definition:celp_lpc_quantizer using VQ */
/*======================================================================*/
void VQ_celp_lpc_quantizer
(
float lpc_coefficients[], /* In: Current unquantised a-pars */
float lpc_coefficients_8[], /* In: Current unquantised a-pars(8 kHz)*/
float int_Qlpc_coefficients[], /* Out: Qaunt/interpolated a-pars */
long lpc_indices[], /* Out: Codes thar are transmitted */
long lpc_order, /* In: Order of LPC */
long num_lpc_indices, /* In: Number of packes LPC codes */
long n_lpc_analysis, /* In: Number of LPC/frame */
long n_subframes, /* In: Number of subframes */
long *interpolation_flag, /* Out: Interpolation Flag */
long *send_lpc_flag, /* Out: Send LPC flag */
long Wideband_VQ,
PHI_PRIV_TYPE *PHI_Priv /* In/Out: PHI private data (instance context) */
)
{
if (lpc_order == ORDER_LPC_8)
{ /* fs = 8 khz */
float *int_lsf;
long *next_codes;
long *current_codes;
float *tmp_lpc_coefficients;
int i,s,k;
/*------------------------------------------------------------------*/
/* Allocate space for current_rfc and current lar */
/*------------------------------------------------------------------*/
if
(
(( int_lsf = (float *)malloc((unsigned int)lpc_order * sizeof(float))) == NULL ) ||
(( next_codes = (long *)malloc((unsigned int)num_lpc_indices * sizeof(long))) == NULL ) ||
(( current_codes = (long *)malloc((unsigned int)num_lpc_indices * sizeof(long))) == NULL )
)
{
printf("MALLOC FAILURE in Routine abs_lpc_quantizer \n");
exit(1);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -