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

📄 classify.c

📁 speech signal process tools
💻 C
📖 第 1 页 / 共 2 页
字号:
/*----------------------------------------------------------------------+|									||   This material contains proprietary software of Entropic Speech,	||   Inc.  Any reproduction, distribution, or publication without the	||   prior written permission of Entropic Speech, Inc. is strictly	||   prohibited.  Any public distribution of copies of this work		||   authorized in writing by Entropic Speech, Inc. must bear the	||   notice								||									||    "Copyright (c) 1987 Entropic Speech, Inc. All rights reserved."	||									|+-----------------------------------------------------------------------+| 									||  Program:	main.c							|| 									||  Written by:  Rodney Johnson.						||  Checked by:								|| 									||  Main module of classify.						||									||  Classifies records in an ESPS feature file by the maximum-likeli-	||  hood method, according to information in a statistics file.		||									|+----------------------------------------------------------------------*/#ifndef lintstatic char *sccs_id = "@(#)classify.c	1.1 6/5/87";#endif/* * system include files */#include <stdio.h>/* * ESPS include files */#include <sps/sps.h>#include <sps/fea.h>#include <sps/feastat.h>/* * defines */#define DEBUG(n) if (debug_level >= n) Fprintf#define Fprintf (void)fprintf#define PROG Fprintf(stderr, "%s: ", ProgName)#define EXIT Fprintf(stderr, "\n"); exit(1);#define ERROR_EXIT(text) {PROG; Fprintf(stderr, (text)); EXIT}#define ERROR_EXIT1(fmt,a) {PROG; Fprintf(stderr, (fmt), (a)); EXIT}#define ERROR_EXIT2(fmt,a,b) {PROG; Fprintf(stderr, (fmt), (a), (b)); EXIT}#define TRYALLOC(type,num,var,msg) { \    if (((var) = (type *) calloc((unsigned)(num),sizeof(type))) == NULL) \    ERROR_EXIT1("Can't allocate memory--%s", (msg))}#define SYNTAX USAGE("classify [-x debug_level][-f field][-e elements]\[-d][-C field][-L field]\n\[-h file.his] input.stat input.fea output.fea")/* * system functions and variables */int     getopt();extern int  optind;extern char *optarg;int	atoi();long	time();char	*ctime();int	strcmp();char    *strcpy();void    exit();char    *calloc();void	perror();/* * external ESPS functions */char	*get_cmd_line();void	write_header();struct header	*read_header();int	lin_search();int	add_comment();char	*fea_decode();long	*grange_switch();char	**get_fea_deriv();long	get_fea_siz();short	get_fea_type();char	*get_deriv_vec();void	copy_fea_rec();/* * global function declarations */void	pr_farray();int	classify();int	num_enums();/* * global variable declarations */int     debug_level = 0;       char    *ProgName = "classify";char    *Version = "1.1";char	*Date = "6/5/87";char	*cmd_line;/* * main program */main(argc, argv)    int	    argc;    char    **argv;{    char    *statfield;		    /* Field name.  Get features from this */				    /* field or its source fields. */    long    feasize;		    /* Size of named field in input. */    long    statsize;		    /* Field size from statistics file. */    long    *elements;		    /* Indices specified with -e option. */    long    num_elems;		    /* Number of indices specified. */    char    *e_arg;		    /* Argument of -e option. */    short   d_flag = NO,	    /* -d option specified? */	    e_flag = NO,	    /* -e option specified? */	    f_flag = NO;	    /* -f option specified? */    char    *hist_name = NULL;	    /* History-file name. */    FILE    *hist_strm;		    /* History file. */    long    tloc;		    /* Current time. */    char    *stat_name;		    /* Statistics-file name. */    FILE    *stat_strm;		    /* Statistics file. */    struct header   *stat_ih;	    /* Statistics-file header. */    struct feastat  *stat_rec,	    /* Statistics-file record. */	    **stat_recs;	    /* All statistics-file records. */    float   **means;		    /* Mean vectors from statistics file. */    float   ***invcovars;	    /* Inverse covariance matrices from */				    /* statistics file. */    int	    max_clas,		    /* Upper bound on number of classes. */	    num_clas;		    /* Actual number of classes. */    char    **fields;		    /* Source-field definitions. */    char    *infea_name;	    /* Name of input feature file. */    FILE    *infea_strm;	    /* Input feature file. */    struct header   *infea_ih;	    /* Input feature-file header. */    struct fea_data *infea_rec;	    /* Input feature-file record. */    char    *fea_ptr;		    /* Pointer to data in input record. */    float   *feavec = NULL;	    /* Features from input record. */    long    length;		    /* Length of feavec. */    char    *outfea_name;	    /* Output feature-file name. */    FILE    *outfea_strm;	    /* Output feature-file.  */    struct header   *outfea_oh;	    /* Output feature-file header. */    struct fea_data *outfea_rec;    /* Output feature-file record. */    char    **enums;		    /* Class names for output header. */    char    *clasfield = "class";   /* Output field name for class. */    short   *class;		    /* Pointer to output field for class. */    char    *postfield = "posteriors";				    /* Output field name for likelihoods. */    float   *posteriors;	    /* Output vector for likelihoods. */    long    *count;		    /* Count records in each class. */    long    nrec;		    /* Number of records. */    int	    c;			    /* Input option letter. */    int	    i, j;		    /* Loop indices. */    cmd_line = get_cmd_line(argc, argv);/* * process command line options */    while ((c = getopt(argc, argv, "x:f:e:dC:L:h:")) != EOF)    {	switch (c)	{	case 'x': 	    debug_level = atoi(optarg);	    break;	case 'f':	    f_flag = YES;	    statfield = optarg;	    break;	case 'e':	    e_flag = YES;	    elements = grange_switch(e_arg = optarg, &num_elems);	    break;	case 'd':	    d_flag = YES;	    break;	case 'C':	    clasfield = optarg;	    break;	case 'L':	    postfield = optarg;	    break;	case 'h':	    hist_name = optarg;	    break;	default:	    SYNTAX	    break;	}    }    if (d_flag && (e_flag || f_flag))	ERROR_EXIT("The -d option is incompatible with -e and -f.")/* * process file arguments */    if (optind != argc - 3) SYNTAX    stat_name = argv[optind++];    if (strcmp(stat_name, "-") == 0)    {	stat_name = "<stdin>";	stat_strm = stdin;    }    else	TRYOPEN(ProgName, stat_name, "r", stat_strm);    if ((stat_ih = read_header(stat_strm)) == NULL)	NOTSPS(ProgName, stat_name)    if (stat_ih->common.type != FT_FEA	    || stat_ih->hd.fea->fea_type != FEA_STAT)	ERROR_EXIT1("%s is not an ESPS statistics file.", stat_name)    infea_name = argv[optind++];    if (strcmp(infea_name, "-") == 0)    {	if (stat_strm == stdin)	    ERROR_EXIT("Input files can't both be standard input.")	infea_name = "<stdin>";	infea_strm = stdin;    }    else	TRYOPEN(ProgName, infea_name, "r", infea_strm);    if ((infea_ih = read_header(infea_strm)) == NULL)	NOTSPS(ProgName, infea_name)    if (infea_ih->common.type != FT_FEA)	ERROR_EXIT1("%s is not an ESPS feature file.", infea_name)    outfea_name = argv[optind++];    if (strcmp(outfea_name, "-") == 0)    {	outfea_name = "<stdout>";	outfea_strm = stdout;    }    else	TRYOPEN(ProgName, outfea_name, "w", outfea_strm);/* * open optional history file and initial output */    if (hist_name != NULL)    {	TRYOPEN(ProgName, hist_name, "w", hist_strm);	tloc = time((long *) NULL);	Fprintf(hist_strm, "Classify history output on %s", ctime(&tloc));	Fprintf(hist_strm, "Classify version %s of %s\n", Version, Date);	Fprintf(hist_strm, "Command line:\n%s", cmd_line);    }/* * read statistics records */    if (get_fea_siz("invcovar", stat_ih, (short *) NULL, (long **) NULL)	<= 0) ERROR_EXIT(	    "Statistics file does not have inverse covariance matrices.")    max_clas = num_enums("class", stat_ih);    TRYALLOC(struct feastat *, max_clas, stat_recs, 	    "statistics record pointers.")    stat_rec = allo_feastat_rec(stat_ih);    num_clas = 0;    while (get_feastat_rec(stat_rec, stat_ih, stat_strm) != EOF	    && num_clas < max_clas)    {	stat_recs[num_clas++] = stat_rec;	stat_rec = allo_feastat_rec(stat_ih);    }    if (num_clas == 0) ERROR_EXIT("Empty statistics file.")    DEBUG(1)(stderr, "Read %d statistics records.\n", num_clas);    for (i = 0; i < num_clas; i++)

⌨️ 快捷键说明

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