/src/libxaac/encoder/ixheaace_mps_enc.c
Line | Count | Source (jump to first uncovered line) |
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 | | |
21 | | #include <stdlib.h> |
22 | | #include <string.h> |
23 | | #include <math.h> |
24 | | #include "ixheaac_type_def.h" |
25 | | #include "impd_drc_common_enc.h" |
26 | | #include "impd_drc_uni_drc.h" |
27 | | #include "impd_drc_tables.h" |
28 | | #include "impd_drc_api.h" |
29 | | #include "ixheaace_api.h" |
30 | | #include "ixheaac_error_standards.h" |
31 | | #include "ixheaace_error_codes.h" |
32 | | #include "ixheaace_mps_common_fix.h" |
33 | | #include "ixheaace_mps_defines.h" |
34 | | #include "ixheaace_mps_common_define.h" |
35 | | #include "ixheaac_constants.h" |
36 | | #include "ixheaace_bitbuffer.h" |
37 | | #include "ixheaace_sbr_def.h" |
38 | | #include "ixheaace_mps_buf.h" |
39 | | #include "ixheaace_mps_lib.h" |
40 | | #include "ixheaace_mps_main_structure.h" |
41 | | #include "ixheaace_mps_bitstream.h" |
42 | | #include "ixheaace_mps_onset_detect.h" |
43 | | #include "ixheaace_mps_filter.h" |
44 | | #include "ixheaace_mps_param_extract.h" |
45 | | #include "ixheaace_mps_static_gain.h" |
46 | | |
47 | | #include "ixheaace_mps_dmx_tdom_enh.h" |
48 | | #include "ixheaace_mps_tools_rom.h" |
49 | | #include "ixheaace_mps_qmf.h" |
50 | | #include "ixheaace_mps_struct_def.h" |
51 | | #include "ixheaace_mps_sac_polyphase.h" |
52 | | #include "ixheaace_mps_sac_hybfilter.h" |
53 | | #include "ixheaace_mps_spatial_bitstream.h" |
54 | | #include "ixheaace_mps_tree.h" |
55 | | #include "ixheaace_mps_rom.h" |
56 | | #include "ixheaace_mps_delay.h" |
57 | | #include "ixheaace_mps_frame_windowing.h" |
58 | | #include "ixheaace_mps_structure.h" |
59 | | #include "ixheaace_mps_memory.h" |
60 | | #include "ixheaace_mps_enc.h" |
61 | | #include "ixheaac_basic_ops32.h" |
62 | | #include "ixheaac_basic_ops40.h" |
63 | | #include "ixheaac_basic_ops.h" |
64 | | |
65 | 2.69k | static UWORD8 ixheaace_mps_212_space_get_num_qmf_bands(const UWORD32 num_sample_rate) { |
66 | 2.69k | UWORD8 num_qmf_bands = 0; |
67 | 2.69k | if (num_sample_rate < 27713) |
68 | 0 | num_qmf_bands = 32; |
69 | 2.69k | else if (num_sample_rate < 55426) |
70 | 2.69k | num_qmf_bands = 64; |
71 | | |
72 | 2.69k | return num_qmf_bands; |
73 | 2.69k | } |
74 | | |
75 | | static VOID ixheaace_mps_212_space_tree_open(ixheaace_mps_pstr_space_tree *pstr_ph_space_tree, |
76 | 1.35k | ixheaace_mps_212_memory_struct *pstr_mps_memory) { |
77 | 1.35k | ixheaace_mps_pstr_space_tree pstr_space_tree = NULL; |
78 | 1.35k | WORD32 box; |
79 | | |
80 | 1.35k | pstr_space_tree = &pstr_mps_memory->spacce_tree; |
81 | | |
82 | 2.70k | for (box = 0; box < IXHEAACE_MPS_MAX_NUM_BOXES; box++) { |
83 | 1.35k | ixheaace_mps_pstr_tto_box pstr_tto_box = NULL; |
84 | 1.35k | pstr_tto_box = &pstr_mps_memory->tto_box; |
85 | | |
86 | 1.35k | if (NULL != pstr_space_tree) { |
87 | 1.35k | pstr_space_tree->pstr_tto_box[box] = pstr_tto_box; |
88 | 1.35k | } |
89 | 1.35k | } |
90 | 1.35k | *pstr_ph_space_tree = pstr_space_tree; |
91 | 1.35k | } |
92 | | |
93 | | static VOID ixheaace_mps_212_init_num_param_bands( |
94 | 1.34k | ixheaace_mps_pstr_space_structure pstr_space_enc, const WORD32 num_param_bands) { |
95 | 1.34k | WORD32 k = 0; |
96 | 1.34k | const WORD32 n = sizeof(valid_bands_ld) / sizeof(UWORD8); |
97 | 1.34k | const UWORD8 *p_bands = valid_bands_ld; |
98 | | |
99 | 11.1k | while (k < n && p_bands[k] != (UWORD8)num_param_bands) ++k; |
100 | 1.34k | if (k == n) { |
101 | 0 | pstr_space_enc->num_param_bands = IXHEAACE_MPS_SAC_BANDS_INVALID; |
102 | 1.34k | } else { |
103 | 1.34k | pstr_space_enc->num_param_bands = num_param_bands; |
104 | 1.34k | } |
105 | 1.34k | } |
106 | | |
107 | | static IA_ERRORCODE ixheaace_mps_212_configure( |
108 | | ixheaace_mps_pstr_space_structure pstr_space_enc, |
109 | 1.34k | const ixheaace_mps_pstr_spece_enc_setup pstr_h_set_up) { |
110 | 1.34k | IA_ERRORCODE error = IA_NO_ERROR; |
111 | | |
112 | 1.34k | pstr_space_enc->num_sample_rate = pstr_h_set_up->sample_rate; |
113 | 1.34k | pstr_space_enc->num_qmf_bands = |
114 | 1.34k | ixheaace_mps_212_space_get_num_qmf_bands(pstr_space_enc->num_sample_rate); |
115 | 1.34k | pstr_space_enc->time_alignment = pstr_h_set_up->time_alignment; |
116 | 1.34k | pstr_space_enc->quant_mode = pstr_h_set_up->quant_mode; |
117 | | |
118 | 1.34k | pstr_space_enc->use_coarse_quant_cld = pstr_h_set_up->b_use_coarse_quant; |
119 | 1.34k | pstr_space_enc->use_coarse_quant_cpc = pstr_h_set_up->b_use_coarse_quant; |
120 | 1.34k | pstr_space_enc->use_frame_keep = (pstr_h_set_up->b_ld_mode == 2); |
121 | 1.34k | pstr_space_enc->use_coarse_quant_icc = 0; |
122 | 1.34k | pstr_space_enc->use_coarse_quant_arb_dmx = 0; |
123 | 1.34k | pstr_space_enc->independency_factor = pstr_h_set_up->independency_factor; |
124 | 1.34k | pstr_space_enc->independency_count = 0; |
125 | 1.34k | pstr_space_enc->independency_flag = 1; |
126 | | |
127 | 1.34k | pstr_space_enc->num_hybrid_bands = pstr_space_enc->num_qmf_bands; |
128 | 1.34k | pstr_space_enc->num_frame_time_slots = pstr_h_set_up->frame_time_slots; |
129 | 1.34k | ixheaace_mps_212_init_num_param_bands(pstr_space_enc, pstr_h_set_up->num_param_bands); |
130 | | |
131 | 1.34k | return error; |
132 | 1.34k | } |
133 | | |
134 | | static WORD32 ixheaace_mps_212_get_analysis_length_time_slots(FLOAT32 *ptr_frame_window_ana, |
135 | 106k | WORD32 num_time_slots) { |
136 | 106k | WORD32 i; |
137 | 1.56M | for (i = num_time_slots - 1; i >= 0; i--) { |
138 | 1.56M | if (ptr_frame_window_ana[i] != 0) { |
139 | 106k | break; |
140 | 106k | } |
141 | 1.56M | } |
142 | 106k | num_time_slots = i + 1; |
143 | 106k | return num_time_slots; |
144 | 106k | } |
145 | | |
146 | | static WORD32 ixheaace_mps_212_get_analysis_start_time_slot(FLOAT32 *ptr_frame_window_ana, |
147 | 106k | WORD32 num_time_slots) { |
148 | 106k | WORD32 start_time_slot = 0; |
149 | 106k | WORD32 i; |
150 | 1.71M | for (i = 0; i < num_time_slots; i++) { |
151 | 1.71M | if (ptr_frame_window_ana[i] != 0) { |
152 | 106k | break; |
153 | 106k | } |
154 | 1.71M | } |
155 | 106k | start_time_slot = i; |
156 | 106k | return start_time_slot; |
157 | 106k | } |
158 | | |
159 | | static VOID ixheaace_mps_212_memcpy_flex_pcm(FLOAT32 *const ptr_dst, const WORD32 dst_stride, |
160 | | const FLOAT32 *const ptr_src, |
161 | 0 | const WORD32 src_stride, const WORD32 num_samples) { |
162 | 0 | WORD32 i; |
163 | |
|
164 | 0 | for (i = 0; i < num_samples; i++) { |
165 | 0 | ptr_dst[i * dst_stride] = ptr_src[i * src_stride]; |
166 | 0 | } |
167 | 0 | } |
168 | | |
169 | | static IA_ERRORCODE ixheaace_mps_212_feed_de_inter_pre_scale( |
170 | | ixheaace_mps_pstr_space_structure pstr_space_enc, FLOAT32 const *const ptr_samples, |
171 | | FLOAT32 *const ptr_output_samples, WORD32 const num_samples, |
172 | | UWORD32 const is_input_inter_leaved, UWORD32 const input_buffer_size_per_channel, |
173 | 106k | UWORD32 *const ptr_n_samples_fed) { |
174 | 106k | IA_ERRORCODE error = IA_NO_ERROR; |
175 | 106k | WORD32 ch; |
176 | 106k | const WORD32 num_ch_in = pstr_space_enc->n_input_channels; |
177 | 106k | const WORD32 num_ch_in_with_dmx = num_ch_in; |
178 | 106k | const WORD32 samples_to_feed = |
179 | 106k | MIN(num_samples, pstr_space_enc->n_samples_next - pstr_space_enc->n_samples_valid); |
180 | 106k | const WORD32 num_samples_per_channel = samples_to_feed / num_ch_in_with_dmx; |
181 | | |
182 | 106k | if ((samples_to_feed < 0) || (samples_to_feed % num_ch_in_with_dmx != 0) || |
183 | 106k | (samples_to_feed > num_ch_in_with_dmx * (WORD32)pstr_space_enc->n_frame_length)) { |
184 | 0 | return IA_EXHEAACE_CONFIG_NONFATAL_MPS_INVALID_CONFIG; |
185 | 0 | } |
186 | 106k | const FLOAT32 *p_input_mps; |
187 | 106k | const FLOAT32 *p_input_2_mps; |
188 | 106k | { |
189 | 106k | p_input_mps = ptr_samples; |
190 | 106k | p_input_2_mps = ptr_samples + (pstr_space_enc->n_input_delay * num_ch_in_with_dmx); |
191 | 106k | } |
192 | 318k | for (ch = 0; ch < num_ch_in; ch++) { |
193 | 212k | memcpy(&(pstr_space_enc->time_signal_in[ch][0]), |
194 | 212k | &(pstr_space_enc->time_signal_delay_in[ch][0]), |
195 | 212k | pstr_space_enc->n_surround_analysis_buffer_delay * sizeof(FLOAT32)); |
196 | | |
197 | 212k | if (is_input_inter_leaved) { |
198 | 0 | ixheaace_mps_212_memcpy_flex_pcm( |
199 | 0 | &(pstr_space_enc->time_signal_in[ch][pstr_space_enc->n_surround_analysis_buffer_delay]), |
200 | 0 | 1, p_input_mps + ch, num_ch_in_with_dmx, pstr_space_enc->n_input_delay); |
201 | 0 | ixheaace_mps_212_memcpy_flex_pcm( |
202 | 0 | &(pstr_space_enc->time_signal_in[ch][pstr_space_enc->n_surround_analysis_buffer_delay + |
203 | 0 | pstr_space_enc->n_input_delay]), |
204 | 0 | 1, p_input_2_mps + ch, num_ch_in_with_dmx, |
205 | 0 | num_samples_per_channel - pstr_space_enc->n_input_delay); |
206 | 212k | } else { |
207 | 212k | memcpy( |
208 | 212k | &(pstr_space_enc->time_signal_in[ch][pstr_space_enc->n_surround_analysis_buffer_delay]), |
209 | 212k | p_input_mps + ch * input_buffer_size_per_channel, |
210 | 212k | pstr_space_enc->n_input_delay * sizeof(FLOAT32)); |
211 | 212k | memcpy( |
212 | 212k | &(pstr_space_enc->time_signal_in[ch][pstr_space_enc->n_surround_analysis_buffer_delay + |
213 | 212k | pstr_space_enc->n_input_delay]), |
214 | 212k | p_input_2_mps + ch * input_buffer_size_per_channel, |
215 | 212k | (num_samples_per_channel - pstr_space_enc->n_input_delay) * sizeof(FLOAT32)); |
216 | 212k | } |
217 | | |
218 | 212k | memcpy(&(pstr_space_enc->time_signal_delay_in[ch][0]), |
219 | 212k | &(pstr_space_enc->time_signal_in[ch][pstr_space_enc->n_frame_length]), |
220 | 212k | pstr_space_enc->n_surround_analysis_buffer_delay * sizeof(FLOAT32)); |
221 | 212k | } |
222 | | |
223 | 106k | error = ixheaace_mps_212_apply_enhanced_time_domain_dmx( |
224 | 106k | pstr_space_enc->pstr_enhanced_time_dmx, pstr_space_enc->time_signal_in, ptr_output_samples, |
225 | 106k | pstr_space_enc->n_surround_analysis_buffer_delay); |
226 | 106k | if (error) { |
227 | 0 | return error; |
228 | 0 | } |
229 | | |
230 | 106k | pstr_space_enc->n_samples_valid += samples_to_feed; |
231 | | |
232 | 106k | *ptr_n_samples_fed = samples_to_feed; |
233 | 106k | return error; |
234 | 106k | } |
235 | | |
236 | | static IA_ERRORCODE ixheaace_mps_212_init_delay_compensation( |
237 | 1.34k | ixheaace_mps_pstr_space_structure pstr_space_enc, const WORD32 core_coder_delay, WORD32 aot) { |
238 | 1.34k | IA_ERRORCODE error = IA_NO_ERROR; |
239 | 1.34k | WORD32 i; |
240 | 1.34k | memset(&pstr_space_enc->pstr_delay->delay_config, 0, |
241 | 1.34k | sizeof(pstr_space_enc->pstr_delay->delay_config)); |
242 | 1.34k | pstr_space_enc->core_coder_delay = core_coder_delay; |
243 | 1.34k | pstr_space_enc->pstr_delay->delay_config.num_qmf_len = pstr_space_enc->num_qmf_bands; |
244 | 1.34k | pstr_space_enc->pstr_delay->delay_config.num_frame_len = pstr_space_enc->n_frame_length; |
245 | 1.34k | pstr_space_enc->pstr_delay->delay_config.num_core_coder_delay = core_coder_delay; |
246 | 1.34k | pstr_space_enc->pstr_delay->delay_config.num_sac_stream_mux_delay = |
247 | 1.34k | pstr_space_enc->time_alignment; |
248 | 1.34k | pstr_space_enc->pstr_delay->delay_config.b_dmx_align = 0; |
249 | 1.34k | pstr_space_enc->pstr_delay->delay_config.b_minimize_delay = 1; |
250 | | |
251 | 1.34k | ixheaace_mps_212_delay_sub_calculate_buffer_delays(pstr_space_enc->pstr_delay); |
252 | | |
253 | 1.34k | pstr_space_enc->n_bitstream_delay_buffer = |
254 | 1.34k | pstr_space_enc->pstr_delay->num_bitstream_frame_buffer_size; |
255 | 1.34k | pstr_space_enc->n_output_buffer_delay = pstr_space_enc->pstr_delay->num_output_audio_buffer; |
256 | 1.34k | pstr_space_enc->n_surround_analysis_buffer_delay = |
257 | 1.34k | pstr_space_enc->pstr_delay->num_surround_analysis_buffer; |
258 | 1.34k | pstr_space_enc->n_bitstream_buffer_read = 0; |
259 | 1.34k | pstr_space_enc->n_bitstream_buffer_write = pstr_space_enc->n_bitstream_delay_buffer - 1; |
260 | 1.34k | pstr_space_enc->num_discard_out_frames = pstr_space_enc->pstr_delay->num_discard_out_frames; |
261 | 1.34k | pstr_space_enc->n_input_delay = pstr_space_enc->pstr_delay->num_dmx_align_buffer; |
262 | 1.34k | pstr_space_enc->independency_count = 0; |
263 | 1.34k | pstr_space_enc->independency_flag = 1; |
264 | | |
265 | 1.34k | for (i = 0; i < pstr_space_enc->n_bitstream_delay_buffer - 1; i++) { |
266 | 0 | ixheaace_mps_spatial_frame *pstr_frame_data = NULL; |
267 | 0 | pstr_frame_data = &pstr_space_enc->pstr_bitstream_formatter->frame; |
268 | 0 | pstr_frame_data->bs_independency_flag = 1; |
269 | 0 | pstr_frame_data->framing_info.num_param_sets = 1; |
270 | 0 | pstr_frame_data->framing_info.bs_framing_type = 0; |
271 | |
|
272 | 0 | error = ixheaace_mps_212_write_spatial_frame( |
273 | 0 | pstr_space_enc->bit_stream_delay_buffer[i], MAX_MPEGS_BYTES, |
274 | 0 | &pstr_space_enc->pn_output_bits[i], pstr_space_enc->pstr_bitstream_formatter, aot); |
275 | 0 | if (error) { |
276 | 0 | return error; |
277 | 0 | } |
278 | 0 | } |
279 | | |
280 | 1.34k | if ((pstr_space_enc->n_input_delay > MAX_DELAY_INPUT) || |
281 | 1.34k | (pstr_space_enc->n_output_buffer_delay > MAX_DELAY_OUTPUT) || |
282 | 1.34k | (pstr_space_enc->n_surround_analysis_buffer_delay > MAX_DELAY_SURROUND_ANALYSIS) || |
283 | 1.34k | (pstr_space_enc->n_bitstream_delay_buffer > MAX_BITSTREAM_DELAY)) { |
284 | 0 | return IA_EXHEAACE_INIT_FATAL_MPS_INIT_FAILED; |
285 | 0 | } |
286 | 1.34k | return error; |
287 | 1.34k | } |
288 | | |
289 | | static IA_ERRORCODE ixheaace_mps_212_fill_spatial_specific_config( |
290 | | const ixheaace_mps_pstr_space_structure pstr_space_enc, |
291 | 1.34k | ixheaace_mps_spatial_specific_config *const pstr_h_ssc) { |
292 | 1.34k | IA_ERRORCODE error = IA_NO_ERROR; |
293 | | |
294 | 1.34k | ixheaace_mps_space_tree_description space_tree_description; |
295 | 1.34k | WORD32 i; |
296 | 1.34k | space_tree_description = pstr_space_enc->pstr_space_tree->descr; |
297 | 1.34k | memset(pstr_h_ssc, 0, sizeof(ixheaace_mps_spatial_specific_config)); |
298 | | |
299 | 1.34k | pstr_h_ssc->num_bands = pstr_space_enc->space_tree_setup.num_param_bands; |
300 | 1.34k | pstr_h_ssc->tree_description.num_ott_boxes = space_tree_description.num_ott_boxes; |
301 | 1.34k | pstr_h_ssc->tree_description.num_in_chan = space_tree_description.num_in_channels; |
302 | 1.34k | pstr_h_ssc->tree_description.num_out_chan = space_tree_description.num_out_channels; |
303 | | |
304 | 2.69k | for (i = 0; i < IXHEAACE_MPS_MAX_NUM_BOXES; i++) { |
305 | 1.34k | pstr_h_ssc->ott_config[i].bs_ott_bands = pstr_h_ssc->num_bands; |
306 | 1.34k | } |
307 | 1.34k | pstr_h_ssc->bs_tree_config = IXHEAACE_MPS_TREE_212; |
308 | 1.34k | pstr_h_ssc->bs_sampling_frequency = pstr_space_enc->num_sample_rate; |
309 | 1.34k | pstr_h_ssc->bs_frame_length = pstr_space_enc->num_frame_time_slots - 1; |
310 | 1.34k | pstr_h_ssc->bs_decorr_config = IXHEAACE_MPS_DECORR_QMFSPLIT0; |
311 | 1.34k | pstr_h_ssc->bs_quant_mode = pstr_space_enc->quant_mode; |
312 | 1.34k | if (pstr_space_enc->pstr_static_gain->fixed_gain_dmx > IXHEAACE_MPS_MAX_FIXED_GAIN_DMX) { |
313 | 0 | pstr_h_ssc->bs_fixed_gain_dmx = IXHEAACE_MPS_FIXED_GAIN_DMX_INVALID; |
314 | 1.34k | } else { |
315 | 1.34k | pstr_h_ssc->bs_fixed_gain_dmx = pstr_space_enc->pstr_static_gain->fixed_gain_dmx; |
316 | 1.34k | } |
317 | 1.34k | pstr_h_ssc->bs_env_quant_mode = 0; |
318 | 1.34k | return error; |
319 | 1.34k | } |
320 | | |
321 | | static IA_ERRORCODE ixheaace_mps_212_fill_space_tree_setup( |
322 | | const ixheaace_mps_pstr_space_structure pstr_space_enc, |
323 | 1.34k | ixheaace_mps_space_tree_setup *const ptr_space_tree_setup) { |
324 | 1.34k | IA_ERRORCODE error = IA_NO_ERROR; |
325 | | |
326 | 1.34k | ptr_space_tree_setup->num_param_bands = pstr_space_enc->num_param_bands; |
327 | 1.34k | ptr_space_tree_setup->use_coarse_quant_tto_cld_flag = pstr_space_enc->use_coarse_quant_cld; |
328 | 1.34k | ptr_space_tree_setup->use_coarse_quant_tto_icc_flag = pstr_space_enc->use_coarse_quant_icc; |
329 | 1.34k | ptr_space_tree_setup->quant_mode = pstr_space_enc->quant_mode; |
330 | 1.34k | ptr_space_tree_setup->num_hybrid_bands_max = pstr_space_enc->num_hybrid_bands; |
331 | 1.34k | ptr_space_tree_setup->num_channels_in_max = 2; |
332 | 1.34k | return error; |
333 | 1.34k | } |
334 | | |
335 | | static VOID ixheaace_mps_212_get_info(const ixheaace_mps_pstr_space_structure pstr_space_enc, |
336 | 1.34k | ixheaace_mps_space_info *const pstr_space_info) { |
337 | 1.34k | pstr_space_info->num_sample_rate = pstr_space_enc->num_sample_rate; |
338 | 1.34k | pstr_space_info->num_samples_frame = pstr_space_enc->n_frame_length; |
339 | 1.34k | pstr_space_info->num_total_input_channels = pstr_space_enc->n_input_channels; |
340 | 1.34k | pstr_space_info->dmx_delay = pstr_space_enc->pstr_delay->num_info_dmx_delay; |
341 | 1.34k | pstr_space_info->codec_delay = pstr_space_enc->pstr_delay->num_info_codec_delay; |
342 | 1.34k | pstr_space_info->decoder_delay = pstr_space_enc->pstr_delay->num_info_decoder_delay; |
343 | 1.34k | pstr_space_info->pay_load_delay = |
344 | 1.34k | pstr_space_enc->pstr_delay->num_bitstream_frame_buffer_size - 1; |
345 | 1.34k | pstr_space_info->num_discard_out_frames = pstr_space_enc->num_discard_out_frames; |
346 | 1.34k | pstr_space_info->p_ssc_buf = &pstr_space_enc->ssc_buf; |
347 | 1.34k | } |
348 | | |
349 | | static VOID ixheaace_mps_212_duplicate_parameter_set( |
350 | | const ixheaace_mps_spatial_frame *const pstr_spatial_frame_from, const WORD32 set_from, |
351 | 106k | ixheaace_mps_spatial_frame *const pstr_spatial_frame_to, const WORD32 set_to) { |
352 | 106k | WORD32 box; |
353 | 212k | for (box = 0; box < IXHEAACE_MPS_MAX_NUM_BOXES; box++) { |
354 | 106k | memcpy(pstr_spatial_frame_to->ott_data.cld[box][set_to], |
355 | 106k | pstr_spatial_frame_from->ott_data.cld[box][set_from], |
356 | 106k | sizeof(pstr_spatial_frame_from->ott_data.cld[0][0])); |
357 | 106k | pstr_spatial_frame_to->cld_lossless_data.bs_xxx_data_mode[box][set_to] = |
358 | 106k | pstr_spatial_frame_from->cld_lossless_data.bs_xxx_data_mode[box][set_from]; |
359 | 106k | pstr_spatial_frame_to->cld_lossless_data.bs_data_pair[box][set_to] = |
360 | 106k | pstr_spatial_frame_from->cld_lossless_data.bs_data_pair[box][set_from]; |
361 | 106k | pstr_spatial_frame_to->cld_lossless_data.bs_quant_coarse_xxx[box][set_to] = |
362 | 106k | pstr_spatial_frame_from->cld_lossless_data.bs_quant_coarse_xxx[box][set_from]; |
363 | 106k | pstr_spatial_frame_to->cld_lossless_data.bs_freq_res_stride_xxx[box][set_to] = |
364 | 106k | pstr_spatial_frame_from->cld_lossless_data.bs_freq_res_stride_xxx[box][set_from]; |
365 | | |
366 | 106k | memcpy(pstr_spatial_frame_to->ott_data.icc[box][set_to], |
367 | 106k | pstr_spatial_frame_from->ott_data.icc[box][set_from], |
368 | 106k | sizeof(pstr_spatial_frame_from->ott_data.icc[0][0])); |
369 | 106k | pstr_spatial_frame_to->icc_lossless_data.bs_xxx_data_mode[box][set_to] = |
370 | 106k | pstr_spatial_frame_from->icc_lossless_data.bs_xxx_data_mode[box][set_from]; |
371 | 106k | pstr_spatial_frame_to->icc_lossless_data.bs_data_pair[box][set_to] = |
372 | 106k | pstr_spatial_frame_from->icc_lossless_data.bs_data_pair[box][set_from]; |
373 | 106k | pstr_spatial_frame_to->icc_lossless_data.bs_quant_coarse_xxx[box][set_to] = |
374 | 106k | pstr_spatial_frame_from->icc_lossless_data.bs_quant_coarse_xxx[box][set_from]; |
375 | 106k | pstr_spatial_frame_to->icc_lossless_data.bs_freq_res_stride_xxx[box][set_to] = |
376 | 106k | pstr_spatial_frame_from->icc_lossless_data.bs_freq_res_stride_xxx[box][set_from]; |
377 | 106k | } |
378 | 106k | } |
379 | | |
380 | | static IA_ERRORCODE ixheaace_mps_212_encode( |
381 | | const ixheaace_mps_pstr_space_structure pstr_space_enc, |
382 | | const ixheaace_mps_buf_descr *ptr_in_buf_desc, const ixheaace_mps_buf_descr *ptr_out_buf_desc, |
383 | | const ixheaace_mps_in_args *pstr_in_args, ixheaace_mps_out_args *pstr_out_args, WORD32 aot, |
384 | 106k | WORD8 *ptr_scratch) { |
385 | 106k | IA_ERRORCODE error = IA_NO_ERROR; |
386 | 106k | WORD32 num_output_samples; |
387 | 106k | WORD32 i, ch, ps, win_cnt, ts, slot; |
388 | 106k | WORD32 curr_trans_pos = -1; |
389 | 106k | WORD32 num_ch_in; |
390 | 106k | WORD32 num_ch_in_with_dmx; |
391 | 106k | WORD32 num_ch_out; |
392 | 106k | WORD32 num_samples_per_channel; |
393 | 106k | WORD32 num_output_samples_max; |
394 | 106k | WORD32 num_frame_time_slots; |
395 | 106k | WORD32 num_frame_time_slots_reduction; |
396 | 106k | ixheaace_mps_spatial_frame *pstr_frame_data = NULL; |
397 | 106k | UWORD8 *ptr_bitstream_delay_buffer; |
398 | 106k | const FLOAT32 *ptr_input_samples = |
399 | 106k | (const FLOAT32 *)ptr_in_buf_desc->pp_base[IXHEAACE_MPS_INPUT_BUFFER_IDX]; |
400 | | |
401 | 106k | FLOAT32 *const ptr_output_samples = |
402 | 106k | (FLOAT32 *)ptr_out_buf_desc->pp_base[IXHEAACE_MPS_OUTUT_BUFFER_IDX]; |
403 | | |
404 | 106k | const WORD32 num_output_samples_buffer_size = |
405 | 106k | ptr_out_buf_desc->p_buf_size[IXHEAACE_MPS_OUTUT_BUFFER_IDX] / |
406 | 106k | ptr_out_buf_desc->p_ele_size[IXHEAACE_MPS_OUTUT_BUFFER_IDX]; |
407 | 106k | num_ch_in = pstr_space_enc->n_input_channels; |
408 | 106k | num_ch_in_with_dmx = num_ch_in; |
409 | 106k | num_ch_out = pstr_space_enc->n_output_channels; |
410 | 106k | num_samples_per_channel = pstr_in_args->num_input_samples / num_ch_in_with_dmx; |
411 | 106k | num_output_samples_max = num_samples_per_channel * num_ch_out; |
412 | 106k | num_frame_time_slots = pstr_space_enc->num_frame_time_slots; |
413 | 106k | num_frame_time_slots_reduction = pstr_space_enc->num_frame_time_slots >> 1; |
414 | 106k | if ((0 != pstr_in_args->num_input_samples % num_ch_in_with_dmx)) { |
415 | 0 | return IA_EXHEAACE_CONFIG_NONFATAL_MPS_INVALID_CONFIG; |
416 | 0 | } |
417 | 106k | pstr_frame_data = &pstr_space_enc->pstr_bitstream_formatter->frame; |
418 | | |
419 | 106k | if (aot != AOT_USAC) { |
420 | 41.7k | if (pstr_space_enc->num_discard_out_frames > 0) { |
421 | 0 | pstr_space_enc->independency_count = 0; |
422 | 0 | pstr_space_enc->independency_flag = 1; |
423 | 41.7k | } else { |
424 | 41.7k | pstr_space_enc->independency_flag = (pstr_space_enc->independency_count == 0) ? 1 : 0; |
425 | 41.7k | if (pstr_space_enc->independency_factor > 0) { |
426 | 41.7k | pstr_space_enc->independency_count++; |
427 | 41.7k | pstr_space_enc->independency_count = |
428 | 41.7k | pstr_space_enc->independency_count % ((WORD32)pstr_space_enc->independency_factor); |
429 | 41.7k | } else { |
430 | 0 | pstr_space_enc->independency_count = -1; |
431 | 0 | } |
432 | 41.7k | } |
433 | 41.7k | } |
434 | | |
435 | 106k | error = ixheaace_mps_212_feed_de_inter_pre_scale( |
436 | 106k | pstr_space_enc, ptr_input_samples, ptr_output_samples, pstr_in_args->num_input_samples, |
437 | 106k | pstr_in_args->is_input_inter_leaved, pstr_in_args->input_buffer_size_per_channel, |
438 | 106k | &pstr_out_args->num_samples_consumed); |
439 | 106k | if (error) { |
440 | 0 | return error; |
441 | 0 | } |
442 | | |
443 | 106k | if (pstr_space_enc->n_samples_next != pstr_space_enc->n_samples_valid) { |
444 | 0 | return IA_EXHEAACE_CONFIG_NONFATAL_MPS_INVALID_CONFIG; |
445 | 0 | } |
446 | | |
447 | 318k | for (ch = 0; ch < num_ch_in; ch++) { |
448 | 6.01M | for (slot = 0; slot < num_frame_time_slots; slot++) { |
449 | 5.80M | ixheaace_cmplx_str *pstr_cmplx_data; |
450 | | |
451 | 5.80M | pstr_cmplx_data = |
452 | 5.80M | pstr_space_enc |
453 | 5.80M | ->cmplx_hybrid_in[ch][pstr_space_enc->n_update_hybrid_position_time_slots + |
454 | 5.80M | num_frame_time_slots - num_frame_time_slots_reduction + slot]; |
455 | 5.80M | memset(pstr_cmplx_data, 0, 2 * pstr_space_enc->num_hybrid_bands * sizeof(WORD32)); |
456 | 5.80M | } |
457 | 212k | } |
458 | | |
459 | 318k | for (ch = 0; ch < num_ch_in; ch++) { |
460 | 212k | FLOAT32 qmf_in_real[MAX_QMF_BANDS]; |
461 | 212k | FLOAT32 qmf_in_imag[MAX_QMF_BANDS]; |
462 | 212k | FLOAT32 p_work_buffer[MAX_QMF_BANDS << 1]; |
463 | 212k | FLOAT32 *ptr_pre_gain = pstr_space_enc->pstr_static_gain->pre_gain; |
464 | 6.01M | for (ts = 0; ts < num_frame_time_slots; ts++) { |
465 | 5.80M | FLOAT32 *ptr_spec_real; |
466 | 5.80M | FLOAT32 *ptr_spec_imag; |
467 | | |
468 | 5.80M | FLOAT32 *ptr_time_in = |
469 | 5.80M | &pstr_space_enc->time_signal_in[ch][(ts * pstr_space_enc->num_qmf_bands)]; |
470 | | |
471 | 5.80M | ixheaace_mps_212_apply_dc_filter(pstr_space_enc->pstr_dc_filter[ch], ptr_time_in, |
472 | 5.80M | ptr_time_in, pstr_space_enc->num_qmf_bands); |
473 | | |
474 | 5.80M | error = ixheaace_mps_212_qmf_analysis_filtering_slot(pstr_space_enc->pstr_qmf_filter_in[ch], |
475 | 5.80M | qmf_in_real, qmf_in_imag, ptr_time_in, |
476 | 5.80M | 1, p_work_buffer, ptr_scratch); |
477 | 5.80M | if (error != IA_NO_ERROR) { |
478 | 0 | return error; |
479 | 0 | } |
480 | | |
481 | 5.80M | ptr_spec_real = qmf_in_real; |
482 | 5.80M | ptr_spec_imag = qmf_in_imag; |
483 | 5.80M | if (1.0f != ptr_pre_gain[ch]) { |
484 | 0 | for (i = 0; i < pstr_space_enc->num_hybrid_bands; i++) { |
485 | 0 | pstr_space_enc |
486 | 0 | ->cmplx_hybrid_in[ch][pstr_space_enc->n_analysis_lookahead_time_slots + ts][i] |
487 | 0 | .re = ptr_spec_real[i] * ptr_pre_gain[ch]; |
488 | 0 | pstr_space_enc |
489 | 0 | ->cmplx_hybrid_in[ch][pstr_space_enc->n_analysis_lookahead_time_slots + ts][i] |
490 | 0 | .im = ptr_spec_imag[i] * ptr_pre_gain[ch]; |
491 | 0 | } |
492 | 5.80M | } else { |
493 | 377M | for (i = 0; i < pstr_space_enc->num_hybrid_bands; i++) { |
494 | 371M | pstr_space_enc |
495 | 371M | ->cmplx_hybrid_in[ch][pstr_space_enc->n_analysis_lookahead_time_slots + ts][i] |
496 | 371M | .re = ptr_spec_real[i]; |
497 | 371M | pstr_space_enc |
498 | 371M | ->cmplx_hybrid_in[ch][pstr_space_enc->n_analysis_lookahead_time_slots + ts][i] |
499 | 371M | .im = ptr_spec_imag[i]; |
500 | 371M | } |
501 | 5.80M | } |
502 | 5.80M | } |
503 | 212k | } |
504 | | |
505 | 318k | for (ch = 0; ch < num_ch_in; ch++) { |
506 | 8.94M | for (slot = 0; slot < (WORD32)(pstr_space_enc->n_update_hybrid_position_time_slots + |
507 | 8.94M | num_frame_time_slots - num_frame_time_slots_reduction); |
508 | 8.72M | slot++) { |
509 | 8.72M | memmove(pstr_space_enc->cmplx_hybrid_in[ch][slot], |
510 | 8.72M | pstr_space_enc->cmplx_hybrid_in_static[ch][slot], |
511 | 8.72M | sizeof(ixheaace_cmplx_str) * pstr_space_enc->num_hybrid_bands); |
512 | 8.72M | } |
513 | | |
514 | 8.94M | for (slot = 0; slot < (WORD32)(pstr_space_enc->n_update_hybrid_position_time_slots + |
515 | 8.94M | num_frame_time_slots - num_frame_time_slots_reduction); |
516 | 8.72M | slot++) { |
517 | 8.72M | memmove(pstr_space_enc->cmplx_hybrid_in_static[ch][slot], |
518 | 8.72M | pstr_space_enc->cmplx_hybrid_in[ch][num_frame_time_slots + slot], |
519 | 8.72M | sizeof(ixheaace_cmplx_str) * pstr_space_enc->num_hybrid_bands); |
520 | 8.72M | } |
521 | | |
522 | 212k | error = ixheaace_mps_212_onset_detect_apply( |
523 | 212k | pstr_space_enc->pstr_onset_detect[ch], num_frame_time_slots, |
524 | 212k | &pstr_space_enc->cmplx_hybrid_in[ch][pstr_space_enc->n_analysis_lookahead_time_slots], |
525 | 212k | pstr_space_enc->tr_prev_pos[1], pstr_space_enc->pp_tr_curr_pos[ch]); |
526 | 212k | if (error) { |
527 | 0 | return error; |
528 | 0 | } |
529 | | |
530 | 212k | if (pstr_space_enc->use_frame_keep == 0) { |
531 | 0 | pstr_space_enc->pp_tr_curr_pos[ch][0] = -1; |
532 | 0 | } |
533 | | |
534 | 212k | if ((pstr_space_enc->pp_tr_curr_pos[ch][0] >= 0) && |
535 | 212k | ((curr_trans_pos < 0) || (pstr_space_enc->pp_tr_curr_pos[ch][0] < curr_trans_pos))) { |
536 | 27.3k | curr_trans_pos = pstr_space_enc->pp_tr_curr_pos[ch][0]; |
537 | 27.3k | } |
538 | 212k | } |
539 | 106k | if (pstr_space_enc->use_frame_keep == 1) { |
540 | 106k | if ((curr_trans_pos != -1) || (pstr_space_enc->independency_flag == 1)) { |
541 | 32.8k | pstr_space_enc->avoid_keep = NUM_KEEP_WINDOWS; |
542 | 32.8k | curr_trans_pos = -1; |
543 | 32.8k | } |
544 | 106k | } |
545 | | |
546 | 106k | pstr_space_enc->tr_prev_pos[0] = MAX(-1, pstr_space_enc->tr_prev_pos[1] - num_frame_time_slots); |
547 | 106k | pstr_space_enc->tr_prev_pos[1] = curr_trans_pos; |
548 | | |
549 | 318k | for (ch = 0; ch < num_ch_in; ch++) { |
550 | 212k | error = ixheaace_mps_212_onset_detect_update(pstr_space_enc->pstr_onset_detect[ch], |
551 | 212k | num_frame_time_slots); |
552 | 212k | if (error) { |
553 | 0 | return error; |
554 | 0 | } |
555 | 212k | } |
556 | | |
557 | 106k | ixheaace_mps_212_frame_window_get_window( |
558 | 106k | pstr_space_enc->h_frame_window, pstr_space_enc->tr_prev_pos, num_frame_time_slots, |
559 | 106k | &pstr_frame_data->framing_info, pstr_space_enc->ptr_frame_window_ana, |
560 | 106k | &pstr_space_enc->frame_win_list, pstr_space_enc->avoid_keep); |
561 | | |
562 | 212k | for (ps = 0, win_cnt = 0; ps < pstr_space_enc->frame_win_list.win_list_cnt; ++ps) { |
563 | 106k | if (pstr_space_enc->frame_win_list.dat[ps].hold == IXHEAACE_MPS_FRAME_WINDOWING_HOLD) { |
564 | 0 | ixheaace_mps_212_duplicate_parameter_set(&pstr_space_enc->save_frame, 0, pstr_frame_data, |
565 | 0 | ps); |
566 | 106k | } else { |
567 | 106k | WORD32 num_analysis_length_time_slots, analysis_start_time_slot; |
568 | 106k | FLOAT32 *ptr_frame_window_ana; |
569 | 106k | num_analysis_length_time_slots = ixheaace_mps_212_get_analysis_length_time_slots( |
570 | 106k | pstr_space_enc->ptr_frame_window_ana[win_cnt], |
571 | 106k | pstr_space_enc->num_analysis_length_time_slots); |
572 | | |
573 | 106k | analysis_start_time_slot = ixheaace_mps_212_get_analysis_start_time_slot( |
574 | 106k | pstr_space_enc->ptr_frame_window_ana[win_cnt], |
575 | 106k | pstr_space_enc->num_analysis_length_time_slots); |
576 | | |
577 | 106k | ptr_frame_window_ana = pstr_space_enc->ptr_frame_window_ana[win_cnt]; |
578 | | |
579 | 106k | error = ixheaace_mps_212_space_tree_apply( |
580 | 106k | pstr_space_enc->pstr_space_tree, ps, num_ch_in, num_analysis_length_time_slots, |
581 | 106k | analysis_start_time_slot, pstr_space_enc->num_hybrid_bands, ptr_frame_window_ana, |
582 | 106k | pstr_space_enc->cmplx_hybrid_in, pstr_space_enc->cmplx_hybrid_in, pstr_frame_data, |
583 | 106k | pstr_space_enc->avoid_keep); |
584 | 106k | if (error) { |
585 | 0 | return error; |
586 | 0 | } |
587 | | |
588 | 106k | ixheaace_mps_212_duplicate_parameter_set(pstr_frame_data, ps, &pstr_space_enc->save_frame, |
589 | 106k | 0); |
590 | 106k | ++win_cnt; |
591 | 106k | } |
592 | 106k | if (pstr_space_enc->avoid_keep > 0) { |
593 | 54.7k | pstr_space_enc->avoid_keep--; |
594 | 54.7k | } |
595 | 106k | } |
596 | | |
597 | 106k | memset(&pstr_frame_data->smg_data, 0, sizeof(pstr_frame_data->smg_data)); |
598 | | |
599 | 106k | ptr_bitstream_delay_buffer = |
600 | 106k | (UWORD8 *)ptr_out_buf_desc->pp_base[IXHEAACE_MPS_BITSTREAM_BUFFER_IDX]; |
601 | 106k | pstr_frame_data->bs_independency_flag = pstr_space_enc->independency_flag; |
602 | | |
603 | 106k | error = ixheaace_mps_212_write_spatial_frame( |
604 | 106k | ptr_bitstream_delay_buffer, MAX_MPEGS_BYTES, |
605 | 106k | &pstr_space_enc->pn_output_bits[pstr_space_enc->n_bitstream_buffer_write], |
606 | 106k | pstr_space_enc->pstr_bitstream_formatter, aot); |
607 | 106k | if (error) { |
608 | 0 | return error; |
609 | 0 | } |
610 | | |
611 | 106k | if ((pstr_space_enc->num_discard_out_frames == 0) && |
612 | 106k | (IXHEAACE_MPS_BITSTREAM_BUFFER_IDX != -1)) { |
613 | 106k | const WORD32 idx = IXHEAACE_MPS_BITSTREAM_BUFFER_IDX; |
614 | 106k | const WORD32 out_bits = |
615 | 106k | pstr_space_enc->pn_output_bits[pstr_space_enc->n_bitstream_buffer_read]; |
616 | | |
617 | 106k | if (((out_bits + 7) / 8) > |
618 | 106k | (WORD32)(ptr_out_buf_desc->p_buf_size[idx] / ptr_out_buf_desc->p_ele_size[idx])) { |
619 | 0 | pstr_out_args->num_output_bits = 0; |
620 | 0 | return IA_EXHEAACE_EXE_NONFATAL_MPS_ENCODE_ERROR; |
621 | 0 | } |
622 | 106k | pstr_out_args->num_output_bits = out_bits; |
623 | 106k | } else { |
624 | 0 | pstr_out_args->num_output_bits = 0; |
625 | 0 | } |
626 | | |
627 | 106k | pstr_space_enc->n_bitstream_buffer_read = |
628 | 106k | (pstr_space_enc->n_bitstream_buffer_read + 1) % pstr_space_enc->n_bitstream_delay_buffer; |
629 | 106k | pstr_space_enc->n_bitstream_buffer_write = |
630 | 106k | (pstr_space_enc->n_bitstream_buffer_write + 1) % pstr_space_enc->n_bitstream_delay_buffer; |
631 | | |
632 | 106k | num_output_samples = |
633 | 106k | (pstr_space_enc->num_discard_out_frames == 0) ? (num_output_samples_max) : 0; |
634 | 106k | if (num_output_samples > num_output_samples_buffer_size) { |
635 | 0 | return IA_EXHEAACE_CONFIG_NONFATAL_MPS_INVALID_CONFIG; |
636 | 0 | } |
637 | 106k | pstr_out_args->num_output_samples = num_output_samples; |
638 | | |
639 | 106k | if (pstr_space_enc->num_discard_out_frames > 0) { |
640 | 0 | pstr_space_enc->num_discard_out_frames--; |
641 | 0 | } |
642 | 106k | pstr_space_enc->n_samples_valid = 0; |
643 | | |
644 | 106k | return error; |
645 | 106k | } |
646 | | |
647 | | static IA_ERRORCODE ixheaace_mps_212_init(ixheaace_mps_pstr_space_structure pstr_space_enc, |
648 | 1.34k | const WORD32 dmx_delay, WORD32 aot) { |
649 | 1.34k | IA_ERRORCODE error = IA_NO_ERROR; |
650 | 1.34k | WORD32 ch; |
651 | 1.34k | WORD32 num_ch_in_arb_dmx; |
652 | 1.34k | ixheaace_mps_space_tree_description space_tree_description; |
653 | 1.34k | ixheaace_mps_onset_detect_config onset_detect_config; |
654 | 1.34k | ixheaace_mps_frame_win_config frame_window_config; |
655 | | |
656 | 1.34k | error = ixheaace_mps_212_configure(pstr_space_enc, &pstr_space_enc->user); |
657 | 1.34k | if (error) { |
658 | 0 | return error; |
659 | 0 | } |
660 | 1.34k | pstr_space_enc->b_enc_mode_212_only = pstr_space_enc->setup->b_enc_mode_212; |
661 | | |
662 | 1.34k | if (pstr_space_enc->num_frame_time_slots < 1) { |
663 | 0 | return IA_EXHEAACE_CONFIG_NONFATAL_MPS_INVALID_CONFIG; |
664 | 0 | } |
665 | 1.34k | pstr_space_enc->n_frame_length = |
666 | 1.34k | pstr_space_enc->num_qmf_bands * pstr_space_enc->num_frame_time_slots; |
667 | | |
668 | 1.34k | if (pstr_space_enc->use_frame_keep == 1) { |
669 | 1.34k | pstr_space_enc->num_analysis_length_time_slots = 3 * pstr_space_enc->num_frame_time_slots; |
670 | 1.34k | pstr_space_enc->n_update_hybrid_position_time_slots = pstr_space_enc->num_frame_time_slots; |
671 | 1.34k | } else { |
672 | 0 | pstr_space_enc->num_analysis_length_time_slots = 2 * pstr_space_enc->num_frame_time_slots; |
673 | 0 | pstr_space_enc->n_update_hybrid_position_time_slots = 0; |
674 | 0 | } |
675 | | |
676 | 1.34k | pstr_space_enc->n_analysis_lookahead_time_slots = |
677 | 1.34k | pstr_space_enc->num_analysis_length_time_slots - |
678 | 1.34k | 3 * pstr_space_enc->num_frame_time_slots / 2; |
679 | | |
680 | 1.34k | ixheaace_mps_212_calc_parameter_band_to_hybrid_band_offset( |
681 | 1.34k | pstr_space_enc->num_hybrid_bands, pstr_space_enc->ptr_parameter_band_2_hybrid_band_offset, |
682 | 1.34k | aot); |
683 | | |
684 | 1.34k | error = |
685 | 1.34k | ixheaace_mps_212_fill_space_tree_setup(pstr_space_enc, &pstr_space_enc->space_tree_setup); |
686 | 1.34k | if (error) { |
687 | 0 | return error; |
688 | 0 | } |
689 | 1.34k | error = ixheaace_mps_212_space_tree_init( |
690 | 1.34k | pstr_space_enc->pstr_space_tree, &pstr_space_enc->space_tree_setup, |
691 | 1.34k | pstr_space_enc->ptr_parameter_band_2_hybrid_band_offset, pstr_space_enc->use_frame_keep, |
692 | 1.34k | aot); |
693 | 1.34k | if (error) { |
694 | 0 | return error; |
695 | 0 | } |
696 | | |
697 | 1.34k | space_tree_description = pstr_space_enc->pstr_space_tree->descr; |
698 | 1.34k | pstr_space_enc->n_input_channels = space_tree_description.num_out_channels; |
699 | 1.34k | pstr_space_enc->n_output_channels = space_tree_description.num_in_channels; |
700 | 1.34k | frame_window_config.num_time_slots_max = pstr_space_enc->num_frame_time_slots; |
701 | 1.34k | frame_window_config.frame_keep_flag = pstr_space_enc->use_frame_keep; |
702 | 1.34k | onset_detect_config.max_time_slots = pstr_space_enc->num_frame_time_slots; |
703 | 1.34k | onset_detect_config.lower_bound_onset_detection = |
704 | 1.34k | ((2 * 1725 * pstr_space_enc->num_qmf_bands) / pstr_space_enc->num_sample_rate); |
705 | 1.34k | onset_detect_config.upper_bound_onset_detection = pstr_space_enc->num_hybrid_bands; |
706 | 1.34k | num_ch_in_arb_dmx = 0; |
707 | | |
708 | 4.03k | for (ch = 0; ch < pstr_space_enc->n_input_channels; ch++) { |
709 | 2.69k | ixheaace_mps_212_qmf_init_filter_bank( |
710 | 2.69k | pstr_space_enc->pstr_qmf_filter_in[ch], |
711 | 2.69k | pstr_space_enc->pstr_qmf_filter_in[ch]->ptr_filter_states, 1, |
712 | 2.69k | pstr_space_enc->num_qmf_bands, pstr_space_enc->num_qmf_bands, |
713 | 2.69k | pstr_space_enc->num_qmf_bands); |
714 | 2.69k | if (error) { |
715 | 0 | return error; |
716 | 0 | } |
717 | 2.69k | ixheaace_mps_212_init_dc_filter(pstr_space_enc->pstr_dc_filter[ch], |
718 | 2.69k | pstr_space_enc->num_sample_rate); |
719 | 2.69k | error = ixheaace_mps_212_onset_detect_init(pstr_space_enc->pstr_onset_detect[ch], |
720 | 2.69k | &onset_detect_config, 1); |
721 | 2.69k | if (error) { |
722 | 0 | return error; |
723 | 0 | } |
724 | 2.69k | } |
725 | | |
726 | 1.34k | error = |
727 | 1.34k | ixheaace_mps_212_frame_window_init(pstr_space_enc->h_frame_window, &frame_window_config); |
728 | 1.34k | if (error) { |
729 | 0 | return error; |
730 | 0 | } |
731 | | |
732 | 1.34k | error = ixheaace_mps_212_static_gain_init(pstr_space_enc->pstr_static_gain, |
733 | 1.34k | pstr_space_enc->pstr_static_gain_config); |
734 | 1.34k | if (error) { |
735 | 0 | return error; |
736 | 0 | } |
737 | | |
738 | 1.34k | error = ixheaace_mps_212_init_enhanced_time_domain_dmx( |
739 | 1.34k | pstr_space_enc->pstr_enhanced_time_dmx, pstr_space_enc->pstr_static_gain->pre_gain, |
740 | 1.34k | pstr_space_enc->pstr_static_gain->post_gain, pstr_space_enc->n_frame_length); |
741 | 1.34k | if (error) { |
742 | 0 | return error; |
743 | 0 | } |
744 | | |
745 | 1.34k | memset(pstr_space_enc->pstr_bitstream_formatter, 0, sizeof(ixheaace_mps_spatial_frame)); |
746 | 1.34k | pstr_space_enc->pstr_bitstream_formatter->frame.bs_independency_flag = 1; |
747 | 1.34k | pstr_space_enc->pstr_bitstream_formatter->frame.framing_info.num_param_sets = 1; |
748 | | |
749 | 1.34k | error = ixheaace_mps_212_fill_spatial_specific_config( |
750 | 1.34k | pstr_space_enc, &pstr_space_enc->pstr_bitstream_formatter->spatial_specific_config); |
751 | 1.34k | if (error) { |
752 | 0 | return error; |
753 | 0 | } |
754 | | |
755 | 1.34k | error = ixheaace_mps_212_write_spatial_specific_config( |
756 | 1.34k | &pstr_space_enc->pstr_bitstream_formatter->spatial_specific_config, |
757 | 1.34k | pstr_space_enc->ssc_buf.ptr_ssc, MAX_SSC_BYTES, &pstr_space_enc->ssc_buf.num_ssc_size_bits, |
758 | 1.34k | aot); |
759 | 1.34k | if (error) { |
760 | 0 | return error; |
761 | 0 | } |
762 | | |
763 | 1.34k | error = ixheaace_mps_212_init_delay_compensation(pstr_space_enc, dmx_delay, aot); |
764 | 1.34k | if (error) { |
765 | 0 | return error; |
766 | 0 | } |
767 | | |
768 | 1.34k | pstr_space_enc->n_samples_next = |
769 | 1.34k | pstr_space_enc->n_frame_length * (pstr_space_enc->n_input_channels + num_ch_in_arb_dmx); |
770 | 1.34k | pstr_space_enc->n_samples_valid = 0; |
771 | | |
772 | 1.34k | return error; |
773 | 1.34k | } |
774 | | |
775 | | static VOID ixheaace_mps_open(ixheaace_mps_pstr_space_structure *pstr_space_enc_structure, |
776 | 1.35k | ixheaace_mps_212_memory_struct *pstr_mps_memory) { |
777 | 1.35k | WORD32 ch; |
778 | 1.35k | WORD32 param; |
779 | 1.35k | ixheaace_mps_pstr_space_structure pstr_space_enc = NULL; |
780 | 1.35k | pstr_space_enc = &pstr_mps_memory->mp4_space_encoder_instance; |
781 | 1.35k | if (NULL != pstr_space_enc) { |
782 | 1.35k | memset(pstr_space_enc, 0, sizeof(struct ixheaace_mps_space_structure)); |
783 | 1.35k | } |
784 | 1.35k | pstr_space_enc->setup = &pstr_mps_memory->setup; |
785 | 1.35k | pstr_space_enc->setup->max_sampling_rate = MAX_SAMPLING_RATE; |
786 | 1.35k | pstr_space_enc->setup->max_frame_time_slots = MAX_FRAME_TIME_SLOT; |
787 | 1.35k | pstr_space_enc->setup->max_analysis_length_time_slots = |
788 | 1.35k | 3 * pstr_space_enc->setup->max_frame_time_slots; |
789 | 1.35k | pstr_space_enc->setup->max_qmf_bands = |
790 | 1.35k | ixheaace_mps_212_space_get_num_qmf_bands(pstr_space_enc->setup->max_sampling_rate); |
791 | 1.35k | pstr_space_enc->setup->max_hybrid_bands = pstr_space_enc->setup->max_qmf_bands; |
792 | 1.35k | pstr_space_enc->setup->max_frame_length = |
793 | 1.35k | pstr_space_enc->setup->max_qmf_bands * pstr_space_enc->setup->max_frame_time_slots; |
794 | 1.35k | pstr_space_enc->setup->max_ch_in = 2; |
795 | 1.35k | pstr_space_enc->setup->max_ch_out = 1; |
796 | 1.35k | pstr_space_enc->setup->max_ch_tot_out = pstr_space_enc->setup->max_ch_out; |
797 | 1.35k | pstr_space_enc->setup->b_enc_mode_212 = 1; |
798 | 1.35k | pstr_space_enc->setup->max_hybrid_in_static_slots = 24; |
799 | | |
800 | 1.35k | pstr_space_enc->pstr_static_gain_config = &pstr_mps_memory->static_gain_config; |
801 | 1.35k | pstr_space_enc->pstr_enhanced_time_dmx = &pstr_mps_memory->enhanced_time_dmx; |
802 | 1.35k | pstr_space_enc->pstr_enhanced_time_dmx->sinus_window = pstr_mps_memory->sinus_window_flt; |
803 | 1.35k | pstr_space_enc->ptr_parameter_band_2_hybrid_band_offset = |
804 | 1.35k | pstr_mps_memory->parameter_band_2_hybrid_band_offset; |
805 | 1.35k | ixheaace_mps_212_space_tree_open(&pstr_space_enc->pstr_space_tree, pstr_mps_memory); |
806 | 1.35k | pstr_space_enc->pstr_qmf_filter_in = pstr_mps_memory->pstr_qmf_filter_bank; |
807 | 4.05k | for (ch = 0; ch < pstr_space_enc->setup->max_ch_in; ch++) { |
808 | 2.70k | pstr_space_enc->pstr_qmf_filter_in[ch] = &pstr_mps_memory->qmf_filter_bank[ch]; |
809 | 2.70k | pstr_space_enc->pstr_qmf_filter_in[ch]->ptr_filter_states = |
810 | 2.70k | &pstr_mps_memory->ptr_filter_states[ch]; |
811 | 2.70k | pstr_space_enc->pstr_dc_filter[ch] = &pstr_mps_memory->dc_filter[ch]; |
812 | 2.70k | pstr_space_enc->pstr_onset_detect[ch] = &pstr_mps_memory->onset_detect[ch]; |
813 | 2.70k | pstr_space_enc->pstr_onset_detect[ch]->p_energy_hist = |
814 | 2.70k | &pstr_mps_memory->energy_hist_float[ch][0]; |
815 | 2.70k | } |
816 | 1.35k | pstr_space_enc->h_frame_window = &pstr_mps_memory->frame_window; |
817 | 1.35k | pstr_space_enc->pstr_static_gain = &pstr_mps_memory->static_gain; |
818 | 1.35k | pstr_space_enc->pstr_bitstream_formatter = &pstr_mps_memory->bitstream; |
819 | 1.35k | pstr_space_enc->ssc_buf.ptr_ssc = pstr_mps_memory->ssc; |
820 | 1.35k | pstr_space_enc->pstr_delay = &pstr_mps_memory->delay; |
821 | 1.35k | pstr_space_enc->pn_output_bits = pstr_mps_memory->n_output_bits; |
822 | 10.8k | for (param = 0; param < MAX_NUM_PARAMS; param++) { |
823 | 9.45k | pstr_space_enc->ptr_frame_window_ana[param] = |
824 | 9.45k | &pstr_mps_memory->frame_window_ana_flt[param][0]; |
825 | 9.45k | } |
826 | 1.35k | pstr_space_enc->pstr_enhanced_time_dmx->max_frame_length = |
827 | 1.35k | pstr_space_enc->setup->max_frame_length; |
828 | 4.05k | for (ch = 0; ch < pstr_space_enc->setup->max_ch_in; ch++) { |
829 | 2.70k | pstr_space_enc->pstr_onset_detect[ch]->max_time_slots = |
830 | 2.70k | pstr_space_enc->setup->max_frame_time_slots; |
831 | 2.70k | pstr_space_enc->pstr_onset_detect[ch]->min_trans_dist = 8; |
832 | 2.70k | pstr_space_enc->pstr_onset_detect[ch]->avg_energy_dist = 16; |
833 | 2.70k | pstr_space_enc->pstr_onset_detect[ch]->avg_energy_dist_scale = 4; |
834 | 2.70k | } |
835 | 1.35k | pstr_space_enc->pstr_static_gain_config->fixed_gain_dmx = IXHEAACE_MPS_DMX_GAIN_DEFAULT; |
836 | 1.35k | pstr_space_enc->pstr_static_gain_config->pre_gain_factor_db = 0; |
837 | | |
838 | 1.35k | if (NULL != pstr_space_enc_structure) { |
839 | 1.35k | *pstr_space_enc_structure = pstr_space_enc; |
840 | 1.35k | } |
841 | 1.35k | } |
842 | | |
843 | | static WORD32 ixheaace_mps_212_get_closest_bit_rate(const WORD32 audio_object_type, |
844 | | const UWORD32 sampling_rate, |
845 | 1.34k | const UWORD32 sbr_ratio, UWORD32 bitrate) { |
846 | 1.34k | UWORD32 idx; |
847 | 1.34k | WORD32 target_bitrate = -1; |
848 | | |
849 | 29.5k | for (idx = 0; idx < sizeof(mps_config_tab) / sizeof(ixheaace_mps_config_table); idx++) { |
850 | 28.2k | if ((mps_config_tab[idx].sampling_rate == sampling_rate) && |
851 | 28.2k | (mps_config_tab[idx].audio_object_type == audio_object_type) && |
852 | 28.2k | (mps_config_tab[idx].sbr_ratio == sbr_ratio)) { |
853 | 1.34k | target_bitrate = |
854 | 1.34k | MIN(MAX(bitrate, mps_config_tab[idx].bitrate_min), mps_config_tab[idx].bitrate_max); |
855 | 1.34k | } |
856 | 28.2k | } |
857 | | |
858 | 1.34k | return target_bitrate; |
859 | 1.34k | } |
860 | | |
861 | | static WORD32 ixheaace_mps_212_write_spatial_specific_config_data( |
862 | 1.34k | ixheaace_mps_pstr_struct pstr_mps_enc, ixheaace_bit_buf_handle pstr_bit_buf) { |
863 | 1.34k | WORD32 idx; |
864 | 1.34k | WORD32 ssc_bits = 0; |
865 | 1.34k | WORD32 written_bits = 0; |
866 | 1.34k | ixheaace_mps_space_info pstr_space_encoder_info; |
867 | 1.34k | ixheaace_mps_212_get_info(pstr_mps_enc->ptr_sac_encoder, &pstr_space_encoder_info); |
868 | | |
869 | 4.64k | for (idx = 0; idx<pstr_space_encoder_info.p_ssc_buf->num_ssc_size_bits>> 3; idx++) { |
870 | 3.30k | ixheaace_write_bits(pstr_bit_buf, pstr_space_encoder_info.p_ssc_buf->ptr_ssc[idx], 8); |
871 | 3.30k | written_bits += 8; |
872 | 3.30k | } |
873 | 1.34k | ixheaace_write_bits( |
874 | 1.34k | pstr_bit_buf, pstr_space_encoder_info.p_ssc_buf->ptr_ssc[idx], |
875 | 1.34k | (UWORD8)(pstr_space_encoder_info.p_ssc_buf->num_ssc_size_bits - written_bits)); |
876 | | |
877 | 1.34k | ssc_bits = pstr_space_encoder_info.p_ssc_buf->num_ssc_size_bits; |
878 | 1.34k | return ssc_bits; |
879 | 1.34k | } |
880 | | |
881 | | VOID ixheaace_mps_212_open(VOID **pstr_handle_mps, |
882 | 1.35k | ixheaace_mps_212_memory_struct *pstr_mps_memory) { |
883 | 1.35k | ixheaace_mps_pstr_struct pstr_mps_enc = NULL; |
884 | 1.35k | pstr_mps_enc = &pstr_mps_memory->mps_encoder_instance; |
885 | 1.35k | memset(pstr_mps_enc, 0, sizeof(ixheaace_mps_struct)); |
886 | 1.35k | ixheaace_mps_open(&pstr_mps_enc->ptr_sac_encoder, pstr_mps_memory); |
887 | 1.35k | *pstr_handle_mps = pstr_mps_enc; |
888 | 1.35k | } |
889 | | |
890 | 0 | VOID ixheaace_mps_212_close(VOID **pstr_handle_mps) { |
891 | 0 | ixheaace_mps_pstr_struct *pstr_mps_enc = (ixheaace_mps_pstr_struct *)pstr_handle_mps; |
892 | 0 | if (*pstr_mps_enc != NULL) { |
893 | 0 | *pstr_mps_enc = NULL; |
894 | 0 | } |
895 | 0 | } |
896 | | |
897 | | IA_ERRORCODE ixheaace_mps_212_initialise(VOID *pstr_handle_mps, const WORD32 audio_object_type, |
898 | | const UWORD32 sampling_rate, WORD32 *ptr_bitrate, |
899 | | const UWORD32 sbr_ratio, const UWORD32 frame_length, |
900 | | const UWORD32 input_buffer_size_per_channel, |
901 | 1.35k | const UWORD32 core_coder_delay, WORD8 *ptr_scratch) { |
902 | 1.35k | IA_ERRORCODE error = IA_NO_ERROR; |
903 | 1.35k | const UWORD32 fs_low = 27713; |
904 | 1.35k | const UWORD32 fs_high = 55426; |
905 | 1.35k | const UWORD32 no_inter_frame_coding = 0; |
906 | 1.35k | UWORD32 num_time_slots = 0, num_qmf_bands_ld = 0; |
907 | 1.35k | ixheaace_mps_pstr_struct pstr_mps_enc = (ixheaace_mps_pstr_struct)pstr_handle_mps; |
908 | 1.35k | switch (sbr_ratio) { |
909 | 0 | case 1: |
910 | 0 | if (!(sampling_rate < fs_low)) { |
911 | 0 | return IA_EXHEAACE_INIT_FATAL_MPS_INIT_FAILED; |
912 | 0 | } |
913 | 0 | break; |
914 | 1.21k | case 2: |
915 | 1.35k | case 4: |
916 | 1.35k | if (!((sampling_rate >= fs_low) && (sampling_rate < fs_high))) { |
917 | 5 | return IA_EXHEAACE_INIT_FATAL_MPS_INIT_FAILED; |
918 | 5 | } |
919 | 1.34k | break; |
920 | 1.34k | case 0: |
921 | 0 | default:; |
922 | 1.35k | } |
923 | | |
924 | 1.34k | num_qmf_bands_ld = (sampling_rate < fs_low) ? 5 : ((sampling_rate > fs_high) ? 7 : 6); |
925 | 1.34k | num_time_slots = frame_length >> num_qmf_bands_ld; |
926 | 1.34k | *ptr_bitrate = ixheaace_mps_212_get_closest_bit_rate(audio_object_type, sampling_rate, |
927 | 1.34k | sbr_ratio, *ptr_bitrate); |
928 | | |
929 | 1.34k | pstr_mps_enc->ptr_sac_encoder->user.b_ld_mode = ((no_inter_frame_coding == 1) ? 1 : 2); |
930 | 1.34k | pstr_mps_enc->ptr_sac_encoder->user.sample_rate = sampling_rate; |
931 | 1.34k | pstr_mps_enc->ptr_sac_encoder->user.frame_time_slots = num_time_slots; |
932 | 1.34k | if (audio_object_type == AOT_AAC_ELD) { |
933 | 306 | pstr_mps_enc->ptr_sac_encoder->user.num_param_bands = IXHEAACE_MPS_SAC_BANDS_ld; |
934 | 306 | pstr_mps_enc->ptr_sac_encoder->user.independency_factor = 20; |
935 | 1.03k | } else { |
936 | 1.03k | pstr_mps_enc->ptr_sac_encoder->user.num_param_bands = IXHEAACE_MPS_SAC_BANDS_usac; |
937 | 1.03k | pstr_mps_enc->ptr_sac_encoder->user.independency_factor = 25; |
938 | 1.03k | } |
939 | | |
940 | 1.34k | pstr_mps_enc->ptr_sac_encoder->user.b_use_coarse_quant = 0; |
941 | 1.34k | pstr_mps_enc->ptr_sac_encoder->user.quant_mode = IXHEAACE_MPS_QUANTMODE_FINE; |
942 | 1.34k | pstr_mps_enc->ptr_sac_encoder->user.time_alignment = 0; |
943 | 1.34k | pstr_mps_enc->audio_object_type = audio_object_type; |
944 | 1.34k | error = |
945 | 1.34k | ixheaace_mps_212_init(pstr_mps_enc->ptr_sac_encoder, core_coder_delay, audio_object_type); |
946 | 1.34k | if (error) { |
947 | 0 | return IA_EXHEAACE_INIT_FATAL_MPS_INIT_FAILED; |
948 | 0 | } |
949 | | |
950 | 1.34k | pstr_mps_enc->in_buf_desc.pp_base = (VOID **)&pstr_mps_enc->p_in_buffer; |
951 | 1.34k | pstr_mps_enc->in_buf_desc.p_buf_size = pstr_mps_enc->p_in_buffer_size; |
952 | 1.34k | pstr_mps_enc->in_buf_desc.p_ele_size = pstr_mps_enc->p_in_buffer_el_size; |
953 | 1.34k | pstr_mps_enc->in_buf_desc.p_buf_type = pstr_mps_enc->p_in_buffer_type; |
954 | 1.34k | pstr_mps_enc->in_buf_desc.num_bufs = 1; |
955 | | |
956 | 1.34k | pstr_mps_enc->out_buf_desc.pp_base = (VOID **)&pstr_mps_enc->p_out_buffer; |
957 | 1.34k | pstr_mps_enc->out_buf_desc.p_buf_size = pstr_mps_enc->p_out_buffer_size; |
958 | 1.34k | pstr_mps_enc->out_buf_desc.p_ele_size = pstr_mps_enc->p_out_buffer_el_size; |
959 | 1.34k | pstr_mps_enc->out_buf_desc.p_buf_type = pstr_mps_enc->p_out_buffer_type; |
960 | 1.34k | pstr_mps_enc->out_buf_desc.num_bufs = 2; |
961 | | |
962 | 1.34k | pstr_mps_enc->p_in_buffer[0] = NULL; |
963 | 1.34k | pstr_mps_enc->p_in_buffer_size[0] = 0; |
964 | 1.34k | pstr_mps_enc->p_in_buffer_el_size[0] = sizeof(FLOAT32); |
965 | 1.34k | pstr_mps_enc->p_in_buffer_type[0] = IXHEAACE_MPS_INPUT_BUFFER_IDX; |
966 | | |
967 | 1.34k | pstr_mps_enc->p_out_buffer[0] = NULL; |
968 | 1.34k | pstr_mps_enc->p_out_buffer_size[0] = 0; |
969 | 1.34k | pstr_mps_enc->p_out_buffer_el_size[0] = sizeof(FLOAT32); |
970 | 1.34k | pstr_mps_enc->p_out_buffer_type[0] = IXHEAACE_MPS_OUTUT_BUFFER_IDX; |
971 | | |
972 | 1.34k | pstr_mps_enc->p_out_buffer[1] = NULL; |
973 | 1.34k | pstr_mps_enc->p_out_buffer_size[1] = 0; |
974 | 1.34k | pstr_mps_enc->p_out_buffer_el_size[1] = sizeof(UWORD8); |
975 | 1.34k | pstr_mps_enc->p_out_buffer_type[1] = IXHEAACE_MPS_BITSTREAM_BUFFER_IDX; |
976 | | |
977 | 1.34k | pstr_mps_enc->in_args.is_input_inter_leaved = 0; |
978 | 1.34k | pstr_mps_enc->in_args.input_buffer_size_per_channel = input_buffer_size_per_channel; |
979 | | |
980 | 1.34k | pstr_mps_enc->ptr_scratch = ptr_scratch; |
981 | | |
982 | 1.34k | return error; |
983 | 1.34k | } |
984 | | |
985 | | IA_ERRORCODE ixheaace_mps_212_process(VOID *pstr_handle_mps, FLOAT32 *const ptr_audio_samples, |
986 | | const WORD32 num_audio_samples, |
987 | 106k | ixheaace_mps_enc_ext_payload *pstr_mps_ext_payload) { |
988 | 106k | IA_ERRORCODE error = IA_NO_ERROR; |
989 | 106k | ixheaace_mps_pstr_struct pstr_mps_enc = (ixheaace_mps_pstr_struct)pstr_handle_mps; |
990 | 106k | WORD32 aot = pstr_mps_enc->audio_object_type; |
991 | 106k | WORD32 sac_header_flag = 0; |
992 | 106k | WORD32 sac_out_buffer_offset = 0; |
993 | | |
994 | 106k | if (aot == AOT_AAC_ELD) { |
995 | 41.7k | pstr_mps_enc->sac_out_buffer[0] = (sac_header_flag == 0) ? 0x3 : 0x7; |
996 | 41.7k | sac_out_buffer_offset += 1; |
997 | 41.7k | } |
998 | | |
999 | 106k | pstr_mps_enc->p_in_buffer[0] = (VOID *)ptr_audio_samples; |
1000 | 106k | pstr_mps_enc->in_args.num_input_samples = num_audio_samples; |
1001 | | |
1002 | 106k | pstr_mps_enc->p_out_buffer[0] = (VOID *)ptr_audio_samples; |
1003 | 106k | pstr_mps_enc->p_out_buffer_size[0] = sizeof(FLOAT32) * ((WORD32)num_audio_samples) / 2; |
1004 | | |
1005 | 106k | pstr_mps_enc->p_out_buffer[1] = (VOID *)&pstr_mps_enc->sac_out_buffer[sac_out_buffer_offset]; |
1006 | 106k | pstr_mps_enc->p_out_buffer_size[1] = |
1007 | 106k | sizeof(pstr_mps_enc->sac_out_buffer) - sac_out_buffer_offset; |
1008 | | |
1009 | 106k | error = ixheaace_mps_212_encode(pstr_mps_enc->ptr_sac_encoder, &pstr_mps_enc->in_buf_desc, |
1010 | 106k | &pstr_mps_enc->out_buf_desc, &pstr_mps_enc->in_args, |
1011 | 106k | &pstr_mps_enc->out_args, aot, pstr_mps_enc->ptr_scratch); |
1012 | 106k | if (error) { |
1013 | 0 | return error; |
1014 | 0 | } |
1015 | | |
1016 | 106k | pstr_mps_ext_payload->p_data = (UWORD8 *)pstr_mps_enc->sac_out_buffer; |
1017 | 106k | pstr_mps_ext_payload->data_size = pstr_mps_enc->out_args.num_output_bits; |
1018 | 106k | if (aot == AOT_AAC_ELD) { |
1019 | 41.7k | pstr_mps_ext_payload->data_size += 8 * (sac_out_buffer_offset - 1); |
1020 | 41.7k | } |
1021 | 106k | pstr_mps_ext_payload->data_type = IXHEAACE_MPS_EXT_LDSAC_DATA; |
1022 | 106k | pstr_mps_ext_payload->associated_ch_element = -1; |
1023 | | |
1024 | 106k | return error; |
1025 | 106k | } |
1026 | | |
1027 | | WORD32 ixheaace_mps_212_get_spatial_specific_config(VOID *pstr_handle_mps, WORD8 *ptr_out_buffer, |
1028 | 1.34k | WORD32 buf_size, WORD32 aot) { |
1029 | 1.34k | ixheaace_bit_buf bit_buf; |
1030 | 1.34k | ixheaace_bit_buf_handle pstr_bit_buf = |
1031 | 1.34k | ia_enhaacplus_enc_create_bitbuffer(&bit_buf, (UWORD8 *)ptr_out_buffer, buf_size); |
1032 | 1.34k | ixheaace_mps_212_write_spatial_specific_config_data(pstr_handle_mps, pstr_bit_buf); |
1033 | 1.34k | if (aot == AOT_AAC_ELD) { |
1034 | 306 | ixheaace_byte_align_buffer(pstr_bit_buf); |
1035 | 306 | } |
1036 | 1.34k | return ia_enhaacplus_enc_get_bits_available(pstr_bit_buf); |
1037 | 1.34k | } |
1038 | | |
1039 | 512 | WORD32 ixheaace_mps_515_scratch_size(VOID) { |
1040 | 512 | WORD32 size = 0; |
1041 | 512 | size += ((MAX_INPUT_CHANNELS * MAX_BUFFER_SIZE) * sizeof(FLOAT32)); |
1042 | 512 | size += ((MAX_OUTPUT_CHANNELS * MAX_BUFFER_SIZE) * sizeof(FLOAT32)); |
1043 | 512 | size += |
1044 | 512 | (((MAX_INPUT_CHANNELS * MAX_BUFFER_SIZE) + (2 * MAX_BUFFER_SIZE) + (2 * MAX_BUFFER_SIZE)) * |
1045 | 512 | sizeof(FLOAT32)); |
1046 | 512 | size += (((6 * MAX_TIME_SLOTS * NUM_QMF_BANDS) + (6 * MAX_TIME_SLOTS * NUM_QMF_BANDS) + |
1047 | 512 | (6 * MAX_TIME_SLOTS * NUM_QMF_BANDS) + (6 * MAX_TIME_SLOTS * NUM_QMF_BANDS) + |
1048 | 512 | (6 * MAX_TIME_SLOTS * MAX_HYBRID_BANDS) + (6 * MAX_TIME_SLOTS * MAX_HYBRID_BANDS)) * |
1049 | 512 | sizeof(FLOAT32)); |
1050 | 512 | size += (INPUT_LEN_DOWNSAMPLE * IXHEAACE_MAX_CH_IN_BS_ELE * UPSAMPLE_FAC * sizeof(FLOAT32)); |
1051 | 512 | size += (INPUT_LEN_DOWNSAMPLE * IXHEAACE_MAX_CH_IN_BS_ELE * UPSAMPLE_FAC * sizeof(FLOAT32)); |
1052 | 512 | size = IXHEAAC_GET_SIZE_ALIGNED(size, BYTE_ALIGN_8); |
1053 | 512 | return size; |
1054 | 512 | } |
1055 | | |
1056 | | IA_ERRORCODE ixheaace_mps_515_open(VOID **pstr_handle_mps, WORD32 sample_freq, WORD32 tree_config, |
1057 | | ixheaace_bit_buf_handle pstr_bitstream, |
1058 | | WORD32 *ptr_bits_written, |
1059 | | ixheaace_mps_515_memory_struct *pstr_mps_memory, |
1060 | 492 | WORD32 flag_480) { |
1061 | 492 | WORD32 i; |
1062 | 492 | IA_ERRORCODE error = IA_NO_ERROR; |
1063 | 492 | ixheaace_mps_sac_specific_config *pstr_mps_specific_config; |
1064 | 492 | ixheaace_mps_sac_pstr_enc pstr_mps_enc = &pstr_mps_memory->spatial_enc_instance; |
1065 | | |
1066 | 492 | ixheaace_mps_sac_pstr_qmf_ana_filter_bank pstr_qmf_ana_bank = &pstr_mps_enc->qmf_fltbank; |
1067 | 492 | ixheaace_mps_sac_pstr_qmf_synth_filter_bank pstr_qmf_synth_bank = |
1068 | 492 | &pstr_mps_enc->qmf_synth_fltbank; |
1069 | | |
1070 | 492 | memset(pstr_mps_enc, 0, sizeof(ixheaace_mps_sac_enc)); |
1071 | 492 | pstr_mps_enc->tree_config = tree_config; |
1072 | 492 | switch (tree_config) { |
1073 | 157 | case 5151: |
1074 | 222 | case 5152: |
1075 | 222 | pstr_mps_enc->output_channels = 1; |
1076 | 222 | break; |
1077 | 270 | case 525: |
1078 | 270 | pstr_mps_enc->output_channels = 2; |
1079 | 492 | } |
1080 | 492 | if (flag_480) { |
1081 | 175 | pstr_mps_enc->time_slots = 15; |
1082 | 317 | } else { |
1083 | 317 | pstr_mps_enc->time_slots = 16; |
1084 | 317 | } |
1085 | | |
1086 | 492 | pstr_mps_enc->frame_size = NUM_QMF_BANDS * pstr_mps_enc->time_slots; |
1087 | | |
1088 | 492 | pstr_qmf_ana_bank->p_filter = ia_mps_enc_qmf_64_640; |
1089 | | |
1090 | 492 | pstr_qmf_synth_bank->p_filter = ia_mps_enc_qmf_64_640; |
1091 | 492 | pstr_qmf_synth_bank->alt_sin_twiddle = sbr_alt_sin_twiddle; |
1092 | 492 | pstr_qmf_synth_bank->cos_twiddle = sbr_cos_twiddle; |
1093 | 492 | pstr_qmf_synth_bank->sin_twiddle = sbr_sin_twiddle; |
1094 | | |
1095 | 3.44k | for (i = 0; i < 6; i++) { |
1096 | 2.95k | memset(&pstr_mps_enc->filterbank[i], 0, sizeof(ixheaace_mps_sac_sbr_encoder_ana_filter_bank)); |
1097 | | |
1098 | 2.95k | memset(&pstr_mps_enc->hyb_state[i], 0, sizeof(ixheaace_mps_hyb_filter_state)); |
1099 | 2.95k | } |
1100 | | |
1101 | 492 | pstr_mps_enc->bitstream_formatter = &pstr_mps_memory->bsf_memory_instance; |
1102 | 492 | pstr_mps_specific_config = &pstr_mps_enc->bitstream_formatter->spatial_specific_config; |
1103 | | |
1104 | 492 | memset(pstr_mps_specific_config, 0, sizeof(ixheaace_mps_sac_specific_config)); |
1105 | | |
1106 | 492 | pstr_mps_enc->bitstream_formatter->current_frame.bs_independency_flag_count = 0; |
1107 | 492 | pstr_mps_specific_config->bs_sampling_frequency = sample_freq; |
1108 | | |
1109 | 492 | switch (tree_config) { |
1110 | 157 | case 5151: |
1111 | 157 | pstr_mps_specific_config->bs_tree_config = IXHEAACE_MPS_TREE_5151; |
1112 | 157 | pstr_mps_specific_config->ott_config[4].bs_ott_bands = 2; |
1113 | 157 | break; |
1114 | | |
1115 | 65 | case 5152: |
1116 | 65 | pstr_mps_specific_config->bs_tree_config = IXHEAACE_MPS_TREE_5152; |
1117 | 65 | pstr_mps_specific_config->ott_config[2].bs_ott_bands = 2; |
1118 | 65 | break; |
1119 | | |
1120 | 270 | case 525: |
1121 | 270 | pstr_mps_specific_config->bs_tree_config = IXHEAACE_MPS_TREE_525; |
1122 | 270 | pstr_mps_specific_config->ott_config[0].bs_ott_bands = 2; |
1123 | 270 | pstr_mps_specific_config->ttt_config->bs_ttt_bands_low = PARAMETER_BANDS; |
1124 | 270 | pstr_mps_specific_config->ttt_config->bs_ttt_mode_low = 5; |
1125 | 492 | } |
1126 | | |
1127 | 492 | pstr_mps_specific_config->bs_frame_length = pstr_mps_enc->time_slots - 1; |
1128 | 492 | pstr_mps_specific_config->bs_freq_res = 2; |
1129 | | |
1130 | 492 | pstr_mps_specific_config->bs_fixed_gain_sur = 2; |
1131 | 492 | pstr_mps_specific_config->bs_fixed_gain_lfe = 1; |
1132 | 492 | pstr_mps_specific_config->bs_fixed_gain_dmx = 0; |
1133 | | |
1134 | 492 | error = ixheaace_mps_515_write_spatial_specific_config(pstr_bitstream, |
1135 | 492 | pstr_mps_enc->bitstream_formatter); |
1136 | | |
1137 | 492 | *ptr_bits_written = ia_enhaacplus_enc_get_bits_available(pstr_bitstream); |
1138 | 492 | *pstr_handle_mps = pstr_mps_enc; |
1139 | 492 | return error; |
1140 | 492 | } |
1141 | | |
1142 | | IA_ERRORCODE ixheaace_mps_515_apply(ixheaace_mps_sac_enc *pstr_mps_enc, FLOAT32 *ptr_audio_input, |
1143 | | FLOAT32 *ptr_audio_output, |
1144 | 23.2k | ixheaace_bit_buf_handle pstr_bitstream, VOID *ptr_scratch) { |
1145 | 23.2k | IA_ERRORCODE error = IA_NO_ERROR; |
1146 | 23.2k | FLOAT32 *pstr_scratch = (FLOAT32 *)ptr_scratch; |
1147 | | |
1148 | 23.2k | FLOAT32 *in = (FLOAT32 *)pstr_scratch; |
1149 | 23.2k | memset(in, 0, sizeof(*in) * MAX_INPUT_CHANNELS * MAX_BUFFER_SIZE); |
1150 | 23.2k | pstr_scratch += MAX_INPUT_CHANNELS * MAX_BUFFER_SIZE; |
1151 | | |
1152 | 23.2k | FLOAT32 *out = (FLOAT32 *)pstr_scratch; |
1153 | 23.2k | memset(out, 0, sizeof(*out) * 2 * MAX_BUFFER_SIZE); |
1154 | 23.2k | pstr_scratch += 2 * MAX_BUFFER_SIZE; |
1155 | | |
1156 | 23.2k | FLOAT32 *out1 = (FLOAT32 *)pstr_scratch; |
1157 | 23.2k | memset(out1, 0, sizeof(*out1) * 2 * MAX_BUFFER_SIZE); |
1158 | 23.2k | pstr_scratch += 2 * MAX_BUFFER_SIZE; |
1159 | | |
1160 | 23.2k | FLOAT32 *m_qmf_real = (FLOAT32 *)pstr_scratch; |
1161 | 23.2k | memset(m_qmf_real, 0, sizeof(*m_qmf_real) * 6 * MAX_TIME_SLOTS * NUM_QMF_BANDS); |
1162 | 23.2k | pstr_scratch += 6 * MAX_TIME_SLOTS * NUM_QMF_BANDS; |
1163 | | |
1164 | 23.2k | FLOAT32 *m_qmf_imag = (FLOAT32 *)pstr_scratch; |
1165 | 23.2k | memset(m_qmf_imag, 0, sizeof(*m_qmf_imag) * 6 * MAX_TIME_SLOTS * NUM_QMF_BANDS); |
1166 | 23.2k | pstr_scratch += 6 * MAX_TIME_SLOTS * NUM_QMF_BANDS; |
1167 | | |
1168 | 23.2k | FLOAT32 *m_hybrid_real = (FLOAT32 *)pstr_scratch; |
1169 | 23.2k | memset(m_hybrid_real, 0, sizeof(*m_hybrid_real) * 6 * MAX_TIME_SLOTS * MAX_HYBRID_BANDS); |
1170 | 23.2k | pstr_scratch += 6 * MAX_TIME_SLOTS * MAX_HYBRID_BANDS; |
1171 | | |
1172 | 23.2k | FLOAT32 *m_hybrid_imag = (FLOAT32 *)pstr_scratch; |
1173 | 23.2k | memset(m_hybrid_imag, 0, sizeof(*m_hybrid_imag) * 6 * MAX_TIME_SLOTS * MAX_HYBRID_BANDS); |
1174 | 23.2k | pstr_scratch += 6 * MAX_TIME_SLOTS * MAX_HYBRID_BANDS; |
1175 | | |
1176 | 23.2k | FLOAT32 *m_qmf_real_out = (FLOAT32 *)pstr_scratch; |
1177 | 23.2k | memset(m_qmf_real_out, 0, sizeof(*m_qmf_real_out) * 6 * MAX_TIME_SLOTS * NUM_QMF_BANDS); |
1178 | 23.2k | pstr_scratch += 6 * MAX_TIME_SLOTS * NUM_QMF_BANDS; |
1179 | | |
1180 | 23.2k | FLOAT32 *m_qmf_imag_out = (FLOAT32 *)pstr_scratch; |
1181 | 23.2k | memset(m_qmf_imag_out, 0, sizeof(*m_qmf_imag_out) * 6 * MAX_TIME_SLOTS * NUM_QMF_BANDS); |
1182 | | |
1183 | 23.2k | ixheaace_mps_sac_spatial_frame *pstr_frame_data; |
1184 | 23.2k | ixheaace_mps_sac_pstr_qmf_ana_filter_bank pstr_qmf_ana_bank = &pstr_mps_enc->qmf_fltbank; |
1185 | 23.2k | ixheaace_mps_sac_pstr_qmf_synth_filter_bank pstr_qmf_synth_bank = |
1186 | 23.2k | &pstr_mps_enc->qmf_synth_fltbank; |
1187 | | |
1188 | 23.2k | WORD32 i, j, k, l; |
1189 | | |
1190 | 23.2k | FLOAT32 p_pre_scale[6] = {1.f, 1.f, 1.f, 0.3162f, 0.7071f, 0.7071f}; |
1191 | 8.19M | for (i = 0; i < DELAY_COMPENSATION; i++) { |
1192 | 57.2M | for (j = 0; j < 6; j++) { |
1193 | 49.0M | pstr_mps_enc->in1[j][i] = pstr_mps_enc->in1[j][i + pstr_mps_enc->frame_size]; |
1194 | 49.0M | } |
1195 | 8.17M | } |
1196 | | |
1197 | 23.2M | for (i = 0; i < pstr_mps_enc->frame_size; i++) { |
1198 | 162M | for (j = 0; j < 6; j++) { |
1199 | 139M | pstr_mps_enc->in1[j][i + DELAY_COMPENSATION] = ptr_audio_input[i * 6 + j] * p_pre_scale[j]; |
1200 | 139M | } |
1201 | 23.2M | } |
1202 | | |
1203 | 23.2M | for (i = 0; i < pstr_mps_enc->frame_size; i++) { |
1204 | 162M | for (j = 0; j < 6; j++) { |
1205 | 139M | in[j * MAX_BUFFER_SIZE + i] = ptr_audio_input[i * 6 + j] * p_pre_scale[j]; |
1206 | 139M | } |
1207 | 23.2M | } |
1208 | | |
1209 | 23.2M | for (i = 0; i < pstr_mps_enc->frame_size; i++) { |
1210 | 23.2M | if (pstr_mps_enc->output_channels == 1) |
1211 | 10.8M | out1[i] = in[i] + in[MAX_BUFFER_SIZE + i] + in[2 * MAX_BUFFER_SIZE + i] + |
1212 | 10.8M | in[3 * MAX_BUFFER_SIZE + i] + in[4 * MAX_BUFFER_SIZE + i] + |
1213 | 10.8M | in[5 * MAX_BUFFER_SIZE + i]; |
1214 | 12.4M | else { |
1215 | 12.4M | out1[i] = in[i] + 0.7071f * (in[2 * MAX_BUFFER_SIZE + i] + in[3 * MAX_BUFFER_SIZE + i]) + |
1216 | 12.4M | in[4 * MAX_BUFFER_SIZE + i]; |
1217 | 12.4M | out1[MAX_BUFFER_SIZE + i] = |
1218 | 12.4M | in[MAX_BUFFER_SIZE + i] + |
1219 | 12.4M | 0.7071f * (in[2 * MAX_BUFFER_SIZE + i] + in[3 * MAX_BUFFER_SIZE + i]) + |
1220 | 12.4M | in[5 * MAX_BUFFER_SIZE + i]; |
1221 | 12.4M | } |
1222 | 23.2M | } |
1223 | | |
1224 | 23.2M | for (i = 0; i < pstr_mps_enc->frame_size; i++) { |
1225 | 162M | for (j = 0; j < 6; j++) { |
1226 | 139M | in[j * MAX_BUFFER_SIZE + i] = pstr_mps_enc->in1[j][i]; |
1227 | 139M | } |
1228 | 23.2M | } |
1229 | | |
1230 | 386k | for (l = 0; l < pstr_mps_enc->time_slots; l++) { |
1231 | 2.54M | for (j = 0; j < 6; j++) { |
1232 | 2.18M | ixheaace_mps_515_calculate_ana_filterbank( |
1233 | 2.18M | &pstr_mps_enc->filterbank[j], in + (j * MAX_BUFFER_SIZE) + (l * 64), |
1234 | 2.18M | m_qmf_real + (j * MAX_TIME_SLOTS * NUM_QMF_BANDS) + (l * NUM_QMF_BANDS), |
1235 | 2.18M | m_qmf_imag + (j * MAX_TIME_SLOTS * NUM_QMF_BANDS) + (l * NUM_QMF_BANDS), |
1236 | 2.18M | pstr_qmf_ana_bank); |
1237 | 2.18M | } |
1238 | 363k | } |
1239 | | |
1240 | 162k | for (k = 0; k < 6; k++) { |
1241 | 139k | ixheaace_mps_515_apply_ana_hyb_filterbank( |
1242 | 139k | &pstr_mps_enc->hyb_state[k], m_qmf_real + (k * MAX_TIME_SLOTS * NUM_QMF_BANDS), |
1243 | 139k | m_qmf_imag + (k * MAX_TIME_SLOTS * NUM_QMF_BANDS), pstr_mps_enc->time_slots, |
1244 | 139k | m_hybrid_real + (k * MAX_TIME_SLOTS * MAX_HYBRID_BANDS), |
1245 | 139k | m_hybrid_imag + k * MAX_TIME_SLOTS * MAX_HYBRID_BANDS); |
1246 | 139k | } |
1247 | | |
1248 | 23.2k | pstr_frame_data = &pstr_mps_enc->bitstream_formatter->current_frame; |
1249 | 23.2k | switch (pstr_mps_enc->tree_config) { |
1250 | 6.51k | case 5151: |
1251 | 6.51k | ixheaace_mps_515_ott_box(pstr_mps_enc->time_slots, m_hybrid_real, m_hybrid_imag, |
1252 | 6.51k | m_hybrid_real + MAX_TIME_SLOTS * MAX_HYBRID_BANDS, |
1253 | 6.51k | m_hybrid_imag + MAX_TIME_SLOTS * MAX_HYBRID_BANDS, |
1254 | 6.51k | pstr_frame_data->ott_data.cld[3][0], |
1255 | 6.51k | pstr_frame_data->ott_data.icc[3][0]); |
1256 | 6.51k | ixheaace_mps_515_ott_box( |
1257 | 6.51k | pstr_mps_enc->time_slots, m_hybrid_real + 4 * MAX_TIME_SLOTS * MAX_HYBRID_BANDS, |
1258 | 6.51k | m_hybrid_imag + 4 * MAX_TIME_SLOTS * MAX_HYBRID_BANDS, |
1259 | 6.51k | m_hybrid_real + 5 * MAX_TIME_SLOTS * MAX_HYBRID_BANDS, |
1260 | 6.51k | m_hybrid_imag + 5 * MAX_TIME_SLOTS * MAX_HYBRID_BANDS, |
1261 | 6.51k | pstr_frame_data->ott_data.cld[2][0], pstr_frame_data->ott_data.icc[2][0]); |
1262 | 6.51k | ixheaace_mps_515_ott_box( |
1263 | 6.51k | pstr_mps_enc->time_slots, m_hybrid_real + 2 * MAX_TIME_SLOTS * MAX_HYBRID_BANDS, |
1264 | 6.51k | m_hybrid_imag + 2 * MAX_TIME_SLOTS * MAX_HYBRID_BANDS, |
1265 | 6.51k | m_hybrid_real + 3 * MAX_TIME_SLOTS * MAX_HYBRID_BANDS, |
1266 | 6.51k | m_hybrid_imag + 3 * MAX_TIME_SLOTS * MAX_HYBRID_BANDS, |
1267 | 6.51k | pstr_frame_data->ott_data.cld[4][0], pstr_frame_data->ott_data.icc[4][0]); |
1268 | 6.51k | ixheaace_mps_515_ott_box(pstr_mps_enc->time_slots, m_hybrid_real, m_hybrid_imag, |
1269 | 6.51k | m_hybrid_real + 2 * MAX_TIME_SLOTS * MAX_HYBRID_BANDS, |
1270 | 6.51k | m_hybrid_imag + 2 * MAX_TIME_SLOTS * MAX_HYBRID_BANDS, |
1271 | 6.51k | pstr_frame_data->ott_data.cld[1][0], |
1272 | 6.51k | pstr_frame_data->ott_data.icc[1][0]); |
1273 | 6.51k | ixheaace_mps_515_ott_box(pstr_mps_enc->time_slots, m_hybrid_real, m_hybrid_imag, |
1274 | 6.51k | m_hybrid_real + 4 * MAX_TIME_SLOTS * MAX_HYBRID_BANDS, |
1275 | 6.51k | m_hybrid_imag + 4 * MAX_TIME_SLOTS * MAX_HYBRID_BANDS, |
1276 | 6.51k | pstr_frame_data->ott_data.cld[0][0], |
1277 | 6.51k | pstr_frame_data->ott_data.icc[0][0]); |
1278 | | |
1279 | 6.51k | break; |
1280 | 4.26k | case 5152: |
1281 | 4.26k | ixheaace_mps_515_ott_box(pstr_mps_enc->time_slots, m_hybrid_real, m_hybrid_imag, |
1282 | 4.26k | m_hybrid_real + 4 * MAX_TIME_SLOTS * MAX_HYBRID_BANDS, |
1283 | 4.26k | m_hybrid_imag + 4 * MAX_TIME_SLOTS * MAX_HYBRID_BANDS, |
1284 | 4.26k | pstr_frame_data->ott_data.cld[3][0], |
1285 | 4.26k | pstr_frame_data->ott_data.icc[3][0]); |
1286 | 4.26k | ixheaace_mps_515_ott_box( |
1287 | 4.26k | pstr_mps_enc->time_slots, m_hybrid_real + MAX_TIME_SLOTS * MAX_HYBRID_BANDS, |
1288 | 4.26k | m_hybrid_imag + MAX_TIME_SLOTS * MAX_HYBRID_BANDS, |
1289 | 4.26k | m_hybrid_real + 5 * MAX_TIME_SLOTS * MAX_HYBRID_BANDS, |
1290 | 4.26k | m_hybrid_imag + 5 * MAX_TIME_SLOTS * MAX_HYBRID_BANDS, |
1291 | 4.26k | pstr_frame_data->ott_data.cld[4][0], pstr_frame_data->ott_data.icc[4][0]); |
1292 | 4.26k | ixheaace_mps_515_ott_box( |
1293 | 4.26k | pstr_mps_enc->time_slots, m_hybrid_real + 2 * MAX_TIME_SLOTS * MAX_HYBRID_BANDS, |
1294 | 4.26k | m_hybrid_imag + 2 * MAX_TIME_SLOTS * MAX_HYBRID_BANDS, |
1295 | 4.26k | m_hybrid_real + 3 * MAX_TIME_SLOTS * MAX_HYBRID_BANDS, |
1296 | 4.26k | m_hybrid_imag + 3 * MAX_TIME_SLOTS * MAX_HYBRID_BANDS, |
1297 | 4.26k | pstr_frame_data->ott_data.cld[2][0], pstr_frame_data->ott_data.icc[2][0]); |
1298 | 4.26k | ixheaace_mps_515_ott_box(pstr_mps_enc->time_slots, m_hybrid_real, m_hybrid_imag, |
1299 | 4.26k | m_hybrid_real + MAX_TIME_SLOTS * MAX_HYBRID_BANDS, |
1300 | 4.26k | m_hybrid_imag + MAX_TIME_SLOTS * MAX_HYBRID_BANDS, |
1301 | 4.26k | pstr_frame_data->ott_data.cld[1][0], |
1302 | 4.26k | pstr_frame_data->ott_data.icc[1][0]); |
1303 | 4.26k | ixheaace_mps_515_ott_box(pstr_mps_enc->time_slots, m_hybrid_real, m_hybrid_imag, |
1304 | 4.26k | m_hybrid_real + 2 * MAX_TIME_SLOTS * MAX_HYBRID_BANDS, |
1305 | 4.26k | m_hybrid_imag + 2 * MAX_TIME_SLOTS * MAX_HYBRID_BANDS, |
1306 | 4.26k | pstr_frame_data->ott_data.cld[0][0], |
1307 | 4.26k | pstr_frame_data->ott_data.icc[0][0]); |
1308 | 4.26k | break; |
1309 | 12.4k | case 525: |
1310 | 12.4k | ixheaace_mps_515_ott_box(pstr_mps_enc->time_slots, m_hybrid_real, m_hybrid_imag, |
1311 | 12.4k | m_hybrid_real + 4 * MAX_TIME_SLOTS * MAX_HYBRID_BANDS, |
1312 | 12.4k | m_hybrid_imag + 4 * MAX_TIME_SLOTS * MAX_HYBRID_BANDS, |
1313 | 12.4k | pstr_frame_data->ott_data.cld[1][0], |
1314 | 12.4k | pstr_frame_data->ott_data.icc[1][0]); |
1315 | 12.4k | ixheaace_mps_515_ott_box( |
1316 | 12.4k | pstr_mps_enc->time_slots, m_hybrid_real + MAX_TIME_SLOTS * MAX_HYBRID_BANDS, |
1317 | 12.4k | m_hybrid_imag + MAX_TIME_SLOTS * MAX_HYBRID_BANDS, |
1318 | 12.4k | m_hybrid_real + 5 * MAX_TIME_SLOTS * MAX_HYBRID_BANDS, |
1319 | 12.4k | m_hybrid_imag + 5 * MAX_TIME_SLOTS * MAX_HYBRID_BANDS, |
1320 | 12.4k | pstr_frame_data->ott_data.cld[2][0], pstr_frame_data->ott_data.icc[2][0]); |
1321 | 12.4k | ixheaace_mps_515_ott_box( |
1322 | 12.4k | pstr_mps_enc->time_slots, m_hybrid_real + 2 * MAX_TIME_SLOTS * MAX_HYBRID_BANDS, |
1323 | 12.4k | m_hybrid_imag + 2 * MAX_TIME_SLOTS * MAX_HYBRID_BANDS, |
1324 | 12.4k | m_hybrid_real + 3 * MAX_TIME_SLOTS * MAX_HYBRID_BANDS, |
1325 | 12.4k | m_hybrid_imag + 3 * MAX_TIME_SLOTS * MAX_HYBRID_BANDS, |
1326 | 12.4k | pstr_frame_data->ott_data.cld[0][0], pstr_frame_data->ott_data.icc[0][0]); |
1327 | 12.4k | ixheaace_mps_515_ttt_box(pstr_mps_enc->time_slots, m_hybrid_real, m_hybrid_imag, |
1328 | 12.4k | m_hybrid_real + MAX_TIME_SLOTS * MAX_HYBRID_BANDS, |
1329 | 12.4k | m_hybrid_imag + MAX_TIME_SLOTS * MAX_HYBRID_BANDS, |
1330 | 12.4k | m_hybrid_real + 2 * MAX_TIME_SLOTS * MAX_HYBRID_BANDS, |
1331 | 12.4k | m_hybrid_imag + 2 * MAX_TIME_SLOTS * MAX_HYBRID_BANDS, |
1332 | 12.4k | pstr_frame_data->ttt_data.cpc_cld1[0][0], |
1333 | 12.4k | pstr_frame_data->ttt_data.cpc_cld2[0][0]); |
1334 | 23.2k | } |
1335 | | |
1336 | 23.2k | pstr_frame_data->framing_info.bs_framing_type = 1; |
1337 | 23.2k | pstr_frame_data->framing_info.bs_num_param_sets = 1; |
1338 | | |
1339 | 23.2k | pstr_frame_data->framing_info.bs_param_slots[0] = 31; |
1340 | 23.2k | if (pstr_frame_data->bs_independency_flag_count == 0) { |
1341 | 2.58k | pstr_frame_data->bs_independency_flag = 1; |
1342 | 2.58k | } |
1343 | 23.2k | pstr_frame_data->bs_independency_flag_count = |
1344 | 23.2k | (pstr_frame_data->bs_independency_flag_count + 1) % 10; |
1345 | | |
1346 | 23.2k | error = ixheaace_mps_515_write_spatial_frame(pstr_bitstream, pstr_mps_enc->bitstream_formatter); |
1347 | 23.2k | if (error) { |
1348 | 0 | return error; |
1349 | 0 | } |
1350 | | |
1351 | 23.2k | if (pstr_mps_enc->output_channels == 1) { |
1352 | 10.7k | ixheaace_mps_515_apply_syn_hyb_filterbank( |
1353 | 10.7k | m_hybrid_real, m_hybrid_imag, pstr_mps_enc->time_slots, m_qmf_real_out, m_qmf_imag_out); |
1354 | | |
1355 | 10.7k | ixheaace_mps_515_calculate_sbr_syn_filterbank(m_qmf_real_out, m_qmf_imag_out, out, 0, |
1356 | 10.7k | pstr_qmf_synth_bank, pstr_mps_enc->time_slots, |
1357 | 10.7k | pstr_mps_enc->sbr_qmf_states_synthesis); |
1358 | | |
1359 | 10.8M | for (j = 0; j < pstr_mps_enc->frame_size; j++) { |
1360 | 10.8M | ptr_audio_output[j] = out1[j]; |
1361 | 10.8M | } |
1362 | 12.4k | } else { |
1363 | 12.4k | ixheaace_mps_515_apply_syn_hyb_filterbank( |
1364 | 12.4k | m_hybrid_real, m_hybrid_imag, pstr_mps_enc->time_slots, m_qmf_real_out, m_qmf_imag_out); |
1365 | 12.4k | ixheaace_mps_515_apply_syn_hyb_filterbank(m_hybrid_real + MAX_TIME_SLOTS * MAX_HYBRID_BANDS, |
1366 | 12.4k | m_hybrid_imag + MAX_TIME_SLOTS * MAX_HYBRID_BANDS, |
1367 | 12.4k | pstr_mps_enc->time_slots, |
1368 | 12.4k | m_qmf_real_out + MAX_TIME_SLOTS * MAX_HYBRID_BANDS, |
1369 | 12.4k | m_qmf_imag_out + MAX_TIME_SLOTS * MAX_HYBRID_BANDS); |
1370 | | |
1371 | 12.4k | ixheaace_mps_515_calculate_sbr_syn_filterbank(m_qmf_real_out, m_qmf_imag_out, out, 0, |
1372 | 12.4k | pstr_qmf_synth_bank, pstr_mps_enc->time_slots, |
1373 | 12.4k | pstr_mps_enc->sbr_qmf_states_synthesis); |
1374 | 12.4k | ixheaace_mps_515_calculate_sbr_syn_filterbank( |
1375 | 12.4k | m_qmf_real_out + MAX_TIME_SLOTS * MAX_HYBRID_BANDS, |
1376 | 12.4k | m_qmf_imag_out + MAX_TIME_SLOTS * MAX_HYBRID_BANDS, out + MAX_BUFFER_SIZE, 1, |
1377 | 12.4k | pstr_qmf_synth_bank, pstr_mps_enc->time_slots, pstr_mps_enc->sbr_qmf_states_synthesis); |
1378 | | |
1379 | 12.4M | for (j = 0; j < pstr_mps_enc->frame_size; j++) { |
1380 | 12.4M | ptr_audio_output[2 * j] = out1[j]; |
1381 | 12.4M | ptr_audio_output[2 * j + 1] = out1[MAX_BUFFER_SIZE + j]; |
1382 | 12.4M | } |
1383 | 12.4k | } |
1384 | 23.2k | return IA_NO_ERROR; |
1385 | 23.2k | } |
1386 | | |
1387 | 0 | VOID ixheaace_mps_515_close(ixheaace_mps_sac_enc *pstr_mps_enc) { |
1388 | 0 | if (pstr_mps_enc != NULL) { |
1389 | 0 | pstr_mps_enc->bitstream_formatter = NULL; |
1390 | 0 | } |
1391 | 0 | } |