me_spec.c

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

C
617
字号
/* * 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.      * * History:  pre-SDS version by Shankar Narayan *	     SDS version by Joe Buck *	     SPS version by Rod Johnson *	     converted to use FEA_ANA files and to avoid ndrec by John Shore *	     non-RC spec_reps, non-FEA_ANA files added by Rod Johnson * * Brief description: makes spectral records from analysis feature records. * */static char *sccs_id = "@(#)me_spec.c	1.14	8/31/95	ESI/ERL";extern char *ProgName, *Version, *Date;		/* Defined in version.c. */ #include <stdio.h>#include <esps/esps.h>#include <esps/unix.h>#include <esps/fea.h>#include <esps/anafea.h>#include "genana.h"#include <esps/feaspec.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 SYNTAX \USAGE("me_spec [-n num_freqs] [-o max_order] [-r range] [-x debug_level]\n [-G] [-P params] file.fea file.spec") \ ;/* GLOBAL ARRAYS*/char *yesno[] = {"NO", "YES", NULL};/* External ESPS functions. */char    *get_cmd_line();char    *eopen();struct zfunc	*get_genzfunc();long	*fld_range_switch();void	lrange_switch();int	reps_rc();void	rctoc();void	get_arspec();/* local ESPS function. */double  avg_raw_pwr();int     debug_level = 0;	/* Specified with -x option. */voidmain(argc, argv)    int     argc;    char    **argv;{    int	    c;			/* Command-line option letter. */    extern  optind;		/* Used by getopt for command-line parsing. */    extern char            *optarg;		/* Used by getopt for command-line parsing. */    int	    nflag = NO;		/* -n option specified? */    int     num_freqs;		/* Number of frequencies in output spectra. */    int	    oflag = NO;		/* max_order defined? */    int	    max_order;		/* Upper bound on order of output spectra. */    int	    rflag = NO;		/* -r option specified? */    char    *range;		/* Range of records to process */    long    startrec, endrec;	/* Starting and ending input records. */    long    nrecs;		/* Number of input records to process. */    int	    Gflag = NO;		/* -G option specified? */    int	    fana;		/* special FEA_ANA processing? */    char    *params = NULL;	/* Parameter-file name. */    char    *spec_param_field;	/* Field name for spectral parameters. */    short   spec_rep;		/* Numerical code for type of spec. params. */    char    *power_field;	/* Name of field containing spectral power. */    double  def_power;		/* Used if power not in input records. */    float   total_power;            char    *samp_freq_name;	/* Name of header item for sampling freq. */    double  samp_freq;		/* Sampling frequency. */    double src_sf;              /* sampling freq. of source sampled data file*/    struct header            *ihd, *ohd;		/* Input and output file headers. */    char    *iname;		/* Input file name. */    FILE    *ifile,		/* Input stream. */            *ofile;		/* Output stream. */    struct genana            *ana_rec;		/* Input analysis feature record. */    float   *spec_params;    struct feaspec            *spec_rec;		/* Output spectrum record. */    float   *lpcfilter;		/* LPC filter coefficients. */    float   *reflcoef;		/* Reflection coefficients. */    float   gain;		/* Filter gain. */    double  raw_pwr;		/* Raw power or average raw power. */    int     i;			/* Loop index */    int	    input_order;    long    fld_len;    long    *elements;    int     order;		/* Filter order */    long    order_vcd;		/* Order of voiced frames in FEA_ANA file. */    long    order_unvcd;	/* Order of unvoiced frames in FEA_ANA file. */    char    *cmd_line;		/* Command line saved for output header. */    int	    first = YES;	/* First time through main loop? */    int     frame_meth;         /* holds frame type information */    long    frlen;    cmd_line = get_cmd_line(argc, argv); /* Store copy of command line. *//* Process command-line options. */    while ((c = getopt(argc, argv, "n:o:r:x:GP:")) != EOF)    switch (c)    {    case 'n':	nflag = YES;        num_freqs = atoi(optarg);        break;    case 'o':	oflag = YES;	max_order = atoi(optarg);	break;    case 'r': 	rflag = YES;        range = optarg;        break;    case 'x':         debug_level = atoi(optarg);        break;    case 'G':	Gflag = YES;	break;    case 'P':	params = 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);    (void) eopen(ProgName, argv[optind++],			    "w", FT_FEA, NONE, &ohd, &ofile);/* Get parameter values. */    (void) read_params(params, SC_NOCOMMON, (char *) NULL);    if (!nflag)	num_freqs =	    (symtype("num_freqs") == ST_INT)	    ? getsym_i("num_freqs")	    : 513;    if (num_freqs < 2)    {        Fprintf(stderr,	    "%s: number of frequencies %d is less than 2.\n",	    ProgName, num_freqs);        exit(1);                        }        if (debug_level)	Fprintf(stderr, "num_freqs: %d\n", num_freqs);    if (!oflag && symtype("max_order") == ST_INT)    {	max_order = getsym_i("max_order");	oflag = YES;    }    if (debug_level)	if (oflag)	    Fprintf(stderr, "max_order: %d\n", max_order);	else	    Fprintf(stderr, "no max_order\n");    if (rflag)    {	startrec = 1;	endrec = LONG_MAX;	lrange_switch(range, &startrec, &endrec, 0);	nrecs =	    (endrec != LONG_MAX)	    ? endrec - startrec + 1	    : 0;    }    else    {	startrec =	    (symtype("start") == ST_INT)	    ? getsym_i("start")	    : 1;	nrecs =	    (symtype("nan") == ST_INT)	    ? getsym_i("nan")	    : 0;	endrec = (nrecs != 0)	    ? startrec - 1 + nrecs	    : LONG_MAX;    }    if (startrec < 1)    {	Fprintf(stderr, "%s: Can't start before beginning of file.\n",	    ProgName);	exit(1);    }    if (endrec < startrec)    {	Fprintf(stderr, "%s: Last record precedes first.\n", ProgName);	exit(1);    }    nrecs = endrec - (startrec - 1);    if (debug_level)	Fprintf(stderr, "start: %ld.  endrec: %ld.  nan: %ld.\n",	    startrec, endrec, nrecs);    fana = ihd->hd.fea->fea_type == FEA_ANA && !Gflag;        if (symtype("spec_param_field") == ST_STRING)	spec_param_field = getsym_s("spec_param_field");    else if (fana)	spec_param_field = "spec_param";    else    {	Fprintf(stderr, "Name of spec_param field not specified.\n");	exit(1);    }    if (debug_level)	Fprintf(stderr, "spec_param_field: \"%s\"\n", spec_param_field);    if (symtype("spec_rep") == ST_STRING)    {	spec_rep = lin_search(spec_reps, getsym_s("spec_rep"));	if (spec_rep < 0)	{	    Fprintf(stderr,		"%s: Unrecognized spectral representation %s.\n",		 ProgName, getsym_s("spec_rep"));	    exit(1);	}    }    else if (fana)	spec_rep = *get_genhd_s("spec_rep", ihd);    else    {	Fprintf(stderr, "%s: Spectral representation not specified.\n",	    ProgName);	exit(1);    }    if ( symtype("power_field") == ST_STRING	|| symtype("power") == ST_FLOAT )    {	if (symtype("power_field") != ST_STRING)	    power_field = NULL;	else	{	    power_field = getsym_s("power_field");	    if (get_fea_type(power_field, ihd) != FLOAT)		if (symtype("power") == ST_FLOAT)		    power_field = NULL;		else		{		    Fprintf(stderr,

⌨️ 快捷键说明

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