Make file access in cdr_custom similar to cdr_csv.
[asterisk-bristuff.git] / codecs / ilbc / StateConstructW.c
blobe48fe035d4a64b8adce238ea25f7ee036d662011
2 /******************************************************************
6 iLBC Speech Coder ANSI-C Source Code
8 StateConstructW.c
10 Copyright (C) The Internet Society (2004).
11 All Rights Reserved.
13 ******************************************************************/
15 #include <math.h>
16 #include <string.h>
18 #include "iLBC_define.h"
19 #include "StateConstructW.h"
20 #include "constants.h"
21 #include "filter.h"
23 /*----------------------------------------------------------------*
24 * decoding of the start state
25 *---------------------------------------------------------------*/
27 void StateConstructW(
28 int idxForMax, /* (i) 6-bit index for the quantization of
29 max amplitude */
30 int *idxVec, /* (i) vector of quantization indexes */
31 float *syntDenum, /* (i) synthesis filter denumerator */
32 float *out, /* (o) the decoded state vector */
33 int len /* (i) length of a state vector */
35 float maxVal, tmpbuf[LPC_FILTERORDER+2*STATE_LEN], *tmp,
36 numerator[LPC_FILTERORDER+1];
37 float foutbuf[LPC_FILTERORDER+2*STATE_LEN], *fout;
38 int k,tmpi;
40 /* decoding of the maximum value */
42 maxVal = state_frgqTbl[idxForMax];
43 maxVal = (float)pow(10,maxVal)/(float)4.5;
45 /* initialization of buffers and coefficients */
47 memset(tmpbuf, 0, LPC_FILTERORDER*sizeof(float));
48 memset(foutbuf, 0, LPC_FILTERORDER*sizeof(float));
49 for (k=0; k<LPC_FILTERORDER; k++) {
50 numerator[k]=syntDenum[LPC_FILTERORDER-k];
52 numerator[LPC_FILTERORDER]=syntDenum[0];
53 tmp = &tmpbuf[LPC_FILTERORDER];
54 fout = &foutbuf[LPC_FILTERORDER];
56 /* decoding of the sample values */
58 for (k=0; k<len; k++) {
59 tmpi = len-1-k;
60 /* maxVal = 1/scal */
63 tmp[k] = maxVal*state_sq3Tbl[idxVec[tmpi]];
66 /* circular convolution with all-pass filter */
68 memset(tmp+len, 0, len*sizeof(float));
69 ZeroPoleFilter(tmp, numerator, syntDenum, 2*len,
70 LPC_FILTERORDER, fout);
71 for (k=0;k<len;k++) {
72 out[k] = fout[len-1-k]+fout[2*len-1-k];