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 <memory.h>
22 #include "ixheaacd_type_def.h"
23
24 #include "ixheaacd_cnst.h"
25 #include "ixheaacd_constants.h"
26 #include "ixheaacd_basic_ops32.h"
27 #include "ixheaacd_basic_ops40.h"
28
29 static const FLOAT32 ixheaacd_gamma_table[17] = {
30 1.0f, 0.92f, 0.8464f, 0.778688f, 0.716393f, 0.659082f,
31 0.606355f, 0.557847f, 0.513219f, 0.472161f, 0.434389f, 0.399637f,
32 0.367666f, 0.338253f, 0.311193f, 0.286298f, 0.263394f};
33
ixheaacd_rand_gen(WORD16 * seed)34 WORD16 ixheaacd_rand_gen(WORD16 *seed) {
35 *seed = (WORD16)(*seed * 31821L + 13849L);
36 return (*seed);
37 }
38
ixheaacd_preemphsis_tool(WORD32 * signal,WORD32 mu,WORD32 len,WORD32 mem)39 VOID ixheaacd_preemphsis_tool(WORD32 *signal, WORD32 mu, WORD32 len,
40 WORD32 mem) {
41 WORD32 i;
42 WORD32 temp;
43
44 temp = signal[len - 1];
45 for (i = len - 1; i > 0; i--) {
46 signal[i] -= (WORD32)ixheaacd_mul32_sh(mu, signal[i - 1], 16);
47 }
48 signal[0] -= (WORD32)ixheaacd_mul32_sh(mu, mem, 16);
49 return;
50 }
51
ixheaacd_preemphsis_tool_float(FLOAT32 * signal,FLOAT32 mu,WORD32 len,FLOAT32 mem)52 VOID ixheaacd_preemphsis_tool_float(FLOAT32 *signal, FLOAT32 mu, WORD32 len,
53 FLOAT32 mem) {
54 WORD32 i;
55 FLOAT32 temp;
56 temp = signal[len - 1];
57 for (i = len - 1; i > 0; i--) {
58 signal[i] = signal[i] - mu * signal[i - 1];
59 }
60 signal[0] -= mu * mem;
61 return;
62 }
63
ixheaacd_deemphsis_tool(FLOAT32 * signal,WORD32 len,FLOAT32 mem)64 VOID ixheaacd_deemphsis_tool(FLOAT32 *signal, WORD32 len, FLOAT32 mem) {
65 WORD32 i;
66 signal[0] = signal[0] + PREEMPH_FILT_FAC * mem;
67 for (i = 1; i < len; i++) {
68 signal[i] = signal[i] + PREEMPH_FILT_FAC * signal[i - 1];
69 }
70 return;
71 }
72
ixheaacd_lpc_wt_synthesis_tool(FLOAT32 a[],FLOAT32 x[],WORD32 l)73 VOID ixheaacd_lpc_wt_synthesis_tool(FLOAT32 a[], FLOAT32 x[], WORD32 l) {
74 FLOAT32 s;
75 WORD32 i, j;
76
77 for (i = 0; i < l; i++) {
78 s = x[i];
79 for (j = 1; j <= ORDER; j += 4) {
80 s -= (a[j] * ixheaacd_gamma_table[j]) * x[i - j];
81 s -= (a[j + 1] * ixheaacd_gamma_table[j + 1]) * x[i - (j + 1)];
82 s -= (a[j + 2] * ixheaacd_gamma_table[j + 2]) * x[i - (j + 2)];
83 s -= (a[j + 3] * ixheaacd_gamma_table[j + 3]) * x[i - (j + 3)];
84 }
85 x[i] = s;
86 }
87
88 return;
89 }
90
ixheaacd_synthesis_tool_float(FLOAT32 a[],FLOAT32 x[],FLOAT32 y[],WORD32 l,FLOAT32 mem[])91 VOID ixheaacd_synthesis_tool_float(FLOAT32 a[], FLOAT32 x[], FLOAT32 y[],
92 WORD32 l, FLOAT32 mem[]) {
93 FLOAT32 buf[LEN_FRAME * 2];
94 FLOAT32 s;
95 FLOAT32 *yy;
96 WORD32 i, j;
97 memcpy(buf, mem, ORDER * sizeof(FLOAT32));
98 yy = &buf[ORDER];
99 for (i = 0; i < l; i++) {
100 s = x[i];
101 for (j = 1; j <= ORDER; j += 4) {
102 s -= a[j] * yy[i - j];
103 s -= a[j + 1] * yy[i - (j + 1)];
104 s -= a[j + 2] * yy[i - (j + 2)];
105 s -= a[j + 3] * yy[i - (j + 3)];
106 }
107 yy[i] = s;
108 y[i] = s;
109 }
110
111 return;
112 }
113
ixheaacd_synthesis_tool_float1(FLOAT32 a[],FLOAT32 x[],WORD32 l)114 VOID ixheaacd_synthesis_tool_float1(FLOAT32 a[], FLOAT32 x[], WORD32 l) {
115 FLOAT32 s;
116 WORD32 i, j;
117 for (i = 0; i < l; i++) {
118 s = x[i];
119 for (j = 1; j <= ORDER; j += 4) {
120 s -= a[j] * x[i - j];
121 s -= a[j + 1] * x[i - (j + 1)];
122 s -= a[j + 2] * x[i - (j + 2)];
123 s -= a[j + 3] * x[i - (j + 3)];
124 }
125 x[i] = s;
126 }
127
128 return;
129 }
130
ixheaacd_residual_tool(WORD32 * a,WORD32 * x,WORD32 * y,WORD32 l,WORD32 count)131 VOID ixheaacd_residual_tool(WORD32 *a, WORD32 *x, WORD32 *y, WORD32 l,
132 WORD32 count) {
133 WORD32 s;
134 WORD32 i, j;
135 WORD32 n = l * count;
136
137 for (i = 0; i < n; i++) {
138 s = x[i];
139 for (j = 1; j <= 16; j++)
140 s += (WORD32)ixheaacd_mul32_sh(a[j], x[i - j], 24);
141 y[i] = s;
142 }
143
144 return;
145 }
146
ixheaacd_residual_tool_float(FLOAT32 * a,FLOAT32 * x,FLOAT32 * y,WORD32 l,WORD32 loop_count)147 VOID ixheaacd_residual_tool_float(FLOAT32 *a, FLOAT32 *x, FLOAT32 *y, WORD32 l,
148 WORD32 loop_count) {
149 FLOAT32 s;
150 WORD32 i, j;
151 for (j = 0; j < loop_count; j++) {
152 for (i = 0; i < l; i++) {
153 s = x[i];
154 s += a[1] * x[i - 1];
155 s += a[2] * x[i - 2];
156 s += a[3] * x[i - 3];
157 s += a[4] * x[i - 4];
158 s += a[5] * x[i - 5];
159 s += a[6] * x[i - 6];
160 s += a[7] * x[i - 7];
161 s += a[8] * x[i - 8];
162 s += a[9] * x[i - 9];
163 s += a[10] * x[i - 10];
164 s += a[11] * x[i - 11];
165 s += a[12] * x[i - 12];
166 s += a[13] * x[i - 13];
167 s += a[14] * x[i - 14];
168 s += a[15] * x[i - 15];
169 s += a[16] * x[i - 16];
170 y[i] = s;
171 }
172 a += 17;
173 x += l;
174 y += l;
175 }
176 return;
177 }
178
ixheaacd_residual_tool_float1(FLOAT32 * a,FLOAT32 * x,FLOAT32 * y,WORD32 l,WORD32 loop_count)179 VOID ixheaacd_residual_tool_float1(FLOAT32 *a, FLOAT32 *x, FLOAT32 *y, WORD32 l,
180 WORD32 loop_count) {
181 FLOAT32 s;
182 WORD32 i, j;
183 for (j = 0; j < loop_count; j++) {
184 for (i = 0; i < l; i++) {
185 s = x[i];
186 s += a[1] * x[i - 1];
187 s += a[2] * x[i - 2];
188 s += a[3] * x[i - 3];
189 s += a[4] * x[i - 4];
190 s += a[5] * x[i - 5];
191 s += a[6] * x[i - 6];
192 s += a[7] * x[i - 7];
193 s += a[8] * x[i - 8];
194 s += a[9] * x[i - 9];
195 s += a[10] * x[i - 10];
196 s += a[11] * x[i - 11];
197 s += a[12] * x[i - 12];
198 s += a[13] * x[i - 13];
199 s += a[14] * x[i - 14];
200 s += a[15] * x[i - 15];
201 s += a[16] * x[i - 16];
202 y[i] = s;
203 }
204 x += l;
205 y += l;
206 }
207 return;
208 }
209