xref: /aosp_15_r20/external/libxaac/encoder/iusace_block_switch.c (revision 15dc779a375ca8b5125643b829a8aa4b70d7f451)
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 "iusace_type_def.h"
22*15dc779aSAndroid Build Coastguard Worker #include "ixheaace_mps_common_define.h"
23*15dc779aSAndroid Build Coastguard Worker #include "iusace_cnst.h"
24*15dc779aSAndroid Build Coastguard Worker #include "iusace_block_switch_const.h"
25*15dc779aSAndroid Build Coastguard Worker #include "iusace_block_switch_struct_def.h"
26*15dc779aSAndroid Build Coastguard Worker #include "iusace_rom.h"
27*15dc779aSAndroid Build Coastguard Worker 
iusace_fmult(FLOAT32 a,FLOAT32 b)28*15dc779aSAndroid Build Coastguard Worker static FLOAT32 iusace_fmult(FLOAT32 a, FLOAT32 b) { return (a * b); }
29*15dc779aSAndroid Build Coastguard Worker 
iusace_fadd(FLOAT32 a,FLOAT32 b)30*15dc779aSAndroid Build Coastguard Worker static FLOAT32 iusace_fadd(FLOAT32 a, FLOAT32 b) { return (a + b); }
31*15dc779aSAndroid Build Coastguard Worker 
iusace_init_block_switching(ia_block_switch_ctrl * pstr_blk_switch_ctrl,const WORD32 bit_rate,const WORD32 num_chans)32*15dc779aSAndroid Build Coastguard Worker VOID iusace_init_block_switching(ia_block_switch_ctrl *pstr_blk_switch_ctrl,
33*15dc779aSAndroid Build Coastguard Worker                                  const WORD32 bit_rate, const WORD32 num_chans) {
34*15dc779aSAndroid Build Coastguard Worker   WORD32 i, w;
35*15dc779aSAndroid Build Coastguard Worker 
36*15dc779aSAndroid Build Coastguard Worker   if ((num_chans == 1 && bit_rate > 24000) || (num_chans > 1 && bit_rate / num_chans > 16000)) {
37*15dc779aSAndroid Build Coastguard Worker     pstr_blk_switch_ctrl->inv_attack_ratio = INV_ATTACK_RATIO_HIGH_BR;
38*15dc779aSAndroid Build Coastguard Worker   } else {
39*15dc779aSAndroid Build Coastguard Worker     pstr_blk_switch_ctrl->inv_attack_ratio = INV_ATTACK_RATIO_LOW_BR;
40*15dc779aSAndroid Build Coastguard Worker   }
41*15dc779aSAndroid Build Coastguard Worker 
42*15dc779aSAndroid Build Coastguard Worker   for (i = 0; i < BLK_SWITCH_FILT_LEN; i++) {
43*15dc779aSAndroid Build Coastguard Worker     pstr_blk_switch_ctrl->iir_states[i] = 0;
44*15dc779aSAndroid Build Coastguard Worker   }
45*15dc779aSAndroid Build Coastguard Worker 
46*15dc779aSAndroid Build Coastguard Worker   /* Clear Filtered Window Energies */
47*15dc779aSAndroid Build Coastguard Worker   for (w = 0; w < MAX_SHORT_WINDOWS; w++) {
48*15dc779aSAndroid Build Coastguard Worker     pstr_blk_switch_ctrl->win_energy_filt[0][w] = 0;
49*15dc779aSAndroid Build Coastguard Worker     pstr_blk_switch_ctrl->win_energy_filt[1][w] = 0;
50*15dc779aSAndroid Build Coastguard Worker     pstr_blk_switch_ctrl->win_energy[0][w] = 0;
51*15dc779aSAndroid Build Coastguard Worker     pstr_blk_switch_ctrl->win_energy[1][w] = 0;
52*15dc779aSAndroid Build Coastguard Worker   }
53*15dc779aSAndroid Build Coastguard Worker   pstr_blk_switch_ctrl->acc_win_energy = 0;
54*15dc779aSAndroid Build Coastguard Worker 
55*15dc779aSAndroid Build Coastguard Worker   pstr_blk_switch_ctrl->window_seq = ONLY_LONG_SEQUENCE;
56*15dc779aSAndroid Build Coastguard Worker   pstr_blk_switch_ctrl->next_win_seq = ONLY_LONG_SEQUENCE;
57*15dc779aSAndroid Build Coastguard Worker 
58*15dc779aSAndroid Build Coastguard Worker   pstr_blk_switch_ctrl->attack = 0;
59*15dc779aSAndroid Build Coastguard Worker   pstr_blk_switch_ctrl->lastattack = 0;
60*15dc779aSAndroid Build Coastguard Worker   pstr_blk_switch_ctrl->attack_idx = 0;
61*15dc779aSAndroid Build Coastguard Worker   pstr_blk_switch_ctrl->last_attack_idx = 0;
62*15dc779aSAndroid Build Coastguard Worker 
63*15dc779aSAndroid Build Coastguard Worker   return;
64*15dc779aSAndroid Build Coastguard Worker }
65*15dc779aSAndroid Build Coastguard Worker 
iusace_srch_max_with_idx(const FLOAT32 * ptr_in,WORD32 * index)66*15dc779aSAndroid Build Coastguard Worker static FLOAT32 iusace_srch_max_with_idx(const FLOAT32 *ptr_in, WORD32 *index) {
67*15dc779aSAndroid Build Coastguard Worker   FLOAT32 max;
68*15dc779aSAndroid Build Coastguard Worker   WORD32 i, idx;
69*15dc779aSAndroid Build Coastguard Worker 
70*15dc779aSAndroid Build Coastguard Worker   max = 0;
71*15dc779aSAndroid Build Coastguard Worker   idx = 0;
72*15dc779aSAndroid Build Coastguard Worker 
73*15dc779aSAndroid Build Coastguard Worker   for (i = 0; i < MAX_SHORT_WINDOWS; i++) {
74*15dc779aSAndroid Build Coastguard Worker     if (ptr_in[i + 1] > max) {
75*15dc779aSAndroid Build Coastguard Worker       max = ptr_in[i + 1];
76*15dc779aSAndroid Build Coastguard Worker       idx = i;
77*15dc779aSAndroid Build Coastguard Worker     }
78*15dc779aSAndroid Build Coastguard Worker   }
79*15dc779aSAndroid Build Coastguard Worker   *index = idx;
80*15dc779aSAndroid Build Coastguard Worker 
81*15dc779aSAndroid Build Coastguard Worker   return max;
82*15dc779aSAndroid Build Coastguard Worker }
83*15dc779aSAndroid Build Coastguard Worker 
iusace_blk_switch_iir_filt(const FLOAT32 * ptr_in,const FLOAT32 * ptr_iir_coeff,const WORD32 w,FLOAT32 * ptr_iir_states,FLOAT32 * energy_accu,WORD32 block_len)84*15dc779aSAndroid Build Coastguard Worker static VOID iusace_blk_switch_iir_filt(const FLOAT32 *ptr_in, const FLOAT32 *ptr_iir_coeff,
85*15dc779aSAndroid Build Coastguard Worker                                        const WORD32 w, FLOAT32 *ptr_iir_states,
86*15dc779aSAndroid Build Coastguard Worker                                        FLOAT32 *energy_accu, WORD32 block_len) {
87*15dc779aSAndroid Build Coastguard Worker   FLOAT32 accu1;
88*15dc779aSAndroid Build Coastguard Worker 
89*15dc779aSAndroid Build Coastguard Worker   WORD32 i;
90*15dc779aSAndroid Build Coastguard Worker 
91*15dc779aSAndroid Build Coastguard Worker   FLOAT32 accu_unfilt = 0.0f;
92*15dc779aSAndroid Build Coastguard Worker   FLOAT32 accu_filt = 0.0f;
93*15dc779aSAndroid Build Coastguard Worker   FLOAT32 accu2, temp2, temp1;
94*15dc779aSAndroid Build Coastguard Worker 
95*15dc779aSAndroid Build Coastguard Worker   FLOAT32 state0 = ptr_iir_states[0];
96*15dc779aSAndroid Build Coastguard Worker   FLOAT32 state1 = ptr_iir_states[1];
97*15dc779aSAndroid Build Coastguard Worker 
98*15dc779aSAndroid Build Coastguard Worker   FLOAT32 coeff0 = ptr_iir_coeff[0];
99*15dc779aSAndroid Build Coastguard Worker   FLOAT32 coeff1 = ptr_iir_coeff[1];
100*15dc779aSAndroid Build Coastguard Worker 
101*15dc779aSAndroid Build Coastguard Worker   const FLOAT32 *p_time_signal = &ptr_in[(block_len * w)];
102*15dc779aSAndroid Build Coastguard Worker 
103*15dc779aSAndroid Build Coastguard Worker   for (i = 0; i < block_len; i++) {
104*15dc779aSAndroid Build Coastguard Worker     accu2 = iusace_fmult(state0, coeff1);
105*15dc779aSAndroid Build Coastguard Worker     accu1 = iusace_fmult(state1, coeff0);
106*15dc779aSAndroid Build Coastguard Worker     accu1 += accu2;
107*15dc779aSAndroid Build Coastguard Worker 
108*15dc779aSAndroid Build Coastguard Worker     state0 = p_time_signal[i];
109*15dc779aSAndroid Build Coastguard Worker     state1 = iusace_fmult(state0, coeff1);
110*15dc779aSAndroid Build Coastguard Worker     state1 = (state1 - accu1);
111*15dc779aSAndroid Build Coastguard Worker 
112*15dc779aSAndroid Build Coastguard Worker     temp1 = iusace_fmult(state0, state0);
113*15dc779aSAndroid Build Coastguard Worker     temp2 = iusace_fmult(state1, state1);
114*15dc779aSAndroid Build Coastguard Worker 
115*15dc779aSAndroid Build Coastguard Worker     accu_unfilt = iusace_fadd(accu_unfilt, temp1);
116*15dc779aSAndroid Build Coastguard Worker     accu_filt = iusace_fadd(accu_filt, temp2);
117*15dc779aSAndroid Build Coastguard Worker   }
118*15dc779aSAndroid Build Coastguard Worker 
119*15dc779aSAndroid Build Coastguard Worker   energy_accu[0] = accu_unfilt;
120*15dc779aSAndroid Build Coastguard Worker   energy_accu[1] = accu_filt;
121*15dc779aSAndroid Build Coastguard Worker 
122*15dc779aSAndroid Build Coastguard Worker   ptr_iir_states[0] = state0;
123*15dc779aSAndroid Build Coastguard Worker   ptr_iir_states[1] = state1;
124*15dc779aSAndroid Build Coastguard Worker 
125*15dc779aSAndroid Build Coastguard Worker   return;
126*15dc779aSAndroid Build Coastguard Worker }
127*15dc779aSAndroid Build Coastguard Worker 
iusace_calc_window_energy(ia_block_switch_ctrl * ptr_blk_switch_ctrl,const FLOAT32 * ptr_in,FLOAT32 * max,WORD32 ccfl)128*15dc779aSAndroid Build Coastguard Worker static VOID iusace_calc_window_energy(ia_block_switch_ctrl *ptr_blk_switch_ctrl,
129*15dc779aSAndroid Build Coastguard Worker                                       const FLOAT32 *ptr_in, FLOAT32 *max, WORD32 ccfl) {
130*15dc779aSAndroid Build Coastguard Worker   WORD32 w;
131*15dc779aSAndroid Build Coastguard Worker 
132*15dc779aSAndroid Build Coastguard Worker   FLOAT32 energy_accu[2];
133*15dc779aSAndroid Build Coastguard Worker   *max = 0.0f;
134*15dc779aSAndroid Build Coastguard Worker 
135*15dc779aSAndroid Build Coastguard Worker   for (w = 0; w < MAX_SHORT_WINDOWS; w++) {
136*15dc779aSAndroid Build Coastguard Worker     // block length for calculating energy is corecoder frame length / MAX_SHORT_WINDOWS
137*15dc779aSAndroid Build Coastguard Worker     iusace_blk_switch_iir_filt(ptr_in, iusace_iir_hipass_coeffs, w,
138*15dc779aSAndroid Build Coastguard Worker                                ptr_blk_switch_ctrl->iir_states, &energy_accu[0], ccfl >> 3);
139*15dc779aSAndroid Build Coastguard Worker 
140*15dc779aSAndroid Build Coastguard Worker     ptr_blk_switch_ctrl->win_energy[1][w] = energy_accu[0];
141*15dc779aSAndroid Build Coastguard Worker     ptr_blk_switch_ctrl->win_energy_filt[1][w] = energy_accu[1];
142*15dc779aSAndroid Build Coastguard Worker 
143*15dc779aSAndroid Build Coastguard Worker     if (ptr_blk_switch_ctrl->win_energy_filt[1][w] > *max)
144*15dc779aSAndroid Build Coastguard Worker       *max = ptr_blk_switch_ctrl->win_energy_filt[1][w];
145*15dc779aSAndroid Build Coastguard Worker   }
146*15dc779aSAndroid Build Coastguard Worker   return;
147*15dc779aSAndroid Build Coastguard Worker }
148*15dc779aSAndroid Build Coastguard Worker 
iusace_block_switching(ia_block_switch_ctrl * ptr_blk_switch_ctrl,const FLOAT32 * ptr_in,WORD32 ccfl)149*15dc779aSAndroid Build Coastguard Worker VOID iusace_block_switching(ia_block_switch_ctrl *ptr_blk_switch_ctrl, const FLOAT32 *ptr_in,
150*15dc779aSAndroid Build Coastguard Worker                             WORD32 ccfl) {
151*15dc779aSAndroid Build Coastguard Worker   WORD32 i;
152*15dc779aSAndroid Build Coastguard Worker 
153*15dc779aSAndroid Build Coastguard Worker   FLOAT32 temp1, temp2;
154*15dc779aSAndroid Build Coastguard Worker   FLOAT32 max;
155*15dc779aSAndroid Build Coastguard Worker   FLOAT32 energy, energy_max;
156*15dc779aSAndroid Build Coastguard Worker 
157*15dc779aSAndroid Build Coastguard Worker   for (i = 0; i < MAX_SHORT_WINDOWS; i++) {
158*15dc779aSAndroid Build Coastguard Worker     ptr_blk_switch_ctrl->group_len[i] = 0;
159*15dc779aSAndroid Build Coastguard Worker   }
160*15dc779aSAndroid Build Coastguard Worker 
161*15dc779aSAndroid Build Coastguard Worker   ptr_blk_switch_ctrl->max_win_energy =
162*15dc779aSAndroid Build Coastguard Worker       iusace_srch_max_with_idx(&ptr_blk_switch_ctrl->win_energy[0][MAX_SHORT_WINDOWS - 1],
163*15dc779aSAndroid Build Coastguard Worker                                &ptr_blk_switch_ctrl->attack_idx);
164*15dc779aSAndroid Build Coastguard Worker 
165*15dc779aSAndroid Build Coastguard Worker   ptr_blk_switch_ctrl->attack_idx = ptr_blk_switch_ctrl->last_attack_idx;
166*15dc779aSAndroid Build Coastguard Worker   ptr_blk_switch_ctrl->tot_grps_cnt = MAXIMUM_NO_OF_GROUPS;
167*15dc779aSAndroid Build Coastguard Worker 
168*15dc779aSAndroid Build Coastguard Worker   for (i = 0; i < MAXIMUM_NO_OF_GROUPS; i++) {
169*15dc779aSAndroid Build Coastguard Worker     ptr_blk_switch_ctrl->group_len[i] =
170*15dc779aSAndroid Build Coastguard Worker         iusace_suggested_grouping_table[ptr_blk_switch_ctrl->attack_idx][i];
171*15dc779aSAndroid Build Coastguard Worker   }
172*15dc779aSAndroid Build Coastguard Worker 
173*15dc779aSAndroid Build Coastguard Worker   for (i = 0; i < MAX_SHORT_WINDOWS; i++) {
174*15dc779aSAndroid Build Coastguard Worker     ptr_blk_switch_ctrl->win_energy[0][i] = ptr_blk_switch_ctrl->win_energy[1][i];
175*15dc779aSAndroid Build Coastguard Worker     ptr_blk_switch_ctrl->win_energy_filt[0][i] = ptr_blk_switch_ctrl->win_energy_filt[1][i];
176*15dc779aSAndroid Build Coastguard Worker   }
177*15dc779aSAndroid Build Coastguard Worker 
178*15dc779aSAndroid Build Coastguard Worker   iusace_calc_window_energy(ptr_blk_switch_ctrl, ptr_in, &max, ccfl);
179*15dc779aSAndroid Build Coastguard Worker 
180*15dc779aSAndroid Build Coastguard Worker   ptr_blk_switch_ctrl->attack = FALSE;
181*15dc779aSAndroid Build Coastguard Worker 
182*15dc779aSAndroid Build Coastguard Worker   energy_max = 0.0f;
183*15dc779aSAndroid Build Coastguard Worker 
184*15dc779aSAndroid Build Coastguard Worker   energy = ptr_blk_switch_ctrl->win_energy_filt[0][MAX_SHORT_WINDOWS - 1];
185*15dc779aSAndroid Build Coastguard Worker 
186*15dc779aSAndroid Build Coastguard Worker   for (i = 0; i < MAX_SHORT_WINDOWS; i++) {
187*15dc779aSAndroid Build Coastguard Worker     temp1 = iusace_fmult(ONE_MINUS_ACC_WINDOW_NRG_FAC, ptr_blk_switch_ctrl->acc_win_energy);
188*15dc779aSAndroid Build Coastguard Worker     temp2 = iusace_fmult(ACC_WINDOW_NRG_FAC, energy);
189*15dc779aSAndroid Build Coastguard Worker     ptr_blk_switch_ctrl->acc_win_energy = iusace_fadd(temp1, temp2);
190*15dc779aSAndroid Build Coastguard Worker 
191*15dc779aSAndroid Build Coastguard Worker     temp1 = iusace_fmult(ptr_blk_switch_ctrl->win_energy_filt[1][i],
192*15dc779aSAndroid Build Coastguard Worker                          ptr_blk_switch_ctrl->inv_attack_ratio);
193*15dc779aSAndroid Build Coastguard Worker     if (temp1 > ptr_blk_switch_ctrl->acc_win_energy) {
194*15dc779aSAndroid Build Coastguard Worker       ptr_blk_switch_ctrl->attack = TRUE;
195*15dc779aSAndroid Build Coastguard Worker       ptr_blk_switch_ctrl->last_attack_idx = i;
196*15dc779aSAndroid Build Coastguard Worker     }
197*15dc779aSAndroid Build Coastguard Worker 
198*15dc779aSAndroid Build Coastguard Worker     energy = ptr_blk_switch_ctrl->win_energy_filt[1][i];
199*15dc779aSAndroid Build Coastguard Worker     if (energy_max < energy) energy_max = energy;
200*15dc779aSAndroid Build Coastguard Worker   }
201*15dc779aSAndroid Build Coastguard Worker 
202*15dc779aSAndroid Build Coastguard Worker   if (ccfl == LEN_SUPERFRAME_768) {
203*15dc779aSAndroid Build Coastguard Worker     energy_max = (energy_max * 4) / 3.0f;
204*15dc779aSAndroid Build Coastguard Worker   }
205*15dc779aSAndroid Build Coastguard Worker   if (energy_max < USAC_MIN_ATTACK_NRG) {
206*15dc779aSAndroid Build Coastguard Worker     ptr_blk_switch_ctrl->attack = FALSE;
207*15dc779aSAndroid Build Coastguard Worker   }
208*15dc779aSAndroid Build Coastguard Worker 
209*15dc779aSAndroid Build Coastguard Worker   if ((!ptr_blk_switch_ctrl->attack) && (ptr_blk_switch_ctrl->lastattack)) {
210*15dc779aSAndroid Build Coastguard Worker     if (ptr_blk_switch_ctrl->attack_idx == MAX_SHORT_WINDOWS - 1) {
211*15dc779aSAndroid Build Coastguard Worker       ptr_blk_switch_ctrl->attack = TRUE;
212*15dc779aSAndroid Build Coastguard Worker     }
213*15dc779aSAndroid Build Coastguard Worker     ptr_blk_switch_ctrl->lastattack = FALSE;
214*15dc779aSAndroid Build Coastguard Worker   } else {
215*15dc779aSAndroid Build Coastguard Worker     ptr_blk_switch_ctrl->lastattack = ptr_blk_switch_ctrl->attack;
216*15dc779aSAndroid Build Coastguard Worker   }
217*15dc779aSAndroid Build Coastguard Worker   ptr_blk_switch_ctrl->window_seq = ptr_blk_switch_ctrl->next_win_seq;
218*15dc779aSAndroid Build Coastguard Worker 
219*15dc779aSAndroid Build Coastguard Worker   if (ptr_blk_switch_ctrl->attack) {
220*15dc779aSAndroid Build Coastguard Worker     ptr_blk_switch_ctrl->next_win_seq = EIGHT_SHORT_SEQUENCE;
221*15dc779aSAndroid Build Coastguard Worker   } else {
222*15dc779aSAndroid Build Coastguard Worker     ptr_blk_switch_ctrl->next_win_seq = ONLY_LONG_SEQUENCE;
223*15dc779aSAndroid Build Coastguard Worker   }
224*15dc779aSAndroid Build Coastguard Worker   if (ptr_blk_switch_ctrl->next_win_seq == EIGHT_SHORT_SEQUENCE) {
225*15dc779aSAndroid Build Coastguard Worker     if (ptr_blk_switch_ctrl->window_seq == ONLY_LONG_SEQUENCE) {
226*15dc779aSAndroid Build Coastguard Worker       ptr_blk_switch_ctrl->window_seq = LONG_START_SEQUENCE;
227*15dc779aSAndroid Build Coastguard Worker     }
228*15dc779aSAndroid Build Coastguard Worker 
229*15dc779aSAndroid Build Coastguard Worker     if (ptr_blk_switch_ctrl->window_seq == LONG_STOP_SEQUENCE) {
230*15dc779aSAndroid Build Coastguard Worker       ptr_blk_switch_ctrl->window_seq = EIGHT_SHORT_SEQUENCE;
231*15dc779aSAndroid Build Coastguard Worker       ptr_blk_switch_ctrl->tot_grps_cnt = 3;
232*15dc779aSAndroid Build Coastguard Worker       ptr_blk_switch_ctrl->group_len[0] = 3;
233*15dc779aSAndroid Build Coastguard Worker       ptr_blk_switch_ctrl->group_len[1] = 3;
234*15dc779aSAndroid Build Coastguard Worker       ptr_blk_switch_ctrl->group_len[2] = 2;
235*15dc779aSAndroid Build Coastguard Worker     }
236*15dc779aSAndroid Build Coastguard Worker   }
237*15dc779aSAndroid Build Coastguard Worker 
238*15dc779aSAndroid Build Coastguard Worker   if (ptr_blk_switch_ctrl->next_win_seq == ONLY_LONG_SEQUENCE) {
239*15dc779aSAndroid Build Coastguard Worker     if (ptr_blk_switch_ctrl->window_seq == EIGHT_SHORT_SEQUENCE) {
240*15dc779aSAndroid Build Coastguard Worker       ptr_blk_switch_ctrl->next_win_seq = LONG_STOP_SEQUENCE;
241*15dc779aSAndroid Build Coastguard Worker     }
242*15dc779aSAndroid Build Coastguard Worker   }
243*15dc779aSAndroid Build Coastguard Worker   return;
244*15dc779aSAndroid Build Coastguard Worker }
245*15dc779aSAndroid Build Coastguard Worker 
iusace_sync_block_switching(ia_block_switch_ctrl * ptr_blk_switch_left_ctrl,ia_block_switch_ctrl * ptr_blk_switch_right_ctrl)246*15dc779aSAndroid Build Coastguard Worker VOID iusace_sync_block_switching(ia_block_switch_ctrl *ptr_blk_switch_left_ctrl,
247*15dc779aSAndroid Build Coastguard Worker                                  ia_block_switch_ctrl *ptr_blk_switch_right_ctrl) {
248*15dc779aSAndroid Build Coastguard Worker   WORD32 i;
249*15dc779aSAndroid Build Coastguard Worker   WORD32 patch_type = ONLY_LONG_SEQUENCE;
250*15dc779aSAndroid Build Coastguard Worker 
251*15dc779aSAndroid Build Coastguard Worker   patch_type = iusace_synchronized_block_types[patch_type][ptr_blk_switch_left_ctrl->window_seq];
252*15dc779aSAndroid Build Coastguard Worker   patch_type = iusace_synchronized_block_types[patch_type][ptr_blk_switch_right_ctrl->window_seq];
253*15dc779aSAndroid Build Coastguard Worker 
254*15dc779aSAndroid Build Coastguard Worker   ptr_blk_switch_left_ctrl->window_seq = patch_type;
255*15dc779aSAndroid Build Coastguard Worker   ptr_blk_switch_right_ctrl->window_seq = patch_type;
256*15dc779aSAndroid Build Coastguard Worker 
257*15dc779aSAndroid Build Coastguard Worker   if (patch_type != EIGHT_SHORT_SEQUENCE) { /* tns_data_long Blocks */
258*15dc779aSAndroid Build Coastguard Worker     ptr_blk_switch_left_ctrl->tot_grps_cnt = 1;
259*15dc779aSAndroid Build Coastguard Worker     ptr_blk_switch_right_ctrl->tot_grps_cnt = 1;
260*15dc779aSAndroid Build Coastguard Worker     ptr_blk_switch_left_ctrl->group_len[0] = 1;
261*15dc779aSAndroid Build Coastguard Worker     ptr_blk_switch_right_ctrl->group_len[0] = 1;
262*15dc779aSAndroid Build Coastguard Worker 
263*15dc779aSAndroid Build Coastguard Worker     for (i = 1; i < MAX_SHORT_WINDOWS; i++) {
264*15dc779aSAndroid Build Coastguard Worker       ptr_blk_switch_left_ctrl->group_len[i] = 0;
265*15dc779aSAndroid Build Coastguard Worker       ptr_blk_switch_right_ctrl->group_len[i] = 0;
266*15dc779aSAndroid Build Coastguard Worker     }
267*15dc779aSAndroid Build Coastguard Worker   } else { /* tns_data_short Blocks */
268*15dc779aSAndroid Build Coastguard Worker     if (ptr_blk_switch_left_ctrl->max_win_energy > ptr_blk_switch_right_ctrl->max_win_energy) {
269*15dc779aSAndroid Build Coastguard Worker       ptr_blk_switch_right_ctrl->tot_grps_cnt = ptr_blk_switch_left_ctrl->tot_grps_cnt;
270*15dc779aSAndroid Build Coastguard Worker       for (i = 0; i < ptr_blk_switch_right_ctrl->tot_grps_cnt; i++) {
271*15dc779aSAndroid Build Coastguard Worker         ptr_blk_switch_right_ctrl->group_len[i] = ptr_blk_switch_left_ctrl->group_len[i];
272*15dc779aSAndroid Build Coastguard Worker       }
273*15dc779aSAndroid Build Coastguard Worker     } else {
274*15dc779aSAndroid Build Coastguard Worker       ptr_blk_switch_left_ctrl->tot_grps_cnt = ptr_blk_switch_right_ctrl->tot_grps_cnt;
275*15dc779aSAndroid Build Coastguard Worker       for (i = 0; i < ptr_blk_switch_left_ctrl->tot_grps_cnt; i++) {
276*15dc779aSAndroid Build Coastguard Worker         ptr_blk_switch_left_ctrl->group_len[i] = ptr_blk_switch_right_ctrl->group_len[i];
277*15dc779aSAndroid Build Coastguard Worker       }
278*15dc779aSAndroid Build Coastguard Worker     }
279*15dc779aSAndroid Build Coastguard Worker   }
280*15dc779aSAndroid Build Coastguard Worker 
281*15dc779aSAndroid Build Coastguard Worker   return;
282*15dc779aSAndroid Build Coastguard Worker }
283