📄 ugst-utl.c
字号:
~~~~~~~~~~~ bit_stm ... input buffer with bitstream to be parallelized. par_buf ... output buffer with right-adjusted samples. bs_len .... number of bits per frame (ie, size of 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 parallel words converted from the input bitstream (The sync word is removed and not copied to the output buffer). 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. 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 parallelize_right_justifiedstl92 (bit_stm, par_buf, bs_len, resol, sync) short *bit_stm, *par_buf; long bs_len, resol; char sync;{ unsigned short tmp, *bs; long n,j,k; /* * ......... INITIALIZATIONS ......... */ /* Calculate size of bitstream */ n = (bs_len - (sync==1?1:0))/resol; /* * ......... PROCEEDS NORMAL PROCESSING ......... */ /* initialize unsigned pointer to input (potentially signed) and output buffers */ bs = (unsigned short *)bit_stm; /* Convert every sample in parallel buffer into a bitstream, including a sync word if requested */ for (j=0; j<n; j++) { /* Skip sync word if present */ if (*bs == SYNC_WORD) bs++; /* Get 1st bit ... */ tmp = (unsigned short)(*bs++==EID_ONE)?1:0; /* Parallelize all the other bits ... */ for (k=1; k<resol; k++) { tmp += (unsigned short)( ( (*bs++) == EID_ONE ? 1 : 0) << k); } /* Save word as short */ par_buf[j] = (short)tmp; } /* * ......... RETURN ......... */ return((long)n);}#undef EID_ONE#undef EID_ZERO#undef SYNC_WORD/* ............... End of parallelize_right_justifiedstl92() .............. */ /* ============================================================================ long serialize_left_justifiedstl92 (short *par_buf, ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ short *bit_stm, long n, long resol, char sync); Description: ~~~~~~~~~~~~ Routine to convert a frame of `n' left-justified samples with a resolution `resol' into a bitstream of length n*resol. Input data is converted first from left-adjusted to right-adjusted (both in 2's complement), according to the resolution specified, and then converted into a bitstream vector. The bitstream is a sequence of 16-bit words whose least significant bits are either EID_ONE or EID_ZERO (defined below), 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 MOST SIGNIFICANT BITS of the left- justified input word are SERIALIZED FIRST, such that the bitstream is a stream with most significant bits coming first, complementary to the right-justified routines above (see example there). 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 left-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 left-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). 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_left_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,l; /* * ......... 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 samples from left- to right-justified in input buffer */ l = 16-resol; /* 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] >> l); /* 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_left_justifiedstl92() ............... */ /*============================================================================ long parallelize_left_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(*) left-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, as for the right-justified routines above (see example there). Output data is converted from right-adjusted to left-adjusted (both in 2's complement) before returning, according to the resolution specified. (*)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. 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: ~~~~~~~~~~~ bit_stm ... input buffer with bitstream to be parallelized. par_buf ... output buffer with left-adjusted samples. bs_len .... number of bits per frame (ie, size of input buffer). resol ..... resolution (number of bits) of the left-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 parallel words extracted from the input bitstream (The sync word is removed and not copied to the output buffer). 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. 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 parallelize_left_justifiedstl92 (bit_stm, par_buf, bs_len, resol, sync) short *bit_stm, *par_buf; long bs_len, resol; char sync;{ unsigned short tmp, *bs; long n,j,k; /* * ......... INITIALIZATIONS ......... */ /* Calculate size of bitstream */ n = (bs_len - (sync==1?1:0))/resol; /* * ......... PROCEEDS NORMAL PROCESSING ......... */ /* initialize unsigned pointer to input (potentially signed) and output buffers */ bs = (unsigned short *)bit_stm; /* Convert every sample in parallel buffer into a bitstream, including a sync word if requested */ for (j=0; j<n; j++) { /* Skip sync word if present */ if (*bs == SYNC_WORD) bs++;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -