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

📄 copyana.c

📁 speech signal process tools
💻 C
字号:
/*   This material contains proprietary software of Entropic Processing, Inc.     Any reproduction, distribution, or publication without the the prior	     written permission of Entropic Processing, Inc. is strictly prohibited.  Any public distribution of copies of this work authorized in writing by  Entropic Processing, Inc. must bear the notice			 								               "Copyright 1986 Entropic Processing, Inc." 				 	   This program copies selected portions of an ana file   to a new ana file, or appends to an existing ana file.      */#ifdef SCCSstatic char *sccs_id = "@(#)copyana.c	1.11 3/20/87 EPI";#define VERSION "1.11"#define DATE "3/20/87"#endif#ifndef VERSION#define VERSION "debug"#endif#ifndef DATE#define DATE "none"#endif#include <stdio.h>#include <sps/sps.h>#include <sps/ana.h>#define SYNTAX USAGE ("copyana [-x debug-level] -f -h [-N #_of_pulses] [-n range] [-{vu}] [-O{+-}power_level] infile outfile")main(argc, argv)int argc;char **argv;{	int getopt();	extern optind;	extern char *optarg, *mktemp(), *get_cmd_line();	FILE *f1strm, *f2strm, *tstrm, *fopen();	struct header *f1hd, *f2hd;	struct ana_data *rec;	char *f1name, *f2name, *range, *strcpy();	char *template = "/usr/tmp/cpaXXXXXX";	double atof(), power_level;	int debug=0, vflag=0, uflag=0, Oflag=0, Nflag = 0, rec_count=0;	int c, size_rec(), i, j, s_rec, e_rec, n_rec, reject=0;	int Iflag=0, Pflag=0, pflag=0, Eflag=0, eflag=0, Rflag=0, rflag=0;	int Sflag=0, sflag=0, Cflag=0, cflag=0, zflag=0;	int new_file=0, set_start=0, num_pulses;	int fast=0, nohead=0;		while ((c = getopt(argc,argv,"x:fhn:N:vuO:I:P:E:R:p:e:r:S:s:C:c:z")) != EOF)        {	 switch (c) {		case 'x':		 debug++;		 break;		case 'n':		 range = optarg;		 break;		case 'N':		 Nflag++;		 num_pulses = atof (optarg);		 if(debug) fprintf(stderr, "copyana: Num_of_pulses: %lg\n",			           num_pulses);		 break;	   	case 'v':		 vflag++;		 break;		case 'u':		 uflag++;		 break;		case 'O':		 Oflag++;		 power_level = atof (optarg);		 if(debug) fprintf(stderr,"copyana: power_level: %lg\n",					   power_level);		 break;		case 'I':		 Iflag++;		 break;		case 'P':		 Pflag++;		 break;		case 'E':		 Eflag++;		 break;		case 'R':		 Rflag++;		 break;		case 'p':		 pflag++;		 break;		case 'e':		 eflag++;		 break;		case 'r':		 rflag++;		 break;		case 'S':		 Sflag++;		 break;		case 'C':		 Cflag++;		 break;		case 's':		 sflag++;		 break;		case 'c':		 cflag++;		 break;		case 'z':		 zflag++;		 break;		case 'f':		 fast++;	        case 'h':		 nohead++;		 break;	 	default:		 SYNTAX;	 }        }	if (Pflag || Eflag || Rflag || pflag || eflag || rflag || Sflag ||	    sflag || Cflag || cflag || Iflag) {	 fprintf(stderr,		 "The -I and -{PERperSsCc} options are not implemented yet\n");	 exit(1);	}	if (uflag != 0 && vflag != 0) {	 fprintf(stderr,"copyana: cannot use both u and v flag\n");	 exit(1);	}	if (argc - optind < 2) {	 fprintf(stderr,"copyana: missing file names\n");	 SYNTAX;	}	f1name = argv[optind++];	TRYOPEN("copyana",f1name,"r",f1strm);	if(debug)	 fprintf(stderr,"copyana: input file: %s\n",f1name);	if (!(f1hd = read_header(f1strm)))	 NOTSPS("copyana", f1name);	if (f1hd->common.type != FT_ANA) {	 fprintf(stderr,"copyana: %s is not a ANA file.\n",f1name);	 exit(1);	}/* zflag is a hack to fix up some ANA files that have -1 as the src_sf*/        if (zflag && (f1hd->hd.ana->src_sf == -1)) f1hd->hd.ana->src_sf = 8000;	f2name = argv[optind];	if (strcmp(f1name,f2name) == 0) {	 fprintf(stderr,"copyana: file1 and file2 cannot be the same.\n");	 exit(1);	}	if ((f2strm = fopen(f2name,"r")) != NULL) { /* see if file is there */	 if (!(f2hd = read_header(f2strm)))   /* it does, read it into temp */	   NOTSPS("copyana", f2name);	 if (f2hd->common.type != FT_ANA) {	  fprintf(stderr,"copyana: %s is not an ANA file.\n",f2name);	  exit(1);	 }         if((f1hd->hd.ana->order_vcd != f2hd->hd.ana->order_vcd) ||	    (f1hd->hd.ana->order_unvcd != f2hd->hd.ana->order_unvcd) ||	    (f1hd->hd.ana->maxraw != f2hd->hd.ana->maxraw) ||	    (f1hd->hd.ana->maxlpc != f2hd->hd.ana->maxlpc) ||	    (f1hd->hd.ana->maxpulses != f2hd->hd.ana->maxpulses)) {	    fprintf(stderr,	     "copyana: this version requires that maxraw, maxlpc, and maxpulses be the same\n");	    exit(1);	  }	 /*This test doesn't work quite right.   Its commented out until we fix it.	 if (strcmp(f1hd->common.hdvers,f2hd->common.hdvers) != 0) {	    fprintf(stderr,	     "copyana: input and output files have different\n");	    fprintf(stderr,    	     "copyana: versions of the SPS header.  Cannot do a fast copy.\n");	    fast=0;	 }*/	  rec = allo_ana_rec(f2hd);	  if(!fast) { /* copy the file to a temp */	    if ((tstrm = fopen(mktemp(template),"w")) == NULL)	     CANTOPEN("copyana",template);	    for (i=0;i<f2hd->common.ndrec; i++) {	     if(get_ana_rec(rec,f2hd,f2strm) == EOF) {	      fprintf(stderr,"copyana: EOF on %s\n",f2name);	      break; 	     }	     rec_count++;	     put_ana_rec(rec,f2hd,tstrm);	    }	  (void) fclose(f2strm);	  }	  else { /* fast flag is set,   append selected records to the output file */	    (void) fclose(f2strm);	    tstrm = fopen(f2name,"a+");/* ugly hack to fix r+ on SYS 5.2	    tstrm->_flag |= _IOWRT;*/	  }        }	else {  	/* file doesn't exist */ 	 fast=0;	/* reset fast flag if on */	 if ((tstrm = fopen(mktemp(template),"w")) == NULL)	   CANTOPEN("copyana",template);	 f2hd = copy_header(f1hd);	 new_file = 1;	 set_start = 1;	/* flag to cause tag of first rec to go into start */	 f2hd->hd.ana->nan = 0;	 rec = allo_ana_rec(f1hd);	}	if (!fast) {	 if (!nohead)	  (void) add_source_file(f2hd,f1name,f1hd);	 else	  (void) add_source_file(f2hd,f1name,NULL);	}		s_rec = 1;	e_rec = f1hd->common.ndrec;	(void) range_switch (range, &s_rec, &e_rec, 1);	if(debug)	 fprintf(stderr,"copyana: s_rec: %d, e_rec: %d\n",s_rec,e_rec);	if(e_rec > f1hd->common.ndrec) {	 fprintf(stderr,"copyana: only %d records in file.\n",			f1hd->common.ndrec);	 e_rec = f1hd->common.ndrec;	}	(void) skiprec(f1strm, s_rec-1, size_rec(f1hd));	n_rec = e_rec - s_rec + 1;	for (i=0; i < n_rec; i++) {	 if(get_ana_rec(rec,f1hd,f1strm) == EOF) {	    fprintf(stderr,"copyana: EOF on %s\n",f1name);	    break; 	 }	 reject=0;	 if (vflag && (rec->p_pulse_len[0] == 0)) reject++;	 if (uflag && (rec->p_pulse_len[0] != 0)) reject++;         if (Oflag) {          double pow_sum = 0;	  for(j=0; (j < f1hd->hd.ana->maxraw && rec->raw_power[j]>=0); j++) {	   pow_sum  += rec->raw_power[j];	  }	  if (power_level > 0) {	   if (pow_sum < power_level) reject++;	  }	  else {	   if (pow_sum > (-power_level)) reject++;	  } 	 } /*add number of pulses stuff*/	 if(Nflag != 0) {		int pulse_cnt = 0;		for(j=0; j<f1hd->hd.ana->maxpulses && rec->p_pulse_len[j] != 0; j++) {			pulse_cnt++;		}		if(pulse_cnt != num_pulses)			reject++;	} 	 if(reject == 0) {	  rec_count++;	  if(set_start && new_file) {		f2hd->hd.ana->start = rec->tag;		set_start=0;	  }	  if(new_file) f2hd->hd.ana->nan += rec->frame_len;	  put_ana_rec(rec,f1hd,tstrm);	 }	}	if(fast) {	 rewind(tstrm);	 f2hd->common.ndrec += rec_count;	 (void) write_header(f2hd,tstrm);	 (void) fclose(tstrm);	}	else {	 TRYOPEN("copyana",f2name,"w",f2strm);	 (void) strcpy(f2hd->common.prog, "copyana");	 (void) strcpy(f2hd->common.vers, VERSION);	 (void) strcpy(f2hd->common.progdate, DATE);	 if (!nohead)	  (void) add_comment (f2hd, get_cmd_line(argc,argv));	 f2hd->common.ndrec = rec_count;	 if(debug) fprintf(stderr,"copyana: ndrec: %d\n",f2hd->common.ndrec);	 if(!new_file) {		/* make some header items invalid */	  f2hd->hd.ana->start = -1;	  f2hd->hd.ana->nan = -1; 	  f2hd->hd.ana->frmlen = -1;	  f2hd->hd.ana->p_offset = -1;	  f2hd->hd.ana->piq_method = NONE;	  f2hd->hd.ana->rcq_method = NONE;	  f2hd->hd.ana->pwq_method = NONE;  	  f2hd->hd.ana->lpq_method = NONE;	  f2hd->hd.ana->win_type = NONE;	  f2hd->hd.ana->a_method = NONE;	  f2hd->hd.ana->dcrem = -1;	  f2hd->hd.ana->psynch = NONE;	  f2hd->hd.ana->matsiz = -1;	  f2hd->hd.ana->rms_fullscale = -1;	  f2hd->hd.ana->sinc_flg = NONE;	  if(f2hd->hd.ana->src_sf != f1hd->hd.ana->src_sf)		 f2hd->hd.ana->src_sf = -1;	 }	 (void) write_header(f2hd,f2strm);         (void) fclose(tstrm);	 tstrm = fopen(template,"r");	 while (rec_count > 0) {	  if ((get_ana_rec(rec,f2hd,tstrm)) == EOF) {	   fprintf(stderr,"copyana: internal error, eof on temp file\n");	   break;	  }	  put_ana_rec(rec,f2hd,f2strm);	  rec_count--;	 }  	 (void) unlink(template); 	 (void) fclose(f2strm);       }}

⌨️ 快捷键说明

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