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

📄 xspectrum.c

📁 speech signal process tools
💻 C
📖 第 1 页 / 共 5 页
字号:
  char mess[MES_BUF_SIZE];  sprintf(mess,"%s cursor frequency %f",name,freq);  mess_write(mess);}/*********************************************************************/static voidsetcursors(ob, curs_freq)    Objects *ob;    double  curs_freq;		/* cursor frequency */{    int	    x;    double  m;    int	    i;    if (!ob) return;    send_curs_freq(ob->name,curs_freq);     if(hcurs_on && curs_freq != 0.0) {      m = ((curs_freq > 0.0) ? ob->xhigh : ob->xlow) / curs_freq;      ob->x_curs_num =	(m >= X_CURS_MAX) ? X_CURS_MAX : (m <= 1) ? 1 : (int) m;    } else	ob->x_curs_num = 1;    for (i = 0; i < ob->x_curs_num; i++)	ob->cursorx[i] = (i+1)*curs_freq;    x = frequency_to_x(ob, curs_freq);    for (i = 0; i < TRACE_MAX && ob->trace[i] && ob->trace[i]->data; i++)	ob->cursory[i] = ob->trace[i]->data[x_to_index(ob, x, i)] -	  ((scale_type == SCALE_DB)? reference_level : 0.0);    ob->y_curs_num = i;}/*********************************************************************/static voidsave_as_ref(ob)    Objects *ob;{    Trace   *cur_trace, *ref_trace;    int	    n, t, x;    double  *dp, *dq;    if (!(cur_trace = ob->trace[0]) || !cur_trace->data) return;    n = cur_trace->n;    t = ob->trace_num;    ref_trace =	ob->trace[t] = new_trace(ob->trace[t], n, !!cur_trace->freqs);    if (ref_trace);    {	ob->trace_num = (t < TRACE_MAX - 1) ? t + 1 : 1;	ref_trace->band_low = cur_trace->band_low;	ref_trace->band = cur_trace->band;	ref_trace->scale_type = cur_trace->scale_type;	if ((dp = cur_trace->data) && (dq = ref_trace->data))	    for (x = 0; x < n; x++)		*dq++ = *dp++;	if ((dp = cur_trace->freqs) && (dq = ref_trace->freqs))	    for (x = 0; x < n; x++)		*dq++ = *dp++;    }}/*********************************************************************/static voidset_ref_level(ob, x)    Objects *ob;     int x;{    Trace   *cur_trace;    if (!(cur_trace = ob->trace[0]) || !cur_trace->data) return;    reference_level = cur_trace->data[x_to_index(ob, x, 0)];    if(debug_level)      fprintf(stderr, "Setting reference level to %f dB\n", reference_level);}/*********************************************************************/plot_v_marker(ob, x)     Objects *ob;     int x;{  Xv_Window	pw;  Rect	*rec;  if (ob && ob->view &&      (pw = canvas_paint_window(ob->view))) {    rec = (Rect *) xv_get(pw, WIN_RECT);    pw_vector(pw, x, 0, x, rec->r_height - 1,	      PIX_COLOR(MARKER_COLOR)|(PIX_SRC^PIX_DST), MARKER_COLOR);  }}  /*********************************************************************/move_v_markers(o,event)     Objects *o;     Event *event;{  int x = event_x(event), y = event_y(event);  double freq = x_to_frequency(o,x);  if(event_is_down(event)) {	/* move the left marker */    plot_v_marker(o, frequency_to_x(o, o->l_marker));    o->l_marker = freq;    plot_v_marker(o, x);  } else {    plot_v_marker(o, frequency_to_x(o, o->r_marker));    if(freq < o->l_marker) {      o->r_marker = o->l_marker;      o->l_marker = freq;    } else      o->r_marker = freq;    if(f_autozoom)      redo_display(o);    else      plot_v_marker(o, x);  }}/*********************************************************************/plot_h_marker(ob, y)     Objects *ob;     int y;{  Xv_Window	pw;  Rect	*rec;  if (ob && ob->view &&      (pw = canvas_paint_window(ob->view))) {    rec = (Rect *) xv_get(pw, WIN_RECT);    pw_vector(pw, ob->x_off, y, rec->r_width - 1, y,	      PIX_COLOR(MARKER_COLOR)|(PIX_SRC^PIX_DST), MARKER_COLOR);  }}  /*********************************************************************/move_h_markers(o,event)     Objects *o;     Event *event;{  int x = event_x(event), y = event_y(event);  double ampl = y_to_amplitude(o,y);  if(event_is_down(event)) {	/* move the top marker */    plot_h_marker(o, amplitude_to_y(o,o->t_marker));    o->t_marker = ampl;    plot_h_marker(o, y);  } else {    plot_h_marker(o, amplitude_to_y(o,o->b_marker));    if(ampl > o->t_marker) {      o->b_marker = o->t_marker;      o->t_marker = ampl;    } else      o->b_marker = ampl;    if(a_autozoom)      redo_display(o);    else      plot_h_marker(o, y);  }}/*********************************************************************/plot_markers(ob)     Objects *ob;{  if(ob->l_marker != ob->r_marker) {    plot_v_marker(ob, frequency_to_x(ob, ob->l_marker));    plot_v_marker(ob, frequency_to_x(ob, ob->r_marker));  }  if(ob->t_marker != ob->b_marker) {    plot_h_marker(ob, amplitude_to_y(ob, ob->t_marker));    plot_h_marker(ob, amplitude_to_y(ob, ob->b_marker));  }}/*********************************************************************/move_markers(ob, event)     Objects *ob;     Event *event;{  if(event_shift_is_down(event))    move_h_markers(ob,event);  else    move_v_markers(ob,event);}/*********************************************************************//* This is the event handler, which deals with mouse   interactions in windows created by meth_make_object(). */static void doit(pw, event, arg)    Xv_Window	pw;    Event	*event;    caddr_t	arg;{    Objects	*ob;    int		x, y;    Canvas	canvas = xv_get(pw, CANVAS_PAINT_CANVAS_WINDOW);    Menu	me;    Menu_item   inv_item;/* This is how "user" data associated with a window may be retrieved: */  if(!(canvas && (ob = (Objects *) xv_get(canvas, WIN_CLIENT_DATA))))    return;    x = event_x(event);		/* mouse coordinates within the window */  y = event_y(event);  switch(event_id(event)){	/* identify nature of interaction: */  case MS_LEFT:	    /* copy current spectrum to reference spectrum array */    move_markers(ob,event);    break;  case MS_MIDDLE:   /* currently, just a means of gettting out of wind w/o		       cursor movement */    break;  case MS_RIGHT:    /* bring up menu */    if (event_is_up(event)) return;	/* Ignore button release. */    me = (Menu) xv_get(canvas, WIN_MENU);    /* inverse filtering is not an option for non-LPC methods */    inv_item = (Menu_item) xv_find(me, MENUITEM,				  MENU_VALUE, e_inv_filt, 0);    if (function != esps_compute_spect)       xv_set(inv_item, MENU_INACTIVE, TRUE, 0);    else       xv_set(inv_item, MENU_INACTIVE, FALSE, 0);    menu_show(me, canvas, event, 0);    break;  case LOC_MOVE:		/* "locator move" with or without button press */  case LOC_DRAG:    if(event_middle_is_down(event)) /* to escape the window and leave cursor */      break;/*IFF hcurs_on: Translate the current x position into a frequency.  Thisfrequency is then taken as that of the current_harmonic and is dividedaccordingly to get the fundamental.  This frequency then becomes theargument of the setcursors() call.  If the current harmonic is morethan the fundamental away from the hightest plottable frequency, andit is also less than the max harmonic number plottable, increase the currentharmonic by one.  If the harmonic is bumped, the cursor location isforced to the corresponding location.*/    if(XEventsQueued(xv_get(canvas, XV_DISPLAY),QueuedAlready) <= 0) {      plotcursors(ob);		/* XOR off old cursors */      /* if there's data to interact with... */      if (ob->trace[0] && ob->trace[0]->data && (ob->trace[0]->n > 0)) {	if(hcurs_on) {	  double high_h = x_to_frequency(ob, x);	  double fund = high_h/ob->current_harmonic;	  /* To avoid instability, only process the most recent event. */	  setcursors(ob, fund);	  if((ob->current_harmonic < X_CURS_MAX) &&	     (ob->xhigh - high_h) > (2.0*fund)) {	    int newx = frequency_to_x(ob, high_h + fund);	    xv_set(ob->view, WIN_MOUSE_XY, newx, y, 0);	    ob->current_harmonic++;	  } else	    if((ob->current_harmonic > 1) &&	       (ob->xhigh - high_h) < (0.5*fund)) {	      int newx = frequency_to_x(ob, high_h - fund);	      xv_set(ob->view, WIN_MOUSE_XY, newx, y, 0);	      ob->current_harmonic--;	    }	} else			/* no harmonic cursors */	  setcursors(ob,x_to_frequency(ob,x));      } else			/* no data to display */	ob->x_curs_num = ob->y_curs_num = 0;          plotcursors(ob);		/* draw new cursor positions */      printcursors(ob);		/* print frequency and amplitude */    }    break;  default:    break;  }  return;}/*********************************************************************//* Plot the spectrum (and reference spectrum, if any) *//* pointed to by ob->data; (ob->n points) */plot_data(ob)    Objects	*ob;{  if(ob && ob->view) {    Xv_Window	pw;    Rect	*rec;    int		xoff, yoff;    double	xscale, yscale, width, height;    Reticle	*r;    int		i;    if (debug_level)       fprintf(stderr, "entered plot_data()\n");     if (!ob) return FALSE;    pw = canvas_paint_window(ob->view);    if((r = ob->ret)) {      height = r->bounds.bottom - r->bounds.top;      width = r->bounds.right - r->bounds.left;      xoff = r->bounds.left + 0.5; /* 0.5 for rounding */      yoff = r->bounds.bottom + 0.5; /* 0.5 for rounding */    } else {      rec = (Rect *) xv_get(pw, WIN_RECT);      height = rec->r_height - 1 - ob->y_off;      width = rec->r_width - 1 - ob->x_off;      xoff = ob->x_off + 0.5;	/* 0.5 for rounding */      yoff = rec->r_height - 1 - ob->y_off + 0.5; /* 0.5 for rounding */    }    xscale = width / (ob->xhigh - ob->xlow);    yscale = -height/(ob->yhigh - ob->ylow);    if (!plot_trace(pw, xoff, yoff, xscale, yscale, ob->xlow, ob->xhigh,  ob->ylow,		    ob->trace[0], trace_color(0)))      return FALSE;    for (i = 1; i < TRACE_MAX && ob->trace[i]; i++)      (void) plot_trace(pw, xoff, yoff, xscale, yscale, ob->xlow, ob->xhigh, ob->ylow,			ob->trace[i], trace_color(i));    return TRUE;  }  return(FALSE);}/*********************************************************************/char *meth_print_data(ob, str)     Objects *ob;     char *str;{  static char output[NAMELEN];  static Selector s1 = {"output", "#qstr", output, NULL};  FILE *fp = NULL;  struct header *hdr;  int i;  double freq;  *output = 0;  get_args(str, &s1);  if(*output && ob->view && ob->trace[0] && (ob->trace[0]->n > 1)) {    if((fp = fopen(output, "w"))) {      if(ob->sig && ob->sig->name) {	fprintf(fp,"signal %s\n",ob->sig->name);	fprintf(fp,"time %f\n",ob->time);	if((ob->sig->type & SPECIAL_SIGNALS) != SIG_SPECTROGRAM)	  freq = ob->sig->freq;	else	  if((hdr = ob->sig->header->esps_hdr))	    freq = get_genhd_val("src_sf",hdr,				 get_genhd_val("sf",hdr,(double)-1.0));	if(freq > 0.0)	  fprintf(fp,"src_sf %f\n",freq);	fprintf(fp,"num_freqs %d\n", ob->trace[0]->n);	output_variables_to_file(fp, &g1);	if(ob->trace[0]->freqs)	  for(i=0 ; i < ob->trace[0]->n; i++)	    fprintf(fp,"%f	%f\n",		    ob->trace[0]->freqs[i],ob->trace[0]->data[i]);	else {	  double df = (ob->trace[0]->band - ob->trace[0]->band_low) /			(ob->trace[0]->n - 1);	  for(i=0; i < ob->trace[0]->n; i++)	    fprintf(fp,"%f	%f\n",		    ob->trace[0]->band_low + (df * i),		    ob->trace[0]->data[i]);	}	Fclose(fp);	return(Ok);      } else {	sprintf(notice_msg, "Can't open %s for output in xspectrum.",		output);	show_notice(1, notice_msg);      }    }  }  return(Null);}#define scoff(x) ((int)(yoffs + ((double)(x - ydboff) * scale)))plot_a_trace(val, s_data, index, line_type, xoffset, scale, yoffs, incr, npix, nsam, pw, ymin)     Xv_Window	pw;     int val, index, npix, line_type, nsam;     double *s_data, xoffset, scale, yoffs, incr;{  register int i, j, k, y, y2;  register double *q, *r, *p, imin, sump, imax, x, ydboff = 0.0;;  if(scale_type == SCALE_DB) ydboff = reference_level;  switch(line_type) {  case 1:			/* standard solid line type */  default:    if(incr < 1.0){		/* must do max-min computation? */      for(k=0, j = xoffset, sump=0.0,	  p = (double *) s_data + index ;    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;	}	pw_vector(pw, j, scoff(imax), j, scoff(imin),		  PIX_COLOR(val)|PIX_SRC, val);      }    } else {			/* no need for max-min */      for(k = xoffset, x = xoffset + incr,	  p = (double *) s_data + index,	  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;      }    }    break;  case 2:			/* histogram-style */    if(incr < 1.0){		/* must do max-min computation? */      for(k=0, j = xoffset, sump=0.0,	  y = scoff(ymin),	  p = (double *) s_data + index ;    k < npix;	  j++, k++, sump -= 1.0) {	for(imax = *p; sump < 1.0; sump += incr )	  if(*++p > imax)imax = *p;	pw_vector(pw, j, scoff(imax), j, y,		  PIX_COLOR(val)|PIX_SRC, val);      }    } else {			/* no need for max-min */      for(k = xoffset, x =  xoffset + incr,	  y2 = scoff(ymin),	  p = (double *) s_data + index,

⌨️ 快捷键说明

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