/src/libxaac/encoder/ixheaace_radix2_fft.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 <math.h> |
22 | | #include "ixheaac_type_def.h" |
23 | | #include "ixheaac_constants.h" |
24 | | #include "ixheaace_aac_constants.h" |
25 | | #include "ixheaace_psy_const.h" |
26 | | #include "ixheaace_tns.h" |
27 | | #include "ixheaace_tns_params.h" |
28 | | #include "ixheaace_rom.h" |
29 | | #include "ixheaace_common_rom.h" |
30 | | #include "ixheaace_bitbuffer.h" |
31 | | |
32 | | static VOID ia_enhaacplus_enc_ps_fft(complex *out, LOOPINDEX N, WORD32 nob, |
33 | 4.65M | ixheaace_common_tables *comm_tab_ptr) { |
34 | 4.65M | LOOPINDEX block_per_stage, stage_num, inner; |
35 | | |
36 | 4.65M | WORD32 index_1, index_2, tab_modifier; |
37 | 4.65M | WORD32 len, increment, i; |
38 | | |
39 | 4.65M | FLOAT32 cos_val; |
40 | 4.65M | FLOAT32 sin_val; |
41 | | |
42 | 4.65M | WORD16 index1; |
43 | 4.65M | FLOAT32 re_temp, re_temp2; |
44 | 4.65M | FLOAT32 im_temp, im_temp2; |
45 | 4.65M | FLOAT32 *out1_w32, *out2_w32; |
46 | | |
47 | 4.65M | len = N >> 1; |
48 | 4.65M | index_1 = 0; |
49 | | |
50 | 4.65M | out1_w32 = (FLOAT32 *)&out[index_1]; |
51 | 4.65M | out2_w32 = (FLOAT32 *)&out[index_1 + 1]; |
52 | | |
53 | 17.0M | for (block_per_stage = len - 1; block_per_stage >= 0; block_per_stage--) { |
54 | 12.4M | re_temp = out1_w32[0]; |
55 | 12.4M | im_temp = out1_w32[1]; |
56 | | |
57 | 12.4M | re_temp2 = out2_w32[0]; |
58 | 12.4M | im_temp2 = out2_w32[1]; |
59 | | |
60 | 12.4M | out1_w32[0] = re_temp + re_temp2; |
61 | 12.4M | out1_w32[1] = im_temp + im_temp2; |
62 | | |
63 | 12.4M | out2_w32[0] = re_temp - re_temp2; |
64 | 12.4M | out2_w32[1] = im_temp - im_temp2; |
65 | | |
66 | 12.4M | out1_w32 += 4; |
67 | 12.4M | out2_w32 += 4; |
68 | 12.4M | } |
69 | | |
70 | 4.65M | if (nob == 3) { |
71 | 1.55M | i = 2; /* used for dist calculation*/ |
72 | 1.55M | increment = 1; |
73 | 1.55M | tab_modifier = 2; |
74 | 4.65M | for (stage_num = 1; stage_num >= 0; stage_num--) { |
75 | 3.10M | len = len >> 1; |
76 | 3.10M | index_1 = 0; |
77 | 3.10M | increment += 1; |
78 | | |
79 | 3.10M | tab_modifier--; |
80 | | |
81 | 7.76M | for (block_per_stage = len - 1; block_per_stage >= 0; block_per_stage--) { |
82 | 4.65M | index_2 = index_1 + i; |
83 | | |
84 | 4.65M | out1_w32 = (FLOAT32 *)&out[index_1]; |
85 | 4.65M | out2_w32 = (FLOAT32 *)&out[index_2]; |
86 | | |
87 | 4.65M | re_temp = out1_w32[0]; |
88 | 4.65M | im_temp = out1_w32[1]; |
89 | | |
90 | 4.65M | re_temp2 = out2_w32[0]; |
91 | 4.65M | im_temp2 = out2_w32[1]; |
92 | | |
93 | 4.65M | out1_w32[0] = re_temp + re_temp2; |
94 | 4.65M | out1_w32[1] = im_temp + im_temp2; |
95 | | |
96 | 4.65M | out2_w32[0] = re_temp - re_temp2; |
97 | 4.65M | out2_w32[1] = im_temp - im_temp2; |
98 | | |
99 | 4.65M | index1 = (WORD16)tab_modifier; |
100 | | |
101 | 4.65M | out1_w32 += 2; |
102 | 4.65M | out2_w32 += 2; |
103 | | |
104 | 12.4M | for (inner = 0; inner < (2 * i - 2); inner += 2) { |
105 | 7.76M | cos_val = comm_tab_ptr->cos_arr[index1]; |
106 | 7.76M | sin_val = comm_tab_ptr->sin_arr[index1]; |
107 | | |
108 | 7.76M | index1++; |
109 | | |
110 | 7.76M | re_temp = (out2_w32[inner] * cos_val) + (out2_w32[inner + 1] * sin_val); |
111 | 7.76M | im_temp = (out2_w32[inner + 1] * cos_val) - (out2_w32[inner] * sin_val); |
112 | | |
113 | 7.76M | re_temp2 = out1_w32[inner]; |
114 | 7.76M | im_temp2 = out1_w32[inner + 1]; |
115 | | |
116 | 7.76M | out1_w32[inner] = re_temp2 + re_temp; |
117 | 7.76M | out1_w32[inner + 1] = im_temp2 + im_temp; |
118 | | |
119 | 7.76M | out2_w32[inner] = re_temp2 - re_temp; |
120 | 7.76M | out2_w32[inner + 1] = im_temp2 - im_temp; |
121 | 7.76M | } |
122 | | |
123 | 4.65M | index_1 += (WORD32)pow(2, increment); |
124 | 4.65M | } |
125 | 3.10M | i <<= 1; |
126 | 3.10M | } |
127 | 3.10M | } else { |
128 | 3.10M | out1_w32 = (FLOAT32 *)&out[0]; |
129 | 3.10M | out2_w32 = (FLOAT32 *)&out[2]; |
130 | | |
131 | 3.10M | re_temp = out1_w32[0]; |
132 | 3.10M | im_temp = out1_w32[1]; |
133 | | |
134 | 3.10M | re_temp2 = out2_w32[0]; |
135 | 3.10M | im_temp2 = out2_w32[1]; |
136 | | |
137 | 3.10M | out1_w32[0] = re_temp + re_temp2; |
138 | 3.10M | out1_w32[1] = im_temp + im_temp2; |
139 | | |
140 | 3.10M | out2_w32[0] = re_temp - re_temp2; |
141 | 3.10M | out2_w32[1] = im_temp - im_temp2; |
142 | | |
143 | 3.10M | out1_w32 += 2; |
144 | 3.10M | out2_w32 += 2; |
145 | | |
146 | 3.10M | sin_val = comm_tab_ptr->sin_arr[1]; |
147 | | |
148 | 3.10M | re_temp = out2_w32[1] * sin_val; |
149 | 3.10M | im_temp = out2_w32[0] * sin_val; |
150 | | |
151 | 3.10M | re_temp2 = out1_w32[0]; |
152 | 3.10M | im_temp2 = out1_w32[1]; |
153 | | |
154 | 3.10M | out1_w32[0] = re_temp2 + re_temp; |
155 | 3.10M | out1_w32[1] = im_temp2 - im_temp; |
156 | | |
157 | 3.10M | out2_w32[0] = re_temp2 - re_temp; |
158 | 3.10M | out2_w32[1] = im_temp2 + im_temp; |
159 | 3.10M | } |
160 | 4.65M | } |
161 | | |
162 | 4.65M | VOID ia_enhaacplus_enc_fft(complex *out, WORD32 N, ixheaace_common_tables *pstr_common_tab) { |
163 | 4.65M | WORD32 nob; |
164 | 4.65M | WORD32 len; |
165 | | |
166 | | /* time domain samples obtained with bit reversal*/ |
167 | 4.65M | len = N; |
168 | | |
169 | 4.65M | if (len == 8) { |
170 | 1.55M | nob = 3; |
171 | 3.10M | } else { |
172 | 3.10M | nob = 2; |
173 | 3.10M | } |
174 | 4.65M | ia_enhaacplus_enc_ps_fft(out, N, nob, pstr_common_tab); |
175 | 4.65M | } |