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

📄 eid.c

📁 Reference Implementation of G.711 standard and other voice codecs
💻 C
📖 第 1 页 / 共 5 页
字号:
                       with the EID hardware and Rec.G.192. Code not                       changed <simao@ctd.comsat.com> ============================================================================*/void BER_insertion_stl92(lseg, xbuff,ybuff, EPbuff)    long lseg;    short *xbuff;     short *ybuff;     short *EPbuff;{   long i;   /* FIRST STEP: Copy SYNC-word -> output buffer */    ybuff[0] = xbuff[0];  /* THEN: Process data bits */    /*    for (i=1; i<lseg+1; i++) This was in the STL92, but this is wrong!     */    for (i=1; i<lseg; i++)    {         if (xbuff[i]==(short)0x007F)        {          /* input bit = '0' ('hard bit' = 7F) */          ybuff[i] = (short)(0x00FF) &   EPbuff[i-1];        }      else        {            /* input bit = '1' ('hard bit' = 81) */          ybuff[i] = (short)(0x00FF) & (~EPbuff[i-1] + 1);        }    }}/* ..................... End of BER_insertion_stl92() ..................... */  /*                                                                              ============================================================================         void BER_insertion_stl96 (long lseg, short *xbuff, short *ybuff,         ~~~~~~~~~~~~~~~~~~~~~~~~  short *error_pattern);        Description:        ~~~~~~~~~~~~        Disturbing an input bitstream according stored error        patterns. The input (undisturbed) and output (disturbed)        buffers have samples conforming to the bitstream        representation description in Annex B of G.192. This bitstream        has a synchronism (sync) header at frame boundaries, which        consists of a synchronism (SYNC) word followed by a 16-bit,        2-complement word with the number of softbits in the frame        (i.e., the frame length). The error-pattern does not have the        sync header.        This function is aliased to BER_insertion by default in        eid.h. If the pre-STL96 version is desired, the module needs        to be compiled with the symbol STL92 defined.        ---------------------------------------------------------------                         NOTES on Data Representation:                         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~        Each individual bit is stored in one location of a  short-array,        where in location 0 the SYNC-word is  stored (SYNC-word =        0x6B21, 0x6B22, ... 0x6B2F).  To allow the processing of        'soft-bits' (see separate  ITU-T-paper) in future applications,        the following  definitions have been made:         a) input signal: 'hard' bit '0' must be represented as 0x007F                          'hard' bit '1' must be represented as 0x0081         b) error pattern:         * probability for undisturbed transmission:             0x0001 ... 0x007F       (0x0001: lowest probability that the             or   1 ... 127 dec.      transmission has been indeed undisturbed)        * probability for disturbed transmission:             0x00FF ... 0x0081       (0x00FF: lowest probability that the            or 255 ... 129 dec.      transmission has been really disturbed)        c) output signal computation:         For input '1' (0x0081):           * if error pattern 0x00FF ... 0x0081 (255 ... 129), then                   output = 0x0001 ... 0x007F  (  1 ... 127);          * if error pattern 0x0001 ... 0x007F (  1 ... 127), then                    output = 0x00FF ... 0x0081  (255 ... 129).        For input '0' (0x007F):           * if error pattern 0x00FF ... 0x0081 (255 ... 129), then                    output = 0x00FF ... 0x0081  (255 ... 129);          * if error pattern 0x0001 ... 0x007F (  1 ... 127), then                   output = 0x0001 ... 0x007F  (  1 ... 127).        ---------------------------------------------------------------        Parameters:          ~~~~~~~~~~~        lseg: ..... length of current frame (WITH sync header). This                     has been MODIFIED from the definition in the                    pre-STL96 version of this function. Therefore lseg                    is the number of softbits in the input bitstream                    plus two (to account for the sync word and for the                    length word).        xbuff: .... buffer with input G.192 bitstream (length = "lseg")        ybuff: .... buffer with output G.192 bitstream (length = "lseg")        EPbuff: ... buffer with error pattern (without sync header)                    (length = "lseg-2")         Return value:        ~~~~~~~~~~~~~        None.        Author:        ~~~~~~~        Simao Ferraz de Campos Neto        Comsat Laboratories                  Tel:    +1-301-428-4516        22300 Comsat Drive                   Fax:    +1-301-428-9287        Clarksburg MD 20871 - USA            E-mail: simao@ctd.comsat.com        History:        ~~~~~~~~        07.Mar.96 v1.0 Created based on the STL92 version of this function,                        which did not comply with the bitstream data                       representation in Annex B of G.192.                       <simao@ctd.comsat.com> ============================================================================*/void BER_insertion_stl96(lseg, xbuff,ybuff, EPbuff)    long lseg;    short *xbuff;     short *ybuff;     short *EPbuff;{  register long i;   /* FIRST STEP: Copy sync header to the output buffer */  ybuff[0] = xbuff[0];  ybuff[1] = xbuff[1];  /* THEN: Process data bits */  for (i=2; i<lseg; i++)  {       if (xbuff[i]==(short)0x007F)    {      /* input bit = '0' ('hard bit' = 7F) */      ybuff[i] = (short)(0x00FF) &   EPbuff[i-2];    }    else    {        /* input bit = '1' ('hard bit' = 81) */      ybuff[i] = (short)(0x00FF) & (~EPbuff[i-2] + 1);    }  }}/* ..................... End of BER_insertion_stl96() ..................... */  /*  ============================================================================         double FER_generator_random (SCD_EID *EID);        Description:        ~~~~~~~~~~~~        Implementation of the `Frame Erasure' function:        - computes the 'frame erasure pattern'         Parameters:           ~~~~~~~~~~~         EID: ..... pointer to EID struct.        Return value:        ~~~~~~~~~~~~~        Returns (double)1 if the current frame has been erased, and        (double)0 otherwise.         Author: <hf@pkinbg.uucp>        ~~~~~~~	Modified by G. Schroeder         History:        ~~~~~~~~        28.Feb.92 v1.0 Release of 1st version <hf@pkinbg.uucp> ============================================================================ */double FER_generator_random(EID)SCD_EID *EID; {   long n;                        /* value of random generator */   double RAN,fer;    /* Get next random number */   RAN = EID_random(&(EID->seed));    /* See if another channel state has to be entered */   for (n=0; n<EID->nstates; n++)   {     if (RAN < EID->matrix[EID->current_state][n])     {       EID->current_state = n; /* go to the selected state */       n = EID->nstates;       /* -> aborts loop */     }   } /*   * ......... Compute bit error in current state .........   */   /* Get next random number */   RAN = EID_random(&(EID->seed));    /* if random number below the threshold (bit error rate in current state),       erase current frame totally */   if (RAN < EID->ber[EID->current_state])   {     fer = 1.0;   }   else   {     fer = 0.0;   }  /* Return the frame erasure flag */    return(fer);}/* ....................... End of FER_generator_random() ................. *//*  ============================================================================         double FER_module_stl92 (SCD_EID *EID, long lseg, short *xbuff,         ~~~~~~~~~~~~~~~~~~~~~~~  short *ybuff);        Description:        ~~~~~~~~~~~~        Implementation of the `Frame Erasure' function:        - computes the 'frame erasure pattern'         - erases all bits in one frame according the current           state of the pattern generator.         The input buffer contains 'lseg' words, containing the data bits,        preceeded by a SYNC-word.  If the frame should be erased (depending         on the frame  erasure pattern), all bits are set to 0x0000.        Since a '0' is represented by 0x7F and a '1' is  represented         by 0x81, this corresponds to a total uncertainty about the true bit        values.         In addition the lower 4 bits of the SYNC-word in the sync        header are set to '0'. This makes it easier for the        succeeding software to detect an erased frame.        Parameters:           ~~~~~~~~~~~         EID: ..... pointer to EID struct.        lseg: .... length of current frame (including SYNC-word).        xbuff: ... buffer with input bit stream xbuff[0](= SYNC-word) is                   not processed.        ybuff: ... buffer with output bit stream         Return value:        ~~~~~~~~~~~~~        Returns (double)1 if the current frame has been erased, and        (double)0 otherwise.         Author: <hf@pkinbg.uucp>        ~~~~~~~        History:        ~~~~~~~~        28.Feb.92 v1.0 Release of 1st version <hf@pkinbg.uucp>        06.Jun.95 v1.1 Changed self-documentation to align the EID module                        with the EID hardware and Rec.G.192. Code not                       changed <simao@ctd.comsat.com> ============================================================================ */double FER_module_stl92(EID, lseg,xbuff,ybuff)SCD_EID *EID; long  lseg; short *xbuff; short *ybuff; {   long i,n;                        /* value of random generator */   double RAN,fer;         /* Get next random number */        RAN = EID_random(&(EID->seed));         /* See if another channel state has to be entered */        for (n=0; n<EID->nstates; n++)        {            if (RAN < EID->matrix[EID->current_state][n])            {                EID->current_state = n; /* go to the selected state */                n = EID->nstates;       /* -> aborts loop */            }        } /*   * ......... Compute bit error in current state .........   */        /* Get next random number */        RAN = EID_random(&(EID->seed));         /* if random number below the threshold (bit error rate in current state),            erase current frame totally */        if (RAN < EID->ber[EID->current_state])        {            ybuff[0] = xbuff[0] & 0x0000FFF0; /* modify SYNC-word */            /* set all bits in current frame to 0 (which means 'not good -                not bad') */            for (i=1; i<lseg; i++) ybuff[i] = (short)0;                fer = 1.0;        }        else        {        /* otherwise copy current frame into output buffer */            ybuff[0] = xbuff[0];        /* store SYNC-word */            for (i=1; i<lseg; i++)      /* store data */                ybuff[i] = (short)(0x00FF) & (xbuff[i]);            fer = 0.0;        }  /* Return the frame erasure flag */    return(fer);}/* ....................... End of FER_module_stl92() ....................... */ /*  ============================================================================         double FER_module_stl96 (SCD_EID *EID, long lseg, short *xbuff,         ~~~~~~~~~~~~~~~~~~~~~~~  short *ybuff);        Description:        ~~~~~~~~~~~~        Implementation of the `Frame Erasure' function:        - computes the 'frame erasure pattern'         - erases all bits in one frame according the current           state of the pattern generator.         The input (undisturbed) and output (disturbed)        buffers have samples conforming to the bitstream        representation description in Annex B of G.192. This bitstream        has a synchronism (sync) header at frame boundaries, which        consists of a synchronism (SYNC) word followed by a 16-bit,        2-complement word with the number of softbits in the frame        (i.e., the frame length). Should the frame be erased (depending         on the frame  erasure pattern), all softbits are set to 0x0000.        Since a '0' is represented by 0x7F and a '1' is  represented         by 0x81, this corresponds to a total uncertainty about the true bit        values.         In addition the lower 4 bits of the SYNC-word in the sync        header are set to '0'. This makes it easier for the succeeding        software to detect an erased frame. The frame length word is        copied unmodified to the output buffer.        This function is aliased to FER_module by default in        eid.h. If the pre-STL96 version is desired, the module needs        to be compiled with the symbol STL92 defined.        Parameters:           ~~~~~~~~~~~         EID: ..... pointer to EID struct.        lseg: .... length of current frame (including SYNC header).

⌨️ 快捷键说明

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