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

📄 phi_nec_lpc.c

📁 MPEG2/MPEG4编解码参考程序(实现了MPEG4的部分功能)
💻 C
📖 第 1 页 / 共 2 页
字号:
             lpc_order);     }}/*======================================================================*//*   Function Definition:PHI_lpc_analysis                               *//*======================================================================*/voidNEC_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        */long  lpc_order                 /* In:  Order of LPC                    */){/* lag window */static float lagWin_20[21] = { 1.0000100, 0.9997225, 0.9988903, 0.9975049, 0.9955685, 0.9930844, 0.9900568, 0.9864905, 0.9823916, 0.9777667, 0.9726235, 0.9669703, 0.9608164, 0.9541719, 0.9470474, 0.9394543, 0.9314049, 0.9229120, 0.9139889, 0.9046499, 0.8949091,};    /*------------------------------------------------------------------*/    /*    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(NEC_LPC_ORDER_FRQ16!=lpc_order) {        printf("\n irregular LPC order in BWS mode\n");        exit(1);    }    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);    /* lag windowing */    for(k=0;k<=lpc_order;k++) *(acf+k) *= *(lagWin_20+k);    /*------------------------------------------------------------------*/    /* 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                                              */    /*------------------------------------------------------------------*/    /* not used !    for(k = 0; k < (int)lpc_order; k++)    {        lpc_coefficients[k] = (float)apars[k] * PHI_GammaArrayBE[k];    }    */    for(k = 0; k < (int)lpc_order; k++)    {        lpc_coefficients[k] = (float)apars[k];    }        /*------------------------------------------------------------------*/    /* Free the arrays that were malloced                               */    /*------------------------------------------------------------------*/    free(LpcAnalysisBlock);    free(reflection_coeffs);    free(acf);    free(apars);}/*======================================================================*//*   Function Definition:PHI_CalcAcf                                    *//*======================================================================*/static void PHI_CalcAcf(double sp_in[],         /* In:  Input segment [0..N-1]                  */double acf[],           /* Out: Autocorrelation coeffs [0..P]           */int N,                  /* In:  Number of samples in the segment        */ int P                   /* In:  LPC Order                               */){    int	    i, l;    double  *pin1, *pin2;    double  temp;        for (i = 0; i <= P; i++)    {		pin1 = sp_in;		pin2 = pin1 + i;		temp = (double)0.0;		for (l = 0; l < N - i; l++)	    	temp += *pin1++ * *pin2++;		*acf++ = temp;    }    return;}/*======================================================================*//*   Function Definition:PHI_LevinsonDurbin                             *//*======================================================================*/static int              /* Retun Value: 1 if unstable filter            */ PHI_LevinsonDurbin( double acf[],           /* In:  Autocorrelation coeffs [0..P]           */         double apar[],          /* Out: Polynomial coeffciients  [0..P-1]       */           double rfc[],           /* Out: Reflection coefficients [0..P-1]        */int P,                  /* In:  LPC Order                               */double * E              /* Out: Residual energy at the last stage       */){    int	    i, j;    double  tmp1;    double  *tmp;        if ((tmp = (double *) malloc((unsigned int)P * sizeof(double))) == NULL)    {	printf("\nERROR in library procedure levinson_durbin: memory allocation failed!");	exit(1);    }        *E = acf[0];    if (*E > (double)0.0)    {		for (i = 0; i < P; i++)		{	    	tmp1 = (double)0.0;	    	for (j = 0; j < i; j++)			tmp1 += tmp[j] * acf[i-j];	    	rfc[i] = (acf[i+1] - tmp1) / *E;	    	if (fabs(rfc[i]) >= 1.0)	    	{			for (j = i; j < P; j++)		    	rfc[j] = (double)0.0;			free(tmp);			return(1);  /* error in calculation */	    	}	    	apar[i] = rfc[i];	    	for (j = 0; j < i; j++)			apar[j] = tmp[j] - rfc[i] * tmp[i-j-1];	    	*E *= (1.0 - rfc[i] * rfc[i]);	    	for (j = 0; j <= i; j++)			tmp[j] = apar[j];			}		free(tmp);		return(0);    }    else    {        for(i= 0; i < P; i++)        {            rfc[i] = 0.0;            apar[i] = 0.0;        }		free(tmp);		return(2);	    /* zero energy frame */    }}/*======================================================================*//*      H I S T O R Y                                                   *//*======================================================================*//* 17-04-96 R. Taori  Initial Version                                   *//* 30-07-96 R. Taori  Modified interface  to meet the MPEG-4 requirement*//* 30-08-96 R. Taori  Prefixed "PHI_" to several subroutines(MPEG req.) *//* 07-11-96 N. Tanaka (Panasonic)                                       *//*                    Added several modules for narrowband coder (PAN_) *//* 14-11-96 A. Gerrits Introduction of dynamic threshold                */

⌨️ 快捷键说明

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