1*15dc779aSAndroid Build Coastguard Worker /******************************************************************************
2*15dc779aSAndroid Build Coastguard Worker * *
3*15dc779aSAndroid Build Coastguard Worker * Copyright (C) 2023 The Android Open Source Project
4*15dc779aSAndroid Build Coastguard Worker *
5*15dc779aSAndroid Build Coastguard Worker * Licensed under the Apache License, Version 2.0 (the "License");
6*15dc779aSAndroid Build Coastguard Worker * you may not use this file except in compliance with the License.
7*15dc779aSAndroid Build Coastguard Worker * You may obtain a copy of the License at:
8*15dc779aSAndroid Build Coastguard Worker *
9*15dc779aSAndroid Build Coastguard Worker * http://www.apache.org/licenses/LICENSE-2.0
10*15dc779aSAndroid Build Coastguard Worker *
11*15dc779aSAndroid Build Coastguard Worker * Unless required by applicable law or agreed to in writing, software
12*15dc779aSAndroid Build Coastguard Worker * distributed under the License is distributed on an "AS IS" BASIS,
13*15dc779aSAndroid Build Coastguard Worker * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14*15dc779aSAndroid Build Coastguard Worker * See the License for the specific language governing permissions and
15*15dc779aSAndroid Build Coastguard Worker * limitations under the License.
16*15dc779aSAndroid Build Coastguard Worker *
17*15dc779aSAndroid Build Coastguard Worker *****************************************************************************
18*15dc779aSAndroid Build Coastguard Worker * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
19*15dc779aSAndroid Build Coastguard Worker */
20*15dc779aSAndroid Build Coastguard Worker
21*15dc779aSAndroid Build Coastguard Worker #include <math.h>
22*15dc779aSAndroid Build Coastguard Worker #include <stdlib.h>
23*15dc779aSAndroid Build Coastguard Worker #include <string.h>
24*15dc779aSAndroid Build Coastguard Worker
25*15dc779aSAndroid Build Coastguard Worker #include "ixheaac_type_def.h"
26*15dc779aSAndroid Build Coastguard Worker #include "ixheaac_constants.h"
27*15dc779aSAndroid Build Coastguard Worker #include "ixheaace_aac_constants.h"
28*15dc779aSAndroid Build Coastguard Worker #include "ixheaac_basic_ops32.h"
29*15dc779aSAndroid Build Coastguard Worker #include "ixheaac_basic_ops16.h"
30*15dc779aSAndroid Build Coastguard Worker #include "ixheaac_basic_ops40.h"
31*15dc779aSAndroid Build Coastguard Worker #include "ixheaac_basic_ops.h"
32*15dc779aSAndroid Build Coastguard Worker
33*15dc779aSAndroid Build Coastguard Worker #include "ixheaace_psy_const.h"
34*15dc779aSAndroid Build Coastguard Worker #include "ixheaace_tns.h"
35*15dc779aSAndroid Build Coastguard Worker #include "ixheaace_tns_params.h"
36*15dc779aSAndroid Build Coastguard Worker #include "ixheaace_rom.h"
37*15dc779aSAndroid Build Coastguard Worker #include "ixheaace_common_rom.h"
38*15dc779aSAndroid Build Coastguard Worker #include "ixheaace_bitbuffer.h"
39*15dc779aSAndroid Build Coastguard Worker
40*15dc779aSAndroid Build Coastguard Worker #include "ixheaace_block_switch.h"
41*15dc779aSAndroid Build Coastguard Worker #include "ixheaace_psy_data.h"
42*15dc779aSAndroid Build Coastguard Worker #include "ixheaace_interface.h"
43*15dc779aSAndroid Build Coastguard Worker #include "ixheaace_adjust_threshold_data.h"
44*15dc779aSAndroid Build Coastguard Worker #include "ixheaace_dynamic_bits.h"
45*15dc779aSAndroid Build Coastguard Worker #include "ixheaace_qc_data.h"
46*15dc779aSAndroid Build Coastguard Worker #include "ixheaac_error_standards.h"
47*15dc779aSAndroid Build Coastguard Worker #include "ixheaace_stereo_preproc.h"
48*15dc779aSAndroid Build Coastguard Worker #include "ixheaace_common_utils.h"
49*15dc779aSAndroid Build Coastguard Worker
iaace_init_stereo_pre_processing(ixheaace_stereo_pre_pro_pstr pstr_stereo_pre_pro,WORD32 no_channels,WORD32 bit_rate,WORD32 sample_rate,FLOAT32 used_scf_ratio)50*15dc779aSAndroid Build Coastguard Worker IA_ERRORCODE iaace_init_stereo_pre_processing(ixheaace_stereo_pre_pro_pstr pstr_stereo_pre_pro,
51*15dc779aSAndroid Build Coastguard Worker WORD32 no_channels, WORD32 bit_rate, WORD32 sample_rate,
52*15dc779aSAndroid Build Coastguard Worker FLOAT32 used_scf_ratio) {
53*15dc779aSAndroid Build Coastguard Worker FLOAT32 bpf = bit_rate * 1024.0f / sample_rate;
54*15dc779aSAndroid Build Coastguard Worker FLOAT32 tmp;
55*15dc779aSAndroid Build Coastguard Worker
56*15dc779aSAndroid Build Coastguard Worker memset(pstr_stereo_pre_pro, 0, sizeof(ixheaace_stereo_pre_pro_struct));
57*15dc779aSAndroid Build Coastguard Worker
58*15dc779aSAndroid Build Coastguard Worker if (no_channels == 2) {
59*15dc779aSAndroid Build Coastguard Worker (pstr_stereo_pre_pro)->stereo_attenuation_flag = 1;
60*15dc779aSAndroid Build Coastguard Worker
61*15dc779aSAndroid Build Coastguard Worker (pstr_stereo_pre_pro)->norm_pe_fac = 230.0f * used_scf_ratio / bpf;
62*15dc779aSAndroid Build Coastguard Worker (pstr_stereo_pre_pro)->impact_factor =
63*15dc779aSAndroid Build Coastguard Worker MIN(1, 400000.0f / (FLOAT32)(bit_rate - sample_rate * sample_rate / 72000.0f));
64*15dc779aSAndroid Build Coastguard Worker (pstr_stereo_pre_pro)->inc_stereo_attenuation = 22050.0f / sample_rate * 400.0f / bpf;
65*15dc779aSAndroid Build Coastguard Worker (pstr_stereo_pre_pro)->dec_stereo_attenuation = 22050.0f / sample_rate * 200.0f / bpf;
66*15dc779aSAndroid Build Coastguard Worker
67*15dc779aSAndroid Build Coastguard Worker (pstr_stereo_pre_pro)->const_attenuation = 0.0f;
68*15dc779aSAndroid Build Coastguard Worker (pstr_stereo_pre_pro)->stereo_attenuation_max = 12.0f;
69*15dc779aSAndroid Build Coastguard Worker
70*15dc779aSAndroid Build Coastguard Worker /* energy ratio thresholds (dB) */
71*15dc779aSAndroid Build Coastguard Worker (pstr_stereo_pre_pro)->sm_min = 0.0f;
72*15dc779aSAndroid Build Coastguard Worker (pstr_stereo_pre_pro)->sm_max = 15.0f;
73*15dc779aSAndroid Build Coastguard Worker (pstr_stereo_pre_pro)->lr_min = 10.0f;
74*15dc779aSAndroid Build Coastguard Worker (pstr_stereo_pre_pro)->lr_max = 30.0f;
75*15dc779aSAndroid Build Coastguard Worker
76*15dc779aSAndroid Build Coastguard Worker /* pe thresholds */
77*15dc779aSAndroid Build Coastguard Worker (pstr_stereo_pre_pro)->pe_crit = 1200.0f;
78*15dc779aSAndroid Build Coastguard Worker (pstr_stereo_pre_pro)->pe_min = 700.0f;
79*15dc779aSAndroid Build Coastguard Worker (pstr_stereo_pre_pro)->pe_impact_max = 100.0f;
80*15dc779aSAndroid Build Coastguard Worker
81*15dc779aSAndroid Build Coastguard Worker /* init start values */
82*15dc779aSAndroid Build Coastguard Worker (pstr_stereo_pre_pro)->average_freq_energy_l = 0.0f;
83*15dc779aSAndroid Build Coastguard Worker (pstr_stereo_pre_pro)->average_freq_energy_r = 0.0f;
84*15dc779aSAndroid Build Coastguard Worker (pstr_stereo_pre_pro)->average_freq_energy_s = 0.0f;
85*15dc779aSAndroid Build Coastguard Worker (pstr_stereo_pre_pro)->average_freq_energy_m = 0.0f;
86*15dc779aSAndroid Build Coastguard Worker (pstr_stereo_pre_pro)->smoothed_pe_sum_sum = 7000.0f; /* typical start value */
87*15dc779aSAndroid Build Coastguard Worker (pstr_stereo_pre_pro)->avg_s_to_m = -10.0f; /* typical start value */
88*15dc779aSAndroid Build Coastguard Worker (pstr_stereo_pre_pro)->last_l_to_r = 0.0f;
89*15dc779aSAndroid Build Coastguard Worker (pstr_stereo_pre_pro)->last_nrg_lr = 0.0f;
90*15dc779aSAndroid Build Coastguard Worker
91*15dc779aSAndroid Build Coastguard Worker tmp = 1.0f - (bpf / 2600.0f);
92*15dc779aSAndroid Build Coastguard Worker
93*15dc779aSAndroid Build Coastguard Worker tmp = MAX(tmp, 0.0f);
94*15dc779aSAndroid Build Coastguard Worker
95*15dc779aSAndroid Build Coastguard Worker (pstr_stereo_pre_pro)->stereo_attenuation =
96*15dc779aSAndroid Build Coastguard Worker tmp * (pstr_stereo_pre_pro)->stereo_attenuation_max;
97*15dc779aSAndroid Build Coastguard Worker }
98*15dc779aSAndroid Build Coastguard Worker
99*15dc779aSAndroid Build Coastguard Worker return IA_NO_ERROR;
100*15dc779aSAndroid Build Coastguard Worker }
101*15dc779aSAndroid Build Coastguard Worker
iaace_apply_stereo_preproc(ixheaace_stereo_pre_pro_pstr pstr_stereo_pre_pro,WORD32 num_channels,ixheaace_element_info * pstr_elem_info,FLOAT32 * ptr_time_data,WORD32 granule_len)102*15dc779aSAndroid Build Coastguard Worker VOID iaace_apply_stereo_preproc(ixheaace_stereo_pre_pro_pstr pstr_stereo_pre_pro,
103*15dc779aSAndroid Build Coastguard Worker WORD32 num_channels, ixheaace_element_info *pstr_elem_info,
104*15dc779aSAndroid Build Coastguard Worker FLOAT32 *ptr_time_data, WORD32 granule_len) {
105*15dc779aSAndroid Build Coastguard Worker FLOAT32 sm_ratio, s_to_m;
106*15dc779aSAndroid Build Coastguard Worker FLOAT32 lr_ratio, l_to_r, delta_l_to_r, delta_nrg;
107*15dc779aSAndroid Build Coastguard Worker FLOAT32 en_impact, pe_impact, pe_norm;
108*15dc779aSAndroid Build Coastguard Worker FLOAT32 att, att_aimed;
109*15dc779aSAndroid Build Coastguard Worker FLOAT32 max_inc, max_dec, swift_factor;
110*15dc779aSAndroid Build Coastguard Worker FLOAT32 delta = 0.1f;
111*15dc779aSAndroid Build Coastguard Worker FLOAT32 fac = pstr_stereo_pre_pro->stereo_attenuation_fac;
112*15dc779aSAndroid Build Coastguard Worker FLOAT32 m_part, upper, div;
113*15dc779aSAndroid Build Coastguard Worker FLOAT32 l_fac, r_fac;
114*15dc779aSAndroid Build Coastguard Worker FLOAT32 L, R;
115*15dc779aSAndroid Build Coastguard Worker WORD32 i;
116*15dc779aSAndroid Build Coastguard Worker
117*15dc779aSAndroid Build Coastguard Worker if (!pstr_stereo_pre_pro->stereo_attenuation_flag) {
118*15dc779aSAndroid Build Coastguard Worker return;
119*15dc779aSAndroid Build Coastguard Worker }
120*15dc779aSAndroid Build Coastguard Worker
121*15dc779aSAndroid Build Coastguard Worker m_part = 2.0f * pstr_stereo_pre_pro->average_freq_energy_m * (1.0f - fac * fac);
122*15dc779aSAndroid Build Coastguard Worker
123*15dc779aSAndroid Build Coastguard Worker upper = pstr_stereo_pre_pro->average_freq_energy_l * (1.0f + fac) +
124*15dc779aSAndroid Build Coastguard Worker pstr_stereo_pre_pro->average_freq_energy_r * (1.0f - fac) - m_part;
125*15dc779aSAndroid Build Coastguard Worker div = pstr_stereo_pre_pro->average_freq_energy_r * (1.0f + fac) +
126*15dc779aSAndroid Build Coastguard Worker pstr_stereo_pre_pro->average_freq_energy_l * (1.0f - fac) - m_part;
127*15dc779aSAndroid Build Coastguard Worker
128*15dc779aSAndroid Build Coastguard Worker if ((div == 0.0f) || (upper == 0.0f)) {
129*15dc779aSAndroid Build Coastguard Worker l_to_r = pstr_stereo_pre_pro->lr_max;
130*15dc779aSAndroid Build Coastguard Worker } else {
131*15dc779aSAndroid Build Coastguard Worker lr_ratio = (FLOAT32)fabs(upper / div);
132*15dc779aSAndroid Build Coastguard Worker l_to_r = (FLOAT32)fabs(10.0f * log10(lr_ratio));
133*15dc779aSAndroid Build Coastguard Worker }
134*15dc779aSAndroid Build Coastguard Worker
135*15dc779aSAndroid Build Coastguard Worker /* Calculate delta energy to previous frame */
136*15dc779aSAndroid Build Coastguard Worker delta_nrg = (pstr_stereo_pre_pro->average_freq_energy_l +
137*15dc779aSAndroid Build Coastguard Worker pstr_stereo_pre_pro->average_freq_energy_r + 1.0f) /
138*15dc779aSAndroid Build Coastguard Worker (pstr_stereo_pre_pro->last_nrg_lr + 1.0f);
139*15dc779aSAndroid Build Coastguard Worker
140*15dc779aSAndroid Build Coastguard Worker delta_nrg = (FLOAT32)(fabs(10.0f * log10(delta_nrg)));
141*15dc779aSAndroid Build Coastguard Worker
142*15dc779aSAndroid Build Coastguard Worker /* Smooth S/M over time */
143*15dc779aSAndroid Build Coastguard Worker sm_ratio = (pstr_stereo_pre_pro->average_freq_energy_s + 1.0f) /
144*15dc779aSAndroid Build Coastguard Worker (pstr_stereo_pre_pro->average_freq_energy_m + 1.0f);
145*15dc779aSAndroid Build Coastguard Worker
146*15dc779aSAndroid Build Coastguard Worker s_to_m = (FLOAT32)(10.0f * log10(sm_ratio));
147*15dc779aSAndroid Build Coastguard Worker
148*15dc779aSAndroid Build Coastguard Worker pstr_stereo_pre_pro->avg_s_to_m =
149*15dc779aSAndroid Build Coastguard Worker delta * s_to_m + (1 - delta) * pstr_stereo_pre_pro->avg_s_to_m;
150*15dc779aSAndroid Build Coastguard Worker
151*15dc779aSAndroid Build Coastguard Worker en_impact = 1.0f;
152*15dc779aSAndroid Build Coastguard Worker
153*15dc779aSAndroid Build Coastguard Worker if (pstr_stereo_pre_pro->avg_s_to_m > pstr_stereo_pre_pro->sm_min) {
154*15dc779aSAndroid Build Coastguard Worker if (pstr_stereo_pre_pro->avg_s_to_m > pstr_stereo_pre_pro->sm_max) {
155*15dc779aSAndroid Build Coastguard Worker en_impact = 0.0f;
156*15dc779aSAndroid Build Coastguard Worker } else {
157*15dc779aSAndroid Build Coastguard Worker en_impact = (pstr_stereo_pre_pro->sm_max - pstr_stereo_pre_pro->avg_s_to_m) /
158*15dc779aSAndroid Build Coastguard Worker (pstr_stereo_pre_pro->sm_max - pstr_stereo_pre_pro->sm_min);
159*15dc779aSAndroid Build Coastguard Worker }
160*15dc779aSAndroid Build Coastguard Worker }
161*15dc779aSAndroid Build Coastguard Worker
162*15dc779aSAndroid Build Coastguard Worker if (l_to_r > pstr_stereo_pre_pro->lr_min) {
163*15dc779aSAndroid Build Coastguard Worker if (l_to_r > pstr_stereo_pre_pro->lr_max) {
164*15dc779aSAndroid Build Coastguard Worker en_impact = 0.0f;
165*15dc779aSAndroid Build Coastguard Worker } else {
166*15dc779aSAndroid Build Coastguard Worker en_impact *= (pstr_stereo_pre_pro->lr_max - l_to_r) /
167*15dc779aSAndroid Build Coastguard Worker (pstr_stereo_pre_pro->lr_max - pstr_stereo_pre_pro->lr_min);
168*15dc779aSAndroid Build Coastguard Worker }
169*15dc779aSAndroid Build Coastguard Worker }
170*15dc779aSAndroid Build Coastguard Worker
171*15dc779aSAndroid Build Coastguard Worker pe_impact = 0.0f;
172*15dc779aSAndroid Build Coastguard Worker
173*15dc779aSAndroid Build Coastguard Worker pe_norm = pstr_stereo_pre_pro->smoothed_pe_sum_sum * pstr_stereo_pre_pro->norm_pe_fac;
174*15dc779aSAndroid Build Coastguard Worker
175*15dc779aSAndroid Build Coastguard Worker if (pe_norm > pstr_stereo_pre_pro->pe_min) {
176*15dc779aSAndroid Build Coastguard Worker pe_impact = ((pe_norm - pstr_stereo_pre_pro->pe_min) /
177*15dc779aSAndroid Build Coastguard Worker (pstr_stereo_pre_pro->pe_crit - pstr_stereo_pre_pro->pe_min));
178*15dc779aSAndroid Build Coastguard Worker }
179*15dc779aSAndroid Build Coastguard Worker
180*15dc779aSAndroid Build Coastguard Worker pe_impact = MIN(pe_impact, pstr_stereo_pre_pro->pe_impact_max);
181*15dc779aSAndroid Build Coastguard Worker
182*15dc779aSAndroid Build Coastguard Worker att_aimed = MIN((en_impact * pe_impact * pstr_stereo_pre_pro->impact_factor),
183*15dc779aSAndroid Build Coastguard Worker pstr_stereo_pre_pro->stereo_attenuation_max);
184*15dc779aSAndroid Build Coastguard Worker
185*15dc779aSAndroid Build Coastguard Worker /* Only accept changes if they are large enough */
186*15dc779aSAndroid Build Coastguard Worker if ((fabs(att_aimed - pstr_stereo_pre_pro->stereo_attenuation) < 1.0f) && (att_aimed != 0.0f)) {
187*15dc779aSAndroid Build Coastguard Worker att_aimed = pstr_stereo_pre_pro->stereo_attenuation;
188*15dc779aSAndroid Build Coastguard Worker }
189*15dc779aSAndroid Build Coastguard Worker
190*15dc779aSAndroid Build Coastguard Worker att = att_aimed;
191*15dc779aSAndroid Build Coastguard Worker
192*15dc779aSAndroid Build Coastguard Worker swift_factor = (6.0f + pstr_stereo_pre_pro->stereo_attenuation) / (10.0f + l_to_r) *
193*15dc779aSAndroid Build Coastguard Worker MAX(1.0f, 0.2f * delta_nrg);
194*15dc779aSAndroid Build Coastguard Worker
195*15dc779aSAndroid Build Coastguard Worker delta_l_to_r = MAX(3.0f, l_to_r - pstr_stereo_pre_pro->last_l_to_r);
196*15dc779aSAndroid Build Coastguard Worker
197*15dc779aSAndroid Build Coastguard Worker max_dec = MIN((delta_l_to_r * delta_l_to_r / 9.0f * swift_factor), 5.0f);
198*15dc779aSAndroid Build Coastguard Worker
199*15dc779aSAndroid Build Coastguard Worker max_dec *= pstr_stereo_pre_pro->dec_stereo_attenuation;
200*15dc779aSAndroid Build Coastguard Worker
201*15dc779aSAndroid Build Coastguard Worker max_dec = MIN(max_dec, pstr_stereo_pre_pro->stereo_attenuation * 0.8f);
202*15dc779aSAndroid Build Coastguard Worker
203*15dc779aSAndroid Build Coastguard Worker delta_l_to_r = MAX(3.0f, pstr_stereo_pre_pro->last_l_to_r - l_to_r);
204*15dc779aSAndroid Build Coastguard Worker
205*15dc779aSAndroid Build Coastguard Worker max_inc = MIN((delta_l_to_r * delta_l_to_r / 9.0f * swift_factor), 5.0f);
206*15dc779aSAndroid Build Coastguard Worker
207*15dc779aSAndroid Build Coastguard Worker max_inc *= pstr_stereo_pre_pro->inc_stereo_attenuation;
208*15dc779aSAndroid Build Coastguard Worker
209*15dc779aSAndroid Build Coastguard Worker att = MIN(att, pstr_stereo_pre_pro->stereo_attenuation + max_inc);
210*15dc779aSAndroid Build Coastguard Worker
211*15dc779aSAndroid Build Coastguard Worker att = MAX(att, pstr_stereo_pre_pro->stereo_attenuation - max_dec);
212*15dc779aSAndroid Build Coastguard Worker
213*15dc779aSAndroid Build Coastguard Worker pstr_stereo_pre_pro->stereo_attenuation = (pstr_stereo_pre_pro->const_attenuation == 0)
214*15dc779aSAndroid Build Coastguard Worker ? att
215*15dc779aSAndroid Build Coastguard Worker : pstr_stereo_pre_pro->const_attenuation;
216*15dc779aSAndroid Build Coastguard Worker
217*15dc779aSAndroid Build Coastguard Worker /* Perform attenuation of side channel */
218*15dc779aSAndroid Build Coastguard Worker pstr_stereo_pre_pro->stereo_attenuation_fac =
219*15dc779aSAndroid Build Coastguard Worker (FLOAT32)pow(10.0f, 0.05f * (-pstr_stereo_pre_pro->stereo_attenuation));
220*15dc779aSAndroid Build Coastguard Worker
221*15dc779aSAndroid Build Coastguard Worker l_fac = 0.5f * (1.0f + pstr_stereo_pre_pro->stereo_attenuation_fac);
222*15dc779aSAndroid Build Coastguard Worker r_fac = 0.5f * (1.0f - pstr_stereo_pre_pro->stereo_attenuation_fac);
223*15dc779aSAndroid Build Coastguard Worker
224*15dc779aSAndroid Build Coastguard Worker for (i = 0; i < granule_len; i++) {
225*15dc779aSAndroid Build Coastguard Worker L = l_fac * ptr_time_data[num_channels * i + pstr_elem_info->channel_index[0]] +
226*15dc779aSAndroid Build Coastguard Worker r_fac * ptr_time_data[num_channels * i + pstr_elem_info->channel_index[1]];
227*15dc779aSAndroid Build Coastguard Worker R = r_fac * ptr_time_data[num_channels * i + pstr_elem_info->channel_index[0]] +
228*15dc779aSAndroid Build Coastguard Worker l_fac * ptr_time_data[num_channels * i + pstr_elem_info->channel_index[1]];
229*15dc779aSAndroid Build Coastguard Worker
230*15dc779aSAndroid Build Coastguard Worker ptr_time_data[num_channels * i + pstr_elem_info->channel_index[0]] = L;
231*15dc779aSAndroid Build Coastguard Worker ptr_time_data[num_channels * i + pstr_elem_info->channel_index[1]] = R;
232*15dc779aSAndroid Build Coastguard Worker }
233*15dc779aSAndroid Build Coastguard Worker
234*15dc779aSAndroid Build Coastguard Worker pstr_stereo_pre_pro->last_l_to_r = l_to_r;
235*15dc779aSAndroid Build Coastguard Worker
236*15dc779aSAndroid Build Coastguard Worker pstr_stereo_pre_pro->last_nrg_lr =
237*15dc779aSAndroid Build Coastguard Worker pstr_stereo_pre_pro->average_freq_energy_l + pstr_stereo_pre_pro->average_freq_energy_r;
238*15dc779aSAndroid Build Coastguard Worker }
239*15dc779aSAndroid Build Coastguard Worker
iaace_update_stereo_pre_process(ixheaace_psy_out_channel ** pstr_psy_out,ixheaace_qc_out_element * pstr_qc_out,ixheaace_stereo_pre_pro_pstr pstr_stereo_pre_pro,FLOAT32 weight_pe_fac)240*15dc779aSAndroid Build Coastguard Worker VOID iaace_update_stereo_pre_process(ixheaace_psy_out_channel **pstr_psy_out,
241*15dc779aSAndroid Build Coastguard Worker ixheaace_qc_out_element *pstr_qc_out,
242*15dc779aSAndroid Build Coastguard Worker ixheaace_stereo_pre_pro_pstr pstr_stereo_pre_pro,
243*15dc779aSAndroid Build Coastguard Worker FLOAT32 weight_pe_fac) {
244*15dc779aSAndroid Build Coastguard Worker if (pstr_stereo_pre_pro->stereo_attenuation_flag) {
245*15dc779aSAndroid Build Coastguard Worker FLOAT32 delta = 0.1f;
246*15dc779aSAndroid Build Coastguard Worker
247*15dc779aSAndroid Build Coastguard Worker pstr_stereo_pre_pro->average_freq_energy_l = pstr_psy_out[0]->sfb_sum_lr_energy;
248*15dc779aSAndroid Build Coastguard Worker pstr_stereo_pre_pro->average_freq_energy_r = pstr_psy_out[1]->sfb_sum_lr_energy;
249*15dc779aSAndroid Build Coastguard Worker pstr_stereo_pre_pro->average_freq_energy_m = pstr_psy_out[0]->sfb_sum_ms_energy;
250*15dc779aSAndroid Build Coastguard Worker pstr_stereo_pre_pro->average_freq_energy_s = pstr_psy_out[1]->sfb_sum_ms_energy;
251*15dc779aSAndroid Build Coastguard Worker
252*15dc779aSAndroid Build Coastguard Worker pstr_stereo_pre_pro->smoothed_pe_sum_sum =
253*15dc779aSAndroid Build Coastguard Worker delta * pstr_qc_out->pe * weight_pe_fac +
254*15dc779aSAndroid Build Coastguard Worker (1 - delta) * pstr_stereo_pre_pro->smoothed_pe_sum_sum;
255*15dc779aSAndroid Build Coastguard Worker }
256*15dc779aSAndroid Build Coastguard Worker }
257