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

📄 reverse_sd.c

📁 speech signal process tools
💻 C
字号:
/* * This material contains proprietary software of Entropic Speech, Inc. * Any reproduction, distribution, or publication without the prior * written permission of Entropic Speech, Inc. is strictly prohibited. * Any public distribution of copies of this work authorized in writing by * Entropic Speech, Inc. must bear the notice * *    "Copyright (c) 1987 Entropic Speech, Inc.; All rights reserved" * * Program: reverse_sd.c	 * * Written by:  John Shore * Checked by: * * This program reverses a sampled data file */#ifndef lintstatic char *sccs_id = "@(#)reverse_sd.c	1.2 6/5/87 ESI";#endif/* * system include files */#include <stdio.h>#include <values.h> /* might be MASSCOMP specific *//* * ESPS include files */#include <esps/esps.h>/* * defines */#define Fprintf (void)fprintf#define Fflush (void)fflush#define DEBUG(n) if (debug_level >= n) Fprintf#define ERROR_EXIT(text) {(void) fprintf(stderr, "%s: %s - exiting\n", \		ProgName, text); exit(1);}#define SYNTAX USAGE ("reverse_sd [-p range] input.sd output.sd")/* * system functions and variables */int getopt ();extern  optind;extern	char *optarg;void exit(), perror();char *calloc();/* * external SPS functions */char *get_cmd_line();void read_params(), symerr_exit(), write_header(), set_sd_type();lin_search();void lrange_switch(), put_sd_recf();char *strcpy();/* * global function declarations */void get_range();/* * global variable declarations */char		    *ProgName = "reverse_sd";/* * main program */main (argc, argv)int argc;char **argv;{/* * setup and initialization */    char *Version = "1.2";    char *Date = "6/5/87";    long	    s_rec; 		/* starting record position */    long	    e_rec;	/* ending record position */    long	    n_rec;		/*number of records*/    char	    *in_sd = NULL;	    /*SD file for input sampled data*/    FILE	    *in_strm;    struct header   *inh;    char	    *out_sd;		    /*output SD file (reverse_sdd)*/    struct header   *oh;    FILE	    *out_strm = stdout;    int		    c;			    /*for getopt return*/    char	    *range;		    /* string to hold range */    int		    p_flag = 0;		    /* flag for -p option */    char	    rangebuf[100];	    /* string for range comment */    float	    *data;		    /*array for sampled data*/    float	    temp;		    /*temp for data reversal*/    int		    half;		    /*half size of data (truncated)*/    int		    top;		    /*top index in data*/    int i;/* * process command line options */    while ((c = getopt (argc, argv, "p:")) != EOF) {	switch (c) {	    case 'p':		range = optarg;		p_flag++;		break;	    default:		SYNTAX;	}    }/* * process file arguments */    /*stdin not allowed for input file; this makes allocation easy     */    if (optind < argc) {	in_sd = argv[optind++];	TRYOPEN (argv[0], in_sd, "r", in_strm);	}    else {	Fprintf(stderr, "reverse_sd: no input SD file specified.\n");	SYNTAX;}    if (optind < argc) {	out_sd = argv[optind++];	if (strcmp (out_sd, "-") == 0)	    out_sd = "<stdout>";	else	    TRYOPEN (argv[0], out_sd, "w", out_strm);	}    else {	Fprintf(stderr, "reverse_sd: no output file specified.\n");	SYNTAX;        }/* * read values header of input SD file */    if ((inh = read_header(in_strm)) == NULL)      	ERROR_EXIT("couldn't read input SD file header");/* * read range from SPS common, if range option not used;  * the filename in common match that of the input SD file */    if (!p_flag) read_params((char *)NULL, SC_CHECK_FILE, in_sd);    get_range(&s_rec, &e_rec, range, p_flag);    symerr_exit();  /*exit if any of the parameters were missing*//* * finish range processing (exploit fact that we know ndrec for input.sd) */    if (e_rec > inh->common.ndrec) e_rec = inh->common.ndrec;    n_rec = e_rec - s_rec + 1;    if ( s_rec > e_rec ) ERROR_EXIT("start record greater than end record");/* * create and write header for output file; */    oh = copy_header(inh);    add_source_file(oh, in_sd, inh);    (void) strcpy (oh->common.prog, "reverse_sd");    (void) strcpy (oh->common.vers, Version);    (void) strcpy (oh->common.progdate, Date);    (void) add_comment (oh, get_cmd_line(argc,argv));    (void) sprintf (rangebuf,         "reversed samples %d to %d of %s.\n", s_rec, e_rec, in_sd);    (void) add_comment (oh, rangebuf);    oh->hd.sd->equip = NONE;    oh->hd.sd->src_sf = oh->hd.sd->sf = inh->hd.sd->sf;    write_header(oh, out_strm);    data = (float *) calloc((unsigned) n_rec, sizeof(float));    spsassert(data != NULL, "reverse_sd: couldn't allocate enough memory");/* * main processing goes here */    (void) skiprec (in_strm, (long)s_rec - 1, size_rec (inh));    (void) get_sd_recf(data, (int) n_rec, inh, in_strm);    /*     *reverse_sd the data     */    half = n_rec / 2;     top = n_rec - 1;    for (i=0; i < half; i++) {	temp = data[i];	data[i] = data[top - i];	data[top - i] = temp;    }    put_sd_recf(data, (int) n_rec, oh, out_strm);/* * put output file info in ESPS common */    if (strcmp(out_sd, "<stdout>") != 0) {	(void) putsym_s("filename", out_sd);	(void) putsym_s("prog", ProgName);	(void) putsym_i("start", (int) 1);	(void) putsym_i("nan", (int) n_rec);    }        exit(0);}voidget_range(srec, erec, rng, rflag)long *srec;			/* starting record */long *erec;			/* end record */char *rng;			/* range string from range option */int rflag;			/* flag for whether range option used */{    *srec = 1;    *erec = MAXLONG;    if (rflag) 	lrange_switch (rng, srec, erec, 1);	    else {	if(symtype("start") != ST_UNDEF) *srec = getsym_i("start");	if(symtype("nan") != ST_UNDEF) *erec = *srec + getsym_i("nan") - 1;     }}

⌨️ 快捷键说明

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