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 <stdio.h>
21 #include <string.h>
22
23 #include <math.h>
24
25 #include "ixheaacd_sbr_common.h"
26 #include "ixheaac_type_def.h"
27
28 #include "ixheaac_constants.h"
29 #include "ixheaac_basic_ops32.h"
30 #include "ixheaac_basic_ops16.h"
31 #include "ixheaac_basic_ops40.h"
32 #include "ixheaac_basic_ops.h"
33 #include "ixheaacd_bitbuffer.h"
34
35 #include "ixheaac_basic_op.h"
36 #include "ixheaacd_intrinsics.h"
37 #include "ixheaac_sbr_const.h"
38
39 #include "ixheaacd_defines.h"
40
41 #include "ixheaacd_aac_rom.h"
42
43 #include "ixheaacd_definitions.h"
44
45 #include "ixheaacd_error_codes.h"
46
47 #include "ixheaacd_pulsedata.h"
48
49 #include "ixheaacd_pns.h"
50 #include "ixheaacd_drc_data_struct.h"
51
52 #include "ixheaacd_lt_predict.h"
53 #include "ixheaacd_cnst.h"
54 #include "ixheaacd_ec_defines.h"
55 #include "ixheaacd_ec_struct_def.h"
56 #include "ixheaacd_channelinfo.h"
57 #include "ixheaacd_drc_dec.h"
58 #include "ixheaacd_sbrdecoder.h"
59 #include "ixheaacd_block.h"
60 #include "ixheaacd_channel.h"
61
62 #include "ixheaacd_sbr_payload.h"
63 #include "ixheaacd_common_rom.h"
64
65 #include "ixheaacd_sbrdecsettings.h"
66 #include "ixheaacd_sbr_scale.h"
67 #include "ixheaacd_env_extr_part.h"
68 #include "ixheaacd_sbr_rom.h"
69 #include "ixheaacd_stereo.h"
70 #include "ixheaacd_lpp_tran.h"
71 #include "ixheaacd_hybrid.h"
72 #include "ixheaacd_ps_dec.h"
73 #include "ixheaacd_env_extr.h"
74 #include "ixheaacd_adts.h"
75 #
76 #include "ixheaacd_audioobjtypes.h"
77 #include "ixheaacd_memory_standards.h"
78 #include "ixheaacd_latmdemux.h"
79 #include "ixheaacd_aacdec.h"
80 #include "ixheaacd_mps_polyphase.h"
81 #include "ixheaacd_config.h"
82 #include "ixheaacd_qmf_dec.h"
83 #include "ixheaacd_env_calc.h"
84
85 #include "ixheaacd_pvc_dec.h"
86 #include "ixheaacd_sbr_dec.h"
87 #include "ixheaacd_mps_macro_def.h"
88 #include "ixheaacd_mps_struct_def.h"
89 #include "ixheaacd_mps_res_rom.h"
90 #include "ixheaacd_mps_aac_struct.h"
91 #include "ixheaacd_mps_dec.h"
92 #include "ixheaacd_struct_def.h"
93
94 #include "ixheaacd_mps_process.h"
95
96 #include "ixheaacd_ld_mps_dec.h"
97 #include "ixheaacd_interface.h"
98 #include "ixheaacd_info.h"
99 #include "ixheaacd_tns_usac.h"
100 #include "ixheaacd_acelp_info.h"
101 #include "ixheaacd_main.h"
102 #include "ixheaacd_struct.h"
103 #include "ixheaacd_create.h"
104
ixheaacd_ld_qmf_analysis(ia_mps_dec_state_struct * self,WORD16 * output_buf)105 WORD32 ixheaacd_ld_qmf_analysis(ia_mps_dec_state_struct *self,
106 WORD16 *output_buf) {
107 WORD32 *p_arr_qmf_buf_real[MAX_ENV_COLS + MAX_ENV_COLS];
108 WORD32 **p_arr_qmf_buf_imag = &p_arr_qmf_buf_real[MAX_ENV_COLS];
109 WORD32 temp_arr[64 * 64];
110 WORD32 *ptr = &temp_arr[0];
111 float in_gain_n_q8_fac = self->input_gain * 0.00390625f;
112
113 int i;
114 WORD32 ts;
115
116 for (ts = 2; ts < self->time_slots + 2; ts++) {
117 p_arr_qmf_buf_real[ts] = ptr;
118 ptr += NO_SYNTHESIS_CHANNELS;
119
120 p_arr_qmf_buf_imag[ts] = ptr;
121 ptr += NO_SYNTHESIS_CHANNELS;
122 }
123
124 self->str_mps_qmf_bank.num_time_slots = self->time_slots;
125 self->str_mps_qmf_bank.no_channels = self->qmf_band_count;
126
127 ixheaacd_cplx_anal_qmffilt_32((WORD32 *)output_buf, self->str_sbr_scale_fact,
128 &p_arr_qmf_buf_real[0], &p_arr_qmf_buf_imag[0],
129 &self->str_mps_qmf_bank,
130 self->qmf_dec_tables_ptr, 2, 0);
131
132 for (ts = 0; ts < self->time_slots; ts++) {
133 for (i = 0; i < self->qmf_band_count; i++) {
134 self->qmf_in[0][ts][i].re =
135 (p_arr_qmf_buf_real[ts + 2][i] * in_gain_n_q8_fac);
136 self->qmf_in[0][ts][i].im =
137 (p_arr_qmf_buf_imag[ts + 2][i] * in_gain_n_q8_fac);
138 }
139 }
140
141 return 0;
142 }
143
ixheaacd_ld_mps_apply(ia_exhaacplus_dec_api_struct * p_obj_exhaacplus_dec,WORD16 * output_buf)144 WORD32 ixheaacd_ld_mps_apply(ia_exhaacplus_dec_api_struct *p_obj_exhaacplus_dec,
145 WORD16 *output_buf) {
146 ia_aac_dec_state_struct *aac_handle = p_obj_exhaacplus_dec->p_state_aac;
147 ia_mps_dec_state_struct *mps_handle = &(aac_handle->mps_dec_handle);
148 WORD32 err = 0;
149 WORD32 ts, i;
150 ia_dec_data_struct *pstr_dec_data =
151 (ia_dec_data_struct *)aac_handle->pstr_dec_data;
152 ia_usac_data_struct *pstr_usac_data = &(pstr_dec_data->str_usac_data);
153
154 mps_handle->hyb_band_count[0] = mps_handle->hyb_band_count_max;
155 mps_handle->hyb_band_count[1] = mps_handle->hyb_band_count_max;
156
157 err = ixheaacd_mps_frame_decode(mps_handle);
158 if (err != IA_NO_ERROR) return err;
159
160 if (aac_handle->mps_dec_handle.num_parameter_sets_prev <= 0) return IA_FATAL_ERROR;
161
162 if (mps_handle->ldmps_config.bs_tree_config == 7) {
163 ixheaacd_pre_and_mix_matrix_calculation(&(aac_handle->mps_dec_handle));
164 ixheaacd_mps_pre_matrix_mix_matrix_smoothing(&(aac_handle->mps_dec_handle));
165 }
166 mps_handle->output_buffer = pstr_usac_data->time_sample_vector;
167 if (mps_handle->ldmps_config.no_ldsbr_present)
168 ixheaacd_ld_qmf_analysis(mps_handle, output_buf);
169 else {
170 for (ts = 0; ts < mps_handle->time_slots; ts++) {
171 FLOAT32 *qmf_re = p_obj_exhaacplus_dec->p_state_aac->str_sbr_dec_info[0]
172 ->pstr_sbr_channel[0]
173 ->str_sbr_dec.mps_qmf_buf_real[ts + 2];
174 FLOAT32 *qmf_im = p_obj_exhaacplus_dec->p_state_aac->str_sbr_dec_info[0]
175 ->pstr_sbr_channel[0]
176 ->str_sbr_dec.mps_qmf_buf_imag[ts + 2];
177 for (i = 0; i < mps_handle->qmf_band_count; i++) {
178 mps_handle->qmf_in[0][ts][i].re = qmf_re[i] * mps_handle->input_gain;
179 mps_handle->qmf_in[0][ts][i].im = qmf_im[i] * mps_handle->input_gain;
180 }
181 }
182 }
183 ixheaacd_mps_qmf_hyb_analysis(mps_handle);
184
185 mps_handle->bs_high_rate_mode = 1;
186
187 ixheaacd_mps_apply_pre_matrix(mps_handle);
188
189 ixheaacd_mps_create_w(mps_handle);
190
191 if ((!(mps_handle->res_bands | mps_handle->pre_mix_req)) &&
192 (mps_handle->config->bs_phase_coding == 0)) {
193 ixheaacd_mps_apply_mix_matrix_type1(mps_handle);
194
195 } else if (mps_handle->pre_mix_req) {
196 ixheaacd_mps_apply_mix_matrix_type2(mps_handle);
197
198 } else {
199 ixheaacd_mps_apply_mix_matrix_type3(mps_handle);
200 }
201
202 if (mps_handle->ldmps_config.bs_temp_shape_config == 2) {
203 ixheaacd_mps_time_env_shaping(mps_handle);
204 }
205
206 err = ixheaacd_mps_temp_process(mps_handle);
207 mps_handle->pre_mix_req = 0;
208 if (err)
209 return err;
210
211 return err;
212 }
213