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

📄 rasta.c

📁 ears-0.32, linux下有用的语音信号处理工具包
💻 C
📖 第 1 页 / 共 2 页
字号:
  float step_barks;  char *funcname;  funcname = "init_param";  pptr->winpts = (int)((double)pptr->sampfreq * (double)pptr->winsize                       / 1000.);  pptr->steppts = (int)((double)pptr->sampfreq * (double)pptr->stepsize                        / 1000.);  overlap = pptr->winpts - pptr->steppts;  if(pptr->online == TRUE)    {      pptr->nframes = 1;        /* Always looking at one frame,                                   in infinite loop. */    }  else    {      usable_length = sptr->length - overlap;      pptr->nframes = (double)usable_length / (double)pptr->steppts;    }  /* Here is some magical stuff to get the Nyquist frequency in barks */  tmp = pptr->sampfreq / 1200.;  pptr->nyqbar = 6. * log(((double)pptr->sampfreq /1200.)                           + sqrt(tmp * tmp + 1.));  /* compute number of filters for at most 1 Bark spacing;     This includes the constant 1 since we have a filter at d.c and     a filter at the Nyquist (used only for dft purposes) */  if(pptr->nfilts == NOT_SET)    {      pptr->nfilts = ceil(pptr->nyqbar) + 1;    }  if((pptr->nfilts < MINFILTS) || (pptr->nfilts > MAXFILTS))    {      fprintf(stderr,"Nfilts value of %d not OK\n",              pptr->nfilts);      exit(-1);    }  /* compute filter step in Barks */  step_barks = pptr->nyqbar / (float)(pptr->nfilts - 1);  /* for a given step, must ignore the first and last few filters */  pptr->first_good = (int)(1.0 / step_barks + 0.5);  if(pptr->nout == NOT_SET)    {      pptr->nout = pptr->order + 1;    }  if((pptr->nout < MIN_NFEATS) || (pptr->nout > MAX_NFEATS))    {      fprintf(stderr,"Feature vector length of %d not OK\n",              pptr->nout);      exit(-1);    }}/* Check numerical parameters to see if in a reasonable range, and the logical   sense of combinations of flags. For the numerical comparisons,   see the constant definitions in rasta.h . */voidcheck_args( struct param *pptr ){          char *funcname;  funcname = "check_args";#ifndef IO_ESPS  if(pptr->espsin == TRUE || pptr->espsout == TRUE)    {      fprintf(stderr,"Compiled without IO_ESPS flag (no ESPS licence) -> no ESPS file I/O available");      fprintf(stderr,"\n");      exit(-1);    }#endif#ifndef IO_MAT  if(pptr->matin == TRUE || pptr->matout == TRUE)    {      fprintf(stderr,"Compiled without IO_MAT flag (no MATLAB licence) -> no MAT file I/O available");      fprintf(stderr,"\n");      exit(-1);    }#endif  if((pptr->winsize < MIN_WINSIZE ) || (pptr->winsize > MAX_WINSIZE ))    {      fprintf(stderr,"Window size of %f msec not OK\n",              pptr->winsize);      exit(-1);    }  if((pptr->stepsize < MIN_STEPSIZE )||(pptr->stepsize > MAX_STEPSIZE ))    {      fprintf(stderr,"Step size of %f msec not OK\n",              pptr->stepsize);      exit(-1);    }  if((pptr->sampfreq < MIN_SAMPFREQ ) || (pptr->sampfreq > MAX_SAMPFREQ ))    {      fprintf(stderr,"Sampling frequency of %d not OK\n",              pptr->sampfreq);      exit(-1);    }  if((pptr->polepos < MIN_POLEPOS ) || (pptr->polepos >= MAX_POLEPOS ))    {      fprintf(stderr,"Pole position of %f not OK\n",              pptr->polepos);      exit(-1);    }  if((pptr->order < MIN_ORDER ) || (pptr->order > MAX_ORDER ))    {      fprintf(stderr,"LPC model order of %d not OK\n",              pptr->order);      exit(-1);    }  if((pptr->lift < MIN_LIFT ) || (pptr->lift > MAX_LIFT ))    {      fprintf(stderr,"Cepstral exponent of %f not OK\n",              pptr->lift);      exit(-1);    }  if((pptr->winco < MIN_WINCO ) || (pptr->winco > MAX_WINCO ))    {      fprintf(stderr,"Window coefficient of %f not OK\n",              pptr->winco);      exit(-1);    }  if((pptr->rfrac < MIN_RFRAC ) || (pptr->rfrac > MAX_RFRAC ))    {      fprintf(stderr,"Rasta fraction of %f not OK\n",              pptr->rfrac);      exit(-1);    }  if((pptr->jah < MIN_JAH ) || (pptr->jah > MAX_JAH ))    {      fprintf(stderr,"Jah value of %e not OK\n",              pptr->jah);      exit(-1);    }  if((pptr->lrasta ==FALSE) && (pptr->jrasta == FALSE))    {      if(pptr->rfrac != 1.0)        {          fprintf(stderr,"Can't mix if no rasta flag\n");          exit(-1);        }    }  if((pptr->lrasta == TRUE) && (pptr->jrasta == TRUE))    {      fprintf(stderr,"Can't do log rasta and jah rasta at the same time\n");      exit(-1);    }  if(pptr->online == TRUE)    {      if(pptr->espsin==TRUE)        {          fprintf(stderr,"can't run on-line on esps input\n");          exit(-1);        }      if(pptr->matin==TRUE)        {          fprintf(stderr,"can't run on-line on MAT input\n");          exit(-1);        }      if(pptr->ascin==TRUE)        {          fprintf(stderr,"can't run on-line on ascii input\n");          exit(-1);        }      if(strcmp (pptr->infname, "-") != 0)        {          fprintf(stderr,"on-line mode uses stdin only\n");          exit(-1);        }    }  if((pptr->espsin == TRUE && pptr->matin == TRUE) ||     (pptr->espsin == TRUE && pptr->ascin == TRUE) ||     (pptr->ascin == TRUE && pptr->matin == TRUE))    {      fprintf(stderr,"can't read different input formats simultaneously\n");      exit(-1);    }  if((pptr->espsout == TRUE && pptr->matout == TRUE) ||     (pptr->espsout == TRUE && pptr->ascout == TRUE) ||     (pptr->ascout == TRUE && pptr->matout == TRUE))    {      fprintf(stderr,"can't write different output formats simultaneously\n");      exit(-1);    }  if((pptr->swapbytes == TRUE) && (sizeof(short) != 2) &&     (sizeof(short) != 4))    {      fprintf(stderr,"Shorts are %ld bytes.\n", sizeof(short));      fprintf(stderr,"Byte-swapping function in rasta.h will\n");      fprintf(stderr,"not work!\n");      exit(-1);    }}/* Print out ascii for float vector with specified width (n columns) */void print_vec(const struct param *pptr, FILE *fp, struct fvec *fptr, int width){  int i;  char *funcname;  int lastfilt;  funcname = "print_vec";  if ((pptr->crbout == FALSE) && (pptr->comcrbout == FALSE))    {              for(i=0; i<fptr->length; i++)        {          fprintf(fp, "%g ", fptr->values[i]);          if((i+1)%width == 0)            {              fprintf(fp, "\n");            }        }    }  else    {      lastfilt = pptr->nfilts - pptr->first_good;      for (i= pptr->first_good; i<lastfilt; i++)        {          fprintf(fp, "%g ", fptr->values[i]);        }      fprintf(fp, "\n");    }}voiddo_rasta (struct fvec *s, struct fvec **p, int* nframes, int rate, int rasta_f){	/* function prototypes for local calls */	void init_param(struct fvec *, struct param *);	struct fvec *get_data(struct param *), 	    *rastaplp(struct fhistory *, struct param *, struct fvec *),	    *fill_frame(struct fvec *, struct param *, int),	    *get_online_bindata(struct fhistory *, struct param * );	/*  	Variables and data structures	*/	struct param runparam;	struct fhistory history;	struct fvec *speech, *frame;	int nframe;	char *funcname;	speech = s;	param_init(&runparam);	runparam.sampfreq = rate;	runparam.lrasta = rasta_f? TRUE : FALSE;	init_param(speech, &runparam); /* Compute necessary parameters 					  for analysis */		check_args( &runparam ); /* Exits if params out of range *//* 	main analysis loop */	*nframes = runparam.nframes;	for(nframe = 0; nframe < runparam.nframes; )	{		frame = fill_frame( speech, &runparam, nframe);		nframe++;		if (nframe>=1000) { fprintf(stderr,"Too much frames (>1000)!"); exit(-1); }		p[nframe-1] = alloc_fvec (runparam.nout);		fvec_copy("do_rasta",rastaplp(&history,&runparam,frame),p[nframe-1]);	}	        return;}

⌨️ 快捷键说明

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