1 /******************************************************************************
2 * *
3 * Copyright (C) 2018 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 #include "ixheaacd_type_def.h"
21 #include "ixheaacd_bitbuffer.h"
22 #include "ixheaacd_common_rom.h"
23 #include "ixheaacd_sbrdecsettings.h"
24 #include "ixheaacd_sbr_scale.h"
25 #include "ixheaacd_env_extr_part.h"
26 #include "ixheaacd_sbr_rom.h"
27 #include "ixheaacd_hybrid.h"
28 #include "ixheaacd_ps_dec.h"
29 #include "ixheaacd_config.h"
30 #include "ixheaacd_qmf_dec.h"
31 #include "ixheaacd_mps_polyphase.h"
32 #include "ixheaacd_mps_struct_def.h"
33 #include "ixheaacd_mps_res_rom.h"
34 #include "ixheaacd_mps_aac_struct.h"
35 #include "ixheaacd_constants.h"
36 #include "ixheaacd_basic_ops32.h"
37 #include "ixheaacd_basic_ops40.h"
38 #include "ixheaacd_mps_dec.h"
39 #include "ixheaacd_error_standards.h"
40 #include "ixheaacd_error_codes.h"
41 #include "ixheaacd_mps_macro_def.h"
42 #include "ixheaacd_mps_smoothing.h"
43 #include "ixheaacd_mps_tonality.h"
44 #ifndef MULT
45 #define MULT(a, b) (a * b)
46 #endif
47 #define ONE_BY_128_IN_Q30 (8388608)
48 #define ONE_IN_Q30 (1073741824)
49 #define PI_IN_Q27 (421657440)
50 #define FIFTY_X_PI_BY_180_Q27 (117127067)
51 #define TWENTY_FIVE_X_PI_BY_180_Q27 (58563533)
52 #define Q28_VALUE (1 << 28)
53 #define Q28_FLOAT_VAL ((FLOAT32)(1 << 28))
54 #define ONE_BY_Q28_FLOAT_VAL (1.0f / Q28_FLOAT_VAL)
55
ixheaacd_mps_pre_matrix_mix_matrix_smoothing(ia_mps_dec_state_struct * self)56 VOID ixheaacd_mps_pre_matrix_mix_matrix_smoothing(
57 ia_mps_dec_state_struct *self) {
58 WORD32 smooth_band;
59 FLOAT32 delta, one_minus_delta;
60 WORD32 ps = 0, pb, row, col;
61 WORD32 res_bands = 0;
62 WORD32 *p_smoothing_data;
63
64 if (self->residual_coding) res_bands = self->max_res_bands;
65
66 p_smoothing_data = &self->smoothing_data[ps][res_bands];
67
68 delta = self->param_slot_diff[ps] * self->inv_smoothing_time[ps];
69 one_minus_delta = 1.0f - delta;
70
71 for (pb = res_bands; pb < self->bs_param_bands; pb++) {
72 smooth_band = *p_smoothing_data++;
73 if (smooth_band) {
74 for (row = 0; row < MAX_M_OUTPUT; row++) {
75 for (col = 0; col < MAX_M_INPUT; col++) {
76 self->m1_param_re[ps][pb][row][col] =
77 (MULT(delta, self->m1_param_re[ps][pb][row][col]) +
78 MULT(one_minus_delta, self->m1_param_re_prev[pb][row][col]));
79 self->m1_param_im[ps][pb][row][col] =
80 (MULT(delta, self->m1_param_im[ps][pb][row][col]) +
81 MULT(one_minus_delta, self->m1_param_im_prev[pb][row][col]));
82 self->m2_decor_re[ps][pb][row][col] =
83 (MULT(delta, self->m2_decor_re[ps][pb][row][col]) +
84 MULT(one_minus_delta, self->m2_decor_re_prev[pb][row][col]));
85 self->m2_decor_im[ps][pb][row][col] =
86 (MULT(delta, self->m2_decor_im[ps][pb][row][col]) +
87 MULT(one_minus_delta, self->m2_decor_im_prev[pb][row][col]));
88 self->m2_resid_re[ps][pb][row][col] =
89 (MULT(delta, self->m2_resid_re[ps][pb][row][col]) +
90 MULT(one_minus_delta, self->m2_resid_re_prev[pb][row][col]));
91 self->m2_resid_im[ps][pb][row][col] =
92 (MULT(delta, self->m2_resid_im[ps][pb][row][col]) +
93 MULT(one_minus_delta, self->m2_resid_im_prev[pb][row][col]));
94 }
95 }
96 self->pre_mix_req++;
97 }
98 }
99
100 for (ps = 1; ps < self->num_parameter_sets; ps++) {
101 delta = self->param_slot_diff[ps] * self->inv_smoothing_time[ps];
102 one_minus_delta = 1.0f - delta;
103
104 p_smoothing_data = &self->smoothing_data[ps][res_bands];
105
106 for (pb = res_bands; pb < self->bs_param_bands; pb++) {
107 smooth_band = *p_smoothing_data++;
108 if (smooth_band) {
109 for (row = 0; row < MAX_M_OUTPUT; row++) {
110 for (col = 0; col < MAX_M_INPUT; col++) {
111 self->m1_param_re[ps][pb][row][col] =
112 (MULT(delta, self->m1_param_re[ps][pb][row][col]) +
113 MULT(one_minus_delta,
114 self->m1_param_re[ps - 1][pb][row][col]));
115 self->m1_param_im[ps][pb][row][col] =
116 (MULT(delta, self->m1_param_im[ps][pb][row][col]) +
117 MULT(one_minus_delta,
118 self->m1_param_im[ps - 1][pb][row][col]));
119 self->m2_resid_re[ps][pb][row][col] =
120 (MULT(delta, self->m2_resid_re[ps][pb][row][col]) +
121 MULT(one_minus_delta,
122 self->m2_resid_re[ps - 1][pb][row][col]));
123 self->m2_decor_re[ps][pb][row][col] =
124 (MULT(delta, self->m2_decor_re[ps][pb][row][col]) +
125 MULT(one_minus_delta,
126 self->m2_decor_re[ps - 1][pb][row][col]));
127 self->m2_decor_im[ps][pb][row][col] =
128 (MULT(delta, self->m2_decor_im[ps][pb][row][col]) +
129 MULT(one_minus_delta,
130 self->m2_decor_im[ps - 1][pb][row][col]));
131 self->m2_resid_im[ps][pb][row][col] =
132 (MULT(delta, self->m2_resid_im[ps][pb][row][col]) +
133 MULT(one_minus_delta,
134 self->m2_resid_im[ps - 1][pb][row][col]));
135 }
136 }
137 self->pre_mix_req++;
138 }
139 }
140 }
141 }
142
ixheaacd_mps_smoothing_opd(ia_mps_dec_state_struct * self)143 VOID ixheaacd_mps_smoothing_opd(ia_mps_dec_state_struct *self) {
144 WORD32 ps, pb;
145 WORD32 delta, one_minus_delta;
146
147 if (self->opd_smoothing_mode == 0) {
148 for (pb = 0; pb < self->bs_param_bands; pb++) {
149 self->opd_smooth.smooth_l_phase[pb] =
150 ((WORD32)(self->phase_l[self->num_parameter_sets - 1][pb] *
151 Q28_VALUE)) >>
152 1;
153 self->opd_smooth.smooth_r_phase[pb] =
154 ((WORD32)(self->phase_r[self->num_parameter_sets - 1][pb] *
155 Q28_VALUE)) >>
156 1;
157 }
158 return;
159 }
160 for (ps = 0; ps < self->num_parameter_sets; ps++) {
161 WORD32 thr = self->bs_frame.ipd_data.bs_quant_coarse_xxx[ps]
162 ? FIFTY_X_PI_BY_180_Q27
163 : TWENTY_FIVE_X_PI_BY_180_Q27;
164
165 delta = self->param_slot_diff[ps] * ONE_BY_128_IN_Q30;
166 one_minus_delta = ONE_IN_Q30 - delta;
167
168 for (pb = 0; pb < self->bs_param_bands; pb++) {
169 WORD32 ltemp, rtemp, tmp;
170 ltemp = ((WORD32)(self->phase_l[ps][pb] * Q28_FLOAT_VAL)) >> 1;
171 rtemp = ((WORD32)(self->phase_r[ps][pb] * Q28_FLOAT_VAL)) >> 1;
172
173 while (ltemp > self->opd_smooth.smooth_l_phase[pb] + PI_IN_Q27)
174 ltemp -= 2 * PI_IN_Q27;
175 while (ltemp < self->opd_smooth.smooth_l_phase[pb] - PI_IN_Q27)
176 ltemp += 2 * PI_IN_Q27;
177 while (rtemp > self->opd_smooth.smooth_r_phase[pb] + PI_IN_Q27)
178 rtemp -= 2 * PI_IN_Q27;
179 while (rtemp < self->opd_smooth.smooth_r_phase[pb] - PI_IN_Q27)
180 rtemp += 2 * PI_IN_Q27;
181
182 self->opd_smooth.smooth_l_phase[pb] =
183 (ixheaacd_mult32_shl(delta, ltemp) +
184 ixheaacd_mult32_shl(one_minus_delta,
185 self->opd_smooth.smooth_l_phase[pb]))
186 << 1;
187 self->opd_smooth.smooth_r_phase[pb] =
188 (ixheaacd_mult32_shl(delta, rtemp) +
189 ixheaacd_mult32_shl(one_minus_delta,
190 self->opd_smooth.smooth_r_phase[pb]))
191 << 1;
192
193 tmp = (ltemp - rtemp) - (self->opd_smooth.smooth_l_phase[pb] -
194 self->opd_smooth.smooth_r_phase[pb]);
195 while (tmp > PI_IN_Q27) tmp -= 2 * PI_IN_Q27;
196 while (tmp < -PI_IN_Q27) tmp += 2 * PI_IN_Q27;
197
198 if (ixheaacd_abs32(tmp) > thr) {
199 self->opd_smooth.smooth_l_phase[pb] = ltemp;
200 self->opd_smooth.smooth_r_phase[pb] = rtemp;
201 }
202
203 while (self->opd_smooth.smooth_l_phase[pb] > 2 * PI_IN_Q27)
204 self->opd_smooth.smooth_l_phase[pb] -= 2 * PI_IN_Q27;
205 while (self->opd_smooth.smooth_l_phase[pb] < 0)
206 self->opd_smooth.smooth_l_phase[pb] += 2 * PI_IN_Q27;
207 while (self->opd_smooth.smooth_r_phase[pb] > 2 * PI_IN_Q27)
208 self->opd_smooth.smooth_r_phase[pb] -= 2 * PI_IN_Q27;
209 while (self->opd_smooth.smooth_r_phase[pb] < 0)
210 self->opd_smooth.smooth_r_phase[pb] += 2 * PI_IN_Q27;
211
212 self->phase_l[ps][pb] =
213 (self->opd_smooth.smooth_l_phase[pb] << 1) * ONE_BY_Q28_FLOAT_VAL;
214 self->phase_r[ps][pb] =
215 (self->opd_smooth.smooth_r_phase[pb] << 1) * ONE_BY_Q28_FLOAT_VAL;
216 }
217 }
218 }
219
ixheaacd_calc_filter_coeff(ia_heaac_mps_state_struct * pstr_mps_state,WORD32 ps,WORD32 * delta)220 static VOID ixheaacd_calc_filter_coeff(
221 ia_heaac_mps_state_struct *pstr_mps_state, WORD32 ps, WORD32 *delta) {
222 WORD32 d_slots;
223 WORD32 *param_slot = pstr_mps_state->aux_struct->param_slot;
224 WORD32 *smg_time = pstr_mps_state->aux_struct->smg_time;
225
226 if (ps == 0)
227 d_slots = param_slot[ps] + 1;
228 else
229 d_slots = param_slot[ps] - param_slot[ps - 1];
230
231 if (pstr_mps_state->smooth_control) {
232 switch (smg_time[ps]) {
233 case SMG_TIME_64:
234 *delta = d_slots << 9;
235 break;
236 case SMG_TIME_128:
237 *delta = d_slots << 8;
238 break;
239 case SMG_TIME_256:
240 *delta = d_slots << 7;
241 break;
242 case SMG_TIME_512:
243 *delta = d_slots << 6;
244 break;
245 default:
246 break;
247 }
248 } else {
249 *delta = d_slots << 7;
250 }
251
252 return;
253 }
254
ixheaacd_smooth_m1m2(ia_heaac_mps_state_struct * pstr_mps_state)255 VOID ixheaacd_smooth_m1m2(ia_heaac_mps_state_struct *pstr_mps_state) {
256 ia_heaac_mps_state_struct *curr_state = pstr_mps_state;
257 ia_mps_persistent_mem *persistent_mem = &curr_state->mps_persistent_mem;
258 ia_mps_dec_auxilary_struct *p_aux_struct = pstr_mps_state->aux_struct;
259 ia_mps_dec_m2_param_struct *m2_param = p_aux_struct->m2_param;
260 ia_mps_dec_m1_param_struct *m1_param = pstr_mps_state->array_struct->m1_param;
261 WORD32 *m1_param_real_prev = persistent_mem->m1_param_real_prev;
262 WORD32 *m2_decor_real_prev = persistent_mem->m2_decor_real_prev;
263 WORD32 *m2_resid_real_prev = persistent_mem->m2_resid_real_prev;
264
265 WORD32 num_parameter_bands = curr_state->num_parameter_bands;
266 WORD32 num_direct_signals = curr_state->num_direct_signals;
267 WORD32 num_decor_signals = curr_state->num_decor_signals;
268 WORD32 m1_param_imag_present = curr_state->m1_param_imag_present;
269 WORD32 m2_param_imag_present = curr_state->m2_param_imag_present;
270 WORD32 col_counter = num_direct_signals + num_decor_signals;
271 WORD32 num_parameter_sets = curr_state->num_parameter_sets;
272 WORD32 num_output_channels = curr_state->num_output_channels;
273 WORD32 num_v_channels = curr_state->num_v_channels;
274 WORD32 num_x_channels = curr_state->num_x_channels;
275 WORD32 smooth_control = curr_state->smooth_control;
276 WORD32 smooth_config = curr_state->smooth_config;
277 WORD32 resid_col_counter;
278 WORD32 smooth_band_arr[MAX_PARAMETER_SETS][MAX_PARAMETER_BANDS];
279
280 WORD32 *delta, *one_minus_delta, *delta_ptr, *one_minus_delta_ptr;
281 WORD32 *param_r, *param_i, *param_prev_r, *param_prev_i;
282
283 WORD32 *ton;
284 WORD32 i, ps, pb, row, col;
285 WORD32 res_bands = 0;
286 WORD32 idx = 0;
287
288 WORD32 *m2_decor_imag_prev = persistent_mem->m2_decor_imag_prev;
289 WORD32 *m2_resid_imag_prev = persistent_mem->m2_resid_imag_prev;
290 WORD32 *m1_param_imag_prev = persistent_mem->m1_param_imag_prev;
291
292 ton = pstr_mps_state->mps_scratch_mem_v;
293 delta = delta_ptr = ton + MAX_PARAMETER_BANDS;
294 one_minus_delta = one_minus_delta_ptr = delta + MAX_PARAMETER_SETS;
295
296 param_r = curr_state->res_bands;
297 if (curr_state->residual_coding) {
298 for (i = 0; i < MAX_RESIDUAL_CHANNELS_MPS; i++) {
299 if (param_r[i] > res_bands) {
300 res_bands = param_r[i];
301 }
302 }
303 }
304
305 if (curr_state->arbitrary_downmix == 2) {
306 if (res_bands < curr_state->arbdmx_residual_bands) {
307 res_bands = curr_state->arbdmx_residual_bands;
308 }
309 }
310
311 if (smooth_config) {
312 ixheaacd_measure_tonality(pstr_mps_state, ton);
313 }
314
315 for (ps = 0; ps < num_parameter_sets; ps++) {
316 ixheaacd_calc_filter_coeff(pstr_mps_state, ps, delta);
317 *one_minus_delta++ = (1 << 15) - *delta++;
318 }
319
320 if (smooth_control) {
321 for (ps = 0; ps < num_parameter_sets; ps++) {
322 if (ps < 8) {
323 for (pb = 0; pb < num_parameter_bands; pb++) {
324 smooth_band_arr[ps][pb] = pstr_mps_state->aux_struct->smg_data[ps][pb];
325 }
326 }
327 }
328 } else if (smooth_config) {
329 for (ps = 0; ps < num_parameter_sets; ps++) {
330 for (pb = 0; pb < num_parameter_bands; pb++) {
331 smooth_band_arr[ps][pb] = (ton[pb] > POINT_EIGHT_Q15);
332 }
333 }
334 }
335
336 if (!(smooth_control == 0 && smooth_config == 0)) {
337 if (m1_param_imag_present) {
338 WORD32 *ptr_r1 = &m1_param->m1_param_real[0][0][0][0];
339 WORD32 *ptr_i1 = &m1_param->m1_param_imag[0][0][0][0];
340 for (row = 0; row < num_v_channels; row++) {
341 WORD32 *ptr_r2 = ptr_r1;
342 WORD32 *ptr_i2 = ptr_i1;
343 for (col = 0; col < num_x_channels; col++) {
344 param_r = ptr_r2;
345 param_i = ptr_i2;
346 m1_param_real_prev += res_bands;
347 m1_param_imag_prev += res_bands;
348
349 for (pb = res_bands; pb < num_parameter_bands; pb++) {
350 if (smooth_band_arr[0][pb]) {
351 WORD64 acc;
352
353 acc = (WORD64)((WORD64)param_r[pb] * (WORD64)(*delta_ptr) +
354 (WORD64)(*m1_param_real_prev) *
355 (WORD64)(*one_minus_delta_ptr));
356
357 acc >>= 15;
358
359 param_r[pb] = (WORD32)acc;
360
361 acc = (WORD64)((WORD64)param_i[pb] * (WORD64)(*delta_ptr) +
362 (WORD64)(*m1_param_imag_prev) *
363 (WORD64)(*one_minus_delta_ptr));
364
365 acc >>= 15;
366
367 param_i[pb] = (WORD32)acc;
368 }
369 m1_param_real_prev++;
370 m1_param_imag_prev++;
371 }
372 param_r += MAX_PARAMETER_BANDS;
373 param_i += MAX_PARAMETER_BANDS;
374
375 for (ps = 1; ps < num_parameter_sets; ps++) {
376 WORD32 del = delta_ptr[ps];
377 WORD32 one_minus_del = one_minus_delta_ptr[ps];
378
379 param_prev_r = param_r - MAX_PARAMETER_BANDS;
380 param_prev_i = param_i - MAX_PARAMETER_BANDS;
381
382 for (pb = res_bands; pb < num_parameter_bands; pb++) {
383 if (smooth_band_arr[ps][pb]) {
384 WORD64 acc;
385
386 acc = (WORD64)((WORD64)param_r[pb] * (WORD64)(del) +
387 (WORD64)param_prev_r[pb] *
388 (WORD64)(one_minus_del));
389
390 acc >>= 15;
391
392 param_r[pb] = (WORD32)acc;
393
394 acc = (WORD64)((WORD64)param_i[pb] * (WORD64)(del) +
395 (WORD64)param_prev_i[pb] *
396 (WORD64)(one_minus_del));
397
398 acc >>= 15;
399
400 param_i[pb] = (WORD32)acc;
401 }
402 }
403 param_r += MAX_PARAMETER_BANDS;
404 param_i += MAX_PARAMETER_BANDS;
405 }
406 ptr_r2 += PBXPS;
407 ptr_i2 += PBXPS;
408 }
409 ptr_r1 += INCHXPBXPS;
410 ptr_i1 += INCHXPBXPS;
411 }
412 } else {
413 WORD32 *ptr1 = (WORD32 *)m1_param;
414
415 for (row = 0; row < num_v_channels; row++) {
416 WORD32 *ptr2 = ptr1;
417
418 for (col = 0; col < num_x_channels; col++) {
419 WORD32 *param_r = ptr2;
420
421 WORD32 del = delta_ptr[0];
422 WORD32 one_minus_del = one_minus_delta_ptr[0];
423
424 m1_param_real_prev += res_bands;
425
426 for (pb = res_bands; pb < num_parameter_bands; pb++) {
427 if (smooth_band_arr[0][pb]) {
428 WORD64 acc;
429
430 acc = (WORD64)((WORD64)(param_r[pb]) * (WORD64)(del)) +
431 (WORD64)((WORD64)(*m1_param_real_prev) *
432 (WORD64)(one_minus_del));
433
434 param_r[pb] = (WORD32)(acc >> 15);
435 }
436 m1_param_real_prev++;
437 }
438 param_r += MAX_PARAMETER_BANDS;
439
440 for (ps = 1; ps < num_parameter_sets; ps++) {
441 WORD32 del = delta_ptr[ps];
442 WORD32 one_minus_del = one_minus_delta_ptr[ps];
443
444 param_prev_r = param_r - MAX_PARAMETER_BANDS;
445
446 for (pb = res_bands; pb < num_parameter_bands; pb++) {
447 if (smooth_band_arr[ps][pb]) {
448 WORD64 acc;
449
450 acc = (WORD64)((WORD64)(param_r[pb]) * (WORD64)del) +
451 (WORD64)((WORD64)(param_prev_r[pb]) *
452 (WORD64)one_minus_del);
453
454 param_r[pb] = (WORD32)(acc >> 15);
455 }
456 }
457 param_r += MAX_PARAMETER_BANDS;
458 }
459 ptr2 += PBXPS;
460 }
461 ptr1 += INCHXPBXPS;
462 }
463 }
464
465 if (curr_state->residual_coding)
466 resid_col_counter = col_counter;
467 else
468 resid_col_counter = num_direct_signals;
469
470 idx = 0;
471 if (m2_param_imag_present) {
472 WORD32 *ptr_r1 = &m2_param->m2_resid_real[0][0][0];
473 WORD32 *ptr_i1 = &m2_param->m2_resid_imag[0][0][0];
474 for (row = 0; row < num_output_channels; row++) {
475 for (col = 0; col < resid_col_counter; col++) {
476 if (curr_state->m2_param_present[row][col] & 2) {
477 WORD32 del = *delta_ptr;
478 WORD32 one_minus_del = *one_minus_delta_ptr;
479
480 param_r = ptr_r1;
481 param_i = ptr_i1;
482
483 m2_resid_real_prev += res_bands;
484 m2_resid_imag_prev += res_bands;
485
486 for (pb = res_bands; pb < num_parameter_bands; pb++) {
487 if (smooth_band_arr[0][pb]) {
488 WORD64 acc;
489 acc = (WORD64)((WORD64)(param_r[pb]) * (WORD64)(del) +
490 (WORD64)(*m2_resid_real_prev) *
491 (WORD64)(one_minus_del));
492
493 acc >>= 15;
494 param_r[pb] = (WORD32)acc;
495
496 acc = (WORD64)((WORD64)(param_i[pb]) * (WORD64)(del) +
497 (WORD64)(*m2_resid_imag_prev) *
498 (WORD64)(one_minus_del));
499
500 acc >>= 15;
501 param_i[pb] = (WORD32)acc;
502 }
503
504 m2_resid_real_prev++;
505 m2_resid_imag_prev++;
506 }
507
508 param_r += MAX_PARAMETER_BANDS;
509 param_i += MAX_PARAMETER_BANDS;
510
511 for (ps = 1; ps < num_parameter_sets; ps++) {
512 WORD32 del = delta_ptr[ps];
513 WORD32 one_minus_del = one_minus_delta_ptr[ps];
514
515 param_prev_r = param_r - MAX_PARAMETER_BANDS;
516 param_prev_i = param_i - MAX_PARAMETER_BANDS;
517 for (pb = res_bands; pb < num_parameter_bands; pb++) {
518 if (smooth_band_arr[ps][pb]) {
519 WORD64 acc;
520 acc = (WORD64)((WORD64)(param_r[pb]) * (WORD64)(del) +
521 (WORD64)(param_prev_r[pb]) *
522 (WORD64)(one_minus_del));
523
524 acc >>= 15;
525 param_r[pb] = (WORD32)acc;
526
527 acc = (WORD64)((WORD64)(param_i[pb]) * (WORD64)(del) +
528 (WORD64)(param_prev_i[pb]) *
529 (WORD64)(one_minus_del));
530
531 acc >>= 15;
532 param_i[pb] = (WORD32)acc;
533 }
534 }
535 param_r += MAX_PARAMETER_BANDS;
536 param_i += MAX_PARAMETER_BANDS;
537 }
538 idx++;
539 ptr_r1 += PBXPS;
540 ptr_i1 += PBXPS;
541 }
542 }
543 }
544
545 idx = 0;
546
547 ptr_r1 = &m2_param->m2_resid_real[0][0][0];
548 ptr_i1 = &m2_param->m2_resid_imag[0][0][0];
549 for (row = 0; row < num_output_channels; row++) {
550 for (col = num_direct_signals; col < col_counter; col++) {
551 if (curr_state->m2_param_present[row][col] & 1) {
552 WORD32 del = *delta_ptr;
553 WORD32 one_minus_del = *one_minus_delta_ptr;
554 m2_decor_real_prev += res_bands;
555 m2_decor_imag_prev += res_bands;
556
557 param_r = ptr_r1;
558 param_i = ptr_i1;
559
560 for (pb = res_bands; pb < num_parameter_bands; pb++) {
561 if (smooth_band_arr[0][pb]) {
562 WORD64 acc;
563 acc = (WORD64)((WORD64)(param_r[pb]) * (WORD64)del +
564 (WORD64)(*m2_decor_real_prev) *
565 (WORD64)one_minus_del);
566 acc >>= 15;
567 param_r[pb] = (WORD32)acc;
568
569 acc = (WORD64)((WORD64)(param_i[pb]) * (WORD64)del +
570 (WORD64)(*m2_decor_imag_prev) *
571 (WORD64)one_minus_del);
572 acc >>= 15;
573 param_i[pb] = (WORD32)acc;
574 }
575 m2_decor_real_prev++;
576 m2_decor_imag_prev++;
577 }
578
579 param_r += MAX_PARAMETER_BANDS;
580 param_i += MAX_PARAMETER_BANDS;
581
582 for (ps = 1; ps < num_parameter_sets; ps++) {
583 WORD32 del = delta_ptr[ps];
584 WORD32 one_minus_del = one_minus_delta_ptr[ps];
585 param_prev_r = param_r - MAX_PARAMETER_BANDS;
586 param_prev_i = param_i - MAX_PARAMETER_BANDS;
587 for (pb = res_bands; pb < num_parameter_bands; pb++) {
588 if (smooth_band_arr[ps][pb]) {
589 WORD64 acc;
590
591 acc = (WORD64)((WORD64)(param_r[pb]) * (WORD64)del +
592 (WORD64)(param_prev_r[pb]) *
593 (WORD64)one_minus_del);
594 acc >>= 15;
595 param_r[pb] = (WORD32)acc;
596
597 acc = (WORD64)((WORD64)(param_i[pb]) * (WORD64)del +
598 (WORD64)(param_prev_i[pb]) *
599 (WORD64)one_minus_del);
600 acc >>= 15;
601 param_i[pb] = (WORD32)acc;
602 }
603 }
604 param_r += MAX_PARAMETER_BANDS;
605 param_i += MAX_PARAMETER_BANDS;
606 }
607
608 idx++;
609 ptr_r1 += PBXPS;
610 ptr_i1 += PBXPS;
611 }
612 }
613 }
614 } else {
615 WORD32 *ptr1 = &m2_param->m2_resid_real[0][0][0];
616
617 for (row = 0; row < num_output_channels; row++) {
618 for (col = 0; col < resid_col_counter; col++) {
619 if (curr_state->m2_param_present[row][col] & 2) {
620 WORD32 *ptr2 = ptr1;
621 WORD32 del = *delta_ptr;
622 WORD32 one_minus_del = *one_minus_delta_ptr;
623 m2_resid_real_prev += res_bands;
624
625 for (pb = res_bands; pb < num_parameter_bands; pb++) {
626 if (smooth_band_arr[0][pb]) {
627 WORD64 acc;
628
629 acc = (WORD64)((WORD64)(ptr2[pb]) * (WORD64)(del) +
630 (WORD64)(*m2_resid_real_prev) *
631 (WORD64)(one_minus_del));
632
633 acc >>= 15;
634 ptr2[pb] = (WORD32)acc;
635 }
636
637 m2_resid_real_prev++;
638 }
639
640 ptr2 += MAX_PARAMETER_BANDS;
641
642 for (ps = 1; ps < num_parameter_sets; ps++) {
643 WORD32 del = delta_ptr[ps];
644 WORD32 one_minus_del = one_minus_delta_ptr[ps];
645
646 param_prev_r = ptr2 - MAX_PARAMETER_BANDS;
647
648 for (pb = res_bands; pb < num_parameter_bands; pb++) {
649 if (smooth_band_arr[ps][pb]) {
650 WORD64 acc;
651
652 acc = (WORD64)((WORD64)(ptr2[pb]) * (WORD64)(del) +
653 (WORD64)(*param_prev_r) *
654 (WORD64)(one_minus_del));
655
656 acc >>= 15;
657 ptr2[pb] = (WORD32)acc;
658 }
659
660 param_prev_r++;
661 }
662 ptr2 += MAX_PARAMETER_BANDS;
663 }
664 idx++;
665 ptr1 += PBXPS;
666 }
667 }
668 }
669 idx = 0;
670 ptr1 = &m2_param->m2_decor_real[0][0][0];
671
672 for (row = 0; row < num_output_channels; row++) {
673 for (col = num_direct_signals; col < col_counter; col++) {
674 if (curr_state->m2_param_present[row][col] & 1) {
675 WORD32 *ptr2 = ptr1;
676 m2_decor_real_prev += res_bands;
677
678 param_r = &m2_param->m2_decor_real[idx][0][res_bands];
679 for (pb = res_bands; pb < num_parameter_bands; pb++) {
680 if (smooth_band_arr[0][pb]) {
681 WORD64 acc;
682 acc = (WORD64)((WORD64)(ptr2[pb]) * (WORD64)*delta_ptr +
683 (WORD64)(*m2_decor_real_prev) *
684 (WORD64)*one_minus_delta_ptr);
685 acc >>= 15;
686 ptr2[pb] = (WORD32)acc;
687 }
688 m2_decor_real_prev++;
689 }
690 ptr2 += MAX_PARAMETER_BANDS;
691
692 for (ps = 1; ps < num_parameter_sets; ps++) {
693 WORD32 del = delta_ptr[ps];
694 WORD32 one_minus_del = one_minus_delta_ptr[ps];
695
696 param_prev_r = ptr2 - MAX_PARAMETER_BANDS;
697 for (pb = res_bands; pb < num_parameter_bands; pb++) {
698 if (smooth_band_arr[ps][pb]) {
699 WORD64 acc;
700
701 acc =
702 (WORD64)((WORD64)(ptr2[pb]) * (WORD64)del +
703 (WORD64)(*param_prev_r) * (WORD64)one_minus_del);
704 acc >>= 15;
705 ptr2[pb] = (WORD32)acc;
706 }
707
708 param_prev_r++;
709 }
710
711 ptr2 += MAX_PARAMETER_BANDS;
712 }
713
714 idx++;
715
716 ptr1 += PBXPS;
717 }
718 }
719 }
720 }
721 }
722 return;
723 }
724