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

📄 phi_lpc.c

📁 MPEG-4编解码的实现(包括MPEG4视音频编解码)
💻 C
📖 第 1 页 / 共 5 页
字号:
   
    /* -----------------------------------------------------------------*/
    /* Create Array for Quantiser (wideband)                            */
    /* -----------------------------------------------------------------*/
  
    if((PHI_Priv->previous_q_lsf_16_dec=(float *)calloc(order, sizeof(float)))==NULL) {
       printf("\n memory allocation error in initialization_encoder\n");
       exit(1);
    }
    for(i=0;i<order;i++) 
       *(PHI_Priv->previous_q_lsf_16_dec+i) = ((i+1)/(float)((order)+1)) * PAN_PI;

    if((PHI_Priv->current_q_lsf_16_dec=(float *)calloc(order, sizeof(float)))==NULL) {
       printf("\n memory allocation error in initialization_encoder\n");
       exit(1);
    }
    for(i=0;i<order;i++) 
       *(PHI_Priv->current_q_lsf_16_dec+i) = ((i+1)/(float)((order)+1)) * PAN_PI;

    if((PHI_Priv->next_q_lsf_16_dec=(float *)calloc(order, sizeof(float)))==NULL) {
       printf("\n memory allocation error in initialization_encoder\n");
       exit(1);
    }
    for(i=0;i<order;i++) 
       *(PHI_Priv->next_q_lsf_16_dec+i) = ((i+1)/(float)((order)+1)) * PAN_PI;
   
       
    /* -----------------------------------------------------------------*/       
    /* Initialise arrays                                                */
    /* -----------------------------------------------------------------*/
    for(x=0; x < (int)order; x++)
    {
        PHI_Priv->PHI_mem_s[x] = PHI_Priv->PHI_dec_prev_lar[x] = PHI_Priv->PHI_dec_current_lar[x] = (float)0.0;
    }    
}

/*======================================================================*/
/* Function Definition: PHI_FreeLpcAnalysisEncoder                      */
/*======================================================================*/
void PHI_FreeLpcAnalysisEncoder
(
long n_lpc_analysis,
PHI_PRIV_TYPE *PHI_Priv		/* In/Out: PHI private data (instance context) */
)
{

    /* -----------------------------------------------------------------*/
    /*FREE the arrays that were malloc'd                               */
    /* -----------------------------------------------------------------*/
    
  FREE(PHI_Priv->next_uq_lsf_16);
  FREE(PHI_Priv->current_uq_lsf_16);
  FREE(PHI_Priv->previous_uq_lsf_16);

  FREE(PHI_Priv->next_q_lsf_16);
  FREE(PHI_Priv->current_q_lsf_16);
  FREE(PHI_Priv->previous_q_lsf_16);

  FREE(PHI_Priv->previous_q_lsf_int_16);
  FREE(PHI_Priv->previous_q_lsf_int_8);

  FREE(PHI_Priv->next_uq_lsf_8);
  FREE(PHI_Priv->current_uq_lsf_8);
  FREE(PHI_Priv->previous_uq_lsf_8);

  FREE(PHI_Priv->next_q_lsf_8);
  FREE(PHI_Priv->current_q_lsf_8);
  FREE(PHI_Priv->previous_q_lsf_8);

  FREE(PHI_Priv->PHI_mem_i);
  FREE(PHI_Priv->PHI_prev_lar);
  FREE(PHI_Priv->PHI_prev_indices);
  FREE(PHI_Priv->PHI_current_lar);

}

/*======================================================================*/
/* Function Definition: PAN_FreeLpcAnalysisEncoder                      */
/*     Nov. 07 96  - Added for narrowband coder                         */
/*======================================================================*/
void PAN_FreeLpcAnalysisEncoder
(
long n_lpc_analysis,
PHI_PRIV_TYPE *PHI_Priv		/* In/Out: PHI private data (instance context) */
)
{
    /* -----------------------------------------------------------------*/
    /*FREE the arrays that were malloc'd                               */
    /* -----------------------------------------------------------------*/
  FREE(PHI_Priv->PHI_mem_i);
}

