📄 celp_decoder.c
字号:
*(*org_frame_bit_allocation+(ctr++)) = PAN_BIT_LSP22_1;
*(*org_frame_bit_allocation+(ctr++)) = PAN_BIT_LSP22_2;
*(*org_frame_bit_allocation+(ctr++)) = PAN_BIT_LSP22_3;
*(*org_frame_bit_allocation+(ctr++)) = PAN_BIT_LSP22_4;
*(*org_frame_bit_allocation+(ctr++)) = NEC_BIT_MODE;
*(*org_frame_bit_allocation+(ctr++)) = NEC_BIT_RMS;
for ( i = 0; i < *n_subframes; i++ ) {
*(*org_frame_bit_allocation+(ctr++)) = NEC_BIT_ACB;
*(*org_frame_bit_allocation+(ctr++)) = mp_pos_bits;
*(*org_frame_bit_allocation+(ctr++)) = mp_sgn_bits;
*(*org_frame_bit_allocation+(ctr++)) = NEC_BIT_GAIN;
}
for ( i = 0; i < num_enhstages; i++ ) {
for ( j = 0; j < *n_subframes; j++ ) {
*(*org_frame_bit_allocation+(ctr++)) = 0;
*(*org_frame_bit_allocation+(ctr++)) = enh_pos_bits;
*(*org_frame_bit_allocation+(ctr++)) = enh_sgn_bits;
*(*org_frame_bit_allocation+(ctr++)) = NEC_BIT_ENH_GAIN;
}
}
if (*BandwidthScalabilityMode==ON) {
*(*org_frame_bit_allocation+(ctr++)) = NEC_BIT_LSP1620_0;
*(*org_frame_bit_allocation+(ctr++)) = NEC_BIT_LSP1620_1;
*(*org_frame_bit_allocation+(ctr++)) = NEC_BIT_LSP1620_2;
*(*org_frame_bit_allocation+(ctr++)) = NEC_BIT_LSP1620_3;
*(*org_frame_bit_allocation+(ctr++)) = NEC_BIT_LSP1620_4;
*(*org_frame_bit_allocation+(ctr++)) = NEC_BIT_LSP1620_5;
for ( i = 0; i < n_subframes_bws; i++ ) {
*(*org_frame_bit_allocation+(ctr++)) = NEC_BIT_ACB_FRQ16;
*(*org_frame_bit_allocation+(ctr++)) = bws_pos_bits;
*(*org_frame_bit_allocation+(ctr++)) = bws_sgn_bits;
*(*org_frame_bit_allocation+(ctr++)) = NEC_BIT_GAIN_FRQ16;
}
}
if((prev_Qlsp_coefficients=(float *)calloc(*lpc_order,
sizeof(float)))==NULL) {
fprintf(stderr,"\n memory allocation error in initialization_decoder\n");
exit(5);
}
for(i=0;i<(*lpc_order);i++)
*(prev_Qlsp_coefficients+i) = (i+1)/(float)((*lpc_order)+1);
if (*BandwidthScalabilityMode==ON) {
if((buf_Qlsp_coefficients_bws=(float *)calloc(*lpc_order,
sizeof(float)))==NULL) {
fprintf(stderr,"\n memory allocation error in initialization_decoder\n");
exit(5);
}
if((prev_Qlsp_coefficients_bws=(float *)calloc(lpc_order_bws,
sizeof(float)))==NULL) {
fprintf(stderr,"\n memory allocation error in initialization_decoder\n");
exit(5);
}
for(i=0;i<(lpc_order_bws);i++)
*(prev_Qlsp_coefficients_bws+i) = PAN_PI * (i+1)
/ (float)(lpc_order_bws+1);
}
/* submodules for initialization */
if ((*BandwidthScalabilityMode==ON)&&(dec_bwsmode)) {
PHI_InitLpcAnalysisDecoder(lpc_order_bws, *lpc_order, InstCtxt->PHI_Priv);
} else {
PHI_InitLpcAnalysisDecoder(*lpc_order, *lpc_order, InstCtxt->PHI_Priv);
}
if (*LosslessCodingMode == ON) {
*num_lpc_indices = 10;
}
}
if (*SampleRateMode == fs16kHz) {
int i, j;
long ctr;
num_enhstages = *NumEnhLayers;
dec_enhstages = DecEnhStage;
if ((*MPE_Configuration>=0) && (*MPE_Configuration<7)) {
*frame_size = NEC_FRAME20MS_FRQ16;
*n_subframes = NEC_NSF4;
} else if((*MPE_Configuration>=8)&&(*MPE_Configuration<16)) {
*frame_size = NEC_FRAME20MS_FRQ16;
*n_subframes = NEC_NSF8;
} else if((*MPE_Configuration>=16)&&(*MPE_Configuration<23)) {
*frame_size = NEC_FRAME10MS_FRQ16;
*n_subframes = NEC_NSF2;
} else if((*MPE_Configuration>=24)&&(*MPE_Configuration<32)) {
*frame_size = NEC_FRAME10MS_FRQ16;
*n_subframes = NEC_NSF4;
} else {
fprintf(stderr,"Error: Illegal BitRate configuration.\n");
exit(1);
}
*sbfrm_size = *frame_size/(*n_subframes);
*lpc_order = NEC_LPC_ORDER_FRQ16;
*num_shape_cbks = NEC_NUM_SHAPE_CBKS;
*num_gain_cbks = NEC_NUM_GAIN_CBKS;
*num_lpc_indices = PAN_NUM_LPC_INDICES_W;
num_indices = NEC_NUM_OTHER_INDICES + PAN_NUM_LPC_INDICES_W
+ (num_enhstages + 1) * (*n_subframes) *
(NEC_NUM_SHAPE_CBKS+NEC_NUM_GAIN_CBKS);
switch ( *MPE_Configuration ) {
case 0:
mp_pos_bits = 20; mp_sgn_bits = 5; break;
case 1:
mp_pos_bits = 22; mp_sgn_bits = 6; break;
case 2:
mp_pos_bits = 24; mp_sgn_bits = 7; break;
case 3:
mp_pos_bits = 26; mp_sgn_bits = 8; break;
case 4:
mp_pos_bits = 28; mp_sgn_bits = 9; break;
case 5:
mp_pos_bits = 30; mp_sgn_bits = 10; break;
case 6:
mp_pos_bits = 31; mp_sgn_bits = 11; break;
case 7:
break;
case 8:
mp_pos_bits = 11; mp_sgn_bits = 3; break;
case 9:
mp_pos_bits = 13; mp_sgn_bits = 4; break;
case 10:
mp_pos_bits = 15; mp_sgn_bits = 5; break;
case 11:
mp_pos_bits = 16; mp_sgn_bits = 6; break;
case 12:
mp_pos_bits = 17; mp_sgn_bits = 7; break;
case 13:
mp_pos_bits = 18; mp_sgn_bits = 8; break;
case 14:
mp_pos_bits = 19; mp_sgn_bits = 9; break;
case 15:
mp_pos_bits = 20; mp_sgn_bits = 10; break;
case 16:
mp_pos_bits = 20; mp_sgn_bits = 5; break;
case 17:
mp_pos_bits = 22; mp_sgn_bits = 6; break;
case 18:
mp_pos_bits = 24; mp_sgn_bits = 7; break;
case 19:
mp_pos_bits = 26; mp_sgn_bits = 8; break;
case 20:
mp_pos_bits = 28; mp_sgn_bits = 9; break;
case 21:
mp_pos_bits = 30; mp_sgn_bits = 10; break;
case 22:
mp_pos_bits = 31; mp_sgn_bits = 11; break;
case 23:
break;
case 24:
mp_pos_bits = 11; mp_sgn_bits = 3; break;
case 25:
mp_pos_bits = 13; mp_sgn_bits = 4; break;
case 26:
mp_pos_bits = 15; mp_sgn_bits = 5; break;
case 27:
mp_pos_bits = 16; mp_sgn_bits = 6; break;
case 28:
mp_pos_bits = 17; mp_sgn_bits = 7; break;
case 29:
mp_pos_bits = 18; mp_sgn_bits = 8; break;
case 30:
mp_pos_bits = 19; mp_sgn_bits = 9; break;
case 31:
mp_pos_bits = 20; mp_sgn_bits = 10; break;
}
if ( *sbfrm_size == NEC_SBFRM_SIZE40 ) {
enh_pos_bits = NEC_BIT_ENH_POS40_2;
enh_sgn_bits = NEC_BIT_ENH_SGN40_2;
} else {
enh_pos_bits = NEC_BIT_ENH_POS80_4;
enh_sgn_bits = NEC_BIT_ENH_SGN80_4;
}
if((*org_frame_bit_allocation=(long *)calloc(num_indices,
sizeof(long)))==NULL) {
fprintf(stderr,"\n memory allocation error in initialization_encoder\n");
exit(3);
}
ctr = 0;
*(*org_frame_bit_allocation+(ctr++)) = PAN_BIT_LSP_WL_0;
*(*org_frame_bit_allocation+(ctr++)) = PAN_BIT_LSP_WL_1;
*(*org_frame_bit_allocation+(ctr++)) = PAN_BIT_LSP_WL_2;
*(*org_frame_bit_allocation+(ctr++)) = PAN_BIT_LSP_WL_3;
*(*org_frame_bit_allocation+(ctr++)) = PAN_BIT_LSP_WL_4;
*(*org_frame_bit_allocation+(ctr++)) = PAN_BIT_LSP_WU_0;
*(*org_frame_bit_allocation+(ctr++)) = PAN_BIT_LSP_WU_1;
*(*org_frame_bit_allocation+(ctr++)) = PAN_BIT_LSP_WU_2;
*(*org_frame_bit_allocation+(ctr++)) = PAN_BIT_LSP_WU_3;
*(*org_frame_bit_allocation+(ctr++)) = PAN_BIT_LSP_WU_4;
*(*org_frame_bit_allocation+(ctr++)) = NEC_BIT_MODE;
*(*org_frame_bit_allocation+(ctr++)) = NEC_BIT_RMS;
for ( i = 0; i < *n_subframes; i++ ) {
*(*org_frame_bit_allocation+(ctr++)) = NEC_ACB_BIT_WB;
*(*org_frame_bit_allocation+(ctr++)) = mp_pos_bits;
*(*org_frame_bit_allocation+(ctr++)) = mp_sgn_bits;
*(*org_frame_bit_allocation+(ctr++)) = NEC_BIT_GAIN_WB;
}
for ( i = 0; i < num_enhstages; i++ ) {
for ( j = 0; j < *n_subframes; j++ ) {
*(*org_frame_bit_allocation+(ctr++)) = 0;
*(*org_frame_bit_allocation+(ctr++)) = enh_pos_bits;
*(*org_frame_bit_allocation+(ctr++)) = enh_sgn_bits;
*(*org_frame_bit_allocation+(ctr++)) = NEC_BIT_ENH_GAIN;
}
}
if((prev_Qlsp_coefficients=(float *)calloc(*lpc_order,
sizeof(float)))==NULL) {
fprintf(stderr,"\n memory allocation error in initialization_decoder\n");
exit(5);
}
for(i=0;i<(*lpc_order);i++)
*(prev_Qlsp_coefficients+i) = (i+1)/(float)((*lpc_order)+1);
/* submodules for initialization */
PHI_InitLpcAnalysisDecoder(*lpc_order, *lpc_order, InstCtxt->PHI_Priv);
}
}
}
/*======================================================================*/
/* Function Definition: celp_close_decoder */
/*======================================================================*/
void celp_close_decoder
(
long ExcitationMode,
long SampleRateMode,
long BandwidthScalabilityMode,
long frame_bit_allocation[], /* In: bit num. for each index */
void **InstanceContext /* In/Out: handle to instance context */
)
{
INST_CONTEXT_LPC_DEC_TYPE *InstCtxt;
PHI_PRIV_TYPE *PHI_Priv;
/* -----------------------------------------------------------------*/
/* Set up pointers to private data */
/* -----------------------------------------------------------------*/
PHI_Priv = ((INST_CONTEXT_LPC_DEC_TYPE *) *InstanceContext)->PHI_Priv;
/* -----------------------------------------------------------------*/
/* */
/* -----------------------------------------------------------------*/
if (ExcitationMode == RegularPulseExc)
{
PHI_ClosePostProcessor(PHI_Priv);
PHI_close_excitation_generation(PHI_Priv);
PHI_FreeLpcAnalysisDecoder(PHI_Priv);
PHI_free_bit_allocation(frame_bit_allocation);
}
if (ExcitationMode == MultiPulseExc)
{
if (prev_Qlsp_coefficients != NULL) {
FREE(prev_Qlsp_coefficients);
prev_Qlsp_coefficients = NULL;
}
PHI_FreeLpcAnalysisDecoder(PHI_Priv);
if (BandwidthScalabilityMode == ON)
{
if (buf_Qlsp_coefficients_bws != NULL) {
FREE(buf_Qlsp_coefficients_bws);
buf_Qlsp_coefficients_bws = NULL;
}
if (prev_Qlsp_coefficients_bws != NULL) {
FREE(prev_Qlsp_coefficients_bws);
prev_Qlsp_coefficients_bws = NULL;
}
}
}
/* -----------------------------------------------------------------*/
/* Print Total Frames Processed */
/* -----------------------------------------------------------------*/
if (CELPdecDebugLevel) { /* HP 971120 */
fprintf(stderr,"\n");
fprintf(stderr,"Total Frames: %ld \n", frame_ctr);
}
/* -----------------------------------------------------------------*/
/* Dispose of private storage for instance context */
/* -----------------------------------------------------------------*/
InstCtxt = (INST_CONTEXT_LPC_DEC_TYPE *)*InstanceContext;
if (InstCtxt->PHI_Priv != NULL) {
FREE(InstCtxt->PHI_Priv);
InstCtxt->PHI_Priv = NULL;
}
FREE(InstCtxt);
*InstanceContext = NULL;
}
/*======================================================================*/
/* H I S T O R Y */
/*======================================================================*/
/* 01-09-96 R. Taori Initial Version */
/* 18-09-96 R. Taori Brought in line with MPEG-4 Interface */
/* 05-05-98 R. Funken Brought in line with MPEG-4 FCD: 3 complexity levels */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -