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

📄 copysd.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 sd file   to a new sd file.   It can also be used to change the type of   a file.     Man page by Dave Burton, Program by Alan Parker */#ifdef SCCSstatic char *sccs_id = "@(#)copysd.c	1.15	6/18/87	ESI";#define VERSION "1.15"#define DATE "6/18/87"#endif#ifndef VERSION#define VERSION "debug"#endif#ifndef DATE#define DATE "none"#endif#include <stdio.h>#include <esps/esps.h>#include <esps/sd.h>#include <math.h>     /* because I use fabs() */#define SYNTAX USAGE ("copysd [-x debug-level] [-r range] [-d type] [-s scale] [-o] file1 [file2 ...] outfile")#define PARAM "params"#define SIZE 1024extern  int optind;char *optarg, *mktemp (), *get_cmd_line();char *strcpy();double atof();void exit(), lrange_switch();void set_sd_type();main (argc, argv)int     argc;char  **argv;{    int     getopt (), c, first = 1;    FILE    *in = stdin, *out = stdout, *tstrm;    struct  header  *ih, *oh;    int     i = 0,  debug = 0, oflag = 0, dflag = 0, n, qflag=0,            nofile=0, down_size=0, in_type=0;    long    n_rec, s_rec, e_rec, total_rec=0;    char    *range=NULL, type,  *ifile=NULL, *ofile, combuf[100];    char    *template = "/usr/tmp/cpXXXXXX";    double  scale=0, dbuf[SIZE], maxvalue = 0;    float   first_sf;     while ((c = getopt (argc, argv, "x:r:d:os:q")) != EOF) {	switch (c) {	    case 'x': 		debug++;		break;	    case 'r': 		range = optarg;		break;	    case 'd': 		dflag++;		type = optarg[0];		break;	    case 'o': 		oflag++;		break;	    case 's': 		scale = atof (optarg);		break;	    case 'q':		qflag++;		break;	}    }    if (argc - optind < 1) 	SYNTAX;    ofile = argv[argc - 1];    if (strcmp (ofile, "-") == 0)	ofile = "<stdout>";    else 	TRYOPEN (argv[0], ofile, "w", out);    if (argc - optind < 2)	nofile = 1;    else	ifile = argv[optind];    read_params(NULL,SC_CHECK_FILE,ifile);    if(nofile) {	if(symtype("filename") == ST_UNDEF) {	 Fprintf(stderr,"copysd: no input file\n");	 exit(1);	}    }    first = 1;    while (optind < argc - 1 || nofile) {	if (nofile) 	   ifile = getsym_s("filename");	else	  ifile = argv[optind];	if (strcmp (ifile, "-") == 0) {	    ifile = "<stdin>";	    in = stdin;	}	else	    TRYOPEN (argv[0], ifile, "r", in);	if (!(ih = read_header (in)))	    NOTSPS ("copysd:", ifile);	if (ih -> common.type != FT_SD) {	    Fprintf (stderr, "copysd:  %s not a sampled data file.\n", ifile);	    exit (1);	}	s_rec = 1;	e_rec = ih -> common.ndrec;	if (first) {	  if(symtype("start") != ST_UNDEF) 	      s_rec = getsym_i("start");	  if(symtype("nan") != ST_UNDEF)	      e_rec = s_rec + getsym_i("nan") - 1;	}	(void) lrange_switch (range, &s_rec, &e_rec, 1);        if (in != stdin && out != stdout) {	    (void)putsym_s("filename",ifile);	    (void)putsym_s("prog",argv[0]);	    (void)putsym_i("start",(int)s_rec);	    (void)putsym_i("nan",(int)(e_rec-s_rec+1));        }	if (debug || nofile)	    Fprintf (stderr,              "copysd: file: %s start %ld, end %ld\n", ifile, s_rec, e_rec);	if (e_rec > ih -> common.ndrec) {	    Fprintf (stderr, "copysd: only %ld records in file.\n",              ih -> common.ndrec);	    e_rec = ih -> common.ndrec;	}	(void) sprintf (combuf, 	 "  Copied from %s, samples %ld to %ld; by copysd.\n",	 ifile, s_rec, e_rec);	if (first) {	    first_sf = ih -> hd.sd -> sf;	    oh = copy_header (ih);	    (void) strcpy (oh -> common.prog, "copysd");	    (void) strcpy (oh -> common.vers, VERSION);	    (void) strcpy (oh -> common.progdate, DATE);	    oh -> common.tag = NO;	    in_type = get_sd_type (ih);	    if (dflag) {		switch (type) {		    case 'b': 			Fprintf (stderr,"copysd: type 'b' not supported yet\n");			exit (1);			break;		    case 's': 			(void) set_sd_type (oh, SHORT);			if (in_type != CHAR || in_type != SHORT)			    down_size = 1;			maxvalue = SHRT_MAX;			break;		    case 'l': 			(void) set_sd_type (oh, LONG);			if (in_type == DOUBLE)			    down_size = 1;			maxvalue = LONG_MAX;			break;		    case 'f': 			(void) set_sd_type (oh, FLOAT);			if (in_type == DOUBLE || in_type == LONG)			    down_size = 1;			maxvalue = FLT_MAX;			break;		    case 'd': 			(void) set_sd_type (oh, DOUBLE);			maxvalue = DBL_MAX;			break;		    default: 			Fprintf (stderr, 			 "copysd: -d %c type unknown\n", type);			exit (1);		}	    }	    else		(void) set_sd_type (oh, get_sd_type (ih));	    if ((tstrm = fopen (mktemp (template), "w+")) == NULL)		CANTOPEN (argv[0], template);	} 	if (ih->hd.sd->sf != first_sf) {	    Fprintf(stderr,	     "copysd: all files must have same sf, file %s sf is %g.\n",	     ifile,ih->hd.sd->sf);	    (void) unlink(template);	    exit(1); 	}	if (!oflag)	    (void) add_source_file (oh, ifile, ih);	(void) add_comment (oh, combuf);	(void) skiprec (in, s_rec - 1, size_rec (ih));	n_rec = e_rec - s_rec + 1;	total_rec += n_rec;	n = SIZE;	while (n_rec > 0) {	    if (n_rec < n)		n = n_rec;	    if (get_sd_recd (dbuf, n, ih, in) == EOF) {		Fprintf (stderr, 		 "copysd:  ran out of data in file %s.\n",ifile);		break;	    }	    if (scale != 0)		for (i = 0; i < n; i++)		    dbuf[i] *= scale;	    if (down_size) {		for (i = 0; i < n; i++) {		    double y = fabs(dbuf[i]);		    if (y > maxvalue) {			if(!qflag) {			   Fprintf(stderr,"copysd: Warning, sample %ld",				i+1+e_rec-n_rec);			}			if(dbuf[i] > 0) {			   Fprintf(stderr," value clipped from %lg to %lg\n",				dbuf[i], maxvalue); 			   dbuf[i] = maxvalue;			}			else {			   Fprintf(stderr," value clipped from %lg to %lg\n",				dbuf[i], -maxvalue); 			   dbuf[i] = -maxvalue;			}		    }		}	    }	    (void) put_sd_recd (dbuf, n, oh, tstrm);	    n_rec -= n;	}	(void) fclose (in);	first = 0;	nofile = 0;	optind++;    }    (void) fclose (tstrm);    tstrm = fopen (template, "r");    oh -> common.ndrec = total_rec;    (void) add_comment (oh, get_cmd_line(argc,argv));    (void) write_header (oh, out);    n_rec = total_rec;    n = SIZE;    while (n_rec > 0) {	if (n_rec < n)	    n = n_rec;	if (get_sd_recd (dbuf, n, oh, tstrm) == EOF) {	    Fprintf (stderr, "copysd:  ran out of data.\n");	    break;	}	(void) put_sd_recd (dbuf, n, oh, out);	n_rec -= n;    }    (void) fclose (out);    (void) fclose (tstrm);    (void) unlink(template);}

⌨️ 快捷键说明

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