xref: /aosp_15_r20/external/libxaac/encoder/ixheaace_mps_rom.c (revision 15dc779a375ca8b5125643b829a8aa4b70d7f451)
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 "ixheaace_mps_common_fix.h"
23 #include "ixheaace_mps_defines.h"
24 #include "ixheaace_mps_common_define.h"
25 #include "ixheaace_bitbuffer.h"
26 
27 #include "ixheaace_mps_struct_def.h"
28 #include "ixheaace_mps_sac_polyphase.h"
29 #include "ixheaace_mps_sac_hybfilter.h"
30 #include "ixheaace_mps_spatial_bitstream.h"
31 #include "ixheaace_mps_param_extract.h"
32 #include "ixheaace_mps_bitstream.h"
33 #include "ixheaace_mps_tree.h"
34 
35 const UWORD8 freq_res_bin_table_ld[MAX_FREQ_RES_INDEX] = {0, 23, 15, 12, 9, 7, 5, 4};
36 
37 const UWORD8 freq_res_bin_table_usac[8] = {0, 28, 20, 14, 10, 7, 5, 4};
38 
39 const UWORD8 freq_res_stride_table_212[4] = {1, 2, 5, 23};
40 
41 const ixheaace_mps_sac_tree_description tree_config_table[] = {{5, {0, 0, 0, 0, 1}, 0, 1, 6, 0},
42                                                                {5, {0, 0, 1, 0, 0}, 0, 1, 6, 0},
43                                                                {3, {1, 0, 0, 0, 0}, 1, 2, 6, 0}};
44 const ixheaace_mps_tree_setup tree_setup_table = {
45     2, 1, 1, {{0, 0, 1, 0, 1, WIN_ACTIV, WIN_ACTIV}}};
46 
47 const WORD32 freq_res_bin_table[] = {0, 28, 20, 14, 10, 7, 5, 4};
48 const UWORD8 valid_bands_ld[10] = {4, 5, 7, 9, 12, 15, 20, 23, 28, 40};
49 const WORD32 freq_res_stride_table[] = {1, 2, 5, 23, 28};
50 const UWORD8 lav_huff_val[4] = {0, 2, 6, 7};
51 const UWORD8 lav_huff_len[4] = {1, 2, 3, 3};
52 
53 const UWORD8 lav_step_cld[] = {0, 0, 0, 0, 1, 1, 2, 2, 3, 3};
54 const UWORD8 lav_step_icc[] = {0, 0, 1, 1, 2, 2, 3, 3};
55 
56 const WORD32 temp_shape_chan_table[][7] = {{5, 5, 4, 6, 6, 4, 4}, {5, 5, 5, 7, 7, 4, 4}};
57 
58 const UWORD8 subband_2_parameter_ld[NUM_QMF_BANDS] = {
59     14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
60     14, 14, 14, 14, 14, 14, 14, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 12, 12, 12,
61     12, 12, 11, 11, 11, 11, 10, 10, 10, 9,  9,  8,  7,  6,  5,  4,  3,  2,  1,  0};
62 
63 const UWORD8 subband_2_parameter_usac[MAX_QMF_BANDS] = {
64     27, 27, 27, 27, 27, 27, 27, 27, 27, 26, 26, 26, 26, 26, 26, 26, 25, 25, 25, 25, 25, 25,
65     24, 24, 24, 24, 24, 23, 23, 23, 23, 22, 22, 22, 21, 21, 21, 20, 20, 19, 19, 18, 18, 17,
66     17, 16, 15, 14, 13, 12, 11, 10, 9,  8,  7,  6,  5,  4,  3,  2,  1,  0,  0,  1};
67 
68 const FLOAT32 cld_quant_table_fine_enc[IXHEAACE_MPS_MAX_CLD_QUANT_FINE] = {
69     -50.0f, -45.0f, -40.0f, -35.0f, -30.0f, -25.0f, -22.0f, -19.0f, -16.0f, -13.0f, -10.0f,
70     -8.0f,  -6.0f,  -4.0f,  -2.0f,  0.0f,   2.0f,   4.0f,   6.0f,   8.0f,   10.0f,  13.0f,
71     16.0f,  19.0f,  22.0f,  25.0f,  30.0f,  35.0f,  40.0f,  45.0f,  50.0f};
72 
73 const FLOAT32 cld_quant_table_coarse_enc[IXHEAACE_MPS_MAX_CLD_QUANT_COARSE] = {
74     -50.0f, -35.0f, -25.0f, -19.0f, -13.0f, -8.0f, -4.0f, 0.0f,
75     4.0f,   8.0f,   13.0f,  19.0f,  25.0f,  35.0f, 50.0f};
76 
77 const FLOAT32 icc_quant_table_fine[IXHEAACE_MPS_MAX_ICC_QUANT_FINE] = {
78     0.9995f, 0.937f, 0.84118f, 0.60092f, 0.36764f, 0.0f, -0.589f, -0.99f};
79 
80 const FLOAT32 icc_quant_table_coarse[IXHEAACE_MPS_MAX_ICC_QUANT_COARSE] = {0.99f, 0.84118f,
81                                                                            0.36764f, -0.5890f};
82 
83 const FLOAT32 pre_gain_factor_table_flt_new[41] = {
84     0.800000012f, 0.897614777f, 0.503570139f, 0.565015018f, 0.633957267f, 0.711311758f,
85     0.798104942f, 0.895488441f, 0.502377272f, 0.563676596f, 0.632455528f, 0.709626794f,
86     0.796214342f, 0.893367171f, 0.501187205f, 0.562341332f, 0.630957365f, 0.707945764f,
87     0.794328213f, 0.891250908f, 0.5f,         0.561009228f, 0.629462719f, 0.706268787f,
88     0.792446613f, 0.889139712f, 0.997631133f, 0.559680283f, 0.62797159f,  0.704595745f,
89     0.790569425f, 0.887033463f, 0.995267928f, 0.558354497f, 0.626484036f, 0.702926636f,
90     0.788696706f, 0.88493222f,  0.992910266f, 0.55703181f,  0.625f};
91 
92 const FLOAT32 dmx_gain_table_flt[] = {0.84089650f, 0.70710706f, 0.59460385f, 0.50000000f,
93                                       0.42044825f, 0.35355341f, 0.25000000f};
94 
95 const FLOAT32 ia_mps_enc_qmf_64_640[325] = {
96     -0.0005525286f, 0.0143904666f,  0.3723795546f, -0.3499914122f, -0.0121849995f,
97     -0.0005617692f, 0.0155405553f,  0.3836350013f, -0.3388722693f, -0.0111315548f,
98     -0.0004947518f, 0.0167324712f,  0.3949211761f, -0.3278113727f, -0.0101150215f,
99     -0.0004875227f, 0.0179433381f,  0.4062317676f, -0.3168278913f, -0.0091325329f,
100     -0.0004893791f, 0.0191872431f,  0.4175696896f, -0.3059098575f, -0.0081798233f,
101     -0.0005040714f, 0.0204531793f,  0.4289119920f, -0.2950716717f, -0.0072615816f,
102     -0.0005226564f, 0.0217467550f,  0.4402553754f, -0.2843214189f, -0.0063792293f,
103     -0.0005466565f, 0.0230680169f,  0.4515996535f, -0.2736634040f, -0.0055337211f,
104     -0.0005677802f, 0.0244160992f,  0.4629308085f, -0.2631053299f, -0.0047222596f,
105     -0.0005870930f, 0.0257875847f,  0.4742453214f, -0.2526480309f, -0.0039401124f,
106     -0.0006132747f, 0.0271859429f,  0.4855253091f, -0.2423016884f, -0.0031933778f,
107     -0.0006312493f, 0.0286072173f,  0.4967708254f, -0.2320690870f, -0.0024826723f,
108     -0.0006540333f, 0.0300502657f,  0.5079817500f, -0.2219652696f, -0.0018039472f,
109     -0.0006777690f, 0.0315017608f,  0.5191234970f, -0.2119735853f, -0.0011568135f,
110     -0.0006941614f, 0.0329754081f,  0.5302240895f, -0.2021250176f, -0.0005464280f,
111     -0.0007157736f, 0.0344620948f,  0.5412553448f, -0.1923966745f, 0.0000276045f,
112     -0.0007255043f, 0.0359697560f,  0.5522051258f, -0.1828172548f, 0.0005832264f,
113     -0.0007440941f, 0.0374812850f,  0.5630789140f, -0.1733808172f, 0.0010902329f,
114     -0.0007490598f, 0.0390053679f,  0.5738524131f, -0.1640958855f, 0.0015784682f,
115     -0.0007681371f, 0.0405349170f,  0.5845403235f, -0.1549607071f, 0.0020274176f,
116     -0.0007724848f, 0.0420649094f,  0.5951123086f, -0.1459766491f, 0.0024508540f,
117     -0.0007834332f, 0.0436097542f,  0.6055783538f, -0.1371551761f, 0.0028446757f,
118     -0.0007779869f, 0.0451488405f,  0.6159109932f, -0.1285002850f, 0.0032091885f,
119     -0.0007803664f, 0.0466843027f,  0.6261242695f, -0.1200077984f, 0.0035401246f,
120     -0.0007801449f, 0.0482165720f,  0.6361980107f, -0.1116826931f, 0.0038456408f,
121     -0.0007757977f, 0.0497385755f,  0.6461269695f, -0.1035329531f, 0.0041251642f,
122     -0.0007630793f, 0.0512556155f,  0.6559016302f, -0.0955533352f, 0.0043801861f,
123     -0.0007530001f, 0.0527630746f,  0.6655139880f, -0.0877547536f, 0.0046039530f,
124     -0.0007319357f, 0.0542452768f,  0.6749663190f, -0.0801372934f, 0.0048109469f,
125     -0.0007215391f, 0.0557173648f,  0.6842353293f, -0.0726943300f, 0.0049839687f,
126     -0.0006917937f, 0.0571616450f,  0.6933282376f, -0.0654409853f, 0.0051382275f,
127     -0.0006650415f, 0.0585915683f,  0.7022388719f, -0.0583705326f, 0.0052715758f,
128     -0.0006341594f, 0.0599837480f,  0.7109410426f, -0.0514804176f, 0.0053838975f,
129     -0.0005946118f, 0.0613455171f,  0.7194462634f, -0.0447806821f, 0.0054753783f,
130     -0.0005564576f, 0.0626857808f,  0.7277448900f, -0.0382776572f, 0.0055404363f,
131     -0.0005145572f, 0.0639715898f,  0.7358211758f, -0.0319531274f, 0.0055917128f,
132     -0.0004606325f, 0.0652247106f,  0.7436827863f, -0.0258227288f, 0.0056266114f,
133     -0.0004095121f, 0.0664367512f,  0.7513137456f, -0.0198834129f, 0.0056389199f,
134     -0.0003501175f, 0.0676075985f,  0.7587080760f, -0.0141288827f, 0.0056455196f,
135     -0.0002896981f, 0.0687043828f,  0.7658674865f, -0.0085711749f, 0.0056220643f,
136     -0.0002098337f, 0.0697630244f,  0.7727780881f, -0.0032086896f, 0.0055938023f,
137     -0.0001446380f, 0.0707628710f,  0.7794287519f, 0.0019765601f,  0.0055475714f,
138     -0.0000617334f, 0.0717002673f,  0.7858353120f, 0.0069636862f,  0.0054876040f,
139     0.0000134949f,  0.0725682583f,  0.7919735841f, 0.0117623832f,  0.0054196775f,
140     0.0001094383f,  0.0733620255f,  0.7978466413f, 0.0163701258f,  0.0053471681f,
141     0.0002043017f,  0.0741003642f,  0.8034485751f, 0.0207997072f,  0.0052461166f,
142     0.0002949531f,  0.0747452558f,  0.8087695004f, 0.0250307561f,  0.0051407353f,
143     0.0004026540f,  0.0753137336f,  0.8138191270f, 0.0290824006f,  0.0050393022f,
144     0.0005107388f,  0.0758008358f,  0.8185776004f, 0.0329583930f,  0.0049137603f,
145     0.0006239376f,  0.0761992479f,  0.8230419890f, 0.0366418116f,  0.0047932560f,
146     0.0007458025f,  0.0764992170f,  0.8272275347f, 0.0401458278f,  0.0046606460f,
147     0.0008608443f,  0.0767093490f,  0.8311038457f, 0.0434768782f,  0.0045209852f,
148     0.0009885988f,  0.0768173975f,  0.8346937361f, 0.0466303305f,  0.0043730719f,
149     0.0011250155f,  0.0768230011f,  0.8379717337f, 0.0495978676f,  0.0042264269f,
150     0.0012577884f,  0.0767204924f,  0.8409541392f, 0.0524093821f,  0.0040819753f,
151     0.0013902494f,  0.0765050718f,  0.8436238281f, 0.0550460034f,  0.0039207432f,
152     0.0015443219f,  0.0761748321f,  0.8459818469f, 0.0575152691f,  0.0037603922f,
153     0.0016868083f,  0.0757305756f,  0.8480315777f, 0.0598166570f,  0.0036008268f,
154     0.0018348265f,  0.0751576255f,  0.8497805198f, 0.0619602779f,  0.0034418874f,
155     0.0019841140f,  0.0744664394f,  0.8511971524f, 0.0639444805f,  0.0032739613f,
156     0.0021461583f,  0.0736406005f,  0.8523047035f, 0.0657690668f,  0.0031125420f,
157     0.0023017254f,  0.0726774642f,  0.8531020949f, 0.0674525021f,  0.0029469447f,
158     0.0024625616f,  0.0715826364f,  0.8535720573f, 0.0689664013f,  0.0027870464f,
159     0.0026201758f,  0.0703533073f,  0.8537385600f, 0.0703533073f,  0.0026201758f,
160     -0.0132718220f, -0.3611589903f, 0.3611589903f, 0.0132718220f,  0.0000000000f,
161 };
162 
163 const FLOAT32 trig_data_fct4_8[8] = {0.995184726672197f, 0.098017140329561f, 0.956940335732209f,
164                                      0.290284677254462f, 0.881921264348355f, 0.471396736825998f,
165                                      0.773010453362737f, 0.634393284163645f};
166 
167 const FLOAT32 trig_data_fct4_16[16] = {
168     0.998795456205172f, 0.049067674327418f, 0.989176509964781f, 0.146730474455362f,
169     0.970031253194544f, 0.242980179903264f, 0.941544065183021f, 0.336889853392220f,
170     0.903989293123443f, 0.427555093430282f, 0.857728610000272f, 0.514102744193222f,
171     0.803207531480645f, 0.595699304492433f, 0.740951125354959f, 0.671558954847018f};
172 const FLOAT32 trig_data_fct4_32[32] = {
173     0.999698818696204f, 0.024541228522912f, 0.997290456678690f, 0.073564563599667f,
174     0.992479534598710f, 0.122410675199216f, 0.985277642388941f, 0.170961888760301f,
175     0.975702130038529f, 0.219101240156870f, 0.963776065795440f, 0.266712757474898f,
176     0.949528180593037f, 0.313681740398892f, 0.932992798834739f, 0.359895036534988f,
177     0.914209755703531f, 0.405241314004990f, 0.893224301195515f, 0.449611329654607f,
178     0.870086991108711f, 0.492898192229784f, 0.844853565249707f, 0.534997619887097f,
179     0.817584813151584f, 0.575808191417845f, 0.788346427626606f, 0.615231590580627f,
180     0.757208846506485f, 0.653172842953777f, 0.724247082951467f, 0.689540544737067f};
181 
182 /*  sin (PI / L * n) */
183 const FLOAT32 sbr_alt_sin_twiddle[] = {
184     0.00000000000000f, 0.04906767432742f, 0.09801714032956f, 0.14673047445536f, 0.19509032201613f,
185     0.24298017990326f, 0.29028467725446f, 0.33688985339222f, 0.38268343236509f, 0.42755509343028f,
186     0.47139673682600f, 0.51410274419322f, 0.55557023301960f, 0.59569930449243f, 0.63439328416365f,
187     0.67155895484702f, 0.70710678118655f, 0.74095112535496f, 0.77301045336274f, 0.80320753148064f,
188     0.83146961230255f, 0.85772861000027f, 0.88192126434835f, 0.90398929312344f, 0.92387953251129f,
189     0.94154406518302f, 0.95694033573221f, 0.97003125319454f, 0.98078528040323f, 0.98917650996478f,
190     0.99518472667220f, 0.99879545620517f, 1.00000000000000f};
191 
192 const FLOAT32 sbr_cos_twiddle[] = {
193     0.99992470183914f, 0.99811811290015f, 0.99390697000236f, 0.98730141815786f, 0.97831737071963f,
194     0.96697647104485f, 0.95330604035419f, 0.93733901191257f, 0.91911385169006f, 0.89867446569395f,
195     0.87607009419541f, 0.85135519310527f, 0.82458930278503f, 0.79583690460888f, 0.76516726562246f,
196     0.73265427167241f, 0.69837624940897f, 0.66241577759017f, 0.62485948814239f, 0.58579785745644f,
197     0.54532498842205f, 0.50353838372572f, 0.46053871095824f, 0.41642956009764f, 0.37131719395184f,
198     0.32531029216226f, 0.27851968938505f, 0.23105810828067f, 0.18303988795514f, 0.13458070850713f,
199     0.08579731234444f, 0.03680722294136f};
200 /*  sin (PI / L * (n + 0.25)); */
201 const FLOAT32 sbr_sin_twiddle[] = {
202     0.01227153828572f, 0.06132073630221f, 0.11022220729388f, 0.15885814333386f, 0.20711137619222f,
203     0.25486565960451f, 0.30200594931923f, 0.34841868024943f, 0.39399204006105f, 0.43861623853853f,
204     0.48218377207912f, 0.52458968267847f, 0.56573181078361f, 0.60551104140433f, 0.64383154288979f,
205     0.68060099779545f, 0.71573082528382f, 0.74913639452346f, 0.78073722857209f, 0.81045719825259f,
206     0.83822470555484f, 0.86397285612159f, 0.88763962040285f, 0.90916798309052f, 0.92850608047322f,
207     0.94560732538052f, 0.96043051941557f, 0.97293995220556f, 0.98310548743122f, 0.99090263542778f,
208     0.99631261218278f, 0.99932238458835f,
209 };
210 
211 const FLOAT32 fft_c[4] = {9.807852804032304e-1f, 8.314696123025452e-1f, 5.555702330196023e-1f,
212                           1.950903220161283e-1f};
213 
214 const FLOAT32 p8_13[13] = {-0.00746082949812f,
215                            -0.02270420949825f,
216                            -0.04546865930473f,
217                            -0.07266113929591f,
218                            -0.09885108575264f,
219                            0.11793710567217f,
220                            0.125f,
221                            0.11793710567217f,
222                            0.09885108575264f,
223                            0.07266113929591f,
224                            0.04546865930473f,
225                            0.02270420949825f,
226                            0.00746082949812f};
227 
228 const FLOAT32 p2_6[6] = {0.01899487526049f, -0.07293139167538f, 0.30596630545168f,
229                          0.30596630545168f, -0.07293139167538f, 0.01899487526049f};
230 
231 const WORD32 kernels_20[MAX_HYBRID_BANDS] = {
232     1,  0,  0,  1,  2,  3,  4,  5,  6,  7,  8,  9,  10, 11, 12, 13, 14, 14,
233     15, 15, 15, 16, 16, 16, 16, 17, 17, 17, 17, 17, 18, 18, 18, 18, 18, 18,
234     18, 18, 18, 18, 18, 18, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
235     19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19};
236 
237 const FLOAT32 ia_qmf_anl_addt_cos[32] = {
238     0.99969881869620f, 0.99729045667869f, 0.99247953459871f, 0.98527764238894f, 0.97570213003853f,
239     0.96377606579544f, 0.94952818059304f, 0.93299279883474f, 0.91420975570353f, 0.89322430119552f,
240     0.87008699110871f, 0.84485356524971f, 0.81758481315158f, 0.78834642762661f, 0.75720884650649f,
241     0.72424708295147f, 0.68954054473707f, 0.65317284295378f, 0.61523159058063f, 0.57580819141785f,
242     0.53499761988710f, 0.49289819222979f, 0.44961132965461f, 0.40524131400499f, 0.35989503653499f,
243     0.31368174039889f, 0.26671275747490f, 0.21910124015687f, 0.17096188876030f, 0.12241067519922f,
244     0.07356456359967f, 0.02454122852291f};
245 
246 const FLOAT32 ia_qmf_anl_addt_sin[32] = {
247     -0.02454122852291f, -0.07356456359967f, -0.12241067519922f, -0.17096188876030f,
248     -0.21910124015687f, -0.26671275747490f, -0.31368174039889f, -0.35989503653499f,
249     -0.40524131400499f, -0.44961132965461f, -0.49289819222978f, -0.53499761988710f,
250     -0.57580819141785f, -0.61523159058063f, -0.65317284295378f, -0.68954054473707f,
251     -0.72424708295147f, -0.75720884650648f, -0.78834642762661f, -0.81758481315158f,
252     -0.84485356524971f, -0.87008699110871f, -0.89322430119552f, -0.91420975570353f,
253     -0.93299279883474f, -0.94952818059304f, -0.96377606579544f, -0.97570213003853f,
254     -0.98527764238894f, -0.99247953459871f, -0.99729045667869f, -0.99969881869620f};
255