/src/libxaac/encoder/ixheaace_sbr_code_envelope.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 "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 |
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 | 85.8k | ixheaace_str_sbr_huff_tabs *pstr_sbr_huff_tabs) { |
60 | 85.8k | pstr_sbr_env->init_sbr_amp_res = amp_res; |
61 | | |
62 | 85.8k | switch (amp_res) { |
63 | 46.0k | case IXHEAACE_SBR_AMP_RES_3_0: |
64 | | |
65 | 46.0k | pstr_sbr_env->ptr_huff_tab_lvl_time_c = pstr_sbr_huff_tabs->v_huff_env_lvl_c11t; |
66 | 46.0k | pstr_sbr_env->ptr_huff_tab_lvl_time_l = pstr_sbr_huff_tabs->v_huff_env_lvl_l11t; |
67 | 46.0k | pstr_sbr_env->ptr_huff_tab_bal_time_c = pstr_sbr_huff_tabs->book_sbr_env_bal_c11t; |
68 | 46.0k | pstr_sbr_env->ptr_huff_tab_bal_time_l = pstr_sbr_huff_tabs->book_sbr_env_bal_l11t; |
69 | | |
70 | 46.0k | pstr_sbr_env->ptr_huff_tab_lvl_freq_c = pstr_sbr_huff_tabs->v_huff_env_lvl_c11f; |
71 | 46.0k | pstr_sbr_env->ptr_huff_tab_lvl_freq_l = pstr_sbr_huff_tabs->v_huff_env_lvl_l11f; |
72 | 46.0k | pstr_sbr_env->ptr_huff_tab_bal_freq_c = pstr_sbr_huff_tabs->book_sbr_env_bal_c11f; |
73 | 46.0k | pstr_sbr_env->ptr_huff_tab_bal_freq_l = pstr_sbr_huff_tabs->book_sbr_env_bal_l11f; |
74 | | |
75 | 46.0k | pstr_sbr_env->ptr_huff_tab_time_c = pstr_sbr_huff_tabs->v_huff_env_lvl_c11t; |
76 | 46.0k | pstr_sbr_env->ptr_huff_tab_time_l = pstr_sbr_huff_tabs->v_huff_env_lvl_l11t; |
77 | 46.0k | pstr_sbr_env->ptr_huff_tab_freq_c = pstr_sbr_huff_tabs->v_huff_env_lvl_c11f; |
78 | 46.0k | pstr_sbr_env->ptr_huff_tab_freq_l = pstr_sbr_huff_tabs->v_huff_env_lvl_l11f; |
79 | | |
80 | 46.0k | pstr_sbr_env->code_book_scf_lav_balance = CODE_BCK_SCF_LAV_BALANCE11; |
81 | 46.0k | pstr_sbr_env->code_book_scf_lav = CODE_BCK_SCF_LAV11; |
82 | | |
83 | 46.0k | pstr_sbr_env->si_sbr_start_env_bits = SI_SBR_START_ENV_BITS_AMP_RES_3_0; |
84 | 46.0k | pstr_sbr_env->si_sbr_start_env_bits_balance = SI_SBR_START_ENV_BITS_BALANCE_AMP_RES_3_0; |
85 | 46.0k | break; |
86 | | |
87 | 39.7k | case IXHEAACE_SBR_AMP_RES_1_5: |
88 | | |
89 | 39.7k | pstr_sbr_env->ptr_huff_tab_lvl_time_c = pstr_sbr_huff_tabs->v_huff_env_lvl_c10t; |
90 | 39.7k | pstr_sbr_env->ptr_huff_tab_lvl_time_l = pstr_sbr_huff_tabs->v_huff_env_lvl_l10t; |
91 | 39.7k | pstr_sbr_env->ptr_huff_tab_bal_time_c = pstr_sbr_huff_tabs->book_sbr_env_bal_c10t; |
92 | 39.7k | pstr_sbr_env->ptr_huff_tab_bal_time_l = pstr_sbr_huff_tabs->book_sbr_env_bal_l10t; |
93 | | |
94 | 39.7k | pstr_sbr_env->ptr_huff_tab_lvl_freq_c = pstr_sbr_huff_tabs->v_huff_env_lvl_c10f; |
95 | 39.7k | pstr_sbr_env->ptr_huff_tab_lvl_freq_l = pstr_sbr_huff_tabs->v_huff_env_lvl_l10f; |
96 | 39.7k | pstr_sbr_env->ptr_huff_tab_bal_freq_c = pstr_sbr_huff_tabs->book_sbr_env_bal_c10f; |
97 | 39.7k | pstr_sbr_env->ptr_huff_tab_bal_freq_l = pstr_sbr_huff_tabs->book_sbr_env_bal_l10f; |
98 | | |
99 | 39.7k | pstr_sbr_env->ptr_huff_tab_time_c = pstr_sbr_huff_tabs->v_huff_env_lvl_c10t; |
100 | 39.7k | pstr_sbr_env->ptr_huff_tab_time_l = pstr_sbr_huff_tabs->v_huff_env_lvl_l10t; |
101 | 39.7k | pstr_sbr_env->ptr_huff_tab_freq_c = pstr_sbr_huff_tabs->v_huff_env_lvl_c10f; |
102 | 39.7k | pstr_sbr_env->ptr_huff_tab_freq_l = pstr_sbr_huff_tabs->v_huff_env_lvl_l10f; |
103 | | |
104 | 39.7k | pstr_sbr_env->code_book_scf_lav_balance = CODE_BCK_SCF_LAV_BALANCE10; |
105 | 39.7k | pstr_sbr_env->code_book_scf_lav = CODE_BCK_SCF_LAV10; |
106 | | |
107 | 39.7k | pstr_sbr_env->si_sbr_start_env_bits = SI_SBR_START_ENV_BITS_AMP_RES_1_5; |
108 | 39.7k | pstr_sbr_env->si_sbr_start_env_bits_balance = SI_SBR_START_ENV_BITS_BALANCE_AMP_RES_1_5; |
109 | 39.7k | break; |
110 | | |
111 | 0 | default: |
112 | 0 | return IA_EXHEAACE_EXE_FATAL_SBR_INVALID_AMP_RES; |
113 | 0 | break; |
114 | 85.8k | } |
115 | | |
116 | 85.8k | pstr_sbr_env->ptr_huff_tab_noise_lvl_time_c = pstr_sbr_huff_tabs->v_huff_noise_lvl_c11t; |
117 | 85.8k | pstr_sbr_env->ptr_huff_tab_noise_lvl_time_l = pstr_sbr_huff_tabs->v_huff_noise_lvl_l11t; |
118 | 85.8k | pstr_sbr_env->ptr_huff_tab_noise_bal_time_c = pstr_sbr_huff_tabs->book_sbr_noise_bal_c11t; |
119 | 85.8k | pstr_sbr_env->ptr_huff_tab_noise_bal_time_l = pstr_sbr_huff_tabs->book_sbr_noise_bal_l11t; |
120 | | |
121 | 85.8k | pstr_sbr_env->ptr_huff_tab_noise_lvl_freq_c = pstr_sbr_huff_tabs->v_huff_env_lvl_c11f; |
122 | 85.8k | pstr_sbr_env->ptr_huff_tab_noise_lvl_freq_l = pstr_sbr_huff_tabs->v_huff_env_lvl_l11f; |
123 | 85.8k | pstr_sbr_env->ptr_huff_tab_noise_bal_freq_c = pstr_sbr_huff_tabs->book_sbr_env_bal_c11f; |
124 | 85.8k | pstr_sbr_env->ptr_huff_tab_noise_bal_freq_l = pstr_sbr_huff_tabs->book_sbr_env_bal_l11f; |
125 | | |
126 | 85.8k | pstr_sbr_env->ptr_huff_tab_noise_time_c = pstr_sbr_huff_tabs->v_huff_noise_lvl_c11t; |
127 | 85.8k | pstr_sbr_env->ptr_huff_tab_noise_time_l = pstr_sbr_huff_tabs->v_huff_noise_lvl_l11t; |
128 | 85.8k | pstr_sbr_env->ptr_huff_tab_noise_freq_c = pstr_sbr_huff_tabs->v_huff_env_lvl_c11f; |
129 | 85.8k | pstr_sbr_env->ptr_huff_tab_noise_freq_l = pstr_sbr_huff_tabs->v_huff_env_lvl_l11f; |
130 | | |
131 | 85.8k | pstr_sbr_env->si_sbr_start_noise_bits = SI_SBR_START_NOISE_BITS_AMP_RES_3_0; |
132 | 85.8k | pstr_sbr_env->si_sbr_start_noise_bits_balance = SI_SBR_START_NOISE_BITS_BALANCE_AMP_RES_3_0; |
133 | | |
134 | 85.8k | pstr_code_env->code_book_scf_lav_bal_time = pstr_sbr_env->code_book_scf_lav_balance; |
135 | 85.8k | pstr_code_env->code_book_scf_lav_bal_freq = pstr_sbr_env->code_book_scf_lav_balance; |
136 | 85.8k | pstr_code_env->code_book_scf_lav_lvl_time = pstr_sbr_env->code_book_scf_lav; |
137 | 85.8k | pstr_code_env->code_book_scf_lav_lvl_freq = pstr_sbr_env->code_book_scf_lav; |
138 | 85.8k | pstr_code_env->code_book_scf_lav_time = pstr_sbr_env->code_book_scf_lav; |
139 | 85.8k | pstr_code_env->code_book_scf_lav_freq = pstr_sbr_env->code_book_scf_lav; |
140 | | |
141 | 85.8k | pstr_code_env->ptr_huff_tab_lvl_time_l = pstr_sbr_env->ptr_huff_tab_lvl_time_l; |
142 | 85.8k | pstr_code_env->ptr_huff_tab_bal_time_l = pstr_sbr_env->ptr_huff_tab_bal_time_l; |
143 | 85.8k | pstr_code_env->ptr_huff_tab_time_l = pstr_sbr_env->ptr_huff_tab_time_l; |
144 | 85.8k | pstr_code_env->ptr_huff_tab_lvl_freq_l = pstr_sbr_env->ptr_huff_tab_lvl_freq_l; |
145 | 85.8k | pstr_code_env->ptr_huff_tab_bal_freq_l = pstr_sbr_env->ptr_huff_tab_bal_freq_l; |
146 | 85.8k | pstr_code_env->ptr_huff_tab_freq_l = pstr_sbr_env->ptr_huff_tab_freq_l; |
147 | | |
148 | 85.8k | pstr_code_env->code_book_scf_lav_freq = pstr_sbr_env->code_book_scf_lav; |
149 | 85.8k | pstr_code_env->code_book_scf_lav_time = pstr_sbr_env->code_book_scf_lav; |
150 | | |
151 | 85.8k | pstr_code_env->start_bits = pstr_sbr_env->si_sbr_start_env_bits; |
152 | 85.8k | pstr_code_env->start_bits_balance = pstr_sbr_env->si_sbr_start_env_bits_balance; |
153 | | |
154 | 85.8k | pstr_noise->code_book_scf_lav_bal_time = CODE_BCK_SCF_LAV_BALANCE11; |
155 | 85.8k | pstr_noise->code_book_scf_lav_bal_freq = CODE_BCK_SCF_LAV_BALANCE11; |
156 | 85.8k | pstr_noise->code_book_scf_lav_lvl_time = CODE_BCK_SCF_LAV11; |
157 | 85.8k | pstr_noise->code_book_scf_lav_lvl_freq = CODE_BCK_SCF_LAV11; |
158 | 85.8k | pstr_noise->code_book_scf_lav_time = CODE_BCK_SCF_LAV11; |
159 | 85.8k | pstr_noise->code_book_scf_lav_freq = CODE_BCK_SCF_LAV11; |
160 | | |
161 | 85.8k | pstr_noise->ptr_huff_tab_lvl_time_l = pstr_sbr_env->ptr_huff_tab_noise_lvl_time_l; |
162 | 85.8k | pstr_noise->ptr_huff_tab_bal_time_l = pstr_sbr_env->ptr_huff_tab_noise_bal_time_l; |
163 | 85.8k | pstr_noise->ptr_huff_tab_time_l = pstr_sbr_env->ptr_huff_tab_noise_time_l; |
164 | 85.8k | pstr_noise->ptr_huff_tab_lvl_freq_l = pstr_sbr_env->ptr_huff_tab_noise_lvl_freq_l; |
165 | 85.8k | pstr_noise->ptr_huff_tab_bal_freq_l = pstr_sbr_env->ptr_huff_tab_noise_bal_freq_l; |
166 | 85.8k | pstr_noise->ptr_huff_tab_freq_l = pstr_sbr_env->ptr_huff_tab_noise_freq_l; |
167 | | |
168 | 85.8k | pstr_noise->start_bits = pstr_sbr_env->si_sbr_start_noise_bits; |
169 | 85.8k | pstr_noise->start_bits_balance = pstr_sbr_env->si_sbr_start_noise_bits_balance; |
170 | | |
171 | 85.8k | pstr_code_env->update = 0; |
172 | 85.8k | pstr_noise->update = 0; |
173 | | |
174 | 85.8k | return IA_NO_ERROR; |
175 | 85.8k | } |
176 | | |
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 | 19.2k | FLOAT32 df_edge_first_env, FLOAT32 df_edge_incr) { |
180 | 19.2k | memset(pstr_code_env, 0, sizeof(ixheaace_str_sbr_code_envelope)); |
181 | | |
182 | 19.2k | pstr_code_env->delta_t_across_frames = delta_t_across_frames; |
183 | 19.2k | pstr_code_env->df_edge_1st_env = df_edge_first_env; |
184 | 19.2k | pstr_code_env->df_edge_incr = df_edge_incr; |
185 | 19.2k | pstr_code_env->df_edge_incr_fac = 0; |
186 | 19.2k | pstr_code_env->update = 0; |
187 | 19.2k | pstr_code_env->num_scf[FREQ_RES_LOW] = num_sfb[FREQ_RES_LOW]; |
188 | 19.2k | pstr_code_env->num_scf[FREQ_RES_HIGH] = num_sfb[FREQ_RES_HIGH]; |
189 | | |
190 | 19.2k | pstr_code_env->offset = |
191 | 19.2k | 2 * pstr_code_env->num_scf[FREQ_RES_LOW] - pstr_code_env->num_scf[FREQ_RES_HIGH]; |
192 | 19.2k | } |