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

📄 ps_ana.c

📁 speech signal process tools
💻 C
📖 第 1 页 / 共 2 页
字号:
      break;    case 'e':      par->preemp = atof(optarg);      pflag++;      break;    case 'S':      if( iflag){	fprintf(stderr,"Error: -S should not be used with -i\n");	exit(0);      }      stepsams = atoi(optarg);      break;    case 'i':      if( stepsams > 0 ) {	fprintf(stderr,"Error: -i should not be used with -S");	exit(0);      }      step = atof(optarg);      iflag++;       break;    case 'z':      parcorflag = 1;      break;    case 'x':      debug_level = atoi(optarg);      break;    }  }  if((ac-optind) !=3){    SYNTAX;    exit(1);  }  (void) read_params(param_file, SC_NOCOMMON, (char *)NULL);  if(stepsams < 0 && !iflag && symtype("frame_step") != ST_UNDEF)    step = getsym_d("frame_step");  if(!oflag && symtype("order") != ST_UNDEF)    par->order = getsym_i("order");  if(!cflag && symtype("spec_rep") != ST_UNDEF){    sym = getsym_s("spec_rep");    par->returned = lin_search(spec_reps, sym);    spsassert(par->returned > -1, "spec_type not recognized");  }  if(!mflag && symtype("spec_method") != ST_UNDEF){    sym = getsym_s("spec_method");    par->method = lin_search(ana_methods, sym);    spsassert(par->method > -1, "analysis method not recognized");  }  if(!wflag && symtype("window") != ST_UNDEF){    sym = getsym_s("window");    par->wtype = win_type_from_name(sym);    spsassert(par->wtype != WT_NONE, "window type not recognized");  }  if(!pflag && symtype("preemphasis") != ST_UNDEF)    par->preemp = getsym_d("preemphasis");  if( symtype("per_step") != ST_UNDEF)    par->per_step = getsym_d("per_step");  if( symtype("per_wsize") != ST_UNDEF)    par->per_wsize = getsym_d("per_wsize");  if( symtype("ps_wsize") != ST_UNDEF)    par->ps_wsize = getsym_d("ps_wsize");  if( symtype("stability") != ST_UNDEF)    par->stab = getsym_d("stability");  if( symtype("phase") != ST_UNDEF)    par->phase = getsym_d("phase");  /* read input file */  ifname = eopen(av[0], av[optind], "r", FT_FEA, FEA_SD, &ihd, &ifile);  get_range( &s_rec, &e_rec, range, rflag, sflag, ihd );  if(debug_level)     fprintf(stderr,"Input sample range: %d - %d\n", s_rec, e_rec);  total_samps = e_rec - s_rec + 1;  inrec = n_rec(&ifile, &ihd);  if ( s_rec + total_samps -1 > inrec)     total_samps = inrec - s_rec + 1;  istart_time = *get_genhd_d("start_time", ihd);  ifreq = *get_genhd_d("record_freq", ihd);  band = ifreq / 2;  isd_rec = allo_feasd_recs( ihd, FLOAT, total_samps, NULL, NO);  idata = (float *) isd_rec->data;  (void) fea_skiprec ( ifile , s_rec - 1,  ihd);  get_feasd_recs( isd_rec, (long) 0L, total_samps, ihd, ifile);  ntime = istart_time + (s_rec-1)/ifreq;  if( stepsams > 0) step = stepsams / ifreq;  /* read pulse file, should allow reading label file in case of   hand-labelled pulses */  pfname = av[optind+1];  pfname = eopen("ps_ana", pfname, "r", FT_FEA, FEA_SD, &phd, &pfile);  pstart_time = *get_genhd_d("start_time", phd);  if( ifreq != *get_genhd_d("record_freq", phd)){    fprintf(stderr,"Error: input speech and pulse files have different frequencies\n");    exit(0);  }  s_prec = 1;  if( pstart_time <= ntime ){    s_prec = (int)(ifreq * ( ntime - pstart_time )) + 1;    pstart_time = ntime;  }  e_prec = s_prec + total_samps - 1;  pnrec = n_rec(&pfile, &phd);  if( e_prec > pnrec) e_prec = pnrec;       psd_rec = allo_feasd_recs( phd, FLOAT, e_prec-s_prec+1, NULL, NO);  (void) fea_skiprec( pfile, s_prec-1, phd);  get_feasd_recs( psd_rec, (long) 0L, e_prec-s_prec+1, phd, pfile);  vl = ptime_from_file( pstart_time, ifreq, e_prec-s_prec+1, psd_rec );    if(!vl) {    vl = (Vlist*)malloc(sizeof(Vlist));    vl->start = ntime;    vl->end = ntime + total_samps / ifreq;    vl->next = NULL;  }  if(debug_level){    for(v=vl; v; v=v->next)      fprintf(stderr,"start:%f end%f\n",v->start,v->end);  }    if(!(pb = analyze(idata, total_samps, ntime, ifreq, vl, par)))    ERROR_EXIT("Problem in analyze()")  /* prepare out_file */  ofname = eopen(av[0], av[optind+2], "w", NONE, NONE, &ohd, &ofile);  ohd = new_header(FT_FEA);  (void) strcpy (ohd->common.prog, ProgName);  (void) strcpy (ohd->common.vers, Version);  (void) strcpy (ohd->common.progdate, Date);  ohd->common.tag = NO;  add_source_file(ohd,ifname,ihd);  add_source_file(ohd,pfname,phd);  add_comment(ohd,get_cmd_line(ac,av));    add_fea_fld("spec_param", par->order, 1, NULL, DOUBLE, NULL, ohd);  ofea_rec = allo_fea_rec(ohd);  pdata = (double *) get_fea_ptr(ofea_rec,"spec_param", ohd);    noframes = 1 + pb->dur/step;  ofreq = 1.0/step;  add_genhd_d("record_freq", &ofreq, 1, ohd);  add_genhd_d("start_time", &pb->start_time, 1, ohd);  add_genhd_d("bandwidth", &band, 1 , ohd);  add_genhd_e("spec_rep", &par->returned, 1, spec_reps, ohd);  add_genhd_e("spec_method", &par->method, 1, ana_methods, ohd);  add_genhd_e("window", &par->wtype, 1, window_types, ohd);  add_genhd_d("preemphasis", &par->preemp, 1, ohd);  add_genhd_d("per_step", &par->per_step, 1, ohd);  add_genhd_d("per_wsize", &par->per_wsize, 1, ohd);  add_genhd_d("ps_wsize", &par->ps_wsize, 1, ohd);  add_genhd_d("stability", &par->stab, 1, ohd);  add_genhd_d("phase", &par->phase, 1, ohd);  write_header(ohd, ofile);  /* prepare out_f0file */  if(ffname){    ffname = eopen(av[0], ffname, "w", NONE, NONE, &fhd, &ffile);    fhd = new_header(FT_FEA);    (void) strcpy (fhd->common.prog, ProgName);    (void) strcpy (fhd->common.vers, Version);    (void) strcpy (fhd->common.progdate, Date);    fhd->common.tag = NO;    add_source_file(fhd,ifname,ihd);    add_source_file(fhd,pfname,phd);    add_comment(fhd,get_cmd_line(ac,av));        add_fea_fld("F0", 1, 0, NULL, DOUBLE, NULL, fhd);    add_fea_fld("prob_voice", 1,0, NULL, DOUBLE, NULL, fhd);    add_fea_fld("rms", 1, 0, NULL, DOUBLE, NULL, fhd);    ffea_rec = allo_fea_rec(fhd);        f0data = (double *) get_fea_ptr(ffea_rec,"F0", fhd);    probdata = (double *) get_fea_ptr(ffea_rec,"prob_voice", fhd);    rmsdata = (double *) get_fea_ptr(ffea_rec,"rms", fhd);        add_genhd_d("record_freq", &ofreq, 1, fhd);    add_genhd_d("start_time", &pb->start_time, 1, fhd);    add_genhd_e("spec_rep", &par->returned, 1, spec_reps, fhd);    add_genhd_e("spec_method", &par->method, 1, ana_methods, fhd);    add_genhd_e("window", &par->wtype, 1, window_types, fhd);    add_genhd_d("preemphasis", &par->preemp, 1, fhd);    add_genhd_d("per_step", &par->per_step, 1, fhd);    add_genhd_d("per_wsize", &par->per_wsize, 1, fhd);    add_genhd_d("ps_wsize", &par->ps_wsize, 1, fhd);    add_genhd_d("stability", &par->stab, 1, fhd);    add_genhd_d("phase", &par->phase, 1, fhd);        write_header(fhd, ffile);  }      if(debug_level) {    fprintf(stderr,"#\n");    for(fp = pb->head; fp; fp=fp->next)      fprintf(stderr,"%f\n",fp->time);  }  for(i=0, time = pb->start_time, fp= pb->head; i < noframes;      i++, time += step) {    while(fp->next && (fp->next->time < time)) fp = fp->next;    if(fp->next) {      if(fabs(time - fp->time) < fabs(time - fp->next->time))	fbp = fp;	else	  fbp = fp->next;    } else      fbp = fp;    for(j=0; j<par->order; j++)      pdata[j] = (parcorflag) ? fbp->coef[j] : -fbp->coef[j];    if(ffname){      *rmsdata = fbp->rms;      if( fbp->fr_type == VOICED) *probdata = 1.0;      else *probdata = 0.0;      if(fbp->period > 0.0) *f0data = 1.0 / fbp->period;      else *f0data = 0;      put_fea_rec( ffea_rec, fhd, ffile);    }    put_fea_rec( ofea_rec, ohd, ofile);  }}    Vlist *ptime_from_file( stime, pfreq, nrec, psd_rec )     double stime, pfreq;     long nrec;     struct feasd *psd_rec;{  Vlist *vl = NULL, *vlt, *vl0 = NULL;  double start;  float *pdata;  int i;  start = stime;  pdata = (float *) psd_rec->data;  for(i = 0; i < nrec; i++){    if( pdata[i] ){      vlt = (Vlist *) malloc(sizeof(Vlist));      vlt->start = start;      vlt->end = stime + ((double)i) / pfreq;      vlt->next = NULL;      if( vl ) vl->next = vlt;      vl = vlt;      if(!vl0) vl0 = vlt;      start = vlt->end;    }  }  if( !pdata[nrec - 1] ){    vlt = (Vlist *) malloc(sizeof(Vlist));    vlt->start = start;    vlt->end = stime + ((double)nrec) / pfreq;    vlt->next = NULL;    if( vl ) vl->next = vlt;    vl = vlt;    if(!vl0) vl0 = vlt;    start = vlt->end;  }  return(vl0);}void get_range(srec, erec, rng, pflag, Sflag, hd)/* * This function facilitates ESPS range processing.  It sets srec and erec * to their parameter/common values unless a range option has been used, in * which case it uses the range specification to set srec and erec.  If * there is no range option and if start and nan do not appear in the * parameter/common file, then srec and erec are set to 1 and LONG_MAX. * Get_range assumes that read_params has been called; If a command-line * range option (e.g., -r range) has been used, get_range should be called * with positive pflag and with rng equal to the range specification. */long *srec;                     /* starting record */long *erec;                     /* end record */char *rng;                      /* range string from range option */int pflag;                      /* flag for whether -r or -p used */int Sflag;                      /* flag for whether -S used */struct header *hd;              /* input file header */{    long common_nan;    *srec = 1;    *erec = LONG_MAX;    if (pflag)        lrange_switch (rng, srec, erec, 1);    else if (Sflag)        trange_switch (rng, hd, srec, erec);    else {        if(symtype("start") != ST_UNDEF) {            *srec = getsym_i("start");        }        if(symtype("nan") != ST_UNDEF) {            common_nan = getsym_i("nan");            if (common_nan != 0)                *erec = *srec + common_nan - 1;        }    }}/* * Get number of samples in a sampled-data file. * Replace input stream with temporary file if input is a pipe or * record size is not fixed. */#define BUFSIZE 1000static longn_rec(file, hd)    FILE **file;    struct header **hd;{    if ((*hd)->common.ndrec != -1)  /* Input is file with fixed record size. */	return (*hd)->common.ndrec; /* Get ndrec from header. */    else			    /* Input is pipe or has				     * variable record length. */    {	FILE	*tmpstrm = tmpfile();	struct header	*tmphdr; /* header for writing and reading temp file */	static double		buf[BUFSIZE];	int	num_read;	long	ndrec = 0;	/*	 * Get version of header without any Esignal header, mu-law	 * flag, etc.  Otherwise we risk getting garbage by writing the	 * temp file as an ESPS FEA file and reading it back as some	 * other format.	 */	tmphdr = copy_header(*hd);	write_header(tmphdr, tmpstrm);	do	{	    num_read = get_sd_recd(buf, BUFSIZE, *hd, *file);	    if (num_read != 0) put_sd_recd(buf, num_read, tmphdr, tmpstrm);	    ndrec += num_read;	} while (num_read == BUFSIZE);	Fclose(*file);	(void) rewind(tmpstrm);	*hd = read_header(tmpstrm);	*file = tmpstrm;	return ndrec;    }}

⌨️ 快捷键说明

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