/src/libxaac/encoder/ixheaace_sbr_env_est_init.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 <string.h> |
22 | | #include <limits.h> |
23 | | |
24 | | #include "ixheaac_type_def.h" |
25 | | #include "ixheaac_constants.h" |
26 | | #include "ixheaac_error_standards.h" |
27 | | #include "ixheaace_error_codes.h" |
28 | | #include "ixheaace_aac_constants.h" |
29 | | #include "ixheaac_basic_ops32.h" |
30 | | #include "ixheaac_basic_ops16.h" |
31 | | #include "ixheaac_basic_ops40.h" |
32 | | #include "ixheaac_basic_ops.h" |
33 | | #include "ixheaace_sbr_header.h" |
34 | | #include "ixheaace_sbr_def.h" |
35 | | #include "ixheaace_resampler.h" |
36 | | #include "ixheaace_sbr_rom.h" |
37 | | #include "ixheaace_common_rom.h" |
38 | | #include "ixheaace_sbr_hbe.h" |
39 | | #include "ixheaace_sbr_qmf_enc.h" |
40 | | #include "ixheaace_sbr_tran_det.h" |
41 | | #include "ixheaace_sbr_frame_info_gen.h" |
42 | | #include "ixheaace_sbr_env_est.h" |
43 | | #include "ixheaace_sbr_code_envelope.h" |
44 | | #include "ixheaace_sbr_main.h" |
45 | | #include "ixheaace_sbr_missing_harmonics_det.h" |
46 | | #include "ixheaace_sbr_inv_filtering_estimation.h" |
47 | | #include "ixheaace_sbr_noise_floor_est.h" |
48 | | |
49 | | #include "ixheaace_common_rom.h" |
50 | | #include "ixheaace_sbr_ton_corr.h" |
51 | | #include "iusace_esbr_pvc.h" |
52 | | #include "iusace_esbr_inter_tes.h" |
53 | | #include "ixheaace_sbr.h" |
54 | | #include "ixheaace_bitbuffer.h" |
55 | | #include "ixheaace_sbr_cmondata.h" |
56 | | #include "ixheaace_sbr_write_bitstream.h" |
57 | | #include "ixheaace_sbr_hybrid.h" |
58 | | #include "ixheaace_sbr_ps_enc.h" |
59 | | |
60 | | IA_ERRORCODE |
61 | | ixheaace_create_extract_sbr_envelope(WORD32 ch, |
62 | | ixheaace_pstr_sbr_extract_envelope pstr_sbr_ext_env, |
63 | | WORD32 start_index, WORD32 *ptr_common_buffer2, |
64 | | FLOAT32 *ptr_sbr_env_r_buf, FLOAT32 *ptr_sbr_env_i_buf, |
65 | 9.83k | WORD32 frame_flag_480, ixheaace_sbr_codec_type sbr_codec) { |
66 | 9.83k | WORD32 i; |
67 | 9.83k | WORD32 y_buffer_length, r_buffer_length; |
68 | 9.83k | WORD32 offset = 0; |
69 | 9.83k | WORD32 y_buffer_write_offset = 32; |
70 | 9.83k | WORD32 no_cols = 32; |
71 | 9.83k | WORD32 time_slots = 16; |
72 | 9.83k | WORD32 sbr_ratio_idx = pstr_sbr_ext_env->sbr_ratio_idx; |
73 | 9.83k | WORD32 qmf_time_slots = IXHEAACE_QMF_TIME_SLOTS; |
74 | 9.83k | FLOAT32 *ptr_buffer = NULL; |
75 | 9.83k | FLOAT32 *ptr_i_buffer = NULL; |
76 | 9.83k | memset(pstr_sbr_ext_env, 0, sizeof(ixheaace_str_sbr_extr_env)); |
77 | | |
78 | 9.83k | pstr_sbr_ext_env->pre_transient_info[0] = 0; |
79 | 9.83k | pstr_sbr_ext_env->pre_transient_info[1] = 0; |
80 | | |
81 | 9.83k | if (sbr_codec == ELD_SBR) { |
82 | 2.07k | if (frame_flag_480) { |
83 | 1.07k | no_cols = 30; |
84 | 1.07k | time_slots = 15; |
85 | 1.07k | } |
86 | | |
87 | 2.07k | y_buffer_write_offset = time_slots / 2; |
88 | 2.07k | pstr_sbr_ext_env->y_buffer_write_offset = y_buffer_write_offset; |
89 | 2.07k | pstr_sbr_ext_env->no_cols = no_cols; |
90 | 2.07k | pstr_sbr_ext_env->no_rows = 64; |
91 | 2.07k | pstr_sbr_ext_env->start_index = start_index; |
92 | 2.07k | pstr_sbr_ext_env->time_slots = time_slots; |
93 | 2.07k | pstr_sbr_ext_env->time_step = 1; |
94 | | |
95 | 2.07k | y_buffer_length = y_buffer_write_offset + time_slots; |
96 | 2.07k | r_buffer_length = time_slots; |
97 | 7.76k | } else { |
98 | 7.76k | if ((sbr_codec == USAC_SBR) && (USAC_SBR_RATIO_INDEX_4_1 == sbr_ratio_idx)) { |
99 | 888 | qmf_time_slots = QMF_TIME_SLOTS_USAC_4_1; |
100 | 888 | y_buffer_write_offset = QMF_TIME_SLOTS_USAC_4_1; |
101 | 888 | no_cols = qmf_time_slots; |
102 | 888 | } |
103 | | |
104 | 7.76k | pstr_sbr_ext_env->y_buffer_write_offset = y_buffer_write_offset; |
105 | | |
106 | 7.76k | y_buffer_length = pstr_sbr_ext_env->y_buffer_write_offset + y_buffer_write_offset; |
107 | | |
108 | 7.76k | r_buffer_length = y_buffer_write_offset; |
109 | | |
110 | 7.76k | pstr_sbr_ext_env->pre_transient_info[0] = 0; |
111 | 7.76k | pstr_sbr_ext_env->pre_transient_info[1] = 0; |
112 | | |
113 | 7.76k | pstr_sbr_ext_env->no_cols = no_cols; |
114 | 7.76k | pstr_sbr_ext_env->no_rows = 64; |
115 | 7.76k | pstr_sbr_ext_env->start_index = start_index; |
116 | | |
117 | 7.76k | pstr_sbr_ext_env->time_slots = time_slots; |
118 | 7.76k | pstr_sbr_ext_env->time_step = no_cols / time_slots; |
119 | | |
120 | 7.76k | if ((r_buffer_length != qmf_time_slots) || (y_buffer_length != 2 * qmf_time_slots)) { |
121 | 0 | return IA_EXHEAACE_INIT_FATAL_SBR_INVALID_BUFFER_LENGTH; |
122 | 0 | } |
123 | | |
124 | 7.76k | y_buffer_length /= 2; |
125 | | |
126 | 7.76k | if ((sbr_codec == USAC_SBR) && (USAC_SBR_RATIO_INDEX_4_1 == sbr_ratio_idx)) { |
127 | 888 | pstr_sbr_ext_env->y_buffer_write_offset /= 4; |
128 | 6.87k | } else { |
129 | 6.87k | pstr_sbr_ext_env->y_buffer_write_offset /= 2; |
130 | 6.87k | } |
131 | 7.76k | } |
132 | | |
133 | 9.83k | pstr_sbr_ext_env->buffer_flag = 0; |
134 | | |
135 | 9.83k | ptr_buffer = |
136 | 9.83k | (FLOAT32 *)&ptr_common_buffer2[ch * y_buffer_length * 64 + offset * IXHEAACE_QMF_CHANNELS]; |
137 | | |
138 | 9.83k | i = 0; |
139 | 149k | while (i < pstr_sbr_ext_env->y_buffer_write_offset) { |
140 | 139k | pstr_sbr_ext_env->ptr_y_buffer[i] = ptr_buffer + i * IXHEAACE_QMF_CHANNELS; |
141 | 139k | memset(pstr_sbr_ext_env->ptr_y_buffer[i], 0, |
142 | 139k | IXHEAACE_QMF_CHANNELS * sizeof(pstr_sbr_ext_env->ptr_y_buffer[0])); |
143 | 139k | i++; |
144 | 139k | } |
145 | | |
146 | 9.83k | ptr_buffer = |
147 | 9.83k | (FLOAT32 *)&ptr_common_buffer2[ch * y_buffer_length * 64 - offset * IXHEAACE_QMF_CHANNELS]; |
148 | 194k | for (i = pstr_sbr_ext_env->y_buffer_write_offset; i < y_buffer_length; i++) { |
149 | 184k | pstr_sbr_ext_env->ptr_y_buffer[i] = ptr_buffer + i * IXHEAACE_QMF_CHANNELS; |
150 | 184k | memset(pstr_sbr_ext_env->ptr_y_buffer[i], 0, |
151 | 184k | IXHEAACE_QMF_CHANNELS * sizeof(pstr_sbr_ext_env->ptr_y_buffer[0])); |
152 | 184k | } |
153 | | |
154 | 9.83k | ptr_buffer = &ptr_sbr_env_r_buf[ch * qmf_time_slots * IXHEAACE_QMF_CHANNELS]; |
155 | 9.83k | ptr_i_buffer = &ptr_sbr_env_i_buf[ch * qmf_time_slots * IXHEAACE_QMF_CHANNELS]; |
156 | 318k | for (i = 0; i < r_buffer_length; i++) { |
157 | 308k | pstr_sbr_ext_env->ptr_r_buffer[i] = ptr_buffer + i * IXHEAACE_QMF_CHANNELS; |
158 | 308k | memset(pstr_sbr_ext_env->ptr_r_buffer[i], 0, |
159 | 308k | IXHEAACE_QMF_CHANNELS * sizeof(pstr_sbr_ext_env->ptr_r_buffer[0])); |
160 | 308k | pstr_sbr_ext_env->ptr_i_buffer[i] = ptr_i_buffer + i * IXHEAACE_QMF_CHANNELS; |
161 | 308k | memset(pstr_sbr_ext_env->ptr_i_buffer[i], 0, |
162 | 308k | IXHEAACE_QMF_CHANNELS * sizeof(pstr_sbr_ext_env->ptr_i_buffer[0])); |
163 | 308k | } |
164 | | |
165 | 9.83k | memset(pstr_sbr_ext_env->envelope_compensation, 0, |
166 | 9.83k | sizeof(pstr_sbr_ext_env->envelope_compensation[0]) * MAXIMUM_FREQ_COEFFS); |
167 | | |
168 | 9.83k | return IA_NO_ERROR; |
169 | 9.83k | } |