Initialize Tizen 2.3
[external/opencore-amr.git] / opencore / codecs_v2 / audio / gsm_amr / amr_wb / dec / src / pred_lt4.cpp
1 /* ------------------------------------------------------------------
2  * Copyright (C) 1998-2009 PacketVideo
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
13  * express or implied.
14  * See the License for the specific language governing permissions
15  * and limitations under the License.
16  * -------------------------------------------------------------------
17  */
18 /****************************************************************************************
19 Portions of this file are derived from the following 3GPP standard:
20
21     3GPP TS 26.173
22     ANSI-C code for the Adaptive Multi-Rate - Wideband (AMR-WB) speech codec
23     Available from http://www.3gpp.org
24
25 (C) 2007, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
26 Permission to distribute, modify and use this file under the standard license
27 terms listed above has been obtained from the copyright holder.
28 ****************************************************************************************/
29 /*
30 ------------------------------------------------------------------------------
31
32
33
34  Filename: pred_lt4.cpp
35
36 ------------------------------------------------------------------------------
37  INPUT AND OUTPUT DEFINITIONS
38
39      int16 signal[],             input signal / output is divided by 16
40      int16 lg,                   lenght of signal
41      int16 mem[]                 in/out: memory (size=30)
42      int16 x[]                   scratch mem ( size= 60)
43
44 ------------------------------------------------------------------------------
45  FUNCTION DESCRIPTION
46
47    Compute the result of long term prediction with fractionnal
48    interpolation of resolution 1/4.
49
50    On return exc[0..L_subfr-1] contains the interpolated signal
51      (adaptive codebook excitation)
52
53
54 ------------------------------------------------------------------------------
55  REQUIREMENTS
56
57
58 ------------------------------------------------------------------------------
59  REFERENCES
60
61 ------------------------------------------------------------------------------
62  PSEUDO-CODE
63
64 ------------------------------------------------------------------------------
65 */
66
67
68 /*----------------------------------------------------------------------------
69 ; INCLUDES
70 ----------------------------------------------------------------------------*/
71
72 #include "pv_amr_wb_type_defs.h"
73 #include "pvamrwbdecoder_basic_op.h"
74 #include "pvamrwbdecoder_acelp.h"
75
76 /*----------------------------------------------------------------------------
77 ; MACROS
78 ; Define module specific macros here
79 ----------------------------------------------------------------------------*/
80
81
82 /*----------------------------------------------------------------------------
83 ; DEFINES
84 ; Include all pre-processor statements here. Include conditional
85 ; compile variables also.
86 ----------------------------------------------------------------------------*/
87
88 #define UP_SAMP      4
89 #define L_INTERPOL2  16
90
91 /*----------------------------------------------------------------------------
92 ; LOCAL FUNCTION DEFINITIONS
93 ; Function Prototype declaration
94 ----------------------------------------------------------------------------*/
95
96 /*----------------------------------------------------------------------------
97 ; LOCAL STORE/BUFFER/POINTER DEFINITIONS
98 ; Variable declaration - defined here and used outside this module
99 ----------------------------------------------------------------------------*/
100
101 /* 1/4 resolution interpolation filter (-3 dB at 0.856*fs/2) in Q14 */
102
103
104 const int16 inter4_2[UP_SAMP][ 2*L_INTERPOL2] =
105 {
106     {
107         0,       -2,        4,       -2,      -10,       38,
108         -88,      165,     -275,      424,     -619,      871,
109         -1207,     1699,    -2598,     5531,    14031,    -2147,
110         780,     -249,      -16,      153,     -213,      226,
111         -209,      175,     -133,       91,      -55,       28,
112         -10,        2
113     },
114     {
115         1,       -7,       19,      -33,       47,      -52,
116         43,       -9,      -60,      175,     -355,      626,
117         -1044,     1749,    -3267,    10359,    10359,    -3267,
118         1749,    -1044,      626,     -355,      175,      -60,
119         -9,       43,      -52,       47,      -33,       19,
120         -7,        1
121     },
122     {
123         2,      -10,       28,      -55,       91,     -133,
124         175,     -209,      226,     -213,      153,      -16,
125         -249,      780,    -2147,    14031,     5531,    -2598,
126         1699,    -1207,      871,     -619,      424,     -275,
127         165,      -88,       38,      -10,       -2,        4,
128         -2,        0
129     },
130     {
131         1,       -7,       22,      -49,       92,     -153,
132         231,     -325,      431,     -544,      656,     -762,
133         853,     -923,      968,    15401,      968,     -923,
134         853,     -762,      656,     -544,      431,     -325,
135         231,     -153,       92,      -49,       22,       -7,
136         1,        0
137     }
138 };
139
140 /*----------------------------------------------------------------------------
141 ; EXTERNAL FUNCTION REFERENCES
142 ; Declare functions defined elsewhere and referenced in this module
143 ----------------------------------------------------------------------------*/
144
145 /*----------------------------------------------------------------------------
146 ; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
147 ; Declare variables used in this module but defined elsewhere
148 ----------------------------------------------------------------------------*/
149
150 /*----------------------------------------------------------------------------
151 ; FUNCTION CODE
152 ----------------------------------------------------------------------------*/
153
154 void Pred_lt4(
155     int16 exc[],                         /* in/out: excitation buffer */
156     int16 T0,                            /* input : integer pitch lag */
157     int16 frac,                          /* input : fraction of lag   */
158     int16 L_subfr                        /* input : subframe size     */
159 )
160 {
161     int16 i, j, *pt_exc;
162     int32 L_sum1;
163     int32 L_sum2;
164     int32 L_sum3;
165     int32 L_sum4;
166     pt_exc = &exc[-T0];
167
168     const int16 *pt_inter4_2;
169
170     frac = -frac;
171
172     if (frac < 0)
173     {
174         frac += UP_SAMP;
175         pt_exc--;
176
177     }
178     pt_exc -= (L_INTERPOL2 - 1);
179
180     pt_inter4_2 = inter4_2[UP_SAMP-1 - frac];
181
182     for (j = 0; j < (L_subfr >> 2); j++)
183     {
184
185         L_sum1 = 0x00002000;  /* pre-roundig */
186         L_sum2 = 0x00002000;
187         L_sum3 = 0x00002000;
188         L_sum4 = 0x00002000;
189
190         for (i = 0; i < L_INTERPOL2 << 1; i += 4)
191         {
192             int16 tmp1 = pt_exc[i  ];
193             int16 tmp2 = pt_exc[i+1];
194             int16 tmp3 = pt_exc[i+2];
195
196
197             L_sum1 = fxp_mac_16by16(tmp1, pt_inter4_2[i  ], L_sum1);
198             L_sum2 = fxp_mac_16by16(tmp2, pt_inter4_2[i  ], L_sum2);
199             L_sum1 = fxp_mac_16by16(tmp2, pt_inter4_2[i+1], L_sum1);
200             L_sum2 = fxp_mac_16by16(tmp3, pt_inter4_2[i+1], L_sum2);
201             L_sum3 = fxp_mac_16by16(tmp3, pt_inter4_2[i  ], L_sum3);
202             L_sum1 = fxp_mac_16by16(tmp3, pt_inter4_2[i+2], L_sum1);
203
204             tmp1 = pt_exc[i+3];
205             tmp2 = pt_exc[i+4];
206
207             L_sum4 = fxp_mac_16by16(tmp1, pt_inter4_2[i  ], L_sum4);
208             L_sum3 = fxp_mac_16by16(tmp1, pt_inter4_2[i+1], L_sum3);
209             L_sum2 = fxp_mac_16by16(tmp1, pt_inter4_2[i+2], L_sum2);
210             L_sum1 = fxp_mac_16by16(tmp1, pt_inter4_2[i+3], L_sum1);
211             L_sum4 = fxp_mac_16by16(tmp2, pt_inter4_2[i+1], L_sum4);
212             L_sum2 = fxp_mac_16by16(tmp2, pt_inter4_2[i+3], L_sum2);
213             L_sum3 = fxp_mac_16by16(tmp2, pt_inter4_2[i+2], L_sum3);
214
215             tmp1 = pt_exc[i+5];
216             tmp2 = pt_exc[i+6];
217
218             L_sum4 = fxp_mac_16by16(tmp1, pt_inter4_2[i+2], L_sum4);
219             L_sum3 = fxp_mac_16by16(tmp1, pt_inter4_2[i+3], L_sum3);
220             L_sum4 = fxp_mac_16by16(tmp2, pt_inter4_2[i+3], L_sum4);
221
222         }
223
224
225
226         exc[(j<<2)] = (int16)(L_sum1 >> 14);
227         exc[(j<<2)+1] = (int16)(L_sum2 >> 14);
228         exc[(j<<2)+2] = (int16)(L_sum3 >> 14);
229         exc[(j<<2)+3] = (int16)(L_sum4 >> 14);
230
231         pt_exc += 4;
232
233     }
234
235     if (L_subfr&1)
236     {
237         L_sum1 = 0x00002000;
238
239         for (i = 0; i < 2*L_INTERPOL2; i += 4)
240         {
241             int16 tmp1 = pt_exc[i  ];
242             int16 tmp2 = pt_exc[i+1];
243             L_sum1 = fxp_mac_16by16(tmp1, pt_inter4_2[i  ], L_sum1);
244             L_sum1 = fxp_mac_16by16(tmp2, pt_inter4_2[i+1], L_sum1);
245             tmp1 = pt_exc[i+2];
246             tmp2 = pt_exc[i+3];
247             L_sum1 = fxp_mac_16by16(tmp1, pt_inter4_2[i+2], L_sum1);
248             L_sum1 = fxp_mac_16by16(tmp2, pt_inter4_2[i+3], L_sum1);
249
250         }
251
252         exc[(j<<2)] = (int16)((L_sum1) >> 14);
253
254     }
255
256
257     return;
258 }
259