xref: /aosp_15_r20/external/libxaac/encoder/ixheaace_sbr.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 struct ixheaace_str_sbr_bitstream_data {
24   WORD32 total_bits;
25   WORD32 payload_bits;
26   WORD32 fill_bits;
27   WORD32 header_active;
28   WORD32 crc_active;
29   WORD32 nr_send_header_data;
30   WORD32 count_send_header_data;
31   WORD32 usac_indep_flag;
32 };
33 
34 struct ixheaace_str_sbr_config_data {
35   WORD32 num_ch;
36   WORD32 num_scf[2];
37   WORD32 num_master;
38   WORD32 sample_freq;
39   WORD32 is_ld_sbr;
40   WORD32 is_esbr;
41   WORD32 xover_freq;
42   UWORD8 sbr_freq_band_tab_lo[MAXIMUM_FREQ_COEFFS / 2 + 1];
43   UWORD8 sbr_freq_band_tab_hi[MAXIMUM_FREQ_COEFFS + 1];
44   UWORD8 *ptr_freq_band_tab[2];
45   UWORD8 *ptr_v_k_master;
46   UWORD8 sbr_v_k_master[MAXIMUM_FREQ_COEFFS + 1];
47   ixheaace_sbr_stereo_mode stereo_mode;
48   WORD32 detect_missing_harmonics;
49   WORD32 use_parametric_coding;
50   WORD32 xpos_control_switch;
51   WORD32 sbr_ratio_idx;
52   ixheaace_sbr_codec_type sbr_codec;
53 };
54 
55 struct ixheaace_str_sbr_env_data {
56   WORD32 sbr_xpos_ctrl;
57   ixheaace_freq_res freq_res_fix;
58   ixheaace_invf_mode sbr_invf_mode;
59   ixheaace_invf_mode sbr_invf_mode_vec[MAXIMUM_NUM_NOISE_VALUES];
60   ixheaace_pvc_bs_info pvc_info;
61   ixheaace_sbr_xpos_mode sbr_xpos_mode;
62   WORD32 ienvelope[IXHEAACE_MAX_ENV][MAXIMUM_FREQ_COEFFS];
63   WORD32 code_book_scf_lav_balance;
64   WORD32 code_book_scf_lav;
65   const WORD32 *ptr_huff_tab_time_c;
66   const WORD32 *ptr_huff_tab_freq_c;
67   const UWORD8 *ptr_huff_tab_time_l;
68   const UWORD8 *ptr_huff_tab_freq_l;
69   const WORD32 *ptr_huff_tab_lvl_time_c;
70   const WORD32 *ptr_huff_tab_bal_time_c;
71   const WORD32 *ptr_huff_tab_lvl_freq_c;
72   const WORD32 *ptr_huff_tab_bal_freq_c;
73   const UWORD8 *ptr_huff_tab_lvl_time_l;
74   const UWORD8 *ptr_huff_tab_bal_time_l;
75   const UWORD8 *ptr_huff_tab_lvl_freq_l;
76   const UWORD8 *ptr_huff_tab_bal_freq_l;
77   const UWORD8 *ptr_huff_tab_noise_time_l;
78   const WORD32 *ptr_huff_tab_noise_time_c;
79   const UWORD8 *ptr_huff_tab_noise_freq_l;
80   const WORD32 *ptr_huff_tab_noise_freq_c;
81   const UWORD8 *ptr_huff_tab_noise_lvl_time_l;
82   const WORD32 *ptr_huff_tab_noise_lvl_time_c;
83   const UWORD8 *ptr_huff_tab_noise_bal_time_l;
84   const WORD32 *ptr_huff_tab_noise_bal_time_c;
85   const UWORD8 *ptr_huff_tab_noise_lvl_freq_l;
86   const WORD32 *ptr_huff_tab_noise_lvl_freq_c;
87   const UWORD8 *ptr_huff_tab_noise_bal_freq_l;
88   const WORD32 *ptr_huff_tab_noise_bal_freq_c;
89   ixheaace_pstr_sbr_grid pstr_sbr_bs_grid;
90   WORD32 synthetic_coding;
91   WORD32 no_harmonics;
92   WORD32 add_harmonic_flag;
93   UWORD8 add_harmonic[MAXIMUM_FREQ_COEFFS];
94   WORD32 si_sbr_start_env_bits_balance;
95   WORD32 si_sbr_start_env_bits;
96   WORD32 si_sbr_start_noise_bits_balance;
97   WORD32 si_sbr_start_noise_bits;
98   WORD32 no_of_envelopes;
99   WORD32 no_scf_bands[IXHEAACE_MAX_ENV];
100   WORD32 domain_vec[IXHEAACE_MAX_ENV];
101   WORD32 domain_vec_noise[IXHEAACE_MAX_ENV];
102   WORD32 noise_level[MAXIMUM_FREQ_COEFFS_HEAAC];
103   WORD32 noise_band_count;
104   WORD32 balance;
105   WORD32 init_sbr_amp_res;
106   WORD32 sbr_patching_mode;
107   WORD32 sbr_oversampling_flag;
108   WORD32 sbr_pitchin_bins_flag;
109   WORD32 sbr_coupling;
110   WORD32 sbr_preprocessing;
111   WORD32 sbr_pitchin_bins;
112   WORD32 harmonic_sbr;
113   WORD32 usac_indep_flag;
114   WORD32 usac_harmonic_sbr;
115   WORD32 sbr_pvc_mode;
116   WORD32 sbr_sinusoidal_pos_flag;
117   WORD32 sbr_sinusoidal_pos;
118   WORD32 sbr_inter_tes;
119   WORD32 *ptr_sbr_inter_tes_shape;
120   WORD32 *ptr_sbr_inter_tes_shape_mode;
121   WORD32 curr_sbr_amp_res;
122 };
123 
124 struct ixheaace_str_enc_channel {
125   ixheaace_str_sbr_trans_detector str_sbr_trans_detector;
126   ixheaace_str_sbr_code_envelope str_sbr_code_env;
127   ixheaace_str_sbr_code_envelope str_sbr_code_noise_floor;
128   ixheaace_str_sbr_extr_env str_sbr_extract_env;
129   ixheaace_str_sbr_qmf_filter_bank str_sbr_qmf;
130   ixheaace_str_sbr_env_frame str_sbr_env_frame;
131   ixheaace_str_sbr_ton_corr_est str_ton_corr;
132   ixheaace_str_inter_tes_params str_inter_tes_enc;
133   ixheaace_str_hbe_enc *pstr_hbe_enc;
134   WORD32 sbr_amp_res_init;
135   struct ixheaace_str_sbr_env_data enc_env_data;
136 };
137 
138 typedef struct {
139   WORD32 sbr_num_chan;
140   WORD32 sbr_coupling;
141   UWORD8 sbr_preprocessing;
142   UWORD8 sbr_patching_mode[2];
143   UWORD8 sbr_oversampling_flag[2];
144   UWORD8 sbr_pitchin_flags[2];
145   UWORD8 sbr_pitchin_bins[2];
146 } ixheaace_str_esbr_bs_data;
147 
148 typedef struct ixheaace_str_sbr_bitstream_data *ixheaace_pstr_sbr_bitstream_data;
149 typedef struct ixheaace_str_sbr_config_data *ixheaace_pstr_sbr_config_data;
150 typedef struct ixheaace_str_enc_channel *ixheaace_pstr_enc_channel;
151 typedef struct ixheaace_str_sbr_env_data *ixheaace_pstr_sbr_env_data;
152