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_sbr_common.h"
21 #include "ixheaacd_type_def.h"
22
23 #include "ixheaacd_constants.h"
24 #include "ixheaacd_basic_ops32.h"
25 #include "ixheaacd_basic_ops16.h"
26 #include "ixheaacd_basic_ops40.h"
27 #include "ixheaacd_basic_ops.h"
28
29 #include "ixheaacd_defines.h"
30 #include "ixheaacd_aac_rom.h"
31 #include "ixheaacd_bitbuffer.h"
32 #include "ixheaacd_common_rom.h"
33 #include "ixheaacd_basic_funcs.h"
34
35 #include "ixheaacd_basic_op.h"
36 #include "ixheaacd_intrinsics.h"
37
38 #include "ixheaacd_pulsedata.h"
39
40 #include "ixheaacd_pns.h"
41 #include "ixheaacd_drc_data_struct.h"
42
43 #include "ixheaacd_lt_predict.h"
44 #include "ixheaacd_cnst.h"
45 #include "ixheaacd_ec_defines.h"
46 #include "ixheaacd_ec_struct_def.h"
47 #include "ixheaacd_channelinfo.h"
48 #include "ixheaacd_channel.h"
49 #include "ixheaacd_drc_dec.h"
50 #include "ixheaacd_audioobjtypes.h"
51
52 #include "ixheaacd_stereo.h"
53
ixheaacd_ms_stereo_process(ia_aac_dec_channel_info_struct * ptr_aac_dec_channel_info[2],ia_aac_dec_tables_struct * ptr_aac_tables)54 VOID ixheaacd_ms_stereo_process(
55 ia_aac_dec_channel_info_struct *ptr_aac_dec_channel_info[2],
56 ia_aac_dec_tables_struct *ptr_aac_tables)
57
58 {
59 WORD32 win_grp, grp_len, k;
60 WORD32 *l_spec = ptr_aac_dec_channel_info[LEFT]->ptr_spec_coeff;
61 WORD32 *r_spec = ptr_aac_dec_channel_info[RIGHT]->ptr_spec_coeff;
62 WORD16 maximum_bins_short =
63 (ptr_aac_dec_channel_info[LEFT]->str_ics_info.frame_length) >> 3;
64 WORD8 *ptr_group_len =
65 ptr_aac_dec_channel_info[LEFT]->str_ics_info.window_group_length;
66 const WORD8 *ptr_sfb_width =
67 ptr_aac_tables
68 ->str_aac_sfb_info[ptr_aac_dec_channel_info[RIGHT]
69 ->str_ics_info.window_sequence]
70 .sfb_width;
71
72 UWORD8 *ptr_ms_used =
73 &ptr_aac_dec_channel_info[LEFT]->pstr_stereo_info->ms_used[0][0];
74
75 for (win_grp = 0;
76 win_grp < ptr_aac_dec_channel_info[LEFT]->str_ics_info.num_window_groups;
77 win_grp++) {
78 for (grp_len = 0; grp_len < ptr_group_len[win_grp]; grp_len++) {
79 WORD32 sfb;
80 WORD32 ixheaacd_drc_offset = 0;
81
82 for (sfb = 0; sfb < ptr_aac_dec_channel_info[LEFT]->str_ics_info.max_sfb;
83 sfb++) {
84 ixheaacd_drc_offset += ptr_sfb_width[sfb];
85
86 if (*ptr_ms_used++) {
87 for (k = 0; k < ptr_sfb_width[sfb]; k = k + 2) {
88 WORD32 left_coef = *l_spec;
89 WORD32 right_coef = *r_spec;
90 WORD32 left_coef2 = *(l_spec + 1);
91 WORD32 right_coef2 = *(r_spec + 1);
92
93 *l_spec++ = ixheaacd_add32_sat(left_coef, right_coef);
94 *r_spec++ = ixheaacd_sub32_sat(left_coef, right_coef);
95 *l_spec++ = ixheaacd_add32_sat(left_coef2, right_coef2);
96 *r_spec++ = ixheaacd_sub32_sat(left_coef2, right_coef2);
97 }
98 } else {
99 l_spec += ptr_sfb_width[sfb];
100 r_spec += ptr_sfb_width[sfb];
101 }
102 }
103 ptr_ms_used -= ptr_aac_dec_channel_info[LEFT]->str_ics_info.max_sfb;
104
105 if (maximum_bins_short == 120) {
106 l_spec = l_spec + maximum_bins_short - ixheaacd_drc_offset;
107 r_spec = r_spec + maximum_bins_short - ixheaacd_drc_offset;
108 } else {
109 l_spec = l_spec + 128 - ixheaacd_drc_offset;
110 r_spec = r_spec + 128 - ixheaacd_drc_offset;
111 }
112 }
113
114 ptr_ms_used += JOINT_STEREO_MAX_BANDS;
115 }
116 }
117
ixheaacd_mult32x16in32l(WORD32 a,WORD32 b)118 static PLATFORM_INLINE WORD32 ixheaacd_mult32x16in32l(WORD32 a, WORD32 b) {
119 WORD32 result;
120 WORD64 temp_result;
121
122 temp_result = (WORD64)a * (WORD64)b;
123
124 result = (WORD32)(temp_result >> 16);
125
126 return (result);
127 }
128
ixheaacd_intensity_stereo_process(ia_aac_dec_channel_info_struct * ptr_aac_dec_channel_info[2],ia_aac_dec_tables_struct * ptr_aac_tables,WORD32 object_type,WORD32 aac_sf_data_resil_flag,WORD16 framelength)129 VOID ixheaacd_intensity_stereo_process(
130 ia_aac_dec_channel_info_struct *ptr_aac_dec_channel_info[2],
131 ia_aac_dec_tables_struct *ptr_aac_tables, WORD32 object_type,
132 WORD32 aac_sf_data_resil_flag, WORD16 framelength) {
133 UWORD8 *ptr_ms_used =
134 &ptr_aac_dec_channel_info[LEFT]->pstr_stereo_info->ms_used[0][0];
135 WORD8 *ptr_code_book = &ptr_aac_dec_channel_info[RIGHT]->ptr_code_book[0];
136 WORD16 *ptr_scale_factor =
137 &ptr_aac_dec_channel_info[RIGHT]->ptr_scale_factor[0];
138 WORD32 *r_spec = &ptr_aac_dec_channel_info[RIGHT]->ptr_spec_coeff[0];
139 WORD32 *l_spec = &ptr_aac_dec_channel_info[LEFT]->ptr_spec_coeff[0];
140 WORD16 maximum_bins_short =
141 (ptr_aac_dec_channel_info[LEFT]->str_ics_info.frame_length) >> 3;
142 WORD8 *ptr_group_len =
143 ptr_aac_dec_channel_info[RIGHT]->str_ics_info.window_group_length;
144 const WORD8 *ptr_sfb_width =
145 ptr_aac_tables
146 ->str_aac_sfb_info[ptr_aac_dec_channel_info[RIGHT]
147 ->str_ics_info.window_sequence]
148 .sfb_width;
149
150 WORD32 *ptr_scale_table;
151
152 if (960 == framelength)
153 ptr_scale_table = ptr_aac_tables->pstr_block_tables->scale_table_960;
154 else
155 ptr_scale_table = ptr_aac_tables->pstr_block_tables->scale_table;
156
157 WORD32 win_grp, grp_len, k;
158
159 for (win_grp = 0;
160 win_grp <
161 ptr_aac_dec_channel_info[RIGHT]->str_ics_info.num_window_groups;
162 win_grp++) {
163 for (grp_len = 0; grp_len < ptr_group_len[win_grp]; grp_len++) {
164 WORD32 sfb;
165 WORD32 ixheaacd_drc_offset = 0;
166
167 for (sfb = 0; sfb < ptr_aac_dec_channel_info[RIGHT]->str_ics_info.max_sfb;
168 sfb++) {
169 WORD8 code_book = ptr_code_book[sfb];
170 ixheaacd_drc_offset += ptr_sfb_width[sfb];
171
172 if (((code_book >= INTENSITY_HCB2) &&
173 ((object_type != AOT_ER_AAC_ELD) &&
174 (object_type != AOT_ER_AAC_LD))) ||
175 (((code_book == INTENSITY_HCB2) || (code_book == INTENSITY_HCB)) &&
176 ((object_type == AOT_ER_AAC_ELD) ||
177 (object_type == AOT_ER_AAC_LD))))
178
179 {
180 WORD32 sfb_factor, scale;
181 WORD32 scf_exp;
182
183 sfb_factor = (ptr_scale_factor[sfb]);
184 if (aac_sf_data_resil_flag) sfb_factor = -sfb_factor;
185
186 scf_exp = (sfb_factor >> 2);
187 scale = *(ptr_scale_table + (sfb_factor & 3));
188 if (!((ptr_ms_used[sfb]) ^ (code_book & 0x1))) {
189 scale = ixheaacd_negate32(scale);
190 }
191
192 scf_exp = -(scf_exp + 2);
193
194 for (k = 0; k < ptr_sfb_width[sfb]; k++) {
195 WORD32 temp, shift_val;
196 temp = *l_spec++;
197
198 shift_val = ixheaacd_norm32(temp);
199 temp = ixheaacd_shl32(temp, shift_val);
200
201 temp = ixheaacd_mult32x16in32l(temp, scale);
202 shift_val = shift_val + scf_exp;
203
204 if (shift_val < 0) {
205 temp = ixheaacd_shl32_sat(temp, -shift_val);
206 } else {
207 temp = ixheaacd_shr32(temp, shift_val);
208 }
209 *r_spec++ = temp;
210 }
211
212 } else {
213 l_spec += ptr_sfb_width[sfb];
214 r_spec += ptr_sfb_width[sfb];
215 }
216 }
217
218 if (maximum_bins_short == 120) {
219 l_spec += maximum_bins_short - ixheaacd_drc_offset;
220 r_spec += maximum_bins_short - ixheaacd_drc_offset;
221 } else {
222 l_spec += 128 - ixheaacd_drc_offset;
223 r_spec += 128 - ixheaacd_drc_offset;
224 }
225 }
226 ptr_ms_used += 64;
227 ptr_code_book += 16;
228 ptr_scale_factor += 16;
229 }
230 }
231