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

📄 wplay.c

📁 speech signal process tools
💻 C
📖 第 1 页 / 共 2 页
字号:
	if (!qflag)	  Fprintf(stderr,"play: start point: %ld, length:%ld, filename: %s\n",		  start_p,np,filename);		skiprec (istrm, start_p - 1, size_rec (ih));		if(debug_level) 	  Fprintf(stderr,"play: np = %ld, sf = %d\n",np,isf);	if((dataf = (float *)malloc((unsigned)np * sizeof FLOAT)) == NULL) {	  Fprintf(stderr,"Cannot alloc %ld floats\n",np);	  exit(1);	}		/*	 * Check data type and allocate shorts if possible	 */	data_type = get_sd_type(ih);	if(data_type == CHAR || data_type == SHORT){	  data = (short *)malloc((unsigned)np * sizeof SHORT);	  spsassert(data != NULL, "Cannot alloc SHORT buffer\n");	}	else{	  dataf = (float *)malloc((unsigned)np * sizeof FLOAT);	  spsassert(dataf != NULL, "Cannot alloc FLOAT buffer\n");	}			if ((get_genhd_val("max_value",ih,0) == 0) && iflag) {	  clip++; write_hfile=1;	  Fprintf(hfile,		  "Samples greater than %d will be clipped to this value\n",		  MAXDA);	  Fprintf(hfile,"Sample\toriginal value\n");	}	if (aflag && !gflag && !bflag && (get_genhd_val("max_value",ih,0) > MAXDA)) {	  gflag++;  	  write_hfile=1;	  gain = (float)MAXDA/ *get_genhd_d("max_value",ih);	  Fprintf(hfile,"hd.sd->max_value: %g\n",*get_genhd_d("max_value",ih));	  Fprintf(hfile,"This D/A MAXDA is %d\n",MAXDA);	  Fprintf(hfile,"Data scaled by %g\n",gain);	  if (!qflag) 	    Fprintf(stderr,"play: Data scaled by %g\n",gain);	}	        if(data_type == CHAR || data_type == SHORT){	  if ((i = get_sd_recs(data,np,ih,istrm)) != np) {	    if (i == 0) {	      Fprintf (stderr, "play: %s is empty!\n");	      exit (1);	    }	    else {	      if (!qflag) 		Fprintf (stderr, 		       "play: only %d points in %s\n", i, filename);	      np = i;	    }	  }	}	else{	  if ((i = get_sd_recf(dataf,np,ih,istrm)) != np) {	    if (i == 0) {	      Fprintf (stderr, "play: %s is empty!\n");	      exit (1);	    }	    else {	      if (!qflag) 		Fprintf (stderr, "play: only %d points in %s\n", i, filename);	      np = i;	    }	  }	}		(void) fclose (istrm);	if (clip) {	  if (data_type != CHAR && data_type != SHORT){            for (i=0; i<np; i++) {	      int j = abs((int)dataf[i]);	      if (j > MAXDA) {		Fprintf(hfile, "%d\t%d\n", i+2,j);		if(j > max) max = j;		if(dataf[i] < 0) dataf[i] = -MAXDA;		else dataf[i] = MAXDA;	      }	    }	  }	  else{            for (i=0; i<np; i++) {	      int j = abs((int)data[i]);	      if (j > MAXDA) {		Fprintf(hfile, "%d\t%d\n", i+2,j);		if(j > max) max = j;		if(data[i] < 0) data[i] = -MAXDA;		else data[i] = MAXDA;	      }	    }	  }	}	/* Wait for previous play to complete.  Then allocate old array. */	if (in_progress) {	  wait_for_end(devpn,(int)(2000.0*prev_np/prev_isf),data);	  if (!qflag)	    Fprintf(stderr,"previous transfer complete\n");	}	prev_np = np;	prev_isf = isf;	/* Allocate short buffer, if not already allocated */        if(data_type != CHAR && data_type != SHORT){	  if((data = (short *)malloc((unsigned)np*sizeof SHORT)) == NULL) {	    Fprintf(stderr,"Cannot alloc %ld shorts\n",np);	    exit(1);	  }	}		/* either, 1) multiply sample by gain factor (slow), 2) shift sample	   bits to right (faster), or 3) just copy sample (fastest)	   */	if(data_type != CHAR && data_type != SHORT)	  {	    if (gflag) 	      for (i=0; i<np; i++) data[i] = dataf[i]*gain;	    else if (bflag && left) 	      for (i=0; i<np; i++) data[i] = (int)dataf[i] << left;	    else if (bflag && right)	      for (i=0; i<np; i++) data[i] = (int)dataf[i] >> right;	    else	      for (i=0; i<np; i++) data[i] = dataf[i];	  }	else	  {	    if (gflag) 	      for (i=0; i<np; i++) data[i] = data[i]*gain;	    else if (bflag && left) 	      for (i=0; i<np; i++) data[i] = (int)data[i] << left;	    else if (bflag && right)	      for (i=0; i<np; i++) data[i] = (int)data[i] >> right;	  }		d_isf = isf;        if (aflag) {	  if (get_genhd_val("max_value",ih,0)!=0) 	    max = get_genhd_val("max_value",ih,0);	  else 	    max = MAXDA;	}		if (debug_level > 1) 	  pr_sarray("play", np, data);	 	if(!qflag) Fprintf(stderr,"play: Transfer starting\n");	        if (dsp_type == DSP32_FAB2){	   if(debug_level) fprintf(stderr,"calling dac_32..\n");	   (void)dac_32(NULL, data, (int)np, &d_isf, max);        }        else if (dsp_type == DSP32C_VME)	   (void)dac_32C(-1, data, (int)np, &d_isf, max);	else{	   spsassert(0,"dsp_type invalid");	}	        (void) free((char *)dataf);	in_progress = 1;        nptot += np;	if(nofile) break;        optind++;      }      nrep--;    }    wait_for_end(devpn,(np/isf)*2000,data);    if(!qflag) Fprintf (stderr, "play: final transfer complete\n");   /* write common file, unless the input was from a pipe or there   was more than one input file*/    if(filecount == 1 && strcmp(filename, "<stdin>") != 0) {    	(void) putsym_i("start",(int)start_p);    	(void) putsym_i("nan",(int)np);    	(void) putsym_s("filename",firstfile);    	(void) putsym_s("prog","play");	if(gflag) 	  (void)putsym_f("gain",gain);	else	  (void)putsym_f("gain", 1.0);	if(bflag) 	  (void)putsym_i("shift", bits);	else	  (void)putsym_i("shift", 0);    }    if(debug_level) Fprintf(stderr,"play: Total points output: %ld\n",nptot);    if(clip && max) Fprintf(hfile,"To avoid clipping use a gain of %g.\n",	(float)MAXDA/(float)abs(max));    if(clip && max && (hfile != stderr) && !qflag) 	Fprintf(stderr,"play: To avoid clipping use a gain of %g.\n",	(float)MAXDA/(float)abs(max));    (void) fclose(hfile);     if(!write_hfile && (hfile != stderr)) (void)unlink(hist);    return 0;}wait_for_end (devpn,arg_wt,data)int devpn, arg_wt;short *data;{    if (data != NULL)	(void) free((char *)data);}char *sd_open(prog_name, file_name, header, stream)    char    *prog_name,	    *file_name;    struct header   **header;    FILE    **stream;{    int fd;     Header *wh = NULL;    Signal *sig;    if (strcmp(file_name, "-") != 0)    {	if ((*stream = fopen(file_name, "r")) == NULL)	{	    Fprintf(stderr, "%s: can't open ", prog_name);	    perror(file_name);	    exit(1);	}    }    else    {	file_name = "<stdin>";	*stream = stdin;    }            if ((*header = read_header(*stream)) == NULL) {            if (*stream == stdin) {		Fprintf(stderr, "%s: stdin is not an ESPS file.\n", prog_name);	exit(1);      }      else  /*try reading as SIGnal file*/ {	(void) fclose(*stream);	fd = open(file_name, O_RDONLY);		if (!(wh = (Header*) get_header(fd))) {	  Fprintf(stderr,	       "%s: input is not an ESPS or SIGnal file\n",	       prog_name);	  exit(1);	}	if (!(sig =	      (Signal*) new_signal(file_name,fd,wh, (caddr_t) NULL,0,0.0,0))) {	  Fprintf(stderr, "%s: couldn't create signal for SIGnal file\n",		  prog_name);	  exit(1);	}	if ((sig->type & VECTOR_SIGNALS) != P_SHORTS) {	  Fprintf(stderr, "%s: SIGnal file not 1D shorts\n",		  prog_name);	  exit(1);	}	/* ok, got playable SIGnal file */	if (debug_level)	  Fprintf(stderr, "%s: read SIGnal P_SHORTS header\n", prog_name);	*stream = fdopen(fd, "r");	if (!*stream) {	  Fprintf(stderr, 		  "%s: couldn't make stream for SIGnal ile descriptor.\n",		  fd);	  exit(1);	}	if (debug_level) 	  Fprintf(stderr, "%s: making ESPS SD header for SIGnal file\n",		  prog_name);	*header = new_header(FT_FEA);        (void) init_feasd_hd(*header, SHORT, (int) 1,                       &sig->start_time, (int) 0, (double) sig->freq);        *add_genhd_d("max_value", (double *) NULL, 1, *header) = 		MAX(fabs(*sig->smax),fabs(*sig->smin));	(*header)->common.ndrec = 	  sig->freq * (sig->end_time - sig->start_time);	if ((*header)->common.ndrec == 0) 	  (*header)->common.ndrec = 10*sig->freq;	if (debug_level) 	  Fprintf(stderr, "%s: sf = %g, ndrec = %ld, max_value = %g\n",		  prog_name, *get_genhd_d("record_freq",*header),		  (*header)->common.ndrec, *get_genhd_d("max_value",*header));      }          }    else {  /*original input was ESPS file*/	struct header *sdtofea();      if (debug_level) 	Fprintf(stderr, "%s: got ESPS SD header\n", prog_name);      if ((*header)->common.type != FT_SD  &&	 ((*header)->common.type != FT_FEA && 		(*header)->hd.fea->fea_type != FEA_SD)) {   	Fprintf(stderr, "%s: %s is not an ESPS SD file.\n",		prog_name, file_name);	exit(1);      }      if ((*header)->common.type == FT_SD) 	*header = sdtofea(*header);    }    return file_name;}void  set_pvd(hdr)    struct header   *hdr;{  /*this function does nothing - it's needed owing to the      convoluted waves library, which needs to be straightened out*/}void pr_sarray(name, n, arr)     long    n;     short  *arr;{  int     i;    Fprintf(stderr, "%s:  -- playing %d points:\n", name, n);  for (i = 0; i < n; i++)    {      Fprintf(stderr, "%d ", arr[i]);      if (i%5 == 4 || i == n - 1) Fprintf(stderr,  "\n");    }}dsp32c_is_available(){  int dc2;  int dc = open("/dev/dc00",O_RDWR,0);  if(dc > 0) {    close(dc);    dc2 = dcopen("/dev/dc00");    if(dc2 > 0) {      close(dc2);      return(1);    }  }  return(0);}

⌨️ 快捷键说明

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