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

📄 vq.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: * Modification History:  *   1/8/91: -i option and codword index field added by Bill Byrne. * * Brief description:  This program is used to vector-quantize FEA fields. */static char *sccs_id = "@(#)vq.c	3.14	1/20/97	ESI/ERL";/* * include files */#include <stdio.h>#include <string.h>#include <esps/esps.h>#include <esps/fea.h>#include <esps/vq.h>/* * defines */#define MAXLINE 200#define MAXCMNT 2047  /* Number of characters in user entered comments. */#define Fprintf (void)fprintf#define Fflush (void)fflush#define ERROR_EXIT(text) {(void) fprintf(stderr, "%s: %s - exiting\n", \		ProgName, text); exit(1);}#define SYNTAX USAGE ("vq [-x debug_level] [-h histfile] [-c record] [-f fieldname] [-i] cbk.fea fea.in fea.out")#define FEA_BUFSIZE 500/* * system functions and variables */#ifndef IBM_RS6000int getopt();double	atof();long time();int atoi(), strcmp(), fclose();char *strtok();char *strcat();char *fgets();void rewind();char *mktemp(), *ctime(), *strcpy();void rewind();#ifndef DEC_ALPHAchar *malloc();char *calloc();#endifdouble sqrt();#endifextern  optind;extern	char *optarg;/* * external SPS functions */char *uniq_name();char *get_cmd_line();long *add_genhd_l();short *add_genhd_s();float *add_genhd_f();char *add_genhd_c();char *get_genhd();int genhd_type();int getsym_i(), lin_search();struct header *read_header();int rc_to_lar();long vqencode();char *savestring();int add_fea_fld();int del_fea_fld();/* * global function declarations */void vec_cy_f();double mse_lar_dist();void wrt_fea_vec();/* * global variable declarations */char		    *ProgName = "vq";char		    *histfile = "vqhist";	/*output ASCII file for history data*/FILE		    *histrm;char		    *local_no_yes[] = {"NO", "YES", NULL}; int		debug_level = 0; /* level of history detail;				  global for library access*//* * main program */main (argc, argv)int argc;char **argv;{/* * setup and initialization */    char		*Version = "3.14";    char		*Date = "1/20/97";    char		*cbk_fea = NULL;    /*input FEA_VQ file for codebook*/    struct header	*cbk_ih;    FILE		*cbk_strm;	        char		*data_in;	    /*input FEA file for quantization*/    FILE		*in_strm = stdin;       struct header	*fea_ih;    struct fea_data	*fea_rec;    struct fea_data	*fea_rec_out;    char		*data_out;	    /*output FEA file - quantized*/    struct header	*fea_oh;    FILE		*out_strm = stdout;    char		*cmd_line;	    /*to hold command line*/    int			c;		    /*for getopt return*/    long		tloc;		    /*for local time*/    long		fea_dim;	    /*numb. columns in feadata*/    struct vqcbk	*cbk;		    /*the VQ codebook*/    double		(*distort)();	    /*routine to use for distortion*/    float		*input_vec;	    /*one feature vector*/    long		nfea;		    /*number of feature vectors*/    long		curr_ind;	    /*current feature vector*/    long		max_ind;	    /*vector index of max distortion*/    double		curr_dist;	    /*distortion of current vector*/    double		max_dist;	    /*maximum vector distortion*/    double		tot_sqdist;	    /*cumulative square distortion*/    double		tot_dist;	    /*cumulative distortion*/    double		dist_mean;	    /*mean distortion*/    double		dist_variance;	    /*variance of distortion*/    double		dist_sd;	    /*standard deviation of distortion*/    int			dist_err = 0;	    /*error return from distort*/    int			ncbkrec;	    /*record number of initial codebook*/    int			c_flag = 0;	    /*flag for -c option*/    long		i;    float		*field;		    /*pointer to field to be quantized*/    float		*field_out;	    /*pointer to quantized field in output*/    char		*fieldname = "spec_param"; /*name of FEA field*/    char		*enc_dist_name = "encode_distortion"; /*a generic name*/    char		*tempname;	    /*holder for generic name*/    long		fea_size;	    /*size of FEA field data*/    int			dumnumb;	    /*dummy variable for number of generics */    char		*cbk_field;	    /*name of design field*/    int	    		sizedummy;	    /*dummy variable for genhd_type*/    int                 i_flag = 0;         /*flag for -i option*/    char                *ndx_fieldname;     /*field name for code word index*/    long                *cw_ndx=NULL;       /*pointer to code word index*//* *Initialization */    cmd_line = get_cmd_line(argc, argv);    /*store copy of command line*/    /* * process command line options */    while ((c = getopt (argc, argv, "x:h:c:f:i")) != EOF) {	switch (c) {	    case 'x': 		debug_level = atoi (optarg);		break;	    case 'h':		histfile = optarg;		break;	    case 'c':		ncbkrec = atoi(optarg);		c_flag++;		break;	    case 'f':		fieldname = optarg; 		break;            case 'i':                i_flag++;		break;	    default:		SYNTAX;	}    }    /* * process file arguments  */    if (optind < argc) {	cbk_fea = argv[optind++];	if (strcmp (cbk_fea, "-") == 0)	    ERROR_EXIT("vq: can't use - for codebook -- exiting");        TRYOPEN (argv[0], cbk_fea, "r", cbk_strm);    }    else {	Fprintf(stderr, "vq: no FEA codebook file specified.\n");	SYNTAX;            }    if (optind < argc) {	data_in = argv[optind++];	if (strcmp (data_in, "-") == 0)	    data_in = "<stdin>";	else	    TRYOPEN (argv[0], data_in, "r", in_strm);	    }    else {	Fprintf(stderr, "vq: no input data file specified.\n");	SYNTAX;    }    if (optind < argc) {	data_out = argv[optind++];	if (strcmp (data_out, "-") == 0)	    data_out = "<stdout>";	else	    TRYOPEN (argv[0], data_out, "w", out_strm);    }    else {	Fprintf(stderr, "vq: no output data file specified.\n");	SYNTAX;    }    TRYOPEN(argv[0], histfile, "w", histrm);/* * read FEA file and get codebook */    if ((cbk_ih = read_header(cbk_strm)) == NULL)	NOTSPS(argv[0], cbk_fea);    if (cbk_ih->common.type != FT_FEA) 	ERROR_EXIT("codebook file not FEA file");    if (cbk_ih->hd.fea->fea_type != FEA_VQ) 	ERROR_EXIT("codebook file not FEA_VQ file");    cbk = allo_vqfea_rec(cbk_ih);    assert (cbk != NULL);    if (!c_flag)	ncbkrec = cbk_ih->common.ndrec;    if (ncbkrec >= 1)    {	fea_skiprec(cbk_strm, (long) ncbkrec - 1, cbk_ih);	if (get_vqfea_rec(cbk, cbk_ih, cbk_strm) == EOF)	    ERROR_EXIT("EOF when trying to read initial codebook");    }    else if (ncbkrec == -1)    {	/* Variable-length records (e.g. Esignal Ascii format).	 * Read records to find the last.	 */	struct vqcbk     *next_cbk, *tmp_cbk;	next_cbk = allo_vqfea_rec(cbk_ih);	if (get_vqfea_rec(cbk, cbk_ih, cbk_strm) == EOF)	    ERROR_EXIT("EOF when trying to read initial codebook");	while (get_vqfea_rec(next_cbk, cbk_ih, cbk_strm) != EOF)	{	    tmp_cbk = cbk;	    cbk = next_cbk;	    next_cbk = tmp_cbk;	}    }    else	ERROR_EXIT("codebook record number less than 1");    fea_dim = *cbk->dimen;/* *select distortion function */    switch (*cbk->dist_type) {	case MSE:  	    distort = NULL;	    break;	case MSE_LAR:	    distort = mse_lar_dist;	    break;	default:	    ERROR_EXIT("invalid distortion type");    }/* * initial history and debug output  */

⌨️ 快捷键说明

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