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

📄 xspect.c

📁 speech signal process tools
💻 C
📖 第 1 页 / 共 5 页
字号:
      > SCREEN_HEIGHT)    {      next_y = 120;      next_x = 0;    }  xv_set (canvas, WIN_MENU, spect_menu,	  XV_KEY_DATA, menu_item_key,	  find_operator (spect_get_ops (), "play between marks"),	  0);  window_fit (frame);  notify_interpose_destroy_func (frame, kill_signal_view);  xv_set (frame, WIN_CLIENT_DATA, (caddr_t) canvas,	  0);  ss->views->canvas = canvas;  cmap_spect (canvas);  /*   * Set repaint and resize procs here instead of the original xv_create to   * guard against premature calls within xv_create.   */  xv_set (canvas, CANVAS_REPAINT_PROC, repaint,	  CANVAS_RESIZE_PROC, rescale_spect,	  0);  xv_set (frame, WIN_SHOW, TRUE,	  0);/* * There is a problem somewhere related to this call that causes few  * different problems at only a few sites.  For a customer with sunos * on a sparc2, waves core dumps on occasion when a spectrogram window * is created.  For another user on SGI, he gets a spectrogram window * without a title bar about 3 out of 10 times.   I can't reproduce either * here, but what I get on our Sparc2 with Sunos is that about 3 out of 10 * spectrogram windows dissappear after briefly flashing on the screen. * Not making the exv_attach_icon() call prevents all of these problems. * I've attempted to locate the actual problem, using Purify, etc., but * nothing conclusive has turned up.   So I'm putting in this awful hack * so that if it isn't fixed in a future release, at least we can tell  * users how to avoid the more serious problem.   They'll get a window that * has a blank icon instead. *  * So tell them to set the environment variable NO_SPECT_ICON to anything.*/  if (no_spect_icon == -1)	no_spect_icon = (getenv("NO_SPECT_ICON") && 1);   if (!no_spect_icon)  	exv_attach_icon (frame, IMAGE_ICON, title, TRANSPARENT);  return (canvas);}/*************************************************************************/print_spect_x (v)     View *v;{  Pixwin *pw;  double time, freq;  char title[100];  if (!v || !(v->canvas) || (doing_print_graphic && print_only_plot))    return;  time = v->cursor_time;  if (time < v->start_time)    time = v->start_time;  if (time > (freq = ET (v)))    time = freq;  freq = v->cursor_yval;  if (freq < v->start_yval)    freq = v->start_yval;  if (freq > v->end_yval)    freq = v->end_yval;  sprintf (title, "Time: %8.4f   Freq: %8.2lf   ", time, freq);  /* If format changes, fix print_spect_y to match. */  pw = (Pixwin *) canvas_paint_window (v->canvas);  pw_text (pw, *v->x_offset + 1, 14,	   PIX_COLOR (FOREGROUND_COLOR) | PIX_SRC, def_font, title);}/*********************************************************************/doublespect_y_to_yval (v, y)     register View *v;     int y;{  register double freq;  freq = v->start_yval + (*(v->y_offset) - y) * *(v->y_scale) / PIX_PER_CM;  if (freq < v->start_yval)    return (v->start_yval);  if (freq > v->end_yval)    return (v->end_yval);  return (freq);}/*************************************************************************/spect_get_cursor_channel (v)     View *v;{  double freq;  int i;  freq = v->cursor_yval;  if (freq < v->start_yval)    freq = v->start_yval;  if (freq > v->end_yval)    freq = v->end_yval;  /*   * ! *//* Hasty hack to get value printout working for nonlinear y scale     * (ARB_FIXED).  There's got to be a better way.   */  if (v->sig->y_dat)    freq = spect_y_to_yval (v, v->yval_to_y (v, freq));  i = 0.5 + (v->sig->dim - 1)    * ((freq - v->start_yval) / (v->end_yval - v->start_yval));  return (i);}/*************************************************************************/print_spect_y (v)     View *v;{  Signal *sig;  char **data;  Canvas canv;  Pixwin *pw;  double time, t;  int i, j;  char msg[100];  if (!v || !(sig = v->sig)      || !(data = (char **) sig->data) || !(canv = v->canvas)      || (doing_print_graphic && print_only_plot))    return;  time = v->cursor_time;  if (time < v->start_time)    time = v->start_time;  if (time > (t = ET (v)))    time = t;  j = time_to_index (sig, time);  if (j < 0 || j >= sig->buff_size)    return;  i = spect_get_cursor_channel (v);  if (!data[i])    return;  sprintf (msg, "Value: %3.0f ",	   v->val_offset[0] + (v->val_scale[0] * data[i][j]));  pw = (Pixwin *) canvas_paint_window (v->canvas);  /* 34 = length of title from print_spect_x */  pw_text (pw, *v->x_offset + 34 * def_font_width, 14,	   PIX_COLOR (FOREGROUND_COLOR) | PIX_SRC, def_font, msg);}/*************************************************************************/voidrescale_spect (c, w, h)     Canvas c;     int w, h;{  View *v;  if (debug_level)    {      Frame frame;      Xv_Window pw;      fprintf (stderr, "rescale_spect(c, %d, %d)\n", w, h);      pw = canvas_paint_window (c);      fprintf (stderr, "Paint window has XV_WIDTH %d,  XV_HEIGHT %d.\n",	       (int) xv_get (pw, XV_WIDTH), (int) xv_get (pw, XV_HEIGHT));      fprintf (stderr, "Canvas has XV_WIDTH %d,  XV_HEIGHT %d.\n",	       (int) xv_get (c, XV_WIDTH), (int) xv_get (c, XV_HEIGHT));      frame = (Frame) xv_get (c, XV_OWNER);      fprintf (stderr, "Frame has XV_WIDTH %d,  XV_HEIGHT %d.\n",	   (int) xv_get (frame, XV_WIDTH), (int) xv_get (frame, XV_HEIGHT));    }  if ((v = (View *) xv_get (c, WIN_CLIENT_DATA)) && w != *v->x_offset)    {      *v->x_scale *= (double) (v->width - *v->x_offset) / (w - *v->x_offset);      v->width = w;      v->height = h;    }}/*********************************************************************/intspect_plot_reticles (v)     View *v;{  if (v && v->canvas && v->reticle_on[0] && v->ret && v->ret[0])    {      draw_reticle (v->canvas, v->ret[0]);      return (TRUE);    }  return (FALSE);}/*************************************************************************/scale_spect_for_canvas (v)     View *v;{  Bound *b;  Reticle *ret;  double endf, endt, dt, df;  Spectrogram *sp;  int comb_height;  extern int h_spect_rescale, v_spect_rescale;#define EF(v) (v->y_to_yval(v, comb_height + b->top))  if (!v || !v->sig || !(ret = *v->ret))    return FALSE;  b = (Bound *) reticle_get_margins (ret);  comb_height = v->readout_height + v->scrollbar->height;  if (!v->h_rescale)		/* Force one pixel per frame. */    *(v->x_scale) = PIX_PER_CM / v->sig->freq;  if (*v->v_rescale && v->height > 0)    {      *(v->y_scale) =	(v->sig->band * PIX_PER_CM)	/ (v->height - (comb_height + b->top + b->bottom));    }  else    {				/* One pixel per frequency bin. */      *(v->y_scale) = (v->sig->band * PIX_PER_CM) / (v->sig->dim - 1);      if (v->height <= 0)	{	  v->height = comb_height + b->top + b->bottom	    + ROUND ((v->sig->band_low + v->sig->band - v->start_yval)		     * PIX_PER_CM / *(v->y_scale));	  if (v->height > MAX_CANVAS_HEIGHT)	    v->height = MAX_CANVAS_HEIGHT;	}    }  *(v->y_offset) = v->height - b->bottom;  ret->absc.start = v->start_time;  ret->ordi.start = v->start_yval;  /*   * The top and right reticle limits are set to the minimum of the data   * limits or the available plotting area.  This assumes that the plotting   * function will follow the same conventions...   */  if ((ret->absc.end = ET (v)) > BUF_END_TIME (v->sig))    ret->absc.end = BUF_END_TIME (v->sig);  if (ret->absc.end < ret->absc.start)    ret->absc.end = ret->absc.start;  if ((ret->ordi.end = EF (v)) > v->sig->band_low + v->sig->band)    ret->ordi.end = v->sig->band_low + v->sig->band;  if (ret->ordi.end < ret->ordi.start)    ret->ordi.end = ret->ordi.start;  ret->bounds.left = *(v->x_offset);  ret->bounds.bottom = *(v->y_offset);  /* Set the pixel limits of the edges of the reticle. */  /* (Somehow this seems like overspecification...) */  ret->bounds.right = ret->bounds.left    + ROUND ((ret->absc.end - ret->absc.start)	     * PIX_PER_CM / *(v->x_scale));  ret->bounds.top = ret->bounds.bottom    - ROUND ((ret->ordi.end - ret->ordi.start)	     * PIX_PER_CM / *(v->y_scale));  /*   * Set lengths and spacing of reticle subdivision tick marks. (Disable   * reticle drawing in case of trouble.)   */  v->reticle_plot =    scale_spect_view_ret (ret, v)    ? spect_plot_reticles    : NULL;  return TRUE;#undef EF}/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */plot_spect_cursors (v, color)     View *v;     int color;{  Pixwin *pw;  struct rect *rec;  int x, y, x1, x2, y1, y2;  if (!v || !v->canvas || (doing_print_graphic && print_only_plot))    return (FALSE);  x = v->time_to_x (v, v->cursor_time);  y = v->yval_to_y (v, v->cursor_yval);  x1 = 0;  x2 = v->width;  if (v->scrollbar && (v->scrollbar->height > 0) && v->scrollbar->is_on)    y1 = v->scrollbar->y + v->scrollbar->height;  else    y1 = 0;  y2 = v->height;  pw = canvas_pixwin (v->canvas);  pw_vector (pw, x, y1, x, y2,	     PIX_COLOR (color) | (PIX_SRC ^ PIX_DST),	     color);  pw_vector (pw, x1, y, x2, y,	     PIX_COLOR (color) | (PIX_SRC ^ PIX_DST),	     color);  return (TRUE);}/*************************************************************************/kill_srvimage (svim)     Server_image svim;{  if (svim)    {      dt_xv_destroy (12, svim);    }}/******************************************************************/Reticle *new_spgm_reticle (sig)     Signal *sig;		/* the spectrogram's SIG structure */{  Reticle *r;  double hz_per_pix, sec_per_pix, lospac, hispac, range, range10, range5,    range2;  int right_of_d;  char abform[20];  if (!sig || !(r = (Reticle *) calloc (1, sizeof (Reticle))))    return (NULL);  r->ordinate.maj.style = MAJOR | EDGES;  r->ordinate.maj.length = 10.0 / sig->freq;	/* 10 pixels long */  /* Want at least 30 pixels between freq. numbering and no more than 60. */  /* Assume total vertical pixels = sig->dim. */  hz_per_pix = sig->band / sig->dim;  lospac = 30.0 * hz_per_pix;  hispac = 60.0 * hz_per_pix;  for (range = 1.0e-6; range < 1.e6; range *= 10.0)    {      range10 = 10.0 * range;      if ((lospac >= range) && (lospac < range10))	{	  range5 = 5.0 * range;	  range2 = 2.0 * range;	  if (hispac >= range10)	    r->ordinate.maj.inter = range10;	  else if ((lospac <= range5) && (hispac >= range5))	    r->ordinate.maj.inter = range5;	  else	    r->ordinate.maj.inter = range2;	  break;	}    }  r->ordinate.maj.list = NULL;  r->ordinate.maj.num = 0;  /* Want at least 70 pixels between time numbering and no more than 140. */  /* Assume one pixel per time step. */  sec_per_pix = 2.0 / sig->freq;  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)    r->abscissa.maj.inter = range10;  else if ((lospac <= range5) && (hispac >= range5))    r->abscissa.maj.inter = range5;  else    r->abscissa.maj.inter = range2;  r->ordinate.min1.style = EDGES;  r->ordinate.min1.length = 5.0 / sig->freq;  r->ordinate.min1.inter = r->ordinate.maj.inter / 2.0;  r->ordinate.min1.list = NULL;  r->ordinate.min1.num = 0;  r->ordinate.min2.style = EDGES;  r->ordinate.min2.length = 3.0 / sig->freq;  r->ordinate.min2.inter = r->ordinate.maj.inter / 10.0;  r->ordinate.min2.list = NULL;  r->ordinate.min2.num = 0;  reticle_set_ord_precision (r, "%6.0f");  r->ordinate.num_inter = r->ordinate.maj.inter;  r->ordinate.num_loc = NUM_LB;  r->abscissa.maj.style = MAJOR | EDGES;  r->abscissa.maj.length = 10.0 * hz_per_pix;  r->abscissa.maj.list = NULL;  r->abscissa.maj.num = 0;  r->abscissa.min1.style = EDGES;  r->abscissa.min1.length = 5.0 * hz_per_pix;  r->abscissa.min1.inter = r->abscissa.maj.inter / 2.0;  r->abscissa.min1.list = NULL;  r->abscissa.min1.num = 0;  r->abscissa.min2.style = EDGES;  r->abscissa.min2.length = 3.0 * hz_per_pix;  r->abscissa.min2.inter = r->abscissa.maj.inter / 10.0;  r->abscissa.min2.list = NULL;  r->abscissa.min2.num = 0;  if (r->abscissa.maj.inter <= 1.0)    right_of_d = 1 + (int) (0.5 - log10 (r->abscissa.maj.inter));  else    right_of_d = 0;  sprintf (abform, "%s%df", "%8.", right_of_d);  reticle_set_absc_precision (r, abform);  r->abscissa.num_inter = r->abscissa.maj.inter;  r->abscissa.num_loc = NUM_LB;  r->bounds.top = 1;  r->bounds.bottom = 384;  r->bounds.left = 1;  r->bounds.right = 512;  r->color = 255;  r->linetype = 1;  r->font = XV_NULL;  r->abs_label = NULL;  r->ord_label = NULL;  r->ordi.start = 0.0;  r->ordi.end = 5000.0;  r->absc.start = 0.0;  r->absc.end = 1.0;  return (r);}/*********************************************************************/spect_xy_to_chan (v, x, y)     View *v;     int x, y;{  if (v && v->sig)    {      int d, i;      d = v->sig->dim - 1;      i = 0.5 + (d * (*v->y_offset - y) * (*v->y_scale)		 / (PIX_PER_CM * (v->end_yval - v->start_yval)));      if (i < 0)	return (0);      if (i > d)	return (d);      return (i);    }  return (0);}/*************************************************************************/isa_spectrogram_view (v)     View *v;{  return (v && (v->extra_type == VIEW_BITMAP) &&	  (v->data_plot == plot_spectrogram));}/*********************************************************************//* Assumes the view is a spectrogram. */int

⌨️ 快捷键说明

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