📄 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 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 ipplic.htm 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
***************************************************************************/
int 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;
int 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
*************************************************************************/
short ownGenNoise_GSMAMR (int *pShiftReg, short numBits)
{
short 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 = State ^ 1;
else State = State ^ 0;
noise_bits <<= 1;
noise_bits = noise_bits | ((short)*pShiftReg & 1);
*pShiftReg = *pShiftReg >> 1;
if(State & 1) *pShiftReg = *pShiftReg | 0x40000000;
}
return noise_bits;
}
/***************************************************************************
* Function : ownBuildCNCode_GSMAMR
***************************************************************************/
void ownBuildCNCode_GSMAMR (int *seed, short *pCNVec)
{
short 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 = 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(short *seed, const short numParam, const short *pTableSizeParam,
short *pCNParam)
{
short i;
const short *ptr_wnd;
*seed = (short)(*seed * 31821 + 13849L);
ptr_wnd = &TableHammingWindow[*seed & 0x7F];
for(i=0; i< numParam;i++){
pCNParam[i] = *ptr_wnd++ & ~(0xFFFF<<pTableSizeParam[i]);
}
}
/*************************************************************************
* Function: ownDecLSPQuantDTX_GSMAMR()
*************************************************************************/
void ownDecLSPQuantDTX_GSMAMR(short *a_PastQntPredErr, short *a_PastLSFQnt, short BadFrInd,
short *indice, short *lsp1_q)
{
short i, index;
short *p_dico, temp;
IPP_ALIGNED_ARRAY(16, short, lsf1_r, LP_ORDER_SIZE);
IPP_ALIGNED_ARRAY(16, short, lsf1_q, LP_ORDER_SIZE);
if (BadFrInd != 0) { /* if bad frame */
for(i = 0; i < LP_ORDER_SIZE; i++)
lsf1_q[i] = ((a_PastLSFQnt[i] * ALPHA_09) >> 15) + ((TableMeanLSF_3[i] * ONE_ALPHA) >> 15);
for (i = 0; i < LP_ORDER_SIZE; i++) {
temp = TableMeanLSF_3[i] + a_PastQntPredErr[i];
a_PastQntPredErr[i] = 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 = TableMeanLSF_3[i] + a_PastQntPredErr[i];
lsf1_q[i] = 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 short lsf_hist_mean_scale[LP_ORDER_SIZE] = {
20000, 20000, 20000, 20000, 20000, 18000, 16384, 8192, 0, 0
};
static __ALIGN32 CONST short 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
***************************************************************************/
int ownDTXDecoder_GSMAMR(sDTXDecoderSt *dtxState, short *a_MemorySyn, short *a_PastQntPredErr,
short *a_PastLSFQnt, short *a_PastQntEnergy, short *a_PastQntEnergy_M122,
short *vHgAverageVar, short *vHgAverageCount, enum enDTXStateType newState,
GSMAMR_Rate_t rate, short *pParmVec, short *pSynthSpeechVec, short *pA_LP)
{
short logEnergyIdx;
short i, j;
short int_fac;
int logEnergy_long;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -