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

📄 xspect.c

📁 speech signal process tools
💻 C
📖 第 1 页 / 共 5 页
字号:
  head_printf (ss->header, "samples", &(ss->buff_size));  head_printf (ss->header, "frequency", &(ss->freq));  head_printf (ss->header, "start_time", &(ss->start_time));  head_printf (ss->header, "dimensions", &(ss->dim));  head_ident (ss->header, "f");  if (ss->header && ss->header->magic == ESPS_MAGIC && ss->header->esps_hdr)    {      *add_genhd_d ("start_time", (double *) NULL, 1, hdr) = ss->start_time;      *add_genhd_d ("end_time", (double *) NULL, 1, hdr) = ss->end_time;      *add_genhd_d ("record_freq", (double *) NULL, 1, hdr) = ss->freq;    }  ss->params = (caddr_t) sp;  sp->sig = NULL;		/* could be freed without sp's knowledge! */  RETURN (ss)#endif}#undef RETURNstatic char e_spect_tname[NAMELEN] = "";/*************************************************************************/clobber_temp_signal_file (){  if (*e_spect_tname)    unlink (e_spect_tname);  *e_spect_tname = 0;}/*************************************************************************//* Do ESPS spectrogram of signal in ESPS file on disk. */Signal *e_spect (sp)     Spectrogram *sp;{  Signal *sig = sp->sig;  char sgram_command[500];  char *data_window;  int fft_order;  double preemphasis;  double step_size;  double window_len;  char spec_name[200];  extern char output_dir[];  char *e_spec_name;  Signal *ss;  Object *o;  if (debug_level)    fprintf (stderr, "e_spect: ESPS spectrogram of signal %s.\n", sig->name);  switch (sp->window_type)    {    case 0:      data_window = "RECT";      break;    case 1:      data_window = "HAMMING";      break;    case 2:      data_window = "COS4";      break;    case 3:      data_window = "HANNING";      break;    case 4:      data_window = "TRIANG";      break;    case 5:      data_window = "NONE";      break;    case 6:      data_window = "KAISER";      break;    case 7:      data_window = "ARB";      break;    case 8:      data_window = "SINC";      break;    case 9:      data_window = "SINC_C4";      break;    default:      sprintf (notice_msg, "Window type %d not recognized.  Using HAMMING.",	       sp->window_type);      show_notice (0, notice_msg);      data_window = "HAMMING";      break;    }  fft_order = ROUND (log ((double) sp->nfft) / log (2.0));  preemphasis = -sp->preemp;  step_size = 1000.0 * sp->window_step;  window_len = 1000.0 * sp->window_size;  sprintf (sgram_command, "%s -s%.9f:%.9f -d%s -o%d -E%g -S%g -w%g",	   sgram_program, sp->start_time, sp->end_time,	   data_window, fft_order, preemphasis, step_size, window_len);  if (sp->outname && *sp->outname)    {      strcpy (spec_name, sp->outname);      e_spec_name = spec_name;    }  else    {#if defined(STARDENT_3000) || defined(M5600) || defined(hpux)      sprintf (spec_name, "%s.f", sp->signame);#else      sprintf (spec_name, "%s.fspec", sp->signame);#endif      /*       * By using just the basename here, we can force the use of output_dir,       * if it is specified.       */      if (*output_dir)	e_spec_name = inc_esps_name (basename (spec_name));      else	e_spec_name = inc_esps_name (spec_name);    }  if ((o = (Object *) (sig->obj)))    set_current_obj_name (o->name);  (void) run_esps_prog (sgram_command,			sig->name, e_spec_name, 1, TRUE,			clobber_temp_signal_file);  return NULL;}/*************************************************************************//* Do ESPS spectrogram of signal buffered in memory. */Signal *e_spgm (sp)     Spectrogram *sp;{  if (sp && sp->sig)    {      char *template = "espstmpXXXXXX", *tname;      int startsamp, nsamps;      Signal *sig;      struct header *hdr;      char comment[300];      short *data;      Signal *ss = sp->sig;      extern int ref_start;      if (debug_level)	fprintf (stderr, "e_spgm: ESPS spectrogram of signal %s.\n", sp->sig->name);      if (ss->header->magic == ESPS_MAGIC)	return (e_spect (sp));      if ((type_of_signal (ss) == P_SHORTS) && (ss->dim == 1))	{	  if (!sp->sig->data	      || !(data = ((short **) sp->sig->data)[0]))	    {	      show_notice (1, "NULL input data array in e_spgm.");	      return NULL;	    }	  tname = mk_esps_temp (template);	  *e_spect_tname = 0;	  if (tname)	    {	      strcpy (e_spect_tname, tname);	      setup_output_dir (e_spect_tname);	      free (tname);	    }	  else	    {	      show_notice (1, "can't create temporary output name in e_spgm,");	      return NULL;	    }	  startsamp =	    0.5 + (sp->start_time - BUF_START_TIME (sp->sig)) * sp->sig->freq;	  nsamps = 0.5 + (sp->end_time - sp->start_time) * sp->sig->freq;	  sig = new_signal (e_spect_tname, SIG_NEW, dup_header (sp->sig->header),			    (caddr_t) NULL, nsamps, sp->sig->freq, 1);	  if (!sig)	    {	      show_notice (1, "e_spgm: Can't make temporary new signal.");	      return NULL;	    }	  sig->start_time = sp->start_time;	  if (ref_start > sig->start_time)	    ref_start = sig->start_time;	  sig->file_size = nsamps;	  sig->end_time = sp->end_time;	  sig->header->magic = ESPS_MAGIC;	  hdr = sig->header->esps_hdr = new_header (FT_SD);	  set_sd_type (hdr, SHORT);	  hdr->hd.sd->sf = sp->sig->freq;	  set_pvd (hdr);	  sprintf (comment,		"xwaves spectrogram: start_time %g end_time %g signal %s\n",		   sp->start_time, sp->end_time, sp->sig->name);	  add_comment (hdr, comment);	  *add_genhd_d ("start_time", (double *) NULL, 1, hdr) = sp->start_time;	  *add_genhd_d ("end_time", (double *) NULL, 1, hdr) = sp->end_time;	  if (output_header (sig))	    {	      put_sd_recs (data + startsamp, nsamps, hdr, sig->header->strm);	      close_sig_file (sig);	      sp->sig = sig;	      ss = e_spect (sp);	    }	  else	    {	      show_notice (1,		   "e_spgm:  Can't output header of temporary new signal.");	      close_sig_file (sig);	      ss = NULL;	    }	  sig->name = NULL;	  free_signal (sig);	  return ss;	}      else	{	  sprintf (notice_msg,	    "Spectrogram method for signal %s is not available.", ss->name);	  show_notice (1, notice_msg);	}    }  else    show_notice (1, "Null signal passed to e_spgm.");  return NULL;}/*************************************************************************/voidspblit (pro, pixel_r, height, width, init)     Server_image pro;     unsigned short *pixel_r;     int height, width, init;{  static Display *display;  static XImage *pr = NULL;  Pixmap pmap;  static int xd = 0;  static GC gc;  /* ! *//* Not working yet. */  if (1)    return;  if (init == 1)    {      XWindowAttributes win_attr;      Visual *visual;      XGCValues gc_val;      xd = 0;      if (!doing_print_graphic)	display = (Display *) xv_get (daddy, XV_DISPLAY);      else	display = get_xp_display ();      XGetWindowAttributes (display, (Window) xv_get (daddy, XV_XID),			    &win_attr);      visual = win_attr.visual;      pr = XCreateImage (display, visual,			 1,	/* depth */			 XYBitmap,			 0,			 (char *) pixel_r,			 16, height,			 16, 0);      gc = XCreateGC (display, (Pixmap) xv_get (pro, SERVER_IMAGE_PIXMAP),		      (unsigned long) None, &gc_val);    }  XPutImage (display, pmap, gc, pr, 0, 0, xd, 0, width, height);  xd += width;  if (init == -1)    {      /* ! *//* Clean up */      pr->data = NULL;      XDestroyImage (pr);      XFreeGC (display, gc);    }}/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */voidcmap_spect (canv)     Canvas canv;{  register int i, j, k, l, lo_lim, hi_lim;  int nreserved;  double scale, a, b, interp, fac;  static char cm_file[100] = "no map yet";  extern char def_cm[];  extern double image_clip, image_range;  static u_char rb[MAX_CMAP_SIZE], gb[MAX_CMAP_SIZE], bb[MAX_CMAP_SIZE];  static int last_lower = -1, last_upper = -1;  nreserved = cmap_size - CMAP_RESERVED;  fac = ((double) CMAP_RESERVED) / (MAX_CMAP_SIZE - nreserved);  hi_lim = 0.5 + ((HI_SPECT_LIM - image_clip) * fac);  lo_lim = hi_lim - (0.5 + (image_range * fac));  if (!do_color)    return;  /*   * The thresholds (static globals) define the grayscale ramp for the   * spectrogram colormap.  The full colormap is divided into four regions:   * colors [0..lower threshold]   == white colors [lower .. upper]       ==   * gray (or color) ramp colors [upper .. reserved]    == black (or other   * color) colors [reserved .. map size] == special use (e.g. cursor color   *    * The reserved colors are assumed to be previously set in an external array   * "rgb".   */  cmap (XV_NULL);		/* ensure an initialized colormap */  if (strcmp (cm_file, def_cm))    {      for (i = 0; i < cmap_size; i++)	{			/* save local copy or orig. colormap */	  rb[i] = rgb[i].red;	  gb[i] = rgb[i].green;	  bb[i] = rgb[i].blue;	}      strcpy (cm_file, def_cm);    }  if (last_lower != lo_lim || last_upper != hi_lim)    {      last_lower = lo_lim;      last_upper = hi_lim;      for (i = 0; i <= lo_lim; ++i)	{	  rgb[i].red = rb[1];	  rgb[i].green = gb[1];	  rgb[i].blue = bb[1];	/* lower region */	}      scale = ((double) CMAP_RESERVED) / (hi_lim - lo_lim);      for (j = 0; i < hi_lim; i++, j++)	{	  interp = 1.0 + ((double) j) * scale;	  k = interp;	  l = k + 1;	  a = interp - (double) k;	  b = 1.0 - a;	  rgb[i].red = (unsigned char) (b * rb[k] + a * rb[l]);	  rgb[i].green = (unsigned char) (b * gb[k] + a * gb[l]);	  rgb[i].blue = (unsigned char) (b * bb[k] + a * bb[l]);	}      for (; i < CMAP_RESERVED; ++i)	{	  rgb[i].red = rb[CMAP_RESERVED - 1];	  rgb[i].green = gb[CMAP_RESERVED - 1];		/* g; */	  rgb[i].blue = bb[CMAP_RESERVED - 1];	/* b; *//* upper region */	}      for (i = 0; i < 3; i++)	{	  rgb[i].red = rb[i];	  rgb[i].green = gb[i];	  rgb[i].blue = bb[i];	/* lowest 3 are taboo also */	}    }  cmap (canv);}/*************************************************************************//* * This assumes that the view and reticle structures have been created, * linked and intelligently initialized... */Canvasnew_spect_window (ss)     Signal *ss;{  Frame frame;  Canvas canvas;  Xv_Cursor cursor;  void rescale_spect ();  extern void doit ();  extern int min_framewidth, cmap_depth, min_frameheight;  int frame_width_adjust,	/* adjustment for frame border width */    frame_height_adjust;	/* adjustment for frame border height */  char title[256];  static int no_spect_icon = -1;  if (!(ss && ss->views && *ss->views->ret))    return XV_NULL;  scale_spect_for_canvas (ss->views);  /* Limit min. size so some of the info. printed in border will be visible. */  if (ss->views->width < min_framewidth)    ss->views->width = min_framewidth;  if (ss->views->height < min_frameheight)    ss->views->height = min_frameheight;  if (debug_level)    fprintf (stderr, "Creating frame with XV_WIDTH %d,  XV_HEIGHT %d.\n",	     ss->views->width, ss->views->height);  if (do_color)    frame = (Frame) xv_create (XV_NULL, FRAME,			       XV_VISUAL, visual_ptr,			       XV_LABEL, title,			       FRAME_NO_CONFIRM, TRUE,			       FRAME_INHERIT_COLORS, FALSE,			       XV_X, next_x,			       XV_Y, next_y,			       XV_SHOW, FALSE,			       XV_WIDTH, ss->views->width + 2 * FRAME_MARGIN,			       XV_HEIGHT, ss->views->height			       + FRAME_HEADER + FRAME_MARGIN,			       WIN_DEPTH, cmap_depth,			       0);  else    frame = (Frame) xv_create (XV_NULL, FRAME,			       XV_LABEL, title,			       FRAME_NO_CONFIRM, TRUE,			       WIN_X, next_x,			       WIN_Y, next_y,			       WIN_SHOW, FALSE,			       XV_WIDTH, ss->views->width + 2 * FRAME_MARGIN,			       XV_HEIGHT, ss->views->height			       + FRAME_HEADER + FRAME_MARGIN,			       0);  if (!window_check_return (frame))    return ((Canvas) XV_NULL);  canvas = (Canvas) xv_create (frame, CANVAS,			       CANVAS_RETAINED, FALSE,			       CANVAS_FIXED_IMAGE, FALSE,			       CANVAS_AUTO_SHRINK, TRUE,			       CANVAS_AUTO_EXPAND, TRUE,			       OPENWIN_NO_MARGIN, TRUE,			       XV_WIDTH, WIN_EXTEND_TO_EDGE,			       XV_HEIGHT, WIN_EXTEND_TO_EDGE,  /* Compatibility attribute--going away in another release. */			       WIN_CLIENT_DATA, ss->views,			       CANVAS_PAINTWINDOW_ATTRS,  /* WIN_DYNAMIC_VISUAL,       TRUE,   */			       XV_VISUAL, visual_ptr,			       WIN_DEPTH, cmap_depth,			       0,			       CANVAS_CMS_REPAINT, FALSE,			       CANVAS_NO_CLIPPING, TRUE,			       0);  xv_set (canvas_paint_window (canvas),	  WIN_CONSUME_EVENTS,	  LOC_DRAG,	  LOC_MOVE,	  LOC_WINEXIT,	  WIN_IN_TRANSIT_EVENTS,	  WIN_ASCII_EVENTS,	  0,	  WIN_IGNORE_EVENTS,	  KBD_USE,	  KBD_DONE,	  0,	  WIN_EVENT_PROC, doit,	  WIN_BIT_GRAVITY, ForgetGravity,	  0);  if (!window_check_return (canvas))    {      dt_xv_destroy_safe (11, frame);      return ((Canvas) 0);    }  next_x += w_x_incr;  next_y += w_y_incr;  if ((next_y + Max (min_frameheight, (int) xv_get (frame, XV_HEIGHT)))

⌨️ 快捷键说明

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