Skip to content

Commit 1eec690

Browse files
committed
Audio: Up_down_mix: Replace simple stubs with generic C versions
This patch replaces the stubs of simple conversion functions with real conversions. In these cases the xtensa C code without arithmetic operations can converted to generic with just e.g. ae_int32 to int32_t replace and AE_MOVINT with type cast. This enables to use testbench x86 build to run up_down_mixer. Also the generic versions are potential for better performance with more recent HiFi cores with improvements in compiler technology. Signed-off-by: Seppo Ingalsuo <seppo.ingalsuo@linux.intel.com>
1 parent 3a718c9 commit 1eec690

File tree

1 file changed

+233
-10
lines changed

1 file changed

+233
-10
lines changed

src/audio/up_down_mixer/up_down_mixer_generic.c

Lines changed: 233 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,43 +16,211 @@
1616
void upmix32bit_1_to_5_1(struct up_down_mixer_data *cd, const uint8_t * const in_data,
1717
const uint32_t in_size, uint8_t * const out_data)
1818
{
19-
sof_panic(0);
19+
int i;
20+
21+
channel_map out_channel_map = cd->out_channel_map;
22+
23+
/* Only load the channel if it's present. */
24+
int32_t *output_left = (int32_t *)(out_data +
25+
(get_channel_location(out_channel_map, CHANNEL_LEFT) << 2));
26+
int32_t *output_center = (int32_t *)(out_data +
27+
(get_channel_location(out_channel_map, CHANNEL_CENTER) << 2));
28+
int32_t *output_right = (int32_t *)(out_data +
29+
(get_channel_location(out_channel_map, CHANNEL_RIGHT) << 2));
30+
int32_t *output_left_surround = (int32_t *)(out_data +
31+
(get_channel_location(out_channel_map, CHANNEL_LEFT_SURROUND) << 2));
32+
int32_t *output_right_surround = (int32_t *)(out_data +
33+
(get_channel_location(out_channel_map, CHANNEL_RIGHT_SURROUND) << 2));
34+
int32_t *output_lfe = (int32_t *)(out_data +
35+
(get_channel_location(out_channel_map, CHANNEL_LFE) << 2));
36+
37+
int32_t *in_ptr = (int32_t *)in_data;
38+
39+
for (i = 0; i < (in_size >> 2); ++i) {
40+
output_left[i * 6] = in_ptr[i];
41+
output_right[i * 6] = in_ptr[i];
42+
output_center[i * 6] = 0;
43+
output_left_surround[i * 6] = in_ptr[i];
44+
output_right_surround[i * 6] = in_ptr[i];
45+
output_lfe[i * 6] = 0;
46+
}
2047
}
2148

2249
void upmix16bit_1_to_5_1(struct up_down_mixer_data *cd, const uint8_t * const in_data,
2350
const uint32_t in_size, uint8_t * const out_data)
2451
{
25-
sof_panic(0);
52+
int i;
53+
54+
channel_map out_channel_map = cd->out_channel_map;
55+
56+
/* Only load the channel if it's present. */
57+
int32_t *output_left = (int32_t *)(out_data +
58+
(get_channel_location(out_channel_map, CHANNEL_LEFT) << 2));
59+
int32_t *output_center = (int32_t *)(out_data +
60+
(get_channel_location(out_channel_map, CHANNEL_CENTER) << 2));
61+
int32_t *output_right = (int32_t *)(out_data +
62+
(get_channel_location(out_channel_map, CHANNEL_RIGHT) << 2));
63+
int32_t *output_left_surround = (int32_t *)(out_data +
64+
(get_channel_location(out_channel_map, CHANNEL_LEFT_SURROUND) << 2));
65+
int32_t *output_right_surround = (int32_t *)(out_data +
66+
(get_channel_location(out_channel_map, CHANNEL_RIGHT_SURROUND) << 2));
67+
int32_t *output_lfe = (int32_t *)(out_data +
68+
(get_channel_location(out_channel_map, CHANNEL_LFE) << 2));
69+
70+
int16_t *in_ptr = (int16_t *)in_data;
71+
72+
for (i = 0; i < (in_size >> 1); ++i) {
73+
output_left[i * 6] = (int32_t)in_ptr[i] << 16;
74+
output_right[i * 6] = (int32_t)in_ptr[i] << 16;
75+
output_center[i * 6] = 0;
76+
output_left_surround[i * 6] = (int32_t)in_ptr[i] << 16;
77+
output_right_surround[i * 6] = (int32_t)in_ptr[i] << 16;
78+
output_lfe[i * 6] = 0;
79+
}
2680
}
2781

2882
void upmix32bit_2_0_to_5_1(struct up_down_mixer_data *cd, const uint8_t * const in_data,
2983
const uint32_t in_size, uint8_t * const out_data)
3084
{
31-
sof_panic(0);
85+
int i;
86+
87+
channel_map out_channel_map = cd->out_channel_map;
88+
89+
const uint8_t left_slot = get_channel_location(out_channel_map, CHANNEL_LEFT);
90+
const uint8_t center_slot = get_channel_location(out_channel_map, CHANNEL_CENTER);
91+
const uint8_t right_slot = get_channel_location(out_channel_map, CHANNEL_RIGHT);
92+
uint8_t left_surround_slot = get_channel_location(out_channel_map, CHANNEL_LEFT_SURROUND);
93+
uint8_t right_surround_slot = get_channel_location(out_channel_map, CHANNEL_RIGHT_SURROUND);
94+
const uint8_t lfe_slot = get_channel_location(out_channel_map, CHANNEL_LFE);
95+
96+
/* Must support also 5.1 Surround */
97+
if (left_surround_slot == CHANNEL_INVALID && right_surround_slot == CHANNEL_INVALID) {
98+
left_surround_slot = get_channel_location(out_channel_map, CHANNEL_LEFT_SIDE);
99+
right_surround_slot = get_channel_location(out_channel_map, CHANNEL_RIGHT_SIDE);
100+
}
101+
102+
int32_t *output_left = (int32_t *)(out_data + (left_slot << 2));
103+
int32_t *output_center = (int32_t *)(out_data + (center_slot << 2));
104+
int32_t *output_right = (int32_t *)(out_data + (right_slot << 2));
105+
int32_t *output_left_surround = (int32_t *)(out_data + (left_surround_slot << 2));
106+
int32_t *output_right_surround = (int32_t *)(out_data + (right_surround_slot << 2));
107+
int32_t *output_lfe = (int32_t *)(out_data + (lfe_slot << 2));
108+
109+
int32_t *in_left_ptr = (int32_t *)in_data;
110+
int32_t *in_right_ptr = (int32_t *)(in_data + 4);
111+
112+
for (i = 0; i < (in_size >> 3); ++i) {
113+
output_left[i * 6] = in_left_ptr[i * 2];
114+
output_right[i * 6] = in_right_ptr[i * 2];
115+
output_center[i * 6] = 0;
116+
output_left_surround[i * 6] = in_left_ptr[i * 2];
117+
output_right_surround[i * 6] = in_right_ptr[i * 2];
118+
output_lfe[i * 6] = 0;
119+
}
32120
}
33121

34122
void upmix16bit_2_0_to_5_1(struct up_down_mixer_data *cd, const uint8_t * const in_data,
35123
const uint32_t in_size, uint8_t * const out_data)
36124
{
37-
sof_panic(0);
125+
int i;
126+
127+
channel_map out_channel_map = cd->out_channel_map;
128+
129+
const uint8_t left_slot = get_channel_location(out_channel_map, CHANNEL_LEFT);
130+
const uint8_t center_slot = get_channel_location(out_channel_map, CHANNEL_CENTER);
131+
const uint8_t right_slot = get_channel_location(out_channel_map, CHANNEL_RIGHT);
132+
uint8_t left_surround_slot = get_channel_location(out_channel_map, CHANNEL_LEFT_SURROUND);
133+
uint8_t right_surround_slot = get_channel_location(out_channel_map, CHANNEL_RIGHT_SURROUND);
134+
const uint8_t lfe_slot = get_channel_location(out_channel_map, CHANNEL_LFE);
135+
136+
/* Must support also 5.1 Surround */
137+
if (left_surround_slot == CHANNEL_INVALID && right_surround_slot == CHANNEL_INVALID) {
138+
left_surround_slot = get_channel_location(out_channel_map, CHANNEL_LEFT_SIDE);
139+
right_surround_slot = get_channel_location(out_channel_map, CHANNEL_RIGHT_SIDE);
140+
}
141+
142+
int32_t *output_left = (int32_t *)(out_data + (left_slot << 2));
143+
int32_t *output_center = (int32_t *)(out_data + (center_slot << 2));
144+
int32_t *output_right = (int32_t *)(out_data + (right_slot << 2));
145+
int32_t *output_left_surround = (int32_t *)(out_data + (left_surround_slot << 2));
146+
int32_t *output_right_surround = (int32_t *)(out_data + (right_surround_slot << 2));
147+
int32_t *output_lfe = (int32_t *)(out_data + (lfe_slot << 2));
148+
149+
int16_t *in_left_ptr = (int16_t *)in_data;
150+
int16_t *in_right_ptr = (int16_t *)(in_data + 2);
151+
152+
for (i = 0; i < (in_size >> 2); ++i) {
153+
output_left[i * 6] = (int32_t)in_left_ptr[i * 2] << 16;
154+
output_right[i * 6] = (int32_t)in_right_ptr[i * 2] << 16;
155+
output_center[i * 6] = 0;
156+
output_left_surround[i * 6] = (int32_t)in_left_ptr[i * 2] << 16;
157+
output_right_surround[i * 6] = (int32_t)in_right_ptr[i * 2] << 16;
158+
output_lfe[i * 6] = 0;
159+
}
38160
}
39161

