📄 pcm2g711transformer.cxx
字号:
// PCM2G711Transformer.cpp: implementation of the PCM2G711Transformer class.
//
//////////////////////////////////////////////////////////////////////
#include <stdio.h>
#include "PCM2G711Transformer.h"
#include "AudioSampleManager.h"
#include "AudioSample.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
PCM2G711Transformer::PCM2G711Transformer()
{
char subFacilityName[100];
sprintf(subFacilityName, "PCM2G711Transformer:%x", this);
tracer.SetSubFacilityName(subFacilityName);
SetTraceLevel();
}
PCM2G711Transformer::~PCM2G711Transformer()
{
}
int
PCM2G711Transformer::SetTraceLevel()
{
#ifdef WIN32
long SystemMask = 0;
if ((SystemMask = GetRegKeyLong(HKEY_CURRENT_USER, "Software\\Cisco Systems\\MTC\\Tracing", "AllComponents", 0x0)) == 0)
{
SystemMask = GetRegKeyLong(HKEY_CURRENT_USER, "Software\\Cisco Systems\\MTC\\Tracing", "PCM2G711Transformer", 0x100000);
}
#endif
return 0;
}
int
PCM2G711Transformer::SetALaw()
{
g711Codec.SetALaw();
return 0;
}
int
PCM2G711Transformer::SetULaw()
{
g711Codec.SetULaw();
return 0;
}
int
PCM2G711Transformer::TransformAudioSamples(std::vector<std::pair<AudioSample *, AudioSource *> > &data, AudioSample **ppAudioSample)
{
if(data.size() == 0) return 0;
AudioSample *inSample = data[0].first;
AudioSample *outSample;
int result = 0;
result = AudioSampleManager::GetInstance()->GetAudioSample(&outSample);
if (outSample)
{
*ppAudioSample = outSample;
if (g711Codec.GetCodecType() == CODECTYPE_ULAW)
{
WAVEFORMATEX wfmx = WaveFormat::GetWaveFormat(WaveFormat_ULaw);
outSample->SetFormat(wfmx);
}
else
{
WAVEFORMATEX wfmx = WaveFormat::GetWaveFormat(WaveFormat_ALaw);
outSample->SetFormat(wfmx);
}
if (inSample->DataSize() <= 0)
{
outSample->SetSilenceDuration(inSample->GetSilenceDuration());
}
else
{
int outputSize = outSample->BufferSize();
result = g711Codec.Encode(inSample->Data(), inSample->DataSize(), outSample->Data(), &outputSize);
outSample->SetDataSize(outputSize);
}
}
else
{
result = -10;
}
return result;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -