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 #pragma once 22 #define AACENC_MAX_CHANNELS 2 /* encoder max channels */ 23 #define AACENC_TRANS_FAC 8 /* encoder WORD16 long ratio */ 24 #define AACENC_PCM_LEVEL 1.0 /* encoder pcm 0db refernence */ 25 26 #define LD_FFT_TWIDDLE_TABLE_SIZE 9 27 #define FFT_TWIDDLE_TABLE_SIZE (1 << LD_FFT_TWIDDLE_TABLE_SIZE) 28 29 /*MDCT Tables*/ 30 typedef struct { 31 UWORD8 re_arr_tab_16[240]; 32 UWORD8 re_arr_tab_sml_240[240]; 33 const FLOAT32 cosine_array_960[480]; 34 WORD32 dig_rev_tab_16[2]; 35 WORD16 w_16[24]; 36 const FLOAT32 cosine_array_1024[512]; 37 const WORD16 w_256[512]; 38 const WORD32 dig_rev_table_512[32]; 39 const FLOAT32 win_512_ld[1920]; 40 const FLOAT32 win_480_ld[1800]; 41 } ixheaace_mdct_tables; 42 extern const ixheaace_mdct_tables ixheaace_enc_mdct_tab; 43 44 /*Huffman Tables*/ 45 typedef struct { 46 const UWORD16 huff_ltab1_2[3][3][3][3]; 47 const UWORD16 huff_ltab3_4[3][3][3][3]; 48 const UWORD16 huff_ltab5_6[9][27]; 49 const UWORD16 huff_ltab7_8[8][27]; 50 const UWORD16 huff_ltab9_10[13][27]; 51 const UWORD16 huff_ltab11[17][27]; 52 const UWORD16 huff_ltabscf[121]; 53 const UWORD16 huff_ctab1[3][3][3][3]; 54 const UWORD16 huff_ctab2[3][3][3][3]; 55 const UWORD16 huff_ctab3[3][3][3][3]; 56 const UWORD16 huff_ctab4[3][3][3][3]; 57 const UWORD16 huff_ctab5[9][9]; 58 const UWORD16 huff_ctab6[9][9]; 59 const UWORD16 huff_ctab7[8][8]; 60 const UWORD16 huff_ctab8[8][8]; 61 const UWORD16 huff_ctab9[13][13]; 62 const UWORD16 huff_ctab10[13][13]; 63 const UWORD16 huff_ctab11[17][17]; 64 const UWORD32 huff_ctabscf[121]; 65 } ixheaace_huffman_tables; 66 67 extern const ixheaace_huffman_tables ixheaace_enc_huff_tab; 68 69 typedef struct { 70 WORD32 sample_rate; 71 const UWORD8 param_long[MAXIMUM_SCALE_FACTOR_BAND_LONG]; 72 const UWORD8 param_short[MAXIMUM_SCALE_FACTOR_BAND_SHORT]; 73 const UWORD8 param_long_960[MAXIMUM_SCALE_FACTOR_BAND_LONG]; 74 const UWORD8 param_short_120[1 + MAXIMUM_SCALE_FACTOR_BAND_SHORT]; 75 const UWORD8 param_long_512_ld[MAXIMUM_SCALE_FACTOR_BAND_LONG]; 76 const UWORD8 param_long_480_ld[MAXIMUM_SCALE_FACTOR_BAND_LONG]; 77 } ixheaace_sfb_info_tab; 78 79 /*Psychoacostics Tables*/ 80 typedef struct { 81 const FLOAT32 ixheaace_bark_quiet_thr_val[25]; 82 const WORD32 pow_point_25_Q23[128]; 83 const WORD32 q_mod_4_inv_pow_point_25_Q32[4]; 84 const ixheaace_sfb_info_tab sfb_info_tab[12]; 85 } ixheaace_psycho_tables; 86 87 extern const ixheaace_psycho_tables ixheaace_enc_psycho_tab; 88 89 /*Quantizer tables*/ 90 typedef struct { 91 const WORD q_quant_table_E_fix[17]; 92 const WORD q_inv_quant_table_E_fix[17]; 93 const WORD32 quant_table_q_Q30[16]; 94 const WORD32 inv_quant_table_q_Q27[16]; 95 const WORD32 power_3_by_4_tab[512]; 96 const WORD32 power_4_by_3_tab_fix[64]; 97 const WORD16 power_2_n_4_by_3_tab[10]; 98 } ixheaace_quant_tables; 99 100 extern const ixheaace_quant_tables ixheaace_enc_quant_tab; 101 typedef struct { 102 const ixheaace_temporal_noise_shaping_max_table tns_max_bands_table[12]; 103 const ixheaace_temporal_noise_shaping_info_tab tns_info_tab[5]; 104 const FLOAT32 tns_coeff_3[8]; 105 const FLOAT32 tns_coeff_3_borders[8]; 106 const FLOAT32 tns_coeff_4[16]; 107 const FLOAT32 tns_coeff_4_borders[16]; 108 } ixheaace_temporal_noise_shaping_tables; 109 110 extern const ixheaace_temporal_noise_shaping_tables ixheaace_enhaacplus_enc_tns_tab; 111 112 typedef struct { 113 ixheaace_mdct_tables *pstr_mdct_tab; 114 ixheaace_huffman_tables *pstr_huff_tab; 115 ixheaace_psycho_tables *pstr_psycho_tab; 116 ixheaace_quant_tables *pstr_quant_tab; 117 ixheaace_temporal_noise_shaping_tables *pstr_tns_tab; 118 } ixheaace_aac_tables; 119 120 extern ixheaace_aac_tables ixheaace_enc_aac_tab; 121 122 /***************/ 123 /* 124 input buffer (1ch) 125 126 |------- 288 --------|--------------- 2048 -------------| 127 spectral_band_replication_2core delay Read, SBR, downmix and ds area 128 (downsampled) 129 */ 130 #define CORE_DELAY_LC (1600) 131 // LC Delay = (Core-delay LC) * 2 + SBR Decoder Delay - SBR Encoder Delay + Magic 132 #define INPUT_DELAY_LC ((CORE_DELAY_LC)*2 + 6 * 64 - 2048 + 1) 133 #define CORE_DELAY_LD_512 (512) 134 #define INPUT_DELAY_LD_512 ((CORE_DELAY_LD_512)*2 - 1024 + 1) 135 // ELD Delay = (Core-delay LD) * 2 + SBR Decoder Delay - SBR Encoder Delay 136 #define INPUT_DELAY_ELD_512 ((CORE_DELAY_LD_512)*2 + 0 - (16 * 64)) 137 // Original ELD delay value retained for multichannel files with MPS 138 #define INPUT_DELAY_ELD_512_MPS ((CORE_DELAY_LD_512)*2 + 1) 139 #define INPUT_DELAY_ELDV2_512 ((CORE_DELAY_LD_512 * 2) + 128 + 1) 140 141 #define CORE_DELAY_LD_480 (480) 142 #define INPUT_DELAY_LD_480 ((CORE_DELAY_LD_480)*2 - 1024 + 1) 143 // ELD Delay = (Core-delay LD / 2) * 2 + SBR Decoder Delay - SBR Encoder Delay 144 #define INPUT_DELAY_ELD_480 ((CORE_DELAY_LD_480 / 2) * 2 + 0 - (15 * 64) + 576) 145 // Original ELD delay value retained for multichannel files with MPS 146 #define INPUT_DELAY_ELD_480_MPS (CORE_DELAY_LD_480 * 2 + 1) 147 #define INPUT_DELAY_ELDV2_480 ((CORE_DELAY_LD_480 * 2) + 128 + 1) 148 #define CORE_DELAY (1600) 149 150 /* ((1600 (core codec)*2 (multi rate) + 6 *(spectral_band_replication_ dec delay) - 151 * (spectral_band_replication_ enc delay) + magic*/ 152 #define INPUT_DELAY ((CORE_DELAY)*2 + 6 * 64 - 2048 + 1) 153 154 /* For 2:1 resampler -> max phase delay * resamp_fac */ 155 #define MAXIMUM_DS_2_1_FILTER_DELAY (16) 156 157 /* For 4:1 resampler -> max phase delay * resamp_fac */ 158 #define MAXIMUM_DS_4_1_FILTER_DELAY (64) 159 160 /* For 8:1 resampler -> max phase delay * resamp_fac */ 161 #define MAXIMUM_DS_8_1_FILTER_DELAY (248) 162 163 /* For 1:3 resampler -> max phase delay * resamp_fac */ 164 #define MAXIMUM_DS_1_3_FILTER_DELAY (36) 165 166 extern const FLOAT32 ixheaace_fd_quant_table[257]; 167 extern const FLOAT32 ixheaace_fd_inv_quant_table[257]; 168 extern const FLOAT32 ixheaace_pow_4_3_table[64]; 169 extern const WORD32 ixheaace_huffman_code_table[121][2]; 170 extern const FLOAT32 long_window_KBD[1024]; 171 extern const FLOAT32 long_window_sine_960[960]; 172 extern const FLOAT32 fft_twiddle_tab[FFT_TWIDDLE_TABLE_SIZE + 1]; 173 extern const FLOAT32 long_window_sine[1024]; 174 extern const FLOAT32 long_window_sine_ld[512]; 175 extern const FLOAT32 long_window_sine_ld_480[480]; 176 extern const FLOAT32 short_window_sine[FRAME_LEN_SHORT_128]; 177 178 extern const FLOAT32 short_window_sine_120[FRAME_LEN_SHORT_120]; 179 180 extern const FLOAT32 iaace_iir_hipass_coeffs[2]; 181 182 extern const WORD32 iaace_suggested_grouping_table[TRANS_FAC][MAXIMUM_NO_OF_GROUPS]; 183 184 extern const WORD32 iaace_synchronized_block_types[4][4]; 185 extern const FLOAT32 ixheaace_mix_rad_twid_tbl[TRANS_FAC]; 186 extern const FLOAT32 ixheaace_mix_rad_twid_tbl_h[TRANS_FAC]; 187 extern const FLOAT32 cos_sin_table_flt[960]; 188 extern const FLOAT32 ixheaace_fft_mix_rad_twid_tbl_32[(FFT16 - 1) * (FFT2 - 1)]; 189 extern const FLOAT32 ixheaace_fft_mix_rad_twid_tbl_h_32[(FFT16 - 1) * (FFT2 - 1)]; 190 extern const FLOAT32 ixheaace_fft_mix_rad_twid_tbl_480[(FFT15 - 1) * (FFT32 - 1)]; 191 extern const FLOAT32 ixheaace_fft_mix_rad_twid_h_tbl_480[(FFT15 - 1) * (FFT32 - 1)]; 192 extern const FLOAT32 ixheaace_cosine_array_240[120]; 193 extern const WORD16 re_arr_tab_5[16]; 194 extern const WORD16 re_arr_tab_3[16]; 195 extern const WORD16 re_arr_tab_sml[16]; 196 extern const WORD16 re_arr_tab_4[60]; 197 extern const WORD16 re_arr_tab_120[60]; 198 extern const WORD16 re_arr_tab_15_4[60]; 199 extern const FLOAT32 low_delay_window_eld[2048]; 200 extern const ixheaace_bandwidth_table bandwidth_table_lc[9]; 201 202 extern const ixheaace_bandwidth_table bandwidth_table_ld_22050[11]; 203 204 extern const ixheaace_bandwidth_table bandwidth_table_ld_24000[11]; 205 206 extern const ixheaace_bandwidth_table bandwidth_table_ld_32000[11]; 207 208 extern const ixheaace_bandwidth_table bandwidth_table_ld_44100[11]; 209 210 extern const ixheaace_bandwidth_table bandwidth_table_ld_48000[11]; 211