audiocodec.cpp
来自「一个VC实现的,用G.729a实现的语言对讲的例子」· C++ 代码 · 共 67 行
CPP
67 行
// AudioCodec.cpp: implementation of the CAudioCodec class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "RemoteTalk.h"
#include "AudioCodec.h"
#include "AudioIOMsgr.h"
#include "include\\g729a.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CAudioCodec::CAudioCodec()
{
va_g729a_init_encoder();
va_g729a_init_decoder();
}
CAudioCodec::~CAudioCodec()
{
}
//压缩音频帧
BOOL CAudioCodec::EncodeAudioData(char *pin, int len, char *pout, int *lenr)
{
if(!pin||len!=SIZE_AUDIO_FRAME||!pout)return FALSE;
va_g729a_encoder((short*)pin,(BYTE*)pout);
va_g729a_encoder((short*)(pin+160),(BYTE*)pout+10);
va_g729a_encoder((short*)(pin+320),(BYTE*)pout+20);
va_g729a_encoder((short*)(pin+480),(BYTE*)pout+30);
va_g729a_encoder((short*)(pin+640),(BYTE*)pout+40);
va_g729a_encoder((short*)(pin+800),(BYTE*)pout+50);
if(lenr) *lenr=SIZE_AUDIO_PACKED;
return TRUE;
}
//解压缩音频帧
BOOL CAudioCodec::DecodeAudioData(char *pin, int len, char *pout, int *lenr)
{
if(!pin||len!=SIZE_AUDIO_PACKED||!pout)return FALSE;
va_g729a_decoder((BYTE*)pin,(short*)(pout),0);
va_g729a_decoder((BYTE*)pin+10,(short*)(pout+160),0);
va_g729a_decoder((BYTE*)pin+20,(short*)(pout+320),0);
va_g729a_decoder((BYTE*)pin+30,(short*)(pout+480),0);
va_g729a_decoder((BYTE*)pin+40,(short*)(pout+640),0);
va_g729a_decoder((BYTE*)pin+50,(short*)(pout+800),0);
if(lenr)*lenr=SIZE_AUDIO_FRAME;
return TRUE;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?