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

📄 cli.c

📁 语音CELP压缩解压源代码(C语音)
💻 C
📖 第 1 页 / 共 2 页
字号:
      *ssum += sbits[i];    bits = nint(*ll / (*l) * log10((float)ncsize) / log10(2.) +           *ll / (*l) * cbgbits + psum + *ssum + *eccbits);    rate = nint(bits * 8000.0 / (*ll));    /*	   1 bit for sync:						*/    rate2 = rate + nint(1.0 * 8000.0 / (*ll));  }  /*	*** read bit error characteristics file if requested		*/  if (*mfile)  {    fp = fopen(mfile, "r");    if (fp == NULL)    {      perror("cli: Error opening the bit error characteristics file");      exit(0);    }    for (i = 0; i < bits; i++)      fscanf(fp, "%1d", mask[i]);    fclose(fp);  }	     /*	*** echo out parameters						*/  gethostname(host,20);  stat(prog, &statbuf);   getwd(dir);  time(&tim);  printf("             User: %s@%s\n", getlogin(), host);  printf("             Time: %s", ctime(&tim));  printf("          Program: %s\n", prog);  printf("         Modified: %s", ctime(&statbuf.st_mtime));  printf("        Directory: %s\n", dir);  if (cflag)  {    printf("     Channel file: %s\n", ifile);    printf("      Output file: %s\n", ofile);  }  else  {    printf("       Input file: %s\n", ifile);    printf("      Output file: %s\n", ofile);    printf("   Parameter file: %s\n", pfile);    printf("Quantization file: %s\n", qfile);    printf("BER and mask file: %s\n", mfile);    printf("         Log file: %s\n", lfile);    printf("           Code book size (ncsize)=%12d\n",ncsize);    printf("              Code word length (l)=%12d\n",*l);    printf("      LPC analysis frame size (ll)=%12d\n",*ll);    printf("             LPC filter order (no)=%12d\n",no);    printf("    Pitch analysis frame size (lp)=%12d\n",*lp);    printf("         Pitch analysis order (np)=%12d\n",*np);    printf(" Modified Excitation switch (mxsw)=%12d\n",mxsw);    printf("Fractional pitch analysis (pstype)=%12s\n",pstype);    printf("Prefilter weighting factor (prewt)=%12f\n",prewt);    printf("    Noise weighting factor (gamma)=%12f\n",gamma2);    printf("      Input scaling factor (scale)=%12f\n",*scale);    printf("   Output scaling factor (descale)=%12f\n",*descale);    printf("            %% bit error rate (BER)=%12f\n",*ber);    if (strcmp(cbgtype, "none"))       printf(" CB Gain: %8s quantizer, bit allocation: %2d\n", cbgtype, cbgbits);    if (strcmp(ptype, "none"))     {      printf("   Pitch: %8s quantizer, bit allocation: ", ptype);      for (i = 0; i < *np+2; i++)        printf("%2d",pbits[i]);      printf("\n");    }    if (strcmp(stype, "none"))     {      printf("Spectrum: %8s quantizer, bit allocation: ", stype);      for (i = 0; i < no; i++)        printf("%2d",sbits[i]);      printf("\n");    }    if (qflag) printf("Data rate = %4d bps %3d bpf (%4d bps with 1 bit sync)\n",                    rate, bits, rate2);    /*	*** verify parameters						*/    if (ncsize > MAXNCSIZE)     {      fprintf(stderr, "cli:  Error - ncsize too big\n");      exit(1);    }    if (*l > MAXL)               {      fprintf(stderr, "cli:  Error - l too big\n");      exit(1);    }    if (*ll > MAXLL)             {      fprintf(stderr, "cli:  Error - ll too big\n");      exit(1);    }    if (no > MAXNO)             {      fprintf(stderr, "cli:  Error - no too big\n");      exit(1);    }    if (*lp > MAXLP)             {      fprintf(stderr, "cli:  Error - lp too big\n");      exit(1);    }    if (*np > MAXNP)             {      fprintf(stderr, "cli:  Error - np too big\n");      exit(1);    }    if (gamma2 > 1.0)            {      fprintf(stderr, "cli:  Error - gamma > 1\n");      exit(1);    }    if (*scale < 0.0)            {      fprintf(stderr, "cli:  Error - scale < 0\n");      exit(1);    }    if (*ber < 0.0)         {      fprintf(stderr, "cli:  Error - ber < 0\n");      exit(1);    }    if (*ll%*l)     {      fprintf(stderr, "cli:  *** Error - ll & l are inconsistent\n");      exit(1);    }    if (*ll%*lp)     {      fprintf(stderr, "cli:  *** Error - ll & lp are inconsistent\n");      exit(1);    }    if (cbgbits < 5 || cbgbits > 7)     {      fprintf(stderr, "cli:  Error - bad cbgbits (not implemented)\n");      exit(1);    }    if (pbits[0] > 8)     {      fprintf(stderr, "cli:  *** Error - bad pbits[0] (not implemented)\n");      exit(1);    }    if (pbits[1] > 7 || pbits[1] < 3)     {      fprintf(stderr, "cli:  *** Error - bad pbits[1] (not implemented)\n");      exit(1);    }    for (i = 2; i < *np+2; i++)    {      if (pbits[i]  <  3 || pbits[i] > 5)          {        fprintf(stderr, "cli:  *** Error - bad pbits (not implemented)\n");        exit(1);      }    }    flag = TRUE;    for (j = 0; j < MAXQTYPE; j++)    {      if (strcmp(cbgtype, qtype[j]) == 0) flag = FALSE;    }    if (flag)     {      fprintf(stderr, "cli:  *** Error - bad cbgain quantizer type\n");      exit(1);    }    flag = TRUE;    for (j = 0; j < MAXQTYPE; j++)    {      if (strcmp(ptype, qtype[j]) == 0) flag = FALSE;    }    if (flag)     {      fprintf(stderr, "cli:  *** Error - bad pitch quantizer type\n");      exit(1);    }    flag = TRUE;    for (j = 0; j < MAXQTYPE; j++)    {      if (strcmp(stype, qtype[j]) == 0) flag = FALSE;    }    if (flag)     {      fprintf(stderr, "cli:  *** Error - bad spectrum quantizer type\n");      exit(1);    }    /*	*** generate log file if requested				*/    if (strcmp(lfile, "none"))    {        if (strcmp(lfile, "celp.log") == 0)      {        fp = fopen(lfile, "a");        if (fp == NULL)        {          perror("cli: Error opening the log file");          exit(0);        }      }      else      {        fp = fopen(lfile, "w");        if (fp == NULL)        {          perror("cli: Error opening the log file");          exit(0);        }      }      fprintf(fp, "             User: %s@%s\n", getlogin(), host);      fprintf(fp, "             Time: %s", ctime(&tim));      fprintf(fp, "          Program: %s\n", prog);      fprintf(fp, "         Modified: %s", ctime(&statbuf.st_mtime));      fprintf(fp, "        Directory: %s\n", dir);      fprintf(fp, "       Input file: %s\n", ifile);      fprintf(fp, "      Output file: %s\n", ofile);      fprintf(fp, "   Parameter file: %s\n", pfile);      fprintf(fp, "Quantization file: %s\n", qfile);      fprintf(fp, "BER and mask file: %s\n", mfile);      fprintf(fp, "         Log file: %s\n", lfile);      fprintf(fp, "           Code book size (ncsize)=%12d\n",ncsize);      fprintf(fp, "              Code word length (l)=%12d\n",*l);      fprintf(fp, "      LPC analysis frame size (ll)=%12d\n",*ll);      fprintf(fp, "             LPC filter order (no)=%12d\n",no);      fprintf(fp, "    Pitch analysis frame size (lp)=%12d\n",*lp);      fprintf(fp, "         Pitch analysis order (np)=%12d\n",*np);      fprintf(fp, " Modified Excitation switch (mxsw)=%12d\n",mxsw);      fprintf(fp, "Fractional pitch analysis (pstype)=%12s\n",pstype);      fprintf(fp, "Prefilter weighting factor (prewt)=%12f\n",prewt);            fprintf(fp, "    Noise weighting factor (gamma)=%12f\n",gamma2);      fprintf(fp, "      Input scaling factor (scale)=%12f\n",*scale);      fprintf(fp, "   Output scaling factor (descale)=%12f\n",*descale);      fprintf(fp, "            %% bit error rate (BER)=%12f\n",*ber);      if (strcmp(cbgtype, "none"))         fprintf(fp, " CB Gain: %8s quantizer, bit allocation: %2d\n",                   cbgtype, cbgbits);      if (strcmp(ptype, "none"))       {        fprintf(fp, "   Pitch: %8s quantizer, bit allocation: ", ptype);        for (i = 0; i < *np+2; i++)          fprintf(fp, "%2d",pbits[i]);        fprintf(fp, "\n");      }      if (strcmp(stype, "none"))       {        fprintf(fp, "Spectrum: %8s quantizer, bit allocation: ", stype);        for (i = 0; i < no; i++)          fprintf(fp, "%2d",sbits[i]);        fprintf(fp, "\n");      }      if (qflag)        fprintf(fp, "Data rate = %4d bps %3d bpf (%4d bps with 1 bit sync)\n",                  rate, bits, rate2);    }  }}/**************************************************************************** ROUTINE*               cliend** FUNCTION*               End of command line interface entry.*		Report and log job characteristics and performance.* * SYNOPSIS**	entry cliend(sumsnr, framesnr, realerror,*     &	            sumdm, framedm, sumdm2, framedm2)**   formal **			data	I/O*	name		type	type	function*       ------------------------------------------------------------------*	sumsnr		float	i	sum of segmental signal-to-noise*	framesnr	int	i	count of frames used for snr sum*	realerror	float	i	bit error rate*	sumdm		float	i	sum of speech distortion measures*						(see dist.c)*	framedm		int	i	count of frames used for sumdm*	sumdm2		float	i	sum of spectral distortion measures*						(see dist.c)*	framedm2	int	i	count of frames used for sumdm2***************************************************************************/#include <sys/times.h>cliend(sumsnr, framesnr, realerror, sumdm, framedm, sumdm2, framedm2)int framesnr, framedm, framedm2;float sumsnr, realerror, sumdm[], sumdm2[];{  long tim;  struct tms buffer;  /*			*calculate run time, print time & date		*/    time(&tim);  times(&buffer);  printf("Finished processing %d frames of data on %s", frame, ctime(&tim));  /*			*actual bit error rate				*/    printf("Overall bit error rate = %8.4f%%\n", realerror);  /*			*average segmental signal-to-noise		*/    if (framesnr <= 0) framesnr = 1;  if (sumsnr / framesnr > 0.0)    printf("Segmental SNR = %8.4f dB (%d subframes averaged for SNR)\n",           10 * log10(sumsnr/framesnr),framesnr);  else     printf("Segmental SNR = %8.4f    (%d subframes averaged for SNR)\n",           sumsnr/framesnr,framesnr);  /*			*speech distortion				*/    if (framedm != 0.0)  {    printf("Speech distortion:\n");    printf("likelihood measures   %7.4f     %7.4f\n",           sumdm[0]/framedm,sumdm[1]/framedm);    printf("cosh measures         %7.4f dB, %7.4f dB, %7.4f dB, %7.4f dB\n",           sumdm[2]/framedm, sumdm[3]/framedm,           sumdm[4]/framedm, sumdm[5]/framedm);    printf("cepstral distance     %7.4f dB, %7.4f dB, %7.4f dB\n",           sumdm[6]/framedm,sumdm[7]/framedm,sumdm[8]/framedm);    printf("average distance      %7.4f dB\n", sumdm[9]/framedm);  }  printf("%d subframes averaged for distance measures\n", framedm);  /*			*spectral distortion				*/    if (framedm2 != 0.0)  {    printf("Spectral distortion:\n");    printf("likelihood measures   %7.4f     %7.4f\n",           sumdm2[0]/framedm2,sumdm2[1]/framedm2);    printf("cosh measures         %7.4f dB, %7.4f dB, %7.4f dB, %7.4f dB\n",           sumdm2[2]/framedm2, sumdm2[3]/framedm2,           sumdm2[4]/framedm2, sumdm2[5]/framedm2);    printf("cepstral distance     %7.4f dB, %7.4f dB, %7.4f dB\n",           sumdm2[6]/framedm2,sumdm2[7]/framedm2,sumdm2[8]/framedm2);    printf("average distance      %7.4f dB\n", sumdm2[9]/framedm2);  }  printf("%d subframes averaged for distance measures\n", framedm2);    /*			*print runtime, etc. (& ring bell)		*/    printf("Elapsed times (s):  %.1f user, %.1f system, %.1f total\7\n",          buffer.tms_utime/60., buffer.tms_stime/60.,          (buffer.tms_utime + buffer.tms_stime)/60.);  /*			*write above to log file			*/    if (strcmp(lfile, "none"))  {    fprintf(fp, "Finished processing %d frames of data on %s",                 frame, ctime(&tim));    fprintf(fp, "Overall bit error rate = %8.4f%%\n", realerror);    if (sumsnr/framesnr > 0.0)      fprintf(fp, "Segmental SNR = %8.4f dB (%d subframes averaged for SNR)\n",                   10 * log10(sumsnr/framesnr), framesnr);    else       fprintf(fp, "Segmental SNR = %8.4f    (%d subframes averaged for SNR)\n",                   sumsnr/framesnr, framesnr);    if (framedm != 0.0)    {      fprintf(fp, "Speech distortion:\n");      fprintf(fp, "likelihood measures %7.4f     %7.4f\n",                 sumdm[0]/framedm,sumdm[1]/framedm);      fprintf(fp, "cosh measures       %7.4f dB, %7.4f dB, %7.4f dB, %7.4f dB\n",                 sumdm[2]/framedm, sumdm[3]/framedm,                 sumdm[4]/framedm, sumdm[5]/framedm);      fprintf(fp, "cepstral distance   %7.4f dB, %7.4f dB, %7.4f dB\n",                 sumdm[6]/framedm,sumdm[7]/framedm,sumdm[8]/framedm);      fprintf(fp, "average distance    %7.4f dB\n", sumdm[9]/framedm);    }    fprintf(fp, "%d subframes averaged for distance measures\n", framedm);    if (framedm2 != 0.0)    {      fprintf(fp, "Spectral distortion:\n");      fprintf(fp, "likelihood measures   %7.4f     %7.4f\n",                 sumdm2[0]/framedm2,sumdm2[1]/framedm2);      fprintf(fp, "cosh measures       %7.4f dB, %7.4f dB, %7.4f dB, %7.4f dB\n",                 sumdm2[2]/framedm2, sumdm2[3]/framedm2,                 sumdm2[4]/framedm2, sumdm2[5]/framedm2);      fprintf(fp, "cepstral distance   %7.4f dB, %7.4f dB, %7.4f dB\n",                 sumdm2[6]/framedm2,sumdm2[7]/framedm2,sumdm2[8]/framedm2);      fprintf(fp, "average distance    %7.4f dB\n", sumdm2[9]/framedm2);    }    fprintf(fp, "%d subframes averaged for distance measures\n", framedm2);    fprintf(fp, "Elapsed times (s):  %f user, %f system, %f total\6\n",                 buffer.tms_utime/60., buffer.tms_stime/60.,                 (buffer.tms_utime + buffer.tms_stime)/60.);    fprintf(fp, "%s%s\n","...................................",                         "...................................");    fclose(fp);  }}

⌨️ 快捷键说明

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