find_ep.c
来自「speech signal process tools」· C语言 代码 · 共 922 行 · 第 1/2 页
C
922 行
/* * 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-1992 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: * * This program locates the endpoints of a speech segment * in a sampled-data file. */static char *sccs_id = "@(#)find_ep.c 1.14 5/12/97 ESI/ERL";#define VERSION "1.14"#define DATE "5/12/97"/* system Includes*/#include <stdio.h>#include <math.h>/*ESPS Includes*/#include <esps/esps.h>#include <esps/ftypes.h>#include <esps/fea.h>#include <esps/feasd.h>#include <esps/unix.h>#define SYNTAX \USAGE("find_ep [-b adbits] [-c context] [-e] [-f final_thresh]\n [-h high_thresh] [-l low_thresh] [-n] [-p start_point] [-r start_point]\n [-s silence_req] [-t time] [-w] [-x debug-level] [infile.sd] [outfile.sd]")/* system functions*//*done via <esps/unix.h>*//* ESPS Functions */void set_sd_type();int get_sd_type();void fea_skiprec();int getopt();int read_params();void symerr_exit();int get_sd_recd();void add_comment();void put_sd_recd();int putsym_i();int putsym_s();int getsym_i();char *getsym_s();char *eopen();/* Global Variables */int debug_level = 0; /* debugger flag */extern optind;extern char *optarg, *get_cmd_line();main (argc, argv) int argc;char **argv;{ int c; /*parameter parsing*/ FILE *f1p, *f2p; /* file steam pointers */ struct header *f1h, *f2h; /* pointers to header structure */ char *f1 = NULL, *f2 = NULL; /* filename pointers */ int lflag = 0; /* low threshold flag */ int hflag = 0; /* high threshold flag */ int fflag = 0; /* final threshold flag*/ int nflag = 0; /* next segment flag */ int eflag = 0; /* supress error flag */ int wflag = 0; /* write output file flag */ float scalad = 1.; /* 2**(adbits - 12) */ int error = 0; /* error status */ int num_of_files = 0; /* number of command line files*/ int adbits = 12; /*number of bits in A/D converter*/ long start = 1; /* starting point in file */ float sil_req = 200.; /* silence required between words*/ float low_thresh = 0.; /* variable for first threshold */ float high_thresh = 0.; /* variable for second threshold */ float final_thresh = 0.; /* variable for end threshold */ float sf = 8000.; /* input file sampling frequancy */ float context = 10.; /* internal frame size in milliseconds */ float time = 150.; /* time period for computing statistics */ double *buff; /* buffer for writing output data */ long s_pt; /* starting record position */ long e_pt; /* ending record position */ int endpoints(); /* function that finds endpoints */ void error_exit(); /* function that prints error messages*//* get options from command line and set various flags */ while ((c = getopt (argc, argv, "x:r:p:s:l:h:f:c:t:b:nwe")) != EOF) { switch (c) { case 'x': debug_level = atoi (optarg); if(debug_level > 0) Fprintf(stderr, "find_ep: debug_level = %d\n", debug_level); break; case 'r': case 'p': start = atoi (optarg); if(start < 1){ Fprintf(stderr, "find_ep: starting point must be >= 1\n"); exit(1); } break; case 's': sil_req = atof (optarg); break; case 'l': lflag++; low_thresh = atof( optarg); if(low_thresh <= 0){ Fprintf(stderr, "find_ep: Low_thresh must be > 0\n"); exit(1); } break; case 'h': hflag++; high_thresh = atof( optarg); break; case 'f': fflag++; final_thresh = atof( optarg); break; case 'c': context = atof( optarg); if(context < 1){ Fprintf(stderr, "find_ep: Context must be >= 1 msec.\n"); exit(1); } break; case 't': time = atof( optarg); break; case 'b': adbits = atoi(optarg); scalad = (float)( pow( (double)(2.), (double)(adbits - 12) ) ); break; case 'n': nflag++; break; case 'e': eflag++; break; case 'w': wflag++; break; default: SYNTAX; } } /* * Check for some inconsistencies */ if( lflag && fflag) /* both low and final threshold specified*/ if(final_thresh >= low_thresh){ Fprintf(stderr, "find_ep: final_thresh must be < low_thresh\n"); exit(1); } if( time < context){ Fprintf(stderr, "Time interval for statistics (-t) must be >= context (-c)\n"); exit(1); }/* find out how many files are specified and open appropriate files */ num_of_files = (argc - optind); if(num_of_files > 1 && !wflag ) /*too many files specified*/ { SYNTAX; exit(1); } if(debug_level > 0) Fprintf(stderr, "find_ep: Number of files = %d\n", num_of_files);/* * Read Common to define symbols*/ (void)read_params((char *)NULL, SC_CHECK_FILE, (char *)NULL); /* * Get input and output file names */ /* * No file specified, get input file name from Common */ if(num_of_files == 0 ){ /* * Get input file name */ if(symtype("filename") == ST_UNDEF){ Fprintf(stderr, "find_ep: No input file specified\n"); SYNTAX; exit(1); } else f1 = getsym_s("filename"); } /* * Only one file specified, decide whether it is input or output */ if(num_of_files == 1){ if(wflag){/*specified file is output filename - get input filename from ESPS Common*/ f2 = argv[optind++]; /* * Get input file name from Common */ if(symtype("filename") == ST_UNDEF){ Fprintf(stderr, "find_ep: No input file in ESPS Common\n"); exit(1); } else f1 = getsym_s("filename"); } else {/* specified file is input filename - no output file */ f1 = argv[optind++]; f2 = "\"none specified\""; } } /* * both input and output files are specified */ if(num_of_files == 2){ f1 = argv[optind++]; f2 = argv[optind++]; } symerr_exit(); if(debug_level > 0){ Fprintf(stderr, "find_ep: Input file is %s\n", f1); Fprintf(stderr, "find_ep: Output file is %s\n", f2); }/* *open input file */ f1 = eopen("find_ep", f1, "r", FT_FEA, FEA_SD, &f1h, &f1p);/* * if needed, open output file*/ if(wflag && (strcmp(f1, "<stdin>")== 0)){ Fprintf(stderr,"find_ep: -w option cannot be used with stdin\n"); exit(1); } if(wflag){ f2 = eopen("find_ep", f2, "w", NONE, NONE, &f2h, &f2p); if(strcmp(f2, "<stdout>") == 0){ Fprintf(stderr, "find_ep: Standard output cannot be used\n"); exit(1); } }/* * check if input file is multichannel*/ if(get_fea_siz("samples", f1h,(short *) NULL, (long **) NULL) != 1) { Fprintf(stderr, "find_ep: Multichannel data not supported yet - exiting.\n"); exit(1); }/* * Check if input data is complex*/ if(is_field_complex(f1h, "samples") == YES) { Fprintf(stderr, "find_ep: Complex data not supported - exiting.\n"); exit(1); }/* * Get sampling frequency from input file*/ sf = (float)get_genhd_val("record_freq",f1h, (double)8000.); if(debug_level > 0) Fprintf(stderr, "find_ep: Sampling frequency = %f\n", sf);/* * if -n specifed, Get starting point from common if possible*/ if(nflag && ( strcmp(f1, "<stdin>") == 0 ) ){ /* * standard input and -n cannot be used together */ Fprintf(stderr, "find_ep: Standard input and -n option cannot both be used\n"); exit(1); } if (nflag) { if (symtype("filename") == ST_UNDEF) { Fprintf(stderr, "find_ep: no filename in ESPS Common\n"); exit(1); } if (strcmp(f1, getsym_s("filename")) != 0) { Fprintf(stderr, "find_ep: ESPS Common filename does not match input filename\n"); exit(1); } if (symtype("start") == ST_UNDEF) { Fprintf(stderr, "find_ep: No start value in Common\n"); exit(1); } start = getsym_i("start"); if (symtype("nan") == ST_UNDEF) { Fprintf(stderr, "find_ep: No nan value in Common\n"); exit(1); } start += getsym_i("nan"); start += ROUND(sf * .05) + 1;/*move 50 msec beyond end of last segment*/ /* check for errors */ symerr_exit(); if (debug_level > 0) Fprintf(stderr, "find_ep: -n option used; starting point from common\n"); } if(debug_level > 0) Fprintf(stderr, "find_ep: Start value = %ld\n", start); /* * Skip forward to the starting point */ if(debug_level > 3) Fprintf(stderr, "find_ep: Size of data record = %d\n", (size_rec(f1h))); fea_skiprec(f1p, start-1, f1h); /* * Setups all done; go find endpoints */ error = 0; error = endpoints(f1h, f1p, start, &s_pt, &e_pt, sf, scalad, sil_req, low_thresh, hflag, high_thresh, fflag, final_thresh, context, time); /* * Check error status; if > 0, problem finding endpoints */ if(debug_level > 0) Fprintf(stderr, "find_ep: Error status = %d\n", error); if(error > 0) error_exit(error, eflag); /* * write output file, if requested */ if(wflag){ if(debug_level > 0){ Fprintf(stderr, "find_ep: Writing output file\n"); Fprintf(stderr, "find_ep: start = %ld, end = %ld\n", s_pt, e_pt); } /* * make header */ f2h = copy_header(f1h); (void)strcpy(f2h -> common.prog, "find_ep"); (void)strcpy(f2h -> common.vers, VERSION); (void)strcpy(f2h -> common.progdate, DATE); add_source_file(f2h, f1, f1h); (void)add_comment(f2h, get_cmd_line(argc, argv)); update_waves_gen(f1h, f2h, (float)s_pt, 1.0); write_header(f2h, f2p); /* * get points from input file */ rewind(f1p); f1h = read_header(f1p); fea_skiprec(f1p, s_pt-1, f1h); /* * check if number of points is greater than an int */ if( (int)(e_pt-s_pt+1) != (e_pt-s_pt+1) ){ Fprintf(stderr, "Data segment is too big to copy\n"); Fprintf(stderr, "Try without the -w option\n"); exit(1); } buff = (double *)calloc((unsigned)(e_pt-s_pt+1), sizeof(double)); spsassert(buff != NULL, "Couldn't allocate space for buff"); if(get_sd_recd(buff, (int)(e_pt-s_pt+1), f1h, f1p) != (e_pt-s_pt+1)){ Fprintf(stderr, "find_ep: Bogus starting (%ld) or end (%ld) points found\n", s_pt, e_pt); Fprintf(stderr, "find_ep: Problem with find_ep program\n"); exit(1); } /* write output data */ put_sd_recd(buff, (int)(e_pt-s_pt+1), f2h, f2p); } /* * Set start and nan in ESPS Common */ /* I would have used putsym_l (put sym long), if it existed*/
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?