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

📄 xf0_methods.c

📁 speech signal process tools
💻 C
📖 第 1 页 / 共 2 页
字号:
  static int  b_siz = 5;  struct   rect *rect;  List *l, *l2;  if(view && (sig = view->sig) && sig_type_hack(sig)) {    canvas = view->canvas;    pw = canvas_pixwin(canvas);	/* get the pixwin to write to *//*!*//* pw_ttext doesn't work right under OpenWindows 1.0.1; */     /* ignore plot spec, except for type, and use a little box */     /* instead of the plot char. */    if(*f0_plot_specs) {       strcpy(f0c,"*");       sscanf(f0_plot_specs,"%d%s%d%d",&type,f0c,&dx,&dy);     }     dx = 2; dy = -2;    rect = (struct rect*)xv_get(canvas, WIN_RECT);    if((f0chan = get_active_labeled_chan(view,"F0")) < 0) f0chan = 0;    if(((pvchan = get_labeled_chan(sig,"P(voice)")) < 0) &&       ((pvchan = get_labeled_chan(sig,"prob_voice")) < 0))      pvchan = 0;        /* Determine the number of waveform samples to plot */    if(view->start_time < (end = BUF_END_TIME(sig))) {      nsam = (end - view->start_time) * sig->freq;    } else {      return(FALSE);    }      /* get x-displacement per waveform sample */    incr = (PIX_PER_CM / *(view->x_scale))/sig->freq;    /*compute the number of  pixels in the x-direction */    npix = incr * nsam;    /* clip to size of canvas */    npix = (npix > (rect->r_width - *(view->x_offset))) ?           rect->r_width - *(view->x_offset) : npix;    nsam = .5 + (((double)npix)/incr);    /* clear window if data is NOT plotted as an overlay */    if(!(view->extra_type & VIEW_OVERLAY))      pw_write(pw,0,0,rect->r_width,rect->r_height,	     PIX_COLOR(BACKGROUND_COLOR)|PIX_SRC,NULL,0,0);    /* deternine starting sample in the waveform */    i = time_to_index(sig,view->start_time);    /* determine x offset due to initial sample time re view start */    fxoff = 0.5 + (PIX_PER_CM * (BUF_START_TIME(sig) -		 view->start_time + ((double)i)/sig->freq) / *(view->x_scale));#define PLOT_TYPE(the_type) { \  register the_type *q, *r, *p, **dpp, imax, imin, *pv; \  dpp = (the_type**)sig->data; \  if (!dpp) return FALSE; \  if(pvchan >= 0) pv = dpp[pvchan]; \  else \    pv = dpp[view->elements[f0chan]]; \  if (!pv) \    return FALSE; \  else \    pv += i; \  for(dim=0; dim < view->dims; dim++) { /* for each dimension... */ \    val = view->colors[dim]; \    scale = - PIX_PER_CM/view->y_scale[dim]; \    yoffs = .5 + (double)view->y_offset[dim]; \    if(dim == f0chan){ \      int washit; \      yoffs += (type? dy : 0); \      if(incr < 1.0){	/* must do max-min computation? */ \	p = dpp[view->elements[dim]]; \        if (!p) return FALSE; \	else    p += i; \	for(k = 0, j = *(view->x_offset)+(type? -dx : 0), sump=0.0; \	    k < npix; \	    j++, k++, sump -= 1.0) { \	      for(washit=0, imax = imin = *p; sump < 1.0; \		  sump += incr ) { \		    if((*pv++ > 0.5) && (*pv > 0.5)) { \		      washit = 1; \		      if(*++p > imax)imax = *p; \		      else \			if(*p < imin)imin = *p; \		    } else \		      p++; \		  } \	      if(washit) { \		if(type) { \		/* pw_ttext(pw,j,scoff(imax),			    PIX_SRC|PIX_COLOR(val),def_font,f0c); */\		pw_write(pw, j, scoff(imax), b_siz, b_siz, \			 PIX_SRC|PIX_COLOR(val), NULL, 0, 0); \		/* pw_ttext(pw,j,scoff(imin),			    PIX_SRC|PIX_COLOR(val),def_font,f0c); */\		pw_write(pw, j, scoff(imin), b_siz, b_siz, \			 PIX_SRC|PIX_COLOR(val), NULL, 0, 0); \		} else \		  { \		     long y1 = scoff(imin); \		     long y2 = scoff(imax); \                     if (y2 != y1) \		        pw_vector(pw, j, y2, j, y1, \				   PIX_COLOR(val)|PIX_SRC, val); \		     else \		        pw_vector(pw, j, y2, j+1, y1, \				   PIX_COLOR(val)|PIX_SRC, val); \	           } \	      } \	    } \      } else {		/* no need for max-min */ \	p = dpp[view->elements[dim]]; \	if (!p) return FALSE; \	else    p += i; \	for(k = *(view->x_offset) + (type? -dx : 0), \	    x = fxoff + k + incr, \	    r = p + 1,  q = p + nsam - 1; p < q; x += incr, p++, r++) { \	      j = x; \	      if(*pv++ > 0.5) { \		if(type) \		  /* pw_ttext(pw,k,scoff(*p),PIX_SRC|PIX_COLOR(val),def_font,f0c); */\		  pw_write(pw, k, scoff(*p), b_siz, b_siz, \			   PIX_SRC|PIX_COLOR(val), NULL, 0, 0); \		else \		  if(*pv > 0.5) \		    pw_vector(pw, k, scoff(*p), j, scoff(*r), \			      PIX_COLOR(val)|PIX_SRC, val); \	      } \	      k = j; \	    } \      } \    } else {		/* it is a "regular" channel */ \      if(incr < 1.0){	/* must do max-min computation? */ \	p = dpp[view->elements[dim]]; \	if (!p) return FALSE; \	else    p += i; \	for(k=0, j = *(view->x_offset), sump=0.0; \	    k < npix; \	    j++, k++, sump -= 1.0) { \	      for(imax = imin = *p; sump < 1.0; sump += incr ) { \		if(*++p > imax)imax = *p; \		else \		  if(*p < imin)imin = *p; \	      } \		  { \		     long y1 = scoff(imin); \		     long y2 = scoff(imax); \                     if (y2 != y1) \		        pw_vector(pw, j, y2, j, y1, \				   PIX_COLOR(val)|PIX_SRC, val); \		     else \		        pw_vector(pw, j, y2, j+1, y1, \				   PIX_COLOR(val)|PIX_SRC, val); \	           } \	    } \      } else {		/* no need for max-min */ \	p = dpp[view->elements[dim]]; \	if (!p) return FALSE; \	else    p += i; \	for(k = *(view->x_offset), x = fxoff + *(view->x_offset) + incr, \	    r = p + 1,  q = p + nsam - 1; p < q; x += incr) { \	      j = x; \	      pw_vector(pw, k, scoff(*p++), j, scoff(*r++), \			PIX_COLOR(val)|PIX_SRC, val); \	      k = j; \	    } \      } \    } \  } \}				/* end of #define PLOT_TYPE() */        switch(sig_type_hack(view->sig)) {    case P_CHARS:    case P_UCHARS:      PLOT_TYPE(char);      break;    case P_SHORTS:      PLOT_TYPE(short);      break;    case P_INTS:    case P_UINTS:      PLOT_TYPE(int);      break;    case P_FLOATS:      PLOT_TYPE(float);      break;    case P_DOUBLES:      PLOT_TYPE(double);      break;    default:      printf("Unknown data type in f0_plot_waves(%d)\n",	     sig_type_hack(view->sig));      return(FALSE);    }#undef PLOT_TYPE    if(l = view->sig->idents) {      int curi, i;            for(dim=0; dim < view->dims; dim++) { /* for each dimension... */	if(view->show_labels[dim]) {	  curi = view->elements[dim];	  for(i = 0, l2 = l; i < curi; i++)	    if(l2->next)	      l2 = l2->next;	  scale = - PIX_PER_CM/view->y_scale[dim];	  yoffs = .5 + (double)view->y_offset[dim];	  	  if(dim == f0chan)	    pw_text(pw, *(view->x_offset), scoff(view->plot_min[dim]),		    PIX_SRC|PIX_COLOR(CURSOR_COLOR), def_font, l2->str);	  else	    pw_text(pw, 0, scoff(view->plot_min[dim]),		    PIX_SRC|PIX_COLOR(TEXT_COLOR), def_font, l2->str);	}      }    }    return(TRUE);  }  return(FALSE);}/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/Reticle *prepare_f0_reticle(v)     View *v;{  Bound *b, *b2;  int width, f0chan, i;  double hz_per_pix, sec_per_pix, lospac, hispac, range, range10,  range5, range2;  int right_of_d;  char abform[20];  Reticle *ret;  Signal *s;  struct rect *rect;  if(v && v->canvas) {    rect = (struct rect*)xv_get(v->canvas, WIN_RECT);    if((f0chan = get_active_labeled_chan(v,"F0")) < 0) f0chan = 0;    if(!(ret = v->ret[f0chan])) {      /* Create a reticle (time/amplitude scales), if necessary. */      if(!(v->ret[f0chan] = ret = new_wave_reticle())) {	printf("Can't create a new reticle structure\n");	return(NULL);      }    }    if((s = v->sig)) {      ret->ordi.end = v->plot_max[f0chan];      ret->ordi.start = v->plot_min[f0chan];      ret->absc.start = v->start_time;      ret->absc.end = ET(v);      ret->color = RETICLE_COLOR;      ret->abs_label = NULL;      ret->ordinate.maj.style = EDGES|MAJOR ;      ret->ordinate.maj.inter = 100.0;      ret->ordinate.min1.style =  EDGES|MAJOR;      ret->ordinate.min1.inter = 50.0;      ret->ordinate.min2.style = EDGES ;      ret->ordinate.min2.inter =  10.0;      ret->ordinate.num_inter = 50.0;      /* Want at least 70 pixels between time numbering and no more than 140. */      /* Assume one pixel per time step. */      sec_per_pix = *(v->x_scale)/PIX_PER_CM;      lospac = 70.0*sec_per_pix;      hispac = 140.0*sec_per_pix;      range = pow(10.0, floor(log10(lospac)));      range10 = 10.0*range;      range5 = 5.0*range;      range2 = 2.0*range;      if(hispac >= range10)	ret->abscissa.maj.inter = range10;      else	if((lospac <= range5) && (hispac >= range5))	  ret->abscissa.maj.inter = range5;	else	  ret->abscissa.maj.inter = range2;      if( ret->abscissa.maj.inter <= 1.0)	right_of_d = 1 + (int)(0.5 - log10( ret->abscissa.maj.inter ));      else	right_of_d = 0;      sprintf(abform,"%s%df","%8.",right_of_d);      reticle_set_absc_precision(ret, abform);      ret->abscissa.maj.style =  EDGES;      ret->abscissa.maj.length = ret->ordinate.maj.inter/10.0;      ret->abscissa.min1.style =  EDGES;      ret->abscissa.min1.length =  ret->ordinate.maj.inter/20.0;      ret->abscissa.min1.inter = ret->abscissa.maj.inter/2.0;      ret->abscissa.min2.style = EDGES;      ret->abscissa.min2.length =  ret->ordinate.maj.inter/40.0;      ret->abscissa.min2.inter = ret->abscissa.maj.inter/10.0;      ret->abscissa.num_inter = ret->abscissa.maj.inter;      ret->ordinate.maj.length =  ret->abscissa.maj.inter/3.0;      ret->ordinate.min1.length = ret->abscissa.maj.inter/5.0;      ret->ordinate.min2.length = ret->abscissa.maj.inter/10.0;      ret->abscissa.num_loc = NUM_LB;        /* get margins required by reticle, numerals, etc. */      b = reticle_get_margins(ret);      /* ret->bounds.top and ret->bounds.bottom are set up in	 scale_f0_for_canvas() */      ret->bounds.right = rect->r_width; /* this is cheating (bit of a kluge) */      ret->bounds.left = b->left;      /* Align the left margins of all SIG_F0 elements with F0. */      *(v->x_offset) = b->left;      return(ret);    }  }  return(NULL);}

⌨️ 快捷键说明

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