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

📄 gen-patt.c

📁 Reference Implementation of G.711 standard and other voice codecs
💻 C
📖 第 1 页 / 共 3 页
字号:
  P (("  be generated according to 3 models: Random bit errors (BER), and\n"));  P (("  random (FER) and (BFER) burst frame erasure.\n"));  P (("\n"));  P (("  Usage:\n"));  P (("  gen-patt [Options] err_pat_bs mode frno start state_f rate\n"));  P (("  Where:\n"));  P (("  err_pat .. name of error pattern bitstream file\n"));  P (("  mode ..... a letter representing one of 4 operating modes: \n"));  P (("             R:Bit Errors F:Simple Frame Erasures B:Bellcore model\n"));  P (("  frno ..... total number of bits|frames in pattern\n"));  P (("  start .... first bit|frame to have errors|erasures introduced [def:1]\n"));  P (("  state_f .. name of an ASCII state variable file NOTE: The parameters\n"));   P (("             saved in an existing state variable file *OVERRIDE*\n"));  P (("             the BER/FER/Gamma values defined by the user in the\n"));  P (("             command-line!!! \n"));  P (("  rate ..... desired error|erasure rate (according to the mode)\n"));  P (("  Options:\n"));  P(("   -ber ..... Bit error mode\n"));  P(("   -fer ..... Frame erasure mode using Gilbert model\n"));  P(("   -bfer .... Burst frame erasure mode using the Bellcore model\n"));  P(("   -rate # .. Desired bit|frame error rate\n"));  P(("              BER/FER:  0.00 .. 0.50      BFER: 0.01, 0.03, or 0.05\n"));  P(("   -gamma # . Correlation for BER|FER modes (0.00 .. 1.00; default: 0)\n"));  P(("   -n # ..... Number of bits|frames to be produced\n"));  P(("   -start # . First bit|frame to start applying errors [default: 1]\n"));  P(("   -byte .... Save error pattern in byte-oriented G.192 format (default)\n"));  P(("   -g192 .... Save error pattern in 16-bit G.192 format\n"));  P(("   -bit ..... Save error pattern in compact binary format (same as -compact)\n"));  P(("   -compact . Save error pattern in compact binary format (same as -bit)\n"));  P(("   -reset ... Reset EID state in between iteractions\n"));  P(("   -max # ... Maximum number of iteractions\n"));  P(("   -tol # ... Max deviation of specified BER/FER/BFER\n"));  P(("   -q ....... Quiet operation mode\n"));  /* Quit program */  exit (-128);}#undef P/* .................... End of display_usage() ........................... *//* ************************************************************************* *//* ****************************  MAIN_PROGRAM ****************************** *//* ************************************************************************* */int             main (argc, argv)  int             argc;  char           *argv[];{  /* Command line parameters */  char            mode = 'R';	       /* Processing mode Random,Frame,Burst */  char            data_file_name[128]; /* Name of the output file */  long            number_of_frames = 0;	/* Total no.of frames in pattern */  long            start_frame = 1;     /* Start inserting error from 1st one */  double          ber_rate = -1;       /* Bit error rate: depend on the mode */  char            state_file[128];     /* File for saving BER/FER/BFER state */  /* File I/O parameter */  FILE           *out_file_ptr;  int             out;  /* EID parameter, Gilbert model */  SCD_EID        *BEReid,	       /* Pointer to BER EID structure */                 *FEReid;	       /* Pointer to FER EID structure */  /* EID parameter, Bellcore model */  BURST_EID      *burst_eid;	       /* Pointer to FER burst EID structure */  /* Data arrays */  short           frame_erased[EID_BUFFER_LENGTH];  short           frame_okay[EID_BUFFER_LENGTH];  short          *error_pat;	       /* Bit error buffer */  /* Aux. variables */  double          FER;		       /* frame erasure rate */  double          BER;		       /* bit error rate */  double          BER_gamma = 0.0;     /* burst factors; NOT NEEDED */  double          FER_gamma = 0.0;     /* burst factors; NOT NEEDED */  double          ber1;		       /* returns values from BER_generator */  double          disturbed;	       /* # of distorted bits/frames */  double          processed;	       /* # of processed bits/frames */  double          generated;	       /* # of generated bits/frames */  double          percentage;  double          tolerance = -1;  /* Tolerance for actual rates; disabled */  char            percent = '%';  long            i, j, k, iteraction = 0;  long            items;	       /* Number of output elements */  long            itot;  long            index;#if defined(VMS)  char            mrs[15] = "mrs=512";#endif  long            max_iteraction = 100;  char            quiet = 0, reset = 0, save_format = byte;  long            (*save_data)() = save_byte;	/* Pointer to a function */#ifdef PORT_TEST    extern int PORTABILITY_TEST_OPERATION;    if (PORTABILITY_TEST_OPERATION)      fprintf(stderr, "WARNING! %s: compiled for PORTABILITY tests!\n\a", argv[0]);#endif  /* ......... GET PARAMETERS ......... */  /* Check options */  if (argc < 2)    display_usage ();  else  {    while (argc > 1 && argv[1][0] == '-')      if (strcmp (argv[1], "-start") == 0)      {	/* Define starting sample/frame for error insertion */	start_frame = atol (argv[2]);	/* Move arg{c,v} over the option to the next argument */	argc -= 2;	argv += 2;      }      else if (strcmp (argv[1], "-n") == 0)      {	/* Define number of samples to extract */	number_of_frames = atol (argv[2]);	/* Move arg{c,v} over the option to the next argument */	argc -= 2;	argv += 2;      }      else if (strcmp (argv[1], "-rate") == 0)      {	/* Define BER/FER/BFER to be used */	ber_rate = atof (argv[2]);	/* Move arg{c,v} over the option to the next argument */	argc -= 2;	argv += 2;      }      else if (strcmp (argv[1], "-ber") == 0 || strcmp (argv[1], "-BER") == 0)      {	/* Operating mode: BER */	mode = 'R';	/* Move arg{c,v} over the option to the next argument */	argc--;	argv++;      }      else if (strcmp (argv[1], "-fer") == 0 || strcmp (argv[1], "-FER") == 0)      {	/* Operating mode: FER */	mode = 'F';	/* Move arg{c,v} over the option to the next argument */	argc--;	argv++;      }      else if (strcmp (argv[1], "-gamma") == 0 ||	       strcmp (argv[1], "-GAMMA") == 0)      {	/* Gamma (correlation) factor: for modes R and F (BER/FER) */	BER_gamma = FER_gamma = atof (argv[2]);	/* Move arg{c,v} over the option to the next argument */	argc -= 2;	argv += 2;      }      else if (strcmp (argv[1], "-bfer") == 0 ||	       strcmp (argv[1], "-BFER") == 0)      {	/* Operating mode: BFER */	mode = 'B';	/* Move arg{c,v} over the option to the next argument */	argc--;	argv++;      }      else if (strcmp (argv[1], "-tol") == 0)      {	/* Max deviation from desired BER/FER/BFER values */	tolerance = atof (argv[2]);	/* Move arg{c,v} over the option to the next argument */	argc -= 2;	argv += 2;      }      else if (strcmp (argv[1], "-max") == 0)      {	/* Max number of iteractions */	max_iteraction = atof (argv[2]);	/* Move arg{c,v} over the option to the next argument */	argc -= 2;	argv += 2;      }      else if (strcmp (argv[1], "-reset") == 0)      {	/* Reset model in-between iteractions */	reset = 1;	/* Move arg{c,v} over the option to the next argument */	argc--;	argv++;      }      else if (strcmp (argv[1], "-g192") == 0)      {	/* Save bitstream as a G.192-compliant serial bitstream */	save_format = g192;	save_data = save_g192;	/* Move arg{c,v} over the option to the next argument */	argc--;	argv++;      }      else if (strcmp (argv[1], "-byte") == 0)      {	/* Save bitstream as a byte-oriented serial bitstream */	save_format = byte;	save_data = save_byte;	/* Move arg{c,v} over the option to the next argument */	argc--;	argv++;      }      else if (strcmp (argv[1], "-compact") == 0 ||	       strcmp (argv[1], "-bit") == 0)      {	/* Save bitstream as a compact binary bitstream */	save_format = compact;	save_data = save_bit;	/* Move arg{c,v} over the option to the next argument */	argc--;	argv++;      }      else if (strcmp (argv[1], "-q") == 0)      {	/* Set quiet mode */	quiet = 1;	/* Move arg{c,v} over the option to the next argument */	argc--;	argv++;      }      else      {	fprintf (stderr, "ERROR! Invalid option \"%s\" in command line\n\n",		 argv[1]);	display_usage ();      }  }  /* Get command line parameters */  GET_PAR_S (1, "_Output bit stream file ...........................: ",	     data_file_name);  FIND_PAR_C (2, "_Processing mode (Random,Frame,Burst) [RFB] .......: ",	      mode, mode);  /* NOTE: For the BER mode, number of frames below indicate the           number of EID_BUFFER_LENGTH bits frames should be generated */  FIND_PAR_L (3, "_Number of frames .................................: ",	      number_of_frames, number_of_frames);  FIND_PAR_L (4, "_Start frame ......................................: ",	      start_frame, start_frame);  FIND_PAR_S (5, "_File for error state variable ....................: ",	      state_file, "sta");  switch(mode)  {  case 'R':    FIND_PAR_D (6, "_Bit error rate (0.0 .. 0.5) ......................: ",		ber_rate, ber_rate);    break;  case 'F':    FIND_PAR_D (6, "_Frame erasure rate (0.0 .. 0.5) ..................: ",		ber_rate, ber_rate);    break;  case 'B':    FIND_PAR_D (6, "_Burst erasure rate (0.01,0.03,0.05) ..............: ",		ber_rate, ber_rate);    /* Check if a percentage was provided */    if (ber_rate < 0)      HARAKIRI(" You need to specify a BFER. Aborted.\n",5);    /* Get index for Bellcore model; verify */    index = (long) (100 * ber_rate + 0.5); /* 0.5 for a stupid bug in tcc */    if (check_bellcore (index) == 0)      HARAKIRI ("Invalid percentage for Bellcore model\n", 5);    break;  }  /* Convert mode to upper-case */  mode = toupper (mode);  /* Check consistency */  if (start_frame > number_of_frames)    HARAKIRI("*** Start frame is higher than number of frames. Aborted.\n", 1)  else if (start_frame == 0)    HARAKIRI("*** Start frame should be greater than zero (i.e. at least 1). Aborted.\n", 9);  if (ber_rate < 0)    HARAKIRI("*** You need to specify a BER/FER/BFER. Aborted.\n",5);  if (tolerance>=0)  {    double min_tol;    /* min_tol = floor((number_of_frames-start_frame-1) * ber_rate + 0.5); */    min_tol = floor((number_of_frames-start_frame) * ber_rate + 0.5);    min_tol = min_tol / (double)(number_of_frames-start_frame) - ber_rate;    min_tol = fabs(min_tol);    if (tolerance == 0)      tolerance = min_tol;    else if (tolerance<min_tol)    {      fprintf(stderr, "Cannot get tolerances smaller than %.2e %s %s\n",	      min_tol, "for the specified rate, pattern length and ",	      "precision. Aborted.");      exit(20);    }    fprintf(stderr, "_Error tolerance set at ...........................: %.2e\n",            tolerance);  }  /* Starting frame is from 0 to number_of_frames-1 */  start_frame--;  /*        **  Open output file   */  if ((out_file_ptr = fopen (data_file_name, WB)) == NULL)    HARAKIRI ("Could not create output file\n", 1);  out = fileno (out_file_ptr);  /*        **  Select mode   */  switch (mode)  {  case 'R':    /* Try to open EID-States file. */    BEReid = recall_eid_from_file (state_file, &BER, &BER_gamma);

⌨️ 快捷键说明

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