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

📄 g711codec.cpp

📁 g711、VAD的激活算法
💻 CPP
字号:
// G711Codec.cpp: implementation of the G711Codec class.
//
//////////////////////////////////////////////////////////////////////

#include "G711Codec.h"
#include "G711Table.h"

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

G711Codec::G711Codec()
{
	SetULaw();
}

G711Codec::~G711Codec()
{

}

int
G711Codec::Encode(void *input, int inputSizeBytes, void *output, int *outputSizeBytes)
{
	char *dataIn = (char *)input;
	char *dataOut = (char *)output;

	if (*outputSizeBytes < inputSizeBytes/2)
	{
		*outputSizeBytes = 0;
		return -10;
	}
	else 
	{
		unsigned char *compTable;
		if (GetCodecType() == CODECTYPE_ULAW)
		{
			compTable = ulaw_comp_table;
		}
		else
		{
			compTable = alaw_comp_table;
		}
		// convert the sample
		for (int i=0; i<inputSizeBytes; i+=2) {
			short input = *((short *)(dataIn + i));
			dataOut[i/2] = compTable[(input / 4) & 0x3fff];
		}
		*outputSizeBytes = inputSizeBytes / 2;
	}
	return 0;
}

int
G711Codec::Decode(void *input, int inputSizeBytes, void *output, int *outputSizeBytes)
{
	unsigned char  *dataIn = (unsigned char *)input;
	short *dataOut = (short *)output;

	if (inputSizeBytes*2 > *outputSizeBytes) 
	{
		*outputSizeBytes = 0;
		return -10;
	}
	else 
	{
		short *expTable;
		if (GetCodecType() == CODECTYPE_ULAW)
		{
			expTable = ulaw_exp_table;
		}
		else
		{
			expTable = alaw_exp_table;
		}
		// convert the sample
		for (int i=0; i<inputSizeBytes; i++)
		{
			dataOut[i] = expTable[dataIn[i]];
		}
		*outputSizeBytes = inputSizeBytes * 2;
	}
	return 0;
}

⌨️ 快捷键说明

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