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

📄 lpcana.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:  Shankar Narayan * Checked by: * Revised by:  John Shore (added per-pulse output, + general method) * * Brief description: * */static char *sccs_id = "@(#)lpcana.c	3.23	1/23/97	ESI/ERL";/* * System Includes */# include <stdio.h>#include <math.h>/* * ESPS includes */#include <esps/esps.h>#include <esps/fea.h>#include <esps/feasd.h>#include <esps/anafea.h>#include <esps/unix.h>#include <esps/window.h>#include <esps/ana_methods.h>/* * DEFINES */#define SYNTAX USAGE("lpcana [-P param_file] [-r range] [-p range] [-m method] [-F] \n [-x debug_level] input_file output_file");#define ERROR_EXIT(text) {(void) fprintf(stderr, "lpcana: %s - exiting\n", text); exit(1);}#define TWENTY 20#define UNVOICED_FRM 0#define VOICED_FRM 1#define BUFSIZE 4096/* Thresholds for voicing decision */#define P_OFFSET 3#define PEAK_THRESHOLD 7.5#define ZCROSS_THRESHOLD 0.20#define LPC_GAIN_THRESHOLD 0.5#define K1_THRESHOLD -0.25/* system functions and variables *//* done via <esps/unix.h>*/FILE *tmpfile();/* external ESPS functions */long   *add_genhd_l ();short  *add_genhd_s ();float  *add_genhd_f ();char   *add_genhd_c ();char   *get_cmd_line ();void write_header ();void put_sd_recf();struct header  *read_header ();struct anafea  *allo_anafea_rec ();int     get_anafea_rec ();void put_anafea_rec ();void lrange_switch();long    debug_level = 0;short   pulse_count = 0;float   *res_data, *raw_data, *tmpbuf;	    /* hold data to be analyzed*/float   fpse[TWENTY], fpeak = 0, bpeak, peakval;float   tcons;int     anal_method = AM_MBURG;int     Fflag = 0;  /* flag for -F (don't redo spectral analysis per pulse */short   frame_size = 160, frame_beg, buf_size, min_pp = 20;short   plocn, zcross_count = 0,  dynamic_frame_size;short   fplocn[TWENTY], fpsize[TWENTY], fptype[TWENTY];long    start, nan = 0, start_p, end_p = 0;/* beginning and end point*/short   matsiz = 11, lpc_order = 10;long    frame_num = 1, frame_count;int	sincn = 0;/* Definitions related to output fea_ana file */FILE * fptr_fea_ana_file = stdout;	/*stream ptr for output file*/char   *fea_ana_file = NULL;		/*holds output file name*/struct header  *fea_oh;			/*points to output header*/struct anafea  *anafea_rec;		/*output data structure*/extern  optind;extern char *optarg;main (argc, argv)    int     argc;    char    *argv[];{/* Definitions related to input SD File */    FILE    *fptr_sd_file = stdin;	/* input file stream */    char    *input_sd_file;		/* input file name */    struct header   *sd_ih;		/* input file header ptr */    FILE    *tmp;			/* ptr for temporary file stream */    struct header   *tmphdr;		/* header for temporary file */    static float    tmpdata[BUFSIZE];	/* for copying data to tmp file */    int     npts = 0;			/* # pts returned by get_sd_recf */    int     common_read = NO;		/* flag for reading ESPS Common */    float   t;    int     c, dataptr, i, j;		/* misc. variables */    char    *param_file = NULL;    int     num_of_files = 0;		/* number of command line filenames */    char   *cmd_line;			/* string for command line */    char   *p_switch = NULL;    char   *Version = "3.23";    char   *Date = "1/23/97";    short   range_err = 0;    long start_orig =0;			/* starting point */    long real_nan = 0;			/* store real nan info */    int   mflag = 0;			/* flag for -m */    int   sflag = 0;			/* flag for -s option*/    long num_channels;    char *analysis;			/* analysis method type *//* check the command line options. */    cmd_line = get_cmd_line (argc, argv);/* store copy of command line *//* this includes an undocumented sync option -- see refcof (1-ESPS) */    while ((c = getopt (argc, argv, "P:x:m:r:p:s:F")) != EOF)    {	switch (c)	{	    case 'r':	    case 'p': 		p_switch = optarg;		break;	    case 'P': 		param_file = optarg;		break;	    case 'm':	        analysis = optarg;		mflag++;		break;	    case 'x': 		debug_level = atoi(optarg);		break;	    case 's':	        sincn = atoi(optarg);	        sflag++;	        break;	    case 'F':		Fflag++;		break;            default: 		SYNTAX;		break;	}    }/* Get the filenames. *//*  * Get the number of filenames on the command line */     if((num_of_files = argc - optind) > 2){	Fprintf(stderr, "Only two file names allowed\n");	SYNTAX;    }    if(debug_level > 0)	Fprintf(stderr, "lpcana: num_of_files = %d\n", num_of_files);    if(num_of_files == 0){	Fprintf(stderr, "No output filename specified\n");	SYNTAX;    }    if(num_of_files == 1) {    /*     * Only output file specified on command line     */    	fea_ana_file = eopen("lpcana", argv[optind], "w", NONE, NONE,			     (struct header **)NULL, &fptr_fea_ana_file);	if (debug_level) 	{	    Fprintf (stderr,"Output file is %s\n", fea_ana_file);	}    /* check common for input filename*/	if((read_params(param_file, SC_CHECK_FILE, (char *)NULL) ) != 0){	    Fprintf(stderr,            "No input file specified on command line and no Common exists\n");	    exit(1);	}	if(symtype("filename") == ST_UNDEF){	    Fprintf(stderr, 	    "No input file specified on command line or in Common\n");	    exit(1);	}	else{	    if(debug_level > 0)		Fprintf(stderr, "Input file name from Common is %s\n",		getsym_s("filename"));	    input_sd_file = eopen("lpcana", getsym_s("filename"), "r",				  FT_FEA, FEA_SD, &sd_ih, &fptr_sd_file);	}	common_read = YES;    }    if (num_of_files == 2)    /*     * Both input and output file names specified on command line     */    {	input_sd_file = eopen("lpcana", argv[optind++], "r", FT_FEA, FEA_SD,			      &sd_ih, &fptr_sd_file);	if (debug_level) 	    Fprintf (stderr,"Input file is %s\n", input_sd_file);    	fea_ana_file = eopen("lpcana", argv[optind], "w", NONE, NONE,			     (struct header **)NULL, &fptr_fea_ana_file);	if (debug_level) 	{	    Fprintf (stderr,"Output file is %s\n", fea_ana_file);	}    }/* * Check for unsupported input types */    if((num_channels =         get_fea_siz("samples", sd_ih,(short *) NULL, (long **) NULL)) != 1)    {	Fprintf(stderr, 		"lpcana: Multichannel data not supported yet - exiting.\n");	exit(1);    }    if(is_field_complex(sd_ih, "samples") == YES)    {	Fprintf(stderr, "lpcana: Complex data not supported - exiting.\n");	exit(1);    }    /*parse range -- whole file unless -p option overrides or common file		contains start and nan */    start = 1;    nan = 0;    if(sd_ih->common.ndrec == -1)   /* input is a pipe or record				     * length is variable */    {    /*     * Copy input into a temporary file      */    	tmp = tmpfile();	/* Get version of header without any Esignal header, mu-law	 * flag, etc.  Otherwise we risk getting garbage by writing the	 * temp file as an ESPS FEA file and reading it back as some	 * other format.	 */	tmphdr = copy_header(sd_ih);	write_header(tmphdr, tmp);    	while ((npts = get_sd_recf(tmpdata, BUFSIZE, sd_ih, fptr_sd_file)) 	       != 0)	{	    put_sd_recf(tmpdata, npts, tmphdr, tmp);	    nan += npts;	}	fclose(fptr_sd_file);        rewind(tmp);	sd_ih = read_header(tmp);	fptr_sd_file = tmp;    }    else	nan = sd_ih->common.ndrec;        real_nan = nan;/* * read params and Common, if approppriate */    if (common_read == NO && strcmp("<stdin>",input_sd_file) != 0){ 	/* not pipe */	/* then read params and read common if file matches */	(void) read_params(param_file, SC_CHECK_FILE, input_sd_file);     }    else /* common_read == no && strcmp("<stdin>",input_sd_file) == 0 */ {	/*it is a pipe - read params, but don't read common*/	(void)read_params(param_file, SC_NOCOMMON, (char *)NULL);    }/* * Check analysis method */    if (!mflag) {	if (symtype("method") != ST_UNDEF)	    analysis = getsym_s("method");	else	    analysis = "MBURG";    }    if ((anal_method = lin_search(ana_methods, analysis)) == -1) {  	(void)fprintf(stderr, "lpcana: analysis method is %s\n", analysis);	ERROR_EXIT("Invalid spectrum analysis method");    }      if (debug_level) Fprintf(stderr,			     "lpcana: analysis method is %s\n",			     ana_methods[anal_method]);    if ((anal_method != AM_AUTOC) 	&& (anal_method != AM_STRCOV) 	&& (anal_method != AM_STRCOV1)	&& sflag)    {	(void) fprintf(stderr, 		       "lpcana: method not AUTOC, STRCOV, or STRCOV1.\n");	(void) fprintf(stderr, " -s option ignored\n");    }    if (!p_switch) {	if(symtype("start") != ST_UNDEF)	    start = getsym_i("start");          	if(symtype("nan") != ST_UNDEF)	    nan = getsym_i("nan");	if(nan == 0)/* do whole file */	    nan = real_nan;	      	if ((start < 1) || (nan < 0) || (nan > real_nan))	  range_err++;    }    else {	/* get start and nan from the command line*/	lrange_switch (p_switch, &start_p, &end_p, 1);	if ((start_p < 1) || (end_p > (start_p + real_nan - 1)))	    range_err++;	start = start_p;	if (end_p == 0)	    end_p = real_nan;	nan = end_p - start_p + 1;    }    if (range_err > 0)    {	Fprintf (stderr,		 "lpcana: specified range %ld:+%ld not in input file\n",		 start, nan);	exit (1);    }/* * Get rest of parameters*/        if(symtype("lpc_frame_size") != ST_UNDEF)        frame_size = getsym_i ("lpc_frame_size");    if(symtype("lpc_filter_order") != ST_UNDEF)        lpc_order = getsym_i ("lpc_filter_order");    if(lpc_order > TWENTY){	Fprintf(stderr, "lpcana: Lpc_filter_order must be <= 20\n");	exit(1);    }    if(symtype("minimum_pulse_length") != ST_UNDEF)        min_pp = getsym_i ("minimum_pulse_length");    symerr_exit (); /* exit if any parameters were missing*//* * Compute constants*/    dynamic_frame_size = frame_size;    matsiz = lpc_order + 1;    frame_beg = 3 * frame_size;    buf_size = 4 * frame_size;    frame_count = nan / frame_size;    nan = frame_count * frame_size;    if (debug_level > 0){	Fprintf(stderr, "lpcana: Input file = %s\n", input_sd_file);	Fprintf(stderr, "lpcana: Output file = %s\n", fea_ana_file);	Fprintf(stderr, 	"lpcana: Frame_size = %d, lpc_order = %d, min_pp= %d\n", 	   frame_size, lpc_order, min_pp);	Fprintf(stderr, "lpcana: frame_beg = %d, buf_size = %d\n",	    frame_beg, buf_size);	Fprintf(stderr, "lpcana: frame_count = %ld, nan = %ld\n",	    frame_count, nan);    }/* Allocate memory for arrays */    res_data = (float *) malloc ((unsigned)(buf_size * sizeof *res_data));    if (res_data == NULL)    {	Fprintf (stderr, "lpcana: couldn't allocate dynamic memory for array - res_data\n");	exit (1);    }    raw_data = (float *) malloc ((unsigned)(buf_size * sizeof *raw_data));    if (raw_data == NULL)    {	Fprintf (stderr, "lpcana: couldn't allocate dynamic memory for array - raw_data\n");	exit (1);    }    for (i = 0; i < buf_size; i++) 	raw_data[i] = res_data[i] = 0;    tmpbuf = (float *) malloc ((unsigned)(frame_size * sizeof *tmpbuf));    if (tmpbuf == NULL)    {	Fprintf (stderr, "lpcana: couldn't allocate dynamic memory for array - tmpbuf\n");	exit (1);    }/* Create output header */

⌨️ 快捷键说明

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