📄 plotpit.c
字号:
/*--------------------------------------------------------------+| ENTROPIC PROCESSING, INC. || || This material contains proprietary software of Entropic || Processing, Inc. Any reproduction, distribution, or || publication without the the prior written permission of || Entropic Processing, Inc. is strictly prohibited. Any || public distribution of copies of this work authorized in || writing by Entropic Processing, Inc. must bear the notice || || "Copyright 1986 Entropic Processing, Inc." || |+---------------------------------------------------------------+| || plotpit -- plot sampled data and pitch-pulse locations in a || form suitable for the plotas and stou filters || || Joseph T. Buck, Entropic Processing, Inc. || Option -e added 1985 Jun 27 by Bernard G. Fraenkel. || Converted 1986 Apr 22 by Rod Johnson to read new SPS format. || Modified for -m, -Y, and SPS common by John Shore on 9/19/86 |+--------------------------------------------------------------*//*plotpit [-x level] [-p range] [-e] [-y range] [-Y range] [-m maxpoints] [-s sdfile] [-t text] pitfileThe speech file name is obtained from the pitch file's header if no -s isspecified.*//* Modified 6/27/85 by Bernard G. Fraenkel to include the -e option for plotingthe pre-emphasized data instead of the true dataWARNING: the pre-emphasis will NOT be exact if the denominator of the pre-emphasis filter has a non-zero order and the data do not start at the beginning of the fileWARNING: the data are off by one or two samples if 1 < start <= NPR*//*Converted 1986 Apr 22 by Rod Johnson to read new SPS format.The bugs referred to in the warnings above HAVE NOT been fixed.The -e option now refers to hd.pit->prefilter, for lack of anything better: SPS pitch file headers no longer contain an hd_pre field.*/#ifdef SCCS static char *sccs_id = "@(#)plotpit.c 1.4 1/12/87 EPI";#endif#include <stdio.h>#include <sps/sps.h>#include <sps/sd.h>#include <sps/pitch.h>#define NPR 3 /* should be in /usr/include/sps/constants.h */FILE *istrm, *labptr;struct header *ih, *ph;#define MAX_FLOAT 1.0e38#define MIN_FLOAT -MAX_FLOAT#define MAXTEXT 10#define stop 0#define SYNTAX USAGE("plotpit [-x level] [-p range] [-e] \[-y range] [-Y range] [-s sdfile] [-m maxpoints] [-t text] pitfile")int debug_level = 0;char *malloc();int atoi();void plotscale();voidmain(argc, argv) int argc; char *argv[];{ void plotscale(); double xmin, xmax, xstep, ymin = -15000., ymax = 15000., ystep; double sqrt(); static double num[NPR], den[NPR]; double dempstate[NPR]; int i, ix, iy, xdp, ydp, ntext = 0, yflag = 0, e_flag = 0; int pflag = 0; int numpoints; int maxpoints = 3000; /*maximum number of points to plot*/ /*if nan>maxpoints, points are skipped*/ int yexact = 0; int interval; double *data; double *dptr, *dptr1; int start, end, lnt, nskip, ndskip, plocn, c; int beginplot, endplot; char *xrange = NULL, *sd_file = NULL, *p_file = NULL; char *text[MAXTEXT], *malloc(); struct pitch *pit_rec; extern int optind; extern char *optarg; pit_rec = allo_pitch_rec(); while ((c = getopt(argc, argv, "x:p:y:Y:t:s:em")) != EOF) switch (c) { case 'x': debug_level = atoi(optarg); break; case 'p': xrange = optarg; pflag++; break; case 'e': e_flag++; break; case 'y': frange_switch(optarg, &ymin, &ymax); yflag++; break; case 'Y': frange_switch(optarg, &ymin, &ymax); yflag++; yexact = 1; break; case 't': if (ntext < MAXTEXT) text[ntext++] = optarg; else { fprintf(stderr, "plotpit: Too many -t options\n"); exit(1); } break; case 'm': maxpoints = atoi(optarg); break; case 's': sd_file = optarg; break; default: SYNTAX; exit(1); } if (optind >= argc) SYNTAX; TRYOPEN("plotpit", argv[optind], "r", labptr); p_file = argv[optind]; if ((ph = read_header(labptr)) == NULL) NOTSPS("plotpit", p_file); if (ph->common.type != FT_PIT) { fprintf(stderr, "plotpit: %s is not pitch data\n", p_file); exit(1); } if (!sd_file) sd_file = ph->variable.source[0]; if (debug_level) fprintf(stderr, "pitch file %s; sampled data file %s\n", p_file, sd_file); if (strcmp(sd_file, "<stdin>") == 0) { fprintf(stderr, "plotpit: pitch file was made from standard input\n"); exit(1); } nskip = ph->hd.pit->start; lnt = ph->hd.pit->nan; xmin = nskip; xmax = nskip + lnt; if (pflag) frange_switch(xrange, &xmin, &xmax); if (xmin < nskip || xmax > nskip + ph->hd.pit->nan) { fprintf(stderr, "plotpit: specified range includes data not analyzed\n"); fprintf(stderr, "spec = (%g,%g), analyzed = (%d,%d)\n", xmin, xmax, nskip, nskip + ph->hd.pit->nan); exit(1); } if (xmin >= xmax){ fprintf(stderr, "plotpit: start point after end point!\n"); exit(1); } xstep = xmax; nskip = xmin; lnt = xmax - xmin; if (e_flag) lnt += NPR - 1; TRYOPEN("plotpit", sd_file, "r", istrm); if ((ih = read_header(istrm)) == NULL) NOTSPS("plotpit", sd_file); if (ih->common.type != FT_SD) { fprintf(stderr, "plotpit: %s is not sampled data\n", sd_file); exit(1); } read_params(NULL,SC_CHECK_FILE,sd_file); start = xmin; end = xmax; if (!pflag) { if (symtype("start") != ST_UNDEF) start = getsym_i("start"); if (symtype("nan") != ST_UNDEF) end = start + getsym_i("nan") - 1; } (void) putsym_i ("start",start); (void) putsym_i ("nan",end-start+1); lnt = end - start; xmin = start; xmax = end; nskip = xmin; if (e_flag) /* request to plot pre-emphasized data */ { if (ph->hd.pit->prefilter) { struct zfunc *z = ph->hd.pit->prefilter; for (i = 0; i < z->nsiz; i++) num[i] = z->zeros[i]; for (i = z->nsiz; i < NPR; i++) num[i] = 0.0; for (i = 0; i < z->dsiz; i++) den[i] = z->poles[i]; for (i = z->dsiz; i < NPR; i++) den[i] = 0.0; } else{num[0] = den[0] = 1.0; for (i = 1; i < NPR; i++) num[i] = den[i] = 0.0;den[1] = -0.875;} } for (i = 0, dptr = dempstate; i < NPR; i++, *dptr++ = 0.0); if (!e_flag) nskip -= NPR; ndskip = nskip - 1;printf("nskip = %d\tndskip = %d\n", nskip, ndskip); if (ndskip < 0) { fprintf(stderr, "plotpit: no point %d in %s\n", ndskip + 1, sd_file); exit(1); } skiprec(istrm, ndskip, size_rec(ih)); data = (double *) malloc((unsigned) lnt * sizeof(double)); if (data == NULL) { fprintf(stderr, "plotpit: can't allocate memory for %d data points\n", lnt); exit(1); } get_sd_recd(data, lnt, ih, istrm); if (e_flag) { emphasis(data, lnt, num, den, dempstate); /* shift data to remove the first NPR samples */ lnt -= NPR -1; if (nskip > NPR) for (i=0, dptr1 = data + NPR - 1, dptr = data; i<lnt; i++) *dptr++ = *dptr1++; } if (lnt < maxpoints || maxpoints == 0) { interval = 1; numpoints = lnt; } else { interval = lnt / maxpoints; numpoints = lnt / interval; } if (!yflag) { ymin = MAX_FLOAT; ymax = MIN_FLOAT; for (i = 0; i < lnt; i++) { if (data[i] < ymin) ymin = data[i]; else if (data[i] > ymax) ymax = data[i]; } } plotscale(xmin, xmax, 1.0, &xmin, &xmax, &xstep, &xdp); if (yexact) plotexscale(ymin, ymax, 1.0, &ymin, &ymax, &ystep, &ydp); else plotscale(ymin, ymax, 1.0, &ymin, &ymax, &ystep, &ydp); draw_box(xmin, xmax, xstep, xdp, ymin, ymax, ystep, ydp); printf("c 2\n"); plot_datad(data, numpoints, xmin, xmax, ymin, ymax, nskip, interval); printf("c 3\n"); iy = 3000 + ymin * 2500.0 / (ymax - ymin); plocn = 0; while (plocn < nskip + lnt) { if (plocn >= nskip) { ix = 500.0 + (plocn - xmin) * 5000.0 / (xmax - xmin); printf("m %d %d\n", iy, ix); printf("d 500 %d\n", ix); printf("m 480 %d\nt 4 2\n%d\n", ix, plocn); } if (!get_pitch_rec(pit_rec, labptr)) break; plocn = pit_rec->tag; } /* print header for the plot */ printf("c 5\nm 3400 500\nt 5 1\nPitch file: %s\n", p_file); iy = 3600; if (e_flag) { printf("c 5\nm %d 500\nt 5 1\nDisplaying pre_emphasized data\n", iy); iy += 200; } for (i = 0; i < ntext; i++) { printf("c 5\nm %d 500\nt 5 1\n%s\n", iy, text[i]); iy += 200; } print_time(200, 4400); (void) putsym_s ("filename", sd_file); (void) putsym_s ("prog", "plotpit"); if ( (beginplot = (int) xmin) == 0 ) beginplot = 1; endplot = (int) xmax; (void) putsym_i ("beginplot", beginplot); (void) putsym_i ("endplot", endplot); exit(0);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -