Asterisk - The Open Source Telephony Project GIT-master-1f1c5bb
Functions
helpfun.c File Reference
#include <math.h>
#include "iLBC_define.h"
#include "constants.h"
Include dependency graph for helpfun.c:

Go to the source code of this file.

Functions

void autocorr (float *r, const float *x, int N, int order)
 
void bwexpand (float *out, float *in, float coef, int length)
 
void interpolate (float *out, float *in1, float *in2, float coef, int length)
 
void levdurb (float *a, float *k, float *r, int order)
 
int LSF_check (float *lsf, int dim, int NoAn)
 
void sort_sq (float *xq, int *index, float x, const float *cb, int cb_size)
 
void SplitVQ (float *qX, int *index, float *X, const float *CB, int nsplit, const int *dim, const int *cbsize)
 
void vq (float *Xq, int *index, const float *CB, float *X, int n_cb, int dim)
 
void window (float *z, const float *x, const float *y, int N)
 

Function Documentation

◆ autocorr()

void autocorr ( float *  r,
const float *  x,
int  N,
int  order 
)

Definition at line 22 of file helpfun.c.

28 {
29 int lag, n;
30 float sum;
31
32 for (lag = 0; lag <= order; lag++) {
33 sum = 0;
34 for (n = 0; n < N - lag; n++) {
35 sum += x[n] * x[n+lag];
36 }
37 r[lag] = sum;
38 }
39
40
41
42
43
44 }
integer order
Definition: analys.c:66

References order.

Referenced by SimpleAnalysis().

◆ bwexpand()

void bwexpand ( float *  out,
float *  in,
float  coef,
int  length 
)

Definition at line 136 of file helpfun.c.

143 {
144 int i;
145
146
147
148
149
150 float chirp;
151
152 chirp = coef;
153
154 out[0] = in[0];
155 for (i = 1; i < length; i++) {
156 out[i] = chirp * in[i];
157 chirp *= coef;
158 }
159 }
FILE * out
Definition: utils/frame.c:33
FILE * in
Definition: utils/frame.c:33

References in, and out.

Referenced by DecoderInterpolateLSF(), SimpleAnalysis(), and SimpleInterpolateLSF().

◆ interpolate()

void interpolate ( float *  out,
float *  in1,
float *  in2,
float  coef,
int  length 
)

Definition at line 114 of file helpfun.c.

122 {
123 int i;
124 float invcoef;
125
126 invcoef = (float)1.0 - coef;
127 for (i = 0; i < length; i++) {
128 out[i] = coef * in1[i] + invcoef * in2[i];
129 }
130 }

References out.

Referenced by LSFinterpolate2a_dec(), and LSFinterpolate2a_enc().

◆ levdurb()

void levdurb ( float *  a,
float *  k,
float *  r,
int  order 
)

Definition at line 67 of file helpfun.c.

73 {
74 float sum, alpha;
75 int m, m_h, i;
76
77 a[0] = 1.0;
78
79 if (r[0] < EPS) { /* if r[0] <= 0, set LPC coeff. to zero */
80 for (i = 0; i < order; i++) {
81 k[i] = 0;
82 a[i+1] = 0;
83 }
84 } else {
85 a[1] = k[0] = -r[1]/r[0];
86 alpha = r[0] + r[1] * k[0];
87 for (m = 1; m < order; m++){
88 sum = r[m + 1];
89 for (i = 0; i < m; i++){
90 sum += a[i+1] * r[m - i];
91 }
92
93
94
95
96
97 k[m] = -sum / alpha;
98 alpha += k[m] * sum;
99 m_h = (m + 1) >> 1;
100 for (i = 0; i < m_h; i++){
101 sum = a[i+1] + k[m] * a[m - i];
102 a[m - i] += k[m] * a[i+1];
103 a[i+1] = sum;
104 }
105 a[m+1] = k[m];
106 }
107 }
108 }
#define EPS
Definition: iLBC_define.h:106
static struct test_val a

References a, EPS, and order.

Referenced by SimpleAnalysis().

◆ LSF_check()

int LSF_check ( float *  lsf,
int  dim,
int  NoAn 
)

Definition at line 272 of file helpfun.c.

