History

added tsmoother

Paul Batchelor committed 5 years ago

Commit 8e2351c1 parent af8052d5 files · +114 −0Browse files

Unified · Split

5 files
  1. dsp/smoother.org +8 −0
  2. nodes/sknodes.h +1 −0
  3. nodes/smoother/l_smoother.c +21 −0
  4. nodes/smoother/smoother.c +83 −0
  5. nodes/smoother/smoother.h +1 −0
dsp/smoother.org+8−0
@@ -159,6 +159,14 @@ it to snap directly to the value =in=. · 158 unmodified lines
159#+BEGIN_SRC c159#+BEGIN_SRC c
160void sk_smoother_reset(sk_smoother *s, SKFLT in);160void sk_smoother_reset(sk_smoother *s, SKFLT in);
161#+END_SRC161#+END_SRC
162
163#+NAME: funcs
164#+BEGIN_SRC c
165void sk_smoother_reset(sk_smoother *s, SKFLT in)
166{
167 s->y0 = in;
168}
169#+END_SRC
162* Compute170* Compute
163Compute a sample with =sk_smoother_tick=. This expects an171Compute a sample with =sk_smoother_tick=. This expects an
164input signal, and returns a single output signal.172input signal, and returns a single output signal.
nodes/sknodes.h+1−0
@@ -18,4 +18,5 @@ int sk_node_div(sk_core *core); · 17 unmodified lines
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);20int sk_node_smoother(sk_core *core);
21int sk_node_tsmoother(sk_core *core);
21#endif22#endif
nodes/smoother/l_smoother.c+21−0
@@ -25,7 +25,28 @@ static lil_value_t smoother(lil_t lil, size_t argc, lil_value_t *argv) · 24 unmodified lines
25 return NULL;25 return NULL;
26}26}
27 27
28static lil_value_t tsmoother(lil_t lil, size_t argc, lil_value_t *argv)
29{
30 sk_core *core;
31 int rc;
32 core = lil_get_data(lil);
33
34 SKLIL_ARITY_CHECK(lil, "tsmoother", argc, 3);
35
36 rc = sklil_param(core, argv[0]);
37 SKLIL_PARAM_CHECK(lil, rc, "tsmoother");
38 rc = sklil_param(core, argv[1]);
39 SKLIL_PARAM_CHECK(lil, rc, "tsmoother");
40 rc = sklil_param(core, argv[2]);
41 SKLIL_PARAM_CHECK(lil, rc, "tsmoother");
42
43 rc = sk_node_tsmoother(core);
44 SKLIL_ERROR_CHECK(lil, rc, "tsmoother didn't work out.");
45 return NULL;
46}
47
28void sklil_load_smoother(lil_t lil)48void sklil_load_smoother(lil_t lil)
29{49{
30 lil_register(lil, "smoother", smoother);50 lil_register(lil, "smoother", smoother);
51 lil_register(lil, "tsmoother", tsmoother);
31}52}
nodes/smoother/smoother.c+83−0
@@ -8,6 +8,7 @@ · 7 unmodified lines
8 8
9struct smoother_n {9struct smoother_n {
10 pw_cable *in;10 pw_cable *in;
11 pw_cable *trig;
11 pw_cable *smooth;12 pw_cable *smooth;
12 pw_cable *out;13 pw_cable *out;
13 sk_smoother smoother;14 sk_smoother smoother;
@@ -35,6 +36,34 @@ static void compute(pw_node *node) · 21 unmodified lines
35 }36 }
36}37}
37 38
39static void compute_withtrig(pw_node *node)
40{
41 int blksize;
42 int n;
43 struct smoother_n *smoother;
44
45 blksize = pw_node_blksize(node);
46
47 smoother = (struct smoother_n *)pw_node_get_data(node);
48
49 for (n = 0; n < blksize; n++) {
50 PWFLT out, smooth, in, trig;
51 in = pw_cable_get(smoother->in, n);
52 trig = pw_cable_get(smoother->trig, n);
53 smooth = pw_cable_get(smoother->smooth, n);
54
55 sk_smoother_time(&smoother->smoother, smooth);
56
57 if (trig != 0) {
58 sk_smoother_reset(&smoother->smoother, in);
59 }
60
61 out = sk_smoother_tick(&smoother->smoother, in);
62
63 pw_cable_set(smoother->out, n, out);
64 }
65}
66
38static void destroy(pw_node *node)67static void destroy(pw_node *node)
39{68{
40 pw_patch *patch;69 pw_patch *patch;
@@ -94,3 +123,57 @@ int sk_node_smoother(sk_core *core) · 53 unmodified lines
94 sk_param_out(core, node, 2);123 sk_param_out(core, node, 2);
95 return 0;124 return 0;
96}125}
126
127int sk_node_tsmoother(sk_core *core)
128{
129 pw_patch *patch;
130 pw_node *node;
131 int rc;
132 sk_param in;
133 sk_param trig;
134 sk_param smooth;
135 void *ud;
136 struct smoother_n *smoother;
137 int sr;
138
139 rc = sk_param_get(core, &smooth);
140 SK_ERROR_CHECK(rc);
141
142 rc = sk_param_get(core, &trig);
143 SK_ERROR_CHECK(rc);
144
145 rc = sk_param_get(core, &in);
146 SK_ERROR_CHECK(rc);
147
148 patch = sk_core_patch(core);
149
150 rc = pw_memory_alloc(patch, sizeof(struct smoother_n), &ud);
151 SK_PW_ERROR_CHECK(rc);
152 smoother = (struct smoother_n *)ud;
153
154 sr = pw_patch_srate_get(patch);
155 sk_smoother_init(&smoother->smoother, sr);
156
157 rc = pw_patch_new_node(patch, &node);
158 SK_PW_ERROR_CHECK(rc);
159
160 rc = pw_node_cables_alloc(node, 4);
161 SK_PW_ERROR_CHECK(rc);
162
163 pw_node_set_block(node, 3);
164
165 pw_node_get_cable(node, 0, &smoother->in);
166 pw_node_get_cable(node, 1, &smoother->trig);
167 pw_node_get_cable(node, 2, &smoother->smooth);
168 pw_node_get_cable(node, 3, &smoother->out);
169
170 pw_node_set_data(node, smoother);
171 pw_node_set_compute(node, compute_withtrig);
172 pw_node_set_destroy(node, destroy);
173
174 sk_param_set(core, node, &in, 0);
175 sk_param_set(core, node, &trig, 1);
176 sk_param_set(core, node, &smooth, 2);
177 sk_param_out(core, node, 3);
178 return 0;
179}
nodes/smoother/smoother.h+1−0
@@ -1,4 +1,5 @@
1#ifndef SK_NODE_SMOOTHER_H1#ifndef SK_NODE_SMOOTHER_H
2#define SK_NODE_SMOOTHER_H2#define SK_NODE_SMOOTHER_H
3int sk_node_smoother(sk_core *core);3int sk_node_smoother(sk_core *core);
4int sk_node_tsmoother(sk_core *core);
4#endif5#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