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

📄 paste.c

📁 speech signal process tools
💻 C
📖 第 1 页 / 共 2 页
字号:
      unlink_signal(s);      snew->others = ((Object*)snew->obj)->signals;      ((Object*)snew->obj)->signals = snew;      s->views = NULL;      free_signal(s);      while(v) {	v->sig = snew;	v = v->next;      }      update_window_titles(snew);      v = snew->views;      while(v) {	v->lmarker_time = lc_time;	v->rmarker_time = rc_time;	v->cursor_time = lc_time;	if(v->start_time < snew->start_time)	  v->start_time = snew->start_time;	if((diff = ET(v) - SIG_END_TIME(snew)) > 0.0)	  v->start_time -= diff;	start = v->start_time;	page_time = ET(v) - start;	get_view_segment(v,&start,&page_time);	plot_view(v);	v = v->next;      }      if(new_files.list) ((Menu_list*)new_files.list)->active = FALSE;      if(add_to_menu_list(&new_files.list, snew->name))	((Menu_list*)new_files.list)->active = TRUE;      if(new_files.canvas) menu_redoit(new_files.canvas, NULL, NULL);      return(TRUE);    }  } else {    show_notice(1,"No destination signal, or source signal is not defined in paste");  }  return(FALSE);}	  compatable(s1,s2)     Signal *s1, *s2;{  if(((s1->type & ~SIG_FORMAT) == (s2->type & ~SIG_FORMAT)) &&     ((s1->freq == s2->freq) || (IS_TAGGED_FEA(s1) && IS_TAGGED_FEA(s2))) &&     (s1->dim == s2->dim) ) return(TRUE);  return(FALSE);}/*********************************************************************/Signal *insert_signal(s1,s2,time)     Signal *s1, *s2;     double time;{  Signal * tag_insert_signal();  /* Assumes s1 and s2 are both on disc; creates a new signal for the   paste-up and returns a pointer to this new signal. s1 and s2 remain   unchanged, except for their buffer positions. */  if(IS_TAGGED_FEA(s1))    return(tag_insert_signal(s1,s2,time));  if(compatable(s1,s2) && (time >= s1->start_time) &&     (time <= SIG_END_TIME(s1))) {    char    tname[300], mess[200];    Signal  *stmp;    double  rtime, wtime, rinc, smax, smin, amax, amin, half_samp;    int	    fd_tmp, skip_tmp, bs, s2start;    Header  *hdr_tmp;        sprintf(tname,"%sXXXXXX",s1->name);	/* temp name for constructing output */    /* Duplicate header and structure of sink file. */    if((stmp = new_signal(mktemp(tname),SIG_NEW,dup_header(s1->header),NULL,			 s1->file_size+s2->file_size,s1->freq,s1->dim))) {      clone_methods(stmp,s1);      head_scanf(s1->header,"maximum",&smax);      head_scanf(s1->header,"minimum",&smin);      head_scanf(s2->header,"maximum",&amax);      head_scanf(s2->header,"minimum",&amin);      if(smax > amax) amax = smax;      if(smin < amin) amin = smin;      head_printf(stmp->header,"maximum",&amax);      head_printf(stmp->header,"minimum",&amin);      sprintf(mess,"insert_signal: source %s sink %s time %f",s2->name,	      s1->name,time);      head_printf(stmp->header,"operation",mess);      /* Output size is combined size of inputs. */      stmp->file_size = stmp->buff_size;      stmp->buff_size = 0;	/* Indicate current buffer is empty. */      head_printf(stmp->header,"samples",&(stmp->file_size));       if(time <= s1->start_time) { /* Initial samples from source or sink? */	time = s1->start_time;	stmp->start_time = s2->start_time;	s2start = TRUE;		/* from source */	head_printf(stmp->header,"start_time",&(stmp->start_time));      } else	s2start = FALSE;	/* from sink */      stmp->end_time = stmp->start_time + SIG_DURATION(s1) + SIG_DURATION(s2);      head_printf(stmp->header,"end_time",&(stmp->end_time));      if (stmp->header	  && stmp->header->magic == ESPS_MAGIC	  && stmp->header->esps_hdr)      {	  struct header	*hdr;	  hdr = stmp->header->esps_hdr = copy_header(stmp->header->esps_hdr);	  set_pvd(hdr);	  add_comment(hdr, "xwaves ");	  strcat(mess, "\n");	  add_comment(hdr, mess);	  *(genhd_type("start_time", (int *) NULL, hdr) == DOUBLE	    ? get_genhd_d("start_time", hdr)	    : add_genhd_d("start_time", (double *) NULL, 1, hdr)	    ) = stmp->start_time;	  *(genhd_type("end_time", (int *) NULL, hdr) == DOUBLE	    ? get_genhd_d("end_time", hdr)	    : add_genhd_d("end_time", (double *) NULL, 1, hdr)	    ) = stmp->end_time;      }      if(output_header(stmp)) {	half_samp = 0.5/stmp->freq; /* Find a reasonable error margin. */	stmp->start_samp = 0;	bs = 0;	if(!s2start)	/* Output starts with samples from sink file. */	  for(rtime=stmp->start_time, rinc=10.0;	      rtime+half_samp < time; rtime += rinc) {	    if((rtime+rinc) > time) rinc = time - rtime;	    if(rinc > 0.0) {	      if(s1->utils->read_data(s1,rtime,rinc)) {		bs = s1->buff_size;		rinc = BUF_DURATION(s1);		fd_tmp = s1->file;		s1->file = stmp->file;		skip_tmp = s1->bytes_skip;		s1->bytes_skip = stmp->bytes_skip;			/* keep s1->header->strm consistent with s1->file */		hdr_tmp = s1->header;		s1->header = stmp->header;		if(debug_level)		  fprintf(stderr,"w1:rtime:%f rinc:%f st:%f et:%f\n",			rtime,rinc,s1->start_time,s1->end_time);		if(!s1->utils->write_data(s1,rtime,rinc)) {		  close_sig_file(s1);		  s1->file = fd_tmp;		  s1->bytes_skip = skip_tmp;			/* keep s1->header->strm consistent with s1->file */		  s1->header = hdr_tmp;		  printf("write_data() error1 in insert_signal()\n");		  free_signal(stmp);		  return(NULL);		}		s1->file = fd_tmp;		s1->bytes_skip = skip_tmp;			/* keep s1->header->strm consistent with s1->file */		s1->header = hdr_tmp;	      } else {		printf("read_data() problems1 in insert_signal()\n");		free_signal(stmp);		return(NULL);	      }	    }	  }	/* Finished transferring initial part of sink file. */	close_sig_file(s1);		/* Now transfer all of the source file. */	stmp->start_samp = s1->start_samp + bs;	/* = tot of s1 sams written */	for(wtime=stmp->start_time + (time - s1->start_time),	    rtime=s2->start_time, rinc=10.0;	    rtime+half_samp < SIG_END_TIME(s2); rtime += rinc, wtime += rinc) {	  if(s2->utils->read_data(s2,rtime,rinc)) {	    rinc = BUF_DURATION(s2);	    stmp->data = s2->data;	    stmp->buff_size = s2->buff_size;	    if(debug_level)	      fprintf(stderr,"w2:wtime:%f rinc:%f st:%f et:%f\n",		    wtime,rinc,stmp->start_time,stmp->end_time);	    if(!stmp->utils->write_data(stmp,wtime,rinc)) {	      printf("write_data() error2 in insert_signal()\n");	      stmp->data = NULL;	      free_signal(stmp);	      return(NULL);	    }	    stmp->start_samp += stmp->buff_size;	  } else {	    printf("read_data() problems2 in insert_signal()\n");	    stmp->data = NULL;	    free_signal(stmp);	    return(NULL);	  }	}	close_sig_file(s2);	/* Finished transferring source file. */	/* Finally, transfer the remainder of the sink file. */	for(rtime=time, rinc=10.0;	    rtime+half_samp < SIG_END_TIME(s1);	    rtime += rinc, wtime += rinc) {	  if(s1->utils->read_data(s1,rtime,rinc)) {	    rinc = BUF_DURATION(s1);	    stmp->data = s1->data;	    stmp->buff_size = s1->buff_size;	    if(debug_level)	      fprintf(stderr,"w3:wtime:%f rinc:%f st:%f et:%f\n",	           wtime,rinc,stmp->start_time,stmp->end_time);	    if(!stmp->utils->write_data(stmp,wtime,rinc)) {	      printf("write_data() error3 in insert_signal()\n");	      stmp->data = NULL;	      free_signal(stmp);	      return(NULL);	    }	    stmp->start_samp += stmp->buff_size;	  } else {	    printf("read_data() problems3 in insert_signal()\n");	    stmp->data = NULL;	    free_signal(stmp);	    return(NULL);	  }	}	stmp->buff_size = 0;	stmp->data = NULL;	stmp->start_samp = 0;	close_sig_file(s1);	close_sig_file(stmp);	return(stmp);      } else	printf("output_header() failure in insert_signal()\n");    } else      show_notice(1,"Can't create a new signal in insert_signal");  } else {    sprintf(notice_msg,        "Incompatible signals (%s %s) or bad insert time (%f) in insert_signal",	s1->name,s2->name,time);    show_notice(1,notice_msg);    }  return(NULL);}

⌨️ 快捷键说明

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