/src/libxaac/encoder/ixheaace_sbr_main.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 <string.h> |
22 | | |
23 | | #include "ixheaac_type_def.h" |
24 | | #include "ixheaac_constants.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 "ixheaace_aac_constants.h" |
31 | | #include "ixheaace_error_codes.h" |
32 | | #include "ixheaac_error_standards.h" |
33 | | #include "ixheaac_basic_ops32.h" |
34 | | #include "ixheaac_basic_ops16.h" |
35 | | #include "ixheaac_basic_ops40.h" |
36 | | #include "ixheaac_basic_ops.h" |
37 | | |
38 | | #include "ixheaace_sbr_header.h" |
39 | | #include "ixheaace_sbr_def.h" |
40 | | #include "ixheaace_resampler.h" |
41 | | #include "ixheaace_sbr_rom.h" |
42 | | #include "ixheaace_common_rom.h" |
43 | | #include "ixheaace_sbr_hbe.h" |
44 | | #include "ixheaace_sbr_qmf_enc.h" |
45 | | #include "ixheaace_sbr_tran_det.h" |
46 | | #include "ixheaace_sbr_frame_info_gen.h" |
47 | | #include "ixheaace_sbr_env_est.h" |
48 | | #include "ixheaace_sbr_code_envelope.h" |
49 | | #include "ixheaace_psy_const.h" |
50 | | #include "ixheaace_tns.h" |
51 | | #include "ixheaace_tns_params.h" |
52 | | #include "ixheaace_rom.h" |
53 | | #include "ixheaace_common_rom.h" |
54 | | #include "ixheaace_bitbuffer.h" |
55 | | |
56 | | #include "ixheaace_sbr_main.h" |
57 | | #include "ixheaace_common_rom.h" |
58 | | #include "ixheaace_sbr_missing_harmonics_det.h" |
59 | | #include "ixheaace_sbr_inv_filtering_estimation.h" |
60 | | #include "ixheaace_sbr_noise_floor_est.h" |
61 | | #include "ixheaace_sbr_ton_corr.h" |
62 | | #include "iusace_esbr_pvc.h" |
63 | | #include "iusace_esbr_inter_tes.h" |
64 | | #include "ixheaace_sbr.h" |
65 | | |
66 | | #include "ixheaace_sbr_freq_scaling.h" |
67 | | |
68 | | #include "ixheaace_bitbuffer.h" |
69 | | |
70 | | #include "ixheaace_sbr_hybrid.h" |
71 | | #include "ixheaace_sbr_ps_enc.h" |
72 | | #include "ixheaace_sbr_cmondata.h" |
73 | | #include "ixheaace_sbr_crc.h" |
74 | | #include "ixheaace_sbr_enc_struct.h" |
75 | | |
76 | | VOID ixheaace_set_usac_sbr_params(ixheaace_pstr_sbr_enc pstr_env_enc, WORD32 usac_indep_flag, |
77 | | WORD32 sbr_pre_proc, WORD32 sbr_pvc_active, WORD32 sbr_pvc_mode, |
78 | | WORD32 inter_tes_active, WORD32 sbr_harmonic, |
79 | 217k | WORD32 sbr_patching_mode) { |
80 | 217k | WORD32 ch; |
81 | 217k | pstr_env_enc->str_sbr_bs.usac_indep_flag = usac_indep_flag; |
82 | 217k | pstr_env_enc->str_sbr_hdr.sbr_pre_proc = sbr_pre_proc; |
83 | 217k | pstr_env_enc->str_sbr_hdr.sbr_pvc_active = sbr_pvc_active; |
84 | 217k | if (pstr_env_enc->str_sbr_cfg.num_ch == 2) { |
85 | 88.1k | pstr_env_enc->str_sbr_hdr.sbr_pvc_mode = 0; |
86 | 129k | } else { |
87 | 129k | pstr_env_enc->str_sbr_hdr.sbr_pvc_mode = sbr_pvc_mode; |
88 | 129k | } |
89 | 217k | pstr_env_enc->str_sbr_hdr.sbr_inter_tes_active = inter_tes_active; |
90 | 217k | pstr_env_enc->str_sbr_hdr.sbr_harmonic = sbr_harmonic; |
91 | 522k | for (ch = 0; ch < pstr_env_enc->str_sbr_cfg.num_ch; ch++) { |
92 | 305k | pstr_env_enc->pstr_env_channel[ch]->enc_env_data.sbr_inter_tes = inter_tes_active; |
93 | 305k | pstr_env_enc->pstr_env_channel[ch]->enc_env_data.sbr_patching_mode = sbr_patching_mode; |
94 | 305k | } |
95 | 217k | } |
96 | 95.4k | FLOAT32 *ixheaace_get_hbe_resample_buffer(ixheaace_pstr_sbr_enc pstr_env_enc) { |
97 | 95.4k | return pstr_env_enc->ptr_hbe_resample_buf; |
98 | 95.4k | } |
99 | | |
100 | | static FLAG ia_enhaacplus_enc_get_sbr_tuning_table_idx( |
101 | | UWORD32 bitrate, UWORD32 num_ch, UWORD32 sample_rate, ixheaace_str_qmf_tabs *pstr_qmf_tab, |
102 | | UWORD32 *ptr_closest_br, WORD32 *ptr_idx_sr, WORD32 *ptr_idx_ch, WORD32 *ptr_idx_entry, |
103 | 26.4k | ixheaace_sbr_tuning_tables sbr_tune_table[10][2][10]) { |
104 | 26.4k | WORD32 found = 0; |
105 | 26.4k | WORD32 i_sr, br_closest_lower_idx_sr = -1, br_closest_upper_idx_sr = -1; |
106 | 26.4k | WORD32 br_closest_lower_idx_ch = -1, br_closest_upper_idx_sch = -1; |
107 | 26.4k | UWORD32 i_ch; |
108 | 26.4k | WORD32 i_entry, br_closest_lower_idx_entry = -1, br_closest_upper_idx_entry = -1; |
109 | 26.4k | UWORD32 br_closest_upper = 0, br_closest_lower = IXHEAACE_DISTANCE_CEIL_VALUE; |
110 | 26.4k | const UWORD32 *ptr_sample_rate_supported = pstr_qmf_tab->supported_sample_rate; |
111 | 26.4k | WORD32 check_size = sizeof(sbr_tune_table[i_sr][i_ch]) / sizeof(sbr_tune_table[i_sr][i_ch][0]); |
112 | 151k | for (i_sr = 0; i_sr < 9; i_sr++) { |
113 | 407k | for (i_ch = 0; i_ch < 2; i_ch++) { |
114 | 282k | found = 1; |
115 | 282k | if ((num_ch - 1) == (i_ch) && (sample_rate == ptr_sample_rate_supported[i_sr])) { |
116 | 104k | for (i_entry = 0; i_entry < check_size - 1; i_entry++) { |
117 | 104k | if ((bitrate >= sbr_tune_table[i_sr][i_ch][i_entry].bitrate_from) && |
118 | 104k | (bitrate < sbr_tune_table[i_sr][i_ch][i_entry].bitrate_to)) { |
119 | 22.7k | *ptr_idx_sr = i_sr; |
120 | 22.7k | *ptr_idx_ch = i_ch; |
121 | 22.7k | *ptr_idx_entry = i_entry; |
122 | 22.7k | return IXHEAACE_TABLE_IDX_FOUND; |
123 | 81.6k | } else { |
124 | 81.6k | if ((sbr_tune_table[i_sr][i_ch][i_entry].bitrate_from > bitrate) && |
125 | 81.6k | (sbr_tune_table[i_sr][i_ch][i_entry].bitrate_from < br_closest_lower)) { |
126 | 1.51k | br_closest_lower = sbr_tune_table[i_sr][i_ch][i_entry].bitrate_from; |
127 | 1.51k | br_closest_lower_idx_sr = i_sr; |
128 | 1.51k | br_closest_lower_idx_ch = i_ch; |
129 | 1.51k | br_closest_lower_idx_entry = i_entry; |
130 | 1.51k | } |
131 | 81.6k | if ((sbr_tune_table[i_sr][i_ch][i_entry].bitrate_to <= bitrate) && |
132 | 81.6k | (sbr_tune_table[i_sr][i_ch][i_entry].bitrate_to > br_closest_upper)) { |
133 | 72.1k | br_closest_upper = sbr_tune_table[i_sr][i_ch][i_entry].bitrate_to - 1; |
134 | 72.1k | br_closest_upper_idx_sr = i_sr; |
135 | 72.1k | br_closest_upper_idx_sch = i_ch; |
136 | 72.1k | br_closest_upper_idx_entry = i_entry; |
137 | 72.1k | } |
138 | 81.6k | } |
139 | | |
140 | 81.6k | if (sbr_tune_table[i_sr][i_ch][i_entry + 1].bitrate_from == 0) { |
141 | 3.69k | *ptr_idx_sr = i_sr; |
142 | 3.69k | *ptr_idx_ch = i_ch; |
143 | 3.69k | *ptr_idx_entry = i_entry; |
144 | 3.69k | break; |
145 | 3.69k | } |
146 | 81.6k | } |
147 | 26.4k | } |
148 | 282k | } |
149 | 147k | } |
150 | | |
151 | 3.76k | if (br_closest_upper_idx_entry >= 0) { |
152 | 1.78k | return IXHEAACE_TABLE_IDX_FOUND; |
153 | 1.78k | } |
154 | | |
155 | 1.98k | if (ptr_closest_br != NULL) { |
156 | 1.51k | if (found) { |
157 | 1.51k | WORD32 distance_upper = IXHEAACE_DISTANCE_CEIL_VALUE, |
158 | 1.51k | distance_lower = IXHEAACE_DISTANCE_CEIL_VALUE; |
159 | 1.51k | if (br_closest_lower_idx_entry >= 0) { |
160 | 1.51k | distance_lower = sbr_tune_table[br_closest_lower_idx_sr][br_closest_lower_idx_ch] |
161 | 1.51k | [br_closest_lower_idx_entry] |
162 | 1.51k | .bitrate_from - |
163 | 1.51k | bitrate; |
164 | 1.51k | } |
165 | 1.51k | if (br_closest_upper_idx_entry >= 0) { |
166 | 0 | distance_upper = |
167 | 0 | bitrate - sbr_tune_table[br_closest_upper_idx_sr][br_closest_upper_idx_sch] |
168 | 0 | [br_closest_lower_idx_entry] |
169 | 0 | .bitrate_to; |
170 | 0 | } |
171 | | |
172 | 1.51k | *ptr_closest_br = (distance_upper < distance_lower) ? br_closest_upper : br_closest_lower; |
173 | 1.51k | } else { |
174 | 0 | *ptr_closest_br = 0; |
175 | 0 | } |
176 | 1.51k | } |
177 | | |
178 | 1.98k | return IXHEAACE_TABLE_IDX_NOT_FOUND; |
179 | 3.76k | } |
180 | | |
181 | | static IA_ERRORCODE ixheaace_create_env_channel( |
182 | | WORD32 ch, ixheaace_pstr_sbr_config_data pstr_sbr_cfg, |
183 | | ixheaace_pstr_sbr_hdr_data pstr_sbr_hdr, ixheaace_pstr_enc_channel pstr_env, |
184 | | ixheaace_pstr_sbr_cfg params, WORD32 *ptr_common_buf, WORD32 *ptr_common_buffer2, |
185 | 12.5k | FLOAT32 *ptr_sbr_env_r_buf, FLOAT32 *ptr_sbr_env_i_buf, ixheaace_str_sbr_tabs *pstr_sbr_tab) { |
186 | 12.5k | WORD32 e = 1; |
187 | 12.5k | WORD32 tran_fc = 0; |
188 | 12.5k | IA_ERRORCODE err_code = IA_NO_ERROR; |
189 | | |
190 | 12.5k | WORD32 start_index; |
191 | 12.5k | WORD32 noise_groups[2] = {3, 3}; |
192 | | |
193 | 12.5k | e = ixheaac_shl32(1, params->e); |
194 | | |
195 | 12.5k | if (params->use_low_freq_res == 1) { |
196 | 3.87k | pstr_env->enc_env_data.freq_res_fix = FREQ_RES_LOW; |
197 | 8.66k | } else { |
198 | 8.66k | pstr_env->enc_env_data.freq_res_fix = FREQ_RES_HIGH; |
199 | 8.66k | } |
200 | | |
201 | 12.5k | pstr_env->enc_env_data.sbr_xpos_mode = (ixheaace_sbr_xpos_mode)params->sbr_xpos_mode; |
202 | 12.5k | pstr_env->enc_env_data.sbr_xpos_ctrl = params->sbr_xpos_ctrl; |
203 | | |
204 | 12.5k | if (params->is_ld_sbr) { |
205 | 2.65k | pstr_env->str_sbr_qmf.num_time_slots = 16; |
206 | 2.65k | pstr_env->str_sbr_qmf.rate = 1; |
207 | 2.65k | if (params->frame_flag_480 == 1) { |
208 | 1.30k | pstr_env->str_sbr_qmf.num_time_slots = 15; |
209 | 1.30k | } |
210 | 9.87k | } else { |
211 | 9.87k | pstr_env->str_sbr_qmf.num_time_slots = 16; |
212 | 9.87k | pstr_env->str_sbr_qmf.rate = 2; |
213 | 9.87k | if (params->frame_flag_960 == 1) { |
214 | 1.32k | pstr_env->str_sbr_qmf.num_time_slots = 15; |
215 | 1.32k | } |
216 | 9.87k | if (pstr_sbr_cfg->sbr_codec == USAC_SBR) { |
217 | 5.48k | if (USAC_SBR_RATIO_INDEX_4_1 == pstr_sbr_cfg->sbr_ratio_idx) { |
218 | 1.18k | pstr_env->str_sbr_qmf.rate = 4; |
219 | 1.18k | } |
220 | 5.48k | } |
221 | 9.87k | } |
222 | | |
223 | 12.5k | ixheaace_create_qmf_bank(&pstr_env->str_sbr_qmf, pstr_sbr_tab, params->is_ld_sbr); |
224 | | |
225 | 12.5k | start_index = 576; |
226 | | |
227 | 12.5k | err_code = ixheaace_create_ton_corr_param_extr( |
228 | 12.5k | ch, &pstr_env->str_ton_corr, pstr_sbr_cfg->sample_freq, 64, params->sbr_xpos_ctrl, |
229 | 12.5k | pstr_sbr_cfg->ptr_freq_band_tab[LOW_RES][0], pstr_sbr_cfg->ptr_v_k_master, |
230 | 12.5k | pstr_sbr_cfg->num_master, params->ana_max_level, pstr_sbr_cfg->ptr_freq_band_tab, |
231 | 12.5k | pstr_sbr_cfg->num_scf, pstr_sbr_hdr->sbr_noise_bands, params->use_speech_config, |
232 | 12.5k | ptr_common_buf, pstr_sbr_tab->ptr_qmf_tab, params->is_ld_sbr); |
233 | 12.5k | if (err_code) { |
234 | 0 | return err_code; |
235 | 0 | } |
236 | | |
237 | 12.5k | pstr_env->enc_env_data.noise_band_count = |
238 | 12.5k | pstr_env->str_ton_corr.sbr_noise_floor_est.num_of_noise_bands; |
239 | | |
240 | 12.5k | noise_groups[0] = pstr_env->enc_env_data.noise_band_count; |
241 | 12.5k | noise_groups[1] = pstr_env->enc_env_data.noise_band_count; |
242 | | |
243 | 12.5k | pstr_env->enc_env_data.sbr_invf_mode = (ixheaace_invf_mode)params->sbr_invf_mode; |
244 | | |
245 | 12.5k | if (pstr_env->enc_env_data.sbr_invf_mode == IXHEAACE_INVF_SWITCHED) { |
246 | 12.5k | pstr_env->enc_env_data.sbr_invf_mode = IXHEAACE_INVF_MID_LEVEL; |
247 | 12.5k | pstr_env->str_ton_corr.switch_inverse_filt = TRUE; |
248 | 12.5k | } else { |
249 | 0 | pstr_env->str_ton_corr.switch_inverse_filt = FALSE; |
250 | 0 | } |
251 | | |
252 | 12.5k | tran_fc = params->tran_fc; |
253 | | |
254 | 12.5k | if (tran_fc == 0) { |
255 | 12.5k | tran_fc = ixheaac_min32(5000, ixheaace_get_sbr_start_freq_raw(pstr_sbr_hdr->sbr_start_freq, |
256 | 12.5k | 64, pstr_sbr_cfg->sample_freq)); |
257 | 12.5k | } |
258 | | |
259 | 12.5k | tran_fc = (tran_fc * 4 * 64 / pstr_sbr_cfg->sample_freq + 1) >> 1; |
260 | 12.5k | if (params->sbr_codec == USAC_SBR) { |
261 | 5.48k | pstr_env->str_sbr_extract_env.sbr_ratio_idx = params->sbr_ratio_idx; |
262 | 5.48k | } |
263 | 12.5k | err_code = ixheaace_create_extract_sbr_envelope( |
264 | 12.5k | ch, &pstr_env->str_sbr_extract_env, start_index, ptr_common_buffer2, ptr_sbr_env_r_buf, |
265 | 12.5k | ptr_sbr_env_i_buf, params->frame_flag_480, params->sbr_codec); |
266 | 12.5k | if (err_code) { |
267 | 0 | return err_code; |
268 | 0 | } |
269 | | |
270 | 12.5k | ixheaace_create_sbr_code_envelope(&pstr_env->str_sbr_code_env, pstr_sbr_cfg->num_scf, |
271 | 12.5k | params->delta_t_across_frames, params->df_edge_1st_env, |
272 | 12.5k | params->df_edge_incr); |
273 | | |
274 | 12.5k | ixheaace_create_sbr_code_envelope(&pstr_env->str_sbr_code_noise_floor, noise_groups, |
275 | 12.5k | params->delta_t_across_frames, 0, 0); |
276 | | |
277 | 12.5k | pstr_env->sbr_amp_res_init = pstr_sbr_hdr->sbr_amp_res; |
278 | | |
279 | 12.5k | err_code = ixheaace_init_sbr_huffman_tabs( |
280 | 12.5k | &pstr_env->enc_env_data, &pstr_env->str_sbr_code_env, &pstr_env->str_sbr_code_noise_floor, |
281 | 12.5k | pstr_env->sbr_amp_res_init, pstr_sbr_tab->ptr_sbr_huff_tab); |
282 | 12.5k | if (err_code) { |
283 | 0 | return err_code; |
284 | 0 | } |
285 | | |
286 | 12.5k | ixheaace_create_frame_info_generator(&pstr_env->str_sbr_env_frame, params->spread, e, |
287 | 12.5k | params->stat, pstr_env->enc_env_data.freq_res_fix, |
288 | 12.5k | params->use_low_freq_res); |
289 | | |
290 | 12.5k | ixheaace_create_sbr_transient_detector( |
291 | 12.5k | &pstr_env->str_sbr_trans_detector, pstr_sbr_cfg->sample_freq, |
292 | 12.5k | params->codec_settings.standard_bitrate * params->codec_settings.num_channels, |
293 | 12.5k | params->codec_settings.bit_rate, params->tran_thr, params->tran_det_mode, tran_fc, |
294 | 12.5k | params->frame_flag_480, params->is_ld_sbr, params->sbr_ratio_idx, params->sbr_codec, |
295 | 12.5k | pstr_sbr_cfg->ptr_freq_band_tab[0][0]); |
296 | | |
297 | 12.5k | pstr_sbr_cfg->xpos_control_switch = params->sbr_xpos_ctrl; |
298 | 12.5k | pstr_env->enc_env_data.no_harmonics = pstr_sbr_cfg->num_scf[HI]; |
299 | 12.5k | pstr_env->enc_env_data.synthetic_coding = pstr_sbr_cfg->detect_missing_harmonics; |
300 | 12.5k | pstr_env->enc_env_data.add_harmonic_flag = 0; |
301 | 12.5k | ixheaace_init_esbr_inter_tes(&pstr_env->str_inter_tes_enc, params->sbr_ratio_idx); |
302 | 12.5k | pstr_env->enc_env_data.ptr_sbr_inter_tes_shape = pstr_env->str_inter_tes_enc.bs_tes_shape; |
303 | 12.5k | pstr_env->enc_env_data.ptr_sbr_inter_tes_shape_mode = |
304 | 12.5k | pstr_env->str_inter_tes_enc.bs_tes_shape_mode; |
305 | | |
306 | 12.5k | if (params->sbr_codec == USAC_SBR) { |
307 | 5.48k | pstr_env->enc_env_data.harmonic_sbr = pstr_sbr_hdr->sbr_harmonic; |
308 | 5.48k | if (1 == pstr_env->enc_env_data.harmonic_sbr) { |
309 | 2.42k | WORD32 persist_mem_used = 0, bd; |
310 | 2.42k | WORD32 upsamp_4_flag, num_aac_samples, num_out_samples; |
311 | 2.42k | switch (pstr_sbr_cfg->sbr_ratio_idx) { |
312 | 1.68k | case USAC_SBR_RATIO_INDEX_2_1: |
313 | 1.68k | upsamp_4_flag = 0; |
314 | 1.68k | num_aac_samples = 1024; |
315 | 1.68k | num_out_samples = 2048; |
316 | 1.68k | break; |
317 | 741 | case USAC_SBR_RATIO_INDEX_4_1: |
318 | 741 | upsamp_4_flag = 1; |
319 | 741 | num_aac_samples = 1024; |
320 | 741 | num_out_samples = 4096; |
321 | 741 | break; |
322 | 0 | case USAC_SBR_RATIO_INDEX_8_3: |
323 | 0 | upsamp_4_flag = 0; |
324 | 0 | num_aac_samples = 768; |
325 | 0 | num_out_samples = 2048; |
326 | 0 | break; |
327 | 0 | default: |
328 | 0 | upsamp_4_flag = 0; |
329 | 0 | num_aac_samples = 1024; |
330 | 0 | num_out_samples = 2048; |
331 | 0 | break; |
332 | 2.42k | } |
333 | | |
334 | 2.42k | ixheaace_esbr_hbe_data_init( |
335 | 2.42k | pstr_env->pstr_hbe_enc->pstr_hbe_txposer, num_aac_samples, upsamp_4_flag, |
336 | 2.42k | num_out_samples, pstr_env->pstr_hbe_enc->ptr_hbe_txposer_buffers, &persist_mem_used); |
337 | | |
338 | 2.42k | ixheaace_esbr_qmf_init(&(pstr_env->pstr_hbe_enc->str_codec_qmf_bank), |
339 | 2.42k | pstr_sbr_cfg->sbr_ratio_idx, num_out_samples); |
340 | | |
341 | 72.7k | for (bd = 0; bd < (IXHEAACE_MAX_FREQ_COEFFS / 2 + 1); bd++) { |
342 | 70.3k | pstr_env->pstr_hbe_enc->pstr_hbe_txposer->freq_band_tbl_lo[bd] = |
343 | 70.3k | pstr_sbr_cfg->sbr_freq_band_tab_lo[bd]; |
344 | 70.3k | pstr_env->pstr_hbe_enc->pstr_hbe_txposer->freq_band_tbl_hi[bd] = |
345 | 70.3k | pstr_sbr_cfg->sbr_freq_band_tab_hi[bd]; |
346 | 70.3k | } |
347 | | |
348 | 70.3k | for (; bd < (IXHEAACE_MAX_FREQ_COEFFS + 1); bd++) { |
349 | 67.9k | pstr_env->pstr_hbe_enc->pstr_hbe_txposer->freq_band_tbl_hi[bd] = |
350 | 67.9k | pstr_sbr_cfg->sbr_freq_band_tab_hi[bd]; |
351 | 67.9k | } |
352 | | |
353 | 2.42k | pstr_env->pstr_hbe_enc->pstr_hbe_txposer->ptr_freq_band_tab[LO] = |
354 | 2.42k | pstr_env->pstr_hbe_enc->pstr_hbe_txposer->freq_band_tbl_lo; |
355 | 2.42k | pstr_env->pstr_hbe_enc->pstr_hbe_txposer->ptr_freq_band_tab[HI] = |
356 | 2.42k | pstr_env->pstr_hbe_enc->pstr_hbe_txposer->freq_band_tbl_hi; |
357 | 2.42k | pstr_env->pstr_hbe_enc->pstr_hbe_txposer->num_sf_bands[0] = |
358 | 2.42k | (WORD16)pstr_sbr_cfg->num_scf[0]; |
359 | 2.42k | pstr_env->pstr_hbe_enc->pstr_hbe_txposer->num_sf_bands[1] = |
360 | 2.42k | (WORD16)pstr_sbr_cfg->num_scf[1]; |
361 | 2.42k | pstr_env->pstr_hbe_enc->pstr_hbe_txposer->upsamp_4_flag = upsamp_4_flag; |
362 | 2.42k | err_code = ixheaace_dft_hbe_data_reinit(pstr_env->pstr_hbe_enc->pstr_hbe_txposer); |
363 | 2.42k | if (err_code) { |
364 | 0 | return err_code; |
365 | 0 | } |
366 | 2.42k | err_code = ixheaace_qmf_hbe_data_reinit(pstr_env->pstr_hbe_enc->pstr_hbe_txposer); |
367 | 2.42k | if (err_code) { |
368 | 0 | return err_code; |
369 | 0 | } |
370 | 2.42k | } |
371 | 5.48k | } else |
372 | | |
373 | 7.05k | { |
374 | 7.05k | pstr_env->enc_env_data.harmonic_sbr = 0; |
375 | 7.05k | } |
376 | | |
377 | 12.5k | return err_code; |
378 | 12.5k | } |
379 | | |
380 | | UWORD32 |
381 | | ixheaace_is_sbr_setting_available(UWORD32 bitrate, UWORD32 num_output_channels, |
382 | | UWORD32 sample_rate_input, UWORD32 *ptr_core_sr, |
383 | 4.96k | ixheaace_str_qmf_tabs *pstr_qmf_tab, WORD32 aot) { |
384 | 4.96k | FLAG table_found = IXHEAACE_TABLE_IDX_NOT_FOUND; |
385 | 4.96k | WORD32 idx_sr; |
386 | 4.96k | WORD32 idx_ch; |
387 | 4.96k | WORD32 idx_entry; |
388 | | |
389 | 4.96k | switch (num_output_channels) { |
390 | 2.67k | case MONO: |
391 | 2.67k | if (sample_rate_input < 16000 || sample_rate_input > 48000) { |
392 | 32 | return 0; |
393 | 32 | } |
394 | 4.92k | case STEREO: |
395 | 4.92k | if (sample_rate_input < 32000 || sample_rate_input > 48000) { |
396 | 2 | return 0; |
397 | 2 | } |
398 | 4.96k | } |
399 | | |
400 | 4.92k | *ptr_core_sr = sample_rate_input / 2; |
401 | | |
402 | 4.92k | table_found = ia_enhaacplus_enc_get_sbr_tuning_table_idx( |
403 | 4.92k | bitrate, num_output_channels, *ptr_core_sr, pstr_qmf_tab, NULL, &idx_sr, &idx_ch, |
404 | 4.92k | &idx_entry, |
405 | 4.92k | ((AOT_AAC_ELD == aot) ? pstr_qmf_tab->sbr_tuning_table_ld |
406 | 4.92k | : pstr_qmf_tab->sbr_tuning_table_lc)); |
407 | | |
408 | 4.92k | return (table_found == IXHEAACE_TABLE_IDX_NOT_FOUND) ? 0 : 1; |
409 | 4.96k | } |
410 | | |
411 | | UWORD32 ixheaace_sbr_limit_bitrate(UWORD32 bit_rate, UWORD32 num_ch, UWORD32 core_sample_rate, |
412 | 12.7k | ixheaace_str_qmf_tabs *pstr_qmf_tab, WORD32 aot) { |
413 | 12.7k | UWORD32 new_bit_rate; |
414 | 12.7k | WORD32 index; |
415 | 12.7k | WORD32 idx_sr; |
416 | 12.7k | WORD32 idx_ch; |
417 | 12.7k | WORD32 idx_entry; |
418 | | |
419 | 12.7k | index = ia_enhaacplus_enc_get_sbr_tuning_table_idx( |
420 | 12.7k | bit_rate, num_ch, core_sample_rate, pstr_qmf_tab, &new_bit_rate, &idx_sr, &idx_ch, |
421 | 12.7k | &idx_entry, |
422 | 12.7k | ((AOT_AAC_ELD == aot) ? pstr_qmf_tab->sbr_tuning_table_ld |
423 | 12.7k | : pstr_qmf_tab->sbr_tuning_table_lc)); |
424 | 12.7k | if (index != IXHEAACE_TABLE_IDX_NOT_FOUND) { |
425 | 11.2k | new_bit_rate = bit_rate; |
426 | 11.2k | } |
427 | | |
428 | 12.7k | return new_bit_rate; |
429 | 12.7k | } |
430 | | |
431 | | VOID ixheaace_adjust_sbr_settings(const ixheaace_pstr_sbr_cfg pstr_config, UWORD32 bit_rate, |
432 | | UWORD32 num_ch, UWORD32 fs_core, UWORD32 trans_fac, |
433 | | UWORD32 std_br, ixheaace_str_qmf_tabs *pstr_qmf_tab, |
434 | 8.80k | WORD32 aot, WORD32 is_esbr_4_1) { |
435 | 8.80k | FLAG table_found = IXHEAACE_TABLE_IDX_NOT_FOUND; |
436 | 8.80k | WORD32 idx_sr = 0; |
437 | 8.80k | WORD32 idx_ch = 0; |
438 | 8.80k | WORD32 idx_entry = 0; |
439 | | /* set the codec settings */ |
440 | 8.80k | pstr_config->codec_settings.bit_rate = bit_rate; |
441 | 8.80k | pstr_config->codec_settings.num_channels = num_ch; |
442 | 8.80k | pstr_config->codec_settings.sample_freq = fs_core; |
443 | 8.80k | pstr_config->codec_settings.trans_fac = trans_fac; |
444 | 8.80k | pstr_config->codec_settings.standard_bitrate = std_br; |
445 | | |
446 | 8.80k | if (bit_rate <= 20000) { |
447 | 2.09k | pstr_config->parametric_coding = 0; |
448 | 2.09k | pstr_config->use_speech_config = 1; |
449 | 2.09k | } |
450 | | |
451 | 8.80k | table_found = ia_enhaacplus_enc_get_sbr_tuning_table_idx( |
452 | 8.80k | bit_rate, num_ch, fs_core, pstr_qmf_tab, NULL, &idx_sr, &idx_ch, &idx_entry, |
453 | 8.80k | ((AOT_AAC_ELD == aot) ? pstr_qmf_tab->sbr_tuning_table_ld |
454 | 8.80k | : pstr_qmf_tab->sbr_tuning_table_lc)); |
455 | | |
456 | 8.80k | if (table_found == IXHEAACE_TABLE_IDX_NOT_FOUND) { |
457 | 472 | if (aot == AOT_USAC) { |
458 | 472 | if (num_ch == 1) { |
459 | 39 | if (bit_rate >= 30000) { |
460 | 6 | pstr_config->start_freq = 7; |
461 | 6 | pstr_config->stop_freq = 9; |
462 | 33 | } else { |
463 | 33 | pstr_config->start_freq = 5; |
464 | 33 | pstr_config->stop_freq = 7; |
465 | 33 | } |
466 | 433 | } else { |
467 | 433 | pstr_config->start_freq = 12; |
468 | 433 | pstr_config->stop_freq = 9; |
469 | 433 | } |
470 | 472 | } |
471 | 8.33k | } else { |
472 | 8.33k | switch (aot) { |
473 | 1.96k | case AOT_AAC_ELD: { |
474 | 1.96k | pstr_config->start_freq = |
475 | 1.96k | pstr_qmf_tab->sbr_tuning_table_ld[idx_sr][idx_ch][idx_entry].freq_band.start_freq; |
476 | 1.96k | pstr_config->stop_freq = |
477 | 1.96k | pstr_qmf_tab->sbr_tuning_table_ld[idx_sr][idx_ch][idx_entry].freq_band.stop_freq; |
478 | | |
479 | 1.96k | pstr_config->sbr_noise_bands = |
480 | 1.96k | pstr_qmf_tab->sbr_tuning_table_ld[idx_sr][idx_ch][idx_entry].noise.num_noise_bands; |
481 | | |
482 | 1.96k | pstr_config->noise_floor_offset = |
483 | 1.96k | pstr_qmf_tab->sbr_tuning_table_ld[idx_sr][idx_ch][idx_entry].noise.noise_floor_offset; |
484 | | |
485 | 1.96k | pstr_config->ana_max_level = |
486 | 1.96k | pstr_qmf_tab->sbr_tuning_table_ld[idx_sr][idx_ch][idx_entry].noise.noise_max_level; |
487 | 1.96k | pstr_config->stereo_mode = |
488 | 1.96k | pstr_qmf_tab->sbr_tuning_table_ld[idx_sr][idx_ch][idx_entry].stereo_mode; |
489 | 1.96k | pstr_config->freq_scale = |
490 | 1.96k | pstr_qmf_tab->sbr_tuning_table_ld[idx_sr][idx_ch][idx_entry].freq_scale; |
491 | 1.96k | break; |
492 | 0 | } |
493 | 6.36k | default: { |
494 | 6.36k | pstr_config->start_freq = |
495 | 6.36k | pstr_qmf_tab->sbr_tuning_table_lc[idx_sr][idx_ch][idx_entry].freq_band.start_freq; |
496 | 6.36k | pstr_config->stop_freq = |
497 | 6.36k | pstr_qmf_tab->sbr_tuning_table_lc[idx_sr][idx_ch][idx_entry].freq_band.stop_freq; |
498 | | |
499 | 6.36k | pstr_config->sbr_noise_bands = |
500 | 6.36k | pstr_qmf_tab->sbr_tuning_table_lc[idx_sr][idx_ch][idx_entry].noise.num_noise_bands; |
501 | | |
502 | 6.36k | pstr_config->noise_floor_offset = |
503 | 6.36k | pstr_qmf_tab->sbr_tuning_table_lc[idx_sr][idx_ch][idx_entry].noise.noise_floor_offset; |
504 | | |
505 | 6.36k | pstr_config->ana_max_level = |
506 | 6.36k | pstr_qmf_tab->sbr_tuning_table_lc[idx_sr][idx_ch][idx_entry].noise.noise_max_level; |
507 | 6.36k | pstr_config->stereo_mode = |
508 | 6.36k | pstr_qmf_tab->sbr_tuning_table_lc[idx_sr][idx_ch][idx_entry].stereo_mode; |
509 | 6.36k | pstr_config->freq_scale = |
510 | 6.36k | pstr_qmf_tab->sbr_tuning_table_lc[idx_sr][idx_ch][idx_entry].freq_scale; |
511 | 6.36k | break; |
512 | 0 | } |
513 | 8.33k | } |
514 | | |
515 | 8.33k | if (pstr_config->sbr_codec == ELD_SBR) { |
516 | 1.96k | pstr_config->send_header_data_time = -1; |
517 | 1.96k | if ((num_ch == NUM_CHANS_MONO) && (bit_rate <= 22000)) { |
518 | 533 | pstr_config->use_low_freq_res = 1; |
519 | 533 | } |
520 | 1.96k | if ((num_ch == NUM_CHANS_STEREO) && (bit_rate <= 48000)) { |
521 | 514 | pstr_config->use_low_freq_res = 1; |
522 | 514 | } |
523 | 1.96k | } |
524 | 6.36k | else { |
525 | 6.36k | if ((num_ch == NUM_CHANS_MONO) && (bit_rate <= 18000)) { |
526 | 966 | pstr_config->use_low_freq_res = 1; |
527 | 966 | } |
528 | 6.36k | if ((num_ch == NUM_CHANS_STEREO) && (bit_rate <= 28000)) { |
529 | 853 | pstr_config->use_low_freq_res = 1; |
530 | 853 | } |
531 | 6.36k | } |
532 | 8.33k | if (bit_rate <= 20000) { |
533 | 2.08k | pstr_config->parametric_coding = 0; |
534 | 2.08k | pstr_config->use_speech_config = 1; |
535 | 2.08k | } |
536 | | |
537 | 8.33k | if (pstr_config->use_ps) { |
538 | 354 | pstr_config->ps_mode = ixheaace_get_ps_mode(bit_rate); |
539 | 354 | } |
540 | 8.33k | } |
541 | | |
542 | 8.80k | if (is_esbr_4_1) { |
543 | 862 | pstr_config->start_freq = 10; |
544 | 862 | pstr_config->stop_freq = 11; |
545 | 862 | } |
546 | 8.80k | } |
547 | | |
548 | 8.84k | VOID ixheaace_initialize_sbr_defaults(ixheaace_pstr_sbr_cfg pstr_config) { |
549 | 8.84k | pstr_config->send_header_data_time = 500; |
550 | 8.84k | pstr_config->crc_sbr = 0; |
551 | 8.84k | pstr_config->tran_thr = 13000; |
552 | 8.84k | pstr_config->detect_missing_harmonics = 1; |
553 | 8.84k | pstr_config->parametric_coding = 1; |
554 | 8.84k | pstr_config->use_speech_config = 0; |
555 | | |
556 | 8.84k | pstr_config->sbr_data_extra = 0; |
557 | 8.84k | pstr_config->amp_res = IXHEAACE_SBR_AMP_RES_3_0; |
558 | 8.84k | pstr_config->tran_fc = 0; |
559 | 8.84k | pstr_config->tran_det_mode = 1; |
560 | 8.84k | pstr_config->spread = 1; |
561 | 8.84k | pstr_config->stat = 0; |
562 | 8.84k | pstr_config->e = 1; |
563 | 8.84k | pstr_config->delta_t_across_frames = 1; |
564 | 8.84k | pstr_config->df_edge_1st_env = 0.3f; |
565 | 8.84k | pstr_config->df_edge_incr = 0.3f; |
566 | | |
567 | 8.84k | pstr_config->sbr_invf_mode = IXHEAACE_INVF_SWITCHED; |
568 | 8.84k | pstr_config->sbr_xpos_mode = IXHEAACE_XPOS_LC; |
569 | 8.84k | pstr_config->sbr_xpos_ctrl = SBR_XPOS_CTRL_DEFAULT; |
570 | 8.84k | pstr_config->sbr_xpos_lvl = 0; |
571 | | |
572 | 8.84k | pstr_config->use_ps = 0; |
573 | 8.84k | pstr_config->ps_mode = -1; |
574 | | |
575 | 8.84k | pstr_config->stereo_mode = IXHEAACE_SBR_MODE_SWITCH_LRC; |
576 | 8.84k | pstr_config->ana_max_level = 6; |
577 | 8.84k | pstr_config->noise_floor_offset = 0; |
578 | 8.84k | pstr_config->start_freq = 5; |
579 | 8.84k | pstr_config->stop_freq = 9; |
580 | | |
581 | 8.84k | pstr_config->freq_scale = SBR_FREQ_SCALE_DEFAULT; |
582 | 8.84k | pstr_config->alter_scale = SBR_ALTER_SCALE_DEFAULT; |
583 | 8.84k | pstr_config->sbr_noise_bands = SBR_NOISE_BANDS_DEFAULT; |
584 | | |
585 | 8.84k | pstr_config->sbr_limiter_bands = SBR_LIMITER_BANDS_DEFAULT; |
586 | 8.84k | pstr_config->sbr_limiter_gains = SBR_LIMITER_GAINS_DEFAULT; |
587 | 8.84k | pstr_config->sbr_interpol_freq = SBR_INTERPOL_FREQ_DEFAULT; |
588 | 8.84k | pstr_config->sbr_smoothing_length = SBR_SMOOTHING_LENGTH_DEFAULT; |
589 | 8.84k | pstr_config->is_ld_sbr = 0; |
590 | 8.84k | pstr_config->is_esbr = 0; |
591 | 8.84k | pstr_config->frame_flag_960 = 0; |
592 | 8.84k | pstr_config->frame_flag_480 = 0; |
593 | 8.84k | pstr_config->hq_esbr = 0; |
594 | 8.84k | pstr_config->sbr_pvc_active = 0; |
595 | 8.84k | pstr_config->sbr_harmonic = 0; |
596 | 8.84k | pstr_config->sbr_ratio_idx = 0; // NO_SBR |
597 | 8.84k | pstr_config->use_low_freq_res = 0; |
598 | 8.84k | } |
599 | | |
600 | | static IA_ERRORCODE ia_enhaacplus_enc_update_freq_band_tab( |
601 | | ixheaace_pstr_sbr_config_data pstr_sbr_cfg, ixheaace_pstr_sbr_hdr_data pstr_sbr_hdr, |
602 | 8.37k | WORD32 num_qmf_ch) { |
603 | 8.37k | IA_ERRORCODE err_code = IA_NO_ERROR; |
604 | 8.37k | WORD32 k0, k2; |
605 | 8.37k | WORD32 samp_freq = pstr_sbr_cfg->sample_freq; |
606 | 8.37k | if ((pstr_sbr_cfg->sbr_codec == USAC_SBR) && |
607 | 8.37k | (pstr_sbr_cfg->sbr_ratio_idx == USAC_SBR_RATIO_INDEX_4_1)) { |
608 | 862 | samp_freq = samp_freq / 2; |
609 | 862 | } |
610 | 8.37k | err_code = ixheaace_find_start_and_stop_band( |
611 | 8.37k | samp_freq, num_qmf_ch, pstr_sbr_hdr->sbr_start_freq, pstr_sbr_hdr->sbr_stop_freq, |
612 | 8.37k | pstr_sbr_hdr->sample_rate_mode, &k0, &k2, pstr_sbr_cfg->sbr_ratio_idx, |
613 | 8.37k | pstr_sbr_cfg->sbr_codec); |
614 | 8.37k | if (err_code) { |
615 | 32 | return err_code; |
616 | 32 | } |
617 | | |
618 | 8.34k | err_code = ixheaace_update_freq_scale( |
619 | 8.34k | pstr_sbr_cfg->ptr_v_k_master, &pstr_sbr_cfg->num_master, k0, k2, pstr_sbr_hdr->freq_scale, |
620 | 8.34k | pstr_sbr_hdr->alter_scale, pstr_sbr_hdr->sample_rate_mode); |
621 | 8.34k | if (err_code) { |
622 | 7 | return err_code; |
623 | 7 | } |
624 | | |
625 | 8.33k | pstr_sbr_hdr->sbr_xover_band = 0; |
626 | | |
627 | 8.33k | ixheaace_update_high_res(pstr_sbr_cfg->ptr_freq_band_tab[HI], &pstr_sbr_cfg->num_scf[HI], |
628 | 8.33k | pstr_sbr_cfg->ptr_v_k_master, pstr_sbr_cfg->num_master, |
629 | 8.33k | &pstr_sbr_hdr->sbr_xover_band, pstr_sbr_hdr->sample_rate_mode, |
630 | 8.33k | num_qmf_ch); |
631 | | |
632 | 8.33k | ixheaace_update_low_res(pstr_sbr_cfg->ptr_freq_band_tab[LO], &pstr_sbr_cfg->num_scf[LO], |
633 | 8.33k | pstr_sbr_cfg->ptr_freq_band_tab[HI], pstr_sbr_cfg->num_scf[HI]); |
634 | | |
635 | 8.33k | pstr_sbr_cfg->xover_freq = |
636 | 8.33k | (pstr_sbr_cfg->ptr_freq_band_tab[LOW_RES][0] * pstr_sbr_cfg->sample_freq / num_qmf_ch + |
637 | 8.33k | 1) >> |
638 | 8.33k | 1; |
639 | | |
640 | 8.33k | return err_code; |
641 | 8.34k | } |
642 | | |
643 | 10.2k | VOID ia_enhaacplus_enc_init_sbr_tabs(ixheaace_str_sbr_tabs *pstr_sbr_tabs) { |
644 | 10.2k | pstr_sbr_tabs->ptr_ps_tab = (ixheaace_str_ps_tab *)&ia_enhaacplus_enc_ps_tab; |
645 | 10.2k | pstr_sbr_tabs->ptr_qmf_tab = (ixheaace_str_qmf_tabs *)&ixheaace_qmf_tab; |
646 | 10.2k | pstr_sbr_tabs->ptr_sbr_huff_tab = (ixheaace_str_sbr_huff_tabs *)&ixheaace_sbr_huff_tab; |
647 | 10.2k | pstr_sbr_tabs->ptr_resamp_tab = |
648 | 10.2k | (ixheaace_resampler_table *)&ixheaace_resamp_2_to_1_iir_filt_params; |
649 | 10.2k | pstr_sbr_tabs->ptr_esbr_sfb_tab = (ixheaace_str_esbr_sfb_bin_tabs *)&ia_esbr_sfb_bin_tabs; |
650 | 10.2k | } |
651 | | |
652 | | IA_ERRORCODE |
653 | | ixheaace_env_encode_frame(ixheaace_pstr_sbr_enc pstr_env_encoder, FLOAT32 *ptr_samples, |
654 | | FLOAT32 *ptr_core_buffer, UWORD32 time_sn_stride, |
655 | | UWORD8 *ptr_num_anc_bytes, UWORD8 *ptr_anc_data, |
656 | | ixheaace_str_sbr_tabs *pstr_sbr_tab, |
657 | | ixheaace_comm_tables *pstr_common_tab, UWORD8 *ptr_mps_data, |
658 | 482k | WORD32 mps_bits, WORD32 flag_fl_small, WORD32 *usac_stat_bits) { |
659 | 482k | IA_ERRORCODE err_code = IA_NO_ERROR; |
660 | | |
661 | 482k | if (pstr_env_encoder != NULL) { |
662 | 482k | ixheaace_pstr_sbr_bitstream_data pstr_sbr_bs = &pstr_env_encoder->str_sbr_bs; |
663 | | |
664 | 482k | pstr_sbr_bs->header_active = 0; |
665 | 482k | if ((pstr_env_encoder->str_sbr_cfg.is_ld_sbr) && |
666 | 482k | (pstr_sbr_bs->count_send_header_data == pstr_sbr_bs->nr_send_header_data - 1)) { |
667 | 1.73k | pstr_sbr_bs->header_active = 1; |
668 | 1.73k | } |
669 | | |
670 | 482k | if (pstr_sbr_bs->count_send_header_data == 0) { |
671 | 49.7k | pstr_sbr_bs->header_active = 1; |
672 | 49.7k | } |
673 | | |
674 | 482k | if (pstr_sbr_bs->nr_send_header_data == 0) { |
675 | 120k | pstr_sbr_bs->count_send_header_data = 1; |
676 | 362k | } else { |
677 | 362k | if (pstr_env_encoder->str_sbr_cfg.is_ld_sbr) { |
678 | 0 | if (pstr_sbr_bs->count_send_header_data >= 0) { |
679 | 0 | pstr_sbr_bs->count_send_header_data++; |
680 | |
|
681 | 0 | pstr_sbr_bs->count_send_header_data %= pstr_sbr_bs->nr_send_header_data; |
682 | 0 | } |
683 | 362k | } else { |
684 | 362k | pstr_sbr_bs->count_send_header_data++; |
685 | | |
686 | 362k | pstr_sbr_bs->count_send_header_data %= pstr_sbr_bs->nr_send_header_data; |
687 | 362k | } |
688 | 362k | } |
689 | | |
690 | 482k | ixheaace_init_sbr_bitstream( |
691 | 482k | &pstr_env_encoder->str_cmon_data, (UWORD8 *)pstr_env_encoder->sbr_payload, |
692 | 482k | sizeof(pstr_env_encoder->sbr_payload), pstr_env_encoder->str_sbr_bs.crc_active, |
693 | 482k | pstr_env_encoder->str_sbr_cfg.sbr_codec); |
694 | | |
695 | 482k | err_code = ixheaace_extract_sbr_envelope(ptr_samples, ptr_core_buffer, time_sn_stride, |
696 | 482k | pstr_env_encoder, pstr_sbr_tab, pstr_common_tab, |
697 | 482k | flag_fl_small); |
698 | 482k | if (err_code) { |
699 | 14.1k | return err_code; |
700 | 14.1k | } |
701 | | |
702 | 468k | if (mps_bits) { |
703 | 123k | WORD32 num_bytes; |
704 | 123k | if (pstr_env_encoder->str_sbr_cfg.sbr_codec == ELD_SBR) { |
705 | 56.8k | ixheaace_write_bits(&pstr_env_encoder->str_cmon_data.str_sbr_bit_buf, |
706 | 56.8k | IXHEAACE_MPS_EXT_LDSAC_DATA, 4); |
707 | 56.8k | ixheaace_write_bits(&pstr_env_encoder->str_cmon_data.str_sbr_bit_buf, *ptr_mps_data++, 4); |
708 | 56.8k | } |
709 | 123k | num_bytes = mps_bits >> 3; |
710 | 1.12M | for (WORD32 k = 0; k < num_bytes; k++) { |
711 | 1.00M | ixheaace_write_bits(&pstr_env_encoder->str_cmon_data.str_sbr_bit_buf, *ptr_mps_data++, 8); |
712 | 1.00M | } |
713 | 123k | if (mps_bits & 0x7) { |
714 | 100k | ixheaace_write_bits(&pstr_env_encoder->str_cmon_data.str_sbr_bit_buf, |
715 | 100k | (*ptr_mps_data++) >> (8 - (mps_bits & 0x7)), mps_bits & 0x7); |
716 | 100k | } |
717 | 123k | } |
718 | | |
719 | 468k | ixheaace_assemble_sbr_bitstream(&pstr_env_encoder->str_cmon_data, |
720 | 468k | pstr_env_encoder->str_sbr_cfg.sbr_codec); |
721 | | |
722 | 468k | pstr_env_encoder->sbr_payload_size = |
723 | 468k | ((ia_enhaacplus_enc_get_bits_available(&pstr_env_encoder->str_cmon_data.str_sbr_bit_buf) + |
724 | 468k | 7) / |
725 | 468k | 8); |
726 | | |
727 | 468k | if (pstr_env_encoder->sbr_payload_size > IXHEAACE_MAX_PAYLOAD_SIZE) { |
728 | 0 | pstr_env_encoder->sbr_payload_size = 0; |
729 | 0 | } |
730 | | |
731 | 468k | if (ptr_anc_data) { |
732 | 468k | *ptr_num_anc_bytes = (UWORD8)pstr_env_encoder->sbr_payload_size; |
733 | 468k | memcpy(ptr_anc_data, pstr_env_encoder->sbr_payload, pstr_env_encoder->sbr_payload_size); |
734 | 468k | } |
735 | 468k | if (usac_stat_bits) { |
736 | 206k | *usac_stat_bits = pstr_env_encoder->str_cmon_data.sbr_hdr_bits + |
737 | 206k | pstr_env_encoder->str_cmon_data.sbr_data_bits; |
738 | 206k | } |
739 | 468k | } |
740 | 468k | return err_code; |
741 | 482k | } |
742 | | |
743 | 25.8k | WORD32 ixheaace_sbr_enc_scr_size(VOID) { |
744 | 25.8k | return IXHEAAC_GET_SIZE_ALIGNED(sizeof(ixheaace_str_sbr_enc_scratch), BYTE_ALIGN_8); |
745 | 25.8k | } |
746 | | |
747 | | VOID ia_enhaacplus_enc_get_scratch_bufs(VOID *ptr_scr, FLOAT32 **ptr_shared_buf1, |
748 | 916k | FLOAT32 **ptr_shared_buf2) { |
749 | 916k | ixheaace_str_sbr_enc_scratch *ptr_sbr_enc_scr = (ixheaace_str_sbr_enc_scratch *)ptr_scr; |
750 | | |
751 | 916k | *ptr_shared_buf1 = ptr_sbr_enc_scr->sbr_env_r_buf; |
752 | 916k | *ptr_shared_buf2 = ptr_sbr_enc_scr->sbr_env_i_buf; |
753 | 916k | } |
754 | | |
755 | | VOID ia_enhaacplus_enc_get_shared_bufs(VOID *ptr_scr, WORD32 **ptr_shared_buf1, |
756 | | WORD32 **ptr_shared_buf2, WORD32 **ptr_shared_buf3, |
757 | 7.23k | WORD8 **ptr_shared_buf4, WORD32 aacenc_blocksize) { |
758 | 7.23k | ixheaace_str_sbr_enc_scratch *ptr_sbr_enc_scr = (ixheaace_str_sbr_enc_scratch *)ptr_scr; |
759 | | |
760 | 7.23k | *ptr_shared_buf1 = (WORD32 *)ptr_sbr_enc_scr->ps_buf3; |
761 | 7.23k | *ptr_shared_buf2 = (WORD32 *)ptr_sbr_enc_scr->sbr_env_r_buf; |
762 | 7.23k | *ptr_shared_buf3 = (WORD32 *)ptr_sbr_enc_scr->sbr_env_i_buf; |
763 | 7.23k | *ptr_shared_buf4 = |
764 | 7.23k | (WORD8 *)&ptr_sbr_enc_scr |
765 | 7.23k | ->sbr_env_i_buf[IXHEAACE_QMF_TIME_SLOTS * IXHEAACE_QMF_CHANNELS + aacenc_blocksize]; |
766 | 7.23k | } |
767 | | |
768 | 273k | VOID ixheaace_sbr_set_scratch_ptr(ixheaace_pstr_sbr_enc pstr_env_enc, VOID *ptr_scr) { |
769 | 273k | pstr_env_enc->ptr_sbr_enc_scr = ptr_scr; |
770 | 273k | } |
771 | | |
772 | 19.1k | WORD32 ixheaace_sbr_enc_pers_size(WORD32 num_ch, WORD32 use_ps, WORD32 harmonic_sbr) { |
773 | 19.1k | WORD32 num_bytes; |
774 | 19.1k | num_bytes = IXHEAAC_GET_SIZE_ALIGNED(sizeof(struct ixheaace_str_sbr_enc), BYTE_ALIGN_8); |
775 | 19.1k | num_bytes += (IXHEAAC_GET_SIZE_ALIGNED(sizeof(struct ixheaace_str_enc_channel), BYTE_ALIGN_8) * |
776 | 19.1k | num_ch); |
777 | 19.1k | num_bytes += IXHEAAC_GET_SIZE_ALIGNED(sizeof(ixheaace_pvc_enc), BYTE_ALIGN_8); |
778 | 19.1k | num_bytes += (IXHEAAC_GET_SIZE_ALIGNED(2 * sizeof(FLOAT32) * QMF_FILTER_LENGTH, BYTE_ALIGN_8) * |
779 | 19.1k | num_ch); |
780 | 19.1k | if (1 == harmonic_sbr) { |
781 | 3.33k | num_bytes += (IXHEAAC_GET_SIZE_ALIGNED(sizeof(ixheaace_str_hbe_enc), BYTE_ALIGN_8) * num_ch); |
782 | 3.33k | num_bytes += (IXHEAAC_GET_SIZE_ALIGNED(sizeof(ixheaace_str_esbr_hbe_txposer), BYTE_ALIGN_8) * |
783 | 3.33k | num_ch); |
784 | 3.33k | num_bytes += (IXHEAAC_GET_SIZE_ALIGNED(IXHEAACE_MAX_HBE_PERSISTENT_SIZE, BYTE_ALIGN_8) * |
785 | 3.33k | num_ch); |
786 | 3.33k | num_bytes += IXHEAAC_GET_SIZE_ALIGNED(ESBR_RESAMP_SAMPLES * sizeof(FLOAT32), BYTE_ALIGN_8); |
787 | 3.33k | } |
788 | 19.1k | num_bytes += (IXHEAAC_GET_SIZE_ALIGNED(sizeof(FLOAT32) * 5 * NO_OF_ESTIMATES * |
789 | 19.1k | MAXIMUM_FREQ_COEFFS, BYTE_ALIGN_8) * num_ch); |
790 | | |
791 | 19.1k | num_bytes += (IXHEAAC_GET_SIZE_ALIGNED(sizeof(FLOAT32) * MAX_QMF_TIME_SLOTS * |
792 | 19.1k | IXHEAACE_QMF_CHANNELS, BYTE_ALIGN_8) * num_ch); |
793 | | |
794 | 19.1k | if (use_ps) { |
795 | 708 | num_bytes += IXHEAAC_GET_SIZE_ALIGNED(sizeof(struct ixheaace_str_enc_channel), BYTE_ALIGN_8); |
796 | 708 | num_bytes += IXHEAAC_GET_SIZE_ALIGNED(sizeof(struct ixheaace_ps_enc), BYTE_ALIGN_8); |
797 | 708 | num_bytes += IXHEAAC_GET_SIZE_ALIGNED(sizeof(FLOAT32) * QMF_FILTER_LENGTH, BYTE_ALIGN_8); |
798 | | |
799 | 708 | num_bytes += IXHEAAC_GET_SIZE_ALIGNED(sizeof(WORD32) * 5 * NO_OF_ESTIMATES * |
800 | 708 | MAXIMUM_FREQ_COEFFS, BYTE_ALIGN_8); |
801 | | |
802 | | /*shared between spectral_band_replication_envYBuffer_fix and IIC IDD PS data buffers*/ |
803 | 708 | num_bytes += IXHEAAC_GET_SIZE_ALIGNED(sizeof(WORD32) * IXHEAACE_QMF_TIME_SLOTS * |
804 | 708 | IXHEAACE_QMF_CHANNELS, BYTE_ALIGN_8); |
805 | 708 | } |
806 | 19.1k | num_bytes += IXHEAAC_GET_SIZE_ALIGNED(sizeof(ixheaace_str_sbr_qmf_filter_bank), BYTE_ALIGN_8); |
807 | 19.1k | return num_bytes; |
808 | 19.1k | } |
809 | | |
810 | | VOID ia_enhaacplus_enc_sbr_set_persist_buf(WORD8 *ptr_base, WORD32 num_ch, WORD32 use_ps, |
811 | 8.37k | WORD32 harmonic_sbr) { |
812 | 8.37k | struct ixheaace_str_sbr_enc *pstr_env_enc; |
813 | 8.37k | WORD8 *ptr_curr_mem = ptr_base + |
814 | 8.37k | IXHEAAC_GET_SIZE_ALIGNED(sizeof(struct ixheaace_str_sbr_enc), BYTE_ALIGN_8); |
815 | 8.37k | WORD32 i; |
816 | | |
817 | 8.37k | pstr_env_enc = (struct ixheaace_str_sbr_enc *)ptr_base; |
818 | | |
819 | 20.6k | for (i = 0; i < num_ch; i++) { |
820 | 12.2k | pstr_env_enc->pstr_env_channel[i] = (struct ixheaace_str_enc_channel *)(ptr_curr_mem); |
821 | 12.2k | ptr_curr_mem = ptr_curr_mem + |
822 | 12.2k | IXHEAAC_GET_SIZE_ALIGNED(sizeof(struct ixheaace_str_enc_channel), BYTE_ALIGN_8); |
823 | 12.2k | } |
824 | | |
825 | 20.6k | for (i = 0; i < num_ch; i++) { |
826 | 12.2k | pstr_env_enc->pstr_env_channel[i]->str_sbr_qmf.ptr_sbr_qmf_states_ana = |
827 | 12.2k | (FLOAT32 *)ptr_curr_mem; |
828 | 12.2k | ptr_curr_mem += IXHEAAC_GET_SIZE_ALIGNED( |
829 | 12.2k | sizeof(pstr_env_enc->pstr_env_channel[i]->str_sbr_qmf.ptr_sbr_qmf_states_ana[0]) * |
830 | 12.2k | QMF_FILTER_LENGTH, BYTE_ALIGN_8); |
831 | 12.2k | } |
832 | 8.37k | if (!use_ps) { |
833 | 8.02k | pstr_env_enc->ptr_common_buffer1 = (WORD32 *)ptr_curr_mem; |
834 | 8.02k | ptr_curr_mem += IXHEAAC_GET_SIZE_ALIGNED(sizeof(pstr_env_enc->ptr_common_buffer1[0]) * |
835 | 8.02k | num_ch * 5 * NO_OF_ESTIMATES * MAXIMUM_FREQ_COEFFS, BYTE_ALIGN_8); |
836 | | |
837 | 8.02k | pstr_env_enc->ptr_common_buffer2 = (WORD32 *)ptr_curr_mem; |
838 | 8.02k | ptr_curr_mem += IXHEAAC_GET_SIZE_ALIGNED(sizeof(pstr_env_enc->ptr_common_buffer2[0]) * |
839 | 8.02k | num_ch * MAX_QMF_TIME_SLOTS * IXHEAACE_QMF_CHANNELS, BYTE_ALIGN_8); |
840 | 8.02k | } else { |
841 | 354 | pstr_env_enc->ptr_common_buffer1 = (WORD32 *)ptr_curr_mem; |
842 | 354 | ptr_curr_mem += IXHEAAC_GET_SIZE_ALIGNED(2 * sizeof(pstr_env_enc->ptr_common_buffer1[0]) * |
843 | 354 | 5 * NO_OF_ESTIMATES * MAXIMUM_FREQ_COEFFS, BYTE_ALIGN_8); |
844 | | |
845 | 354 | pstr_env_enc->ptr_common_buffer2 = (WORD32 *)ptr_curr_mem; |
846 | 354 | ptr_curr_mem += IXHEAAC_GET_SIZE_ALIGNED(2 * sizeof(pstr_env_enc->ptr_common_buffer2[0]) * |
847 | 354 | IXHEAACE_QMF_TIME_SLOTS * IXHEAACE_QMF_CHANNELS, BYTE_ALIGN_8); |
848 | 354 | } |
849 | | // PVC encoder |
850 | 8.37k | pstr_env_enc->pstr_pvc_enc = (ixheaace_pvc_enc *)ptr_curr_mem; |
851 | 8.37k | ptr_curr_mem = ptr_curr_mem + IXHEAAC_GET_SIZE_ALIGNED(sizeof(ixheaace_pvc_enc), BYTE_ALIGN_8); |
852 | | // Harmonic SBR |
853 | 8.37k | if (1 == harmonic_sbr) { |
854 | 4.08k | for (i = 0; i < num_ch; i++) { |
855 | 2.43k | pstr_env_enc->pstr_env_channel[i]->pstr_hbe_enc = (ixheaace_str_hbe_enc *)ptr_curr_mem; |
856 | 2.43k | ptr_curr_mem = ptr_curr_mem + |
857 | 2.43k | IXHEAAC_GET_SIZE_ALIGNED(sizeof(ixheaace_str_hbe_enc), BYTE_ALIGN_8); |
858 | 2.43k | pstr_env_enc->pstr_env_channel[i]->pstr_hbe_enc->pstr_hbe_txposer = |
859 | 2.43k | (ixheaace_str_esbr_hbe_txposer *)ptr_curr_mem; |
860 | 2.43k | ptr_curr_mem = ptr_curr_mem + |
861 | 2.43k | IXHEAAC_GET_SIZE_ALIGNED(sizeof(ixheaace_str_esbr_hbe_txposer), BYTE_ALIGN_8); |
862 | 2.43k | pstr_env_enc->pstr_env_channel[i]->pstr_hbe_enc->ptr_hbe_txposer_buffers = |
863 | 2.43k | (VOID *)ptr_curr_mem; |
864 | 2.43k | ptr_curr_mem = ptr_curr_mem + IXHEAACE_MAX_HBE_PERSISTENT_SIZE; |
865 | 2.43k | } |
866 | 1.64k | pstr_env_enc->ptr_hbe_resample_buf = (FLOAT32 *)ptr_curr_mem; |
867 | 1.64k | ptr_curr_mem = ptr_curr_mem + IXHEAAC_GET_SIZE_ALIGNED( |
868 | 1.64k | (ESBR_RESAMP_SAMPLES * sizeof(pstr_env_enc->ptr_hbe_resample_buf[0])), BYTE_ALIGN_8); |
869 | 1.64k | } |
870 | 8.37k | if (use_ps) { |
871 | 354 | pstr_env_enc->pstr_env_channel[1] = (struct ixheaace_str_enc_channel *)(ptr_curr_mem); |
872 | 354 | ptr_curr_mem = ptr_curr_mem + |
873 | 354 | IXHEAAC_GET_SIZE_ALIGNED(sizeof(struct ixheaace_str_enc_channel), BYTE_ALIGN_8); |
874 | 354 | memset(pstr_env_enc->pstr_env_channel[1], 0, sizeof(struct ixheaace_str_enc_channel)); |
875 | | |
876 | 354 | pstr_env_enc->pstr_env_channel[1]->str_sbr_qmf.ptr_sbr_qmf_states_ana = |
877 | 354 | (FLOAT32 *)ptr_curr_mem; |
878 | 354 | ptr_curr_mem += IXHEAAC_GET_SIZE_ALIGNED( |
879 | 354 | sizeof(pstr_env_enc->pstr_env_channel[1]->str_sbr_qmf.ptr_sbr_qmf_states_ana[0]) * |
880 | 354 | QMF_FILTER_LENGTH, BYTE_ALIGN_8); |
881 | 354 | memset(pstr_env_enc->pstr_env_channel[1]->str_sbr_qmf.ptr_sbr_qmf_states_ana, 0, |
882 | 354 | sizeof(pstr_env_enc->pstr_env_channel[1]->str_sbr_qmf.ptr_sbr_qmf_states_ana[0]) * |
883 | 354 | QMF_FILTER_LENGTH); |
884 | | |
885 | 354 | pstr_env_enc->pstr_ps_enc = (struct ixheaace_ps_enc *)(ptr_curr_mem); |
886 | 354 | ptr_curr_mem = ptr_curr_mem + |
887 | 354 | IXHEAAC_GET_SIZE_ALIGNED(sizeof(struct ixheaace_ps_enc), BYTE_ALIGN_8); |
888 | 354 | memset(pstr_env_enc->pstr_ps_enc, 0, sizeof(struct ixheaace_ps_enc)); |
889 | 354 | } |
890 | 8.37k | pstr_env_enc->pstr_synthesis_qmf_bank = (ixheaace_str_sbr_qmf_filter_bank *)(ptr_curr_mem); |
891 | 8.37k | memset(pstr_env_enc->pstr_synthesis_qmf_bank, 0, sizeof(ixheaace_str_sbr_qmf_filter_bank)); |
892 | | |
893 | 8.37k | pstr_env_enc->pstr_synthesis_qmf_bank->ptr_sbr_qmf_states_ana = NULL; |
894 | 8.37k | } |
895 | | |
896 | | IA_ERRORCODE |
897 | | ixheaace_env_open(ixheaace_pstr_sbr_enc *pstr_env_encoder, ixheaace_pstr_sbr_cfg params, |
898 | | WORD32 *ptr_core_bw, WORD8 *ptr_sbr_scratch, |
899 | | ixheaace_str_sbr_tabs *pstr_sbr_tab, |
900 | 8.37k | ixheaace_pstr_sbr_hdr_data *pstr_sbr_config) { |
901 | 8.37k | ixheaace_pstr_sbr_enc pstr_env_enc; |
902 | 8.37k | WORD32 ch; |
903 | 8.37k | IA_ERRORCODE err_code = IA_NO_ERROR; |
904 | | |
905 | 8.37k | pstr_env_enc = *pstr_env_encoder; |
906 | | |
907 | 8.37k | memset(pstr_env_enc, 0, sizeof(struct ixheaace_str_sbr_enc)); |
908 | | |
909 | 8.37k | *pstr_sbr_config = &pstr_env_enc->str_sbr_hdr; |
910 | | |
911 | 8.37k | ixheaace_sbr_set_scratch_ptr(pstr_env_enc, ptr_sbr_scratch); |
912 | | |
913 | 8.37k | ia_enhaacplus_enc_sbr_set_persist_buf((WORD8 *)pstr_env_enc, |
914 | 8.37k | params->codec_settings.num_channels, params->use_ps, |
915 | 8.37k | params->sbr_harmonic); |
916 | | |
917 | 8.37k | if ((params->codec_settings.num_channels < 1) || |
918 | 8.37k | (params->codec_settings.num_channels > IXHEAACE_MAX_CH_IN_BS_ELE)) { |
919 | 0 | return IA_EXHEAACE_INIT_FATAL_SBR_INVALID_NUM_CHANNELS; |
920 | 0 | } |
921 | | |
922 | 8.37k | pstr_env_enc->str_sbr_cfg.ptr_freq_band_tab[LO] = |
923 | 8.37k | pstr_env_enc->str_sbr_cfg.sbr_freq_band_tab_lo; |
924 | | |
925 | 8.37k | memset( |
926 | 8.37k | pstr_env_enc->str_sbr_cfg.ptr_freq_band_tab[LO], 0, |
927 | 8.37k | sizeof(pstr_env_enc->str_sbr_cfg.ptr_freq_band_tab[LO][0]) * (MAXIMUM_FREQ_COEFFS / 2 + 1)); |
928 | | |
929 | 8.37k | pstr_env_enc->str_sbr_cfg.ptr_freq_band_tab[HI] = |
930 | 8.37k | pstr_env_enc->str_sbr_cfg.sbr_freq_band_tab_hi; |
931 | | |
932 | 8.37k | memset(pstr_env_enc->str_sbr_cfg.ptr_freq_band_tab[HI], 0, |
933 | 8.37k | sizeof(pstr_env_enc->str_sbr_cfg.ptr_freq_band_tab[HI][0]) * (MAXIMUM_FREQ_COEFFS + 1)); |
934 | | |
935 | 8.37k | pstr_env_enc->str_sbr_cfg.ptr_v_k_master = pstr_env_enc->str_sbr_cfg.sbr_v_k_master; |
936 | | |
937 | 8.37k | memset(pstr_env_enc->str_sbr_cfg.ptr_v_k_master, 0, |
938 | 8.37k | sizeof(pstr_env_enc->str_sbr_cfg.ptr_v_k_master[0]) * (MAXIMUM_FREQ_COEFFS + 1)); |
939 | | |
940 | 8.37k | ia_enhaacplus_enc_create_bitbuffer(&pstr_env_enc->str_cmon_data.str_sbr_bit_buf, |
941 | 8.37k | (UWORD8 *)pstr_env_enc->sbr_payload, |
942 | 8.37k | sizeof(pstr_env_enc->sbr_payload)); |
943 | | |
944 | 8.37k | pstr_env_enc->str_cmon_data.prev_bit_buf_read_offset = 0; |
945 | 8.37k | pstr_env_enc->str_cmon_data.prev_bit_buf_write_offset = 0; |
946 | | |
947 | 8.37k | ia_enhaacplus_enc_create_bitbuffer(&pstr_env_enc->str_cmon_data.str_sbr_bit_buf_prev, |
948 | 8.37k | (UWORD8 *)pstr_env_enc->sbr_payload_prev, |
949 | 8.37k | sizeof(pstr_env_enc->sbr_payload)); |
950 | | |
951 | 8.37k | pstr_env_enc->str_cmon_data.str_sbr_bit_buf_prev.ptr_read_next = |
952 | 8.37k | pstr_env_enc->str_cmon_data.str_sbr_bit_buf_prev.ptr_bit_buf_base + |
953 | 8.37k | pstr_env_enc->str_cmon_data.prev_bit_buf_read_offset; |
954 | 8.37k | pstr_env_enc->str_cmon_data.str_sbr_bit_buf_prev.ptr_write_next = |
955 | 8.37k | pstr_env_enc->str_cmon_data.str_sbr_bit_buf_prev.ptr_bit_buf_base + |
956 | 8.37k | pstr_env_enc->str_cmon_data.prev_bit_buf_write_offset; |
957 | | |
958 | 8.37k | pstr_env_enc->str_sbr_cfg.num_ch = params->codec_settings.num_channels; |
959 | 8.37k | pstr_env_enc->str_sbr_cfg.is_ld_sbr = params->is_ld_sbr; |
960 | 8.37k | pstr_env_enc->str_sbr_cfg.sbr_codec = params->sbr_codec; |
961 | 8.37k | pstr_env_enc->str_sbr_cfg.is_esbr = params->is_esbr; |
962 | 8.37k | if (pstr_env_enc->str_sbr_cfg.sbr_codec == USAC_SBR) { |
963 | 3.87k | pstr_env_enc->str_sbr_cfg.sbr_ratio_idx = params->sbr_ratio_idx; |
964 | 3.87k | } |
965 | 8.37k | pstr_env_enc->str_sbr_cfg.stereo_mode = |
966 | 8.37k | (params->codec_settings.num_channels == 2) ? params->stereo_mode : IXHEAACE_SBR_MODE_MONO; |
967 | | |
968 | 8.37k | if (params->codec_settings.sample_freq <= 24000) { |
969 | 7.62k | pstr_env_enc->str_sbr_hdr.sample_rate_mode = IXHEAACE_DUAL_RATE; |
970 | 7.62k | if (params->sbr_codec == USAC_SBR) { |
971 | 3.12k | pstr_env_enc->str_sbr_cfg.sample_freq = 2 * params->codec_settings.sample_freq; |
972 | 3.12k | if (USAC_SBR_RATIO_INDEX_4_1 == params->sbr_ratio_idx) { |
973 | 862 | pstr_env_enc->str_sbr_cfg.sample_freq = 4 * params->codec_settings.sample_freq; |
974 | 862 | pstr_env_enc->str_sbr_hdr.sample_rate_mode = IXHEAACE_QUAD_RATE; |
975 | 862 | } |
976 | 4.50k | } else { |
977 | 4.50k | pstr_env_enc->str_sbr_cfg.sample_freq = 2 * params->codec_settings.sample_freq; |
978 | 4.50k | } |
979 | 7.62k | } else { |
980 | 754 | pstr_env_enc->str_sbr_hdr.sample_rate_mode = IXHEAACE_SINGLE_RATE; |
981 | 754 | pstr_env_enc->str_sbr_cfg.sample_freq = params->codec_settings.sample_freq; |
982 | 754 | } |
983 | 8.37k | if (params->is_ld_sbr) { |
984 | 1.78k | pstr_env_enc->str_sbr_bs.count_send_header_data = -1; |
985 | 6.59k | } else { |
986 | 6.59k | pstr_env_enc->str_sbr_bs.count_send_header_data = 0; |
987 | 6.59k | } |
988 | 8.37k | if (params->send_header_data_time > 0) { |
989 | 6.59k | pstr_env_enc->str_sbr_bs.nr_send_header_data = (WORD32)( |
990 | 6.59k | params->send_header_data_time * 0.001 * pstr_env_enc->str_sbr_cfg.sample_freq / 2048); |
991 | | |
992 | 6.59k | pstr_env_enc->str_sbr_bs.nr_send_header_data = |
993 | 6.59k | ixheaac_max32(pstr_env_enc->str_sbr_bs.nr_send_header_data, 1); |
994 | 6.59k | } else { |
995 | 1.78k | pstr_env_enc->str_sbr_bs.nr_send_header_data = 0; |
996 | 1.78k | } |
997 | | |
998 | 8.37k | pstr_env_enc->str_sbr_hdr.sbr_data_extra = params->sbr_data_extra; |
999 | 8.37k | pstr_env_enc->str_sbr_bs.crc_active = params->crc_sbr; |
1000 | 8.37k | pstr_env_enc->str_sbr_bs.header_active = 0; |
1001 | 8.37k | pstr_env_enc->str_sbr_hdr.sbr_start_freq = params->start_freq; |
1002 | 8.37k | pstr_env_enc->str_sbr_hdr.sbr_stop_freq = params->stop_freq; |
1003 | 8.37k | pstr_env_enc->str_sbr_hdr.sbr_xover_band = 0; |
1004 | | |
1005 | 8.37k | if (params->sbr_xpos_ctrl != SBR_XPOS_CTRL_DEFAULT) { |
1006 | 0 | pstr_env_enc->str_sbr_hdr.sbr_data_extra = 1; |
1007 | 0 | } |
1008 | | |
1009 | 8.37k | pstr_env_enc->str_sbr_hdr.protocol_version = SI_SBR_PROTOCOL_VERSION_ID; |
1010 | | |
1011 | 8.37k | pstr_env_enc->str_sbr_hdr.sbr_amp_res = (ixheaace_amp_res)params->amp_res; |
1012 | | |
1013 | 8.37k | pstr_env_enc->str_sbr_hdr.freq_scale = params->freq_scale; |
1014 | 8.37k | pstr_env_enc->str_sbr_hdr.alter_scale = params->alter_scale; |
1015 | 8.37k | pstr_env_enc->str_sbr_hdr.sbr_noise_bands = params->sbr_noise_bands; |
1016 | 8.37k | pstr_env_enc->str_sbr_hdr.header_extra_1 = 0; |
1017 | | |
1018 | 8.37k | if ((params->freq_scale != SBR_FREQ_SCALE_DEFAULT) || |
1019 | 8.37k | (params->alter_scale != SBR_ALTER_SCALE_DEFAULT) || |
1020 | 8.37k | (params->sbr_noise_bands != SBR_NOISE_BANDS_DEFAULT)) { |
1021 | 7.22k | pstr_env_enc->str_sbr_hdr.header_extra_1 = 1; |
1022 | 7.22k | } |
1023 | | |
1024 | 8.37k | pstr_env_enc->str_sbr_hdr.sbr_limiter_bands = params->sbr_limiter_bands; |
1025 | 8.37k | pstr_env_enc->str_sbr_hdr.sbr_limiter_gains = params->sbr_limiter_gains; |
1026 | 8.37k | pstr_env_enc->str_sbr_hdr.sbr_interpol_freq = params->sbr_interpol_freq; |
1027 | 8.37k | pstr_env_enc->str_sbr_hdr.sbr_smoothing_length = params->sbr_smoothing_length; |
1028 | 8.37k | pstr_env_enc->str_sbr_hdr.header_extra_2 = 0; |
1029 | | |
1030 | 8.37k | if ((params->sbr_limiter_bands != SBR_LIMITER_BANDS_DEFAULT) || |
1031 | 8.37k | (params->sbr_limiter_gains != SBR_LIMITER_GAINS_DEFAULT) || |
1032 | 8.37k | (params->sbr_interpol_freq != SBR_INTERPOL_FREQ_DEFAULT) || |
1033 | 8.37k | (params->sbr_smoothing_length != SBR_SMOOTHING_LENGTH_DEFAULT)) { |
1034 | 0 | pstr_env_enc->str_sbr_hdr.header_extra_2 = 1; |
1035 | 0 | } |
1036 | 8.37k | pstr_env_enc->str_sbr_hdr.sbr_harmonic = params->sbr_harmonic; |
1037 | 8.37k | pstr_env_enc->str_sbr_hdr.sbr_pvc_active = params->sbr_pvc_active; |
1038 | 8.37k | pstr_env_enc->str_sbr_hdr.hq_esbr = params->hq_esbr; |
1039 | | |
1040 | 8.37k | pstr_env_enc->str_sbr_cfg.detect_missing_harmonics = params->detect_missing_harmonics; |
1041 | 8.37k | pstr_env_enc->str_sbr_cfg.use_parametric_coding = params->parametric_coding; |
1042 | | |
1043 | 8.37k | err_code = ia_enhaacplus_enc_update_freq_band_tab( |
1044 | 8.37k | &pstr_env_enc->str_sbr_cfg, &pstr_env_enc->str_sbr_hdr, IXHEAACE_QMF_CHANNELS); |
1045 | 8.37k | if (err_code) { |
1046 | 39 | return err_code; |
1047 | 39 | } |
1048 | 8.33k | ch = 0; |
1049 | 20.5k | while (ch < pstr_env_enc->str_sbr_cfg.num_ch) { |
1050 | 12.1k | FLOAT32 *ptr_sbr_env_r_buf = &pstr_env_enc->ptr_sbr_enc_scr->sbr_env_r_buf[0]; |
1051 | 12.1k | FLOAT32 *ptr_sbr_env_i_buf = &pstr_env_enc->ptr_sbr_enc_scr->sbr_env_i_buf[0]; |
1052 | 12.1k | if (!params->use_ps) { |
1053 | 11.8k | ptr_sbr_env_r_buf = &pstr_env_enc->ptr_sbr_enc_scr->sbr_env_r_buffer[0]; |
1054 | 11.8k | ptr_sbr_env_i_buf = &pstr_env_enc->ptr_sbr_enc_scr->sbr_env_i_buffer[0]; |
1055 | 11.8k | } |
1056 | | |
1057 | 12.1k | err_code = ixheaace_create_env_channel( |
1058 | 12.1k | ch, &pstr_env_enc->str_sbr_cfg, &pstr_env_enc->str_sbr_hdr, |
1059 | 12.1k | pstr_env_enc->pstr_env_channel[ch], params, pstr_env_enc->ptr_common_buffer1, |
1060 | 12.1k | pstr_env_enc->ptr_common_buffer2, ptr_sbr_env_r_buf, ptr_sbr_env_i_buf, pstr_sbr_tab); |
1061 | 12.1k | if (err_code) { |
1062 | 0 | return err_code; |
1063 | 0 | } |
1064 | 12.1k | ch++; |
1065 | 12.1k | } |
1066 | | |
1067 | 8.33k | if (params->use_ps) { |
1068 | 354 | err_code = ixheaace_create_env_channel( |
1069 | 354 | 1, &pstr_env_enc->str_sbr_cfg, &pstr_env_enc->str_sbr_hdr, |
1070 | 354 | pstr_env_enc->pstr_env_channel[1], params, pstr_env_enc->ptr_common_buffer1, |
1071 | 354 | pstr_env_enc->ptr_common_buffer2, pstr_env_enc->ptr_sbr_enc_scr->sbr_env_r_buf, |
1072 | 354 | pstr_env_enc->ptr_sbr_enc_scr->sbr_env_i_buf, pstr_sbr_tab); |
1073 | 354 | if (err_code) { |
1074 | 0 | return err_code; |
1075 | 0 | } |
1076 | | |
1077 | 354 | ixheaace_create_synthesis_qmf_bank(pstr_env_enc->pstr_synthesis_qmf_bank, |
1078 | 354 | pstr_env_enc->ptr_common_buffer1, pstr_sbr_tab); |
1079 | | |
1080 | 354 | err_code = ixheaace_create_ps_enc(pstr_env_enc->pstr_ps_enc, params->ps_mode, |
1081 | 354 | (FLOAT32 *)pstr_env_enc->ptr_common_buffer1, |
1082 | 354 | (FLOAT32 *)pstr_env_enc->ptr_common_buffer2, |
1083 | 354 | (FLOAT32 *)pstr_env_enc->ptr_sbr_enc_scr->ps_buf3); |
1084 | 354 | if (err_code) { |
1085 | 0 | return err_code; |
1086 | 0 | } |
1087 | 354 | } |
1088 | | |
1089 | 8.33k | pstr_env_enc->str_cmon_data.sbr_num_channels = pstr_env_enc->str_sbr_cfg.num_ch; |
1090 | 8.33k | if (USAC_SBR == params->sbr_codec) { |
1091 | 3.83k | ixheaace_pvc_enc_init(pstr_env_enc->pstr_pvc_enc, params->sbr_pvc_rate); |
1092 | 3.83k | } |
1093 | 8.33k | *pstr_env_encoder = pstr_env_enc; |
1094 | 8.33k | *ptr_core_bw = pstr_env_enc->str_sbr_cfg.xover_freq; |
1095 | | |
1096 | 8.33k | return err_code; |
1097 | 8.33k | } |