⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cbkedit.c

📁 speech signal process tools
💻 C
字号:
#ifdef SCCSstatic char *sccs_id = "@(#)cbkedit.c	1.2 9/3/86 EPI";#define VERSION "1.2"#define DATE "9/3/86"#endif#ifndef DATE #define DATE "none"#endif#ifndef VERSION#define VERSION "debug"#endif#include <stdio.h>#include <sps/sps.h>#include <sps/scbk.h>main(argc, argv)int argc;char **argv;{  int getopt(), c;  extern optind, errno;  extern char *optarg, *mktemp(), *get_cmd_line();  extern char *getenv();  char *editor, buf[256], buf1[256];  char *template = "/tmp/cbXXXXXX";  FILE *in, *tstrm, *out;  struct header *ih, *oh;  struct scbk_data *cbk_rec;  int debug=0,i;#define BCKSIZ 4096  float enc[BCKSIZ], dec[BCKSIZ], final_dist, cdwd_dist[BCKSIZ];  long	final_pop[BCKSIZ];  unsigned int code[BCKSIZ];  float convergence;  long num_items;  int distortion, codebook_type, element_num;  unsigned int num_cdwds;    while ((c = getopt(argc, argv, "x:")) != EOF) {	switch (c) {	   case 'x':		debug = atoi(optarg);		break; 	}  }  if ((argc - optind) != 1) {	fprintf(stderr,"cbkedit: needs file name\n");	exit(1);  }  if(debug) fprintf(stderr,"cbkedit: file: %s\n",argv[optind]);  TRYOPEN("cbkedit",argv[optind],"r",in);  if(!(ih = read_header(in))) NOTSPS("cbkedit:",argv[optind]);  if(ih->common.type != FT_SCBK) {	fprintf(stderr,"cbkedit: %s not a SCBK file.\n",argv[optind]);	exit(1);  }  if ((tstrm = fopen(mktemp(template),"w")) == NULL)	CANTOPEN("cbkedit",template);  if(debug) fprintf(stderr,"cbkedit: temp file: %s\n",template);    if (ih->common.ndrec != 1) 	fprintf(stderr,"cbkedit: Warning, ndrec = %d, should be 1.\n",		ih->common.ndrec);  cbk_rec = allo_scbk_rec(ih);  if(get_scbk_rec(cbk_rec,ih,in) == EOF) {	fprintf(stderr,"cbkedit: No data record in file.\n");	exit(1);  }  fclose(in);  fprintf(tstrm,"Header -- Do not delete any lines in the header.\n");  fprintf(tstrm,"num_items: %ld\n",ih->hd.scbk->num_items);  fprintf(tstrm,"distortion: %d\n",ih->hd.scbk->distortion);  fprintf(tstrm,"num_cdwds: %d (do not edit)\n",ih->hd.scbk->num_cdwds);  fprintf(tstrm,"convergence: %f\n",ih->hd.scbk->convergence);  fprintf(tstrm,"codebook_type: %d\n",ih->hd.scbk->codebook_type);  fprintf(tstrm,"element_num: %d\n",ih->hd.scbk->element_num);  fprintf(tstrm,"final_dist: %g\n",cbk_rec->final_dist);  fprintf(tstrm,"Data -- you may delete or add lines here.\n");  fprintf(tstrm,"/*     enc         dec   code           cdwd_dist   final_pop */\n");  for (i=0; i<ih->hd.scbk->num_cdwds; i++) {	fprintf(tstrm,"%11.5f, %11.5f, 0x%x,    /* %11.5f %9ld */\n",		cbk_rec->qtable[i].enc,		cbk_rec->qtable[i].dec,		cbk_rec->qtable[i].code,		cbk_rec->cdwd_dist[i],		cbk_rec->final_pop[i]);  }  fclose(tstrm);  if ((editor = getenv("EDITOR")) == NULL) editor = "vi";  sprintf(buf,"%s %s",editor,template);  system(buf);  printf("cbkedit: Make changes? [return for yes, 'n' for abort] ");  if(getchar() != 'n') {    printf("cbkedit: making changes, ");    sprintf(buf,"%s.bak",argv[optind]);    if(rename(argv[optind],buf) != 0) {	  perror("cbkedit");	  exit(1);    }    printf("original %s saved in %s\n",argv[optind],buf);    TRYOPEN("cbkedit",argv[optind],"w",out);    TRYOPEN("cbkedit",template,"r",tstrm);    oh = copy_header(ih);    add_source_file(oh,argv[optind],ih);    add_comment(oh,get_cmd_line(argc,argv));       if(fgets(buf,256,tstrm) == NULL)   goto trouble;    if(fgets(buf,256,tstrm) == NULL)   goto trouble;    if(sscanf(buf,"%s %ld",buf1,&num_items) == 0) goto trouble;    if(fgets(buf,256,tstrm) == NULL)   goto trouble;    if(sscanf(buf,"%s %d",buf1,&distortion) == 0)  goto trouble;    if(fgets(buf,256,tstrm) == NULL)   goto trouble;    if(sscanf(buf,"%s %d",buf1,&num_cdwds) == 0)  goto trouble;    if(fgets(buf,256,tstrm) == NULL)   goto trouble;    if(sscanf(buf,"%s %f",buf1,&convergence) == 0)  goto trouble;    if(fgets(buf,256,tstrm) == NULL)   goto trouble;    if(sscanf(buf,"%s %d",buf1,&codebook_type) == 0)  goto trouble;    if(fgets(buf,256,tstrm) == NULL)   goto trouble;    if(sscanf(buf,"%s %d",buf1,&element_num) == 0)  goto trouble;    if(fgets(buf,256,tstrm) == NULL)   goto trouble;    if(sscanf(buf,"%s %f",buf1,&final_dist) == 0)  goto trouble;      if(fgets(buf,256,tstrm) == NULL)   goto trouble;    if(fgets(buf,256,tstrm) == NULL)   goto trouble;    i=0;    while(fgets(buf,256,tstrm) != NULL) {    	sscanf(buf,"%f, %f, 0x%x, /* %f %ld */",  	&enc[i], &dec[i], &code[i], &cdwd_dist[i], &final_pop[i]);  	i++;    }    if(debug) fprintf(stderr,"cbkedit: %d cdwds read back in.\n",i);    oh->hd.scbk->num_cdwds = i;    cbk_rec = allo_scbk_rec(oh);        oh->hd.scbk->num_items = num_items;    oh->hd.scbk->distortion = distortion;    oh->hd.scbk->convergence = convergence;    oh->hd.scbk->codebook_type = codebook_type;    oh->hd.scbk->element_num = element_num;    strcpy(oh->common.prog,"cbkedit");    strcpy(oh->common.vers,VERSION);    strcpy(oh->common.progdate,DATE);    write_header(oh,out);      		    cbk_rec->final_dist = final_dist;    for(i=0; i<oh->hd.scbk->num_cdwds; i++) {  	cbk_rec->qtable[i].enc = enc[i];  	cbk_rec->qtable[i].dec = dec[i];  	cbk_rec->qtable[i].code = code[i];  	cbk_rec->cdwd_dist[i] = cdwd_dist[i];  	cbk_rec->final_pop[i] = final_pop[i];    }    put_scbk_rec(cbk_rec,oh,out);    fclose(out);    fclose(tstrm);  }  else { /* other part of the if abort */   printf("cbkedit: aborting without making changes.\n");  }  unlink(template);  exit(0);  trouble:  fprintf(stderr,"cbkedit: trouble reading temp file back.\n");  fprintf(stderr,"cbkedit: temp file saved in %s\n",template);  exit(1);}    

⌨️ 快捷键说明

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