www.pudn.com > IP_phone.rar > Compress.cpp
/**********************************************************/
/*类名:CCompress */
/*简述:分装G.729压缩接口 */
/**********************************************************/
// Compress.cpp: implementation of the CCompress class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "../NC_Client.h"
#include "Compress.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
extern "C" void va_g729a_init_encoder();
extern "C" void va_g729a_encoder(short *speech, unsigned char *bitstream);
extern "C" void va_g729a_init_decoder();
extern "C" void va_g729a_decoder(unsigned char *bitstream, short *synth_short, int bfi);
#define L_FRAME_COMPRESSED 10
#define L_FRAME 80
#pragma comment(lib,"G729a")
CCompress::CCompress()
{
va_g729a_init_encoder();
va_g729a_init_decoder();
}
CCompress::~CCompress()
{
}
///////////////////////////////////////////////////////////////////////////////
//压缩
BOOL CCompress::CompressAudioData(char *pin,int len,char* pout,int* lenr)
{
if(!pin||len!=SIZE_AUDIO_FRAME||!pout)
return false;
//分为6块压缩
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/*60*/;
return true;
}
///////////////////////////////////////////////////////////////////////////////
//解压
BOOL CCompress::DeCompressAudioData(char *pin,int len,char* pout,int* lenr)
{
if(!pin||len!=SIZE_AUDIO_PACKED||!pout)
return false;
//分为6块解压
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/*60*/;
return true;
}
///////////////////////////////////////////////////////////////////////////////