📄 fea2ana.c
字号:
/* * This material contains proprietary software of Entropic Speech, Inc. * Any reproduction, distribution, or publication without the 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 1986 Entropic Speech, Inc." * * Program: * * Written by: John Shore * Checked by: * * This is fea2ana.c -- converts FEA_ANA file to ANA file */#ifndef lintstatic char *sccs_id = "@(#)fea2ana.c 1.3 5/22/87 ESI";#endif#define MAX(a, b) ((a > b) ? a : b) /*returns greater of a, b*/#define getval(a,b,c) (p = get_genhd(a,b)) ? *(c *)p : 0/* * system include files */#include <stdio.h>/* * system include files */#include <sps/sps.h>#include <sps/fea.h>#include <sps/ana.h>#include <sps/anafea.h>/* * defines */#define ERROR_EXIT(text) {(void) fprintf(stderr, "ana2fea: %s - exiting\n", \ text); exit(1);}#define SYNTAX USAGE ("ana2fea input.fea output.ana")/* * system functions and variables */int getopt ();int atoi(), strcmp(), fclose();extern optind;extern char *optarg;char *strcpy();void exit(), perror();/* * external SPS functions */long *add_genhd_l();short *add_genhd_s();float *add_genhd_f();char *add_genhd_c();char *get_cmd_line();void write_header();struct header *read_header();struct ana_data *allo_ana_rec();struct anafea *allo_anafea_rec();int init_anafea_rec();int get_anafea_rec();void put_anafea_rec();/* * global function declarations */void fea2ana();/* * global variable declarations */char *cmd_line; /*string for command line*//* * main program */main (argc, argv)int argc;char **argv;{/* * setup and initialization */ char *version = "1.3"; char *date = "5/22/87"; char *out_ana = NULL; /*output ANA file*/ FILE *ana_strm = stdout; struct header *ana_oh; char *in_fea = NULL; /*input FEA_ANA file*/ struct header *fea_ih; FILE *fea_strm = stdin; int c; /*for getopt return*/ struct anafea *anafea_rec; struct ana_data *ana_rec; int i; int debug_level = 0; long maxp, maxr, maxl, order_v, order_uv; short *pre_siz, size; float *pre_zeros, *pre_poles; char *p; cmd_line = get_cmd_line(argc, argv); /*store copy of command line*//* * process command line options */ while ((c = getopt (argc, argv, "x:")) != EOF) { switch (c) { case 'x': debug_level = atoi (optarg); break; default: SYNTAX; } }/* * process file arguments */ if (optind < argc) { in_fea = argv[optind++]; if (strcmp (in_fea, "-") == 0) in_fea = "<stdin>"; else TRYOPEN (argv[0], in_fea, "r", fea_strm); } else { Fprintf(stderr, "ana2fea no input FEA file specified.\n"); SYNTAX; } if (optind < argc) { out_ana = argv[optind++]; if (strcmp (out_ana, "-") == 0) out_ana = "<stdout>"; else TRYOPEN (argv[0], out_ana, "w", ana_strm); } else { Fprintf(stderr, "ana2fea no output ANA file specified.\n"); SYNTAX; }/* * read values from header of input FEA file */ if ((fea_ih = read_header(fea_strm)) == NULL) ERROR_EXIT("couldn't read input FEA file header"); maxp = *(long *)get_genhd("maxpulses", fea_ih); maxl = *(long *)get_genhd("maxlpc", fea_ih); maxr = *(long *)get_genhd("maxraw", fea_ih); order_v = *(long *)get_genhd("order_vcd", fea_ih); order_uv = *(long *)get_genhd("order_unvcd", fea_ih); if (*(short *)get_genhd("spec_rep", fea_ih) != RC) ERROR_EXIT("input FEA_ANA file doesn't contain RCs"); if ((*(short *) get_genhd("filters", fea_ih)) == YES) Fprintf(stderr, "fea2ana: WARNING - filters being discarded\n");/* * create and write headers for output file */ ana_oh = new_header(FT_ANA); ana_oh->variable.refer = fea_ih->variable.refer; ana_oh->common.tag = fea_ih->common.tag; add_source_file(ana_oh, in_fea, fea_ih); (void) strcpy (ana_oh->common.prog, "fea2ana"); (void) strcpy (ana_oh->common.vers, version); (void) strcpy (ana_oh->common.progdate, date); if (add_comment(ana_oh, cmd_line) == 0) Fprintf(stderr, "fea2ana: WARNING - not enough space for command line in comment\n"); ana_oh->hd.ana->order_vcd = order_v; ana_oh->hd.ana->order_unvcd = order_uv; ana_oh->hd.ana->maxraw = maxr; ana_oh->hd.ana->maxlpc = maxl; ana_oh->hd.ana->maxpulses = maxp; ana_oh->hd.ana->src_sf = *(float *)get_genhd("src_sf", fea_ih); ana_oh->hd.ana->start = getval("start",fea_ih,long); ana_oh->hd.ana->nan = getval("nan",fea_ih,long); ana_oh->hd.ana->frmlen = getval("frmlen",fea_ih,short); ana_oh->hd.ana->p_offset = getval("p_offset",fea_ih,short); ana_oh->hd.ana->piq_method = getval("piq_method",fea_ih,short); ana_oh->hd.ana->rcq_method = getval("rcq_method",fea_ih,short); ana_oh->hd.ana->pwq_method = getval("pwq_method",fea_ih,short); ana_oh->hd.ana->lpq_method = getval("lpq_method",fea_ih,short); ana_oh->hd.ana->win_type = getval("win_type",fea_ih,short); ana_oh->hd.ana->a_method = getval("a_method",fea_ih,short); ana_oh->hd.ana->dcrem = getval("dcrem",fea_ih,float); ana_oh->hd.ana->psynch = getval("psynch",fea_ih,short); ana_oh->hd.ana->matsiz = getval("matsiz",fea_ih,short); ana_oh->hd.ana->rms_fullscale = getval("rms_fullscale",fea_ih,double); ana_oh->hd.ana->sinc_flg = getval("sinc_flg",fea_ih,short); if (genhd_type("pre_siz",&size,fea_ih) != HD_UNDEF) { pre_siz = (short *)get_genhd("pre_siz",fea_ih); if (pre_siz[0] > 0) pre_zeros = (float *)get_genhd("pre_zeros",fea_ih); if (pre_siz[1] > 0) pre_poles = (float *)get_genhd("pre_poles",fea_ih); ana_oh->hd.ana->pre_emp = new_zfunc(pre_siz[0], pre_siz[1], pre_zeros, pre_poles); } write_header(ana_oh, ana_strm);/* * allocate records for SPS files */ anafea_rec = allo_anafea_rec(fea_ih); ana_rec = allo_ana_rec(ana_oh);/* * main processing goes here */ while (get_anafea_rec(anafea_rec, fea_ih, fea_strm) != EOF) { fea2ana(anafea_rec, ana_rec, ana_oh); put_ana_rec(ana_rec, ana_oh, ana_strm); } exit(0);}voidfea2ana(fea, ana, anahd)struct ana_data *ana;struct anafea *fea;struct header *anahd;/* *convert an FEA_ANA record to an ANA record*/{ short voiced; long npulse = 0; long maxorder; int i; maxorder = MAX(anahd->hd.ana->order_vcd, anahd->hd.ana->order_unvcd); if (anahd->common.tag == YES) ana->tag = *fea->tag; ana->frame_len = *fea->frame_len; voiced = (*fea->num_pulses != 0); for (i = 0; i < anahd->hd.ana->maxpulses; i++) { if (voiced && (i < *fea->num_pulses)) ana->p_pulse_len[i] = fea->p_pulse_len[i]; else ana->p_pulse_len[i] = 0; } for (i = 0; i < anahd->hd.ana->maxraw; i++) ana->raw_power[i] = fea->raw_power[i]; for (i = 0; i < anahd->hd.ana->maxlpc; i++) ana->lpc_power[i] = fea->lpc_power[i]; for (i = 0; i < maxorder; i++) ana->ref_coeff[i] = fea->spec_param[i]; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -