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 <math.h>
22 #include "ixheaac_type_def.h"
23 #include "ixheaace_mps_common_fix.h"
24 #include "ixheaace_mps_defines.h"
25 #include "ixheaace_mps_common_define.h"
26
27 FLOAT32
ixheaace_mps_212_sum_up_cplx_pow_2_dim_2(ixheaace_cmplx_str inp[MAX_ANA_TIME_SLOT][MAX_QMF_BANDS],const WORD32 start_dim_1,const WORD32 stop_dim_1,const WORD32 start_dim_2,const WORD32 stop_dim_2)28 ixheaace_mps_212_sum_up_cplx_pow_2_dim_2(ixheaace_cmplx_str inp[MAX_ANA_TIME_SLOT][MAX_QMF_BANDS],
29 const WORD32 start_dim_1, const WORD32 stop_dim_1,
30 const WORD32 start_dim_2, const WORD32 stop_dim_2) {
31 WORD32 idx_1, idx_2;
32
33 FLOAT32 sum;
34 sum = 0.0f;
35 for (idx_1 = start_dim_1; idx_1 < stop_dim_1; idx_1++) {
36 for (idx_2 = start_dim_2; idx_2 < stop_dim_2; idx_2++) {
37 sum += inp[idx_1][idx_2].re * inp[idx_1][idx_2].re;
38 sum += inp[idx_1][idx_2].im * inp[idx_1][idx_2].im;
39 }
40 }
41 return (sum / 2);
42 }
43
ixheaace_mps_212_cplx_scalar_product(ixheaace_cmplx_str * const out,ixheaace_cmplx_str inp_1[MAX_ANA_TIME_SLOT][MAX_QMF_BANDS],ixheaace_cmplx_str inp_2[MAX_ANA_TIME_SLOT][MAX_QMF_BANDS],const WORD32 start_dim_1,const WORD32 stop_dim_1,const WORD32 start_dim_2,const WORD32 stop_dim_2)44 VOID ixheaace_mps_212_cplx_scalar_product(
45 ixheaace_cmplx_str *const out, ixheaace_cmplx_str inp_1[MAX_ANA_TIME_SLOT][MAX_QMF_BANDS],
46 ixheaace_cmplx_str inp_2[MAX_ANA_TIME_SLOT][MAX_QMF_BANDS], const WORD32 start_dim_1,
47 const WORD32 stop_dim_1, const WORD32 start_dim_2, const WORD32 stop_dim_2) {
48 WORD32 idx_1, idx_2;
49 FLOAT32 re_x, re_y, im_x, im_y, re, im;
50 re = 0.0f;
51 im = 0.0f;
52
53 for (idx_1 = start_dim_1; idx_1 < stop_dim_1; idx_1++) {
54 for (idx_2 = start_dim_2; idx_2 < stop_dim_2; idx_2++) {
55 re_x = inp_1[idx_1][idx_2].re;
56 im_x = inp_1[idx_1][idx_2].im;
57 re_y = inp_2[idx_1][idx_2].re;
58 im_y = inp_2[idx_1][idx_2].im;
59 re += (re_x * re_y) + (im_x * im_y);
60 im += (im_x * re_y) - (re_x * im_y);
61 }
62 }
63
64 out->re = re / 2;
65 out->im = im / 2;
66 }
67
ixheaace_mps_212_sum_up_cplx_pow_2(const ixheaace_cmplx_str * const inp,const WORD32 len)68 FLOAT32 ixheaace_mps_212_sum_up_cplx_pow_2(const ixheaace_cmplx_str *const inp,
69 const WORD32 len) {
70 WORD32 idx;
71 FLOAT32 sum;
72 sum = 0.0f;
73
74 for (idx = 0; idx < len; idx++) {
75 sum += inp[idx].re * inp[idx].re;
76 sum += inp[idx].im * inp[idx].im;
77 }
78
79 return (sum / 2);
80 }
81