• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_ENV_EXTR_H
21 #define IXHEAACD_ENV_EXTR_H
22 #include "ixheaacd_error_standards.h"
23 #define ENV_EXP_FRACT 0
24 
25 #define EXP_BITS 6
26 
27 #define MASK_M (((1 << (SHORT_BITS - EXP_BITS)) - 1) << EXP_BITS)
28 #define MASK_FOR_EXP ((1 << EXP_BITS) - 1)
29 
30 #define SIGN_EXT (((WORD8)-1) ^ MASK_FOR_EXP)
31 #define ROUNDING (1 << (EXP_BITS - 1))
32 #define NRG_EXP_OFFSET 16
33 #define NOISE_EXP_OFFSET 38
34 #define MAX_QMF_SUB_BANDS 64
35 
36 typedef const UWORD16 *ia_huffman_data_type;
37 
38 #define COUPLING_OFF 0
39 #define COUPLING_LEVEL 1
40 #define COUPLING_BAL 2
41 
42 #define MAX_INVF_BANDS MAX_NOISE_COEFFS
43 
44 typedef struct {
45   WORD16 sfb_nrg_prev[MAX_FREQ_COEFFS];
46   WORD16 prev_noise_level[MAX_NOISE_COEFFS];
47   WORD16 amp_res;
48   WORD16 end_position;
49   WORD32 max_qmf_subband_aac;
50   WORD32 coupling_mode;
51   WORD32 sbr_invf_mode[MAX_NUM_NOISE_VALUES];
52 } ia_sbr_prev_frame_data_struct;
53 
54 typedef struct {
55   WORD16 num_env_sfac;
56   ia_frame_info_struct str_frame_info_details;
57   WORD16 del_cod_dir_arr[MAX_ENVELOPES];
58   WORD16 del_cod_dir_noise_arr[MAX_NOISE_ENVELOPES];
59   WORD32 sbr_invf_mode[MAX_NUM_NOISE_VALUES];
60   WORD32 coupling_mode;
61   WORD16 amp_res;
62   WORD32 max_qmf_subband_aac;
63   FLAG add_harmonics[MAX_FREQ_COEFFS];
64   WORD16 int_env_sf_arr[MAX_NUM_ENVELOPE_VALUES];
65   WORD16 int_noise_floor[MAX_NUM_NOISE_VALUES];
66   WORD32 num_noise_sfac;
67   ia_frame_info_struct str_pvc_frame_info;
68   WORD32 env_short_flag_prev;
69   ia_sbr_header_data_struct *pstr_sbr_header;
70   WORD32 num_time_slots;
71   WORD32 rate;
72   WORD32 sbr_patching_mode;
73   WORD32 prev_sbr_patching_mode;
74   WORD32 over_sampling_flag;
75   WORD32 pitch_in_bins;
76   WORD32 pvc_mode;
77 
78   WORD32 sbr_invf_mode_prev[MAX_NUM_NOISE_VALUES];
79   FLOAT32 flt_env_sf_arr[MAX_NUM_ENVELOPE_VALUES];
80   FLOAT32 flt_noise_floor[MAX_NUM_NOISE_VALUES];
81   FLOAT32 sfb_nrg_prev[MAX_FREQ_COEFFS];
82   FLOAT32 prev_noise_level[MAX_NUM_NOISE_VALUES];
83   WORD32 inter_temp_shape_mode[MAX_ENVELOPES];
84   WORD32 var_len;
85   WORD32 bs_sin_pos_present;
86   WORD32 sine_position;
87   WORD32 sin_start_for_next_top;
88   WORD32 sin_len_for_next_top;
89   WORD32 sin_start_for_cur_top;
90   WORD32 sin_len_for_cur_top;
91   WORD32 var_len_id_prev;
92   ia_frame_info_struct str_frame_info_prev;
93   FLOAT32 bw_array_prev[MAX_NUM_PATCHES];
94   struct ixheaacd_lpp_trans_patch patch_param;
95   WORD32 harm_index;
96   WORD32 phase_index;
97   WORD8 harm_flag_prev[64];
98   FLOAT32 e_gain[5][64];
99   FLOAT32 noise_buf[5][64];
100   WORD32 lim_table[4][12 + 1];
101   WORD32 gate_mode[4];
102   WORD8 harm_flag_varlen_prev[64];
103   WORD8 harm_flag_varlen[64];
104   FLOAT32 qmapped_pvc[MAX_QMF_SUB_BANDS][MAX_FREQ_COEFFS_SBR];
105   FLOAT32 env_tmp[MAX_QMF_SUB_BANDS][MAX_FREQ_COEFFS_SBR];
106   FLOAT32 noise_level_pvc[MAX_QMF_SUB_BANDS][MAX_FREQ_COEFFS_SBR];
107   FLOAT32 nrg_est_pvc[MAX_QMF_SUB_BANDS][MAX_FREQ_COEFFS_SBR];
108   FLOAT32 nrg_ref_pvc[MAX_QMF_SUB_BANDS][MAX_FREQ_COEFFS_SBR];
109   FLOAT32 nrg_gain_pvc[MAX_QMF_SUB_BANDS][MAX_FREQ_COEFFS_SBR];
110   FLOAT32 nrg_tone_pvc[MAX_QMF_SUB_BANDS][MAX_FREQ_COEFFS_SBR];
111   WORD32 stereo_config_idx;
112   FLAG reset_flag;
113   FLAG mps_sbr_flag;
114   FLAG usac_independency_flag;
115   FLAG inter_tes_flag;
116   FLAG sbr_mode;
117   FLAG prev_sbr_mode;
118   WORD32 eld_sbr_flag;
119 
120 } ia_sbr_frame_info_data_struct;
121 
122 WORD8 ixheaacd_sbr_read_sce(ia_sbr_header_data_struct *ptr_header_data,
123                             ia_sbr_frame_info_data_struct *ptr_frame_data,
124                             ia_ps_dec_struct *ptr_ps_dec,
125                             ia_bit_buf_struct *it_bit_buff,
126                             ia_sbr_tables_struct *ptr_sbr_tables,
127                             WORD audio_object_type);
128 
129 WORD8 ixheaacd_sbr_read_cpe(ia_sbr_header_data_struct *ptr_header_data,
130                             ia_sbr_frame_info_data_struct **ptr_frame_data,
131                             ia_bit_buf_struct *itt_bit_buf,
132                             ia_sbr_tables_struct *ptr_sbr_tables,
133                             WORD audio_object_type);
134 
135 WORD32 ixheaacd_sbr_read_header_data(
136     ia_sbr_header_data_struct *ptr_sbr_header, ia_bit_buf_struct *it_bit_buf,
137     FLAG stereo_flag, ia_sbr_header_data_struct *ptr_sbr_dflt_header);
138 
139 WORD32 ixheaacd_ssc_huff_dec(ia_huffman_data_type h,
140                              ia_bit_buf_struct *it_bit_buff);
141 
142 int ixheaacd_extract_frame_info_ld(ia_bit_buf_struct *it_bit_buff,
143                                    ia_sbr_frame_info_data_struct *h_frame_data);
144 
145 WORD32 ixheaacd_pvc_time_freq_grid_info(
146     ia_bit_buf_struct *it_bit_buff,
147     ia_sbr_frame_info_data_struct *ptr_frame_data);
148 
149 WORD16 ixheaacd_sbr_time_freq_grid_info(
150     ia_bit_buf_struct *it_bit_buff,
151     ia_sbr_frame_info_data_struct *ptr_frame_data,
152     ia_env_extr_tables_struct *env_extr_tables_ptr);
153 
154 WORD16 ixheaacd_read_sbr_env_data(
155     ia_sbr_header_data_struct *ptr_header_data,
156     ia_sbr_frame_info_data_struct *ptr_frame_data,
157     ia_bit_buf_struct *it_bit_buff,
158     ia_env_extr_tables_struct *env_extr_tables_ptr, WORD audio_object_type);
159 
160 VOID ixheaacd_sbr_env_dtdf_data(ia_sbr_frame_info_data_struct *ptr_frame_data,
161                                 ia_bit_buf_struct *it_bit_buff,
162                                 WORD32 usac_flag);
163 
164 VOID ixheaacd_read_sbr_noise_floor_data(
165     ia_sbr_header_data_struct *ptr_header_data,
166     ia_sbr_frame_info_data_struct *ptr_frame_data,
167     ia_bit_buf_struct *it_bit_buff,
168     ia_env_extr_tables_struct *env_extr_tables_ptr);
169 
170 VOID ixheaacd_huffman_decode(WORD32 it_bit_buff, WORD16 *h_index, WORD16 *len,
171                              const UWORD16 *input_table,
172                              const UWORD32 *idx_table);
173 
174 IA_ERRORCODE ixheaacd_createlimiterbands(
175     WORD32 lim_table[4][12 + 1], WORD32 gate_mode[4], WORD16 *freq_band_tbl,
176     WORD32 ixheaacd_num_bands, WORD32 x_over_qmf[MAX_NUM_PATCHES],
177     WORD32 b_patching_mode, WORD32 upsamp_4_flag,
178     struct ixheaacd_lpp_trans_patch *patch_param);
179 
180 VOID ixheaacd_apply_inter_tes(FLOAT32 *qmf_real1, FLOAT32 *qmf_imag1,
181                               FLOAT32 *qmf_real, FLOAT32 *qmf_imag,
182                               WORD32 num_sample, WORD32 sub_band_start,
183                               WORD32 num_subband, WORD32 gamma_idx);
184 
185 #endif
186