/src/libxaac/encoder/iusace_acelp_enc.c
Line | Count | Source (jump to first uncovered line) |
1 | | /****************************************************************************** |
2 | | * * |
3 | | * Copyright (C) 2023 The Android Open Source Project |
4 | | * |
5 | | * Licensed under the Apache License, Version 2.0 (the "License"); |
6 | | * you may not use this file except in compliance with the License. |
7 | | * You may obtain a copy of the License at: |
8 | | * |
9 | | * http://www.apache.org/licenses/LICENSE-2.0 |
10 | | * |
11 | | * Unless required by applicable law or agreed to in writing, software |
12 | | * distributed under the License is distributed on an "AS IS" BASIS, |
13 | | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
14 | | * See the License for the specific language governing permissions and |
15 | | * limitations under the License. |
16 | | * |
17 | | ***************************************************************************** |
18 | | * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore |
19 | | */ |
20 | | |
21 | | #include <string.h> |
22 | | #include <math.h> |
23 | | #include "ixheaac_type_def.h" |
24 | | #include "iusace_bitbuffer.h" |
25 | | |
26 | | /* DRC */ |
27 | | #include "impd_drc_common_enc.h" |
28 | | #include "impd_drc_uni_drc.h" |
29 | | #include "impd_drc_tables.h" |
30 | | #include "impd_drc_api.h" |
31 | | #include "impd_drc_uni_drc_eq.h" |
32 | | #include "impd_drc_uni_drc_filter_bank.h" |
33 | | #include "impd_drc_gain_enc.h" |
34 | | #include "impd_drc_struct_def.h" |
35 | | |
36 | | #include "iusace_cnst.h" |
37 | | #include "iusace_tns_usac.h" |
38 | | #include "iusace_psy_mod.h" |
39 | | #include "ixheaace_adjust_threshold_data.h" |
40 | | #include "iusace_fd_qc_util.h" |
41 | | #include "iusace_config.h" |
42 | | #include "iusace_arith_enc.h" |
43 | | #include "iusace_block_switch_const.h" |
44 | | #include "iusace_block_switch_struct_def.h" |
45 | | #include "iusace_lpd_rom.h" |
46 | | #include "iusace_lpd.h" |
47 | | |
48 | | VOID iusace_acelp_encode(FLOAT32 *lp_filt_coeff, FLOAT32 *quant_lp_filt_coeff, FLOAT32 *speech_in, |
49 | | FLOAT32 *wsig_in, FLOAT32 *synth_out, FLOAT32 *wsynth_out, |
50 | | WORD16 acelp_core_mode, ia_usac_lpd_state_struct *lpd_state, |
51 | | WORD32 len_subfrm, FLOAT32 norm_corr, FLOAT32 norm_corr2, |
52 | | WORD32 ol_pitch_lag1, WORD32 ol_pitch_lag2, WORD32 pit_adj, |
53 | 717k | WORD32 *acelp_params, iusace_scratch_mem *pstr_scratch) { |
54 | 717k | WORD32 i, i_subfr, num_bits, t; |
55 | 717k | WORD32 t0, t0_min, t0_max, index, subfrm_flag; |
56 | 717k | WORD32 t0_frac; |
57 | 717k | FLOAT32 temp, energy, max_ener, mean_ener_code; |
58 | 717k | FLOAT32 pitch_gain, code_gain, gain1, gain2; |
59 | 717k | FLOAT32 tgt_cb_corr[5], tgt_cb_corr2[2]; |
60 | 717k | FLOAT32 *p_lp_filt_coeff, *p_quant_lp_filt_coeff, weighted_lpc[ORDER + 1]; |
61 | 717k | FLOAT32 imp_res[LEN_SUBFR]; |
62 | 717k | FLOAT32 code[LEN_SUBFR]; |
63 | 717k | WORD16 cb_exc[LEN_SUBFR]; |
64 | 717k | FLOAT32 error[ORDER + LEN_SUBFR + 8]; |
65 | 717k | FLOAT32 cn[LEN_SUBFR]; |
66 | 717k | FLOAT32 xn[LEN_SUBFR]; |
67 | 717k | FLOAT32 xn2[LEN_SUBFR]; |
68 | 717k | FLOAT32 dn[LEN_SUBFR]; |
69 | 717k | FLOAT32 y0[LEN_SUBFR]; |
70 | 717k | FLOAT32 y1[LEN_SUBFR]; |
71 | 717k | FLOAT32 y2[LEN_SUBFR]; |
72 | 717k | WORD32 min_pitch_lag_res1_4; |
73 | 717k | WORD32 min_pitch_lag_res1_2; |
74 | 717k | WORD32 min_pitch_lag_res1; |
75 | 717k | WORD32 max_pitch_lag; |
76 | 717k | FLOAT32 *exc_buf = pstr_scratch->p_acelp_exc_buf; |
77 | 717k | FLOAT32 *exc; |
78 | 717k | FLOAT32 mem_txn, mem_txnq; |
79 | 717k | WORD32 fac_length = len_subfrm / 2; |
80 | 717k | if (lpd_state->mode > 0) { |
81 | 34.7M | for (i = 0; i < fac_length; i++) { |
82 | 34.4M | acelp_params[i] = lpd_state->avq_params[i]; |
83 | 34.4M | } |
84 | 288k | acelp_params += fac_length; |
85 | 288k | } |
86 | | |
87 | 717k | if (pit_adj == SR_MAX) |
88 | 91.5k | exc = exc_buf + (2 * len_subfrm) + 41; |
89 | 626k | else |
90 | 626k | exc = exc_buf + (2 * len_subfrm); |
91 | | |
92 | 717k | memset(exc_buf, 0, (2 * len_subfrm) * sizeof(exc_buf[0])); |
93 | 717k | memcpy(exc_buf, lpd_state->acelp_exc, 2 * len_subfrm * sizeof(FLOAT32)); |
94 | 717k | memcpy(synth_out - 128, &(lpd_state->synth[ORDER]), 128 * sizeof(FLOAT32)); |
95 | 717k | memcpy(wsynth_out - 128, &(lpd_state->wsynth[1]), 128 * sizeof(FLOAT32)); |
96 | | |
97 | 717k | num_bits = ((iusace_acelp_core_numbits_1024[acelp_core_mode] - NBITS_MODE) / 4) - NBITS_LPC; |
98 | | |
99 | 717k | if (pit_adj == 0) { |
100 | 0 | min_pitch_lag_res1_4 = TMIN; |
101 | 0 | min_pitch_lag_res1_2 = TFR2; |
102 | 0 | min_pitch_lag_res1 = TFR1; |
103 | 0 | max_pitch_lag = TMAX; |
104 | 717k | } else { |
105 | 717k | i = (((pit_adj * TMIN) + (FSCALE_DENOM / 2)) / FSCALE_DENOM) - TMIN; |
106 | 717k | min_pitch_lag_res1_4 = TMIN + i; |
107 | 717k | min_pitch_lag_res1_2 = TFR2 - i; |
108 | 717k | min_pitch_lag_res1 = TFR1; |
109 | 717k | max_pitch_lag = TMAX + (6 * i); |
110 | 717k | } |
111 | | |
112 | 717k | ol_pitch_lag1 *= OPL_DECIM; |
113 | 717k | ol_pitch_lag2 *= OPL_DECIM; |
114 | | |
115 | 717k | t0_min = ol_pitch_lag1 - 8; |
116 | | |
117 | 717k | t = MIN(ol_pitch_lag1, ol_pitch_lag2) - 4; |
118 | 717k | if (t0_min < t) t0_min = t; |
119 | | |
120 | 717k | if (t0_min < min_pitch_lag_res1_4) { |
121 | 224k | t0_min = min_pitch_lag_res1_4; |
122 | 224k | } |
123 | 717k | t0_max = t0_min + 15; |
124 | 717k | t = MAX(ol_pitch_lag1, ol_pitch_lag2) + 4; |
125 | 717k | if (t0_max > t) t0_max = t; |
126 | | |
127 | 717k | if (t0_max > max_pitch_lag) { |
128 | 40.9k | t0_max = max_pitch_lag; |
129 | 40.9k | t0_min = t0_max - 15; |
130 | 40.9k | } |
131 | | |
132 | 717k | max_ener = 0.0; |
133 | 717k | mean_ener_code = 0.0; |
134 | 717k | p_quant_lp_filt_coeff = quant_lp_filt_coeff; |
135 | 3.39M | for (i_subfr = 0; i_subfr < len_subfrm; i_subfr += LEN_SUBFR) { |
136 | 2.68M | iusace_compute_lp_residual(p_quant_lp_filt_coeff, &speech_in[i_subfr], &exc[i_subfr], |
137 | 2.68M | LEN_SUBFR); |
138 | 2.68M | energy = 0.01f; |
139 | 174M | for (i = 0; i < LEN_SUBFR; i++) { |
140 | 171M | energy += exc[i + i_subfr] * exc[i + i_subfr]; |
141 | 171M | } |
142 | 2.68M | energy = 10.0f * (FLOAT32)log10(energy / ((FLOAT32)LEN_SUBFR)); |
143 | 2.68M | if (energy < 0.0) { |
144 | 947k | energy = 0.0; |
145 | 947k | } |
146 | 2.68M | if (energy > max_ener) { |
147 | 982k | max_ener = energy; |
148 | 982k | } |
149 | 2.68M | mean_ener_code += 0.25f * energy; |
150 | 2.68M | p_quant_lp_filt_coeff += (ORDER + 1); |
151 | 2.68M | } |
152 | | |
153 | 717k | mean_ener_code -= 5.0f * norm_corr; |
154 | 717k | mean_ener_code -= 5.0f * norm_corr2; |
155 | | |
156 | 717k | temp = (mean_ener_code - 18.0f) / 12.0f; |
157 | 717k | index = (WORD32)floor(temp + 0.5); |
158 | 717k | if (index < 0) { |
159 | 360k | index = 0; |
160 | 360k | } |
161 | 717k | if (index > 3) { |
162 | 27.6k | index = 3; |
163 | 27.6k | } |
164 | 717k | mean_ener_code = (((FLOAT32)index) * 12.0f) + 18.0f; |
165 | | |
166 | 1.01M | while ((mean_ener_code < (max_ener - 27.0)) && (index < 3)) { |
167 | 293k | index++; |
168 | 293k | mean_ener_code += 12.0; |
169 | 293k | } |
170 | 717k | *acelp_params = index; |
171 | 717k | acelp_params++; |
172 | | |
173 | 717k | p_lp_filt_coeff = lp_filt_coeff; |
174 | 717k | p_quant_lp_filt_coeff = quant_lp_filt_coeff; |
175 | 3.39M | for (i_subfr = 0; i_subfr < len_subfrm; i_subfr += LEN_SUBFR) { |
176 | 2.68M | subfrm_flag = i_subfr; |
177 | 2.68M | if ((len_subfrm == 256) && (i_subfr == (2 * LEN_SUBFR))) { |
178 | 526k | subfrm_flag = 0; |
179 | | |
180 | 526k | t0_min = ol_pitch_lag2 - 8; |
181 | | |
182 | 526k | t = MIN(ol_pitch_lag1, ol_pitch_lag2) - 4; |
183 | 526k | if (t0_min < t) t0_min = t; |
184 | | |
185 | 526k | if (t0_min < min_pitch_lag_res1_4) { |
186 | 122k | t0_min = min_pitch_lag_res1_4; |
187 | 122k | } |
188 | 526k | t0_max = t0_min + 15; |
189 | | |
190 | 526k | t = MAX(ol_pitch_lag1, ol_pitch_lag2) + 4; |
191 | 526k | if (t0_max > t) t0_max = t; |
192 | | |
193 | 526k | if (t0_max > max_pitch_lag) { |
194 | 18.1k | t0_max = max_pitch_lag; |
195 | 18.1k | t0_min = t0_max - 15; |
196 | 18.1k | } |
197 | 526k | } |
198 | | |
199 | 2.68M | memcpy(xn, &wsig_in[i_subfr], LEN_SUBFR * sizeof(FLOAT32)); |
200 | | |
201 | 2.68M | memcpy(error, &synth_out[i_subfr - ORDER], ORDER * sizeof(FLOAT32)); |
202 | 2.68M | memset(error + ORDER, 0, LEN_SUBFR * sizeof(FLOAT32)); |
203 | 2.68M | iusace_synthesis_tool_float(p_quant_lp_filt_coeff, error + ORDER, error + ORDER, LEN_SUBFR, |
204 | 2.68M | error, pstr_scratch->p_buf_synthesis_tool); |
205 | 2.68M | iusace_get_weighted_lpc(p_lp_filt_coeff, weighted_lpc); |
206 | 2.68M | iusace_compute_lp_residual(weighted_lpc, error + ORDER, xn2, LEN_SUBFR); |
207 | | |
208 | 2.68M | temp = wsynth_out[i_subfr - 1]; |
209 | 2.68M | iusace_apply_deemph(xn2, TILT_FAC, LEN_SUBFR, &temp); |
210 | 2.68M | memcpy(y0, xn2, LEN_SUBFR * sizeof(FLOAT32)); |
211 | | |
212 | 174M | for (i = 0; i < LEN_SUBFR; i++) { |
213 | 171M | xn[i] -= xn2[i]; |
214 | 171M | } |
215 | 2.68M | iusace_compute_lp_residual(p_quant_lp_filt_coeff, &speech_in[i_subfr], &exc[i_subfr], |
216 | 2.68M | LEN_SUBFR); |
217 | | |
218 | 2.68M | memset(&code[0], 0, ORDER * sizeof(code[0])); |
219 | 2.68M | memcpy(code + ORDER, xn, (LEN_SUBFR / 2) * sizeof(FLOAT32)); |
220 | 2.68M | temp = 0.0; |
221 | 2.68M | iusace_apply_preemph(code + ORDER, TILT_FAC, LEN_SUBFR / 2, &temp); |
222 | 2.68M | iusace_get_weighted_lpc(p_lp_filt_coeff, weighted_lpc); |
223 | 2.68M | iusace_synthesis_tool_float(weighted_lpc, code + ORDER, code + ORDER, LEN_SUBFR / 2, code, |
224 | 2.68M | pstr_scratch->p_buf_synthesis_tool); |
225 | 2.68M | iusace_compute_lp_residual(p_quant_lp_filt_coeff, code + ORDER, cn, LEN_SUBFR / 2); |
226 | 2.68M | memcpy(cn + (LEN_SUBFR / 2), &exc[i_subfr + (LEN_SUBFR / 2)], |
227 | 2.68M | (LEN_SUBFR / 2) * sizeof(FLOAT32)); |
228 | | |
229 | 2.68M | iusace_get_weighted_lpc(p_lp_filt_coeff, weighted_lpc); |
230 | 2.68M | memset(imp_res, 0, LEN_SUBFR * sizeof(FLOAT32)); |
231 | 2.68M | memcpy(imp_res, weighted_lpc, (ORDER + 1) * sizeof(FLOAT32)); |
232 | 2.68M | iusace_synthesis_tool_float(p_quant_lp_filt_coeff, imp_res, imp_res, LEN_SUBFR, |
233 | 2.68M | &imp_res[ORDER + 1], pstr_scratch->p_buf_synthesis_tool); |
234 | 2.68M | temp = 0.0; |
235 | 2.68M | iusace_apply_deemph(imp_res, TILT_FAC, LEN_SUBFR, &temp); |
236 | | |
237 | 2.68M | iusace_closed_loop_search(&exc[i_subfr], xn, imp_res, t0_min, t0_max, &t0_frac, subfrm_flag, |
238 | 2.68M | min_pitch_lag_res1_2, min_pitch_lag_res1, &t0); |
239 | | |
240 | 2.68M | if (subfrm_flag == 0) { |
241 | 1.24M | if (t0 < min_pitch_lag_res1_2) { |
242 | 765k | index = t0 * 4 + t0_frac - (min_pitch_lag_res1_4 * 4); |
243 | 765k | } else if (t0 < min_pitch_lag_res1) { |
244 | 135k | index = t0 * 2 + (t0_frac >> 1) - (min_pitch_lag_res1_2 * 2) + |
245 | 135k | ((min_pitch_lag_res1_2 - min_pitch_lag_res1_4) * 4); |
246 | 343k | } else { |
247 | 343k | index = t0 - min_pitch_lag_res1 + ((min_pitch_lag_res1_2 - min_pitch_lag_res1_4) * 4) + |
248 | 343k | ((min_pitch_lag_res1 - min_pitch_lag_res1_2) * 2); |
249 | 343k | } |
250 | | |
251 | 1.24M | t0_min = t0 - 8; |
252 | 1.24M | if (t0_min < min_pitch_lag_res1_4) { |
253 | 489k | t0_min = min_pitch_lag_res1_4; |
254 | 489k | } |
255 | 1.24M | t0_max = t0_min + 15; |
256 | 1.24M | if (t0_max > max_pitch_lag) { |
257 | 35.6k | t0_max = max_pitch_lag; |
258 | 35.6k | t0_min = t0_max - 15; |
259 | 35.6k | } |
260 | 1.43M | } else { |
261 | 1.43M | i = t0 - t0_min; |
262 | 1.43M | index = i * 4 + t0_frac; |
263 | 1.43M | } |
264 | 2.68M | *acelp_params = index; |
265 | 2.68M | acelp_params++; |
266 | | |
267 | 2.68M | iusace_acelp_ltpred_cb_exc(&exc[i_subfr], t0, t0_frac, LEN_SUBFR + 1); |
268 | 2.68M | iusace_convolve(&exc[i_subfr], imp_res, y1); |
269 | 2.68M | gain1 = iusace_acelp_tgt_cb_corr2(xn, y1, tgt_cb_corr); |
270 | 2.68M | iusace_acelp_cb_target_update(xn, xn2, y1, gain1); |
271 | 2.68M | energy = 0.0; |
272 | 174M | for (i = 0; i < LEN_SUBFR; i++) { |
273 | 171M | energy += xn2[i] * xn2[i]; |
274 | 171M | } |
275 | | |
276 | 174M | for (i = 0; i < LEN_SUBFR; i++) { |
277 | 171M | code[i] = (FLOAT32)(0.18 * exc[i - 1 + i_subfr] + 0.64 * exc[i + i_subfr] + |
278 | 171M | 0.18 * exc[i + 1 + i_subfr]); |
279 | 171M | } |
280 | 2.68M | iusace_convolve(code, imp_res, y2); |
281 | 2.68M | gain2 = iusace_acelp_tgt_cb_corr2(xn, y2, tgt_cb_corr2); |
282 | | |
283 | 2.68M | iusace_acelp_cb_target_update(xn, xn2, y2, gain2); |
284 | 2.68M | temp = 0.0; |
285 | 174M | for (i = 0; i < LEN_SUBFR; i++) { |
286 | 171M | temp += xn2[i] * xn2[i]; |
287 | 171M | } |
288 | | |
289 | 2.68M | if (temp < energy) { |
290 | 1.26M | *acelp_params = 0; |
291 | 1.26M | memcpy(&exc[i_subfr], code, LEN_SUBFR * sizeof(FLOAT32)); |
292 | 1.26M | memcpy(y1, y2, LEN_SUBFR * sizeof(FLOAT32)); |
293 | 1.26M | pitch_gain = gain2; |
294 | 1.26M | tgt_cb_corr[0] = tgt_cb_corr2[0]; |
295 | 1.26M | tgt_cb_corr[1] = tgt_cb_corr2[1]; |
296 | 1.41M | } else { |
297 | 1.41M | *acelp_params = 1; |
298 | 1.41M | pitch_gain = gain1; |
299 | 1.41M | } |
300 | 2.68M | acelp_params++; |
301 | | |
302 | 2.68M | iusace_acelp_cb_target_update(xn, xn2, y1, pitch_gain); |
303 | 2.68M | iusace_acelp_cb_target_update(cn, cn, &exc[i_subfr], pitch_gain); |
304 | | |
305 | 2.68M | temp = 0.0; |
306 | 2.68M | iusace_apply_preemph(imp_res, TILT_CODE, LEN_SUBFR, &temp); |
307 | 2.68M | if (t0_frac > 2) { |
308 | 500k | t0++; |
309 | 500k | } |
310 | | |
311 | 29.0M | for (i = t0; i < LEN_SUBFR; i++) { |
312 | 26.3M | imp_res[i] += imp_res[i - t0] * PIT_SHARP; |
313 | 26.3M | } |
314 | | |
315 | 2.68M | iusace_acelp_tgt_ir_corr(xn2, imp_res, dn); |
316 | | |
317 | 2.68M | if (acelp_core_mode == ACELP_CORE_MODE_9k6) { |
318 | 0 | iusace_acelp_cb_exc(dn, cn, imp_res, cb_exc, y2, ACELP_NUM_BITS_20, acelp_params, |
319 | 0 | pstr_scratch->p_acelp_ir_buf); |
320 | 0 | acelp_params += 4; |
321 | 2.68M | } else if (acelp_core_mode == ACELP_CORE_MODE_11k2) { |
322 | 0 | iusace_acelp_cb_exc(dn, cn, imp_res, cb_exc, y2, ACELP_NUM_BITS_28, acelp_params, |
323 | 0 | pstr_scratch->p_acelp_ir_buf); |
324 | 0 | acelp_params += 4; |
325 | 2.68M | } else if (acelp_core_mode == ACELP_CORE_MODE_12k8) { |
326 | 260k | iusace_acelp_cb_exc(dn, cn, imp_res, cb_exc, y2, ACELP_NUM_BITS_36, acelp_params, |
327 | 260k | pstr_scratch->p_acelp_ir_buf); |
328 | 260k | acelp_params += 4; |
329 | 2.42M | } else if (acelp_core_mode == ACELP_CORE_MODE_14k4) { |
330 | 0 | iusace_acelp_cb_exc(dn, cn, imp_res, cb_exc, y2, ACELP_NUM_BITS_44, acelp_params, |
331 | 0 | pstr_scratch->p_acelp_ir_buf); |
332 | 0 | acelp_params += 4; |
333 | 2.42M | } else if (acelp_core_mode == ACELP_CORE_MODE_16k) { |
334 | 51.5k | iusace_acelp_cb_exc(dn, cn, imp_res, cb_exc, y2, ACELP_NUM_BITS_52, acelp_params, |
335 | 51.5k | pstr_scratch->p_acelp_ir_buf); |
336 | 51.5k | acelp_params += 4; |
337 | 2.36M | } else if (acelp_core_mode == ACELP_CORE_MODE_18k4) { |
338 | 2.36M | iusace_acelp_cb_exc(dn, cn, imp_res, cb_exc, y2, ACELP_NUM_BITS_64, acelp_params, |
339 | 2.36M | pstr_scratch->p_acelp_ir_buf); |
340 | 2.36M | acelp_params += 8; |
341 | 2.36M | } else { |
342 | 0 | iusace_acelp_cb_exc(dn, cn, imp_res, cb_exc, y2, ACELP_NUM_BITS_64, acelp_params, |
343 | 0 | pstr_scratch->p_acelp_ir_buf); |
344 | 0 | acelp_params += 8; |
345 | 0 | } |
346 | | |
347 | 174M | for (i = 0; i < LEN_SUBFR; i++) { |
348 | 171M | code[i] = (FLOAT32)(cb_exc[i] / 512); |
349 | 171M | } |
350 | | |
351 | 2.68M | temp = 0.0; |
352 | 2.68M | iusace_apply_preemph(code, TILT_CODE, LEN_SUBFR, &temp); |
353 | 29.0M | for (i = t0; i < LEN_SUBFR; i++) { |
354 | 26.3M | code[i] += code[i - t0] * PIT_SHARP; |
355 | 26.3M | } |
356 | | |
357 | 2.68M | iusace_acelp_tgt_cb_corr1(xn, y1, y2, tgt_cb_corr); |
358 | 2.68M | iusace_acelp_quant_gain(code, &pitch_gain, &code_gain, tgt_cb_corr, mean_ener_code, |
359 | 2.68M | acelp_params); |
360 | 2.68M | acelp_params++; |
361 | | |
362 | 2.68M | temp = 0.0; |
363 | 174M | for (i = 0; i < LEN_SUBFR; i++) { |
364 | 171M | temp += code[i] * code[i]; |
365 | 171M | } |
366 | 2.68M | temp *= code_gain * code_gain; |
367 | | |
368 | 174M | for (i = 0; i < LEN_SUBFR; i++) { |
369 | 171M | wsynth_out[i + i_subfr] = y0[i] + (pitch_gain * y1[i]) + (code_gain * y2[i]); |
370 | 171M | } |
371 | | |
372 | 174M | for (i = 0; i < LEN_SUBFR; i++) { |
373 | 171M | exc[i + i_subfr] = pitch_gain * exc[i + i_subfr] + code_gain * code[i]; |
374 | 171M | } |
375 | | |
376 | 2.68M | iusace_synthesis_tool_float(p_quant_lp_filt_coeff, &exc[i_subfr], &synth_out[i_subfr], |
377 | 2.68M | LEN_SUBFR, &synth_out[i_subfr - ORDER], |
378 | 2.68M | pstr_scratch->p_buf_synthesis_tool); |
379 | 2.68M | p_lp_filt_coeff += (ORDER + 1); |
380 | 2.68M | p_quant_lp_filt_coeff += (ORDER + 1); |
381 | 2.68M | } |
382 | | |
383 | 717k | memcpy(lpd_state->acelp_exc, exc - len_subfrm, 2 * len_subfrm * sizeof(FLOAT32)); |
384 | 717k | memcpy(lpd_state->synth, synth_out + len_subfrm - (ORDER + 128), |
385 | 717k | (ORDER + 128) * sizeof(FLOAT32)); |
386 | 717k | memcpy(lpd_state->wsynth, wsynth_out + len_subfrm - (1 + 128), (1 + 128) * sizeof(FLOAT32)); |
387 | 717k | memcpy(lpd_state->lpc_coeffs_quant, p_quant_lp_filt_coeff - (2 * (ORDER + 1)), |
388 | 717k | (2 * (ORDER + 1)) * sizeof(FLOAT32)); |
389 | 717k | memcpy(lpd_state->lpc_coeffs, p_lp_filt_coeff - (2 * (ORDER + 1)), |
390 | 717k | (2 * (ORDER + 1)) * sizeof(FLOAT32)); |
391 | | |
392 | 717k | mem_txn = lpd_state->tcx_mem[128 - 1]; |
393 | 717k | mem_txnq = lpd_state->tcx_fac; |
394 | | |
395 | 717k | p_quant_lp_filt_coeff = quant_lp_filt_coeff; |
396 | 1.96M | for (i_subfr = 0; i_subfr < (len_subfrm - 2 * LEN_SUBFR); i_subfr += LEN_SUBFR) { |
397 | 1.24M | iusace_get_weighted_lpc(p_quant_lp_filt_coeff, weighted_lpc); |
398 | | |
399 | 1.24M | memcpy(error, &speech_in[i_subfr], LEN_SUBFR * sizeof(FLOAT32)); |
400 | 1.24M | iusace_apply_deemph(error, TILT_FAC, LEN_SUBFR, &mem_txn); |
401 | | |
402 | 1.24M | memcpy(error, &synth_out[i_subfr], LEN_SUBFR * sizeof(FLOAT32)); |
403 | 1.24M | iusace_apply_deemph(error, TILT_FAC, LEN_SUBFR, &mem_txnq); |
404 | | |
405 | 1.24M | p_quant_lp_filt_coeff += (ORDER + 1); |
406 | 1.24M | } |
407 | | |
408 | 717k | lpd_state->tcx_quant[0] = mem_txnq; |
409 | 2.15M | for (i_subfr = 0; i_subfr < (2 * LEN_SUBFR); i_subfr += LEN_SUBFR) { |
410 | 1.43M | iusace_get_weighted_lpc(p_quant_lp_filt_coeff, weighted_lpc); |
411 | | |
412 | 1.43M | memcpy(&(lpd_state->tcx_mem[i_subfr]), &speech_in[i_subfr + (len_subfrm - 2 * LEN_SUBFR)], |
413 | 1.43M | LEN_SUBFR * sizeof(FLOAT32)); |
414 | 1.43M | iusace_apply_deemph(&(lpd_state->tcx_mem[i_subfr]), TILT_FAC, LEN_SUBFR, &mem_txn); |
415 | | |
416 | 1.43M | memcpy(&(lpd_state->tcx_quant[1 + i_subfr]), |
417 | 1.43M | &synth_out[i_subfr + (len_subfrm - 2 * LEN_SUBFR)], LEN_SUBFR * sizeof(FLOAT32)); |
418 | 1.43M | iusace_apply_deemph(&(lpd_state->tcx_quant[1 + i_subfr]), TILT_FAC, LEN_SUBFR, &mem_txnq); |
419 | 1.43M | p_quant_lp_filt_coeff += (ORDER + 1); |
420 | 1.43M | } |
421 | 717k | lpd_state->tcx_fac = mem_txnq; |
422 | | |
423 | 717k | iusace_get_weighted_lpc(p_quant_lp_filt_coeff, weighted_lpc); |
424 | | |
425 | 717k | memcpy(error, &synth_out[len_subfrm - ORDER], ORDER * sizeof(FLOAT32)); |
426 | 2.15M | for (i_subfr = (2 * LEN_SUBFR); i_subfr < (4 * LEN_SUBFR); i_subfr += LEN_SUBFR) { |
427 | 1.43M | memset(error + ORDER, 0, LEN_SUBFR * sizeof(FLOAT32)); |
428 | | |
429 | 1.43M | iusace_synthesis_tool_float(p_quant_lp_filt_coeff, error + ORDER, error + ORDER, LEN_SUBFR, |
430 | 1.43M | error, pstr_scratch->p_buf_synthesis_tool); |
431 | 1.43M | memcpy(&(lpd_state->tcx_quant[1 + i_subfr]), error + ORDER, LEN_SUBFR * sizeof(FLOAT32)); |
432 | 1.43M | iusace_apply_deemph(&(lpd_state->tcx_quant[1 + i_subfr]), TILT_FAC, LEN_SUBFR, &mem_txnq); |
433 | 1.43M | memcpy(error, error + LEN_SUBFR, ORDER * sizeof(FLOAT32)); |
434 | 1.43M | } |
435 | | |
436 | 717k | lpd_state->mode = 0; |
437 | | |
438 | 717k | lpd_state->num_bits = num_bits; |
439 | 717k | } |