📄 copysps.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) 1987-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: Ajaipal S. Virdy Checked by: Revised by: Alan Parker * * Copy records of an ESPS file to a new ESPS file or append to an existing ESPS * file. * */#ifdef SCCSstatic char *sccs_id = "@(#)copysps.c 3.24 6/3/98 ESI/ERL";#define VERSION "3.24"#define DATE "6/3/98"#endif#ifndef VERSION#define VERSION "debug"#endif#ifndef DATE#define DATE "none"#endif#include <stdio.h>#include <errno.h>#include <esps/esps.h>#include <esps/fea.h>#include <esps/feasd.h>#include <esps/spec.h>#include <esps/filt.h>#include <esps/scbk.h>#include <esps/unix.h>#include <esps/esignal_fea.h>#define SYNTAX USAGE ("copysps [-x debug_level] [-f] [-r|-p gen_range] [-s time_range ] [-z] [infile] outfile")#define ERROR_EXIT(text) {(void) fprintf(stderr, "copysps: %s - exiting\n", text); exit(1);}int debug_level = 0;extern void trange_switch();char *e_temp_name();char *get_sphere_hdr();main(argc, argv) int argc; char **argv;{ /* begin main */ int c, getopt(); extern int optind; extern int errno; extern char *optarg; char *get_cmd_line(); char *f1name, *f2name, *tmpname; FILE *f1strm, *f2strm, *tstrm; struct header *f1hd, *f2hd; char *dbuf; /* array to hold data read in */ int debug = 0; int rflag = 0; int gflag = 0; long *rec_range = NULL; long tot_rec; int sflag = 0; char *srange = NULL; char *rrange = NULL; long input_ndrec = 0; long i, s_rec = 1, e_rec; int fast = 0; int nohead = 0; int update = 0; /* set if we have to update output * file */ int nofile = 0; /* set if no input file on command * line */ int zflag = 0; long cur_pos, new_pos; /* variables for positioning * seek() */ char *template = "copyspsXXXXXX"; struct fea_data *f1rec, *f2rec; /* ESPS functions referenced */ long *grange_switch(); int size_rec(); int recsize1, recsize2; char *eopen(); char *savestring(); int j; /* Local functions referenced */ void check_sd(); void check_spec(); void check_filt(); void add_sd_comment(); void add_spec_comment(); void add_filt_comment(); long common_nan; while ((c = getopt(argc, argv, "x:fr:p:s:hzg:")) != EOF) switch (c) { case 'x': debug = atoi(optarg); break; case 'p': case 'g': rec_range = grange_switch(optarg, &tot_rec); gflag = 1; break; case 's': srange = optarg; sflag = 1; break; case 'r': rrange = optarg; rflag = 1; break; case 'f': fast++; break; case 'h': nohead++; break; case 'z': zflag++; break; default: SYNTAX; } /* Determine if output file is specified */ if (argc - optind < 1) { Fprintf(stderr, "copysps: no output file specified.\n"); SYNTAX; } /* * If f2name is "-", then use stdout for f2strm. If f2name exists, * then update the file, otherwise create it. */ f2name = argv[argc - 1]; if (strcmp(f2name, "-") != 0) if ((f2strm = fopen(f2name, "r")) == NULL) update = 0; /* outfile doesn't exist */ else update = 1; /* outfile exists */ if (argc - optind < 2) {/* only output file name specified */ /* user must supply two file names (or "-") */ /* SYNTAX; */ nofile = 1; f1name = NULL; } else { /* open input file */ f1name = eopen("copysps", argv[optind], "r", NONE, NONE, &f1hd, &f1strm); if (strcmp(f1name, "<stdin>") == 0) { ERROR_EXIT("Standard input not supported"); } } /* * If command line has no input file name, then it might be in ESPS * common; we need to read_params anyway (provided stdin not used), * so we do it here (checking common only); However, we don't check * common if more than one input file is given since this is error * prone. */ if (nofile || ((f1strm != stdin) && (argc - optind <= 2))) { if (debug) Fprintf(stderr, "copysps: checking ESPS common\n"); (void) read_params((char *) NULL, SC_CHECK_FILE, f1name); } if (nofile) { if (symtype("filename") == ST_UNDEF) { ERROR_EXIT("no input file name on command line or in common"); } else { f1name = getsym_s("filename"); if (debug) Fprintf(stderr, "copysps: input file name from common is %s\n", f1name); if (strcmp(f2name, f1name) == 0) ERROR_EXIT("input name from common same as output file"); (void) eopen("copysps", f1name, "r", NONE, NONE, &f1hd, &f1strm); if (!f1hd->common.edr && edr_default(f1hd->common.machine_code)) f1hd->common.edr = YES; if (!zflag) Fprintf(stderr, "copysps: input file name %s taken from ESPS Common.\n", f1name); } } s_rec = 1; e_rec = (f1hd->common.ndrec != -1 ? f1hd->common.ndrec : LONG_MAX); if (rflag) range_switch(rrange, &s_rec, &e_rec, 1); if (sflag) { s_rec = 1; e_rec = f1hd->common.ndrec; trange_switch(srange, f1hd, &s_rec, &e_rec); if (s_rec < 0) { ERROR_EXIT("requested start time is less than start_time of file"); } } if (!gflag && !sflag && !rflag) { s_rec = 1; e_rec = f1hd->common.ndrec; if (symtype("start") != ST_UNDEF) { s_rec = getsym_i("start"); if (!zflag) Fprintf(stderr, "copysd: starting record = %ld taken from ESPS Common\n", s_rec); } if (symtype("nan") != ST_UNDEF) { common_nan = getsym_i("nan"); if (!zflag) Fprintf(stderr, "copysd: number records = %ld taken from ESPS Common\n", common_nan); if (common_nan != 0) e_rec = s_rec + common_nan - 1; } } if (strcmp(f1name, f2name) == 0) { ERROR_EXIT("infile and outfile cannot be the same"); } if (debug) Fprintf(stderr, "copysps: infile = %s, outfile = %s, update = %d, fast = %d\n", f1name, f2name, update, fast); /* Check if outfile exists and is an ESPS file */ if (update) { /* outfile exists */ if (!(f2hd = read_header(f2strm))) NOTSPS("copysps", f2name); if (get_esignal_hdr(f2hd)) { ERROR_EXIT("cannot append to an Esignal file"); } if (get_sphere_hdr(f2hd)) { ERROR_EXIT("cannot append to a Sphere file"); } if (get_pc_wav_hdr(f2hd)) { ERROR_EXIT("cannot append to a PC WAV (RIFF) file"); } input_ndrec = f2hd->common.ndrec; /* Check for compatibility */ if (debug) Fprintf(stderr, "copysps: %s already exists; check for compatibility.\n", f2name); switch (f2hd->common.type) { case FT_FEA:{ short **trans; /* translation table * returned */ int com_lev; /* compatibility level */ if (debug) Fprintf(stderr, "copysps: calling fea_compat.\n"); com_lev = fea_compat(f1hd, f2hd, (char **) NULL, &trans); if (debug) Fprintf(stderr, "copysps: com_lev = %d, trans is %s.\n", com_lev, (trans == NULL) ? "NULL" : "not NULL"); if ((com_lev != 1) || (trans != NULL)) { Fprintf(stderr, "copysps: fea_compat: feature fields in %s and %s incompatible.\n", f1name, f2name); exit(1); } /* * check record_freq, if it exists and files * FEA_SD */ if (f2hd->hd.fea->fea_type == FEA_SD) { if (get_genhd_val("record_freq", f1hd, (double) 0) != get_genhd_val("record_freq", f2hd, (double) 0)) { Fprintf(stderr, "copysps: %s and %s have different record_freq - exiting.\n", f1name, f2name);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -