• 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 #include <string.h>
21 #include "ixheaacd_sbr_common.h"
22 #include "ixheaacd_type_def.h"
23 
24 #include "ixheaacd_constants.h"
25 #include "ixheaacd_basic_ops32.h"
26 #include "ixheaacd_basic_ops16.h"
27 #include "ixheaacd_basic_ops40.h"
28 #include "ixheaacd_basic_ops_arr.h"
29 #include "ixheaacd_basic_ops.h"
30 
31 #include "ixheaacd_defines.h"
32 #include "ixheaacd_basic_op.h"
33 #include "ixheaacd_intrinsics.h"
34 #include "ixheaacd_common_rom.h"
35 #include "ixheaacd_basic_funcs.h"
36 #include "ixheaacd_bitbuffer.h"
37 #include "ixheaacd_sbrdecsettings.h"
38 #include "ixheaacd_defines.h"
39 #include "ixheaacd_pns.h"
40 #include "ixheaacd_aac_rom.h"
41 #include "ixheaacd_pulsedata.h"
42 
43 #include "ixheaacd_drc_data_struct.h"
44 #include "ixheaacd_lt_predict.h"
45 #include "ixheaacd_cnst.h"
46 #include "ixheaacd_ec_defines.h"
47 #include "ixheaacd_ec_struct_def.h"
48 #include "ixheaacd_channelinfo.h"
49 #include "ixheaacd_drc_dec.h"
50 #include "ixheaacd_sbrdecoder.h"
51 #include "ixheaacd_sbr_scale.h"
52 #include "ixheaacd_lpp_tran.h"
53 #include "ixheaacd_env_extr_part.h"
54 #include "ixheaacd_sbr_rom.h"
55 #include "ixheaacd_hybrid.h"
56 #include "ixheaacd_ps_dec.h"
57 #include "ixheaacd_env_extr.h"
58 
59 #include "ixheaacd_aac_rom.h"
60 #include "ixheaacd_ps_dec.h"
61 
62 #include "ixheaacd_qmf_dec.h"
63 #include "ixheaacd_env_calc.h"
64 #include "ixheaacd_sbr_const.h"
65 #include "ixheaacd_pvc_dec.h"
66 #include "ixheaacd_sbr_dec.h"
67 #include "ixheaacd_function_selector.h"
68 
ixheaacd_apply_ps(ia_ps_dec_struct * ptr_ps_dec,WORD32 ** p_buf_left_real,WORD32 ** p_buf_left_imag,WORD32 * p_buf_right_real,WORD32 * p_buf_right_imag,ia_sbr_scale_fact_struct * sbr_scale_factor,WORD16 slot,ia_sbr_tables_struct * sbr_tables_ptr,WORD no_col)69 VOID ixheaacd_apply_ps(ia_ps_dec_struct *ptr_ps_dec, WORD32 **p_buf_left_real,
70                        WORD32 **p_buf_left_imag, WORD32 *p_buf_right_real,
71                        WORD32 *p_buf_right_imag,
72                        ia_sbr_scale_fact_struct *sbr_scale_factor, WORD16 slot,
73                        ia_sbr_tables_struct *sbr_tables_ptr, WORD no_col) {
74 
75   WORD16 shiftdelay;
76 
77   if (no_col != 30) {
78     shiftdelay =
79         (WORD16)((slot < (32 - MAX_OV_COLS)) ? 0 : (sbr_scale_factor->lb_scale -
80             sbr_scale_factor->ps_scale));
81   } else {
82   shiftdelay =
83       (WORD16)((slot < (no_col - MAX_OV_COLS)) ? 0 : (sbr_scale_factor->lb_scale -
84           sbr_scale_factor->ps_scale));
85   }
86 
87   ixheaacd_hybrid_analysis(p_buf_left_real[HYBRID_FILTER_DELAY],
88                            ptr_ps_dec->ptr_hyb_left_re,
89                            ptr_ps_dec->ptr_hyb_left_im, &ptr_ps_dec->str_hybrid,
90                            shiftdelay, sbr_tables_ptr);
91 
92   (*ixheaacd_decorrelation)(ptr_ps_dec, p_buf_left_real[0], p_buf_left_imag[0],
93                             p_buf_right_real, p_buf_right_imag,
94                             sbr_tables_ptr->ps_tables_ptr);
95 
96   (*ixheaacd_apply_rot)(ptr_ps_dec, p_buf_left_real[0], p_buf_left_imag[0],
97                         p_buf_right_real, p_buf_right_imag, sbr_tables_ptr,
98                         ptr_ps_dec->str_hybrid.ptr_resol);
99 }
100 
ixheaacd_scale_ps_states(ia_ps_dec_struct * ptr_ps_dec,WORD16 scale)101 VOID ixheaacd_scale_ps_states(ia_ps_dec_struct *ptr_ps_dec, WORD16 scale) {
102   WORD i, m;
103   WORD32 delay;
104 
105   if (scale > 0) {
106     WORD16 scale1 = scale;
107     if (scale > 15) scale1 = 15;
108 
109     for (m = 0; m < 2; m++)
110       ixheaacd_scale_short_vec_left(
111           (WORD16 *)&ptr_ps_dec->delay_buf_qmf_ap_re_im[m][3 * 2],
112           2 * NUM_OF_QUAD_MIRROR_FILTER_ALL_PASS_CHNLS, scale1);
113 
114     delay = 2 * HIGH_DEL * SMALL_DEL_STRT +
115             2 * SMALL_DEL *
116                 (NUM_OF_QUAD_MIRROR_FILTER_ICC_CHNLS -
117                  (NUM_OF_QUAD_MIRROR_FILTER_ALL_PASS_CHNLS + SMALL_DEL_STRT));
118     ixheaacd_scale_short_vec_left((WORD16 *)ptr_ps_dec->delay_buf_qmf_ld_re_im,
119                                   delay, scale1);
120 
121     delay = 2 * 16 * DEL_ALL_PASS + 2 * NUM_SER_AP_LINKS * 5 * 16;
122     ixheaacd_scale_short_vec_left((WORD16 *)ptr_ps_dec->delay_buf_qmf_sub_re_im,
123                                   delay, scale1);
124 
125     for (i = 0; i < NUM_SER_AP_LINKS; i++) {
126       for (m = 0; m < ptr_ps_dec->delay_sample_ser[i]; m++) {
127         ixheaacd_scale_short_vec_left(
128             (WORD16 *)&ptr_ps_dec->delay_buf_qmf_ser_re_im[m][i][2 * 3],
129             2 * NUM_OF_QUAD_MIRROR_FILTER_ALL_PASS_CHNLS, scale1);
130       }
131     }
132 
133     ixheaacd_scale_int_vec_left(
134         ptr_ps_dec->str_hybrid.ptr_qmf_buf_re[0],
135         2 * NO_QMF_CHANNELS_IN_HYBRID * ptr_ps_dec->str_hybrid.ptr_qmf_buf,
136         scale);
137 
138     scale = (scale + scale);
139 
140     ixheaacd_scale_int_vec_left(ptr_ps_dec->peak_decay_diff, 3 * NUM_OF_BINS,
141                                 scale);
142 
143   } else {
144     if (scale != 0) {
145       scale = -scale;
146       for (m = 0; m < 2; m++)
147         ixheaacd_scale_short_vec_right(
148             (WORD16 *)&ptr_ps_dec->delay_buf_qmf_ap_re_im[m][3 * 2],
149             2 * NUM_OF_QUAD_MIRROR_FILTER_ALL_PASS_CHNLS, scale);
150 
151       delay = 2 * HIGH_DEL * SMALL_DEL_STRT +
152               2 * SMALL_DEL *
153                   (NUM_OF_QUAD_MIRROR_FILTER_ICC_CHNLS -
154                    (NUM_OF_QUAD_MIRROR_FILTER_ALL_PASS_CHNLS + SMALL_DEL_STRT));
155       ixheaacd_scale_short_vec_right(
156           (WORD16 *)ptr_ps_dec->delay_buf_qmf_ld_re_im, delay, scale);
157 
158       delay = 2 * 16 * DEL_ALL_PASS + 2 * NUM_SER_AP_LINKS * 5 * 16;
159       ixheaacd_scale_short_vec_right(
160           (WORD16 *)ptr_ps_dec->delay_buf_qmf_sub_re_im, delay, scale);
161 
162       for (i = 0; i < NUM_SER_AP_LINKS; i++) {
163         for (m = 0; m < ptr_ps_dec->delay_sample_ser[i]; m++) {
164           ixheaacd_scale_short_vec_right(
165               (WORD16 *)&ptr_ps_dec->delay_buf_qmf_ser_re_im[m][i][3 * 2],
166               2 * NUM_OF_QUAD_MIRROR_FILTER_ALL_PASS_CHNLS, scale);
167         }
168       }
169 
170       ixheaacd_scale_int_vec_right(
171           ptr_ps_dec->str_hybrid.ptr_qmf_buf_re[0],
172           2 * NO_QMF_CHANNELS_IN_HYBRID * ptr_ps_dec->str_hybrid.ptr_qmf_buf,
173           scale);
174 
175       scale = (scale + scale);
176 
177       ixheaacd_scale_int_vec_right(ptr_ps_dec->peak_decay_diff, 3 * NUM_OF_BINS,
178                                    scale);
179     }
180   }
181 }
182