Coverity cleanups for iLBC

This commit is contained in:
Steve Underwood 2014-07-22 12:06:50 +08:00
parent 720e7a23c4
commit 0c32ae8ca0
3 changed files with 129 additions and 131 deletions

View File

@ -134,7 +134,7 @@ void DownSample(const float *In, /* (i) input samples */
o = 0.0f; o = 0.0f;
stop = (i < FILTERORDER_DS) ? i + 1 : FILTERORDER_DS; stop = (i < FILTERORDER_DS) ? (i + 1) : FILTERORDER_DS;
for (j = 0; j < stop; j++) for (j = 0; j < stop; j++)
o += *Coef_ptr++ * (*In_ptr--); o += *Coef_ptr++ * (*In_ptr--);
@ -151,14 +151,13 @@ void DownSample(const float *In, /* (i) input samples */
if (i<lengthIn) if (i<lengthIn)
{ {
Coef_ptr = &Coef[0]; Coef_ptr = &Coef[0];
In_ptr = &In[i];
for (j = 0; j < FILTERORDER_DS; j++) for (j = 0; j < FILTERORDER_DS; j++)
o += *Coef_ptr++ * (*Out_ptr--); o += *Coef_ptr++ * (*Out_ptr--);
} }
else else
{ {
Coef_ptr = &Coef[i-lengthIn]; Coef_ptr = &Coef[i - lengthIn];
In_ptr = &In[lengthIn-1]; In_ptr = &In[lengthIn - 1];
for (j = 0; j < FILTERORDER_DS - (i - lengthIn); j++) for (j = 0; j < FILTERORDER_DS - (i - lengthIn); j++)
o += *Coef_ptr++ * (*In_ptr--); o += *Coef_ptr++ * (*In_ptr--);
} }

View File

@ -66,77 +66,6 @@
#endif #endif
#endif #endif
/*----------------------------------------------------------------*
* Initiation of decoder instance.
*---------------------------------------------------------------*/
ilbc_decode_state_t *ilbc_decode_init(ilbc_decode_state_t *iLBCdec_inst, /* (i/o) Decoder instance */
int mode, /* (i) frame size mode */
int use_enhancer) /* (i) 1 to use enhancer
0 to run without enhancer */
{
int i;
iLBCdec_inst->mode = mode;
if (mode == 30)
{
iLBCdec_inst->blockl = ILBC_BLOCK_LEN_30MS;
iLBCdec_inst->nsub = NSUB_30MS;
iLBCdec_inst->nasub = NASUB_30MS;
iLBCdec_inst->lpc_n = LPC_N_30MS;
iLBCdec_inst->no_of_bytes = ILBC_NO_OF_BYTES_30MS;
iLBCdec_inst->state_short_len = STATE_SHORT_LEN_30MS;
/* ULP init */
iLBCdec_inst->ULP_inst = &ULP_30msTbl;
}
else if (mode == 20)
{
iLBCdec_inst->blockl = ILBC_BLOCK_LEN_20MS;
iLBCdec_inst->nsub = NSUB_20MS;
iLBCdec_inst->nasub = NASUB_20MS;
iLBCdec_inst->lpc_n = LPC_N_20MS;
iLBCdec_inst->no_of_bytes = ILBC_NO_OF_BYTES_20MS;
iLBCdec_inst->state_short_len = STATE_SHORT_LEN_20MS;
/* ULP init */
iLBCdec_inst->ULP_inst = &ULP_20msTbl;
}
else
{
return NULL;
}
memset(iLBCdec_inst->syntMem, 0, ILBC_LPC_FILTERORDER*sizeof(float));
memcpy((*iLBCdec_inst).lsfdeqold, lsfmeanTbl, ILBC_LPC_FILTERORDER*sizeof(float));
memset(iLBCdec_inst->old_syntdenum,
0,
((ILBC_LPC_FILTERORDER + 1)*ILBC_NUM_SUB_MAX)*sizeof(float));
for (i = 0; i < ILBC_NUM_SUB_MAX; i++)
iLBCdec_inst->old_syntdenum[i*(ILBC_LPC_FILTERORDER + 1)] = 1.0f;
iLBCdec_inst->last_lag = 20;
iLBCdec_inst->prevLag = 120;
iLBCdec_inst->per = 0.0;
iLBCdec_inst->consPLICount = 0;
iLBCdec_inst->prevPLI = 0;
iLBCdec_inst->prevLpc[0] = 1.0f;
memset(iLBCdec_inst->prevLpc + 1, 0, ILBC_LPC_FILTERORDER*sizeof(float));
memset(iLBCdec_inst->prevResidual, 0, ILBC_BLOCK_LEN_MAX*sizeof(float));
iLBCdec_inst->seed = 777;
memset(iLBCdec_inst->hpomem, 0, 4*sizeof(float));
iLBCdec_inst->use_enhancer = use_enhancer;
memset(iLBCdec_inst->enh_buf, 0, ENH_BUFL*sizeof(float));
for (i = 0; i < ENH_NBLOCKS_TOT; i++)
iLBCdec_inst->enh_period[i] = 40.0f;
iLBCdec_inst->prev_enh_pl = 0;
return iLBCdec_inst;
}
/*----------------------------------------------------------------* /*----------------------------------------------------------------*
* frame residual decoder function (subrutine to iLBC_decode) * frame residual decoder function (subrutine to iLBC_decode)
*---------------------------------------------------------------*/ *---------------------------------------------------------------*/
@ -648,3 +577,70 @@ int ilbc_fillin(ilbc_decode_state_t *s, /* (i/o) the decoder state structure
} }
return i; return i;
} }
ilbc_decode_state_t *ilbc_decode_init(ilbc_decode_state_t *iLBCdec_inst, /* (i/o) Decoder instance */
int mode, /* (i) frame size mode */
int use_enhancer) /* (i) 1 to use enhancer
0 to run without enhancer */
{
int i;
iLBCdec_inst->mode = mode;
if (mode == 30)
{
iLBCdec_inst->blockl = ILBC_BLOCK_LEN_30MS;
iLBCdec_inst->nsub = NSUB_30MS;
iLBCdec_inst->nasub = NASUB_30MS;
iLBCdec_inst->lpc_n = LPC_N_30MS;
iLBCdec_inst->no_of_bytes = ILBC_NO_OF_BYTES_30MS;
iLBCdec_inst->state_short_len = STATE_SHORT_LEN_30MS;
/* ULP init */
iLBCdec_inst->ULP_inst = &ULP_30msTbl;
}
else if (mode == 20)
{
iLBCdec_inst->blockl = ILBC_BLOCK_LEN_20MS;
iLBCdec_inst->nsub = NSUB_20MS;
iLBCdec_inst->nasub = NASUB_20MS;
iLBCdec_inst->lpc_n = LPC_N_20MS;
iLBCdec_inst->no_of_bytes = ILBC_NO_OF_BYTES_20MS;
iLBCdec_inst->state_short_len = STATE_SHORT_LEN_20MS;
/* ULP init */
iLBCdec_inst->ULP_inst = &ULP_20msTbl;
}
else
{
return NULL;
}
memset(iLBCdec_inst->syntMem, 0, ILBC_LPC_FILTERORDER*sizeof(float));
memcpy((*iLBCdec_inst).lsfdeqold, lsfmeanTbl, ILBC_LPC_FILTERORDER*sizeof(float));
memset(iLBCdec_inst->old_syntdenum,
0,
((ILBC_LPC_FILTERORDER + 1)*ILBC_NUM_SUB_MAX)*sizeof(float));
for (i = 0; i < ILBC_NUM_SUB_MAX; i++)
iLBCdec_inst->old_syntdenum[i*(ILBC_LPC_FILTERORDER + 1)] = 1.0f;
iLBCdec_inst->last_lag = 20;
iLBCdec_inst->prevLag = 120;
iLBCdec_inst->per = 0.0;
iLBCdec_inst->consPLICount = 0;
iLBCdec_inst->prevPLI = 0;
iLBCdec_inst->prevLpc[0] = 1.0f;
memset(iLBCdec_inst->prevLpc + 1, 0, ILBC_LPC_FILTERORDER*sizeof(float));
memset(iLBCdec_inst->prevResidual, 0, ILBC_BLOCK_LEN_MAX*sizeof(float));
iLBCdec_inst->seed = 777;
memset(iLBCdec_inst->hpomem, 0, 4*sizeof(float));
iLBCdec_inst->use_enhancer = use_enhancer;
memset(iLBCdec_inst->enh_buf, 0, ENH_BUFL*sizeof(float));
for (i = 0; i < ENH_NBLOCKS_TOT; i++)
iLBCdec_inst->enh_period[i] = 40.0f;
iLBCdec_inst->prev_enh_pl = 0;
return iLBCdec_inst;
}

View File

@ -46,46 +46,6 @@
* Initiation of encoder instance. * Initiation of encoder instance.
*---------------------------------------------------------------*/ *---------------------------------------------------------------*/
ilbc_encode_state_t *ilbc_encode_init(ilbc_encode_state_t *iLBCenc_inst, /* (i/o) Encoder instance */
int mode) /* (i) frame size mode */
{
iLBCenc_inst->mode = mode;
if (mode == 30)
{
iLBCenc_inst->blockl = ILBC_BLOCK_LEN_30MS;
iLBCenc_inst->nsub = NSUB_30MS;
iLBCenc_inst->nasub = NASUB_30MS;
iLBCenc_inst->lpc_n = LPC_N_30MS;
iLBCenc_inst->no_of_bytes = ILBC_NO_OF_BYTES_30MS;
iLBCenc_inst->state_short_len = STATE_SHORT_LEN_30MS;
/* ULP init */
iLBCenc_inst->ULP_inst = &ULP_30msTbl;
}
else if (mode == 20)
{
iLBCenc_inst->blockl = ILBC_BLOCK_LEN_20MS;
iLBCenc_inst->nsub = NSUB_20MS;
iLBCenc_inst->nasub = NASUB_20MS;
iLBCenc_inst->lpc_n = LPC_N_20MS;
iLBCenc_inst->no_of_bytes = ILBC_NO_OF_BYTES_20MS;
iLBCenc_inst->state_short_len = STATE_SHORT_LEN_20MS;
/* ULP init */
iLBCenc_inst->ULP_inst = &ULP_20msTbl;
}
else
{
return NULL;
}
memset((*iLBCenc_inst).anaMem, 0, ILBC_LPC_FILTERORDER*sizeof(float));
memcpy((*iLBCenc_inst).lsfold, lsfmeanTbl, ILBC_LPC_FILTERORDER*sizeof(float));
memcpy((*iLBCenc_inst).lsfdeqold, lsfmeanTbl, ILBC_LPC_FILTERORDER*sizeof(float));
memset((*iLBCenc_inst).lpc_buffer, 0, (LPC_LOOKBACK + ILBC_BLOCK_LEN_MAX)*sizeof(float));
memset((*iLBCenc_inst).hpimem, 0, 4*sizeof(float));
return iLBCenc_inst;
}
/*----------------------------------------------------------------* /*----------------------------------------------------------------*
* main encoder function * main encoder function
*---------------------------------------------------------------*/ *---------------------------------------------------------------*/
@ -215,7 +175,7 @@ static int ilbc_encode_frame(ilbc_encode_state_t *iLBCenc_inst, /* (i/o) the
iCBConstruct(&decresidual[start_pos + iLBCenc_inst->state_short_len], iCBConstruct(&decresidual[start_pos + iLBCenc_inst->state_short_len],
extra_cb_index, extra_cb_index,
extra_gain_index, extra_gain_index,
mem + CB_MEML - stMemLTbl, &mem[CB_MEML - stMemLTbl],
stMemLTbl, stMemLTbl,
diff, diff,
CB_NSTAGES); CB_NSTAGES);
@ -252,7 +212,7 @@ static int ilbc_encode_frame(ilbc_encode_state_t *iLBCenc_inst, /* (i/o) the
iCBConstruct(reverseDecresidual, iCBConstruct(reverseDecresidual,
extra_cb_index, extra_cb_index,
extra_gain_index, extra_gain_index,
mem + CB_MEML - stMemLTbl, &mem[CB_MEML - stMemLTbl],
stMemLTbl, stMemLTbl,
diff, diff,
CB_NSTAGES); CB_NSTAGES);
@ -271,7 +231,7 @@ static int ilbc_encode_frame(ilbc_encode_state_t *iLBCenc_inst, /* (i/o) the
if (Nfor > 0) if (Nfor > 0)
{ {
/* Setup memory */ /* Setup memory */
memset(mem, 0, (CB_MEML-STATE_LEN)*sizeof(float)); memset(mem, 0, (CB_MEML - STATE_LEN)*sizeof(float));
memcpy(&mem[CB_MEML - STATE_LEN], decresidual + (start - 1)*SUBL, STATE_LEN*sizeof(float)); memcpy(&mem[CB_MEML - STATE_LEN], decresidual + (start - 1)*SUBL, STATE_LEN*sizeof(float));
memset(weightState, 0, ILBC_LPC_FILTERORDER*sizeof(float)); memset(weightState, 0, ILBC_LPC_FILTERORDER*sizeof(float));
@ -280,10 +240,10 @@ static int ilbc_encode_frame(ilbc_encode_state_t *iLBCenc_inst, /* (i/o) the
{ {
/* Encode sub-frame */ /* Encode sub-frame */
iCBSearch(iLBCenc_inst, iCBSearch(iLBCenc_inst,
cb_index + subcount*CB_NSTAGES, &cb_index[subcount*CB_NSTAGES],
gain_index + subcount*CB_NSTAGES, &gain_index[subcount*CB_NSTAGES],
&residual[(start + 1 + subframe)*SUBL], &residual[(start + 1 + subframe)*SUBL],
mem + CB_MEML-memLfTbl[subcount], &mem[CB_MEML - memLfTbl[subcount]],
memLfTbl[subcount], memLfTbl[subcount],
SUBL, SUBL,
CB_NSTAGES, CB_NSTAGES,
@ -293,9 +253,9 @@ static int ilbc_encode_frame(ilbc_encode_state_t *iLBCenc_inst, /* (i/o) the
/* Construct decoded vector */ /* Construct decoded vector */
iCBConstruct(&decresidual[(start + 1 + subframe)*SUBL], iCBConstruct(&decresidual[(start + 1 + subframe)*SUBL],
cb_index + subcount*CB_NSTAGES, &cb_index[subcount*CB_NSTAGES],
gain_index + subcount*CB_NSTAGES, &gain_index[subcount*CB_NSTAGES],
mem + CB_MEML - memLfTbl[subcount], &mem[CB_MEML - memLfTbl[subcount]],
memLfTbl[subcount], memLfTbl[subcount],
SUBL, SUBL,
CB_NSTAGES); CB_NSTAGES);
@ -338,20 +298,23 @@ static int ilbc_encode_frame(ilbc_encode_state_t *iLBCenc_inst, /* (i/o) the
for (subframe = 0; subframe < Nback; subframe++) for (subframe = 0; subframe < Nback; subframe++)
{ {
/* Encode sub-frame */ /* Encode sub-frame */
iCBSearch(iLBCenc_inst, cb_index+subcount*CB_NSTAGES, iCBSearch(iLBCenc_inst,
gain_index + subcount*CB_NSTAGES, &cb_index[subcount*CB_NSTAGES],
&gain_index[subcount*CB_NSTAGES],
&reverseResidual[subframe*SUBL], &reverseResidual[subframe*SUBL],
mem + CB_MEML - memLfTbl[subcount], &mem[CB_MEML - memLfTbl[subcount]],
memLfTbl[subcount], SUBL, CB_NSTAGES, memLfTbl[subcount],
SUBL,
CB_NSTAGES,
&weightdenum[(start - 2 - subframe)*(ILBC_LPC_FILTERORDER + 1)], &weightdenum[(start - 2 - subframe)*(ILBC_LPC_FILTERORDER + 1)],
weightState, weightState,
subcount + 1); subcount + 1);
/* Construct decoded vector */ /* Construct decoded vector */
iCBConstruct(&reverseDecresidual[subframe*SUBL], iCBConstruct(&reverseDecresidual[subframe*SUBL],
cb_index + subcount*CB_NSTAGES, &cb_index[subcount*CB_NSTAGES],
gain_index + subcount*CB_NSTAGES, &gain_index[subcount*CB_NSTAGES],
mem + CB_MEML - memLfTbl[subcount], &mem[CB_MEML - memLfTbl[subcount]],
memLfTbl[subcount], memLfTbl[subcount],
SUBL, SUBL,
CB_NSTAGES); CB_NSTAGES);
@ -515,3 +478,43 @@ int ilbc_encode(ilbc_encode_state_t *s, /* (i/o) the general encoder state *
} }
return j; return j;
} }
ilbc_encode_state_t *ilbc_encode_init(ilbc_encode_state_t *iLBCenc_inst, /* (i/o) Encoder instance */
int mode) /* (i) frame size mode */
{
iLBCenc_inst->mode = mode;
if (mode == 30)
{
iLBCenc_inst->blockl = ILBC_BLOCK_LEN_30MS;
iLBCenc_inst->nsub = NSUB_30MS;
iLBCenc_inst->nasub = NASUB_30MS;
iLBCenc_inst->lpc_n = LPC_N_30MS;
iLBCenc_inst->no_of_bytes = ILBC_NO_OF_BYTES_30MS;
iLBCenc_inst->state_short_len = STATE_SHORT_LEN_30MS;
/* ULP init */
iLBCenc_inst->ULP_inst = &ULP_30msTbl;
}
else if (mode == 20)
{
iLBCenc_inst->blockl = ILBC_BLOCK_LEN_20MS;
iLBCenc_inst->nsub = NSUB_20MS;
iLBCenc_inst->nasub = NASUB_20MS;
iLBCenc_inst->lpc_n = LPC_N_20MS;
iLBCenc_inst->no_of_bytes = ILBC_NO_OF_BYTES_20MS;
iLBCenc_inst->state_short_len = STATE_SHORT_LEN_20MS;
/* ULP init */
iLBCenc_inst->ULP_inst = &ULP_20msTbl;
}
else
{
return NULL;
}
memset((*iLBCenc_inst).anaMem, 0, ILBC_LPC_FILTERORDER*sizeof(float));
memcpy((*iLBCenc_inst).lsfold, lsfmeanTbl, ILBC_LPC_FILTERORDER*sizeof(float));
memcpy((*iLBCenc_inst).lsfdeqold, lsfmeanTbl, ILBC_LPC_FILTERORDER*sizeof(float));
memset((*iLBCenc_inst).lpc_buffer, 0, (LPC_LOOKBACK + ILBC_BLOCK_LEN_MAX)*sizeof(float));
memset((*iLBCenc_inst).hpimem, 0, 4*sizeof(float));
return iLBCenc_inst;
}