?? g711.c
字號:
/*#include "typedef.h"*/
#include "g711.h"
/*
FUNCTIONS:
alaw_compress: ... compands 1 vector of linear PCM samples to A-law;
uses 13 Most Sig.Bits (MSBs) from input and 8 Least
Sig. Bits (LSBs) on output.
alaw_expand: ..... expands 1 vector of A-law samples to linear PCM;
use 8 Least Sig. Bits (LSBs) from input and
13 Most Sig.Bits (MSBs) on output.
*/
/* ................... Begin of alaw_compress() ..................... */
/*
==========================================================================
FUNCTION NAME: alaw_compress
DESCRIPTION: ALaw encoding rule according CCITT Rec. G.711.
PROTOTYPE: void alaw_compress(long lseg, short *linbuf, short *logbuf)
PARAMETERS:
lseg: (In) number of samples
linbuf: (In) buffer with linear samples (only 12 MSBits are taken
into account)
logbuf: (Out) buffer with compressed samples (8 bit right justified,
without sign extension)
RETURN VALUE: none.
==========================================================================
*/
void alaw_compress(
Word16 *linbuf,
Word16 *logbuf,
Word16 lseg
)
{
Word16 ix, iexp ;
Word16 n ;
for ( n = 0 ; n < lseg ; n ++ )
{
ix = linbuf[n] < 0 ? (~linbuf[n]) >> 4 : (linbuf[n]) >> 4;
/* 0 <= ix < 2048 */
/* 1's complement for negative values */
if (ix > 15)
{
iexp = 1; /* first step: */
while (ix > 16 + 15) /* find mantissa and exponent */
{
ix >>= 1;
iexp++;
}
ix -= 16; /* second step: remove leading '1' */
ix += iexp << 4; /* now compute encoded value */
}
if (linbuf[n] >= 0)
ix |= (0x0080); /* add sign bit */
logbuf[n] = ix ; /* toggle even bits */
}
return ;
}
/*
FUNCTION NAME: alaw_expand
DESCRIPTION: ALaw decoding rule according CCITT Rec. G.711.
PROTOTYPE: void alaw_expand(long lseg, short *logbuf, short *linbuf)
PARAMETERS:
lseg: (In) number of samples
logbuf: (In) buffer with compressed samples (8 bit right justified,
without sign extension)
linbuf: (Out) buffer with linear samples (13 bits left justified)
RETURN VALUE: none.
*/
void alaw_expand(
Word16 *linbuf,
Word16 *logbuf,
Word16 lseg
)
{
Word16 ix, mant, iexp;
Word16 n;
for (n = 0; n < lseg; n++)
{
ix = logbuf[n] ; /* re-toggle toggled bits */
ix &= (0x007F); /* remove sign bit */
iexp = ix >> 4; /* extract exponent */
mant = ix & (0x000F); /* now get mantissa */
if (iexp > 0)
mant = mant + 16; /* add leading '1', if exponent > 0 */
mant = (mant << 4) + (0x0008); /* now mantissa left justified and */
/* 1/2 quantization step added */
if (iexp > 1) /* now left shift according exponent */
mant = mant << (iexp - 1);
linbuf[n] = logbuf[n] > 127 ? mant : -mant;/* invert, if negative sample */
}
return ;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -