1 /****************************************************************************** 2 * * 3 * Copyright (C) 2018 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 #ifndef IXHEAACD_MAIN_H 21 #define IXHEAACD_MAIN_H 22 23 VOID ixheaacd_imdct_flt(FLOAT32 in_data[], FLOAT32 out_data[], WORD32 len); 24 25 VOID usac_tw_imdct(FLOAT32 in_data[], FLOAT32 out_data[], WORD32 len); 26 27 WORD32 ixheaacd_window_calc(FLOAT32 window[], WORD32 len, WORD32 wfun_select); 28 29 VOID calc_window_ratio(FLOAT32 window[], WORD32 len, WORD32 prev_len, 30 WORD32 wfun_select, WORD32 prev_wfun_select); 31 32 WORD32 ixheaacd_tw_window_calc(FLOAT32 window[], WORD32 len, 33 WORD32 wfun_select); 34 35 typedef struct ia_usac_lpd_decoder { 36 WORD32 mode_prev; 37 float synth_prev[MAX_PITCH + SYNTH_DELAY_LMAX]; 38 float xcitation_prev[MAX_PITCH + INTER_LP_FIL_ORDER + 1]; 39 int pitch_prev[NUM_SUBFR_SUPERFRAME_BY2 - 1]; 40 float gain_prev[NUM_SUBFR_SUPERFRAME_BY2 - 1]; 41 42 float lp_flt_coeff_a_prev[2 * (ORDER + 1)]; 43 44 FLOAT32 exc_prev[1 + (2 * FAC_LENGTH)]; 45 46 FLOAT32 bpf_prev[FILTER_DELAY + LEN_SUBFR]; 47 48 WORD32 ilspold[ORDER]; 49 50 FLOAT32 fac_gain; 51 FLOAT32 fac_fd_data[FAC_LENGTH / 4]; 52 53 FLOAT32 lsf_prev[ORDER]; 54 FLOAT32 lspold[ORDER]; 55 WORD32 lsfold_first[ORDER]; 56 57 FLOAT32 gain_threshold; 58 59 WORD32 fscale; 60 61 FLOAT32 fd_synth_buf[3 * LEN_FRAME + 1 + ORDER]; 62 FLOAT32 *fd_synth; 63 WORD32 bpf_active_prev; 64 WORD32 last_tcx_pitch; 65 FLOAT32 synth_prev_ec[ORDER]; 66 } ia_usac_lpd_decoder, *ia_usac_lpd_decoder_handle; 67 68 typedef struct ia_usac_data_main_struct { 69 FLOAT32 time_sample_vector[MAX_NUM_CHANNELS][4096]; 70 FLOAT32 time_sample_vector_prev[MAX_NUM_CHANNELS][4096]; 71 WORD32 input_data_ptr[MAX_NUM_CHANNELS][4096]; 72 WORD32 overlap_data_ptr[MAX_NUM_CHANNELS][4096]; 73 WORD32 output_data_ptr[MAX_NUM_CHANNELS][4096]; 74 75 WORD32 window_shape[MAX_NUM_CHANNELS]; 76 WORD32 window_shape_prev[MAX_NUM_CHANNELS]; 77 WORD32 window_sequence[MAX_NUM_CHANNELS]; 78 WORD32 window_sequence_last[MAX_NUM_CHANNELS]; 79 80 WORD32 output_samples; 81 WORD32 sbr_ratio_idx; 82 WORD32 usac_independency_flg; 83 84 WORD32 sampling_rate_idx; 85 WORD32 audio_object_type; 86 87 WORD32 down_samp_sbr; 88 WORD32 sbr_mode; 89 90 WORD32 tw_mdct[MAX_ELEMENTS]; 91 WORD32 mps_pseudo_lr[MAX_ELEMENTS]; 92 WORD32 td_frame_prev[MAX_NUM_CHANNELS]; 93 94 FLOAT32 warp_sum[MAX_NUM_CHANNELS][2]; 95 FLOAT32 warp_cont_mem[MAX_NUM_CHANNELS][3 * 1024]; 96 FLOAT32 prev_sample_pos[MAX_NUM_CHANNELS][3 * 1024]; 97 FLOAT32 prev_tw_trans_len[MAX_NUM_CHANNELS][2]; 98 WORD32 prev_tw_start_stop[MAX_NUM_CHANNELS][2]; 99 FLOAT32 prev_warped_time_sample_vector[MAX_NUM_CHANNELS][3 * 1024]; 100 101 FLOAT32 lpc_prev[MAX_NUM_CHANNELS][ORDER + 1]; 102 FLOAT32 acelp_in[MAX_NUM_CHANNELS][1 + (2 * FAC_LENGTH)]; 103 104 WORD32 alpha_q_re[MAX_SHORT_WINDOWS][SFB_NUM_MAX]; 105 WORD32 alpha_q_im[MAX_SHORT_WINDOWS][SFB_NUM_MAX]; 106 UWORD8 cplx_pred_used[MAX_SHORT_WINDOWS][SFB_NUM_MAX]; 107 108 WORD32 alpha_q_re_prev[SFB_NUM_MAX]; 109 WORD32 alpha_q_im_prev[SFB_NUM_MAX]; 110 WORD32 dmx_re_prev[BLOCK_LEN_LONG]; 111 112 VOID *sbr_scratch_mem_base; 113 114 WORD32 *coef_fix[MAX_NUM_CHANNELS]; 115 FLOAT32 *coef[MAX_NUM_CHANNELS]; 116 UWORD8 *ms_used[MAX_NUM_CHANNELS]; 117 WORD32 *coef_save[MAX_NUM_CHANNELS]; 118 119 WORD16 *factors[MAX_NUM_CHANNELS]; 120 UWORD8 *group_dis[MAX_NUM_CHANNELS]; 121 122 WORD32 tw_data_present[MAX_NUM_CHANNELS]; 123 WORD32 *tw_ratio[MAX_NUM_CHANNELS]; 124 ia_tns_frame_info_struct *pstr_tns[MAX_NUM_CHANNELS]; 125 126 ia_usac_lpd_decoder_handle str_tddec[MAX_NUM_CHANNELS]; 127 128 WORD32 arith_prev_n[MAX_NUM_CHANNELS]; 129 WORD8 c_prev[MAX_NUM_CHANNELS][1024 / 2 + 4]; 130 WORD8 c[MAX_NUM_CHANNELS][1024 / 2 + 4]; 131 132 WORD32 noise_filling_config[MAX_NUM_ELEMENTS]; 133 UWORD32 seed_value[MAX_NUM_CHANNELS]; 134 WORD32 present_chan; 135 136 WORD32 fac_data_present[MAX_NUM_CHANNELS]; 137 WORD32 fac_data[MAX_NUM_CHANNELS][FAC_LENGTH + 1]; 138 139 ia_sfb_info_struct *pstr_sfb_info[MAX_NUM_CHANNELS]; 140 ia_sfb_info_struct str_only_long_info; 141 ia_sfb_info_struct str_eight_short_info; 142 ia_sfb_info_struct *pstr_usac_winmap[NUM_WIN_SEQ]; 143 WORD16 sfb_width_short[(1 << LEN_MAX_SFBS)]; 144 145 WORD32 ccfl; 146 WORD32 len_subfrm; 147 WORD32 num_subfrm; 148 149 ia_handle_sbr_dec_inst_struct pstr_esbr_dec; 150 ia_aac_dec_sbr_bitstream_struct esbr_bit_str[2]; 151 152 WORD32 x_ac_dec[1024]; 153 WORD32 scratch_buffer[1024]; 154 155 FLOAT32 synth_buf[1883]; 156 FLOAT32 exc_buf[1453]; 157 FLOAT32 lp_flt_coff[290]; 158 WORD32 pitch[25]; 159 FLOAT32 pitch_gain[25]; 160 161 UWORD16 *huffman_code_book_scl; 162 UWORD32 *huffman_code_book_scl_index; 163 164 WORD32 *tns_coeff3_32; 165 166 WORD32 *tns_coeff4_32; 167 168 WORD32 (*tns_max_bands_tbl_usac)[16][2]; 169 170 WORD16 sfb_width_long[(1 << LEN_MAX_SFBL)]; 171 WORD32 usac_flag; 172 173 WORD32 arr_coef_fix[MAX_NUM_CHANNELS][(LN2 + LN2 / 8)]; 174 FLOAT32 arr_coef[MAX_NUM_CHANNELS][(LN2 + LN2 / 8)]; 175 WORD32 arr_coef_save[MAX_NUM_CHANNELS][(LN2 + LN2 / 8)]; 176 WORD16 arr_factors[MAX_NUM_CHANNELS][MAXBANDS]; 177 UWORD8 arr_group_dis[MAX_NUM_CHANNELS][NSHORT]; 178 WORD32 arr_tw_ratio[MAX_NUM_CHANNELS][NUM_TW_NODES]; 179 UWORD8 arr_ms_used[MAX_NUM_CHANNELS][MAXBANDS]; 180 ia_usac_lpd_decoder arr_str_tddec[MAX_NUM_CHANNELS]; 181 ia_tns_frame_info_struct arr_str_tns[MAX_NUM_CHANNELS]; 182 183 WORD32 enh_sbr; 184 WORD32 esbr_hq; 185 WORD32 enh_sbr_ps; 186 WORD32 drc_config_changed; 187 WORD32 core_mode; 188 WORD32 frame_ok; 189 WORD32 sbr_parse_err_flag; 190 WORD32 last_frame_ok; 191 WORD32 ec_flag; 192 WORD32 first_frame; 193 WORD32 sbr_parse_complete; 194 UWORD8 max_sfb[2]; 195 WORD32 num_ch_out; 196 WORD16 spec_scale[MAX_NUM_CHANNELS][128]; 197 ia_ec_state_str str_error_concealment[MAX_NUM_CHANNELS]; 198 ia_td_frame_data_struct *pstr_td_frame; 199 WORD32 sampling_rate; 200 WORD32 td_frame_prev_ec[MAX_NUM_CHANNELS]; 201 FLOAT32 lsp_coeff[5][ORDER]; 202 FLOAT32 lsf_adaptive_mean_cand[ORDER]; 203 FLOAT32 lsf_adaptive_mean[ORDER]; 204 FLOAT32 lpc4_lsf[ORDER]; 205 WORD32 bpf_control_info; 206 WORD32 first_lpd_flag; 207 WORD32 short_fac_flag; 208 WORD32 core_mode_last; 209 FLOAT32 stability_factor_old; 210 WORD32 num_lost_lpd_frames[MAX_NUM_CHANNELS]; 211 WORD32 pitch_lag_old; 212 WORD32 pitch_lag_frac_old; 213 WORD32 pitch_lag; 214 WORD32 pitch_lag_frac; 215 WORD16 seed_ace; 216 ia_ec_state_str *pstr_ec_state; 217 FLOAT32 past_pitch_gain; 218 FLOAT32 past_gain_code; 219 FLOAT32 past_gain_tcx[MAX_NUM_CHANNELS]; 220 WORD32 tcx_spec_coeffs[MAX_NUM_CHANNELS][1280]; 221 FLOAT32 lspold_ec[ORDER]; 222 FLOAT32 lp_flt_coff_a_ec[ORDER + 1]; 223 ia_td_frame_data_struct td_frame_data_prev[MAX_NUM_CHANNELS]; 224 WORD32 last_shiftp; 225 } ia_usac_data_struct; 226 227 IA_ERRORCODE ixheaacd_tns_apply(ia_usac_data_struct *usac_data, WORD32 *spec, 228 WORD32 nbands, 229 ia_sfb_info_struct *pstr_sfb_info, 230 ia_tns_frame_info_struct *pstr_tns); 231 232 WORD32 ixheaacd_calc_max_spectral_line_dec(WORD32 *ptr_tmp, WORD32 size); 233 234 WORD32 ixheaacd_calc_max_spectral_line_armv7(WORD32 *ptr_tmp, WORD32 size); 235 236 WORD32 ixheaacd_calc_max_spectral_line_armv8(WORD32 *ptr_tmp, WORD32 size); 237 238 WORD32 ixheaacd_tw_buff_update(ia_usac_data_struct *usac_data, WORD32 i, 239 ia_usac_lpd_decoder_handle st); 240 241 VOID ixheaacd_fix2flt_data(ia_usac_data_struct *usac_data, 242 ia_usac_lpd_decoder_handle st, WORD32 k); 243 244 VOID ixheaacd_td_frm_dec(ia_usac_data_struct *usac_data, WORD32 k, WORD32 mod0); 245 246 WORD32 ixheaacd_tw_frame_dec(ia_usac_data_struct *usac_data, WORD32 i_ch, 247 FLOAT32 sample_pos[], FLOAT32 tw_trans_len[], 248 WORD32 tw_start_stop[]); 249 250 WORD32 ixheaacd_fd_frm_dec(ia_usac_data_struct *usac_data, WORD32 i_ch); 251 252 VOID ixheaacd_acelp_mdct(WORD32 *ptr_in, WORD32 *ptr_out, WORD32 *preshift, WORD32 length, 253 WORD32 *ptr_scratch); 254 255 VOID ixheaacd_acelp_mdct_main(ia_usac_data_struct *usac_data, WORD32 *x, WORD32 *y, WORD32 l, 256 WORD32 m, WORD32 *preshift); 257 258 VOID ixheaacd_fr_alias_cnx_fix(WORD32 *x_in, WORD32 len_subfr, WORD32 lfac, WORD32 *iaq, 259 WORD32 *izir, WORD32 *ifacdec, WORD8 *qshift1, WORD8 qshift2, 260 WORD8 qshift3, WORD32 *preshift, WORD32 *ptr_scratch); 261 262 VOID ixheaacd_fwd_alias_cancel_tool(ia_usac_data_struct *usac_data, 263 ia_td_frame_data_struct *pstr_td_frame_data, 264 WORD32 fac_length, FLOAT32 *iaq, WORD32 gain); 265 266 WORD32 ixheaacd_lpd_bpf_fix(ia_usac_data_struct *usac_data, WORD32 is_short, 267 FLOAT32 out_buffer[], 268 ia_usac_lpd_decoder_handle st); 269 270 VOID ixheaacd_reset_acelp_data_fix(ia_usac_data_struct *usac_data, 271 ia_usac_lpd_decoder_handle st, 272 WORD32 *ptr_ola_buff, WORD32 last_was_short, 273 WORD32 tw_mdct); 274 275 FLOAT32 ixheaacd_randomsign(UWORD32 *seed); 276 #endif 277