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

📄 xf0_methods.c

📁 speech signal process tools
💻 C
📖 第 1 页 / 共 2 页
字号:
/* * This material contains unpublished, proprietary software of  * Entropic Research Laboratory, Inc. Any reproduction, distribution,  * or publication of this work must be authorized in writing by Entropic  * Research Laboratory, Inc., and must bear the notice:  * *    "Copyright (c) 1987-1990  AT&T, Inc. *    "Copyright (c) 1986-1990  Entropic Speech, Inc.  *    "Copyright (c) 1990-1996  Entropic Research Laboratory, Inc.  *                   All rights reserved" * * The copyright notice above does not evidence any actual or intended  * publication of this source code.      * * Written by:  David Talkin * Checked by: * Revised by: * * Brief description: * a collection of routines for dealing with SIG_F0 signals */static char *sccs_id = "@(#)xf0_methods.c	1.10	1/18/97	ATT/ESI/ERL";#include <Objects.h>#include <xview/font.h>#include <Xp_pw.h>#define scoff(x) ((int)(yoffs + ((double)(x) * scale)))#define ALMOST 0.95extern double  f0_canvas_use, f0_range, f0_min;extern char    f0_plot_specs[];extern Xv_Font def_font;extern int     def_font_height, def_font_width;extern char    *savestring();/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/print_f0_y(v)  register View	*v;{  register int	i, elem, dim, index, slen, w;  register List	*l, *l2;  int		itsf0;  double	time, scale, yoffs, t;  char		tmp[100];  Pixwin	*pw;  Signal	*sig;  if(v && (sig = v->sig)) {    time = v->cursor_time;    if (time < v->start_time) time = v->start_time;    if (time > (t = ET(v)))   time = t;    if((index = time_to_index(sig, time)) > (sig->buff_size - 1)       || index < 0       || (v->dims > 0 && !sig->data))      return(FALSE);    w = def_font_width;    pw = canvas_pixwin(v->canvas);    for(dim=0; dim < v->dims; dim++) { /* for each dimension... */      if(v->show_vals[dim]) {	double offs, scl;	elem = v->elements[dim];	itsf0 = FALSE;	if((v->show_labels[dim]) && (l = sig->idents)) {	  /* find the element's ident. string */	  for(i = 0, l2 = l; i < elem; i++)	    if(l2->next)	      l2 = l2->next;	  slen = strlen(l2->str); /* offset at which to print numeric value */	  if(!strcmp(l2->str,"F0"))	    itsf0 = TRUE;	} else slen = 0;	scale = - PIX_PER_CM/v->y_scale[dim];	yoffs = .5 + (double)v->y_offset[dim];	offs = v->val_offset[elem];	scl = v->val_scale[elem];	switch(sig_type_hack(sig)) {	case P_CHARS:	case P_UCHARS:	  {	    char *dp = ((char **) sig->data)[elem];	    if (!dp)	      return FALSE;	    sprintf(tmp, "%4.0f", offs + (scl * dp[index]));	  } break;	case P_SHORTS:	case P_USHORTS:	  {	    short *dp = ((short **) sig->data)[elem];	    if (!dp)	      return FALSE;	    sprintf(tmp, "%6.0f", offs + (scl * dp[index]));	  } break;	case P_INTS:	case P_UINTS:	  {	    int *dp = ((int **) sig->data)[elem];	    if (!dp)	      return FALSE;	    sprintf(tmp, "%12.0f", offs + (scl * dp[index]));	  } break;	case P_FLOATS:	  {	    float *dp = ((float **) sig->data)[elem];	    if (!dp)	      return FALSE;	    if(! itsf0)	      sprintf(tmp, "%13.6e", offs + (scl * dp[index]));	    else	      sprintf(tmp, "%6.1f", offs + (scl * dp[index]));	  } break;	case P_DOUBLES:	  {	    double *dp = ((double **) sig->data)[elem];	    if (!dp)	      return FALSE;	    if(! itsf0)	      sprintf(tmp, "%13.6e", offs + (scl * dp[index]));	    else	      sprintf(tmp, "%6.1f", offs + (scl * dp[index]));	  } break;	default:	  return(FALSE);	}	if(itsf0)	  pw_text(pw, *(v->x_offset) + (slen*w), scoff(v->plot_min[dim]),		  PIX_SRC|PIX_COLOR(CURSOR_COLOR), def_font, tmp);	else	  pw_text(pw, (slen*w), scoff(v->plot_min[dim]),		  PIX_SRC|PIX_COLOR(TEXT_COLOR), def_font, tmp);      }    }  }  return(TRUE);}/*********************************************************************/homogeneous(s)     Signal *s;{  if(s && IS_GENERIC(s->type)) {    if((s->type & VECTOR_SIGNALS) != P_MIXED)      return(TRUE);    if(s->types) {      int i, typ;      for(i=1, typ = *s->types; i < s->dim; i++)	if(s->types[i] != typ) return(FALSE);      return(TRUE);    }  }  return(FALSE);}/*********************************************************************/View *new_f0_view(s, c)     Signal *s;     Canvas c;{  View *v, *setup_generic_view();  int scale_f0_for_canvas(), plot_f0_waves();  extern double ref_start, ref_size;  if(!homogeneous(s))    return(NULL);     /* F0 plotter only knows homogeneous for now... */  if((v = setup_generic_view(s,c))) {    int f0chan;        v->data_plot = plot_f0_waves;    v->y_print = print_f0_y;    v->start_yval = f0_min;    v->end_yval = f0_min + f0_range;    v->find_crossing = FALSE;    if((f0chan = get_labeled_chan(s,"F0")) >= 0) {      v->plot_min[f0chan] = f0_min;      v->plot_max[f0chan] = f0_min + f0_range;    }    v->set_scale = scale_f0_for_canvas;    v->set_scale(v);    return(v);  }  return(NULL);}/********************************************************************//* This ASSUMES that the signal is homogeneous and that the "P_MIXED"designation is bogus in the sense that all signal elements areactually the same atomic type. */sig_type_hack(sig)     Signal *sig;{  int i;  if((i = (sig->type & VECTOR_SIGNALS)) == P_MIXED)    i = sig->types[0];  return(i);}/***************************************************************************//*Allocate f0_canvas_use of the available canvas height to the F0 signal.  The remainder of the space gets divided evenly among the other channels. */int scale_f0_for_canvas(v)    View *v;{  int i, f0chan;  int	      comb_height;  double maxval, minval, dtm;  double  scale, size, off, f0size, height;  Signal *s;  Canvas c;  Bound *b;  struct rect *r;  Reticle *f0ret, *prepare_f0_reticle();  extern int scrollbar_height, readout_bar_height;    if(v && (f0ret = prepare_f0_reticle(v))) {    /* note side-effects of prepare_f0_reticle() on v!! */    if(v->scrollbar)      comb_height = v->scrollbar->height + v->readout_height;    else      comb_height = scrollbar_height + readout_bar_height;    c = v->canvas;    s = v->sig;    r = (struct rect*)xv_get(c, WIN_RECT);    b = reticle_get_margins(f0ret);    if((f0chan = get_active_labeled_chan(v,"F0")) < 0) f0chan = 0;    if(v->dims > 1)      size = (1.0 - f0_canvas_use) *      ((double)(r->r_height - comb_height))/(v->dims - 1);    f0size = (f0_canvas_use * (r->r_height - comb_height));    height = f0size - (b->top + b->bottom);    for(i=0, off=r->r_height; i < v->dims; i++) {      if(v->elements[i] != f0chan) {	if(v->ret[i]) {		/* if these were set by generic view creation */	  free_reticle(v->ret[i]);	  v->ret[i] = NULL;	}	if(v->v_rescale[i]) {	  maxval = s->smax[v->elements[i]];	  minval = s->smin[v->elements[i]];	} else {	  maxval = v->plot_max[i];	  minval = v->plot_min[i];	}	if((dtm = maxval - minval) == 0.0) dtm = 1.0;	scale = - ALMOST * size/dtm;	v->y_offset[i] = off - (size/2) - (scale * (maxval + minval) / 2.0);	off -= size;      } else {	double f0min = v->plot_min[i],	       f0range = v->plot_max[i] - v->plot_min[i];	v->colors[i] = WAVE2_COLOR;	v->sig->smin[v->elements[i]] = f0min; /* so print_y will work right */	scale = - height/f0range;	v->y_offset[i] = off - b->bottom - (height/2) -	  (scale * (f0min + f0min + f0range) / 2.0);	/* let reticle know the bounds of actual data */	f0ret->bounds.top = off - f0size + b->top;	f0ret->bounds.bottom = f0ret->bounds.top + height;	off -= f0size;      }      if(fabs(scale) > 0.0)	v->y_scale[i] = - PIX_PER_CM/scale;      else	v->y_scale[i] = 1.0e6;    }    return(TRUE);		/* in case anyone cares */  }  return(FALSE);}/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*//* Multi-dimensional waveform plotting using a connect-the-dotsscheme.  This routine is tuned to plot signals with one elementlabeled "F0" and another labeled "P(voice)" (but both labels areoptional).  The F0 component (or element 0, if no "F0" label ispresent) is plotted (with a reticle) so as to use f0_canvas_use of thevertical plotting area for F0 values starting at f0_min and extendingfor f0_range Hz.  The rest of the plotting area is apportioned equallyamong all other vector elements.  If an element labeled "P(voice)" ispresent, it will be used to gate the plotting of F0 on and off(threshold 0.5) so as to avoid meaningless F0 values in unvoicedregions.  If P(voiced) is not labeled, element 0 will be used for thegating signal, thus a single-channel F0 signal will be plottedcorrectly if the values for F0 are set to 0 in unvoiced regions. */plot_f0_waves(view)register View *view;{  register int nsam, i, j, k, npix;  int val, dim, f0chan, pvchan;  Pixwin    *pw;  Signal    *sig;  Canvas    canvas;  double end, start, fxoff, dtm;  register double scale, incr, x, yoffs, sump;  char f0c[10];  static int  dx=4, dy=5, type=0;

⌨️ 快捷键说明

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