xref: /aosp_15_r20/external/libxaac/decoder/ixheaacd_mps_calc_m1m2_emm.c (revision 15dc779a375ca8b5125643b829a8aa4b70d7f451)
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 "ixheaacd_sbr_common.h"
25 #include "ixheaac_constants.h"
26 #include "ixheaac_basic_ops32.h"
27 #include "ixheaac_basic_ops40.h"
28 #include "ixheaacd_bitbuffer.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 "ixheaac_error_standards.h"
37 #include "ixheaacd_mps_polyphase.h"
38 #include "ixheaacd_config.h"
39 #include "ixheaacd_qmf_dec.h"
40 #include "ixheaacd_mps_dec.h"
41 #include "ixheaacd_mps_macro_def.h"
42 #include "ixheaacd_mps_basic_op.h"
43 #include "ixheaacd_mps_calc_m1m2_common.h"
44 
ixheaacd_calc_m1m2_emm(ia_heaac_mps_state_struct * pstr_mps_state)45 VOID ixheaacd_calc_m1m2_emm(ia_heaac_mps_state_struct *pstr_mps_state) {
46   ia_mps_dec_auxilary_struct *p_aux_struct = pstr_mps_state->aux_struct;
47   ia_mps_dec_m2_param_struct *m2_param = p_aux_struct->m2_param;
48   ia_mps_dec_m1_param_struct *m1_param = pstr_mps_state->array_struct->m1_param;
49   WORD32 ps;
50   WORD32 pb;
51   WORD32 col;
52   WORD32 row;
53 
54   WORD64 acc;
55   WORD32 *h11, *h12, *h21, *h22, *dummy1, *dummy2;
56   WORD16 *dummy3, *dummy4;
57 
58   h11 = pstr_mps_state->mps_scratch_mem_v;
59   h12 = h11 + IXHEAAC_GET_SIZE_ALIGNED_TYPE(MAX_PARAMETER_BANDS, sizeof(*h12), BYTE_ALIGN_8);
60   h21 = h12 + IXHEAAC_GET_SIZE_ALIGNED_TYPE(MAX_PARAMETER_BANDS, sizeof(*h21), BYTE_ALIGN_8);
61   h22 = h21 + IXHEAAC_GET_SIZE_ALIGNED_TYPE(MAX_PARAMETER_BANDS, sizeof(*h22), BYTE_ALIGN_8);
62   dummy1 =
63       h22 + IXHEAAC_GET_SIZE_ALIGNED_TYPE(MAX_PARAMETER_BANDS, sizeof(*dummy1), BYTE_ALIGN_8);
64   dummy2 =
65       dummy1 + IXHEAAC_GET_SIZE_ALIGNED_TYPE(MAX_PARAMETER_BANDS, sizeof(*dummy2), BYTE_ALIGN_8);
66 
67   dummy3 = (WORD16 *)pstr_mps_state->mps_scratch_mem_v +
68            IXHEAAC_GET_SIZE_ALIGNED_TYPE(PARAMETER_BANDSX12, sizeof(*dummy3), BYTE_ALIGN_8);
69   dummy4 =
70       dummy3 + IXHEAAC_GET_SIZE_ALIGNED_TYPE(MAX_PARAMETER_BANDS, sizeof(*dummy4), BYTE_ALIGN_8);
71 
72   for (ps = 0; ps < pstr_mps_state->num_parameter_sets; ps++) {
73     ixheaacd_param_2_umx_ps(pstr_mps_state, h11, h12, h21, h22, dummy1, dummy2, dummy3, dummy4, 0,
74                             ps, 0);
75 
76     for (pb = 0; pb < pstr_mps_state->num_parameter_bands; pb++) {
77       WORD32 m11 = p_aux_struct->ttt_cpc_1[0][ps][pb] + ONE_IN_Q16;
78       WORD32 m12 = p_aux_struct->ttt_cpc_2[0][ps][pb] - ONE_IN_Q15;
79       WORD32 m21 = p_aux_struct->ttt_cpc_1[0][ps][pb] - ONE_IN_Q15;
80       WORD32 m22 = p_aux_struct->ttt_cpc_2[0][ps][pb] + ONE_IN_Q16;
81       WORD32 m31 = ONE_IN_Q15 - p_aux_struct->ttt_cpc_1[0][ps][pb];
82       WORD32 m32 = ONE_IN_Q15 - p_aux_struct->ttt_cpc_2[0][ps][pb];
83       WORD32 weight1;
84       WORD32 weight2;
85       WORD32 h_real[2][2];
86       WORD32 h_imag[2][2];
87 
88       ia_mps_dec_spatial_bs_frame_struct *p_cur_bs = pstr_mps_state->bs_frame;
89 
90       ixheaacd_get_matrix_inversion_weights(
91           p_cur_bs->ott_cld_idx[0][ps][pb], p_cur_bs->ott_cld_idx[0][ps][pb], 1,
92           p_aux_struct->ttt_cpc_1[0][ps][pb], p_aux_struct->ttt_cpc_2[0][ps][pb], &weight1,
93           &weight2, &(pstr_mps_state->ia_mps_dec_mps_table));
94 
95       ixheaacd_invert_matrix(weight1, weight2, h_real, h_imag,
96                              pstr_mps_state->ia_mps_dec_mps_table.common_table_ptr);
97 
98       pstr_mps_state->m1_param_imag_present = 1;
99 
100       acc = (WORD64)((WORD64)h_real[0][0] * (WORD64)m11 + (WORD64)h_real[1][0] * (WORD64)m12);
101       acc >>= 15;
102       m1_param->m1_param_real[0][0][ps][pb] = (WORD32)acc;
103 
104       acc = (WORD64)((WORD64)h_real[0][1] * (WORD64)m11 + (WORD64)h_real[1][1] * (WORD64)m12);
105       acc >>= 15;
106       m1_param->m1_param_real[0][1][ps][pb] = (WORD32)acc;
107 
108       acc = (WORD64)((WORD64)h_imag[0][0] * (WORD64)m11 + (WORD64)h_imag[1][0] * (WORD64)m12);
109       acc >>= 15;
110       m1_param->m1_param_imag[0][0][ps][pb] = (WORD32)acc;
111 
112       acc = (WORD64)((WORD64)h_imag[0][1] * (WORD64)m11 + (WORD64)h_imag[1][1] * (WORD64)m12);
113       acc >>= 15;
114       m1_param->m1_param_imag[0][1][ps][pb] = (WORD32)acc;
115 
116       acc = (WORD64)((WORD64)h_real[0][0] * (WORD64)m21 + (WORD64)h_real[1][0] * (WORD64)m22);
117       acc >>= 15;
118       m1_param->m1_param_real[1][0][ps][pb] = (WORD32)acc;
119 
120       acc = (WORD64)((WORD64)h_real[0][1] * (WORD64)m21 + (WORD64)h_real[1][1] * (WORD64)m22);
121       acc >>= 15;
122       m1_param->m1_param_real[1][1][ps][pb] = (WORD32)acc;
123 
124       acc = (WORD64)((WORD64)h_imag[0][0] * (WORD64)m21 + (WORD64)h_imag[1][0] * (WORD64)m22);
125       acc >>= 15;
126       m1_param->m1_param_imag[1][0][ps][pb] = (WORD32)acc;
127 
128       acc = (WORD64)((WORD64)h_imag[0][1] * (WORD64)m21 + (WORD64)h_imag[1][1] * (WORD64)m22);
129       acc >>= 15;
130       m1_param->m1_param_imag[1][1][ps][pb] = (WORD32)acc;
131 
132       acc = (WORD64)((WORD64)h_real[0][0] * (WORD64)m31 + (WORD64)h_real[1][0] * (WORD64)m32);
133       acc >>= 15;
134       m1_param->m1_param_real[2][0][ps][pb] = (WORD32)acc;
135 
136       acc = (WORD64)((WORD64)h_real[0][1] * (WORD64)m31 + (WORD64)h_real[1][1] * (WORD64)m32);
137       acc >>= 15;
138       m1_param->m1_param_real[2][1][ps][pb] = (WORD32)acc;
139 
140       acc = (WORD64)((WORD64)h_imag[0][0] * (WORD64)m31 + (WORD64)h_imag[1][0] * (WORD64)m32);
141       acc >>= 15;
142       m1_param->m1_param_imag[2][0][ps][pb] = (WORD32)acc;
143 
144       acc = (WORD64)((WORD64)h_imag[0][1] * (WORD64)m31 + (WORD64)h_imag[1][1] * (WORD64)m32);
145       acc >>= 15;
146       m1_param->m1_param_imag[2][1][ps][pb] = (WORD32)acc;
147 
148       m1_param->m1_param_real[0][2][ps][pb] = ONE_IN_Q15;
149       m1_param->m1_param_real[1][2][ps][pb] = ONE_IN_Q15;
150       m1_param->m1_param_real[2][2][ps][pb] = -32768;
151 
152       m1_param->m1_param_imag[0][2][ps][pb] = 0;
153       m1_param->m1_param_imag[1][2][ps][pb] = 0;
154       m1_param->m1_param_imag[2][2][ps][pb] = 0;
155 
156       for (row = 0; row < 3; row++) {
157         for (col = 0; col < 3; col++) {
158           m1_param->m1_param_real[row][col][ps][pb] = ixheaacd_mps_mult32_shr_15(
159               m1_param->m1_param_real[row][col][ps][pb], ONE_BY_THREE_Q15);
160           m1_param->m1_param_imag[row][col][ps][pb] = ixheaacd_mps_mult32_shr_15(
161               m1_param->m1_param_imag[row][col][ps][pb], ONE_BY_THREE_Q15);
162         }
163 
164         m1_param->m1_param_real[2][col][ps][pb] =
165             ixheaacd_mps_mult32_shr_15(m1_param->m1_param_real[2][col][ps][pb], SQRT_TWO_Q15);
166         m1_param->m1_param_imag[2][col][ps][pb] =
167             ixheaacd_mps_mult32_shr_15(m1_param->m1_param_imag[2][col][ps][pb], SQRT_TWO_Q15);
168 
169         m1_param->m1_param_real[3][col][ps][pb] = m1_param->m1_param_real[0][col][ps][pb];
170         m1_param->m1_param_imag[3][col][ps][pb] = m1_param->m1_param_imag[0][col][ps][pb];
171         m1_param->m1_param_real[4][col][ps][pb] = m1_param->m1_param_real[1][col][ps][pb];
172         m1_param->m1_param_imag[4][col][ps][pb] = m1_param->m1_param_imag[1][col][ps][pb];
173         m1_param->m1_param_real[5][col][ps][pb] = 0;
174         m1_param->m1_param_imag[5][col][ps][pb] = 0;
175       }
176     }
177 
178     for (pb = 0; pb < pstr_mps_state->num_parameter_bands; pb++) {
179       m2_param->m2_decor_real[0][ps][pb] = h12[pb];
180       m2_param->m2_decor_real[1][ps][pb] = h22[pb];
181       m2_param->m2_decor_real[2][ps][pb] = h12[pb];
182       m2_param->m2_decor_real[3][ps][pb] = h22[pb];
183     }
184 
185     for (pb = 0; pb < pstr_mps_state->num_parameter_bands; pb++) {
186       m2_param->m2_resid_real[0][ps][pb] = h11[pb];
187       m2_param->m2_resid_real[1][ps][pb] = h21[pb];
188       m2_param->m2_resid_real[2][ps][pb] = h21[pb];
189       m2_param->m2_resid_real[3][ps][pb] = 32768;
190     }
191   }
192   return;
193 }
194