xref: /aosp_15_r20/external/libxaac/encoder/iusace_main.h (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 #pragma once
22 
23 typedef struct {
24   WORD32 window_size_samples[MAX_TIME_CHANNELS];
25   WORD32 usac_independency_flag_interval;
26   WORD32 usac_independency_flag_count;
27   WORD32 usac_independency_flag;
28   WORD32 frame_count;
29   WORD32 core_mode[MAX_TIME_CHANNELS];
30   WORD32 core_mode_prev[MAX_TIME_CHANNELS];
31   WORD32 core_mode_prev_copy[MAX_TIME_CHANNELS];
32   WORD32 core_mode_next[MAX_TIME_CHANNELS];
33   WORD32 core_mode_copy[MAX_TIME_CHANNELS];
34   ia_block_switch_ctrl block_switch_ctrl[MAX_TIME_CHANNELS];
35   ia_classification_struct str_sig_class_data;
36   FLOAT32 td_in_buf[MAX_TIME_CHANNELS][LEN_SUPERFRAME + LEN_NEXT_HIGH_RATE];
37   FLOAT32 td_in_prev_buf[MAX_TIME_CHANNELS][LEN_SUPERFRAME + LEN_NEXT_HIGH_RATE + LEN_LPC0];
38   FLOAT32 speech_buf[LEN_TOTAL_HIGH_RATE + LEN_LPC0];
39   FLOAT32 synth_buf[ORDER + LEN_SUPERFRAME];
40   WORD32 param_buf[(NUM_FRAMES * MAX_NUM_TCX_PRM_PER_DIV) + NUM_LPC_PRM];
41   ia_usac_td_encoder_struct *td_encoder[MAX_TIME_CHANNELS];
42   WORD32 total_nbbits[MAX_TIME_CHANNELS];
43   WORD32 FD_nbbits_fac[MAX_TIME_CHANNELS];
44   WORD32 num_td_fac_bits[MAX_TIME_CHANNELS];
45   WORD32 td_bitrate[MAX_TIME_CHANNELS];
46   WORD32 acelp_core_mode[MAX_TIME_CHANNELS];
47   WORD32 max_bitreservoir_bits;
48   WORD32 available_bitreservoir_bits;
49   ia_drc_enc_state str_drc_state;
50   WORD32 num_sbr_bits;
51   ia_ms_info_struct str_ms_info[MAX_TIME_CHANNELS];
52   WORD32 pred_coef_re[MAX_TIME_CHANNELS][MAX_SHORT_WINDOWS][MAX_SFB_LONG],
53       pred_coef_im[MAX_TIME_CHANNELS][MAX_SHORT_WINDOWS][MAX_SFB_LONG];
54   WORD32 pred_coef_re_prev[MAX_TIME_CHANNELS][MAX_SFB_LONG],
55       pred_coef_im_prev[MAX_TIME_CHANNELS][MAX_SFB_LONG];
56   /* Temporary buffers for bitstream writing function when computing static bits */
57   WORD32 temp_pred_coef_re_prev[MAX_TIME_CHANNELS][MAX_SFB_LONG],
58       temp_pred_coef_im_prev[MAX_TIME_CHANNELS][MAX_SFB_LONG];
59   WORD32 pred_dir_idx[MAX_TIME_CHANNELS];
60   WORD32 cplx_pred_all[MAX_TIME_CHANNELS];
61   WORD32 cplx_pred_used[MAX_TIME_CHANNELS][MAX_SHORT_WINDOWS][MAX_SFB_LONG];
62   WORD32 delta_code_time[MAX_TIME_CHANNELS];
63   WORD32 complex_coef[MAX_TIME_CHANNELS];
64   FLOAT64 *ptr_dmx_re_save[MAX_TIME_CHANNELS]; /*For saving previous frame MDCT down-mix */
65   FLOAT64 *ptr_dmx_im[MAX_TIME_CHANNELS];
66   FLOAT64 arr_dmx_im[MAX_TIME_CHANNELS][(FRAME_LEN_LONG + FRAME_LEN_LONG / 8)];
67   FLOAT64 arr_dmx_save_float[MAX_TIME_CHANNELS][(FRAME_LEN_LONG + FRAME_LEN_LONG / 8)];
68   FLOAT64 left_chan_save[MAX_TIME_CHANNELS][(FRAME_LEN_LONG + FRAME_LEN_LONG / 8)];
69   FLOAT64 right_chan_save[MAX_TIME_CHANNELS][(FRAME_LEN_LONG + FRAME_LEN_LONG / 8)];
70 
71   ia_tns_info *pstr_tns_info[MAX_TIME_CHANNELS];
72   WORD32 common_window[MAX_TIME_CHANNELS];
73   WORD32 noise_offset[MAX_TIME_CHANNELS];
74   WORD32 noise_level[MAX_TIME_CHANNELS];
75 
76   ia_usac_quant_info_struct str_quant_info[MAX_TIME_CHANNELS];
77   WORD32 noise_filling[MAX_TIME_CHANNELS];
78   ia_psy_mod_struct str_psy_mod;
79   ia_qc_main_struct str_qc_main;
80   FLOAT64 *ptr_time_data[MAX_TIME_CHANNELS];
81   FLOAT64 *ptr_look_ahead_time_data[MAX_TIME_CHANNELS];
82   FLOAT64 *spectral_line_vector[MAX_TIME_CHANNELS];
83   // Pre-/post- twiddle portions of MDCT use two times ccfl of this buffer, hence size of second
84   // argument is 2 * pstr_config->ccfl
85   FLOAT64 mdst_spectrum[MAX_TIME_CHANNELS][2 * FRAME_LEN_LONG];
86   FLOAT64 *ptr_2frame_time_data[MAX_TIME_CHANNELS];
87   WORD16 td_serial_out[MAX_TIME_CHANNELS][NBITS_MAX];
88   WORD16 fac_out_stream[MAX_TIME_CHANNELS][NBITS_MAX];
89   FLOAT64 overlap_buf[MAX_TIME_CHANNELS][2 * FRAME_LEN_LONG];
90   WORD32 channel_elem_type[MAX_TIME_CHANNELS];
91   WORD32 channel_elem_idx[MAX_TIME_CHANNELS];
92   WORD32 num_ext_elements;
93   WORD32 ext_type[MAX_EXTENSION_PAYLOADS];
94   UWORD8 ext_elem_config_payload[MAX_EXTENSION_PAYLOADS][MAX_EXTENSION_PAYLOAD_LEN];
95   UWORD32 ext_elem_config_len[MAX_EXTENSION_PAYLOADS];
96   iusace_scratch_mem str_scratch;
97   WORD32 min_bits_needed;
98   WORD32 num_drc_bits;
99   WORD32 use_acelp_only;
100   WORD32 prev_out_bytes[MAX_PREROLL_FRAMES];
101   UWORD8 prev_out_data[MAX_PREROLL_FRAMES][MAX_OUTPUT_BYTES_PER_CH * IXHEAACE_MAX_CH_IN_BS_ELE];
102   UWORD32 stereo_config_index;
103 } ia_usac_data_struct;
104 
105 typedef struct {
106   ia_usac_lpd_state_struct lpd_state[6];
107   ia_usac_lpd_state_struct flpd_state[6];
108 
109 } ia_usac_lpd_scratch;
110 
111 IA_ERRORCODE iusace_enc_init(ia_usac_encoder_config_struct *ptr_usac_config,
112                              ixheaace_audio_specific_config_struct *pstr_asc,
113                              ia_usac_data_struct *pstr_state);
114 
115 IA_ERRORCODE iusace_quantize_spec(ia_sfb_params_struct *pstr_sfb_prms,
116                                   WORD32 usac_independancy_flag, WORD32 num_chans,
117                                   ia_usac_data_struct *ptr_usac_data,
118                                   ia_usac_encoder_config_struct *ptr_usac_config, WORD32 chn,
119                                   WORD32 ele_id, WORD32 *is_quant_spec_zero,
120                                   WORD32 *is_gain_limited);
121 
122 IA_ERRORCODE iusace_grouping(ia_sfb_params_struct *pstr_sfb_prms, WORD32 num_chans,
123                              ia_usac_data_struct *ptr_usac_data,
124                              ia_usac_encoder_config_struct *ptr_usac_config, WORD32 chn,
125                              WORD32 ele_id);
126 
127 IA_ERRORCODE iusace_stereo_proc(ia_sfb_params_struct *pstr_sfb_prms,
128                                 WORD32 usac_independancy_flag, ia_usac_data_struct *ptr_usac_data,
129                                 ia_usac_encoder_config_struct *ptr_usac_config, WORD32 chn);
130 
131 VOID iusace_classification(ia_classification_struct *pstr_sig_class,
132                            iusace_scratch_mem *pstr_scratch, WORD32 ccfl);
133