/src/libxaac/encoder/ixheaace_mps_qmf.c
Line | Count | Source (jump to first uncovered line) |
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 | | #include <stdlib.h> |
23 | | #include "ixheaac_type_def.h" |
24 | | #include "ixheaac_error_standards.h" |
25 | | #include "ixheaace_error_codes.h" |
26 | | #include "ixheaace_mps_common_fix.h" |
27 | | #include "ixheaace_mps_defines.h" |
28 | | #include "ixheaace_mps_common_define.h" |
29 | | #include "ixheaace_mps_buf.h" |
30 | | #include "ixheaace_mps_lib.h" |
31 | | #include "ixheaace_mps_main_structure.h" |
32 | | #include "ixheaace_mps_tools_rom.h" |
33 | | #include "ixheaace_mps_dct.h" |
34 | | #include "ixheaace_mps_qmf.h" |
35 | | #include "ixheaac_constants.h" |
36 | | #include "ixheaac_basic_ops32.h" |
37 | | #include "ixheaac_basic_ops40.h" |
38 | | #include "ixheaac_basic_ops.h" |
39 | | |
40 | | static IA_ERRORCODE ixheaace_mps_212_qmf_forward_modulation_hq( |
41 | | ixheaace_mps_pstr_qmf_filter_bank pstr_qmf_filter_bank, const FLOAT32 *time_in, |
42 | 5.80M | FLOAT32 *real_subband, FLOAT32 *imag_subband, WORD8 *ptr_scratch) { |
43 | 5.80M | IA_ERRORCODE error; |
44 | 5.80M | WORD32 idx; |
45 | 5.80M | WORD32 qmf_bands = pstr_qmf_filter_bank->no_channels; |
46 | 5.80M | WORD32 qmf_bands_by_2 = qmf_bands << 1; |
47 | 5.80M | FLOAT32 intermediate_band; |
48 | 5.80M | FLOAT32 x0, x1, y0, y1; |
49 | 5.80M | if (qmf_bands == 64) { |
50 | 5.80M | x0 = time_in[1]; |
51 | 5.80M | y0 = time_in[0]; |
52 | 5.80M | real_subband[0] = (x0 + y0) / 2; |
53 | 5.80M | imag_subband[0] = (x0 - y0) / 2; |
54 | 371M | for (idx = 1; idx < qmf_bands; idx++) { |
55 | 365M | x0 = time_in[idx + 1]; |
56 | 365M | y0 = time_in[qmf_bands_by_2 - idx]; |
57 | 365M | real_subband[idx] = (x0 - y0) / 2; |
58 | 365M | imag_subband[idx] = (x0 + y0) / 2; |
59 | 365M | } |
60 | 5.80M | } else { |
61 | 0 | for (idx = 0; idx < qmf_bands; idx += 2) { |
62 | 0 | x0 = time_in[idx + 0]; |
63 | 0 | x1 = time_in[idx + 1]; |
64 | 0 | y0 = time_in[qmf_bands_by_2 - 1 - idx]; |
65 | 0 | y1 = time_in[qmf_bands_by_2 - 2 - idx]; |
66 | |
|
67 | 0 | real_subband[idx + 0] = (x0 - y0) / 2; |
68 | 0 | real_subband[idx + 1] = (x1 - y1) / 2; |
69 | 0 | imag_subband[idx + 0] = (x0 + y0) / 2; |
70 | 0 | imag_subband[idx + 1] = (x1 + y1) / 2; |
71 | 0 | } |
72 | 0 | } |
73 | 5.80M | error = ixheaace_mps_212_dct_iv(real_subband, qmf_bands, ptr_scratch); |
74 | 5.80M | if (error != IA_NO_ERROR) { |
75 | 0 | return error; |
76 | 0 | } |
77 | 5.80M | error = ixheaace_mps_212_dst_iv(imag_subband, qmf_bands, ptr_scratch); |
78 | 5.80M | if (error != IA_NO_ERROR) { |
79 | 0 | return error; |
80 | 0 | } |
81 | | |
82 | 191M | for (idx = 0; idx < MIN(pstr_qmf_filter_bank->lsb, qmf_bands); idx += 2) { |
83 | 185M | intermediate_band = real_subband[idx]; |
84 | 185M | real_subband[idx] = -imag_subband[idx]; |
85 | 185M | imag_subband[idx] = intermediate_band; |
86 | | |
87 | 185M | intermediate_band = -real_subband[idx + 1]; |
88 | 185M | real_subband[idx + 1] = imag_subband[idx + 1]; |
89 | 185M | imag_subband[idx + 1] = intermediate_band; |
90 | 185M | } |
91 | 5.80M | return IA_NO_ERROR; |
92 | 5.80M | } |
93 | | |
94 | | static VOID ixheaace_mps_212_qmf_ana_prototype_fir_slot(FLOAT32 *ptr_analysis_buffer, |
95 | | WORD32 qmf_bands, |
96 | | const FLOAT32 *ptr_filter, WORD32 stride, |
97 | 5.80M | FLOAT32 *ptr_filter_states) { |
98 | 5.80M | const FLOAT32 *p_flt = ptr_filter; |
99 | 5.80M | WORD32 poly, band; |
100 | 5.80M | FLOAT32 accumlate; |
101 | | |
102 | 749M | for (band = 0; band < 2 * qmf_bands; band++) { |
103 | 743M | accumlate = 0; |
104 | 743M | p_flt += QMF_NO_POLY * (stride - 1); |
105 | 4.46G | for (poly = 0; poly < QMF_NO_POLY; poly++) { |
106 | 3.71G | accumlate += (((*p_flt++) * ptr_filter_states[2 * qmf_bands * poly])); |
107 | 3.71G | } |
108 | 743M | ptr_analysis_buffer[2 * qmf_bands - 1 - band] = accumlate; |
109 | 743M | ptr_filter_states++; |
110 | 743M | } |
111 | 5.80M | } |
112 | | |
113 | | IA_ERRORCODE ixheaace_mps_212_qmf_analysis_filtering_slot( |
114 | | ixheaace_mps_pstr_qmf_filter_bank pstr_qmf_filter_bank, FLOAT32 *real_subband, |
115 | | FLOAT32 *imag_subband, const FLOAT32 *time_in, const WORD32 stride, FLOAT32 *p_work_buffer, |
116 | 5.80M | WORD8 *ptr_scratch) { |
117 | 5.80M | IA_ERRORCODE error = IA_NO_ERROR; |
118 | 5.80M | WORD32 idx; |
119 | 5.80M | WORD32 offset = pstr_qmf_filter_bank->no_channels * (QMF_NO_POLY * 2 - 1); |
120 | 5.80M | FLOAT32 *pstr_filter_states_ana_tmp = |
121 | 5.80M | ((FLOAT32 *)pstr_qmf_filter_bank->ptr_filter_states) + offset; |
122 | 377M | for (idx = 0; idx < pstr_qmf_filter_bank->no_channels; idx++) { |
123 | 371M | *pstr_filter_states_ana_tmp++ = (FLOAT32)*time_in; |
124 | 371M | time_in += stride; |
125 | 371M | } |
126 | 5.80M | ixheaace_mps_212_qmf_ana_prototype_fir_slot( |
127 | 5.80M | p_work_buffer, pstr_qmf_filter_bank->no_channels, pstr_qmf_filter_bank->pstr_filter, |
128 | 5.80M | pstr_qmf_filter_bank->p_stride, (FLOAT32 *)pstr_qmf_filter_bank->ptr_filter_states); |
129 | | |
130 | 5.80M | error = ixheaace_mps_212_qmf_forward_modulation_hq(pstr_qmf_filter_bank, p_work_buffer, |
131 | 5.80M | real_subband, imag_subband, ptr_scratch); |
132 | 5.80M | if (error != IA_NO_ERROR) { |
133 | 0 | return error; |
134 | 0 | } |
135 | | |
136 | 5.80M | memmove(pstr_qmf_filter_bank->ptr_filter_states, |
137 | 5.80M | (FLOAT32 *)pstr_qmf_filter_bank->ptr_filter_states + pstr_qmf_filter_bank->no_channels, |
138 | 5.80M | offset * sizeof(FLOAT32)); |
139 | 5.80M | return error; |
140 | 5.80M | } |
141 | | |
142 | | IA_ERRORCODE |
143 | | ixheaace_mps_212_qmf_init_filter_bank(ixheaace_mps_pstr_qmf_filter_bank pstr_qmf_filter_bank, |
144 | | VOID *ptr_filter_states, WORD32 num_cols, WORD32 lsb, |
145 | 2.69k | WORD32 usb, WORD32 no_channels) { |
146 | 2.69k | memset(pstr_qmf_filter_bank, 0, sizeof(ixheaace_mps_qmf_filter_bank)); |
147 | 2.69k | pstr_qmf_filter_bank->no_channels = no_channels; |
148 | 2.69k | pstr_qmf_filter_bank->no_col = num_cols; |
149 | 2.69k | pstr_qmf_filter_bank->lsb = MIN(lsb, pstr_qmf_filter_bank->no_channels); |
150 | 2.69k | pstr_qmf_filter_bank->usb = MIN(usb, pstr_qmf_filter_bank->no_channels); |
151 | 2.69k | pstr_qmf_filter_bank->ptr_filter_states = (VOID *)ptr_filter_states; |
152 | 2.69k | memset(pstr_qmf_filter_bank->ptr_filter_states, 0, |
153 | 2.69k | (2 * QMF_NO_POLY - 1) * pstr_qmf_filter_bank->no_channels * sizeof(FLOAT32)); |
154 | 2.69k | pstr_qmf_filter_bank->p_stride = 1; |
155 | 2.69k | if (no_channels == 64) { |
156 | 2.69k | pstr_qmf_filter_bank->pstr_filter = qmf_mps_ld_fb_640; |
157 | 2.69k | pstr_qmf_filter_bank->filter_size = 640; |
158 | 2.69k | } else { |
159 | 0 | pstr_qmf_filter_bank->pstr_filter = qmf_mps_ld_fb_320; |
160 | 0 | pstr_qmf_filter_bank->filter_size = 320; |
161 | 0 | } |
162 | | |
163 | 2.69k | return IA_NO_ERROR; |
164 | 2.69k | } |