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

📄 cli.c

📁 语音CELP压缩解压源代码(C语音)
💻 C
📖 第 1 页 / 共 2 页
字号:
/**************************************************************************** ROUTINE*               cli** FUNCTION*               UNIX Command line interface.*		Read and check the UNIX command line.*		Report and log job characteristics and performance.* * SYNOPSIS*	subroutine cli (ifile, ofile, l, ll, lp, np, scale, descale, ber, *    +                  mask, stype, eccbits, sbits)**   formal **			data	I/O*	name		type	type	function*       -------------------------------------------------------------------*	ifile		char	i/o	input file name*	ofile		char	i/o	output file name*	l		int	i/o	Code word length*	ll		int	i/o	LPC analysis frame size*	lp		int	i/o	Pitch analysis frame size*	np		int	i/o	Pitch order*	scale		float	i/o	Input speech scaling factor*	descale		i	i/o	Output speech scaling factor*	ber		float	i/o	% bit error rate*	mask		int	o	Error mask*	stype		char	i/o	Spectrum quantizer type*	sbits		int	i/o	Spectrum bit allocation*	eccbits		int	i/o	Error control bits/frame*	ssum		int	i/o	Sum of spectrum bit allocation**   global common *                       data    I/O*       name            type    type    function*       -------------------------------------------------------------------*	cbgbits		int	i/o*	frame		int	i*	ncsize		int	i/o*	no		int	i/o*	pbits[]		int	i/o*	gamma2		float	i/o*	ptype[]		int	i/o*	cbgtype[]	int	i/o*****************************************************************************			CELP COMMAND *NAME:*     celp - execute the CELP coder**     The celp command generates a codebook-excited-linear-prediction*     processed output file from an input file.**SYNOPSIS:*     celp [-i ifile] [-o ofile] [-p pfile] [-q qfile] [-m mfile] [-l lfile]*     celp [-c chan]  [-o ofile]**ARGUMENTS:*     -i      Input file i*2 direct access format (unformatted, consecutive*             16-bit signed samples).*             For defaults, see celp.c declaration statements.* *     -o      Speech output file (.spd) i*2 direct access format *	      (unformatted, consecutive 16-bit signed samples) and*	      bit stream channel file (.chan) hexadecimal format.*             For defaults, see celp.c declaration statements.**     -p      Parameter file specifying celp characteristics.*             For defaults, see celp.c declaration statements.*             Parameters are stored in a ascii text file in the order below*             with one number per line:**             512	[ncsize = Code book size]*             60	[l      = Code word length]*             240	[ll     = LPC analysis frame size]*             10	[no     = LPC filter order]*             60	[lp     = Pitch analysis frame size]*             1         [np     = Pitch order]*             0.8	[gamma  = Noise weighting factor]*             1.0	[scale  = Input speech scaling factor]*	      1.0       [descale = Output speech scaling factor]*	      0.0	[ber	= % bit error rate]*	      1		[mxsw    = modified excitation logical switch]*	      0.0       [prewt   = prefilter logical switch]*	      hier      [pstype  = type of fractional pitch search]**     -q      Quantization characteristics file.*             For defaults, see celp.c declaration statements.*             The file has 3 sections: cbgain, pitch, and spectrum.*             Each section type is followed by a quantization type,*             which can be one of the following:  "max", "uniform", "vq",*             "log", "opt", or "none".  If the quantization type is not *	      "none",  { the next line is the bit allocation; i.e.:**             cbgain*             none		[unquantized cbgain]*             pitch*             max		[Max quantization]*             8 6 5		[8 bit delay, 6 bit delta delay, 5 bit gain]*             spectrum*             kang		[Kang's quantization]*             3 4 4 4 4 3 3 3 3 3 	[lsp1=3,...,lsp10=3]**     -m      Mask file specifying protected and unprotectected bits*	      in the bit stream when introducing bit errors to the *	      unpermuted bit stream.  (Note, this protection is separate*	      from the Hamming FEC).  Each line of the mfile corresponds*	      to a bit where each line is a 1 (protected) or 0 (not*	      protected).**     -l      Log file output containing run time information.*             Defaults to appending to a file called "celp.log".*             If the file name "none" is specified, no log file*             is generated.***     -c      Input channel file (.chan) hexadecimal format.  Channel*	      files generated from previous analysis runs are used as*	      imputs to a "synthesis only" run.  During this mode, the*	      -i switch is invalid.*EXAMPLES:**     celp*             This causes celp to process ifile.spd into ofile.spd (and a*	      nonpostfiltered output in ofilenpf.spd) using the*             defaults specified by the C declaration statements in*             celp.c, writes the bit stream file ofile.chan and generates *	      a log appended to the file "celp.log".  (If SUNGRAPH is *	      enabled, a set of files, with .sg_data extension, as defined*	      in sungraph_open.com is generated.)**     celp -i speech/dam27 -o dam27.48 -p celp48.p -q celp48.q -l log**             celp processes speech/dam27.spd into the normal, highpassed*	      and nonpostfiltered output, dam27.48.spd, dam27_48hpf.spd*	      and dam27_48npf.spd, respectively, writes the bit stream*	      file dam27_48.chan and appends log information to a file*	      called log.  The celp parameters specified by celp48.p and  *	      quantization characteristics of celp48.q are used.  (If  *	      SUNGRAPH is enabled, a set of files, with .sg_data extension, *             as defined in sungraph_open.com is generated.)*	      **     celp -c speech/512_dam27.chan -o 512_dam27b**	      celp synthesizes speech/512_dam27.chan channel file into *	      the normal, highpassed and nonpostfiltered output, *	      512_dam27b.spd, 512_dam27bhpf.spd and 512_dam27bnpf.spd,*	      respectively.****************************************************************************** CALLED BY**       celp** CALLS**       ***************************************************************************/#define TRUE            1#define FALSE           0#define MAXARG		14#define MAXTYPE		3#define MAXQTYPE	5#include <stdio.h>#include <sys/time.h>#include <sys/types.h>#include <sys/stat.h>#include <math.h>#include "ccsub.h"extern int cbgbits, frame, ncsize, no, pbits[], mxsw;extern float gamma2, prewt;extern char ptype[], cbgtype[], pstype[];static char lfile[82] = "celp.log";FILE *fp;cli (ifile,ofile,l,ll,lp,np,scale,descale,ber,mask,stype,sbits,eccbits,ssum,argc,argv)int *l, *ll, *lp, *np, mask[], sbits[], *eccbits, *ssum, argc;float *scale, *ber, *descale;char ifile[], ofile[], stype[], *argv[];{	/*note:  ncsize, no, and gamma are external variables	*/  int psum, rate, bits, rate2, i, j, flag, qflag, iflag, cflag;  long tim;  char prog[82], dir[82], host[20], temp[12];  static char qtype[][10] = {"kang", "log", "max2", "arcsin", "none"},              pfile[82] = "", qfile[82] = "", mfile[82] = "";  struct stat statbuf;  /*	*** parse the command line:	celp [-i ifile] [-c chan] [-o ofile] [-p pfile] 	     [-q qfile] [-m mfile] [-l lfile] 				*/  if (argc > MAXARG + 1)  {    fprintf(stderr,"cli: Too many arguments %d\n",argc);    fprintf(stderr,"%s%s\n","celp [-i ifile] [-o ofile] [-p pfile] ",                            "[-q qfile] [-m mfile] [-l lfile]");    fprintf(stderr,"%s\n","celp [-c chan] [-o ofile]");  }      if ((argc%2) == 0)  {    fprintf(stderr,"cli: Odd number of arguments %d\n",argc);    fprintf(stderr,"%s%s\n","celp [-i ifile] [-o ofile] [-p pfile] ",                            "[-q qfile] [-m mfile] [-l lfile]");    fprintf(stderr,"%s\n","celp [-c chan] [-o ofile]");    exit(1);  }  strcpy(prog, *argv);  flag = iflag = cflag = FALSE;  while (--argc > 0)  {    if (strncmp("-",*++argv,1) == 0)    {      switch (argv[0][1])      {        case 'i':        case 'I':          if (strncmp("-",*++argv,1) == 0)          {            fprintf(stderr,"cli: Missing input file\n");            flag = TRUE;            --argv;          }          else          {            strcpy(ifile,*argv);            --argc;	    iflag = TRUE;          }          break;        case 'o':        case 'O':          if (strncmp("-",*++argv,1) == 0)          {            fprintf(stderr,"cli: Missing output file\n");            flag = TRUE;            --argv;          }          else          {            strcpy(ofile,*argv);            --argc;          }          break;        case 'p':        case 'P':          if (strncmp("-",*++argv,1) == 0)          {            fprintf(stderr,"cli: Missing parameter file\n");            flag = TRUE;            --argv;          }          else          {            strcpy(pfile,*argv);            --argc;          }          break;        case 'q':        case 'Q':          if (strncmp("-",*++argv,1) == 0)          {            fprintf(stderr,"cli: Missing quantization file\n");            flag = TRUE;            --argv;          }          else          {            strcpy(qfile,*argv);            --argc;          }          break;        case 'm':        case 'M':          if (strncmp("-",*++argv,1) == 0)          {            fprintf(stderr,"cli: Missing mask file\n");            flag = TRUE;            --argv;          }          else          {            strcpy(mfile,*argv);            --argc;          }          break;        case 'l':        case 'L':          if (strncmp("-",*++argv,1) == 0)          {            fprintf(stderr,"cli: Missing log file\n");            flag = TRUE;            --argv;          }          else          {            strcpy(lfile,*argv);            --argc;          }          break;	case 'c':        case 'C':          if (strncmp("-",*++argv,1) == 0)          {            fprintf(stderr,"cli: Missing channel file\n");            flag = TRUE;            --argv;          }          else          {            strcpy(ifile,*argv);            --argc;	    cflag = TRUE;          }          break;        default:          printf("cli: Bad switch %s\n",*argv);          flag = TRUE;      }    }    else    {      printf("cli: Bad switch %s\n",*argv);      flag = TRUE;    }  }  if (iflag && cflag)  {    fprintf(stderr, "%s\n", "cli: the -i switch is invalid with the -c switch");    flag = TRUE;  }  if (flag)  {    fprintf(stderr,"%s%s\n","celp [-i ifile] [-o ofile] [-p pfile] ",                            "[-q qfile] [-m mfile] [-l lfile]");    fprintf(stderr,"%s\n","celp [-c chan] [-o ofile]");    exit(1);  }  /*	*** read input parameter file if requested		(all parameters are required)				*/  if (*pfile)  {    fp = fopen(pfile,"r");    if (fp == NULL)    {      perror("cli: Error opening the parameter file");      exit(0);    }    fscanf(fp,"%d %d %d %d %d %d %f %f %f %f %d %f %s", &ncsize, l, ll, &no,           lp, np, &gamma2, scale, descale, ber, &mxsw, &prewt, pstype);    fclose(fp);  }  /*	*** read quantization characteristics file if requested		(not all parameters are required)			*/  if (*qfile)  {    fp = fopen(qfile,"r");    if (fp == NULL)    {      perror("cli: Error opening the quantization characteristics file");      exit(0);    }    while (fscanf(fp,"%s",temp) != EOF)    {      if (strcmp(temp,"cbgain") == 0)      {        fscanf(fp, "%s", cbgtype);        if (strcmp(cbgtype, "none"))          fscanf(fp, "%d", &cbgbits);      }      else if (strcmp(temp,"pitch") == 0)      {        fscanf(fp, "%s", ptype);        if (strcmp(ptype, "none"))          for (i = 0; i < *np + 2; i++)            fscanf(fp, "%d", &pbits[i]);      }      else if (strcmp(temp,"spectrum") == 0)      {        fscanf(fp, "%s", stype);        if (strcmp(ptype, "none") && strcmp(ptype, "opt"))          for (i = 0; i < no; i++)            fscanf(fp, "%d", &sbits[i]);      }    }    fclose(fp);  }  /*	*** calculate data rate if fully quantized			*/  /*	    (assuming spectrum update rate (ll) = spectrum analysis rate)	    (assuming pitch update rate (lp) = pitch analysis rate)	    (assuming 8khz sampling rate)				*/  qflag = FALSE;  if (strcmp(cbgtype, "none") && strcmp(ptype, "none") &&      strcmp(stype, "none"))  {    qflag = TRUE;    psum = 2*(pbits[0]+pbits[1]) + 4*(pbits[2]);    for (*ssum = 0, i = 0; i < no; i++)

⌨️ 快捷键说明

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