/src/libxaac/encoder/ixheaace_ps_enc_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 "ixheaac_error_standards.h" |
23 | | #include "ixheaac_type_def.h" |
24 | | #include "ixheaace_sbr_def.h" |
25 | | #include "ixheaace_resampler.h" |
26 | | #include "ixheaace_sbr_rom.h" |
27 | | #include "ixheaace_common_rom.h" |
28 | | #include "ixheaace_bitbuffer.h" |
29 | | #include "ixheaace_sbr_hybrid.h" |
30 | | #include "ixheaace_sbr_ps_enc.h" |
31 | | #include "ixheaac_constants.h" |
32 | | #include "ixheaace_aac_constants.h" |
33 | | #include "ixheaace_error_codes.h" |
34 | | #include "ixheaace_bitbuffer.h" |
35 | | |
36 | 249 | WORD32 ixheaace_get_ps_mode(WORD32 bitrate) { |
37 | 249 | WORD32 ps_mode = 0; |
38 | | |
39 | 249 | if (bitrate < 21000) { |
40 | 90 | ps_mode = PS_MODE_LOW_FREQ_RES_IID_ICC; |
41 | 90 | } |
42 | | |
43 | 249 | return ps_mode; |
44 | 249 | } |
45 | | |
46 | | IA_ERRORCODE |
47 | | ixheaace_create_ps_enc(ixheaace_pstr_ps_enc pstr_ps_enc, WORD32 ps_mode, |
48 | | FLOAT32 *ptr_common_buffer, FLOAT32 *ptr_common_buffer2, |
49 | 249 | FLOAT32 *ptr_ps_buf3) { |
50 | 249 | WORD32 i; |
51 | 249 | IA_ERRORCODE err = IA_NO_ERROR; |
52 | | |
53 | 249 | FLOAT32 *ptr1, *ptr2, *ptr3, *ptr4; |
54 | | |
55 | 249 | if (pstr_ps_enc == NULL) { |
56 | 0 | return IA_EXHEAACE_INIT_FATAL_PS_INIT_FAILED; |
57 | 0 | } |
58 | 249 | ptr1 = &ptr_common_buffer2[IXHEAACE_QMF_TIME_SLOTS * IXHEAACE_QMF_CHANNELS]; |
59 | 249 | ptr2 = pstr_ps_enc->ps_buf2; |
60 | 249 | ptr3 = ptr_ps_buf3; |
61 | 249 | ptr4 = &ptr_common_buffer[5 * NO_OF_ESTIMATES * MAXIMUM_FREQ_COEFFS]; |
62 | | |
63 | 249 | pstr_ps_enc->ps_mode = ps_mode; |
64 | 249 | pstr_ps_enc->b_prev_zero_iid = 0; |
65 | 249 | pstr_ps_enc->b_prev_zero_icc = 0; |
66 | 249 | pstr_ps_enc->b_hi_freq_res_iid_icc = ((ps_mode & PS_MODE_LOW_FREQ_RES_IID_ICC) != 0) ? 0 : 1; |
67 | 249 | pstr_ps_enc->iid_icc_bins = |
68 | 249 | (pstr_ps_enc->b_hi_freq_res_iid_icc) ? NUMBER_OF_IID_BINS : NUMBER_OF_LOW_RES_IID_BINS; |
69 | | |
70 | 249 | pstr_ps_enc->aaa_ICC_data_buf = (FLOAT32 **)ptr1; |
71 | 249 | ptr1 += NUMBER_OF_BINS * sizeof(FLOAT32 *) / sizeof(FLOAT32); |
72 | | |
73 | 249 | pstr_ps_enc->aaa_IID_data_buf = (FLOAT32 **)ptr1; |
74 | 249 | ptr1 += NUMBER_OF_BINS * sizeof(FLOAT32 *) / sizeof(FLOAT32); |
75 | | |
76 | 5.22k | for (i = 0; i < NUMBER_OF_BINS; i++) { |
77 | 4.98k | pstr_ps_enc->aaa_ICC_data_buf[i] = ptr1; |
78 | 4.98k | ptr1 += SYSTEMLOOKAHEAD + 1; |
79 | | |
80 | 4.98k | memset(pstr_ps_enc->aaa_ICC_data_buf[i], 0, |
81 | 4.98k | (SYSTEMLOOKAHEAD + 1) * sizeof(pstr_ps_enc->aaa_ICC_data_buf[0])); |
82 | | |
83 | 4.98k | pstr_ps_enc->aaa_IID_data_buf[i] = ptr1; |
84 | 4.98k | ptr1 += SYSTEMLOOKAHEAD + 1; |
85 | | |
86 | 4.98k | memset(pstr_ps_enc->aaa_IID_data_buf[i], 0, |
87 | 4.98k | (SYSTEMLOOKAHEAD + 1) * sizeof(pstr_ps_enc->aaa_IID_data_buf[0])); |
88 | 4.98k | } |
89 | | |
90 | 249 | pstr_ps_enc->ptr_hybrid_left = &pstr_ps_enc->hybrid_left; |
91 | 249 | pstr_ps_enc->ptr_hybrid_right = &pstr_ps_enc->hybrid_right; |
92 | | |
93 | 249 | err = ixheaace_create_hybrid_filter_bank(pstr_ps_enc->ptr_hybrid_left, &ptr4); |
94 | | |
95 | 249 | if (err) { |
96 | 0 | return err; |
97 | 0 | } |
98 | | |
99 | 249 | err = ixheaace_create_hybrid_filter_bank(pstr_ps_enc->ptr_hybrid_right, &ptr4); |
100 | | |
101 | 249 | if (err) { |
102 | 0 | return err; |
103 | 0 | } |
104 | | |
105 | 8.21k | for (i = 0; i < NUMBER_OF_SUBSAMPLES; i++) { |
106 | 7.96k | pstr_ps_enc->m_hybrid_real_left[i] = ptr3; |
107 | 7.96k | ptr3 += IXHEAACE_NUM_HYBRID_BANDS; |
108 | | |
109 | 7.96k | memset(pstr_ps_enc->m_hybrid_real_left[i], 0, |
110 | 7.96k | IXHEAACE_NUM_HYBRID_BANDS * sizeof(pstr_ps_enc->m_hybrid_real_left[0])); |
111 | | |
112 | 7.96k | pstr_ps_enc->m_hybrid_imag_left[i] = ptr3; |
113 | 7.96k | ptr3 += IXHEAACE_NUM_HYBRID_BANDS; |
114 | | |
115 | 7.96k | memset(pstr_ps_enc->m_hybrid_imag_left[i], 0, |
116 | 7.96k | IXHEAACE_NUM_HYBRID_BANDS * sizeof(pstr_ps_enc->m_hybrid_imag_left[0])); |
117 | | |
118 | 7.96k | pstr_ps_enc->m_hybrid_real_right[i] = ptr1; |
119 | 7.96k | ptr1 += IXHEAACE_NUM_HYBRID_BANDS; |
120 | | |
121 | 7.96k | memset(pstr_ps_enc->m_hybrid_real_right[i], 0, |
122 | 7.96k | IXHEAACE_NUM_HYBRID_BANDS * sizeof(pstr_ps_enc->m_hybrid_real_right[0])); |
123 | | |
124 | 7.96k | pstr_ps_enc->m_hybrid_imag_right[i] = ptr1; |
125 | 7.96k | ptr1 += IXHEAACE_NUM_HYBRID_BANDS; |
126 | | |
127 | 7.96k | memset(pstr_ps_enc->m_hybrid_imag_right[i], 0, |
128 | 7.96k | IXHEAACE_NUM_HYBRID_BANDS * sizeof(pstr_ps_enc->m_hybrid_imag_right[0])); |
129 | 7.96k | } |
130 | | |
131 | 249 | pstr_ps_enc->temp_qmf_left_real = (FLOAT32 **)ptr1; |
132 | 249 | ptr1 += IXHEAACE_HYBRID_FILTER_DELAY * sizeof(FLOAT32 *) / sizeof(FLOAT32); |
133 | | |
134 | 249 | pstr_ps_enc->temp_qmf_left_imag = (FLOAT32 **)ptr1; |
135 | 249 | ptr1 += IXHEAACE_HYBRID_FILTER_DELAY * sizeof(WORD32 *) / sizeof(WORD32); |
136 | | |
137 | 249 | pstr_ps_enc->hist_qmf_left_real = (FLOAT32 **)ptr2; |
138 | 249 | ptr2 += IXHEAACE_HYBRID_FILTER_DELAY * sizeof(FLOAT32 *) / sizeof(FLOAT32); |
139 | | |
140 | 249 | pstr_ps_enc->hist_qmf_left_imag = (FLOAT32 **)ptr2; |
141 | 249 | ptr2 += IXHEAACE_HYBRID_FILTER_DELAY * sizeof(FLOAT32 *) / sizeof(FLOAT32); |
142 | | |
143 | 249 | pstr_ps_enc->hist_qmf_right_real = (FLOAT32 **)ptr2; |
144 | 249 | ptr2 += IXHEAACE_HYBRID_FILTER_DELAY * sizeof(FLOAT32 *) / sizeof(FLOAT32); |
145 | | |
146 | 249 | pstr_ps_enc->hist_qmf_right_imag = (FLOAT32 **)ptr2; |
147 | 249 | ptr2 += IXHEAACE_HYBRID_FILTER_DELAY * sizeof(FLOAT32 *) / sizeof(FLOAT32); |
148 | | |
149 | 1.74k | for (i = 0; i < IXHEAACE_HYBRID_FILTER_DELAY; i++) { |
150 | 1.49k | pstr_ps_enc->temp_qmf_left_real[i] = ptr1; |
151 | 1.49k | ptr1 += NUMBER_OF_QMF_BANDS; |
152 | 1.49k | memset(pstr_ps_enc->temp_qmf_left_real[i], 0, |
153 | 1.49k | NUMBER_OF_QMF_BANDS * sizeof(pstr_ps_enc->temp_qmf_left_real[0])); |
154 | | |
155 | 1.49k | pstr_ps_enc->temp_qmf_left_imag[i] = ptr1; |
156 | 1.49k | ptr1 += NUMBER_OF_QMF_BANDS; |
157 | | |
158 | 1.49k | memset(pstr_ps_enc->temp_qmf_left_imag[i], 0, |
159 | 1.49k | NUMBER_OF_QMF_BANDS * sizeof(pstr_ps_enc->temp_qmf_left_imag[0])); |
160 | | |
161 | 1.49k | pstr_ps_enc->hist_qmf_left_real[i] = ptr2; |
162 | 1.49k | ptr2 += NUMBER_OF_QMF_BANDS; |
163 | | |
164 | 1.49k | memset(pstr_ps_enc->hist_qmf_left_real[i], 0, |
165 | 1.49k | NUMBER_OF_QMF_BANDS * sizeof(pstr_ps_enc->hist_qmf_left_real[0])); |
166 | | |
167 | 1.49k | pstr_ps_enc->hist_qmf_left_imag[i] = ptr2; |
168 | 1.49k | ptr2 += NUMBER_OF_QMF_BANDS; |
169 | | |
170 | 1.49k | memset(pstr_ps_enc->hist_qmf_left_imag[i], 0, |
171 | 1.49k | NUMBER_OF_QMF_BANDS * sizeof(pstr_ps_enc->hist_qmf_left_imag[0])); |
172 | | |
173 | 1.49k | pstr_ps_enc->hist_qmf_right_real[i] = ptr2; |
174 | 1.49k | ptr2 += NUMBER_OF_QMF_BANDS; |
175 | | |
176 | 1.49k | memset(pstr_ps_enc->hist_qmf_right_real[i], 0, |
177 | 1.49k | NUMBER_OF_QMF_BANDS * sizeof(pstr_ps_enc->hist_qmf_right_real[0])); |
178 | | |
179 | 1.49k | pstr_ps_enc->hist_qmf_right_imag[i] = ptr2; |
180 | 1.49k | ptr2 += NUMBER_OF_QMF_BANDS; |
181 | | |
182 | 1.49k | memset(pstr_ps_enc->hist_qmf_right_imag[i], 0, |
183 | 1.49k | NUMBER_OF_QMF_BANDS * sizeof(pstr_ps_enc->hist_qmf_right_imag[0])); |
184 | 1.49k | } |
185 | | |
186 | 249 | memset(pstr_ps_enc->pow_left_right, 0, sizeof(pstr_ps_enc->pow_left_right)); |
187 | 249 | memset(pstr_ps_enc->pow_corr_real_imag, 0, sizeof(pstr_ps_enc->pow_corr_real_imag)); |
188 | | |
189 | 249 | if ((pstr_ps_enc->hist_qmf_left_real == NULL) || (pstr_ps_enc->hist_qmf_left_imag == NULL) || |
190 | 249 | (pstr_ps_enc->hist_qmf_right_real == NULL) || (pstr_ps_enc->hist_qmf_right_imag == NULL)) { |
191 | 0 | return IA_EXHEAACE_INIT_FATAL_PS_INIT_FAILED; |
192 | 0 | } |
193 | | |
194 | 4.32k | for (i = 0; i < pstr_ps_enc->iid_icc_bins; i++) { |
195 | 4.08k | pstr_ps_enc->aaa_IID_data_buf[i][0] = 0; |
196 | 4.08k | pstr_ps_enc->aaa_ICC_data_buf[i][0] = -1.0f; |
197 | 4.08k | } |
198 | | |
199 | 249 | pstr_ps_enc->bit_buf_read_offset = 0; |
200 | 249 | pstr_ps_enc->bit_buf_write_offset = 0; |
201 | | |
202 | 249 | ia_enhaacplus_enc_create_bitbuffer(&pstr_ps_enc->ps_bit_buf, (UWORD8 *)ptr1, 255 + 15); |
203 | | |
204 | 249 | pstr_ps_enc->ps_bit_buf.ptr_read_next = |
205 | 249 | pstr_ps_enc->ps_bit_buf.ptr_bit_buf_base + pstr_ps_enc->bit_buf_read_offset; |
206 | 249 | pstr_ps_enc->ps_bit_buf.ptr_write_next = |
207 | 249 | pstr_ps_enc->ps_bit_buf.ptr_bit_buf_base + pstr_ps_enc->bit_buf_write_offset; |
208 | | |
209 | 249 | return err; |
210 | 249 | } |