forked from thesofproject/sof
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtdfb_hifi3.c
More file actions
284 lines (255 loc) · 7.51 KB
/
Copy pathtdfb_hifi3.c
File metadata and controls
284 lines (255 loc) · 7.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
// SPDX-License-Identifier: BSD-3-Clause
//
// Copyright(c) 2020 Intel Corporation. All rights reserved.
//
// Author: Seppo Ingalsuo <seppo.ingalsuo@linux.intel.com>
#include <sof/common.h>
#include <user/tdfb.h>
#include <sof/audio/audio_stream.h>
#include <sof/audio/tdfb/tdfb_comp.h>
#include <user/fir.h>
#include <user/tdfb.h>
#if TDFB_HIFI3
#include <sof/math/fir_hifi3.h>
#if CONFIG_FORMAT_S16LE
void tdfb_fir_s16(struct tdfb_comp_data *cd, struct input_stream_buffer *bsource,
struct output_stream_buffer *bsink, int frames)
{
struct audio_stream *source = bsource->data;
struct audio_stream *sink = bsink->data;
struct sof_tdfb_config *cfg = cd->config;
struct fir_state_32x16 *f;
ae_int16x4 d;
ae_int32 y0;
ae_int32 y1;
ae_int16 *x = audio_stream_get_rptr(source);
ae_int16 *y = audio_stream_get_wptr(sink);
int shift;
int is2;
int is;
int om;
int i;
int j;
int k;
int in_nch = audio_stream_get_channels(source);
int out_nch = audio_stream_get_channels(sink);
int emp_ch = 0;
int n, nmax;
int remaining_frames = frames;
const int inc = sizeof(ae_int16);
while (remaining_frames) {
nmax = audio_stream_frames_without_wrap(source, x);
n = MIN(remaining_frames, nmax);
nmax = audio_stream_frames_without_wrap(sink, y);
n = MIN(n, nmax);
for (j = 0; j < n; j += 2) {
/* Clear output mix*/
memset(cd->out, 0, 2 * out_nch * sizeof(int32_t));
/* Read two frames from all input channels
* there won't be buffer overflow since we
* set 2 frames align in tdfb_prepare function.
*/
for (i = 0; i < 2 * in_nch; i++) {
AE_L16_XP(d, x, inc);
cd->in[i] = (ae_int32)AE_CVT32X2F16_32(d);
tdfb_direction_copy_emphasis(cd, in_nch, &emp_ch, cd->in[i]);
}
/* Run and mix all filters to their output channel */
for (i = 0; i < cfg->num_filters; i++) {
is = cd->input_channel_select[i];
is2 = is + in_nch;
om = cd->output_channel_mix[i];
/* Get filter instance */
f = &cd->fir[i];
shift = -f->out_shift;
/* Compute FIR and mix as Q5.27*/
fir_core_setup_circular(f);
fir_32x16_2x_hifi3(f, cd->in[is], cd->in[is2], &y0, &y1,
shift);
for (k = 0; k < out_nch; k++) {
if (om & 1) {
cd->out[k] += (int32_t)y0 >> 4;
cd->out[k + out_nch] +=
(int32_t)y1 >> 4;
}
om = om >> 1;
}
}
/* Write two frames of output. The values in out[] are shifted
* left and saturated to convert to Q1.27. The values
* are then rounded to 16 bit and converted to Q1.15 for
* sink buffer. TODO: Could saturate four samples with
* one AE_ROUND16X4F32SSYM() instruction.
*/
for (i = 0; i < 2 * out_nch; i++) {
d = AE_ROUND16X4F32SSYM(0, AE_SLAI32S(cd->out[i], 4));
AE_S16_0_XP(d, y, inc);
}
}
remaining_frames -= n;
x = audio_stream_wrap(source, x);
y = audio_stream_wrap(sink, y);
}
}
#endif
#if CONFIG_FORMAT_S24LE
void tdfb_fir_s24(struct tdfb_comp_data *cd, struct input_stream_buffer *bsource,
struct output_stream_buffer *bsink, int frames)
{
struct audio_stream *source = bsource->data;
struct audio_stream *sink = bsink->data;
struct sof_tdfb_config *cfg = cd->config;
struct fir_state_32x16 *f;
ae_int32x2 d;
ae_int32 y0;
ae_int32 y1;
ae_int32 *x = audio_stream_get_rptr(source);
ae_int32 *y = audio_stream_get_wptr(sink);
int shift;
int is2;
int is;
int om;
int i;
int j;
int k;
int in_nch = audio_stream_get_channels(source);
int out_nch = audio_stream_get_channels(sink);
int emp_ch = 0;
int n, nmax;
int remaining_frames = frames;
const int inc = sizeof(ae_int32);
while (remaining_frames) {
nmax = audio_stream_frames_without_wrap(source, x);
n = MIN(remaining_frames, nmax);
nmax = audio_stream_frames_without_wrap(sink, y);
n = MIN(n, nmax);
for (j = 0; j < n; j += 2) {
/* Clear output mix*/
memset(cd->out, 0, 2 * out_nch * sizeof(int32_t));
/* Read two frames from all input channels
* there won't be buffer overflow since we
* set 2 frames align in tdfb_prepare function.
*/
for (i = 0; i < 2 * in_nch; i++) {
AE_L32_XP(d, x, inc);
cd->in[i] = AE_SLAI32(d, 8);
tdfb_direction_copy_emphasis(cd, in_nch, &emp_ch, cd->in[i]);
}
/* Run and mix all filters to their output channel */
for (i = 0; i < cfg->num_filters; i++) {
is = cd->input_channel_select[i];
is2 = is + in_nch;
om = cd->output_channel_mix[i];
/* Get filter instance */
f = &cd->fir[i];
shift = -f->out_shift;
/* Compute FIR and mix as Q5.27*/
fir_core_setup_circular(f);
fir_32x16_2x_hifi3(f, cd->in[is], cd->in[is2], &y0, &y1,
shift);
for (k = 0; k < out_nch; k++) {
if (om & 1) {
cd->out[k] += (int32_t)y0 >> 4;
cd->out[k + out_nch] +=
(int32_t)y1 >> 4;
}
om = om >> 1;
}
}
/* Write two frames of output. The values in out[] are shifted
* left and saturated to convert to Q1.27. The values
* are then rounded to 16 bit and converted to Q1.15 for
* sink buffer. TODO: Could saturate four samples with
* one AE_ROUND16X4F32SSYM() instruction.
*/
for (i = 0; i < 2 * out_nch; i++) {
d = AE_SRAI32(AE_SLAI32S(AE_SRAI32R(cd->out[i], 4), 8), 8);
AE_S32_L_XP(d, y, inc);
}
}
remaining_frames -= n;
x = audio_stream_wrap(source, x);
y = audio_stream_wrap(sink, y);
}
}
#endif
#if CONFIG_FORMAT_S32LE
void tdfb_fir_s32(struct tdfb_comp_data *cd, struct input_stream_buffer *bsource,
struct output_stream_buffer *bsink, int frames)
{
struct audio_stream *source = bsource->data;
struct audio_stream *sink = bsink->data;
struct sof_tdfb_config *cfg = cd->config;
struct fir_state_32x16 *f;
ae_int32x2 d;
ae_int32 y0;
ae_int32 y1;
ae_int32 *x = audio_stream_get_rptr(source);
ae_int32 *y = audio_stream_get_wptr(sink);
int shift;
int is2;
int is;
int om;
int i;
int j;
int k;
int in_nch = audio_stream_get_channels(source);
int out_nch = audio_stream_get_channels(sink);
int emp_ch = 0;
int n, nmax;
int remaining_frames = frames;
const int inc = sizeof(ae_int32);
while (remaining_frames) {
nmax = audio_stream_frames_without_wrap(source, x);
n = MIN(remaining_frames, nmax);
nmax = audio_stream_frames_without_wrap(sink, y);
n = MIN(n, nmax);
for (j = 0; j < n; j += 2) {
/* Clear output mix*/
memset(cd->out, 0, 2 * out_nch * sizeof(int32_t));
/* Read two frames from all input channels
* there won't be buffer overflow since we
* set 2 frames align in tdfb_prepare function.
*/
for (i = 0; i < 2 * in_nch; i++) {
AE_L32_XC(d, x, inc);
cd->in[i] = d;
tdfb_direction_copy_emphasis(cd, in_nch, &emp_ch, cd->in[i]);
}
for (i = 0; i < cfg->num_filters; i++) {
is = cd->input_channel_select[i];
is2 = is + in_nch;
om = cd->output_channel_mix[i];
/* Get filter instance */
f = &cd->fir[i];
shift = -f->out_shift;
/* Compute FIR and mix as Q5.27*/
fir_core_setup_circular(f);
fir_32x16_2x_hifi3(f, cd->in[is], cd->in[is2], &y0, &y1,
shift);
for (k = 0; k < out_nch; k++) {
if (om & 1) {
cd->out[k] += (int32_t)y0 >> 4;
cd->out[k + out_nch] +=
(int32_t)y1 >> 4;
}
om = om >> 1;
}
}
/* Write two frames of output. In Q5.27 to Q1.31 conversion
* rounding is not applicable so just shift left by 4 and
* saturate. TODO: Could shift two samples with one
* instruction.
*/
for (i = 0; i < 2 * out_nch; i++) {
d = AE_SLAI32S(cd->out[i], 4);
AE_S32_L_XP(d, y, inc);
}
}
remaining_frames -= n;
x = audio_stream_wrap(source, x);
y = audio_stream_wrap(sink, y);
}
}
#endif
#endif /* TDFB_HIFI3 */