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
159159 #+BEGIN_SRC c
160160 void sk_smoother_reset(sk_smoother *s, SKFLT in);
161161 #+END_SRC
162+
163+#+NAME: funcs
164+#+BEGIN_SRC c
165+void sk_smoother_reset(sk_smoother *s, SKFLT in)
166+{
167+ s->y0 = in;
168+}
169+#+END_SRC
162170 * Compute
163171 Compute a sample with =sk_smoother_tick=. This expects an
164172 input 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
1818 int sk_node_bigverb(sk_core *core);
1919 int sk_node_gensine(sk_core *core);
2020 int sk_node_smoother(sk_core *core);
21+int sk_node_tsmoother(sk_core *core);
2122 #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
2525 return NULL;
2626 }
2727
28+static 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+
2848 void sklil_load_smoother(lil_t lil)
2949 {
3050 lil_register(lil, "smoother", smoother);
51+ lil_register(lil, "tsmoother", tsmoother);
3152 }
nodes/smoother/smoother.c+83−0
@@ -8,6 +8,7 @@ · 7 unmodified lines
88
99 struct smoother_n {
1010 pw_cable *in;
11+ pw_cable *trig;
1112 pw_cable *smooth;
1213 pw_cable *out;
1314 sk_smoother smoother;
@@ -35,6 +36,34 @@ static void compute(pw_node *node) · 21 unmodified lines
3536 }
3637 }
3738
39+static 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+
3867 static void destroy(pw_node *node)
3968 {
4069 pw_patch *patch;
@@ -94,3 +123,57 @@ int sk_node_smoother(sk_core *core) · 53 unmodified lines
94123 sk_param_out(core, node, 2);
95124 return 0;
96125 }
126+
127+int 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 @@
11 #ifndef SK_NODE_SMOOTHER_H
22 #define SK_NODE_SMOOTHER_H
33 int sk_node_smoother(sk_core *core);
4+int sk_node_tsmoother(sk_core *core);
45 #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