⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 celp_decoder.c

📁 MPEG-4编解码的实现(包括MPEG4视音频编解码)
💻 C
📖 第 1 页 / 共 4 页
字号:

    /* ----------------------------------------------------------------*/
    /* Report on the current frame count                               */
    /* ----------------------------------------------------------------*/
    frame_ctr++;
    if (frame_ctr % 10 == 0)
    {
      if (CELPdecDebugLevel) {	/* HP 971120 */
        fprintf(stderr, "Frame Counter: %ld \r", frame_ctr);
      }
    }

}

/*======================================================================*/
/*   Function Definition: PHI_Postfilter                                */
/*======================================================================*/
static void PHI_Postfilter
(
    const long flag                      /* In: Postfilter On/Off flag  */
)
{
    postfilter = flag;
}

/*======================================================================*/
/*   Function Definition:celp_initialisation_decoder                    */
/*======================================================================*/
void celp_initialisation_decoder
(
BsBitStream *hdrStream,           /* In: Bitstream                     */
long     bit_rate,		                 /* in: bit rate */
long     complexity_level,               /* In: complexity level decoder*/
long     reduced_order,                  /* In: reduced order decoder   */
long     DecEnhStage,
long     DecBwsMode,
long     PostFilterSW,
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 Codeb. */    
long     *num_gain_cbks,                 /* Out: number of Gain Codeb.  */    
long     **org_frame_bit_allocation,     /* Out: bit num. for each index*/
long     * ExcitationMode,               /* Out: Excitation Mode	    */
long     * SampleRateMode,               /* Out: SampleRate Mode	    */
long     * QuantizationMode,             /* Out: Type of Quantization	*/
long     * FineRateControl,              /* Out: Fine Rate Control switch*/
long     * LosslessCodingMode,           /* Out: Lossless Coding Mode  	*/
long     * RPE_configuration,             /* Out: Wideband configuration */
long     * Wideband_VQ, 	             /* Out: Wideband VQ mode		*/
long     * MPE_Configuration,             /* Out: Narrowband configuration*/
long     * NumEnhLayers,	             /* Out: Number of Enhancement Layers*/
long     * BandwidthScalabilityMode,     /* Out: bandwidth switch	    */
long     * BWS_configuration,            /* Out: BWS_configuration		*/
void	 **InstanceContext,		 /* Out: handle to initialised instance context */
int      mp4ffFlag
)
{

   INST_CONTEXT_LPC_DEC_TYPE	*InstCtxt;
   frame_ctr = 0;   /* Frame Counter                   */

   postfilter = 0;           /* Postfilter switch               */
   prev_Qlsp_coefficients = NULL; /* previous quantized LSP coeff.   */

   buf_Qlsp_coefficients_bws = NULL; /* current quantized LSP coeff. */
   prev_Qlsp_coefficients_bws = NULL;/* previous quantized LSP coeff. */

    /* -----------------------------------------------------------------*/
    /* Create & initialise private storage for instance context         */
    /* -----------------------------------------------------------------*/
    if (( InstCtxt = (INST_CONTEXT_LPC_DEC_TYPE*)malloc(sizeof(INST_CONTEXT_LPC_DEC_TYPE))) == NULL )
    {
      fprintf(stderr, "MALLOC FAILURE in celp_initialisation_decoder  \n");
      exit(1);
    }

    if (( InstCtxt->PHI_Priv = (PHI_PRIV_TYPE*)malloc(sizeof(PHI_PRIV_TYPE))) == NULL )
    {
      fprintf(stderr, "MALLOC FAILURE in celp_initialisation_decoder  \n");
      exit(1);
    }
    PHI_Init_Private_Data(InstCtxt->PHI_Priv);

    *InstanceContext = InstCtxt;

    /* -----------------------------------------------------------------*/
    /*                                                                  */
    /* -----------------------------------------------------------------*/
  
    postfilter = PostFilterSW;
    
    /* -----------------------------------------------------------------*/
    /* Read bitstream header                                            */
    /* -----------------------------------------------------------------*/ 
    /* read from object descriptor */

    if (mp4ffFlag==0) 
      read_celp_bitstream_header(hdrStream, ExcitationMode, SampleRateMode, 
                               QuantizationMode, FineRateControl, LosslessCodingMode,
                               RPE_configuration, Wideband_VQ, MPE_Configuration,
                               NumEnhLayers, BandwidthScalabilityMode, BWS_configuration);


    if (*ExcitationMode == RegularPulseExc)
    {
	if (*SampleRateMode == fs8kHz)
	{
	    fprintf (stderr, "Combination of RPE + 8 kHz sampling rate not supported.\n");
	    exit (1);
	}
    
	/* -----------------------------------------------------------------*/
	/*Check if a bit rate is a set of allowed bit rates                 */
	/* -----------------------------------------------------------------*/ 
	if (*RPE_configuration == 0)
	{
		*frame_size = FIFTEEN_MS;
		*n_subframes = 6;        
	}
	else
	if (*RPE_configuration == 1)
	{
		*frame_size  = TEN_MS;
		*n_subframes = 4;        
	}
	else
	if (*RPE_configuration == 2)
	{
		*frame_size  = FIFTEEN_MS;
		*n_subframes = 8;
	}
	else
	if (*RPE_configuration == 3)
	{
		*frame_size  = FIFTEEN_MS;
		*n_subframes = 10;
	}
	else
	{
		fprintf(stderr, "ERROR: Illegal RPE Configuration\n");
		exit(1); 
	}

	*sbfrm_size          = (*frame_size)/(*n_subframes);

	*num_shape_cbks      = 2;     
	*num_gain_cbks       = 2;     

	*lpc_order       = ORDER_LPC_16;
	*num_lpc_indices = N_INDICES_VQ16;
		
	PHI_init_excitation_generation( Lmax, *sbfrm_size, *RPE_configuration, InstCtxt->PHI_Priv );
	PHI_InitLpcAnalysisDecoder(ORDER_LPC_16, ORDER_LPC_8, InstCtxt->PHI_Priv);
	PHI_InitPostProcessor(*lpc_order, InstCtxt->PHI_Priv );
		
	*org_frame_bit_allocation = PHI_init_bit_allocation(*SampleRateMode, *RPE_configuration,
							    *QuantizationMode, *LosslessCodingMode,
							    *FineRateControl, *num_lpc_indices,
							    *n_subframes, *num_shape_cbks, *num_gain_cbks); 
   }	
 
   if (*ExcitationMode == MultiPulseExc) {
     if (*SampleRateMode == fs8kHz) {
       int i, j;
       long	ctr;
		
       num_enhstages = *NumEnhLayers;
       dec_enhstages = DecEnhStage;
       dec_bwsmode = DecBwsMode;

       if ( *MPE_Configuration >= 0 && *MPE_Configuration < 3 ) {
	 frame_size_nb = NEC_FRAME40MS;
	 *n_subframes = NEC_NSF4;
       }
       if ( *MPE_Configuration >= 3 && *MPE_Configuration < 6 ) {
	 frame_size_nb = NEC_FRAME30MS;
	 *n_subframes = NEC_NSF3;
       }
       if ( *MPE_Configuration >= 6 && *MPE_Configuration < 13 ) {
	 frame_size_nb = NEC_FRAME20MS;
	 *n_subframes = NEC_NSF2;
       }
       if ( *MPE_Configuration >= 13 && *MPE_Configuration < 22 ) {
	 frame_size_nb = NEC_FRAME20MS;
	 *n_subframes = NEC_NSF4;
       }
       if ( *MPE_Configuration >= 22 && *MPE_Configuration < 27 ) {
	 frame_size_nb = NEC_FRAME10MS;
	 *n_subframes = NEC_NSF2;
       }
       if ( *MPE_Configuration == 27 ) {
	 frame_size_nb = NEC_FRAME30MS;
	 *n_subframes = NEC_NSF4;
       }
       if ( *MPE_Configuration > 27 ) {
	 fprintf(stderr,"Error: Illegal BitRate configuration.\n");
	 exit(1); 
       }

       *sbfrm_size = frame_size_nb/(*n_subframes);
       *lpc_order = NEC_LPC_ORDER;
       *num_shape_cbks = NEC_NUM_SHAPE_CBKS;
       *num_gain_cbks = NEC_NUM_GAIN_CBKS;
       if (*QuantizationMode == ScalarQuantizer) {
	 *num_lpc_indices = 4;
       } else {
	 *num_lpc_indices = PAN_NUM_LPC_INDICES;
       }

       num_indices = NEC_NUM_OTHER_INDICES + PAN_NUM_LPC_INDICES
	 + (num_enhstages + 1) * (*n_subframes) *
	   (NEC_NUM_SHAPE_CBKS+NEC_NUM_GAIN_CBKS);

       switch ( *MPE_Configuration ) {
       case 0:
	 mp_pos_bits = 14; mp_sgn_bits =  3; break;
       case 1:
	 mp_pos_bits = 17; mp_sgn_bits =  4; break;
       case 2:
	 mp_pos_bits = 20; mp_sgn_bits =  5; break;
       case 3:
	 mp_pos_bits = 20; mp_sgn_bits =  5; break;
       case 4:
	 mp_pos_bits = 22; mp_sgn_bits =  6; break;
       case 5:
	 mp_pos_bits = 24; mp_sgn_bits =  7; break;
       case 6:
	 mp_pos_bits = 22; mp_sgn_bits =  6; break;
       case 7:
	 mp_pos_bits = 24; mp_sgn_bits =  7; break;
       case 8:
	 mp_pos_bits = 26; mp_sgn_bits =  8; break;
       case 9:
	 mp_pos_bits = 28; mp_sgn_bits =  9; break;
       case 10:
	 mp_pos_bits = 30; mp_sgn_bits = 10; break;
       case 11:
	 mp_pos_bits = 31; mp_sgn_bits = 11; break;
       case 12:
	 mp_pos_bits = 32; mp_sgn_bits = 12; break;
       case 13:
	 mp_pos_bits = 13; mp_sgn_bits =  4; break;
       case 14:
	 mp_pos_bits = 15; mp_sgn_bits =  5; break;
       case 15:
	 mp_pos_bits = 16; mp_sgn_bits =  6; break;
       case 16:
	 mp_pos_bits = 17; mp_sgn_bits =  7; break;
       case 17:
	 mp_pos_bits = 18; mp_sgn_bits =  8; break;
       case 18:
	 mp_pos_bits = 19; mp_sgn_bits =  9; break;
       case 19:
	 mp_pos_bits = 20; mp_sgn_bits =  10; break;
       case 20:
	 mp_pos_bits = 20; mp_sgn_bits =  11; break;
       case 21:
	 mp_pos_bits = 20; mp_sgn_bits =  12; break;
       case 22:
	 mp_pos_bits = 18; mp_sgn_bits =  8; break;
       case 23:
	 mp_pos_bits = 19; mp_sgn_bits =  9; break;
       case 24:
	 mp_pos_bits = 20; mp_sgn_bits =  10; break;
       case 25:
	 mp_pos_bits = 20; mp_sgn_bits =  11; break;
       case 26:
	 mp_pos_bits = 20; mp_sgn_bits =  12; break;
       case 27:
	 mp_pos_bits = 19; mp_sgn_bits =  6; break;
       }

       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;
       }

       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;

	 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);
	 switch ( *BWS_configuration ) {
	 case 0:
	   bws_pos_bits = 22; bws_sgn_bits = 6; break;
	 case 1:
	   bws_pos_bits = 26; bws_sgn_bits = 8; break;
	 case 2:
	   bws_pos_bits = 30; bws_sgn_bits =10; break;
	 case 3:
	   bws_pos_bits = 32; bws_sgn_bits =12; break;
	 }
       }

       if ( (*BandwidthScalabilityMode==ON) && (dec_bwsmode) ) {
	 *frame_size = frame_size_bws;
       } else {
	 *frame_size = frame_size_nb;
       }

       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;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -