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 "ixheaace_aac_constants.h"
26 #include "ixheaac_basic_ops32.h"
27 #include "ixheaac_basic_ops16.h"
28 #include "ixheaac_basic_ops40.h"
29 #include "ixheaac_basic_ops.h"
30 #include "ixheaace_error_codes.h"
31 #include "ixheaac_error_standards.h"
32 #include "ixheaace_sbr_header.h"
33 #include "ixheaace_sbr_def.h"
34 #include "ixheaace_resampler.h"
35 #include "ixheaace_sbr_rom.h"
36 #include "ixheaace_common_rom.h"
37 #include "ixheaace_sbr_main.h"
38 #include "ixheaace_sbr_frame_info_gen.h"
39 #include "ixheaace_sbr_hbe.h"
40 #include "ixheaace_sbr_code_envelope.h"
41 #include "ixheaace_sbr_qmf_enc.h"
42 #include "ixheaace_sbr_tran_det.h"
43 #include "ixheaace_sbr_env_est.h"
44 #include "ixheaace_sbr_missing_harmonics_det.h"
45 #include "ixheaace_sbr_inv_filtering_estimation.h"
46 #include "ixheaace_sbr_noise_floor_est.h"
47
48 #include "ixheaace_sbr_ton_corr.h"
49 #include "iusace_esbr_pvc.h"
50 #include "iusace_esbr_inter_tes.h"
51 #include "ixheaace_sbr.h"
52 #include "ixheaace_common_utils.h"
53
54 IA_ERRORCODE
ixheaace_init_sbr_huffman_tabs(ixheaace_pstr_sbr_env_data pstr_sbr_env,ixheaace_pstr_sbr_code_envelope pstr_code_env,ixheaace_pstr_sbr_code_envelope pstr_noise,ixheaace_amp_res amp_res,ixheaace_str_sbr_huff_tabs * pstr_sbr_huff_tabs)55 ixheaace_init_sbr_huffman_tabs(ixheaace_pstr_sbr_env_data pstr_sbr_env,
56 ixheaace_pstr_sbr_code_envelope pstr_code_env,
57 ixheaace_pstr_sbr_code_envelope pstr_noise,
58 ixheaace_amp_res amp_res,
59 ixheaace_str_sbr_huff_tabs *pstr_sbr_huff_tabs) {
60 pstr_sbr_env->init_sbr_amp_res = amp_res;
61
62 switch (amp_res) {
63 case IXHEAACE_SBR_AMP_RES_3_0:
64
65 pstr_sbr_env->ptr_huff_tab_lvl_time_c = pstr_sbr_huff_tabs->v_huff_env_lvl_c11t;
66 pstr_sbr_env->ptr_huff_tab_lvl_time_l = pstr_sbr_huff_tabs->v_huff_env_lvl_l11t;
67 pstr_sbr_env->ptr_huff_tab_bal_time_c = pstr_sbr_huff_tabs->book_sbr_env_bal_c11t;
68 pstr_sbr_env->ptr_huff_tab_bal_time_l = pstr_sbr_huff_tabs->book_sbr_env_bal_l11t;
69
70 pstr_sbr_env->ptr_huff_tab_lvl_freq_c = pstr_sbr_huff_tabs->v_huff_env_lvl_c11f;
71 pstr_sbr_env->ptr_huff_tab_lvl_freq_l = pstr_sbr_huff_tabs->v_huff_env_lvl_l11f;
72 pstr_sbr_env->ptr_huff_tab_bal_freq_c = pstr_sbr_huff_tabs->book_sbr_env_bal_c11f;
73 pstr_sbr_env->ptr_huff_tab_bal_freq_l = pstr_sbr_huff_tabs->book_sbr_env_bal_l11f;
74
75 pstr_sbr_env->ptr_huff_tab_time_c = pstr_sbr_huff_tabs->v_huff_env_lvl_c11t;
76 pstr_sbr_env->ptr_huff_tab_time_l = pstr_sbr_huff_tabs->v_huff_env_lvl_l11t;
77 pstr_sbr_env->ptr_huff_tab_freq_c = pstr_sbr_huff_tabs->v_huff_env_lvl_c11f;
78 pstr_sbr_env->ptr_huff_tab_freq_l = pstr_sbr_huff_tabs->v_huff_env_lvl_l11f;
79
80 pstr_sbr_env->code_book_scf_lav_balance = CODE_BCK_SCF_LAV_BALANCE11;
81 pstr_sbr_env->code_book_scf_lav = CODE_BCK_SCF_LAV11;
82
83 pstr_sbr_env->si_sbr_start_env_bits = SI_SBR_START_ENV_BITS_AMP_RES_3_0;
84 pstr_sbr_env->si_sbr_start_env_bits_balance = SI_SBR_START_ENV_BITS_BALANCE_AMP_RES_3_0;
85 break;
86
87 case IXHEAACE_SBR_AMP_RES_1_5:
88
89 pstr_sbr_env->ptr_huff_tab_lvl_time_c = pstr_sbr_huff_tabs->v_huff_env_lvl_c10t;
90 pstr_sbr_env->ptr_huff_tab_lvl_time_l = pstr_sbr_huff_tabs->v_huff_env_lvl_l10t;
91 pstr_sbr_env->ptr_huff_tab_bal_time_c = pstr_sbr_huff_tabs->book_sbr_env_bal_c10t;
92 pstr_sbr_env->ptr_huff_tab_bal_time_l = pstr_sbr_huff_tabs->book_sbr_env_bal_l10t;
93
94 pstr_sbr_env->ptr_huff_tab_lvl_freq_c = pstr_sbr_huff_tabs->v_huff_env_lvl_c10f;
95 pstr_sbr_env->ptr_huff_tab_lvl_freq_l = pstr_sbr_huff_tabs->v_huff_env_lvl_l10f;
96 pstr_sbr_env->ptr_huff_tab_bal_freq_c = pstr_sbr_huff_tabs->book_sbr_env_bal_c10f;
97 pstr_sbr_env->ptr_huff_tab_bal_freq_l = pstr_sbr_huff_tabs->book_sbr_env_bal_l10f;
98
99 pstr_sbr_env->ptr_huff_tab_time_c = pstr_sbr_huff_tabs->v_huff_env_lvl_c10t;
100 pstr_sbr_env->ptr_huff_tab_time_l = pstr_sbr_huff_tabs->v_huff_env_lvl_l10t;
101 pstr_sbr_env->ptr_huff_tab_freq_c = pstr_sbr_huff_tabs->v_huff_env_lvl_c10f;
102 pstr_sbr_env->ptr_huff_tab_freq_l = pstr_sbr_huff_tabs->v_huff_env_lvl_l10f;
103
104 pstr_sbr_env->code_book_scf_lav_balance = CODE_BCK_SCF_LAV_BALANCE10;
105 pstr_sbr_env->code_book_scf_lav = CODE_BCK_SCF_LAV10;
106
107 pstr_sbr_env->si_sbr_start_env_bits = SI_SBR_START_ENV_BITS_AMP_RES_1_5;
108 pstr_sbr_env->si_sbr_start_env_bits_balance = SI_SBR_START_ENV_BITS_BALANCE_AMP_RES_1_5;
109 break;
110
111 default:
112 return IA_EXHEAACE_EXE_FATAL_SBR_INVALID_AMP_RES;
113 break;
114 }
115
116 pstr_sbr_env->ptr_huff_tab_noise_lvl_time_c = pstr_sbr_huff_tabs->v_huff_noise_lvl_c11t;
117 pstr_sbr_env->ptr_huff_tab_noise_lvl_time_l = pstr_sbr_huff_tabs->v_huff_noise_lvl_l11t;
118 pstr_sbr_env->ptr_huff_tab_noise_bal_time_c = pstr_sbr_huff_tabs->book_sbr_noise_bal_c11t;
119 pstr_sbr_env->ptr_huff_tab_noise_bal_time_l = pstr_sbr_huff_tabs->book_sbr_noise_bal_l11t;
120
121 pstr_sbr_env->ptr_huff_tab_noise_lvl_freq_c = pstr_sbr_huff_tabs->v_huff_env_lvl_c11f;
122 pstr_sbr_env->ptr_huff_tab_noise_lvl_freq_l = pstr_sbr_huff_tabs->v_huff_env_lvl_l11f;
123 pstr_sbr_env->ptr_huff_tab_noise_bal_freq_c = pstr_sbr_huff_tabs->book_sbr_env_bal_c11f;
124 pstr_sbr_env->ptr_huff_tab_noise_bal_freq_l = pstr_sbr_huff_tabs->book_sbr_env_bal_l11f;
125
126 pstr_sbr_env->ptr_huff_tab_noise_time_c = pstr_sbr_huff_tabs->v_huff_noise_lvl_c11t;
127 pstr_sbr_env->ptr_huff_tab_noise_time_l = pstr_sbr_huff_tabs->v_huff_noise_lvl_l11t;
128 pstr_sbr_env->ptr_huff_tab_noise_freq_c = pstr_sbr_huff_tabs->v_huff_env_lvl_c11f;
129 pstr_sbr_env->ptr_huff_tab_noise_freq_l = pstr_sbr_huff_tabs->v_huff_env_lvl_l11f;
130
131 pstr_sbr_env->si_sbr_start_noise_bits = SI_SBR_START_NOISE_BITS_AMP_RES_3_0;
132 pstr_sbr_env->si_sbr_start_noise_bits_balance = SI_SBR_START_NOISE_BITS_BALANCE_AMP_RES_3_0;
133
134 pstr_code_env->code_book_scf_lav_bal_time = pstr_sbr_env->code_book_scf_lav_balance;
135 pstr_code_env->code_book_scf_lav_bal_freq = pstr_sbr_env->code_book_scf_lav_balance;
136 pstr_code_env->code_book_scf_lav_lvl_time = pstr_sbr_env->code_book_scf_lav;
137 pstr_code_env->code_book_scf_lav_lvl_freq = pstr_sbr_env->code_book_scf_lav;
138 pstr_code_env->code_book_scf_lav_time = pstr_sbr_env->code_book_scf_lav;
139 pstr_code_env->code_book_scf_lav_freq = pstr_sbr_env->code_book_scf_lav;
140
141 pstr_code_env->ptr_huff_tab_lvl_time_l = pstr_sbr_env->ptr_huff_tab_lvl_time_l;
142 pstr_code_env->ptr_huff_tab_bal_time_l = pstr_sbr_env->ptr_huff_tab_bal_time_l;
143 pstr_code_env->ptr_huff_tab_time_l = pstr_sbr_env->ptr_huff_tab_time_l;
144 pstr_code_env->ptr_huff_tab_lvl_freq_l = pstr_sbr_env->ptr_huff_tab_lvl_freq_l;
145 pstr_code_env->ptr_huff_tab_bal_freq_l = pstr_sbr_env->ptr_huff_tab_bal_freq_l;
146 pstr_code_env->ptr_huff_tab_freq_l = pstr_sbr_env->ptr_huff_tab_freq_l;
147
148 pstr_code_env->code_book_scf_lav_freq = pstr_sbr_env->code_book_scf_lav;
149 pstr_code_env->code_book_scf_lav_time = pstr_sbr_env->code_book_scf_lav;
150
151 pstr_code_env->start_bits = pstr_sbr_env->si_sbr_start_env_bits;
152 pstr_code_env->start_bits_balance = pstr_sbr_env->si_sbr_start_env_bits_balance;
153
154 pstr_noise->code_book_scf_lav_bal_time = CODE_BCK_SCF_LAV_BALANCE11;
155 pstr_noise->code_book_scf_lav_bal_freq = CODE_BCK_SCF_LAV_BALANCE11;
156 pstr_noise->code_book_scf_lav_lvl_time = CODE_BCK_SCF_LAV11;
157 pstr_noise->code_book_scf_lav_lvl_freq = CODE_BCK_SCF_LAV11;
158 pstr_noise->code_book_scf_lav_time = CODE_BCK_SCF_LAV11;
159 pstr_noise->code_book_scf_lav_freq = CODE_BCK_SCF_LAV11;
160
161 pstr_noise->ptr_huff_tab_lvl_time_l = pstr_sbr_env->ptr_huff_tab_noise_lvl_time_l;
162 pstr_noise->ptr_huff_tab_bal_time_l = pstr_sbr_env->ptr_huff_tab_noise_bal_time_l;
163 pstr_noise->ptr_huff_tab_time_l = pstr_sbr_env->ptr_huff_tab_noise_time_l;
164 pstr_noise->ptr_huff_tab_lvl_freq_l = pstr_sbr_env->ptr_huff_tab_noise_lvl_freq_l;
165 pstr_noise->ptr_huff_tab_bal_freq_l = pstr_sbr_env->ptr_huff_tab_noise_bal_freq_l;
166 pstr_noise->ptr_huff_tab_freq_l = pstr_sbr_env->ptr_huff_tab_noise_freq_l;
167
168 pstr_noise->start_bits = pstr_sbr_env->si_sbr_start_noise_bits;
169 pstr_noise->start_bits_balance = pstr_sbr_env->si_sbr_start_noise_bits_balance;
170
171 pstr_code_env->update = 0;
172 pstr_noise->update = 0;
173
174 return IA_NO_ERROR;
175 }
176
ixheaace_create_sbr_code_envelope(ixheaace_pstr_sbr_code_envelope pstr_code_env,WORD32 * num_sfb,WORD32 delta_t_across_frames,FLOAT32 df_edge_first_env,FLOAT32 df_edge_incr)177 VOID ixheaace_create_sbr_code_envelope(ixheaace_pstr_sbr_code_envelope pstr_code_env,
178 WORD32 *num_sfb, WORD32 delta_t_across_frames,
179 FLOAT32 df_edge_first_env, FLOAT32 df_edge_incr) {
180 memset(pstr_code_env, 0, sizeof(ixheaace_str_sbr_code_envelope));
181
182 pstr_code_env->delta_t_across_frames = delta_t_across_frames;
183 pstr_code_env->df_edge_1st_env = df_edge_first_env;
184 pstr_code_env->df_edge_incr = df_edge_incr;
185 pstr_code_env->df_edge_incr_fac = 0;
186 pstr_code_env->update = 0;
187 pstr_code_env->num_scf[FREQ_RES_LOW] = num_sfb[FREQ_RES_LOW];
188 pstr_code_env->num_scf[FREQ_RES_HIGH] = num_sfb[FREQ_RES_HIGH];
189
190 pstr_code_env->offset =
191 2 * pstr_code_env->num_scf[FREQ_RES_LOW] - pstr_code_env->num_scf[FREQ_RES_HIGH];
192 }
193