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

📄 phi_lpc.c

📁 MPEG2/MPEG4编解码参考程序(实现了MPEG4的部分功能)
💻 C
📖 第 1 页 / 共 5 页
字号:
    /* -----------------------------------------------------------------*/    if((PHI_Priv->previous_q_lsf_8=(float *)calloc(order_8, sizeof(float)))==NULL) {       printf("\n memory allocation error in initialization_encoder\n");       exit(1);    }    for(i=0;i<order_8;i++)        *(PHI_Priv->previous_q_lsf_8+i) = ((i+1)/(float)((order_8)+1))*PAN_PI;    if((PHI_Priv->current_q_lsf_8=(float *)calloc(order_8, sizeof(float)))==NULL) {      printf("\n memory allocation error in initialization_encoder\n");       exit(1);    }    for(i=0;i<order_8;i++)          *(PHI_Priv->current_q_lsf_8+i) = ((i+1)/(float)((order_8)+1))*PAN_PI;    if((PHI_Priv->next_q_lsf_8=(float *)calloc(order_8, sizeof(float)))==NULL) {     printf("\n memory allocation error in initialization_encoder\n");       exit(1);    }    for(i=0;i<order_8;i++)         *(PHI_Priv->next_q_lsf_8+i) = ((i+1)/(float)((order_8)+1))*PAN_PI;    if((PHI_Priv->previous_uq_lsf_8=(float *)calloc(order_8, sizeof(float)))==NULL) {      printf("\n memory allocation error in initialization_encoder\n");       exit(1);    }    for(i=0;i<order_8;i++)         *(PHI_Priv->previous_uq_lsf_8+i) = ((i+1)/(float)((order_8)+1))*PAN_PI;    if((PHI_Priv->current_uq_lsf_8=(float *)calloc(order_8, sizeof(float)))==NULL) {      printf("\n memory allocation error in initialization_encoder\n");       exit(1);    }    for(i=0;i<order_8;i++)         *(PHI_Priv->current_uq_lsf_8+i) = ((i+1)/(float)((order_8)+1))*PAN_PI;    if((PHI_Priv->next_uq_lsf_8=(float *)calloc(order_8, sizeof(float)))==NULL) {      printf("\n memory allocation error in initialization_encoder\n");       exit(1);    }    for(i=0;i<order_8;i++)      *(PHI_Priv->next_uq_lsf_8+i) = ((i+1)/(float)((order_8)+1))*PAN_PI;    if((PHI_Priv->previous_q_lsf_int_8=(float *)calloc(order_8, sizeof(float)))==NULL) {      printf("\n memory allocation error in initialization_encoder\n");       exit(1);    }    for(i=0;i<order_8;i++)         *(PHI_Priv->previous_q_lsf_int_8+i) = ((i+1)/(float)((order_8)+1)) * PAN_PI;    /* -----------------------------------------------------------------*/    /* Create Array for Quantiser (wideband)                            */    /* -----------------------------------------------------------------*/     if((PHI_Priv->previous_q_lsf_int_16=(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_int_16+i) = ((i+1)/(float)((order)+1)) * PAN_PI;     if((PHI_Priv->previous_q_lsf_16=(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+i) = ((i+1)/(float)((order)+1)) * PAN_PI;     if((PHI_Priv->current_q_lsf_16=(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+i) = ((i+1)/(float)((order)+1)) * PAN_PI;    if((PHI_Priv->next_q_lsf_16=(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+i) = ((i+1)/(float)((order)+1)) * PAN_PI;    if((PHI_Priv->previous_uq_lsf_16=(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_uq_lsf_16+i) = ((i+1)/(float)((order)+1)) * PAN_PI;    if((PHI_Priv->current_uq_lsf_16=(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_uq_lsf_16+i) = ((i+1)/(float)((order)+1)) * PAN_PI;    if((PHI_Priv->next_uq_lsf_16=(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_uq_lsf_16+i) = ((i+1)/(float)((order)+1)) * PAN_PI;        /* -----------------------------------------------------------------*/           /* Initialise arrays                                                */    /* -----------------------------------------------------------------*/    for(x=0; x < (int)order; x++)    {	PHI_Priv->PHI_mem_i[x] = PHI_Priv->PHI_prev_lar[x] = PHI_Priv->PHI_current_lar[x] = (float)0.0;	PHI_Priv->PHI_prev_indices[x] = (long)(21 - PHI_tbl_rfc_range[0][x]);    }    /* -----------------------------------------------------------------*/           /* Initialise variables for dynamic threshold                       */    /* -----------------------------------------------------------------*/    {         	long bits_frame;	float per_lpc;	long k;	/* ------------------------------------------------------------*/	/* Determine length of LPC frames and no LPC frames            */	/* ------------------------------------------------------------*/	PHI_Priv->PHI_MAX_BITS = 0;		for (k = 0; k < (2 + num_lpc_indices + n_subframes*(num_shape_cbks+num_gain_cbks)); k++)	{		PHI_Priv->PHI_MAX_BITS += frame_bit_allocation[k];	}	PHI_Priv->PHI_MIN_BITS = PHI_Priv->PHI_MAX_BITS;	for (k = 0; k < num_lpc_indices; k++)	{		PHI_Priv->PHI_MIN_BITS -= frame_bit_allocation[k+2];	}	PHI_Priv->PHI_FR = ((float)frame_size / (float)sampling_frequency);	/*-------------------------------------------------------------*/        /* How many bits per frame are needed to achieve fixed bit rate*/        /* equal to what user has input                                */        /*-------------------------------------------------------------*/        	bits_frame = (long)((float)bit_rate * PHI_Priv->PHI_FR + 0.5F);		/* ------------------------------------------------------------*/       	/*   Store desired bit rate                                    */	/* ------------------------------------------------------------*/       		PHI_Priv->PHI_desired_bit_rate = (long) ((float) bits_frame / PHI_Priv->PHI_FR + 0.5F);	PHI_Priv->PHI_actual_bits = 0;    	          /*-------------------------------------------------------------*/         /* Needed %-lpc to get the desired bit rate                    */         /*-------------------------------------------------------------*/         per_lpc = ((float)(bits_frame-PHI_Priv->PHI_MIN_BITS))/((float)(PHI_Priv->PHI_MAX_BITS-PHI_Priv->PHI_MIN_BITS));         /*-------------------------------------------------------------*/         /*  Choose initial value for distance threshold                */         /*-------------------------------------------------------------*/         if (per_lpc < 0.51F)         {              PHI_Priv->PHI_dyn_lpc_thresh = 1.0F;         }         else         if (per_lpc < 0.6F)         {              PHI_Priv->PHI_dyn_lpc_thresh = 0.25F;            }         else         if (per_lpc < 0.75F)         {               PHI_Priv->PHI_dyn_lpc_thresh = 0.15F;            }         else         if (per_lpc < 0.85F)         {              PHI_Priv->PHI_dyn_lpc_thresh = 0.1F;            }         else         if (per_lpc < 0.97F)         {             PHI_Priv->PHI_dyn_lpc_thresh = 0.05F;            }         else         {              PHI_Priv->PHI_dyn_lpc_thresh = 0.0F;            }                           /*-------------------------------------------------------------*/         /*  Compute number of frames per second                        */         /*-------------------------------------------------------------*/         PHI_Priv->PHI_FRAMES = (long)((float)sampling_frequency/(float)frame_size + 0.5F);         /*-------------------------------------------------------------*/         /*  Determine the stop threshold                               */         /*-------------------------------------------------------------*/                 PHI_Priv->PHI_stop_threshold = (float)0.35;            }}/*======================================================================*//*   Function Definition:PAN_InitLpcAnalysisEncoder                     *//*     Nov. 07 96  - Added for narrowband coder                         *//*======================================================================*/void PAN_InitLpcAnalysisEncoder(long  win_size[],               /* In:  LPC Analysis-Window Size        */long  n_lpc_analysis,           /* In:  Numberof LPC Analysis Frame     */long  order,                    /* In:  Order of LPC                    */float gamma_be,                 /* In:  Bandwidth Expansion Coefficient */long  bit_rate,                 /* In:  Bit Rate                        */PHI_PRIV_TYPE *PHI_Priv		/* In/Out: PHI private data (instance context) */){        /* -----------------------------------------------------------------*/    /* Create Arrays for Hamming Window and gamma array                 */    /* -----------------------------------------------------------------*/    if    (    (( PHI_Priv->PHI_mem_i = (float *)malloc((unsigned int)order * sizeof(float))) == NULL)    )    {		printf("MALLOC FAILURE in Routine InitLpcAnalysis \n");		exit(1);    }}/*======================================================================*//*   Function Definition:PHI_InitLpcAnalysisDecoder                     *//*======================================================================*/void PHI_InitLpcAnalysisDecoder(long  order,                   /* In:  Order of LPC                    */long  order_8,                  /* In:  Order of LPC                    */PHI_PRIV_TYPE *PHI_Priv		/* In/Out: PHI private data (instance context) */){    int     x;    int     i,j ;           /* -----------------------------------------------------------------*/    /* Create Arrays for lars in the decoder                            */    /* -----------------------------------------------------------------*/    if    (    (( PHI_Priv->PHI_mem_s = (float *)malloc((unsigned int)order * sizeof(float))) == NULL ) ||    (( PHI_Priv->PHI_dec_current_lar = (float *)malloc((unsigned int)order * sizeof(float))) == NULL )||    (( PHI_Priv->PHI_dec_prev_lar = (float *)malloc((unsigned int)order * sizeof(float))) == NULL )    )    {		printf("MALLOC FAILURE in Routine InitLpcAnalysis \n");		exit(1);    }    /* -----------------------------------------------------------------*/    /* Create Array for Quantiser BLSP                                  */    /* -----------------------------------------------------------------*/    for ( i = 0; i < NEC_LSPPRDCT_ORDER; i++ )     {       for ( j = 0; j < (int)order; j++ )        {	       if ( j >= (int)(order/2) )	           PHI_Priv->blsp_dec[i][j]=(float)NEC_PAI/(float)(order+1)*(j+1);	      else	           PHI_Priv->blsp_dec[i][j]=(float)0.0;       }    }        /* -----------------------------------------------------------------*/    /* Create Array for Quantiser (narrowband)                          */    /* -----------------------------------------------------------------*/    if((PHI_Priv->previous_q_lsf_8_dec=(float *)calloc(order_8, sizeof(float)))==NULL) {       printf("\n memory allocation error in initialization_encoder\n");       exit(1);    }        for(i=0;i<order_8;i++)        *(PHI_Priv->previous_q_lsf_8_dec+i) = ((i+1)/(float)((order_8)+1))*PAN_PI;    if((PHI_Priv->current_q_lsf_8_dec=(float *)calloc(order_8, sizeof(float)))==NULL) {       printf("\n memory allocation error in initialization_encoder\n");       exit(1);    }    for(i=0;i<order_8;i++)        *(PHI_Priv->current_q_lsf_8_dec+i) = ((i+1)/(float)((order_8)+1))*PAN_PI;    if((PHI_Priv->next_q_lsf_8_dec=(float *)calloc(order_8, sizeof(float)))==NULL) {       printf("\n memory allocation error in initialization_encoder\n");       exit(1);    }    for(i=0;i<order_8;i++)        *(PHI_Priv->next_q_lsf_8_dec+i) = ((i+1)/(float)((order_8)+1))*PAN_PI;           /* -----------------------------------------------------------------*/    /* 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);

⌨️ 快捷键说明

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