History

smoother: initial lil command

Paul Batchelor committed 5 years ago

Commit c7ff5381 parent d4923977 files · +137 −0Browse files

Unified · Split

7 files
  1. nodes/config.mk +1 −0
  2. nodes/loader.c +2 −0
  3. nodes/sknodes.h +1 −0
  4. nodes/smoother/config.mk +2 −0
  5. nodes/smoother/l_smoother.c +31 −0
  6. nodes/smoother/smoother.c +96 −0
  7. nodes/smoother/smoother.h +4 −0
nodes/config.mk+1−0
@@ -12,3 +12,4 @@ include nodes/buffer/config.mk · 11 unmodified lines
12include nodes/bigverb/config.mk12include nodes/bigverb/config.mk
13include nodes/fmpair/config.mk13include nodes/fmpair/config.mk
14include nodes/dcblocker/config.mk14include nodes/dcblocker/config.mk
15include nodes/smoother/config.mk
nodes/loader.c+2−0
@@ -19,6 +19,7 @@ void sklil_load_buffer(lil_t lil); · 18 unmodified lines
19void sklil_load_bigverb(lil_t lil);19void sklil_load_bigverb(lil_t lil);
20void sklil_load_fmpair(lil_t lil);20void sklil_load_fmpair(lil_t lil);
21void sklil_load_dcblocker(lil_t lil);21void sklil_load_dcblocker(lil_t lil);
22void sklil_load_smoother(lil_t lil);
22 23
23void sklil_nodes(lil_t lil)24void sklil_nodes(lil_t lil)
24{25{
@@ -36,6 +37,7 @@ void sklil_nodes(lil_t lil) · 11 unmodified lines
36 sklil_load_bigverb(lil);37 sklil_load_bigverb(lil);
37 sklil_load_fmpair(lil);38 sklil_load_fmpair(lil);
38 sklil_load_dcblocker(lil);39 sklil_load_dcblocker(lil);
40 sklil_load_smoother(lil);
39}41}
40 42
41static lil_value_t computes(lil_t lil, size_t argc, lil_value_t *argv)43static lil_value_t computes(lil_t lil, size_t argc, lil_value_t *argv)
nodes/sknodes.h+1−0
@@ -17,4 +17,5 @@ int sk_node_sub(sk_core *core); · 16 unmodified lines
17int sk_node_div(sk_core *core);17int sk_node_div(sk_core *core);
18int sk_node_bigverb(sk_core *core);18int sk_node_bigverb(sk_core *core);
19int sk_node_gensine(sk_core *core);19int sk_node_gensine(sk_core *core);
20int sk_node_smoother(sk_core *core);
20#endif21#endif
nodes/smoother/config.mk+2−0
@@ -0,0 +1,2 @@
1OBJ+=nodes/smoother/smoother.o
2OBJ+=nodes/smoother/l_smoother.o
nodes/smoother/l_smoother.c+31−0
@@ -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
10static 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
28void sklil_load_smoother(lil_t lil)
29{
30 lil_register(lil, "smoother", smoother);
31}
nodes/smoother/smoother.c+96−0
@@ -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
9struct smoother_n {
10 pw_cable *in;
11 pw_cable *smooth;
12 pw_cable *out;
13 sk_smoother smoother;
14};
15
16static 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
38static 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
50int 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}
nodes/smoother/smoother.h+4−0
@@ -0,0 +1,4 @@
1#ifndef SK_NODE_SMOOTHER_H
2#define SK_NODE_SMOOTHER_H
3int sk_node_smoother(sk_core *core);
4#endif

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t