| @@ -0,0 +1,94 @@ |
| 1 | +#include <math.h> |
| 2 | +#include <stdlib.h> |
| 3 | +#include <stdint.h> |
| 4 | +#include "patchwerk.h" |
| 5 | +#include "core.h" |
| 6 | +#include "dsp/biramp.h" |
| 7 | + |
| 8 | +struct biramp_n { |
| 9 | + pw_cable *in; |
| 10 | + pw_cable *pos; |
| 11 | + pw_cable *out; |
| 12 | + SKFLT lphs; |
| 13 | + SKFLT lpos; |
| 14 | +}; |
| 15 | + |
| 16 | +static void compute(pw_node *node) |
| 17 | +{ |
| 18 | + int blksize; |
| 19 | + int n; |
| 20 | + struct biramp_n *biramp; |
| 21 | + |
| 22 | + blksize = pw_node_blksize(node); |
| 23 | + |
| 24 | + biramp = (struct biramp_n *)pw_node_get_data(node); |
| 25 | + |
| 26 | + for (n = 0; n < blksize; n++) { |
| 27 | + PWFLT in, pos, out; |
| 28 | + in = pw_cable_get(biramp->in, n); |
| 29 | + pos = pw_cable_get(biramp->pos, n); |
| 30 | + |
| 31 | + out = sk_biramp_stateful(in, pos, |
| 32 | + &biramp->lphs, |
| 33 | + &biramp->lpos); |
| 34 | + pw_cable_set(biramp->out, n, out); |
| 35 | + } |
| 36 | +} |
| 37 | + |
| 38 | +static void destroy(pw_node *node) |
| 39 | +{ |
| 40 | + pw_patch *patch; |
| 41 | + int rc; |
| 42 | + void *ud; |
| 43 | + rc = pw_node_get_patch(node, &patch); |
| 44 | + if (rc != PW_OK) return; |
| 45 | + pw_node_cables_free(node); |
| 46 | + ud = pw_node_get_data(node); |
| 47 | + pw_memory_free(patch, &ud); |
| 48 | +} |
| 49 | + |
| 50 | +int sk_node_biramp(sk_core *core) |
| 51 | +{ |
| 52 | + pw_patch *patch; |
| 53 | + pw_node *node; |
| 54 | + int rc; |
| 55 | + sk_param in, pos; |
| 56 | + void *ud; |
| 57 | + struct biramp_n *biramp; |
| 58 | + |
| 59 | + rc = sk_param_get(core, &pos); |
| 60 | + SK_ERROR_CHECK(rc); |
| 61 | + |
| 62 | + rc = sk_param_get(core, &in); |
| 63 | + SK_ERROR_CHECK(rc); |
| 64 | + |
| 65 | + patch = sk_core_patch(core); |
| 66 | + |
| 67 | + rc = pw_memory_alloc(patch, sizeof(struct biramp_n), &ud); |
| 68 | + SK_PW_ERROR_CHECK(rc); |
| 69 | + biramp = (struct biramp_n *)ud; |
| 70 | + |
| 71 | + biramp->lpos = -1; |
| 72 | + biramp->lphs = -1; |
| 73 | + |
| 74 | + rc = pw_patch_new_node(patch, &node); |
| 75 | + SK_PW_ERROR_CHECK(rc); |
| 76 | + |
| 77 | + rc = pw_node_cables_alloc(node, 3); |
| 78 | + SK_PW_ERROR_CHECK(rc); |
| 79 | + |
| 80 | + pw_node_set_block(node, 2); |
| 81 | + |
| 82 | + pw_node_get_cable(node, 0, &biramp->in); |
| 83 | + pw_node_get_cable(node, 1, &biramp->pos); |
| 84 | + pw_node_get_cable(node, 2, &biramp->out); |
| 85 | + |
| 86 | + pw_node_set_data(node, biramp); |
| 87 | + pw_node_set_compute(node, compute); |
| 88 | + pw_node_set_destroy(node, destroy); |
| 89 | + |
| 90 | + sk_param_set(core, node, &in, 0); |
| 91 | + sk_param_set(core, node, &pos, 1); |
| 92 | + sk_param_out(core, node, 2); |
| 93 | + return 0; |
| 94 | +} |