spsros.c

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

C
111
字号
/*  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 converts an SPS SD file to the format for download into   Rosetta via kermit. 	  spsros [-p range] infile outfile  Alan Parker, EPI, Washington*/char *sccs_id = "@(#)spsros.c	1.5 11/14/86 EPI";#include <stdio.h>#include <sps/sps.h>#include <sps/sd.h>#define SYNTAX USAGE("spsros [-p range] infile outfile (use - for stdio)")main(argc,argv)int argc;char **argv;{  unsigned byte1, byte2, byte3;   int byte1c, byte2c, byte3c;  struct header *hdr;  char ros1, ros2, ros3, ros4;  FILE *in=stdin, *out=stdout;  char *infile="<stdin>";  extern optind;  extern char *optarg;  char *p_switch = NULL;  int bytes=0,start=0,end,c,i,bytes_in;  while ((c = getopt(argc,argv,"p:")) != EOF) {    switch (c) {     case 'p':      p_switch = optarg;      break;     default:      SYNTAX;     }  }  if(argc-optind != 2) SYNTAX;  if(strcmp(argv[optind++],"-") != 0) {   infile = argv[optind-1];   TRYOPEN(argv[0],infile,"r",in);  }  if(strcmp(argv[optind],"-") != 0)    TRYOPEN(argv[0],argv[optind],"w",out);  if((hdr = read_header(in)) == NULL)   NOTSPS(argv[0],infile);  end = hdr->common.ndrec;  if(p_switch) range_switch(p_switch,&start,&end,1);  if(start > hdr->common.ndrec) {    fprintf(stderr,"%s: start point greater than number of records.\n",argv[0]);    exit(1);  }  skiprec(in,start,size_rec(hdr));  if(hdr->hd.sd->sf != 8000)    fprintf(stderr,"%s: warning sample freq. not 8000.\n",argv[0]);  if(hdr->common.nshort != 1) {   fprintf(stderr,"%s: input SD file must be integer (short),\n",argv[0]);   fprintf(stderr,"%s: use copysd to convert this file.\n",argv[0]);   exit(1);  }  bytes_in = (end - start + 1) * 2;  while ((byte1c = fgetc(in)) != EOF && bytes_in > 0) {    if((byte2c = fgetc(in)) == EOF)     byte2c = byte3c = 0;    else     if((byte3c = fgetc(in)) == EOF)      byte3c = 0;    byte1 = byte1c;    byte2 = byte2c;    byte3 = byte3c;      ros1 = (byte1 >> 2) + 64;    fputc(ros1,out);      ros2 = ((byte2 >> 4) | ((byte1 & 03) << 4)) + 64;    fputc(ros2,out);        ros3 = ((byte3 >> 6) | ((byte2 & 017) << 2)) + 64;    fputc(ros3,out);      ros4 = (byte3 & 077 ) + 64;    fputc(ros4,out);      bytes_in -= 3;    bytes += 4;  }   fprintf(stderr,"%s: %d (%x hex) bytes stored.\n",argv[0],bytes,bytes);} 

⌨️ 快捷键说明

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