📄 celp_encoder.c
字号:
if (ExcitationMode == MultiPulseExc) { if (SampleRateMode == fs8kHz) { int i, j; long target_mp_bits, mp_pos_bits, mp_sgn_bits; long enh_pos_bits, enh_sgn_bits; long bws_pos_bits, bws_sgn_bits; long ctr, calc_bit_rate; long CoreBitRate; long num_bits_lpc_int; int high_bound_found = 0; long BITRATE1; long BITRATE2; long BITRATE3; long BITRATE4; long BITRATE5; long BITRATE6; long BITRATE7; long len_lpc_analysis; if (QuantizationMode == VectorQuantizer) { BITRATE1=3850; BITRATE2=4900; BITRATE3=5700; BITRATE4=7700; BITRATE5=11000; BITRATE6=12200; BITRATE7=6200; } num_enhstages = NumEnhLayers; if (BandwidthScalabilityMode==ON) { CoreBitRate = BWS_nb_bitrate - NEC_ENH_BITRATE * num_enhstages; } else { CoreBitRate = bit_rate - NEC_ENH_BITRATE * num_enhstages; } if ( CoreBitRate == BITRATE7 && num_enhstages > 0 ) { fprintf(stderr,"Error: BitRateScalable mode is not suported at the Specified BitRate.\n"); exit(1); } *lpc_order = NEC_LPC_ORDER; *num_shape_cbks = NEC_NUM_SHAPE_CBKS; *num_gain_cbks = NEC_NUM_GAIN_CBKS; *num_lpc_indices = PAN_NUM_LPC_INDICES; *n_lag_candidates = PAN_N_PCAN_INT; *min_pitch_frequency = sampling_frequency/(float)NEC_PITCH_MAX; *max_pitch_frequency = sampling_frequency/(float)NEC_PITCH_MIN; if (FineRateControl == ON) { num_bits_lpc_int = 2+PAN_BIT_LSP22_0 +PAN_BIT_LSP22_1+PAN_BIT_LSP22_2 +PAN_BIT_LSP22_3+PAN_BIT_LSP22_4; } else { num_bits_lpc_int = PAN_BIT_LSP22_0+PAN_BIT_LSP22_1+PAN_BIT_LSP22_2 +PAN_BIT_LSP22_3+PAN_BIT_LSP22_4; } while (!high_bound_found) { if ( CoreBitRate == BITRATE7 ) { frame_size_nb = NEC_FRAME30MS; *n_subframes = NEC_NSF4; len_lpc_analysis = NEC_FRAME30MS/NEC_NSF4; } else { len_lpc_analysis = NEC_LEN_LPC_ANALYSIS; if ( CoreBitRate >= BITRATE1 && CoreBitRate < BITRATE2 ) { frame_size_nb = NEC_FRAME40MS; *n_subframes = NEC_NSF4; } if ( CoreBitRate >= BITRATE2 && CoreBitRate < BITRATE3 ) { frame_size_nb = NEC_FRAME30MS; *n_subframes = NEC_NSF3; } if ( CoreBitRate >= BITRATE3 && CoreBitRate < BITRATE4 ) { frame_size_nb = NEC_FRAME20MS; *n_subframes = NEC_NSF2; } if ( CoreBitRate >= BITRATE4 && CoreBitRate < BITRATE5 ) { frame_size_nb = NEC_FRAME20MS; *n_subframes = NEC_NSF4; } if ( CoreBitRate >= BITRATE5 && CoreBitRate <= BITRATE6 ) { frame_size_nb = NEC_FRAME10MS; *n_subframes = NEC_NSF2; } if ( CoreBitRate < BITRATE1 || CoreBitRate > BITRATE6 ) { fprintf(stderr,"Error: Specified BitRate %ld is not supported.\n", CoreBitRate); exit(1); } } *sbfrm_size = (frame_size_nb)/(*n_subframes); *n_lpc_analysis = (frame_size_nb)/len_lpc_analysis; num_indices = NEC_NUM_OTHER_INDICES + PAN_NUM_LPC_INDICES + (num_enhstages + 1) * (*n_subframes) * (NEC_NUM_SHAPE_CBKS+NEC_NUM_GAIN_CBKS); target_mp_bits=(long)(((float)(frame_size_nb)*CoreBitRate/8000 - (num_bits_lpc_int+NEC_BIT_MODE +NEC_BIT_RMS)) /(*n_subframes) - (NEC_BIT_ACB + NEC_BIT_GAIN)); nec_mp_config((*sbfrm_size),target_mp_bits, &mp_pos_bits,&mp_sgn_bits); calc_bit_rate=(long)(((num_bits_lpc_int+NEC_BIT_MODE+NEC_BIT_RMS) +(NEC_BIT_ACB+mp_pos_bits+mp_sgn_bits +NEC_BIT_GAIN)*(*n_subframes)) *8000/(frame_size_nb)); if ( CoreBitRate != calc_bit_rate ) { if (FineRateControl == OFF) { fprintf(stderr,"Error: Specified BitRate %ld is not supported.\n", bit_rate); fprintf(stderr,"\t Please set BitRate at %ld\n", calc_bit_rate+num_enhstages*NEC_ENH_BITRATE); exit(1); } else { CoreBitRate += 25; } } else { high_bound_found = 1; if ( CoreBitRate == BITRATE7 ) { *MPE_Configuration = 27; } else { if ( CoreBitRate >= BITRATE1 && CoreBitRate < BITRATE2 ) { *MPE_Configuration = mp_sgn_bits-3; } if ( CoreBitRate >= BITRATE2 && CoreBitRate < BITRATE3 ) { *MPE_Configuration = (mp_sgn_bits-5)+3; } if ( CoreBitRate >= BITRATE3 && CoreBitRate < BITRATE4 ) { *MPE_Configuration = (mp_sgn_bits-6)+6; } if ( CoreBitRate >= BITRATE4 && CoreBitRate < BITRATE5 ) { *MPE_Configuration = (mp_sgn_bits-4)+13; } if ( CoreBitRate >= BITRATE5 && CoreBitRate <= BITRATE6 ) { *MPE_Configuration = (mp_sgn_bits-8)+22; } } } } if (BandwidthScalabilityMode==ON) { frame_size_bws = frame_size_nb * 2; n_subframes_bws = frame_size_bws/80; sbfrm_size_bws = frame_size_bws / n_subframes_bws; lpc_order_bws = NEC_LPC_ORDER_FRQ16; n_lpc_analysis_bws = frame_size_bws / NEC_LEN_LPC_ANALYSIS; target_mp_bits=(long)(((float)(frame_size_bws)* (bit_rate-BWS_nb_bitrate) /16000 - NEC_BIT_LSP1620) /n_subframes_bws - (NEC_BIT_ACB_FRQ16 + NEC_BIT_GAIN_FRQ16)); nec_mp_config(sbfrm_size_bws,target_mp_bits, &bws_pos_bits,&bws_sgn_bits); calc_bit_rate=(long)((float)(NEC_BIT_LSP1620 +(NEC_BIT_ACB_FRQ16 + bws_pos_bits +bws_sgn_bits + NEC_BIT_GAIN_FRQ16) *n_subframes_bws)*16000/(frame_size_bws)+0.5); if ( (bit_rate-BWS_nb_bitrate) != calc_bit_rate ) { fprintf(stderr,"Error: Specified BitRate %ld is not supported.\n",bit_rate); exit(1); } if ( bws_sgn_bits < 6 || (bws_sgn_bits%2) != 0 ) { fprintf(stderr,"Error: Specified BitRate %ld is not supported.\n",bit_rate); exit(1); } else { *BWS_Configuration = (bws_sgn_bits-6)/2; } *frame_size = frame_size_bws; num_lpc_indices_bws = NEC_NUM_LPC_INDICES_FRQ16 ; num_indices += NEC_NUM_LPC_INDICES_FRQ16 + n_subframes_bws * (NEC_NUM_SHAPE_CBKS +NEC_NUM_GAIN_CBKS); } else { *frame_size = frame_size_nb; } if((*window_sizes=(long *)calloc(*n_lpc_analysis, sizeof(long)))==NULL) { fprintf(stderr,"\n memory allocation error in initialization_encoder\n"); exit(1); } if((*window_offsets=(long *)calloc(*n_lpc_analysis, sizeof(long)))==NULL) { fprintf(stderr,"\n memory allocation error in initialization_encoder\n"); exit(2); } if ((FineRateControl == ON) || (QuantizationMode == ScalarQuantizer)) { for(i=0;i<(*n_lpc_analysis);i++) { *(*window_sizes+i) = NEC_PAN_NLB+NEC_LEN_LPC_ANALYSIS+NEC_PAN_NLA; *(*window_offsets+i) = i*NEC_LEN_LPC_ANALYSIS + ((*frame_size) - NEC_PAN_NLB); } } else { for(i=0;i<(*n_lpc_analysis);i++) { *(*window_sizes+i) = NEC_PAN_NLB+len_lpc_analysis+NEC_PAN_NLA; *(*window_offsets+i) = i*len_lpc_analysis; } } 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_LSP22_0; *(*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; } if ( *sbfrm_size == (NEC_FRAME20MS/NEC_NSF4) ) { 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; } 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 (FineRateControl == ON) { PHI_BUFFER = buffer_size = NEC_PAN_NLB+frame_size_nb+NEC_PAN_NLA + (frame_size_nb-NEC_PAN_NLB); /* AG: one frame delay for interpolation */ } else { PHI_BUFFER = buffer_size = NEC_PAN_NLB+frame_size_nb+NEC_PAN_NLA; } /* momory allocation to static parameters */ if((PHI_sp_pp_buf=(float *)calloc(buffer_size, sizeof(float)))==NULL) { fprintf(stderr,"\n memory allocation error in initialization_encoder\n"); exit(4); } for(i=0;i<buffer_size;i++) *(PHI_sp_pp_buf+i) = 0.; if((prev_Qlsp_coefficients=(float *)calloc(*lpc_order, sizeof(float)))==NULL) { fprintf(stderr,"\n memory allocation error in initialization_encoder\n"); exit(5); } for(i=0;i<(*lpc_order);i++) *(prev_Qlsp_coefficients+i) = (i+1)/(float)((*lpc_order)+1); gamma_num=PAN_GAM_MA; gamma_den=PAN_GAM_AR; /* momory allocation to static parameters */ if (BandwidthScalabilityMode==ON) { if((window_sizes_bws=(long *)calloc(n_lpc_analysis_bws, sizeof(long)))==NULL) { fprintf(stderr,"\n memory allocation error in initialization_encoder\n"); exit(1); } if((window_offsets_bws=(long *)calloc(n_lpc_analysis_bws, sizeof(long)))==NULL) { fprintf(stderr,"\n memory allocation error in initialization_encoder\n"); exit(2); } for(i=0;i<n_lpc_analysis_bws;i++) { *(window_sizes_bws+i) = NEC_FRQ16_NLB+NEC_LEN_LPC_ANALYSIS + NEC_FRQ16_NLA; *(window_offsets_bws+i) = i*NEC_LEN_LPC_ANALYSIS; } buffer_size_bws = NEC_FRQ16_NLB+(frame_size_bws) + NEC_FRQ16_NLA+NEC_LPF_DELAY; if((bws_sp_buffer=(float *)calloc(buffer_size_bws, sizeof(float)))==NULL) { fprintf(stderr,"\n memory allocation error in initialization_encoder\n"); exit(4); } for(i=0;i<buffer_size_bws;i++) *(bws_sp_buffer+i) = 0.; if((buf_Qlsp_coefficients_bws=(float *)calloc(*lpc_order, sizeof(float)))==NULL) { fprintf(stderr,"\n memory allocation error in initialization_encoder\n"); exit(5); } if((prev_Qlsp_coefficients_bws=(float *)calloc(lpc_order_bws, sizeof(float)))==NULL) { fprintf(stderr,"\n memory allocation error in initialization_encoder\n"); exit(5); } for(i=0;i<(lpc_order_bws);i++) *(prev_Qlsp_coefficients_bws+i) = PAN_PI * (i+1) / (float)(lpc_order_bws
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -