📄 dtx_enc.c
字号:
#include "dtx_enc.h"
#include "basic_op.h"
#include "bitno_tab.h"
#include "lpc.h"
static const Word16 lsp_lsf_table[65] =
{ 32767, 32729, 32610, 32413, 32138, 31786, 31357, 30853, 30274, 29622, 28899, 28106, 27246, 26320, 25330, 24279, 23170, 22006, 20788, 19520, 18205, 16846, 15447, 14010, 12540, 11039, 9512, 7962, 6393, 4808, 3212, 1608, 0, -1608, -3212, -4808, -6393, -7962, -9512, -11039, -12540, -14010, -15447, -16846, -18205, -19520, -20788, -22006, -23170, -24279, -25330, -26320, -27246, -28106, -28899, -29622, -30274, -30853, -31357, -31786, -32138, -32413, -32610, -32729, (Word16) 0x8000};
int dtx_enc_init (dtx_encState **st){
dtx_encState* pdtx_encState;
if (st == (dtx_encState **) NULL)
{
fprintf(stderr, "dtx_enc_init: invalid parameter\n");
return -1;
}
*st = NULL;
/* allocate memory */
if ((pdtx_encState= (dtx_encState *) malloc(sizeof(dtx_encState))) == NULL)
{
fprintf(stderr, "dtx_enc_init: can not malloc state structure\n");
return -1;
}
// dtx_enc_reset(pdtx_encState);
pdtx_encState->hist_ptr = 0;
pdtx_encState->log_en_index = 0;
pdtx_encState->init_lsf_vq_index = 0;
pdtx_encState->lsp_index[0] = 0;
pdtx_encState->lsp_index[1] = 0;
pdtx_encState->lsp_index[2] = 0;
/* Init lsp_hist[] */
pdtx_encState->lsp_hist[0] = pdtx_encState->lsp_hist[10] = pdtx_encState->lsp_hist[20] = pdtx_encState->lsp_hist[30] =
pdtx_encState->lsp_hist[40] = pdtx_encState->lsp_hist[50] = pdtx_encState->lsp_hist[60] = pdtx_encState->lsp_hist[70] = lsp_init_data[0];
pdtx_encState->lsp_hist[1] = pdtx_encState->lsp_hist[11] = pdtx_encState->lsp_hist[21] = pdtx_encState->lsp_hist[31] =
pdtx_encState->lsp_hist[41] = pdtx_encState->lsp_hist[51] = pdtx_encState->lsp_hist[61] = pdtx_encState->lsp_hist[71] = lsp_init_data[1];
pdtx_encState->lsp_hist[2] = pdtx_encState->lsp_hist[12] = pdtx_encState->lsp_hist[22] = pdtx_encState->lsp_hist[32] =
pdtx_encState->lsp_hist[42] = pdtx_encState->lsp_hist[52] = pdtx_encState->lsp_hist[62] = pdtx_encState->lsp_hist[72] = lsp_init_data[2];
pdtx_encState->lsp_hist[3] = pdtx_encState->lsp_hist[13] = pdtx_encState->lsp_hist[23] = pdtx_encState->lsp_hist[33] =
pdtx_encState->lsp_hist[43] = pdtx_encState->lsp_hist[53] = pdtx_encState->lsp_hist[63] = pdtx_encState->lsp_hist[73] = lsp_init_data[3];
pdtx_encState->lsp_hist[4] = pdtx_encState->lsp_hist[14] = pdtx_encState->lsp_hist[24] = pdtx_encState->lsp_hist[34] =
pdtx_encState->lsp_hist[44] = pdtx_encState->lsp_hist[54] = pdtx_encState->lsp_hist[64] = pdtx_encState->lsp_hist[74] = lsp_init_data[4];
pdtx_encState->lsp_hist[5] = pdtx_encState->lsp_hist[15] = pdtx_encState->lsp_hist[25] = pdtx_encState->lsp_hist[35] =
pdtx_encState->lsp_hist[45] = pdtx_encState->lsp_hist[55] = pdtx_encState->lsp_hist[65] = pdtx_encState->lsp_hist[75] = lsp_init_data[5];
pdtx_encState->lsp_hist[6] = pdtx_encState->lsp_hist[16] = pdtx_encState->lsp_hist[26] = pdtx_encState->lsp_hist[36] =
pdtx_encState->lsp_hist[46] = pdtx_encState->lsp_hist[56] = pdtx_encState->lsp_hist[66] = pdtx_encState->lsp_hist[76] = lsp_init_data[6];
pdtx_encState->lsp_hist[7] = pdtx_encState->lsp_hist[17] = pdtx_encState->lsp_hist[27] = pdtx_encState->lsp_hist[37] =
pdtx_encState->lsp_hist[47] = pdtx_encState->lsp_hist[57] = pdtx_encState->lsp_hist[67] = pdtx_encState->lsp_hist[77] = lsp_init_data[7];
pdtx_encState->lsp_hist[8] = pdtx_encState->lsp_hist[18] = pdtx_encState->lsp_hist[28] = pdtx_encState->lsp_hist[38] =
pdtx_encState->lsp_hist[48] = pdtx_encState->lsp_hist[58] = pdtx_encState->lsp_hist[68] = pdtx_encState->lsp_hist[78] = lsp_init_data[8];
pdtx_encState->lsp_hist[9] = pdtx_encState->lsp_hist[19] = pdtx_encState->lsp_hist[29] = pdtx_encState->lsp_hist[39] =
pdtx_encState->lsp_hist[49] = pdtx_encState->lsp_hist[59] = pdtx_encState->lsp_hist[69] = pdtx_encState->lsp_hist[79] = lsp_init_data[9];
/* Reset energy history */
// Set_zero(pdtx_encState->log_en_hist, M);
memset(&pdtx_encState->log_en_hist[0], 0, M*sizeof(Word16));
pdtx_encState->dtxHangoverCount = DTX_HANG_CONST;
pdtx_encState->decAnaElapsedCount = 32767;
*st = pdtx_encState;
return 0;
}
int dtx_enc_reset (dtx_encState *st){ dtx_encState *pst = st;
if (pst == (dtx_encState *) NULL)
{ fprintf(stderr, "dtx_enc_reset: invalid parameter\n"); return -1; } pst->hist_ptr = 0;
pst->log_en_index = 0;
pst->init_lsf_vq_index = 0;
pst->lsp_index[0] = 0;
pst->lsp_index[1] = 0;
pst->lsp_index[2] = 0;
/* Init lsp_hist[] */
pst->lsp_hist[0] = pst->lsp_hist[10] = pst->lsp_hist[20] = pst->lsp_hist[30] =
pst->lsp_hist[40] = pst->lsp_hist[50] = pst->lsp_hist[60] = pst->lsp_hist[70] = lsp_init_data[0];
pst->lsp_hist[1] = pst->lsp_hist[11] = pst->lsp_hist[21] = pst->lsp_hist[31] =
pst->lsp_hist[41] = pst->lsp_hist[51] = pst->lsp_hist[61] = pst->lsp_hist[71] = lsp_init_data[1];
pst->lsp_hist[2] = pst->lsp_hist[12] = pst->lsp_hist[22] = pst->lsp_hist[32] =
pst->lsp_hist[42] = pst->lsp_hist[52] = pst->lsp_hist[62] = pst->lsp_hist[72] = lsp_init_data[2];
pst->lsp_hist[3] = pst->lsp_hist[13] = pst->lsp_hist[23] = pst->lsp_hist[33] =
pst->lsp_hist[43] = pst->lsp_hist[53] = pst->lsp_hist[63] = pst->lsp_hist[73] = lsp_init_data[3];
pst->lsp_hist[4] = pst->lsp_hist[14] = pst->lsp_hist[24] = pst->lsp_hist[34] =
pst->lsp_hist[44] = pst->lsp_hist[54] = pst->lsp_hist[64] = pst->lsp_hist[74] = lsp_init_data[4];
pst->lsp_hist[5] = pst->lsp_hist[15] = pst->lsp_hist[25] = pst->lsp_hist[35] =
pst->lsp_hist[45] = pst->lsp_hist[55] = pst->lsp_hist[65] = pst->lsp_hist[75] = lsp_init_data[5];
pst->lsp_hist[6] = pst->lsp_hist[16] = pst->lsp_hist[26] = pst->lsp_hist[36] =
pst->lsp_hist[46] = pst->lsp_hist[56] = pst->lsp_hist[66] = pst->lsp_hist[76] = lsp_init_data[6];
pst->lsp_hist[7] = pst->lsp_hist[17] = pst->lsp_hist[27] = pst->lsp_hist[37] =
pst->lsp_hist[47] = pst->lsp_hist[57] = pst->lsp_hist[67] = pst->lsp_hist[77] = lsp_init_data[7];
pst->lsp_hist[8] = pst->lsp_hist[18] = pst->lsp_hist[28] = pst->lsp_hist[38] =
pst->lsp_hist[48] = pst->lsp_hist[58] = pst->lsp_hist[68] = pst->lsp_hist[78] = lsp_init_data[8];
pst->lsp_hist[9] = pst->lsp_hist[19] = pst->lsp_hist[29] = pst->lsp_hist[39] =
pst->lsp_hist[49] = pst->lsp_hist[59] = pst->lsp_hist[69] = pst->lsp_hist[79] = lsp_init_data[9];
/* Reset energy history */ // Set_zero(st->log_en_hist, M); memset(pst->log_en_hist, 0, M*sizeof(Word16));
pst->dtxHangoverCount = DTX_HANG_CONST;
pst->decAnaElapsedCount = 32767;
return 1;
}
void dtx_enc_exit (dtx_encState **st){ if (st == NULL || *st == NULL) return; /* deallocate memory */ free(*st); *st = NULL; return;}
/**********************************************************
Function : dtx_enc
Description: dtx encoding
Input :
st : State struct
computeSidFlag : compute SID
qSt : Qunatizer state struct
predState : State struct
Output :
st : State struct
qSt : Qunatizer state struct
predState : State struct
anap : analysis parameters
Return :
************************************************************/
int dtx_enc(dtx_encState *st, Word16 computeSidFlag, Q_plsfState *qSt,gc_predState* predState,Word16 **anap )
{
Word16 i; Word16 log_en; Word16 lsf[M]; Word16 lsp[M]; Word16 lsp_q[M]; Word32 L_lsp[M],L_tmp1;
Word16 lsf_min1,ind1,offset1;
const Word16*plsp_lsf_table = lsp_lsf_table;
dtx_encState *pst = st;
gc_predState* ppredState = predState;
/* VOX mode computation of SID parameters */ if ((computeSidFlag != 0)) { /* compute new SID frame if safe i.e don't * compute immediately after a talk spurt */ log_en = 0;
memset(L_lsp , 0 ,40);
/* average energy and lsp */ for (i = 0; i < DTX_HIST_SIZE; i++) { log_en += (pst->log_en_hist[i]>>2);
L_lsp[0] += pst->lsp_hist[i * M ] ;
L_lsp[1] += pst->lsp_hist[i * M + 1] ;
L_lsp[2] += pst->lsp_hist[i * M + 2] ;
L_lsp[3] += pst->lsp_hist[i * M + 3] ;
L_lsp[4] += pst->lsp_hist[i * M + 4] ;
L_lsp[5] += pst->lsp_hist[i * M + 5] ;
L_lsp[6] += pst->lsp_hist[i * M + 6] ;
L_lsp[7] += pst->lsp_hist[i * M + 7] ;
L_lsp[8] += pst->lsp_hist[i * M + 8] ;
L_lsp[9] += pst->lsp_hist[i * M + 9] ;
} log_en >>= 1;
lsp[0] = (Word16)(L_lsp[0]>> 3);
lsp[1] = (Word16)(L_lsp[1]>> 3);
lsp[2] = (Word16)(L_lsp[2]>> 3);
lsp[3] = (Word16)(L_lsp[3]>> 3);
lsp[4] = (Word16)(L_lsp[4]>> 3);
lsp[5] = (Word16)(L_lsp[5]>> 3);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -