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

📄 feaop.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) 1990-1993  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:  Rod Johnson * Checked by: * Revised by: * * Element-by-element binary operations on fields of FEA files. * */static char *sccs_id = "@(#)feaop.c	1.3	8/31/95	ERL";/* INCLUDE FILES */#include <esps/esps.h>#include <esps/unix.h>#include <esps/fea.h>#include <esps/op.h>/* LOCAL CONSTANTS */#define EC_SCCS_DATE "8/31/95"#define EC_SCCS_VERSION "1.3"#define DEF_OUT_FLD "input1_[op]_input2"#define DEF_OUT_TYP "default"/* LOCAL MACROS */#define SYNTAX \USAGE("feaop [-f in_field [-f in_field2 [-f out_field]]] [-g gain_factor]\n\t[-r range [-r range2]] [-t output_type] [-x debug_level] [-z] [-I]\n\t[-O operation] [-P param_file] [-R] file1.in file2.in file3.out")#define ERROR(text) { \  (void) fprintf(stderr, "%s: %s - exiting\n", ProgName, (text)); \  exit(1);}#define REQUIRE(test, text) {if (!(test)) ERROR(text)}/* SYSTEM FUNCTIONS AND VARIABLES */int	getopt();int	optind;char	*optarg;/* ESPS FUNCTIONS AND VARIABLES */void	    lrange_switch();char	    *arr_alloc();short	    cover_type();char	    *get_cmd_line();int	    is_type_numeric();char	    *arr_op();int	    debug_level = 0;/* LOCAL FUNCTION DECLARATIONS */int	    getdata1();/* STATIC (LOCAL) GLOBAL VARIABLES */ static char *ProgName = "feaop";static char *Version = EC_SCCS_VERSION;static char *Date = EC_SCCS_DATE;static char sbuf[256];			/* to hold comment */static FILE		*ifile1;	/* input stream */static struct header	*ihd1;		/* input file header */static struct fea_data	*irec1;		/* input record */static long		offset;		/* starting position in ifile1 */static int		Rflag = NO;	/* -R option specified? *//* MAIN PROGRAM */intmain(argc, argv)    int		argc;    char    	**argv;{    int	    	ch;			/* command-line option letter */    int	    	fflag = 0;		/* -f option used how many times? */    char    	*in_fld1, *in_fld2;	/* names of input fields */	        char    	*out_fld;		/* name of output field */    int	    	warn_if_repl = YES;	/* print warning if output					   field exists in input file? */    char    	**fld_names;		/* fields to be copied unchanged */    int	    	gflag = NO;		/* -g option specified? */    char    	*gain_arg;		/* argument of -g option */    double_cplx	gain;			/* gain factor */    int		scale;			/* Boolean: (gain != 1)? */    char	*gain_ptr;		/* pointer to replicated gain */    double	*dbl_ptr;		/* gain_ptr as (double *) */    double_cplx	*cplx_ptr;		/* gain_ptr as (double_cplx *) */    int	    	rflag = 0;		/* -r option used how many times? */    char	*rrange1, *rrange2;	/* arguments of -r option */	        long    	start_rec1, start_rec2;	/* starting record numbers in inputs */    int    	start_recs[2];		/* start_rec1 & start_rec2 as array */    long    	start_rec3;		/* starting record number in output */    long    	end_rec1, end_rec2;	/* ending record numbers in inputs */    long    	end_rec3;		/* ending record number in output */    long    	num_recs1, num_recs2;	/* number of records (inputs) */    int    	num_recs[2];		/* num_recs1 & num_recs2 as array */    long    	num_recs3;		/* number of records (output) */    long	num_out;		/* number of records written */    int	    	inf_type1, inf_type2;	/* data types of input fields */    int		gain_type;		/* data type of gain factor */    int		scal_type;		/* data type of scaled data */    int	    	tflag = NO;		/* -t option specified? */    char    	*type_name;		/* name of output field type */    int	    	outf_type;		/* data type of output field */    int	    	zflag = NO;		/* -z option specified? */    int	    	Iflag = NO;		/* -I option specified? */    int	    	Oflag = NO;		/* -O option specified? */    char    	*oper_name;		/* name of operation to perform */    int	    	oper;			/* numeric code of operation */    char    	*param_name = NULL;	/* parameter file name */    char	    *iname1, *iname2;	/* input file names */    /* ifile1, ihd1, irec1 global for access by getdata1. */    FILE	    *ifile2;		/* input stream */    struct header   *ihd2;		/* input file header */    struct fea_data *irec2;		/* input record */    char	    *in1_ptr, *in2_ptr;	/* pointers to input data */    char	    *scal_ptr;		/* pointer to scaled input data */    long	    size1, size2;	/* sizes of input data fields */    short	    rank1, rank2;	/* ranks of input fields */    long	    *dim1, *dim2;	/* dimensions of input fields */    char	    *oname;		/* output file name */    FILE	    *ofile;		/* output stream */    struct header   *ohd;		/* output file header */    struct fea_data *orec;		/* output record */    char	    *out_ptr;		/* pointer to output data */    long	    get1, get2;		/* get-data return flags */    double	    rec_fr1, rec_fr2;	/* record_freq header item values */    int		    i;			/* loop index */    /*     * Parse command-line options.     */    while ((ch = getopt(argc, argv, "f:g:r:t:x:zIO:P:R")) != EOF)	switch (ch)	{	case 'f':	    switch (fflag)	    {	    case 0:		in_fld1 = optarg;		fflag++;		break;	    case 1:		in_fld2 = optarg;		fflag++;		break;	    case 2:		out_fld = optarg;		fflag++;		break;	    default:		ERROR("-f option may be specified at most 3 times");		break;	    }	    break;	case 'g':	    gflag = YES;	    gain_arg = optarg;	    break;	case 'r':	    switch (rflag)	    {	    case 0:		rrange1 = optarg;		rflag++;		break;	    case 1:		rrange2 = optarg;		rflag++;		break;	    default:		ERROR("-r option may be specified at most 2 times");		break;	    }	    break;	case 't':	    tflag = YES;	    type_name = optarg;	    break;	case 'x':	    debug_level = atoi(optarg);	    break;	case 'z':	    zflag = YES;	    break;	case 'I':	    Iflag = YES;	    break;	case 'O':	    Oflag = YES;	    oper_name = optarg;	    break;	case 'P':	    param_name = optarg;	    break;	case 'R':	    Rflag = YES;	    break;	default:	    SYNTAX;	    break;	}    /*     * Process file names and open input 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 = argv[optind++];    iname2 = argv[optind++];    oname = argv[optind++];    REQUIRE(strcmp(iname1, "-") || strcmp(iname2, "-"),	    "Input files cannot both be <stdin>");    REQUIRE(!Rflag || strcmp(iname1, "-"),	    "Can't recycle <stdin>");    REQUIRE(!strcmp(oname, "-")	    || (strcmp(oname, iname1) && strcmp(oname, iname2)),	    "Output file cannot be same as input file");    iname1 = eopen(ProgName, iname1, "r", FT_FEA, NONE, &ihd1, &ifile1);    iname2 = eopen(ProgName, iname2, "r", FT_FEA, NONE, &ihd2, &ifile2);    if (debug_level)	Fprintf(stderr, "%s: input files: %s, %s.\n", ProgName, iname1, iname2);    /*     * Process parameters and options.     */    (void) read_params(param_name, SC_NOCOMMON, (char *) NULL);    /* operation code */    if (!Oflag)    {	oper_name =	    (symtype("operation") != ST_UNDEF)		? getsym_s("operation")		    : "ADD";	REQUIRE(oper_name, "Parameter \"operation\" not STRING");    }    if (debug_level)	Fprintf(stderr, "%s: operation \"%s\"\n", ProgName, oper_name);    oper = lin_search(operation_names, oper_name);    REQUIRE(oper != -1, "Invalid operation name");    if (debug_level)	Fprintf(stderr, "%s: operation code %d\n", ProgName, oper);    /* field names */    switch (fflag)    {    case 0:	in_fld1 =	    (symtype("in_field1") != ST_UNDEF)		? getsym_s("in_field1")		    : "samples";	REQUIRE(in_fld1, "Parameter \"in_field1\" not STRING");	in_fld2 =	    (symtype("in_field2") != ST_UNDEF)		? getsym_s("in_field2")		    : "samples";	REQUIRE(in_fld2, "Parameter \"in_field2\" not STRING");	break;    case 1:	in_fld2 = in_fld1;    }    if (debug_level)	Fprintf(stderr, "%s: in_fields \"%s\" and \"%s\"\n",		ProgName, in_fld1, in_fld2);    if (fflag < 3)    {	out_fld =	    (symtype("out_field") != ST_UNDEF)		? getsym_s("out_field")		    : DEF_OUT_FLD;	REQUIRE(out_fld, "Parameter \"out_field\" not STRING");    }    if (debug_level)	Fprintf(stderr, "%s: out_field \"%s\"\n", ProgName, out_fld);    if (!strcmp(out_fld, DEF_OUT_FLD))    {	out_fld = 	    malloc((strlen(in_fld1) + strlen(oper_name) + strlen(in_fld2) + 3)		   * sizeof(char));	REQUIRE(out_fld, "Can't allocate space for output field name");	if (Iflag)	    (void) sprintf(out_fld, "%s_%s_%s", in_fld2, oper_name, in_fld1);	else	    (void) sprintf(out_fld, "%s_%s_%s", in_fld1, oper_name, in_fld2);    }    else if (!strcmp(out_fld, "-"))    {	out_fld = in_fld2;	warn_if_repl = NO;    }    if (debug_level)	Fprintf(stderr, "%s: out_field \"%s\"\n", ProgName, out_fld);    /* output data type */    inf_type1 = get_fea_type(in_fld1, ihd1);    REQUIRE(inf_type1 != UNDEF, "First input field not in file");    inf_type2 = get_fea_type(in_fld2, ihd2);    REQUIRE(inf_type2 != UNDEF, "Second input field not in file");    if (debug_level)	Fprintf(stderr, "%s: input type codes {%d, %d}\n",		ProgName, inf_type1, inf_type2);    if (!tflag)    {	type_name =	    (symtype("output_type") != ST_UNDEF)		? getsym_s("output_type")		    : DEF_OUT_TYP;	REQUIRE(type_name, "Parameter \"output_type\" not STRING");    }    if (debug_level)	Fprintf(stderr, "%s: output_type \"%s\"\n", ProgName, type_name);    if (!strcmp(type_name, DEF_OUT_TYP))    {	outf_type = cover_type(inf_type1, inf_type2);	if (oper == OP_CPLX)	    outf_type = cover_type(outf_type, BYTE_CPLX);    }    else    {	outf_type = lin_search(type_codes, type_name);	if (outf_type == CHAR) outf_type = BYTE;	REQUIRE(is_type_numeric(outf_type), "Invalid output type");    }    if (debug_level)	Fprintf(stderr, "%s: output type code %d\n", ProgName, outf_type);    /* gain factor */    if (gflag)    {	gain.real = 1.0;	gain.imag = 0.0;	(void) sscanf(gain_arg, "%lf,%lf", &gain.real, &gain.imag);    }    else    {	switch (symtype("gain_real"))	{	case ST_UNDEF:	    gain.real = 1.0;	    break;	case ST_FLOAT:	    gain.real = getsym_d("gain_real");	    break;	default:	    ERROR("Parameter \"gain_real\" not FLOAT");	    break;	}	switch (symtype("gain_imag"))	{	case ST_UNDEF:	    gain.imag = 0.0;	    break;	case ST_FLOAT:	    gain.imag = getsym_d("gain_imag");	    break;	default:	    ERROR("Parameter \"gain_imag\" not FLOAT");	    break;	}    }    if (debug_level)	Fprintf(stderr, "%s: gain {%g, %g}\n",		ProgName, gain.real, gain.imag);    /* ranges (start, nan, end) */    if (!rflag)    {	switch (symtype("start"))	{	case ST_UNDEF:	    start_rec1 = start_rec2 = 1;	    break;	case ST_INT:	    start_rec1 = start_rec2 = getsym_i("start");	    break;	case ST_IARRAY:	    REQUIRE(getsym_ia("start", start_recs, 2) == 2,		    "Length of array parameter \"start\" is not 2");	    start_rec1 = start_recs[0];

⌨️ 快捷键说明

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