measure.c

来自「Reference Implementation of G.711 standa」· C语言 代码 · 共 549 行 · 第 1/2 页

C
549
字号
  0x1429, 0x3e7, 0x1bf6, 0xc38, 0xb97, 0x1c59, 0x448, 0x1386,  0xb16, 0x1cd8, 0x4c9, 0x1307, 0x14a8, 0x366, 0x1b77, 0xcb9,  0xa14, 0x1dda, 0x5cb, 0x1205, 0x15aa, 0x264, 0x1a75, 0xdbb,  0x152b, 0x2e5, 0x1af4, 0xd3a, 0xa95, 0x1d5b, 0x54a, 0x1284,};/* Table for ARC CRCs */static WTYPE    crctab_arc[1 << B] = {  0x0, 0xc0c1, 0xc181, 0x140, 0xc301, 0x3c0, 0x280, 0xc241,  0xc601, 0x6c0, 0x780, 0xc741, 0x500, 0xc5c1, 0xc481, 0x440,  0xcc01, 0xcc0, 0xd80, 0xcd41, 0xf00, 0xcfc1, 0xce81, 0xe40,  0xa00, 0xcac1, 0xcb81, 0xb40, 0xc901, 0x9c0, 0x880, 0xc841,  0xd801, 0x18c0, 0x1980, 0xd941, 0x1b00, 0xdbc1, 0xda81, 0x1a40,  0x1e00, 0xdec1, 0xdf81, 0x1f40, 0xdd01, 0x1dc0, 0x1c80, 0xdc41,  0x1400, 0xd4c1, 0xd581, 0x1540, 0xd701, 0x17c0, 0x1680, 0xd641,  0xd201, 0x12c0, 0x1380, 0xd341, 0x1100, 0xd1c1, 0xd081, 0x1040,  0xf001, 0x30c0, 0x3180, 0xf141, 0x3300, 0xf3c1, 0xf281, 0x3240,  0x3600, 0xf6c1, 0xf781, 0x3740, 0xf501, 0x35c0, 0x3480, 0xf441,  0x3c00, 0xfcc1, 0xfd81, 0x3d40, 0xff01, 0x3fc0, 0x3e80, 0xfe41,  0xfa01, 0x3ac0, 0x3b80, 0xfb41, 0x3900, 0xf9c1, 0xf881, 0x3840,  0x2800, 0xe8c1, 0xe981, 0x2940, 0xeb01, 0x2bc0, 0x2a80, 0xea41,  0xee01, 0x2ec0, 0x2f80, 0xef41, 0x2d00, 0xedc1, 0xec81, 0x2c40,  0xe401, 0x24c0, 0x2580, 0xe541, 0x2700, 0xe7c1, 0xe681, 0x2640,  0x2200, 0xe2c1, 0xe381, 0x2340, 0xe101, 0x21c0, 0x2080, 0xe041,  0xa001, 0x60c0, 0x6180, 0xa141, 0x6300, 0xa3c1, 0xa281, 0x6240,  0x6600, 0xa6c1, 0xa781, 0x6740, 0xa501, 0x65c0, 0x6480, 0xa441,  0x6c00, 0xacc1, 0xad81, 0x6d40, 0xaf01, 0x6fc0, 0x6e80, 0xae41,  0xaa01, 0x6ac0, 0x6b80, 0xab41, 0x6900, 0xa9c1, 0xa881, 0x6840,  0x7800, 0xb8c1, 0xb981, 0x7940, 0xbb01, 0x7bc0, 0x7a80, 0xba41,  0xbe01, 0x7ec0, 0x7f80, 0xbf41, 0x7d00, 0xbdc1, 0xbc81, 0x7c40,  0xb401, 0x74c0, 0x7580, 0xb541, 0x7700, 0xb7c1, 0xb681, 0x7640,  0x7200, 0xb2c1, 0xb381, 0x7340, 0xb101, 0x71c0, 0x7080, 0xb041,  0x5000, 0x90c1, 0x9181, 0x5140, 0x9301, 0x53c0, 0x5280, 0x9241,  0x9601, 0x56c0, 0x5780, 0x9741, 0x5500, 0x95c1, 0x9481, 0x5440,  0x9c01, 0x5cc0, 0x5d80, 0x9d41, 0x5f00, 0x9fc1, 0x9e81, 0x5e40,  0x5a00, 0x9ac1, 0x9b81, 0x5b40, 0x9901, 0x59c0, 0x5880, 0x9841,  0x8801, 0x48c0, 0x4980, 0x8941, 0x4b00, 0x8bc1, 0x8a81, 0x4a40,  0x4e00, 0x8ec1, 0x8f81, 0x4f40, 0x8d01, 0x4dc0, 0x4c80, 0x8c41,  0x4400, 0x84c1, 0x8581, 0x4540, 0x8701, 0x47c0, 0x4680, 0x8641,  0x8201, 0x42c0, 0x4380, 0x8341, 0x4100, 0x81c1, 0x8081, 0x4040,};/* -------------- Begin of function updcrc() ---------------------- */WTYPEupdcrc(icrc, icp, icnt, crctab, swapped)  WTYPE           icrc, *crctab;  unsigned char  *icp;  int             icnt;  char            swapped;{  register WTYPE  crc = icrc;  register unsigned char *cp = icp;  register int    cnt = icnt;  if (swapped)    while (cnt--)    {      crc = (crc >> B) ^ crctab[(crc & ((1 << B) - 1)) ^ *cp++];    }  else    while (cnt--)    {      crc = (crc << B) ^ crctab[(crc >> (W - B)) ^ *cp++];    }  return (crc);}/* .......................... End of updcrc() ............................ *//*  * -------------------------------------------------------------------------- * ... Display usage of program ...  *     Simao 10.Mar.94 * -------------------------------------------------------------------------- */#define P(x) printf xvoid display_usage(){  P(("MEASURE Version 1.0 of 10/Mar/1994 \n\n"));  P((" Program to calculate the max, min, and average values for a file.\n"));  P((" Usage:\n"));  P(("  $ measure file \n"));  P(("  where:\n"));  P(("  file          is the name of the file to measured\n"));  P(("\n"));  P((" Options:\n"));  P((" ~~~~~~~~\n"));  P((" -h or -?      show program usage\n"));  P((" -blk size     change the number of samples per block [default 256]\n"));  P((" -skip n       number of blocks to skip [default: none]\n"));  P((" -crc          also calculate crc for files\n"));  P((" -hex          carry-out hex dump\n"));  P(("\n"));  /* Quit program */  exit(-128);}#undef P/* ....................... end of display_usage() ...........................*//*============================== */int main(argc,argv)int argc;char *argv[];/*============================== */{  char display_crc = 0, print_hex = 0;  char inpfil[50];  long count,skip=0;  unsigned short us_max, us_min;  long smpno,blk;  short *samples;#ifdef VMS  static char     mrs[15] = "mrs=512";	/* for correct mrs, VMS environment */#endif  double  avg_x, rms_x, stddev_x, max_x, min_x;  FILE *Fi;  /* DEFAULT OPTIONS AND INITIAL VALUES */  skip = 0;  blk = 256;  /* GETTING OPTIONS */    while (argc > 1 && argv[1][0] == '-')      if (strcmp(argv[1],"-?")==0 || strcmp(argv[1],"-h")==0 )      {	/* Display usage */	display_usage();      }      else if (strcmp(argv[1],"-blk")==0)      {        /* Change block size for averages */	blk = atol(argv[2]);	argc -= 2;	argv += 2;      }      else if (strcmp(argv[1],"-skip")==0)      {        /* Define number of blocks (defined by blk) to skip */	skip = atol(argv[2]);	argc -= 2;	argv += 2;      }      else if (strcmp(argv[1],"-crc")==0)      {        /* Change block size for averages */	display_crc = 1;	argc--;	argv++;      }      else if (strcmp(argv[1],"-hex")==0)      {        /* Change block size for averages */	print_hex = 1;	argc--;	argv++;      }      else if (strcmp(argv[1],"-")==0)      {	break;      }      else      {	fprintf(stderr, "ERROR! Invalid option \"%s\" in command line\n\n",		argv[1]);	display_usage();      }  /* REPEAT FOR ALL FILES IN THE COMMAND LINE */  while(argc>1)  {    /* Get new file name and update argument line pointer/counter */    strcpy(inpfil, argv[1]);    argv++;    argc--;        /* Reset statistics */    avg_x = rms_x = 0;     smpno = 0;    max_x = -1E38;     min_x =  1E38;    /* Initialize crc calculations */    crc_a = init_crc_a;    crc_c = init_crc_c;    crc_x = init_crc_x;        /* Open files */    if (strcmp(inpfil,"-") == 0)      Fi = stdin;    else      if ((Fi=fopen(inpfil,RB))==NULL) KILL(inpfil,2);    /* Move onto start */    fseek(Fi, skip * blk * sizeof(short), 0);    /* Allocate memory */    samples = (short *) calloc(blk, sizeof(short));    if (!samples)      HARAKIRI("Cannot allocate memory - aborted\n", 1);        /* Find statistics */    while((count = fread(samples, sizeof(short), blk, Fi))!=0)    {      /* Update statistics */      avg_x += get_sum(samples, count);      rms_x += get_square(samples, count);      max_x = get_max(max_x, samples, count);      min_x = get_min(min_x, samples, count);          /* Get CRCs on demand */      if (display_crc)      {	crc_a = get_arc_crc(crc_a, (char *)samples, 2 * count);	crc_c = get_ccitt_crc(crc_c, (char *)samples, 2 * count);	crc_x = get_xmodem_crc(crc_x, (char *)samples, 2 * count);      }          /* Update sample counter */      smpno+= count;    }    /* Check if empty file */    if (smpno==0)    {      printf("Samples:     0 Min: ------ Max: ----- DC: ------- AC: -------");      if (display_crc)	printf(" CRC:[ ---- CCITT ---- ARC ---- XMODEM]");      printf("\t%s\n", inpfil);      continue;    }    /* Final adjustements do statistics */    stddev_x = sqrt(get_var(rms_x, avg_x, smpno));    avg_x /= (double)smpno;    rms_x = sqrt(rms_x/(double)smpno);    /* Print results */    if (print_hex)    {      us_max = (unsigned short)max_x;      us_min = (unsigned short)min_x;      printf("Samples: %5ld Min: %04X Max: %04X ", 	     smpno, us_min, us_max);    }    else      printf("Samples: %5ld Min: %5.0f Max: %05.0f ", 	     smpno, min_x, max_x);    printf("DC: %7.2f AC: %7.2f", avg_x, stddev_x);    if (display_crc)      printf(" CRC:[ %04X CCITT %04X ARC %04X XMODEM]", crc_c, crc_a, crc_x);    printf("\t%s\n", inpfil);    /* Close file */    fclose(Fi);  }    /* EXITING */  free(samples);#ifndef VMS  exit(0);#endif}

⌨️ 快捷键说明

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