/src/libxaac/encoder/ixheaace_mps_tree.c
Line | Count | Source |
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 "ixheaac_type_def.h" |
23 | | #include "ixheaac_error_standards.h" |
24 | | #include "ixheaace_error_codes.h" |
25 | | #include "ixheaace_mps_common_fix.h" |
26 | | #include "ixheaace_mps_defines.h" |
27 | | #include "ixheaace_mps_common_define.h" |
28 | | #include "ixheaace_bitbuffer.h" |
29 | | |
30 | | #include "ixheaace_mps_bitstream.h" |
31 | | #include "ixheaace_mps_param_extract.h" |
32 | | #include "ixheaace_mps_frame_windowing.h" |
33 | | #include "ixheaace_mps_tree.h" |
34 | | #include "ixheaace_mps_buf.h" |
35 | | #include "ixheaace_mps_lib.h" |
36 | | #include "ixheaace_mps_onset_detect.h" |
37 | | #include "ixheaace_mps_static_gain.h" |
38 | | #include "ixheaace_mps_filter.h" |
39 | | #include "ixheaace_mps_delay.h" |
40 | | #include "ixheaace_mps_dmx_tdom_enh.h" |
41 | | #include "ixheaace_mps_main_structure.h" |
42 | | #include "ixheaace_mps_tools_rom.h" |
43 | | #include "ixheaace_mps_qmf.h" |
44 | | #include "ixheaace_mps_structure.h" |
45 | | #include "ixheaace_mps_struct_def.h" |
46 | | #include "ixheaace_mps_sac_polyphase.h" |
47 | | #include "ixheaace_mps_sac_nlc_enc.h" |
48 | | #include "ixheaace_mps_sac_hybfilter.h" |
49 | | #include "ixheaace_mps_spatial_bitstream.h" |
50 | | #include "ixheaace_mps_rom.h" |
51 | | |
52 | | static VOID ixheaace_mps_212_space_tree_frame_keep_212( |
53 | | const ixheaace_mps_pstr_space_tree pstr_space_tree, |
54 | 104k | ixheaace_mps_spatial_frame *const pstr_spatial_frame, const WORD32 avoid_keep) { |
55 | 104k | WORD32 band; |
56 | | |
57 | 104k | if (avoid_keep) { |
58 | 1.50M | for (band = 0; band < pstr_space_tree->num_param_bands; band++) { |
59 | 1.44M | pstr_space_tree->icc_prev[0][band] = pstr_spatial_frame->ott_data.icc[0][0][band]; |
60 | 1.44M | pstr_space_tree->cld_prev[0][band] = pstr_spatial_frame->ott_data.cld[0][0][band]; |
61 | 1.44M | } |
62 | 56.0k | } else { |
63 | 48.6k | if (pstr_space_tree->frame_count % 2) { |
64 | 634k | for (band = 0; band < pstr_space_tree->num_param_bands; band++) { |
65 | 610k | pstr_spatial_frame->ott_data.icc[0][0][band] = pstr_space_tree->icc_prev[0][band]; |
66 | 610k | pstr_space_tree->cld_prev[0][band] = pstr_spatial_frame->ott_data.cld[0][0][band]; |
67 | 610k | } |
68 | 24.5k | } else { |
69 | 627k | for (band = 0; band < pstr_space_tree->num_param_bands; band++) { |
70 | 603k | pstr_space_tree->icc_prev[0][band] = pstr_spatial_frame->ott_data.icc[0][0][band]; |
71 | 603k | pstr_spatial_frame->ott_data.cld[0][0][band] = pstr_space_tree->cld_prev[0][band]; |
72 | 603k | } |
73 | 24.0k | } |
74 | 48.6k | } |
75 | 104k | pstr_space_tree->frame_count++; |
76 | 104k | if (pstr_space_tree->frame_count == MAX_KEEP_FRAMECOUNT) { |
77 | 710 | pstr_space_tree->frame_count = 0; |
78 | 710 | } |
79 | 104k | } |
80 | | |
81 | | IA_ERRORCODE |
82 | | ixheaace_mps_212_space_tree_init(ixheaace_mps_pstr_space_tree pstr_space_tree, |
83 | | const ixheaace_mps_space_tree_setup *const pstr_space_tree_setup, |
84 | | UWORD8 *ptr_parameter_band_2_hybrid_band_offset, |
85 | 1.52k | const WORD32 frame_keep_flag, WORD32 aot) { |
86 | 1.52k | IA_ERRORCODE error = IA_NO_ERROR; |
87 | 1.52k | WORD32 box = 0; |
88 | | |
89 | 1.52k | pstr_space_tree->frame_count = 0; |
90 | 1.52k | pstr_space_tree->frame_keep_flag = frame_keep_flag; |
91 | 1.52k | pstr_space_tree->num_param_bands = pstr_space_tree_setup->num_param_bands; |
92 | 1.52k | pstr_space_tree->use_coarse_quant_tto_icc_flag = |
93 | 1.52k | pstr_space_tree_setup->use_coarse_quant_tto_icc_flag; |
94 | 1.52k | pstr_space_tree->use_coarse_quant_tto_cld_flag = |
95 | 1.52k | pstr_space_tree_setup->use_coarse_quant_tto_cld_flag; |
96 | 1.52k | pstr_space_tree->quant_mode = pstr_space_tree_setup->quant_mode; |
97 | 1.52k | pstr_space_tree->num_channels_in_max = pstr_space_tree_setup->num_channels_in_max; |
98 | 1.52k | pstr_space_tree->num_hybrid_bands_max = pstr_space_tree_setup->num_hybrid_bands_max; |
99 | 1.52k | pstr_space_tree->descr.num_ott_boxes = 1; |
100 | 1.52k | pstr_space_tree->descr.num_in_channels = 1; |
101 | 1.52k | pstr_space_tree->descr.num_out_channels = 2; |
102 | | |
103 | 1.52k | if (pstr_space_tree->descr.num_ott_boxes > IXHEAACE_MPS_MAX_NUM_BOXES) { |
104 | 0 | return IA_EXHEAACE_INIT_FATAL_MPS_INIT_FAILED; |
105 | 0 | } |
106 | | |
107 | 3.05k | for (box = 0; box < pstr_space_tree->descr.num_ott_boxes; box++) { |
108 | 1.52k | ixheaace_mps_tto_box_config box_config; |
109 | 1.52k | box_config.b_use_coherence_icc_only = 0; |
110 | 1.52k | box_config.subband_config = pstr_space_tree->num_param_bands; |
111 | 1.52k | box_config.use_coarse_quant_cld_flag = pstr_space_tree->use_coarse_quant_tto_cld_flag; |
112 | 1.52k | box_config.use_coarse_quant_icc_flag = pstr_space_tree->use_coarse_quant_tto_icc_flag; |
113 | 1.52k | box_config.box_quant_mode = pstr_space_tree->quant_mode; |
114 | 1.52k | box_config.num_hybrid_bands_max = pstr_space_tree->num_hybrid_bands_max; |
115 | 1.52k | box_config.frame_keep_flag = pstr_space_tree->frame_keep_flag; |
116 | | |
117 | 1.52k | error = ixheaace_mps_212_init_tto_box(pstr_space_tree->pstr_tto_box[box], &box_config, |
118 | 1.52k | ptr_parameter_band_2_hybrid_band_offset, aot); |
119 | 1.52k | if (error) { |
120 | 0 | return error; |
121 | 0 | } |
122 | 1.52k | } |
123 | | |
124 | 1.52k | return error; |
125 | 1.52k | } |
126 | | |
127 | | IA_ERRORCODE ixheaace_mps_212_space_tree_apply( |
128 | | ixheaace_mps_pstr_space_tree pstr_space_tree, const WORD32 param_set, |
129 | | const WORD32 num_channels_in, const WORD32 num_time_slots, const WORD32 start_time_slot, |
130 | | const WORD32 num_hybrid_bands, FLOAT32 *p_frame_window_ana_mps, |
131 | | ixheaace_cmplx_str ppp_cmplx_hybrid_1[IXHEAACE_MPS_MAX_INPUT_CHANNELS][MAX_ANA_TIME_SLOT] |
132 | | [MAX_QMF_BANDS], |
133 | | ixheaace_cmplx_str ppp_cmplx_hybrid_2[IXHEAACE_MPS_MAX_INPUT_CHANNELS][MAX_ANA_TIME_SLOT] |
134 | | [MAX_QMF_BANDS], |
135 | 104k | ixheaace_mps_spatial_frame *const pstr_spatial_frame, const WORD32 avoid_keep) { |
136 | 104k | IA_ERRORCODE error = IA_NO_ERROR; |
137 | 104k | WORD32 box; |
138 | 104k | const ixheaace_mps_tree_setup *pstr_tree_setup = NULL; |
139 | 104k | pstr_tree_setup = &tree_setup_table; |
140 | | |
141 | 104k | if ((num_channels_in != pstr_tree_setup->num_channels_in) || |
142 | 104k | (num_channels_in > pstr_space_tree->num_channels_in_max) || |
143 | 104k | (num_hybrid_bands > pstr_space_tree->num_hybrid_bands_max)) { |
144 | 0 | return IA_EXHEAACE_CONFIG_NONFATAL_MPS_INVALID_CONFIG; |
145 | 0 | } |
146 | | |
147 | 209k | for (box = 0; box < pstr_tree_setup->n_tto_boxes; box++) { |
148 | 104k | const ixheaace_mps_tto_descriptor *pstr_tto_descriptor = |
149 | 104k | &pstr_tree_setup->tto_descriptor[box]; |
150 | 104k | WORD32 i; |
151 | 104k | WORD32 in_ch[2], out_ch[2], win[2]; |
152 | | |
153 | 104k | in_ch[0] = pstr_tto_descriptor->in_ch1; |
154 | 104k | in_ch[1] = pstr_tto_descriptor->in_ch2; |
155 | 104k | out_ch[0] = pstr_tto_descriptor->in_ch3; |
156 | 104k | out_ch[1] = pstr_tto_descriptor->in_ch4; |
157 | 104k | win[0] = pstr_tto_descriptor->w_ch1; |
158 | 104k | win[1] = pstr_tto_descriptor->w_ch2; |
159 | | |
160 | 313k | for (i = 0; i < 2; i++) { |
161 | 209k | if (win[i] == WIN_ACTIV) { |
162 | 209k | ixheaace_mps_212_analysis_windowing(num_time_slots, start_time_slot, |
163 | 209k | p_frame_window_ana_mps, ppp_cmplx_hybrid_1[in_ch[i]], |
164 | 209k | ppp_cmplx_hybrid_2[out_ch[i]], num_hybrid_bands); |
165 | 209k | } |
166 | 209k | } |
167 | | |
168 | 104k | error = ixheaace_mps_212_apply_tto_box( |
169 | 104k | pstr_space_tree->pstr_tto_box[pstr_tto_descriptor->box_id], num_time_slots, |
170 | 104k | start_time_slot, num_hybrid_bands, ppp_cmplx_hybrid_2[pstr_tto_descriptor->in_ch3], |
171 | 104k | ppp_cmplx_hybrid_2[pstr_tto_descriptor->in_ch4], |
172 | 104k | pstr_spatial_frame->ott_data.icc[pstr_tto_descriptor->box_id][param_set], |
173 | 104k | &(pstr_spatial_frame->icc_lossless_data |
174 | 104k | .bs_quant_coarse_xxx[pstr_tto_descriptor->box_id][param_set]), |
175 | 104k | pstr_spatial_frame->ott_data.cld[pstr_tto_descriptor->box_id][param_set], |
176 | 104k | &(pstr_spatial_frame->cld_lossless_data |
177 | 104k | .bs_quant_coarse_xxx[pstr_tto_descriptor->box_id][param_set]), |
178 | 104k | pstr_spatial_frame->b_use_bb_cues); |
179 | 104k | if (error) { |
180 | 0 | return error; |
181 | 0 | } |
182 | 104k | } |
183 | | |
184 | 104k | if (pstr_space_tree->frame_keep_flag == 1) { |
185 | 104k | ixheaace_mps_212_space_tree_frame_keep_212(pstr_space_tree, pstr_spatial_frame, avoid_keep); |
186 | 104k | } |
187 | 104k | return error; |
188 | 104k | } |