/*======================================================================*/
/* Function Definition: PHI_FreeLpcAnalysisDecoder                      */
/*======================================================================*/
void PHI_FreeLpcAnalysisDecoder
(
PHI_PRIV_TYPE *PHI_Priv		/* In/Out: PHI private data (instance context) */
)
{
    /* -----------------------------------------------------------------*/
    /*FREE the arrays that were malloc'd                               */
    /* -----------------------------------------------------------------*/
     
  FREE(PHI_Priv->next_q_lsf_16_dec);
  FREE(PHI_Priv->current_q_lsf_16_dec);
  FREE(PHI_Priv->previous_q_lsf_16_dec);

  FREE(PHI_Priv->next_q_lsf_8_dec);
  FREE(PHI_Priv->current_q_lsf_8_dec);
  FREE(PHI_Priv->previous_q_lsf_8_dec);

  FREE(PHI_Priv->PHI_mem_s);
  FREE(PHI_Priv->PHI_dec_prev_lar);
  FREE(PHI_Priv->PHI_dec_current_lar);

}

 
/*======================================================================*/
/*   Function Definition:celp_lpc_analysis                              */
/*======================================================================*/
void celp_lpc_analysis
(
float PP_InputSignal[],         /* In:  Input Signal                    */
float lpc_coefficients[],       /* Out: LPC Coefficients[0..lpc_order-1]*/
float *first_order_lpc_par,     /* Out: a_parameter for 1st-order fit   */
long  frame_size,               /* In:  Number of samples in frame      */
long  window_offsets[],         /* In:  offset for window w.r.t curr. fr*/
long  window_sizes[],           /* In:  LPC Analysis-Window Size        */
float *windows[],               /* In:  Array of LPC Analysis windows   */
float gamma_be[],               /* In:  Bandwidth expansion coefficients*/
long  lpc_order,                /* In:  Order of LPC                    */
long  n_lpc_analysis            /* In:  Number of LP analysis/frame     */
)
{
    int i;
    
    
    for(i = 0; i < (int)n_lpc_analysis; i++)
    {
         PHI_lpc_analysis(PP_InputSignal,lpc_coefficients+lpc_order*(long)i, 
             first_order_lpc_par,
             frame_size, windows[i], window_offsets[i], window_sizes[i],
             gamma_be,
             lpc_order); 
    }
}

/*======================================================================*/
/*   Function Definition:PHI_lpc_analysis                               */
/*======================================================================*/
void PHI_lpc_analysis
(
float PP_InputSignal[],         /* In:  Input Signal                    */
float lpc_coefficients[],       /* Out: LPC Coefficients[0..lpc_order-1]*/
float *first_order_lpc_par,     /* Out: a_parameter for 1st-order fit   */
long  frame_size,               /* In:  Number of samples in frame      */
float HamWin[],                 /* In:  Hamming Window                  */
long  window_offset,            /* In:  offset for window w.r.t curr. fr*/
long  window_size,              /* In:  LPC Analysis-Window Size        */
float gamma_be[],               /* In:  Bandwidth expansion coeffs.     */
long  lpc_order                 /* In:  Order of LPC                    */
)
{

    /*------------------------------------------------------------------*/
    /*    Volatile Variables                                            */
    /* -----------------------------------------------------------------*/
    double *acf;                 /* For Autocorrelation Function        */
    double *reflection_coeffs;   /* For Reflection Coefficients         */
    double *LpcAnalysisBlock;    /* For Windowed Input Signal           */
    double *apars;               /* a-parameters of double precision    */
    int k;
 
    /*------------------------------------------------------------------*/
    /* Allocate space for lpc, acf, a-parameters and rcf                */
    /*------------------------------------------------------------------*/

    if 
    (
    (( reflection_coeffs = (double *)malloc((unsigned int)lpc_order * sizeof(double))) == NULL ) ||
    (( acf = (double *)malloc((unsigned int)(lpc_order + 1) * sizeof(double))) == NULL ) ||
    (( apars = (double *)malloc((unsigned int)(lpc_order) * sizeof(double))) == NULL )  ||
    (( LpcAnalysisBlock = (double *)malloc((unsigned int)window_size * sizeof(double))) == NULL )
    )
    {
		printf("MALLOC FAILURE in Routine abs_lpc_analysis \n");
		exit(1);
    }
    
    /*------------------------------------------------------------------*/
    /* Windowing of the input signal                                    */
    /*------------------------------------------------------------------*/
    for(k = 0; k < (int)window_size; k++)
    {
        LpcAnalysisBlock[k] = (double)PP_InputSignal[k + (int)window_offset] * (double)HamWin[k];
    }    

    /*------------------------------------------------------------------*/
    /* Compute Autocorrelation                                          */
    /*------------------------------------------------------------------*/
    PHI_CalcAcf(LpcAnalysisBlock, acf, (int)window_size, (int)lpc_order);

    /*------------------------------------------------------------------*/
    /* Levinson Recursion                                               */
    /*------------------------------------------------------------------*/
    {
         double Energy = 0.0;
     
         PHI_LevinsonDurbin(acf, apars, reflection_coeffs,(int)lpc_order,&Energy);  
    }  
    
    /*------------------------------------------------------------------*/
    /* First-Order LPC Fit                                              */
    /*------------------------------------------------------------------*/
    *first_order_lpc_par = (float)reflection_coeffs[0];

    /*------------------------------------------------------------------*/
    /* Bandwidth Expansion                                              */
    /*------------------------------------------------------------------*/    
    for(k = 0; k < (int)lpc_order; k++)
    {
        lpc_coefficients[k] = (float)apars[k] * gamma_be[k];
    }    

    /*------------------------------------------------------------------*/
    /*FREE the arrays that were malloced                               */
    /*------------------------------------------------------------------*/
  FREE(LpcAnalysisBlock);
  FREE(reflection_coeffs);
  FREE(acf);
  FREE(apars);
}

