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