📄 celp_encoder.c
字号:
/* -----------------------------------------------------------------*/ /* LPC Analysis - I (down sampled parameter computation) */ /* -----------------------------------------------------------------*/ if ((ExcitationMode==RegularPulseExc) && (SampleRateMode == fs16kHz) && (QuantizationMode == VectorQuantizer) && (Wideband_VQ == Scalable_VQ)) { long kk; float dmy_af; for (kk=0; kk < n_lpc_analysis; kk++) { ds_window_offsets[kk] = window_offsets[kk]/2; ds_window_sizes[kk] = window_sizes[kk]/2; } celp_lpc_analysis(Downsampled_signal, ds_ap, &dmy_af, frame_size/2, ds_window_offsets, ds_window_sizes, HammingWindow, PAN_GammaArrayBE, lpc_order/2, n_lpc_analysis); } /* -----------------------------------------------------------------*/ /* LPC Analysis - II (parameter computation) */ /* -----------------------------------------------------------------*/ if (ExcitationMode==RegularPulseExc) { celp_lpc_analysis(PHI_sp_pp_buf, ap, &af_next, frame_size, window_offsets, window_sizes, SquaredHammingWindow, PHI_GammaArrayBE, lpc_order, n_lpc_analysis); } if (ExcitationMode==MultiPulseExc) { if (SampleRateMode == fs8kHz) { celp_lpc_analysis_lag(PHI_sp_pp_buf, ap, &af_next, frame_size_nb, window_offsets, window_sizes, HammingWindow, PAN_GammaArrayBE, lpc_order, n_lpc_analysis); if ( BandwidthScalabilityMode == ON) { float dmy_af_bws; celp_lpc_analysis_bws(bws_sp_buffer, ap_bws, &dmy_af_bws, frame_size_bws, window_offsets_bws, window_sizes_bws, lpc_order_bws, n_lpc_analysis_bws); } } else { celp_lpc_analysis_lag(PHI_sp_pp_buf, ap, &af_next, frame_size, window_offsets, window_sizes, HammingWindow, PAN_GammaArrayBE, lpc_order, n_lpc_analysis); } } /* -----------------------------------------------------------------*/ /* LPC Analysis - III (parameter quantization) */ /* -----------------------------------------------------------------*/ if (ExcitationMode==RegularPulseExc) { VQ_celp_lpc_quantizer(ap, ds_ap, int_ap, codes, lpc_order, num_lpc_indices, n_lpc_analysis, n_subframes, &interpolation_flag, &LPC_Present, Wideband_VQ, PHI_Priv); } if (ExcitationMode==MultiPulseExc) { if (FineRateControl == ON) { VQ_celp_lpc_quantizer(ap, ds_ap, int_ap, codes, lpc_order, num_lpc_indices, n_lpc_analysis, n_subframes, &interpolation_flag, &LPC_Present, Wideband_VQ, PHI_Priv); } else { /* FineRate Control off */ if (SampleRateMode == fs8kHz) { /* LPC quantization & interpolation */ nb_abs_lpc_quantizer(ap, int_ap, codes, lpc_order, num_lpc_indices, n_lpc_analysis, n_subframes, &interpolation_flag, signal_mode, org_frame_bit_allocation, dummy, prev_Qlsp_coefficients); if ( BandwidthScalabilityMode == ON) { for ( k = 0; k < lpc_order; k++ ) { buf_Qlsp_coefficients_bws[k] = PAN_PI * prev_Qlsp_coefficients[k]; } bws_lpc_quantizer(ap_bws, int_ap_bws, codes_bws, lpc_order, lpc_order_bws, num_lpc_indices_bws, n_lpc_analysis_bws, n_subframes_bws,buf_Qlsp_coefficients_bws, prev_Qlsp_coefficients_bws, &org_frame_bit_allocation[PAN_NUM_LPC_INDICES+NEC_NUM_OTHER_INDICES+(num_enhstages+1)*n_subframes*(num_shape_cbks+num_gain_cbks)]); } } if (SampleRateMode == fs16kHz) { /* 16 khz Optimized VQ */ wb_celp_lsp_quantizer(ap, int_ap, codes, lpc_order, num_lpc_indices, n_lpc_analysis, n_subframes, &interpolation_flag, signal_mode, org_frame_bit_allocation, dummy, prev_Qlsp_coefficients); } } } /* -----------------------------------------------------------------*/ /* Also weight the first-order-fit lpc parameter */ /* -----------------------------------------------------------------*/ PHI_af *= (float)GAMMA_WF; if (ExcitationMode == RegularPulseExc) { /* -----------------------------------------------------------------*/ /* Begin Processing on a subframe basis */ /* -----------------------------------------------------------------*/ for (sbfrm_ctr = 0; sbfrm_ctr < n_subframes; sbfrm_ctr++) { long m = sbfrm_ctr * lpc_order; float *sptr; long *lag_cands; float *cbk_sig; float *a_parw; float *residue; float *dummy1; long dum1 = 0; float *Wnum_coeff; float *Wden_coeff; /* -------------------------------------------------------------*/ /* Create Arrays for subframe processing */ /* -------------------------------------------------------------*/ if ( (( lag_cands = (long *)malloc((unsigned int)max_n_lag_candidates * sizeof(long))) == NULL )|| (( residue = (float *)malloc((unsigned int)sbfrm_size * sizeof(float))) == NULL )|| (( cbk_sig = (float *)malloc((unsigned int)sbfrm_size * sizeof(float))) == NULL )|| (( a_parw = (float *)malloc((unsigned int)lpc_order * sizeof(float))) == NULL )|| (( Wden_coeff=(float *)calloc(lpc_order*n_subframes, sizeof(float)))==NULL) || (( Wnum_coeff=(float *)calloc(lpc_order*n_subframes, sizeof(float)))==NULL) || (( dummy1 = (float *)malloc((unsigned int)lpc_order * sizeof(float))) == NULL ) ) { fprintf(stderr, "MALLOC FAILURE in abs_coder \n"); exit(1); } /* -------------------------------------------------------------*/ /* LPC inverse-filtering */ /* -------------------------------------------------------------*/ sptr = PHI_sp_pp_buf + PHI_BUFFER - (3 * frame_size) + (sbfrm_ctr * sbfrm_size); celp_lpc_analysis_filter(sptr, residue, &int_ap[m], lpc_order, sbfrm_size, PHI_Priv); /* -------------------------------------------------------------*/ /* Weighting filter parameter generation */ /* -------------------------------------------------------------*/ celp_weighting_module(&int_ap[m], lpc_order, dummy1, a_parw, (float)GAMMA_WF, (float)GAMMA_WF); /* -------------------------------------------------------------*/ /* Excitation Analysis */ /* -------------------------------------------------------------*/ celp_excitation_analysis ( sp_buf_ptr, residue, a_parw, lpc_order, dummy1, dummy1, PHI_af, lag_cands, max_n_lag_candidates, frame_size, sbfrm_size, n_subframes, signal_mode, org_frame_bit_allocation, &(shape_indices[sbfrm_ctr * num_shape_cbks]), &(gain_indices[sbfrm_ctr * num_gain_cbks]), num_shape_cbks, num_gain_cbks, &dum1, cbk_sig ); /* -------------------------------------------------------------*/ /* Free Arrays for subframe processing */ /* -------------------------------------------------------------*/ free ( lag_cands ); free ( residue ); free ( cbk_sig ); free ( a_parw ); free ( dummy1 ); free(Wnum_coeff); free(Wden_coeff); } } if (ExcitationMode==MultiPulseExc) { long NQlpc_cnt; float *sptr; float *wn_ap; float *wd_ap; float *dec_sig; float *bws_mp_sig; float *dmy_res; /* HP 971112 */ long *dmy_cands; if( (( dec_sig = (float *)malloc((unsigned int)sbfrm_size * sizeof(float))) == NULL )|| (( wn_ap=(float *)calloc(lpc_order*n_subframes, sizeof(float)))==NULL) || (( wd_ap=(float *)calloc(lpc_order*n_subframes, sizeof(float)))==NULL) ) { fprintf(stderr, "MALLOC FAILURE in abs_coder \n"); exit(1); } if (SampleRateMode == fs8kHz) { if( (bws_mp_sig = (float *)malloc((unsigned int)frame_size_nb * sizeof(float))) == NULL ) { fprintf(stderr, "MALLOC FAILURE in abs_coder \n"); exit(1); } } else { if( (bws_mp_sig = (float *)malloc((unsigned int)frame_size * sizeof(float))) == NULL ) { fprintf(stderr, "MALLOC FAILURE in abs_coder \n"); exit(1); } } for ( sbfrm_ctr = 0; sbfrm_ctr < n_subframes; sbfrm_ctr++ ) { NQlpc_cnt = n_lpc_analysis*sbfrm_ctr/n_subframes; celp_weighting_module (ap+lpc_order*NQlpc_cnt, lpc_order, &wn_ap[lpc_order*sbfrm_ctr], &wd_ap[lpc_order*sbfrm_ctr], gamma_num, gamma_den); } for ( sbfrm_ctr = 0; sbfrm_ctr < n_subframes; sbfrm_ctr++ ) { if ((FineRateControl == ON) || (QuantizationMode == ScalarQuantizer)) { sptr = PHI_sp_pp_buf + (sbfrm_ctr * sbfrm_size); } else { if (SampleRateMode == fs8kHz) { sptr = PHI_sp_pp_buf + NEC_PAN_NLB + (sbfrm_ctr * sbfrm_size); } else { sptr = PHI_sp_pp_buf + NEC_FRQ16_NLB + (sbfrm_ctr * sbfrm_size); } } if (SampleRateMode == fs8kHz) { nb_abs_excitation_analysis(sptr, dmy_res, int_ap, lpc_order, wn_ap, wd_ap, PHI_af, dmy_cands, max_n_lag_candidates, frame_size_nb, sbfrm_size, n_subframes, &signal_mode, org_frame_bit_allocation, shape_indices, gain_indices, num_shape_cbks, num_gain_cbks, &rms_index, dec_sig, num_enhstages, bws_mp_sig+sbfrm_size*sbfrm_ctr, SampleRateMode); } else { nb_abs_excitation_analysis(sptr, dmy_res, int_ap, lpc_order, wn_ap, wd_ap, PHI_af, dmy_cands, max_n_lag_candidates, frame_size, sbfrm_size, n_subframes, &signal_mode, org_frame_bit_allocation, shape_indices, gain_indices, num_shape_cbks, num_gain_cbks, &rms_index, dec_sig, num_enhstages, bws_mp_sig+sbfrm_size*sbfrm_ctr, SampleRateMode); } } if ( BandwidthScalabilityMode == ON) { float *wn_ap_bws; float *wd_ap_bws; float *dec_sig_bws; if( (( dec_sig_bws = (float *)malloc((unsigned int)sbfrm_size_bws * sizeof(float))) == NULL )|| (( wn_ap_bws=(float *)calloc(lpc_order_bws*n_subframes_bws, sizeof(float)))==NULL) || (( wd_ap_bws=(float *)calloc(lpc_order_bws*n_subframes_bws, sizeof(float)))==NULL) ) { fprintf(stderr, "MALLOC FAILURE in abs_coder \n"); exit(1); } for ( sbfrm_ctr = 0; sbfrm_ctr < n_subframes_bws; sbfrm_ctr++ ) { NQlpc_cnt = n_lpc_analysis_bws*sbfrm_ctr/n_subframes_bws; celp_weighting_module (ap_bws+lpc_order_bws*NQlpc_cnt, lpc_order_bws, &wn_ap_bws[lpc_order_bws*sbfrm_ctr], &wd_ap_bws[lpc_order_bws*sbfrm_ctr], NEC_GAM_MA, NEC_GAM_AR); } for ( sbfrm_ctr = 0; sbfrm_ctr < n_subframes_bws; sbfrm_ctr++ ) { bws_nb_acb_index[sbfrm_ctr] = shape_indices[sbfrm_ctr*n_subframes/n_subframes_bws*num_shape_cbks]; } for ( sbfrm_ctr = 0; sbfrm_ctr < n_subframes_bws; sbfrm_ctr++ ) { sptr = bws_sp_buffer + NEC_FRQ16_NLB + (sbfrm_ctr * sbfrm_size_bws); bws_excitation_analysis(sptr, int_ap_bws, lpc_order_bws, wn_ap_bws, wd_ap_bws, frame_size_bws, sbfrm_size_bws, n_subframes_bws, signal_mode, &org_frame_bit_allocation[num_indices-n_subframes_bws*(num_shape_cbks+num_gain_cbks)], shape_indices_bws, gain_indices_bws, num_shape_cbks, num_gain_cbks, dec_sig_bws, bws_mp_sig+sbfrm_size*n_subframes/n_subframes_bws*sbfrm_ctr, bws_nb_acb_index, rms_index); } free ( wn_ap_bws ); free ( wd_ap_bws ); free ( dec_sig_bws ); } free ( wn_ap ); free ( wd_ap ); free ( dec_sig ); free ( bws_mp_sig ); } /* CelpBaseFrame() */ /* Celp_LPC() */ /*==================================================================*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -