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