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: wb_syn_filt.cpp
36 ------------------------------------------------------------------------------
37 INPUT AND OUTPUT DEFINITIONS
41 int16 a[], (i) Q12 : a[m+1] prediction coefficients
42 int16 m, (i) : order of LP filter
43 int16 x[], (i) : input signal
44 int16 y[], (o) : output signal
45 int16 lg, (i) : size of filtering
46 int16 mem[], (i/o) : memory associated with this filtering.
47 int16 update, (i) : 0=no update, 1=update of memory.
52 int16 a[], (i) Q12 : a[m+1] prediction coefficients
53 int16 m, (i) : order of LP filter
54 int16 exc[], (i) Qnew: excitation (exc[i] >> Qnew)
55 int16 Qnew, (i) : exc scaling = 0(min) to 8(max)
56 int16 sig_hi[], (o) /16 : synthesis high
57 int16 sig_lo[], (o) /16 : synthesis low
58 int16 lg (i) : size of filtering
60 ------------------------------------------------------------------------------
63 Do the synthesis filtering 1/A(z) 16 and 32-bits version
65 ------------------------------------------------------------------------------
69 ------------------------------------------------------------------------------
72 ------------------------------------------------------------------------------
75 ------------------------------------------------------------------------------
79 /*----------------------------------------------------------------------------
81 ----------------------------------------------------------------------------*/
84 #include "pv_amr_wb_type_defs.h"
85 #include "pvamrwbdecoder_mem_funcs.h"
86 #include "pvamrwbdecoder_basic_op.h"
87 #include "pvamrwb_math_op.h"
88 #include "pvamrwbdecoder_cnst.h"
89 #include "pvamrwbdecoder_acelp.h"
91 /*----------------------------------------------------------------------------
93 ; Define module specific macros here
94 ----------------------------------------------------------------------------*/
97 /*----------------------------------------------------------------------------
99 ; Include all pre-processor statements here. Include conditional
100 ; compile variables also.
101 ----------------------------------------------------------------------------*/
103 /*----------------------------------------------------------------------------
104 ; EXTERNAL FUNCTION REFERENCES
105 ; Declare functions defined elsewhere and referenced in this module
106 ----------------------------------------------------------------------------*/
108 /*----------------------------------------------------------------------------
109 ; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
110 ; Declare variables used in this module but defined elsewhere
111 ----------------------------------------------------------------------------*/
113 /*----------------------------------------------------------------------------
115 ----------------------------------------------------------------------------*/
118 int16 a[], /* (i) Q12 : a[m+1] prediction coefficients */
119 int16 m, /* (i) : order of LP filter */
120 int16 x[], /* (i) : input signal */
121 int16 y[], /* (o) : output signal */
122 int16 lg, /* (i) : size of filtering */
123 int16 mem[], /* (i/o) : memory associated with this filtering. */
124 int16 update, /* (i) : 0=no update, 1=update of memory. */
136 /* copy initial filter states into synthesis buffer */
137 pv_memcpy(y_buf, mem, m*sizeof(*yy));
141 /* Do the filtering. */
143 for (i = 0; i < lg >> 2; i++)
145 L_tmp1 = -((int32)x[(i<<2)] << 11);
146 L_tmp2 = -((int32)x[(i<<2)+1] << 11);
147 L_tmp3 = -((int32)x[(i<<2)+2] << 11);
148 L_tmp4 = -((int32)x[(i<<2)+3] << 11);
150 /* a[] uses Q12 and abs(a) =< 1 */
152 L_tmp1 = fxp_mac_16by16(yy[(i<<2) -3], a[3], L_tmp1);
153 L_tmp2 = fxp_mac_16by16(yy[(i<<2) -2], a[3], L_tmp2);
154 L_tmp1 = fxp_mac_16by16(yy[(i<<2) -2], a[2], L_tmp1);
155 L_tmp2 = fxp_mac_16by16(yy[(i<<2) -1], a[2], L_tmp2);
156 L_tmp1 = fxp_mac_16by16(yy[(i<<2) -1], a[1], L_tmp1);
158 for (j = 4; j < m; j += 2)
160 L_tmp1 = fxp_mac_16by16(yy[(i<<2)-1 - j], a[j+1], L_tmp1);
161 L_tmp2 = fxp_mac_16by16(yy[(i<<2) - j], a[j+1], L_tmp2);
162 L_tmp1 = fxp_mac_16by16(yy[(i<<2) - j], a[j ], L_tmp1);
163 L_tmp2 = fxp_mac_16by16(yy[(i<<2)+1 - j], a[j ], L_tmp2);
164 L_tmp3 = fxp_mac_16by16(yy[(i<<2)+1 - j], a[j+1], L_tmp3);
165 L_tmp4 = fxp_mac_16by16(yy[(i<<2)+2 - j], a[j+1], L_tmp4);
166 L_tmp3 = fxp_mac_16by16(yy[(i<<2)+2 - j], a[j ], L_tmp3);
167 L_tmp4 = fxp_mac_16by16(yy[(i<<2)+3 - j], a[j ], L_tmp4);
170 L_tmp1 = fxp_mac_16by16(yy[(i<<2) - j], a[j], L_tmp1);
171 L_tmp2 = fxp_mac_16by16(yy[(i<<2)+1 - j], a[j], L_tmp2);
172 L_tmp3 = fxp_mac_16by16(yy[(i<<2)+2 - j], a[j], L_tmp3);
173 L_tmp4 = fxp_mac_16by16(yy[(i<<2)+3 - j], a[j], L_tmp4);
175 L_tmp1 = shl_int32(L_tmp1, 4);
177 y[(i<<2)] = yy[(i<<2)] = amr_wb_round(-L_tmp1);
179 L_tmp2 = fxp_mac_16by16(yy[(i<<2)], a[1], L_tmp2);
181 L_tmp2 = shl_int32(L_tmp2, 4);
183 y[(i<<2)+1] = yy[(i<<2)+1] = amr_wb_round(-L_tmp2);
185 L_tmp3 = fxp_mac_16by16(yy[(i<<2) - 1], a[3], L_tmp3);
186 L_tmp4 = fxp_mac_16by16(yy[(i<<2)], a[3], L_tmp4);
187 L_tmp3 = fxp_mac_16by16(yy[(i<<2)], a[2], L_tmp3);
188 L_tmp4 = fxp_mac_16by16(yy[(i<<2) + 1], a[2], L_tmp4);
189 L_tmp3 = fxp_mac_16by16(yy[(i<<2) + 1], a[1], L_tmp3);
191 L_tmp3 = shl_int32(L_tmp3, 4);
193 y[(i<<2)+2] = yy[(i<<2)+2] = amr_wb_round(-L_tmp3);
195 L_tmp4 = fxp_mac_16by16(yy[(i<<2)+2], a[1], L_tmp4);
197 L_tmp4 = shl_int32(L_tmp4, 4);
199 y[(i<<2)+3] = yy[(i<<2)+3] = amr_wb_round(-L_tmp4);
203 /* Update memory if required */
207 pv_memcpy(mem, &y[lg - m], m*sizeof(*y));
213 /*----------------------------------------------------------------------------
215 ----------------------------------------------------------------------------*/
218 int16 a[], /* (i) Q12 : a[m+1] prediction coefficients */
219 int16 m, /* (i) : order of LP filter */
220 int16 exc[], /* (i) Qnew: excitation (exc[i] >> Qnew) */
221 int16 Qnew, /* (i) : exc scaling = 0(min) to 8(max) */
222 int16 sig_hi[], /* (o) /16 : synthesis high */
223 int16 sig_lo[], /* (o) /16 : synthesis low */
224 int16 lg /* (i) : size of filtering */
233 a0 = 9 - Qnew; /* input / 16 and >>Qnew */
235 /* Do the filtering. */
237 for (i = 0; i < lg >> 1; i++)
243 L_tmp1 = fxp_mul_16by16(sig_lo[(i<<1) - 1], a[1]);
244 L_tmp2 = fxp_mul_16by16(sig_hi[(i<<1) - 1], a[1]);
246 for (k = 2; k < m; k += 2)
249 L_tmp1 = fxp_mac_16by16(sig_lo[(i<<1)-1 - k], a[k+1], L_tmp1);
250 L_tmp2 = fxp_mac_16by16(sig_hi[(i<<1)-1 - k], a[k+1], L_tmp2);
251 L_tmp1 = fxp_mac_16by16(sig_lo[(i<<1) - k], a[k ], L_tmp1);
252 L_tmp2 = fxp_mac_16by16(sig_hi[(i<<1) - k], a[k ], L_tmp2);
253 L_tmp3 = fxp_mac_16by16(sig_lo[(i<<1) - k], a[k+1], L_tmp3);
254 L_tmp4 = fxp_mac_16by16(sig_hi[(i<<1) - k], a[k+1], L_tmp4);
255 L_tmp3 = fxp_mac_16by16(sig_lo[(i<<1)+1 - k], a[k ], L_tmp3);
256 L_tmp4 = fxp_mac_16by16(sig_hi[(i<<1)+1 - k], a[k ], L_tmp4);
259 L_tmp1 = -fxp_mac_16by16(sig_lo[(i<<1) - k], a[k], L_tmp1);
260 L_tmp3 = fxp_mac_16by16(sig_lo[(i<<1)+1 - k], a[k], L_tmp3);
261 L_tmp2 = fxp_mac_16by16(sig_hi[(i<<1) - k], a[k], L_tmp2);
262 L_tmp4 = fxp_mac_16by16(sig_hi[(i<<1)+1 - k], a[k], L_tmp4);
266 L_tmp1 >>= 11; /* -4 : sig_lo[i] << 4 */
268 L_tmp1 += (int32)exc[(i<<1)] << a0;
270 L_tmp1 -= (L_tmp2 << 1);
271 /* sig_hi = bit16 to bit31 of synthesis */
272 L_tmp1 = shl_int32(L_tmp1, 3); /* ai in Q12 */
274 sig_hi[(i<<1)] = (int16)(L_tmp1 >> 16);
276 L_tmp4 = fxp_mac_16by16((int16)(L_tmp1 >> 16), a[1], L_tmp4);
278 /* sig_lo = bit4 to bit15 of synthesis */
279 /* L_tmp1 >>= 4 : sig_lo[i] >> 4 */
280 sig_lo[(i<<1)] = (int16)((L_tmp1 >> 4) - ((L_tmp1 >> 16) << 12));
282 L_tmp3 = fxp_mac_16by16(sig_lo[(i<<1)], a[1], L_tmp3);
283 L_tmp3 = -L_tmp3 >> 11;
285 L_tmp3 += (int32)exc[(i<<1)+1] << a0;
287 L_tmp3 -= (L_tmp4 << 1);
288 /* sig_hi = bit16 to bit31 of synthesis */
289 L_tmp3 = shl_int32(L_tmp3, 3); /* ai in Q12 */
290 sig_hi[(i<<1)+1] = (int16)(L_tmp3 >> 16);
292 /* sig_lo = bit4 to bit15 of synthesis */
293 /* L_tmp1 >>= 4 : sig_lo[i] >> 4 */
294 sig_lo[(i<<1)+1] = (int16)((L_tmp3 >> 4) - (sig_hi[(i<<1)+1] << 12));