squeeze.c

来自「speech signal process tools」· C语言 代码 · 共 160 行

C
160
字号
/*   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." 				  This program compacts an existing ANA file by finding the actual  maximum number of pulses, raw powers, and lpc powers and creates   a new file with records just large enough to hold these.        Man page by John Shore, Program by Alan Parker */#ifdef SCCSstatic char *sccs_id = "@(#)squeeze.c	1.2	6/10/86 EPI";#endif#include <stdio.h>#include <sps/sps.h>#include <sps/ana.h>#include <sys/types.h>#include <sys/stat.h>#define SYNTAX USAGE ("squeeze infile [outfile]")#define MAX(a,b) (a > b) ? a : b;char  *mktemp(), *get_cmd_line();main (argc, argv)int     argc;char  **argv;{    FILE *in = stdin, *out = stdout, *tstrm;    char *infile = "<stdin>", *outfile = "<stdout>";    char *template = "/usr/tmp/sqXXXXXX";    struct header  *ih, *oh;    int onefile=0,maxpulses=0,maxraw=0,maxlpc=0,i=0;    int order=0, stdio=1;    long orig_size=0, new_size=0;    struct ana_data *in_rec, *out_rec;    struct stat sbuf;    void stat_err();        if(argc < 2) SYNTAX;    if(strcmp(argv[1], "-") != 0) {  	infile = argv[1];	TRYOPEN(argv[0],infile,"r",in);	if(stat(argv[1],&sbuf) != 0) stat_err(argv[0],argv[1]);	orig_size = sbuf.st_size;    }    if(argc == 2) {	if(in == stdin) {		fprintf(stderr,"%s: Cannot update stdin\n",argv[0]);		exit(1);	}	onefile++;  	outfile = infile;    }    else {      	if (strcmp(argv[2], "-") != 0) {	outfile = argv[2];	TRYOPEN(argv[0],outfile,"w",out);	stdio=0;        }    }    if((tstrm = fopen(mktemp(template),"w")) == NULL)	CANTOPEN(argv[0],template);    if (!(ih = read_header(in))) NOTSPS(argv[0],infile);    if (ih->common.type != FT_ANA) {	(void) fprintf(stderr,"%s: %s is not an ANA file.\n",		argv[0],infile);	exit(1);    }    order = MAX(ih->hd.ana->order_vcd,ih->hd.ana->order_unvcd);    if(onefile) (void) write_header(ih,tstrm);/*    Process through all records in the ANA file and get the maximum   value for maxraw, maxlpc, and maxpulses */    in_rec = allo_ana_rec(ih);    while(get_ana_rec(in_rec,ih,in) != EOF) {	for(i=0;i<ih->hd.ana->maxpulses && in_rec->p_pulse_len[i] != 0;i++) ;	maxpulses = MAX(maxpulses,i);	for(i=0;i<ih->hd.ana->maxraw && in_rec->raw_power[i] > 0;i++) ;	maxraw = MAX(maxraw,i);	for(i=0;i<ih->hd.ana->maxlpc && in_rec->lpc_power[i] > 0;i++) ;	maxlpc = MAX(maxlpc,i);	if(onefile) (void) put_ana_rec(in_rec,ih,tstrm);    }    fprintf(stderr,"%s: Original maxpulses: %d, maxraw: %d, maxlpc: %d\n",	argv[0],ih->hd.ana->maxpulses,ih->hd.ana->maxraw,ih->hd.ana->maxlpc);    fprintf(stderr,"%s: Squeezed maxpulses: %d, maxraw: %d, maxlpc: %d\n",	argv[0],maxpulses,maxraw,maxlpc);    if(!onefile) {    	rewind(in);    }    else {	fclose(tstrm);        if((in = fopen(template,"r")) == NULL)	  CANTOPEN(argv[0],template);        if((out = fopen(argv[1],"w")) == NULL)	  CANTOPEN(argv[0],argv[1]);    }	    if (!(ih = read_header(in))) NOTSPS(argv[0],infile);    oh = copy_header(ih);    oh->hd.ana->maxpulses = maxpulses;    oh->hd.ana->maxraw = maxraw;    oh->hd.ana->maxlpc = maxlpc;    strcpy(oh->common.prog,ih->common.prog);    strcpy(oh->common.vers,ih->common.vers);    strcpy(oh->common.progdate,ih->common.progdate);    for(i=0;i<ih->variable.nnames;i++)	oh->variable.source[i]=ih->variable.source[i];    for(i=0;i<ih->variable.nheads;i++)	oh->variable.srchead[i]=ih->variable.srchead[i];    out_rec = allo_ana_rec(oh);    (void) add_comment(oh,get_cmd_line(argc,argv));    (void) write_header(oh,out);    while(get_ana_rec(in_rec,ih,in) != EOF) {	for(i=0;i<oh->hd.ana->maxpulses;i++) 		out_rec->p_pulse_len[i] = in_rec->p_pulse_len[i];	for(i=0;i<oh->hd.ana->maxraw;i++) 		out_rec->raw_power[i] = in_rec->raw_power[i];	for(i=0;i<oh->hd.ana->maxlpc;i++) 		out_rec->lpc_power[i] = in_rec->lpc_power[i];	for(i=0;i<order;i++)		out_rec->ref_coeff[i] = in_rec->ref_coeff[i];	out_rec->frame_len = in_rec->frame_len;	out_rec->tag = in_rec->tag;	(void) put_ana_rec(out_rec,oh,out);    }    (void) fclose(out);    if(onefile) {	unlink(template);	if(stat(argv[1],&sbuf) != 0) stat_err(argv[0],argv[1]);	new_size = sbuf.st_size;    }    else {	if(stdio == 0) {	  if(stat(argv[2],&sbuf) != 0) stat_err(argv[0],argv[2]);	  new_size = sbuf.st_size;	}    }    if(orig_size != 0 && new_size != 0) 	fprintf(stderr,"%s: Original size: %ld, New size: %ld\n",	 argv[0],orig_size,new_size);	}voidstat_err(name,file)char *name,*file;{   fprintf(stderr,"%s: Error can't stat %s\n",name,file);   exit(1);}

⌨️ 快捷键说明

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