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

📄 hvxcenc.c

📁 语音压缩算法
💻 C
📖 第 1 页 / 共 2 页
字号:
/*This software module was originally developed by    Kazuyuki Iijima (Sony Corporation)     and edited by    Naoya Tanaka (Matsushita Communication Industrial Co., Ltd.),    Akira Inoue (Sony Corporation) and    Yuji Maeda (Sony Corporation)    in the course of development of the MPEG-4 Audio standard (ISO/IEC 14496-3).    This software module is an implementation of a part of one or more    MPEG-4 Audio (ISO/IEC 14496-3) tools as specified by the MPEG-4 Audio    standard (ISO/IEC 14496-3).    ISO/IEC gives users of the MPEG-4 Audio standards (ISO/IEC 14496-3)    free license to this software module or modifications thereof for use    in hardware or software products claiming conformance to the MPEG-4    Audio standards (ISO/IEC 14496-3).    Those intending to use this software module in hardware or software    products are advised that this use may infringe existing patents.    The original developer of this software module and his/her company,    the subsequent editors and their companies, and ISO/IEC have no    liability for use of this software module or modifications thereof in    an implementation.    Copyright is not released for non MPEG-4 Audio (ISO/IEC 14496-3)    conforming products. The original developer retains full right to use    the code for his/her own purpose, assign or donate the code to a third    party and to inhibit third party from using the code for non MPEG-4    Audio (ISO/IEC 14496-3) conforming products.    This copyright notice must be included in all copies or derivative works.    Copyright (c)1996.                                                                  */#include <math.h>#include <stdio.h>#include <stdlib.h>#include <malloc.h>#include "hvxc.h"#include "hvxcCommon.h"#include "hvxcEnc.h"#include "pan_par_const.h"extern float	ipc_coef[SAMPLE];extern float	ipc_coef160[FRM];extern int	ipc_encMode;extern int	ipc_decMode;extern int	ipc_encDelayMode;extern int	ipc_decDelayMode;extern int	ipc_bitstreamMode;int judge = 0;/* 971112 */static float **hamWindow;static float *gammaBE;void IPC_HVXCInit(void){    int	i;    IPC_makeCoef(ipc_coef, SAMPLE);    for(i = 48; i < 208; i++)    {	ipc_coef160[i - 48] = ipc_coef[i];    }    IPC_make_bss();    IPC_set_const_lpcVM();    IPC_make_f_coef();/* 971112 */    if(NULL==(hamWindow=(float **)calloc(1, sizeof(float *)))) {	printf("\n Memory allocation error in HvxcInit\n");	exit(1);    }    if(NULL==(*hamWindow=(float *)calloc((PAN_WIN_LEN_PAR), sizeof(float)))) {	printf("\n Memory allocation error in HvxcInit\n");	exit(1);    }    if(NULL==(gammaBE=(float *)calloc(P, sizeof(float)))) {	printf("\n Memory allocation error in HvxcInit\n");	exit(1);    }    for(i=0;i<PAN_WIN_LEN_PAR;i++) {	*(*hamWindow+i) = (float)(.54-.46*cos((6.283185307*i)		/(double)(PAN_WIN_LEN_PAR)));    }    *gammaBE = (PAN_GAMMA_BE_PAR);    for(i=1;i<P;i++) {	*(gammaBE+i) = (*(gammaBE+i-1))*(PAN_GAMMA_BE_PAR);    }}/* 971112 */void IPC_HVXCFree(void){    free(*hamWindow);    free(hamWindow);    free(gammaBE);}#define LONG64	/* for 64bit platform like IRIX64@R10000(AI 990219) */void IPC_Normalization(float	arysRaw[SAMPLE],float	arysOut[FRM],float	arysres[SAMPLE],float	*frmPwr,float	alpha[P],float	rawLsp[P],float	qLsp[P],IdLsp	*idLsp,int	*offset){    float alphae[P + 1];    float lsp[P + 1];    float lspIn[P + 1];    float lspOut[P + 1];    static int		frm = 0;    int		i;    float	tmp;    float	arysTmp[SAMPLE];    float	alphaq[P + 1];    static long window_sizes[1]={PAN_WIN_LEN_PAR};    static long window_offsets[1]={PAN_WIN_OFFSET_PAR};    float alphaTmp[P];    float lspTmp[P];    float first_order_lpc_par; /* dummy */#include "inc_lsp_575.tbl"    float panLsp[P];    static float prevQLsp[P];    static float p_factor=PAN_LSP_AR_R_PAR;    static float min_gap=PAN_MINGAP_PAR;    static long num_dc=PAN_N_DC_LSP_PAR;    float lspWeight[P];    float dLsp[P+1];    float w_fact;#ifdef LONG64    long idx[L_VQ];#endif    if(0==frm) {        for(i=0;i<P;i++) prevQLsp[i] = (i+1.)/(float)(P+1);    }    for(i = 0; i < SAMPLE; i++)    {	arysTmp[i] = arysRaw[i];    }    IPC_hp_filter4(arysTmp, frm);    for(i = 0; i < FRM; i++)    {	arysOut[i] = arysTmp[OVERLAP / 2 + i];    }    tmp = 0.0;    for(i = 0; i < FRM; i++)    {	tmp += arysOut[i] * arysOut[i];    }    *frmPwr = tmp / (float) FRM;    celp_lpc_analysis(arysTmp, alphaTmp, 		&first_order_lpc_par, 		PAN_WIN_LEN_PAR, window_offsets, window_sizes, 		hamWindow, gammaBE,		PAN_LPC_ORDER_PAR, PAN_NUM_ANA_PAR);    alphae[0] = 1.;    for(i=0;i<P;i++) alphae[i+1] = -alphaTmp[i];/* LPC -> LSP */    pc2lsf(lspTmp, alphae, P);    for(i=0;i<P;i++) lspTmp[i] /= PAN_PI;    lsp[0] = 0.;    for(i=0;i<P;i++) lsp[i+1] = lspTmp[i]*.5;	    for(i=0;i<P;i++) panLsp[i] = lsp[i+1]*2.;    dLsp[0] = panLsp[0];    for(i=1;i<P;i++) dLsp[i] = panLsp[i]-panLsp[i-1];    dLsp[P] = 1.-panLsp[P-1];    for(i=0;i<=P;i++) {        if(dLsp[i]<min_gap) dLsp[i] = min_gap;    }    for(i=0;i<=P;i++) dLsp[i] = 1./dLsp[i];    for(i=0;i<P;i++) lspWeight[i] = dLsp[i]+dLsp[i+1];    w_fact = 1.;    for(i=0;i<4;i++) {        lspWeight[i] *= w_fact;    }    for(i=4;i<8;i++) {        w_fact *= .694;        lspWeight[i] *= w_fact;    }    for(i=8;i<10;i++) {        w_fact *= .510;        lspWeight[i] *= w_fact;    }#ifdef LONG64    pan_lspqtz2_dd(panLsp, prevQLsp, lspOut+1,        lspWeight, p_factor, min_gap, P, num_dc, 	idx, lsp_tbl, d_tbl, pd_tbl,         dim_1, ncd_1, dim_2, ncd_2, 1);    for (i = 0; i < L_VQ; i++) idLsp->nVq[i] = (int)idx[i];#else    pan_lspqtz2_dd(panLsp, prevQLsp, lspOut+1,        lspWeight, p_factor, min_gap, P, num_dc,         (long *)idLsp->nVq, lsp_tbl, d_tbl, pd_tbl,         dim_1, ncd_1, dim_2, ncd_2, 1);#endif/* 98.1.16 */    for(i=0;i<P;i++) prevQLsp[i] = lspOut[i+1];    if(ENC4K==ipc_encMode)    {	for(i = 0; i < P + 1; i++)	{	    lspIn[i] = 2.0 * lsp[i];	}		IPC_quanlsp_enh(lspIn, lspOut, lspOut, idLsp, lspWeight);    }        for(i=0;i<P;i++) lspOut[i+1] *= .5;    for(i = 0; i < P; i++)    {	alpha[i] = alphae[i + 1];    }        for(i = 0; i < P; i++)    {	rawLsp[i] = lsp[i + 1];    }        for(i = 0; i < P; i++)    {	qLsp[i] = lspOut[i + 1];    }    alphaq[0] = 1.0;    IPC_lsp_lpc(lspOut, alphaq);    for(i = 1; i < 11; i++)    {	alphaq[i] *= -1.0;    }    IPC_calc_residue256(arysTmp, alphaq, arysres);        *offset = - OVERLAP / 2;    frm++;    return;}void IPC_NormalizationVR(float   arysRaw[SAMPLE],float   arysOut[FRM],float   arysres[SAMPLE],float   *frmPwr,float   alpha[P],float   rawLsp[P],float   qLsp[P],IdLsp   *idLsp,int     *offset,int     idVUV){    float alphae[P + 1];    float lsp[P + 1];    float lspIn[P + 1];    float lspOut[P + 1];    static int          frm = 0;    int         i;    float       tmp;    float       arysTmp[SAMPLE];    float       alphaq[P + 1];    static long window_sizes[1]={PAN_WIN_LEN_PAR};    static long window_offsets[1]={PAN_WIN_OFFSET_PAR};    float alphaTmp[P];    float lspTmp[P];    float first_order_lpc_par; /* dummy */#include "inc_lsp_575.tbl"    float panLsp[P];    static float prevQLsp[P];    static float p_factor=PAN_LSP_AR_R_PAR;    static float min_gap=PAN_MINGAP_PAR;    static long num_dc=PAN_N_DC_LSP_PAR;    float lspWeight[P];    float dLsp[P+1];    float w_fact;    int qMode = 0;    static int prevVUV = 0;#ifdef LONG64    long idx[L_VQ];#endif    if(0==frm) {        for(i=0;i<P;i++) prevQLsp[i] = (i+1.)/(float)(P+1);    }    for(i = 0; i < SAMPLE; i++)    {        arysTmp[i] = arysRaw[i];    }    IPC_hp_filter4(arysTmp, frm);    for(i = 0; i < FRM; i++)    {        arysOut[i] = arysTmp[OVERLAP / 2 + i];    }    tmp = 0.0;    for(i = 0; i < FRM; i++)    {        tmp += arysOut[i] * arysOut[i];    }    *frmPwr = tmp / (float) FRM;    celp_lpc_analysis(arysTmp, alphaTmp,                &first_order_lpc_par,                PAN_WIN_LEN_PAR, window_offsets, window_sizes,		hamWindow, gammaBE,                PAN_LPC_ORDER_PAR, PAN_NUM_ANA_PAR);    alphae[0] = 1.;    for(i=0;i<P;i++) alphae[i+1] = -alphaTmp[i];/* LPC -> LSP */    pc2lsf(lspTmp, alphae, P);    for(i=0;i<P;i++) lspTmp[i] /= PAN_PI;    lsp[0] = 0.;    for(i=0;i<P;i++) lsp[i+1] = lspTmp[i]*.5;    for(i=0;i<P;i++) panLsp[i] = lsp[i+1]*2.;    dLsp[0] = panLsp[0];    for(i=1;i<P;i++) dLsp[i] = panLsp[i]-panLsp[i-1];    dLsp[P] = 1.-panLsp[P-1];    for(i=0;i<=P;i++) {        if(dLsp[i]<min_gap) dLsp[i] = min_gap;    }    for(i=0;i<=P;i++) dLsp[i] = 1./dLsp[i];    for(i=0;i<P;i++) lspWeight[i] = dLsp[i]+dLsp[i+1];    w_fact = 1.;    for(i=0;i<4;i++) {        lspWeight[i] *= w_fact;    }    for(i=4;i<8;i++) {        w_fact *= .694;        lspWeight[i] *= w_fact;    }    for(i=8;i<10;i++) {        w_fact *= .510;        lspWeight[i] *= w_fact;    }    if(idVUV == 1 || prevVUV == 1)    {        qMode = 1;    }#ifdef LONG64    pan_lspqtz2_dd(panLsp, prevQLsp, lspOut+1,        lspWeight, p_factor, min_gap, P, num_dc, 	idx, lsp_tbl, d_tbl, pd_tbl,         dim_1, ncd_1, dim_2, ncd_2, 1);    for (i = 0; i < L_VQ; i++) idLsp->nVq[i] = (int)idx[i];#else    pan_lspqtz2_dd(panLsp, prevQLsp, lspOut+1,        lspWeight, p_factor, min_gap, P, num_dc,         (long *)idLsp->nVq, lsp_tbl, d_tbl, pd_tbl,         dim_1, ncd_1, dim_2, ncd_2, 1);#endif/* 98.1.20 */    for(i=0;i<P;i++) prevQLsp[i] = lspOut[i+1];    if(ENC4K==ipc_encMode) {        for(i = 0; i < P + 1; i++)        {            lspIn[i] = 2.0 * lsp[i];        }        IPC_quanlsp_enh(lspIn, lspOut, lspOut, idLsp, lspWeight);    }    for(i=0;i<P;i++) lspOut[i+1] *= .5;    for(i = 0; i < P; i++)    {        alpha[i] = alphae[i + 1];    }    for(i = 0; i < P; i++)    {        rawLsp[i] = lsp[i + 1];    }    for(i = 0; i < P; i++)    {        qLsp[i] = lspOut[i + 1];    }    alphaq[0] = 1.0;    IPC_lsp_lpc(lspOut, alphaq);    for(i = 1; i < 11; i++)    {        alphaq[i] *= -1.0;    }    IPC_calc_residue256(arysTmp, alphaq, arysres);    *offset = - OVERLAP / 2;    prevVUV = idVUV;    frm++;    return;}void IPC_HVXCEncParFrm(short int	*frmBuf,IdLsp		*idLsp,int		*idVUV,IdCelp		*idCelp,

⌨️ 快捷键说明

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