/src/libxaac/encoder/iusace_tcx_mdct.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 "ixheaac_type_def.h" |
22 | | #include "iusace_block_switch_const.h" |
23 | | #include "iusace_cnst.h" |
24 | | #include "iusace_rom.h" |
25 | | #include "iusace_bitbuffer.h" |
26 | | |
27 | | /* DRC */ |
28 | | #include "impd_drc_common_enc.h" |
29 | | #include "impd_drc_uni_drc.h" |
30 | | #include "impd_drc_tables.h" |
31 | | #include "impd_drc_api.h" |
32 | | #include "impd_drc_uni_drc_eq.h" |
33 | | #include "impd_drc_uni_drc_filter_bank.h" |
34 | | #include "impd_drc_gain_enc.h" |
35 | | #include "impd_drc_struct_def.h" |
36 | | |
37 | | #include "iusace_tns_usac.h" |
38 | | #include "iusace_psy_mod.h" |
39 | | #include "iusace_tns_usac.h" |
40 | | #include "iusace_config.h" |
41 | | #include "iusace_fft.h" |
42 | | #include "iusace_tcx_mdct.h" |
43 | | |
44 | | VOID iusace_tcx_mdct_main(FLOAT32 *ptr_in, FLOAT32 *ptr_out, WORD32 l, WORD32 m, WORD32 r, |
45 | 1.08M | iusace_scratch_mem *pstr_scratch) { |
46 | 1.08M | WORD32 length = l / 2 + m + r / 2; |
47 | 1.08M | FLOAT32 *input = pstr_scratch->p_tcx_input; |
48 | 1.08M | WORD32 i; |
49 | | |
50 | 91.3M | for (i = 0; i < m / 2; i++) { |
51 | 90.2M | input[m / 2 + r / 2 + i] = -ptr_in[l + m / 2 - 1 - i]; |
52 | 90.2M | } |
53 | 127M | for (i = 0; i < l / 2; i++) { |
54 | 126M | input[m / 2 + r / 2 + m / 2 + i] = ptr_in[i] - ptr_in[l - 1 - i]; |
55 | 126M | } |
56 | 91.3M | for (i = 0; i < m / 2; i++) { |
57 | 90.2M | input[m / 2 + r / 2 - 1 - i] = -ptr_in[l + m / 2 + i]; |
58 | 90.2M | } |
59 | 127M | for (i = 0; i < r / 2; i++) { |
60 | 126M | input[m / 2 + r / 2 - 1 - m / 2 - i] = -ptr_in[l + m + i] - ptr_in[l + m + r - 1 - i]; |
61 | 126M | } |
62 | | |
63 | 1.08M | iusace_tcx_mdct(input, ptr_out, length, pstr_scratch); |
64 | | |
65 | 1.08M | return; |
66 | 1.08M | } |
67 | | |
68 | | VOID iusace_tcx_imdct(FLOAT32 *ptr_in, FLOAT32 *ptr_out, WORD32 l, WORD32 m, WORD32 r, |
69 | 1.08M | iusace_scratch_mem *pstr_scratch) { |
70 | 1.08M | WORD32 length = l / 2 + m + r / 2; |
71 | 1.08M | FLOAT32 *output = pstr_scratch->p_tcx_output; |
72 | 1.08M | iusace_tcx_mdct(ptr_in, output, length, pstr_scratch); |
73 | | |
74 | 1.08M | WORD32 i; |
75 | | |
76 | 91.3M | for (i = 0; i < m / 2; i++) { |
77 | 90.2M | ptr_out[l + m / 2 - 1 - i] = -1.0f * output[m / 2 + r / 2 + i]; |
78 | 90.2M | } |
79 | 127M | for (i = 0; i < l / 2; i++) { |
80 | 126M | ptr_out[i] = output[m / 2 + r / 2 + m / 2 + i]; |
81 | 126M | ptr_out[l - 1 - i] = -1.0f * output[m / 2 + r / 2 + m / 2 + i]; |
82 | 126M | } |
83 | 91.3M | for (i = 0; i < m / 2; i++) { |
84 | 90.2M | ptr_out[l + m / 2 + i] = -1.0f * output[m / 2 + r / 2 - 1 - i]; |
85 | 90.2M | } |
86 | 127M | for (i = 0; i < r / 2; i++) { |
87 | 126M | ptr_out[l + m + i] = -1.0f * output[m / 2 + r / 2 - 1 - m / 2 - i]; |
88 | 126M | ptr_out[l + m + r - 1 - i] = -1.0f * output[m / 2 + r / 2 - 1 - m / 2 - i]; |
89 | 126M | } |
90 | 1.08M | return; |
91 | 1.08M | } |
92 | | |
93 | | static VOID iusace_get_pre_post_twid(FLOAT32 **ptr_pre_twid_re, FLOAT32 **ptr_pre_twid_im, |
94 | | FLOAT32 **ptr_post_twid_re, FLOAT32 **ptr_post_twid_im, |
95 | 6.51M | WORD32 length) { |
96 | 6.51M | switch (length) { |
97 | 396k | case 512: |
98 | 396k | *ptr_pre_twid_re = (FLOAT32 *)&iusace_pre_post_twid_cos_sin_256[0][0]; |
99 | 396k | *ptr_pre_twid_im = (FLOAT32 *)&iusace_pre_post_twid_cos_sin_256[1][0]; |
100 | 396k | *ptr_post_twid_re = (FLOAT32 *)&iusace_pre_post_twid_cos_sin_256[2][0]; |
101 | 396k | *ptr_post_twid_im = (FLOAT32 *)&iusace_pre_post_twid_cos_sin_256[3][0]; |
102 | 396k | break; |
103 | 792k | case 256: |
104 | 792k | *ptr_pre_twid_re = (FLOAT32 *)&iusace_pre_post_twid_cos_sin_128[0][0]; |
105 | 792k | *ptr_pre_twid_im = (FLOAT32 *)&iusace_pre_post_twid_cos_sin_128[1][0]; |
106 | 792k | *ptr_post_twid_re = (FLOAT32 *)&iusace_pre_post_twid_cos_sin_128[2][0]; |
107 | 792k | *ptr_post_twid_im = (FLOAT32 *)&iusace_pre_post_twid_cos_sin_128[3][0]; |
108 | 792k | break; |
109 | 2.78M | case 128: |
110 | 2.78M | *ptr_pre_twid_re = (FLOAT32 *)&iusace_pre_post_twid_cos_sin_64[0][0]; |
111 | 2.78M | *ptr_pre_twid_im = (FLOAT32 *)&iusace_pre_post_twid_cos_sin_64[1][0]; |
112 | 2.78M | *ptr_post_twid_re = (FLOAT32 *)&iusace_pre_post_twid_cos_sin_64[2][0]; |
113 | 2.78M | *ptr_post_twid_im = (FLOAT32 *)&iusace_pre_post_twid_cos_sin_64[3][0]; |
114 | 2.78M | break; |
115 | 681 | case 64: |
116 | 681 | *ptr_pre_twid_re = (FLOAT32 *)&iusace_pre_post_twid_cos_sin_32[0][0]; |
117 | 681 | *ptr_pre_twid_im = (FLOAT32 *)&iusace_pre_post_twid_cos_sin_32[1][0]; |
118 | 681 | *ptr_post_twid_re = (FLOAT32 *)&iusace_pre_post_twid_cos_sin_32[2][0]; |
119 | 681 | *ptr_post_twid_im = (FLOAT32 *)&iusace_pre_post_twid_cos_sin_32[3][0]; |
120 | 681 | break; |
121 | 2.54M | default: |
122 | 2.54M | *ptr_pre_twid_re = (FLOAT32 *)&iusace_pre_post_twid_cos_sin_512[0][0]; |
123 | 2.54M | *ptr_pre_twid_im = (FLOAT32 *)&iusace_pre_post_twid_cos_sin_512[1][0]; |
124 | 2.54M | *ptr_post_twid_re = (FLOAT32 *)&iusace_pre_post_twid_cos_sin_512[2][0]; |
125 | 2.54M | *ptr_post_twid_im = (FLOAT32 *)&iusace_pre_post_twid_cos_sin_512[3][0]; |
126 | 6.51M | } |
127 | | |
128 | 6.51M | return; |
129 | 6.51M | } |
130 | | |
131 | | static VOID iusace_pre_twid(FLOAT32 *ptr_twid_re, FLOAT32 *ptr_twid_im, FLOAT32 *ptr_in, |
132 | 6.51M | WORD32 length) { |
133 | 6.51M | WORD32 i; |
134 | 692M | for (i = 0; i < length; i++) { |
135 | 686M | FLOAT32 temp = ptr_in[2 * i] * ptr_twid_re[i] - ptr_in[2 * i + 1] * ptr_twid_im[i]; |
136 | | |
137 | 686M | ptr_in[2 * i + 1] = ptr_in[2 * i] * ptr_twid_im[i] + ptr_in[2 * i + 1] * ptr_twid_re[i]; |
138 | | |
139 | 686M | ptr_in[2 * i] = temp; |
140 | 686M | } |
141 | 6.51M | return; |
142 | 6.51M | } |
143 | | |
144 | | static VOID iusace_post_twid(FLOAT32 *ptr_twid_re, FLOAT32 *ptr_twid_im, FLOAT32 *ptr_in, |
145 | 6.51M | WORD32 length) { |
146 | 6.51M | WORD32 i; |
147 | 692M | for (i = 0; i < length; i++) { |
148 | 686M | FLOAT32 temp = ptr_in[2 * i] * ptr_twid_re[i] - ptr_in[2 * i + 1] * ptr_twid_im[i]; |
149 | | |
150 | 686M | ptr_in[2 * i + 1] = -ptr_in[2 * i] * ptr_twid_im[i] - ptr_in[2 * i + 1] * ptr_twid_re[i]; |
151 | 686M | ptr_in[2 * i] = temp; |
152 | 686M | } |
153 | 6.51M | return; |
154 | 6.51M | } |
155 | | |
156 | | VOID iusace_tcx_mdct(FLOAT32 *ptr_in, FLOAT32 *ptr_out, WORD32 length, |
157 | 6.51M | iusace_scratch_mem *pstr_scratch) { |
158 | 6.51M | FLOAT32 *ptr_pre_twid_re, *ptr_pre_twid_im; |
159 | 6.51M | FLOAT32 *ptr_post_twid_re, *ptr_post_twid_im; |
160 | 6.51M | WORD32 i; |
161 | 6.51M | FLOAT32 *ptr_real = pstr_scratch->p_temp_mdct; |
162 | 6.51M | WORD32 len_by_2 = length >> 1; |
163 | | |
164 | 6.51M | iusace_get_pre_post_twid(&ptr_pre_twid_re, &ptr_pre_twid_im, &ptr_post_twid_re, |
165 | 6.51M | &ptr_post_twid_im, length); |
166 | | |
167 | 692M | for (i = 0; i < len_by_2; i++) { |
168 | 686M | ptr_real[2 * i] = ptr_in[2 * i]; |
169 | 686M | ptr_real[2 * i + 1] = ptr_in[length - 1 - 2 * i]; |
170 | 686M | } |
171 | | |
172 | | /* pre twiddle */ |
173 | 6.51M | iusace_pre_twid(ptr_pre_twid_re, ptr_pre_twid_im, ptr_real, len_by_2); |
174 | | |
175 | 6.51M | iusace_complex_fft(ptr_real, len_by_2, pstr_scratch); |
176 | | |
177 | | /* post twiddle */ |
178 | 6.51M | iusace_post_twid(ptr_post_twid_re, ptr_post_twid_im, ptr_real, len_by_2); |
179 | | |
180 | 692M | for (i = 0; i < len_by_2; i++) { |
181 | 686M | ptr_out[2 * i] = ptr_real[2 * i]; |
182 | 686M | ptr_out[length - 1 - 2 * i] = ptr_real[2 * i + 1]; |
183 | 686M | } |
184 | | |
185 | 6.51M | return; |
186 | 6.51M | } |