278 {
279 int k,n,m, Nit=2, change=0,pos;
280 static float eps=(float)0.039; /* 50 Hz */
281 static float eps2=(float)0.0195;
282 static float maxlsf=(float)3.14; /* 4000 Hz */
283 static float minlsf=(float)0.01; /* 0 Hz */
284
285 /* LSF separation check*/
286
287 for (n=0; n<Nit; n++) { /* Run through a couple of times */
288 for (m=0; m<NoAn; m++) { /* Number of analyses per frame */
289 for (k=0; k<(dim-1); k++) {
290 pos=m*dim+k;
291
292 if ((lsf[pos+1]-lsf[pos])<eps) {
293
294 if (lsf[pos+1]<lsf[pos]) {
295 lsf[pos+1]= lsf[pos]+eps2;
296 lsf[pos]= lsf[pos+1]-eps2;
297 } else {
298 lsf[pos]-=eps2;
299 lsf[pos+1]+=eps2;
300 }
301 change=1;
302
303
304
305
306
307 }
308
309 if (lsf[pos]<minlsf) {
310 lsf[pos]=minlsf;
311 change=1;
312 }
313
314 if (lsf[pos]>maxlsf) {
315 lsf[pos]=maxlsf;
316 change=1;
317 }
318 }
319 }
320 }
321
322 return change;
323 }

Referenced by iLBC_decode(), and LPCencode().

◆ sort_sq()

void sort_sq ( float *  xq,
int *  index,
float  x,
const float *  cb,
int  cb_size 
)

Definition at line 235 of file helpfun.c.

241 {
242 int i;
243
244 if (x <= cb[0]) {
245 *index = 0;
246 *xq = cb[0];
247 } else {
248 i = 0;
249 while ((x > cb[i]) && i < cb_size - 1) {
250 i++;
251
252
253
254
255
256 }
257
258 if (x > ((cb[i] + cb[i - 1])/2)) {
259 *index = i;
260 *xq = cb[i];
261 } else {
262 *index = i - 1;
263 *xq = cb[i - 1];
264 }
265 }
266 }

Referenced by AbsQuantW(), and StateSearchW().

◆ SplitVQ()

void SplitVQ ( float *  qX,
int *  index,
float *  X,
const float *  CB,
int  nsplit,
const int *  dim,
const int *  cbsize 
)

Definition at line 209 of file helpfun.c.

218 {
219 int cb_pos, X_pos, i;
220
221 cb_pos = 0;
222 X_pos= 0;
223 for (i = 0; i < nsplit; i++) {
224 vq(qX + X_pos, index + i, CB + cb_pos, X + X_pos,
225 cbsize[i], dim[i]);
226 X_pos += dim[i];
227 cb_pos += dim[i] * cbsize[i];
228 }
229 }
void vq(float *Xq, int *index, const float *CB, float *X, int n_cb, int dim)
Definition: helpfun.c:165

References vq().

Referenced by SimplelsfQ().

◆ vq()

void vq ( float *  Xq,
int *  index,
const float *  CB,
float *  X,
int  n_cb,
int  dim 
)

Definition at line 165 of file helpfun.c.

172 {
173 int i, j;
174 int pos, minindex;
175 float dist, tmp, mindist;
176
177 pos = 0;
178 mindist = FLOAT_MAX;
179 minindex = 0;
180 for (j = 0; j < n_cb; j++) {
181 dist = X[0] - CB[pos];
182 dist *= dist;
183 for (i = 1; i < dim; i++) {
184 tmp = X[i] - CB[pos + i];
185 dist += tmp*tmp;
186 }
187
188 if (dist < mindist) {
189 mindist = dist;
190 minindex = j;
191 }
192 pos += dim;
193 }
194 for (i = 0; i < dim; i++) {
195 Xq[i] = CB[minindex*dim + i];
196 }
197 *index = minindex;
198
199
200
201
202
203 }
static int tmp()
Definition: bt_open.c:389
#define FLOAT_MAX
Definition: iLBC_define.h:105

References FLOAT_MAX, and tmp().

Referenced by SplitVQ().

◆ window()

void window ( float *  z,
const float *  x,
const float *  y,
int  N 
)

Definition at line 50 of file helpfun.c.

55 {
56 int i;
57
58 for (i = 0; i < N; i++) {
59 z[i] = x[i] * y[i];
60 }
61 }