| @@ -0,0 +1,113 @@ |
| 1 | +#include <math.h> |
| 2 | +#include <stdlib.h> |
| 3 | +#include <stdint.h> |
| 4 | +#include "patchwerk.h" |
| 5 | +#include "core.h" |
| 6 | +#define SK_PEAKEQ_PRIV |
| 7 | +#include "dsp/peakeq.h" |
| 8 | + |
| 9 | +struct peakeq_n { |
| 10 | + pw_cable *in; |
| 11 | + pw_cable *freq; |
| 12 | + pw_cable *bw; |
| 13 | + pw_cable *gain; |
| 14 | + pw_cable *out; |
| 15 | + sk_peakeq peakeq; |
| 16 | +}; |
| 17 | + |
| 18 | +static void compute(pw_node *node) |
| 19 | +{ |
| 20 | + int blksize; |
| 21 | + int n; |
| 22 | + struct peakeq_n *peakeq; |
| 23 | + |
| 24 | + blksize = pw_node_blksize(node); |
| 25 | + |
| 26 | + peakeq = (struct peakeq_n *)pw_node_get_data(node); |
| 27 | + |
| 28 | + for (n = 0; n < blksize; n++) { |
| 29 | + PWFLT in, freq, bw, gain, out; |
| 30 | + in = pw_cable_get(peakeq->in, n); |
| 31 | + |
| 32 | + freq = pw_cable_get(peakeq->freq, n); |
| 33 | + sk_peakeq_freq(&peakeq->peakeq, freq); |
| 34 | + |
| 35 | + bw = pw_cable_get(peakeq->bw, n); |
| 36 | + sk_peakeq_bandwidth(&peakeq->peakeq, bw); |
| 37 | + |
| 38 | + gain = pw_cable_get(peakeq->gain, n); |
| 39 | + sk_peakeq_gain(&peakeq->peakeq, gain); |
| 40 | + |
| 41 | + out = sk_peakeq_tick(&peakeq->peakeq, in); |
| 42 | + pw_cable_set(peakeq->out, n, out); |
| 43 | + } |
| 44 | +} |
| 45 | + |
| 46 | +static void destroy(pw_node *node) |
| 47 | +{ |
| 48 | + pw_patch *patch; |
| 49 | + int rc; |
| 50 | + void *ud; |
| 51 | + rc = pw_node_get_patch(node, &patch); |
| 52 | + if (rc != PW_OK) return; |
| 53 | + pw_node_cables_free(node); |
| 54 | + ud = pw_node_get_data(node); |
| 55 | + pw_memory_free(patch, &ud); |
| 56 | +} |
| 57 | + |
| 58 | +int sk_node_peakeq(sk_core *core) |
| 59 | +{ |
| 60 | + pw_patch *patch; |
| 61 | + pw_node *node; |
| 62 | + int rc; |
| 63 | + sk_param in, freq, bw, gain; |
| 64 | + void *ud; |
| 65 | + struct peakeq_n *peakeq; |
| 66 | + int sr; |
| 67 | + |
| 68 | + rc = sk_param_get(core, &gain); |
| 69 | + SK_ERROR_CHECK(rc); |
| 70 | + |
| 71 | + rc = sk_param_get(core, &bw); |
| 72 | + SK_ERROR_CHECK(rc); |
| 73 | + |
| 74 | + rc = sk_param_get(core, &freq); |
| 75 | + SK_ERROR_CHECK(rc); |
| 76 | + |
| 77 | + rc = sk_param_get(core, &in); |
| 78 | + SK_ERROR_CHECK(rc); |
| 79 | + |
| 80 | + patch = sk_core_patch(core); |
| 81 | + |
| 82 | + rc = pw_memory_alloc(patch, sizeof(struct peakeq_n), &ud); |
| 83 | + SK_PW_ERROR_CHECK(rc); |
| 84 | + peakeq = (struct peakeq_n *)ud; |
| 85 | + |
| 86 | + sr = pw_patch_srate_get(patch); |
| 87 | + sk_peakeq_init(&peakeq->peakeq, sr); |
| 88 | + |
| 89 | + rc = pw_patch_new_node(patch, &node); |
| 90 | + SK_PW_ERROR_CHECK(rc); |
| 91 | + |
| 92 | + rc = pw_node_cables_alloc(node, 5); |
| 93 | + SK_PW_ERROR_CHECK(rc); |
| 94 | + |
| 95 | + pw_node_set_block(node, 4); |
| 96 | + |
| 97 | + pw_node_get_cable(node, 0, &peakeq->in); |
| 98 | + pw_node_get_cable(node, 1, &peakeq->freq); |
| 99 | + pw_node_get_cable(node, 2, &peakeq->bw); |
| 100 | + pw_node_get_cable(node, 3, &peakeq->gain); |
| 101 | + pw_node_get_cable(node, 4, &peakeq->out); |
| 102 | + |
| 103 | + pw_node_set_data(node, peakeq); |
| 104 | + pw_node_set_compute(node, compute); |
| 105 | + pw_node_set_destroy(node, destroy); |
| 106 | + |
| 107 | + sk_param_set(core, node, &in, 0); |
| 108 | + sk_param_set(core, node, &freq, 1); |
| 109 | + sk_param_set(core, node, &bw, 2); |
| 110 | + sk_param_set(core, node, &gain, 3); |
| 111 | + sk_param_out(core, node, 4); |
| 112 | + return 0; |
| 113 | +} |