feafunc.c
来自「speech signal process tools」· C语言 代码 · 共 676 行 · 第 1/2 页
C
676 行
/* * 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-1991 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: John Shore * Checked by: * Revised by: Rodney Johnson * * Apply optional function, gain factor, additive constant, and type change * to FEA fields * */static char *sccs_id = "@(#)feafunc.c 1.11 8/31/95 ESI/ERL";/* Based on window.c. */#define VERSION "1.11"#define DATE "8/31/95"#include <stdio.h>#include <esps/esps.h>#include <esps/unix.h>#include <esps/fea.h>#include <esps/feasd.h>#include <esps/func.h>#include <signal.h>#define REQUIRE(test, text) {if (!(test)) {(void) fprintf(stderr, \"%s: %s - exiting\n", ProgName, text); exit(1);}}#define SYNTAX \USAGE("feafunc [-d add_constant] [-f input_field [-f output_field]]\n\t[-g gain_factor] [-r range] [-t output_type] [-x debug_level]\n\t[-F function] [-P params] input.fea output.fea") ;#define ABS(x) ((x) < 0 ? -(x) : (x))extern char *type_codes[];extern char *function_types[];char *get_cmd_line();void lrange_switch();char *arr_alloc();char *arr_func();char *type_convert();static int fpe_handler(); /* fpe handler routine */static void clip_warn(); /* used with type_convert to print warning in case of clipping */static int numeric(); /* tests whether type is numeric */char *ProgName = "feafunc";char *Version = VERSION;char *Date = DATE;char sbuf[256]; /* to hold comment */int debug_level = 0; /* debug level, global for library*/long num_read; /* number of records skipped or read */long clip_warn_flag = 0; /* last record for which clip_warn was called *//* * 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 */ int fflag = 0; /* -f option specified 0, 1, or 2 times? */ int tflag = 0; /* -t option specified? */ int gflag = 0; /* -g option specified? */ int dflag = 0; /* -d option specified? */ double gain_re; /* real gain factor */ double gain_im; /* imaginary part of gain factor */ double add_re; /* real add constant */ double add_im; /* imaginary part of additive constant */ char *inf_name; /* field name for input field */ int inf_type; /* data type of input field */ char *type_code; /* string specifying output field type */ int outf_type; /* data type of output field */ char *outf_name; /* field name for output field */ int warn_if_repl = YES; /* print warning if output field exists in input file? */ char *inf_names[2]; /* need arrays for print_fea_recf */ char *outf_names[2]; /* need arrays for print_fea_recf */ char **fld_names; /* fields to be copied unchanged */ char *function_type; /* name of function to apply to data */ short func; /* function code */ int complex; /* do complex computations? */ int func_flag = 0; /* flag for window option */ int rflag = NO; /* -r option specified? */ char *rrange; /* arguments of -r option */ long start_rec; /* starting record number */ long end_rec; /* ending record number */ long num_recs; /* number of records to read (0 means all up to end of file) */ char *param_name = NULL; /* parameter file name */ char *iname; /* input file name */ FILE *ifile; /* input stream */ struct header *ihd; /* input file header */ struct fea_data *irec; /* input record */ char *inf_ptr; /* pointer (untyped) to field in input record */ char *outf_ptr; /* pointer (untyped) to field in output record*/ long size; /* size of input data field */ short rank; /* number of dimensions of input field */ long *dimens; /* dimensions of input field */ double *data; /* input real data as double */ double_cplx *cdata; /* input complex data as double */ char *oname; /* output file name */ FILE *ofile; /* output stream */ struct header *ohd; /* output file header */ struct fea_data *orec; /* output record */ int i; /* loop index */ /* * Parse command-line options. */ while ((ch = getopt(argc, argv, "d:f:g:r:t:x:P:F:")) != EOF) switch (ch) { case 'd': dflag++; add_re = add_im = 0.0; sscanf(optarg, "%lf,%lf", &add_re, &add_im); break; case 'f': switch (fflag) { case 0: inf_name = optarg; fflag++; break; case 1: outf_name = optarg; fflag++; break; default: Fprintf(stderr, "%s: -f option may be specified at most twice.\n", ProgName); exit(1); } break; case 'g': gflag++; gain_re = gain_im = 0.0; sscanf(optarg, "%lf,%lf", &gain_re, &gain_im); break; case 'r': rflag = YES; rrange = optarg; break; case 't': tflag++; type_code = optarg; break; case 'x': debug_level = atoi(optarg); break; case 'F': function_type = optarg; func_flag++; break; case 'P': param_name = optarg; break; default: SYNTAX break; } /* * Process file names and open files. */ if (argc - optind > 2) { Fprintf(stderr, "%s: too many file names specified.\n", ProgName); SYNTAX } if (argc - optind < 2) { Fprintf(stderr, "%s: too few file names specified.\n", ProgName); SYNTAX } iname = eopen(ProgName, argv[optind++], "r", FT_FEA, NONE, &ihd, &ifile); if (ifile != stdin) REQUIRE(strcmp(iname, argv[optind]), "output file same as input"); oname = eopen(ProgName, argv[optind++], "w", NONE, NONE, &ohd, &ofile); if (debug_level) Fprintf(stderr, "Input file: %s\nOutput file: %s\n", iname, oname); /* * Get parameter values. */ if (ifile != stdin) (void) read_params(param_name, SC_CHECK_FILE, iname); else (void) read_params(param_name, SC_NOCOMMON, iname); if (!func_flag) function_type = (symtype("function_type") != ST_UNDEF) ? getsym_s("function_type") : "none"; func = lin_search(function_types, function_type); if (func == -1) { Fprintf(stderr, "%s: invalid function type %s\n", ProgName, function_type); exit(1); } if (debug_level) Fprintf(stderr, "%s: function_type = %s, function code = %d\n", ProgName, function_type, func); if (fflag < 1) inf_name = (symtype("input_field") != ST_UNDEF) ? getsym_s("input_field") : "samples"; if (fflag < 2) outf_name = (symtype("output_field") != ST_UNDEF) ? getsym_s("output_field") : NULL; if ((outf_name == NULL) || (strcmp(outf_name, "input_name_[function]") == 0)) { outf_name = malloc((unsigned)(strlen(inf_name) + strlen(function_type) + 2)); REQUIRE(outf_name, "can't allocate space for output field name"); (void) strcpy(outf_name, inf_name); (void) strcat(outf_name, "_"); (void) strcat(outf_name, function_type); } else if (strcmp(outf_name, "-") == 0) { outf_name = inf_name; warn_if_repl = NO; } inf_names[0] = inf_name; outf_names[0] = outf_name; inf_names[1] = outf_names[1] = NULL; if (!gflag) { gain_re = (symtype("gain_real") != ST_UNDEF) ? getsym_d("gain_real") : 1.0; gain_im = (symtype("gain_imag") != ST_UNDEF) ? getsym_d("gain_imag") : 0.0; } if (!dflag) { add_re = (symtype("add_real") != ST_UNDEF) ? getsym_d("add_real") : 0.0; add_im = (symtype("add_imag") != ST_UNDEF) ? getsym_d("add_imag") : 0.0; } if (debug_level) { Fprintf(stderr, "input_field: \"%s\". output_field: \"%s\".\n", inf_name, outf_name); Fprintf(stderr, "gain: [%g, %g]. add: [%g, %g]\n", gain_re, gain_im, add_re, add_im); } inf_type = get_fea_type(inf_name, ihd); if (inf_type == UNDEF) { Fprintf(stderr, "%s: input_field %s not in input file\n", ProgName, inf_name); exit(1); } if (!tflag) type_code = (symtype("output_type") != ST_UNDEF) ? getsym_s("output_type") : NULL; if (type_code == NULL || strcmp(type_code ,"input type") == 0) outf_type = inf_type; else {
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?