refcof.c

来自「speech signal process tools」· C语言 代码 · 共 623 行 · 第 1/2 页

C
623
字号
/* * 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.      * * History:   *  Originally by Brian Sublett; *  Revised by David Burton (added -m option) *  Revised by John Shore (added -r and -p options, removed ndrec  *          dependence, fixed a bunch of bugs) *  Rewritten by John Shore for ESPS 3.0 (added choice of spectrum  *          analysis method, used simpler SD buffer method).  *  Revised by Shore to have range option specify full range rather than *            first frame *  Revised by Shore to use overlapping frames and windowing.   *  Revised by Shore to add fBURG, VBURG, STRCOV, STRCOV1; and also to  *             to create compute_rc; *  * Purpose:  This program reads data from an ESPS FEA_SD file and computes the * reflection coefficients and power for the purposes of plotting the maximum * entropy spectrum.  The output is written to an ESPS FEA_ANA file.  * */static char *sccs_id = "@(#)refcof.c	3.28	9/9/98	ESI/ERL";#include <stdio.h>#include <esps/unix.h>#include <esps/esps.h>#include <esps/fea.h>#include <esps/feasd.h>#include <esps/anafea.h>#include <esps/window.h>#include <esps/ana_methods.h>/*** User defines go here. ***/#define WT_PREFIX "WT_"#define SYNTAX \USAGE("refcof [-P param] [-{pr} range] [-l frame_len] [-e preemphasis] \n \ [-S step] [-w window_type] [-m method] [-o order] [-d ] [-Z] \n \ [-x debug_level] [-s sinc_n] [-c conv_test] [-i max_iter]  \n \ [-z] file.sd file.rc")#define DEBUG(n) if (debug_level >= n) Fprintf#define Fprintf (void)fprintf#define DEF_ORDER 15#define DEF_FRAMELEN 1000#define FILNAMSIZE 40		/* Maximum size of filter name + 4 */#define ERROR_EXIT(text) {(void) fprintf(stderr, "refcof: %s - exiting\n", text); exit(1);}long		atol();char           *eopen();char           *get_cmd_line();double          getsym_d();void            put_sd_recs();void		pr_farray();void            symerr_exit();void            lrange_switch();int             debug_level = 0;	/* debugging level */char	       *local_no_yes[] = {"NO", "YES", NULL};int             initflag = 0; /* needed by bestauto, but I don't know why */char	       *ProgName = "refcof";char	       *nomemory = "refcof: couldn't allocate enough memory";static long	n_rec();static void     get_range();main(argc, argv)    int             argc;    char           *argv[];{    FILE           *fopen(), *fpin, *fpout;    char           *in_file, *out_file;    struct header  *ih, *oh;    struct anafea  *recp;    char           *param_file = NULL;    int             i, k;    float          *x, *px, *rc, fst;    double         *r;    int		    first = 1;	/* flag for get_sd_orec */    long	    step;	/* step size for shifting frames */    long            start = 1;    long	    nan = LONG_MAX;     int		    win;	/* window type code */    long	    frame_len = -1;  /* frame length */    int		    actsize;    int		    sincn = 0;    int             order = DEF_ORDER;    int             c;    long            nframes = 1;    double          atof();    float           gain;    char           *cmd_line;	/* to hold command line */    extern char    *optarg;    extern          optind;    char           *analysis;   /*analysis method type */    int		    method;    char	    *window_type; /* name of type of window to apply to data */    char	    *pref_w_type; /* window type name with added prefix */    float           preemp = 0;    int		    wflag = 0; /* flag for window option*/    int		    zflag = 0; /* flag for -z silent option*/    int		    Zflag = 0; /* flag for -Z don't zero-fill option*/    int		    dflag = 0; /* flag for dc remove option*/    int             mflag = 0;	/* flag for analysis method option */    int             pflag = 0;	/* flag for range option */    int             lflag = 0;	/* flag for -l frame_len option */    int		    Sflag = 0;  /* flag for -S option (step size)*/    int		    sflag = 0; /* flag for -s option*/    int             oflag = 0;	/* flag for order option */    int             cflag = 0;	/* flag for -c option */    int             iflag = 0;	/* flag for -i option */    int             eflag = 0;  /* flag for -e option */    char           *prange = NULL;	/* string for range specification					 * (-p) */    int             more = 1;	/* flag to indicate more sampled data */    double         record_freq; /* holds sampling frequency*/    double         strcov_test = 1e-5; /*convergence test for STRCOV */    int            strcov_maxiter = 20;   /* max iterations for STRCOV */    char           *Version = "3.28";    char           *Date = "9/9/98";   /* Initialization.    */    cmd_line = get_cmd_line(argc, argv);	/* store copy of command line */    /* Check the command line options. */    while ((c = getopt(argc, argv, "P:p:r:x:m:o:l:s:S:w:c:i:e:dzZ")) != EOF) {	switch (c) {	case 'P':	    param_file = optarg;	    break;	case 'p':	case 'r':	    prange = optarg;	    pflag++;	    break;	case 'l':	    frame_len = atoi(optarg);	    lflag++;	    break;	case 'x':	    debug_level = atoi(optarg);	    break;	case 'm':	    analysis = optarg;	    mflag++;	    break;	case 'o':	    order = atoi(optarg);	    oflag++;	    break;        case 'e':	    preemp = atof(optarg);	    eflag++;	    break;	case 'd':	    dflag++;	    break;	case 'z':	    zflag++;	    break;	case 'Z':	    Zflag++;	    break;	case 'w':	    window_type = optarg;	    wflag++;	    break;	case 'S':	    step = atol(optarg);	    Sflag++;	    break;	case 's':	    sincn = atoi(optarg);	    sflag++;	    break;	case 'c':	    strcov_test = atof(optarg);	    cflag++;	    break;	case 'i':	    strcov_maxiter = atoi(optarg);	    iflag++;	    break;	default:	    SYNTAX;	}    }    /*     * open input and output files     */    if (optind < argc)	in_file = eopen(ProgName, argv[optind++], "r", FT_FEA, FEA_SD, &ih, &fpin);    else {	Fprintf(stderr, "%s: no input file specified.\n", ProgName);	SYNTAX;    }    if (debug_level)	Fprintf(stderr, "Input file is %s\n", in_file);    if (is_field_complex(ih, "samples") == YES){	ERROR_EXIT("does not support complex input data");    }    if (optind < argc)	out_file = eopen(ProgName, argv[optind++], "w", NONE, NONE, &oh, &fpout);    else {	Fprintf(stderr, "%s: no output FEA_ANA file specified.\n", ProgName);	SYNTAX;    }    if (debug_level)	Fprintf(stderr, "Output file is %s\n", out_file);    /*     * read the parameter file and process the range     */    if (strcmp(in_file, "<stdin>") != 0)	(void) read_params(param_file, SC_CHECK_FILE, in_file);    else        (void) read_params(param_file, SC_NOCOMMON, in_file);    get_range(&start, &nan, &frame_len, &step, &nframes, 	prange, pflag, lflag, Sflag, &fpin, ih, zflag, Zflag);    if (!wflag)	window_type =	    (symtype("window_type") != ST_UNDEF)	    ? getsym_s("window_type")	    : "RECT";    pref_w_type = 	malloc((unsigned)(strlen(WT_PREFIX) + strlen(window_type) + 1));    spsassert(pref_w_type, "can't allocate space for window type name");    (void) strcpy(pref_w_type, WT_PREFIX);    (void) strcat(pref_w_type, window_type);    win = lin_search(window_types, pref_w_type);    spsassert(win > -1, "window type not recognized");    if (debug_level)	Fprintf(stderr, "%s: window_type = %s, win = %d\n",	    ProgName, window_type, win);    if (!oflag)	if (symtype("order") != ST_UNDEF)	    order = getsym_i("order");    if (!eflag)	if (symtype("preemphasis") != ST_UNDEF)	    preemp = getsym_d("preemphasis");    if (debug_level) Fprintf(stderr,	"%s: start = %ld, nan = %ld, frame size = %ld, step = %ld nframes = %ld\n",	    ProgName, start, nan, frame_len, step, nframes);    if (debug_level) 	Fprintf(stderr, "%s: order = %d, preempahsis = %f\n", ProgName, order, preemp);    symerr_exit();    if (start <= 0)	ERROR_EXIT("negative or zero starting point");    if (frame_len < 0)	ERROR_EXIT("can't have negative frame length");    if (!mflag) {	if (symtype("method") != ST_UNDEF)	    analysis = getsym_s("method");	else	    analysis = "AUTOC";    }    fea_skiprec(fpin, start - 1, ih);    x = (float *) calloc((unsigned) frame_len, sizeof(float));    spsassert(x != NULL, nomemory);    if(preemp){      px = (float *) calloc((unsigned) frame_len, sizeof(float));      spsassert(px != NULL, nomemory);    }    r = (double *) calloc((unsigned) order + 1, sizeof(double));    spsassert(r != NULL, nomemory);    rc = (float *) calloc((unsigned) order + 1, sizeof(float));    spsassert(rc != NULL, nomemory);    /*     *Create the output header     */    oh = new_header(FT_FEA);    if (init_anafea_hd(oh, 0L, (long) order, 1L, 1L, 1L, 0, 0) != 0)	ERROR_EXIT("error filling FEA_ANA header");    add_source_file(oh, in_file, ih);    add_comment(oh, cmd_line);    (void) strcpy(oh->common.prog, "refcof");    (void) strcpy(oh->common.vers, Version);    (void) strcpy(oh->common.progdate, Date);    oh->common.tag = YES;    oh->variable.refer = in_file;    if((record_freq = get_genhd_val("record_freq", ih, (double) -1.)) == -1.){      Fprintf(stderr, 	      "refcof: Invalid record frequency in input file - exiting.\n");      exit(1);    }    *get_genhd_f("src_sf", oh) = (float)record_freq;    *get_genhd_s("spec_rep", oh) = RC;

⌨️ 快捷键说明

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