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

📄 signal.c

📁 speech signal process tools
💻 C
📖 第 1 页 / 共 2 页
字号:
      close_sig_file(s);   /* should be called before header or name freed */      if (s->name) {	 free(s->name);	 s->name = NULL;      }      if (s->header && s->header->magic == ESPS_MAGIC) {	 if (is_feasd_sphere(s))	    close_feasd_sphere(s);          if (s->header->esps_clean && s->header->esps_hdr) 	    free_header(s->header->esps_hdr, (long)0, (char*)NULL);      }      if (s->header) {	 if (s->header->header)	    free(s->header->header);	 free(s->header);	 s->header = NULL;      }      if (s->utils->free_data)	 s->utils->free_data(s);      free(s->utils);		/* after `free_data' used! */      l = s->idents;      while (l) {	 if (l->str) {	    free(l->str);	 }	 l2 = l->next;	 free(l);	 l = l2;      }      if ((v = s->views))	 while (v) {	    v2 = v->next;	    free_view(v);	    v = v2;	 }      s2 = s->others;      free(s);      s = s2;   }}/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */unlink_signal(s)   Signal         *s;{   Object         *o;   Signal         *s2;   if (s && (o = (Object *) s->obj)) {      if (s == (s2 = o->signals)) {	 o->signals = s->others;	 s->others = NULL;	 s->obj = NULL;	 return (TRUE);      } else {	 while (s2) {	    if (s2->others == s) {	       s2->others = s->others;	       s->others = NULL;	       s->obj = NULL;	       return (TRUE);	    }	    s2 = s2->others;	 }      }   }   return (FALSE);}/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */unlink_view(v, hv)   View           *v,		/* view to unlink */                 **hv;		/* head of its view list */{   View           *v2;   if (v && (v2 = *hv)) {      if (v2 == v) {	 *hv = v->next;      } else {	 while (v2->next && (v2->next != v))	    v2 = v2->next;	 if (!v2->next) {	    printf("Request to unlink_view(%d) failed; not in list !\n", v);	    return (FALSE);	 } else	    v2->next = v->next;      }      return (TRUE);   }   return (FALSE);}/*************************************************************************/voidfree_spectrogram(s)   Spectrogram    *s;{   if (s) {      if (s->dimp)	 free(s->dimp);      if (s->signame)	 free(s->signame);      if (s->outname)	 free(s->outname);      free(s);      /*       * NOTE: Do NOT attempt to free s->bitmap.  It is only used to pass the       * address of the pixrect structure!       */   }}/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */View           *new_view(s, c)   Signal         *s;   canvas_t        c;		/* Canvas with SUNVIEW or XVIEW; else caddr_t */{   View           *v = NULL, *v2 = NULL;   Signal         *s2 = NULL;   Object         *ob = NULL;   int             i;   int             dim;   if (!s)      return (NULL);   dim = (s) ? s->dim : 1;   if ((s->type & SPECIAL_SIGNALS) == SIG_SPECTROGRAM)      dim = 1;   if ((v = (View *) malloc(sizeof(View)))) {      if ((v->x_scale = (double *) malloc(sizeof(double))) &&	  (v->x_offset = (int *) malloc(sizeof(int))) &&	  (v->y_scale = (double *) malloc(sizeof(double) * dim)) &&	  (v->y_offset = (int *) malloc(sizeof(int) * dim)) &&	  (v->z_scale = (double *) malloc(sizeof(double) * dim)) &&	  (v->val_scale = (double *) malloc(sizeof(double) * dim)) &&	  (v->val_offset = (double *) malloc(sizeof(double) * dim)) &&	  (v->z_offset = (int *) malloc(sizeof(int) * dim)) &&	  (v->v_rescale = (int *) malloc(sizeof(int) * dim)) &&	  (v->show_vals = (int *) malloc(sizeof(int) * dim)) &&	  (v->show_labels = (int *) malloc(sizeof(int) * dim)) &&	  (v->reticle_on = (int *) malloc(sizeof(int) * dim)) &&	  (v->elements = (int *) malloc(sizeof(int) * dim)) &&	  (v->plot_max = (double *) malloc(sizeof(double) * dim)) &&	  (v->plot_min = (double *) malloc(sizeof(double) * dim)) &&	  (v->colors = (int *) malloc(sizeof(int) * dim)) &&	  (v->line_types = (int *) malloc(sizeof(int) * dim)) &&	  (v->ret = (Reticle **) malloc(sizeof(Reticle *) * s->dim))) {	 v->canvas = c;	 v->sig = s;	 v->dims = dim;	 for (i = 0; i < dim; i++) {	    v->y_scale[i] = 1.0;/* y units per cm */	    v->y_offset[i] = 0;	    v->val_offset[i] = 0.0;	    v->val_scale[i] = 1.0;	    v->v_rescale[i] = 1;	    v->show_vals[i] = 1;	    v->show_labels[i] = 1;	    v->reticle_on[i] = 1;	    v->elements[i] = i;	    v->colors[i] = 1;	    v->line_types[i] = 1;	    if (s->smax && s->smin) {	       v->plot_max[i] = s->smax[i];	       v->plot_min[i] = s->smin[i];	    }	 }	 for (i = 0; i < s->dim; i++)	    ((char **) (v->ret))[i] = NULL;	 v->width = 1000;	/* Saved since resize proc gives no access */	 v->height = 200;	/* to previous canvas size. */	 v->start_time = (s) ? BUF_START_TIME(s) : 0.0;	 *(v->x_offset) = 0;	 if (s && v->width)	/* seconds per cm */	    *(v->x_scale) = BUF_DURATION(s) * PIX_PER_CM /	       (v->width - *v->x_offset);	 else	    *(v->x_scale) = .08;	 v->plotted = FALSE;	 v->overlay_n = -1;	 v->zoom_ratio = 0.5;	 v->cross_level = 0.0;	 v->page_step = 2.0;	 v->background = 0;	 v->invert_dither = FALSE;	 v->overlay_as_number = FALSE;	 v->redraw_on_release = TRUE;	 v->rewrite_after_edit = TRUE;	 v->spect_interp = TRUE;	 v->h_rescale = FALSE;	 v->rescale_scope = SCOPE_VIEW;	 v->readout_height = 20;	 v->shorten_header = 0;	 v->cursor_channel = 0;	 v->tmarker_chan = 0;	 v->bmarker_chan = 0;	 v->find_crossing = 0;	 v->next = NULL;	 v->extra = NULL;	 v->extra_type = VIEW_STANDARD;	 v->scrollbar = NULL;	 v->left_but_proc = NULL;	 v->mid_but_proc = NULL;	 v->move_proc = NULL;	 v->mark_reference = NULL;	 v->right_but_proc = NULL;	 v->handle_scrollbar = NULL;	 v->data_plot = NULL;	 v->cursor_plot = NULL;	 v->hmarker_plot = NULL;	 v->vmarker_plot = NULL;	 v->reticle_plot = NULL;	 v->x_print = NULL;	 v->y_print = NULL;	 v->free_extra = NULL;	 v->set_scale = NULL;	 v->time_to_x = NULL;	 v->x_to_time = NULL;	 v->xy_to_chan = NULL;	 v->yval_to_y = NULL;	 v->y_to_yval = NULL;	 if (s->band > 0.0) {	    v->start_yval = s->band_low;	    v->end_yval = s->band_low + s->band;	 } else {	    v->start_yval = 0.0;	    v->end_yval = s->freq / 2;	/* Nyquist limit */	 }	 /*	  * if a previous view exists in this object, use its current	  * cursor/marker/etc. values to init this new view	  */	 if (s && (ob = (Object *) s->obj)) {	/* find a previous view */	    for (v2 = NULL, s2 = ob->signals; s2 && !v2; s2 = s2->others)	       for (v2 = s2->views; v2; v2 = v2->next)		  if (v != v2)		     break;	/* found a previous view */	 }	 if (v2) {		/* if not first, use current values */	    v->cursor_time = v2->cursor_time;	    v->cursor_yval = v2->cursor_yval;	    v->cursor_channel = v2->cursor_channel;	    v->tmarker_chan = v2->tmarker_chan;	    v->bmarker_chan = v2->bmarker_chan;	    v->lmarker_time = v2->lmarker_time;	    v->rmarker_time = v2->rmarker_time;	    v->tmarker_yval = v2->tmarker_yval;	    v->bmarker_yval = v2->bmarker_yval;	 } else {		/* if first view, make up values */	    v->cursor_time = v->start_time;	    v->cursor_yval = v->start_yval;	    v->lmarker_time = v->start_time;	    v->rmarker_time = ET(v);	    v->tmarker_yval = 0.0;	    v->bmarker_yval = 0.0;	 }	 return (v);      } else	 printf("Can't allocate data arrays in new_view()\n");   } else {      printf("Can't allocate a View in new_view()\n");   }   return (NULL);		/* default if failure */}/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */#define GET_MAXMIN(the_type) { \    register the_type	**dpp = (the_type **) sig->data; \    for (i = 0; i < sig->dim; i++) { \	register the_type   *p, *q, ima, imi, t; \	for (p = dpp[i], q = p + sig->buff_size, ima = imi = *p++; p < q; ) { \	    if ((t = *p++) > ima) ima = t; \	    else \		if (t < imi) imi = t; \	} \	sig->smax[i] = ima; \	sig->smin[i] = imi; \    }}#define GET_MAXMIN_1(the_type) { \    register the_type	*dp = (the_type *) s_data; \    register the_type   *p, *q, ima, imi, t; \    for (p = dp, q = p + sig->buff_size, ima = imi = *p++; p < q; ) { \	if ((t = *p++) > ima) ima = t; \	else \	    if (t < imi) imi = t; \    } \    sig->smax[i] = ima; \    sig->smin[i] = imi; \    }/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */get_maxmin(sig)   Signal         *sig;{   if (sig && sig->type && sig->data) {      if (IS_GENERIC(sig->type)) {	 register int    i;	 switch (sig->type & VECTOR_SIGNALS) {	 case P_CHARS:	 case P_UCHARS:	    GET_MAXMIN(char);	    break;	 case P_SHORTS:	    GET_MAXMIN(short);	    break;	 case P_FLOATS:	    GET_MAXMIN(float);	    break;	 case P_INTS:	 case P_UINTS:	    GET_MAXMIN(int);	    break;	 case P_DOUBLES:	    GET_MAXMIN(double);	    break;	 case P_MIXED:	    for (i = 0; i < sig->dim; i++) {	       caddr_t         s_data = ((caddr_t *) sig->data)[i];	       switch (sig->types[i]) {	       case P_CHARS:	       case P_UCHARS:		  GET_MAXMIN_1(char);		  break;	       case P_SHORTS:		  GET_MAXMIN_1(short);		  break;	       case P_FLOATS:		  GET_MAXMIN_1(float);		  break;	       case P_INTS:	       case P_UINTS:		  GET_MAXMIN_1(int);		  break;	       case P_DOUBLES:		  GET_MAXMIN_1(double);		  break;	       default:		  printf("Unknown element data type in get_maxmin(%x)\n",			 sig->types[i]);		  return (FALSE);	       }	    }	    break;	 default:	    printf("Unknown data type in get_maxmin(%x)\n", sig->type);	    return (FALSE);	 }	 return (TRUE);      } else	 printf("Unknown data type in get_maxmin(%x)\n", sig->type);   }   return (FALSE);}#undef GET_MAXMIN_1#undef GET_MAXMIN/*************************************************************************//* * These routines compute buffer start/end times in seconds. Routines like * these must be pointed to by s->utils->buf_start and s->utils->buf_end. * This is set up in new_signal() for generic signals and should be setup in * read_<non-generic>_data() for non-generic types. */doublevec_buf_start(s)		/* (buffer) start time for Vector signals */   register Signal *s;{   return (s->start_time + (((double) (s->start_samp)) / s->freq));}doublevec_buf_end(s)			/* (buffer) end time for Vector signals */   register Signal *s;{   return (s->start_time + (((double) (s->start_samp + s->buff_size)) / s->freq));}/* * Signal duration routines. */doublevec_sig_dur(s)   register Signal *s;{   return s->file_size / s->freq;}/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */doublevec_index_to_time(s, index)   Signal         *s;   int             index;{   if (index < 0)      index = 0;   else if (index >= s->buff_size)      index = s->buff_size - 1;   return (s->start_time + (((double) (s->start_samp + index)) / s->freq));}/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */vec_time_to_index(s, time)   Signal         *s;   double          time;{   double          rtim;   int             ind;   if (time > (rtim = BUF_END_TIME(s)))      time = rtim;   if ((rtim = (time - BUF_START_TIME(s))) < 0.0)      rtim = 0.0;   ind = (int) (0.5 + (s->freq * rtim));   if (ind >= s->buff_size)      ind = s->buff_size - 1;   return (ind);}/* * Misc. utility routines. */free_data(s)			/* default fn. works on multi-dim. vectors, */   register Signal *s;		/* (anything with table of channel vectors) */{   register void **dpp;   register int    n;   if (s && (n = s->dim) && (dpp = (void **) s->data)) {      while (n-- > 0)	 if (dpp[n])	    free(dpp[n]);      free(dpp);   }   return (TRUE);		/* meaningless return value */}/*************************************************************************//* * Return a pointer to the vector element array corresponding to the "name" * argument.  The returned pointer type must be coerced appropriately by the * caller.  If sig->idents is null, the "identifiers" in the header are used. * If sig->idents is non-null, it is assumed to contain a valid ordered list * of vector-element identifiers, in which case sig->header is not reparsed. */char           *get_signal_element(sig, name)   Signal         *sig;   char           *name;{   extern Selector head_a0;   if (sig && sig->data && (sig->header || sig->idents) && name && *name) {      List           *l = sig->idents;      int             ind = 0;      if (!l) {	 setup_access(NULL);	 head_a0.dest = (char *) &(sig->idents);	 get_header_args(sig->header->header, &head_a0);	 l = sig->idents;      }      while (l && (ind < sig->dim)) {	 if (!strcmp(l->str, name))	    return (((char **) (sig->data))[ind]);	 ind++;	 l = l->next;      }   }   return (NULL);}

⌨️ 快捷键说明

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