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

📄 vqdes.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) 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.      * * Written by:  John Shore * Checked by: * Revised by: * * Brief description:  This program is used to design a VQ codebook from  *                     FEA data * */static char *sccs_id = "@(#)vqdes.c	3.10	1/20/97	ESI/ERL";int  	    debug_level = 2;	    /*level of history detail*//* * include files */#include <stdio.h>#include <esps/esps.h>#include <esps/fea.h>#include <esps/vq.h>/* * defines */#define Fprintf (void)fprintf#define Fflush (void)fflush#define DEBUG(n) if (debug_level >= n) Fprintf#define ERROR_EXIT(text) {(void) fprintf(stderr, "%s: %s - exiting\n", \		ProgName, text); exit(1);}#define SYNTAX USAGE ("vqdes [-x debug_level] [-P param_file] [-h histfile] [-k checkfile] [-i] input.fea output.fea")#define FEA_BUFSIZE 1000000#define MAX_ITER 500/* * system functions and variables */int getopt ();double	atof();double log();long time();int atoi(), strcmp(), fclose();void rewind();extern  optind;extern	char *optarg;char *mktemp(), *ctime(), *strcpy();void rewind();#ifndef DEC_ALPHAchar *calloc();#endif/* * external SPS functions */int symtype();long *add_genhd_l();short *add_genhd_s();float *add_genhd_f();char *get_genhd();char *add_genhd_c();long get_fea_siz();short get_fea_type();char *get_cmd_line(), *getsym_s();void symerr_exit(), write_header(), set_sd_type();int getsym_i(), lin_search();struct header *read_header();struct fea_data *allo_fea_rec();float **f_mat_alloc();int rc_to_lar();void vec_copy_f();/* * global function declarations */long rc_get_chunk();double mse_lar_dist();void s_param_err();int checkpnt();/* * global variable declarations */char		    *ProgName = "vqdes";char		    *cmd_line;		/*string for command line*/char		    *histfile = "vqdeshist";	/*output ASCII file for history data*/FILE		    *histrm;char		    *input_ana = NULL;  /*input FEA file*/FILE		    *fea_strm = stdin;struct header	    *fea_ih;struct fea_data	    *fea_rec;char		    *fea_field = NULL;  /*name of FEA data field*/long		    ndrec_ana;		/* num records in FEA file					   or -1 if unknown */int		    whole_fits;		/* flag for whether all FEA data fits					   in feadata */char		    *out_vq = NULL;	/*output FEA file for codebook*/struct header	    *vq_oh;FILE		    *vq_strm = stdout;char		    *checkfile = "vqdes.chk";    /*checkpoint file*/FILE		    *chkstrm;struct header	    *chk_oh;/* * main program */main (argc, argv)int argc;char **argv;{/* * setup and initialization */    char		*Version = "3.10";    char		*Date = "1/20/97";    char		*paramfile = NULL;  /*parameter file name*/    char		*init_file = NULL;  /*file with initial codebook*/    FILE		*init_strm;    struct header	*init_ih;    int			init_rec;	    /*record number of initial codebook*/    int			init_behav;	    /*whether to cluster initial codebook*/    int			c;		    /*for getopt return*/    long		tloc;		    /*for local time*/    long		i, j;		    /*loop variables*/    long		fea_size;	    /*size of FEA field data*/    short		vqfea_type;	    /*generic header item type in					      initial codebook*/    float		*fea_ptr;	    /* location of FEA field data					       in fea_rec */    float		**feadata;	    /*matrix of training FEA data*/    long		*enc;		    /*final encode indices for data*/     long		fea_len;	    /*numb. rows in feadata*/    long		fea_dim;	    /*numb. columns in feadata*/    long		c_rows;		    /*size of VQ codebook*/    struct vqcbk	*cbk;		    /*the VQ codebook*/    struct vqcbk	*icbk;		    /*an initial VQ codebook*/    int			cbk_type = -1;    /*type of codebook (param file)*/    double		(*distort)();	    /*routine to use for distortion*/    int			vq_ret;		    /*return value from vqdesign*/        int			init_flag = 0;	    /*flag for -i option*/    int			max_iter = MAX_ITER;/*max no. of iterations*//* *initialization */    cmd_line = get_cmd_line(argc, argv); /*store copy of command line*//* * process command line options */    while ((c = getopt (argc, argv, "x:P:h:k:i")) != EOF) {	switch (c) {	    case 'x': 		debug_level = atoi (optarg);		break;	    case 'P':		paramfile = optarg;		break;	    case 'h':		histfile = optarg;		break;	    case 'k':		checkfile = optarg;		break;	    case 'i':		init_flag++;		break;	    default:		SYNTAX;	}    }/* * process file arguments */    if (optind < argc) {	input_ana = argv[optind++];	if (strcmp (input_ana, "-") == 0) {	    input_ana = "<stdin>"; 	    /*For now, can't use stdin*/	    ERROR_EXIT("can't use standard input for training sequence");	}	else	    TRYOPEN (argv[0], input_ana, "r", fea_strm);	}    else {	Fprintf(stderr, "vqdes: no input FEA file specified.\n");	SYNTAX;        }    if (optind < argc) {	out_vq = argv[optind++];	if (strcmp (out_vq, "-") == 0)	    out_vq = "<stdout>";	else	    TRYOPEN (argv[0], out_vq, "w", vq_strm);	}    else {	Fprintf(stderr, "vqdes: no output file specified.\n");	SYNTAX;        }    TRYOPEN(argv[0], histfile, "w", histrm);/* * initial history and debug output */    if (debug_level > 0) {        tloc = time(0);        Fprintf(histrm, "vqdes history output on %s", ctime(&tloc));        Fprintf(histrm, "vqdes version %s, date %s\n", Version, Date);        Fprintf(histrm, "command line:\n%s", cmd_line);	Fprintf(histrm, "checkpoint file is %s\n", checkfile);	Fflush(histrm);    }/* * read FEA header and allocate record */    if ((fea_ih = read_header(fea_strm)) == NULL)      	ERROR_EXIT("couldn't read input FEA file header");    if (fea_ih->common.type != FT_FEA)	ERROR_EXIT("input not FEA file");    ndrec_ana = fea_ih->common.ndrec;    fea_rec = allo_fea_rec(fea_ih);/* * read parameters from parameter file and SPS common - require that * the filename in common match that of the input FEA file */    (void) read_params(paramfile, SC_CHECK_FILE, input_ana);    if(symtype("max_iter") != ST_UNDEF) 	max_iter = getsym_i("max_iter");    fea_dim = getsym_i("fea_dim");    c_rows = getsym_i("vq_size");    fea_field = getsym_s("fea_field");    symerr_exit();  /*exit if any of the parameters were missing*/    if (init_flag) {	/*         *get name and record for initial codebook -- make sure file is ok	 */	init_file = getsym_s("init_file");	if (strcmp(checkfile, init_file) == 0)	    ERROR_EXIT("Checkpoint file has same name as init_file.")	init_rec = getsym_i("init_rec");	TRYOPEN(argv[0], init_file, "r", init_strm);	if ((init_ih = read_header(init_strm)) == NULL) 	    ERROR_EXIT("couldn't read input FEA_VQ file header");	if ((init_ih->common.type != FT_FEA) || (init_ih->hd.fea->fea_type != FEA_VQ))	    ERROR_EXIT("initial codebook file not FEA or not FEA_VQ");    }    /*     * cbk_type is optional     */    if (symtype("cbk_type") != ST_UNDEF) 	if ((cbk_type = lin_search(vq_cbk_types, getsym_s("cbk_type"))) == -1)	    ERROR_EXIT("invalid cbk_type in parameter file");    /*     *check to make sure fea_field exists, has right type, and is big     * enough     */    fea_size = get_fea_siz(fea_field, fea_ih, (short *) NULL, (long **) NULL);    if (fea_size == 0) {	Fprintf(stderr, fea_field, 	    "vqdes: field %s doesn't exist in input file\n", fea_field);	exit(1);    }    if (fea_dim > fea_size) ERROR_EXIT("VQ_DIM larger than FEA field size");    if (fea_dim != fea_size)  	Fprintf(histrm, 	  "vqdes: WARNING - size of FEA field greater than VQ_DIM\n");    if (get_fea_type(fea_field, fea_ih) != FLOAT) 	ERROR_EXIT("specified fea_field is not type FLOAT");/* *create FEA header  */    vq_oh = new_header(FT_FEA);    if (init_vqfea_hd(vq_oh, c_rows, fea_dim) != 0) 	ERROR_EXIT("error filling FEA header");    (void) strcpy (vq_oh->common.prog, "vqdes");    (void) strcpy (vq_oh->common.vers, Version);    (void) strcpy (vq_oh->common.progdate, Date);    add_source_file(vq_oh, input_ana, fea_ih);    if (init_flag) add_source_file(vq_oh, init_file, init_ih);    add_comment(vq_oh, cmd_line);    /*     *     *add generic header item for field name     */    (void) add_genhd_c("fea_field", fea_field, 0, vq_oh);/* *Now that the header is complete, we can write it out */    write_header(vq_oh, vq_strm);    Fflush(vq_strm); /*just in case vqdes bombs :-)*//* *Allocate FEA_VQ record. */    cbk = allo_vqfea_rec(vq_oh);/* *Now finish processing the parameters and initializing the codebook

⌨️ 快捷键说明

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