Asterisk - The Open Source Telephony Project GIT-master-f36a736
LPCencode.c
Go to the documentation of this file.
1
2 /******************************************************************
3
4 iLBC Speech Coder ANSI-C Source Code
5
6 LPCencode.c
7
8 Copyright (C) The Internet Society (2004).
9 All Rights Reserved.
10
11 ******************************************************************/
12
13 #include <string.h>
14
15 #include "iLBC_define.h"
16 #include "helpfun.h"
17 #include "lsf.h"
18 #include "constants.h"
19
20
21
22
23
24 /*----------------------------------------------------------------*
25 * lpc analysis (subroutine to LPCencode)
26 *---------------------------------------------------------------*/
27
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 */
33 ){
34 int k, is;
35 float temp[BLOCKL_MAX], lp[LPC_FILTERORDER + 1];
36 float lp2[LPC_FILTERORDER + 1];
37 float r[LPC_FILTERORDER + 1];
38
39 is=LPC_LOOKBACK+BLOCKL_MAX-iLBCenc_inst->blockl;
40 memcpy(iLBCenc_inst->lpc_buffer+is,data,
41 iLBCenc_inst->blockl*sizeof(float));
42
43 /* No lookahead, last window is asymmetric */
44
45 for (k = 0; k < iLBCenc_inst->lpc_n; k++) {
46
47 is = LPC_LOOKBACK;
48
49 if (k < (iLBCenc_inst->lpc_n - 1)) {
50 window(temp, lpc_winTbl,
51 iLBCenc_inst->lpc_buffer, BLOCKL_MAX);
52 } else {
54 iLBCenc_inst->lpc_buffer + is, BLOCKL_MAX);
55 }
56
59
60 levdurb(lp, temp, r, LPC_FILTERORDER);
62
63 a2lsf(lsf + k*LPC_FILTERORDER, lp2);
64 }
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,
68 is*sizeof(float));
69 }
70
71 /*----------------------------------------------------------------*
72
73
74
75
76
77 * lsf interpolator and conversion from lsf to a coefficients
78 * (subroutine to SimpleInterpolateLSF)
79 *---------------------------------------------------------------*/
80
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
86 lsf1 and lsf2 */
87 long length /* (i) length of coefficient vectors */
88 ){
89 float lsftmp[LPC_FILTERORDER];
90
91 interpolate(lsftmp, lsf1, lsf2, coef, length);
92 lsf2a(a, lsftmp);
93 }
94
95 /*----------------------------------------------------------------*
96 * lsf interpolator (subroutine to LPCencode)
97 *---------------------------------------------------------------*/
98
100 float *syntdenum, /* (o) the synthesis filter denominator
101 resulting from the quantized
102 interpolated lsf */
103 float *weightdenum, /* (o) the weighting filter denominator
104 resulting from the unquantized
105 interpolated lsf */
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 */
115 ){
116 int i, pos, lp_length;
117 float lp[LPC_FILTERORDER + 1], *lsf2, *lsfdeq2;
118
119 lsf2 = lsf + length;
120 lsfdeq2 = lsfdeq + length;
121 lp_length = length + 1;
122
123 if (iLBCenc_inst->mode==30) {
124 /* sub-frame 1: Interpolation between old and first
125
126
127
128
129
130 set of lsf coefficients */
131
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);
138
139 /* sub-frame 2 to 6: Interpolation between first
140 and second set of lsf coefficients */
141
142 pos = lp_length;
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));
147
148 LSFinterpolate2a_enc(lp, lsf, lsf2,
149 lsf_weightTbl_30ms[i], length);
150 bwexpand(weightdenum + pos, lp,
151 LPC_CHIRP_WEIGHTDENUM, lp_length);
152 pos += lp_length;
153 }
154 }
155 else {
156 pos = 0;
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);
165 pos += lp_length;
166 }
167 }
168
169 /* update memory */
170
171 if (iLBCenc_inst->mode==30) {
172 memcpy(lsfold, lsf2, length*sizeof(float));
173 memcpy(lsfdeqold, lsfdeq2, length*sizeof(float));
174 }
175 else {
176 memcpy(lsfold, lsf, length*sizeof(float));
177 memcpy(lsfdeqold, lsfdeq, length*sizeof(float));
178
179
180
181
182
183 }
184 }
185
186 /*----------------------------------------------------------------*
187 * lsf quantizer (subroutine to LPCencode)
188 *---------------------------------------------------------------*/
189
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 */
197 ){
198 /* Quantize first LSF with memoryless split VQ */
199 SplitVQ(lsfdeq, index, lsf, lsfCbTbl, LSF_NSPLIT,
201
202 if (lpc_n==2) {
203 /* Quantize second LSF with memoryless split VQ */
204 SplitVQ(lsfdeq + LPC_FILTERORDER, index + LSF_NSPLIT,
207 }
208 }
209
210 /*----------------------------------------------------------------*
211 * lpc encoder
212 *---------------------------------------------------------------*/
213
215 float *syntdenum, /* (i/o) synthesis filter coefficients
216 before/after encoding */
217 float *weightdenum, /* (i/o) weighting denumerator
218 coefficients before/after
219 encoding */
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 */
224 ){
225 float lsf[LPC_FILTERORDER * LPC_N_MAX];
226 float lsfdeq[LPC_FILTERORDER * LPC_N_MAX];
227
228 SimpleAnalysis(lsf, data, iLBCenc_inst);
229 SimplelsfQ(lsfdeq, lsf_index, lsf, iLBCenc_inst->lpc_n);
230
231
232
233
234 LSF_check(lsfdeq, LPC_FILTERORDER, iLBCenc_inst->lpc_n);
235 SimpleInterpolateLSF(syntdenum, weightdenum,
236 lsf, lsfdeq, iLBCenc_inst->lsfold,
237 iLBCenc_inst->lsfdeqold, LPC_FILTERORDER, iLBCenc_inst);
238 }
void SimpleAnalysis(float *lsf, float *data, iLBC_Enc_Inst_t *iLBCenc_inst)
Definition: LPCencode.c:28
void SimplelsfQ(float *lsfdeq, int *index, float *lsf, int lpc_n)
Definition: LPCencode.c:190
void SimpleInterpolateLSF(float *syntdenum, float *weightdenum, float *lsf, float *lsfdeq, float *lsfold, float *lsfdeqold, int length, iLBC_Enc_Inst_t *iLBCenc_inst)
Definition: LPCencode.c:99
void LPCencode(float *syntdenum, float *weightdenum, int *lsf_index, float *data, iLBC_Enc_Inst_t *iLBCenc_inst)
Definition: LPCencode.c:214
void LSFinterpolate2a_enc(float *a, float *lsf1, float *lsf2, float coef, long length)
Definition: LPCencode.c:81
float lpc_winTbl[BLOCKL_MAX]
Definition: constants.c:224
float lsf_weightTbl_20ms[4]
Definition: constants.c:220
int size_lsfCbTbl[LSF_NSPLIT]
Definition: constants.c:203
int dim_lsfCbTbl[LSF_NSPLIT]
Definition: constants.c:202
float lpc_asymwinTbl[BLOCKL_MAX]
Definition: constants.c:317
float lsfCbTbl[64 *3+128 *3+128 *4]
Definition: constants.c:413
float lsf_weightTbl_30ms[6]
Definition: constants.c:216
float lpc_lagwinTbl[LPC_FILTERORDER+1]
Definition: constants.c:406
char window[WINSIZE]
Definition: eagi_proxy.c:69
int LSF_check(float *lsf, int dim, int NoAn)
Definition: helpfun.c:272
void SplitVQ(float *qX, int *index, float *X, const float *CB, int nsplit, const int *dim, const int *cbsize)
Definition: helpfun.c:209
void interpolate(float *out, float *in1, float *in2, float coef, int length)
Definition: helpfun.c:114
void autocorr(float *r, const float *x, int N, int order)
Definition: helpfun.c:22
void levdurb(float *a, float *k, float *r, int order)
Definition: helpfun.c:67
void bwexpand(float *out, float *in, float coef, int length)
Definition: helpfun.c:136
#define LPC_CHIRP_SYNTDENUM
Definition: iLBC_define.h:41
#define LPC_LOOKBACK
Definition: iLBC_define.h:43
#define BLOCKL_MAX
Definition: iLBC_define.h:21
#define LPC_FILTERORDER
Definition: iLBC_define.h:40
#define LPC_CHIRP_WEIGHTDENUM
Definition: iLBC_define.h:42
#define LPC_N_MAX
Definition: iLBC_define.h:46
#define LSF_NSPLIT
Definition: iLBC_define.h:50
void a2lsf(float *freq, float *a)
Definition: lsf.c:27
void lsf2a(float *a_coef, float *freq)
Definition: lsf.c:170
float lsfold[LPC_FILTERORDER]
Definition: iLBC_define.h:150
float lpc_buffer[LPC_LOOKBACK+BLOCKL_MAX]
Definition: iLBC_define.h:154
float lsfdeqold[LPC_FILTERORDER]
Definition: iLBC_define.h:151
static struct test_val a