/*======================================================================*/
/*   Function Definition:VQ_celp_lpc_decode                             */
/*======================================================================*/
void VQ_celp_lpc_decode
(
unsigned long  lpc_indices[],  /* In: Received Packed LPC Codes         */
float int_Qlpc_coefficients[], /* Out: Qaunt/interpolated a-pars        */
long  lpc_order,               /* In:  Order of LPC                     */
long  num_lpc_indices,         /* In:  Number of packes LPC codes       */
long  n_subframes,             /* In:  Number of subframes              */
unsigned long interpolation_flag, /* In:  Was interpolation done?          */
long  Wideband_VQ,             /* In:  Wideband VQ switch               */
PHI_PRIV_TYPE *PHI_Priv		/* In/Out: PHI private data (instance context) */
)
{
    if (lpc_order == ORDER_LPC_8)
    {   /*   8 khz  */
    	float *int_lsf;
    	int   s,k;
    	float *tmp_lpc_coefficients;

    	/*------------------------------------------------------------------*/
    	/* Allocate space for current_rfc and current lar                   */
    	/*------------------------------------------------------------------*/
    	if 
    	(
    	(( int_lsf = (float *)malloc((unsigned int)lpc_order * sizeof(float))) == NULL )
    	)
    	{
			printf("MALLOC FAILURE in Routine abs_lpc_quantizer \n");
			exit(1);
    	}

    	if((tmp_lpc_coefficients=(float *)calloc(lpc_order+1, sizeof(float)))==NULL) {
			printf("\n Memory allocation error in abs_lpc_quantizer\n");
			exit(4);
		}

    	if (interpolation_flag)
    	{
    		/*----------------------------------------------------------*/
    		/* Compute LSP coeffs of the next frame                     */
    		/*----------------------------------------------------------*/
  		mod_nb_abs_lsp_decode(lpc_indices, PHI_Priv->previous_q_lsf_8_dec,
    	            	  PHI_Priv->next_q_lsf_8_dec, lpc_order, 5);

    		/*------------------------------------------------------------------*/
    		/* Interpolate LSP coeffs to obtain coeficients of cuurent frame    */
    		/*------------------------------------------------------------------*/
        	for(k = 0; k < (int)lpc_order; k++)
        	{
        		PHI_Priv->current_q_lsf_8_dec[k] = 
        	    	(float)0.5 * (PHI_Priv->previous_q_lsf_8_dec[k] + PHI_Priv->next_q_lsf_8_dec[k]);
        	} 
    	}
    	else
    	{
         	if (PHI_Priv->PHI_dec_prev_interpolation_flag == 0)
        	{
    			/*--------------------------------------------------------------*/
    			/* Compute LSP coeffs of the current frame                      */
    			/*--------------------------------------------------------------*/
     			mod_nb_abs_lsp_decode(lpc_indices, PHI_Priv->previous_q_lsf_8_dec,
    	            		  PHI_Priv->current_q_lsf_8_dec,
		    				  lpc_order, 5);
        	}
                else
        	{
            	/* LSPs received in the previous frame: do nothing */
            	;
        	}
    	}

    	/*------------------------------------------------------------------*/

⌨️ 快捷键说明

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