• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /******************************************************************************
2  *                                                                            *
3  * Copyright (C) 2018 The Android Open Source Project
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at:
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  *****************************************************************************
18  * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
19 */
20 #include <math.h>
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include <string.h>
24 
25 #include "ixheaacd_type_def.h"
26 #include "ixheaacd_interface.h"
27 
28 #include "ixheaacd_bitbuffer.h"
29 #include "ixheaacd_interface.h"
30 
31 #include "ixheaacd_tns_usac.h"
32 #include "ixheaacd_cnst.h"
33 #include "ixheaacd_acelp_info.h"
34 
35 #include "ixheaacd_td_mdct.h"
36 
37 #include "ixheaacd_sbrdecsettings.h"
38 #include "ixheaacd_info.h"
39 #include "ixheaacd_sbr_common.h"
40 #include "ixheaacd_drc_data_struct.h"
41 #include "ixheaacd_drc_dec.h"
42 #include "ixheaacd_sbrdecoder.h"
43 #include "ixheaacd_mps_polyphase.h"
44 #include "ixheaacd_sbr_const.h"
45 #include "ixheaacd_main.h"
46 #include "ixheaacd_arith_dec.h"
47 #include "ixheaacd_windows.h"
48 
49 #include "ixheaacd_vec_baisc_ops.h"
50 #include "ixheaacd_constants.h"
51 #include "ixheaacd_function_selector.h"
52 #include "ixheaacd_basic_ops32.h"
53 #include "ixheaacd_basic_ops40.h"
54 
55 #include "ixheaacd_func_def.h"
56 
57 #include "ixheaacd_windows.h"
58 
59 extern const WORD32 ixheaacd_pre_post_twid_cos_512[512];
60 extern const WORD32 ixheaacd_pre_post_twid_sin_512[512];
61 extern const WORD32 ixheaacd_pre_post_twid_cos_384[384];
62 extern const WORD32 ixheaacd_pre_post_twid_sin_384[384];
63 extern const WORD32 ixheaacd_pre_post_twid_cos_64[64];
64 extern const WORD32 ixheaacd_pre_post_twid_sin_64[64];
65 extern const WORD32 ixheaacd_pre_post_twid_cos_48[48];
66 extern const WORD32 ixheaacd_pre_post_twid_sin_48[48];
67 extern const FLOAT64 ixheaacd_power_10_table[28];
68 
69 #define ABS(A) ((A) < 0 ? (-A) : (A))
70 
ixheaacd_calc_max_spectralline(WORD32 * p_in_ibuffer,WORD32 n)71 static WORD32 ixheaacd_calc_max_spectralline(WORD32 *p_in_ibuffer, WORD32 n) {
72   WORD32 k, shiftp, itemp = 0;
73   for (k = 0; k < n; k++) {
74     if (ixheaacd_abs32_sat(p_in_ibuffer[k]) > itemp)
75       itemp = ixheaacd_abs32_sat(p_in_ibuffer[k]);
76   }
77 
78   shiftp = ixheaacd_norm32(itemp);
79 
80   return (shiftp);
81 }
82 
ixheaacd_normalize(WORD32 * buff,WORD32 shift,WORD len)83 static void ixheaacd_normalize(WORD32 *buff, WORD32 shift, WORD len) {
84   WORD32 i;
85 
86   for (i = 0; i < len; i++) {
87     buff[i] = buff[i] << shift;
88   }
89 }
90 
ixheaacd_pow10(WORD32 input)91 static FLOAT32 ixheaacd_pow10(WORD32 input) {
92   FLOAT32 output = 1;
93   while (input > 0) {
94     output *= 10;
95     input--;
96   }
97   return (output);
98 }
99 
ixheaacd_calc_pre_twid_dec(WORD32 * ptr_x,WORD32 * r_ptr,WORD32 * i_ptr,WORD32 nlength,const WORD32 * cos_ptr,const WORD32 * sin_ptr)100 void ixheaacd_calc_pre_twid_dec(WORD32 *ptr_x, WORD32 *r_ptr, WORD32 *i_ptr,
101                                 WORD32 nlength, const WORD32 *cos_ptr,
102                                 const WORD32 *sin_ptr) {
103   WORD32 i;
104   WORD32 *ptr_y;
105 
106   ptr_y = &ptr_x[2 * nlength - 1];
107 
108   for (i = 0; i < nlength; i++) {
109     *r_ptr++ = ((ixheaacd_mult32(ixheaacd_negate32_sat(*ptr_x), (*cos_ptr)) -
110                  ixheaacd_mult32((*ptr_y), (*sin_ptr))));
111     *i_ptr++ = ((ixheaacd_mult32((*ptr_y), (*cos_ptr++)) -
112                  ixheaacd_mult32((*ptr_x), (*sin_ptr++))));
113     ptr_x += 2;
114     ptr_y -= 2;
115   }
116 }
117 
ixheaacd_calc_post_twid_dec(WORD32 * xptr,WORD32 * r_ptr,WORD32 * i_ptr,WORD32 nlength,const WORD32 * cos_ptr,const WORD32 * sin_ptr)118 void ixheaacd_calc_post_twid_dec(WORD32 *xptr, WORD32 *r_ptr, WORD32 *i_ptr,
119                                  WORD32 nlength, const WORD32 *cos_ptr,
120                                  const WORD32 *sin_ptr
121 
122                                  ) {
123   WORD32 i;
124   WORD32 *yptr;
125 
126   yptr = &xptr[2 * nlength - 1];
127 
128   for (i = 0; i < nlength; i++) {
129     *xptr = (-(ixheaacd_mult32((r_ptr[i]), (*cos_ptr)) -
130                ixheaacd_mult32((i_ptr[i]), (*sin_ptr))));
131     *yptr = (-(ixheaacd_mult32((i_ptr[i]), (*cos_ptr++)) +
132                ixheaacd_mult32((r_ptr[i]), (*sin_ptr++))));
133     xptr += 2;
134     yptr -= 2;
135   }
136 }
137 
ixheaacd_fft_based_imdct(WORD32 * data,WORD32 npoints,WORD32 * preshift,WORD32 * tmp_data)138 static void ixheaacd_fft_based_imdct(WORD32 *data, WORD32 npoints,
139                                      WORD32 *preshift, WORD32 *tmp_data) {
140   WORD32 *data_r;
141   WORD32 *data_i;
142   WORD32 nlength = npoints >> 1;
143   const WORD32 *cos_ptr;
144   const WORD32 *sin_ptr;
145 
146   data_r = tmp_data;
147   data_i = tmp_data + 512;
148 
149   if (nlength == 512) {
150     cos_ptr = ixheaacd_pre_post_twid_cos_512;
151     sin_ptr = ixheaacd_pre_post_twid_sin_512;
152   } else if (nlength == 384) {
153     cos_ptr = ixheaacd_pre_post_twid_cos_384;
154     sin_ptr = ixheaacd_pre_post_twid_sin_384;
155   } else if (nlength == 64) {
156     cos_ptr = ixheaacd_pre_post_twid_cos_64;
157     sin_ptr = ixheaacd_pre_post_twid_sin_64;
158   } else if (nlength == 48) {
159     cos_ptr = ixheaacd_pre_post_twid_cos_48;
160     sin_ptr = ixheaacd_pre_post_twid_sin_48;
161   } else {
162     cos_ptr = ixheaacd_pre_post_twid_cos_48;
163     sin_ptr = ixheaacd_pre_post_twid_sin_48;
164   }
165 
166   (*ixheaacd_calc_pre_twid)(data, data_r, data_i, nlength, cos_ptr, sin_ptr);
167   ixheaacd_complex_fft(data_r, data_i, nlength, 1, preshift);
168   (*ixheaacd_calc_post_twid)(data, data_r, data_i, nlength, cos_ptr, sin_ptr);
169 }
170 
171 #define N_LONG_LEN_MAX 1024
172 
ixheaacd_acelp_imdct(WORD32 * imdct_in,WORD32 npoints,WORD8 * qshift,WORD32 * tmp_data)173 void ixheaacd_acelp_imdct(WORD32 *imdct_in, WORD32 npoints, WORD8 *qshift,
174                           WORD32 *tmp_data) {
175   WORD32 preshift = 0;
176   WORD32 i;
177   WORD32 k = (npoints / 2);
178 
179   while (((k & 1) == 0) & (k != 1)) {
180     k = k >> 1;
181     preshift++;
182   }
183 
184   if ((k != 1)) {
185     for (i = 0; i < (npoints / 2); i++) {
186       imdct_in[i] = (imdct_in[i] / 3) << 1;
187     }
188     preshift++;
189   }
190 
191   ixheaacd_fft_based_imdct(imdct_in, npoints / 2, &preshift, tmp_data);
192   preshift += 2;
193   *qshift -= preshift;
194 }
195 
ixheaacd_cal_fac_data(ia_usac_data_struct * usac_data,WORD32 i_ch,WORD32 n_long,WORD32 lfac,WORD32 * fac_idata)196 WORD8 ixheaacd_cal_fac_data(ia_usac_data_struct *usac_data, WORD32 i_ch,
197                             WORD32 n_long, WORD32 lfac, WORD32 *fac_idata) {
198   WORD32 gain_fac, scale, k, *i_aq, itemp = 0, *izir;
199   WORD32 int_aq[ORDER + 1] = {0};
200   WORD32 intzir[2 * LEN_FRAME] = {0};
201   WORD32 x_in[FAC_LENGTH] = {0};
202   FLOAT32 gain, ztemp, ftemp, pow10, rem10;
203   FLOAT32 qfac1;
204   WORD8 qshift1 = 0;
205   WORD8 qshift2 = 0;
206   WORD8 qshift3 = 0;
207   WORD32 preshift = 0;
208 
209   FLOAT32 *last_lpc = usac_data->lpc_prev[i_ch];
210   FLOAT32 *acelp_in = usac_data->acelp_in[i_ch];
211   WORD32 *fac_data = usac_data->fac_data[i_ch];
212   WORD32 *ptr_scratch = &usac_data->scratch_buffer[0];
213 
214   WORD32 quo = fac_data[0] / 28;
215   WORD32 rem = fac_data[0] % 28;
216   pow10 = ixheaacd_pow10(quo);
217   rem10 = (FLOAT32)ixheaacd_power_10_table[rem];
218 
219   gain = pow10 * rem10;
220   scale = (WORD32)(ixheaacd_norm32((WORD32)((ABS(gain) + 1))));
221   gain_fac = (WORD32)(gain * (FLOAT32)((WORD64)1 << scale));
222   scale += 4;
223   qfac1 = 1.0f / (gain);
224 
225   if (acelp_in != NULL) {
226     izir = intzir;
227     ftemp = 0.0;
228     for (k = 0; k < n_long / 4; k++) {
229       ztemp = acelp_in[k] * (qfac1);
230       if (ABS(ztemp) > ftemp) ftemp = ABS(ztemp);
231     }
232 
233     itemp = (WORD32)(ftemp);
234     qshift3 = ixheaacd_norm32(itemp);
235 
236     for (k = 0; k < n_long / 4; k++) {
237       izir[k] =
238           (WORD32)((acelp_in[k] * (qfac1)) * (FLOAT32)((WORD64)1 << qshift3));
239     }
240   } else
241     izir = NULL;
242 
243   if (last_lpc != NULL) {
244     ftemp = 0.0;
245     i_aq = int_aq;
246     for (k = 0; k < ORDER + 1; k++) {
247       if (ABS(last_lpc[k]) > ftemp) ftemp = ABS(last_lpc[k]);
248     }
249 
250     itemp = (WORD32)(ftemp);
251     qshift2 = ixheaacd_norm32(itemp);
252 
253     for (k = 0; k < ORDER + 1; k++) {
254       i_aq[k] = (WORD32)(last_lpc[k] * (FLOAT32)((WORD64)1 << qshift2));
255     }
256   } else
257     i_aq = NULL;
258 
259   for (k = 0; k < lfac; k++) {
260     if (ixheaacd_abs32_sat(fac_data[k + 1]) > itemp)
261       itemp = ixheaacd_abs32_sat(fac_data[k + 1]);
262   }
263 
264   qshift1 = ixheaacd_norm32(itemp);
265 
266   for (k = 0; k < lfac; k++) {
267     fac_data[k + 1] =
268         (WORD32)(fac_data[k + 1] * (FLOAT32)((WORD64)1 << qshift1));
269   }
270 
271   for (k = 0; k < lfac / 2; k++) {
272     x_in[k] = fac_data[2 * k + 1];
273     x_in[lfac / 2 + k] = fac_data[lfac - 2 * k];
274   }
275 
276   ixheaacd_fr_alias_cnx_fix(x_in, n_long / 4, lfac, i_aq, izir, fac_idata + 16,
277                             &qshift1, qshift2, qshift3, &preshift, ptr_scratch);
278   preshift += 4;
279 
280   if (acelp_in != NULL) {
281     for (k = 0; k < 2 * lfac; k++) {
282       fac_idata[k] =
283           ixheaacd_mul32_sh(fac_idata[k + 16], gain_fac, (WORD8)(scale));
284     }
285   }
286   return (qshift1 - preshift);
287 }
288 
ixheaacd_fd_imdct_short(ia_usac_data_struct * usac_data,WORD32 i_ch,WORD32 * fac_data_out,offset_lengths * ixheaacd_drc_offset,WORD8 fac_q)289 static WORD32 ixheaacd_fd_imdct_short(ia_usac_data_struct *usac_data,
290                                       WORD32 i_ch, WORD32 *fac_data_out,
291                                       offset_lengths *ixheaacd_drc_offset,
292                                       WORD8 fac_q) {
293   FLOAT32 qfac;
294   WORD32 overlap_data_buf[2 * N_LONG_LEN_MAX] = {0};
295   WORD32 *window_short, k, *window_short_prev_ptr;
296   WORD32 *overlap_data, *fp;
297 
298   WORD32 *p_overlap_ibuffer = usac_data->overlap_data_ptr[i_ch];
299   WORD32 *p_in_ibuffer = usac_data->coef_fix[i_ch];
300   FLOAT32 *p_out_buffer = usac_data->time_sample_vector[i_ch];
301   WORD32 *p_out_ibuffer = usac_data->output_data_ptr[i_ch];
302   WORD32 *scratch_mem = usac_data->scratch_buffer;
303   WORD32 td_frame_prev = usac_data->td_frame_prev[i_ch];
304   WORD32 fac_apply = usac_data->fac_data_present[i_ch];
305   WORD8 shiftp, input_q, output_q, shift_olap = 14;
306   WORD32 max_shift;
307 
308   WORD32 window_select = usac_data->window_shape[i_ch];
309   WORD32 window_select_prev = usac_data->window_shape_prev[i_ch];
310   ia_usac_lpd_decoder_handle st = usac_data->str_tddec[i_ch];
311   WORD32 err_code = 0;
312 
313   max_shift =
314       ixheaacd_calc_max_spectralline(p_in_ibuffer, ixheaacd_drc_offset->n_long);
315   ixheaacd_normalize(p_in_ibuffer, max_shift, ixheaacd_drc_offset->n_long);
316   shiftp = max_shift + 6;
317   input_q = shiftp;
318 
319   memcpy(overlap_data_buf, p_overlap_ibuffer,
320          sizeof(WORD32) * ixheaacd_drc_offset->n_long);
321   overlap_data = overlap_data_buf;
322 
323   fp = overlap_data + ixheaacd_drc_offset->n_flat_ls;
324 
325   for (k = 0; k < 8; k++) {
326     shiftp = input_q;
327     ixheaacd_acelp_imdct(p_in_ibuffer + (k * ixheaacd_drc_offset->n_short),
328                          2 * ixheaacd_drc_offset->n_short, &shiftp,
329                          scratch_mem);
330   }
331 
332   max_shift =
333       ixheaacd_calc_max_spectralline(p_in_ibuffer, ixheaacd_drc_offset->n_long);
334   ixheaacd_normalize(p_in_ibuffer, max_shift - 1, ixheaacd_drc_offset->n_long);
335   shiftp += max_shift - 1;
336 
337   err_code = ixheaacd_calc_window(&window_short, ixheaacd_drc_offset->n_short,
338                                   window_select);
339   if (err_code == -1) return err_code;
340   err_code =
341       ixheaacd_calc_window(&window_short_prev_ptr,
342                            ixheaacd_drc_offset->n_trans_ls, window_select_prev);
343   if (err_code == -1) return err_code;
344 
345   if (fac_apply)
346     ixheaacd_windowing_short1(p_in_ibuffer + ixheaacd_drc_offset->n_short / 2,
347                               window_short_prev_ptr, fp, ixheaacd_drc_offset,
348                               shiftp, shift_olap);
349 
350   else
351     ixheaacd_windowing_short2(p_in_ibuffer + ixheaacd_drc_offset->n_short / 2,
352                               window_short_prev_ptr, fp, ixheaacd_drc_offset,
353                               shiftp, shift_olap);
354 
355   output_q = ixheaacd_windowing_short3(
356       p_in_ibuffer, window_short + ixheaacd_drc_offset->n_short - 1,
357       fp + ixheaacd_drc_offset->n_short, ixheaacd_drc_offset->n_short, shiftp,
358       shift_olap);
359   p_in_ibuffer += ixheaacd_drc_offset->n_short;
360   fp += ixheaacd_drc_offset->n_short;
361   window_short_prev_ptr = window_short;
362 
363   for (k = 1; k < 7; k++) {
364     output_q = ixheaacd_windowing_short4(
365         p_in_ibuffer, window_short_prev_ptr, fp,
366         window_short_prev_ptr + ixheaacd_drc_offset->n_short - 1,
367         ixheaacd_drc_offset->n_short, 1, shiftp, shift_olap, output_q);
368     p_in_ibuffer += ixheaacd_drc_offset->n_short;
369     fp += ixheaacd_drc_offset->n_short;
370     window_short_prev_ptr = window_short;
371   }
372 
373   output_q = ixheaacd_windowing_short4(
374       p_in_ibuffer, window_short_prev_ptr, fp,
375       window_short_prev_ptr + ixheaacd_drc_offset->n_short - 1,
376       ixheaacd_drc_offset->n_short, 0, shiftp, shift_olap, output_q);
377   p_in_ibuffer += ixheaacd_drc_offset->n_short;
378   fp += ixheaacd_drc_offset->n_short;
379 
380   if (fac_apply) {
381     ixheaacd_combine_fac(overlap_data + ixheaacd_drc_offset->n_flat_ls +
382                              ixheaacd_drc_offset->lfac,
383                          fac_data_out,
384                          overlap_data + ixheaacd_drc_offset->n_flat_ls +
385                              ixheaacd_drc_offset->lfac,
386                          2 * ixheaacd_drc_offset->lfac, output_q, fac_q);
387   }
388   memset(overlap_data + 2 * ixheaacd_drc_offset->n_long -
389              ixheaacd_drc_offset->n_flat_ls,
390          0, sizeof(WORD32) * ixheaacd_drc_offset->n_flat_ls);
391   ixheaacd_scale_down(overlap_data, overlap_data,
392                       ixheaacd_drc_offset->n_flat_ls, shift_olap, output_q);
393 
394   ixheaacd_scale_down(p_overlap_ibuffer,
395                       overlap_data + ixheaacd_drc_offset->n_long,
396                       ixheaacd_drc_offset->n_long, output_q, shift_olap);
397   ixheaacd_scale_down(p_out_ibuffer, overlap_data, ixheaacd_drc_offset->n_long,
398                       output_q, 15);
399 
400   if (td_frame_prev) {
401     qfac = 1.0f / (FLOAT32)(1 << 15);
402 
403     for (k = 0; k < ixheaacd_drc_offset->n_long; k++) {
404       p_out_buffer[k] = ((FLOAT32)p_out_ibuffer[k]) * qfac;
405     }
406     err_code = ixheaacd_lpd_bpf_fix(usac_data, 1, p_out_buffer, st);
407     if (err_code != 0) return err_code;
408 
409     for (k = 0; k < ixheaacd_drc_offset->n_long; k++) {
410       p_out_ibuffer[k] = (WORD32)(p_out_buffer[k] * (1 << 15));
411     }
412   }
413 
414   return 0;
415 }
416 
ixheaacd_fd_imdct_long(ia_usac_data_struct * usac_data,WORD32 i_ch,WORD32 * fac_idata,offset_lengths * ixheaacd_drc_offset,WORD8 fac_q)417 static WORD32 ixheaacd_fd_imdct_long(ia_usac_data_struct *usac_data,
418                                      WORD32 i_ch, WORD32 *fac_idata,
419                                      offset_lengths *ixheaacd_drc_offset,
420                                      WORD8 fac_q) {
421   FLOAT32 qfac;
422   WORD32 *window_long_prev, k, i, *window_short_prev_ptr;
423 
424   WORD32 *p_in_ibuffer = usac_data->coef_fix[i_ch];
425   WORD32 *p_overlap_ibuffer = usac_data->overlap_data_ptr[i_ch];
426   WORD32 *p_out_ibuffer = usac_data->output_data_ptr[i_ch];
427   FLOAT32 *p_out_buffer = usac_data->time_sample_vector[i_ch];
428   WORD32 *scratch_mem = usac_data->scratch_buffer;
429   WORD32 n_long = usac_data->ccfl;
430   WORD32 td_frame_prev = usac_data->td_frame_prev[i_ch];
431   WORD32 fac_apply = usac_data->fac_data_present[i_ch];
432   WORD8 shiftp, output_q = 0, shift_olap = 14;
433   WORD32 max_shift;
434 
435   WORD32 window_sequence = usac_data->window_sequence[i_ch];
436   WORD32 window_select_prev = usac_data->window_shape_prev[i_ch];
437   ia_usac_lpd_decoder_handle st = usac_data->str_tddec[i_ch];
438 
439   WORD32 err_code = 0;
440 
441   max_shift =
442       ixheaacd_calc_max_spectralline(p_in_ibuffer, ixheaacd_drc_offset->n_long);
443   ixheaacd_normalize(p_in_ibuffer, max_shift, ixheaacd_drc_offset->n_long);
444   shiftp = max_shift + 6;
445 
446   ixheaacd_acelp_imdct(p_in_ibuffer, 2 * ixheaacd_drc_offset->n_long, &shiftp,
447                        scratch_mem);
448 
449   max_shift =
450       ixheaacd_calc_max_spectralline(p_in_ibuffer, ixheaacd_drc_offset->n_long);
451   ixheaacd_normalize(p_in_ibuffer, max_shift - 1, ixheaacd_drc_offset->n_long);
452   shiftp += max_shift - 1;
453 
454   switch (window_sequence) {
455     case ONLY_LONG_SEQUENCE:
456     case LONG_START_SEQUENCE:
457       err_code = ixheaacd_calc_window(
458           &window_long_prev, ixheaacd_drc_offset->n_long, window_select_prev);
459       if (err_code == -1) return err_code;
460       output_q = ixheaacd_windowing_long1(
461           p_in_ibuffer + n_long / 2, p_overlap_ibuffer, window_long_prev,
462           window_long_prev + ixheaacd_drc_offset->n_long - 1, p_out_ibuffer,
463           ixheaacd_drc_offset->n_long, shiftp, shift_olap);
464       break;
465 
466     case STOP_START_SEQUENCE:
467     case LONG_STOP_SEQUENCE:
468       err_code = ixheaacd_calc_window(&window_short_prev_ptr,
469                                       ixheaacd_drc_offset->n_trans_ls,
470                                       window_select_prev);
471       if (err_code == -1) return err_code;
472       if (fac_apply) {
473         output_q = ixheaacd_windowing_long2(
474             p_in_ibuffer + n_long / 2, window_short_prev_ptr, fac_idata,
475             p_overlap_ibuffer, p_out_ibuffer, ixheaacd_drc_offset, shiftp,
476             shift_olap, fac_q);
477       } else {
478         output_q = ixheaacd_windowing_long3(
479             p_in_ibuffer + n_long / 2, window_short_prev_ptr, p_overlap_ibuffer,
480             p_out_ibuffer,
481             window_short_prev_ptr + ixheaacd_drc_offset->n_trans_ls - 1,
482             ixheaacd_drc_offset, shiftp, shift_olap);
483       }
484       break;
485   }
486 
487   for (i = 0; i < ixheaacd_drc_offset->n_long / 2; i++) {
488     p_overlap_ibuffer[ixheaacd_drc_offset->n_long / 2 + i] =
489         ixheaacd_negate32_sat(p_in_ibuffer[i]) >> (shiftp - shift_olap);
490     p_overlap_ibuffer[ixheaacd_drc_offset->n_long / 2 - i - 1] =
491         ixheaacd_negate32_sat(p_in_ibuffer[i]) >> (shiftp - shift_olap);
492   }
493 
494   ixheaacd_scale_down_adj(p_out_ibuffer, p_out_ibuffer,
495                           ixheaacd_drc_offset->n_long, output_q, 15);
496 
497   if (td_frame_prev) {
498     qfac = 1.0f / (FLOAT32)(1 << 15);
499 
500     for (k = 0; k < ixheaacd_drc_offset->n_long; k++) {
501       p_out_buffer[k] = ((FLOAT32)p_out_ibuffer[k]) * qfac;
502     }
503     err_code = ixheaacd_lpd_bpf_fix(usac_data, 0, p_out_buffer, st);
504     if (err_code != 0) return err_code;
505 
506     for (k = 0; k < ixheaacd_drc_offset->n_long; k++) {
507       p_out_ibuffer[k] = (WORD32)(p_out_buffer[k] * (1 << 15));
508     }
509   }
510 
511   return 0;
512 }
513 
ixheaacd_fd_frm_dec(ia_usac_data_struct * usac_data,WORD32 i_ch)514 WORD32 ixheaacd_fd_frm_dec(ia_usac_data_struct *usac_data, WORD32 i_ch) {
515   WORD32 fac_idata[2 * FAC_LENGTH + 16];
516   offset_lengths ixheaacd_drc_offset;
517   WORD8 fac_q = 0;
518   WORD32 td_frame_prev = usac_data->td_frame_prev[i_ch];
519   WORD32 fac_apply = usac_data->fac_data_present[i_ch];
520   WORD32 window_sequence = usac_data->window_sequence[i_ch];
521   ixheaacd_drc_offset.n_long = usac_data->ccfl;
522   ixheaacd_drc_offset.n_short = ixheaacd_drc_offset.n_long >> 3;
523 
524   memset(fac_idata, 0, sizeof(fac_idata));
525 
526   if (td_frame_prev) {
527     if (window_sequence == EIGHT_SHORT_SEQUENCE) {
528       ixheaacd_drc_offset.lfac = ixheaacd_drc_offset.n_long >> 4;
529     } else {
530       ixheaacd_drc_offset.lfac = ixheaacd_drc_offset.n_long >> 3;
531     }
532     ixheaacd_drc_offset.n_flat_ls =
533         (ixheaacd_drc_offset.n_long - (ixheaacd_drc_offset.lfac) * 2) >> 1;
534 
535     ixheaacd_drc_offset.n_trans_ls = (ixheaacd_drc_offset.lfac) << 1;
536   } else {
537     ixheaacd_drc_offset.lfac = FAC_LENGTH;
538     ixheaacd_drc_offset.n_flat_ls =
539         (ixheaacd_drc_offset.n_long - ixheaacd_drc_offset.n_short) >> 1;
540     ixheaacd_drc_offset.n_trans_ls = ixheaacd_drc_offset.n_short;
541   }
542 
543   if (fac_apply)
544     fac_q = ixheaacd_cal_fac_data(usac_data, i_ch, ixheaacd_drc_offset.n_long,
545                                   ixheaacd_drc_offset.lfac, fac_idata);
546 
547   if (window_sequence != EIGHT_SHORT_SEQUENCE)
548     ixheaacd_fd_imdct_long(usac_data, i_ch, fac_idata, &ixheaacd_drc_offset,
549                            fac_q);
550 
551   else
552     ixheaacd_fd_imdct_short(usac_data, i_ch, fac_idata, &ixheaacd_drc_offset,
553                             fac_q);
554 
555   return 0;
556 }
557