/src/libxaac/decoder/ixheaacd_mps_reshape_bb_env.c
Line | Count | Source |
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 | | #include "ixheaac_type_def.h" |
21 | | #include "ixheaacd_mps_struct_def.h" |
22 | | #include "ixheaacd_mps_res_rom.h" |
23 | | #include "ixheaacd_mps_aac_struct.h" |
24 | | #include "ixheaac_constants.h" |
25 | | #include "ixheaac_basic_ops32.h" |
26 | | #include "ixheaac_basic_ops40.h" |
27 | | #include "ixheaacd_bitbuffer.h" |
28 | | #include "ixheaacd_error_codes.h" |
29 | | #include "ixheaacd_common_rom.h" |
30 | | #include "ixheaacd_sbrdecsettings.h" |
31 | | #include "ixheaacd_sbr_scale.h" |
32 | | #include "ixheaacd_env_extr_part.h" |
33 | | #include "ixheaacd_sbr_rom.h" |
34 | | #include "ixheaacd_hybrid.h" |
35 | | #include "ixheaacd_ps_dec.h" |
36 | | #include "ixheaacd_mps_polyphase.h" |
37 | | #include "ixheaacd_config.h" |
38 | | #include "ixheaacd_qmf_dec.h" |
39 | | #include "ixheaacd_mps_dec.h" |
40 | | #include "ixheaacd_mps_bitdec.h" |
41 | | #include "ixheaacd_mps_macro_def.h" |
42 | | #include "ixheaacd_mps_basic_op.h" |
43 | | #include "ixheaacd_mps_reshape_bb_env.h" |
44 | | #include "ixheaac_error_standards.h" |
45 | | |
46 | | #define ALIGN_SIZE64(x) ((((x) + 7) >> 3) << 3) |
47 | | |
48 | 1.09k | VOID ixheaacd_init_bb_env(ia_heaac_mps_state_struct *pstr_mps_state) { |
49 | 1.09k | WORD32 k, j; |
50 | 1.09k | ia_mps_dec_reshape_bb_env_state_struct *reshape_bb_env_state = |
51 | 1.09k | pstr_mps_state->mps_persistent_mem.reshape_bb_env_state; |
52 | | |
53 | 25.1k | for (k = 0; k < 2 * MAX_OUTPUT_CHANNELS_MPS + MAX_INPUT_CHANNELS_MPS; k++) { |
54 | 24.0k | reshape_bb_env_state->norm_nrg_prev[k] = ONE_IN_Q30; |
55 | 24.0k | reshape_bb_env_state->frame_nrg_prev[k] = 0; |
56 | 24.0k | reshape_bb_env_state->q_frame_nrg_prev[k] = 30; |
57 | 24.0k | reshape_bb_env_state->q_norm_nrg_prev[k] = 30; |
58 | 697k | for (j = 0; j < MAX_PARAMETER_BANDS; j++) { |
59 | 673k | reshape_bb_env_state->part_nrg_prev[k][j] = 0; |
60 | 673k | reshape_bb_env_state->q_part_nrg_prev[k][j] = 30; |
61 | 673k | } |
62 | 24.0k | } |
63 | 1.09k | } |
64 | | |
65 | | static VOID ixheaacd_extract_bb_env(ia_heaac_mps_state_struct *pstr_mps_state, WORD32 inp, |
66 | 42.0k | WORD32 ch, WORD32 *env, VOID *scratch, WORD32 flag) { |
67 | 42.0k | ia_mps_dec_reshape_bb_env_state_struct *reshape_bb_env_state = |
68 | 42.0k | pstr_mps_state->mps_persistent_mem.reshape_bb_env_state; |
69 | 42.0k | WORD64 *slot_nrg_fix, *slot_nrg; |
70 | 42.0k | WORD16 *q_slot_nrg_fix, *q_slot_nrg; |
71 | 42.0k | WORD32 *part_nrg_fix; |
72 | 42.0k | WORD16 *q_part_nrg_fix; |
73 | | |
74 | 42.0k | WORD32 *p_buffer_real, *p_buffer_imag, *p_buffer_re, *p_buffer_im; |
75 | 42.0k | WORD32 ts, qs, pb; |
76 | | |
77 | 42.0k | WORD32 start_p = 10; |
78 | 42.0k | WORD32 end_p = 18; |
79 | 42.0k | WORD32 env_fix_l; |
80 | 42.0k | WORD16 q_env_fix_l; |
81 | | |
82 | 42.0k | WORD16 alpha_fix = ALPHA_Q15; |
83 | 42.0k | WORD16 beta_fix = BETA_Q15; |
84 | | |
85 | 42.0k | WORD16 one_min_alpha_fix = ONE_MINUS_ALPHA_Q16; |
86 | 42.0k | WORD16 one_min_beta_fix = ONE_MINUS_BETA_Q16; |
87 | 42.0k | WORD16 one_by_nine = ONE_BY_NINE_Q16; |
88 | 42.0k | WORD32 frame_nrg_fix = 0; |
89 | 42.0k | WORD32 *norm_nrg_fix; |
90 | 42.0k | WORD16 q_frame_nrg_fix = 0; |
91 | 42.0k | WORD16 *q_norm_nrg_fix; |
92 | 42.0k | WORD32 temp_1, temp4; |
93 | 42.0k | WORD16 qtemp1, q_env; |
94 | | |
95 | 42.0k | WORD32 prev_ch_offs; |
96 | 42.0k | WORD32 cnt = min(42, pstr_mps_state->hybrid_bands); |
97 | 42.0k | WORD32 time_slots = pstr_mps_state->time_slots; |
98 | 42.0k | const WORD32 *sqrt_tab = pstr_mps_state->ia_mps_dec_mps_table.common_table_ptr->sqrt_tab; |
99 | 42.0k | WORD32 *hyb_output_real_dry, *n_slot_nrg; |
100 | 42.0k | WORD32 *hyb_output_imag_dry; |
101 | | |
102 | 42.0k | const WORD32 *bb_env_kernels = |
103 | 42.0k | pstr_mps_state->ia_mps_dec_mps_table.bitdec_table_ptr->kernel_table.bb_env_kernels; |
104 | | |
105 | 42.0k | q_slot_nrg_fix = (WORD16 *)scratch; |
106 | 42.0k | n_slot_nrg = |
107 | 42.0k | (WORD32 *)((WORD8 *)scratch + IXHEAAC_GET_SIZE_ALIGNED(RESHAPE_OFFSET_1, BYTE_ALIGN_8)); |
108 | 42.0k | slot_nrg_fix = |
109 | 42.0k | (WORD64 *)((WORD8 *)scratch + IXHEAAC_GET_SIZE_ALIGNED(RESHAPE_OFFSET_2, BYTE_ALIGN_8)); |
110 | 42.0k | switch (inp) { |
111 | 0 | WORD32 frame_nrg_prev; |
112 | 0 | WORD16 q_frame_nrg_prev; |
113 | 0 | WORD32 *p_hyb_out_dry_real, *p_hyb_out_dry_imag; |
114 | | |
115 | 28.3k | case INP_DRY_WET: |
116 | 28.3k | frame_nrg_prev = reshape_bb_env_state->frame_nrg_prev[ch]; |
117 | 28.3k | q_frame_nrg_prev = reshape_bb_env_state->q_frame_nrg_prev[ch]; |
118 | | |
119 | 28.3k | part_nrg_fix = &reshape_bb_env_state->part_nrg_prev[ch][0]; |
120 | 28.3k | q_part_nrg_fix = &reshape_bb_env_state->q_part_nrg_prev[ch][0]; |
121 | | |
122 | 28.3k | norm_nrg_fix = &reshape_bb_env_state->norm_nrg_prev[ch]; |
123 | 28.3k | q_norm_nrg_fix = &reshape_bb_env_state->q_norm_nrg_prev[ch]; |
124 | | |
125 | 28.3k | p_buffer_real = pstr_mps_state->array_struct->buf_real + ch * TSXHB + 12; |
126 | 28.3k | p_buffer_imag = pstr_mps_state->array_struct->buf_imag + ch * TSXHB + 12; |
127 | | |
128 | 28.3k | p_hyb_out_dry_real = pstr_mps_state->array_struct->hyb_output_real_dry + ch * TSXHB + 12; |
129 | 28.3k | p_hyb_out_dry_imag = pstr_mps_state->array_struct->hyb_output_imag_dry + ch * TSXHB + 12; |
130 | | |
131 | 830k | for (ts = 0; ts < time_slots; ts++) { |
132 | 801k | WORD32 prev_idx = 10; |
133 | | |
134 | 801k | slot_nrg = slot_nrg_fix + 4; |
135 | 4.81M | for (pb = 14; pb <= end_p; pb++) *slot_nrg++ = 0; |
136 | | |
137 | 801k | slot_nrg = slot_nrg_fix; |
138 | | |
139 | 801k | p_buffer_re = p_buffer_real; |
140 | 801k | p_buffer_im = p_buffer_imag; |
141 | | |
142 | 801k | hyb_output_real_dry = p_hyb_out_dry_real; |
143 | 801k | hyb_output_imag_dry = p_hyb_out_dry_imag; |
144 | | |
145 | 4.00M | for (qs = 12; qs < 16; qs++) { |
146 | 3.20M | temp_1 = ixheaac_add32_sat(*hyb_output_real_dry, *p_buffer_re); |
147 | 3.20M | temp4 = ixheaac_add32_sat(*hyb_output_imag_dry, *p_buffer_im); |
148 | | |
149 | 3.20M | *slot_nrg++ = ixheaac_add64_sat(ixheaac_mult32x32in64(temp_1, temp_1), |
150 | 3.20M | ixheaac_mult32x32in64(temp4, temp4)); |
151 | | |
152 | 3.20M | p_buffer_re++; |
153 | 3.20M | p_buffer_im++; |
154 | 3.20M | hyb_output_real_dry++; |
155 | 3.20M | hyb_output_imag_dry++; |
156 | 3.20M | } |
157 | 801k | prev_idx = 14; |
158 | 12.0M | for (; qs < 30; qs++) { |
159 | 11.2M | WORD32 idx = bb_env_kernels[qs]; |
160 | 11.2M | if (prev_idx != idx) { |
161 | 2.40M | slot_nrg++; |
162 | 2.40M | prev_idx = idx; |
163 | 2.40M | } |
164 | 11.2M | temp_1 = ixheaac_add32_sat(*hyb_output_real_dry, *p_buffer_re); |
165 | 11.2M | temp4 = ixheaac_add32_sat(*hyb_output_imag_dry, *p_buffer_im); |
166 | | |
167 | 11.2M | *slot_nrg = ixheaac_add64_sat(*slot_nrg, ixheaac_mult32x32in64(temp_1, temp_1)); |
168 | 11.2M | *slot_nrg = ixheaac_add64_sat(*slot_nrg, ixheaac_mult32x32in64(temp4, temp4)); |
169 | | |
170 | 11.2M | p_buffer_re++; |
171 | 11.2M | p_buffer_im++; |
172 | 11.2M | hyb_output_real_dry++; |
173 | 11.2M | hyb_output_imag_dry++; |
174 | 11.2M | } |
175 | 801k | slot_nrg++; |
176 | 10.2M | for (; qs < cnt; qs++) { |
177 | 9.43M | temp_1 = ixheaac_add32_sat(*hyb_output_real_dry, *p_buffer_re); |
178 | 9.43M | temp4 = ixheaac_add32_sat(*hyb_output_imag_dry, *p_buffer_im); |
179 | | |
180 | 9.43M | *slot_nrg = ixheaac_add64_sat(*slot_nrg, ixheaac_mult32x32in64(temp_1, temp_1)); |
181 | 9.43M | *slot_nrg = ixheaac_add64_sat(*slot_nrg, ixheaac_mult32x32in64(temp4, temp4)); |
182 | | |
183 | 9.43M | p_buffer_re++; |
184 | 9.43M | p_buffer_im++; |
185 | 9.43M | hyb_output_real_dry++; |
186 | 9.43M | hyb_output_imag_dry++; |
187 | 9.43M | } |
188 | | |
189 | 801k | slot_nrg = slot_nrg_fix; |
190 | 801k | q_slot_nrg = q_slot_nrg_fix; |
191 | | |
192 | 801k | frame_nrg_fix = 0; |
193 | 801k | q_frame_nrg_fix = 30; |
194 | 8.01M | for (pb = start_p; pb <= end_p; pb++) { |
195 | 7.21M | *n_slot_nrg = ixheaacd_mps_narrow(*slot_nrg, q_slot_nrg); |
196 | 7.21M | slot_nrg++; |
197 | 7.21M | temp_1 = ixheaac_mult32x16in32(*n_slot_nrg, one_min_alpha_fix); |
198 | 7.21M | temp4 = ixheaac_mult32x16in32((part_nrg_fix[pb]) << 1, alpha_fix); |
199 | 7.21M | part_nrg_fix[pb] = |
200 | 7.21M | ixheaacd_mps_reshape_add32(temp4, temp_1, &q_part_nrg_fix[pb], *q_slot_nrg); |
201 | | |
202 | 7.21M | frame_nrg_fix = ixheaacd_mps_reshape_add32(frame_nrg_fix, *n_slot_nrg++, |
203 | 7.21M | &q_frame_nrg_fix, *q_slot_nrg++); |
204 | 7.21M | } |
205 | | |
206 | 801k | frame_nrg_fix = ixheaac_mult32x16in32(frame_nrg_fix, one_by_nine); |
207 | | |
208 | 801k | temp_1 = ixheaac_mult32x16in32(frame_nrg_fix, one_min_alpha_fix); |
209 | 801k | temp4 = ixheaac_mult32x16in32((frame_nrg_prev) << 1, alpha_fix); |
210 | 801k | frame_nrg_fix = |
211 | 801k | ixheaacd_mps_reshape_add32(temp_1, temp4, &q_frame_nrg_fix, q_frame_nrg_prev); |
212 | | |
213 | 801k | frame_nrg_prev = frame_nrg_fix; |
214 | 801k | q_frame_nrg_prev = q_frame_nrg_fix; |
215 | | |
216 | 801k | env_fix_l = 0; |
217 | 801k | q_env_fix_l = 30; |
218 | 801k | q_slot_nrg = q_slot_nrg_fix; |
219 | | |
220 | 801k | n_slot_nrg -= PB_OFFSET; |
221 | 8.01M | for (pb = start_p; pb <= end_p; pb++) { |
222 | 7.21M | temp_1 = ixheaacd_mps_div_32(*n_slot_nrg++, part_nrg_fix[pb], &qtemp1); |
223 | 7.21M | qtemp1 = *q_slot_nrg++ + qtemp1 - q_part_nrg_fix[pb]; |
224 | 7.21M | env_fix_l = ixheaacd_mps_reshape_add32(env_fix_l, temp_1, &q_env_fix_l, qtemp1); |
225 | 7.21M | } |
226 | 801k | n_slot_nrg -= PB_OFFSET; |
227 | | |
228 | 801k | env_fix_l = |
229 | 801k | ixheaacd_mps_mult32x32(env_fix_l, frame_nrg_fix, &q_env_fix_l, q_frame_nrg_fix); |
230 | | |
231 | 801k | temp_1 = ixheaac_mult32x16in32(env_fix_l, one_min_beta_fix); |
232 | 801k | temp4 = ixheaac_mult32x16in32((*norm_nrg_fix) << 1, beta_fix); |
233 | 801k | *norm_nrg_fix = ixheaacd_mps_reshape_add32(temp4, temp_1, q_norm_nrg_fix, q_env_fix_l); |
234 | | |
235 | 801k | if (flag) { |
236 | 27.4k | temp_1 = ixheaacd_mps_div_32(env_fix_l, *norm_nrg_fix, &qtemp1); |
237 | 27.4k | q_env = q_env_fix_l + qtemp1 - *q_norm_nrg_fix; |
238 | 27.4k | env[ts] = ixheaacd_mps_sqrt(temp_1, &(q_env), sqrt_tab); |
239 | 27.4k | env[ts] = ixheaacd_mps_convert_to_qn(env[ts], q_env, 15); |
240 | 27.4k | } |
241 | | |
242 | 801k | p_buffer_real += MAX_HYBRID_BANDS; |
243 | 801k | p_buffer_imag += MAX_HYBRID_BANDS; |
244 | | |
245 | 801k | p_hyb_out_dry_real += MAX_HYBRID_BANDS; |
246 | 801k | p_hyb_out_dry_imag += MAX_HYBRID_BANDS; |
247 | 801k | } |
248 | 28.3k | reshape_bb_env_state->frame_nrg_prev[ch] = frame_nrg_prev; |
249 | 28.3k | reshape_bb_env_state->q_frame_nrg_prev[ch] = q_frame_nrg_prev; |
250 | | |
251 | 28.3k | break; |
252 | 13.7k | case INP_DMX: |
253 | 13.7k | prev_ch_offs = ch + pstr_mps_state->num_output_channels; |
254 | | |
255 | 13.7k | frame_nrg_prev = reshape_bb_env_state->frame_nrg_prev[prev_ch_offs]; |
256 | 13.7k | q_frame_nrg_prev = reshape_bb_env_state->q_frame_nrg_prev[prev_ch_offs]; |
257 | | |
258 | 13.7k | part_nrg_fix = &reshape_bb_env_state->part_nrg_prev[prev_ch_offs][0]; |
259 | 13.7k | q_part_nrg_fix = &reshape_bb_env_state->q_part_nrg_prev[prev_ch_offs][0]; |
260 | | |
261 | 13.7k | norm_nrg_fix = &reshape_bb_env_state->norm_nrg_prev[prev_ch_offs]; |
262 | 13.7k | q_norm_nrg_fix = &reshape_bb_env_state->q_norm_nrg_prev[prev_ch_offs]; |
263 | | |
264 | 13.7k | p_buffer_real = pstr_mps_state->array_struct->x_real + ch * TSXHB + 12; |
265 | 13.7k | p_buffer_imag = pstr_mps_state->array_struct->x_imag + ch * TSXHB + 12; |
266 | 403k | for (ts = 0; ts < time_slots; ts++) { |
267 | 389k | WORD32 prev_idx; |
268 | | |
269 | 389k | slot_nrg = slot_nrg_fix + 4; |
270 | 2.33M | for (pb = 14; pb <= end_p; pb++) *slot_nrg++ = 0; |
271 | | |
272 | 389k | slot_nrg = slot_nrg_fix; |
273 | | |
274 | 389k | hyb_output_real_dry = p_buffer_real; |
275 | 389k | hyb_output_imag_dry = p_buffer_imag; |
276 | | |
277 | 1.94M | for (qs = 12; qs < 16; qs++) { |
278 | 1.55M | *slot_nrg++ = ixheaac_add64_sat(ixheaac_mult32x32in64(*hyb_output_real_dry, *hyb_output_real_dry), |
279 | 1.55M | ixheaac_mult32x32in64(*hyb_output_imag_dry, *hyb_output_imag_dry)); |
280 | | |
281 | 1.55M | hyb_output_real_dry++; |
282 | 1.55M | hyb_output_imag_dry++; |
283 | 1.55M | } |
284 | 389k | prev_idx = 14; |
285 | 5.84M | for (; qs < 30; qs++) { |
286 | 5.45M | WORD32 idx = bb_env_kernels[qs]; |
287 | 5.45M | if (prev_idx != idx) { |
288 | 1.16M | slot_nrg++; |
289 | 1.16M | prev_idx = idx; |
290 | 1.16M | } |
291 | | |
292 | 5.45M | *slot_nrg = ixheaac_add64_sat(*slot_nrg, ixheaac_mult32x32in64(*hyb_output_real_dry, *hyb_output_real_dry)); |
293 | 5.45M | *slot_nrg = ixheaac_add64_sat(*slot_nrg, ixheaac_mult32x32in64(*hyb_output_imag_dry, *hyb_output_imag_dry)); |
294 | | |
295 | 5.45M | hyb_output_real_dry++; |
296 | 5.45M | hyb_output_imag_dry++; |
297 | 5.45M | } |
298 | 389k | slot_nrg++; |
299 | 5.00M | for (; qs < cnt; qs++) { |
300 | 4.61M | *slot_nrg = ixheaac_add64_sat(*slot_nrg, ixheaac_mult32x32in64(*hyb_output_real_dry, *hyb_output_real_dry)); |
301 | 4.61M | *slot_nrg = ixheaac_add64_sat(*slot_nrg, ixheaac_mult32x32in64(*hyb_output_imag_dry, *hyb_output_imag_dry)); |
302 | | |
303 | 4.61M | hyb_output_real_dry++; |
304 | 4.61M | hyb_output_imag_dry++; |
305 | 4.61M | } |
306 | | |
307 | 389k | slot_nrg = slot_nrg_fix; |
308 | 389k | q_slot_nrg = q_slot_nrg_fix; |
309 | | |
310 | 389k | frame_nrg_fix = 0; |
311 | 389k | q_frame_nrg_fix = 30; |
312 | 3.89M | for (pb = start_p; pb <= end_p; pb++) { |
313 | 3.50M | *n_slot_nrg = ixheaacd_mps_narrow(*slot_nrg, q_slot_nrg); |
314 | 3.50M | slot_nrg++; |
315 | 3.50M | temp_1 = ixheaac_mult32x16in32(*n_slot_nrg, one_min_alpha_fix); |
316 | 3.50M | temp4 = ixheaac_mult32x16in32((part_nrg_fix[pb]) << 1, alpha_fix); |
317 | 3.50M | part_nrg_fix[pb] = |
318 | 3.50M | ixheaacd_mps_reshape_add32(temp4, temp_1, &q_part_nrg_fix[pb], *q_slot_nrg); |
319 | 3.50M | frame_nrg_fix = ixheaacd_mps_reshape_add32(frame_nrg_fix, *n_slot_nrg++, |
320 | 3.50M | &q_frame_nrg_fix, *q_slot_nrg++); |
321 | 3.50M | } |
322 | | |
323 | 389k | frame_nrg_fix = ixheaac_mult32x16in32(frame_nrg_fix, one_by_nine); |
324 | | |
325 | 389k | temp_1 = ixheaac_mult32x16in32(frame_nrg_fix, one_min_alpha_fix); |
326 | 389k | temp4 = ixheaac_mult32x16in32((frame_nrg_prev) << 1, alpha_fix); |
327 | 389k | frame_nrg_fix = |
328 | 389k | ixheaacd_mps_reshape_add32(temp_1, temp4, &q_frame_nrg_fix, q_frame_nrg_prev); |
329 | | |
330 | 389k | frame_nrg_prev = frame_nrg_fix; |
331 | 389k | q_frame_nrg_prev = q_frame_nrg_fix; |
332 | | |
333 | 389k | env_fix_l = 0; |
334 | 389k | q_env_fix_l = 30; |
335 | | |
336 | 389k | q_slot_nrg = q_slot_nrg_fix; |
337 | 389k | n_slot_nrg -= PB_OFFSET; |
338 | 3.89M | for (pb = start_p; pb <= end_p; pb++) { |
339 | 3.50M | temp_1 = ixheaacd_mps_div_32(*n_slot_nrg++, part_nrg_fix[pb], &qtemp1); |
340 | 3.50M | qtemp1 = *q_slot_nrg++ + qtemp1 - q_part_nrg_fix[pb]; |
341 | 3.50M | env_fix_l = ixheaacd_mps_reshape_add32(env_fix_l, temp_1, &q_env_fix_l, qtemp1); |
342 | 3.50M | } |
343 | 389k | n_slot_nrg -= PB_OFFSET; |
344 | | |
345 | 389k | env_fix_l = |
346 | 389k | ixheaacd_mps_mult32x32(env_fix_l, frame_nrg_fix, &q_env_fix_l, q_frame_nrg_fix); |
347 | | |
348 | 389k | temp_1 = ixheaac_mult32x16in32(env_fix_l, one_min_beta_fix); |
349 | 389k | temp4 = ixheaac_mult32x16in32((*norm_nrg_fix) << 1, beta_fix); |
350 | 389k | *norm_nrg_fix = ixheaacd_mps_reshape_add32(temp4, temp_1, q_norm_nrg_fix, q_env_fix_l); |
351 | | |
352 | 389k | temp_1 = ixheaacd_mps_div_32(env_fix_l, *norm_nrg_fix, &qtemp1); |
353 | 389k | q_env = q_env_fix_l + qtemp1 - *q_norm_nrg_fix; |
354 | 389k | env[ts] = ixheaacd_mps_sqrt(temp_1, &(q_env), sqrt_tab); |
355 | 389k | env[ts] = ixheaacd_mps_convert_to_qn(env[ts], q_env, 15); |
356 | | |
357 | 389k | p_buffer_real += MAX_HYBRID_BANDS; |
358 | 389k | p_buffer_imag += MAX_HYBRID_BANDS; |
359 | 389k | } |
360 | 13.7k | reshape_bb_env_state->frame_nrg_prev[prev_ch_offs] = frame_nrg_prev; |
361 | 13.7k | reshape_bb_env_state->q_frame_nrg_prev[prev_ch_offs] = q_frame_nrg_prev; |
362 | | |
363 | 13.7k | break; |
364 | 0 | default: |
365 | 0 | break; |
366 | 42.0k | } |
367 | 42.0k | return; |
368 | 42.0k | } |
369 | | |
370 | 6.91k | VOID ixheaacd_reshape_bb_env(ia_heaac_mps_state_struct *pstr_mps_state) { |
371 | 6.91k | WORD32 *env_dry; |
372 | 6.91k | WORD32 *env_dmx_0, *env_dmx_1; |
373 | | |
374 | 6.91k | WORD32 *p_buffer_real, *p_buffer_imag, *p_buffer_re, *p_buffer_im; |
375 | 6.91k | WORD32 *hyb_output_real_wet, *hyb_output_imag_wet; |
376 | | |
377 | 6.91k | WORD32 temp_1, temp_2; |
378 | 6.91k | WORD16 qtemp1, qtemp2; |
379 | 6.91k | WORD32 tmp, dry_fac, slot_amp_dry, slot_amp_wet; |
380 | 6.91k | WORD16 q_dry_fac, q_slot_amp_dry, q_slot_amp_wet; |
381 | | |
382 | 6.91k | WORD32 slot_amp_ratio; |
383 | 6.91k | WORD16 q_slot_amp_ratio; |
384 | 6.91k | WORD32 ch, ch2, ts, qs; |
385 | 6.91k | WORD32 *hyb_output_real_dry, *hyb_out_dry_real; |
386 | 6.91k | WORD32 *hyb_output_imag_dry, *hyb_out_dry_imag; |
387 | 6.91k | WORD64 *inter; |
388 | | |
389 | 6.91k | VOID *free_scratch; |
390 | 6.91k | const WORD32 *sqrt_tab = pstr_mps_state->ia_mps_dec_mps_table.common_table_ptr->sqrt_tab; |
391 | 6.91k | ia_mps_dec_auxilary_struct *p_aux_struct = pstr_mps_state->aux_struct; |
392 | 6.91k | WORD32 *temp_shape_enable_channel_ges = p_aux_struct->temp_shape_enable_channel_ges; |
393 | | |
394 | 6.91k | WORD32 start_hsb; |
395 | 6.91k | WORD32 time_slots = pstr_mps_state->time_slots; |
396 | 6.91k | WORD32 num_output_channels = pstr_mps_state->num_output_channels; |
397 | 6.91k | WORD32 tree_config = pstr_mps_state->tree_config; |
398 | 6.91k | WORD32 hybrid_bands = pstr_mps_state->hybrid_bands; |
399 | | |
400 | 6.91k | const WORD32 *ch_idx = &pstr_mps_state->ia_mps_dec_mps_table.m1_m2_table_ptr->idx_table |
401 | 6.91k | .row_2_channel_ges[tree_config][0]; |
402 | 6.91k | WORD64 acc, acc2; |
403 | 6.91k | start_hsb = 6; |
404 | | |
405 | 6.91k | free_scratch = pstr_mps_state->mps_scratch_mem_v; |
406 | 6.91k | env_dry = free_scratch; |
407 | 6.91k | env_dmx_0 = pstr_mps_state->array_struct->env_dmx_0; |
408 | 6.91k | env_dmx_1 = pstr_mps_state->array_struct->env_dmx_1; |
409 | 6.91k | inter = (WORD64 *)((WORD8 *)free_scratch + |
410 | 6.91k | IXHEAAC_GET_SIZE_ALIGNED(MAX_TIME_SLOTSX12, BYTE_ALIGN_8)); |
411 | 6.91k | free_scratch = |
412 | 6.91k | inter + IXHEAAC_GET_SIZE_ALIGNED_TYPE(MAX_TIME_SLOTS, sizeof(*inter), BYTE_ALIGN_8); |
413 | | |
414 | 6.91k | p_buffer_real = pstr_mps_state->array_struct->buf_real + start_hsb; |
415 | 6.91k | p_buffer_imag = pstr_mps_state->array_struct->buf_imag + start_hsb; |
416 | | |
417 | 61.5k | for (ch = 0; ch < num_output_channels; ch++) { |
418 | 54.6k | ch2 = ch_idx[ch]; |
419 | | |
420 | 54.6k | if (ch2 == -1) continue; |
421 | | |
422 | 28.3k | p_buffer_re = p_buffer_real; |
423 | 28.3k | p_buffer_im = p_buffer_imag; |
424 | | |
425 | 28.3k | ixheaacd_extract_bb_env(pstr_mps_state, INP_DRY_WET, ch, env_dry, free_scratch, |
426 | 28.3k | temp_shape_enable_channel_ges[ch2]); |
427 | | |
428 | 28.3k | if (temp_shape_enable_channel_ges[ch2]) { |
429 | 957 | WORD32 *env = &p_aux_struct->env_shape_data[ch2][0]; |
430 | 957 | switch (tree_config) { |
431 | 39 | case TREE_5151: |
432 | 135 | case TREE_5152: |
433 | 3.60k | for (ts = 0; ts < time_slots; ts++) { |
434 | 3.47k | inter[ts] = (WORD64)((WORD64)*env++ * (WORD64)env_dmx_0[ts]); |
435 | 3.47k | } |
436 | 135 | break; |
437 | | |
438 | 104 | case TREE_525: |
439 | 287 | case TREE_7271: |
440 | 311 | case TREE_7272: |
441 | | |
442 | 311 | switch (ch2) { |
443 | 95 | case 0: |
444 | 133 | case 3: |
445 | 166 | case 5: |
446 | | |
447 | 5.32k | for (ts = 0; ts < time_slots; ts++) { |
448 | 5.16k | inter[ts] = (WORD64)((WORD64)*env++ * (WORD64)env_dmx_0[ts]); |
449 | 5.16k | } |
450 | 166 | break; |
451 | 37 | case 1: |
452 | 77 | case 4: |
453 | 107 | case 6: |
454 | | |
455 | 3.45k | for (ts = 0; ts < time_slots; ts++) { |
456 | 3.34k | inter[ts] = (WORD64)((WORD64)*env++ * (WORD64)env_dmx_1[ts]); |
457 | 3.34k | } |
458 | 107 | break; |
459 | 38 | case 2: |
460 | | |
461 | 1.20k | for (ts = 0; ts < time_slots; ts++) { |
462 | 1.16k | temp_2 = ((WORD64)env_dmx_0[ts] + (WORD64)env_dmx_1[ts]) >> 1; |
463 | 1.16k | inter[ts] = (WORD64)((WORD64)*env++ * (WORD64)temp_2); |
464 | 1.16k | } |
465 | 38 | break; |
466 | 0 | default: |
467 | 0 | break; |
468 | 311 | } |
469 | 311 | break; |
470 | | |
471 | 311 | case TREE_7571: |
472 | 511 | case TREE_7572: |
473 | 511 | switch (ch2) { |
474 | 168 | case 0: |
475 | 305 | case 2: |
476 | 8.88k | for (ts = 0; ts < time_slots; ts++) { |
477 | 8.57k | inter[ts] = (WORD64)((WORD64)*env++ * (WORD64)env_dmx_0[ts]); |
478 | 8.57k | } |
479 | | |
480 | 305 | break; |
481 | 135 | case 1: |
482 | 206 | case 3: |
483 | 5.88k | for (ts = 0; ts < time_slots; ts++) { |
484 | 5.68k | inter[ts] = (WORD64)((WORD64)*env++ * (WORD64)env_dmx_1[ts]); |
485 | 5.68k | } |
486 | 206 | break; |
487 | 0 | default: |
488 | 0 | break; |
489 | 511 | } |
490 | 511 | default: |
491 | 511 | break; |
492 | 957 | } |
493 | | |
494 | 957 | hyb_out_dry_real = |
495 | 957 | pstr_mps_state->array_struct->hyb_output_real_dry + ch * TSXHB + start_hsb; |
496 | 957 | hyb_out_dry_imag = |
497 | 957 | pstr_mps_state->array_struct->hyb_output_imag_dry + ch * TSXHB + start_hsb; |
498 | | |
499 | 28.3k | for (ts = 0; ts < time_slots; ts++) { |
500 | 27.4k | tmp = ixheaacd_mps_narrow(inter[ts], &qtemp1); |
501 | | |
502 | 27.4k | if (env_dry[ts] == 0) { |
503 | 11.5k | q_dry_fac = 0; |
504 | 11.5k | dry_fac = MAX_32; |
505 | 15.8k | } else { |
506 | 15.8k | dry_fac = ixheaacd_mps_div_32(tmp, env_dry[ts], &q_dry_fac); |
507 | 15.8k | q_dry_fac += qtemp1 - 5; |
508 | 15.8k | } |
509 | | |
510 | 27.4k | hyb_output_real_wet = p_buffer_re; |
511 | 27.4k | hyb_output_imag_wet = p_buffer_im; |
512 | | |
513 | 27.4k | hyb_output_real_dry = hyb_out_dry_real; |
514 | 27.4k | hyb_output_imag_dry = hyb_out_dry_imag; |
515 | 27.4k | acc = 0; |
516 | 27.4k | acc2 = 0; |
517 | | |
518 | 1.40M | for (qs = start_hsb; qs < hybrid_bands; qs++) { |
519 | 1.38M | acc = ixheaac_add64_sat(acc, ixheaac_mult32x32in64(*hyb_output_real_dry, *hyb_output_real_dry)); |
520 | 1.38M | hyb_output_real_dry++; |
521 | 1.38M | acc = ixheaac_add64_sat(acc, ixheaac_mult32x32in64(*hyb_output_imag_dry, *hyb_output_imag_dry)); |
522 | 1.38M | hyb_output_imag_dry++; |
523 | | |
524 | 1.38M | acc2 = ixheaac_add64_sat(acc2, ixheaac_mult32x32in64(*hyb_output_real_wet, *hyb_output_real_wet)); |
525 | 1.38M | hyb_output_real_wet++; |
526 | 1.38M | acc2 = ixheaac_add64_sat(acc2, ixheaac_mult32x32in64(*hyb_output_imag_wet, *hyb_output_imag_wet)); |
527 | 1.38M | hyb_output_imag_wet++; |
528 | 1.38M | } |
529 | 27.4k | slot_amp_dry = ixheaacd_mps_narrow(acc, &q_slot_amp_dry); |
530 | 27.4k | slot_amp_wet = ixheaacd_mps_narrow(acc2, &q_slot_amp_wet); |
531 | | |
532 | 27.4k | qtemp1 = q_slot_amp_dry; |
533 | | |
534 | 27.4k | temp_1 = ixheaacd_mps_add32(slot_amp_dry, ABS_THR_FIX, &qtemp1, 15); |
535 | 27.4k | temp_2 = ixheaacd_mps_div_32(slot_amp_wet, temp_1, &qtemp2); |
536 | 27.4k | q_slot_amp_ratio = qtemp2 + q_slot_amp_wet - qtemp1; |
537 | 27.4k | slot_amp_ratio = ixheaacd_mps_sqrt(temp_2, &q_slot_amp_ratio, sqrt_tab); |
538 | | |
539 | 27.4k | temp_1 = ixheaacd_mps_convert_to_qn(dry_fac, q_dry_fac, 15); |
540 | 27.4k | temp_1 -= ONE_IN_Q15; |
541 | 27.4k | temp_1 = ixheaacd_mps_mult32_shr_16(temp_1, slot_amp_ratio); |
542 | 27.4k | q_slot_amp_ratio -= 1; |
543 | | |
544 | 27.4k | temp_1 = ixheaacd_mps_add32(temp_1, dry_fac, &q_slot_amp_ratio, q_dry_fac); |
545 | | |
546 | 27.4k | temp_1 = ixheaacd_mps_convert_to_qn(temp_1, q_slot_amp_ratio, 15); |
547 | 27.4k | temp_1 = max(ONE_IN_Q13, temp_1); |
548 | 27.4k | dry_fac = min(FOUR_IN_Q15, temp_1); |
549 | | |
550 | 27.4k | hyb_output_real_dry = hyb_out_dry_real; |
551 | 27.4k | hyb_output_imag_dry = hyb_out_dry_imag; |
552 | | |
553 | 1.40M | for (qs = start_hsb; qs < hybrid_bands; qs++) { |
554 | 1.38M | *hyb_output_real_dry = ixheaacd_mps_mult32_shr_15(*hyb_output_real_dry, dry_fac); |
555 | 1.38M | hyb_output_real_dry++; |
556 | 1.38M | *hyb_output_imag_dry = ixheaacd_mps_mult32_shr_15(*hyb_output_imag_dry, dry_fac); |
557 | 1.38M | hyb_output_imag_dry++; |
558 | 1.38M | } |
559 | 27.4k | p_buffer_re += MAX_HYBRID_BANDS; |
560 | 27.4k | p_buffer_im += MAX_HYBRID_BANDS; |
561 | 27.4k | hyb_out_dry_real += MAX_HYBRID_BANDS; |
562 | 27.4k | hyb_out_dry_imag += MAX_HYBRID_BANDS; |
563 | 27.4k | } |
564 | 957 | } |
565 | 28.3k | p_buffer_real += TSXHB; |
566 | 28.3k | p_buffer_imag += TSXHB; |
567 | 28.3k | } |
568 | 6.91k | return; |
569 | 6.91k | } |
570 | | |
571 | 6.91k | VOID ixheaacd_pre_reshape_bb_env(ia_heaac_mps_state_struct *pstr_mps_state) { |
572 | 6.91k | WORD32 *env_dmx_0, *env_dmx_1; |
573 | | |
574 | 6.91k | VOID *free_scratch; |
575 | | |
576 | 6.91k | WORD32 tree_config = pstr_mps_state->tree_config; |
577 | | |
578 | 6.91k | free_scratch = pstr_mps_state->mps_scratch_mem_v; |
579 | 6.91k | env_dmx_0 = pstr_mps_state->array_struct->env_dmx_0; |
580 | 6.91k | env_dmx_1 = pstr_mps_state->array_struct->env_dmx_1; |
581 | | |
582 | 6.91k | switch (tree_config) { |
583 | 6.42k | case TREE_7572: |
584 | 6.42k | ixheaacd_extract_bb_env(pstr_mps_state, INP_DMX, 0 + 4, env_dmx_0, free_scratch, 0); |
585 | 6.42k | ixheaacd_extract_bb_env(pstr_mps_state, INP_DMX, 1 + 4, env_dmx_1, free_scratch, 0); |
586 | 6.42k | break; |
587 | 487 | default: |
588 | 487 | ixheaacd_extract_bb_env(pstr_mps_state, INP_DMX, 0, env_dmx_0, free_scratch, 0); |
589 | 487 | if (min(pstr_mps_state->num_input_channels, 2) == 2) { |
590 | 371 | ixheaacd_extract_bb_env(pstr_mps_state, INP_DMX, 1, env_dmx_1, free_scratch, 0); |
591 | 371 | } |
592 | 6.91k | } |
593 | 6.91k | return; |
594 | 6.91k | } |