📄 dtxgsmamr.c
字号:
/*/////////////////////////////////////////////////////////////////////////////
//
// 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) 2005-2007 Intel Corporation. All Rights Reserved.
//
// Intel(R) Integrated Performance Primitives
// USC - Unified Speech Codec interface library
//
// By downloading and installing USC codec, you hereby agree that the
// accompanying Materials are being provided to you under the terms and
// conditions of the End User License Agreement for the Intel(R) Integrated
// Performance Primitives product previously accepted by you. Please refer
// to the file ippEULA.rtf or ippEULA.txt located in the root directory of your Intel(R) IPP
// product installation for more information.
//
// A speech coding standards promoted by ITU, ETSI, 3GPP and other
// organizations. Implementations of these standards, or the standard enabled
// platforms may require licenses from various entities, including
// Intel Corporation.
//
//
// Purpose: GSMAMR speech codec: DTX utilities.
//
*/
#include "owngsmamr.h"
#define NB_PULSE 10 /* number of random pulses in DTX operation */
/***************************************************************************
* Function : ownDecSidSyncReset_GSMAMR
***************************************************************************/
Ipp32s ownDecSidSyncReset_GSMAMR(sDTXDecoderSt *dtxState)
{
dtxState->vSinceLastSid = 0;
dtxState->vDTXHangCount = DTX_HANG_PERIOD;
dtxState->vExpireCount = 32767;
dtxState->vDataUpdated = 0;
return 0;
}
enum enDTXStateType ownDecSidSync(sDTXDecoderSt *dtxState, RXFrameType frame_type)
{
enum enDTXStateType newState;
Ipp32s d_dtxHangoverAdded=0;
/* set DTX state to: SPEECH, DTX or DTX_MUTE */
if ((frame_type == RX_SID_FIRST) ||
(frame_type == RX_SID_UPDATE) ||
(frame_type == RX_SID_BAD) ||
(((dtxState->eDTXPrevState == DTX) ||
(dtxState->eDTXPrevState == DTX_MUTE)) &&
((frame_type == RX_NO_DATA) ||
(frame_type == RX_SPEECH_BAD) ||
(frame_type == RX_ONSET))))
{
newState = DTX;
dtxState->vSinceLastSid++;
if ((dtxState->eDTXPrevState == DTX_MUTE) &&
((frame_type == RX_SID_BAD) ||
(frame_type == RX_SID_FIRST) ||
(frame_type == RX_ONSET) ||
(frame_type == RX_NO_DATA)))
{
newState = DTX_MUTE;
}
if( (frame_type != RX_SID_UPDATE) && (dtxState->vSinceLastSid > DTX_MAX_EMPTY_THRESH) ) {
/* DTX_MUTE threshold exceeded*/
newState = DTX_MUTE;
dtxState->vSinceLastSid = 0;
}
} else {
newState = SPEECH;
dtxState->vSinceLastSid = 0;
}
if((dtxState->vDataUpdated == 0) && (frame_type == RX_SID_UPDATE))
dtxState->vExpireCount = 0;
if (dtxState->vExpireCount != 32767) dtxState->vExpireCount++;
if ((frame_type == RX_SPEECH_GOOD) ||
(frame_type == RX_SPEECH_DEGRADED) ||
(frame_type == RX_SPEECH_BAD) ||
((frame_type == RX_NO_DATA) && (newState == SPEECH)) /*REL-4 Version 4.1.0 */
)
{
dtxState->vDTXHangCount = DTX_HANG_PERIOD;
} else {
if (dtxState->vExpireCount > DTX_ELAPSED_FRAMES_THRESH) {
d_dtxHangoverAdded = 1;
dtxState->vExpireCount = 0;
dtxState->vDTXHangCount = 0;
} else if (dtxState->vDTXHangCount == 0) {
dtxState->vExpireCount = 0;
} else {
dtxState->vDTXHangCount--;
}
}
if (newState != SPEECH) {
/* DTX or DTX_MUTE */
if (frame_type == RX_SID_FIRST) {
dtxState->vSinceLastSid = 0;
if(d_dtxHangoverAdded != 0)
dtxState->vDataUpdated = 1;
} else if (frame_type == RX_SID_UPDATE) {
dtxState->vSinceLastSid = 0;
dtxState->vDataUpdated = 1;
} else if (frame_type == RX_SID_BAD) {
dtxState->vSinceLastSid = 0;
}
}
if(frame_type == RX_NO_DATA)
newState = DTX_NODATA;
return newState;
/* newState is used by both SPEECH AND DTX synthesis routines */
}
/*************************************************************************
* Function: ownGenNoise_GSMAMR
*************************************************************************/
Ipp16s ownGenNoise_GSMAMR (Ipp32s *pShiftReg, Ipp16s numBits)
{
Ipp16s noise_bits, State, i;
noise_bits = 0;
for (i = 0; i < numBits; i++) {
/* State n == 31 */
if ((*pShiftReg & 0x00000001) != 0) State = 1;
else State = 0;
/* State n == 3 */
if ((*pShiftReg & 0x10000000) != 0) State = (Ipp16s)(State ^ 1);
else State = (Ipp16s)(State ^ 0);
noise_bits <<= 1;
noise_bits = (Ipp16s)(noise_bits | ((Ipp16s)*pShiftReg & 1));
*pShiftReg = *pShiftReg >> 1;
if(State & 1) *pShiftReg = *pShiftReg | 0x40000000;
}
return noise_bits;
}
/***************************************************************************
* Function : ownBuildCNCode_GSMAMR
***************************************************************************/
void ownBuildCNCode_GSMAMR (Ipp32s *seed, Ipp16s *pCNVec)
{
Ipp16s i, j, k;
ippsZero_16s(pCNVec, SUBFR_SIZE_GSMAMR);
for (k = 0; k < NB_PULSE; k++) {
i = ownGenNoise_GSMAMR(seed, 2); /* generate pulse position */
i = (Ipp16s)(i * 10 + k);
j = ownGenNoise_GSMAMR(seed, 1); /* generate sign */
if (j > 0) pCNVec[i] = 4096;
else pCNVec[i] = -4096;
}
return;
}
/*************************************************************************
* Function: ownBuildCNParam_GSMAMR
*************************************************************************/
void ownBuildCNParam_GSMAMR(Ipp16s *seed, const Ipp16s numParam, const Ipp16s *pTableSizeParam,
Ipp16s *pCNParam)
{
Ipp16s i;
const Ipp16s *ptr_wnd;
*seed = (Ipp16s)(*seed * 31821 + 13849L);
ptr_wnd = &TableHammingWindow[*seed & 0x7F];
for(i=0; i< numParam;i++){
pCNParam[i] = (Ipp16s)(*ptr_wnd++ & ~(0xFFFF<<pTableSizeParam[i]));
}
}
/*************************************************************************
* Function: ownDecLSPQuantDTX_GSMAMR()
*************************************************************************/
void ownDecLSPQuantDTX_GSMAMR(Ipp16s *a_PastQntPredErr, Ipp16s *a_PastLSFQnt, Ipp16s BadFrInd,
Ipp16s *indice, Ipp16s *lsp1_q)
{
Ipp16s i, index;
Ipp16s *p_dico, temp;
IPP_ALIGNED_ARRAY(16, Ipp16s, lsf1_r, LP_ORDER_SIZE);
IPP_ALIGNED_ARRAY(16, Ipp16s, lsf1_q, LP_ORDER_SIZE);
if (BadFrInd != 0) { /* if bad frame */
for(i = 0; i < LP_ORDER_SIZE; i++)
lsf1_q[i] = (Ipp16s)(((a_PastLSFQnt[i] * ALPHA_09) >> 15) + ((TableMeanLSF_3[i] * ONE_ALPHA) >> 15));
for (i = 0; i < LP_ORDER_SIZE; i++) {
temp = (Ipp16s)(TableMeanLSF_3[i] + a_PastQntPredErr[i]);
a_PastQntPredErr[i] = (Ipp16s)(lsf1_q[i] - temp);
}
} else {
/* MR59, MR67, MR74, MR102, MRDTX */
index = *indice++;
p_dico = &TableDecCode1LSF_3[3*index];
lsf1_r[0] = *p_dico++;
lsf1_r[1] = *p_dico++;
lsf1_r[2] = *p_dico++;
index = *indice++;
p_dico = &TableDecCode2LSF_3[3*index];
lsf1_r[3] = *p_dico++;
lsf1_r[4] = *p_dico++;
lsf1_r[5] = *p_dico++;
index = *indice++;
p_dico = &TableDecCode3LSF_3[index << 2];
lsf1_r[6] = *p_dico++;
lsf1_r[7] = *p_dico++;
lsf1_r[8] = *p_dico++;
lsf1_r[9] = *p_dico++;
for (i = 0; i < LP_ORDER_SIZE; i++) {
temp = (Ipp16s)(TableMeanLSF_3[i] + a_PastQntPredErr[i]);
lsf1_q[i] = (Ipp16s)(lsf1_r[i] + temp);
a_PastQntPredErr[i] = lsf1_r[i];
}
}
ownReorderLSFVec_GSMAMR(lsf1_q, LSF_GAP, LP_ORDER_SIZE);
ippsCopy_16s(lsf1_q, a_PastLSFQnt, LP_ORDER_SIZE);
ippsLSFToLSP_GSMAMR_16s(lsf1_q, lsp1_q);
return;
}
static __ALIGN32 CONST Ipp16s lsf_hist_mean_scale[LP_ORDER_SIZE] = {
20000, 20000, 20000, 20000, 20000, 18000, 16384, 8192, 0, 0
};
static __ALIGN32 CONST Ipp16s dtx_log_en_adjust[9] =
{
/* MR475 MR515 MR59 MR67 MR74 MR795 MR102 MR122 MRDTX */
-1023, -878, -732, -586, -440, -294, -148, 0, 0
};
/***************************************************************************
* Function : ownDTXDecoder_GSMAMR
***************************************************************************/
Ipp32s ownDTXDecoder_GSMAMR(sDTXDecoderSt *dtxState, Ipp16s *a_MemorySyn, Ipp16s *a_PastQntPredErr,
Ipp16s *a_PastLSFQnt, Ipp16s *a_PastQntEnergy, Ipp16s *a_PastQntEnergy_M122,
Ipp16s *vHgAverageVar, Ipp16s *vHgAverageCount, enum enDTXStateType newState,
GSMAMR_Rate_t rate, Ipp16s *pParmVec, Ipp16s *pSynthSpeechVec, Ipp16s *pA_LP)
{
Ipp16s logEnergyIdx;
Ipp16s i, j;
Ipp16s int_fac;
Ipp32s logEnergy_long;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -