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

📄 tag_methods.c

📁 speech signal process tools
💻 C
📖 第 1 页 / 共 2 页
字号:
    {	struct header  *new_hdr;	int points;	double ssf;		if((ssf = get_genhd_val("src_sf",s->header->esps_hdr,-1.0)) <= 0.0) {	  show_notice(0,	     "Warning: src_sf not present in tagged file; guessing 8kHz");	  ssf = 8000.0;	}		if(ssf != s->freq)	  points = 0.5 + (ssf * duration);	else	  points = s->file_size;		new_hdr = copy_header(so->header->esps_hdr);	so->header->esps_hdr = new_hdr;	set_pvd(new_hdr);	add_comment(new_hdr, "xwaves ");	strcat(comment, "\n");	add_comment(new_hdr, comment);	*(genhd_type("nan", (int *) NULL, new_hdr) == LONG	  ? get_genhd_l("nan", new_hdr)	  : add_genhd_l("nan", (long *) NULL, 1, new_hdr)	  ) = points;	*(genhd_type("start_time", (int *) NULL, new_hdr) == DOUBLE	  ? get_genhd_d("start_time", new_hdr)	  : add_genhd_d("start_time", (double *) NULL, 1, new_hdr)	  ) = start_time;	*(genhd_type("end_time", (int *) NULL, new_hdr) == DOUBLE	  ? get_genhd_d("end_time", new_hdr)	  : add_genhd_d("end_time", (double *) NULL, 1, new_hdr)	  ) = so->end_time;    }    if((BUF_START_TIME(s) <= start_time) &&       (BUF_END_TIME(s) >= (start_time + duration))) {      if(!(so->data =	   (caddr_t)(dpp = (char**)malloc(sizeof(char*) * s->dim)))) {	printf("Allocation problems in tag_save_seg()\n");	free_signal(so);	return(FALSE);      }      i = time_to_index(s,start_time);      dppi = (char**)(s->data);      for(j=0; j < s->dim; j++)	/* new pointer array for signal subsegment */	dpp[j] = dppi[j] + element_size(s, j) * i;      so->x_dat = s->x_dat + i;      so->start_samp = 0;      so->file_size = so->buff_size = time_to_index(s,etr) - i + 1;      get_maxmin(so);      head_printf(so->header,"operation",comment);      head_printf(so->header,"samples", (char *) &n);      head_printf(so->header,"version", (char *) &(so->version));      head_printf(so->header,"start_time", (char *) &start_time);      head_printf(so->header,"end_time", (char *) &(so->end_time));      head_printf(so->header,"maximum", (char *) &(*so->smax));      head_printf(so->header,"minimum",(char *) &(*so->smin));      head_printf(so->header,"time",get_date());      if(!(i = put_signal(so)))	printf("put_signal() problems in tag_save_seg()\n");      free(so->data);      so->data = NULL;      so->x_dat = NULL;      free_signal(so);      return(i);    } else {			/* must do read/write transfers */      extern int max_buff_bytes;	/* defined in globals.c */      double      ts, dur, amax, amin, tstep, st;      int         bsize;      bsize = s->buff_size; /* make chunks approx. equal to current source */      tstep = BUF_DURATION(s);      /* First, read over the data and find max and min. */      for(amax = *s->smin, amin = *s->smax, dur=duration, ts=tstep,	  st=start_time ;	  dur > 0;) {	if(ts > dur) ts = dur;	if(ts > 0.5/so->freq) { /* more than 1/2 sample interval? */	  if(s->utils->read_data(s,st,ts)) {	    get_maxmin(s);	    if(*s->smin < amin) amin = *s->smin;	    if(*s->smax > amax) amax = *s->smax;	  } else {	    printf("read_data() error in tag_save_seg()\n");	    return(FALSE);	  }	  dur -= BUF_DURATION(s);	  st += BUF_DURATION(s);	}      }      head_printf(so->header,"operation",comment);      head_printf(so->header,"samples", (char *) &n);      head_printf(so->header,"version", (char *) &(so->version));      head_printf(so->header,"start_time",  (char *) &start_time);      head_printf(so->header,"end_time",  (char *) &(so->end_time));      head_printf(so->header,"maximum", (char *) &amax);      head_printf(so->header,"minimum", (char *) &amin);      head_printf(so->header,"time",get_date());      if(!output_header(so)) {	printf("Problems with header or file open in tag_save_seg()\n");	return(FALSE);      }    /* Now do the real read/write transfers. */      for(so->start_samp = 0, dur=duration, ts=tstep ; dur > 0; ) {	if(ts > dur) ts = dur;	if(ts > 0.5/so->freq) { /* more than 1/2 sample interval? */	  if(s->utils->read_data(s,start_time,ts)) {	    so->data = s->data;	    so->x_dat = s->x_dat;	    so->buff_size = s->buff_size;	    if(so->utils->write_data(so,start_time,ts))	      so->start_samp += so->buff_size;	    else {	      printf("write_data() error in tag_save_seg()\n");	      return(FALSE);	    }	  } else {	    printf("read_data() error in tag_save_seg()\n");	    return(FALSE);	  }	  dur -= BUF_DURATION(so);	  start_time += BUF_DURATION(so);	}      }      so->data = NULL;	/* NOTE: so->data was == s->data (don't free)*/      so->x_dat = NULL;      free_signal(so);      if(s->views) 	read_data(s,s->views->start_time,		  ET(s->views) - s->views->start_time);      close_sig_file(s);      return(TRUE);    }  } else    printf("Can't create a scratch buffer signal in tag_save_seg()\n");  return(FALSE);}/*********************************************************************/Signal *tag_insert_signal(s1,s2,time)     Signal *s1, *s2;     double time;{  /* Assumes s1 and s2 are both on disc and that both are tagged filed;     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(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,            ssf = 8000.0;    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,"tag_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;	  int points;	  if((ssf = get_genhd_val("src_sf",s1->header->esps_hdr,-1.0)) <= 0.0) {	    show_notice(0,	     "Warning: src_sf not present in tagged file; guessing 8kHz");	    ssf = 8000.0;	  }	  if(ssf != stmp->freq)	    points = 0.5 + (ssf * (stmp->end_time - stmp->start_time));	  else	    points = s1->file_size + s2->file_size;	  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("nan", (int *) NULL, hdr) == LONG	    ? get_genhd_l("nan", hdr)	    : add_genhd_l("nan", (long *) NULL, 1, hdr)	    ) = points;	  *(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)) {	if(s1->file_size > 1)	  half_samp = 0.5 * SIG_DURATION(s1)/s1->file_size;	else	  half_samp = 1.0/ssf;	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;		if((rinc = BUF_DURATION(s1)) > 0.0) {		  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 t1:%f et:%f\n",			  rtime,rinc,s1->start_time,s1->x_dat[0],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 tag_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		  break;	      } else {		printf("read_data() problems1 in tag_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)) {	    if((rinc = BUF_DURATION(s2)) > 0.0) {	      if(s2->x_dat) {	/* Offset the tags correctly */		register double correct = wtime - s2->start_time, *dp = s2->x_dat,		*tp = (double*)malloc(sizeof(double)*s2->buff_size);		int i;		for(i=0, stmp->x_dat = tp; i < s2->buff_size; i++)		  *tp++ = *dp++ + correct;	      }	      stmp->data = s2->data;	      stmp->buff_size = s2->buff_size;	      if(debug_level)		fprintf(stderr,"w2:wtime:%f rinc:%f st:%f t1:%f et:%f\n",		      wtime,rinc,stmp->start_time,stmp->x_dat[0],stmp->end_time);	      if(!stmp->utils->write_data(stmp,wtime,rinc)) {		printf("write_data() error2 in tag_insert_signal()\n");		stmp->data = NULL;		free_signal(stmp);		return(NULL);	      }	      if(stmp->x_dat) {		free(stmp->x_dat);		stmp->x_dat = NULL;	      }	      stmp->start_samp += stmp->buff_size;	    } else	      break;	  } else {	    printf("read_data() problems2 in tag_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)) {	    if((rinc = BUF_DURATION(s1)) > 0.0) {	      stmp->data = s1->data;	      stmp->buff_size = s1->buff_size;	      if(s1->x_dat) {	/*Offset the tags correctly*/		register double correct = wtime - s1->x_dat[0], *dp = s1->x_dat,		*tp = (double*)malloc(sizeof(double)*s1->buff_size);		int i;		for(i=0, stmp->x_dat = tp; i < s1->buff_size; i++)		  *tp++ = *dp++ + correct;	      }	      if(debug_level)		fprintf(stderr,"w3:wtime:%f rinc:%f st:%f t1:%f et:%f\n",		      wtime,rinc,stmp->start_time,stmp->x_dat[0],stmp->end_time);	      if(!stmp->utils->write_data(stmp,wtime,rinc)) {		printf("write_data() error3 in tag_insert_signal()\n");		stmp->data = NULL;		free_signal(stmp);		return(NULL);	      }	      if(stmp->x_dat) {		free(stmp->x_dat);		stmp->x_dat = NULL;	      }	      stmp->start_samp += stmp->buff_size;	    } else	      break;	  } else {	    printf("read_data() problems3 in tag_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 tag_insert_signal()\n");    } else      show_notice(0,"Can't create a new signal in tag_insert_signal");  } else {    sprintf(notice_msg,    "Incompatible signals (%s %s) or bad insert time (%f) in tag_insert_signal",	   s1->name,s2->name,time);    show_notice(1,notice_msg);  }  return(NULL);}

⌨️ 快捷键说明

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