?? g711codec.cpp
字號(hào):
// 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;
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -