xref: /aosp_15_r20/external/libxaac/encoder/ixheaace_mps_spatial_bitstream.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 typedef struct {
23   WORD32 num_ott_boxes;
24   WORD32 ott_mode_lfe[MAX_NUM_BOXES];
25   WORD32 num_ttt_boxes;
26   WORD32 num_in_chan;
27   WORD32 num_out_chan;
28   WORD32 arbitrary_tree;
29 } ixheaace_mps_sac_tree_description;
30 
31 typedef struct {
32   WORD32 bs_ott_bands;
33 } ixheaace_mps_sac_ott_config;
34 
35 typedef struct {
36   WORD32 bs_ttt_dual_mode;
37   WORD32 bs_ttt_mode_low;
38   WORD32 bs_ttt_mode_high;
39   WORD32 bs_ttt_bands_low;
40 } ixheaace_mps_sac_ttt_config;
41 
42 typedef struct {
43   UWORD32 bs_sampling_frequency;
44   WORD32 bs_smooth_config;
45   WORD32 bs_tree_config;
46   ixheaace_mps_sac_tree_description tree_description;
47   WORD32 bs_frame_length;
48   WORD32 bs_freq_res;
49   WORD32 bs_quant_mode;
50   WORD32 bs_fixed_gain_sur;
51   WORD32 bs_fixed_gain_lfe;
52   WORD32 bs_fixed_gain_dmx;
53   WORD32 bs_matrix_mode;
54   WORD32 bs_temp_shape_config;
55   WORD32 bs_decorr_config;
56   WORD32 bs_3d_audio_mode;
57   WORD32 bs_one_icc;
58   WORD32 bs_arbitrary_downmix;
59   WORD32 bs_residual_coding;
60   ixheaace_mps_sac_ott_config ott_config[MAX_NUM_BOXES];
61   ixheaace_mps_sac_ttt_config ttt_config[MAX_NUM_BOXES];
62   WORD32 aac_residual_fs;
63   WORD32 aac_residual_frames_per_spatial_frame;
64   WORD32 aac_residual_use_tns;
65   FLOAT32 aac_residual_bwhz[MAX_NUM_BOXES];
66   WORD32 aac_residual_bit_rate[MAX_NUM_BOXES];
67 } ixheaace_mps_sac_specific_config;
68 
69 typedef struct {
70   WORD32 bs_framing_type;
71   WORD32 bs_num_param_sets;
72   WORD32 bs_param_slots[MAX_NUM_PARAMS];
73 } ixheaace_mps_sac_framing_info;
74 
75 typedef struct {
76   WORD32 cld[MAX_NUM_BOXES][MAX_NUM_PARAMS][MAX_NUM_BINS];
77   WORD32 icc[MAX_NUM_BOXES][MAX_NUM_PARAMS][MAX_NUM_BINS];
78   WORD32 cld_old[MAX_NUM_BOXES][MAX_NUM_BINS];
79   WORD32 icc_old[MAX_NUM_BOXES][MAX_NUM_BINS];
80 } ixheaace_mps_sac_ott_data;
81 
82 typedef struct {
83   WORD32 cpc_cld1[MAX_NUM_BOXES][MAX_NUM_PARAMS][MAX_NUM_BINS];
84   WORD32 cpc_cld2[MAX_NUM_BOXES][MAX_NUM_PARAMS][MAX_NUM_BINS];
85   WORD32 icc[MAX_NUM_BOXES][MAX_NUM_PARAMS][MAX_NUM_BINS];
86   WORD32 cpc_cld1_old[MAX_NUM_BOXES][MAX_NUM_BINS];
87   WORD32 cpc_cld2_old[MAX_NUM_BOXES][MAX_NUM_BINS];
88   WORD32 icc_old[MAX_NUM_BOXES][MAX_NUM_BINS];
89 } ixheaace_mps_sac_ttt_data;
90 
91 typedef struct {
92   WORD32 bs_smooth_control;
93   WORD32 bs_smooth_mode[MAX_NUM_PARAMS];
94   WORD32 bs_smooth_time[MAX_NUM_PARAMS];
95   WORD32 bs_freq_res_stride[MAX_NUM_PARAMS];
96   WORD32 bs_smg_data[MAX_NUM_PARAMS][MAX_NUM_BINS];
97 } ixheaace_mps_sac_smg_data;
98 
99 typedef struct {
100   WORD32 bs_temp_shape_enable;
101   WORD32 bs_temp_shape_enable_channel[MAX_NUM_OUTPUTCHANNELS];
102 } ixheaace_mps_sac_temp_shape_data;
103 
104 typedef struct {
105   WORD32 bs_xxx_data_mode[MAX_NUM_BOXES][MAX_NUM_PARAMS];
106   WORD32 bs_data_pair[MAX_NUM_BOXES][MAX_NUM_PARAMS];
107   WORD32 bs_quant_coarse_xxx[MAX_NUM_BOXES][MAX_NUM_PARAMS];
108   WORD32 bs_freq_res_stride_xxx[MAX_NUM_BOXES][MAX_NUM_PARAMS];
109 } ixheaace_mps_sac_lossless_data;
110 
111 typedef struct {
112   ixheaace_mps_sac_framing_info framing_info;
113   WORD32 bs_independency_flag;
114   WORD32 bs_independency_flag_count;
115   ixheaace_mps_sac_ott_data ott_data;
116   ixheaace_mps_sac_ttt_data ttt_data;
117   ixheaace_mps_sac_smg_data smg_data;
118   ixheaace_mps_sac_temp_shape_data temp_shape_data;
119   ixheaace_mps_sac_lossless_data cld_lossless_data;
120   ixheaace_mps_sac_lossless_data icc_lossless_data;
121   ixheaace_mps_sac_lossless_data cpc_lossless_data;
122   WORD32 aac_window_grouping[MAX_AAC_FRAMES][MAX_AAC_SHORTWINDOWGROUPS];
123   WORD32 aac_window_sequence;
124 } ixheaace_mps_sac_spatial_frame;
125 
126 typedef struct {
127   ixheaace_mps_sac_specific_config spatial_specific_config;
128   ixheaace_mps_sac_spatial_frame current_frame;
129 
130   WORD32 num_bins;
131   WORD32 total_bits;
132 } ixheaace_mps_sac_bsf_instance;
133 
134 typedef struct {
135   WORD32 tree_config;
136   WORD32 output_channels;
137   WORD32 time_slots;
138   WORD32 frame_size;
139   ixheaace_mps_sac_sbr_encoder_ana_filter_bank filterbank[6];
140   ixheaace_mps_hyb_filter_state hyb_state[6];
141   ixheaace_mps_sac_bsf_instance *bitstream_formatter;
142   ixheaace_mps_sac_qmf_ana_filter_bank qmf_fltbank;
143   ixheaace_mps_sac_qmf_synth_filter_bank qmf_synth_fltbank;
144   FLOAT32 in1[MAX_INPUT_CHANNELS][MAX_BUFFER_SIZE + DELAY_COMPENSATION];
145   FLOAT32 sbr_qmf_states_synthesis[2 * QMF_FILTER_STATE_SYN_SIZE];
146 } ixheaace_mps_sac_enc, *ixheaace_mps_sac_pstr_enc;
147 
148 WORD32 ixheaace_mps_515_icc_quant(FLOAT32 val);
149 
150 WORD32 ixheaace_mps_515_cld_quant(FLOAT32 val);
151 
152 VOID ixheaace_mps_515_ttt_box(WORD32 slots, FLOAT32 *ptr_real1, FLOAT32 *ptr_imag1,
153                               FLOAT32 *ptr_real2, FLOAT32 *ptr_imag2, FLOAT32 *ptr_real3,
154                               FLOAT32 *ptr_imag3, WORD32 *ptr_qclds1, WORD32 *ptr_qclds2);
155 
156 VOID ixheaace_mps_515_ott_box(WORD32 slots, FLOAT32 *ptr_real1, FLOAT32 *ptr_imag1,
157                               FLOAT32 *ptr_real2, FLOAT32 *ptr_imag2, WORD32 *ptr_p_qclds,
158                               WORD32 *ptr_qiccs);
159 
160 IA_ERRORCODE
161 ixheaace_mps_515_write_spatial_specific_config(ixheaace_bit_buf_handle pstr_bit_buf,
162                                                ixheaace_mps_sac_bsf_instance *pstr_bsf_instance);
163 
164 IA_ERRORCODE
165 ixheaace_mps_515_write_spatial_frame(ixheaace_bit_buf_handle pstr_bit_buf,
166                                      ixheaace_mps_sac_bsf_instance *pstr_bsf_instance);
167