1 /* ------------------------------------------------------------------
2 * Copyright (C) 1998-2009 PacketVideo
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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
14 * See the License for the specific language governing permissions
15 * and limitations under the License.
16 * -------------------------------------------------------------------
18 /****************************************************************************************
19 Portions of this file are derived from the following 3GPP standard:
22 ANSI-C code for the Adaptive Multi-Rate - Wideband (AMR-WB) speech codec
23 Available from http://www.3gpp.org
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 ****************************************************************************************/
30 ------------------------------------------------------------------------------
34 Filename: pred_lt4.cpp
36 ------------------------------------------------------------------------------
37 INPUT AND OUTPUT DEFINITIONS
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)
44 ------------------------------------------------------------------------------
47 Compute the result of long term prediction with fractionnal
48 interpolation of resolution 1/4.
50 On return exc[0..L_subfr-1] contains the interpolated signal
51 (adaptive codebook excitation)
54 ------------------------------------------------------------------------------
58 ------------------------------------------------------------------------------
61 ------------------------------------------------------------------------------
64 ------------------------------------------------------------------------------
68 /*----------------------------------------------------------------------------
70 ----------------------------------------------------------------------------*/
72 #include "pv_amr_wb_type_defs.h"
73 #include "pvamrwbdecoder_basic_op.h"
74 #include "pvamrwbdecoder_acelp.h"
76 /*----------------------------------------------------------------------------
78 ; Define module specific macros here
79 ----------------------------------------------------------------------------*/
82 /*----------------------------------------------------------------------------
84 ; Include all pre-processor statements here. Include conditional
85 ; compile variables also.
86 ----------------------------------------------------------------------------*/
89 #define L_INTERPOL2 16
91 /*----------------------------------------------------------------------------
92 ; LOCAL FUNCTION DEFINITIONS
93 ; Function Prototype declaration
94 ----------------------------------------------------------------------------*/
96 /*----------------------------------------------------------------------------
97 ; LOCAL STORE/BUFFER/POINTER DEFINITIONS
98 ; Variable declaration - defined here and used outside this module
99 ----------------------------------------------------------------------------*/
101 /* 1/4 resolution interpolation filter (-3 dB at 0.856*fs/2) in Q14 */
104 const int16 inter4_2[UP_SAMP][ 2*L_INTERPOL2] =
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,
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,
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,
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,
140 /*----------------------------------------------------------------------------
141 ; EXTERNAL FUNCTION REFERENCES
142 ; Declare functions defined elsewhere and referenced in this module
143 ----------------------------------------------------------------------------*/
145 /*----------------------------------------------------------------------------
146 ; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
147 ; Declare variables used in this module but defined elsewhere
148 ----------------------------------------------------------------------------*/
150 /*----------------------------------------------------------------------------
152 ----------------------------------------------------------------------------*/
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 */
168 const int16 *pt_inter4_2;
178 pt_exc -= (L_INTERPOL2 - 1);
180 pt_inter4_2 = inter4_2[UP_SAMP-1 - frac];
182 for (j = 0; j < (L_subfr >> 2); j++)
185 L_sum1 = 0x00002000; /* pre-roundig */
190 for (i = 0; i < L_INTERPOL2 << 1; i += 4)
192 int16 tmp1 = pt_exc[i ];
193 int16 tmp2 = pt_exc[i+1];
194 int16 tmp3 = pt_exc[i+2];
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);
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);
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);
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);
239 for (i = 0; i < 2*L_INTERPOL2; i += 4)
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);
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);
252 exc[(j<<2)] = (int16)((L_sum1) >> 14);