📄 vqdst.c
字号:
/* * 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. * * Written by: David Burton * Checked by: * Revised by: * * Brief description: This program vector quantizes a FEA field * in an array of codebook records * */static char *sccs_id = "@(#)vqdst.c 1.5 1/27/97 ESI/ERL";/* * include files */#include <stdio.h>/* * ESPS Includes */#include <esps/esps.h>#include <esps/fea.h>#include <esps/vq.h>#include <esps/feadst.h>#include <esps/anafea.h>#include <esps/unix.h>/* * defines */#define ERROR_EXIT(text) {(void)fprintf(stderr, "vqdst: %s - exiting\n", \ text); exit(1);}#define SYNTAX USAGE ("vqdst [-x debug_level] [-P params_file] [-d distortion]\[-f field]\n[-n rep_number] [-s] [-t] [-c] [-q] infile1.fea infile2.cbk outfile.dst")#define ONE 1/* * system functions and variables *//*done via <esps/unix.h>/* * external ESPS functions */char *get_cmd_line();int lin_search();char *eopen();char *getsym_s();/* * global variable declarations */extern optind;extern char *optarg;int debug_level = 0; /*flag for debug output*/static long n_rec();/* * main program */main (argc, argv)int argc;char **argv;{/* * setup and initialization */ char *version = "1.5"; char *date = "1/27/97"; char *params_file = NULL;/*default parameter file name*/ char *cbk_in = NULL; /*input FEA_VQ codebook name*/ FILE *cbk_strm = NULL; /*codebook stream pointer*/ struct header *cbk_ih = NULL; /*codebook header pointer*/ char *data_in = NULL; /*input FEA file name*/ FILE *data_strm = NULL; /*input stream pointer*/ struct header *data_ih = NULL; /*input data headerpointer*/ struct fea_data *data_rec = NULL; /*input data record pointer*/ char *dst_out = NULL; /*output FEA file - quantized*/ struct header *dst_oh = NULL; /*output file header*/ FILE *dst_strm = stdout; /* output stream pointer */ struct feadst *dst_rec = NULL; /*output distortion record*/ struct vqcbk **codebooks = NULL; /*pointer to codebook info*/ char *cmd_line = NULL; /*to hold command line*/ int c; /*for getopt return*/ double (*distort)(); /*routine to use for distortion*/ float *input_vec; /*one feature vector*/ long nfea; /*number of feature vectors*/ double *dist_mean; /*mean distortion*/ double *dist_val; /*distortions for current frame*/ int ncbkrec; /*rec. number current codebook*/ long i; /*loop index*/ char *field = NULL; /*field to be quantized*/ char *field_rep = "Not Applicable"; /*description of field*/ char *enc_dist = "MSE"; /*encoding distortion*/ long fea_size; /*size of FEA field data*/ int dist_type; /*integer rep. of dsit. msre*/ int sflag = 0; /* check source flag*/ int tflag = 0; /*check signal flag*/ int cflag = 0; /*check field flag*/ int dflag = 0; /*distortion measure flag*/ int fflag = 0; /*quantized field flag*/ int qflag = 0; /*add fea file headers*/ short spec_rep; /*holds fana spec_param value*/ short rep_number = -1; /*rep # of input FEA file*/ int header_size; /*needed by genhd_type()*//* *Initialization */ cmd_line = get_cmd_line(argc, argv); /*store copy of command line*/ /* * process command line options */ while ((c = getopt (argc, argv, "x:P:d:f:n:stcq")) != EOF) { switch (c) { case 'x': debug_level = atoi (optarg); break; case 'P': params_file = optarg; break; case 'd': dflag++; enc_dist = optarg; break; case 'f': fflag++; field = optarg; break; case 's': sflag++; break; case 't': tflag++; break; case 'c': cflag++; break; case 'q': qflag++; break; case 'n': rep_number = (short) atoi(optarg); break; default: SYNTAX; } }/* * Read Params and Common */ (void)read_params(params_file, SC_CHECK_FILE, (char *)NULL);/* * process file arguments */ if((argc - optind) != 3 && (argc - optind) != 2) SYNTAX; if ((argc - optind) == 3) /* all three filenames specified*/ data_in = eopen("vqdst", argv[optind++], "r", FT_FEA, NONE, &data_ih, &data_strm); else if((argc - optind) == 2){/* only codebook and dst file specified; get input from Common*/ /* * Get input file name and open file */ if(symtype("filename") == ST_UNDEF){ ERROR_EXIT("No input file in ESPS Common\n"); } else data_in = eopen("vqdst", getsym_s("filename"), "r", FT_FEA, NONE, &data_ih, &data_strm); } /* * Now open other two files */ /* First open input codebook file*/ cbk_in = eopen("vqdst", argv[optind++], "r", FT_FEA, FEA_VQ, &cbk_ih, &cbk_strm); if(strcmp(cbk_in, "<stdin>") == 0) ERROR_EXIT("Stdin cannot be used for the codebook file"); /* Now work on output FEA_DST file*/ dst_out = argv[optind]; if( ( dst_strm = fopen(dst_out, "r") ) == NULL || strcmp(dst_out, "-") == 0 ){ /* output file does not exist*/ /*Open output file*/ if(strcmp(dst_out, "-") == 0){ dst_out = "<stdout>"; dst_strm = stdout; } else if((dst_strm = fopen(dst_out, "w")) == NULL){ Fprintf(stderr, "vqdst: Cannot open %s\n", dst_out); exit(1); } /* * Set up output header and write it */ dst_oh = new_header(FT_FEA); if(init_feadst_hd(dst_oh, (long)ONE) > 0) ERROR_EXIT("Error filling FEA_DST header"); (void) strcpy (dst_oh->common.prog, "vqdst"); (void) strcpy (dst_oh->common.vers, version); (void) strcpy (dst_oh->common.progdate, date); add_source_file(dst_oh, cbk_in, cbk_ih); add_source_file(dst_oh, data_in, data_ih); add_comment(dst_oh, cmd_line); write_header(dst_oh, dst_strm); } else if (qflag){/*append to existing output file*/ /*open file, read header, make appropriate checks*/ dst_out = eopen("vqdst", dst_out, "r", FT_FEA, FEA_DST, &dst_oh, &dst_strm); if(fclose(dst_strm) != 0) ERROR_EXIT("Troube closing fea_dst file"); if(*(long *)get_genhd("max_num_sects", dst_oh) != ONE) ERROR_EXIT( "FEA_DST file represents multisection data; not supported yet") if((dst_strm = fopen(dst_out, "a")) == NULL){ Fprintf(stderr, "vqdst: Could not open %s for appending\n", dst_out); exit(1); } } else{ Fprintf(stderr, "vqdst: Source file information cannot be included\n"); Fprintf(stderr, "vqdst: Try -q option\n"); exit(1); } if(debug_level > 0){ Fprintf(stderr, "vqdst: in FEA = %s, in VQCBK = %s, FEADST = %s\n", data_in, cbk_in, dst_out); Fprintf(stderr, "vqdst: input field = %s, encoding distortion = %s\n", field, enc_dist); Fprintf(stderr, "vqdst: dflag = %d, fflag = %d, sflag = %d, tflag = %d\n", dflag, fflag, sflag, tflag); Fprintf(stderr, "vqdst: cflag = %d\n", cflag); }/* * Get info from parameter file, if appropriate */ if( (dflag == 0) && (symtype("distortion") != ST_UNDEF) ) enc_dist = getsym_s("distortion"); if( (fflag == 0) && (symtype("field") == ST_UNDEF) ) ERROR_EXIT("No field to quantize specified"); if(fflag == 0) field = getsym_s("field"); symerr_exit(); /* * Check if input data is complex - exit if it is */ if(is_field_complex(data_ih, field) == YES) ERROR_EXIT("Complex data fields not supported yet"); /* * allocate space for data records */ data_rec = allo_fea_rec(data_ih); /* get number of codebook records from codebook header*/ ncbkrec = n_rec(&cbk_strm, &cbk_ih); /* allocate space for all the codebook info I'll need*/ codebooks = (struct vqcbk **)calloc((unsigned)ncbkrec, sizeof(struct vqcbk *));/* * Get codebook info from input file and pack codebooks array */ for(i = 0; i < ncbkrec; i++){ codebooks[i] = allo_vqfea_rec(cbk_ih); if (get_vqfea_rec(codebooks[i], cbk_ih, cbk_strm) == EOF) ERROR_EXIT("EOF when trying to read codebook record\n"); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -