• 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_SBR_DEC_H
21 #define IXHEAACD_SBR_DEC_H
22 
23 typedef struct {
24   WORD32 x_over_qmf[MAX_NUM_PATCHES];
25   WORD32 max_stretch;
26   WORD32 core_frame_length;
27   WORD32 hbe_qmf_in_len;
28   WORD32 hbe_qmf_out_len;
29   WORD32 no_bins;
30   WORD32 start_band;
31   WORD32 end_band;
32   WORD32 upsamp_4_flag;
33   WORD32 synth_buf_offset;
34 
35   FLOAT32 *ptr_input_buf;
36 
37   FLOAT32 **qmf_in_buf;
38   FLOAT32 **qmf_out_buf;
39 
40   WORD32 k_start;
41   WORD32 synth_size;
42   FLOAT32 synth_buf[1280];
43   FLOAT32 analy_buf[640];
44   FLOAT32 *synth_wind_coeff;
45   FLOAT32 *analy_wind_coeff;
46 
47   FLOAT32 *synth_cos_tab;
48   FLOAT32 *analy_cos_sin_tab;
49 
50   FLOAT32 norm_qmf_in_buf[46][128];
51   VOID (*ixheaacd_real_synth_fft)(FLOAT32 *inp, FLOAT32 *out, WORD32 n_points);
52 
53   VOID (*ixheaacd_cmplx_anal_fft)(FLOAT32 *inp, FLOAT32 *out, WORD32 n_points);
54 
55 } ia_esbr_hbe_txposer_struct;
56 
57 typedef struct {
58   WORD32 *ptr_sbr_overlap_buf;
59   WORD32 **drc_factors_sbr;
60   ia_sbr_qmf_filter_bank_struct str_codec_qmf_bank;
61   ia_sbr_qmf_filter_bank_struct str_synthesis_qmf_bank;
62   ia_sbr_calc_env_struct str_sbr_calc_env;
63   ia_sbr_hf_generator_struct str_hf_generator;
64 
65   ia_sbr_scale_fact_struct str_sbr_scale_fact;
66 
67   WORD32 max_samp_val;
68   ia_esbr_hbe_txposer_struct *p_hbe_txposer;
69 
70   FLOAT32 core_sample_buf[2624];
71   FLOAT32 ph_vocod_qmf_real[TIMESLOT_BUFFER_SIZE][NO_QMF_SYNTH_CHANNELS];
72   FLOAT32 ph_vocod_qmf_imag[TIMESLOT_BUFFER_SIZE][NO_QMF_SYNTH_CHANNELS];
73   FLOAT32 sbr_qmf_out_real[TIMESLOT_BUFFER_SIZE][NO_QMF_SYNTH_CHANNELS];
74   FLOAT32 sbr_qmf_out_imag[TIMESLOT_BUFFER_SIZE][NO_QMF_SYNTH_CHANNELS];
75   FLOAT32 qmf_buf_real[TIMESLOT_BUFFER_SIZE + 2 * 32][NO_QMF_SYNTH_CHANNELS];
76   FLOAT32 qmf_buf_imag[TIMESLOT_BUFFER_SIZE + 2 * 32][NO_QMF_SYNTH_CHANNELS];
77 
78   FLOAT32 mps_qmf_buf_real[TIMESLOT_BUFFER_SIZE][NO_QMF_SYNTH_CHANNELS];
79   FLOAT32 mps_qmf_buf_imag[TIMESLOT_BUFFER_SIZE][NO_QMF_SYNTH_CHANNELS];
80   FLOAT32 mps_sbr_qmf_buf_real[TIMESLOT_BUFFER_SIZE][NO_QMF_SYNTH_CHANNELS];
81   FLOAT32 mps_sbr_qmf_buf_imag[TIMESLOT_BUFFER_SIZE][NO_QMF_SYNTH_CHANNELS];
82 
83   WORD32 sbr_scratch_local[256];
84   FLOAT32 scratch_buff[320];
85 
86   FLOAT32 qmf_energy_buf[64][32];
87   FLOAT32 pvc_qmf_enrg_arr[16 * 32];
88 
89   FLOAT32 **pp_qmf_buf_real;
90   FLOAT32 **pp_qmf_buf_imag;
91 
92   FLOAT32 *time_sample_buf;
93 } ia_sbr_dec_struct;
94 
95 typedef struct {
96   ia_sbr_prev_frame_data_struct *pstr_prev_frame_data;
97   ia_sbr_dec_struct str_sbr_dec;
98   WORD32 output_frame_size;
99   WORD32 sync_state;
100 } ia_sbr_channel_struct;
101 
102 struct ia_sbr_dec_inst_struct {
103   ia_ps_dec_struct *pstr_ps_stereo_dec;
104   FLAG ps_present;
105   ia_sbr_channel_struct *pstr_sbr_channel[MAXNRSBRCHANNELS];
106   ia_sbr_header_data_struct *pstr_sbr_header[MAXNRSBRCHANNELS];
107   ia_freq_band_data_struct *pstr_freq_band_data[MAXNRSBRCHANNELS];
108   ia_sbr_tables_struct *pstr_sbr_tables;
109   ixheaacd_misc_tables *pstr_common_tables;
110   ia_pvc_data_struct *ptr_pvc_data_str;
111   VOID *hbe_txposer_buffers;
112   FLOAT32 *time_sample_buf[MAXNRSBRCHANNELS];
113   VOID *scratch_mem_v;
114   VOID *frame_buffer[2];
115   ia_sbr_header_data_struct str_sbr_dflt_header;
116   FLAG stereo_config_idx;
117   FLAG usac_independency_flag;
118   FLAG pvc_flag;
119   FLAG hbe_flag;
120   FLAG sbr_mode;
121   FLAG prev_sbr_mode;
122   FLAG inter_tes_flag;
123   FLAG aot_usac_flag;
124 };
125 
126 typedef struct ia_sbr_pers_struct {
127   WORD16 *sbr_qmf_analy_states;
128 
129   WORD32 *sbr_qmf_analy_states_32;
130 
131   WORD16 *sbr_qmf_synth_states;
132 
133   WORD32 *sbr_qmf_synth_states_32;
134 
135   WORD32 **sbr_lpc_filter_states_real[MAXNRSBRCHANNELS];
136 
137   WORD32 **sbr_lpc_filter_states_imag[MAXNRSBRCHANNELS];
138 
139   WORD32 *ptr_sbr_overlap_buf[MAXNRSBRCHANNELS];
140 
141   struct ia_sbr_dec_inst_struct str_sbr_dec_inst;
142 
143   ia_transposer_settings_struct str_sbr_tran_settings;
144 
145   WORD16 *sbr_smooth_gain_buf[MAXNRSBRCHANNELS];
146 
147   WORD16 *sbr_smooth_noise_buf[MAXNRSBRCHANNELS];
148 
149   ia_sbr_prev_frame_data_struct *pstr_prev_frame_data[MAXNRSBRCHANNELS];
150 
151 } ia_sbr_pers_struct;
152 
153 WORD32 ixheaacd_sbr_dec(ia_sbr_dec_struct *ptr_sbr_dec, WORD16 *ptr_time_data,
154                         ia_sbr_header_data_struct *ptr_header_data,
155                         ia_sbr_frame_info_data_struct *ptr_frame_data,
156                         ia_sbr_prev_frame_data_struct *ptr_frame_data_prev,
157                         ia_ps_dec_struct *ptr_ps_dec,
158                         ia_sbr_qmf_filter_bank_struct *ptr_qmf_synth_bank_r,
159                         ia_sbr_scale_fact_struct *ptr_sbr_sf_r,
160                         FLAG apply_processing, FLAG low_pow_flag,
161                         WORD32 *ptr_work_buf_core,
162                         ia_sbr_tables_struct *sbr_tables_ptr,
163                         ixheaacd_misc_tables *pstr_common_tables, WORD ch_fac,
164                         ia_pvc_data_struct *ptr_pvc_data_str, FLAG drc_on,
165                         WORD32 drc_sbr_factors[][64], WORD32 audio_object_type);
166 
167 WORD16 ixheaacd_create_sbrdec(ixheaacd_misc_tables *pstr_common_table,
168                               ia_sbr_channel_struct *ptr_sbr_channel,
169                               ia_sbr_header_data_struct *ptr_header_data,
170                               WORD16 chan, FLAG down_sample_flag,
171                               VOID *sbr_persistent_mem_v, WORD ps_enable,
172                               WORD audio_object_type);
173 
174 #define MAX_NUM_QMF_BANDS_ESBR 128
175 
176 WORD32 ixheaacd_sbr_dec_from_mps(FLOAT32 *p_mps_qmf_output, VOID *p_sbr_dec,
177                                  VOID *p_sbr_frame, VOID *p_sbr_header);
178 
179 WORD32 ixheaacd_qmf_hbe_apply(ia_esbr_hbe_txposer_struct *h_hbe_txposer,
180                               FLOAT32 qmf_buf_real[][64],
181                               FLOAT32 qmf_buf_imag[][64], WORD32 num_columns,
182                               FLOAT32 pv_qmf_buf_real[][64],
183                               FLOAT32 pv_qmf_buf_imag[][64],
184                               WORD32 pitch_in_bins);
185 
186 VOID ixheaacd_sbr_env_calc(ia_sbr_frame_info_data_struct *frame_data,
187                            FLOAT32 input_real[][64], FLOAT32 input_imag[][64],
188                            FLOAT32 input_real1[][64], FLOAT32 input_imag1[][64],
189                            WORD32 x_over_qmf[MAX_NUM_PATCHES],
190                            FLOAT32 *scratch_buff, FLOAT32 *env_out);
191 
192 WORD32 ixheaacd_generate_hf(FLOAT32 ptr_src_buf_real[][64],
193                             FLOAT32 ptr_src_buf_imag[][64],
194                             FLOAT32 ptr_ph_vocod_buf_real[][64],
195                             FLOAT32 ptr_ph_vocod_buf_imag[][64],
196                             FLOAT32 ptr_dst_buf_real[][64],
197                             FLOAT32 ptr_dst_buf_imag[][64],
198                             ia_sbr_frame_info_data_struct *ptr_frame_data,
199                             ia_sbr_header_data_struct *ptr_header_data);
200 
201 VOID ixheaacd_clr_subsamples(WORD32 *ptr_qmf_buf, WORD32 num, WORD32 size);
202 
203 VOID ixheaacd_rescale_x_overlap(
204     ia_sbr_dec_struct *ptr_sbr_dec, ia_sbr_header_data_struct *ptr_header_data,
205     ia_sbr_frame_info_data_struct *ptr_frame_data,
206     ia_sbr_prev_frame_data_struct *ptr_frame_data_prev,
207     WORD32 **pp_overlap_buffer_real, FLAG low_pow_flag);
208 
209 WORD32 ixheaacd_qmf_hbe_data_reinit(
210     ia_esbr_hbe_txposer_struct *ptr_hbe_transposer_str,
211     WORD16 *ptr_freq_band_tbl[MAX_FREQ_COEFFS + 1], WORD16 *ptr_num_sf_bands,
212     WORD32 upsamp_4_flag);
213 
214 WORD32 ixheaacd_sbr_read_pvc_sce(ia_sbr_frame_info_data_struct *ptr_frame_data,
215                                  ia_bit_buf_struct *it_bit_buff,
216                                  WORD32 hbe_flag,
217                                  ia_pvc_data_struct *ptr_pvc_data,
218                                  ia_sbr_tables_struct *sbr_tables_ptr,
219                                  ia_sbr_header_data_struct *ptr_header_data);
220 
221 WORD32 ixheaacd_qmf_hbe_apply(ia_esbr_hbe_txposer_struct *h_hbe_txposer,
222                               FLOAT32 qmf_buf_real[][64],
223                               FLOAT32 qmf_buf_imag[][64], WORD32 num_columns,
224                               FLOAT32 pv_qmf_buf_real[][64],
225                               FLOAT32 pv_qmf_buf_imag[][64],
226                               WORD32 pitch_in_bins);
227 
228 WORD32 ixheaacd_esbr_dec(ia_sbr_dec_struct *ptr_sbr_dec,
229                          ia_sbr_header_data_struct *ptr_header_data,
230                          ia_sbr_frame_info_data_struct *ptr_frame_data,
231                          FLAG apply_processing, FLAG low_pow_flag,
232                          ia_sbr_tables_struct *sbr_tables_ptr, WORD32 ch_fac);
233 
234 VOID ixheaacd_hbe_repl_spec(WORD32 x_over_qmf[MAX_NUM_PATCHES],
235                             FLOAT32 qmf_buf_real[][64],
236                             FLOAT32 qmf_buf_imag[][64], WORD32 no_bins,
237                             WORD32 max_stretch);
238 
239 #endif
240