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

📄 cross_cor.c

📁 speech signal process tools
💻 C
📖 第 1 页 / 共 2 页
字号:
/* * This material contains unpublished, proprietary software of  * Entropic Research Laboratory, Inc. Any reproduction, distribution,  * or publication of this work must be authorized in writing by Entropic  * Research Laboratory, Inc., and must bear the notice:  * *    "Copyright (c) 1986-1990  Entropic Speech, Inc.  *    "Copyright (c) 1990-1996  Entropic Research Laboratory, Inc.  *                   All rights reserved." * * The copyright notice above does not evidence any actual or intended  * publication of this source code.      * * Written by:  Rodney Johnson * Checked by: * Revised by: * * This program computes cross correlations between two sampled-data * files and writes the results in a FEA file. * */static char *sccs_id = "@(#)cross_cor.c	1.16	1/21/97	ESI/ERL";#define VERSION "1.16"#define DATE "1/21/97"#include <stdio.h>#include <esps/esps.h>#include <esps/unix.h>#include <esps/sd.h>#include <esps/fea.h>#include <esps/window.h>#define TRYALLOC(type,num,var,msg) { \    if (((var) = (type *) calloc((unsigned)(num), sizeof(type))) == NULL) \    {Fprintf(stderr, "%s: can't allocate memory--%s", ProgName, (msg)); \    exit(1);}}#define REQUIRE(test, text) {if (!(test)) {(void) fprintf(stderr, \"%s: %s - exiting\n", ProgName, text); exit(1);}}#define SYNTAX \USAGE("cross_cor [-l frame_len][-o range][-{pr} range][-w window_type]\n [-x debug_level][-P param][-S step] [-N] input1.sd input2.sd output.fea") \ ;/* Delete ; when esps.h fixed */#define WT_PREFIX "WT_"void	lrange_switch();int	get_sd_orecd();char	*get_cmd_line();void	d_cross_cor();void	pr_darray();long	n_rec();char	*ProgName = "cross_cor";char	*Version = VERSION;char	*Date = DATE;int debug_level = 0;/* * MAIN PROGRAM */main(argc, argv)    int  argc;    char **argv;{    extern int	    optind;		/* for use of getopt() */    extern char	    *optarg;		/* for use of getopt() */    int	    ch;			/* command-line option letter */    long    frame_len;		/* length of each frame */    int	    lflag = 0;		/* -l option specified? */    long    step;		/* shift between successive frame positions */    int	    Sflag = 0;		/* -S option specified? */    long    minlag, maxlag;	/* least and greatest lags for cross-cor */    char    *orange;		/* arguments of -o option */    int	    oflag = 0;		/* -o option specified? */    char    *prange[2];		/* arguments of -p option */    int	    pnum = 0;		/* number of -p options */    long    start1, start2;	/* starting points in the input files */    long    nan;		/* total number of samples to analyze */    long    last;		/* end of range */    long    nan1, nan2;		/* tentative values for nan */    char    *window_type;	/* name of type of window to apply to data */    char    *pref_w_type;	/* window type name with added prefix */    int	    wflag = 0;		/* -w option specified? */    int	    win;		/* window type code */    extern char	    *window_types[];    /* standard window type names */    int	    debug = 0;		/* debug level */    char    *param_name = NULL;				/* parameter file name */    char    *iname1, *iname2;	/* input file names */    FILE    *ifile1, *ifile2;	/* input streams */    struct header	    *ihd1, *ihd2;	/* input file headers */    double  *x, *y;		/* sampled data from the two input files */    double  *wx, *wy;		/* windowed sampled data */    char    *oname;		/* output file name */    FILE    *ofile;		/* output stream */    struct header	    *ohd;		/* output file header */    struct fea_data	    *fea_rec;		/* output record */    long    *tag1, *tag2;	/* pointers to fields in output record */    float   *c_cor;		/* pointer to field in output record */    double  *d_c_cor;		/* computed cross correlation */    long    n_frames;		/* number of frames to process */    int	    first;		/* flag for initial call of get_sd_orecd() */    int     nsrflag = 0;        /* no shift reference flag *//* Parse command-line options. */    while ((ch = getopt(argc, argv, "l:o:p:r:w:x:P:S:N")) != EOF)        switch (ch)	{	case 'l':	    frame_len = atol(optarg);	    lflag++;	    break;	case 'o':	    orange = optarg;	    oflag++;	    break;	case 'p':	case 'r':	    REQUIRE(pnum < 2, "at most two -p or -r options allowed");	    prange[pnum++] = optarg;	    break;	case 'w':	    window_type = optarg;	    wflag++;	    break;	case 'x':	    debug_level = atoi(optarg);	    break;	case 'P':	    param_name = optarg;	    break;	case 'S':	    step = atol(optarg);	    Sflag++;	    break;        case 'N':	    nsrflag++;	    break;	default:	    SYNTAX	    break;	}/* Process file names and open files. */    if (argc - optind > 3)    {	Fprintf(stderr,	    "%s: too many file names specified.\n", ProgName);	SYNTAX    }    if (argc - optind < 3)    {	Fprintf(stderr,	    "%s: too few file names specified.\n", ProgName);	SYNTAX    }    iname1 = eopen(ProgName,	    argv[optind++], "r", FT_FEA, FEA_SD, &ihd1, &ifile1);    iname2 = eopen(ProgName,	    argv[optind++], "r", FT_FEA, FEA_SD, &ihd2, &ifile2);    REQUIRE(ifile1 != stdin || ifile2 != stdin,	"input files must not both be standard input");    oname = eopen(ProgName,	    argv[optind++], "w", NONE, NONE, &ohd, &ofile);    if (debug_level)	Fprintf(stderr, "Input files: %s, %s\nOutput file: %s\n",	    iname1, iname2, oname);/* Are input files single-channel and real? */    if (get_fea_siz("samples", ihd1, (short *) NULL, (long **) NULL) != 1        || get_fea_siz("samples", ihd2, (short *) NULL, (long **) NULL) != 1)    {	Fprintf(stderr, "%s: Multichannel data not supported yet.\n",		ProgName);	exit(1);    }    if (is_field_complex(ihd1, "samples") || is_field_complex(ihd2, "samples"))    {	Fprintf(stderr, "%s: Complex data not supported yet.\n",		ProgName);	exit(1);    }/* Get parameter values. */    (void) read_params(param_name, SC_NOCOMMON, (char *) NULL);    if (!lflag)	frame_len =	    (symtype("frame_len") != ST_UNDEF)	    ? getsym_i("frame_len")	    : 0;    if (debug_level)	Fprintf(stderr, "frame_len: %ld\n", frame_len);    if (oflag)    {	minlag = -10; maxlag = 10;	lrange_switch(orange, &minlag, &maxlag, 0);    }    else    {	minlag =	    (symtype("minlag") != ST_UNDEF)	    ? getsym_i("minlag")	    : -10;	maxlag =	    (symtype("maxlag") != ST_UNDEF)	    ? getsym_i("maxlag")	    : 10;    }    if (debug_level)	Fprintf(stderr, "minlag: %ld;  maxlag: %ld\n", minlag, maxlag);    REQUIRE(minlag <= maxlag, "maxlag less than minlag.");    if (debug_level)    {	int i;	Fprintf(stderr, "%d -p options.\n", pnum);	for (i = 0; i < pnum; i++)	    Fprintf(stderr, "  prange[%d]: %s\n", i, prange[i]);    }    switch (pnum)    {    case 0:	start1 =	    (symtype("start1") != ST_UNDEF)	    ? getsym_i("start1")	    : 1;	start2 =	    (symtype("start2") != ST_UNDEF)	    ? getsym_i("start2")	    : 1;	if (symtype("nan") != ST_UNDEF && getsym_i("nan") != 0)	    nan1 = nan2 = getsym_i("nan");	else	{	    nan1 = n_rec(&ifile1, &ihd1) - start1 + 1;	    nan2 = n_rec(&ifile2, &ihd2) - start2 + 1;	}	break;    case 1:	prange[1] = prange[0];	/* FALL THROUGH */    case 2:	start1 = 1;	last = LONG_MAX;	lrange_switch(prange[0], &start1, &last, 0);	REQUIRE(start1 >= 1,	    "can't start before beginning of first input file");	REQUIRE(last >= start1,	    "empty range specified for first input file");	nan1 = ((last == LONG_MAX) ? n_rec(&ifile1, &ihd1) : last)		- start1 + 1;	start2 = 1;	last = LONG_MAX;	lrange_switch(prange[1], &start2, &last, 0);	REQUIRE(start2 >= 1,	    "can't start before beginning of second input file");	REQUIRE(last >= start2,	    "empty range specified for second input file");	nan2 = ((last == LONG_MAX) ? n_rec(&ifile2, &ihd2) : last)		- start2 + 1;	break;    default:	Fprintf(stderr, "%s: at most two -p options allowed", ProgName);	exit(1);	break;    }

⌨️ 快捷键说明

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