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

📄 eiddemo.c

📁 Reference Implementation of G.711 standard and other voice codecs
💻 C
📖 第 1 页 / 共 2 页
字号:
    fprintf(stderr, "\r%.0f bits processed", prcbits);  printf("CPU-time %f sec\r\n\n", t);  if (prcbits > 0)  {    printf("measured bit error rate    : %f\n", dstbits / prcbits);    printf("  (%.0f of %.0f bits distorted)\n", dstbits, prcbits);  }  if (prcfrms > 0)  {    printf("measured frame erasure rate: %f\n", ersfrms / prcfrms);    printf("  (%.0f of %.0f frames erased) \n", ersfrms, prcfrms);  }/*  * ...... Save EID-status to file for bit error and frame erasure EIDs ......  */  /* NB: the following file I/O is a user defined routine, so this function   * is located within this DEMO file -- see below */  save_EID_to_file(BEReid, &BERfile[0], BER, BER_gamma);  if (FER != 0.0)    save_EID_to_file(FEReid, &FERfile[0], FER, FER_gamma);#ifndef VMS			/* return value to OS if not VMS */  return 0;#endif}/* .......................... End of main() .......................... *//*  ============================================================================        void display_usage (void);        ~~~~~~~~~~~~~~~~~~        Description:        ~~~~~~~~~~~~        Display usage of this demo program and exit;        Return value:  None.        ~~~~~~~~~~~~~        Author: <hf@pkinbg.uucp>        ~~~~~~~        History:        ~~~~~~~~        28.Feb.92 v1.0 Release of 1st version <hf@pkinbg.uucp> ============================================================================*/#define P(x) printf xvoid            display_usage(){  char            prompt;  /* Choose a nice prompt */#if defined(VMS)  prompt = '$';#elif defined(MSDOS)  prompt = '>';#else  prompt = '#';#endif  P (("eiddemo.c version 3.2 of 28/Mar/2000\n"));  /* Print the proper usage */  P(("  Usage: %c %s%s", prompt,	          "EID ifile ofile BERfile FERfile ",                  "[ BER BER_gamma FER FER_gamma]\n\n"));  P(("\tifile      : binary file with  input bitstream\n"));  P(("\tofile      : binary file with output bitstream\n"));  P(("%s%s", "\tBERfile    : File, containing the EID-status ",	                  "for bit error rate \n"));  P(("%s%s", "\tFERfile    : File, containing the EID-status ",	                  "for frame erasure module\n"));  P(("\tBER        : bit error rate (0.0 ... 0.50)\n"));  P(("\tBER_gamma  : burst factor   (0.0 ... 0.99)\n"));  P(("\t\t         =0.00 --> errors are totally random\n"));  P(("\t\t         =0.50 --> errors are slightly bursty\n"));  P(("\t\t         =0.99 --> errors are totally bursty\n"));  P(("\tFER        : frame erasure rate (0.0 ... 0.5)\n"));  P(("\tFER_gamma  : burst factor   (0.0 ... 0.99)\n"));  P(("\t\t         =0.00 --> erasures are totally random\n"));  P(("\t\t         =0.50 --> errsures are slightly bursty\n"));  P(("\t\t         =0.99 --> errsures are totally bursty\n\n"));  exit(1);}/* .................. End of display_usage() ....................... *//*  ===========================================================================        long save_EID_to_file (SCD_EID *EID, char *EIDfile, double BER,        ~~~~~~~~~~~~~~~~~~~~~  double GAMMA);        Description:        ~~~~~~~~~~~~        Save current states of EID to file. Data are stored on an        ASCII file. May be that on some platforms this function must be        slightly modified, but has worked nicely for the all tested.        The contents of the EID-struct are stored on an ASCII file to        allow the user observation or control or what  ever. The file        should look like:                         BER           = 0.020000                         GAMMA         = 0.500000                         RAN-seed      = 0x1db85ea6                         Current State = G                         GOOD->GOOD    = 0.980000                         GOOD->BAD     = 1.000000                         BAD ->GOOD    = 0.480000                         BAD ->BAD     = 1.000000        Parameters:        ~~~~~~~~~~~        SCD_EID *EID .......... EID-structure        char *EIDfile ......... filename for saving the state        double BER ............ bit error rate        double GAMMA .......... burst factor        Return value:        ~~~~~~~~~~~~~        Returns 1 if EID-state was successfully saved to file; 0 if failed.        Author: <hf@pkinbg.uucp>        ~~~~~~~        History:        ~~~~~~~~        28.Feb.92 v1.0 Release of 1st version <hf@pkinbg.uucp>  ===========================================================================*/long            save_EID_to_file(EID, EIDfile, BER, GAMMA)  SCD_EID        *EID;  char           *EIDfile;  double          BER, GAMMA;{  FILE           *EIDfileptr;  /* open specified ASCII file for "overwriting": */  EIDfileptr = fopen(EIDfile, RWT);  /* If failed, create new file: */  if (EIDfileptr == NULL)  {    if ((EIDfileptr = fopen(EIDfile, WT)) == NULL)      return (0L);  }  /* otherwise: set filepointer to beginning of file for overwriting */    else    {      fseek(EIDfileptr, 0L, 0);    }  /* Since the selected bit error rate and burst factor cannot be seen from   * the transition matrix, these values are also stored in file (only for   * documentation purposes). */  fprintf(EIDfileptr, "BER           = %f\n", BER);  fprintf(EIDfileptr, "GAMMA         = %f\n", GAMMA);  /* current state of random generator: */  fprintf(EIDfileptr, "RAN-seed      = 0x%08lx\n", get_RAN_seed(EID));  /* current state of GEC-model: */  fprintf(EIDfileptr, "Current State = %c\n", get_GEC_current_state(EID));  /* Save contents of Transition Matrix: */  fprintf(EIDfileptr, "GOOD->GOOD    = %f\n", get_GEC_matrix(EID, 'G', 'G'));  fprintf(EIDfileptr, "GOOD->BAD     = %f\n", get_GEC_matrix(EID, 'G', 'B'));  fprintf(EIDfileptr, "BAD ->GOOD    = %f\n", get_GEC_matrix(EID, 'B', 'G'));  fprintf(EIDfileptr, "BAD ->BAD     = %f\n", get_GEC_matrix(EID, 'B', 'B'));  fclose(EIDfileptr);  return (1L);}/* ....................... End of save_EID_to_file() ....................... *//*  ============================================================================        SCD_EID *open_eid_from_file (char *EIDfile,        ~~~~~~~~~~~~~~~~~~~~~~~~~~~  double *ber, double *gamma);        Description:        ~~~~~~~~~~~~        Allocate memory for EID struct and load EID-states from        previous call (which is saved on file) into a struct SCD_EID.        Data are read from an ASCII file. May be that  on some platforms        this function must be slightly modified, but has worked nicely        for the all tested.        Parameters:        ~~~~~~~~~~~        char *EIDfile ... file with EID states        double *ber ..... pointer to "bit error rate"        double *gamma ... pointer to burst factor        Return value:        ~~~~~~~~~~~~~        Returns a pointer to a EID-state data structure; if failed, it        will be a null pointer.        Author: <hf@pkinbg.uucp>        ~~~~~~~        History:        ~~~~~~~~        28.Feb.92 v1.0 Release of 1st version <hf@pkinbg.uucp> ============================================================================*/SCD_EID        *recall_eid_from_file(EIDfile, ber, gamma)  char           *EIDfile;  double         *ber;  double         *gamma;{  SCD_EID        *EID;  FILE           *EIDfileptr;  char            chr;  double          thr;  long            seed;  /* Open ASCII file with EID states */  if ((EIDfileptr = fopen(EIDfile, RT)) == NULL)    return ((SCD_EID *) 0);  /* Load channel model parameters ber and gamma */  READ_lf(EIDfileptr, 1L, ber);  READ_lf(EIDfileptr, 1L, gamma);  /* Now open EID with default values and update states afterwards from file */  if ((EID = open_eid(*ber, *gamma)) == (SCD_EID *) 0)    return ((SCD_EID *) 0);  /* update EID-struct from file: seed for random generator */  READ_L(EIDfileptr, 1L, &seed);  set_RAN_seed(EID, (unsigned long) seed);	/* store into struct */  /* update EID-struct from file: current state */  READ_c(EIDfileptr, 1L, &chr);  set_GEC_current_state(EID, chr);  /* update EID-struct from file: threshold GOOD->GOOD */  READ_lf(EIDfileptr, 1L, &thr);  set_GEC_matrix(EID, thr, 'G', 'G');  /* update EID-struct from file: threshold GOOD->BAD */  READ_lf(EIDfileptr, 1L, &thr);  set_GEC_matrix(EID, thr, 'G', 'B');  /* update EID-struct from file: threshold BAD ->GOOD */  READ_lf(EIDfileptr, 1L, &thr);  set_GEC_matrix(EID, thr, 'B', 'G');  /* update EID-struct from file: threshold BAD ->BAD */  READ_lf(EIDfileptr, 1L, &thr);  set_GEC_matrix(EID, thr, 'B', 'B');  /* Finalizations */  fclose(EIDfileptr);  return (EID);}/* ..................... End of recall_eid_from_file() ..................... *//*  ============================================================================        long READ_L (FILE *fp, long n, long *ary);        ~~~~~~~~~~~        Description:        ~~~~~~~~~~~~        Read `n' longs from an EID-state file onto an array.        Return value:        ~~~~~~~~~~~~~        Returns the number of longs read.        Author: <hf@pkinbg.uucp>        ~~~~~~~        History:        ~~~~~~~~        28.Feb.92 v1.0 Release of 1st version <hf@pkinbg.uucp> ============================================================================*/long                READ_L(fp, n, longary)  FILE           *fp;  long            n;  long           *longary;{  long            i, ic;  char            c;  char            ch[16];  while ((c = getc(fp)) != '=');  for (i = 0; i < n; i++)  {    while (((c = getc(fp)) == 32) || (c == 9));    ic = 0;    while ((c != 32) && (c != 9) && (c != '\n') && (ic < 15))    {      ch[ic++] = c;      c = getc(fp);    }    ch[ic] = (char) 0;    if ((ch[0] == '0') && (toupper(ch[1]) == 'X'))    {      sscanf(&ch[2], "%lx", &longary[i]);    }    else    {      sscanf(ch, "%ld", &longary[i]);    }  }  return (n);}/* ....................... End of READ_L() ....................... *//*  ============================================================================        long READ_lf (FILE *fp, long n, double *doubleary);        ~~~~~~~~~~~~        Description:        ~~~~~~~~~~~~        Read `n' doubles from an EID-state file onto an array.        Return value:        ~~~~~~~~~~~~~        Returns the number of doubles read.        Author: <hf@pkinbg.uucp>        ~~~~~~~        History:        ~~~~~~~~        28.Feb.92 v1.0 Release of 1st version <hf@pkinbg.uucp> ============================================================================*/long                READ_lf(fp, n, doubleary)  FILE           *fp;  long            n;  double         *doubleary;{  long            i, ic;  char            c;  char            ch[64];  while ((c = getc(fp)) != '=');  for (i = 0; i < n; i++)  {    while (((c = getc(fp)) == 32) || (c == 9));    ic = 0;    while ((c != 32) && (c != 9) && (c != '\n') && (ic < 63))    {      ch[ic++] = c;      c = getc(fp);    }    ch[ic] = (char) 0;    sscanf(ch, "%lf", &doubleary[i]);  }  return (n);}/* ....................... End of READ_lf() ....................... *//*  ============================================================================        long READ_c (FILE *fp, long n, char *chr);        ~~~~~~~~~~~        Description:        ~~~~~~~~~~~~        Read `n' doubles from an EID-state file onto an array.        Return value:        ~~~~~~~~~~~~~        Returns the number of chars read.        Author: <hf@pkinbg.uucp>        ~~~~~~~        History:        ~~~~~~~~        28.Feb.92 v1.0 Release of 1st version <hf@pkinbg.uucp> ============================================================================*/long                READ_c(fp, n, chr)  FILE           *fp;  long            n;  char           *chr;{  long            i;  char            c;  while ((c = getc(fp)) != '=');  for (i = 0; i < n; i++)  {    while (((c = getc(fp)) == 32) || (c == 9));    *chr = c;    while ((c = getc(fp)) != '\n');  }  return (n);}/* ....................... End of READ_c() ....................... */

⌨️ 快捷键说明

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