📄 celp_encoder.c
字号:
/* CELP Lpc Mux */ /*==================================================================*/ /* -------------------------------------------------------------*/ /* Vector Quantization Mode */ /* -------------------------------------------------------------*/ if (FineRateControl == ON) { /* ---------------------------------------------------------*/ /* Step I: Read interpolation_flag and LPC_present flag */ /* ---------------------------------------------------------*/ BsPutBit(bitStream, interpolation_flag, 1); BsPutBit(bitStream, LPC_Present, 1); /* ---------------------------------------------------------*/ /* Step II: If LPC is present */ /* ---------------------------------------------------------*/ if (LPC_Present == YES) { /* LSP_VQ() */ if (SampleRateMode == fs8kHz) { Write_NarrowBand_LSP(bitStream, codes); } if (SampleRateMode == fs16kHz) { Write_Wideband_LSP(bitStream, codes); } /* end of LSP_VQ() */ } } else { /* LSP_VQ() */ if (SampleRateMode == fs8kHz) { Write_NarrowBand_LSP(bitStream, codes); } if (SampleRateMode == fs16kHz) { Write_Wideband_LSP(bitStream, codes); } /* end of LSP_VQ() */ } /*==================================================================*/ /* CELP Excitation decoding */ /*==================================================================*/ if ( ExcitationMode == RegularPulseExc ) { /* RPE_Frame() */ long subframe; /*--------------------------------------------------------------*/ /* Regular Pulse Excitation */ /*--------------------------------------------------------------*/ for(subframe = 0; subframe < n_subframes; subframe++) { /* ---------------------------------------------------------*/ /*Read the Adaptive Codebook Lag */ /* ---------------------------------------------------------*/ BsPutBit(bitStream, shape_indices[subframe * num_shape_cbks], 8); /* ---------------------------------------------------------*/ /*Read the Fixed Codebook Index (function of bit-rate) */ /* ---------------------------------------------------------*/ switch (RPE_configuration) { case 0 : BsPutBit(bitStream, shape_indices[subframe * num_shape_cbks + 1], 11); break; case 1 : BsPutBit(bitStream, shape_indices[subframe * num_shape_cbks + 1], 11); break; case 2 : BsPutBit(bitStream, shape_indices[subframe * num_shape_cbks + 1], 12); break; case 3 : BsPutBit(bitStream, shape_indices[subframe * num_shape_cbks + 1], 12); break; } /* ---------------------------------------------------------*/ /*Read the Adaptive Codebook Gain */ /* ---------------------------------------------------------*/ BsPutBit(bitStream, gain_indices[subframe * num_gain_cbks], 6); /* ---------------------------------------------------------*/ /*Read the Fixed Codebook Gain (function of subframe) */ /*Later subframes are encoded differentially w.r.t previous */ /* ---------------------------------------------------------*/ if (subframe == 0) { BsPutBit(bitStream, gain_indices[subframe * num_gain_cbks + 1], 5); } else { BsPutBit(bitStream, gain_indices[subframe * num_gain_cbks + 1], 3); } } } if (ExcitationMode == MultiPulseExc) { /* MPE_frame() */ /*--------------------------------------------------------------*/ /* Multi-Pulse Excitation */ /*--------------------------------------------------------------*/ long i; long mp_pos_bits, mp_sgn_bits; BsPutBit(bitStream, signal_mode, NEC_BIT_MODE); BsPutBit(bitStream, rms_index, NEC_BIT_RMS); if (SampleRateMode == fs8kHz) { mp_pos_bits = org_frame_bit_allocation[PAN_NUM_LPC_INDICES+NEC_NUM_OTHER_INDICES+1]; mp_sgn_bits = org_frame_bit_allocation[PAN_NUM_LPC_INDICES+NEC_NUM_OTHER_INDICES+2]; for ( i = 0; i < n_subframes; i++ ) { BsPutBit(bitStream,shape_indices[i*num_shape_cbks+0], NEC_BIT_ACB); BsPutBit(bitStream,shape_indices[i*num_shape_cbks+1], mp_pos_bits); BsPutBit(bitStream,shape_indices[i*num_shape_cbks+2], mp_sgn_bits); BsPutBit(bitStream,gain_indices[i*num_gain_cbks+0], NEC_BIT_GAIN); } } else { mp_pos_bits = org_frame_bit_allocation[PAN_NUM_LPC_INDICES_W+NEC_NUM_OTHER_INDICES+1]; mp_sgn_bits = org_frame_bit_allocation[PAN_NUM_LPC_INDICES_W+NEC_NUM_OTHER_INDICES+2]; for ( i = 0; i < n_subframes; i++ ) { BsPutBit(bitStream, shape_indices[i*num_shape_cbks+0], NEC_ACB_BIT_WB); BsPutBit(bitStream, shape_indices[i*num_shape_cbks+1], mp_pos_bits); BsPutBit(bitStream, shape_indices[i*num_shape_cbks+2], mp_sgn_bits); BsPutBit(bitStream, gain_indices[i*num_gain_cbks+0], NEC_BIT_GAIN_WB); } } } /* end of CelpBaseFrame() */ if (ExcitationMode == MultiPulseExc) { long i, j; long enh_pos_bits, enh_sgn_bits; long bws_pos_bits, bws_sgn_bits; /* CelpBRSenhFrame() */ if ( num_enhstages >= 1 ) { if (SampleRateMode == fs8kHz) { enh_pos_bits = org_frame_bit_allocation[PAN_NUM_LPC_INDICES+NEC_NUM_OTHER_INDICES+n_subframes*(num_shape_cbks+num_gain_cbks)+1]; enh_sgn_bits = org_frame_bit_allocation[PAN_NUM_LPC_INDICES+NEC_NUM_OTHER_INDICES+n_subframes*(num_shape_cbks+num_gain_cbks)+2]; } else { enh_pos_bits = org_frame_bit_allocation[PAN_NUM_LPC_INDICES_W+NEC_NUM_OTHER_INDICES+n_subframes*(num_shape_cbks+num_gain_cbks)+1]; enh_sgn_bits = org_frame_bit_allocation[PAN_NUM_LPC_INDICES_W+NEC_NUM_OTHER_INDICES+n_subframes*(num_shape_cbks+num_gain_cbks)+2]; } for ( j = 1; j <= num_enhstages; j++ ) { for ( i = 0; i < n_subframes; i++ ) { BsPutBit(bitStream, shape_indices[(j*n_subframes+i)*num_shape_cbks+1], enh_pos_bits); BsPutBit(bitStream, shape_indices[(j*n_subframes+i)*num_shape_cbks+2], enh_sgn_bits); BsPutBit(bitStream, gain_indices[(j*n_subframes+i)*num_gain_cbks+0], NEC_BIT_ENH_GAIN); } } } /* CelpBWSenhFrame() */ if (SampleRateMode == fs8kHz && FineRateControl == OFF && QuantizationMode == VectorQuantizer && BandwidthScalabilityMode == ON) { Write_BandScalable_LSP(bitStream, codes_bws); bws_pos_bits = org_frame_bit_allocation[PAN_NUM_LPC_INDICES+NEC_NUM_OTHER_INDICES+(num_enhstages+1)*n_subframes*(num_shape_cbks+num_gain_cbks)+NEC_NUM_LPC_INDICES_FRQ16+1]; bws_sgn_bits = org_frame_bit_allocation[PAN_NUM_LPC_INDICES+NEC_NUM_OTHER_INDICES+(num_enhstages+1)*n_subframes*(num_shape_cbks+num_gain_cbks)+NEC_NUM_LPC_INDICES_FRQ16+2]; for ( i = 0; i < n_subframes_bws; i++ ) { BsPutBit(bitStream, shape_indices_bws[i*num_shape_cbks+0], NEC_BIT_ACB_FRQ16); BsPutBit(bitStream, shape_indices_bws[i*num_shape_cbks+1], bws_pos_bits); BsPutBit(bitStream, shape_indices_bws[i*num_shape_cbks+2], bws_sgn_bits); BsPutBit(bitStream, gain_indices_bws[i*num_gain_cbks+0], NEC_BIT_GAIN_FRQ16); } } } /* -----------------------------------------------------------------*/ /* Next becomes currrent af */ /* -----------------------------------------------------------------*/ PHI_af = af_next; /* -----------------------------------------------------------------*/ /* Free Arrays that were malloced for Frame processing */ /* -----------------------------------------------------------------*/ free ( int_ap ); free ( ap ); free ( shape_indices ); free ( gain_indices ); free ( codes ); free ( ds_ap ); free ( ds_window_offsets ); free ( ds_window_sizes ); if (SampleRateMode == fs8kHz) { if ( BandwidthScalabilityMode == ON) { free ( int_ap_bws ); free ( ap_bws ); free ( shape_indices_bws ); free ( gain_indices_bws ); free ( codes_bws ); free ( bws_nb_acb_index ); } } /* -----------------------------------------------------------------*/ /* Frame Counter */ /* -----------------------------------------------------------------*/ if (!interpolation_flag) { lpc_sent_frames++; } frame_ctr++; if ((frame_ctr % 10) == 0) { if (CELPencDebugLevel) { /* HP 971120 */ fprintf(stderr, "Frame Counter: %ld \r", frame_ctr); } }}/*======================================================================*//* Function Definition:celp_initialisation_encoder *//*======================================================================*/void celp_initialisation_encoder(BsBitStream *hdrStream, /* Out: Bitstream */long bit_rate, /* In: bit rate */long sampling_frequency, /* In: sampling frequency */long ExcitationMode, /* In: Excitation Mode */long SampleRateMode, /* In: SampleRate Mode */long QuantizationMode, /* In: Type of Quantization */long FineRateControl, /* In: Fine Rate Control switch */long LosslessCodingMode, /* In: Lossless Coding Mode */long *RPE_configuration, /* Out: RPE_configuration */long Wideband_VQ, /* Out: Wideband VQ mode */long *MPE_Configuration, /* Out: Multi-Pulse Exc. configuration */long NumEnhLayers, /* In: Number of Enhancement Layers for MPE */long BandwidthScalabilityMode, /* In: bandwidth switch */long *BWS_Configuration, /* Out: BWS_configuration */long BWS_nb_bitrate, /* In: narrowband bitrate for BWS */long InputConfiguration, /* In: desired RPE/MPE Configuration for FRC */long *frame_size, /* Out: frame size */long *n_subframes, /* Out: number of subframes */long *sbfrm_size, /* Out: subframe size */ long *lpc_order, /* Out: LP analysis order */long *num_lpc_indices, /* Out: number of LPC indices */long *num_shape_cbks, /* Out: number of Shape Codebooks */long *num_gain_cbks, /* Out: number of Gain Codebooks */ long *n_lpc_analysis, /* Out: number of LP analysis per frame*/long **window_offsets, /* Out: window offset for each LP ana */long **window_sizes, /* Out: window size for each LP ana */long *n_lag_candidates, /* Out: number of pitch candidates */float *min_pitch_frequency, /* Out: minimum pitch frequency */float *max_pitch_frequency, /* Out: maximum pitch frequency */long **org_frame_bit_allocation, /* Out: bit num. for each index */void **InstanceContext, /* Out: handle to initialised instance context */int sysFlag /* In: system interface(flexmux) flag */){ INST_CONTEXT_LPC_ENC_TYPE *InstCtxt; /* -----------------------------------------------------------------*/ /* Create & initialise private storage for instance context */ /* -----------------------------------------------------------------*/ if (( InstCtxt = malloc(sizeof(INST_CONTEXT_LPC_ENC_TYPE))) == NULL ) { fprintf(stderr, "MALLOC FAILURE in celp_initialisation_encoder \n"); exit(1); } if (( InstCtxt->PHI_Priv = malloc(sizeof(PHI_PRIV_TYPE))) == NULL ) { fprintf(stderr, "MALLOC FAILURE in celp_initialisation_encoder \n"); exit(1); } PHI_Init_Private_Data(InstCtxt->PHI_Priv); *InstanceContext = InstCtxt; /* -----------------------------------------------------------------*/ /* */ /* -----------------------------------------------------------------*/ if (ExcitationMode == RegularPulseExc) { int k, x; long BIT_RATE_1; long BIT_RATE_2; long BIT_RATE_3; long BIT_RATE_4; long BIT_RATE_5; long BIT_RATE_6; long BIT_RATE_7; long BIT_RATE_8; if (SampleRateMode == fs16kHz) { if (FineRateControl == OFF) { /* VQ, FRC off */ BIT_RATE_1 = 14400; BIT_RATE_2 = 16000; BIT_RATE_3 = 18667; BIT_RATE_4 = 22533; BIT_RATE_5 = 0; BIT_RATE_6 = 0; BIT_RATE_7 = 0; BIT_RATE_8 = 0; } else { /* VQ, FRC on */ BIT_RATE_1 = 13000; BIT_RATE_2 = 14533; BIT_RATE_3 = 13900; BIT_RATE_4 = 16200; BIT_RATE_5 = 17267; BIT_RATE_6 = 18800; BIT_RATE_7 = 21133; BIT_RATE_8 = 22667; } } /* -----------------------------------------------------------------*/ /*Check if the bitrate is set correctly */ /* -----------------------------------------------------------------*/ if (FineRateControl == OFF)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -