www.pudn.com > MFCCandLPC.rar > main.cpp
// 语音信号LPC美尔倒谱系数的分析程序 /* 文件名:main.cpp */ #include#include #include #include #include #define PREEMPHASIS 1 /* pre-emphasis on(1)/off(0) */ #define ERROR -1 #define AD_SIZE 240000 /* max size of A/D data */ #define TRN_SIZE 512 /* file read size (bytes) */ #define W_SIZE 256 /* window size when 12khz, window=21.33msec */ #define MEL_ODR 10 /* ordea of mel-warped lpc cestrum */ #define SHIFT 96 /* window shift (points) when 12khz,frame=8mesc */ #define ORDER 14 /* order of autocorrelation etc. */ #define ALPHA 0.41 /* 0.31 at 8khz sampling */ /* 0.35 at 10khz sampling */ /* 0.41 at 12khz sampling */ /* 函数名称:main */ /* 函数功能:语音参数分析主程序 */ bool ham(float r[],short nad[],int iw); void correl(float rsam[],float roor[],int iw,int ip); void corref(int ip,float cor[],float alf[],float ref[],float *resid); void alfcep(int ip,float alf[],float cep[],int n); void cepmel(float *cep,float *mel); static int argc; static char *argv[5]; void main() { static short ad[AD_SIZE+W_SIZE], num_frame; static short ead[AD_SIZE+W_SIZE]; float rad[W_SIZE]; float cor[ORDER+1]; float ref[ORDER+1]; float alf[ORDER+1]; float cep[ORDER+1]; float mel[ORDER+1]; float resid; int fp, fp_a, fp_l; int i, j, n, nn; FILE *fp_c, *fopen(); char f_a[256], f_l[256], f_p[256], f_c[256]; /* 命令行检查 */ if (argc!=3) { printf("Usage : %s \n",argv[0]); exit(1); } f_a[0]=f_l[0]=f_p[0]='\0'; strcpy(f_c,argv[2]); /* 文件打开 */ if (fp=fopen()==NULL) { printf("%s:cannot creat file \n",f_c); exit(1); } /* A/D 数据文件读取 */ nn=0; for(i=0;i %s[%d words] \n",argv[1],nn); if(i>AD_SIZE+W_SIZE/2-TRN_SIZE/2) { printf("%s:too long data file \n",argv[1]); exit(1); } for(i=nn+W_SIZE/2;i %s[%d frames] \n",f_c,num_frame); } /* 函数名称:ham 函数功能:计算加窗后的信号 输入参数:r---加汉明窗后的信号数据 nad---读入的信号数据 iw---数据窗的长度(8= 1024) { printf("ham err"); return(1); } for(i=0;i 0) { for(i=1;i<=ip;i++) { u=0.0; for(j=0;j ip) goto step4; if(i =0;--n) u0[n]=cep[n]+alpha*u0[n+1]; mel[0]=u0[0];//ORDER:为迭代次数 //计算mel[1] u1[ORDER+1]=0.0; for(n=ORDER;n>=0;--n) u1[n]=(1.0-alpha*alpha)*u0[n+1]+alpha*u1[n+1]; mel[1]=u1[0]; //计算mel[2] mel[3]-----mel[ORDER] for(k=2;k<=ORDER;++k) { for(n=0;n<=ORDER+1;++n) u0[n]=u1[n]; for(n=ORDER;n>=0;n--) u1[n]=u0[n+1]+alpha*(u1[n+1]-u0[n]); mel[k]=u1[0]; } }