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

📄 hvxcvxcenc.c

📁 语音压缩算法
💻 C
📖 第 1 页 / 共 2 页
字号:
 /*This software module was originally developed by    Kazuyuki Iijima  (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 "hvxc.h"#include "hvxcEnc.h"#include "hvxcCommon.h"#include "hvxcVxcEnc.h"#include "hvxcCbCelp.h"#include "hvxcCbCelp4k.h"#define RND_MAX	0x7fffffff#ifdef __cplusplusextern "C"{#endif/* long random(void); */#ifdef __cplusplus}#endif#if defined(SUN)#ifdef __cplusplusextern "C"{#endif/* void srandom(int seed); */#ifdef __cplusplus}#endif#endif#define	BLND_RATIO_L0_4K	0.6#define	BLND_RATIO_L1_4K	0.0#define	BLND_RATIO_L0_2K	0.6#define	BLND_RATIO_L1_2K	0.0extern int	ipc_encMode;extern int	ipc_decMode;static void SpectralWeightingFilter(float	*alpha,float	*alphaFir){    int		i, j;    static float Lma[Np+1] =    {	0.0, 0.9, 0.81, 0.729, 0.6561, 0.59049,	0.531441, 0.478297, 0.430467, 0.387420,	0.348678    };    static float Lar[Np+1] =    {	0.0, 0.4, 0.16, 0.064, 0.0256, 0.01024,	0.004096, 0.001638, 0.000655, 0.000262,	0.000105    };    float	LAma[Nfir + 1], LAar[Np + 1];    float	state[Np + 1], tmp;    for(i = 1; i <= Np; i++)    {	state[i] = 0.0;	LAma[i] = Lma[i] * alpha[i];	LAar[i] = Lar[i] * alpha[i];    }    alphaFir[0] = state[1] = 1.0;    LAma[Nfir] = 0.0;    for(i = 1; i <= Nfir; i++)    {	tmp = LAma[i];	for(j = Np; j > 0; j--)	{	    tmp -= LAar[j] * state[j];	    state[j] = state[j - 1];	}	alphaFir[i] = tmp;	state[1] = tmp;    }}static void PerceptualWeightingFilter(int	fsize,float	*Ssub,float	*alphaFir,float	*spw,float	*statePWF){    int		i, j;    float	tmp;    for(i = 0; i < fsize; i++)    {	statePWF[i + FLTBUF - fsize] = Ssub[i];    }    for(i = 0; i < fsize; i++)    {	tmp = 0.0;	for(j = 0; j <= Nfir; j++)	{	    tmp += statePWF[i + FLTBUF - fsize - j] * alphaFir[j];	}		spw[i] = tmp;    }        for(i = 0; i < FLTBUF - fsize; i++)    {	statePWF[i] = statePWF[fsize + i];    }}static void ZeroInputResponseSubtraction(float	*alphaFir,float	*alphaP,float	*stateI,float	*stateAq,int	fsize,float	*spw,float	*r){    int			i, j;    float		preS[FLTBUF], *s;    float		*zero, tmp;    s = (float *) calloc(FLTBUF + fsize, sizeof(float));    zero = (float *) calloc(fsize, sizeof(float));        for(i = 0; i < FLTBUF; i++)    {	preS[i] = 0.0;    }    for(i = 0; i < FLTBUF + fsize; i++)    {	s[i] = 0.0;    }    for(i = 0; i < Nfir; i++)    {	preS[i + FLTBUF - fsize - Nfir] = stateI[i];    }        for(i = 0; i < fsize; i++)    {	tmp = 0.0;	for(j = 0; j <= Nfir; j++)	{	    tmp += preS[i + FLTBUF - fsize - j] * alphaFir[j];	}		s[FLTBUF + i] = tmp;    }    for(i = 1; i < ACR; i++) preS[i] = stateAq[i];    for(i = 0; i < fsize; i++)    {	tmp = s[FLTBUF + i];	for(j = ACR - 1; j > 0; j--)	{	    tmp -= alphaP[j] * preS[j];	    preS[j] = preS[j - 1];	}	preS[1] = tmp;	s[FLTBUF + i] = tmp;	zero[i] = tmp;	r[i] = spw[i] - zero[i];    }    free(s);    free(zero);}static void ZeroStateSynthesis(int	fsize,float	*in,float	*out,float	*alphaFir,float	*alphaP){    int i, j;    float pre_s[FLTBUF];    float temp;    float *s;        s = (float *) calloc(FLTBUF + fsize, sizeof(float));    for(i = 0; i <= Nfir; i++) pre_s[i+FLTBUF-fsize-Nfir] = 0.0;    for(i = 0; i < fsize; i++)    {	pre_s[i + FLTBUF - fsize] = in[i];	temp = 0.0;		for(j=0; j <= Nfir; j++)	{	    temp += pre_s[i + FLTBUF - fsize - j] * alphaFir[j];	}		s[FLTBUF + i] = temp;    }        for (i = 1; i < ACR; i++) pre_s[i] = 0.0;        for (i = 0; i < fsize; i++)    {	temp = s[FLTBUF + i];	for(j = ACR - 1; j > 0; j--)	{	    temp -= alphaP[j] * pre_s[j];	    pre_s[j] = pre_s[j-1];	}	pre_s[1] = temp;	out[i] = temp;    }    free(s);}static void UpdateFilterStates(float	g,float	*SC,float	*stateAq,float	*stateI,float	*alphaFir,float	*alphaQ,int	fsize,float	*ex){    int		i, j;    float	pre_s[FLTBUF], *s;    float	temp;    s = (float *) calloc(FLTBUF + fsize, sizeof(float));    for(i = 0; i < FLTBUF; i++)    {	pre_s[i] = 0.0;    }    for(i = 0; i < FLTBUF + fsize; i++)    {	s[i] = 0.0;    }    for(i = 0; i < fsize; i++)    {	ex[i] = g * SC[i];    }    for (i = 0; i < Nfir; i++)    {	pre_s[i + FLTBUF - fsize - Nfir] = stateI[i];	stateI[i] = ex[fsize - Nfir + i];    }    for (i=0;i<fsize;i++)    {	pre_s[i + FLTBUF - fsize] = ex[i];	temp = 0.0;	for(j = 0;j <= Nfir; j++)	{	    temp += pre_s[i + FLTBUF - fsize - j]		* alphaFir[j];	}	s[FLTBUF + i] = temp;    }    for (i = 0; i < fsize; i++)    {	temp = s[FLTBUF+i];		for(j = ACR - 1; j > 0; j--)	{	    temp -= alphaQ[j] * stateAq[j];	    stateAq[j] = stateAq[j-1];	}	stateAq[1] = temp;	s[FLTBUF + i] = temp;    }    free(s);}static float Power(float *vec, int size){    int		i;    float	nrm;        nrm = 0.0;    for(i = 0; i < size; i++)    {	nrm += vec[i] * vec[i];    }    return(nrm);}static float Norm(float *vec, int size){    return((float) sqrt((double) Power(vec, size)));}static void IpLsp2Lpc2(float	qLsp[10],float	(*alphaip)[11]){    int		i, j;    float	ipLsp[2][P + 1];        ipLsp[0][0] = ipLsp[1][0] = 0.0;    for(i = 0; i < P; i++)    {	ipLsp[0][i + 1] = qLsp[i];	ipLsp[1][i + 1] = qLsp[i];    }        IPC_lsp_lpc(ipLsp[0], alphaip[0]);    IPC_lsp_lpc(ipLsp[1], alphaip[1]);        for(j = 0; j < 2; j++)    {	alphaip[j][0] = 1.0;	for(i = 1; i < P + 1; i++)	{	    alphaip[j][i] = -alphaip[j][i];	}    }    return;}    static void IpLsp2Lpc4(float	qLsp[10],float	(*alphaip)[11]){    int		i, j;    float	ipLsp[4][P + 1];        ipLsp[0][0] = ipLsp[1][0] = 0.0;    for(i = 0; i < P; i++)    {	ipLsp[0][i + 1] = qLsp[i];	ipLsp[1][i + 1] = qLsp[i];	ipLsp[2][i + 1] = qLsp[i];	ipLsp[3][i + 1] = qLsp[i];    }        IPC_lsp_lpc(ipLsp[0], alphaip[0]);    IPC_lsp_lpc(ipLsp[1], alphaip[1]);    IPC_lsp_lpc(ipLsp[2], alphaip[2]);    IPC_lsp_lpc(ipLsp[3], alphaip[3]);    for(j = 0; j < 4; j++)    {	alphaip[j][0] = 1.0;	for(i = 1; i < P + 1; i++)	{	    alphaip[j][i] = -alphaip[j][i];	}    }    return;}    static void ClearStates(float *stateAq, float *stateI, float *statePWF){    int		i;        for(i = 0; i < P + 1; i++)    {	stateAq[i] = 0.0;    }    for(i = 0; i < Nfir + 1; i++)    {	stateI[i] = 0.0;    }    for(i = 0; i < FLTBUF; i++)    {	statePWF[i] = 0.0;    }}#define		Nfir		11#define		FLTBUF		100#define		REFtypedef struct{    int		num;    float	val;}SelCb;static int CmpIp(const void *a, const void *b){    if((* (SelCb *) a).val < (* (SelCb *) b).val)    {	return(-1);    }    else if((* (SelCb *) a).val == (* (SelCb *) b).val)    {	return(0);    }    else    {	return(1);    }}static void VxcSynthesis(	/* appended by Y.Maeda on 98/08/06 */ float *qRes, float *qVec, float *qAlpha, int csflag ){    int i, j;    float temp;    static float w[ACR];    if (csflag != 0) 	for (i = 0; i < ACR; i++) w[i] = 0;    for (i = 0; i < FRM/2; i++)    {	temp = qRes[i];	for(j = ACR - 1; j > 0; j--)	{	    temp -= qAlpha[j] * w[j];	    w[j] = w[j-1];	}	w[1] = temp;	qVec[i] = temp;    }}				/* appended by Y.Maeda on 98/08/06 */#define N_PRE_SEL	16static void EncSGVQResBF(float	*inVec,float	(*cb0)[80],float	*g0,float	*qVec,float	*qRes,float	*alpha,float	*qAlpha,float	*alphaFir,int	*idS,int	*idG,float	*outVec,int	csflag,		/* appended by Y.Maeda on 98/08/06 */float	*stateAq,float	*stateI,float	*statePWF){    int		i, j;    float	ip, maxIp;    float	sq, minSq;        float	inVecW[FRM / 2], synCbS[FRM / 2], ref[FRM / 2];    float	ex[FRM / 2], rvsRef[FRM / 2], synRvsRef[FRM / 2];    float	synRef[FRM / 2];    float	tmp, pwr, nrmRef, pwrVec, gain;        SelCb	preSelCb[N_PRE_SEL];    SelCb	selCb;    float	blnd;

⌨️ 快捷键说明

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