Hi @ all,
I capture speech from Microphone with DirectSound in a circular buffer with 48000hz and 16bit.
My intention is to downsample it to 8kHz then encode it into uLaw and least send it about RTP Session.
After Capturing i filter all noises out which lies between 200 and 1500 to reduce the network performance and just send speech.
Then i will downsample to 8kHz with weighted average:
int CAudioOut::Reduce48to8kHz(short* pBuffer, int nBytesToReduce)
{
ASSERT((nBytesToReduce % 6) == 0);
short* pSrc = pBuffer;
short* pDst = pBuffer;
for(int i = 0; i < (nBytesToReduce / 6); i++)
{
long val = 0;
val = *pSrc++;
val += (long)*pSrc++ * 4;
val += (long)*pSrc++ * 14;
val += (long)*pSrc++ * 14;
val += (long)*pSrc++ *4;
val += *pSrc++;
*pDst++ = (short)(val/38);
}
return (pDst - pBuffer);
}
pBuffer is 20ms of raw data with 48000Hz and 16bit
Then I do encode the result buffer to uLaw
unsigned char CG711::encodeULaw(short pcm_val)
{
static int exp_lut[256] = {0,0,1,1,2,2,2,2,3,3,3,3,3,3,3,3,
4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,
5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7};
int sign, exponent, mantissa;
unsigned char ulawbyte;
sign = (pcm_val >> 8) & 0x80;
if (sign != 0) pcm_val = -pcm_val;
if (pcm_val > CLIP) pcm_val = CLIP;
pcm_val = pcm_val + BIAS;
exponent = exp_lut[(pcm_val >> 7) & 0xFF];
mantissa = (pcm_val >> (exponent + 3)) & 0x0F;
ulawbyte = ~(sign | (exponent << 4) | mantissa);
#ifdef ZEROTRAP
if (ulawbyte == 0) ulawbyte = 0x02;
#endif
return(ulawbyte);
}
for(int i = 0; i < size2; i++)
newPacket.m_payload[i] = g711.encodeULaw(downsampledAudio[i]);
The resulting sound is satisfying but not good enough.
There is a regularly clicking noise if the packet reaches the receiver.
I don´t know why this clicking noise is there. I don´t find my mistake that I make.
Hope for help here and be thankful in forward.
greetings
Crazy
|