void StateConstructW( int idxForMax, /* (i) 6-bit index for the quantization of max amplitude */ int *idxVec, /* (i) vector of quantization indexes */ float *syntDenum, /* (i) synthesis filter denumerator */ float *out, /* (o) the decoded state vector */ int len /* (i) length of a state vector */ ){ float maxVal, tmpbuf[LPC_FILTERORDER+2*STATE_LEN], *tmp, numerator[LPC_FILTERORDER+1]; float foutbuf[LPC_FILTERORDER+2*STATE_LEN], *fout; int k,tmpi; /* decoding of the maximum value */ maxVal = state_frgqTbl[idxForMax]; maxVal = (float)pow(10,maxVal)/(float)4.5; /* initialization of buffers and coefficients */ memset(tmpbuf, 0, LPC_FILTERORDER*sizeof(float)); memset(foutbuf, 0, LPC_FILTERORDER*sizeof(float)); for (k=0; k<LPC_FILTERORDER; k++) { numerator[k]=syntDenum[LPC_FILTERORDER-k]; } numerator[LPC_FILTERORDER]=syntDenum[0]; tmp = &tmpbuf[LPC_FILTERORDER]; fout = &foutbuf[LPC_FILTERORDER]; /* decoding of the sample values */ for (k=0; k<len; k++) { tmpi = len-1-k; /* maxVal = 1/scal */ tmp[k] = maxVal*state_sq3Tbl[idxVec[tmpi]]; } /* circular convolution with all-pass filter */ memset(tmp+len, 0, len*sizeof(float)); ZeroPoleFilter(tmp, numerator, syntDenum, 2*len, LPC_FILTERORDER, fout); for (k=0;k<len;k++) { out[k] = fout[len-1-k]+fout[2*len-1-k]; } }
void StateSearchW( iLBC_Enc_Inst_t *iLBCenc_inst, /* (i) Encoder instance */ float *residual,/* (i) target residual vector */ float *syntDenum, /* (i) lpc synthesis filter */ float *weightDenum, /* (i) weighting filter denuminator */ int *idxForMax, /* (o) quantizer index for maximum amplitude */ int *idxVec, /* (o) vector of quantization indexes */ int len, /* (i) length of all vectors */ int state_first /* (i) position of start state in the 80 vec */ ){ float dtmp, maxVal; float tmpbuf[LPC_FILTERORDER+2*STATE_SHORT_LEN_30MS]; float *tmp, numerator[1+LPC_FILTERORDER]; float foutbuf[LPC_FILTERORDER+2*STATE_SHORT_LEN_30MS], *fout; int k; float qmax, scal; /* initialization of buffers and filter coefficients */ memset(tmpbuf, 0, LPC_FILTERORDER*sizeof(float)); memset(foutbuf, 0, LPC_FILTERORDER*sizeof(float)); for (k=0; k<LPC_FILTERORDER; k++) { numerator[k]=syntDenum[LPC_FILTERORDER-k]; } numerator[LPC_FILTERORDER]=syntDenum[0]; tmp = &tmpbuf[LPC_FILTERORDER]; fout = &foutbuf[LPC_FILTERORDER]; /* circular convolution with the all-pass filter */ memcpy(tmp, residual, len*sizeof(float)); memset(tmp+len, 0, len*sizeof(float)); ZeroPoleFilter(tmp, numerator, syntDenum, 2*len, LPC_FILTERORDER, fout); for (k=0; k<len; k++) { fout[k] += fout[k+len]; } /* identification of the maximum amplitude value */ maxVal = fout[0]; for (k=1; k<len; k++) { if (fout[k]*fout[k] > maxVal*maxVal){ maxVal = fout[k]; } } maxVal=(float)fabs(maxVal); /* encoding of the maximum amplitude value */ if (maxVal < 10.0) { maxVal = 10.0; } maxVal = (float)log10(maxVal); sort_sq(&dtmp, idxForMax, maxVal, state_frgqTbl, 64); /* decoding of the maximum amplitude representation value, and corresponding scaling of start state */ maxVal=state_frgqTbl[*idxForMax]; qmax = (float)pow(10,maxVal); scal = (float)(4.5)/qmax; for (k=0; k<len; k++){ fout[k] *= scal; } /* predictive noise shaping encoding of scaled start state */ AbsQuantW(iLBCenc_inst, fout,syntDenum, weightDenum,idxVec, len, state_first); }