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

📄 sv56demo.c

📁 Reference Implementation of G.711 standard and other voice codecs
💻 C
📖 第 1 页 / 共 2 页
字号:
  }}/* .................... End of print_p56_long_summary() ................... *//*   ============================================================================       void print_p56_short_summary (char *file, SVP56_state state,       ~~~~~~~~~~~~~~~~~~~~~~~~  double al_dB, double ratio);       Print one-line summary of P.56 statistics       Parameter:       ~~~~~~~~~~       file ..... File name       state .... P.56 state variable       al_dB .... active level in dB       ratio .... ratio of maximum number representable in the system (based on                  the number of bits, or resolution, of the input speech file)		  to the range of the input signal. E.g., for a 16 bit system		  with a +-1 signal range, ratio = 32760 / 1.0.       Returns       ~~~~~~~       None       Original author       ~~~~~~~~~~~~~~~       simao@ctd.comsat.com       Log of changes       ~~~~~~~~~~~~~~       01.Nov.96	v1.0	Creation.  ============================================================================*/void print_p56_short_summary(out, file, state, al_dB, ratio, gain)  FILE *out;  SVP56_state     state;  char *file;  double ratio, al_dB, gain;{  /* Report number of samples */  fprintf(out, "Samples: %5ld ", state.n);  /* Skip if filesize is zero */  if (state.n==0)  {    fprintf(out, "%s%s%s", "Min: ------ Max: ----- DC: ------- ",	   "RMSLev[dB]: ------- ActLev[dB]: ------- %Active:  ------ ",	    "Gain:  ------ ");  }  else  {    fprintf(out, "Min: %-5.0f ",       ratio * state.maxN);    fprintf(out, "Max: %-5.0f ",       ratio * state.maxP);    fprintf(out, "DC: %-7.2f ",        ratio * state.DClevel);    fprintf(out, "RMSLev[dB]: %7.3f ", state.rmsdB);    fprintf(out, "ActLev[dB]: %7.3f ", al_dB);    fprintf(out, "%%Active: %7.3f",    state.ActivityFactor * 100);    fprintf(out, "Gain[]: %7.3f",      gain);  }  fprintf(out, "\t%s\n", file);}/* ................... End of print_p56_short_summary() .................... *//*   **************************************************************************   ***                                                                    ***   ***        Demo-Program for testing the correct implementation         ***   ***               and to show how to use the programs                  ***   ***                                                                    ***   ***************************************************************************/int main(argc, argv)  int             argc;  char           *argv[];{  /* DECLARATIONS */  /* Parameters for operation */  double          Overflow;	/* Max.positive value for AD_resolution bits */  long            N=256, N1=1, N2=0, i, l;  double          NdB=-26; /* dBov */  /* Intermediate storage variables for speech voltmeter */  SVP56_state     state;  /* File-related variables */  char            FileIn[50], FileOut[50];  FILE           *Fi, *Fo;	/* input/output file pointers */  FILE           *out=stdout;   /* where to print the statistical results */#ifdef VMS  char            mrs[15];#endif  /* Other variables */  char	          quiet=0, use_active_level = 1, long_summary = 1;  short           buffer[4096];  float           Buf[4096];  long            NrSat = 0, start_byte, bitno = 16;  double          sf = 16000, factor;  double          ActiveLeveldB, DesiredSpeechLeveldB;  static char     funny[5] = {'/', '-', '\\', '|', '-'};  static unsigned mask[5] = {0xFFFF,0xFFFE,0xFFFB,0xFFF8,0xFFF0};  /* ......... GET PARAMETERS ......... */   /* Getting options */  if (argc < 2)    display_usage();  else  {    while (argc > 1 && argv[1][0] == '-')      if (strcmp(argv[1], "-lev") == 0)      {	/* Change default level normalization */	NdB = atof(argv[2]);	/* Update argc/argv to next valid option/argument */	argv+=2;	argc-=2;      }      else if (strcmp(argv[1], "-sf") == 0)      {	/* Change default sampling frequency */	sf = atof(argv[2]);	/* Update argc/argv to next valid option/argument */	argv+=2;	argc-=2;      }      else if (strcmp(argv[1], "-bits") == 0)      {	/* Change default sampling frequency */	bitno = atol(argv[2]);	/* Update argc/argv to next valid option/argument */	argv+=2;	argc-=2;      }      else if (strcmp(argv[1], "-rms") == 0)      {	/* Use the RMS level to normalize instead of the active level */	use_active_level = 0;	/* Update argc/argv to next valid option/argument */	argv++;	argc--;      }      else if (strcmp(argv[1], "-blk") == 0)      {	/* Change default sampling frequency */	N = atol(argv[2]);	/* Update argc/argv to next valid option/argument */	argv+=2;	argc-=2;      }      else if (strcmp(argv[1], "-start") == 0)      {	/* Change default sampling frequency */	N1 = atol(argv[2]);	/* Update argc/argv to next valid option/argument */	argv+=2;	argc-=2;      }      else if (strcmp(argv[1], "-end") == 0)      {	/* Change number of blocks based on the last block */	N2 = atol(argv[2]) - N1 + 1;	/* Update argc/argv to next valid option/argument */	argv+=2;	argc-=2;      }      else if (strcmp(argv[1], "-n") == 0)      {	/* Change default number of blocks */	N2 = atol(argv[2]);	/* Update argc/argv to next valid option/argument */	argv+=2;	argc-=2;      }      else if (strcmp(argv[1], "-log") == 0)      {	/* Log statistics into a file */	if ((out=fopen(argv[2], WT)) == NULL)	  KILL(argv[2], 2);	else	  fprintf(stderr, "Statitics will be logged in %s\n", argv[2]);	/* Update argc/argv to next valid option/argument */	argv+=2;	argc-=2;      }      else if (strcmp(argv[1], "-q") == 0)      {	/* Don't print progress indicator */	quiet = 1;	/* Move argv over the option to the next argument */	argv++;	argc--;      }      else if (strcmp(argv[1], "-qq") == 0)      {	/* Don't print progress indicator and print short summary */	quiet = 1;	long_summary = 0;	/* Move argv over the option to the next argument */	argv++;	argc--;      }      else if (strcmp(argv[1], "-?") == 0 || strstr(argv[1], "-help"))      {	/* Print help */	display_usage();      }      else      {	fprintf(stderr, "ERROR! Invalid option \"%s\" in command line\n\n",		argv[1]);	display_usage();      }  }  /* Reads parameters for processing */  GET_PAR_S(1, "_Input File: ........................... ", FileIn);  GET_PAR_S(2, "_Output File: .......................... ", FileOut);  FIND_PAR_L(3, "_Block Length: ......................... ", N, N);  FIND_PAR_L(4, "_Start Block: .......................... ", N1, N1);  FIND_PAR_L(5, "_No. of Blocks: ........................ ", N2, N2);  FIND_PAR_D(6, "_dBs relative to system overload: ...... ", NdB, NdB);  FIND_PAR_D(7, "_Sampling Frequency: ................... ", sf, sf);  FIND_PAR_L(8, "_A/D resolution: ....................... ", bitno, bitno);  /* ......... SOME INITIALIZATIONS ......... */  start_byte = --N1;  start_byte *= N * sizeof(short);  /* Check if is to process the whole file */  if (N2 == 0)  {    struct stat     st;    /* ... find the input file size ... */    stat(FileIn, &st);    N2 = ceil((st.st_size - start_byte) / (double)(N * sizeof(short)));  }  /* Overflow (saturation) point */  Overflow = pow((double)2.0, (double)(bitno-1));  /* reset variables for speech level measurements */  init_speech_voltmeter(&state, sf);/* * ......... FILE PREPARATION ......... */  /* Opening input file; abort if there's any problem */#ifdef VMS  sprintf(mrs, "mrs=%d", 2 * N);#endif  if ((Fi = fopen(FileIn, RB)) == NULL)    KILL(FileIn, 2);  /* Creates output file */  if ((Fo = fopen(FileOut, WB)) == NULL)    KILL(FileOut, 3);  /* Move pointer to 1st block of interest */  if (fseek(Fi, start_byte, 0) < 0l)    KILL(FileIn, 4);  /* ... MEASUREMENT OF ACTIVE SPEECH LEVEL ACCORDING P.56 ... */  /* Print info */  if (!quiet)    printf("  Processing \r");  /* Process selected blocks */  for (i = 0; i < N2; i++)  {    /* Read samples ... */    if ((l = fread(buffer, sizeof(short), N, Fi)) > 0)    {      /* ... Convert samples to float */      sh2fl((long) l, buffer, Buf, bitno, 1);      /* ... Get the active level */      ActiveLeveldB = speech_voltmeter(Buf, (long) l, &state);      /* Print some preliminary information */      if (!quiet) 	printf("%c\r", funny[i % 5]);    }    else    {      KILL(FileIn, 5);    }  }  /* Beautify screen ... */  if (!quiet)    printf("\n");  /* ... COMPUTE EQUALIZATION FACTOR ... */  /* Computes the equalization factor to be used in the output file */  DesiredSpeechLeveldB = (double) NdB;  if (use_active_level)    factor = pow(10.0, (DesiredSpeechLeveldB-ActiveLeveldB) / 20.0);  else    factor = pow(10.0, (DesiredSpeechLeveldB-SVP56_get_rms_dB(state)) / 20.0);  /* ... PRINT-OUT OF RESULTS ... */  if (long_summary)    print_p56_long_summary(out, FileIn, state, ActiveLeveldB, NdB,			   Overflow, factor, N, N1, N2, bitno);  else    print_p56_short_summary(out, FileIn, state, ActiveLeveldB, 			    Overflow, factor);  /* EQUALIZATION: hard clipping (with truncation) */  /* Move pointer to 1st desired block */  if (fseek(Fi, start_byte, 0) < 0l)    KILL(FileIn, 4);  /* Get data of interest, equalize and de-normalize */  for (i = 0; i < N2; i++)  {    if ((l = fread(buffer, sizeof(short), N, Fi)) > 0)    {      /* convert samples to float */      sh2fl((long) l, buffer, Buf, bitno, 1);      /* equalizes vector */      scale(Buf, (long) l, (double) factor);      /* Convert from float to short with hard clip and truncation */      NrSat += fl2sh((long) l, Buf, buffer, (double) 0.0, mask[16-bitno]);      /* write equalized, de-normalized and hard-clipped samples to file */      if ((l = fwrite(buffer, sizeof(short), l, Fo)) < 0)	KILL(FileOut, 6);    }    else    {      KILL(FileIn, 5);    }  }  /* Log number of clipped samples */  if (NrSat != 0)    fprintf(out, "\n  Number of clippings: .......... %7ld []\n", NrSat);  else    fprintf(out, "\n");  /* FINALIZATIONS */  /* Beautify screen ... */  if (!quiet)    printf("---> DONE    \n");  /* Close files ... */  fclose(Fi);  fclose(Fo);  if (out != stdout)    fclose(out);#if !defined(VMS)  return (0);#endif}

⌨️ 快捷键说明

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