40162
void upmix32bit_2_0_to_7_1(struct up_down_mixer_data *cd, const uint8_t * const in_data,
41163
const uint32_t in_size, uint8_t * const out_data)
42164
{
43-
sof_panic(0);
165+
int i;
166+
167+
channel_map out_channel_map = cd->out_channel_map;
168+
169+
/* Only load the channel if it's present. */
170+
int32_t *output_left = (int32_t *)(out_data +
171+
(get_channel_location(out_channel_map, CHANNEL_LEFT) << 2));
172+
int32_t *output_center = (int32_t *)(out_data +
173+
(get_channel_location(out_channel_map, CHANNEL_CENTER) << 2));
174+
int32_t *output_right = (int32_t *)(out_data +
175+
(get_channel_location(out_channel_map, CHANNEL_RIGHT) << 2));
176+
int32_t *output_left_surround = (int32_t *)(out_data +
177+
(get_channel_location(out_channel_map, CHANNEL_LEFT_SURROUND) << 2));
178+
int32_t *output_right_surround = (int32_t *)(out_data +
179+
(get_channel_location(out_channel_map, CHANNEL_RIGHT_SURROUND) << 2));
180+
int32_t *output_lfe = (int32_t *)(out_data +
181+
(get_channel_location(out_channel_map, CHANNEL_LFE) << 2));
182+
int32_t *output_left_side = (int32_t *)(out_data +
183+
(get_channel_location(out_channel_map, CHANNEL_LEFT_SIDE) << 2));
184+
int32_t *output_right_side = (int32_t *)(out_data +
185+
(get_channel_location(out_channel_map, CHANNEL_RIGHT_SIDE) << 2));
186+
187+
int32_t *in_left_ptr = (int32_t *)in_data;
188+
int32_t *in_right_ptr = (int32_t *)(in_data + 4);
189+
190+
for (i = 0; i < (in_size >> 3); ++i) {
191+
output_left[i * 8] = in_left_ptr[i * 2];
192+
output_right[i * 8] = in_right_ptr[i * 2];
193+
output_center[i * 8] = 0;
194+
output_left_surround[i * 8] = in_left_ptr[i * 2];
195+
output_right_surround[i * 8] = in_right_ptr[i * 2];
196+
output_lfe[i * 8] = 0;
197+
output_left_side[i * 8] = 0;
198+
output_right_side[i * 8] = 0;
199+
}
44200
}
45201

46202
void shiftcopy32bit_mono(struct up_down_mixer_data *cd, const uint8_t * const in_data,
47203
const uint32_t in_size, uint8_t * const out_data)
48204
{
49-
sof_panic(0);
205+
int i;
206+
207+
uint32_t *in_ptr = (uint32_t *)in_data;
208+
uint64_t *out_ptr = (uint64_t *)out_data;
209+
210+
for (i = 0; i < (in_size >> 2); ++i)
211+
out_ptr[i] = ((uint64_t)in_ptr[i] << 32) | in_ptr[i];
50212
}
51213

52214
void shiftcopy32bit_stereo(struct up_down_mixer_data *cd, const uint8_t * const in_data,
53215
const uint32_t in_size, uint8_t * const out_data)
54216
{
55-
sof_panic(0);
217+
int i;
218+
219+
int64_t *in_ptr = (int64_t *)in_data;
220+
int64_t *out_ptr = (int64_t *)out_data;
221+
222+
for (i = 0; i < (in_size >> 3); ++i)
223+
out_ptr[i] = in_ptr[i];
56224
}
57225

58226
void downmix32bit_2_1(struct up_down_mixer_data *cd, const uint8_t * const in_data,
@@ -112,13 +280,29 @@ void downmix16bit_stereo(struct up_down_mixer_data *cd, const uint8_t * const in
112280
void shiftcopy16bit_mono(struct up_down_mixer_data *cd, const uint8_t * const in_data,
113281
const uint32_t in_size, uint8_t * const out_data)
114282
{
115-
sof_panic(0);
283+
int i;
284+
285+
uint16_t *in_ptrs = (uint16_t *)in_data;
286+
uint64_t *out_ptrs = (uint64_t *)out_data;
287+
288+
for (i = 0; i < (in_size >> 1); ++i)
289+
out_ptrs[i] = (uint64_t)in_ptrs[i] << 48 | ((uint64_t)in_ptrs[i] << 16);
116290
}
117291

118292
void shiftcopy16bit_stereo(struct up_down_mixer_data *cd, const uint8_t * const in_data,
119293
const uint32_t in_size, uint8_t * const out_data)
120294
{
121-
sof_panic(0);
295+
uint32_t i;
296+
297+
uint32_t *in_ptrs = (uint32_t *)in_data;
298+
uint64_t *out_ptrs = (uint64_t *)out_data;
299+
uint32_t in_regs;
300+
301+
for (i = 0; i < (in_size >> 2); ++i) {
302+
in_regs = in_ptrs[i];
303+
out_ptrs[i] = (((uint64_t)in_regs & 0xffff) << 16) |
304+
(((uint64_t)in_regs & 0xffff0000) << 32);
305+
}
122306
}
123307

124308
void downmix16bit(struct up_down_mixer_data *cd, const uint8_t * const in_data,
@@ -190,7 +374,46 @@ void upmix32bit_4_0_to_5_1(struct up_down_mixer_data *cd, const uint8_t * const
190374
void upmix32bit_quatro_to_5_1(struct up_down_mixer_data *cd, const uint8_t * const in_data,
191375
const uint32_t in_size, uint8_t * const out_data)
192376
{
193-
sof_panic(0);
377+
int i;
378+
379+
channel_map out_channel_map = cd->out_channel_map;
380+
381+
const uint8_t left_slot = get_channel_location(out_channel_map, CHANNEL_LEFT);
382+
const uint8_t center_slot = get_channel_location(out_channel_map, CHANNEL_CENTER);
383+
const uint8_t right_slot = get_channel_location(out_channel_map, CHANNEL_RIGHT);
384+
uint8_t right_surround_slot = get_channel_location(out_channel_map, CHANNEL_RIGHT_SURROUND);
385+
uint8_t left_surround_slot = get_channel_location(out_channel_map, CHANNEL_LEFT_SURROUND);
386+
const uint8_t lfe_slot = get_channel_location(out_channel_map, CHANNEL_LFE);
387+
388+
/* Must support also 5.1 Surround */
389+
const bool surround_5_1_channel_map = (left_surround_slot == CHANNEL_INVALID) &&
390+
(right_surround_slot == CHANNEL_INVALID);
391+
392+
if (surround_5_1_channel_map) {
393+
left_surround_slot = get_channel_location(cd->in_channel_map, CHANNEL_LEFT_SIDE);
394+
right_surround_slot = get_channel_location(cd->in_channel_map, CHANNEL_RIGHT_SIDE);
395+
}
396+
397+
int32_t *output_left = (int32_t *)(out_data + (left_slot << 2));
398+
int32_t *output_center = (int32_t *)(out_data + (center_slot << 2));
399+
int32_t *output_right = (int32_t *)(out_data + (right_slot << 2));
400+
int32_t *output_side_left = (int32_t *)(out_data + (left_surround_slot << 2));
401+
int32_t *output_side_right = (int32_t *)(out_data + (right_surround_slot << 2));
402+
int32_t *output_lfe = (int32_t *)(out_data + (lfe_slot << 2));
403+
404+
int32_t *in_left_ptr = (int32_t *)in_data;
405+
int32_t *in_right_ptr = (int32_t *)(in_data + 4);
406+
int32_t *in_left_sorround_ptr = (int32_t *)(in_data + 8);
407+
int32_t *in_right_sorround_ptr = (int32_t *)(in_data + 12);
408+
409+
for (i = 0; i < (in_size >> 4); ++i) {
410+
output_left[i * 6] = in_left_ptr[i * 4];
411+
output_right[i * 6] = in_right_ptr[i * 4];
412+
output_center[i * 6] = 0;
413+
output_side_left[i * 6] = in_left_sorround_ptr[i * 4];
414+
output_side_right[i * 6] = in_right_sorround_ptr[i * 4];
415+
output_lfe[i * 6] = 0;
416+
}
194417
}
195418

196419
#endif /* #if SOF_USE_HIFI(NONE, UP_DOWN_MIXER) */

0 commit comments

Comments
 (0)