• 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 <string.h>
21 #include "ixheaacd_type_def.h"
22 
23 #include "ixheaacd_constants.h"
24 
25 #include "ixheaacd_basic_ops32.h"
26 #include "ixheaacd_windows.h"
27 
ixheaacd_mult32_sh1(WORD32 a,WORD32 b)28 static PLATFORM_INLINE WORD32 ixheaacd_mult32_sh1(WORD32 a, WORD32 b) {
29   WORD32 result;
30   WORD64 temp_result;
31 
32   temp_result = (WORD64)a * (WORD64)b;
33   result = (WORD32)(temp_result >> 31);
34 
35   return (result);
36 }
37 
ixheaacd_memset(FLOAT32 * x,WORD32 n)38 VOID ixheaacd_memset(FLOAT32 *x, WORD32 n) {
39   memset(x, 0, n * sizeof(FLOAT32));
40   return;
41 }
42 
ixheaacd_mem_cpy(const FLOAT32 x[],FLOAT32 y[],WORD32 n)43 VOID ixheaacd_mem_cpy(const FLOAT32 x[], FLOAT32 y[], WORD32 n) {
44   memcpy(y, x, n * sizeof(FLOAT32));
45   return;
46 }
47 
ixheaacd_vec_cnst_mul(FLOAT32 a,FLOAT32 x[],FLOAT32 z[],WORD32 n)48 VOID ixheaacd_vec_cnst_mul(FLOAT32 a, FLOAT32 x[], FLOAT32 z[], WORD32 n) {
49   WORD32 i;
50   for (i = 0; i < n; i++) {
51     z[i] = (FLOAT32)a * x[i];
52   }
53   return;
54 }
55 
ixheaacd_combine_fac(WORD32 * src1,WORD32 * src2,WORD32 * dest,WORD32 len,WORD8 output_q,WORD8 fac_q)56 VOID ixheaacd_combine_fac(WORD32 *src1, WORD32 *src2, WORD32 *dest, WORD32 len,
57                           WORD8 output_q, WORD8 fac_q) {
58   WORD32 i;
59   if (fac_q > output_q) {
60     for (i = 0; i < len; i++) {
61       *dest = ixheaacd_add32_sat(*src1, ((*src2) >> (fac_q - output_q)));
62       dest++;
63       src1++;
64       src2++;
65     }
66   } else {
67     for (i = 0; i < len; i++) {
68       *dest = ixheaacd_add32_sat(
69           *src1, ixheaacd_shl32_sat((*src2), (output_q - fac_q)));
70       dest++;
71       src1++;
72       src2++;
73     }
74   }
75 }
76 
ixheaacd_windowing_long1(WORD32 * src1,WORD32 * src2,const WORD32 * win_fwd,const WORD32 * win_rev,WORD32 * dest,WORD32 vlen,WORD8 shift1,WORD8 shift2)77 WORD8 ixheaacd_windowing_long1(WORD32 *src1, WORD32 *src2,
78                                const WORD32 *win_fwd, const WORD32 *win_rev,
79                                WORD32 *dest, WORD32 vlen, WORD8 shift1,
80                                WORD8 shift2) {
81   WORD32 i;
82   WORD32 *rsrc2 = src2 + vlen - 1;
83 
84   if (shift1 > shift2) {
85     for (i = 0; i < vlen / 2; i++) {
86       *dest = ixheaacd_add32_sat(
87           ((ixheaacd_mult32_sh1(*src1, *win_fwd)) >> (shift1 - shift2)),
88           ixheaacd_mult32_sh1(*src2, *win_rev));
89       *(dest + (vlen - (2 * i)) - 1) = ixheaacd_add32_sat(
90           ((ixheaacd_mult32_sh1(ixheaacd_negate32_sat(*src1), *win_rev)) >>
91            (shift1 - shift2)),
92           ixheaacd_mult32_sh1(*rsrc2, *win_fwd));
93 
94       src1++;
95       src2++;
96       win_fwd++;
97       win_rev--;
98       rsrc2--;
99       dest++;
100     }
101     return (shift2);
102   } else {
103     for (i = 0; i < vlen / 2; i++) {
104       *dest = ixheaacd_add32_sat(
105           ixheaacd_mult32_sh1(*src1, *win_fwd),
106           ((ixheaacd_mult32_sh1(*src2, *win_rev)) >> (shift2 - shift1)));
107 
108       *(dest + (vlen - (2 * i)) - 1) = ixheaacd_add32_sat(
109           ixheaacd_mult32_sh1(ixheaacd_negate32_sat(*src1), *win_rev),
110           ((ixheaacd_mult32_sh1(*rsrc2, *win_fwd)) >> (shift2 - shift1)));
111       src1++;
112       src2++;
113       win_fwd++;
114       win_rev--;
115       rsrc2--;
116       dest++;
117     }
118     return (shift1);
119   }
120 }
121 
ixheaacd_windowing_long2(WORD32 * src1,const WORD32 * win_fwd,WORD32 * fac_data_out,WORD32 * over_lap,WORD32 * p_out_buffer,offset_lengths * ixheaacd_drc_offset,WORD8 shiftp,WORD8 shift_olap,WORD8 fac_q)122 WORD8 ixheaacd_windowing_long2(WORD32 *src1, const WORD32 *win_fwd,
123                                WORD32 *fac_data_out, WORD32 *over_lap,
124                                WORD32 *p_out_buffer,
125                                offset_lengths *ixheaacd_drc_offset,
126                                WORD8 shiftp, WORD8 shift_olap, WORD8 fac_q) {
127   WORD32 i;
128   WORD32 *dest = p_out_buffer;
129 
130   win_fwd += ixheaacd_drc_offset->lfac;
131 
132   if (shiftp > fac_q) {
133     if (shift_olap > fac_q) {
134       for (i = 0;
135            i < ixheaacd_drc_offset->n_flat_ls + ixheaacd_drc_offset->lfac;
136            i++) {
137         dest[i] = over_lap[i] >> (shift_olap - fac_q);
138       }
139 
140       for (i = ixheaacd_drc_offset->n_flat_ls + ixheaacd_drc_offset->lfac;
141            i < ixheaacd_drc_offset->n_flat_ls + ixheaacd_drc_offset->n_trans_ls;
142            i++) {
143         dest[i] = ixheaacd_add32_sat(
144             (ixheaacd_mult32_sh1(
145                  ixheaacd_negate32_sat(src1[ixheaacd_drc_offset->n_long / 2 +
146                                             ixheaacd_drc_offset->n_flat_ls +
147                                             ixheaacd_drc_offset->lfac - i - 1]),
148                  *win_fwd) >>
149              (shiftp - fac_q)),
150             (*fac_data_out));
151         win_fwd++;
152         fac_data_out++;
153       }
154 
155       for (;
156            i < ixheaacd_drc_offset->n_flat_ls + (ixheaacd_drc_offset->lfac * 3);
157            i++) {
158         dest[i] = ixheaacd_add32_sat(
159             (ixheaacd_negate32_sat(src1[ixheaacd_drc_offset->n_long / 2 +
160                                         ixheaacd_drc_offset->n_flat_ls +
161                                         ixheaacd_drc_offset->lfac - i - 1]) >>
162              (shiftp - fac_q)),
163             (*fac_data_out));
164         fac_data_out++;
165       }
166 
167       for (; i < ixheaacd_drc_offset->n_long; i++) {
168         dest[i] =
169             ixheaacd_negate32_sat(src1[ixheaacd_drc_offset->n_long / 2 +
170                                        ixheaacd_drc_offset->n_flat_ls +
171                                        ixheaacd_drc_offset->lfac - i - 1]) >>
172             (shiftp - fac_q);
173       }
174       return (fac_q);
175     } else {
176       memcpy(dest, over_lap, sizeof(WORD32) * (ixheaacd_drc_offset->n_flat_ls +
177                                                ixheaacd_drc_offset->lfac));
178 
179       for (i = ixheaacd_drc_offset->n_flat_ls + ixheaacd_drc_offset->lfac;
180            i < ixheaacd_drc_offset->n_flat_ls + ixheaacd_drc_offset->n_trans_ls;
181            i++) {
182         dest[i] = ixheaacd_add32_sat(
183             (ixheaacd_mult32_sh1(
184                  ixheaacd_negate32_sat(src1[ixheaacd_drc_offset->n_long / 2 +
185                                             ixheaacd_drc_offset->n_flat_ls +
186                                             ixheaacd_drc_offset->lfac - i - 1]),
187                  *win_fwd) >>
188              (shiftp - shift_olap)),
189             (*fac_data_out) >> (fac_q - shift_olap));
190         win_fwd++;
191         fac_data_out++;
192       }
193 
194       for (;
195            i < ixheaacd_drc_offset->n_flat_ls + (ixheaacd_drc_offset->lfac * 3);
196            i++) {
197         dest[i] = ixheaacd_add32_sat(
198             (ixheaacd_negate32_sat(src1[ixheaacd_drc_offset->n_long / 2 +
199                                         ixheaacd_drc_offset->n_flat_ls +
200                                         ixheaacd_drc_offset->lfac - i - 1]) >>
201              (shiftp - shift_olap)),
202             (*fac_data_out) >> (fac_q - shift_olap));
203         fac_data_out++;
204       }
205 
206       for (; i < ixheaacd_drc_offset->n_long; i++) {
207         dest[i] =
208             ixheaacd_negate32_sat(src1[ixheaacd_drc_offset->n_long / 2 +
209                                        ixheaacd_drc_offset->n_flat_ls +
210                                        ixheaacd_drc_offset->lfac - i - 1]) >>
211             (shiftp - shift_olap);
212       }
213       return (shift_olap);
214     }
215   } else {
216     if (shift_olap > shiftp) {
217       for (i = 0;
218            i < ixheaacd_drc_offset->n_flat_ls + ixheaacd_drc_offset->lfac;
219            i++) {
220         dest[i] = over_lap[i] >> (shift_olap - shiftp);
221       }
222 
223       for (i = ixheaacd_drc_offset->n_flat_ls + ixheaacd_drc_offset->lfac;
224            i < ixheaacd_drc_offset->n_flat_ls + ixheaacd_drc_offset->n_trans_ls;
225            i++) {
226         dest[i] = ixheaacd_add32_sat(
227             ixheaacd_mult32_sh1(
228                 ixheaacd_negate32_sat(src1[ixheaacd_drc_offset->n_long / 2 +
229                                            ixheaacd_drc_offset->n_flat_ls +
230                                            ixheaacd_drc_offset->lfac - i - 1]),
231                 *win_fwd),
232             (*fac_data_out) >> (fac_q - shiftp));
233         win_fwd++;
234         fac_data_out++;
235       }
236 
237       for (;
238            i < ixheaacd_drc_offset->n_flat_ls + (ixheaacd_drc_offset->lfac * 3);
239            i++) {
240         dest[i] = ixheaacd_add32_sat(
241             ixheaacd_negate32_sat(src1[ixheaacd_drc_offset->n_long / 2 +
242                                        ixheaacd_drc_offset->n_flat_ls +
243                                        ixheaacd_drc_offset->lfac - i - 1]),
244             (*fac_data_out) >> (fac_q - shiftp));
245         fac_data_out++;
246       }
247 
248       for (; i < ixheaacd_drc_offset->n_long; i++) {
249         dest[i] =
250             ixheaacd_negate32_sat(src1[ixheaacd_drc_offset->n_long / 2 +
251                                        ixheaacd_drc_offset->n_flat_ls +
252                                        ixheaacd_drc_offset->lfac - i - 1]);
253       }
254       return (shiftp);
255     } else {
256       memcpy(dest, over_lap, sizeof(WORD32) * (ixheaacd_drc_offset->n_flat_ls +
257                                                ixheaacd_drc_offset->lfac));
258 
259       for (i = ixheaacd_drc_offset->n_flat_ls + ixheaacd_drc_offset->lfac;
260            i < ixheaacd_drc_offset->n_flat_ls + ixheaacd_drc_offset->n_trans_ls;
261            i++) {
262         dest[i] = ixheaacd_add32_sat(
263             (ixheaacd_mult32_sh1(
264                  ixheaacd_negate32_sat(src1[ixheaacd_drc_offset->n_long / 2 +
265                                             ixheaacd_drc_offset->n_flat_ls +
266                                             ixheaacd_drc_offset->lfac - i - 1]),
267                  *win_fwd) >>
268              (shiftp - shift_olap)),
269             (*fac_data_out) >> (fac_q - shift_olap));
270         win_fwd++;
271         fac_data_out++;
272       }
273 
274       for (;
275            i < ixheaacd_drc_offset->n_flat_ls + (ixheaacd_drc_offset->lfac * 3);
276            i++) {
277         dest[i] = ixheaacd_add32_sat(
278             (ixheaacd_negate32_sat(src1[ixheaacd_drc_offset->n_long / 2 +
279                                         ixheaacd_drc_offset->n_flat_ls +
280                                         ixheaacd_drc_offset->lfac - i - 1]) >>
281              (shiftp - shift_olap)),
282             (*fac_data_out) >> (fac_q - shift_olap));
283         fac_data_out++;
284       }
285 
286       for (; i < ixheaacd_drc_offset->n_long; i++) {
287         dest[i] =
288             ixheaacd_negate32_sat(src1[ixheaacd_drc_offset->n_long / 2 +
289                                        ixheaacd_drc_offset->n_flat_ls +
290                                        ixheaacd_drc_offset->lfac - i - 1]) >>
291             (shiftp - shift_olap);
292       }
293       return (shift_olap);
294     }
295   }
296 }
297 
ixheaacd_windowing_long3(WORD32 * src1,const WORD32 * win_fwd,WORD32 * over_lap,WORD32 * p_out_buffer,const WORD32 * win_rev,offset_lengths * ixheaacd_drc_offset,WORD8 shiftp,WORD8 shift_olap)298 WORD8 ixheaacd_windowing_long3(WORD32 *src1, const WORD32 *win_fwd,
299                                WORD32 *over_lap, WORD32 *p_out_buffer,
300                                const WORD32 *win_rev,
301                                offset_lengths *ixheaacd_drc_offset,
302                                WORD8 shiftp, WORD8 shift_olap) {
303   WORD32 i;
304   WORD32 *dest = p_out_buffer;
305 
306   if (shiftp > shift_olap) {
307     memcpy(dest, over_lap, sizeof(FLOAT32) * ixheaacd_drc_offset->n_flat_ls);
308 
309     for (i = ixheaacd_drc_offset->n_flat_ls;
310          i < ixheaacd_drc_offset->n_long / 2; i++) {
311       dest[i] = ixheaacd_add32_sat(
312           (ixheaacd_mult32_sh1(src1[i], *win_fwd) >> (shiftp - shift_olap)),
313           ixheaacd_mult32_sh1(over_lap[i], *win_rev));
314       win_fwd++;
315       win_rev--;
316     }
317 
318     for (i = ixheaacd_drc_offset->n_long / 2;
319          i < ixheaacd_drc_offset->n_flat_ls + ixheaacd_drc_offset->n_trans_ls;
320          i++) {
321       dest[i] = ixheaacd_add32_sat(
322           (ixheaacd_mult32_sh1(
323                ixheaacd_negate32_sat(src1[ixheaacd_drc_offset->n_long - i - 1]),
324                *win_fwd) >>
325            (shiftp - shift_olap)),
326           ixheaacd_mult32_sh1(over_lap[i], *win_rev));
327       win_fwd++;
328       win_rev--;
329     }
330 
331     for (; i < ixheaacd_drc_offset->n_long; i++) {
332       dest[i] =
333           ixheaacd_negate32_sat(src1[ixheaacd_drc_offset->n_long - i - 1]) >>
334           (shiftp - shift_olap);
335     }
336 
337     return (shift_olap);
338   } else {
339     for (i = 0; i < ixheaacd_drc_offset->n_flat_ls; i++) {
340       dest[i] = over_lap[i] >> (shift_olap - shiftp);
341     }
342 
343     for (i = ixheaacd_drc_offset->n_flat_ls;
344          i < ixheaacd_drc_offset->n_long / 2; i++) {
345       dest[i] = ixheaacd_add32_sat(
346           ixheaacd_mult32_sh1(src1[i], *win_fwd),
347           ixheaacd_mult32_sh1(over_lap[i], *win_rev) >> (shift_olap - shiftp));
348       win_fwd++;
349       win_rev--;
350     }
351 
352     for (i = ixheaacd_drc_offset->n_long / 2;
353          i < ixheaacd_drc_offset->n_flat_ls + ixheaacd_drc_offset->n_trans_ls;
354          i++) {
355       dest[i] = ixheaacd_add32_sat(
356           ixheaacd_mult32_sh1(
357               ixheaacd_negate32_sat(src1[ixheaacd_drc_offset->n_long - i - 1]),
358               *win_fwd),
359           ixheaacd_mult32_sh1(over_lap[i], *win_rev) >> (shift_olap - shiftp));
360       win_fwd++;
361       win_rev--;
362     }
363 
364     for (; i < ixheaacd_drc_offset->n_long; i++) {
365       dest[i] =
366           ixheaacd_negate32_sat(src1[ixheaacd_drc_offset->n_long - i - 1]);
367     }
368 
369     return (shiftp);
370   }
371 }
372 
ixheaacd_windowing_short1(WORD32 * src1,WORD32 * src2,WORD32 * fp,offset_lengths * ixheaacd_drc_offset,WORD8 shiftp,WORD8 shift_olap)373 VOID ixheaacd_windowing_short1(WORD32 *src1, WORD32 *src2, WORD32 *fp,
374                                offset_lengths *ixheaacd_drc_offset,
375                                WORD8 shiftp, WORD8 shift_olap) {
376   WORD32 i;
377   WORD32 *dest = fp;
378 
379   if (shift_olap > shiftp) {
380     if (ixheaacd_drc_offset->n_short > ixheaacd_drc_offset->lfac) {
381       for (i = 0; i < ixheaacd_drc_offset->lfac; i++) {
382         dest[i] = dest[i] >> (shift_olap - shiftp);
383       }
384       for (i = ixheaacd_drc_offset->lfac; i < ixheaacd_drc_offset->n_short;
385            i++) {
386         dest[i] = ixheaacd_mult32_sh1(
387             ixheaacd_negate32_sat(src1[ixheaacd_drc_offset->n_short - i - 1]),
388             src2[i]);
389       }
390 
391       for (; i < ixheaacd_drc_offset->n_flat_ls + ixheaacd_drc_offset->lfac;
392            i++) {
393         dest[i] = 0;
394       }
395     } else {
396       for (i = 0; i < ixheaacd_drc_offset->lfac; i++) {
397         dest[i] = dest[i] >> (shift_olap - shiftp);
398       }
399       for (i = ixheaacd_drc_offset->lfac;
400            i < ixheaacd_drc_offset->n_flat_ls + ixheaacd_drc_offset->lfac;
401            i++) {
402         dest[i] = 0;
403       }
404     }
405   } else {
406     if (ixheaacd_drc_offset->n_short > ixheaacd_drc_offset->lfac) {
407       for (i = ixheaacd_drc_offset->lfac; i < ixheaacd_drc_offset->n_short;
408            i++) {
409         dest[i] =
410             ixheaacd_mult32_sh1(ixheaacd_negate32_sat(
411                                     src1[ixheaacd_drc_offset->n_short - i - 1]),
412                                 src2[i]) >>
413             (shiftp - shift_olap);
414       }
415 
416       for (; i < ixheaacd_drc_offset->n_flat_ls + ixheaacd_drc_offset->lfac;
417            i++) {
418         dest[i] = 0;
419       }
420     } else {
421       for (i = ixheaacd_drc_offset->lfac;
422            i < ixheaacd_drc_offset->n_flat_ls + ixheaacd_drc_offset->lfac;
423            i++) {
424         dest[i] = 0;
425       }
426     }
427   }
428 }
429 
ixheaacd_windowing_short2(WORD32 * src1,WORD32 * win_fwd,WORD32 * fp,offset_lengths * ixheaacd_drc_offset,WORD8 shiftp,WORD8 shift_olap)430 VOID ixheaacd_windowing_short2(WORD32 *src1, WORD32 *win_fwd, WORD32 *fp,
431                                offset_lengths *ixheaacd_drc_offset,
432                                WORD8 shiftp, WORD8 shift_olap) {
433   WORD32 i;
434 
435   WORD32 *win_rev = win_fwd + ixheaacd_drc_offset->n_short - 1;
436 
437   if (shift_olap > shiftp) {
438     for (i = 0; i < ixheaacd_drc_offset->n_short / 2; i++) {
439       fp[i] = ixheaacd_add32_sat(
440           ixheaacd_mult32_sh1(src1[i], *win_fwd),
441           (ixheaacd_mult32_sh1(fp[i], *win_rev) >> (shift_olap - shiftp)));
442 
443       fp[ixheaacd_drc_offset->n_short - i - 1] = ixheaacd_add32_sat(
444           ixheaacd_mult32_sh1(ixheaacd_negate32_sat(src1[i]), *win_rev),
445           (ixheaacd_mult32_sh1(fp[ixheaacd_drc_offset->n_short - i - 1],
446                                *win_fwd) >>
447            (shift_olap - shiftp)));
448       win_fwd++;
449       win_rev--;
450     }
451 
452     for (i = ixheaacd_drc_offset->n_short;
453          i < ixheaacd_drc_offset->n_flat_ls + ixheaacd_drc_offset->n_short;
454          i++) {
455       fp[i] = 0;
456     }
457   } else {
458     for (i = 0; i < ixheaacd_drc_offset->n_short / 2; i++) {
459       fp[i] = ixheaacd_add32_sat(
460           (ixheaacd_mult32_sh1(src1[i], *win_fwd) >> (shiftp - shift_olap)),
461           ixheaacd_mult32_sh1(fp[i], *win_rev));
462 
463       fp[ixheaacd_drc_offset->n_short - i - 1] = ixheaacd_add32_sat(
464           (ixheaacd_mult32_sh1(ixheaacd_negate32_sat(src1[i]), *win_rev) >>
465            (shiftp - shift_olap)),
466           ixheaacd_mult32_sh1(fp[ixheaacd_drc_offset->n_short - i - 1],
467                               *win_fwd));
468 
469       win_fwd++;
470       win_rev--;
471     }
472 
473     for (i = ixheaacd_drc_offset->n_short;
474          i < ixheaacd_drc_offset->n_flat_ls + ixheaacd_drc_offset->n_short;
475          i++) {
476       fp[i] = 0;
477     }
478   }
479 }
480 
ixheaacd_windowing_short3(WORD32 * src1,WORD32 * win_rev,WORD32 * fp,WORD32 n_short,WORD8 shiftp,WORD8 shift_olap)481 WORD8 ixheaacd_windowing_short3(WORD32 *src1, WORD32 *win_rev, WORD32 *fp,
482                                 WORD32 n_short, WORD8 shiftp,
483                                 WORD8 shift_olap) {
484   WORD32 i;
485   const WORD32 *win_fwd = win_rev - n_short + 1;
486   if (shift_olap > shiftp) {
487     for (i = 0; i < n_short / 2; i++) {
488       fp[i] = ixheaacd_add32_sat(
489           ixheaacd_mult32_sh1(ixheaacd_negate32_sat(src1[n_short / 2 - i - 1]),
490                               *win_rev),
491           (fp[i] >> (shift_olap - shiftp)));
492 
493       fp[n_short - i - 1] = ixheaacd_add32_sat(
494           ixheaacd_mult32_sh1(ixheaacd_negate32_sat(src1[n_short / 2 - i - 1]),
495                               *win_fwd),
496           (fp[n_short - i - 1] >> (shift_olap - shiftp)));
497       win_rev--;
498       win_fwd++;
499     }
500     return (shiftp);
501   } else {
502     for (i = 0; i < n_short / 2; i++) {
503       fp[i] = ixheaacd_add32_sat(
504           (ixheaacd_mult32_sh1(ixheaacd_negate32_sat(src1[n_short / 2 - i - 1]),
505                                *win_rev) >>
506            (shiftp - shift_olap)),
507           fp[i]);
508 
509       fp[n_short - i - 1] = ixheaacd_add32_sat(
510           (ixheaacd_mult32_sh1(ixheaacd_negate32_sat(src1[n_short / 2 - i - 1]),
511                                *win_fwd) >>
512            (shiftp - shift_olap)),
513           fp[n_short - i - 1]);
514 
515       win_rev--;
516       win_fwd++;
517     }
518     return (shift_olap);
519   }
520 }
521 
ixheaacd_windowing_short4(WORD32 * src1,WORD32 * win_fwd,WORD32 * fp,WORD32 * win_fwd1,WORD32 n_short,WORD32 flag,WORD8 shiftp,WORD8 shift_olap,WORD8 output_q)522 WORD8 ixheaacd_windowing_short4(WORD32 *src1, WORD32 *win_fwd, WORD32 *fp,
523                                 WORD32 *win_fwd1, WORD32 n_short, WORD32 flag,
524                                 WORD8 shiftp, WORD8 shift_olap,
525                                 WORD8 output_q) {
526   WORD32 i;
527   const WORD32 *win_rev = win_fwd + n_short - 1;
528   const WORD32 *win_rev1 = win_fwd1 - n_short + 1;
529   if (shift_olap > output_q) {
530     for (i = 0; i < n_short / 2; i++) {
531       fp[i] = ixheaacd_add32_sat(
532           ixheaacd_mult32_sh1(src1[n_short / 2 + i], *win_fwd) >>
533               (shiftp - output_q),
534           fp[i]);
535 
536       fp[n_short - i - 1] = ixheaacd_add32_sat(
537           ixheaacd_mult32_sh1(ixheaacd_negate32_sat(src1[n_short / 2 + i]),
538                               *win_rev) >>
539               (shiftp - output_q),
540           fp[n_short - i - 1]);
541 
542       win_fwd++;
543       win_rev--;
544     }
545     if (flag == 1) {
546       for (; i < n_short; i++) {
547         fp[i + n_short / 2] = ixheaacd_add32_sat(
548             ixheaacd_mult32_sh1(ixheaacd_negate32_sat(src1[n_short - i - 1]),
549                                 *win_fwd1) >>
550                 (shiftp - output_q),
551             (fp[i + n_short / 2] >> (shift_olap - output_q)));
552 
553         fp[3 * n_short - n_short / 2 - i - 1] = ixheaacd_add32_sat(
554             ixheaacd_mult32_sh1(ixheaacd_negate32_sat(src1[n_short - i - 1]),
555                                 *win_rev1) >>
556                 (shiftp - output_q),
557             (fp[3 * n_short - n_short / 2 - i - 1] >> (shift_olap - output_q)));
558 
559         win_fwd1--;
560         win_rev1++;
561       }
562     } else {
563       for (; i < n_short; i++) {
564         fp[i + n_short / 2] = ixheaacd_add32_sat(
565             ixheaacd_negate32_sat(src1[n_short - i - 1]) >> (shiftp - output_q),
566             fp[i + n_short / 2] >> (shift_olap - output_q));
567         fp[3 * n_short - n_short / 2 - i - 1] = ixheaacd_add32_sat(
568             ixheaacd_negate32_sat(src1[n_short - i - 1]) >> (shiftp - output_q),
569             fp[3 * n_short - n_short / 2 - i - 1] >> (shift_olap - output_q));
570       }
571     }
572     return (output_q);
573   } else {
574     for (i = 0; i < n_short / 2; i++) {
575       fp[i] = ixheaacd_add32_sat(
576           ixheaacd_mult32_sh1(src1[n_short / 2 + i], *win_fwd) >>
577               (shiftp - shift_olap),
578           fp[i] >> (output_q - shift_olap));
579 
580       fp[n_short - i - 1] = ixheaacd_add32_sat(
581           ixheaacd_mult32_sh1(ixheaacd_negate32_sat(src1[n_short / 2 + i]),
582                               *win_rev) >>
583               (shiftp - shift_olap),
584           fp[n_short - i - 1]);
585 
586       win_fwd++;
587       win_rev--;
588     }
589     if (flag == 1) {
590       for (; i < n_short; i++) {
591         fp[i + n_short / 2] = ixheaacd_add32_sat(
592             ixheaacd_mult32_sh1(ixheaacd_negate32_sat(src1[n_short - i - 1]),
593                                 *win_fwd1) >>
594                 (shiftp - shift_olap),
595             fp[i + n_short / 2]);
596 
597         fp[3 * n_short - n_short / 2 - i - 1] = ixheaacd_add32_sat(
598             ixheaacd_mult32_sh1(ixheaacd_negate32_sat(src1[n_short - i - 1]),
599                                 *win_rev1) >>
600                 (shiftp - shift_olap),
601             fp[3 * n_short - n_short / 2 - i - 1]);
602 
603         win_fwd1--;
604         win_rev1++;
605       }
606     } else {
607       for (; i < n_short; i++) {
608         fp[i + n_short / 2] =
609             ixheaacd_add32_sat(ixheaacd_negate32_sat(src1[n_short - i - 1]) >>
610                                    (shiftp - shift_olap),
611                                fp[i + n_short / 2]);
612         fp[3 * n_short - n_short / 2 - i - 1] =
613             ixheaacd_add32_sat(ixheaacd_negate32_sat(src1[n_short - i - 1]) >>
614                                    (shiftp - shift_olap),
615                                fp[3 * n_short - n_short / 2 - i - 1]);
616       }
617     }
618     return (shift_olap);
619   }
620 }
621 
ixheaacd_scale_down(WORD32 * dest,WORD32 * src,WORD32 len,WORD8 shift1,WORD8 shift2)622 VOID ixheaacd_scale_down(WORD32 *dest, WORD32 *src, WORD32 len, WORD8 shift1,
623                          WORD8 shift2) {
624   WORD32 i;
625   if (shift1 > shift2) {
626     for (i = 0; i < len; i++) {
627       *dest = *src >> (shift1 - shift2);
628       src++;
629       dest++;
630     }
631   } else {
632     for (i = 0; i < len; i++) {
633       *dest = ixheaacd_shl32_sat((*src), (shift2 - shift1));
634       src++;
635       dest++;
636     }
637   }
638 }
639 
ixheaacd_scale_down_adj(WORD32 * dest,WORD32 * src,WORD32 len,WORD8 shift1,WORD8 shift2)640 VOID ixheaacd_scale_down_adj(WORD32 *dest, WORD32 *src, WORD32 len,
641                              WORD8 shift1, WORD8 shift2) {
642   WORD32 i;
643   if (shift1 > shift2) {
644     for (i = 0; i < len; i++) {
645       *dest = ixheaacd_add32_sat((*src >> (shift1 - shift2)), ADJ_SCALE);
646       src++;
647       dest++;
648     }
649   } else {
650     for (i = 0; i < len; i++) {
651       *dest = ixheaacd_add32_sat(ixheaacd_shl32_sat((*src), (shift2 - shift1)),
652                                  ADJ_SCALE);
653       src++;
654       dest++;
655     }
656   }
657 }
658