• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *  Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
3  *
4  *  Use of this source code is governed by a BSD-style license
5  *  that can be found in the LICENSE file in the root of the source
6  *  tree. An additional intellectual property rights grant can be found
7  *  in the file PATENTS.  All contributing project authors may
8  *  be found in the AUTHORS file in the root of the source tree.
9  */
10 
11 /******************************************************************
12 
13  iLBC Speech Coder ANSI-C Source Code
14 
15  WebRtcIlbcfix_StateConstruct.c
16 
17 ******************************************************************/
18 
19 #include "defines.h"
20 #include "constants.h"
21 
22 /*----------------------------------------------------------------*
23  *  decoding of the start state
24  *---------------------------------------------------------------*/
25 
WebRtcIlbcfix_StateConstruct(int16_t idxForMax,int16_t * idxVec,int16_t * syntDenum,int16_t * Out_fix,int16_t len)26 void WebRtcIlbcfix_StateConstruct(
27     int16_t idxForMax,   /* (i) 6-bit index for the quantization of
28                                            max amplitude */
29     int16_t *idxVec,   /* (i) vector of quantization indexes */
30     int16_t *syntDenum,  /* (i) synthesis filter denumerator */
31     int16_t *Out_fix,  /* (o) the decoded state vector */
32     int16_t len    /* (i) length of a state vector */
33                                   ) {
34   int k;
35   int16_t maxVal;
36   int16_t *tmp1, *tmp2, *tmp3;
37   /* Stack based */
38   int16_t numerator[1+LPC_FILTERORDER];
39   int16_t sampleValVec[2*STATE_SHORT_LEN_30MS+LPC_FILTERORDER];
40   int16_t sampleMaVec[2*STATE_SHORT_LEN_30MS+LPC_FILTERORDER];
41   int16_t *sampleVal = &sampleValVec[LPC_FILTERORDER];
42   int16_t *sampleMa = &sampleMaVec[LPC_FILTERORDER];
43   int16_t *sampleAr = &sampleValVec[LPC_FILTERORDER];
44 
45   /* initialization of coefficients */
46 
47   for (k=0; k<LPC_FILTERORDER+1; k++){
48     numerator[k] = syntDenum[LPC_FILTERORDER-k];
49   }
50 
51   /* decoding of the maximum value */
52 
53   maxVal = WebRtcIlbcfix_kFrgQuantMod[idxForMax];
54 
55   /* decoding of the sample values */
56   tmp1 = sampleVal;
57   tmp2 = &idxVec[len-1];
58 
59   if (idxForMax<37) {
60     for(k=0; k<len; k++){
61       /*the shifting is due to the Q13 in sq4_fixQ13[i], also the adding of 2097152 (= 0.5 << 22)
62         maxVal is in Q8 and result is in Q(-1) */
63       (*tmp1) = (int16_t) ((WEBRTC_SPL_MUL_16_16(maxVal,WebRtcIlbcfix_kStateSq3[(*tmp2)])+(int32_t)2097152) >> 22);
64       tmp1++;
65       tmp2--;
66     }
67   } else if (idxForMax<59) {
68     for(k=0; k<len; k++){
69       /*the shifting is due to the Q13 in sq4_fixQ13[i], also the adding of 262144 (= 0.5 << 19)
70         maxVal is in Q5 and result is in Q(-1) */
71       (*tmp1) = (int16_t) ((WEBRTC_SPL_MUL_16_16(maxVal,WebRtcIlbcfix_kStateSq3[(*tmp2)])+(int32_t)262144) >> 19);
72       tmp1++;
73       tmp2--;
74     }
75   } else {
76     for(k=0; k<len; k++){
77       /*the shifting is due to the Q13 in sq4_fixQ13[i], also the adding of 65536 (= 0.5 << 17)
78         maxVal is in Q3 and result is in Q(-1) */
79       (*tmp1) = (int16_t) ((WEBRTC_SPL_MUL_16_16(maxVal,WebRtcIlbcfix_kStateSq3[(*tmp2)])+(int32_t)65536) >> 17);
80       tmp1++;
81       tmp2--;
82     }
83   }
84 
85   /* Set the rest of the data to zero */
86   WebRtcSpl_MemSetW16(&sampleVal[len], 0, len);
87 
88   /* circular convolution with all-pass filter */
89 
90   /* Set the state to zero */
91   WebRtcSpl_MemSetW16(sampleValVec, 0, (LPC_FILTERORDER));
92 
93   /* Run MA filter + AR filter */
94   WebRtcSpl_FilterMAFastQ12(
95       sampleVal, sampleMa,
96       numerator, LPC_FILTERORDER+1, (int16_t)(len + LPC_FILTERORDER));
97   WebRtcSpl_MemSetW16(&sampleMa[len + LPC_FILTERORDER], 0, (len - LPC_FILTERORDER));
98   WebRtcSpl_FilterARFastQ12(
99       sampleMa, sampleAr,
100       syntDenum, LPC_FILTERORDER+1, (int16_t)(2*len));
101 
102   tmp1 = &sampleAr[len-1];
103   tmp2 = &sampleAr[2*len-1];
104   tmp3 = Out_fix;
105   for(k=0;k<len;k++){
106     (*tmp3) = (*tmp1) + (*tmp2);
107     tmp1--;
108     tmp2--;
109     tmp3++;
110   }
111 }
112