视频监控行业G711编解码[续]编码样例

//G711 PCMA解码
bool G711A_AudioDecode(unsigned char*pFrameBuf, unsigned int nFrameSize, unsigned char* pOutput, unsigned int& nOutLen)
{
	if(nFrameSize <= 0 || !pFrameBuf)
		return false;

	unsigned int out_size = (nFrameSize << 1);

	for(int i=0, nOffset=0; i<nFrameSize; i++)
	{
		int iLinear = alaw2linear(pFrameBuf[i]);
		memcpy(pOutput + nOffset, &iLinear, 2);
		nOffset += 2;
	}
	nOutLen = out_size;
	
	return true;
}

//G711 PCMU解码
bool G711U_AudioDecode(unsigned char*pFrameBuf, unsigned int nFrameSize, unsigned char* pOutput, unsigned int& nOutLen)
{
	if(nFrameSize <= 0 || !pFrameBuf)
		return false;

	unsigned int out_size = (nFrameSize << 1);

	for(int i=0, nOffset=0; i<nFrameSize; i++)
	{
		int iLinear = ulaw2linear(pFrameBuf[i]);
		memcpy(pOutput + nOffset, &iLinear, 2);
		nOffset += 2;
	}
	nOutLen = out_size;

	return true;
}

//G711 PCMA编码
bool G711A_AudioEncode(unsigned char* pInput, unsigned int nInLen, unsigned char* pOutput, unsigned int& nOutLen)
{
	if(!pInput || !pOutput || nInLen <= 0)
		return false;

	unsigned int out_size = (nInLen >> 1);
	uint8_t* pout_data = pOutput;
	int16_t* pin_data = (int16_t*)pInput;

	for(int i=0; i<out_size; i++)
	{
		pout_data[i] = linear2alaw(pin_data[i]);
	}

	nOutLen = out_size;
	return true;
}

//G711 PCMU编码
bool G711U_AudioEncode(unsigned char* pInput, unsigned int nInLen, unsigned char* pOutput, unsigned int& nOutLen)
{
	if(!pInput || !pOutput || nInLen <= 0)
		return false;

	unsigned int out_size = (nInLen >> 1);
	uint8_t* pout_data = pOutput;
	int16_t* pin_data = (int16_t*)pInput;

	for(int i=0; i<out_size; i++)
	{
		pout_data[i] = linear2ulaw(pin_data[i]);
	}

	nOutLen = out_size;
	return true;
}


你可能感兴趣的:(PCMU,编码样例,PCMA)