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

📄 eid_io.c

📁 Reference Implementation of G.711 standard and other voice codecs
💻 C
📖 第 1 页 / 共 2 页
字号:
/*                                                       V.2.01 - 13.Jan.99  =========================================================================   EID_IO.C   ~~~~~~~~   Routines for performing the EID-state I/O - used by the demo   program eid8k.c, gen-patt.c, and eid-xor.c    ORIGINAL AUTHOR:   ~~~~~~~~~~~~~~~~   Gerhard Schroeder   Deutsche Bundespost TELEKOM    Tel +49 6151 833973     Postfach 100003                FAX +49 6151 895234   64276 Darmstadt                Email: gerhard.schroeder@ties.itu.ch   Germany    HISTORY:   ~~~~~~~~   29.Jul.93 v1.0  Created <gerhard.schroeder@ties.itu.ch>   19.Apr.94 v1.1  Functions recall_burst_eid_from_file() and                   save_burst_eid_to_file() had the local variable state_ptr		   changed to pointer.   15.Aug.97 v2.0  - Added magic number to save/recall eid (random/burst)                     state functions; 		   - Added functions to save bitstreams in different                     formats <simao.campos@comsat.com>   13.Jan.98 v2.01 Clarified ambigous syntax in save_EID_to_file() <simao>  =========================================================================*//*****  INCLUDE FILES***/#include <stdio.h>#include <string.h>#include <stdlib.h>#include <ctype.h>#include "ugstdemo.h"#include "eid.h"#include "eid_io.h"#define MAGIC_EID "EID"#define MAGIC_BURST 0x42464552 /* Long int encoding for ASCII string "BFER" *//*  ===========================================================================  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  A magic number is saved to prevent that other EID modes read this  state variable file as valid.  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  and 0 if failed (couldn't create or write to the file).  Author: <hf@pkinbg.uucp>  ~~~~~~~  History:  ~~~~~~~~  28.Feb.92 v1.0 Release of 1st version <hf@pkinbg.uucp>  14.Aug.97 v1.1 Added magic number <simao.campos@comsat.com>  ===========================================================================*/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);    }  /* Save EID magic number into state variable file */  fprintf(EIDfileptr, "%s\n", MAGIC_EID);  /* 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 *recall_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 all the ones tested.  A magic number prevents that state variable files saved by other  modes of the EID be read. If a magic number is not found, the  function returns as having failed.  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 (couldn't find the file, or the file did not have  a valid magic number, or could not allocate memory for the state  variable).  Author: <hf@pkinbg.uucp>  ~~~~~~~  History:  ~~~~~~~~  28.Feb.92 v1.0 Release of 1st version <hf@pkinbg.uucp>  14.Aug.97 v1.1 Added magic number <simao.campos@comsat.com> ============================================================================*/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;  char            magic[8];  /* Open ASCII file with EID states */  if ((EIDfileptr = fopen(EIDfile, RT)) == NULL)    return ((SCD_EID *) 0);  /* Look for EID magic number into state variable file */  /* If the magic number is not found, returns a NULL pointer */  fgets(magic, 5, EIDfileptr);  if (strncmp(magic, MAGIC_EID, strlen(MAGIC_EID)))    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'))    {

⌨️ 快捷键说明

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