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

📄 nb_celp_enc.c

📁 MPEG2/MPEG4编解码参考程序(实现了MPEG4的部分功能)
💻 C
📖 第 1 页 / 共 2 页
字号:
	long lag_candidates[],         /* in: lag candidates */	long n_lag_candidates,         /* in: number of lag candididates */	long frame_size,               /* in: frame size */	long sbfrm_size,               /* in: subframe size */	long n_subframes,              /* in: number of subframes */	long *signal_mode,             /* out: signal mode */	long frame_bit_allocation[],   /* in: bit number for each index */	long shape_indices[],          /* out: shape code indices */	long gain_indices[],           /* out: gain code indices */	long num_shape_cbks,           /* in: number of shape codebooks */	long num_gain_cbks,            /* in: number of gain codebooks */	long *rms_index,               /* out: RMS code index */	float decoded_excitation[],    /* out: decoded excitation */	long num_enhstages,	float bws_mp_exc[],        long SampleRateMode){/* local */    float *RevIntQLPCoef;    float *RevWnumCoef;    float *RevWdenCoef;    long i;    static long c_subframe = 0;    long num_lpc_indices;    if(fs8kHz==SampleRateMode) {        num_lpc_indices = PAN_NUM_LPC_INDICES;    }else {        num_lpc_indices = PAN_NUM_LPC_INDICES_W;    }    c_subframe = c_subframe % n_subframes;/* memory allocation */    if((RevIntQLPCoef=(float *)calloc(lpc_order*n_subframes,             sizeof(float)))==NULL) {        printf("\n memory allocation error in excitation analysis\n");        exit(1);    }    if((RevWnumCoef=(float *)calloc(lpc_order*n_subframes,             sizeof(float)))==NULL) {        printf("\n memory allocation error in excitation analysis\n");        exit(2);    }    if((RevWdenCoef=(float *)calloc(lpc_order*n_subframes,             sizeof(float)))==NULL) {        printf("\n memory allocation error in excitation analysis\n");        exit(3);    }/* reverse the sign of LP parameters */    for(i=0;i<lpc_order*n_subframes;i++) *(RevIntQLPCoef+i) = -(*(int_Qlpc_coefficients+i));    for(i=0;i<lpc_order*n_subframes;i++) *(RevWnumCoef+i) = -(*(Wnum_coeff+i));    for(i=0;i<lpc_order*n_subframes;i++) *(RevWdenCoef+i) = -(*(Wden_coeff+i));    nec_abs_excitation_analysis (	PP_InputSignal,            /* in: preprocessed input signal */	RevIntQLPCoef,             /* in: interpolated LPC */	RevWnumCoef,               /* in: weighting coeff.(numerator) */	RevWdenCoef,               /* in: weighting coeff.(denominator) */	shape_indices,             /* out: shape code indices */	gain_indices,              /* out: gain_code_indices */	rms_index,                 /* out: RMS code index */	signal_mode,               /* out: signal mode */	decoded_excitation,        /* out: decoded excitation */	lpc_order,                 /* in: order of LPC */	frame_size,                /* in: frame size */	sbfrm_size,                /* in: subframe size */	n_subframes,               /* in: number of subframes */	frame_bit_allocation+num_lpc_indices,	num_shape_cbks,            /* in: number of shape codebooks */	num_gain_cbks,              /* in: number of gain codebooks */	num_enhstages,             /* in: number of enhancement stages */        bws_mp_exc,        SampleRateMode				    );    c_subframe++;    free(RevIntQLPCoef);    free(RevWnumCoef);    free(RevWdenCoef);}void bws_excitation_analysis(	float PP_InputSignal[],        /* in: preprocessed input signal */	float int_Qlpc_coefficients[], /* in: interpolated LPC */	long lpc_order,                /* in: order of LPC */	float Wnum_coeff[],            /* in: weighting coeff.(numerator) */	float Wden_coeff[],            /* in: weighting coeff.(denominator) */	long frame_size,               /* in: frame size */	long sbfrm_size,               /* in: subframe size */	long n_subframes,              /* in: number of subframes */	long signal_mode,              /* in: signal mode */	long frame_bit_allocation[],   /* in: bit number for each index */	long shape_indices[],          /* out: shape code indices */	long gain_indices[],           /* out: gain code indices */	long num_shape_cbks,           /* in: number of shape codebooks */	long num_gain_cbks,            /* in: number of gain codebooks */	float decoded_excitation[],    /* out: decoded excitation */        float bws_mp_exc[],        long  *acb_index_8,	long  rms_index			/* in: RMS code index */){/* local */    float *RevIntQLPCoef;    float *RevWnumCoef;    float *RevWdenCoef;    long i;    static long c_subframe = 0;    c_subframe = c_subframe % n_subframes;/* memory allocation */    if((RevIntQLPCoef=(float *)calloc(lpc_order*n_subframes,             sizeof(float)))==NULL) {        printf("\n memory allocation error in excitation analysis\n");        exit(1);    }    if((RevWnumCoef=(float *)calloc(lpc_order*n_subframes,             sizeof(float)))==NULL) {        printf("\n memory allocation error in excitation analysis\n");        exit(2);    }    if((RevWdenCoef=(float *)calloc(lpc_order*n_subframes,             sizeof(float)))==NULL) {        printf("\n memory allocation error in excitation analysis\n");        exit(3);    }/* reverse the sign of LP parameters */    for(i=0;i<lpc_order*n_subframes;i++) *(RevIntQLPCoef+i) = -(*(int_Qlpc_coefficients+i));    for(i=0;i<lpc_order*n_subframes;i++) *(RevWnumCoef+i) = -(*(Wnum_coeff+i));    for(i=0;i<lpc_order*n_subframes;i++) *(RevWdenCoef+i) = -(*(Wden_coeff+i));    nec_bws_excitation_analysis (	PP_InputSignal,            /* in: preprocessed input signal */	RevIntQLPCoef,             /* in: interpolated LPC */	RevWnumCoef,               /* in: weighting coeff.(numerator) */	RevWdenCoef,               /* in: weighting coeff.(denominator) */	shape_indices,             /* out: shape code indices */	gain_indices,              /* out: gain_code_indices */	decoded_excitation,        /* out: decoded excitation */	lpc_order,                 /* in: order of LPC */	sbfrm_size,                /* in: subframe size */	n_subframes,               /* in: number of subframes */	frame_bit_allocation,	num_shape_cbks,            /* in: number of shape codebooks */	num_gain_cbks,              /* in: number of gain codebooks */	bws_mp_exc,		/* input */	acb_index_8,		/* input */	rms_index,			/* in: RMS code index */	signal_mode		/* in: signal mode */				    );    c_subframe++;    free(RevIntQLPCoef);    free(RevWnumCoef);    free(RevWdenCoef);}/* LSP VQ modules for wideband 980107 */void wb_celp_lsp_quantizer (    float lpc_coefficients[],		/* in: LPC */    float int_Qlpc_coefficients[],	/* out: quantized & interpolated LPC */     long lpc_indices[], 		/* out: LPC code indices */    long lpc_order,			/* in: order of LPC */    long num_lpc_indices,    /* in: number of LPC indices */    long n_lpc_analysis,     /* in: number of LP analysis per frame */    long n_subframes,        /* in: number of subframes */    long *interpolation_flag,	/* out: interpolation flag */    long signal_mode,			/* inp: signal mode */    long frame_bit_allocation[], /* in: bit number for each index */    long sampling_frequency,	/* in: sampling frequency */    float *prev_Qlsp_coefficients){    #include	"inc_lsp46w.tbl"    float *lsp_coefficients;    float *Qlsp_coefficients;    float *int_Qlsp_coefficients;    float *tmp_lpc_coefficients;    long i, j;    float *lsp_weight;    float *d_lsp;    float *lsp_tbl;    float *d_tbl;    float *pd_tbl;    long *dim_1;    long *dim_2;    long *ncd_1;    long *ncd_2;    long offset;    long orderLsp;    long h_n_subframes;/* Memory allocation */    if((lsp_coefficients=(float *)calloc(lpc_order, sizeof(float)))==NULL) {		printf("\n Memory allocation error in abs_lpc_quantizer\n");		exit(1);	}    if((Qlsp_coefficients=(float *)calloc(lpc_order, sizeof(float)))==NULL) {		printf("\n Memory allocation error in abs_lpc_quantizer\n");		exit(2);	}    if((int_Qlsp_coefficients=(float *)calloc(lpc_order, sizeof(float)))==NULL) {		printf("\n Memory allocation error in abs_lpc_quantizer\n");		exit(3);	}    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((lsp_weight=(float *)calloc(lpc_order, sizeof(float)))==NULL) {		printf("\n Memory allocation error in abs_lpc_quantizer\n");		exit(5);	}    if((d_lsp=(float *)calloc((lpc_order+1), sizeof(float)))==NULL) {		printf("\n Memory allocation error in abs_lpc_quantizer\n");		exit(6);	}/* reverse the sign of input LPCs *//*   Philips: 			A(z) = 1+a1z^(-1)+ ... +apz^(-p) *//*   AT&T, Panasonic:	A(z) = 1-a1z^(-1)- ... -apz^(-p) */    tmp_lpc_coefficients[0] = 1.;    for(i=0;i<lpc_order;i++)         tmp_lpc_coefficients[i+1] = 			-lpc_coefficients[lpc_order*(n_lpc_analysis-1)+i];/* LPC -> LSP */    pc2lsf(lsp_coefficients, tmp_lpc_coefficients, lpc_order);    for(i=0;i<lpc_order;i++) lsp_coefficients[i] /= PAN_PI;/* Weighting factor */    d_lsp[0] = lsp_coefficients[0];    for(i=1;i<lpc_order;i++) {         d_lsp[i] = lsp_coefficients[i]-lsp_coefficients[i-1];    }    d_lsp[lpc_order] = 1.-lsp_coefficients[lpc_order-1];    for(i=0;i<=lpc_order;i++) {        if(d_lsp[i]<PAN_MINGAP_CELP_W) d_lsp[i] = PAN_MINGAP_CELP_W;    }     for(i=0;i<=lpc_order;i++) d_lsp[i] = 1./d_lsp[i];    for(i=0;i<lpc_order;i++) {        lsp_weight[i] = d_lsp[i]+d_lsp[i+1];    }/* Quantization - lower part */    orderLsp = dim46w_L1[0]+dim46w_L1[1];    lsp_tbl = lsp_tbl46w_L;    d_tbl = d_tbl46w_L;    pd_tbl = pd_tbl46w_L;    dim_1 = dim46w_L1;    dim_2 = dim46w_L2;    ncd_1 = ncd46w_L1;    ncd_2 = ncd46w_L2;    pan_lspqtz2_dd(lsp_coefficients,         prev_Qlsp_coefficients, Qlsp_coefficients,         lsp_weight, PAN_LSP_AR_R_CELP_W, PAN_MINGAP_CELP_W,         orderLsp, PAN_N_DC_LSP_CELP_W,             lpc_indices, lsp_tbl, d_tbl, pd_tbl,         dim_1, ncd_1, dim_2, ncd_2, 0);/* Quantization - upper part */    orderLsp = dim46w_U1[0]+dim46w_U1[1];    offset = dim46w_L1[0]+dim46w_L1[1];    lsp_tbl = lsp_tbl46w_U;    d_tbl = d_tbl46w_U;    pd_tbl = pd_tbl46w_U;    dim_1 = dim46w_U1;    dim_2 = dim46w_U2;    ncd_1 = ncd46w_U1;    ncd_2 = ncd46w_U2;    pan_lspqtz2_dd(lsp_coefficients+offset,         prev_Qlsp_coefficients+offset, Qlsp_coefficients+offset,         lsp_weight+offset, PAN_LSP_AR_R_CELP_W, PAN_MINGAP_CELP_W,         orderLsp, PAN_N_DC_LSP_CELP_W,             lpc_indices+5, lsp_tbl, d_tbl, pd_tbl,         dim_1, ncd_1, dim_2, ncd_2, 0);    pan_stab(Qlsp_coefficients, PAN_MINGAP_CELP_W, lpc_order);/* for Testing     for(i=0;i<lpc_order;i++) printf("%7.5f ", Qlsp_coefficients[i]);    printf("\n");*//* Interpolation & LSP -> LPC conversion */    for(i=0;i<n_subframes;i++) {        pan_lsp_interpolation(prev_Qlsp_coefficients, Qlsp_coefficients,             int_Qlsp_coefficients, lpc_order, n_subframes, i);        for(j=0;j<lpc_order;j++) int_Qlsp_coefficients[j] *= PAN_PI;        lsf2pc(tmp_lpc_coefficients, int_Qlsp_coefficients, lpc_order);        for(j=0;j<lpc_order;j++)             int_Qlpc_coefficients[lpc_order*i+j]                 = -tmp_lpc_coefficients[j+1];    }    pan_mv_fdata(prev_Qlsp_coefficients, Qlsp_coefficients, lpc_order);    free(lsp_coefficients);    free(Qlsp_coefficients);    free(int_Qlsp_coefficients);    free(tmp_lpc_coefficients);    free(lsp_weight);    free(d_lsp);}

⌨️ 快捷键说明

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