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

📄 phi_lpc.c

📁 MPEG2/MPEG4编解码参考程序(实现了MPEG4的部分功能)
💻 C
📖 第 1 页 / 共 5 页
字号:
    	/* -----------------------------------------------------------------*/    	/* Save memory                                                      */    	/* -----------------------------------------------------------------*/    	for(k=0; k < (int)lpc_order; k++)    	{         	PHI_Priv->previous_q_lsf_8_dec[k] = PHI_Priv->current_q_lsf_8_dec[k];        	PHI_Priv->current_q_lsf_8_dec[k] = PHI_Priv->next_q_lsf_8_dec[k];    	}    	PHI_Priv->PHI_dec_prev_interpolation_flag = interpolation_flag;    	/* -----------------------------------------------------------------*/    	/* Free the malloc'd arrays                                         */    	/* -----------------------------------------------------------------*/    	free(int_lsf);    	free(tmp_lpc_coefficients);        }    else    {   /*  16 khz  */        	float *int_lsf;    	int   s,k;    	float *tmp_lpc_coefficients;	if (Wideband_VQ == Scalable_VQ)	{   	    /*   16 khz Scalable VQ  */	    	    /*------------------------------------------------------------------*/	    /* 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/2, 5);    		    mod_nec_bws_lsp_decoder( lpc_indices + 5, PHI_Priv->next_q_lsf_8_dec,				    PHI_Priv->next_q_lsf_16_dec,				    lpc_order, lpc_order/2, 6, PHI_Priv->blsp_dec, PHI_Priv);    		    /*------------------------------------------------------------------*/		    /* Interpolate LSP coeffs to obtain coeficients of cuurent frame    */		    /*------------------------------------------------------------------*/		    for(k = 0; k < (int)lpc_order; k++)		    {			    PHI_Priv->current_q_lsf_16_dec[k] = 			    (float)0.5 * (PHI_Priv->previous_q_lsf_16_dec[k] + PHI_Priv->next_q_lsf_16_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/2, 5);    			    mod_nec_bws_lsp_decoder( lpc_indices + 5, PHI_Priv->current_q_lsf_8_dec,					    PHI_Priv->current_q_lsf_16_dec,					    lpc_order, lpc_order/2, 6, PHI_Priv->blsp_dec, PHI_Priv);		    }		    else		    {		    /* LSPs received in the previous frame: do nothing */		    ;		    }	    }    	    /*------------------------------------------------------------------*/	    /* Interpolation Procedure on LSPs                                  */	    /*------------------------------------------------------------------*/	    for(s = 0; s < (int)n_subframes; s++)	    {		    for(k = 0; k < (int)lpc_order; k++)		    {		    register float tmp;    		    tmp = (((float)((int)n_subframes - s - 1) * PHI_Priv->previous_q_lsf_16_dec[k]) 		       + ((float)(1 + s) * PHI_Priv->current_q_lsf_16_dec[k]))/(float)n_subframes;		    int_lsf[k] = tmp;		    }    		    /*--------------------------------------------------------------*/		    /*Compute corresponding a-parameters                            */		    /*--------------------------------------------------------------*/		    lsf2pc(tmp_lpc_coefficients, int_lsf, lpc_order);		    for( k = 0; k < lpc_order; k++)		    {		      int_Qlpc_coefficients[s*(int)lpc_order + k] = -tmp_lpc_coefficients[k+1];		    }	    }    	    /* -----------------------------------------------------------------*/	    /* Save memory                                                      */	    /* -----------------------------------------------------------------*/	    for(k=0; k < (int)lpc_order/2; k++)	    {		    PHI_Priv->previous_q_lsf_8_dec[k] = PHI_Priv->current_q_lsf_8_dec[k];		    PHI_Priv->current_q_lsf_8_dec[k] = PHI_Priv->next_q_lsf_8_dec[k];	    }    	    for(k=0; k < (int)lpc_order; k++)	    {		    PHI_Priv->previous_q_lsf_16_dec[k] = PHI_Priv->current_q_lsf_16_dec[k];		    PHI_Priv->current_q_lsf_16_dec[k] = PHI_Priv->next_q_lsf_16_dec[k];	    }	    PHI_Priv->PHI_dec_prev_interpolation_flag = interpolation_flag;    	    /* -----------------------------------------------------------------*/	    /* Free the malloc'd arrays                                         */	    /* -----------------------------------------------------------------*/	    free(int_lsf);	    free(tmp_lpc_coefficients);		}	else	{    /*    16 khz Optimized VQ   */	    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_wb_celp_lsp_decode(lpc_indices, PHI_Priv->previous_q_lsf_16_dec,		                           PHI_Priv->next_q_lsf_16_dec, lpc_order, 		                           num_lpc_indices);    		    /*------------------------------------------------------------------*/		    /* Interpolate LSP coeffs to obtain coeficients of cuurent frame    */		    /*------------------------------------------------------------------*/		    for(k = 0; k < (int)lpc_order; k++)		    {			    PHI_Priv->current_q_lsf_16_dec[k] = 			    (float)0.5 * (PHI_Priv->previous_q_lsf_16_dec[k] + PHI_Priv->next_q_lsf_16_dec[k]);		    } 	    }	    else	    {		    if (PHI_Priv->PHI_dec_prev_interpolation_flag == 0)		    {			    /*--------------------------------------------------------------*/			    /* Compute LSP coeffs of the current frame                      */			    /*--------------------------------------------------------------*/			    mod_wb_celp_lsp_decode(lpc_indices, 					    PHI_Priv->previous_q_lsf_16_dec,					    PHI_Priv->current_q_lsf_16_dec,						      lpc_order, num_lpc_indices);		    }		    else		    {		    /* LSPs received in the previous frame: do nothing */		    ;		    }	    }    	    /*------------------------------------------------------------------*/	    /* Interpolation Procedure on LSPs                                  */	    /*------------------------------------------------------------------*/	    for(s = 0; s < (int)n_subframes; s++)	    {		    for(k = 0; k < (int)lpc_order; k++)		    {		    register float tmp;    		    tmp = (((float)((int)n_subframes - s - 1) * PHI_Priv->previous_q_lsf_16_dec[k]) 		       + ((float)(1 + s) * PHI_Priv->current_q_lsf_16_dec[k]))/(float)n_subframes;		    int_lsf[k] = tmp;		    }    		    /*--------------------------------------------------------------*/		    /*Compute corresponding a-parameters                            */		    /*--------------------------------------------------------------*/		    lsf2pc(tmp_lpc_coefficients, int_lsf, lpc_order);		    for( k = 0; k < lpc_order; k++)		    {		      int_Qlpc_coefficients[s*(int)lpc_order + k] = -tmp_lpc_coefficients[k+1];		    }	    }    	    /* -----------------------------------------------------------------*/	    /* Save memory                                                      */	    /* -----------------------------------------------------------------*/	    for(k=0; k < (int)lpc_order; k++)	    {		    PHI_Priv->previous_q_lsf_16_dec[k] = PHI_Priv->current_q_lsf_16_dec[k];		    PHI_Priv->current_q_lsf_16_dec[k] = PHI_Priv->next_q_lsf_16_dec[k];	    }	    PHI_Priv->PHI_dec_prev_interpolation_flag = interpolation_flag;    	    /* -----------------------------------------------------------------*/	    /* Free the malloc'd arrays                                         */	    /* -----------------------------------------------------------------*/	    free (int_lsf);	    free (tmp_lpc_coefficients);	}        }}/*======================================================================*//*   Function Definition:celp_lpc_quantizer using VQ                    *//*======================================================================*/void VQ_celp_lpc_quantizer(float lpc_coefficients[],      /* In:  Current unquantised a-pars       */float lpc_coefficients_8[],    /* In:  Current unquantised a-pars(8 kHz)*/float int_Qlpc_coefficients[], /* Out: Qaunt/interpolated a-pars        */long  lpc_indices[],           /* Out: Codes thar are transmitted       */long  lpc_order,               /* In:  Order of LPC                     */long  num_lpc_indices,         /* In:  Number of packes LPC codes       */long  n_lpc_analysis,          /* In:  Number of LPC/frame              */long  n_subframes,             /* In:  Number of subframes              */long  *interpolation_flag,     /* Out: Interpolation Flag               */long  *send_lpc_flag,          /* Out: Send LPC flag                    */long  Wideband_VQ,PHI_PRIV_TYPE *PHI_Priv	      /* In/Out: PHI private data (instance context) */){    if (lpc_order == ORDER_LPC_8)    {    /*   fs = 8 khz  */	    float *int_lsf;	    long  *next_codes;	    long  *current_codes;	    float *tmp_lpc_coefficients;	    int   i,s,k;	    /*------------------------------------------------------------------*/	    /* Allocate space for current_rfc and current lar                   */	    /*------------------------------------------------------------------*/	    if 	    (	    (( int_lsf = (float *)malloc((unsigned int)lpc_order * sizeof(float))) == NULL ) ||	    (( next_codes = (long *)malloc((unsigned int)num_lpc_indices * sizeof(long))) == NULL ) ||	    (( current_codes = (long *)malloc((unsigned int)num_lpc_indices * sizeof(long))) == 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);		    }    	    /*------------------------------------------------------------------*/	    /* Calculate Narrowband LSPs                                        */	    /*------------------------------------------------------------------*/	    tmp_lpc_coefficients[0] = 1.;	    for(i=0;i<lpc_order;i++) 		    tmp_lpc_coefficients[i+1] = 				    -lpc_coefficients[i];    	    pc2lsf(PHI_Priv->next_uq_lsf_8, tmp_lpc_coefficients, lpc_order);	    /*------------------------------------------------------------------*/	    /* Narrowband Quantization Procedure                                */	    /*------------------------------------------------------------------*/	    mod_nb_abs_lsp_quantizer(PHI_Priv->next_uq_lsf_8, PHI_Priv->previous_q_lsf_8, PHI_Priv->next_q_lsf_8,				     next_codes, lpc_order, 5,				     n_lpc_analysis);	    /*------------------------------------------------------------------*/	    /* Narrowband Quantization Procedure                                */	    /*------------------------------------------------------------------*/	    mod_nb_abs_lsp_quantizer(PHI_Priv->current_uq_lsf_8, PHI_Priv->previous_q_lsf_8, PHI_Priv->current_q_lsf_8,				     current_codes, lpc_order, 5,

⌨️ 快捷键说明

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