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

📄 celp_decoder.c

📁 MPEG2/MPEG4编解码参考程序(实现了MPEG4的部分功能)
💻 C
📖 第 1 页 / 共 4 页
字号:
    if (ExcitationMode == MultiPulseExc) {      long i, j;      /* CelpBRSenhFrame() */      if ( num_enhstages >= 1 ) {	for ( j = 1; j <= num_enhstages; j++ ) {	  for ( i = 0; i < n_subframes; i++ ) {	    shape_indices[(j*n_subframes+i)*num_shape_cbks+0] = 0;	    BsGetBit(bitStream,		   &shape_indices[(j*n_subframes+i)*num_shape_cbks+1],		   enh_pos_bits);	    BsGetBit(bitStream,		   &shape_indices[(j*n_subframes+i)*num_shape_cbks+2],		   enh_sgn_bits);	    BsGetBit(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) {	Read_BandScalable_LSP(bitStream, indices_bws);	for ( i = 0; i < n_subframes_bws; i++ ) {	  BsGetBit(bitStream,		 &shape_indices_bws[i*num_shape_cbks+0],		 NEC_BIT_ACB_FRQ16);	  BsGetBit(bitStream,		 &shape_indices_bws[i*num_shape_cbks+1], bws_pos_bits);	  BsGetBit(bitStream,		 &shape_indices_bws[i*num_shape_cbks+2], bws_sgn_bits);	  BsGetBit(bitStream,		 &gain_indices_bws[i*num_gain_cbks+0],		 NEC_BIT_GAIN_FRQ16);	}      }    }    /* -----------------------------------------------------------------*/    /* Decode LPC coefficients                                          */    /* -----------------------------------------------------------------*/      if (FineRateControl == ON)    {	VQ_celp_lpc_decode(indices, int_ap, lpc_order, num_lpc_indices, n_subframes,	                       interpolation_flag, Wideband_VQ, PHI_Priv);    }	    else    {  /*  FineRate Control OFF  */	if (SampleRateMode == fs8kHz)	{	    long k;	    if (ExcitationMode == RegularPulseExc)	    {	      fprintf (stderr, "Combination of RPE + 8 kHz sampling rate not supported.\n");	      exit (1);	    }	    if (ExcitationMode == MultiPulseExc)	    {		nb_abs_lpc_decode(indices, int_ap, lpc_order, n_subframes,				  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_decoder(indices_bws, int_ap_bws, lpc_order, lpc_order_bws,				n_subframes_bws, buf_Qlsp_coefficients_bws, 				prev_Qlsp_coefficients_bws );	    }	}				if (SampleRateMode == fs16kHz)	{	    if (ExcitationMode == RegularPulseExc)	    {		VQ_celp_lpc_decode(indices, int_ap, lpc_order, num_lpc_indices, n_subframes,		                   interpolation_flag, Wideband_VQ, PHI_Priv);	    }	    if (ExcitationMode == MultiPulseExc)	    {		wb_celp_lsp_decode(indices, int_ap, lpc_order, n_subframes,		                   prev_Qlsp_coefficients);	    }	    	}     }    if (ExcitationMode==RegularPulseExc)    {	/* -----------------------------------------------------------------*/	/* Subframe processing                                              */	/* -----------------------------------------------------------------*/	for (sbfrm_ctr = 0; sbfrm_ctr < n_subframes; sbfrm_ctr++)	{	    long  m = sbfrm_ctr * lpc_order;	    float *cbk_sig;	    float *syn_speech;	    float dumf;		    	    /* -------------------------------------------------------------*/	    /* Create Arrays for subframe processing                        */	    /* -------------------------------------------------------------*/	    if	    (	    (( cbk_sig = (float *)malloc((unsigned int)sbfrm_size * sizeof(float))) == NULL )||	    (( syn_speech = (float *)malloc((unsigned int)sbfrm_size * sizeof(float))) == NULL )	    )	    {		fprintf(stderr, "MALLOC FAILURE in abs_decoder  \n");		exit(1);	    }    	    /* ------------------------------------------------------------*/	    /* Excitation Generation                                       */	    /* ------------------------------------------------------------*/	    celp_excitation_generation(&(shape_indices[sbfrm_ctr*num_shape_cbks]),	                               &(gain_indices[sbfrm_ctr*num_gain_cbks]), num_shape_cbks,				       num_gain_cbks, dum, &int_ap[m], lpc_order, sbfrm_size,				       n_subframes, dum, org_frame_bit_allocation, cbk_sig, &dum,				       &dumf, PHI_Priv);		    	    /* ------------------------------------------------------------*/	    /* Speech Generation                                           */	    /* ------------------------------------------------------------*/	    celp_lpc_synthesis_filter(cbk_sig, syn_speech, &int_ap[m], lpc_order, sbfrm_size, PHI_Priv);    	    if (postfilter)	    {		    /* --------------------------------------------------------*/		    /* Post Processing                                         */		    /* --------------------------------------------------------*/		    celp_postprocessing(syn_speech, &(OutputSignal[0][sbfrm_ctr*sbfrm_size]), &int_ap[m], lpc_order, sbfrm_size, dum, dumf, PHI_Priv);     	    }	    else	    {		long k;		float *psyn_speech   =  syn_speech;		float *pOutputSignal =  &(OutputSignal[0][sbfrm_ctr*sbfrm_size]);    		for(k=0; k < sbfrm_size; k++)		{		    *pOutputSignal++ = *psyn_speech++;    		}	    }		    	    /* -------------------------------------------------------------*/	    /* Free   Arrays for subframe processing                        */	    /* -------------------------------------------------------------*/	    free ( syn_speech );	    free ( cbk_sig );	}          }     if (ExcitationMode==MultiPulseExc)    {      float *dec_sig;      float *bws_mp_sig;      long  *acb_delay;      float *adaptive_gain;      float *dec_sig_bws;      long  *bws_delay;      float *bws_adpt_gain;      float *syn_sig;	/* HP 971112 */      long  kk;      if (SampleRateMode == fs8kHz) {	if(	   (( dec_sig   = (float *)malloc((unsigned int)frame_size_nb * sizeof(float))) == NULL )||	   (( bws_mp_sig   = (float *)malloc((unsigned int)frame_size_nb * sizeof(float))) == NULL )	   ) {	  fprintf(stderr, "MALLOC FAILURE in abs_decoder  \n");	  exit(1);	}      } else {	if(	   (( dec_sig   = (float *)malloc((unsigned int)frame_size * sizeof(float))) == NULL )||	   (( bws_mp_sig   = (float *)malloc((unsigned int)frame_size * sizeof(float))) == NULL )	   ) {	  fprintf(stderr, "MALLOC FAILURE in abs_decoder  \n");	  exit(1);	}      }      if((( acb_delay   = (long *)malloc(n_subframes * sizeof(long))) == NULL )||		   (( adaptive_gain   = (float *)malloc(n_subframes * sizeof(float))) == NULL ) ) {			fprintf(stderr, "MALLOC FAILURE in abs_decoder  \n");			exit(1);      }      for (sbfrm_ctr = 0; sbfrm_ctr < n_subframes; sbfrm_ctr++) {	nb_abs_excitation_generation(shape_indices, gain_indices, 				     num_shape_cbks, num_gain_cbks, rms_index,				     int_ap+lpc_order*sbfrm_ctr, lpc_order, 				     sbfrm_size, n_subframes, signal_mode, 				     org_frame_bit_allocation,				     dec_sig+sbfrm_size*sbfrm_ctr, 				     bws_mp_sig+sbfrm_size*sbfrm_ctr, 				     acb_delay+sbfrm_ctr,				     adaptive_gain+sbfrm_ctr,				     dec_enhstages,postfilter,				     SampleRateMode);      }      if (BandwidthScalabilityMode == ON) {	if(	   (( dec_sig_bws   = (float *)malloc((unsigned int)frame_size_bws * sizeof(float))) == NULL )	   ) {	  fprintf(stderr, "MALLOC FAILURE in abs_decoder  \n");	  exit(1);	}	if((( bws_delay   = (long *)malloc(n_subframes_bws * sizeof(long))) == NULL )||		   (( bws_adpt_gain   = (float *)malloc(n_subframes_bws * sizeof(float))) == NULL ) ) {			fprintf(stderr, "MALLOC FAILURE in abs_decoder  \n");			exit(1);	}	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++) {	  bws_excitation_generation(shape_indices_bws, gain_indices_bws, 				    num_shape_cbks, num_gain_cbks, rms_index,				    int_ap_bws+lpc_order_bws*sbfrm_ctr,				    lpc_order_bws, 				    sbfrm_size_bws, n_subframes_bws,				    signal_mode, 				    &org_frame_bit_allocation[num_indices-n_subframes_bws*(num_shape_cbks+num_gain_cbks)],				    dec_sig_bws+sbfrm_size_bws*sbfrm_ctr, 				    bws_mp_sig+sbfrm_size*n_subframes/n_subframes_bws*sbfrm_ctr,				    bws_nb_acb_index,				    bws_delay+sbfrm_ctr,bws_adpt_gain+sbfrm_ctr,postfilter);	}      }      if ( (BandwidthScalabilityMode==ON) && (dec_bwsmode) ) {        if(( syn_sig = (float *)malloc((unsigned int)sbfrm_size_bws * sizeof(float))) == NULL ){	  fprintf(stderr, "MALLOC FAILURE in abs_decoder  \n");	  exit(1);	}	for (sbfrm_ctr = 0; sbfrm_ctr < n_subframes_bws; sbfrm_ctr++) {	  celp_lpc_synthesis_filter(dec_sig_bws+sbfrm_size_bws*sbfrm_ctr,				    syn_sig,				    int_ap_bws+lpc_order_bws*sbfrm_ctr,				    lpc_order_bws, sbfrm_size_bws, PHI_Priv);	  if (postfilter) {	    nb_abs_postprocessing(syn_sig,				  &(OutputSignal[0][sbfrm_ctr*sbfrm_size_bws]),				  int_ap_bws+lpc_order_bws*sbfrm_ctr,				  lpc_order_bws, sbfrm_size_bws,				  bws_delay[sbfrm_ctr],				  bws_adpt_gain[sbfrm_ctr]);	  } else {            for(kk=0; kk < sbfrm_size_bws; kk++)	      OutputSignal[0][sbfrm_ctr*sbfrm_size_bws+kk] = syn_sig[kk];	  }	}	free( syn_sig );      } else {        if(( syn_sig = (float *)malloc((unsigned int)sbfrm_size * sizeof(float))) == NULL ){	  fprintf(stderr, "MALLOC FAILURE in abs_decoder  \n");	  exit(1);	}	for (sbfrm_ctr = 0; sbfrm_ctr < n_subframes; sbfrm_ctr++) {	  celp_lpc_synthesis_filter(dec_sig+sbfrm_size*sbfrm_ctr,				    syn_sig,				    int_ap+lpc_order*sbfrm_ctr,				    lpc_order, sbfrm_size, PHI_Priv);	  if (postfilter) {	    nb_abs_postprocessing(syn_sig,				  &(OutputSignal[0][sbfrm_ctr*sbfrm_size]),				  int_ap+lpc_order*sbfrm_ctr,				  lpc_order, sbfrm_size,				  acb_delay[sbfrm_ctr],				  adaptive_gain[sbfrm_ctr]);	  } else {            for(kk=0; kk < sbfrm_size; kk++)	      OutputSignal[0][sbfrm_ctr*sbfrm_size+kk] = syn_sig[kk];	  }	}	free( syn_sig );      }      free ( dec_sig );      free ( bws_mp_sig );      free ( acb_delay );      free ( adaptive_gain );      if (BandwidthScalabilityMode == ON) {	free ( dec_sig_bws );	free ( bws_delay );	free ( bws_adpt_gain );      }    }    /* -----------------------------------------------------------------*/    /* Free   Arrays for Frame processing                               */    /* -----------------------------------------------------------------*/    free ( int_ap );    free ( shape_indices );    free ( gain_indices );    free ( indices );

⌨️ 快捷键说明

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