Unified · Split
| @@ -12,3 +12,4 @@ include nodes/buffer/config.mk · 11 unmodified lines | ||
| 12 | 12 | include nodes/bigverb/config.mk |
| 13 | 13 | include nodes/fmpair/config.mk |
| 14 | 14 | include nodes/dcblocker/config.mk |
| 15 | +include nodes/smoother/config.mk | |
| @@ -19,6 +19,7 @@ void sklil_load_buffer(lil_t lil); · 18 unmodified lines | ||
| 19 | 19 | void sklil_load_bigverb(lil_t lil); |
| 20 | 20 | void sklil_load_fmpair(lil_t lil); |
| 21 | 21 | void sklil_load_dcblocker(lil_t lil); |
| 22 | +void sklil_load_smoother(lil_t lil); | |
| 22 | 23 | |
| 23 | 24 | void sklil_nodes(lil_t lil) |
| 24 | 25 | { |
| @@ -36,6 +37,7 @@ void sklil_nodes(lil_t lil) · 11 unmodified lines | ||
| 36 | 37 | sklil_load_bigverb(lil); |
| 37 | 38 | sklil_load_fmpair(lil); |
| 38 | 39 | sklil_load_dcblocker(lil); |
| 40 | + sklil_load_smoother(lil); | |
| 39 | 41 | } |
| 40 | 42 | |
| 41 | 43 | static lil_value_t computes(lil_t lil, size_t argc, lil_value_t *argv) |
| @@ -17,4 +17,5 @@ int sk_node_sub(sk_core *core); · 16 unmodified lines | ||
| 17 | 17 | int sk_node_div(sk_core *core); |
| 18 | 18 | int sk_node_bigverb(sk_core *core); |
| 19 | 19 | int sk_node_gensine(sk_core *core); |
| 20 | +int sk_node_smoother(sk_core *core); | |
| 20 | 21 | #endif |
| @@ -0,0 +1,2 @@ | ||
| 1 | +OBJ+=nodes/smoother/smoother.o | |
| 2 | +OBJ+=nodes/smoother/l_smoother.o | |
| @@ -0,0 +1,31 @@ | ||
| 1 | +#include <stdlib.h> | |
| 2 | +#include <stdio.h> | |
| 3 | +#include <string.h> | |
| 4 | +#include "lil/lil.h" | |
| 5 | +#include "patchwerk/patchwerk.h" | |
| 6 | +#include "core.h" | |
| 7 | +#include "sklil.h" | |
| 8 | +#include "smoother.h" | |
| 9 | + | |
| 10 | +static lil_value_t smoother(lil_t lil, size_t argc, lil_value_t *argv) | |
| 11 | +{ | |
| 12 | + sk_core *core; | |
| 13 | + int rc; | |
| 14 | + core = lil_get_data(lil); | |
| 15 | + | |
| 16 | + SKLIL_ARITY_CHECK(lil, "smoother", argc, 2); | |
| 17 | + | |
| 18 | + rc = sklil_param(core, argv[0]); | |
| 19 | + SKLIL_PARAM_CHECK(lil, rc, "smoother"); | |
| 20 | + rc = sklil_param(core, argv[1]); | |
| 21 | + SKLIL_PARAM_CHECK(lil, rc, "smoother"); | |
| 22 | + | |
| 23 | + rc = sk_node_smoother(core); | |
| 24 | + SKLIL_ERROR_CHECK(lil, rc, "smoother didn't work out."); | |
| 25 | + return NULL; | |
| 26 | +} | |
| 27 | + | |
| 28 | +void sklil_load_smoother(lil_t lil) | |
| 29 | +{ | |
| 30 | + lil_register(lil, "smoother", smoother); | |
| 31 | +} | |
| @@ -0,0 +1,96 @@ | ||
| 1 | +#include <math.h> | |
| 2 | +#include <stdlib.h> | |
| 3 | +#include <stdint.h> | |
| 4 | +#include "patchwerk.h" | |
| 5 | +#include "core.h" | |
| 6 | +#define SK_SMOOTHER_PRIV | |
| 7 | +#include "dsp/smoother.h" | |
| 8 | + | |
| 9 | +struct smoother_n { | |
| 10 | + pw_cable *in; | |
| 11 | + pw_cable *smooth; | |
| 12 | + pw_cable *out; | |
| 13 | + sk_smoother smoother; | |
| 14 | +}; | |
| 15 | + | |
| 16 | +static void compute(pw_node *node) | |
| 17 | +{ | |
| 18 | + int blksize; | |
| 19 | + int n; | |
| 20 | + struct smoother_n *smoother; | |
| 21 | + | |
| 22 | + blksize = pw_node_blksize(node); | |
| 23 | + | |
| 24 | + smoother = (struct smoother_n *)pw_node_get_data(node); | |
| 25 | + | |
| 26 | + for (n = 0; n < blksize; n++) { | |
| 27 | + PWFLT out, smooth, in; | |
| 28 | + in = pw_cable_get(smoother->in, n); | |
| 29 | + smooth = pw_cable_get(smoother->smooth, n); | |
| 30 | + | |
| 31 | + sk_smoother_time(&smoother->smoother, smooth); | |
| 32 | + out = sk_smoother_tick(&smoother->smoother, in); | |
| 33 | + | |
| 34 | + pw_cable_set(smoother->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_smoother(sk_core *core) | |
| 51 | +{ | |
| 52 | + pw_patch *patch; | |
| 53 | + pw_node *node; | |
| 54 | + int rc; | |
| 55 | + sk_param in; | |
| 56 | + sk_param smooth; | |
| 57 | + void *ud; | |
| 58 | + struct smoother_n *smoother; | |
| 59 | + int sr; | |
| 60 | + | |
| 61 | + rc = sk_param_get(core, &smooth); | |
| 62 | + SK_ERROR_CHECK(rc); | |
| 63 | + | |
| 64 | + rc = sk_param_get(core, &in); | |
| 65 | + SK_ERROR_CHECK(rc); | |
| 66 | + | |
| 67 | + patch = sk_core_patch(core); | |
| 68 | + | |
| 69 | + rc = pw_memory_alloc(patch, sizeof(struct smoother_n), &ud); | |
| 70 | + SK_PW_ERROR_CHECK(rc); | |
| 71 | + smoother = (struct smoother_n *)ud; | |
| 72 | + | |
| 73 | + sr = pw_patch_srate_get(patch); | |
| 74 | + sk_smoother_init(&smoother->smoother, sr); | |
| 75 | + | |
| 76 | + rc = pw_patch_new_node(patch, &node); | |
| 77 | + SK_PW_ERROR_CHECK(rc); | |
| 78 | + | |
| 79 | + rc = pw_node_cables_alloc(node, 3); | |
| 80 | + SK_PW_ERROR_CHECK(rc); | |
| 81 | + | |
| 82 | + pw_node_set_block(node, 2); | |
| 83 | + | |
| 84 | + pw_node_get_cable(node, 0, &smoother->in); | |
| 85 | + pw_node_get_cable(node, 1, &smoother->smooth); | |
| 86 | + pw_node_get_cable(node, 2, &smoother->out); | |
| 87 | + | |
| 88 | + pw_node_set_data(node, smoother); | |
| 89 | + pw_node_set_compute(node, compute); | |
| 90 | + pw_node_set_destroy(node, destroy); | |
| 91 | + | |
| 92 | + sk_param_set(core, node, &in, 0); | |
| 93 | + sk_param_set(core, node, &smooth, 1); | |
| 94 | + sk_param_out(core, node, 2); | |
| 95 | + return 0; | |
| 96 | +} | |
| @@ -0,0 +1,4 @@ | ||
| 1 | +#ifndef SK_NODE_SMOOTHER_H | |
| 2 | +#define SK_NODE_SMOOTHER_H | |
| 3 | +int sk_node_smoother(sk_core *core); | |
| 4 | +#endif | |