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

📄 ugst-utl.c

📁 ITU-T G.191中包含的G.722语音压缩编解码程序
💻 C
📖 第 1 页 / 共 5 页
字号:
        Parameters:        ~~~~~~~~~~~        n ........... is the number of samples in ix[];        ix .......... is input short array's pointer;        y ........... is output float array's pointer;        mask ........ mask for truncation of the input values                      to the desired resolution:                      0xFFFF: take 16 MSBs                      0xFFFE: take 15 MSBs                      0xFFFC: take 14 MSBs                      0xFFF8: take 13 MSBs                      0xFFF0: take 12 MSBs           Returns value:  none        ~~~~~~~~~~~~~~         Prototype:  in ugst-utl.h        ~~~~~~~~~~         Original authors:        ~~~~~~~~~~~~~~~~~         V1.0 <bloecher@pkinbg.uucp>         History:        ~~~~~~~~        27.Nov.92 v1.0 Version based in sh2fl() v1.1 where output 		       samples are always normalised to -1.0 ... +1.0.		       The input vector is not changed.		       <bloecher@pkinbg.uucp>   --------------------------------------------------------------------------*/ void            sh2fl_alt(n, ix, y, mask)  long            n;  short          *ix, mask;  float          *y;{  register long   k;  register float  factor;  for (k = 0, factor = (1. / 32768.); k < n; k++)    *y++ = factor * ((*ix++) & mask);}              /* ......... end of sh2fl_alt() ......... */ /*  --------------------------------------------------------------------------          void sh2fl (long  n, short *ix, float *y,        ~~~~~~~~~~  long resolution, char norm);         Description:        ~~~~~~~~~~~~         Common conversion routine. The conversion routine expect the        fixed point data to be in the range between -32768..32767.        Conversion to float is done by taking into account only the        most significant bits, which are right-shifted before the        conversion to float using the user-specified `resolution',        and normalized to the range -1..+1 if `norm' is 1.         Parameters:        ~~~~~~~~~~~        n ........... is the number of samples in y[];        ix .......... is input short array's pointer;        y ........... is output float array's pointer;        resolution .. is the resolution (number of bits) desired                      for the input data in the floating point                      representation.        norm ........ flag for normalization:                      1 ... normalize float data to the range -1..+1;                      0 ... only convert from short to float,                            leaving the data in the range:                            -32768>>resolution .. 32767>>resolution.         Returns value:  none        ~~~~~~~~~~~~~~         Prototype:  in ugst-utl.h        ~~~~~~~~~~         Original author:        ~~~~~~~~~~~~~~~~              tdsimao@venus.cpqd.ansp.br         History:        ~~~~~~~~        25.Feb.92 v1.0 Release of 1st version.                       <tdsimao@venus.cpqd.ansp.br>        18.May.92 v1.1 Corrected bug in norm.factor calculation                       <tdsimao@venus.cpqd.ansp.br>        27.Nov.92 v1.2 Corrected bug when left-adjusting to the                        desired resolution <bloecher@pkinbg.uucp>   --------------------------------------------------------------------------*/ void            sh2fl(n, ix, y, resolution, norm)  long            n;  short          *ix;  float          *y;  long            resolution;  char            norm;{  register long   k;  float           factor;   /* Shift of left-adjusted samples to the desired resolution */  if (resolution != 16)  { /* Block been correct as per suggestion from <bloecher@pkinbg.uucp> */    register long tmp;    tmp = 16 - resolution;    for (k = 0; k < n; k++)      ix[k] >>= tmp;  }  /* Factor for normalization */  if (norm)    for (factor = 32768.0, k = 16 - resolution; k > 0; k--)      factor /= 2;   /* Convert all samples */  for (k = 0; k < n; k++)    y[k] = (float) ix[k];   /* Normalize samples, fi requested, to the range -1..+1 */  if (norm)    for (k = 0; k < n; k++)      y[k] /= factor; }                  /* ......... end of sh2fl() ......... */   /* ============================================================================   long serialize_right_justifiedstl92 (short *par_buf,  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~  short *bit_stm, long n, long resol,                                        char sync);         Description:        ~~~~~~~~~~~~         Routine to convert a frame of `n' right-justified samples with a        resolution `resol' into a bitstream of length n*resol. The bit-        stream is a sequence of 16-bit words whose least significant        bits are either EID_ONE or EID_ZERO, depending if the        correspondent bit in the input word was 1 or 0. (Therefore,        the bitstream 16-bit words are always right-justified!)         If a synchronism (SYNC_WORD) word is to be included at frame        boundaries, then the length of the bit stream is increased to        (n+1)*resol.         ----------------------------------------------------------------        NOTE! Be sure that the memory reserved (allocated) for "bit_stm"              is big enough to accomodate all the data:               - with sync word: ...... (n+1)*resol               - without sync word: ...  n*resol        ----------------------------------------------------------------         Please note that the less significant bits of the input word are        serialized first, such that the bitstream is a stream with less        significant bits coming first! (Please see example below).         Example: ADPCM input paralell sequence, in blocks of 256                 samples, for 10 blocks (note that for each frame an                 individual call to this function is needed!):         Input contents:         frame no.:  |   1st          | | 2nd ...| ... | last one  |        sample no.:    1    2 ...  256  257 ...         (last one)        sample:     1011,0101,...,1001 1111 ...          1010         Output:         Word no.:          1   2 3 4 5 6  ...  *       1026  ...     ...        x        +----+-+-+-+-+-+ ... +-+-+-+-+----+-+-+-+-+ ... +-+-+-+-+        |Sync|1|1|0|1|1| ... |1|0|0|1|Sync|1|1|1|1| ... |0|1|0|1|        +----+-+-+-+-+-+ ... +-+-+-+-+----+-+-+-+-+ ... +-+-+-+-+        * = word no.1022        x = word no.10250         Here, the bitstream value `1' is defined by EID_ONE, `0' as        EID_ZERO, and the sync word  by SYNC_WORD:                       Bit '0' is represented as '0x007F'                      Bit '1' is represented as '0x0081'                      SYNC-word is represented as '0x6B21'          Parameters:        ~~~~~~~~~~~        par_buf ... input buffer with right-adjusted samples to be serialized.        bit_stm ... output buffer with bitstream.        n ......... number of words in the input buffer.        resol ..... resolution (number of bits) of the right-adjusted samples                    in par_buf.        sync ...... flag to say whether a sync word is (1) to be used                    (appended) in the boundaries of each frame of the                    bitstream, or (0) not.         Return value:        ~~~~~~~~~~~~~         On success, returns the number of bits of the output bitstream        (including sync word). If the value returned is 0, the number of        converted samples is zero.         Original author:        ~~~~~~~~~~~~~~~~        Simao Ferraz de Campos Neto        CPqD/Telebras        DDS/Pr.11        Rd. Mogi Mirim-Campinas Km.118        13.085 - Campinas - SP (Brazil)         Phone : +55-192-39-6396        FAX   : +55-192-53-4754        EMail : tdsimao@venus.cpqd.ansp.br         History        ~~~~~~~        20.Mar.92 v1.0 1st release to UGST.        18.May.92 v1.1 Initialization in-routine removed.        06.Jun.95 v2.0 Exchanged definition of softbits '1' and '0' for                       compatibitilty with EID module, HW, and Rec.G.192                       <simao@ctd.comsat.com> ============================================================================*/#define EID_ZERO  0x007F#define EID_ONE   0x0081#define SYNC_WORD 0x6B21 long serialize_right_justifiedstl92 (par_buf, bit_stm, n, resol, sync)        short *par_buf, *bit_stm;        long n, resol;        char sync;{  unsigned short tmp, *bs;  long bs_length;  long j,k;  /*  * ......... INITIALIZATIONS .........  */   /* Calculate size of bitstream */  bs_length = n * resol + (sync==1?1:0);  /*  * ......... PROCEEDS NORMAL PROCESSING .........  */   /* initialize unsigned pointer to input (potentially signed) and     output buffers */  bs = (unsigned short *)bit_stm;   /* Put a sync word at beginning of the frame, if requested */    if (sync) *bs++ = SYNC_WORD;   /* Convert every sample in parallel buffer into a bitstream,     including a sync word if requested */  for (j=0; j<n; j++)  {    /* Convert input word to unsigned */    tmp = (unsigned short)par_buf[j];     /* Serialize all sample's bits ... */    for (k=0; k<resol; k++)    {      *bs++ = (tmp&0x0001)?EID_ONE:EID_ZERO;      tmp >>= 1;    }  }  /*  * ......... RETURN bitstream length (include sync word) .........  */    return((long)((short *)bs-bit_stm)); }#undef EID_ONE#undef EID_ZERO#undef SYNC_WORD/* ............... End of serialize_right_justifiedstl92() ............... */   /*============================================================================         long parallelize_right_justifiedstl92 (short *bit_stm, short *par_buf,        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~  long bs_len, long resol, char sync);          Description:        ~~~~~~~~~~~~         Routine to convert a bitstream of length `bs_len' into a frame        of bs_len/resol(*) right-justified samples with a resolution        `resol'. The bitstream is a sequence of 16-bit words whose        least significant bits are either EID_ONE or EID_ZERO, depending        if the correspondent bit in the originating word was 1 or 0        (Therefore, the bitstream 16-bit words are always right-justified!).        Note that the bits that come first are less significant than the        next ones, when referring to a same word. Then, when mounting a        word from the bitstream, bits from the bitstream that comes        first are allocated to lower significant bits (see example        below).               (*)PS: if there are sync words in the bitstream, the                     number of samples per frame is (bs_len-1)/resol.         If a synchronism (SYNC_WORD) word is included at frame        boundaries (parameter sync==1), then sync word is removed from        the bitstream and not copied to the output buffer.         Example: ADPCM input paralell sequence, in blocks of 256                 samples, for 10 blocks (note that for each frame an                 individual call to this function is needed!):         Input contents:         Word no.:          1   2 3 4 5 6  ...  *       1026  ...     ...        x        +----+-+-+-+-+-+ ... +-+-+-+-+----+-+-+-+-+ ... +-+-+-+-+        |Sync|1|1|0|1|1| ... |1|0|0|1|Sync|1|1|1|1| ... |0|1|0|1|        +----+-+-+-+-+-+ ... +-+-+-+-+----+-+-+-+-+ ... +-+-+-+-+        * = word no.1022        x = word no.10250         Output:         frame no.:  |   1st          | | 2nd ...| ... | last one  |        sample no.:    1    2 ...  256  257 ...         (last one)        sample:     1011,0101,...,1001 1111 ...          1010         Here, the bitstream value `1' is defined by EID_ONE, `0' as        EID_ZERO, and the sync word  by SYNC_WORD:                       Bit '0' is represented as '0x007F'                      Bit '1' is represented as '0x0081'                      SYNC-word is represented as '0x6B21'         ----------------------------------------------------------------          NOTE! This routine assumes that memory HAS already been                allocated to BOTH the bit stream bit_stm and to the                parallel samples' buffer par_buf.          ALSO! This routine considers that the first `bit' of the bit-                stream corresponds to the least significant bit of the                original word!        ----------------------------------------------------------------         Parameters:

⌨️ 快捷键说明

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