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_channelinfo.h"
46 #include "ixheaacd_drc_dec.h"
47 #include "ixheaacd_sbrdecoder.h"
48 #include "ixheaacd_sbr_scale.h"
49 #include "ixheaacd_lpp_tran.h"
50 #include "ixheaacd_env_extr_part.h"
51 #include <ixheaacd_sbr_rom.h>
52 #include "ixheaacd_hybrid.h"
53 #include "ixheaacd_ps_dec.h"
54 #include "ixheaacd_env_extr.h"
55
56 #include <ixheaacd_aac_rom.h>
57 #include "ixheaacd_ps_dec.h"
58
59 #include "ixheaacd_qmf_dec.h"
60 #include "ixheaacd_env_calc.h"
61 #include "ixheaacd_sbr_const.h"
62 #include "ixheaacd_pvc_dec.h"
63 #include "ixheaacd_sbr_dec.h"
64 #include "ixheaacd_function_selector.h"
65
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)66 VOID ixheaacd_apply_ps(ia_ps_dec_struct *ptr_ps_dec, WORD32 **p_buf_left_real,
67 WORD32 **p_buf_left_imag, WORD32 *p_buf_right_real,
68 WORD32 *p_buf_right_imag,
69 ia_sbr_scale_fact_struct *sbr_scale_factor, WORD16 slot,
70 ia_sbr_tables_struct *sbr_tables_ptr) {
71 WORD16 shiftdelay =
72 (WORD16)((slot < (32 - MAX_OV_COLS)) ? 0 : (sbr_scale_factor->lb_scale -
73 sbr_scale_factor->ps_scale));
74
75 ixheaacd_hybrid_analysis(p_buf_left_real[HYBRID_FILTER_DELAY],
76 ptr_ps_dec->ptr_hyb_left_re,
77 ptr_ps_dec->ptr_hyb_left_im, &ptr_ps_dec->str_hybrid,
78 shiftdelay, sbr_tables_ptr);
79
80 (*ixheaacd_decorrelation)(ptr_ps_dec, p_buf_left_real[0], p_buf_left_imag[0],
81 p_buf_right_real, p_buf_right_imag,
82 sbr_tables_ptr->ps_tables_ptr);
83
84 (*ixheaacd_apply_rot)(ptr_ps_dec, p_buf_left_real[0], p_buf_left_imag[0],
85 p_buf_right_real, p_buf_right_imag, sbr_tables_ptr,
86 ptr_ps_dec->str_hybrid.ptr_resol);
87 }
88
ixheaacd_scale_ps_states(ia_ps_dec_struct * ptr_ps_dec,WORD16 scale)89 VOID ixheaacd_scale_ps_states(ia_ps_dec_struct *ptr_ps_dec, WORD16 scale) {
90 WORD i, m;
91 WORD32 delay;
92
93 if (scale > 0) {
94 WORD16 scale1 = scale;
95 if (scale > 15) scale1 = 15;
96
97 for (m = 0; m < 2; m++)
98 ixheaacd_scale_short_vec_left(
99 (WORD16 *)&ptr_ps_dec->delay_buf_qmf_ap_re_im[m][3 * 2],
100 2 * NUM_OF_QUAD_MIRROR_FILTER_ALL_PASS_CHNLS, scale1);
101
102 delay = 2 * HIGH_DEL * SMALL_DEL_STRT +
103 2 * SMALL_DEL *
104 (NUM_OF_QUAD_MIRROR_FILTER_ICC_CHNLS -
105 (NUM_OF_QUAD_MIRROR_FILTER_ALL_PASS_CHNLS + SMALL_DEL_STRT));
106 ixheaacd_scale_short_vec_left((WORD16 *)ptr_ps_dec->delay_buf_qmf_ld_re_im,
107 delay, scale1);
108
109 delay = 2 * 16 * DEL_ALL_PASS + 2 * NUM_SER_AP_LINKS * 5 * 16;
110 ixheaacd_scale_short_vec_left((WORD16 *)ptr_ps_dec->delay_buf_qmf_sub_re_im,
111 delay, scale1);
112
113 for (i = 0; i < NUM_SER_AP_LINKS; i++) {
114 for (m = 0; m < ptr_ps_dec->delay_sample_ser[i]; m++) {
115 ixheaacd_scale_short_vec_left(
116 (WORD16 *)&ptr_ps_dec->delay_buf_qmf_ser_re_im[m][i][2 * 3],
117 2 * NUM_OF_QUAD_MIRROR_FILTER_ALL_PASS_CHNLS, scale1);
118 }
119 }
120
121 ixheaacd_scale_int_vec_left(
122 ptr_ps_dec->str_hybrid.ptr_qmf_buf_re[0],
123 2 * NO_QMF_CHANNELS_IN_HYBRID * ptr_ps_dec->str_hybrid.ptr_qmf_buf,
124 scale);
125
126 scale = (scale + scale);
127
128 ixheaacd_scale_int_vec_left(ptr_ps_dec->peak_decay_diff, 3 * NUM_OF_BINS,
129 scale);
130
131 } else {
132 if (scale != 0) {
133 scale = -scale;
134 for (m = 0; m < 2; m++)
135 ixheaacd_scale_short_vec_right(
136 (WORD16 *)&ptr_ps_dec->delay_buf_qmf_ap_re_im[m][3 * 2],
137 2 * NUM_OF_QUAD_MIRROR_FILTER_ALL_PASS_CHNLS, scale);
138
139 delay = 2 * HIGH_DEL * SMALL_DEL_STRT +
140 2 * SMALL_DEL *
141 (NUM_OF_QUAD_MIRROR_FILTER_ICC_CHNLS -
142 (NUM_OF_QUAD_MIRROR_FILTER_ALL_PASS_CHNLS + SMALL_DEL_STRT));
143 ixheaacd_scale_short_vec_right(
144 (WORD16 *)ptr_ps_dec->delay_buf_qmf_ld_re_im, delay, scale);
145
146 delay = 2 * 16 * DEL_ALL_PASS + 2 * NUM_SER_AP_LINKS * 5 * 16;
147 ixheaacd_scale_short_vec_right(
148 (WORD16 *)ptr_ps_dec->delay_buf_qmf_sub_re_im, delay, scale);
149
150 for (i = 0; i < NUM_SER_AP_LINKS; i++) {
151 for (m = 0; m < ptr_ps_dec->delay_sample_ser[i]; m++) {
152 ixheaacd_scale_short_vec_right(
153 (WORD16 *)&ptr_ps_dec->delay_buf_qmf_ser_re_im[m][i][3 * 2],
154 2 * NUM_OF_QUAD_MIRROR_FILTER_ALL_PASS_CHNLS, scale);
155 }
156 }
157
158 ixheaacd_scale_int_vec_right(
159 ptr_ps_dec->str_hybrid.ptr_qmf_buf_re[0],
160 2 * NO_QMF_CHANNELS_IN_HYBRID * ptr_ps_dec->str_hybrid.ptr_qmf_buf,
161 scale);
162
163 scale = (scale + scale);
164
165 ixheaacd_scale_int_vec_right(ptr_ps_dec->peak_decay_diff, 3 * NUM_OF_BINS,
166 scale);
167 }
168 }
169 }
170