Skip to content

Commit a01b336

Browse files
committed
add DSP demos
1 parent 540dcfc commit a01b336

File tree

1 file changed

+42
-3
lines changed

1 file changed

+42
-3
lines changed

ports/raspberrypi/common-hal/rp2pio/StateMachine.c

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1428,9 +1428,48 @@ mp_obj_t common_hal_rp2pio_statemachine_get_last_write(rp2pio_statemachine_obj_t
14281428

14291429
bool common_hal_rp2pio_statemachine_process(rp2pio_statemachine_obj_t *self, uint8_t stride_in_bytes,
14301430
sm_buf_info *target_buf_info, sm_buf_info *parameters_buf_info, sm_buf_info *input_buf_info) {
1431-
for (void *i = target_buf_info->info.buf; i < target_buf_info->info.buf + (target_buf_info->info.len * stride_in_bytes); i += stride_in_bytes)
1432-
{};
1433-
1431+
if (parameters_buf_info->info.len > 2) {
1432+
if (stride_in_bytes == 2) {
1433+
int16_t op = ((int16_t *)parameters_buf_info->info.buf)[0];
1434+
int16_t *target;
1435+
target = (int16_t *)target_buf_info->info.buf;
1436+
1437+
switch (op) {
1438+
case 1: // multiply
1439+
int16_t *factor;
1440+
uint16_t *factor_index;
1441+
size_t factor_samples;
1442+
factor_samples = (parameters_buf_info->info.len - (2 * stride_in_bytes)) / stride_in_bytes;
1443+
factor_index = ((uint16_t *)(parameters_buf_info->info.buf)) + 1;
1444+
factor = ((int16_t *)(parameters_buf_info->info.buf)) + 2;
1445+
for (size_t i = 0; i < (target_buf_info->info.len / stride_in_bytes); i++) {
1446+
target[i] = ((int32_t)target[i] * (int32_t)factor[*factor_index]) >> 16;
1447+
(*factor_index)++;
1448+
if (*factor_index >= factor_samples) {
1449+
*factor_index = 0;
1450+
}
1451+
}
1452+
break;
1453+
1454+
case 2: // echo
1455+
int16_t *memory;
1456+
uint16_t *memory_index;
1457+
size_t memory_samples;
1458+
memory_samples = (parameters_buf_info->info.len - (2 * stride_in_bytes)) / stride_in_bytes;
1459+
memory_index = ((uint16_t *)(parameters_buf_info->info.buf)) + 1;
1460+
memory = ((int16_t *)(parameters_buf_info->info.buf)) + 2;
1461+
for (size_t i = 0; i < (target_buf_info->info.len / stride_in_bytes); i++) {
1462+
target[i] = (target[i] + (memory[*memory_index] >> 1)) >> 1; // fixed 50% decay for now
1463+
memory[*memory_index] = target[i];
1464+
(*memory_index)++;
1465+
if (*memory_index >= memory_samples) {
1466+
*memory_index = 0;
1467+
}
1468+
}
1469+
break;
1470+
}
1471+
}
1472+
}
14341473
return 1;
14351474
}
14361475

0 commit comments

Comments
 (0)