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

📄 xchartprocs.c

📁 speech signal process tools
💻 C
📖 第 1 页 / 共 2 页
字号:
/* Copyright (c) 1995 Entropic Research Laboratory, Inc. *//* xchartprocs.c *//* * 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-1993  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:   * Checked by: * Revised by: * * Brief description: * */static char *sccs_id = "@(#)xchartprocs.c	1.7	9/26/95	ATT/ERL";/*These routines are designed to manipulate displays of "charts."  Achart is a collection of segment hypotheses, E.g. word hypotheses.  Itis assumed that the hypotheses for a given symbol are non-overlapping intime.  Other than this, no assumptions are made about the number orordering of the hypotheses in the input file.  The input file is aregular ASCII file with a header and one or more lines containingsegment hypotheses.  The file format is as follows:   Optional header elements [default value; explanation]:type		[1; 1 ==> hypothesis bounds in seconds; 2 ==> samples]frequency	[8000; specifies PCM sampling frequency when type == 2]color		[124; specifies color of plotted text in chart]font		[system default font; specifies font for chart display]# [# terminates header; must be present with or without other header elements.]   Any number of segment hypotheses formatted as [ID T1 T2 Likelihood Text]:12	0.234	0.456	0.77		foobar12	0.567	1.987	0.97		foobar15	0.267	1.456	0.27		barfoo	.	.	.The decimal points are optional and the numbers may have any number ofsignificant figures.  The ID and "likelihood" values are not currently usedand may have any numerical value.*/#include <Objects.h>#include <labels.h>#include <charts.h>#include <xview/font.h>#define _NO_PROTO#include <Xp.h>#include <Xp_pw.h>#include <esps/epaths.h>extern int debug_level;extern 	double x_to_time();Wobject *charts=NULL;void chart_menu_proc();/*********************************************************************/Menu make_chart_menu(){  char text[256];  int i, j, nitems, itsok = FALSE;  int rows, cols;  Menu m, make_menu();  extern char chartmenu[];    nitems = 0;/*  if(!(m = make_menu(chartmenu, &nitems, chart_menu_proc))) {    printf("Couldn't find chart menu file (%s); trying default\n",chartmenu);    m = make_menu(full_path("WAVES_MISC","chartmenu"),&nitems,		  chart_menu_proc);   }*/    if (!FIND_WAVES_MENU(chartmenu,chartmenu)) {      (void) fprintf(stderr, "xchart: couldn't find chartmenu %s\n", chartmenu);      return (FALSE);    }    m = make_menu(chartmenu,&nitems, chart_menu_proc);  if(!(m && nitems))    printf("Problems getting chart menu (n:%d)\n",nitems);  return(m);}  /*********************************************************************/Wobject *new_wobject(ob)     Objects *ob;{  if(ob && ob->name) {    Wobject *w = (Wobject*)malloc(sizeof(Wobject));    if(w) {      w->obj = ob;      w->label_loc = 0;	/* 0==>top; 1==>bottom; 3==>off */      w->label_size = 80;	/* pixel height of label area */      w->charts = NULL;      w->next = charts;      w->menu = make_chart_menu();      charts = w;      return(w);    } else      printf("Allocation failure in new_wobject()\n");  } else    printf("Bogus Objects passed to new_wobject()\n");  return(NULL);}/**********************************************************************/kill_chartfile(name,ob)     char *name;     Objects *ob;{  Wobject *w;  if(name && *name && ob && (w = get_wobject(ob))) {    Chartfile *c = w->charts, *cn;    if(c) {      if(!strcmp(c->chart_name,name)) {	w->charts = c->next;	free_chartfile(c);	return(TRUE);      }      while(c->next) {	if(!strcmp(c->next->chart_name,name)) {	  cn = c->next;	  c->next = cn->next;	  free_chartfile(cn);	  return(TRUE);	}	c = c->next;      }    }  }  return(FALSE);}/**********************************************************************/kill_wobject(w)     Wobject *w;{  if(w) {    Chartfile *c = w->charts, *cn;    Wobject *wo = charts;        if(wo) {			/* unlink it from the list */      if(wo == w)	charts = w->next;      else	while(wo->next) {	  if(wo->next == w) {	    wo->next = w->next;	    break;	  }	  wo = wo->next;	}    }    while(c) {			/* kill all its chartfiles */      cn = c->next;      free_chartfile(c);      c = cn;    }    if(w->menu) {      menu_destroy(w->menu);    }    free(w);  }}/*********************************************************************/free_chartfile(c)     Chartfile *c;{  if(c) {    Word *word, *wn;    Hit *hit, *hitn;        if(c->sig_name) free(c->sig_name);    if(c->chart_name) free(c->chart_name);    if(c->comment) free(c->comment);    if((word = c->first_word)) {      do {	if(word->str) free(word->str);	hit = word->hits;	while(hit) {	  hitn = hit->next;	  free(hit);	  hit = hitn;	}	wn = word->next;	free(word);	word = wn;      } while(word != c->first_word);    }  }}/*********************************************************************/plotting_labels(ob)     Objects *ob;{  Wobject *w = get_wobject(ob);  if(w && (w->label_loc == 3))    return(FALSE);  else    return(ob && ob->labels);}/*********************************************************************/Chartfile*get_chart_level(wob,y)     Wobject *wob;     register int y;{  static Chartfile *cfo = NULL;  Rect *rec;  register int n, at, yoffset, height;  register Chartfile *cf;  if(wob && (cf = wob->charts)) {    n=1;    while ((cf = cf->next)) n++;    if(n==1) return(wob->charts);    rec = (Rect*)xv_get(wob->obj->canvas, WIN_RECT);    if(plotting_labels(wob->obj)) {      yoffset = (wob->label_loc)? 0 : wob->label_size;      height =  rec->r_height - wob->label_size;    } else {      yoffset = 0;      height = rec->r_height;    }    if(y < yoffset) return(NULL);    at = (n * (y-yoffset))/height;    if(at == n) at--;    cf = wob->charts;    while(cf && at--) cf = cf->next;    cfo = cf;    return(cf);  }  return(NULL);}/*********************************************************************/plotting_charts(wob)     Wobject *wob;{  return(wob && wob->charts && wob->charts->first_word);}/**********************************************************************/send_play_seg(ob,ptime,ntime)     Objects *ob;     double ptime,ntime;{  if(ob) {    char mes[MES_BUF_SIZE];    if(ntime > 0.0)      sprintf(mes,"%s play start %f end %f\n",ob->name,ptime,ntime);    else      sprintf(mes,"%s play start %f\n",ob->name, ptime);    mess_write(mes);  }}     /**********************************************************************/double left_bound(word,time)     Word *word;     double time;{  if(word) {    Hit *hit = word->hits;    while(hit) {      if(hit->start <= time) {	if(hit->end >= time)	  return(hit->start);	else	  if(!hit->next || (hit->next && (hit->next->start >= time)))	    return(hit->end);      }      hit = hit->next;    }   }  return(-1.0);}/**********************************************************************/double right_bound(word,time)     Word *word;     double time;{  if(word) {    Hit *hit = word->hits;    while(hit) {      if(hit->start > time)	return(hit->start);      else	if(hit->end > time)	  return(hit->end);      hit = hit->next;    }   }  return(-1.0);}/**********************************************************************/Word *get_word_level(cfi,y)     Chartfile *cfi;     int y;{  Rect *rec;  register int n, at, me, yspace, ystep,yoffset,height;  register Chartfile *cf;  Pixfont* pf;  Wobject *wob;  Word *w;  if(cfi && (wob = cfi->obj) && (cf = wob->charts)) {    /* Count total charts and find position of cfi. */    me = n = 1;    while ((cf = cf->next)) {      n++;      if(cf == cfi) me = n;    }    if((pf = cfi->font)) {     yspace = (int)(xv_get(pf,FONT_DEFAULT_CHAR_HEIGHT) * 0.2);     ystep = xv_get(pf,FONT_DEFAULT_CHAR_HEIGHT) + yspace;    } else {      printf("Problems accessing fonts in get_word_level()\n");      return(NULL);    }    rec = (Rect*)xv_get(wob->obj->canvas, WIN_RECT);    if(plotting_labels(wob->obj)) {      yoffset = (wob->label_loc)? 0 : wob->label_size;      height =  rec->r_height - wob->label_size;    } else {      yoffset = 0;      height = rec->r_height;    }    at = (y - yoffset - (((me-1)*height)/n))/ystep;    if(at < 0) return(NULL);    if((w = cfi->first_word)) {      do {	if(w->plotted && (at-- <= 0))	  return(w);	w = w->next;      } while(w != cfi->first_word);    }    return(w);  } else    printf("Bogus chartfile passed to get_word_level()\n");  return(NULL);}/**********************************************************************/play_chart_entry(wob,time,y)     Wobject *wob;     double time;     int y;{  Chartfile *cf = get_chart_level(wob,y);  double ptime, ntime;  if(cf) {    Word *word = (Word*)get_word_level(cf,y);    double left, right;    if(word)  {      send_play_seg(wob->obj,(ptime = left_bound(word,time)),		    (ntime = right_bound(word,time)));      mark_window(wob->obj, ptime, ntime);    }  }    }/**********************************************************************//* redisplay the chart so that the symbol specified by str in chart cf will   be at the top of the chart display. */top_word(str,cf)     char *str;     Chartfile *cf;{  if(str && *str && cf && cf->first_word) {    Word *w = cf->first_word;    do {      if(!strcmp(str,w->str)) {	cf->first_word = w;	plot_chart(cf);	return(TRUE);      }      w = w->next;    } while(w != cf->first_word);  }  return(FALSE);}/**********************************************************************//* scroll() assumes that plot_charts() has been called at least once   so that the word-plotted flags will all have been set in the Chartfile   word list. */scroll(wob,time,y,up)     Wobject *wob;     double time;     int y, up;{  Chartfile *cf = get_chart_level(wob,y);  if(cf) {    Word *word = (Word*)get_word_level(cf,y);        if(word) {      if(debug_level)	fprintf(stderr,"scroll():Target word is %s\n",word->str);      if(up) {	cf->first_word = word;      } else {			/* Scroll down. */	Word *w = cf->first_word, *wp = word;	do {	  if(wp->plotted) {	    w = w->prev;	    while(! w->plotted && (w != cf->first_word)) w = w->prev;	  }	  wp = wp->prev;	} while(wp != cf->first_word);	cf->first_word = w;      }      if(debug_level)	fprintf(stderr,"scroll():First word is now %s\n",word->str);      plot_chart(cf);    }  }}/**********************************************************************/

⌨️ 快捷键说明

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