📄 psps.c.old
字号:
/* psps - prints SPS data files * * 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." * * psps - dumps an SPS data file on standard output. This verison by * Alan Parker, based on the SDS version by Joe Buck. */#include <stdio.h>#include <sps/sps.h>#include <sps/ana.h>#include <sps/pitch.h>#include <sps/sd.h>#include <sps/spec.h>#include <sps/ros.h>#include <sps/filt.h>#include <sps/scbk.h>#include <sps/fea.h>#define HUGE 2000000000#ifdef SCCS static char *sccs_id = "%W% %G% EPI";#endifint getopt();int atoi();int skiprec();int size_rec();char *file_type();short get_rec_len();char *calloc();void range_switch();void pr_full_header();void pr_history();long pr_sd_data();void print_ana();void print_common();void print_fea();void print_filt(); void print_generic();void print_pitch();void print_ros();void print_scbk();void print_sd();void print_spec();void tab();int vflag = 0;extern char *optarg;extern int optind;main (argc, argv)int argc;char **argv;{ int c; long i; int history = 0; /* if true, print a history */ int recursive = 0; /* if true, recursively print all headers */ int full = 0; /* if true, print full header(s) */ int nohead = 0; /* if true, don't print header ' */ int xflag = 0; /* -x given? */ char *otext = NULL; /* -o argument */ char *inp_file; /* input file name */ FILE *istrm = stdin; struct header *h; struct ana_data *ana_rec; struct pitch *pit_rec; struct spec_data *spec_rec; struct ros_data *ros_rec; struct filt_data *filt_rec; struct scbk_data *scbk_rec; struct fea_data *fea_rec; int srec = 1; /* first record to print */ int erec = HUGE; /* last record to print */ double dbuf[500]; double *data; long tag; long rec_size;#define MAX_TAGS 200 int tags[MAX_TAGS]; int num_tags = 0; int k = 0; int nfound = 0; int tflag = 0; int oflag = 0; int gflag = 0; /* print any SPS file in generic format */ short type; /* SPS filt type */ while ((c = getopt (argc, argv, "hfnrxo:t:vg")) != EOF) { switch (c) { case 'h': history++; break; case 'r': recursive++; /* fall through to case 'f' intentional */ case 'f': full++; break; case 'n': nohead++; break; case 'x': xflag++; break; case 'o': otext = optarg; oflag++; break; case 't': tags[num_tags++] = atoi (optarg); tflag++; break; case 'v': vflag++; full++; break; case 'g': gflag++; break; default: exit (1); } }/* check for conflicting switches */ if (xflag && otext || nohead && full || history && full) { fprintf (stderr, "psps: conflicting switches\n"); exit (1); } if (tflag && oflag) { (void) fprintf (stderr, "psps: conflicting switches: -t and -o options.\n"); exit (1); } if (optind == argc) USAGE("psps [-r] [-f] [-x] [-o] [-h] [-n] [-v] [-t tag] [- g] file"); inp_file = argv[optind]; if(strcmp(inp_file,"-") != 0) { if ((istrm = fopen (inp_file, "r")) == NULL) CANTOPEN ("psps", inp_file); } else inp_file = "<stdin>"; if ((h = read_header (istrm)) == NULL) NOTSPS ("psps", inp_file); if (tflag && (h->common.tag == NO)) { (void) fprintf (stderr, "%s: Data is not tagged, cannot use -t option.\n", argv[0]); exit (1); } if (full) pr_full_header (inp_file, h, recursive, 0); else if (history) pr_history (inp_file, h, 0); else if (!nohead) { (void) printf("File: %s\n",inp_file); print_common(0,h); } if (xflag) exit (0); srec = 1; range_switch (otext, &srec, &erec, 1); if(srec > h->common.ndrec) (void) printf("psps: warning, starting point > than h->ndrec\n"); if (gflag) type = -1; else type = h->common.type; switch (type) { case FT_SD: i = srec; while(srec-- > 1 && (get_sd_recd(dbuf,1,h,istrm) != EOF)); if (srec > 1) { (void) printf ("%s: not enough records in %s\n", argv[0], inp_file); break; } i = pr_sd_data (istrm, i, erec, h); break; case FT_ANA: ana_rec = allo_ana_rec(h); i = srec; while(srec-- > 1 && (get_ana_rec(ana_rec,h,istrm) != EOF)); if (srec > 1) { (void) printf ("%s: not enough records in %s\n", argv[0], inp_file); break; } while (i++ <= erec && (get_ana_rec(ana_rec,h,istrm) != EOF)) { if (tflag) { for (k = 0; k < num_tags; k++) if (ana_rec->tag == tags[k]) { (void) printf("\nRecord %d: ",i-1); (void) print_ana_rec(ana_rec,h,stdout); nfound++; break; } if (nfound == num_tags) break; } else { (void) printf("\nRecord %d: ",i-1); (void) print_ana_rec(ana_rec,h,stdout); } } break; case FT_PIT: pit_rec = allo_pitch_rec(); i = srec; while(srec-- > 1 && (get_pitch_rec(pit_rec,istrm) != EOF)); if (srec > 1) { (void) printf ("%s: not enough records in %s\n", argv[0], inp_file); break; } while (i++ <= erec && (get_pitch_rec(pit_rec,istrm) != EOF)) { if (tflag) { for (k = 0; k < num_tags; k++) if (pit_rec->tag == tags[k]) { (void) printf("\nRecord %d: ",i-1); (void) print_pitch_rec(pit_rec,stdout); nfound++; break; } if (nfound == num_tags) break; } else { (void) printf("\nRecord %d: ",i-1); (void) print_pitch_rec(pit_rec,stdout); } } break; case FT_SPEC: spec_rec = allo_spec_rec(h); i = srec; while(srec-- > 1 && (get_spec_rec(spec_rec,h,istrm) != EOF)); if (srec > 1) { (void) printf ("%s: not enough records in %s\n", argv[0], inp_file); break; } while (i++ <= erec && (get_spec_rec(spec_rec,h,istrm) != EOF)) { if (tflag) { for (k = 0; k < num_tags; k++) if (spec_rec->tag == tags[k]) { (void) printf("\nRecord %d: ",i-1); (void) print_spec_rec(spec_rec,h,stdout); nfound++; break; } if (nfound == num_tags) break; } else { (void) printf("\nRecord %d: ",i-1); (void) print_spec_rec(spec_rec,h,stdout); } } break; case FT_ROS: ros_rec = allo_ros_rec(h); i = srec; while(srec-- > 1 && (get_ros_rec(ros_rec,h,istrm) != EOF)); if (srec > 1) { (void) printf ("%s: not enough records in %s\n", argv[0], inp_file); break; } while (i++ <= erec && (get_ros_rec(ros_rec,h,istrm) != EOF)) { if (tflag) { for (k = 0; k < num_tags; k++) if (ros_rec->tag == tags[k]) { (void) printf("\nRecord %d: ",i-1); (void) print_ros_rec(ros_rec,h,stdout); nfound++; break; } if (nfound == num_tags) break; } else { (void) printf("\nRecord %d: ",i-1); (void) print_ros_rec(ros_rec,h,stdout); } } break; case FT_FILT: filt_rec = allo_filt_rec(h); i = srec; while(srec-- > 1 && (get_filt_rec(filt_rec,h,istrm) != EOF)); if (srec > 1) { (void) printf ("%s: not enough records in %s\n", argv[0], inp_file); break; } while (i++ <= erec && (get_filt_rec(filt_rec,h,istrm) != EOF)) { if (tflag) { for (k = 0; k < num_tags; k++) if (filt_rec->tag == tags[k]) { (void) printf("\nRecord %d: ",i-1); (void) print_filt_rec(filt_rec,h,stdout); nfound++; break; } if (nfound == num_tags) break; } else { (void) printf("\nRecord %d: ",i-1); (void) print_filt_rec(filt_rec,h,stdout); } } break; case FT_SCBK: scbk_rec = allo_scbk_rec(h); i = srec; while(srec-- > 1 && (get_scbk_rec(scbk_rec,h,istrm) != EOF)); if (srec > 1) { (void) printf ("%s: not enough records in %s\n", argv[0], inp_file); break; } while (i++ <= erec && (get_scbk_rec(scbk_rec,h,istrm) != EOF)) { if (tflag) { (void) fprintf(stdout, "psps: No tags exist in Scalar Quantization Codebook.\n"); exit (1); } else { (void) printf("\nRecord %d: ",i-1); (void) print_scbk_rec(scbk_rec,h,stdout); } } break; case FT_FEA: fea_rec = allo_fea_rec(h); i = srec; while(srec-- >1 && (get_fea_rec(fea_rec,h,istrm) != EOF)); if (srec > 1) { (void) printf ("%s: not enough records in %s\n", argv[0], inp_file); break; } while (i++ <= erec && (get_fea_rec(fea_rec,h,istrm) != EOF)) { if (tflag) { for (k = 0; k < num_tags; k++) if (fea_rec->tag == tags[k]) { (void) printf("\nRecord %d: ",i-1); (void) print_fea_rec(fea_rec,h,stdout); nfound++; break; } if (nfound == num_tags) break; } else { (void) printf("\nRecord %d: ",i-1); (void) print_fea_rec(fea_rec,h,stdout); } } break; default: if (!gflag) (void) printf("Unknown file type, code: %d\n",h->common.type); rec_size = get_rec_len (h); if ((data = (double *) calloc((unsigned)rec_size, sizeof(double))) == NULL) { (void) fprintf (stderr, "%s: calloc: could not allocate memory for data.\n", argv[0]); exit (1); } i = srec; while(srec-- >1 && (get_gen_recd (data, &tag,h,istrm) != EOF)); if (srec > 1) { (void) printf ("%s: not enough records in %s\n", argv[0], inp_file); break; } while (i++ <= erec && (get_gen_recd(data,&tag,h,istrm) != EOF)) { if (tflag) { int k1; for (k1=0; k1 < num_tags; k1++) if (tag == tags[k1]) { (void) printf ("Record: %d Tag: %ld\n", i-1,tag); for (k = 0; k < rec_size; k++) (void) printf (" element%d: %g\n",k+1,data[k]); nfound++; break; } if (nfound == num_tags) break; } else { (void) printf ("Record: %d", i-1); if (h->common.tag == YES) (void) printf (" Tag: %ld\n", tag); else (void) printf ("\n"); for (k = 0; k < rec_size; k++) (void) printf (" element%d: %g\n",k+1,data[k]); } } } if (i-2 > h->common.ndrec) printf("\nThere are %ld records, the header claims there are %ld.\n", i-2, h->common.ndrec); exit (0);}voidpr_history(name,h,level)char *name;struct header *h;int level;{ int i; tab(level); (void) printf("File: %s\n",name); print_common(level,h); level++; for (i = 0; h->variable.srchead[i] && i < h->variable.nheads; i++) { if (i > 0) { tab (level); (void) printf ("----------------\n"); } pr_history (h->variable.source[i], h->variable.srchead[i], level); } return;}char *file_type(type)short type;{ switch (type) { case FT_ANA: return "Analysis File"; case FT_SD: return "Sampled Data File"; case FT_PIT: return "Pitch Data File"; case FT_SPEC: return "Spectral Records"; case FT_ROS: return "Rosetta Speech Frame File"; case FT_FILT: return "Filter Coefficient File"; case FT_SCBK: return "Scaler Codebook File"; case FT_FEA: return "Feature File"; case FT_SPECT_DB: return "Spectrum Records, Decibels"; default: return "Unknown type"; }}/* print_header, prints the type specfic part of the header pointed to by h*//* pr_sampled_data - print a range of data from a SPS sampled data file | * for integer types, 10/line. For floating types, 5/line. |*/longpr_sd_data (istrm, rec, erec, h)FILE *istrm;struct header *h;int rec, erec;{ int itype; double data[10]; long count = rec-1; int i, npl, nleft = erec - rec - 1; itype = (h->common.nlong || h->common.nshort || h->common.nchar); if (rec > erec) return; npl = (itype ? 10 : 5); while (nleft > 0) { (void) printf ("%6d: ", rec); if (npl > nleft) npl = nleft; if(get_sd_recd (data, npl, h, istrm) == EOF) break; if (itype) for (i = 0; i < npl; i++) { (void) printf ("%7d", (int) data[i]); count++; } else for (i = 0; i < npl; i++) { (void) printf (" %10.4f", data[i]); count++; } putchar ('\n'); nleft -= npl; rec += npl; } return count;}voidpr_full_header(name,h,recursive,level)char *name;struct header *h;int recursive,level;{ tab (level); (void) printf("File: %s\n",name); print_common(level,h); if (h->variable.refhd) { (void) printf("Reference Header:\n"); pr_full_header("reference header",h->variable.refhd,0,level+1); } if (h->common.type == FT_ANA) print_ana(level,h); if (h->common.type == FT_PIT) print_pitch(level,h); if (h->common.type == FT_SD) print_sd(level,h); if (h->common.type == FT_SPEC) print_spec(level,h); if (h->common.type == FT_ROS) print_ros(level,h); if (h->common.type == FT_FILT) print_filt(level,h); if (h->common.type == FT_SCBK) print_scbk(level,h); if (h->common.type == FT_FEA) if (vflag) print_fea(level,h); print_generic(level,h); if (recursive) { int i = 0; level++; while (h->variable.srchead[i] && i < h->variable.nheads) { if (i > 0) { tab (level); (void) printf ("----------------\n"); } pr_full_header (h->variable.source[i], h->variable.srchead[i], recursive, level); i++; } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -