/src/libxaac/decoder/ixheaacd_ld_mps_dec.c
Line | Count | Source |
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 | | |
105 | | WORD32 ixheaacd_ld_qmf_analysis(ia_mps_dec_state_struct *self, |
106 | 133 | WORD16 *output_buf) { |
107 | 133 | WORD32 *p_arr_qmf_buf_real[MAX_ENV_COLS + MAX_ENV_COLS]; |
108 | 133 | WORD32 **p_arr_qmf_buf_imag = &p_arr_qmf_buf_real[MAX_ENV_COLS]; |
109 | 133 | WORD32 temp_arr[64 * 64]; |
110 | 133 | WORD32 *ptr = &temp_arr[0]; |
111 | 133 | float in_gain_n_q8_fac = self->input_gain * 0.00390625f; |
112 | | |
113 | 133 | int i; |
114 | 133 | WORD32 ts; |
115 | | |
116 | 1.66k | for (ts = 2; ts < self->time_slots + 2; ts++) { |
117 | 1.53k | p_arr_qmf_buf_real[ts] = ptr; |
118 | 1.53k | ptr += NO_SYNTHESIS_CHANNELS; |
119 | | |
120 | 1.53k | p_arr_qmf_buf_imag[ts] = ptr; |
121 | 1.53k | ptr += NO_SYNTHESIS_CHANNELS; |
122 | 1.53k | } |
123 | | |
124 | 133 | self->str_mps_qmf_bank.num_time_slots = self->time_slots; |
125 | 133 | self->str_mps_qmf_bank.no_channels = self->qmf_band_count; |
126 | | |
127 | 133 | ixheaacd_cplx_anal_qmffilt_32((WORD32 *)output_buf, self->str_sbr_scale_fact, |
128 | 133 | &p_arr_qmf_buf_real[0], &p_arr_qmf_buf_imag[0], |
129 | 133 | &self->str_mps_qmf_bank, |
130 | 133 | self->qmf_dec_tables_ptr, 2, 0); |
131 | | |
132 | 1.66k | for (ts = 0; ts < self->time_slots; ts++) { |
133 | 72.2k | for (i = 0; i < self->qmf_band_count; i++) { |
134 | 70.6k | self->qmf_in[0][ts][i].re = |
135 | 70.6k | (p_arr_qmf_buf_real[ts + 2][i] * in_gain_n_q8_fac); |
136 | 70.6k | self->qmf_in[0][ts][i].im = |
137 | 70.6k | (p_arr_qmf_buf_imag[ts + 2][i] * in_gain_n_q8_fac); |
138 | 70.6k | } |
139 | 1.53k | } |
140 | | |
141 | 133 | return 0; |
142 | 133 | } |
143 | | |
144 | | WORD32 ixheaacd_ld_mps_apply(ia_exhaacplus_dec_api_struct *p_obj_exhaacplus_dec, |
145 | 3.37k | WORD16 *output_buf) { |
146 | 3.37k | ia_aac_dec_state_struct *aac_handle = p_obj_exhaacplus_dec->p_state_aac; |
147 | 3.37k | ia_mps_dec_state_struct *mps_handle = &(aac_handle->mps_dec_handle); |
148 | 3.37k | WORD32 err = 0; |
149 | 3.37k | WORD32 ts, i; |
150 | 3.37k | ia_dec_data_struct *pstr_dec_data = |
151 | 3.37k | (ia_dec_data_struct *)aac_handle->pstr_dec_data; |
152 | 3.37k | ia_usac_data_struct *pstr_usac_data = &(pstr_dec_data->str_usac_data); |
153 | | |
154 | 3.37k | mps_handle->hyb_band_count[0] = mps_handle->hyb_band_count_max; |
155 | 3.37k | mps_handle->hyb_band_count[1] = mps_handle->hyb_band_count_max; |
156 | | |
157 | 3.37k | err = ixheaacd_mps_frame_decode(mps_handle); |
158 | 3.37k | if (err != IA_NO_ERROR) return err; |
159 | | |
160 | 3.35k | if (aac_handle->mps_dec_handle.num_parameter_sets_prev <= 0) return IA_FATAL_ERROR; |
161 | | |
162 | 3.28k | if (mps_handle->ldmps_config.bs_tree_config == 7) { |
163 | 194 | ixheaacd_pre_and_mix_matrix_calculation(&(aac_handle->mps_dec_handle)); |
164 | 194 | ixheaacd_mps_pre_matrix_mix_matrix_smoothing(&(aac_handle->mps_dec_handle)); |
165 | 194 | } |
166 | 3.28k | mps_handle->output_buffer = pstr_usac_data->time_sample_vector; |
167 | 3.28k | if (mps_handle->ldmps_config.no_ldsbr_present) |
168 | 133 | ixheaacd_ld_qmf_analysis(mps_handle, output_buf); |
169 | 3.15k | else { |
170 | 68.5k | for (ts = 0; ts < mps_handle->time_slots; ts++) { |
171 | 65.3k | FLOAT32 *qmf_re = p_obj_exhaacplus_dec->p_state_aac->str_sbr_dec_info[0] |
172 | 65.3k | ->pstr_sbr_channel[0] |
173 | 65.3k | ->str_sbr_dec.mps_qmf_buf_real[ts + 2]; |
174 | 65.3k | FLOAT32 *qmf_im = p_obj_exhaacplus_dec->p_state_aac->str_sbr_dec_info[0] |
175 | 65.3k | ->pstr_sbr_channel[0] |
176 | 65.3k | ->str_sbr_dec.mps_qmf_buf_imag[ts + 2]; |
177 | 3.88M | for (i = 0; i < mps_handle->qmf_band_count; i++) { |
178 | 3.82M | mps_handle->qmf_in[0][ts][i].re = qmf_re[i] * mps_handle->input_gain; |
179 | 3.82M | mps_handle->qmf_in[0][ts][i].im = qmf_im[i] * mps_handle->input_gain; |
180 | 3.82M | } |
181 | 65.3k | } |
182 | 3.15k | } |
183 | 3.28k | ixheaacd_mps_qmf_hyb_analysis(mps_handle); |
184 | | |
185 | 3.28k | mps_handle->bs_high_rate_mode = 1; |
186 | | |
187 | 3.28k | ixheaacd_mps_apply_pre_matrix(mps_handle); |
188 | | |
189 | 3.28k | ixheaacd_mps_create_w(mps_handle); |
190 | | |
191 | 3.28k | if ((!(mps_handle->res_bands | mps_handle->pre_mix_req)) && |
192 | 2.85k | (mps_handle->config->bs_phase_coding == 0)) { |
193 | 2.85k | ixheaacd_mps_apply_mix_matrix_type1(mps_handle); |
194 | | |
195 | 2.85k | } else if (mps_handle->pre_mix_req) { |
196 | 434 | ixheaacd_mps_apply_mix_matrix_type2(mps_handle); |
197 | | |
198 | 434 | } else { |
199 | 0 | ixheaacd_mps_apply_mix_matrix_type3(mps_handle); |
200 | 0 | } |
201 | | |
202 | 3.28k | if (mps_handle->ldmps_config.bs_temp_shape_config == 2) { |
203 | 863 | ixheaacd_mps_time_env_shaping(mps_handle); |
204 | 863 | } |
205 | | |
206 | 3.28k | err = ixheaacd_mps_temp_process(mps_handle); |
207 | 3.28k | mps_handle->pre_mix_req = 0; |
208 | 3.28k | if (err) |
209 | 0 | return err; |
210 | | |
211 | 3.28k | return err; |
212 | 3.28k | } |