• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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      Date: 05/08/2004
37 
38 ------------------------------------------------------------------------------
39  REVISION HISTORY
40 
41 
42  Description:
43 
44 ------------------------------------------------------------------------------
45  INPUT AND OUTPUT DEFINITIONS
46 
47      int16 signal[],             input signal / output is divided by 16
48      int16 lg,                   lenght of signal
49      int16 mem[]                 in/out: memory (size=30)
50      int16 x[]                   scratch mem ( size= 60)
51 
52 ------------------------------------------------------------------------------
53  FUNCTION DESCRIPTION
54 
55    Compute the result of long term prediction with fractionnal
56    interpolation of resolution 1/4.
57 
58    On return exc[0..L_subfr-1] contains the interpolated signal
59      (adaptive codebook excitation)
60 
61 
62 ------------------------------------------------------------------------------
63  REQUIREMENTS
64 
65 
66 ------------------------------------------------------------------------------
67  REFERENCES
68 
69 ------------------------------------------------------------------------------
70  PSEUDO-CODE
71 
72 ------------------------------------------------------------------------------
73 */
74 
75 
76 /*----------------------------------------------------------------------------
77 ; INCLUDES
78 ----------------------------------------------------------------------------*/
79 
80 #include "pv_amr_wb_type_defs.h"
81 #include "pvamrwbdecoder_basic_op.h"
82 #include "pvamrwbdecoder_acelp.h"
83 
84 /*----------------------------------------------------------------------------
85 ; MACROS
86 ; Define module specific macros here
87 ----------------------------------------------------------------------------*/
88 
89 
90 /*----------------------------------------------------------------------------
91 ; DEFINES
92 ; Include all pre-processor statements here. Include conditional
93 ; compile variables also.
94 ----------------------------------------------------------------------------*/
95 
96 #define UP_SAMP      4
97 #define L_INTERPOL2  16
98 
99 /*----------------------------------------------------------------------------
100 ; LOCAL FUNCTION DEFINITIONS
101 ; Function Prototype declaration
102 ----------------------------------------------------------------------------*/
103 
104 /*----------------------------------------------------------------------------
105 ; LOCAL STORE/BUFFER/POINTER DEFINITIONS
106 ; Variable declaration - defined here and used outside this module
107 ----------------------------------------------------------------------------*/
108 
109 /* 1/4 resolution interpolation filter (-3 dB at 0.856*fs/2) in Q14 */
110 
111 
112 const int16 inter4_2[UP_SAMP][ 2*L_INTERPOL2] =
113 {
114     {
115         0,       -2,        4,       -2,      -10,       38,
116         -88,      165,     -275,      424,     -619,      871,
117         -1207,     1699,    -2598,     5531,    14031,    -2147,
118         780,     -249,      -16,      153,     -213,      226,
119         -209,      175,     -133,       91,      -55,       28,
120         -10,        2
121     },
122     {
123         1,       -7,       19,      -33,       47,      -52,
124         43,       -9,      -60,      175,     -355,      626,
125         -1044,     1749,    -3267,    10359,    10359,    -3267,
126         1749,    -1044,      626,     -355,      175,      -60,
127         -9,       43,      -52,       47,      -33,       19,
128         -7,        1
129     },
130     {
131         2,      -10,       28,      -55,       91,     -133,
132         175,     -209,      226,     -213,      153,      -16,
133         -249,      780,    -2147,    14031,     5531,    -2598,
134         1699,    -1207,      871,     -619,      424,     -275,
135         165,      -88,       38,      -10,       -2,        4,
136         -2,        0
137     },
138     {
139         1,       -7,       22,      -49,       92,     -153,
140         231,     -325,      431,     -544,      656,     -762,
141         853,     -923,      968,    15401,      968,     -923,
142         853,     -762,      656,     -544,      431,     -325,
143         231,     -153,       92,      -49,       22,       -7,
144         1,        0
145     }
146 };
147 
148 /*----------------------------------------------------------------------------
149 ; EXTERNAL FUNCTION REFERENCES
150 ; Declare functions defined elsewhere and referenced in this module
151 ----------------------------------------------------------------------------*/
152 
153 /*----------------------------------------------------------------------------
154 ; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
155 ; Declare variables used in this module but defined elsewhere
156 ----------------------------------------------------------------------------*/
157 
158 /*----------------------------------------------------------------------------
159 ; FUNCTION CODE
160 ----------------------------------------------------------------------------*/
161 
Pred_lt4(int16 exc[],int16 T0,int16 frac,int16 L_subfr)162 void Pred_lt4(
163     int16 exc[],                         /* in/out: excitation buffer */
164     int16 T0,                            /* input : integer pitch lag */
165     int16 frac,                          /* input : fraction of lag   */
166     int16 L_subfr                        /* input : subframe size     */
167 )
168 {
169     int16 i, j, *pt_exc;
170     int32 L_sum1;
171     int32 L_sum2;
172     int32 L_sum3;
173     int32 L_sum4;
174     pt_exc = &exc[-T0];
175 
176     const int16 *pt_inter4_2;
177 
178     frac = -frac;
179 
180     if (frac < 0)
181     {
182         frac += UP_SAMP;
183         pt_exc--;
184 
185     }
186     pt_exc -= (L_INTERPOL2 - 1);
187 
188     pt_inter4_2 = inter4_2[UP_SAMP-1 - frac];
189 
190     for (j = 0; j < (L_subfr >> 2); j++)
191     {
192 
193         L_sum1 = 0x00002000;  /* pre-roundig */
194         L_sum2 = 0x00002000;
195         L_sum3 = 0x00002000;
196         L_sum4 = 0x00002000;
197 
198         for (i = 0; i < L_INTERPOL2 << 1; i += 4)
199         {
200             int16 tmp1 = pt_exc[i  ];
201             int16 tmp2 = pt_exc[i+1];
202             int16 tmp3 = pt_exc[i+2];
203 
204 
205             L_sum1 = fxp_mac_16by16(tmp1, pt_inter4_2[i  ], L_sum1);
206             L_sum2 = fxp_mac_16by16(tmp2, pt_inter4_2[i  ], L_sum2);
207             L_sum1 = fxp_mac_16by16(tmp2, pt_inter4_2[i+1], L_sum1);
208             L_sum2 = fxp_mac_16by16(tmp3, pt_inter4_2[i+1], L_sum2);
209             L_sum3 = fxp_mac_16by16(tmp3, pt_inter4_2[i  ], L_sum3);
210             L_sum1 = fxp_mac_16by16(tmp3, pt_inter4_2[i+2], L_sum1);
211 
212             tmp1 = pt_exc[i+3];
213             tmp2 = pt_exc[i+4];
214 
215             L_sum4 = fxp_mac_16by16(tmp1, pt_inter4_2[i  ], L_sum4);
216             L_sum3 = fxp_mac_16by16(tmp1, pt_inter4_2[i+1], L_sum3);
217             L_sum2 = fxp_mac_16by16(tmp1, pt_inter4_2[i+2], L_sum2);
218             L_sum1 = fxp_mac_16by16(tmp1, pt_inter4_2[i+3], L_sum1);
219             L_sum4 = fxp_mac_16by16(tmp2, pt_inter4_2[i+1], L_sum4);
220             L_sum2 = fxp_mac_16by16(tmp2, pt_inter4_2[i+3], L_sum2);
221             L_sum3 = fxp_mac_16by16(tmp2, pt_inter4_2[i+2], L_sum3);
222 
223             tmp1 = pt_exc[i+5];
224             tmp2 = pt_exc[i+6];
225 
226             L_sum4 = fxp_mac_16by16(tmp1, pt_inter4_2[i+2], L_sum4);
227             L_sum3 = fxp_mac_16by16(tmp1, pt_inter4_2[i+3], L_sum3);
228             L_sum4 = fxp_mac_16by16(tmp2, pt_inter4_2[i+3], L_sum4);
229 
230         }
231 
232 
233 
234         exc[(j<<2)] = (int16)(L_sum1 >> 14);
235         exc[(j<<2)+1] = (int16)(L_sum2 >> 14);
236         exc[(j<<2)+2] = (int16)(L_sum3 >> 14);
237         exc[(j<<2)+3] = (int16)(L_sum4 >> 14);
238 
239         pt_exc += 4;
240 
241     }
242 
243     if (L_subfr&1)
244     {
245         L_sum1 = 0x00002000;
246 
247         for (i = 0; i < 2*L_INTERPOL2; i += 4)
248         {
249             int16 tmp1 = pt_exc[i  ];
250             int16 tmp2 = pt_exc[i+1];
251             L_sum1 = fxp_mac_16by16(tmp1, pt_inter4_2[i  ], L_sum1);
252             L_sum1 = fxp_mac_16by16(tmp2, pt_inter4_2[i+1], L_sum1);
253             tmp1 = pt_exc[i+2];
254             tmp2 = pt_exc[i+3];
255             L_sum1 = fxp_mac_16by16(tmp1, pt_inter4_2[i+2], L_sum1);
256             L_sum1 = fxp_mac_16by16(tmp2, pt_inter4_2[i+3], L_sum1);
257 
258         }
259 
260         exc[(j<<2)] = (int16)((L_sum1) >> 14);
261 
262     }
263 
264 
265     return;
266 }
267 
268