xref: /aosp_15_r20/external/libxaac/encoder/ixheaace_sbr_frame_info_gen.c (revision 15dc779a375ca8b5125643b829a8aa4b70d7f451)
1 /******************************************************************************
2  *                                                                            *
3  * Copyright (C) 2023 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 
21 #include <string.h>
22 
23 #include "ixheaac_type_def.h"
24 #include "ixheaac_constants.h"
25 #include "ixheaace_aac_constants.h"
26 #include "ixheaac_basic_ops32.h"
27 #include "ixheaac_basic_ops16.h"
28 #include "ixheaac_basic_ops40.h"
29 #include "ixheaac_basic_ops.h"
30 
31 #include "ixheaac_error_standards.h"
32 #include "ixheaace_error_codes.h"
33 
34 #include "ixheaace_sbr_header.h"
35 #include "ixheaace_sbr_def.h"
36 #include "ixheaace_resampler.h"
37 #include "ixheaace_sbr_rom.h"
38 #include "ixheaace_common_rom.h"
39 #include "ixheaace_sbr_main.h"
40 #include "ixheaace_sbr_frame_info_gen.h"
41 #include "ixheaace_sbr_misc.h"
42 
ixheaace_add_freq_left(ixheaace_freq_res * ptr_vector,WORD32 * ptr_length_vector,ixheaace_freq_res value)43 static VOID ixheaace_add_freq_left(ixheaace_freq_res *ptr_vector, WORD32 *ptr_length_vector,
44                                    ixheaace_freq_res value) {
45   memmove(ptr_vector + 1, ptr_vector, *ptr_length_vector * sizeof(ptr_vector[0]));
46   ptr_vector[0] = value;
47   (*ptr_length_vector)++;
48 }
49 
ixheaace_add_freq_vec_left(ixheaace_freq_res * ptr_dst,WORD32 * length_dst,ixheaace_freq_res * ptr_src,WORD32 length_src)50 static VOID ixheaace_add_freq_vec_left(ixheaace_freq_res *ptr_dst, WORD32 *length_dst,
51                                        ixheaace_freq_res *ptr_src, WORD32 length_src) {
52   WORD32 i;
53   i = length_src - 1;
54   while (i >= 0) {
55     ixheaace_add_freq_left(ptr_dst, length_dst, ptr_src[i]);
56     i--;
57   }
58 }
59 
ixheaace_add_freq_right(ixheaace_freq_res * ptr_vector,WORD32 * ptr_length_vector,ixheaace_freq_res value)60 static VOID ixheaace_add_freq_right(ixheaace_freq_res *ptr_vector, WORD32 *ptr_length_vector,
61                                     ixheaace_freq_res value) {
62   ptr_vector[*ptr_length_vector] = value;
63 
64   (*ptr_length_vector)++;
65 }
66 
ixheaace_fill_frame_tran(WORD32 * ptr_v_bord,WORD32 * ptr_length_v_bord,ixheaace_freq_res * ptr_v_freq,WORD32 * ptr_length_v_freq,WORD32 * ptr_bmin,WORD32 * ptr_bmax,WORD32 tran,WORD32 * ptr_ptr_v_tuning_segm,ixheaace_freq_res * ptr_tuning_freq)67 static VOID ixheaace_fill_frame_tran(WORD32 *ptr_v_bord, WORD32 *ptr_length_v_bord,
68                                      ixheaace_freq_res *ptr_v_freq, WORD32 *ptr_length_v_freq,
69                                      WORD32 *ptr_bmin, WORD32 *ptr_bmax, WORD32 tran,
70                                      WORD32 *ptr_ptr_v_tuning_segm,
71                                      ixheaace_freq_res *ptr_tuning_freq) {
72   WORD32 bord, i;
73 
74   *ptr_length_v_bord = 0;
75   *ptr_length_v_freq = 0;
76 
77   if (ptr_ptr_v_tuning_segm[0]) {
78     ixheaace_add_right(ptr_v_bord, ptr_length_v_bord, (tran - ptr_ptr_v_tuning_segm[0]));
79 
80     ixheaace_add_freq_right(ptr_v_freq, ptr_length_v_freq, ptr_tuning_freq[0]);
81   }
82 
83   bord = tran;
84 
85   ixheaace_add_right(ptr_v_bord, ptr_length_v_bord, tran);
86 
87   if (ptr_ptr_v_tuning_segm[1]) {
88     bord += ptr_ptr_v_tuning_segm[1];
89 
90     ixheaace_add_right(ptr_v_bord, ptr_length_v_bord, bord);
91 
92     ixheaace_add_freq_right(ptr_v_freq, ptr_length_v_freq, ptr_tuning_freq[1]);
93   }
94 
95   if (ptr_ptr_v_tuning_segm[2] != 0) {
96     bord += ptr_ptr_v_tuning_segm[2];
97 
98     ixheaace_add_right(ptr_v_bord, ptr_length_v_bord, bord);
99 
100     ixheaace_add_freq_right(ptr_v_freq, ptr_length_v_freq, ptr_tuning_freq[2]);
101   }
102 
103   ixheaace_add_freq_right(ptr_v_freq, ptr_length_v_freq, FREQ_RES_HIGH);
104 
105   *ptr_bmin = ptr_v_bord[0];
106   *ptr_bmax = ptr_v_bord[0];
107 
108   for (i = 0; i < *ptr_length_v_bord; i++) {
109     if (ptr_v_bord[i] < *ptr_bmin) {
110       *ptr_bmin = ptr_v_bord[i];
111     }
112     if (ptr_v_bord[i] > *ptr_bmax) {
113       *ptr_bmax = ptr_v_bord[i];
114     }
115   }
116 }
117 
ixheaace_fill_frame_pre(WORD32 dmax,WORD32 * ptr_v_bord,WORD32 * ptr_length_v_bord,ixheaace_freq_res * ptr_v_freq,WORD32 * ptr_length_v_freq,WORD32 bmin,WORD32 rest)118 static VOID ixheaace_fill_frame_pre(WORD32 dmax, WORD32 *ptr_v_bord, WORD32 *ptr_length_v_bord,
119                                     ixheaace_freq_res *ptr_v_freq, WORD32 *ptr_length_v_freq,
120                                     WORD32 bmin, WORD32 rest) {
121   WORD32 ptr_parts, ptr_d, j, S, s = 0, segm, bord;
122 
123   ptr_parts = 1;
124   ptr_d = rest;
125 
126   while (ptr_d > dmax) {
127     ptr_parts++;
128 
129     segm = rest / ptr_parts;
130 
131     S = ixheaac_shr32((segm - 2), 1);
132 
133     s = ixheaac_min32(8, 2 * S + 2);
134 
135     ptr_d = rest - (ptr_parts - 1) * s;
136   }
137 
138   bord = bmin;
139   j = 0;
140   while (j <= ptr_parts - 2) {
141     bord = bord - s;
142 
143     ixheaace_add_left(ptr_v_bord, ptr_length_v_bord, bord);
144 
145     ixheaace_add_freq_left(ptr_v_freq, ptr_length_v_freq, FREQ_RES_HIGH);
146     j++;
147   }
148 }
149 
ixheaace_fill_Frame_Post(WORD32 * ptr_parts,WORD32 * ptr_d,WORD32 dmax,WORD32 * ptr_v_bord,WORD32 * ptr_length_v_bord,ixheaace_freq_res * ptr_v_freq,WORD32 * ptr_length_v_freq,WORD32 bmax,WORD32 fmax)150 static VOID ixheaace_fill_Frame_Post(WORD32 *ptr_parts, WORD32 *ptr_d, WORD32 dmax,
151                                      WORD32 *ptr_v_bord, WORD32 *ptr_length_v_bord,
152                                      ixheaace_freq_res *ptr_v_freq, WORD32 *ptr_length_v_freq,
153                                      WORD32 bmax, WORD32 fmax) {
154   WORD32 j, rest, segm, S, s = 0, bord;
155 
156   rest = 32 - bmax;
157 
158   *ptr_d = rest;
159 
160   if (*ptr_d > 0) {
161     *ptr_parts = 1; /* start with one envelope */
162 
163     while (*ptr_d > dmax) {
164       *ptr_parts = *ptr_parts + 1;
165 
166       segm = rest / (*ptr_parts);
167 
168       S = ixheaac_shr32((segm - 2), 1);
169 
170       s = ixheaac_min32(fmax, 2 * S + 2);
171 
172       *ptr_d = rest - (*ptr_parts - 1) * s;
173     }
174 
175     bord = bmax;
176 
177     for (j = 0; j <= *ptr_parts - 2; j++) {
178       bord += s;
179 
180       ixheaace_add_right(ptr_v_bord, ptr_length_v_bord, bord);
181 
182       ixheaace_add_freq_right(ptr_v_freq, ptr_length_v_freq, FREQ_RES_HIGH);
183     }
184   } else {
185     *ptr_parts = 1;
186 
187     *ptr_length_v_bord = *ptr_length_v_bord - 1;
188     *ptr_length_v_freq = *ptr_length_v_freq - 1;
189   }
190 }
191 
ixheaace_fill_frame_inter(WORD32 * ptr_n_l,WORD32 * ptr_ptr_v_tuning_segm,WORD32 * ptr_v_bord,WORD32 * ptr_length_v_bord,WORD32 bmin,ixheaace_freq_res * ptr_v_freq,WORD32 * ptr_length_v_freq,WORD32 * ptr_v_bord_follow,WORD32 * ptr_length_v_bord_follow,ixheaace_freq_res * ptr_v_freq_follow,WORD32 * ptr_length_v_freq_follow,WORD32 fill_follow,WORD32 dmin,WORD32 dmax)192 static VOID ixheaace_fill_frame_inter(WORD32 *ptr_n_l, WORD32 *ptr_ptr_v_tuning_segm,
193                                       WORD32 *ptr_v_bord, WORD32 *ptr_length_v_bord, WORD32 bmin,
194                                       ixheaace_freq_res *ptr_v_freq, WORD32 *ptr_length_v_freq,
195                                       WORD32 *ptr_v_bord_follow, WORD32 *ptr_length_v_bord_follow,
196                                       ixheaace_freq_res *ptr_v_freq_follow,
197                                       WORD32 *ptr_length_v_freq_follow, WORD32 fill_follow,
198                                       WORD32 dmin, WORD32 dmax) {
199   WORD32 middle, b_new, num_bord_follow, bord_max_follow;
200 
201   if (fill_follow >= 1) {
202     *ptr_length_v_bord_follow = fill_follow;
203     *ptr_length_v_freq_follow = fill_follow;
204   }
205 
206   num_bord_follow = *ptr_length_v_bord_follow;
207 
208   bord_max_follow = ptr_v_bord_follow[num_bord_follow - 1];
209 
210   middle = bmin - bord_max_follow;
211 
212   while (middle < 0) {
213     num_bord_follow--;
214 
215     bord_max_follow = ptr_v_bord_follow[num_bord_follow - 1];
216 
217     middle = bmin - bord_max_follow;
218   }
219 
220   *ptr_length_v_bord_follow = num_bord_follow;
221   *ptr_length_v_freq_follow = num_bord_follow;
222 
223   *ptr_n_l = num_bord_follow - 1;
224 
225   b_new = *ptr_length_v_bord;
226 
227   if ((middle <= dmax) && (middle >= dmin)) {
228     ixheaace_add_vec_left(ptr_v_bord, ptr_length_v_bord, ptr_v_bord_follow,
229                           *ptr_length_v_bord_follow);
230 
231     ixheaace_add_freq_vec_left(ptr_v_freq, ptr_length_v_freq, ptr_v_freq_follow,
232                                *ptr_length_v_freq_follow);
233   }
234 
235   else if ((middle <= dmax) && (middle < dmin)) {
236     if (ptr_ptr_v_tuning_segm[0] != 0) {
237       *ptr_length_v_bord = b_new - 1;
238 
239       ixheaace_add_vec_left(ptr_v_bord, ptr_length_v_bord, ptr_v_bord_follow,
240                             *ptr_length_v_bord_follow);
241 
242       *ptr_length_v_freq = b_new - 1;
243 
244       ixheaace_add_freq_vec_left(ptr_v_freq + 1, ptr_length_v_freq, ptr_v_freq_follow,
245                                  *ptr_length_v_freq_follow);
246     } else {
247       if (*ptr_length_v_bord_follow > 1) {
248         ixheaace_add_vec_left(ptr_v_bord, ptr_length_v_bord, ptr_v_bord_follow,
249                               *ptr_length_v_bord_follow - 1);
250 
251         ixheaace_add_freq_vec_left(ptr_v_freq, ptr_length_v_freq, ptr_v_freq_follow,
252                                    *ptr_length_v_bord_follow - 1);
253 
254         *ptr_n_l = *ptr_n_l - 1;
255       } else {
256         memmove(ptr_v_bord, ptr_v_bord + 1, (*ptr_length_v_bord - 1) * sizeof(*ptr_v_bord));
257 
258         memmove(ptr_v_freq, ptr_v_freq + 1, (*ptr_length_v_freq - 1) * sizeof(*ptr_v_freq));
259         *ptr_length_v_bord = b_new - 1;
260         *ptr_length_v_freq = b_new - 1;
261 
262         ixheaace_add_vec_left(ptr_v_bord, ptr_length_v_bord, ptr_v_bord_follow,
263                               *ptr_length_v_bord_follow);
264 
265         ixheaace_add_freq_vec_left(ptr_v_freq, ptr_length_v_freq, ptr_v_freq_follow,
266                                    *ptr_length_v_freq_follow);
267       }
268     }
269   } else {
270     ixheaace_fill_frame_pre(dmax, ptr_v_bord, ptr_length_v_bord, ptr_v_freq, ptr_length_v_freq,
271                             bmin, middle);
272 
273     ixheaace_add_vec_left(ptr_v_bord, ptr_length_v_bord, ptr_v_bord_follow,
274                           *ptr_length_v_bord_follow);
275 
276     ixheaace_add_freq_vec_left(ptr_v_freq, ptr_length_v_freq, ptr_v_freq_follow,
277                                *ptr_length_v_freq_follow);
278   }
279 }
280 
ixheaace_calc_frame_class(ixheaace_frame_class * ptr_frame_type,ixheaace_frame_class * ptr_frame_type_old,WORD32 tran_flag,WORD32 * ptr_spread_flag,WORD32 is_ld_sbr)281 static VOID ixheaace_calc_frame_class(ixheaace_frame_class *ptr_frame_type,
282                                       ixheaace_frame_class *ptr_frame_type_old, WORD32 tran_flag,
283                                       WORD32 *ptr_spread_flag, WORD32 is_ld_sbr) {
284   if (0 == is_ld_sbr) {
285     switch (*ptr_frame_type_old) {
286       case IXHEAACE_FIXFIX:
287 
288         *ptr_frame_type = (tran_flag ? IXHEAACE_FIXVAR : IXHEAACE_FIXFIX);
289         break;
290 
291       case IXHEAACE_FIXVAR:
292 
293         if (tran_flag) {
294           *ptr_frame_type = IXHEAACE_VARVAR;
295           *ptr_spread_flag = 0;
296         } else {
297           *ptr_frame_type = (*ptr_spread_flag ? IXHEAACE_VARVAR : IXHEAACE_VARFIX);
298         }
299         break;
300 
301       case IXHEAACE_VARFIX:
302 
303         *ptr_frame_type = (tran_flag ? IXHEAACE_FIXVAR : IXHEAACE_FIXFIX);
304         break;
305 
306       case IXHEAACE_VARVAR:
307 
308         if (tran_flag) {
309           *ptr_frame_type = IXHEAACE_VARVAR;
310           *ptr_spread_flag = 0;
311         } else {
312           *ptr_frame_type = (*ptr_spread_flag ? IXHEAACE_VARVAR : IXHEAACE_VARFIX);
313         }
314         break;
315       default:
316         break;
317     }
318   } else {
319     *ptr_frame_type = (tran_flag ? IXHEAACE_LD_TRAN : IXHEAACE_FIXFIX);
320   }
321   *ptr_frame_type_old = *ptr_frame_type;
322 }
323 
ixheaace_special_case(WORD32 * ptr_spread_flag,WORD32 allow_spread,WORD32 * ptr_a_borders,WORD32 * ptr_border_vec_len,ixheaace_freq_res * ptr_freq_res,WORD32 * ptr_freq_res_vec_len,WORD32 * ptr_num_parts,WORD32 ptr_d)324 static VOID ixheaace_special_case(WORD32 *ptr_spread_flag, WORD32 allow_spread,
325                                   WORD32 *ptr_a_borders, WORD32 *ptr_border_vec_len,
326                                   ixheaace_freq_res *ptr_freq_res, WORD32 *ptr_freq_res_vec_len,
327                                   WORD32 *ptr_num_parts, WORD32 ptr_d) {
328   WORD32 L;
329 
330   L = *ptr_border_vec_len;
331 
332   if (allow_spread) {
333     *ptr_spread_flag = 1;
334 
335     ixheaace_add_right(ptr_a_borders, ptr_border_vec_len, ptr_a_borders[L - 1] + 8);
336 
337     ixheaace_add_freq_right(ptr_freq_res, ptr_freq_res_vec_len, FREQ_RES_HIGH);
338 
339     (*ptr_num_parts)++;
340   } else {
341     if (ptr_d == 1) {
342       *ptr_border_vec_len = L - 1;
343       *ptr_freq_res_vec_len = L - 1;
344     } else {
345       if ((ptr_a_borders[L - 1] - ptr_a_borders[L - 2]) > 2) {
346         ptr_a_borders[L - 1] = ptr_a_borders[L - 1] - 2;
347 
348         ptr_freq_res[*ptr_freq_res_vec_len - 1] = FREQ_RES_LOW;
349       }
350     }
351   }
352 }
353 
ixheaace_calc_cmon_border(WORD32 * ptr_cmon_border_idx,WORD32 * ptr_tran_idx,WORD32 * ptr_a_borders,WORD32 * ptr_border_vec_len,WORD32 tran)354 static VOID ixheaace_calc_cmon_border(WORD32 *ptr_cmon_border_idx, WORD32 *ptr_tran_idx,
355                                       WORD32 *ptr_a_borders, WORD32 *ptr_border_vec_len,
356                                       WORD32 tran
357 
358 ) {
359   WORD32 i;
360 
361   for (i = 0; i < *ptr_border_vec_len; i++) {
362     if (ptr_a_borders[i] >= 16) {
363       *ptr_cmon_border_idx = i;
364       break;
365     }
366   }
367   i = 0;
368   while (i < *ptr_border_vec_len) {
369     if (ptr_a_borders[i] >= tran) {
370       *ptr_tran_idx = i;
371       break;
372     } else {
373       *ptr_tran_idx = IXHEAACE_EMPTY;
374     }
375     i++;
376   }
377 }
378 
ixheaace_keep_for_follow_up(WORD32 * ptr_a_borders_follow,WORD32 * ptr_border_vec_len_follow,ixheaace_freq_res * ptr_a_freq_res_follow,WORD32 * ptr_freq_res_vec_len_follow,WORD32 * ptr_tran_idx_follow,WORD32 * ptr_fill_idx_follow,WORD32 * ptr_a_borders,WORD32 * ptr_border_vec_len,ixheaace_freq_res * ptr_freq_res,WORD32 cmon_border_idx,WORD32 tran_idx,WORD32 num_parts)379 static VOID ixheaace_keep_for_follow_up(WORD32 *ptr_a_borders_follow,
380                                         WORD32 *ptr_border_vec_len_follow,
381                                         ixheaace_freq_res *ptr_a_freq_res_follow,
382                                         WORD32 *ptr_freq_res_vec_len_follow,
383                                         WORD32 *ptr_tran_idx_follow, WORD32 *ptr_fill_idx_follow,
384                                         WORD32 *ptr_a_borders, WORD32 *ptr_border_vec_len,
385                                         ixheaace_freq_res *ptr_freq_res, WORD32 cmon_border_idx,
386                                         WORD32 tran_idx, WORD32 num_parts
387 
388 ) {
389   WORD32 L, i, j;
390 
391   L = *ptr_border_vec_len;
392 
393   (*ptr_border_vec_len_follow) = 0;
394   (*ptr_freq_res_vec_len_follow) = 0;
395 
396   j = 0, i = cmon_border_idx;
397 
398   while (i < L) {
399     ptr_a_borders_follow[j] = ptr_a_borders[i] - 16;
400 
401     ptr_a_freq_res_follow[j] = ptr_freq_res[i];
402 
403     (*ptr_border_vec_len_follow)++;
404     (*ptr_freq_res_vec_len_follow)++;
405     i++, j++;
406   }
407 
408   *ptr_tran_idx_follow =
409       (tran_idx != IXHEAACE_EMPTY ? tran_idx - cmon_border_idx : IXHEAACE_EMPTY);
410 
411   *ptr_fill_idx_follow = L - (num_parts - 1) - cmon_border_idx;
412 }
413 
ixheaace_calc_ctrl_signal(ixheaace_pstr_sbr_grid pstr_sbr_grid,ixheaace_frame_class frame_type,WORD32 * ptr_v_bord,WORD32 length_v_bord,ixheaace_freq_res * ptr_v_freq,WORD32 length_v_freq,WORD32 i_cmon,WORD32 i_tran,WORD32 spread_flag,WORD32 ptr_n_l)414 static VOID ixheaace_calc_ctrl_signal(ixheaace_pstr_sbr_grid pstr_sbr_grid,
415                                       ixheaace_frame_class frame_type, WORD32 *ptr_v_bord,
416                                       WORD32 length_v_bord, ixheaace_freq_res *ptr_v_freq,
417                                       WORD32 length_v_freq, WORD32 i_cmon, WORD32 i_tran,
418                                       WORD32 spread_flag, WORD32 ptr_n_l) {
419   WORD32 i, r, a, n, p, b, a_l, a_r, ntot, nmax, n_r;
420 
421   ixheaace_freq_res *ptr_v_f = pstr_sbr_grid->v_f;
422   ixheaace_freq_res *ptr_v_f_lr = pstr_sbr_grid->v_f_lr;
423   WORD32 *ptr_v_r = pstr_sbr_grid->bs_rel_bord;
424   WORD32 *ptr_v_rl = pstr_sbr_grid->bs_rel_bord_0;
425   WORD32 *ptr_v_rr = pstr_sbr_grid->bs_rel_bord_1;
426 
427   WORD32 length_v_r = 0;
428   WORD32 length_v_rr = 0;
429   WORD32 length_v_rl = 0;
430 
431   switch (frame_type) {
432     case IXHEAACE_FIXVAR:
433 
434       a = ptr_v_bord[i_cmon];
435 
436       length_v_r = 0;
437       i = i_cmon;
438 
439       while (i >= 1) {
440         r = ptr_v_bord[i] - ptr_v_bord[i - 1];
441 
442         ixheaace_add_right(ptr_v_r, &length_v_r, r);
443 
444         i--;
445       }
446 
447       n = length_v_r;
448 
449       for (i = 0; i < i_cmon; i++) {
450         ptr_v_f[i] = ptr_v_freq[i_cmon - 1 - i];
451       }
452 
453       ptr_v_f[i_cmon] = FREQ_RES_HIGH;
454 
455       if ((i_cmon >= i_tran) && (i_tran != IXHEAACE_EMPTY)) {
456         p = i_cmon - i_tran + 1;
457       } else {
458         p = 0;
459       }
460 
461       pstr_sbr_grid->frame_type = frame_type;
462       pstr_sbr_grid->bs_abs_bord = a;
463       pstr_sbr_grid->n = n;
464       pstr_sbr_grid->p = p;
465 
466       break;
467     case IXHEAACE_VARFIX:
468 
469       a = ptr_v_bord[0];
470 
471       length_v_r = 0;
472 
473       i = 1;
474       while (i < length_v_bord) {
475         r = ptr_v_bord[i] - ptr_v_bord[i - 1];
476 
477         ixheaace_add_right(ptr_v_r, &length_v_r, r);
478 
479         i++;
480       }
481 
482       n = length_v_r;
483 
484       memcpy(ptr_v_f, ptr_v_freq, length_v_freq * sizeof(ixheaace_freq_res));
485 
486       if ((i_tran >= 0) && (i_tran != IXHEAACE_EMPTY)) {
487         p = i_tran + 1;
488       } else {
489         p = 0;
490       }
491 
492       pstr_sbr_grid->frame_type = frame_type;
493       pstr_sbr_grid->bs_abs_bord = a;
494       pstr_sbr_grid->n = n;
495       pstr_sbr_grid->p = p;
496 
497       break;
498     case IXHEAACE_VARVAR:
499 
500       if (spread_flag) {
501         b = length_v_bord;
502 
503         a_l = ptr_v_bord[0];
504 
505         a_r = ptr_v_bord[b - 1];
506 
507         ntot = b - 2;
508 
509         nmax = 2;
510 
511         if (ntot > nmax) {
512           ptr_n_l = nmax;
513           n_r = ntot - nmax;
514         } else {
515           ptr_n_l = ntot;
516           n_r = 0;
517         }
518 
519         length_v_rl = 0;
520 
521         i = 1;
522         while (i <= ptr_n_l) {
523           r = ptr_v_bord[i] - ptr_v_bord[i - 1];
524 
525           ixheaace_add_right(ptr_v_rl, &length_v_rl, r);
526 
527           i++;
528         }
529 
530         length_v_rr = 0;
531 
532         i = b - 1;
533 
534         while (i >= b - n_r) {
535           r = ptr_v_bord[i] - ptr_v_bord[i - 1];
536 
537           ixheaace_add_right(ptr_v_rr, &length_v_rr, r);
538 
539           i--;
540         }
541 
542         if ((i_tran > 0) && (i_tran != IXHEAACE_EMPTY)) {
543           p = b - i_tran;
544         } else {
545           p = 0;
546         }
547 
548         for (i = 0; i < b - 1; i++) {
549           ptr_v_f_lr[i] = ptr_v_freq[i];
550         }
551       } else {
552         length_v_bord = i_cmon + 1;
553 
554         b = length_v_bord;
555 
556         a_l = ptr_v_bord[0];
557 
558         a_r = ptr_v_bord[b - 1];
559 
560         ntot = b - 2;
561         n_r = ntot - ptr_n_l;
562 
563         length_v_rl = 0;
564 
565         i = 1;
566         while (i <= ptr_n_l) {
567           r = ptr_v_bord[i] - ptr_v_bord[i - 1];
568 
569           ixheaace_add_right(ptr_v_rl, &length_v_rl, r);
570 
571           i++;
572         }
573 
574         length_v_rr = 0;
575 
576         i = b - 1;
577 
578         while (i >= b - n_r) {
579           r = ptr_v_bord[i] - ptr_v_bord[i - 1];
580 
581           ixheaace_add_right(ptr_v_rr, &length_v_rr, r);
582 
583           i--;
584         }
585 
586         if ((i_cmon >= i_tran) && (i_tran != IXHEAACE_EMPTY)) {
587           p = i_cmon - i_tran + 1;
588         } else {
589           p = 0;
590         }
591 
592         for (i = 0; i < b - 1; i++) {
593           ptr_v_f_lr[i] = ptr_v_freq[i];
594         }
595       }
596 
597       pstr_sbr_grid->frame_type = frame_type;
598       pstr_sbr_grid->bs_abs_bord_0 = a_l;
599       pstr_sbr_grid->bs_abs_bord_1 = a_r;
600       pstr_sbr_grid->bs_num_rel_0 = ptr_n_l;
601       pstr_sbr_grid->bs_num_rel_1 = n_r;
602       pstr_sbr_grid->p = p;
603 
604       break;
605 
606     default:
607       break;
608   }
609 }
610 
ixheaace_create_def_frame_info(ixheaace_pstr_sbr_frame_info pstr_sbr_frame_info,WORD32 n_env,ixheaace_str_qmf_tabs * ptr_qmf_tab)611 static VOID ixheaace_create_def_frame_info(ixheaace_pstr_sbr_frame_info pstr_sbr_frame_info,
612                                            WORD32 n_env, ixheaace_str_qmf_tabs *ptr_qmf_tab) {
613   switch (n_env) {
614     case NUM_ENVELOPE_1:
615 
616       memcpy(pstr_sbr_frame_info, &(ptr_qmf_tab->frame_info1_2048),
617              sizeof(ixheaace_str_frame_info_sbr));
618 
619       break;
620 
621     case NUM_ENVELOPE_2:
622 
623       memcpy(pstr_sbr_frame_info, &(ptr_qmf_tab->frame_info2_2048),
624              sizeof(ixheaace_str_frame_info_sbr));
625 
626       break;
627 
628     case NUM_ENVELOPE_4:
629 
630       memcpy(pstr_sbr_frame_info, &(ptr_qmf_tab->frame_info4_2048),
631              sizeof(ixheaace_str_frame_info_sbr));
632 
633       break;
634   }
635 }
ixheaace_create_ld_transient_frame_info(ixheaace_pstr_sbr_frame_info pstr_sbr_frame_info,ixheaace_pstr_sbr_grid pstr_sbr_grid,WORD32 tran_pos,WORD32 num_time_slots,WORD32 low_tran_flag)636 static VOID ixheaace_create_ld_transient_frame_info(
637     ixheaace_pstr_sbr_frame_info pstr_sbr_frame_info, ixheaace_pstr_sbr_grid pstr_sbr_grid,
638     WORD32 tran_pos, WORD32 num_time_slots, WORD32 low_tran_flag) {
639   WORD32 num_env, i, diff;
640   const WORD32 *env_tab = NULL;
641 
642   switch (num_time_slots)
643 
644   {
645     case TIME_SLOTS_15:
646       env_tab = ixheaace_ld_env_tab_480[tran_pos];
647       break;
648 
649     default:
650       env_tab = ixheaace_ld_env_tab_512[tran_pos];
651       break;
652   }
653 
654   num_env = env_tab[0];
655 
656   for (i = 1; i < num_env; i++) {
657     pstr_sbr_frame_info->borders[i] = env_tab[i];
658   }
659 
660   pstr_sbr_frame_info->borders[0] = 0;
661   pstr_sbr_frame_info->borders[num_env] = num_time_slots;
662 
663   i = 0;
664   while (i < num_env) {
665     diff = pstr_sbr_frame_info->borders[i + 1] - pstr_sbr_frame_info->borders[i];
666 
667     if (low_tran_flag) {
668       pstr_sbr_frame_info->freq_res[i] = FREQ_RES_LOW;
669     } else {
670       pstr_sbr_frame_info->freq_res[i] = (diff <= 5) ? FREQ_RES_LOW : FREQ_RES_HIGH;
671     }
672 
673     pstr_sbr_grid->v_f[i] = pstr_sbr_frame_info->freq_res[i];
674 
675     i++;
676   }
677 
678   pstr_sbr_frame_info->n_envelopes = num_env;
679   pstr_sbr_frame_info->short_env = env_tab[IXHEAACE_SBR_ENVT_TRANIDX];
680   pstr_sbr_frame_info->borders_noise[0] = pstr_sbr_frame_info->borders[0];
681   pstr_sbr_frame_info->borders_noise[1] = pstr_sbr_frame_info->borders[1];
682   pstr_sbr_frame_info->borders_noise[2] = num_time_slots;
683   pstr_sbr_frame_info->n_noise_envelopes = 2;
684   pstr_sbr_grid->frame_type = IXHEAACE_LD_TRAN;
685   pstr_sbr_grid->bs_transient_position = tran_pos;
686   pstr_sbr_grid->bs_num_env = num_env;
687 }
ixheaace_create_def_frame_480_info(ixheaace_pstr_sbr_frame_info pstr_sbr_frame_info,WORD32 n_env,ixheaace_str_qmf_tabs * ptr_qmf_tab)688 static VOID ixheaace_create_def_frame_480_info(ixheaace_pstr_sbr_frame_info pstr_sbr_frame_info,
689                                                WORD32 n_env, ixheaace_str_qmf_tabs *ptr_qmf_tab) {
690   switch (n_env) {
691     case NUM_ENVELOPE_1:
692 
693       memcpy(pstr_sbr_frame_info, &(ptr_qmf_tab->frame_480_info1_2048),
694              sizeof(ixheaace_str_frame_info_sbr));
695 
696       break;
697 
698     case NUM_ENVELOPE_2:
699 
700       memcpy(pstr_sbr_frame_info, &(ptr_qmf_tab->frame_480_info2_2048),
701              sizeof(ixheaace_str_frame_info_sbr));
702 
703       break;
704 
705     case NUM_ENVELOPE_4:
706 
707       memcpy(pstr_sbr_frame_info, &(ptr_qmf_tab->frame_480_info4_2048),
708              sizeof(ixheaace_str_frame_info_sbr));
709 
710       break;
711   }
712 }
713 
ixheaace_ctrl_signal2_frame_info(ixheaace_pstr_sbr_grid pstr_sbr_grid,ixheaace_pstr_sbr_frame_info pstr_sbr_frame_info,ixheaace_freq_res freq_res_fix,ixheaace_str_qmf_tabs * ptr_qmf_tab,WORD32 frame_length_480)714 static IA_ERRORCODE ixheaace_ctrl_signal2_frame_info(
715     ixheaace_pstr_sbr_grid pstr_sbr_grid, ixheaace_pstr_sbr_frame_info pstr_sbr_frame_info,
716     ixheaace_freq_res freq_res_fix, ixheaace_str_qmf_tabs *ptr_qmf_tab, WORD32 frame_length_480) {
717   WORD32 n_env = 0, border = 0, i, k, p;
718   WORD32 *ptr_v_r = pstr_sbr_grid->bs_rel_bord;
719   ixheaace_freq_res *ptr_v_f = pstr_sbr_grid->v_f;
720 
721   ixheaace_frame_class frame_type = pstr_sbr_grid->frame_type;
722 
723   switch (frame_type) {
724     case IXHEAACE_FIXFIX:
725       if (frame_length_480) {
726         ixheaace_create_def_frame_480_info(pstr_sbr_frame_info, pstr_sbr_grid->bs_num_env,
727                                            ptr_qmf_tab);
728       } else {
729         ixheaace_create_def_frame_info(pstr_sbr_frame_info, pstr_sbr_grid->bs_num_env,
730                                        ptr_qmf_tab);
731       }
732 
733       if (freq_res_fix == FREQ_RES_LOW) {
734         for (i = 0; i < pstr_sbr_frame_info->n_envelopes; i++) {
735           pstr_sbr_frame_info->freq_res[i] = FREQ_RES_LOW;
736         }
737       }
738       break;
739 
740     case IXHEAACE_FIXVAR:
741     case IXHEAACE_VARFIX:
742 
743       n_env = pstr_sbr_grid->n + 1;
744 
745       if ((n_env <= 0) || (n_env > IXHEAACE_MAX_ENV_FIXVAR_VARFIX)) {
746         return IA_EXHEAACE_EXE_FATAL_INVALID_SBR_NUM_ENVELOPES;
747       }
748 
749       pstr_sbr_frame_info->n_envelopes = n_env;
750 
751       border = pstr_sbr_grid->bs_abs_bord;
752 
753       pstr_sbr_frame_info->n_noise_envelopes = (n_env == 1 ? 1 : 2);
754 
755       break;
756 
757     case IXHEAACE_VARVAR:
758       break;
759     default:
760       return IA_EXHEAACE_EXE_FATAL_INVALID_SBR_FRAME_TYPE;
761       break;
762   }
763 
764   switch (frame_type) {
765     case IXHEAACE_FIXVAR:
766 
767       pstr_sbr_frame_info->borders[0] = 0;
768 
769       pstr_sbr_frame_info->borders[n_env] = border;
770 
771       k = 0;
772       i = n_env - 1;
773       while (k < n_env - 1) {
774         border -= ptr_v_r[k];
775 
776         pstr_sbr_frame_info->borders[i] = border;
777         k++;
778         i--;
779       }
780 
781       p = pstr_sbr_grid->p;
782 
783       if (p == 0) {
784         pstr_sbr_frame_info->short_env = 0;
785       } else {
786         pstr_sbr_frame_info->short_env = n_env + 1 - p;
787       }
788 
789       for (k = 0, i = n_env - 1; k < n_env; k++, i--) {
790         pstr_sbr_frame_info->freq_res[i] = ptr_v_f[k];
791       }
792 
793       if (p == 0 || p == 1) {
794         pstr_sbr_frame_info->borders_noise[1] = pstr_sbr_frame_info->borders[n_env - 1];
795       } else {
796         pstr_sbr_frame_info->borders_noise[1] =
797             pstr_sbr_frame_info->borders[pstr_sbr_frame_info->short_env];
798       }
799 
800       break;
801 
802     case IXHEAACE_VARFIX:
803       pstr_sbr_frame_info->borders[0] = border;
804 
805       for (k = 0; k < n_env - 1; k++) {
806         border += ptr_v_r[k];
807 
808         pstr_sbr_frame_info->borders[k + 1] = border;
809       }
810 
811       pstr_sbr_frame_info->borders[n_env] = 16;
812 
813       p = pstr_sbr_grid->p;
814 
815       if (p == 0 || p == 1) {
816         pstr_sbr_frame_info->short_env = 0;
817       } else {
818         pstr_sbr_frame_info->short_env = p - 1;
819       }
820 
821       for (k = 0; k < n_env; k++) {
822         pstr_sbr_frame_info->freq_res[k] = ptr_v_f[k];
823       }
824 
825       switch (p) {
826         case 0:
827           pstr_sbr_frame_info->borders_noise[1] = pstr_sbr_frame_info->borders[1];
828           break;
829         case 1:
830           pstr_sbr_frame_info->borders_noise[1] = pstr_sbr_frame_info->borders[n_env - 1];
831           break;
832         default:
833           pstr_sbr_frame_info->borders_noise[1] =
834               pstr_sbr_frame_info->borders[pstr_sbr_frame_info->short_env];
835           break;
836       }
837       break;
838 
839     case IXHEAACE_VARVAR:
840       n_env = pstr_sbr_grid->bs_num_rel_0 + pstr_sbr_grid->bs_num_rel_1 + 1;
841 
842       if ((n_env < 1) || (n_env > IXHEAACE_MAX_ENV_VARVAR)) {
843         return IA_EXHEAACE_EXE_FATAL_INVALID_SBR_NUM_ENVELOPES;
844       }
845       pstr_sbr_frame_info->n_envelopes = n_env;
846 
847       pstr_sbr_frame_info->borders[0] = border = pstr_sbr_grid->bs_abs_bord_0;
848 
849       for (k = 0, i = 1; k < pstr_sbr_grid->bs_num_rel_0; k++, i++) {
850         border += pstr_sbr_grid->bs_rel_bord_0[k];
851 
852         pstr_sbr_frame_info->borders[i] = border;
853       }
854 
855       border = pstr_sbr_grid->bs_abs_bord_1;
856 
857       pstr_sbr_frame_info->borders[n_env] = border;
858 
859       for (k = 0, i = n_env - 1; k < pstr_sbr_grid->bs_num_rel_1; k++, i--) {
860         border -= pstr_sbr_grid->bs_rel_bord_1[k];
861 
862         pstr_sbr_frame_info->borders[i] = border;
863       }
864 
865       p = pstr_sbr_grid->p;
866 
867       pstr_sbr_frame_info->short_env = (p == 0 ? 0 : n_env + 1 - p);
868 
869       for (k = 0; k < n_env; k++) {
870         pstr_sbr_frame_info->freq_res[k] = pstr_sbr_grid->v_f_lr[k];
871       }
872 
873       if (n_env == 1) {
874         pstr_sbr_frame_info->n_noise_envelopes = 1;
875         pstr_sbr_frame_info->borders_noise[0] = pstr_sbr_grid->bs_abs_bord_0;
876         pstr_sbr_frame_info->borders_noise[1] = pstr_sbr_grid->bs_abs_bord_1;
877       } else {
878         pstr_sbr_frame_info->n_noise_envelopes = 2;
879         pstr_sbr_frame_info->borders_noise[0] = pstr_sbr_grid->bs_abs_bord_0;
880 
881         if (p == 0 || p == 1) {
882           pstr_sbr_frame_info->borders_noise[1] = pstr_sbr_frame_info->borders[n_env - 1];
883         } else {
884           pstr_sbr_frame_info->borders_noise[1] =
885               pstr_sbr_frame_info->borders[pstr_sbr_frame_info->short_env];
886         }
887 
888         pstr_sbr_frame_info->borders_noise[2] = pstr_sbr_grid->bs_abs_bord_1;
889       }
890       break;
891 
892     default:
893       break;
894   }
895 
896   if (frame_type == IXHEAACE_VARFIX || frame_type == IXHEAACE_FIXVAR) {
897     pstr_sbr_frame_info->borders_noise[0] = pstr_sbr_frame_info->borders[0];
898 
899     if (n_env == 1) {
900       pstr_sbr_frame_info->borders_noise[1] = pstr_sbr_frame_info->borders[n_env];
901     } else {
902       pstr_sbr_frame_info->borders_noise[2] = pstr_sbr_frame_info->borders[n_env];
903     }
904   }
905   return IA_NO_ERROR;
906 }
907 
908 IA_ERRORCODE
ixheaace_frame_info_generator(ixheaace_pstr_sbr_env_frame pstr_sbr_env_frame,WORD32 * ptr_v_pre_transient_info,WORD32 * ptr_v_transient_info,WORD32 * ptr_v_tuning,ixheaace_str_qmf_tabs * ptr_qmf_tab,WORD32 num_time_slots,WORD32 is_ld_sbr,ixheaace_pstr_sbr_frame_info * ptr_frame_info,WORD32 flag_framelength_small)909 ixheaace_frame_info_generator(ixheaace_pstr_sbr_env_frame pstr_sbr_env_frame,
910                               WORD32 *ptr_v_pre_transient_info, WORD32 *ptr_v_transient_info,
911                               WORD32 *ptr_v_tuning, ixheaace_str_qmf_tabs *ptr_qmf_tab,
912                               WORD32 num_time_slots, WORD32 is_ld_sbr,
913                               ixheaace_pstr_sbr_frame_info *ptr_frame_info,
914                               WORD32 flag_framelength_small) {
915   IA_ERRORCODE err_code = IA_NO_ERROR;
916   WORD32 num_env, tran = 0, bmin = 0, bmax = 0;
917   WORD32 ptr_parts, ptr_d, i_cmon = 0, i_tran = IXHEAACE_EMPTY, ptr_n_l;
918   WORD32 fmax = 0;
919 
920   WORD32 *ptr_v_bord = pstr_sbr_env_frame->v_bord;
921   ixheaace_freq_res *ptr_v_freq = pstr_sbr_env_frame->v_freq;
922   WORD32 *ptr_v_bord_follow = pstr_sbr_env_frame->v_bord_follow;
923   ixheaace_freq_res *ptr_v_freq_follow = pstr_sbr_env_frame->v_freq_follow;
924 
925   WORD32 *ptr_length_v_bord_follow = &pstr_sbr_env_frame->length_v_bord_follow;
926   WORD32 *ptr_length_v_freq_follow = &pstr_sbr_env_frame->length_v_freq_follow;
927   WORD32 *ptr_length_v_bord = &pstr_sbr_env_frame->length_v_bord;
928   WORD32 *ptr_length_v_freq = &pstr_sbr_env_frame->length_v_freq;
929   WORD32 *ptr_spread_flag = &pstr_sbr_env_frame->spread_flag;
930   WORD32 *ptr_tran_follow = &pstr_sbr_env_frame->i_tran_follow;
931   WORD32 *ptr_fill_follow = &pstr_sbr_env_frame->i_fill_follow;
932   ixheaace_frame_class *ptr_frame_type_old = &pstr_sbr_env_frame->frame_type_old;
933   ixheaace_frame_class frame_type = IXHEAACE_FIXFIX;
934 
935   WORD32 allow_spread = pstr_sbr_env_frame->allow_spread;
936   WORD32 num_env_static = pstr_sbr_env_frame->num_env_static;
937   WORD32 static_framing = pstr_sbr_env_frame->static_framing;
938   WORD32 dmin = pstr_sbr_env_frame->dmin;
939   WORD32 dmax = pstr_sbr_env_frame->dmax;
940 
941   WORD32 tran_pos = ptr_v_transient_info[0];
942   WORD32 tran_flag = ptr_v_transient_info[1];
943 
944   WORD32 *ptr_ptr_v_tuning_segm = ptr_v_tuning;
945   ixheaace_freq_res *ptr_tuning_freq = (ixheaace_freq_res *)(ptr_v_tuning + 3);
946 
947   ixheaace_freq_res freq_res_fix = pstr_sbr_env_frame->freq_res_fix;
948 
949   if (is_ld_sbr) {
950     if ((!tran_flag && ptr_v_pre_transient_info[1]) &&
951         (num_time_slots - ptr_v_pre_transient_info[0] < 4)) {
952       tran_flag = 1;
953       tran_pos = 0;
954     }
955   }
956   if (static_framing) {
957     frame_type = IXHEAACE_FIXFIX;
958     num_env = num_env_static;
959     *ptr_frame_type_old = IXHEAACE_FIXFIX;
960     pstr_sbr_env_frame->sbr_grid.bs_num_env = num_env;
961     pstr_sbr_env_frame->sbr_grid.frame_type = frame_type;
962   } else {
963     ixheaace_calc_frame_class(&frame_type, ptr_frame_type_old, tran_flag, ptr_spread_flag,
964                               is_ld_sbr);
965     if (is_ld_sbr && tran_flag) {
966       frame_type = IXHEAACE_LD_TRAN;
967       *ptr_frame_type_old = IXHEAACE_FIXFIX;
968     }
969     if (tran_flag) {
970       if (tran_pos < 4) {
971         fmax = 6;
972       } else if (tran_pos == 4 || tran_pos == 5) {
973         fmax = 4;
974       } else
975         fmax = 8;
976 
977       tran = tran_pos + 4;
978 
979       ixheaace_fill_frame_tran(ptr_v_bord, ptr_length_v_bord, ptr_v_freq, ptr_length_v_freq,
980                                &bmin, &bmax, tran, ptr_ptr_v_tuning_segm, ptr_tuning_freq);
981     }
982     if (0 == is_ld_sbr) {
983       switch (frame_type) {
984         case IXHEAACE_FIXVAR:
985 
986           ixheaace_fill_frame_pre(dmax, ptr_v_bord, ptr_length_v_bord, ptr_v_freq,
987                                   ptr_length_v_freq, bmin, bmin);
988 
989           ixheaace_fill_Frame_Post(&ptr_parts, &ptr_d, dmax, ptr_v_bord, ptr_length_v_bord,
990                                    ptr_v_freq, ptr_length_v_freq, bmax, fmax);
991 
992           if (ptr_parts == 1 && ptr_d < dmin) {
993             ixheaace_special_case(ptr_spread_flag, allow_spread, ptr_v_bord, ptr_length_v_bord,
994                                   ptr_v_freq, ptr_length_v_freq, &ptr_parts, ptr_d);
995           }
996 
997           ixheaace_calc_cmon_border(&i_cmon, &i_tran, ptr_v_bord, ptr_length_v_bord, tran);
998           ixheaace_keep_for_follow_up(ptr_v_bord_follow, ptr_length_v_bord_follow,
999                                       ptr_v_freq_follow, ptr_length_v_freq_follow,
1000                                       ptr_tran_follow, ptr_fill_follow, ptr_v_bord,
1001                                       ptr_length_v_bord, ptr_v_freq, i_cmon, i_tran, ptr_parts);
1002 
1003           ixheaace_calc_ctrl_signal(&pstr_sbr_env_frame->sbr_grid, frame_type, ptr_v_bord,
1004                                     *ptr_length_v_bord, ptr_v_freq, *ptr_length_v_freq, i_cmon,
1005                                     i_tran, *ptr_spread_flag, IXHEAACE_DC);
1006           break;
1007         case IXHEAACE_VARFIX:
1008           ixheaace_calc_ctrl_signal(&pstr_sbr_env_frame->sbr_grid, frame_type, ptr_v_bord_follow,
1009                                     *ptr_length_v_bord_follow, ptr_v_freq_follow,
1010                                     *ptr_length_v_freq_follow, IXHEAACE_DC, *ptr_tran_follow,
1011                                     *ptr_spread_flag, IXHEAACE_DC);
1012           break;
1013         case IXHEAACE_VARVAR:
1014 
1015           if (*ptr_spread_flag) {
1016             ixheaace_calc_ctrl_signal(&pstr_sbr_env_frame->sbr_grid, frame_type,
1017                                       ptr_v_bord_follow, *ptr_length_v_bord_follow,
1018                                       ptr_v_freq_follow, *ptr_length_v_freq_follow, IXHEAACE_DC,
1019                                       *ptr_tran_follow, *ptr_spread_flag, IXHEAACE_DC);
1020 
1021             *ptr_spread_flag = 0;
1022 
1023             ptr_v_bord_follow[0] = pstr_sbr_env_frame->sbr_grid.bs_abs_bord_1 - 16;
1024 
1025             ptr_v_freq_follow[0] = FREQ_RES_HIGH;
1026             *ptr_length_v_bord_follow = 1;
1027             *ptr_length_v_freq_follow = 1;
1028 
1029             *ptr_tran_follow = -IXHEAACE_DC;
1030             *ptr_fill_follow = -IXHEAACE_DC;
1031           } else {
1032             ixheaace_fill_frame_inter(
1033                 &ptr_n_l, ptr_ptr_v_tuning_segm, ptr_v_bord, ptr_length_v_bord, bmin, ptr_v_freq,
1034                 ptr_length_v_freq, ptr_v_bord_follow, ptr_length_v_bord_follow, ptr_v_freq_follow,
1035                 ptr_length_v_freq_follow, *ptr_fill_follow, dmin, dmax);
1036 
1037             ixheaace_fill_Frame_Post(&ptr_parts, &ptr_d, dmax, ptr_v_bord, ptr_length_v_bord,
1038                                      ptr_v_freq, ptr_length_v_freq, bmax, fmax);
1039 
1040             if (ptr_parts == 1 && ptr_d < dmin) {
1041               ixheaace_special_case(ptr_spread_flag, allow_spread, ptr_v_bord, ptr_length_v_bord,
1042                                     ptr_v_freq, ptr_length_v_freq, &ptr_parts, ptr_d);
1043             }
1044 
1045             ixheaace_calc_cmon_border(&i_cmon, &i_tran, ptr_v_bord, ptr_length_v_bord, tran);
1046 
1047             ixheaace_keep_for_follow_up(ptr_v_bord_follow, ptr_length_v_bord_follow,
1048                                         ptr_v_freq_follow, ptr_length_v_freq_follow,
1049                                         ptr_tran_follow, ptr_fill_follow, ptr_v_bord,
1050                                         ptr_length_v_bord, ptr_v_freq, i_cmon, i_tran, ptr_parts);
1051 
1052             ixheaace_calc_ctrl_signal(&pstr_sbr_env_frame->sbr_grid, frame_type, ptr_v_bord,
1053                                       *ptr_length_v_bord, ptr_v_freq, *ptr_length_v_freq, i_cmon,
1054                                       i_tran, 0, ptr_n_l);
1055           }
1056           break;
1057         case IXHEAACE_FIXFIX:
1058 
1059           num_env = (tran_pos == 0 ? 1 : 2);
1060 
1061           pstr_sbr_env_frame->sbr_grid.bs_num_env = num_env;
1062           pstr_sbr_env_frame->sbr_grid.frame_type = frame_type;
1063 
1064           break;
1065         default:
1066           break;
1067       }
1068       err_code = ixheaace_ctrl_signal2_frame_info(
1069           &pstr_sbr_env_frame->sbr_grid, &pstr_sbr_env_frame->sbr_frame_info, freq_res_fix,
1070           ptr_qmf_tab, flag_framelength_small);
1071       if (err_code) {
1072         return err_code;
1073       }
1074     } else {
1075       WORD32 i;
1076 
1077       switch (frame_type) {
1078         case IXHEAACE_FIXFIX: {
1079           pstr_sbr_env_frame->sbr_grid.frame_type = frame_type;
1080           pstr_sbr_env_frame->sbr_grid.bs_transient_position = tran_pos;
1081           pstr_sbr_env_frame->sbr_frame_info.n_envelopes = 1;
1082           pstr_sbr_env_frame->sbr_grid.bs_num_env = 1;
1083           if (tran_pos == 1) {
1084             pstr_sbr_env_frame->sbr_grid.bs_num_env = 2;
1085           }
1086           pstr_sbr_env_frame->sbr_frame_info.short_env = 0;
1087           if (flag_framelength_small) {
1088             ixheaace_create_def_frame_480_info(&pstr_sbr_env_frame->sbr_frame_info,
1089                                                pstr_sbr_env_frame->sbr_grid.bs_num_env,
1090                                                ptr_qmf_tab);
1091           } else {
1092             ixheaace_create_def_frame_info(&pstr_sbr_env_frame->sbr_frame_info,
1093                                            pstr_sbr_env_frame->sbr_grid.bs_num_env, ptr_qmf_tab);
1094           }
1095 
1096           if (pstr_sbr_env_frame->sbr_frame_info.n_envelopes > 1) {
1097             for (i = 0; i < pstr_sbr_env_frame->sbr_frame_info.n_envelopes; i++) {
1098               pstr_sbr_env_frame->sbr_frame_info.freq_res[i] = FREQ_RES_LOW;
1099               pstr_sbr_env_frame->sbr_grid.v_f[i] = FREQ_RES_LOW;
1100             }
1101           } else {
1102             for (i = 0; i < pstr_sbr_env_frame->sbr_frame_info.n_envelopes; i++) {
1103               pstr_sbr_env_frame->sbr_frame_info.freq_res[i] = FREQ_RES_HIGH;
1104               pstr_sbr_env_frame->sbr_grid.v_f[i] = FREQ_RES_HIGH;
1105             }
1106           }
1107         } break;
1108 
1109         case IXHEAACE_LD_TRAN: {
1110           ixheaace_create_ld_transient_frame_info(&pstr_sbr_env_frame->sbr_frame_info,
1111                                                   &pstr_sbr_env_frame->sbr_grid, tran_pos,
1112                                                   num_time_slots,
1113                                                   pstr_sbr_env_frame->use_low_freq_res);
1114         } break;
1115         default:
1116           break;
1117       }
1118     }
1119   }
1120 
1121   *ptr_frame_info = &pstr_sbr_env_frame->sbr_frame_info;
1122   return err_code;
1123 }
1124 
ixheaace_create_frame_info_generator(ixheaace_pstr_sbr_env_frame pstr_sbr_env_frame,WORD32 allow_spread,WORD32 num_env_static,WORD32 static_framing,ixheaace_freq_res freq_res_fix,WORD32 use_low_freq_res)1125 VOID ixheaace_create_frame_info_generator(ixheaace_pstr_sbr_env_frame pstr_sbr_env_frame,
1126                                           WORD32 allow_spread, WORD32 num_env_static,
1127                                           WORD32 static_framing, ixheaace_freq_res freq_res_fix,
1128                                           WORD32 use_low_freq_res) {
1129   memset(pstr_sbr_env_frame, 0, sizeof(ixheaace_str_sbr_env_frame));
1130 
1131   pstr_sbr_env_frame->frame_type_old = IXHEAACE_FIXFIX;
1132   pstr_sbr_env_frame->spread_flag = 0;
1133 
1134   pstr_sbr_env_frame->allow_spread = allow_spread;
1135   pstr_sbr_env_frame->num_env_static = num_env_static;
1136   pstr_sbr_env_frame->static_framing = static_framing;
1137   pstr_sbr_env_frame->freq_res_fix = freq_res_fix;
1138   pstr_sbr_env_frame->use_low_freq_res = use_low_freq_res;
1139 
1140   pstr_sbr_env_frame->length_v_bord = 0;
1141   pstr_sbr_env_frame->length_v_bord_follow = 0;
1142 
1143   pstr_sbr_env_frame->length_v_freq = 0;
1144   pstr_sbr_env_frame->length_v_freq_follow = 0;
1145 
1146   pstr_sbr_env_frame->i_tran_follow = 0;
1147   pstr_sbr_env_frame->i_fill_follow = 0;
1148 
1149   pstr_sbr_env_frame->dmin = 4;
1150   pstr_sbr_env_frame->dmax = 12;
1151 }
1152