2
/******************************************************************
4
iLBC Speech Coder ANSI-C Source Code
8
Copyright (C) The Internet Society (2004).
11
******************************************************************/
15
#include "iLBC_define.h"
18
#include "constants.h"
24
/*----------------------------------------------------------------*
25
* lpc analysis (subrutine to LPCencode)
26
*---------------------------------------------------------------*/
29
float *lsf, /* (o) lsf coefficients */
30
float *data, /* (i) new data vector */
31
iLBC_Enc_Inst_t *iLBCenc_inst
32
/* (i/o) the encoder state structure */
35
float temp[BLOCKL_MAX], lp[LPC_FILTERORDER + 1];
36
float lp2[LPC_FILTERORDER + 1];
37
float r[LPC_FILTERORDER + 1];
39
is=LPC_LOOKBACK+BLOCKL_MAX-iLBCenc_inst->blockl;
40
memcpy(iLBCenc_inst->lpc_buffer+is,data,
41
iLBCenc_inst->blockl*sizeof(float));
43
/* No lookahead, last window is asymmetric */
45
for (k = 0; k < iLBCenc_inst->lpc_n; k++) {
49
if (k < (iLBCenc_inst->lpc_n - 1)) {
50
window(temp, lpc_winTbl,
51
iLBCenc_inst->lpc_buffer, BLOCKL_MAX);
53
window(temp, lpc_asymwinTbl,
54
iLBCenc_inst->lpc_buffer + is, BLOCKL_MAX);
57
autocorr(r, temp, BLOCKL_MAX, LPC_FILTERORDER);
58
window(r, r, lpc_lagwinTbl, LPC_FILTERORDER + 1);
60
levdurb(lp, temp, r, LPC_FILTERORDER);
61
bwexpand(lp2, lp, LPC_CHIRP_SYNTDENUM, LPC_FILTERORDER+1);
63
a2lsf(lsf + k*LPC_FILTERORDER, lp2);
65
is=LPC_LOOKBACK+BLOCKL_MAX-iLBCenc_inst->blockl;
66
memmove(iLBCenc_inst->lpc_buffer,
67
iLBCenc_inst->lpc_buffer+LPC_LOOKBACK+BLOCKL_MAX-is,
71
/*----------------------------------------------------------------*
77
* lsf interpolator and conversion from lsf to a coefficients
78
* (subrutine to SimpleInterpolateLSF)
79
*---------------------------------------------------------------*/
81
void LSFinterpolate2a_enc(
82
float *a, /* (o) lpc coefficients */
83
float *lsf1,/* (i) first set of lsf coefficients */
84
float *lsf2,/* (i) second set of lsf coefficients */
85
float coef, /* (i) weighting coefficient to use between
87
long length /* (i) length of coefficient vectors */
89
float lsftmp[LPC_FILTERORDER];
91
interpolate(lsftmp, lsf1, lsf2, coef, length);
95
/*----------------------------------------------------------------*
96
* lsf interpolator (subrutine to LPCencode)
97
*---------------------------------------------------------------*/
99
void SimpleInterpolateLSF(
100
float *syntdenum, /* (o) the synthesis filter denominator
101
resulting from the quantized
103
float *weightdenum, /* (o) the weighting filter denominator
104
resulting from the unquantized
106
float *lsf, /* (i) the unquantized lsf coefficients */
107
float *lsfdeq, /* (i) the dequantized lsf coefficients */
108
float *lsfold, /* (i) the unquantized lsf coefficients of
109
the previous signal frame */
110
float *lsfdeqold, /* (i) the dequantized lsf coefficients of
111
the previous signal frame */
112
int length, /* (i) should equate LPC_FILTERORDER */
113
iLBC_Enc_Inst_t *iLBCenc_inst
114
/* (i/o) the encoder state structure */
116
int i, pos, lp_length;
117
float lp[LPC_FILTERORDER + 1], *lsf2, *lsfdeq2;
120
lsfdeq2 = lsfdeq + length;
121
lp_length = length + 1;
123
if (iLBCenc_inst->mode==30) {
124
/* sub-frame 1: Interpolation between old and first
130
set of lsf coefficients */
132
LSFinterpolate2a_enc(lp, lsfdeqold, lsfdeq,
133
lsf_weightTbl_30ms[0], length);
134
memcpy(syntdenum,lp,lp_length*sizeof(float));
135
LSFinterpolate2a_enc(lp, lsfold, lsf,
136
lsf_weightTbl_30ms[0], length);
137
bwexpand(weightdenum, lp, LPC_CHIRP_WEIGHTDENUM, lp_length);
139
/* sub-frame 2 to 6: Interpolation between first
140
and second set of lsf coefficients */
143
for (i = 1; i < iLBCenc_inst->nsub; i++) {
144
LSFinterpolate2a_enc(lp, lsfdeq, lsfdeq2,
145
lsf_weightTbl_30ms[i], length);
146
memcpy(syntdenum + pos,lp,lp_length*sizeof(float));
148
LSFinterpolate2a_enc(lp, lsf, lsf2,
149
lsf_weightTbl_30ms[i], length);
150
bwexpand(weightdenum + pos, lp,
151
LPC_CHIRP_WEIGHTDENUM, lp_length);
157
for (i = 0; i < iLBCenc_inst->nsub; i++) {
158
LSFinterpolate2a_enc(lp, lsfdeqold, lsfdeq,
159
lsf_weightTbl_20ms[i], length);
160
memcpy(syntdenum+pos,lp,lp_length*sizeof(float));
161
LSFinterpolate2a_enc(lp, lsfold, lsf,
162
lsf_weightTbl_20ms[i], length);
163
bwexpand(weightdenum+pos, lp,
164
LPC_CHIRP_WEIGHTDENUM, lp_length);
171
if (iLBCenc_inst->mode==30) {
172
memcpy(lsfold, lsf2, length*sizeof(float));
173
memcpy(lsfdeqold, lsfdeq2, length*sizeof(float));
176
memcpy(lsfold, lsf, length*sizeof(float));
177
memcpy(lsfdeqold, lsfdeq, length*sizeof(float));
186
/*----------------------------------------------------------------*
187
* lsf quantizer (subrutine to LPCencode)
188
*---------------------------------------------------------------*/
191
float *lsfdeq, /* (o) dequantized lsf coefficients
192
(dimension FILTERORDER) */
193
int *index, /* (o) quantization index */
194
float *lsf, /* (i) the lsf coefficient vector to be
195
quantized (dimension FILTERORDER ) */
196
int lpc_n /* (i) number of lsf sets to quantize */
198
/* Quantize first LSF with memoryless split VQ */
199
SplitVQ(lsfdeq, index, lsf, lsfCbTbl, LSF_NSPLIT,
200
dim_lsfCbTbl, size_lsfCbTbl);
203
/* Quantize second LSF with memoryless split VQ */
204
SplitVQ(lsfdeq + LPC_FILTERORDER, index + LSF_NSPLIT,
205
lsf + LPC_FILTERORDER, lsfCbTbl, LSF_NSPLIT,
206
dim_lsfCbTbl, size_lsfCbTbl);
210
/*----------------------------------------------------------------*
212
*---------------------------------------------------------------*/
215
float *syntdenum, /* (i/o) synthesis filter coefficients
216
before/after encoding */
217
float *weightdenum, /* (i/o) weighting denumerator
218
coefficients before/after
220
int *lsf_index, /* (o) lsf quantization index */
221
float *data, /* (i) lsf coefficients to quantize */
222
iLBC_Enc_Inst_t *iLBCenc_inst
223
/* (i/o) the encoder state structure */
225
float lsf[LPC_FILTERORDER * LPC_N_MAX];
226
float lsfdeq[LPC_FILTERORDER * LPC_N_MAX];
229
SimpleAnalysis(lsf, data, iLBCenc_inst);
230
SimplelsfQ(lsfdeq, lsf_index, lsf, iLBCenc_inst->lpc_n);
236
change=LSF_check(lsfdeq, LPC_FILTERORDER, iLBCenc_inst->lpc_n);
237
SimpleInterpolateLSF(syntdenum, weightdenum,
238
lsf, lsfdeq, iLBCenc_inst->lsfold,
239
iLBCenc_inst->lsfdeqold, LPC_FILTERORDER, iLBCenc_inst);