xref: /aosp_15_r20/external/libxaac/encoder/ixheaace_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 "ixheaac_type_def.h"
22*15dc779aSAndroid Build Coastguard Worker #include "ixheaac_constants.h"
23*15dc779aSAndroid Build Coastguard Worker #include "ixheaace_aac_constants.h"
24*15dc779aSAndroid Build Coastguard Worker #include "ixheaace_psy_const.h"
25*15dc779aSAndroid Build Coastguard Worker #include "ixheaace_tns.h"
26*15dc779aSAndroid Build Coastguard Worker #include "ixheaace_tns_params.h"
27*15dc779aSAndroid Build Coastguard Worker #include "ixheaace_rom.h"
28*15dc779aSAndroid Build Coastguard Worker #include "ixheaace_common_rom.h"
29*15dc779aSAndroid Build Coastguard Worker #include "ixheaace_bitbuffer.h"
30*15dc779aSAndroid Build Coastguard Worker #include "ixheaac_basic_ops32.h"
31*15dc779aSAndroid Build Coastguard Worker #include "ixheaac_basic_ops40.h"
32*15dc779aSAndroid Build Coastguard Worker #include "ixheaac_basic_ops.h"
33*15dc779aSAndroid Build Coastguard Worker #include "ixheaace_block_switch.h"
34*15dc779aSAndroid Build Coastguard Worker #include "iusace_block_switch_struct_def.h"
35*15dc779aSAndroid Build Coastguard Worker #include <string.h>
36*15dc779aSAndroid Build Coastguard Worker 
iaace_fmult(FLOAT32 a,FLOAT32 b)37*15dc779aSAndroid Build Coastguard Worker static FLOAT32 iaace_fmult(FLOAT32 a, FLOAT32 b) { return (a * b); }
38*15dc779aSAndroid Build Coastguard Worker 
iaace_fadd(FLOAT32 a,FLOAT32 b)39*15dc779aSAndroid Build Coastguard Worker static FLOAT32 iaace_fadd(FLOAT32 a, FLOAT32 b) { return (a + b); }
40*15dc779aSAndroid Build Coastguard Worker 
iaace_init_block_switching(ixheaace_block_switch_control * pstr_blk_switch_ctrl,const WORD32 bit_rate,const WORD32 num_chans)41*15dc779aSAndroid Build Coastguard Worker VOID iaace_init_block_switching(ixheaace_block_switch_control *pstr_blk_switch_ctrl,
42*15dc779aSAndroid Build Coastguard Worker                                 const WORD32 bit_rate, const WORD32 num_chans) {
43*15dc779aSAndroid Build Coastguard Worker   if ((num_chans == 1 && bit_rate > BLK_SWITCH_HIGH_BR_MONO) ||
44*15dc779aSAndroid Build Coastguard Worker       (num_chans > 1 && bit_rate / num_chans > BLK_SWITCH_HIGH_BR_STEREO)) {
45*15dc779aSAndroid Build Coastguard Worker     pstr_blk_switch_ctrl->inv_attack_ratio = INV_ATTACK_RATIO_HIGH_BR;
46*15dc779aSAndroid Build Coastguard Worker   } else {
47*15dc779aSAndroid Build Coastguard Worker     pstr_blk_switch_ctrl->inv_attack_ratio = INV_ATTACK_RATIO_LOW_BR;
48*15dc779aSAndroid Build Coastguard Worker   }
49*15dc779aSAndroid Build Coastguard Worker 
50*15dc779aSAndroid Build Coastguard Worker   memset(pstr_blk_switch_ctrl->iir_states, 0,
51*15dc779aSAndroid Build Coastguard Worker          BLK_SWITCH_FILT_LEN * sizeof(pstr_blk_switch_ctrl->iir_states[0]));
52*15dc779aSAndroid Build Coastguard Worker   /* Clear Filtered Window Energies */
53*15dc779aSAndroid Build Coastguard Worker 
54*15dc779aSAndroid Build Coastguard Worker   memset(pstr_blk_switch_ctrl->win_energy_filt, 0,
55*15dc779aSAndroid Build Coastguard Worker          BLK_SWITCH_WIN * sizeof(pstr_blk_switch_ctrl->win_energy_filt[0][0]));
56*15dc779aSAndroid Build Coastguard Worker   memset(pstr_blk_switch_ctrl->win_energy, 0,
57*15dc779aSAndroid Build Coastguard Worker          BLK_SWITCH_WIN * sizeof(pstr_blk_switch_ctrl->win_energy[0][0]));
58*15dc779aSAndroid Build Coastguard Worker 
59*15dc779aSAndroid Build Coastguard Worker   pstr_blk_switch_ctrl->acc_win_energy = 0;
60*15dc779aSAndroid Build Coastguard Worker 
61*15dc779aSAndroid Build Coastguard Worker   pstr_blk_switch_ctrl->win_seq = LONG_WINDOW;
62*15dc779aSAndroid Build Coastguard Worker   pstr_blk_switch_ctrl->nxt_win_seq = LONG_WINDOW;
63*15dc779aSAndroid Build Coastguard Worker 
64*15dc779aSAndroid Build Coastguard Worker   pstr_blk_switch_ctrl->attack = 0;
65*15dc779aSAndroid Build Coastguard Worker   pstr_blk_switch_ctrl->lastattack = 0;
66*15dc779aSAndroid Build Coastguard Worker   pstr_blk_switch_ctrl->attack_idx = 0;
67*15dc779aSAndroid Build Coastguard Worker   pstr_blk_switch_ctrl->last_attack_idx = 0;
68*15dc779aSAndroid Build Coastguard Worker }
69*15dc779aSAndroid Build Coastguard Worker 
iaace_search_max_with_idx(const FLOAT32 * ptr_in,WORD32 * ptr_index,WORD32 len)70*15dc779aSAndroid Build Coastguard Worker static FLOAT32 iaace_search_max_with_idx(const FLOAT32 *ptr_in, WORD32 *ptr_index, WORD32 len) {
71*15dc779aSAndroid Build Coastguard Worker   FLOAT32 max = 0;
72*15dc779aSAndroid Build Coastguard Worker   WORD32 i = 0, idx = 0;
73*15dc779aSAndroid Build Coastguard Worker 
74*15dc779aSAndroid Build Coastguard Worker   do {
75*15dc779aSAndroid Build Coastguard Worker     if (ptr_in[i + 1] > max) {
76*15dc779aSAndroid Build Coastguard Worker       max = ptr_in[i + 1];
77*15dc779aSAndroid Build Coastguard Worker       idx = i;
78*15dc779aSAndroid Build Coastguard Worker     }
79*15dc779aSAndroid Build Coastguard Worker     i++;
80*15dc779aSAndroid Build Coastguard Worker   } while (i < len);
81*15dc779aSAndroid Build Coastguard Worker 
82*15dc779aSAndroid Build Coastguard Worker   *ptr_index = idx;
83*15dc779aSAndroid Build Coastguard Worker 
84*15dc779aSAndroid Build Coastguard Worker   return max;
85*15dc779aSAndroid Build Coastguard Worker }
86*15dc779aSAndroid Build Coastguard Worker 
iaace_blk_switch_iir_filt(const FLOAT32 input,const FLOAT32 * ptr_iir_coeff,FLOAT32 * ptr_iir_states)87*15dc779aSAndroid Build Coastguard Worker static FLOAT32 iaace_blk_switch_iir_filt(const FLOAT32 input, const FLOAT32 *ptr_iir_coeff,
88*15dc779aSAndroid Build Coastguard Worker                                          FLOAT32 *ptr_iir_states) {
89*15dc779aSAndroid Build Coastguard Worker   FLOAT32 accu_1, accu_2;
90*15dc779aSAndroid Build Coastguard Worker   FLOAT32 out;
91*15dc779aSAndroid Build Coastguard Worker 
92*15dc779aSAndroid Build Coastguard Worker   accu_1 = ptr_iir_coeff[1] * (input - ptr_iir_states[0]);
93*15dc779aSAndroid Build Coastguard Worker 
94*15dc779aSAndroid Build Coastguard Worker   accu_2 = ptr_iir_coeff[0] * ptr_iir_states[1];
95*15dc779aSAndroid Build Coastguard Worker 
96*15dc779aSAndroid Build Coastguard Worker   out = accu_1 - accu_2;
97*15dc779aSAndroid Build Coastguard Worker   ptr_iir_states[0] = input;
98*15dc779aSAndroid Build Coastguard Worker   ptr_iir_states[1] = out;
99*15dc779aSAndroid Build Coastguard Worker 
100*15dc779aSAndroid Build Coastguard Worker   return out;
101*15dc779aSAndroid Build Coastguard Worker }
102*15dc779aSAndroid Build Coastguard Worker 
iaace_calc_window_energy(ixheaace_block_switch_control * pstr_blk_switch_ctrl,const FLOAT32 * ptr_time_signal,WORD32 ch_increment,WORD32 win_len)103*15dc779aSAndroid Build Coastguard Worker static VOID iaace_calc_window_energy(ixheaace_block_switch_control *pstr_blk_switch_ctrl,
104*15dc779aSAndroid Build Coastguard Worker                                      const FLOAT32 *ptr_time_signal, WORD32 ch_increment,
105*15dc779aSAndroid Build Coastguard Worker                                      WORD32 win_len) {
106*15dc779aSAndroid Build Coastguard Worker   WORD32 i, w;
107*15dc779aSAndroid Build Coastguard Worker   FLOAT32 acc_nrg_unfilt, acc_nrg_filt;
108*15dc779aSAndroid Build Coastguard Worker   FLOAT32 tmp_nrg_unfilt, tmp_nrg_filt;
109*15dc779aSAndroid Build Coastguard Worker   for (w = 0; w < BLK_SWITCH_WIN; w++) {
110*15dc779aSAndroid Build Coastguard Worker     acc_nrg_unfilt = 0.0f;
111*15dc779aSAndroid Build Coastguard Worker     acc_nrg_filt = 0.0f;
112*15dc779aSAndroid Build Coastguard Worker 
113*15dc779aSAndroid Build Coastguard Worker     for (i = 0; i < win_len; i++) {
114*15dc779aSAndroid Build Coastguard Worker       tmp_nrg_unfilt = ptr_time_signal[(win_len * w + i) * ch_increment];
115*15dc779aSAndroid Build Coastguard Worker       tmp_nrg_filt = iaace_blk_switch_iir_filt(tmp_nrg_unfilt, iaace_iir_hipass_coeffs,
116*15dc779aSAndroid Build Coastguard Worker                                                pstr_blk_switch_ctrl->iir_states);
117*15dc779aSAndroid Build Coastguard Worker 
118*15dc779aSAndroid Build Coastguard Worker       acc_nrg_unfilt += (tmp_nrg_unfilt * tmp_nrg_unfilt);
119*15dc779aSAndroid Build Coastguard Worker       acc_nrg_filt += (tmp_nrg_filt * tmp_nrg_filt);
120*15dc779aSAndroid Build Coastguard Worker     }
121*15dc779aSAndroid Build Coastguard Worker 
122*15dc779aSAndroid Build Coastguard Worker     pstr_blk_switch_ctrl->win_energy[1][w] = acc_nrg_unfilt;
123*15dc779aSAndroid Build Coastguard Worker     pstr_blk_switch_ctrl->win_energy_filt[1][w] = acc_nrg_filt;
124*15dc779aSAndroid Build Coastguard Worker   }
125*15dc779aSAndroid Build Coastguard Worker }
126*15dc779aSAndroid Build Coastguard Worker 
iaace_block_switching(ixheaace_block_switch_control * pstr_blk_switch_ctrl,const FLOAT32 * ptr_time_signal,WORD32 frame_length,WORD32 num_chans)127*15dc779aSAndroid Build Coastguard Worker VOID iaace_block_switching(ixheaace_block_switch_control *pstr_blk_switch_ctrl,
128*15dc779aSAndroid Build Coastguard Worker                            const FLOAT32 *ptr_time_signal, WORD32 frame_length,
129*15dc779aSAndroid Build Coastguard Worker                            WORD32 num_chans) {
130*15dc779aSAndroid Build Coastguard Worker   WORD32 win_idx;
131*15dc779aSAndroid Build Coastguard Worker   FLOAT32 tmp_nrg_1, tmp_nrg_2;
132*15dc779aSAndroid Build Coastguard Worker   FLOAT32 prev_win_nrg, max_nrg;
133*15dc779aSAndroid Build Coastguard Worker 
134*15dc779aSAndroid Build Coastguard Worker   memset(pstr_blk_switch_ctrl->group_len, 0,
135*15dc779aSAndroid Build Coastguard Worker          TRANS_FAC * sizeof(pstr_blk_switch_ctrl->group_len[0]));
136*15dc779aSAndroid Build Coastguard Worker 
137*15dc779aSAndroid Build Coastguard Worker   pstr_blk_switch_ctrl->max_win_energy =
138*15dc779aSAndroid Build Coastguard Worker       iaace_search_max_with_idx(&pstr_blk_switch_ctrl->win_energy[0][BLK_SWITCH_WIN - 1],
139*15dc779aSAndroid Build Coastguard Worker                                 &pstr_blk_switch_ctrl->attack_idx, BLK_SWITCH_WIN);
140*15dc779aSAndroid Build Coastguard Worker 
141*15dc779aSAndroid Build Coastguard Worker   pstr_blk_switch_ctrl->attack_idx = pstr_blk_switch_ctrl->last_attack_idx;
142*15dc779aSAndroid Build Coastguard Worker   pstr_blk_switch_ctrl->total_groups_cnt = MAXIMUM_NO_OF_GROUPS;
143*15dc779aSAndroid Build Coastguard Worker 
144*15dc779aSAndroid Build Coastguard Worker   memcpy(pstr_blk_switch_ctrl->group_len,
145*15dc779aSAndroid Build Coastguard Worker          iaace_suggested_grouping_table[pstr_blk_switch_ctrl->attack_idx],
146*15dc779aSAndroid Build Coastguard Worker          MAXIMUM_NO_OF_GROUPS * sizeof(pstr_blk_switch_ctrl->group_len[0]));
147*15dc779aSAndroid Build Coastguard Worker 
148*15dc779aSAndroid Build Coastguard Worker   memcpy(pstr_blk_switch_ctrl->win_energy[0], pstr_blk_switch_ctrl->win_energy[1],
149*15dc779aSAndroid Build Coastguard Worker          BLK_SWITCH_WIN * sizeof(pstr_blk_switch_ctrl->win_energy[0][0]));
150*15dc779aSAndroid Build Coastguard Worker   memcpy(pstr_blk_switch_ctrl->win_energy_filt[0], pstr_blk_switch_ctrl->win_energy_filt[1],
151*15dc779aSAndroid Build Coastguard Worker          BLK_SWITCH_WIN * sizeof(pstr_blk_switch_ctrl->win_energy_filt[0][0]));
152*15dc779aSAndroid Build Coastguard Worker 
153*15dc779aSAndroid Build Coastguard Worker   iaace_calc_window_energy(
154*15dc779aSAndroid Build Coastguard Worker       pstr_blk_switch_ctrl, ptr_time_signal, num_chans,
155*15dc779aSAndroid Build Coastguard Worker       (frame_length == FRAME_LEN_960 ? FRAME_LEN_SHORT_120 : FRAME_LEN_SHORT_128));
156*15dc779aSAndroid Build Coastguard Worker 
157*15dc779aSAndroid Build Coastguard Worker   pstr_blk_switch_ctrl->attack = FALSE;
158*15dc779aSAndroid Build Coastguard Worker 
159*15dc779aSAndroid Build Coastguard Worker   max_nrg = 0.0f;
160*15dc779aSAndroid Build Coastguard Worker 
161*15dc779aSAndroid Build Coastguard Worker   prev_win_nrg = pstr_blk_switch_ctrl->win_energy_filt[0][BLK_SWITCH_WIN - 1];
162*15dc779aSAndroid Build Coastguard Worker 
163*15dc779aSAndroid Build Coastguard Worker   for (win_idx = 0; win_idx < BLK_SWITCH_WIN; win_idx++) {
164*15dc779aSAndroid Build Coastguard Worker     tmp_nrg_1 = iaace_fmult(ONE_MINUS_ACC_WINDOW_NRG_FAC, pstr_blk_switch_ctrl->acc_win_energy);
165*15dc779aSAndroid Build Coastguard Worker     tmp_nrg_2 = iaace_fmult(ACC_WINDOW_NRG_FAC, prev_win_nrg);
166*15dc779aSAndroid Build Coastguard Worker     pstr_blk_switch_ctrl->acc_win_energy = iaace_fadd(tmp_nrg_1, tmp_nrg_2);
167*15dc779aSAndroid Build Coastguard Worker 
168*15dc779aSAndroid Build Coastguard Worker     tmp_nrg_1 = iaace_fmult(pstr_blk_switch_ctrl->win_energy_filt[1][win_idx],
169*15dc779aSAndroid Build Coastguard Worker                             pstr_blk_switch_ctrl->inv_attack_ratio);
170*15dc779aSAndroid Build Coastguard Worker     if (tmp_nrg_1 > pstr_blk_switch_ctrl->acc_win_energy) {
171*15dc779aSAndroid Build Coastguard Worker       pstr_blk_switch_ctrl->attack = TRUE;
172*15dc779aSAndroid Build Coastguard Worker       pstr_blk_switch_ctrl->last_attack_idx = win_idx;
173*15dc779aSAndroid Build Coastguard Worker     }
174*15dc779aSAndroid Build Coastguard Worker 
175*15dc779aSAndroid Build Coastguard Worker     prev_win_nrg = pstr_blk_switch_ctrl->win_energy_filt[1][win_idx];
176*15dc779aSAndroid Build Coastguard Worker 
177*15dc779aSAndroid Build Coastguard Worker     max_nrg = MAX(prev_win_nrg, max_nrg);
178*15dc779aSAndroid Build Coastguard Worker   }
179*15dc779aSAndroid Build Coastguard Worker 
180*15dc779aSAndroid Build Coastguard Worker   if (max_nrg < MIN_ATTACK_NRG) {
181*15dc779aSAndroid Build Coastguard Worker     pstr_blk_switch_ctrl->attack = FALSE;
182*15dc779aSAndroid Build Coastguard Worker   }
183*15dc779aSAndroid Build Coastguard Worker 
184*15dc779aSAndroid Build Coastguard Worker   if ((!pstr_blk_switch_ctrl->attack) && (pstr_blk_switch_ctrl->lastattack)) {
185*15dc779aSAndroid Build Coastguard Worker     if (pstr_blk_switch_ctrl->attack_idx == (TRANS_FAC - 1)) {
186*15dc779aSAndroid Build Coastguard Worker       pstr_blk_switch_ctrl->attack = TRUE;
187*15dc779aSAndroid Build Coastguard Worker     }
188*15dc779aSAndroid Build Coastguard Worker     pstr_blk_switch_ctrl->lastattack = FALSE;
189*15dc779aSAndroid Build Coastguard Worker   } else {
190*15dc779aSAndroid Build Coastguard Worker     pstr_blk_switch_ctrl->lastattack = pstr_blk_switch_ctrl->attack;
191*15dc779aSAndroid Build Coastguard Worker   }
192*15dc779aSAndroid Build Coastguard Worker   pstr_blk_switch_ctrl->win_seq = pstr_blk_switch_ctrl->nxt_win_seq;
193*15dc779aSAndroid Build Coastguard Worker 
194*15dc779aSAndroid Build Coastguard Worker   pstr_blk_switch_ctrl->nxt_win_seq =
195*15dc779aSAndroid Build Coastguard Worker       (pstr_blk_switch_ctrl->attack == 1) ? SHORT_WINDOW : LONG_WINDOW;
196*15dc779aSAndroid Build Coastguard Worker 
197*15dc779aSAndroid Build Coastguard Worker   if (pstr_blk_switch_ctrl->nxt_win_seq == SHORT_WINDOW) {
198*15dc779aSAndroid Build Coastguard Worker     if (pstr_blk_switch_ctrl->win_seq == LONG_WINDOW) {
199*15dc779aSAndroid Build Coastguard Worker       pstr_blk_switch_ctrl->win_seq = START_WINDOW;
200*15dc779aSAndroid Build Coastguard Worker     } else if (pstr_blk_switch_ctrl->win_seq == STOP_WINDOW) {
201*15dc779aSAndroid Build Coastguard Worker       pstr_blk_switch_ctrl->win_seq = SHORT_WINDOW;
202*15dc779aSAndroid Build Coastguard Worker       pstr_blk_switch_ctrl->total_groups_cnt = 3;
203*15dc779aSAndroid Build Coastguard Worker       pstr_blk_switch_ctrl->group_len[0] = 3;
204*15dc779aSAndroid Build Coastguard Worker       pstr_blk_switch_ctrl->group_len[1] = 3;
205*15dc779aSAndroid Build Coastguard Worker       pstr_blk_switch_ctrl->group_len[2] = 2;
206*15dc779aSAndroid Build Coastguard Worker     }
207*15dc779aSAndroid Build Coastguard Worker   }
208*15dc779aSAndroid Build Coastguard Worker 
209*15dc779aSAndroid Build Coastguard Worker   if (pstr_blk_switch_ctrl->nxt_win_seq == LONG_WINDOW &&
210*15dc779aSAndroid Build Coastguard Worker       pstr_blk_switch_ctrl->win_seq == SHORT_WINDOW) {
211*15dc779aSAndroid Build Coastguard Worker     pstr_blk_switch_ctrl->nxt_win_seq = STOP_WINDOW;
212*15dc779aSAndroid Build Coastguard Worker   }
213*15dc779aSAndroid Build Coastguard Worker }
214*15dc779aSAndroid Build Coastguard Worker 
iaace_sync_block_switching(ixheaace_block_switch_control * pstr_blk_switch_left_ctrl,ixheaace_block_switch_control * pstr_blk_switch_right_ctrl,const WORD32 num_channels)215*15dc779aSAndroid Build Coastguard Worker VOID iaace_sync_block_switching(ixheaace_block_switch_control *pstr_blk_switch_left_ctrl,
216*15dc779aSAndroid Build Coastguard Worker                                 ixheaace_block_switch_control *pstr_blk_switch_right_ctrl,
217*15dc779aSAndroid Build Coastguard Worker                                 const WORD32 num_channels) {
218*15dc779aSAndroid Build Coastguard Worker   WORD32 i;
219*15dc779aSAndroid Build Coastguard Worker   WORD32 patch_type = LONG_WINDOW;
220*15dc779aSAndroid Build Coastguard Worker 
221*15dc779aSAndroid Build Coastguard Worker   if (num_channels == 1) {
222*15dc779aSAndroid Build Coastguard Worker     if (pstr_blk_switch_left_ctrl->win_seq != SHORT_WINDOW) {
223*15dc779aSAndroid Build Coastguard Worker       pstr_blk_switch_left_ctrl->total_groups_cnt = 1;
224*15dc779aSAndroid Build Coastguard Worker       pstr_blk_switch_left_ctrl->group_len[0] = 1;
225*15dc779aSAndroid Build Coastguard Worker 
226*15dc779aSAndroid Build Coastguard Worker       for (i = 1; i < TRANS_FAC; i++) {
227*15dc779aSAndroid Build Coastguard Worker         pstr_blk_switch_left_ctrl->group_len[i] = 0;
228*15dc779aSAndroid Build Coastguard Worker       }
229*15dc779aSAndroid Build Coastguard Worker     }
230*15dc779aSAndroid Build Coastguard Worker   } else {
231*15dc779aSAndroid Build Coastguard Worker     /* Stereo */
232*15dc779aSAndroid Build Coastguard Worker 
233*15dc779aSAndroid Build Coastguard Worker     patch_type = iaace_synchronized_block_types[patch_type][pstr_blk_switch_left_ctrl->win_seq];
234*15dc779aSAndroid Build Coastguard Worker     patch_type = iaace_synchronized_block_types[patch_type][pstr_blk_switch_right_ctrl->win_seq];
235*15dc779aSAndroid Build Coastguard Worker 
236*15dc779aSAndroid Build Coastguard Worker     pstr_blk_switch_left_ctrl->win_seq = patch_type;
237*15dc779aSAndroid Build Coastguard Worker     pstr_blk_switch_right_ctrl->win_seq = patch_type;
238*15dc779aSAndroid Build Coastguard Worker 
239*15dc779aSAndroid Build Coastguard Worker     if (patch_type != SHORT_WINDOW) { /* tns_data_long Blocks */
240*15dc779aSAndroid Build Coastguard Worker       pstr_blk_switch_left_ctrl->total_groups_cnt = 1;
241*15dc779aSAndroid Build Coastguard Worker       pstr_blk_switch_right_ctrl->total_groups_cnt = 1;
242*15dc779aSAndroid Build Coastguard Worker       pstr_blk_switch_left_ctrl->group_len[0] = 1;
243*15dc779aSAndroid Build Coastguard Worker       pstr_blk_switch_right_ctrl->group_len[0] = 1;
244*15dc779aSAndroid Build Coastguard Worker 
245*15dc779aSAndroid Build Coastguard Worker       for (i = 1; i < TRANS_FAC; i++) {
246*15dc779aSAndroid Build Coastguard Worker         pstr_blk_switch_left_ctrl->group_len[i] = 0;
247*15dc779aSAndroid Build Coastguard Worker         pstr_blk_switch_right_ctrl->group_len[i] = 0;
248*15dc779aSAndroid Build Coastguard Worker       }
249*15dc779aSAndroid Build Coastguard Worker     } else { /* tns_data_short Blocks */
250*15dc779aSAndroid Build Coastguard Worker       if (pstr_blk_switch_left_ctrl->max_win_energy >
251*15dc779aSAndroid Build Coastguard Worker           pstr_blk_switch_right_ctrl->max_win_energy) {
252*15dc779aSAndroid Build Coastguard Worker         pstr_blk_switch_right_ctrl->total_groups_cnt =
253*15dc779aSAndroid Build Coastguard Worker             pstr_blk_switch_left_ctrl->total_groups_cnt;
254*15dc779aSAndroid Build Coastguard Worker         for (i = 0; i < TRANS_FAC; i++) {
255*15dc779aSAndroid Build Coastguard Worker           pstr_blk_switch_right_ctrl->group_len[i] = pstr_blk_switch_left_ctrl->group_len[i];
256*15dc779aSAndroid Build Coastguard Worker         }
257*15dc779aSAndroid Build Coastguard Worker       } else {
258*15dc779aSAndroid Build Coastguard Worker         pstr_blk_switch_left_ctrl->total_groups_cnt =
259*15dc779aSAndroid Build Coastguard Worker             pstr_blk_switch_right_ctrl->total_groups_cnt;
260*15dc779aSAndroid Build Coastguard Worker         for (i = 0; i < TRANS_FAC; i++) {
261*15dc779aSAndroid Build Coastguard Worker           pstr_blk_switch_left_ctrl->group_len[i] = pstr_blk_switch_right_ctrl->group_len[i];
262*15dc779aSAndroid Build Coastguard Worker         }
263*15dc779aSAndroid Build Coastguard Worker       }
264*15dc779aSAndroid Build Coastguard Worker     }
265*15dc779aSAndroid Build Coastguard Worker   }
266*15dc779aSAndroid Build Coastguard Worker }
267