2
/******************************************************************
4
iLBC Speech Coder ANSI-C Source Code
8
Copyright (C) The Internet Society (2004).
11
******************************************************************/
16
#include "iLBC_define.h"
17
#include "constants.h"
21
/*----------------------------------------------------------------*
22
* predictive noise shaping encoding of scaled start state
23
* (subrutine for StateSearchW)
24
*---------------------------------------------------------------*/
27
iLBC_Enc_Inst_t *iLBCenc_inst,
28
/* (i) Encoder instance */
29
float *in, /* (i) vector to encode */
30
float *syntDenum, /* (i) denominator of synthesis filter */
31
float *weightDenum, /* (i) denominator of weighting filter */
32
int *out, /* (o) vector of quantizer indexes */
33
int len, /* (i) length of vector to encode and
34
vector of quantizer indexes */
35
int state_first /* (i) position of start state in the
39
float syntOutBuf[LPC_FILTERORDER+STATE_SHORT_LEN_30MS];
44
/* initialization of buffer for filtering */
46
memset(syntOutBuf, 0, LPC_FILTERORDER*sizeof(float));
53
/* initialization of pointer for filtering */
55
syntOut = &syntOutBuf[LPC_FILTERORDER];
57
/* synthesis and weighting filters on input */
60
AllPoleFilter (in, weightDenum, SUBL, LPC_FILTERORDER);
62
AllPoleFilter (in, weightDenum,
63
iLBCenc_inst->state_short_len-SUBL,
69
for (n=0; n<len; n++) {
71
/* time update of filter coefficients */
73
if ((state_first)&&(n==SUBL)){
74
syntDenum += (LPC_FILTERORDER+1);
75
weightDenum += (LPC_FILTERORDER+1);
77
/* synthesis and weighting filters on input */
78
AllPoleFilter (&in[n], weightDenum, len-n,
81
} else if ((state_first==0)&&
82
(n==(iLBCenc_inst->state_short_len-SUBL))) {
83
syntDenum += (LPC_FILTERORDER+1);
84
weightDenum += (LPC_FILTERORDER+1);
86
/* synthesis and weighting filters on input */
87
AllPoleFilter (&in[n], weightDenum, len-n,
92
/* prediction of synthesized and weighted input */
95
AllPoleFilter (&syntOut[n], weightDenum, 1,
100
toQ = in[n]-syntOut[n];
106
sort_sq(&xq, &index, toQ, state_sq3Tbl, 8);
108
syntOut[n] = state_sq3Tbl[out[n]];
110
/* update of the prediction filter */
112
AllPoleFilter(&syntOut[n], weightDenum, 1,
117
/*----------------------------------------------------------------*
118
* encoding of start state
119
*---------------------------------------------------------------*/
122
iLBC_Enc_Inst_t *iLBCenc_inst,
123
/* (i) Encoder instance */
124
float *residual,/* (i) target residual vector */
125
float *syntDenum, /* (i) lpc synthesis filter */
126
float *weightDenum, /* (i) weighting filter denuminator */
127
int *idxForMax, /* (o) quantizer index for maximum
129
int *idxVec, /* (o) vector of quantization indexes */
130
int len, /* (i) length of all vectors */
131
int state_first /* (i) position of start state in the
135
float tmpbuf[LPC_FILTERORDER+2*STATE_SHORT_LEN_30MS];
136
float *tmp, numerator[1+LPC_FILTERORDER];
137
float foutbuf[LPC_FILTERORDER+2*STATE_SHORT_LEN_30MS], *fout;
141
/* initialization of buffers and filter coefficients */
143
memset(tmpbuf, 0, LPC_FILTERORDER*sizeof(float));
144
memset(foutbuf, 0, LPC_FILTERORDER*sizeof(float));
145
for (k=0; k<LPC_FILTERORDER; k++) {
146
numerator[k]=syntDenum[LPC_FILTERORDER-k];
148
numerator[LPC_FILTERORDER]=syntDenum[0];
149
tmp = &tmpbuf[LPC_FILTERORDER];
150
fout = &foutbuf[LPC_FILTERORDER];
152
/* circular convolution with the all-pass filter */
159
memcpy(tmp, residual, len*sizeof(float));
160
memset(tmp+len, 0, len*sizeof(float));
161
ZeroPoleFilter(tmp, numerator, syntDenum, 2*len,
162
LPC_FILTERORDER, fout);
163
for (k=0; k<len; k++) {
164
fout[k] += fout[k+len];
167
/* identification of the maximum amplitude value */
170
for (k=1; k<len; k++) {
172
if (fout[k]*fout[k] > maxVal*maxVal){
176
maxVal=(float)fabs(maxVal);
178
/* encoding of the maximum amplitude value */
183
maxVal = (float)log10(maxVal);
184
sort_sq(&dtmp, idxForMax, maxVal, state_frgqTbl, 64);
186
/* decoding of the maximum amplitude representation value,
187
and corresponding scaling of start state */
189
maxVal=state_frgqTbl[*idxForMax];
190
qmax = (float)pow(10,maxVal);
191
scal = (float)(4.5)/qmax;
192
for (k=0; k<len; k++){
196
/* predictive noise shaping encoding of scaled start state */
198
AbsQuantW(iLBCenc_inst, fout,syntDenum,
199
weightDenum,idxVec, len, state_first);