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

📄 ana2fea.c

📁 speech signal process tools
💻 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 ana2fea.c -- converts ANA file to FEA_ANA file */#ifndef lintstatic char *sccs_id = "@(#)ana2fea.c	1.3 5/22/87 ESI";#endif#define MAX(a, b) ((a > b) ? a : b) /*returns greater of a, b*//* * 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.ana output.fea")/* * 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 ana2fea();/* * 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	    *input_ana = NULL;	    /*input ANA file*/    FILE	    *ana_strm = stdin;    struct header   *ana_ih;    char	    *out_fea = NULL;	    /*output FEA_ANA file*/    struct header   *fea_oh;    FILE	    *fea_strm = stdout;    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;    float *pre_zeros, *pre_poles;    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) {	input_ana = argv[optind++];	if (strcmp (input_ana, "-") == 0)	    input_ana = "<stdin>";	else	    TRYOPEN (argv[0], input_ana, "r", ana_strm);	}    else {	Fprintf(stderr, "ana2fea no input ANA file specified.\n");	SYNTAX;        }    if (optind < argc) {	out_fea = argv[optind++];	if (strcmp (out_fea, "-") == 0)	    out_fea = "<stdout>";	else	    TRYOPEN (argv[0], out_fea, "w", fea_strm);	}    else {	Fprintf(stderr, "ana2fea no output file specified.\n");	SYNTAX;        }/* * read values from header of input SD file */    if ((ana_ih = read_header(ana_strm)) == NULL)      	ERROR_EXIT("couldn't read input ANA file header");    maxp = ana_ih->hd.ana->maxpulses;    maxr = ana_ih->hd.ana->maxraw;    maxl = ana_ih->hd.ana->maxlpc;    order_v = ana_ih->hd.ana->order_vcd;    order_uv = ana_ih->hd.ana->order_unvcd;/* * create and write headers for output file (no filters in record) */    fea_oh = new_header(FT_FEA);    fea_oh->common.tag = ana_ih->common.tag;    fea_oh->variable.refer = ana_ih->variable.refer;    if (init_anafea_hd(fea_oh, order_v, order_uv, maxp, maxr, maxl, 0, 0) != 0)	ERROR_EXIT("error filling FEA_ANA header");    add_source_file(fea_oh, input_ana, ana_ih);    (void) strcpy (fea_oh->common.prog, "ana2fea");    (void) strcpy (fea_oh->common.vers, version);    (void) strcpy (fea_oh->common.progdate, date);    if (add_comment(fea_oh, cmd_line) == 0) 	Fprintf(stderr, 	 "ana2fea: WARNING - not enough space for command line in comment\n");    *add_genhd_l("start", (long *)NULL, 1, fea_oh) = ana_ih->hd.ana->start;    *add_genhd_l("nan", (long *)NULL, 1, fea_oh) = ana_ih->hd.ana->nan;    *add_genhd_s("frmlen", (short *)NULL, 1, fea_oh) = ana_ih->hd.ana->frmlen;    *add_genhd_s("p_offset", (short *)NULL, 1, fea_oh) = 		ana_ih->hd.ana->p_offset;    *add_genhd_s("piq_method", (short *)NULL, 1, fea_oh) = 		ana_ih->hd.ana->piq_method;    *add_genhd_s("rcq_method", (short *)NULL, 1, fea_oh) = 		ana_ih->hd.ana->rcq_method;    *add_genhd_s("pwq_method", (short *)NULL, 1, fea_oh) = 		ana_ih->hd.ana->pwq_method;    *add_genhd_s("lpq_method", (short *)NULL, 1, fea_oh) = 		ana_ih->hd.ana->lpq_method;    *add_genhd_s("win_type", (short *)NULL, 1, fea_oh) = 		ana_ih->hd.ana->win_type;    *add_genhd_s("a_method", (short *)NULL, 1, fea_oh) = 		ana_ih->hd.ana->a_method;    *add_genhd_f("dcrem", (short *)NULL, 1, fea_oh) = 		ana_ih->hd.ana->dcrem;    *add_genhd_s("psynch", (short *)NULL, 1, fea_oh) = 		ana_ih->hd.ana->psynch;    *add_genhd_s("matsiz", (short *)NULL, 1, fea_oh) = 		ana_ih->hd.ana->matsiz;    *add_genhd_d("rms_fullscale", (short *)NULL, 1, fea_oh) = 		ana_ih->hd.ana->rms_fullscale;    *add_genhd_s("sinc_flg", (short *)NULL, 1, fea_oh) = 		ana_ih->hd.ana->sinc_flg;    pre_siz = add_genhd_s("pre_siz", (short *)NULL, 2, fea_oh);    pre_siz[0] = ana_ih->hd.ana->pre_emp->nsiz;    pre_siz[1] = ana_ih->hd.ana->pre_emp->dsiz;    pre_zeros = add_genhd_f("pre_zeros", (float *)NULL, (int)pre_siz[0],	fea_oh);    pre_poles = add_genhd_f("pre_poles", (float *)NULL, (int)pre_siz[1],	fea_oh);    (void) f_copy(pre_zeros, ana_ih->hd.ana->pre_emp->zeros, pre_siz[0]);    (void) f_copy(pre_poles, ana_ih->hd.ana->pre_emp->poles, pre_siz[1]);    *(float *) get_genhd("src_sf", fea_oh) = ana_ih->hd.ana->src_sf;    *(short *) get_genhd("spec_rep", fea_oh) = RC;    write_header(fea_oh, fea_strm);/* * allocate records for SPS files  */    anafea_rec = allo_anafea_rec(fea_oh);    ana_rec = allo_ana_rec(ana_ih);/* * main processing goes here */    while (get_ana_rec(ana_rec, ana_ih, ana_strm) != EOF) {	ana2fea(ana_rec, anafea_rec, ana_ih);	put_anafea_rec(anafea_rec, fea_oh, fea_strm);    }    exit(0);}   voidana2fea(ana, fea, anahd)struct ana_data *ana;struct anafea *fea;struct header *anahd;/* *convert an ANA record to a FEA_ANA record*/{    short voiced;    long maxorder;    int i;    maxorder = MAX(anahd->hd.ana->order_vcd, anahd->hd.ana->order_unvcd);    if (anahd->common.tag) *fea->tag = ana->tag;    *fea->frame_len = ana->frame_len;    voiced = (ana->p_pulse_len[0] != 0);    if (voiced) {	*fea->frame_type = VOICED;	*fea->voiced_fraction = 1.0;    }    else {	*fea->frame_type = UNVOICED;	*fea->voiced_fraction = 0.0;    }    for (i = 0; i < anahd->hd.ana->maxpulses; i++) {	fea->p_pulse_len[i] = ana->p_pulse_len[i];    }    *fea->num_pulses = anahd->hd.ana->maxpulses;    for (i = 0; i < anahd->hd.ana->maxpulses; i++) {	if (fea->p_pulse_len[i] == 0) {		*fea->num_pulses = i;		break;	}    }    for (i = 0; i < anahd->hd.ana->maxraw; i++) 	fea->raw_power[i] = ana->raw_power[i];    for (i = 0; i < anahd->hd.ana->maxlpc; i++) 	fea->lpc_power[i] = ana->lpc_power[i];    for (i = 0; i < maxorder; i++) 	fea->spec_param[i] = ana->ref_coeff[i];  }

⌨️ 快捷键说明

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