📄 umc_speech_decoder.cpp
字号:
/*//////////////////////////////////////////////////////////////////////////////
//
// INTEL CORPORATION PROPRIETARY INFORMATION
// This software is supplied under the terms of a license agreement or
// nondisclosure agreement with Intel Corporation and may not be copied
// or disclosed except in accordance with the terms of that agreement.
// Copyright(c) 2006 Intel Corporation. All Rights Reserved.
//
*/
#include "umc_speech_decoder.h"
#include "vm_debug.h"
namespace UMC
{
SpeechDecoder::~SpeechDecoder()
{
if (m_pDataBuffer)
ippsFree(m_pDataBuffer);
}
Status SpeechDecoder::PackToSpeechMediaData(MediaData* pData)
{
Ipp8u* pSrc = (Ipp8u*)pData->GetDataPointer();
Ipp8u cHeader = (pSrc[0] << 1) >> 4; // (2,3,4,5) bits are frametype
Ipp32u nSize = 0;
switch(cHeader)
{
case 0: SET_DATA(m_SpeechDataIn, 0, 4750, 12); break;
case 1: SET_DATA(m_SpeechDataIn, 0, 5150, 13); break;
case 2: SET_DATA(m_SpeechDataIn, 0, 5900, 15); break;
case 3: SET_DATA(m_SpeechDataIn, 0, 6700, 17); break;
case 4: SET_DATA(m_SpeechDataIn, 0, 7400, 19); break;
case 5: SET_DATA(m_SpeechDataIn, 0, 7950, 20); break;
case 6: SET_DATA(m_SpeechDataIn, 0, 10200, 26); break;
case 7: SET_DATA(m_SpeechDataIn, 0, 12200, 31); break;
case 8: SET_DATA(m_SpeechDataIn, 1, m_CurrentBitrate, 5); break;
case 15: SET_DATA(m_SpeechDataIn, 1, m_CurrentBitrate, 0); break;
default: vm_debug_trace1(VM_DEBUG_ERROR, VM_STRING("SpeechDecoder::PackToSpeechMediaData: not implemented FT=%d\n"),
cHeader);
return UMC_ERR_NOT_IMPLEMENTED;
}
pSrc += 1; //first byte is header
nSize = m_SpeechDataIn.GetNBytes() + 1; //size of frame
m_CurrentBitrate = m_SpeechDataIn.GetBitrate();
//check if data is correct (size in header is not more, than size of input data)
if (nSize > pData->GetDataSize())
return UMC_ERR_FAILED;
if (!m_pDataBuffer)
{
m_pDataBuffer = ippsMalloc_8u(nSize);
m_SpeechDataIn.SetBufferPointer(m_pDataBuffer, MAX_FRAME_BITS_LEN);
}
//reorder data to be suitable for USC AMR decoder
if((cHeader >= 0) && (cHeader < 8)) {
ReorderActiveFrame(pSrc, (Ipp8u*)m_SpeechDataIn.GetBufferPointer(), nSize - 1, cHeader);
} else if(cHeader == 8){
ReorderSIDFrame(pSrc, (Ipp8u*)m_SpeechDataIn.GetBufferPointer(), nSize - 1, cHeader);
}
//data from input MediaData
m_SpeechDataIn.SetDataSize(pData->GetDataSize());
m_SpeechDataIn.SetTime(pData->GetTime());
return UMC_OK;
};
Status SpeechDecoder::UnpackFromSpeechMediaData(MediaData* pData)
{
Ipp64f dStart = 0, dEnd = 0;
m_SpeechDataOut.GetTime(dStart, dEnd);
pData->SetTime(dStart, dEnd);
pData->SetDataSize(m_SpeechDataOut.GetDataSize());
return UMC_OK;
};
Status SpeechDecoder::GetFrame(MediaData *in, MediaData *out)
{
Status umcRes = UMC_OK;
CHECK_POINTER(in);
CHECK_POINTER(out);
umcRes = PackToSpeechMediaData(in);
CHECK_STATUS(umcRes);
m_SpeechDataOut.SetBufferPointer((Ipp8u*)out->GetBufferPointer(), out->GetBufferSize());
m_SpeechDataOut.SetDataSize(out->GetDataSize());
umcRes = USCDecoder::GetFrame(&m_SpeechDataIn, &m_SpeechDataOut);
CHECK_STATUS(umcRes);
in->MoveDataPointer(m_SpeechDataIn.GetNBytes() + 1);
umcRes = UnpackFromSpeechMediaData(out);
CHECK_STATUS(umcRes);
return UMC_OK;
}
Status SpeechDecoder::Init(BaseCodecParams *init)
{
SpeechCodecParams cSpeechCodecParams;
AudioCodecParams* pAudioCodecParams = DynamicCast<AudioCodecParams, BaseCodecParams>(init);;
CHECK_POINTER(pAudioCodecParams);
cSpeechCodecParams.m_info_in = pAudioCodecParams->m_info_in;
cSpeechCodecParams.m_frame_num = pAudioCodecParams->m_frame_num;
cSpeechCodecParams.m_pData = pAudioCodecParams->m_pData;
cSpeechCodecParams.m_info_out.channels = pAudioCodecParams->m_info_out.channels;
m_CurrentBitrate = 12200;
return USCDecoder::Init(&cSpeechCodecParams);
};
};// namespace UMC
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -